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

Side by Side Diff: LayoutTests/fast/files/file-constructor.html

Issue 111373003: Migrate bindings constructors to the new ExceptionState model. (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Ugh. Created 7 years 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 | Annotate | Revision Log
OLDNEW
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: File constructor requires at least two arguments'"); 19 shouldThrow("(new File())", '"TypeError: Failed to construct \'File\': 2 argumen ts required, but only 0 present."');
20 shouldThrow("(new File([]))", "'TypeError: File constructor requires at least tw o arguments'"); 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 blob parts. 28 // Test invalid blob 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 1st argument is neither an array, nor does it have indexed propert ies."');
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 1st argument is neither an array, nor does it have indexed properties."' );
(...skipping 27 matching lines...) Expand all
58 shouldBe("(new File([], null)).name", "'null'"); 58 shouldBe("(new File([], null)).name", "'null'");
59 shouldBe("(new File([], 12)).name", "'12'"); 59 shouldBe("(new File([], 12)).name", "'12'");
60 shouldBe("(new File([], '')).name", "''"); 60 shouldBe("(new File([], '')).name", "''");
61 shouldBe("(new File([], {})).name", "'[object Object]'"); 61 shouldBe("(new File([], {})).name", "'[object Object]'");
62 shouldBe("(new File([], document)).name", "'[object HTMLDocument]'"); 62 shouldBe("(new File([], document)).name", "'[object HTMLDocument]'");
63 shouldBe("(new File([], toStringingObj)).name", "'A string'"); 63 shouldBe("(new File([], toStringingObj)).name", "'A string'");
64 shouldThrow("(new File([], throwingObj)).name", "'Error'"); 64 shouldThrow("(new File([], throwingObj)).name", "'Error'");
65 65
66 // Test some invalid property bags. 66 // Test some invalid property bags.
67 shouldBeTrue("(new File([], 'world.html', {unknownKey:'value'})) instanceof wind ow.File"); // Ignore invalid keys 67 shouldBeTrue("(new File([], 'world.html', {unknownKey:'value'})) instanceof wind ow.File"); // Ignore invalid keys
68 shouldThrow("new File([], 'world.html', {endings:'illegalValue'})", "'TypeError: Failed to construct \\'File\\': The \"endings\" property must be either \"trans parent\" or \"native\".'"); 68 shouldThrow("new File([], 'world.html', {endings:'illegalValue'})", "'TypeError: Failed to construct \\'File\\': The \\'endings\\' property must be either \\'tr ansparent\\' or \\'native\\'.'");
69 shouldThrow("new File([], 'world.html', {endings:throwingObj})", "'Error'"); 69 shouldThrow("new File([], 'world.html', {endings:throwingObj})", "'Error'");
70 shouldThrow("new File([], 'world.html', {type:throwingObj})", "'Error'"); 70 shouldThrow("new File([], 'world.html', {type:throwingObj})", "'Error'");
71 shouldThrow("new File([], 'world.html', {type:'hello\u00EE'})", "'SyntaxError: F ailed to construct \\'File\\': The \"type\" property must consist of ASCII chara cters.'"); 71 shouldThrow("new File([], 'world.html', {type:'hello\u00EE'})", "'SyntaxError: F ailed to construct \\'File\\': The \\'type\\' property must consist of ASCII cha racters.'");
72 72
73 // Test various non-object literals being used as property bags. 73 // Test various non-object literals being used as property bags.
74 shouldThrow("(new File([], 'world.html', null)) instanceof window.File", "'TypeE rror: Failed to construct \\'File\\': The 3rd argument is not of type Object.'") ; 74 shouldThrow("(new File([], 'world.html', null)) instanceof window.File", "'TypeE rror: Failed to construct \\'File\\': The 3rd argument is not of type Object.'") ;
75 shouldThrow("(new File([], 'world.html', undefined)) instanceof window.File", "' TypeError: Failed to construct \\'File\\': The 3rd argument is not of type Objec t.'"); 75 shouldThrow("(new File([], 'world.html', undefined)) instanceof window.File", "' TypeError: Failed to construct \\'File\\': The 3rd argument is not of type Objec t.'");
76 shouldThrow("(new File([], 'world.html', 123)) instanceof window.File", "'TypeEr ror: Failed to construct \\'File\\': The 3rd argument is not of type Object.'"); 76 shouldThrow("(new File([], 'world.html', 123)) instanceof window.File", "'TypeEr ror: Failed to construct \\'File\\': The 3rd argument is not of type Object.'");
77 shouldThrow("(new File([], 'world.html', 123.4)) instanceof window.File", "'Type Error: Failed to construct \\'File\\': The 3rd argument is not of type Object.'" ); 77 shouldThrow("(new File([], 'world.html', 123.4)) instanceof window.File", "'Type Error: Failed to construct \\'File\\': The 3rd argument is not of type Object.'" );
78 shouldThrow("(new File([], 'world.html', true)) instanceof window.File", "'TypeE rror: Failed to construct \\'File\\': The 3rd argument is not of type Object.'") ; 78 shouldThrow("(new File([], 'world.html', true)) instanceof window.File", "'TypeE rror: Failed to construct \\'File\\': The 3rd argument is not of type Object.'") ;
79 shouldThrow("(new File([], 'world.html', 'abc')) instanceof window.File", "'Type Error: Failed to construct \\'File\\': The 3rd argument is not of type Object.'" ); 79 shouldThrow("(new File([], 'world.html', 'abc')) instanceof window.File", "'Type Error: Failed to construct \\'File\\': The 3rd argument is not of type Object.'" );
80 shouldBeTrue("(new File([], 'world.html', [])) instanceof window.File"); 80 shouldBeTrue("(new File([], 'world.html', [])) instanceof window.File");
81 shouldBeTrue("(new File([], 'world.html', /abc/)) instanceof window.File"); 81 shouldBeTrue("(new File([], 'world.html', /abc/)) instanceof window.File");
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after
137 // Test building Blobs with ArrayBuffer / ArrayBufferView parts enclosed in file s. 137 // Test building Blobs with ArrayBuffer / ArrayBufferView parts enclosed in file s.
138 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"); 138 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");
139 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"); 139 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");
140 140
141 // Test passing blob parts in sequences. 141 // Test passing blob parts in sequences.
142 shouldBeTrue("new File({length: 0}, 'world.txt') instanceof window.File"); 142 shouldBeTrue("new File({length: 0}, 'world.txt') instanceof window.File");
143 shouldBe("new File({length: 0}, 'world.txt').size", "0"); 143 shouldBe("new File({length: 0}, 'world.txt').size", "0");
144 shouldBe("new File({length: 1, 0: 'string'}, 'world.txt').size", "6"); 144 shouldBe("new File({length: 1, 0: 'string'}, 'world.txt').size", "6");
145 shouldBe("new File({length: 2, 0: new Uint8Array(100), 1: new Int16Array(100)}, 'world.txt').size", "300"); 145 shouldBe("new File({length: 2, 0: new Uint8Array(100), 1: new Int16Array(100)}, 'world.txt').size", "300");
146 shouldBe("new File({length: 1, 0: 'string'}, 'world.txt', {type: 'text/html'}).t ype", "'text/html'"); 146 shouldBe("new File({length: 1, 0: 'string'}, 'world.txt', {type: 'text/html'}).t ype", "'text/html'");
147 shouldThrow("new File({length: 0}, 'world.txt', {endings:'illegal'})", "'TypeErr or: Failed to construct \\'File\\': The \"endings\" property must be either \"tr ansparent\" or \"native\".'"); 147 shouldThrow("new File({length: 0}, 'world.txt', {endings:'illegal'})", "'TypeErr or: Failed to construct \\'File\\': The \\'endings\\' property must be either \\ 'transparent\\' or \\'native\\'.'");
148 148
149 // Test passing blog parts in a sequence-like object that throws on property acc ess. 149 // Test passing blog parts in a sequence-like object that throws on property acc ess.
150 var throwingSequence = {length: 4, 0: 'hello', 3: 'world'}; 150 var throwingSequence = {length: 4, 0: 'hello', 3: 'world'};
151 Object.defineProperty(throwingSequence, "1", { 151 Object.defineProperty(throwingSequence, "1", {
152 get: function() { throw new Error("Misbehaving property"); }, 152 get: function() { throw new Error("Misbehaving property"); },
153 enumerable: true, configurable: true 153 enumerable: true, configurable: true
154 }); 154 });
155 Object.defineProperty(throwingSequence, "2", { 155 Object.defineProperty(throwingSequence, "2", {
156 get: function() { throw new Error("This should not be thrown"); }, 156 get: function() { throw new Error("This should not be thrown"); },
157 enumerable: true, configurable: true 157 enumerable: true, configurable: true
158 }); 158 });
159 shouldThrow("new File(throwingSequence, 'world.txt')", "'Error: Misbehaving prop erty'"); 159 shouldThrow("new File(throwingSequence, 'world.txt')", "'Error: Misbehaving prop erty'");
160 </script> 160 </script>
OLDNEW
« no previous file with comments | « LayoutTests/fast/files/blob-constructor-expected.txt ('k') | LayoutTests/fast/files/file-constructor-expected.txt » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698