1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/dom/tests/mochitest/chrome/test_docshell_swap.xul Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,76 @@ 1.4 +<?xml version="1.0"?> 1.5 +<?xml-stylesheet type="text/css" href="chrome://global/skin"?> 1.6 +<?xml-stylesheet type="text/css" href="chrome://mochikit/content/tests/SimpleTest/test.css"?> 1.7 +<window title="Docshell swap test" 1.8 + xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul"> 1.9 + <script type="application/javascript" src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js"/> 1.10 + 1.11 + <!-- test results are displayed in the html:body --> 1.12 + <body xmlns="http://www.w3.org/1999/xhtml"> 1.13 + 1.14 + </body> 1.15 + 1.16 + <!-- test code goes here --> 1.17 + <script type="application/javascript"> 1.18 + <![CDATA[ 1.19 + 1.20 + SimpleTest.waitForExplicitFinish(); 1.21 + 1.22 + // Create two identical windows, each with a <browser> element. 1.23 + let win1 = window.openDialog("window_docshell_swap.xul", "_blank","chrome,width=300,height=200"); 1.24 + let win2 = window.openDialog("window_docshell_swap.xul", "_blank","chrome,width=300,height=200"); 1.25 + 1.26 + let loadCount = 0; 1.27 + function loadHandler() { 1.28 + loadCount++; 1.29 + if (loadCount < 2) 1.30 + return; 1.31 + 1.32 + let browser1 = win1.document.getElementById("browser"); 1.33 + let browser2 = win2.document.getElementById("browser"); 1.34 + 1.35 + let flo1 = browser1.QueryInterface(Components.interfaces.nsIFrameLoaderOwner); 1.36 + let flo2 = browser2.QueryInterface(Components.interfaces.nsIFrameLoaderOwner); 1.37 + 1.38 + let pongCount = 0; 1.39 + 1.40 + function gotPong(target_ok) { 1.41 + pongCount++; 1.42 + ok(target_ok, "message went to correct target"); 1.43 + if (pongCount == 1) { 1.44 + win1.close(); 1.45 + win2.close(); 1.46 + SimpleTest.finish(); 1.47 + } 1.48 + } 1.49 + 1.50 + let mm1 = flo1.frameLoader.messageManager; 1.51 + let mm2 = flo2.frameLoader.messageManager; 1.52 + mm1.addMessageListener("pong", () => { gotPong(true); }); 1.53 + mm2.addMessageListener("pong", () => { gotPong(false); }); 1.54 + 1.55 + // Swap docshells. Everything should be identical to before, since there was nothing to 1.56 + // distinguish these docshells. 1.57 + flo1.swapFrameLoaders(flo2); 1.58 + 1.59 + // mm1 shouldn't change here, but we update it in case it does due to a bug. 1.60 + mm1 = flo1.frameLoader.messageManager; 1.61 + 1.62 + // Load ping-pong code into first window. 1.63 + mm1.loadFrameScript("data:,addMessageListener('ping', () => sendAsyncMessage('pong'));", false); 1.64 + 1.65 + // A pong message received in win1 means success. 1.66 + win1.messageManager.addMessageListener("pong", () => { gotPong(true); }); 1.67 + 1.68 + // A pong message received in win2 means failure! 1.69 + win2.messageManager.addMessageListener("pong", () => { gotPong(false); }); 1.70 + 1.71 + // Send the ping to win1. 1.72 + mm1.sendAsyncMessage("ping"); 1.73 + } 1.74 + 1.75 + win1.addEventListener("load", loadHandler, false); 1.76 + win2.addEventListener("load", loadHandler, false); 1.77 + ]]> 1.78 + </script> 1.79 +</window>