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

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: 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'})", "'Sy ntaxError: Failed to construct \\'File\\': The \"lastModifiedDate\" property mus t be a Date instance.'");
73 shouldThrow("new File([], 'world.html', {lastModifiedDate: null})", "'SyntaxErro r: Failed to construct \\'File\\': The \"lastModifiedDate\" property must be a D ate instance.'");
72 74
73 // Test various non-object literals being used as property bags. 75 // 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.'") ; 76 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.'"); 77 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.'"); 78 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.'" ); 79 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.'") ; 80 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.'" ); 81 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"); 82 shouldBeTrue("(new File([], 'world.html', [])) instanceof window.File");
81 shouldBeTrue("(new File([], 'world.html', /abc/)) instanceof window.File"); 83 shouldBeTrue("(new File([], 'world.html', /abc/)) instanceof window.File");
82 shouldBeTrue("(new File([], 'world.html', function () {})) instanceof window.Fil e"); 84 shouldBeTrue("(new File([], 'world.html', function () {})) instanceof window.Fil e");
83 85
84 // Test that the name/type/size are correctly added to the File. 86 // Test that the name/type/size are correctly added to the File.
85 shouldBe("(new File([], 'world.html', {type:'text/html'})).name", "'world.html'" ); 87 shouldBe("(new File([], 'world.html', {type:'text/html'})).name", "'world.html'" );
86 shouldBe("(new File([], 'world.html', {type:'text/html'})).type", "'text/html'") ; 88 shouldBe("(new File([], 'world.html', {type:'text/html'})).type", "'text/html'") ;
87 shouldBe("(new File([], 'world.html', {type:'text/html'})).size", "0"); 89 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'"); 90 shouldBe("(new File([], 'world.html', {type:'text/plain;charset=UTF-8'})).type", "'text/plain;charset=utf-8'");
89 91
92 // Test that the lastModificationDate is correctly added to the File.
93 var aDate = new Date(441532800000);
94 shouldBeTrue("(new File([], 'world.html', {lastModifiedDate: aDate})).lastModifi edDate instanceof Date");
95 shouldBe("(new File([], 'world.html', {lastModifiedDate: aDate})).lastModifiedDa te.valueOf()", "aDate.valueOf()");
96 shouldBeTrue("(new File([], 'world.html', {lastModifiedDate: 441532800000})).las tModifiedDate instanceof Date");
97 shouldBe("(new File([], 'world.html', {lastModifiedDate: 441532800000})).lastMod ifiedDate.valueOf()", "aDate.valueOf()");
98 shouldBeTrue("Math.abs(Date.now() - (new File([], 'world.html')).lastModifiedDat e) <= 1000"); // Unless specified, lastModifiedDate should default to now.
99
90 // Test the number of expected arguments in the File constructor. 100 // Test the number of expected arguments in the File constructor.
91 shouldBe("window.File.length", "2"); 101 shouldBe("window.File.length", "2");
92 102
93 // Test ArrayBufferView parameters. 103 // Test ArrayBufferView parameters.
94 shouldBe("new File([new DataView(new ArrayBuffer(100))], 'world.html').size", "1 00"); 104 shouldBe("new File([new DataView(new ArrayBuffer(100))], 'world.html').size", "1 00");
95 shouldBe("new File([new Uint8Array(100)], 'world.html').size", "100"); 105 shouldBe("new File([new Uint8Array(100)], 'world.html').size", "100");
96 shouldBe("new File([new Uint8ClampedArray(100)], 'world.html').size", "100"); 106 shouldBe("new File([new Uint8ClampedArray(100)], 'world.html').size", "100");
97 shouldBe("new File([new Uint16Array(100)], 'world.html').size", "200"); 107 shouldBe("new File([new Uint16Array(100)], 'world.html').size", "200");
98 shouldBe("new File([new Uint32Array(100)], 'world.html').size", "400"); 108 shouldBe("new File([new Uint32Array(100)], 'world.html').size", "400");
99 shouldBe("new File([new Int8Array(100)], 'world.html').size", "100"); 109 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", { 147 Object.defineProperty(throwingSequence, "1", {
138 get: function() { throw new Error("Misbehaving property"); }, 148 get: function() { throw new Error("Misbehaving property"); },
139 enumerable: true, configurable: true 149 enumerable: true, configurable: true
140 }); 150 });
141 Object.defineProperty(throwingSequence, "2", { 151 Object.defineProperty(throwingSequence, "2", {
142 get: function() { throw new Error("This should not be thrown"); }, 152 get: function() { throw new Error("This should not be thrown"); },
143 enumerable: true, configurable: true 153 enumerable: true, configurable: true
144 }); 154 });
145 shouldThrow("new File(throwingSequence, 'world.txt')", "'Error: Misbehaving prop erty'"); 155 shouldThrow("new File(throwingSequence, 'world.txt')", "'Error: Misbehaving prop erty'");
146 </script> 156 </script>
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698