dom/xbl/test/test_bug379959.html

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/dom/xbl/test/test_bug379959.html	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,97 @@
     1.4 +<!DOCTYPE HTML>
     1.5 +<html>
     1.6 +<!--
     1.7 +https://bugzilla.mozilla.org/show_bug.cgi?id=379959
     1.8 +-->
     1.9 +<head>
    1.10 +  <title>Test for Bug 379959</title>
    1.11 +  <script type="text/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
    1.12 +  <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" />
    1.13 +</head>
    1.14 +<body onload="runTest();">
    1.15 +  <a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=379959">Mozilla Bug 379959</a>
    1.16 +  <p id="display">
    1.17 +    Note: In order to re-run this test correctly you need to shift-reload
    1.18 +    rather than simply reload. If you just reload we will restore the
    1.19 +    previous url in the iframe which will result in an extra unexpected
    1.20 +    message.
    1.21 +  </p>
    1.22 +  <div id="content" style="display: none"></div>
    1.23 +  <iframe id="f"></iframe>
    1.24 +
    1.25 +  <pre id="test">
    1.26 +    <script class="testbody" type="application/javascript;version=1.7">
    1.27 +SimpleTest.waitForExplicitFinish();
    1.28 +
    1.29 +var messages = 0;
    1.30 +
    1.31 +function receiveMessage(e) {
    1.32 +  is(e.origin, "http://mochi.test:8888", "wrong sender!");
    1.33 +  messages++;
    1.34 +
    1.35 +  switch (messages) {
    1.36 +    case 1:
    1.37 +      receiveMessage1(e.data);
    1.38 +      break;
    1.39 +    case 2:
    1.40 +      receiveMessage2(e.data);
    1.41 +      break;
    1.42 +    case 3:
    1.43 +      receiveMessage3(e.data);
    1.44 +      break;
    1.45 +    case 4:
    1.46 +      receiveMessage4(e.data);
    1.47 +      break;
    1.48 +    default:
    1.49 +      ok(false, "should not be reached");
    1.50 +      Simpletest.finish();
    1.51 +  }
    1.52 +}
    1.53 +
    1.54 +window.addEventListener("message", receiveMessage, false);
    1.55 +
    1.56 +var iframe = document.getElementById('f');
    1.57 +
    1.58 +function runTest() {
    1.59 +  // Test with data-urls off
    1.60 +  SpecialPowers.pushPrefEnv({"set": [["layout.debug.enable_data_xbl", false]]}, runTest1);
    1.61 +}
    1.62 +
    1.63 +function runTest1() {
    1.64 +  iframe.src = "file_bug379959_data.html";
    1.65 +}
    1.66 +
    1.67 +function receiveMessage1(aData) {
    1.68 +  is(aData, 0, "data-url load should have failed");
    1.69 +  // Test with data-urls on
    1.70 +  SpecialPowers.pushPrefEnv({"set": [["layout.debug.enable_data_xbl", true]]}, runTest2);
    1.71 +}
    1.72 +
    1.73 +function runTest2() {
    1.74 +  iframe.src = "file_bug379959_data.html";
    1.75 +}
    1.76 +
    1.77 +function receiveMessage2(aData) {
    1.78 +  is(aData, 1, "data-url load should have been successful");
    1.79 +  // Try a cross-site load
    1.80 +  iframe.src = "file_bug379959_cross.html";
    1.81 +}
    1.82 +
    1.83 +function receiveMessage3(aData) {
    1.84 +  is(aData, 1, "same site load should have succeeded");
    1.85 +}
    1.86 +
    1.87 +function receiveMessage4(aData) {
    1.88 +  is(aData, 0, "cross site load should have failed");
    1.89 +
    1.90 +  // Check that we got the right number of messages to make sure that
    1.91 +  // the right message has aligned with the right test
    1.92 +  is(messages, 4, "wrong number of messages");
    1.93 +
    1.94 +  SimpleTest.finish();
    1.95 +}
    1.96 +
    1.97 +    </script>
    1.98 +  </pre>
    1.99 +</body>
   1.100 +</html>

mercurial