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

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

Issue 74213009: File constructor understands lastModified. (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Removed unnecessary branches for NaN. 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
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");
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
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 \"trans parent\" 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 chara cters.'");
72 shouldThrow("new File([], 'world.html', {lastModifiedDate: 'not a date'})", "'Ty peError: Failed to construct \\'File\\': The \"lastModifiedDate\" property must be a Date instance.'");
73 shouldThrow("new File([], 'world.html', {lastModifiedDate: null})", "'TypeError: Failed to construct \\'File\\': The \"lastModifiedDate\" property must be a Dat e instance.'");
74 shouldThrow("new File([], 'world.html', {lastModifiedDate: Date.now()})", "'Type Error: Failed to construct \\'File\\': The \"lastModifiedDate\" property must be a Date instance.'");
72 75
73 // Test various non-object literals being used as property bags. 76 // 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.'") ; 77 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.'"); 78 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.'"); 79 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.'" ); 80 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.'") ; 81 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.'" ); 82 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"); 83 shouldBeTrue("(new File([], 'world.html', [])) instanceof window.File");
81 shouldBeTrue("(new File([], 'world.html', /abc/)) instanceof window.File"); 84 shouldBeTrue("(new File([], 'world.html', /abc/)) instanceof window.File");
82 shouldBeTrue("(new File([], 'world.html', function () {})) instanceof window.Fil e"); 85 shouldBeTrue("(new File([], 'world.html', function () {})) instanceof window.Fil e");
83 86
84 // Test that the name/type/size are correctly added to the File. 87 // Test that the name/type/size are correctly added to the File.
85 shouldBe("(new File([], 'world.html', {type:'text/html'})).name", "'world.html'" ); 88 shouldBe("(new File([], 'world.html', {type:'text/html'})).name", "'world.html'" );
86 shouldBe("(new File([], 'world.html', {type:'text/html'})).type", "'text/html'") ; 89 shouldBe("(new File([], 'world.html', {type:'text/html'})).type", "'text/html'") ;
87 shouldBe("(new File([], 'world.html', {type:'text/html'})).size", "0"); 90 shouldBe("(new File([], 'world.html', {type:'text/html'})).size", "0");
88 shouldBe("(new File([], 'world.html', {type:'text/plain;charset=UTF-8'})).type", "'text/plain;charset=utf-8'"); 91 shouldBe("(new File([], 'world.html', {type:'text/plain;charset=UTF-8'})).type", "'text/plain;charset=utf-8'");
89 92
93 // Test that the lastModificationDate is correctly added to the File.
94 var aDate = new Date(441532800000);
95 shouldBeTrue("(new File([], 'world.html', {lastModifiedDate: aDate})).lastModifi edDate instanceof Date");
96 shouldBe("(new File([], 'world.html', {lastModifiedDate: aDate})).lastModifiedDa te.valueOf()", "aDate.valueOf()");
97 shouldBeTrue("(new File([], 'world.html', {lastModifiedDate: new Date(NaN)})).la stModifiedDate instanceof Date");
98 shouldBeNaN("(new File([], 'world.html', {lastModifiedDate: new Date(NaN)})).las tModifiedDate.valueOf()");
99 // Unless specified, lastModifiedDate should default to now.
100 shouldBeTrue("(new File([], 'world.html')).lastModifiedDate instanceof Date");
101 shouldBeTrue("Math.abs(Date.now() - (new File([], 'world.html')).lastModifiedDat e) <= 1000");
kinuko 2013/11/18 12:21:43 Feels slightly sketchy, can this be like: 1. Date.
pwnall-personal 2013/11/18 12:48:57 Done. Is the DST robustness overkill?
102
90 // Test the number of expected arguments in the File constructor. 103 // Test the number of expected arguments in the File constructor.
91 shouldBe("window.File.length", "2"); 104 shouldBe("window.File.length", "2");
92 105
93 // Test ArrayBufferView parameters. 106 // Test ArrayBufferView parameters.
94 shouldBe("new File([new DataView(new ArrayBuffer(100))], 'world.html').size", "1 00"); 107 shouldBe("new File([new DataView(new ArrayBuffer(100))], 'world.html').size", "1 00");
95 shouldBe("new File([new Uint8Array(100)], 'world.html').size", "100"); 108 shouldBe("new File([new Uint8Array(100)], 'world.html').size", "100");
96 shouldBe("new File([new Uint8ClampedArray(100)], 'world.html').size", "100"); 109 shouldBe("new File([new Uint8ClampedArray(100)], 'world.html').size", "100");
97 shouldBe("new File([new Uint16Array(100)], 'world.html').size", "200"); 110 shouldBe("new File([new Uint16Array(100)], 'world.html').size", "200");
98 shouldBe("new File([new Uint32Array(100)], 'world.html').size", "400"); 111 shouldBe("new File([new Uint32Array(100)], 'world.html').size", "400");
99 shouldBe("new File([new Int8Array(100)], 'world.html').size", "100"); 112 shouldBe("new File([new Int8Array(100)], 'world.html').size", "100");
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
137 Object.defineProperty(throwingSequence, "1", { 150 Object.defineProperty(throwingSequence, "1", {
138 get: function() { throw new Error("Misbehaving property"); }, 151 get: function() { throw new Error("Misbehaving property"); },
139 enumerable: true, configurable: true 152 enumerable: true, configurable: true
140 }); 153 });
141 Object.defineProperty(throwingSequence, "2", { 154 Object.defineProperty(throwingSequence, "2", {
142 get: function() { throw new Error("This should not be thrown"); }, 155 get: function() { throw new Error("This should not be thrown"); },
143 enumerable: true, configurable: true 156 enumerable: true, configurable: true
144 }); 157 });
145 shouldThrow("new File(throwingSequence, 'world.txt')", "'Error: Misbehaving prop erty'"); 158 shouldThrow("new File(throwingSequence, 'world.txt')", "'Error: Misbehaving prop erty'");
146 </script> 159 </script>
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698