OLD | NEW |
(Empty) | |
| 1 <!DOCTYPE html> |
| 2 <meta charset=utf-8> |
| 3 <title>File constructor</title> |
| 4 <link rel=help href="http://dev.w3.org/2006/webapi/FileAPI/#dfn-file"> |
| 5 <script src="../../../../resources/testharness.js"></script> |
| 6 <script src="../../../../resources/testharnessreport.js"></script> |
| 7 <div id="log"></div> |
| 8 <script> |
| 9 test(function() { |
| 10 assert_true("File" in window, "window should have a File property."); |
| 11 }, "File interface object exists"); |
| 12 |
| 13 function test_first_argument(arg1, expectedSize, testName) { |
| 14 test(function() { |
| 15 var file = new File(arg1, "dummy"); |
| 16 assert_true(file instanceof File); |
| 17 assert_equals(file.name, "dummy"); |
| 18 assert_equals(file.size, expectedSize); |
| 19 assert_equals(file.type, ""); |
| 20 // assert_false(file.isClosed); XXX: File.isClosed doesn't seem to be implem
ented |
| 21 assert_not_equals(file.lastModified, ""); |
| 22 }, testName); |
| 23 } |
| 24 |
| 25 test_first_argument(["bits"], 4, "DOMString fileBits"); |
| 26 test_first_argument(["𝓽𝓮𝔁𝓽"], 16, "Unicode DOMString fileBits"); |
| 27 test_first_argument([new Blob()], 0, "Empty Blob fileBits"); |
| 28 test_first_argument([new Blob(["bits"])], 4, "Blob fileBits"); |
| 29 test_first_argument([new ArrayBuffer(8)], 8, "ArrayBuffer fileBits"); |
| 30 test_first_argument([new Uint8Array([0x50, 0x41, 0x53, 0x53])], 4, "Typed array
fileBits"); |
| 31 test_first_argument(["bits", new Blob(["bits"]), new Blob(), new Uint8Array([0x5
0, 0x41]), |
| 32 new Uint16Array([0x5353]), new Uint32Array([0x53534150])],
16, "Various fileBits"); |
| 33 |
| 34 function test_second_argument(arg2, expectedFileName, testName) { |
| 35 test(function() { |
| 36 var file = new File(["bits"], arg2); |
| 37 assert_true(file instanceof File); |
| 38 assert_equals(file.name, expectedFileName); |
| 39 }, testName); |
| 40 } |
| 41 |
| 42 test_second_argument("dummy", "dummy", "Using fileName"); |
| 43 test_second_argument("dummy/foo", "dummy:foo", "Using special character in fileN
ame"); |
| 44 |
| 45 // testing the third argument |
| 46 test(function() { |
| 47 var file = new File(["bits"], "dummy", { type: "text/plain"}); |
| 48 assert_true(file instanceof File); |
| 49 assert_equals(file.type, "text/plain"); |
| 50 }, "Using type on the File constructor"); |
| 51 test(function() { |
| 52 var file = new File(["bits"], "dummy", { type: "TEXT/PLAIN"}); |
| 53 assert_true(file instanceof File); |
| 54 assert_equals(file.type, "text/plain"); |
| 55 }, "Using uppercase characters in type"); |
| 56 test(function() { |
| 57 var file = new File(["bits"], "dummy", { type: "𝓽𝓮𝔁𝓽/𝔭𝔩𝔞𝔦𝔫"}); |
| 58 assert_true(file instanceof File); |
| 59 assert_equals(file.type, ""); |
| 60 }, "Using illegal character for type"); |
| 61 test(function() { |
| 62 var file = new File(["bits"], "dummy", { lastModified: 42 }); |
| 63 assert_true(file instanceof File); |
| 64 assert_equals(file.lastModified, 42); |
| 65 }, "Using lastModified"); |
| 66 test(function() { |
| 67 var file = new File(["bits"], "dummy", { name: "foo" }); |
| 68 assert_true(file instanceof File); |
| 69 assert_equals(file.name, "dummy"); |
| 70 }, "Misusing name"); |
| 71 |
| 72 </script> |
OLD | NEW |