js/xpconnect/tests/chrome/test_bug773962.xul

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/js/xpconnect/tests/chrome/test_bug773962.xul	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,82 @@
     1.4 +<?xml version="1.0"?>
     1.5 +<?xml-stylesheet type="text/css" href="chrome://global/skin"?>
     1.6 +<?xml-stylesheet type="text/css" href="chrome://mochikit/content/tests/SimpleTest/test.css"?>
     1.7 +<!--
     1.8 +https://bugzilla.mozilla.org/show_bug.cgi?id=773962
     1.9 +-->
    1.10 +<window title="Mozilla Bug 773962"
    1.11 +        xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul">
    1.12 +  <script type="application/javascript" src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js"/>
    1.13 +
    1.14 +  <!-- test results are displayed in the html:body -->
    1.15 +  <body xmlns="http://www.w3.org/1999/xhtml">
    1.16 +  <a href="https://bugzilla.mozilla.org/show_bug.cgi?id=773962"
    1.17 +     target="_blank">Mozilla Bug 773962</a>
    1.18 +  </body>
    1.19 +
    1.20 +  <!-- test code goes here -->
    1.21 +  <script type="application/javascript">
    1.22 +  <![CDATA[
    1.23 +
    1.24 +  /** Test for remapping Xray waivers during brain transplant. **/
    1.25 +  SimpleTest.waitForExplicitFinish();
    1.26 +  const Cu = Components.utils;
    1.27 +
    1.28 +  var gFramesLoaded = 0;
    1.29 +  function frameLoaded() {
    1.30 +    ++gFramesLoaded;
    1.31 +    if (gFramesLoaded == 2)
    1.32 +      startTest();
    1.33 +    if (gFramesLoaded == 3)
    1.34 +      finishTest();
    1.35 +  }
    1.36 +
    1.37 +  function startTest() {
    1.38 +    // grab the windows and the node.
    1.39 +    win1 = document.getElementById('frame1').contentWindow;
    1.40 +    win2 = document.getElementById('frame2').contentWindow;
    1.41 +    node1 = win1.document.getElementById('text');
    1.42 +    loc1 = win1.location;
    1.43 +
    1.44 +    // Grab some Xray waivers.
    1.45 +    win1Waiver = win1.wrappedJSObject;
    1.46 +    node1Waiver = node1.wrappedJSObject;
    1.47 +    loc1Waiver = win1Waiver.location;
    1.48 +
    1.49 +    // Adopt node1 into win2. This causes node1 to be transplanted.
    1.50 +    win2.document.adoptNode(node1);
    1.51 +
    1.52 +    // Navigate win1. This causes win1 to be transplanted.
    1.53 +    win1.location = 'http://test2.example.org/tests/js/xpconnect/tests/mochitest/file_empty.html';
    1.54 +
    1.55 +    // The above happens async. Our onload handler will call finishTest() when we're ready.
    1.56 +  }
    1.57 +
    1.58 +  function finishTest() {
    1.59 +    // Now, recompute some wrappers.
    1.60 +    Cu.recomputeWrappers();
    1.61 +
    1.62 +    // First, pat ourselves on the back for not asserting/crashing. That's most of
    1.63 +    // what we're really testing here.
    1.64 +    ok(true, "Didnt crash!");
    1.65 +
    1.66 +    // Now, make sure everything is set up how we expect.
    1.67 +    ok(win1Waiver === win1.wrappedJSObject, "waivers still work");
    1.68 +    ok(XPCNativeWrapper(win1Waiver) === win1, "waivers still work");
    1.69 +    ok(node1Waiver === node1.wrappedJSObject, "waivers still work");
    1.70 +    ok(XPCNativeWrapper(node1Waiver) === node1, "waivers still work");
    1.71 +
    1.72 +    // The semantics of location are tricky, because win1 now has a new location object.
    1.73 +    // In fact, loc1 should be a dead object proxy. Let's make sure we get this right.
    1.74 +    ok(loc1 !== win1.location, "navigation means different window.location");
    1.75 +    ok(loc1Waiver !== win1.location.wrappedJSObject, "navigation means different window.location");
    1.76 +
    1.77 +    // Whew.
    1.78 +    SimpleTest.finish();
    1.79 +  }
    1.80 +
    1.81 +  ]]>
    1.82 +  </script>
    1.83 +  <iframe id="frame1" onload="frameLoaded();" type="content" src="http://test1.example.org/tests/js/xpconnect/tests/mochitest/file_empty.html" />
    1.84 +  <iframe id="frame2" onload="frameLoaded();" type="content" src="http://test1.example.org/tests/js/xpconnect/tests/mochitest/file_empty.html" />
    1.85 +</window>

mercurial