content/base/test/test_XHR_system.html
author Gregor Wagner <anygregor@gmail.com>
Fri, 17 Aug 2012 17:42:00 -0700
changeset 102691 07d5886658b2a4f48f5325c363512636e5cd4067
parent 96096 57c5763ac3ac9630caa7c5fc30a1626a14c73b7d
child 107903 1f7c4fae49c0d80075e7b0380c4b841a5ed30ab0
permissions -rw-r--r--
Bug 781331 - Hook up systemXHR to permissions manager. r=sicking

<!DOCTYPE html>
<html>
<head>
  <meta charset="utf-8">
  <title>Test for XMLHttpRequest with system privileges</title>
  <script type="text/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>        
  <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" />
</head>
<body onload="runTests();">
<p id="display">
</p>
<div id="content" style="display: none">
  
</div>
<pre id="test">
<script class="testbody" type="application/javascript;version=1.8">

function runTests() {
  var comp = SpecialPowers.wrap(Components);
  SimpleTest.waitForExplicitFinish();
  SpecialPowers.addPermission("systemXHR", true, document);

  function tearDown() {
    SpecialPowers.removePermission("systemXHR", document);
    SimpleTest.finish();
  }

  // An XHR with system privileges will be able to do cross-site calls.

  const TEST_URL = "http://example.com/tests/content/base/test/test_XHR_system.html";
  is(window.location.hostname, "mochi.test");

  let 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);
    tearDown();
  };
  xhr.onerror = function onerror() {
    ok(false, "Got an error event!");
    tearDown();
  }
  xhr.send();
}

</script>
</pre>
</body>
</html>