dom/url/tests/test_bug883784.jsm
author danielleleb <danielleleb12@gmail.com>
Tue, 12 Mar 2019 17:38:47 +0000
changeset 521608 f87b1c69a88d995473d2351fa55247774be9c395
parent 457598 b599a95ce057712c6b7804f7f108c9c4acff7e6d
permissions -rw-r--r--
Bug 1532934 - Enable ESLint for dom/url (automatic changes). r=Standard8,baku Differential Revision: https://phabricator.services.mozilla.com/D22736

var EXPORTED_SYMBOLS = ["Test"];

Cu.importGlobalProperties(["URL", "XMLHttpRequest"]);

var Test = {
  start(ok, is, finish) {
    let worker = new ChromeWorker("jsm_url_worker.js");
    worker.onmessage = function(event) {
      if (event.data.type == "status") {
        ok(event.data.status, event.data.msg);
      } else if (event.data.type == "url") {
        var xhr = new XMLHttpRequest();
        xhr.open("GET", event.data.url, false);
        xhr.onreadystatechange = function() {
          if (xhr.readyState == 4) {
            ok(true, "Blob readable!");
            URL.revokeObjectURL(event.data.url);
            finish();
          }
        };
        xhr.onerror = function() {
          ok(false, "Blob unreadable, should not happen!");
          URL.revokeObjectURL(event.data.url);
          finish();
        };
        xhr.send();
      }
    };

    var self = this;
    worker.onerror = function(event) {
      is(event.target, worker);
      ok(false, "Worker had an error: " + event.data);
      self.worker.terminate();
      finish();
    };

    worker.postMessage(0);
  },
};