File: File-constructor.html

package info (click to toggle)
icedove 1%3A45.8.0-3~deb8u1
  • links: PTS, VCS
  • area: main
  • in suites: jessie
  • size: 1,488,584 kB
  • ctags: 1,068,813
  • sloc: cpp: 4,801,496; ansic: 1,929,291; python: 379,296; java: 252,018; xml: 173,182; asm: 146,741; sh: 89,229; makefile: 23,462; perl: 16,380; objc: 4,088; yacc: 1,841; lex: 1,222; exp: 499; php: 437; lisp: 228; awk: 152; pascal: 116; sed: 51; ruby: 47; csh: 31; ada: 16
file content (72 lines) | stat: -rw-r--r-- 2,851 bytes parent folder | download | duplicates (7)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
<!DOCTYPE html>
<meta charset=utf-8>
<title>File constructor</title>
<link rel=help href="http://dev.w3.org/2006/webapi/FileAPI/#dfn-file">
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<div id="log"></div>
<script>
test(function() {
  assert_true("File" in window, "window should have a File property.");
}, "File interface object exists");

function test_first_argument(arg1, expectedSize, testName) {
  test(function() {
    var file = new File(arg1, "dummy");
    assert_true(file instanceof File);
    assert_equals(file.name, "dummy");
    assert_equals(file.size, expectedSize);
    assert_equals(file.type, "");
    // assert_false(file.isClosed); XXX: File.isClosed doesn't seem to be implemented
    assert_not_equals(file.lastModified, "");
  }, testName);
}

test_first_argument(["bits"], 4, "DOMString fileBits");
test_first_argument(["𝓽𝓮𝔁𝓽"], 16, "Unicode DOMString fileBits");
test_first_argument([new Blob()], 0, "Empty Blob fileBits");
test_first_argument([new Blob(["bits"])], 4, "Blob fileBits");
test_first_argument([new ArrayBuffer(8)], 8, "ArrayBuffer fileBits");
test_first_argument([new Uint8Array([0x50, 0x41, 0x53, 0x53])], 4, "Typed array fileBits");
test_first_argument(["bits", new Blob(["bits"]), new Blob(), new Uint8Array([0x50, 0x41]),
                     new Uint16Array([0x5353]), new Uint32Array([0x53534150])], 16, "Various fileBits");

function test_second_argument(arg2, expectedFileName, testName) {
  test(function() {
    var file = new File(["bits"], arg2);
    assert_true(file instanceof File);
    assert_equals(file.name, expectedFileName);
  }, testName);
}

test_second_argument("dummy", "dummy", "Using fileName");
test_second_argument("dummy/foo", "dummy:foo", "Using special character in fileName");

// testing the third argument
test(function() {
  var file = new File(["bits"], "dummy", { type: "text/plain"});
  assert_true(file instanceof File);
  assert_equals(file.type, "text/plain");
}, "Using type on the File constructor");
test(function() {
  var file = new File(["bits"], "dummy", { type: "TEXT/PLAIN"});
  assert_true(file instanceof File);
  assert_equals(file.type, "text/plain");
}, "Using uppercase characters in type");
test(function() {
  var file = new File(["bits"], "dummy", { type: "𝓽𝓮𝔁𝓽/𝔭𝔩𝔞𝔦𝔫"});
  assert_true(file instanceof File);
  assert_equals(file.type, "");
}, "Using illegal character for type");
test(function() {
  var file = new File(["bits"], "dummy", { lastModified: 42 });
  assert_true(file instanceof File);
  assert_equals(file.lastModified, 42);
}, "Using lastModified");
test(function() {
  var file = new File(["bits"], "dummy", { name: "foo" });
  assert_true(file instanceof File);
  assert_equals(file.name, "dummy");
}, "Misusing name");

</script>