1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/toolkit/devtools/server/tests/mochitest/test_makeGlobalObjectReference.html Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,86 @@ 1.4 +<!DOCTYPE HTML> 1.5 +<html> 1.6 +<!-- 1.7 +https://bugzilla.mozilla.org/show_bug.cgi?id=914405 1.8 + 1.9 +Debugger.prototype.makeGlobalObjectReference should dereference WindowProxy 1.10 +(outer window) objects. 1.11 +--> 1.12 +<head> 1.13 + <meta charset="utf-8"> 1.14 + <title>Mozilla Bug 914405</title> 1.15 + <script type="application/javascript" src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js"></script> 1.16 + <link rel="stylesheet" type="text/css" href="chrome://mochikit/content/tests/SimpleTest/test.css"> 1.17 +</head> 1.18 +<body> 1.19 +<pre id="test"> 1.20 +<script> 1.21 + 1.22 +Components.utils.import("resource://gre/modules/jsdebugger.jsm"); 1.23 +addDebuggerToGlobal(this); 1.24 + 1.25 +window.onload = function () { 1.26 + SimpleTest.waitForExplicitFinish(); 1.27 + 1.28 + var iframe = document.createElement("iframe"); 1.29 + iframe.src = "data:text/html,<html>The word 'smorgasbord', spoken by an adorably plump child, symbolizing prosperity</html>"; 1.30 + iframe.onload = iframeOnLoad; 1.31 + document.body.appendChild(iframe); 1.32 + 1.33 + function iframeOnLoad() { 1.34 + var dbg = new Debugger; 1.35 + 1.36 + var g1o = iframe.contentWindow; // 'o' for 'outer window' 1.37 + ok(!dbg.hasDebuggee(g1o), "iframe is not initially a debuggee"); 1.38 + 1.39 + // Like addDebuggee, makeGlobalObjectReference innerizes. 1.40 + // 'i' stands for 'inner window'. 1.41 + // 'DO' stands for 'Debugger.Object'. 1.42 + var g1iDO = dbg.makeGlobalObjectReference(g1o); 1.43 + ok(!dbg.hasDebuggee(g1o), "makeGlobalObjectReference does not add g1 as debuggee, designated via outer"); 1.44 + ok(!dbg.hasDebuggee(g1iDO), "makeGlobalObjectReference does not add g1 as debuggee, designated via D.O "); 1.45 + 1.46 + // Wrapping an object automatically outerizes it, so dereferencing an 1.47 + // inner object D.O gets you an outer object. 1.48 + // ('===' does distinguish inner and outer objects.) 1.49 + // (That's a capital '=', if you must know.) 1.50 + ok(g1iDO.unsafeDereference() === g1o, "g1iDO has the right referent"); 1.51 + 1.52 + // However, Debugger.Objects do distinguish inner and outer windows. 1.53 + var g1oDO = g1iDO.makeDebuggeeValue(g1o); 1.54 + ok(g1iDO !== g1oDO, "makeDebuggeeValue doesn't innerize"); 1.55 + ok(g1iDO.unsafeDereference() === g1oDO.unsafeDereference(), 1.56 + "unsafeDereference() outerizes, so inner and outer window D.Os both dereference to outer"); 1.57 + 1.58 + ok(dbg.addDebuggee(g1o) === g1iDO, "addDebuggee returns the inner window's D.O"); 1.59 + ok(dbg.hasDebuggee(g1o), "addDebuggee adds the correct global"); 1.60 + ok(dbg.hasDebuggee(g1iDO), "hasDebuggee can take a D.O referring to the inner window"); 1.61 + ok(dbg.hasDebuggee(g1oDO), "hasDebuggee can take a D.O referring to the outer window"); 1.62 + 1.63 + var iframe2 = document.createElement("iframe"); 1.64 + iframe2.src = "data:text/html,<html>Her retrospection, in hindsight, was prescient.</html>"; 1.65 + iframe2.onload = iframe2OnLoad; 1.66 + document.body.appendChild(iframe2); 1.67 + 1.68 + function iframe2OnLoad() { 1.69 + // makeGlobalObjectReference dereferences CCWs. 1.70 + var g2o = iframe2.contentWindow; 1.71 + g2o.g1o = g1o; 1.72 + 1.73 + var g2iDO = dbg.addDebuggee(g2o); 1.74 + var g2g1oDO = g2iDO.getOwnPropertyDescriptor('g1o').value; 1.75 + ok(g2g1oDO !== g1oDO, "g2's cross-compartment wrapper for g1o gets its own D.O"); 1.76 + ok(g2g1oDO.unwrap() === g1oDO, 1.77 + "unwrapping g2's cross-compartment wrapper for g1o gets the right D.O"); 1.78 + ok(dbg.makeGlobalObjectReference(g2g1oDO) === g1iDO, 1.79 + "makeGlobalObjectReference unwraps cross-compartment wrappers, and innerizes"); 1.80 + 1.81 + SimpleTest.finish(); 1.82 + } 1.83 + } 1.84 +} 1.85 + 1.86 +</script> 1.87 +</pre> 1.88 +</body> 1.89 +</html>