tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

test_worker_basic.html (1602B)


      1 <!DOCTYPE HTML>
      2 <html>
      3 <head>
      4  <title>Test for Directory API in workers</title>
      5  <script src="/tests/SimpleTest/SimpleTest.js"></script>
      6  <script type="text/javascript" src="filesystem_commons.js"></script>
      7  <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" />
      8 </head>
      9 
     10 <body>
     11 <script type="application/javascript">
     12 
     13 var fileList;
     14 
     15 function create_fileList() {
     16  fileList = document.createElement("input");
     17  fileList.setAttribute("type", "file");
     18  document.body.appendChild(fileList);
     19 
     20  var url = SimpleTest.getTestFileURL("script_fileList.js");
     21  var script = SpecialPowers.loadChromeScript(url);
     22 
     23  function onOpened(message) {
     24    SpecialPowers.wrap(fileList).mozSetDirectory(message.dir);
     25    script.destroy();
     26    next();
     27  }
     28 
     29  script.addMessageListener("dir.opened", onOpened);
     30  script.sendAsyncMessage("dir.open", { path: "test" });
     31 }
     32 
     33 function test_worker() {
     34  SpecialPowers.wrap(fileList).getFilesAndDirectories().then(function(array) {
     35    array = SpecialPowers.unwrap(array);
     36    var worker = new Worker("worker_basic.js");
     37    worker.onmessage = function(e) {
     38      if (e.data.type == "finish") {
     39        next();
     40        return;
     41      }
     42 
     43      if (e.data.type == "test") {
     44        ok(e.data.test, e.data.message);
     45      }
     46    };
     47 
     48    worker.postMessage(array[0]);
     49  });
     50 }
     51 
     52 var tests = [
     53  function() { setup_tests(next); },
     54 
     55  create_fileList,
     56  test_worker,
     57 ];
     58 
     59 function next() {
     60  if (!tests.length) {
     61    SimpleTest.finish();
     62    return;
     63  }
     64 
     65  var test = tests.shift();
     66  test();
     67 }
     68 
     69 SimpleTest.waitForExplicitFinish();
     70 next();
     71 </script>
     72 </body>
     73 </html>