summaryrefslogtreecommitdiffstats
path: root/dom/filesystem/compat/tests/test_no_dnd.html
blob: c49dd5d40fc3e6657083dff8c1132788ed19809d (plain)
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
73
74
75
76
77
78
79
80
81
82
83
84
<!DOCTYPE HTML>
<html>
<head>
  <title>Test for Blink FileSystem API - no DND == no webkitEntries</title>
  <script src="/tests/SimpleTest/SimpleTest.js"></script>
  <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" />
</head>

<body>
<script type="application/javascript">
var fileEntry;
var directoryEntry;
var script;
var entries;

function setup_tests() {
  SpecialPowers.pushPrefEnv({"set": [["dom.webkitBlink.dirPicker.enabled", true],
                                     ["dom.filesystem.pathcheck.disabled", true],
                                     ["dom.webkitBlink.filesystem.enabled", true]]}, next);
}

function populate_entries() {
  entries = document.createElement("input");
  entries.setAttribute("type", "file");
  document.body.appendChild(entries);

  var url = SimpleTest.getTestFileURL("script_entries.js");
  script = SpecialPowers.loadChromeScript(url);

  function onOpened(message) {
    for (var i = 0 ; i < message.data.length; ++i) {
      if (message.data[i] instanceof File) {
        SpecialPowers.wrap(entries).mozSetFileArray([message.data[i]]);
        next();
      }
    }
  }

  script.addMessageListener("entries.opened", onOpened);
  script.sendAsyncMessage("entries.open");
}

function test_entries() {
  ok("webkitEntries" in entries, "HTMLInputElement.webkitEntries");
  is(entries.webkitEntries.length, 0, "HTMLInputElement.webkitEntries.length == 0");
  is(entries.files.length, 1, "HTMLInputElement.files is still populated");

  next();
}

function cleanUpTestingFiles() {
  script.addMessageListener("entries.deleted", function onDeleted() {
    script.removeMessageListener("entries.deleted");
    script.destroy();
    next();
  });

  script.sendAsyncMessage("entries.delete");
}

var tests = [
  setup_tests,
  populate_entries,

  test_entries,

  cleanUpTestingFiles,
];

function next() {
  if (!tests.length) {
    SimpleTest.finish();
    return;
  }

  var test = tests.shift();
  test();
}

SimpleTest.waitForExplicitFinish();
next();
</script>
</body>
</html>