dom/filesystem/tests/test_worker_basic.html
author Andrea Marchesini <amarchesini@mozilla.com>
Tue, 12 Apr 2016 08:50:38 -0400
changeset 330680 b416fc68c0a2d4ea2640a31826233aa053c058c8
child 330682 166555b48e772d021e298740a2ac389a76bdccec
permissions -rw-r--r--
Bug 1257180 - patch 1 - Directory clonable to workers, r=smaug

<!DOCTYPE HTML>
<html>
<head>
  <title>Test for Directory API in workers</title>
  <script type="text/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
  <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" />
</head>

<body>
<input id="fileList" type="file"></input>
<script type="application/javascript;version=1.7">

function create_fileList() {
  var url = SimpleTest.getTestFileURL("script_fileList.js");
  var script = SpecialPowers.loadChromeScript(url);

  function onOpened(message) {
    var fileList = document.getElementById('fileList');
    SpecialPowers.wrap(fileList).mozSetDirectory(message.dir);

    // Just a simple test
    is(fileList.files.length, 1, "Filelist has 1 element");
    ok(fileList.files[0] instanceof Directory, "We have a directory.");

    script.destroy();
    next();
  }

  script.addMessageListener("dir.opened", onOpened);
  script.sendAsyncMessage("dir.open", { path: 'ProfD' });
}

function test_worker() {
  var fileList = document.getElementById('fileList');

  var worker = new Worker('worker_basic.js');
  worker.onmessage = function(e) {
    if (e.data.type == 'finish') {
      next();
      return;
    }

    if (e.data.type == 'test') {
      ok(e.data.test, e.data.message);
    }
  }

  worker.postMessage(fileList.files);
}

var tests = [
  create_fileList,
  test_worker,
];

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

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

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