dom/xbl/test/test_bug379959.html
author Robert O'Callahan <robert@ocallahan.org>
Fri, 10 Jan 2014 16:03:25 +1300
changeset 180086 243259fda9aba5900ae1492c991a0e7a541a584d
parent 157609 content/xbl/test/test_bug379959.html@4e2ac1af304773c7ee42a437bfd57c6a03ea6353
child 296825 58e1f5749c0918b372ed5d484829f579429685d5
permissions -rw-r--r--
Bug 946065. Part 4: Move content/xbl to dom/ and flatten away 'src' directory. r=Ms2ger

<!DOCTYPE HTML>
<html>
<!--
https://bugzilla.mozilla.org/show_bug.cgi?id=379959
-->
<head>
  <title>Test for Bug 379959</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="runTest();">
  <a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=379959">Mozilla Bug 379959</a>
  <p id="display">
    Note: In order to re-run this test correctly you need to shift-reload
    rather than simply reload. If you just reload we will restore the
    previous url in the iframe which will result in an extra unexpected
    message.
  </p>
  <div id="content" style="display: none"></div>
  <iframe id="f"></iframe>

  <pre id="test">
    <script class="testbody" type="application/javascript;version=1.7">
SimpleTest.waitForExplicitFinish();

var messages = 0;

function receiveMessage(e) {
  is(e.origin, "http://mochi.test:8888", "wrong sender!");
  messages++;

  switch (messages) {
    case 1:
      receiveMessage1(e.data);
      break;
    case 2:
      receiveMessage2(e.data);
      break;
    case 3:
      receiveMessage3(e.data);
      break;
    case 4:
      receiveMessage4(e.data);
      break;
    default:
      ok(false, "should not be reached");
      Simpletest.finish();
  }
}

window.addEventListener("message", receiveMessage, false);

var iframe = document.getElementById('f');

function runTest() {
  // Test with data-urls off
  SpecialPowers.pushPrefEnv({"set": [["layout.debug.enable_data_xbl", false]]}, runTest1);
}

function runTest1() {
  iframe.src = "file_bug379959_data.html";
}

function receiveMessage1(aData) {
  is(aData, 0, "data-url load should have failed");
  // Test with data-urls on
  SpecialPowers.pushPrefEnv({"set": [["layout.debug.enable_data_xbl", true]]}, runTest2);
}

function runTest2() {
  iframe.src = "file_bug379959_data.html";
}

function receiveMessage2(aData) {
  is(aData, 1, "data-url load should have been successful");
  // Try a cross-site load
  iframe.src = "file_bug379959_cross.html";
}

function receiveMessage3(aData) {
  is(aData, 1, "same site load should have succeeded");
}

function receiveMessage4(aData) {
  is(aData, 0, "cross site load should have failed");

  // Check that we got the right number of messages to make sure that
  // the right message has aligned with the right test
  is(messages, 4, "wrong number of messages");

  SimpleTest.finish();
}

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