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 var startTime = Date.now(); | |
| 102 var fileTime = (new File([], 'world.html')).lastModifiedDate.valueOf(); | |
| 103 var endTime = Date.now(); | |
| 104 // FIXME: these checks will fail if time goes backwards, e.g. DST. We should hav e a generic bullet-proof method for comparing against Date.now(). | |
|
jsbell
2013/11/18 20:54:05
Drive-by comment:
Date.now() is ms since epoch in
pwnall-personal
2013/11/19 09:10:12
Thank you very much for pointing this out!
I upda
| |
| 105 shouldBeTrue("startTime <= fileTime"); | |
| 106 shouldBeTrue("fileTime <= endTime"); | |
| 107 | |
| 90 // Test the number of expected arguments in the File constructor. | 108 // Test the number of expected arguments in the File constructor. |
| 91 shouldBe("window.File.length", "2"); | 109 shouldBe("window.File.length", "2"); |
| 92 | 110 |
| 93 // Test ArrayBufferView parameters. | 111 // Test ArrayBufferView parameters. |
| 94 shouldBe("new File([new DataView(new ArrayBuffer(100))], 'world.html').size", "1 00"); | 112 shouldBe("new File([new DataView(new ArrayBuffer(100))], 'world.html').size", "1 00"); |
| 95 shouldBe("new File([new Uint8Array(100)], 'world.html').size", "100"); | 113 shouldBe("new File([new Uint8Array(100)], 'world.html').size", "100"); |
| 96 shouldBe("new File([new Uint8ClampedArray(100)], 'world.html').size", "100"); | 114 shouldBe("new File([new Uint8ClampedArray(100)], 'world.html').size", "100"); |
| 97 shouldBe("new File([new Uint16Array(100)], 'world.html').size", "200"); | 115 shouldBe("new File([new Uint16Array(100)], 'world.html').size", "200"); |
| 98 shouldBe("new File([new Uint32Array(100)], 'world.html').size", "400"); | 116 shouldBe("new File([new Uint32Array(100)], 'world.html').size", "400"); |
| 99 shouldBe("new File([new Int8Array(100)], 'world.html').size", "100"); | 117 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", { | 155 Object.defineProperty(throwingSequence, "1", { |
| 138 get: function() { throw new Error("Misbehaving property"); }, | 156 get: function() { throw new Error("Misbehaving property"); }, |
| 139 enumerable: true, configurable: true | 157 enumerable: true, configurable: true |
| 140 }); | 158 }); |
| 141 Object.defineProperty(throwingSequence, "2", { | 159 Object.defineProperty(throwingSequence, "2", { |
| 142 get: function() { throw new Error("This should not be thrown"); }, | 160 get: function() { throw new Error("This should not be thrown"); }, |
| 143 enumerable: true, configurable: true | 161 enumerable: true, configurable: true |
| 144 }); | 162 }); |
| 145 shouldThrow("new File(throwingSequence, 'world.txt')", "'Error: Misbehaving prop erty'"); | 163 shouldThrow("new File(throwingSequence, 'world.txt')", "'Error: Misbehaving prop erty'"); |
| 146 </script> | 164 </script> |
| OLD | NEW |