Chromium Code Reviews| 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 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 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 while (true) { | |
| 102 var startTime = Date.now(); | |
| 103 var fileTime = (new File([], 'world.html')).lastModifiedDate.valueOf(); | |
| 104 var endTime = Date.now(); | |
| 105 | |
| 106 if (startTime > endTime) | |
| 107 continue; // Time went backwards. (DST) | |
|
kinuko
2013/11/18 13:27:09
Ah oh. Right time could go backwards... maybe we c
pwnall-personal
2013/11/18 13:47:34
I just started doing that, then realized that skip
kinuko
2013/11/18 13:57:58
I see, sounds good, could we then remove this DST
pwnall-personal
2013/11/18 14:04:55
Done.
Good point, thank you!
| |
| 108 | |
| 109 shouldBeTrue("startTime <= fileTime"); | |
| 110 shouldBeTrue("fileTime <= endTime"); | |
| 111 break; | |
| 112 } | |
| 113 | |
| 90 // Test the number of expected arguments in the File constructor. | 114 // Test the number of expected arguments in the File constructor. |
| 91 shouldBe("window.File.length", "2"); | 115 shouldBe("window.File.length", "2"); |
| 92 | 116 |
| 93 // Test ArrayBufferView parameters. | 117 // Test ArrayBufferView parameters. |
| 94 shouldBe("new File([new DataView(new ArrayBuffer(100))], 'world.html').size", "1 00"); | 118 shouldBe("new File([new DataView(new ArrayBuffer(100))], 'world.html').size", "1 00"); |
| 95 shouldBe("new File([new Uint8Array(100)], 'world.html').size", "100"); | 119 shouldBe("new File([new Uint8Array(100)], 'world.html').size", "100"); |
| 96 shouldBe("new File([new Uint8ClampedArray(100)], 'world.html').size", "100"); | 120 shouldBe("new File([new Uint8ClampedArray(100)], 'world.html').size", "100"); |
| 97 shouldBe("new File([new Uint16Array(100)], 'world.html').size", "200"); | 121 shouldBe("new File([new Uint16Array(100)], 'world.html').size", "200"); |
| 98 shouldBe("new File([new Uint32Array(100)], 'world.html').size", "400"); | 122 shouldBe("new File([new Uint32Array(100)], 'world.html').size", "400"); |
| 99 shouldBe("new File([new Int8Array(100)], 'world.html').size", "100"); | 123 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", { | 161 Object.defineProperty(throwingSequence, "1", { |
| 138 get: function() { throw new Error("Misbehaving property"); }, | 162 get: function() { throw new Error("Misbehaving property"); }, |
| 139 enumerable: true, configurable: true | 163 enumerable: true, configurable: true |
| 140 }); | 164 }); |
| 141 Object.defineProperty(throwingSequence, "2", { | 165 Object.defineProperty(throwingSequence, "2", { |
| 142 get: function() { throw new Error("This should not be thrown"); }, | 166 get: function() { throw new Error("This should not be thrown"); }, |
| 143 enumerable: true, configurable: true | 167 enumerable: true, configurable: true |
| 144 }); | 168 }); |
| 145 shouldThrow("new File(throwingSequence, 'world.txt')", "'Error: Misbehaving prop erty'"); | 169 shouldThrow("new File(throwingSequence, 'world.txt')", "'Error: Misbehaving prop erty'"); |
| 146 </script> | 170 </script> |
| OLD | NEW |