dom/filesystem/compat/tests/test_no_dnd.html
author Adam Pucciano <aspucciano@myseneca.ca>
Wed, 05 Dec 2018 02:24:58 +0000
changeset 449351 3930f1e2fc9e26f09c9722a941cb77bb28956d0d
parent 348002 109855be8ccb811943553d5af0f5669712442b6e
child 449352 bd4e540b0801acb2dddeaab2e7d63d7a14f0cbc5
permissions -rw-r--r--
Bug 1508989 - Enable ESLint for dom/filesystem / (automatic changes) r=Standard8 Differential Revision: https://phabricator.services.mozilla.com/D13770

<!DOCTYPE HTML>
<html>
<head>
  <title>Test for Blink FileSystem API - no DND == no webkitEntries</title>
  <script type="text/javascript" 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>