content/xbl/test/test_bug379959.html
author Igor Bukanov <igor@mir2.org>
Fri, 20 Jun 2008 11:46:36 +0200
changeset 15452 056158a4c1e84b8621d066d1d4f1fc92db37ae06
parent 14902 da3a8e06916f8c2ecdf7c50892d6a7eab75326c2
child 28048 8f7b73d88f6bbedec99c6c8ef48b243ab922d05c
permissions -rw-r--r--
Backed out changeset 97977f224aff due to build breakage

<!DOCTYPE HTML>
<html>
<!--
https://bugzilla.mozilla.org/show_bug.cgi?id=366770
-->
<head>
  <title>Test for Bug 366770</title>
  <script type="text/javascript" src="/MochiKit/MochiKit.js"></script>
  <script type="text/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
  <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" />
</head>
<body onload="gen.next();">
  <a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=366770">Mozilla Bug 366770</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();

gen = runTest();
var messages = 0;

function receiveMessage(e)
{
  is(e.origin, "http://localhost:8888", "wrong sender!");
  messages++;
  gen.send(e.data);
}

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

const prefName = "layout.debug.enable_data_xbl";

function runTest() {
  iframe = document.getElementById('f');

  // Turn on loads of data-urls
  netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
  var prefs = Components.classes["@mozilla.org/preferences-service;1"]
    .getService(Components.interfaces.nsIPrefBranch);
  var oldPrefVal = undefined;
  if (prefs.prefHasUserValue(prefName)) {
    oldPrefVal = prefs.getBoolPref(prefName);
  }

  // Test with data-urls off
  prefs.setBoolPref(prefName, false);
  iframe.src = "file_bug379959_data.html";
  is((yield), 0, "data-url load should have failed");

  // Test with data-urls on
  prefs.setBoolPref(prefName, true);
  iframe.src = "file_bug379959_data.html";
  is((yield), 1, "data-url load should have been successful");

  // Try a cross-site load
  iframe.src = "file_bug379959_cross.html";
  is((yield), 1, "same site load should have succeeded");
  is((yield), 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");

  // We're done
  if (oldPrefVal === undefined) {
    prefs.clearUserPref(prefName);
  }
  else {
    prefs.setBoolPref(prefName, oldPrefVal);
  }

  SimpleTest.finish();

  yield;
}
    </script>
  </pre>
</body>
</html>