summaryrefslogtreecommitdiffstats
path: root/third_party/WebKit/LayoutTests/fast/files/read-blob-as-array-buffer.html
blob: 0738fdfefa634e1301ea617397a944a460798bfe (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
<!DOCTYPE html>
<html>
<body>
<script src="../../resources/testharness.js"></script>
<script src="../../resources/testharnessreport.js"></script>
<script type="text/javascript">
var test = async_test("Test reading data from a blob as an ArrayBuffer");

var onloadstartSeen = false;

test.step(function() {
    var blob = new Blob(["HelloWorld"]);
    var reader = new FileReader();
    assert_equals(reader.readyState, reader.EMPTY,
                  "reader.readyState");
    reader.readAsArrayBuffer(blob);
    reader.onloadstart = test.step_func(function() {
        assert_false(onloadstartSeen, "onloadstartSeen");
        onloadstartSeen = true;

        assert_equals(reader.readyState, reader.LOADING,
                      "reader.readyState");
        assert_equals(reader.error, null, "reader.error");
        assert_not_equals(reader.result, null, "reader.result");
        assert_true(reader.result.byteLength >= 0 &&
                    reader.result.byteLength <= 10,
                    "reader.result.byteLength between 0 and 10 inclusive");
    });
    reader.onabort = test.step_func(function() {
        assert_unreached("onabort invoked on reader");
    });
    reader.onerror = test.step_func(function() {
        assert_unreached("onerror invoked on reader");
    });
    reader.onloadend = test.step_func(function() {
        assert_equals(reader.readyState, reader.DONE,
                      "reader.readyState");
        assert_equals(reader.error, null, "reader.error");
        assert_not_equals(reader.result, null, "reader.result");
        assert_equals(reader.result.byteLength, 10,
                      "reader.result.byteLength");
        test.done();
    });
});
</script>
</body>
</html>