dom/ipc/tests/test_child_docshell.html

Thu, 22 Jan 2015 13:21:57 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Thu, 22 Jan 2015 13:21:57 +0100
branch
TOR_BUG_9701
changeset 15
b8a032363ba2
permissions
-rw-r--r--

Incorporate requested changes from Mozilla in review:
https://bugzilla.mozilla.org/show_bug.cgi?id=1123480#c6

michael@0 1 <!DOCTYPE HTML>
michael@0 2 <html>
michael@0 3 <!--
michael@0 4 -->
michael@0 5 <head>
michael@0 6 <script type="application/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
michael@0 7 <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/>
michael@0 8 </head>
michael@0 9 <body>
michael@0 10
michael@0 11 <script type="application/javascript;version=1.7">
michael@0 12 "use strict";
michael@0 13
michael@0 14 SimpleTest.waitForExplicitFinish();
michael@0 15 SpecialPowers.addPermission("browser", true, document);
michael@0 16 SpecialPowers.pushPrefEnv({'set':[
michael@0 17 ["dom.mozBrowserFramesEnabled", true],
michael@0 18 ["dom.ipc.tabs.disabled", false]
michael@0 19 ]}, function () {
michael@0 20
michael@0 21 var iframe = document.createElementNS('http://www.w3.org/1999/xhtml', 'iframe');
michael@0 22 iframe.setAttribute("remote", "true");
michael@0 23 SpecialPowers.wrap(iframe).mozbrowser = true;
michael@0 24 document.documentElement.appendChild(iframe);
michael@0 25
michael@0 26 var mm = SpecialPowers.getBrowserFrameMessageManager(iframe);
michael@0 27 mm.addMessageListener("chromeEventHandler", function (msg) {
michael@0 28 msg = SpecialPowers.wrap(msg);
michael@0 29 var result = msg.json;
michael@0 30 is(result.processType, SpecialPowers.Ci.nsIXULRuntime.PROCESS_TYPE_CONTENT,
michael@0 31 "The frame script is running in a real distinct child process");
michael@0 32 ok(result.hasCorrectInterface,
michael@0 33 "docshell.chromeEventHandler has nsIDOMEventTarget interface");
michael@0 34 });
michael@0 35
michael@0 36
michael@0 37 mm.addMessageListener("DOMWindowCreatedReceived", function (msg) {
michael@0 38 msg = SpecialPowers.wrap(msg);
michael@0 39 ok(true, "the chrome event handler looks functional");
michael@0 40 var result = msg.json;
michael@0 41 ok(result.stableChromeEventHandler, "docShell.chromeEventHandler is stable");
michael@0 42 ok(result.iframeHasNewDocShell, "iframe spawns a new docShell");
michael@0 43 ok(result.iframeHasSameChromeEventHandler, "but iframe has the same chrome event handler");
michael@0 44 SimpleTest.finish();
michael@0 45 });
michael@0 46 // Inject a frame script in the child process:
michael@0 47 mm.loadFrameScript('data:,new ' + function ContentScriptScope() {
michael@0 48 var processType = Components.classes["@mozilla.org/xre/runtime;1"]
michael@0 49 .getService(Components.interfaces.nsIXULRuntime)
michael@0 50 .processType;
michael@0 51 var chromeEventHandler = docShell.chromeEventHandler;
michael@0 52 sendAsyncMessage("chromeEventHandler", {
michael@0 53 processType: Services.appinfo.processType,
michael@0 54 hasCorrectInterface: chromeEventHandler instanceof Components.interfaces.nsIDOMEventTarget
michael@0 55 });
michael@0 56
michael@0 57 /*
michael@0 58 Ensure that this chromeEventHandler actually works,
michael@0 59 by creating a new window and listening for its DOMWindowCreated event
michael@0 60 */
michael@0 61 chromeEventHandler.addEventListener("DOMWindowCreated", function listener(evt) {
michael@0 62 if (evt.target == content.document) {
michael@0 63 return;
michael@0 64 }
michael@0 65 chromeEventHandler.removeEventListener("DOMWindowCreated", listener);
michael@0 66 let new_win = evt.target.defaultView;
michael@0 67 let new_docShell = new_win.QueryInterface(Ci.nsIInterfaceRequestor)
michael@0 68 .getInterface(Ci.nsIWebNavigation)
michael@0 69 .QueryInterface(Ci.nsIDocShell);
michael@0 70 sendAsyncMessage("DOMWindowCreatedReceived", {
michael@0 71 stableChromeEventHandler: chromeEventHandler === docShell.chromeEventHandler,
michael@0 72 iframeHasNewDocShell: new_docShell !== docShell,
michael@0 73 iframeHasSameChromeEventHandler: new_docShell.chromeEventHandler === chromeEventHandler
michael@0 74 });
michael@0 75 });
michael@0 76
michael@0 77 let i = content.document.createElement("iframe");
michael@0 78 i.setAttribute("src", "data:text/html,foo");
michael@0 79 content.document.documentElement.appendChild(i);
michael@0 80 }, false);
michael@0 81 });
michael@0 82
michael@0 83 </script>
michael@0 84 </body>
michael@0 85 </html>

mercurial