Merge Chromium + Blink git repositories
[chromium-blink-merge.git] / third_party / WebKit / LayoutTests / fast / filesystem / script-tests / read-directory.js
bloba401b654abbd5f738c5245c7bd04f6c68a21afc6
1 description("DirectoryReader.readEntries() test.");
2 var fileSystem = null;
3 var reader = null;
4 var resultEntries = [];
6 var readEntriesCount = 0;
7 var entriesCallbackCount = 0;
9 // path: isDirectory map.
10 var testEntries = {
11 '/a': true,
12 '/b': false,
13 '/c': true,
14 '/d': false,
15 '/e': false,
16 '/f': true,
18 var testEntriesCount = 0;
20 function endTest()
22 removeAllInDirectory(fileSystem.root);
23 finishJSTest();
26 function errorCallback(error)
28 debug("Error occured:" + error.name);
29 endTest();
32 var entry = null;
33 function verifyTestResult()
35 shouldBe('readEntriesCount', 'entriesCallbackCount');
36 shouldBe('resultEntries.length', 'testEntriesCount');
37 resultEntries.sort(function(a, b) { return (a.fullPath > b.fullPath) ? 1 : (a.fullPath < b.fullPath) ? -1 : 0; });
38 for (i = 0; i < resultEntries.length; ++i) {
39 entry = resultEntries[i];
40 debug('Entry:' + entry.fullPath + ' isDirectory:' + entry.isDirectory);
41 shouldBe('testEntries[entry.fullPath]', 'entry.isDirectory');
45 var entries;
46 function entriesCallback(_entries)
48 entriesCallbackCount++;
49 entries = _entries;
50 shouldBe("entries.__proto__", "Array.prototype");
51 resultEntries.push.apply(resultEntries, entries);
53 if (entries.length) {
54 readEntriesCount++;
55 reader.readEntries(entriesCallback, errorCallback);
56 } else {
57 // Must have read all the entries.
58 verifyTestResult();
59 endTest();
63 function runReadDirectoryTest()
65 readEntriesCount++;
66 reader = fileSystem.root.createReader();
67 reader.readEntries(entriesCallback, errorCallback);
70 function prepareForTest()
72 var helper = new JoinHelper();
73 var done = function() { helper.done(); };
75 for (var path in testEntries) {
76 testEntriesCount++;
77 if (testEntries[path])
78 helper.run(function() { fileSystem.root.getDirectory(path, {create:true}, done, errorCallback); });
79 else
80 helper.run(function() { fileSystem.root.getFile(path, {create:true}, done, errorCallback); });
82 helper.join(runReadDirectoryTest);
85 function successCallback(fs)
87 fileSystem = fs;
88 debug("Successfully obtained Persistent FileSystem:" + fileSystem.name);
89 removeAllInDirectory(fileSystem.root, prepareForTest, errorCallback);
92 if (window.webkitRequestFileSystem) {
93 webkitRequestFileSystem(window.TEMPORARY, 100, successCallback, errorCallback);
94 window.jsTestIsAsync = true;
95 } else
96 debug("This test requires FileSystem API support.");