|
1 <!DOCTYPE HTML> |
|
2 <html> |
|
3 <!-- |
|
4 https://bugzilla.mozilla.org/show_bug.cgi?id=914405 |
|
5 |
|
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> |
|
18 |
|
19 Components.utils.import("resource://gre/modules/jsdebugger.jsm"); |
|
20 addDebuggerToGlobal(this); |
|
21 |
|
22 window.onload = function () { |
|
23 SimpleTest.waitForExplicitFinish(); |
|
24 |
|
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); |
|
29 |
|
30 function iframeOnLoad() { |
|
31 var dbg = new Debugger; |
|
32 |
|
33 var g1o = iframe.contentWindow; // 'o' for 'outer window' |
|
34 ok(!dbg.hasDebuggee(g1o), "iframe is not initially a debuggee"); |
|
35 |
|
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 "); |
|
42 |
|
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"); |
|
48 |
|
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"); |
|
54 |
|
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"); |
|
59 |
|
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); |
|
64 |
|
65 function iframe2OnLoad() { |
|
66 // makeGlobalObjectReference dereferences CCWs. |
|
67 var g2o = iframe2.contentWindow; |
|
68 g2o.g1o = g1o; |
|
69 |
|
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"); |
|
77 |
|
78 SimpleTest.finish(); |
|
79 } |
|
80 } |
|
81 } |
|
82 |
|
83 </script> |
|
84 </pre> |
|
85 </body> |
|
86 </html> |