js/xpconnect/tests/mochitest/test_bug789713.html

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/js/xpconnect/tests/mochitest/test_bug789713.html	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,62 @@
     1.4 +<!DOCTYPE HTML>
     1.5 +<html>
     1.6 +<!--
     1.7 +https://bugzilla.mozilla.org/show_bug.cgi?id=789713
     1.8 +-->
     1.9 +<head>
    1.10 +  <meta charset="utf-8">
    1.11 +  <title>Test for Bug 789713</title>
    1.12 +  <script type="application/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
    1.13 +  <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/>
    1.14 +</head>
    1.15 +<body>
    1.16 +<a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=789713">Mozilla Bug 789713</a>
    1.17 +<p id="display"></p>
    1.18 +<div id="content" style="display: none">
    1.19 +<iframe id="ifr"></iframe>
    1.20 +</div>
    1.21 +<pre id="test">
    1.22 +<script type="application/javascript">
    1.23 +
    1.24 +/** Test for Bug 789713 **/
    1.25 +
    1.26 +function go() {
    1.27 +  var pass = true;
    1.28 +  var doc = document.getElementById('ifr').contentDocument;
    1.29 +
    1.30 +  // Tree walkers use nsDOMGenericSH, which has a spineless PreCreate.
    1.31 +  var walker = doc.createTreeWalker(doc.body);
    1.32 +  pass = pass && (walker.root === doc.body);
    1.33 +
    1.34 +  // Grab a reference to Object.prototype to make sure we test the machinery
    1.35 +  // with respect to standard prototype remapping.
    1.36 +  var objProto = ifr.contentWindow.Object.prototype;
    1.37 +
    1.38 +  // First, do the document.domain operation. This shouldn't crash.
    1.39 +  document.domain = "example.org";
    1.40 +
    1.41 +  // Now, make sure that we still can't access cross-origin properties despite
    1.42 +  // the fact that the WN is shared under the hood.
    1.43 +  try {
    1.44 +    walker.root;
    1.45 +    pass = false;
    1.46 +  } catch (e) { pass = pass && /Permission denied/.exec(e.message); }
    1.47 +  window.parent.postMessage(pass, '*');
    1.48 +}
    1.49 +
    1.50 +// We can't set document.domain on mochi.test, because it's forbidden to set
    1.51 +// document.domain to a TLD.
    1.52 +var ifr = document.getElementById('ifr');
    1.53 +if (window.location.hostname == "mochi.test") {
    1.54 +  SimpleTest.waitForExplicitFinish();
    1.55 +  ifr.src = window.location.toString().replace("mochi.test:8888", "test1.example.org").split('?')[0];
    1.56 +  window.onmessage = function(message) { ok(message.data, "Test succeeded and didn't crash"); SimpleTest.finish(); };
    1.57 +} else {
    1.58 +  ifr.src = "file_empty.html";
    1.59 +  ifr.onload = go;
    1.60 +}
    1.61 +
    1.62 +</script>
    1.63 +</pre>
    1.64 +</body>
    1.65 +</html>

mercurial