summaryrefslogtreecommitdiffstats
path: root/third_party/WebKit/LayoutTests/fast/filesystem/script-tests/read-directory.js
blob: a401b654abbd5f738c5245c7bd04f6c68a21afc6 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
description("DirectoryReader.readEntries() test.");
var fileSystem = null;
var reader = null;
var resultEntries = [];

var readEntriesCount = 0;
var entriesCallbackCount = 0;

// path: isDirectory map.
var testEntries = {
    '/a': true,
    '/b': false,
    '/c': true,
    '/d': false,
    '/e': false,
    '/f': true,
};
var testEntriesCount = 0;

function endTest()
{
    removeAllInDirectory(fileSystem.root);
    finishJSTest();
}

function errorCallback(error)
{
    debug("Error occured:" + error.name);
    endTest();
}

var entry = null;
function verifyTestResult()
{
    shouldBe('readEntriesCount', 'entriesCallbackCount');
    shouldBe('resultEntries.length', 'testEntriesCount');
    resultEntries.sort(function(a, b) { return (a.fullPath > b.fullPath) ? 1 : (a.fullPath < b.fullPath) ? -1 : 0; });
    for (i = 0; i < resultEntries.length; ++i) {
        entry = resultEntries[i];
        debug('Entry:' + entry.fullPath + ' isDirectory:' + entry.isDirectory);
        shouldBe('testEntries[entry.fullPath]', 'entry.isDirectory');
    }
}

var entries;
function entriesCallback(_entries)
{
    entriesCallbackCount++;
    entries = _entries;
    shouldBe("entries.__proto__", "Array.prototype");
    resultEntries.push.apply(resultEntries, entries);

    if (entries.length) {
        readEntriesCount++;
        reader.readEntries(entriesCallback, errorCallback);
    } else {
        // Must have read all the entries.
        verifyTestResult();
        endTest();
    }
}

function runReadDirectoryTest()
{
    readEntriesCount++;
    reader = fileSystem.root.createReader();
    reader.readEntries(entriesCallback, errorCallback);
}

function prepareForTest()
{
    var helper = new JoinHelper();
    var done = function() { helper.done(); };

    for (var path in testEntries) {
        testEntriesCount++;
        if (testEntries[path])
            helper.run(function() { fileSystem.root.getDirectory(path, {create:true}, done, errorCallback); });
        else
            helper.run(function() { fileSystem.root.getFile(path, {create:true}, done, errorCallback); });
    }
    helper.join(runReadDirectoryTest);
}

function successCallback(fs)
{
    fileSystem = fs;
    debug("Successfully obtained Persistent FileSystem:" + fileSystem.name);
    removeAllInDirectory(fileSystem.root, prepareForTest, errorCallback);
}

if (window.webkitRequestFileSystem) {
    webkitRequestFileSystem(window.TEMPORARY, 100, successCallback, errorCallback);
    window.jsTestIsAsync = true;
} else
    debug("This test requires FileSystem API support.");