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
|
function test_blob(fn, expectations) {
var expected = expectations.expected,
type = expectations.type,
desc = expectations.desc;
var t = async_test(desc);
t.step(function() {
var blob = fn();
assert_true(blob instanceof Blob);
assert_false(blob instanceof File);
assert_equals(blob.type, type);
assert_equals(blob.size, expected.length);
var fr = new FileReader();
fr.onload = t.step_func_done(function(event) {
assert_equals(this.result, expected);
}, fr);
fr.onerror = t.step_func(function(e) {
assert_unreached("got error event on FileReader");
});
fr.readAsText(blob, "UTF-8");
});
}
function test_blob_binary(fn, expectations) {
var expected = expectations.expected,
type = expectations.type,
desc = expectations.desc;
var t = async_test(desc);
t.step(function() {
var blob = fn();
assert_true(blob instanceof Blob);
assert_false(blob instanceof File);
assert_equals(blob.type, type);
assert_equals(blob.size, expected.length);
var fr = new FileReader();
fr.onload = t.step_func_done(function(event) {
assert_true(this.result instanceof ArrayBuffer,
"Result should be an ArrayBuffer");
assert_array_equals(new Uint8Array(this.result), expected);
}, fr);
fr.onerror = t.step_func(function(e) {
assert_unreached("got error event on FileReader");
});
fr.readAsArrayBuffer(blob);
});
}
|