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 File constructor."); | 5 description("Test the File constructor."); |
6 | 6 |
7 // Test the different ways you can construct a File. | 7 // Test the different ways you can construct a File. |
8 shouldBeTrue("(new File([], 'world.html')) instanceof window.File"); | 8 shouldBeTrue("(new File([], 'world.html')) instanceof window.File"); |
9 shouldBeTrue("(new File(['hello'], 'world.html')) instanceof window.File"); | 9 shouldBeTrue("(new File(['hello'], 'world.html')) instanceof window.File"); |
10 shouldBeTrue("(new File(['hello'], 'world.html', {})) instanceof window.File"); | 10 shouldBeTrue("(new File(['hello'], 'world.html', {})) instanceof window.File"); |
11 shouldBeTrue("(new File(['hello'], 'world.html', {type:'text/html'})) instanceof
window.File"); | 11 shouldBeTrue("(new File(['hello'], 'world.html', {type:'text/html'})) instanceof
window.File"); |
12 shouldBeTrue("(new File(['hello'], 'world.html', {type:'text/html', endings:'nat
ive'})) instanceof window.File"); | 12 shouldBeTrue("(new File(['hello'], 'world.html', {type:'text/html', endings:'nat
ive'})) instanceof window.File"); |
13 shouldBeTrue("(new File(['hello'], 'world.html', {type:'text/html', endings:'tra
nsparent'})) instanceof window.File"); | 13 shouldBeTrue("(new File(['hello'], 'world.html', {type:'text/html', endings:'tra
nsparent'})) instanceof window.File"); |
14 | 14 |
15 // Test that File inherits from File. | 15 // Test that File inherits from File. |
16 shouldBeTrue("(new File([], 'world.html')) instanceof window.File") | 16 shouldBeTrue("(new File([], 'world.html')) instanceof window.File") |
17 | 17 |
18 // Verify that the file name argument is required. | 18 // Verify that the file name argument is required. |
19 shouldThrow("(new File())", '"TypeError: Failed to construct \'File\': 2 argumen
ts required, but only 0 present."'); | 19 shouldThrow("(new File())", '"TypeError: Failed to construct \'File\': 2 argumen
ts required, but only 0 present."'); |
20 shouldThrow("(new File([]))", '"TypeError: Failed to construct \'File\': 2 argum
ents required, but only 1 present."'); | 20 shouldThrow("(new File([]))", '"TypeError: Failed to construct \'File\': 2 argum
ents required, but only 1 present."'); |
21 | 21 |
22 // Test valid file names. | 22 // Test valid file names. |
23 shouldBeTrue("(new File([], null)) instanceof window.File"); | 23 shouldBeTrue("(new File([], null)) instanceof window.File"); |
24 shouldBeTrue("(new File([], 1)) instanceof window.File"); | 24 shouldBeTrue("(new File([], 1)) instanceof window.File"); |
25 shouldBeTrue("(new File([], '')) instanceof window.File"); | 25 shouldBeTrue("(new File([], '')) instanceof window.File"); |
26 shouldBeTrue("(new File([], document)) instanceof window.File"); | 26 shouldBeTrue("(new File([], document)) instanceof window.File"); |
27 | 27 |
28 // Test invalid file parts. | 28 // Test invalid file parts. |
29 shouldThrow("new File('hello', 'world.html')", '"TypeError: Failed to construct
\'File\': The 1st argument is neither an array, nor does it have indexed propert
ies."'); | 29 shouldThrow("new File('hello', 'world.html')", '"TypeError: Failed to construct
\'File\': The provided value cannot be converted to a sequence."'); |
30 shouldThrow("new File(0, 'world.html')", '"TypeError: Failed to construct \'File
\': The 1st argument is neither an array, nor does it have indexed properties."'
); | 30 shouldThrow("new File(0, 'world.html')", '"TypeError: Failed to construct \'File
\': The provided value cannot be converted to a sequence."'); |
31 shouldThrow("new File(null, 'world.html')", '"TypeError: Failed to construct \'F
ile\': The 1st argument is neither an array, nor does it have indexed properties
."'); | 31 shouldThrow("new File(null, 'world.html')", '"TypeError: Failed to construct \'F
ile\': The provided value cannot be converted to a sequence."'); |
32 | 32 |
33 // Test valid file parts. | 33 // Test valid file parts. |
34 shouldBeTrue("(new File([], 'world.html')) instanceof window.File"); | 34 shouldBeTrue("(new File([], 'world.html')) instanceof window.File"); |
35 shouldBeTrue("(new File(['stringPrimitive'], 'world.html')) instanceof window.Fi
le"); | 35 shouldBeTrue("(new File(['stringPrimitive'], 'world.html')) instanceof window.Fi
le"); |
36 shouldBeTrue("(new File([String('stringObject')], 'world.html')) instanceof wind
ow.File"); | 36 shouldBeTrue("(new File([String('stringObject')], 'world.html')) instanceof wind
ow.File"); |
37 shouldBeTrue("(new File([new Blob], 'world.html')) instanceof window.File"); | 37 shouldBeTrue("(new File([new Blob], 'world.html')) instanceof window.File"); |
38 shouldBeTrue("(new File([new Blob([new Blob])], 'world.html')) instanceof window
.File"); | 38 shouldBeTrue("(new File([new Blob([new Blob])], 'world.html')) instanceof window
.File"); |
39 | 39 |
40 // Test File instances used as blob parts. | 40 // Test File instances used as blob parts. |
41 shouldBeTrue("(new Blob([new File([], 'world.txt')])) instanceof window.Blob"); | 41 shouldBeTrue("(new Blob([new File([], 'world.txt')])) instanceof window.Blob"); |
(...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
144 shouldBe("new File([(new Float32Array(100)).buffer], 'world.html').size", "400")
; | 144 shouldBe("new File([(new Float32Array(100)).buffer], 'world.html').size", "400")
; |
145 shouldBe("new File([(new Float64Array(100)).buffer], 'world.html').size", "800")
; | 145 shouldBe("new File([(new Float64Array(100)).buffer], 'world.html').size", "800")
; |
146 shouldBe("new File([(new Float64Array(100)).buffer, (new Int32Array(100)).buffer
, (new Uint8Array(100)).buffer, (new DataView(new ArrayBuffer(100))).buffer], 'w
orld.html').size", "1400"); | 146 shouldBe("new File([(new Float64Array(100)).buffer, (new Int32Array(100)).buffer
, (new Uint8Array(100)).buffer, (new DataView(new ArrayBuffer(100))).buffer], 'w
orld.html').size", "1400"); |
147 shouldBe("new File([new Blob([(new Int32Array(100)).buffer]), (new Uint8Array(10
0)).buffer, (new Float32Array(100)).buffer, (new DataView(new ArrayBuffer(100)))
.buffer], 'world.html').size", "1000"); | 147 shouldBe("new File([new Blob([(new Int32Array(100)).buffer]), (new Uint8Array(10
0)).buffer, (new Float32Array(100)).buffer, (new DataView(new ArrayBuffer(100)))
.buffer], 'world.html').size", "1000"); |
148 shouldBe("new File([new Blob([(new Int32Array(100)).buffer]), new File([new Uint
16Array(100).buffer], 'world.txt'), (new Uint8Array(100)).buffer, (new Float32Ar
ray(100)).buffer, (new DataView(new ArrayBuffer(100))).buffer], 'world.html').si
ze", "1200"); | 148 shouldBe("new File([new Blob([(new Int32Array(100)).buffer]), new File([new Uint
16Array(100).buffer], 'world.txt'), (new Uint8Array(100)).buffer, (new Float32Ar
ray(100)).buffer, (new DataView(new ArrayBuffer(100))).buffer], 'world.html').si
ze", "1200"); |
149 | 149 |
150 // Test building Blobs with ArrayBuffer / ArrayBufferView parts enclosed in file
s. | 150 // Test building Blobs with ArrayBuffer / ArrayBufferView parts enclosed in file
s. |
151 shouldBe("new Blob([new Blob([new Int32Array(100)]), new File([new Uint16Array(1
00)], 'world.txt'), new Uint8Array(100), new Float32Array(100), new DataView(new
ArrayBuffer(100))]).size", "1200"); | 151 shouldBe("new Blob([new Blob([new Int32Array(100)]), new File([new Uint16Array(1
00)], 'world.txt'), new Uint8Array(100), new Float32Array(100), new DataView(new
ArrayBuffer(100))]).size", "1200"); |
152 shouldBe("new Blob([new Blob([(new Int32Array(100)).buffer]), new File([new Uint
16Array(100).buffer], 'world.txt'), (new Uint8Array(100)).buffer, (new Float32Ar
ray(100)).buffer, (new DataView(new ArrayBuffer(100))).buffer]).size", "1200"); | 152 shouldBe("new Blob([new Blob([(new Int32Array(100)).buffer]), new File([new Uint
16Array(100).buffer], 'world.txt'), (new Uint8Array(100)).buffer, (new Float32Ar
ray(100)).buffer, (new DataView(new ArrayBuffer(100))).buffer]).size", "1200"); |
153 | 153 |
154 // Test passing blob parts in objects with indexed properties. | 154 // Custom iterators, converted via the bindings code to sequence<T>. |
155 // (This depends on the bindings code handling of sequence<T>) | 155 function createIterable(iterations) { |
156 shouldBe("new File({length: 0}, 'world.txt').size", "0"); | 156 return { |
157 shouldBe("new File({length: 1, 0: 'string'}, 'world.txt').size", "6"); | 157 [Symbol.iterator]() { |
| 158 var i = 0; |
| 159 return {next: () => iterations[i++]}; |
| 160 }, |
| 161 }; |
| 162 } |
| 163 shouldBe("new File(createIterable([{done:true}]), 'world.txt').size", "0"); |
| 164 shouldBe("new File(createIterable([{done:false, value:'string'},{done:true}]), '
world.txt').size", "6"); |
158 </script> | 165 </script> |
OLD | NEW |