summaryrefslogtreecommitdiffstats
path: root/dom/xhr/tests/test_worker_xhr_system.js
blob: ee5934363dd6a9e34616d2ab81233277e0d2f705 (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
/* eslint-disable mozilla/no-comparison-or-assignment-inside-ok */

function ok(what, msg) {
  postMessage({ event: msg, test: "ok", a: what });
}

function is(a, b, msg) {
  postMessage({ event: msg, test: "is", a, b });
}

self.onmessage = function onmessage() {
  // An XHR with system privileges will be able to do cross-site calls.

  const TEST_URL =
    "http://example.com/tests/dom/xhr/tests/test_XHR_system.html";
  is(location.hostname, "mochi.test", "hostname should be mochi.test");

  var xhr = new XMLHttpRequest({ mozSystem: true });
  is(xhr.mozSystem, true, ".mozSystem == true");
  xhr.open("GET", TEST_URL);
  xhr.onload = function onload() {
    is(xhr.status, 200);
    ok(xhr.responseText != null);
    ok(xhr.responseText.length);
    postMessage({ test: "finish" });
  };
  xhr.onerror = function onerror() {
    ok(false, "Got an error event!");
    postMessage({ test: "finish" });
  };
  xhr.send();
};