summaryrefslogtreecommitdiffstats
path: root/third_party/WebKit/LayoutTests/fast/files/blob-slice-test.html
blob: 06fec6e4cbc5a427761a131a9f4908be0609185f (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
<!DOCTYPE html>
<html>
<head>
<script>
var blob;
var testIndex = 0;
var sliceParams = [
    [2, 3],
    [2, 12],
    [2, 2],
    [2, 1],
    [2, -12],
    [2, 2147483647],
    [2, -2147483648],
    [2, 9223372036854775000],
    [2, -9223372036854775000],
    [-2, -1],
    [-2, -2],
    [-2, -3],
    [-2, -12],
    [-2, 2147483647],
    [-2, -2147483648],
    [-2, 9223372036854775000],
    [-2, -9223372036854775000],
    [0],
    [2],
    [-2],
    [12],
    [-12],
    [2147483647],
    [-2147483648],
    [9223372036854775000],
    [-9223372036854775000],
    [],
];

function log(message)
{
    document.getElementById('console').appendChild(document.createTextNode(message + "\n"));
}

function testSlicing(start, end)
{
    var subBlob;
    var reader = new FileReader();
    var message = "Slicing ";
    if (start == undefined && end == undefined) {
        message += "without parameters";
        subBlob = blob.slice();
    } else if (end == undefined) {
        message += "from " + start;
        subBlob = blob.slice(start);
    } else {
        message += "from " + start + " to " + end;
        subBlob = blob.slice(start, end);
    }
    message += ": ";
    reader.onload = function(event) {
        log(message + event.target.result);
        runNextTest();
    };
    reader.onerror = function(event) {
        log(message + "error " + event.target.error.code);
        runNextTest();
    };
    reader.readAsText(subBlob);
}

function runNextTest()
{
    if (testIndex >= sliceParams.length) {
        if (window.testRunner)
            testRunner.notifyDone();
        return;
    }

    var start = sliceParams[testIndex][0];
    var end = sliceParams[testIndex][1];
    testIndex++;
    testSlicing(start, end);
}

function runTests()
{
    blob = new Blob(["0123456789"]);

    runNextTest();
}

if (window.testRunner) {
    testRunner.dumpAsText();
    testRunner.waitUntilDone();
}
</script>
</head>
<body onload="runTests()">
<pre id='console'></pre>
</body>
</html>