toolkit/devtools/server/tests/mochitest/test_evalInGlobal-outerized_this.html

Wed, 31 Dec 2014 06:09:35 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:09:35 +0100
changeset 0
6474c204b198
permissions
-rw-r--r--

Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.

michael@0 1 <!DOCTYPE HTML>
michael@0 2 <html>
michael@0 3 <!--
michael@0 4 https://bugzilla.mozilla.org/show_bug.cgi?id=837060
michael@0 5
michael@0 6 When we use Debugger.Object.prototype.evalInGlobal, the 'this' value seen
michael@0 7 by the evaluated code should be the WindowProxy, not the inner window
michael@0 8 object.
michael@0 9 -->
michael@0 10 <head>
michael@0 11 <meta charset="utf-8">
michael@0 12 <title>Mozilla Bug 837060</title>
michael@0 13 <script type="application/javascript" src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js"></script>
michael@0 14 <link rel="stylesheet" type="text/css" href="chrome://mochikit/content/tests/SimpleTest/test.css">
michael@0 15 </head>
michael@0 16 <body>
michael@0 17 <pre id="test">
michael@0 18 <script>
michael@0 19
michael@0 20 Components.utils.import("resource://gre/modules/jsdebugger.jsm");
michael@0 21 addDebuggerToGlobal(this);
michael@0 22
michael@0 23 window.onload = function () {
michael@0 24 SimpleTest.waitForExplicitFinish();
michael@0 25
michael@0 26 var iframe = document.createElement("iframe");
michael@0 27 iframe.src = "data:text/html,<script>var me = 'page 1';<\/script>";
michael@0 28 iframe.onload = firstOnLoadHandler;
michael@0 29 document.body.appendChild(iframe);
michael@0 30
michael@0 31 function firstOnLoadHandler() {
michael@0 32 var dbg = new Debugger;
michael@0 33 var page1DO = dbg.addDebuggee(iframe.contentWindow);
michael@0 34 iframe.src = "data:text/html,<script>var me = 'page 2';<\/script>";
michael@0 35 iframe.onload = function () {
michael@0 36 var page2DO = dbg.addDebuggee(iframe.contentWindow);
michael@0 37 ok(page1DO !== page2DO, "the two pages' globals get distinct D.O's");
michael@0 38 ok(page1DO.unsafeDereference() === page2DO.unsafeDereference(),
michael@0 39 "unwrapping page1DO and page2DO outerizes both, yielding the same outer window");
michael@0 40
michael@0 41 is(page1DO.evalInGlobal('me').return, 'page 1', "page1DO continues to refer to original page");
michael@0 42 is(page2DO.evalInGlobal('me').return, 'page 2', "page2DO refers to current page");
michael@0 43
michael@0 44 is(page1DO.evalInGlobal('this === window').return, true,
michael@0 45 "page 1: Debugger.Object.prototype.evalInGlobal should outerize 'this'");
michael@0 46 is(page1DO.evalInGlobalWithBindings('this === window', {x:2}).return, true,
michael@0 47 "page 1: Debugger.Object.prototype.evalInGlobal should outerize 'this'");
michael@0 48
michael@0 49 is(page2DO.evalInGlobal('this === window').return, true,
michael@0 50 "page 2: Debugger.Object.prototype.evalInGlobal should outerize 'this'");
michael@0 51 is(page2DO.evalInGlobalWithBindings('this === window', {x:2}).return, true,
michael@0 52 "page 2: Debugger.Object.prototype.evalInGlobal should outerize 'this'");
michael@0 53
michael@0 54 // Debugger doesn't let one use outer windows as globals. You have to innerize.
michael@0 55 var outerDO = page1DO.makeDebuggeeValue(page1DO.unsafeDereference());
michael@0 56 ok(outerDO !== page1DO, "outer window gets its own D.O, distinct from page 1's global");
michael@0 57 ok(outerDO !== page2DO, "outer window gets its own D.O, distinct from page 2's global");
michael@0 58 SimpleTest.doesThrow(function () { outerDO.evalInGlobal('me'); },
michael@0 59 "outer window D.Os can't be used as globals");
michael@0 60
michael@0 61 SimpleTest.finish();
michael@0 62 }
michael@0 63 }
michael@0 64 }
michael@0 65
michael@0 66 </script>
michael@0 67 </pre>
michael@0 68 </body>
michael@0 69 </html>

mercurial