OLD | NEW |
1 <!DOCTYPE html> | 1 <!DOCTYPE html> |
2 | 2 |
3 <script src="../../resources/js-test.js"></script> | 3 <script src="../../resources/js-test.js"></script> |
4 <script> | 4 <script> |
5 description("Test the Blob constructor."); | 5 description("Test the Blob constructor."); |
6 var jsTestIsAsync = true; | 6 var jsTestIsAsync = true; |
7 | 7 |
8 // Test the different ways you can construct a Blob. | 8 // Test the different ways you can construct a Blob. |
9 shouldBeTrue("(new Blob()) instanceof window.Blob"); | 9 shouldBeTrue("(new Blob()) instanceof window.Blob"); |
10 shouldBeTrue("(new Blob(undefined)) instanceof window.Blob"); | 10 shouldBeTrue("(new Blob(undefined)) instanceof window.Blob"); |
11 shouldBeTrue("(new Blob([])) instanceof window.Blob"); | 11 shouldBeTrue("(new Blob([])) instanceof window.Blob"); |
12 shouldBeTrue("(new Blob(['hello'])) instanceof window.Blob"); | 12 shouldBeTrue("(new Blob(['hello'])) instanceof window.Blob"); |
13 shouldBeTrue("(new Blob(['hello'], {})) instanceof window.Blob"); | 13 shouldBeTrue("(new Blob(['hello'], {})) instanceof window.Blob"); |
14 shouldBeTrue("(new Blob(['hello'], {type:'text/html'})) instanceof window.Blob")
; | 14 shouldBeTrue("(new Blob(['hello'], {type:'text/html'})) instanceof window.Blob")
; |
15 shouldBeTrue("(new Blob(['hello'], {type:'text/html', endings:'native'})) instan
ceof window.Blob"); | 15 shouldBeTrue("(new Blob(['hello'], {type:'text/html', endings:'native'})) instan
ceof window.Blob"); |
16 shouldBeTrue("(new Blob(['hello'], {type:'text/html', endings:'transparent'})) i
nstanceof window.Blob"); | 16 shouldBeTrue("(new Blob(['hello'], {type:'text/html', endings:'transparent'})) i
nstanceof window.Blob"); |
17 | 17 |
18 // Test default sizes/types. | 18 // Test default sizes/types. |
19 shouldBe("(new Blob()).size", "0"); | 19 shouldBe("(new Blob()).size", "0"); |
20 shouldBe("(new Blob(undefined)).size", "0"); | 20 shouldBe("(new Blob(undefined)).size", "0"); |
21 shouldBeEqualToString("(new Blob()).type", ""); | 21 shouldBeEqualToString("(new Blob()).type", ""); |
22 shouldBeEqualToString("(new Blob(undefined)).type", ""); | 22 shouldBeEqualToString("(new Blob(undefined)).type", ""); |
23 | 23 |
24 // Test invalid blob parts. | 24 // Test invalid blob parts. |
25 shouldThrow("new Blob('hello')", '"TypeError: Failed to construct \'Blob\': The
1st argument is neither an array, nor does it have indexed properties."'); | 25 shouldThrow("new Blob('hello')", '"TypeError: Failed to construct \'Blob\': The
provided value cannot be converted to a sequence."'); |
26 shouldThrow("new Blob(0)", '"TypeError: Failed to construct \'Blob\': The 1st ar
gument is neither an array, nor does it have indexed properties."'); | 26 shouldThrow("new Blob(0)", '"TypeError: Failed to construct \'Blob\': The provid
ed value cannot be converted to a sequence."'); |
27 shouldThrow("new Blob(null)", '"TypeError: Failed to construct \'Blob\': The 1st
argument is neither an array, nor does it have indexed properties."'); | 27 shouldThrow("new Blob(null)", '"TypeError: Failed to construct \'Blob\': The pro
vided value cannot be converted to a sequence."'); |
28 | 28 |
29 // Test valid blob parts. | 29 // Test valid blob parts. |
30 shouldBeTrue("(new Blob([])) instanceof window.Blob"); | 30 shouldBeTrue("(new Blob([])) instanceof window.Blob"); |
31 shouldBeTrue("(new Blob(['stringPrimitive'])) instanceof window.Blob"); | 31 shouldBeTrue("(new Blob(['stringPrimitive'])) instanceof window.Blob"); |
32 shouldBeTrue("(new Blob([String('stringObject')])) instanceof window.Blob"); | 32 shouldBeTrue("(new Blob([String('stringObject')])) instanceof window.Blob"); |
33 shouldBeTrue("(new Blob([new Blob])) instanceof window.Blob"); | 33 shouldBeTrue("(new Blob([new Blob])) instanceof window.Blob"); |
34 shouldBeTrue("(new Blob([new Blob([new Blob])])) instanceof window.Blob"); | 34 shouldBeTrue("(new Blob([new Blob([new Blob])])) instanceof window.Blob"); |
35 | 35 |
36 // Test some conversions to string in the parts array. | 36 // Test some conversions to string in the parts array. |
37 shouldBe("(new Blob([12])).size", "2"); | 37 shouldBe("(new Blob([12])).size", "2"); |
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
121 shouldBe("new Blob([(new Float32Array(100)).buffer]).size", "400"); | 121 shouldBe("new Blob([(new Float32Array(100)).buffer]).size", "400"); |
122 shouldBe("new Blob([(new Float64Array(100)).buffer]).size", "800"); | 122 shouldBe("new Blob([(new Float64Array(100)).buffer]).size", "800"); |
123 shouldBe("new Blob([(new Float64Array(100)).buffer, (new Int32Array(100)).buffer
, (new Uint8Array(100)).buffer, (new DataView(new ArrayBuffer(100))).buffer]).si
ze", "1400"); | 123 shouldBe("new Blob([(new Float64Array(100)).buffer, (new Int32Array(100)).buffer
, (new Uint8Array(100)).buffer, (new DataView(new ArrayBuffer(100))).buffer]).si
ze", "1400"); |
124 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"); | 124 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"); |
125 | 125 |
126 if (window.SharedArrayBuffer) { | 126 if (window.SharedArrayBuffer) { |
127 // Test SharedArrayBuffer parameters. | 127 // Test SharedArrayBuffer parameters. |
128 shouldThrow("new Blob([new Uint8Array(new SharedArrayBuffer(4))])", '"TypeErro
r: Failed to construct \'Blob\': The provided ArrayBufferView value must not be
shared."'); | 128 shouldThrow("new Blob([new Uint8Array(new SharedArrayBuffer(4))])", '"TypeErro
r: Failed to construct \'Blob\': The provided ArrayBufferView value must not be
shared."'); |
129 } | 129 } |
130 | 130 |
131 // Test passing blob parts in objects with indexed properties. | 131 // Custom iterators, converted via the bindings code to sequence<T>. |
132 // (This depends on the bindings code handling of sequence<T>) | 132 function createIterable(iterations) { |
133 shouldBe("new Blob({length: 0}).size", "0"); | 133 return { |
134 shouldBe("new Blob({length: 1, 0: 'string'}).size", "6"); | 134 [Symbol.iterator]() { |
| 135 var i = 0; |
| 136 return {next: () => iterations[i++]}; |
| 137 }, |
| 138 }; |
| 139 } |
| 140 shouldBe("new Blob(createIterable([{done:true}])).size", "0"); |
| 141 shouldBe("new Blob(createIterable([{done:false, value:'string'},{done:true}])).s
ize", "6"); |
135 | 142 |
136 testNormalization(); | 143 testNormalization(); |
137 | 144 |
138 function testNormalization() { | 145 function testNormalization() { |
139 // Test that strings are not NFC normalized | 146 // Test that strings are not NFC normalized |
140 OMICRON_WITH_OXIA = '\u1F79'; // NFC normalized to U+3CC | 147 OMICRON_WITH_OXIA = '\u1F79'; // NFC normalized to U+3CC |
141 shouldBe("OMICRON_WITH_OXIA.charCodeAt(0)", "0x1F79"); | 148 shouldBe("OMICRON_WITH_OXIA.charCodeAt(0)", "0x1F79"); |
142 reader = new FileReader(); | 149 reader = new FileReader(); |
143 reader.readAsText(new Blob([OMICRON_WITH_OXIA])); | 150 reader.readAsText(new Blob([OMICRON_WITH_OXIA])); |
144 reader.onload = function() { | 151 reader.onload = function() { |
145 shouldBe("reader.result.charCodeAt(0)", "0x1F79"); | 152 shouldBe("reader.result.charCodeAt(0)", "0x1F79"); |
146 testEncodingReplacements(); | 153 testEncodingReplacements(); |
147 }; | 154 }; |
148 } | 155 } |
149 | 156 |
150 function testEncodingReplacements() { | 157 function testEncodingReplacements() { |
151 // Test that invalid UTF-16 code units are replaced. | 158 // Test that invalid UTF-16 code units are replaced. |
152 CONTAINS_UNPAIRED_SURROGATES = 'abc\uDC00def\uD800ghi'; | 159 CONTAINS_UNPAIRED_SURROGATES = 'abc\uDC00def\uD800ghi'; |
153 shouldBe("CONTAINS_UNPAIRED_SURROGATES.charCodeAt(3)", "0xDC00"); | 160 shouldBe("CONTAINS_UNPAIRED_SURROGATES.charCodeAt(3)", "0xDC00"); |
154 shouldBe("CONTAINS_UNPAIRED_SURROGATES.charCodeAt(7)", "0xD800"); | 161 shouldBe("CONTAINS_UNPAIRED_SURROGATES.charCodeAt(7)", "0xD800"); |
155 reader = new FileReader(); | 162 reader = new FileReader(); |
156 reader.readAsText(new Blob([CONTAINS_UNPAIRED_SURROGATES])); | 163 reader.readAsText(new Blob([CONTAINS_UNPAIRED_SURROGATES])); |
157 reader.onload = function() { | 164 reader.onload = function() { |
158 shouldBe("reader.result.charCodeAt(3)", "0xFFFD"); | 165 shouldBe("reader.result.charCodeAt(3)", "0xFFFD"); |
159 shouldBe("reader.result.charCodeAt(7)", "0xFFFD"); | 166 shouldBe("reader.result.charCodeAt(7)", "0xFFFD"); |
160 finishJSTest(); | 167 finishJSTest(); |
161 }; | 168 }; |
162 } | 169 } |
163 | 170 |
164 </script> | 171 </script> |
OLD | NEW |