OLD | NEW |
---|---|
1 <!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML//EN"> | 1 <!DOCTYPE html> |
2 <html> | 2 |
3 <head> | |
4 <script src="../../resources/js-test.js"></script> | 3 <script src="../../resources/js-test.js"></script> |
5 </head> | 4 <script> |
6 <body> | 5 description("Test the Blob constructor."); |
7 <script src="script-tests/blob-constructor.js"></script> | 6 |
kinuko
2013/11/14 05:41:06
(It's fine for this CL, but it'd have been probabl
pwnall-personal
2013/11/14 14:31:19
I'm really sorry about that, and appreciate you re
| |
8 </body> | 7 // Test the diffrent ways you can construct a Blob. |
9 </html> | 8 shouldBeTrue("(new Blob()) instanceof window.Blob"); |
9 shouldBeTrue("(new Blob([])) instanceof window.Blob"); | |
10 shouldBeTrue("(new Blob(['hello'])) instanceof window.Blob"); | |
11 shouldBeTrue("(new Blob(['hello'], {})) instanceof window.Blob"); | |
12 shouldBeTrue("(new Blob(['hello'], {type:'text/html'})) instanceof window.Blob") ; | |
13 shouldBeTrue("(new Blob(['hello'], {type:'text/html', endings:'native'})) instan ceof window.Blob"); | |
14 shouldBeTrue("(new Blob(['hello'], {type:'text/html', endings:'transparent'})) i nstanceof window.Blob"); | |
15 | |
16 // Test invalid blob parts | |
17 shouldThrow("new Blob('hello')", '"TypeError: Failed to construct \'Blob\': The 1st argument is neither an array, nor does it have indexed properties."'); | |
18 shouldThrow("new Blob(0)", '"TypeError: Failed to construct \'Blob\': The 1st ar gument is neither an array, nor does it have indexed properties."'); | |
19 | |
20 // Test valid blob parts. | |
21 shouldBeTrue("(new Blob([])) instanceof window.Blob"); | |
22 shouldBeTrue("(new Blob(['stringPrimitive'])) instanceof window.Blob"); | |
23 shouldBeTrue("(new Blob([String('stringObject')])) instanceof window.Blob"); | |
24 shouldBeTrue("(new Blob([new Blob])) instanceof window.Blob"); | |
25 shouldBeTrue("(new Blob([new Blob([new Blob])])) instanceof window.Blob"); | |
26 | |
27 // Test some conversions to string in the parts array. | |
28 shouldBe("(new Blob([12])).size", "2"); | |
29 shouldBe("(new Blob([[]])).size", "0"); // [].toString() is the empty st ring | |
30 shouldBe("(new Blob([{}])).size", "15");; // {}.toString() is the string " [object Object]" | |
31 shouldBe("(new Blob([document])).size", "21"); // document.toString() is the st ring "[object HTMLDocument]" | |
32 | |
33 var toStringingObj = { toString: function() { return "A string"; } }; | |
34 shouldBe("(new Blob([toStringingObj])).size", "8"); | |
35 | |
36 var throwingObj = { toString: function() { throw "Error"; } }; | |
37 shouldThrow("new Blob([throwingObj])", "'Error'"); | |
38 | |
39 // Test some invalid property bags | |
40 shouldBeTrue("(new Blob([], {unknownKey:'value'})) instanceof window.Blob"); // Ignore invalid keys | |
41 shouldThrow("new Blob([], {endings:'illegalValue'})", "'TypeError: Failed to con struct \\'Blob\\': The \"endings\" property must be either \"transparent\" or \" native\".'"); | |
42 shouldThrow("new Blob([], {endings:throwingObj})", "'Error'"); | |
43 shouldThrow("new Blob([], {type:throwingObj})", "'Error'"); | |
44 shouldThrow("new Blob([], {type:'hello\u00EE'})", "'SyntaxError: Failed to const ruct \\'Blob\\': The \"type\" property must consist of ASCII characters.'"); | |
45 | |
46 // Test that order of property bag evaluation is lexigraphical | |
47 var throwingObj1 = { toString: function() { throw "Error 1"; } }; | |
48 var throwingObj2 = { toString: function() { throw "Error 2"; } }; | |
49 shouldThrow("new Blob([], {endings:throwingObj1, type:throwingObj2})", "'Error 1 '"); | |
50 shouldThrow("new Blob([], {type:throwingObj2, endings:throwingObj1})", "'Error 1 '"); | |
51 shouldThrow("new Blob([], {type:throwingObj2, endings:'illegal'})", "'TypeError: Failed to construct \\'Blob\\': The \"endings\" property must be either \"trans parent\" or \"native\".'"); | |
52 | |
53 // Test various non-object literals being used as property bags | |
54 shouldThrow("(new Blob([], null)) instanceof window.Blob", "'TypeError: Failed t o construct \\'Blob\\': The 2nd argument is not of type Object.'"); | |
55 shouldThrow("(new Blob([], undefined)) instanceof window.Blob", "'TypeError: Fai led to construct \\'Blob\\': The 2nd argument is not of type Object.'"); | |
56 shouldThrow("(new Blob([], 123)) instanceof window.Blob", "'TypeError: Failed to construct \\'Blob\\': The 2nd argument is not of type Object.'"); | |
57 shouldThrow("(new Blob([], 123.4)) instanceof window.Blob", "'TypeError: Failed to construct \\'Blob\\': The 2nd argument is not of type Object.'"); | |
58 shouldThrow("(new Blob([], true)) instanceof window.Blob", "'TypeError: Failed t o construct \\'Blob\\': The 2nd argument is not of type Object.'"); | |
59 shouldThrow("(new Blob([], 'abc')) instanceof window.Blob", "'TypeError: Failed to construct \\'Blob\\': The 2nd argument is not of type Object.'"); | |
60 shouldBeTrue("(new Blob([], [])) instanceof window.Blob"); | |
61 shouldBeTrue("(new Blob([], /abc/)) instanceof window.Blob"); | |
62 shouldBeTrue("(new Blob([], function () {})) instanceof window.Blob"); | |
63 | |
64 // Test that the type/size is correctly added to the Blob | |
65 shouldBe("(new Blob([], {type:'text/html'})).type", "'text/html'"); | |
66 shouldBe("(new Blob([], {type:'text/html'})).size", "0"); | |
67 shouldBe("(new Blob([], {type:'text/plain;charset=UTF-8'})).type", "'text/plain; charset=utf-8'"); | |
68 | |
69 // Test the number of expected arguments in the Blob constructor. | |
70 shouldBe("window.Blob.length", "0"); | |
71 | |
72 // Test ArrayBufferView Parameters | |
73 shouldBe("new Blob([new DataView(new ArrayBuffer(100))]).size", "100"); | |
74 shouldBe("new Blob([new Uint8Array(100)]).size", "100"); | |
75 shouldBe("new Blob([new Uint8ClampedArray(100)]).size", "100"); | |
76 shouldBe("new Blob([new Uint16Array(100)]).size", "200"); | |
77 shouldBe("new Blob([new Uint32Array(100)]).size", "400"); | |
78 shouldBe("new Blob([new Int8Array(100)]).size", "100"); | |
79 shouldBe("new Blob([new Int16Array(100)]).size", "200"); | |
80 shouldBe("new Blob([new Int32Array(100)]).size", "400"); | |
81 shouldBe("new Blob([new Float32Array(100)]).size", "400"); | |
82 shouldBe("new Blob([new Float64Array(100)]).size", "800"); | |
83 shouldBe("new Blob([new Float64Array(100), new Int32Array(100), new Uint8Array(1 00), new DataView(new ArrayBuffer(100))]).size", "1400"); | |
84 shouldBe("new Blob([new Blob([new Int32Array(100)]), new Uint8Array(100), new Fl oat32Array(100), new DataView(new ArrayBuffer(100))]).size", "1000"); | |
85 | |
86 // Test ArrayBuffer Parameters | |
87 shouldBe("new Blob([(new DataView(new ArrayBuffer(100))).buffer]).size", "100"); | |
88 shouldBe("new Blob([(new Uint8Array(100)).buffer]).size", "100"); | |
89 shouldBe("new Blob([(new Uint8ClampedArray(100)).buffer]).size", "100"); | |
90 shouldBe("new Blob([(new Uint16Array(100)).buffer]).size", "200"); | |
91 shouldBe("new Blob([(new Uint32Array(100)).buffer]).size", "400"); | |
92 shouldBe("new Blob([(new Int8Array(100)).buffer]).size", "100"); | |
93 shouldBe("new Blob([(new Int16Array(100)).buffer]).size", "200"); | |
94 shouldBe("new Blob([(new Int32Array(100)).buffer]).size", "400"); | |
95 shouldBe("new Blob([(new Float32Array(100)).buffer]).size", "400"); | |
96 shouldBe("new Blob([(new Float64Array(100)).buffer]).size", "800"); | |
97 shouldBe("new Blob([(new Float64Array(100)).buffer, (new Int32Array(100)).buffer , (new Uint8Array(100)).buffer, (new DataView(new ArrayBuffer(100))).buffer]).si ze", "1400"); | |
98 shouldBe("new Blob([new Blob([(new Int32Array(100)).buffer]), (new Uint8Array(10 0)).buffer, (new Float32Array(100)).buffer, (new DataView(new ArrayBuffer(100))) .buffer]).size", "1000"); | |
99 | |
100 // Test passing blob parts in sequences. | |
101 shouldBeTrue("new Blob({length: 0}) instanceof window.Blob"); | |
102 shouldBe("new Blob({length: 0}).size", "0"); | |
103 shouldBe("new Blob({length: 1, 0: 'string'}).size", "6"); | |
104 shouldBe("new Blob({length: 2, 0: new Uint8Array(100), 1: new Int16Array(100)}). size", "300"); | |
105 shouldBe("new Blob({length: 1, 0: 'string'}, {type: 'text/html'}).type", "'text/ html'"); | |
106 shouldThrow("new Blob({length: 0}, {endings:'illegal'})", "'TypeError: Failed to construct \\'Blob\\': The \"endings\" property must be either \"transparent\" o r \"native\".'"); | |
107 </script> | |
OLD | NEW |