Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(813)

Side by Side Diff: LayoutTests/fast/files/script-tests/file-constructor.js

Issue 57483002: Implement File constructor. (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Answered feedback, part 2. Created 7 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(Empty)
1 description("Test the File constructor.");
2
3 // Test the diffrent ways you can construct a File.
4 shouldBeTrue("(new File([], 'world.html')) instanceof window.File");
5 shouldBeTrue("(new File(['hello'], 'world.html')) instanceof window.File");
6 shouldBeTrue("(new File(['hello'], 'world.html', {})) instanceof window.File");
7 shouldBeTrue("(new File(['hello'], 'world.html', {type:'text/html'})) instanceof window.File");
8 shouldBeTrue("(new File(['hello'], 'world.html', {type:'text/html', endings:'nat ive'})) instanceof window.File");
9 shouldBeTrue("(new File(['hello'], 'world.html', {type:'text/html', endings:'tra nsparent'})) instanceof window.File");
10
11 // Test that File inherits from File.
12 shouldBeTrue("(new File([], 'world.html')) instanceof window.File")
13
14 // Verify that the file name argument is required.
15 shouldThrow("(new File())", "'TypeError: Constructor requires at least two argum ents'");
16
17 // Test valid file names.
18 shouldBeTrue("(new File([], null)) instanceof window.File");
19 shouldBeTrue("(new File([], 1)) instanceof window.File");
20 shouldBeTrue("(new File([], document)) instanceof window.File");
21
22 // Test invalid blob parts
23 shouldThrow("new File('hello', 'world.html')", "'TypeError: First argument of th e constructor is not of type Array'");
24 shouldThrow("new File(0, 'world.html')", "'TypeError: First argument of the cons tructor is not of type Array'");
25
26 // Test valid blob parts.
27 shouldBeTrue("(new File([], 'world.html')) instanceof window.File");
28 shouldBeTrue("(new File(['stringPrimitive'], 'world.html')) instanceof window.Fi le");
29 shouldBeTrue("(new File([String('stringObject')], 'world.html')) instanceof wind ow.File");
30 shouldBeTrue("(new File([new Blob], 'world.html')) instanceof window.File");
31 shouldBeTrue("(new File([new Blob([new Blob])], 'world.html')) instanceof window .File");
32
33 // Test File instances used as blob parts.
34 shouldBeTrue("(new Blob([new File([], 'world.txt')])) instanceof window.Blob");
35 shouldBeTrue("(new Blob([new Blob([new File([new Blob], 'world.txt')])])) instan ceof window.Blob");
36 shouldBeTrue("(new File([new File([], 'world.txt')], 'world.html')) instanceof w indow.File");
37 shouldBeTrue("(new File([new Blob([new File([new Blob], 'world.txt')]])], 'world .html')) instanceof window.File");
38
39 // Test some conversions to string in the parts array.
40 shouldBe("(new File([12], 'world.html')).size", "2");
41 shouldBe("(new File([[]], 'world.html')).size", "0"); // [].toString() i s the empty string
42 shouldBe("(new File([{}], 'world.html')).size", "15");; // {}.toString() i s the string "[object Object]"
43 shouldBe("(new File([document], 'world.html')).size", "21"); // document.toStri ng() is the string "[object HTMLDocument]"
44
45 var toStringingObj = { toString: function() { return "A string"; } };
46 shouldBe("(new File([toStringingObj], 'world.html')).size", "8");
47
48 var throwingObj = { toString: function() { throw "Error"; } };
49 shouldThrow("new File([throwingObj], 'world.html')", "'Error'");
50
51 // Test some conversions to string in the file name.
52 shouldBe("(new File([], null)).name", "'null'");
53 shouldBe("(new File([], 12)).name", "'12'");
54 shouldBe("(new File([], {})).name", "'[object Object]'");
55 shouldBe("(new File([], document)).name", "'[object HTMLDocument]'");
56 shouldBe("(new File([], toStringingObj)).name", "'A string'");
57 shouldThrow("(new File([], throwingObj)).name", "'Error'");
58
59 // Test some invalid property bags.
60 shouldBeTrue("(new File([], 'world.html', {unknownKey:'value'})) instanceof wind ow.File"); // Ignore invalid keys
61 shouldThrow("new File([], 'world.html', {endings:'illegalValue'})", "'TypeError: The endings property must be either \"transparent\" or \"native\"'");
62 shouldThrow("new File([], 'world.html', {endings:throwingObj})", "'Error'");
63 shouldThrow("new File([], 'world.html', {type:throwingObj})", "'Error'");
64 shouldThrow("new File([], 'world.html', {type:'hello\u00EE'})", "'SyntaxError: t ype must consist of ASCII characters'");
65
66 // Test various non-object literals being used as property bags.
67 shouldThrow("(new File([], 'world.html', null)) instanceof window.File", "'TypeE rror: Third argument of the constructor is not of type Object'");
68 shouldThrow("(new File([], 'world.html', undefined)) instanceof window.File", "' TypeError: Third argument of the constructor is not of type Object'");
69 shouldThrow("(new File([], 'world.html', 123)) instanceof window.File", "'TypeEr ror: Third argument of the constructor is not of type Object'");
70 shouldThrow("(new File([], 'world.html', 123.4)) instanceof window.File", "'Type Error: Third argument of the constructor is not of type Object'");
71 shouldThrow("(new File([], 'world.html', true)) instanceof window.File", "'TypeE rror: Third argument of the constructor is not of type Object'");
72 shouldThrow("(new File([], 'world.html', 'abc')) instanceof window.File", "'Type Error: Third argument of the constructor is not of type Object'");
73 shouldBeTrue("(new File([], 'world.html', [])) instanceof window.File");
74 shouldBeTrue("(new File([], 'world.html', /abc/)) instanceof window.File");
75 shouldBeTrue("(new File([], 'world.html', function () {})) instanceof window.Fil e");
76
77 // Test that the name/type/size are correctly added to the File.
78 shouldBe("(new File([], 'world.html', {type:'text/html'})).name", "'world.html'" );
79 shouldBe("(new File([], 'world.html', {type:'text/html'})).type", "'text/html'") ;
80 shouldBe("(new File([], 'world.html', {type:'text/html'})).size", "0");
81 shouldBe("(new File([], 'world.html', {type:'text/plain;charset=UTF-8'})).type", "'text/plain;charset=utf-8'");
82
83 // Test ArrayBufferView Parameters.
84 shouldBe("new File([new DataView(new ArrayBuffer(100))], 'world.html').size", "1 00");
85 shouldBe("new File([new Uint8Array(100)], 'world.html').size", "100");
86 shouldBe("new File([new Uint8ClampedArray(100)], 'world.html').size", "100");
87 shouldBe("new File([new Uint16Array(100)], 'world.html').size", "200");
88 shouldBe("new File([new Uint32Array(100)], 'world.html').size", "400");
89 shouldBe("new File([new Int8Array(100)], 'world.html').size", "100");
90 shouldBe("new File([new Int16Array(100)], 'world.html').size", "200");
91 shouldBe("new File([new Int32Array(100)], 'world.html').size", "400");
92 shouldBe("new File([new Float32Array(100)], 'world.html').size", "400");
93 shouldBe("new File([new Float64Array(100)], 'world.html').size", "800");
94 shouldBe("new File([new Float64Array(100), new Int32Array(100), new Uint8Array(1 00), new DataView(new ArrayBuffer(100))], 'world.html').size", "1400");
95 shouldBe("new File([new Blob([new Int32Array(100)]), new Uint8Array(100), new Fl oat32Array(100), new DataView(new ArrayBuffer(100))], 'world.html').size", "1000 ");
96 shouldBe("new File([new Blob([new Int32Array(100)]), new File([new Uint16Array(1 00)], 'world.txt'), new Uint8Array(100), new Float32Array(100), new DataView(new ArrayBuffer(100))], 'world.html').size", "1200");
97
98 // Test ArrayBuffer Parameters.
99 shouldBe("new File([(new DataView(new ArrayBuffer(100))).buffer], 'world.html'). size", "100");
100 shouldBe("new File([(new Uint8Array(100)).buffer], 'world.html').size", "100");
101 shouldBe("new File([(new Uint8ClampedArray(100)).buffer], 'world.html').size", " 100");
102 shouldBe("new File([(new Uint16Array(100)).buffer], 'world.html').size", "200");
103 shouldBe("new File([(new Uint32Array(100)).buffer], 'world.html').size", "400");
104 shouldBe("new File([(new Int8Array(100)).buffer], 'world.html').size", "100");
105 shouldBe("new File([(new Int16Array(100)).buffer], 'world.html').size", "200");
106 shouldBe("new File([(new Int32Array(100)).buffer], 'world.html').size", "400");
107 shouldBe("new File([(new Float32Array(100)).buffer], 'world.html').size", "400") ;
108 shouldBe("new File([(new Float64Array(100)).buffer], 'world.html').size", "800") ;
109 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");
110 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");
111 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");
112
113 // Test building Blobs with ArrayBuffer / ArrayBufferView parts enclosed in file s.
114 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");
115 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");
116
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698