toolkit/devtools/server/tests/mochitest/test_makeGlobalObjectReference.html

Sat, 03 Jan 2015 20:18:00 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Sat, 03 Jan 2015 20:18:00 +0100
branch
TOR_BUG_3246
changeset 7
129ffea94266
permissions
-rw-r--r--

Conditionally enable double key logic according to:
private browsing mode or privacy.thirdparty.isolate preference and
implement in GetCookieStringCommon and FindCookie where it counts...
With some reservations of how to convince FindCookie users to test
condition and pass a nullptr when disabling double key logic.

     1 <!DOCTYPE HTML>
     2 <html>
     3 <!--
     4 https://bugzilla.mozilla.org/show_bug.cgi?id=914405
     6 Debugger.prototype.makeGlobalObjectReference should dereference WindowProxy
     7 (outer window) objects.
     8 -->
     9 <head>
    10   <meta charset="utf-8">
    11   <title>Mozilla Bug 914405</title>
    12   <script type="application/javascript" src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js"></script>
    13   <link rel="stylesheet" type="text/css" href="chrome://mochikit/content/tests/SimpleTest/test.css">
    14 </head>
    15 <body>
    16 <pre id="test">
    17 <script>
    19 Components.utils.import("resource://gre/modules/jsdebugger.jsm");
    20 addDebuggerToGlobal(this);
    22 window.onload = function () {
    23   SimpleTest.waitForExplicitFinish();
    25   var iframe = document.createElement("iframe");
    26   iframe.src = "data:text/html,<html>The word 'smorgasbord', spoken by an adorably plump child, symbolizing prosperity</html>";
    27   iframe.onload = iframeOnLoad;
    28   document.body.appendChild(iframe);
    30   function iframeOnLoad() {
    31     var dbg = new Debugger;
    33     var g1o = iframe.contentWindow; // 'o' for 'outer window'
    34     ok(!dbg.hasDebuggee(g1o), "iframe is not initially a debuggee");
    36     // Like addDebuggee, makeGlobalObjectReference innerizes.
    37     // 'i' stands for 'inner window'.
    38     // 'DO' stands for 'Debugger.Object'.
    39     var g1iDO = dbg.makeGlobalObjectReference(g1o);
    40     ok(!dbg.hasDebuggee(g1o), "makeGlobalObjectReference does not add g1 as debuggee, designated via outer");
    41     ok(!dbg.hasDebuggee(g1iDO), "makeGlobalObjectReference does not add g1 as debuggee, designated via D.O ");
    43     // Wrapping an object automatically outerizes it, so dereferencing an
    44     // inner object D.O gets you an outer object.
    45     // ('===' does distinguish inner and outer objects.)
    46     // (That's a capital '=', if you must know.)
    47     ok(g1iDO.unsafeDereference() === g1o, "g1iDO has the right referent");
    49     // However, Debugger.Objects do distinguish inner and outer windows.
    50     var g1oDO = g1iDO.makeDebuggeeValue(g1o);
    51     ok(g1iDO !== g1oDO, "makeDebuggeeValue doesn't innerize");
    52     ok(g1iDO.unsafeDereference() === g1oDO.unsafeDereference(),
    53        "unsafeDereference() outerizes, so inner and outer window D.Os both dereference to outer");
    55     ok(dbg.addDebuggee(g1o) === g1iDO, "addDebuggee returns the inner window's D.O");
    56     ok(dbg.hasDebuggee(g1o), "addDebuggee adds the correct global");
    57     ok(dbg.hasDebuggee(g1iDO), "hasDebuggee can take a D.O referring to the inner window");
    58     ok(dbg.hasDebuggee(g1oDO), "hasDebuggee can take a D.O referring to the outer window");
    60     var iframe2 = document.createElement("iframe");
    61     iframe2.src = "data:text/html,<html>Her retrospection, in hindsight, was prescient.</html>";
    62     iframe2.onload = iframe2OnLoad;
    63     document.body.appendChild(iframe2);
    65     function iframe2OnLoad() {
    66       // makeGlobalObjectReference dereferences CCWs.
    67       var g2o = iframe2.contentWindow;
    68       g2o.g1o = g1o;
    70       var g2iDO = dbg.addDebuggee(g2o);
    71       var g2g1oDO = g2iDO.getOwnPropertyDescriptor('g1o').value;
    72       ok(g2g1oDO !== g1oDO, "g2's cross-compartment wrapper for g1o gets its own D.O");
    73       ok(g2g1oDO.unwrap() === g1oDO,
    74          "unwrapping g2's cross-compartment wrapper for g1o gets the right D.O");
    75       ok(dbg.makeGlobalObjectReference(g2g1oDO) === g1iDO,
    76          "makeGlobalObjectReference unwraps cross-compartment wrappers, and innerizes");
    78       SimpleTest.finish();
    79     }
    80   }
    81 }
    83 </script>
    84 </pre>
    85 </body>
    86 </html>

mercurial