summaryrefslogtreecommitdiffstats
path: root/third_party/WebKit/LayoutTests/fast/filesystem/resources/async-operations.js
blob: 1d66e947a778ea0c740fa65cc029ff0f48441131 (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
97
98
99
100
101
102
103
104
105
106
if (this.importScripts) {
    importScripts('../resources/fs-worker-common.js');
    importScripts('../../../resources/js-test.js');
    importScripts('../resources/fs-test-util.js');
}

description("Test making multiple async FileSystem operations.");

var fileSystem = null;

var a;
var b;
var c;
var d;

var paths = [];
var dirsCount = 0;
var reader = null;

function errorCallback(error) {
    debug("Got error: " + error.name);
    removeAllInDirectory(fileSystem.root);
    finishJSTest();
}

function entriesCallback(entries) {
    for (var i = 0; i < entries.length; ++i) {
        paths.push(entries[i].fullPath);
        if (entries[i].isDirectory)
            dirsCount++;
    }
    if (!entries.length) {
        reader.readEntries(entriesCallback, errorCallback);
    } else {
        paths.sort();
        shouldBe('"' + paths.join(',') + '"', '"/a,/b,/c,/d2,/e,/f"');
        shouldBe("dirsCount", "3");
        removeAllInDirectory(fileSystem.root);
        finishJSTest();
    }
}

function verify() {
    debug("Verifying the FileSystem status.");
    reader = fileSystem.root.createReader();
    reader.readEntries(entriesCallback, errorCallback);
}

function asyncTest2() {
    debug("Starting async test stage 2.");

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

    helper.run(function() { a.copyTo(b, 'tmp', done, errorCallback); });
    helper.run(function() { a.getMetadata(done, errorCallback); });
    helper.run(function() { b.getParent(done, errorCallback); });
    helper.run(function() { c.copyTo(fileSystem.root, 'f', done, errorCallback); });
    helper.run(function() { d.moveTo(fileSystem.root, 'd2', done, errorCallback); });
    helper.run(function() { fileSystem.root.getFile('e', {create:true}, done, errorCallback); });

    helper.join(verify);
}

function asyncTest1() {
    debug("Starting async test stage 1.");

    var helper = new JoinHelper();
    var root = fileSystem.root;

    helper.run(function() { root.getFile('a', {create:true}, function(entry) {
        a = entry;
        helper.done();
    }, errorCallback); });

    helper.run(function() { root.getDirectory('b', {create:true}, function(entry) {
        b = entry;
        helper.done();
    }, errorCallback); });

    helper.run(function() { root.getDirectory('c', {create:true}, function(entry) {
        c = entry;
        helper.done();
    }, errorCallback); });

    helper.run(function() { root.getFile('d', {create:true}, function(entry) {
        d = entry;
        helper.done();
    }, errorCallback); });

    helper.join(asyncTest2);
}

if (this.webkitRequestFileSystem) {
    jsTestIsAsync = true;
    var helper = new JoinHelper();
    helper.run(function() {
    webkitRequestFileSystem.apply(this, [this.TEMPORARY, 100, function(fs) {
        debug("Got FileSystem:" + fs.name);
        fileSystem = fs;
        removeAllInDirectory(fileSystem.root, function(){ helper.done(); }, errorCallback);
    }, errorCallback]); });
    debug("requested FileSystem.");
    helper.join(asyncTest1);
} else
    debug("This test requires FileSystem API support.");