mirror of
https://github.com/classilla/tenfourfox.git
synced 2024-11-04 10:05:51 +00:00
99 lines
2.5 KiB
HTML
99 lines
2.5 KiB
HTML
|
<!--
|
||
|
Any copyright is dedicated to the Public Domain.
|
||
|
http://creativecommons.org/publicdomain/zero/1.0/
|
||
|
-->
|
||
|
<!DOCTYPE HTML>
|
||
|
<html> <!--
|
||
|
https://bugzilla.mozilla.org/show_bug.cgi?id=XXX
|
||
|
-->
|
||
|
<head>
|
||
|
<title>Test Directory#getFilesAndDirectories of the FileSystem API for device storage</title>
|
||
|
<script type="text/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
|
||
|
<script type="text/javascript" src="devicestorage_common.js"></script>
|
||
|
|
||
|
<link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" />
|
||
|
</head>
|
||
|
<body>
|
||
|
<a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=XXX">Mozilla Bug XXX</a>
|
||
|
<p id="display"></p>
|
||
|
<div id="content" style="display: none">
|
||
|
</div>
|
||
|
<pre id="test">
|
||
|
<script class="testbody" type="text/javascript">
|
||
|
|
||
|
devicestorage_setup(function () {
|
||
|
SimpleTest.requestCompleteLog();
|
||
|
|
||
|
// The root directory object.
|
||
|
var gRoot = null;
|
||
|
|
||
|
function checkContents1(contents) {
|
||
|
var expected = {
|
||
|
"sub2": "/sub",
|
||
|
"sub3": "/sub",
|
||
|
"a.png": "/sub",
|
||
|
"b.png": "/sub",
|
||
|
};
|
||
|
|
||
|
is(contents.length, Object.keys(expected).length,
|
||
|
"The sub-directory should contain four children");
|
||
|
|
||
|
var sub2;
|
||
|
|
||
|
for (var child of contents) {
|
||
|
if (child.name in expected) {
|
||
|
ok(true, "Found '" + child.name + "' in /sub");
|
||
|
if (child.name == "sub2") {
|
||
|
sub2 = child;
|
||
|
}
|
||
|
} else {
|
||
|
ok(false, "Did not expect '" + child.name + "' in /sub");
|
||
|
}
|
||
|
delete expected[child.name];
|
||
|
}
|
||
|
|
||
|
// 'expected' should now be "empty"
|
||
|
for (var missing in Object.keys(expected)) {
|
||
|
ok(false, "Expected '" + missing.name + "' in /sub");
|
||
|
}
|
||
|
|
||
|
sub2.getFilesAndDirectories().then(checkContents2, handleError);
|
||
|
}
|
||
|
|
||
|
function checkContents2(contents) {
|
||
|
is(contents[0].name, "c.png", "'sub2' should contain 'c.png'");
|
||
|
SimpleTest.finish();
|
||
|
}
|
||
|
|
||
|
function handleError(e) {
|
||
|
ok(false, "Should not arrive at handleError! Error: " + e.name);
|
||
|
SimpleTest.finish();
|
||
|
}
|
||
|
|
||
|
var gStorage = navigator.getDeviceStorage("pictures");
|
||
|
|
||
|
ok(gStorage, "Should have gotten a storage.");
|
||
|
|
||
|
function runTests() {
|
||
|
gStorage.getRoot().then(function(rootDir) {
|
||
|
gRoot = rootDir;
|
||
|
return rootDir.get("sub");
|
||
|
}).then(function(subDir) {
|
||
|
return subDir.getFilesAndDirectories();
|
||
|
}).then(checkContents1).catch(handleError);
|
||
|
}
|
||
|
|
||
|
createTestFiles(gStorage, ["sub/a.png", "sub/b.png", "sub/sub2/c.png", "sub/sub3/d.png"]).then(function() {
|
||
|
runTests();
|
||
|
}, function() {
|
||
|
ok(false, "Failed to created test files.");
|
||
|
SimpleTest.finish();
|
||
|
});
|
||
|
|
||
|
});
|
||
|
|
||
|
</script>
|
||
|
</pre>
|
||
|
</body>
|
||
|
</html>
|