summaryrefslogtreecommitdiffstats
path: root/third_party/WebKit/LayoutTests/fast/filesystem/script-tests/filesystem-reference.js
blob: 0fb0109627487b136b8cadfb9f3276d6b9597c44 (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
description("This tests if Entries returned by callbacks keep functioning even after we lose a reference to the filesystem in the script.");

var testDirectory = null;
var testEntries = null;

function errorCallback(error)
{
    testFailed("Error occurred: " + error.name);
    finishJSTest();
}

function runTest1(root)
{
    debug("Running runTest1()...");
    var helper = new JoinHelper();
    var done = function() { helper.done(); };

    helper.run(function() { root.getFile('a', {create:true}, done, errorCallback); });
    helper.run(function() { root.getDirectory('b', {create:true}, done, errorCallback); });
    helper.run(function() { root.getDirectory('c', {create:true}, done, errorCallback); });

    gc();
    helper.join(function() { runTest2(root); });
}

function runTest2(root)
{
    debug("Running runTest2()...");
    var helper = new JoinHelper();
    var done = function() { helper.done(); };

    helper.run(function() { root.getFile('/b/1', {create:true}, done, errorCallback); });
    helper.run(function() { root.getFile('/b/2', {create:true}, done, errorCallback); });
    helper.run(function() { root.getFile('/b/3', {create:true}, done, errorCallback); });
    helper.run(function() { root.getFile('/b/4', {create:true}, done, errorCallback); });
    helper.run(function() { root.getDirectory('b', {create:false}, function(entry) { testDirectory = entry; helper.done(); }, errorCallback); });

    gc();
    helper.join(function() { runTest3(); });
}

function runTest3()
{
    debug("Running runTest3()...");
    testDirectory.createReader().readEntries(entriesCallback, errorCallback);
    testDirectory = null;
    gc();
}

function entriesCallback(entries)
{
    debug("Running runTest4()...");
    testEntries = entries;
    shouldBe("testEntries.length", "4");
    finishJSTest();
}

function fileSystemCallback(fs)
{
    var root = fs.root;
    removeAllInDirectory(fs.root, function() { runTest1(root); }, errorCallback);
    fs = null;
    gc();
}

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