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"); |
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
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"); |
82 shouldBeTrue("(new File([], 'world.html', function () {})) instanceof window.Fil
e"); | 82 shouldBeTrue("(new File([], 'world.html', function () {})) instanceof window.Fil
e"); |
83 | 83 |
84 // Test that the name/type/size are correctly added to the File. | 84 // Test that the name/type/size are correctly added to the File. |
85 shouldBe("(new File([], 'world.html', {type:'text/html'})).name", "'world.html'"
); | 85 shouldBe("(new File([], 'world.html', {type:'text/html'})).name", "'world.html'"
); |
86 shouldBe("(new File([], 'world.html', {type:'text/html'})).type", "'text/html'")
; | 86 shouldBe("(new File([], 'world.html', {type:'text/html'})).type", "'text/html'")
; |
87 shouldBe("(new File([], 'world.html', {type:'text/html'})).size", "0"); | 87 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'"); | 88 shouldBe("(new File([], 'world.html', {type:'text/plain;charset=UTF-8'})).type",
"'text/plain;charset=utf-8'"); |
89 | 89 |
| 90 // Test that the lastModified is correctly added to the File. |
| 91 var aDate = new Date(441532800000); |
| 92 shouldBe("(new File([], 'world.html', {lastModified: 441532800000})).lastModifie
d", "441532800000"); |
| 93 // Unless specified, lastModified should default to now. |
| 94 var startTime = Date.now(); |
| 95 var fileTime = (new File([], 'world.html')).lastModified; |
| 96 var endTime = Date.now(); |
| 97 // FIXME: these checks will fail if time goes backwards, e.g. NTP updates. We sh
ould have a generic bullet-proof method for comparing against Date.now(). http:/
/crbug.com/320686 |
| 98 shouldBeTrue("startTime <= fileTime"); |
| 99 shouldBeTrue("fileTime <= endTime"); |
| 100 // Test that Date instances are implicitly converted to numbers. |
| 101 shouldBe("(new File([], 'world.html', {lastModified: new Date(441532800000)})).l
astModified", "441532800000"); |
| 102 |
| 103 // Test the deprecated attribute lastModifiedDate. |
| 104 shouldBeTrue("(new File([], 'world.html', {lastModified: 441532800000})).lastMod
ifiedDate instanceof Date"); |
| 105 shouldBe("(new File([], 'world.html', {lastModified: 441532800000})).lastModifie
dDate.valueOf()", "441532800000"); |
| 106 |
90 // Test the number of expected arguments in the File constructor. | 107 // Test the number of expected arguments in the File constructor. |
91 shouldBe("window.File.length", "2"); | 108 shouldBe("window.File.length", "2"); |
92 | 109 |
93 // Test ArrayBufferView parameters. | 110 // Test ArrayBufferView parameters. |
94 shouldBe("new File([new DataView(new ArrayBuffer(100))], 'world.html').size", "1
00"); | 111 shouldBe("new File([new DataView(new ArrayBuffer(100))], 'world.html').size", "1
00"); |
95 shouldBe("new File([new Uint8Array(100)], 'world.html').size", "100"); | 112 shouldBe("new File([new Uint8Array(100)], 'world.html').size", "100"); |
96 shouldBe("new File([new Uint8ClampedArray(100)], 'world.html').size", "100"); | 113 shouldBe("new File([new Uint8ClampedArray(100)], 'world.html').size", "100"); |
97 shouldBe("new File([new Uint16Array(100)], 'world.html').size", "200"); | 114 shouldBe("new File([new Uint16Array(100)], 'world.html').size", "200"); |
98 shouldBe("new File([new Uint32Array(100)], 'world.html').size", "400"); | 115 shouldBe("new File([new Uint32Array(100)], 'world.html').size", "400"); |
99 shouldBe("new File([new Int8Array(100)], 'world.html').size", "100"); | 116 shouldBe("new File([new Int8Array(100)], 'world.html').size", "100"); |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
137 Object.defineProperty(throwingSequence, "1", { | 154 Object.defineProperty(throwingSequence, "1", { |
138 get: function() { throw new Error("Misbehaving property"); }, | 155 get: function() { throw new Error("Misbehaving property"); }, |
139 enumerable: true, configurable: true | 156 enumerable: true, configurable: true |
140 }); | 157 }); |
141 Object.defineProperty(throwingSequence, "2", { | 158 Object.defineProperty(throwingSequence, "2", { |
142 get: function() { throw new Error("This should not be thrown"); }, | 159 get: function() { throw new Error("This should not be thrown"); }, |
143 enumerable: true, configurable: true | 160 enumerable: true, configurable: true |
144 }); | 161 }); |
145 shouldThrow("new File(throwingSequence, 'world.txt')", "'Error: Misbehaving prop
erty'"); | 162 shouldThrow("new File(throwingSequence, 'world.txt')", "'Error: Misbehaving prop
erty'"); |
146 </script> | 163 </script> |
OLD | NEW |