content/xbl/test/test_bug379959.html
author Gene Lian <clian@mozilla.com>
Fri, 28 Sep 2012 14:02:28 +0800
changeset 108418 cba5ba69091f52840af3d8f738ac43bbcc256e6d
parent 74314 95496a360748609134a5c666d57c7f48aa23393e
child 138088 d134dbb62202fa527750efbd995fe6f84c84db23
permissions -rw-r--r--
Bug 789973 - B2G system time: adjust system clock after receiving NITZ timestamp (part 1). r=jlebar

<!DOCTYPE HTML>
<html>
<!--
https://bugzilla.mozilla.org/show_bug.cgi?id=366770
-->
<head>
  <title>Test for Bug 366770</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="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://mochi.test: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>