test_worker_xhr_system.js 864 B

12345678910111213141516171819202122232425262728293031
  1. function ok(what, msg) {
  2. postMessage({ event: msg, test: 'ok', a: what });
  3. }
  4. function is(a, b, msg) {
  5. postMessage({ event: msg, test: 'is', a: a, b: b });
  6. }
  7. self.onmessage = function onmessage(event) {
  8. // An XHR with system privileges will be able to do cross-site calls.
  9. const TEST_URL = "http://example.com/tests/dom/xhr/tests/test_XHR_system.html";
  10. is(location.hostname, "mochi.test", "hostname should be mochi.test");
  11. var xhr = new XMLHttpRequest({mozSystem: true});
  12. is(xhr.mozSystem, true, ".mozSystem == true");
  13. xhr.open("GET", TEST_URL);
  14. xhr.onload = function onload() {
  15. is(xhr.status, 200);
  16. ok(xhr.responseText != null);
  17. ok(xhr.responseText.length);
  18. postMessage({test: "finish"});
  19. };
  20. xhr.onerror = function onerror() {
  21. ok(false, "Got an error event!");
  22. postMessage({test: "finish"});
  23. }
  24. xhr.send();
  25. };