Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 <!DOCTYPE html> | |
| 2 | |
| 3 <script src="../../resources/js-test.js"></script> | |
| 4 <script> | |
| 5 description("Test the File constructor."); | |
| 6 | |
| 7 // Test the diffrent ways you can construct a File. | |
| 8 shouldBeTrue("(new File([], '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"); | |
| 11 shouldBeTrue("(new File(['hello'], 'world.html', {type:'text/html'})) instanceof window.File"); | |
| 12 shouldBeTrue("(new File(['hello'], 'world.html', {type:'text/html', endings:'nat ive'})) instanceof window.File"); | |
| 13 shouldBeTrue("(new File(['hello'], 'world.html', {type:'text/html', endings:'tra nsparent'})) instanceof window.File"); | |
| 14 | |
| 15 // Test that File inherits from File. | |
| 16 shouldBeTrue("(new File([], 'world.html')) instanceof window.File") | |
| 17 | |
| 18 // Verify that the file name argument is required. | |
| 19 shouldThrow("(new File())", "'TypeError: Constructor requires at least two argum ents'"); | |
| 20 | |
| 21 // Test valid file names. | |
| 22 shouldBeTrue("(new File([], null)) instanceof window.File"); | |
| 23 shouldBeTrue("(new File([], 1)) instanceof window.File"); | |
| 24 shouldBeTrue("(new File([], document)) instanceof window.File"); | |
| 25 | |
| 26 // Test invalid blob parts | |
| 27 shouldThrow("new File('hello', 'world.html')", "'TypeError: First argument of th e constructor is not of type Array'"); | |
| 28 shouldThrow("new File(0, 'world.html')", "'TypeError: First argument of the cons tructor is not of type Array'"); | |
| 29 | |
| 30 // Test valid blob parts. | |
| 31 shouldBeTrue("(new File([], 'world.html')) instanceof window.File"); | |
| 32 shouldBeTrue("(new File(['stringPrimitive'], 'world.html')) instanceof window.Fi le"); | |
| 33 shouldBeTrue("(new File([String('stringObject')], 'world.html')) instanceof wind ow.File"); | |
| 34 shouldBeTrue("(new File([new Blob], 'world.html')) instanceof window.File"); | |
| 35 shouldBeTrue("(new File([new Blob([new Blob])], 'world.html')) instanceof window .File"); | |
| 36 | |
| 37 // Test File instances used as blob parts. | |
| 38 shouldBeTrue("(new Blob([new File([], 'world.txt')])) instanceof window.Blob"); | |
| 39 shouldBeTrue("(new Blob([new Blob([new File([new Blob], 'world.txt')])])) instan ceof window.Blob"); | |
| 40 shouldBeTrue("(new File([new File([], 'world.txt')], 'world.html')) instanceof w indow.File"); | |
| 41 shouldBeTrue("(new File([new Blob([new File([new Blob], 'world.txt')]])], 'world .html')) instanceof window.File"); | |
| 42 | |
| 43 // Test some conversions to string in the parts array. | |
| 44 shouldBe("(new File([12], 'world.html')).size", "2"); | |
| 45 shouldBe("(new File([[]], 'world.html')).size", "0"); // [].toString() i s the empty string | |
| 46 shouldBe("(new File([{}], 'world.html')).size", "15");; // {}.toString() i s the string "[object Object]" | |
| 47 shouldBe("(new File([document], 'world.html')).size", "21"); // document.toStri ng() is the string "[object HTMLDocument]" | |
| 48 | |
| 49 var toStringingObj = { toString: function() { return "A string"; } }; | |
| 50 shouldBe("(new File([toStringingObj], 'world.html')).size", "8"); | |
| 51 | |
| 52 var throwingObj = { toString: function() { throw "Error"; } }; | |
| 53 shouldThrow("new File([throwingObj], 'world.html')", "'Error'"); | |
| 54 | |
| 55 // Test some conversions to string in the file name. | |
| 56 shouldBe("(new File([], null)).name", "'null'"); | |
| 57 shouldBe("(new File([], 12)).name", "'12'"); | |
| 58 shouldBe("(new File([], {})).name", "'[object Object]'"); | |
| 59 shouldBe("(new File([], document)).name", "'[object HTMLDocument]'"); | |
| 60 shouldBe("(new File([], toStringingObj)).name", "'A string'"); | |
| 61 shouldThrow("(new File([], throwingObj)).name", "'Error'"); | |
| 62 | |
|
Inactive
2013/11/07 14:27:44
Could you please add a check to make sure File.len
pwnall-personal
2013/11/08 07:36:41
Done.
| |
| 63 // Test some invalid property bags. | |
| 64 shouldBeTrue("(new File([], 'world.html', {unknownKey:'value'})) instanceof wind ow.File"); // Ignore invalid keys | |
| 65 shouldThrow("new File([], 'world.html', {endings:'illegalValue'})", "'TypeError: The endings property must be either \"transparent\" or \"native\"'"); | |
| 66 shouldThrow("new File([], 'world.html', {endings:throwingObj})", "'Error'"); | |
| 67 shouldThrow("new File([], 'world.html', {type:throwingObj})", "'Error'"); | |
| 68 shouldThrow("new File([], 'world.html', {type:'hello\u00EE'})", "'SyntaxError: t ype must consist of ASCII characters'"); | |
| 69 | |
| 70 // Test various non-object literals being used as property bags. | |
| 71 shouldThrow("(new File([], 'world.html', null)) instanceof window.File", "'TypeE rror: Third argument of the constructor is not of type Object'"); | |
| 72 shouldThrow("(new File([], 'world.html', undefined)) instanceof window.File", "' TypeError: Third argument of the constructor is not of type Object'"); | |
| 73 shouldThrow("(new File([], 'world.html', 123)) instanceof window.File", "'TypeEr ror: Third argument of the constructor is not of type Object'"); | |
| 74 shouldThrow("(new File([], 'world.html', 123.4)) instanceof window.File", "'Type Error: Third argument of the constructor is not of type Object'"); | |
| 75 shouldThrow("(new File([], 'world.html', true)) instanceof window.File", "'TypeE rror: Third argument of the constructor is not of type Object'"); | |
| 76 shouldThrow("(new File([], 'world.html', 'abc')) instanceof window.File", "'Type Error: Third argument of the constructor is not of type Object'"); | |
| 77 shouldBeTrue("(new File([], 'world.html', [])) instanceof window.File"); | |
| 78 shouldBeTrue("(new File([], 'world.html', /abc/)) instanceof window.File"); | |
| 79 shouldBeTrue("(new File([], 'world.html', function () {})) instanceof window.Fil e"); | |
| 80 | |
| 81 // Test that the name/type/size are correctly added to the File. | |
| 82 shouldBe("(new File([], 'world.html', {type:'text/html'})).name", "'world.html'" ); | |
| 83 shouldBe("(new File([], 'world.html', {type:'text/html'})).type", "'text/html'") ; | |
| 84 shouldBe("(new File([], 'world.html', {type:'text/html'})).size", "0"); | |
| 85 shouldBe("(new File([], 'world.html', {type:'text/plain;charset=UTF-8'})).type", "'text/plain;charset=utf-8'"); | |
| 86 | |
| 87 // Test ArrayBufferView Parameters. | |
| 88 shouldBe("new File([new DataView(new ArrayBuffer(100))], 'world.html').size", "1 00"); | |
| 89 shouldBe("new File([new Uint8Array(100)], 'world.html').size", "100"); | |
| 90 shouldBe("new File([new Uint8ClampedArray(100)], 'world.html').size", "100"); | |
| 91 shouldBe("new File([new Uint16Array(100)], 'world.html').size", "200"); | |
| 92 shouldBe("new File([new Uint32Array(100)], 'world.html').size", "400"); | |
| 93 shouldBe("new File([new Int8Array(100)], 'world.html').size", "100"); | |
| 94 shouldBe("new File([new Int16Array(100)], 'world.html').size", "200"); | |
| 95 shouldBe("new File([new Int32Array(100)], 'world.html').size", "400"); | |
| 96 shouldBe("new File([new Float32Array(100)], 'world.html').size", "400"); | |
| 97 shouldBe("new File([new Float64Array(100)], 'world.html').size", "800"); | |
| 98 shouldBe("new File([new Float64Array(100), new Int32Array(100), new Uint8Array(1 00), new DataView(new ArrayBuffer(100))], 'world.html').size", "1400"); | |
| 99 shouldBe("new File([new Blob([new Int32Array(100)]), new Uint8Array(100), new Fl oat32Array(100), new DataView(new ArrayBuffer(100))], 'world.html').size", "1000 "); | |
| 100 shouldBe("new File([new Blob([new Int32Array(100)]), new File([new Uint16Array(1 00)], 'world.txt'), new Uint8Array(100), new Float32Array(100), new DataView(new ArrayBuffer(100))], 'world.html').size", "1200"); | |
| 101 | |
| 102 // Test ArrayBuffer Parameters. | |
| 103 shouldBe("new File([(new DataView(new ArrayBuffer(100))).buffer], 'world.html'). size", "100"); | |
| 104 shouldBe("new File([(new Uint8Array(100)).buffer], 'world.html').size", "100"); | |
| 105 shouldBe("new File([(new Uint8ClampedArray(100)).buffer], 'world.html').size", " 100"); | |
| 106 shouldBe("new File([(new Uint16Array(100)).buffer], 'world.html').size", "200"); | |
| 107 shouldBe("new File([(new Uint32Array(100)).buffer], 'world.html').size", "400"); | |
| 108 shouldBe("new File([(new Int8Array(100)).buffer], 'world.html').size", "100"); | |
| 109 shouldBe("new File([(new Int16Array(100)).buffer], 'world.html').size", "200"); | |
| 110 shouldBe("new File([(new Int32Array(100)).buffer], 'world.html').size", "400"); | |
| 111 shouldBe("new File([(new Float32Array(100)).buffer], 'world.html').size", "400") ; | |
| 112 shouldBe("new File([(new Float64Array(100)).buffer], 'world.html').size", "800") ; | |
| 113 shouldBe("new File([(new Float64Array(100)).buffer, (new Int32Array(100)).buffer , (new Uint8Array(100)).buffer, (new DataView(new ArrayBuffer(100))).buffer], 'w orld.html').size", "1400"); | |
| 114 shouldBe("new File([new Blob([(new Int32Array(100)).buffer]), (new Uint8Array(10 0)).buffer, (new Float32Array(100)).buffer, (new DataView(new ArrayBuffer(100))) .buffer], 'world.html').size", "1000"); | |
| 115 shouldBe("new File([new Blob([(new Int32Array(100)).buffer]), new File([new Uint 16Array(100).buffer], 'world.txt'), (new Uint8Array(100)).buffer, (new Float32Ar ray(100)).buffer, (new DataView(new ArrayBuffer(100))).buffer], 'world.html').si ze", "1200"); | |
| 116 | |
| 117 // Test building Blobs with ArrayBuffer / ArrayBufferView parts enclosed in file s. | |
| 118 shouldBe("new Blob([new Blob([new Int32Array(100)]), new File([new Uint16Array(1 00)], 'world.txt'), new Uint8Array(100), new Float32Array(100), new DataView(new ArrayBuffer(100))]).size", "1200"); | |
| 119 shouldBe("new Blob([new Blob([(new Int32Array(100)).buffer]), new File([new Uint 16Array(100).buffer], 'world.txt'), (new Uint8Array(100)).buffer, (new Float32Ar ray(100)).buffer, (new DataView(new ArrayBuffer(100))).buffer]).size", "1200"); | |
| 120 </script> | |
| OLD | NEW |