1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/toolkit/devtools/server/tests/mochitest/test_inspector-mutations-frameload.html Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,217 @@ 1.4 +<!DOCTYPE HTML> 1.5 +<html> 1.6 +<!-- 1.7 +https://bugzilla.mozilla.org/show_bug.cgi?id= 1.8 +--> 1.9 +<head> 1.10 + <meta charset="utf-8"> 1.11 + <title>Test for Bug </title> 1.12 + 1.13 + <script type="application/javascript" src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js"></script> 1.14 + <link rel="stylesheet" type="text/css" href="chrome://mochikit/content/tests/SimpleTest/test.css"> 1.15 + <script type="application/javascript;version=1.8" src="inspector-helpers.js"></script> 1.16 + <script type="application/javascript;version=1.8"> 1.17 +Components.utils.import("resource://gre/modules/devtools/Loader.jsm"); 1.18 +const {Promise: promise} = Components.utils.import("resource://gre/modules/Promise.jsm", {}); 1.19 + 1.20 +const inspector = devtools.require("devtools/server/actors/inspector"); 1.21 + 1.22 +window.onload = function() { 1.23 + SimpleTest.waitForExplicitFinish(); 1.24 + runNextTest(); 1.25 +} 1.26 + 1.27 +var gInspectee = null; 1.28 +var gWalker = null; 1.29 +var gClient = null; 1.30 +var gChildFrame = null; 1.31 +var gChildDocument = null; 1.32 +var gCleanupConnection = null; 1.33 + 1.34 +function setup(callback) { 1.35 + let url = document.getElementById("inspectorContent").href; 1.36 + gCleanupConnection = attachURL(url, function(err, client, tab, doc) { 1.37 + gInspectee = doc; 1.38 + let {InspectorFront} = devtools.require("devtools/server/actors/inspector"); 1.39 + let inspector = InspectorFront(client, tab); 1.40 + promiseDone(inspector.getWalker().then(walker => { 1.41 + gClient = client; 1.42 + gWalker = walker; 1.43 + }).then(callback)); 1.44 + }); 1.45 +} 1.46 + 1.47 +function teardown() { 1.48 + gWalker = null; 1.49 + gClient = null; 1.50 + gInspectee = null; 1.51 + gChildFrame = null; 1.52 + if (gCleanupConnection) { 1.53 + gCleanupConnection(); 1.54 + gCleanupConnection = null; 1.55 + } 1.56 +} 1.57 + 1.58 +function assertOwnership() { 1.59 + return assertOwnershipTrees(gWalker); 1.60 +} 1.61 + 1.62 +function loadChildSelector(selector) { 1.63 + return gWalker.querySelector(gWalker.rootNode, "#childFrame").then(frame => { 1.64 + ok(frame.numChildren > 0, "Child frame should consider its loaded document as a child."); 1.65 + gChildFrame = frame; 1.66 + return gWalker.children(frame); 1.67 + }).then(children => { 1.68 + return gWalker.querySelectorAll(children.nodes[0], selector); 1.69 + }).then(nodeList => { 1.70 + return nodeList.items(); 1.71 + }); 1.72 +} 1.73 + 1.74 +function getUnloadedDoc(mutations) { 1.75 + for (let change of mutations) { 1.76 + if (isUnload(change)) { 1.77 + return change.target; 1.78 + } 1.79 + } 1.80 + return null; 1.81 +} 1.82 + 1.83 +addTest(function loadNewChild() { 1.84 + setup(() => { 1.85 + let beforeUnloadSize = 0; 1.86 + // Load a bunch of fronts for actors inside the child frame. 1.87 + promiseDone(loadChildSelector("#longlist div").then(() => { 1.88 + let childFrame = gInspectee.querySelector("#childFrame"); 1.89 + childFrame.src = "data:text/html,<html>new child</html>"; 1.90 + return waitForMutation(gWalker, isChildList); 1.91 + }).then(mutations => { 1.92 + let unloaded = getUnloadedDoc(mutations); 1.93 + mutations = assertSrcChange(mutations); 1.94 + mutations = assertUnload(mutations); 1.95 + mutations = assertFrameLoad(mutations); 1.96 + mutations = assertChildList(mutations); 1.97 + 1.98 + is(mutations.length, 0, "Got the expected mutations."); 1.99 + 1.100 + assertOwnership(); 1.101 + 1.102 + return checkMissing(gClient, unloaded); 1.103 + }).then(() => { 1.104 + teardown(); 1.105 + }).then(runNextTest)); 1.106 + }); 1.107 +}); 1.108 + 1.109 +addTest(function loadNewChildTwice() { 1.110 + setup(() => { 1.111 + let beforeUnloadSize = 0; 1.112 + // Load a bunch of fronts for actors inside the child frame. 1.113 + promiseDone(loadChildSelector("#longlist div").then(() => { 1.114 + let childFrame = gInspectee.querySelector("#childFrame"); 1.115 + childFrame.src = "data:text/html,<html>new child</html>"; 1.116 + return waitForMutation(gWalker, isChildList); 1.117 + }).then(mutations => { 1.118 + // The first load went through as expected (as tested in loadNewChild) 1.119 + // Now change the source again, but this time we *don't* expect 1.120 + // an unload, because we haven't seen the new child document yet. 1.121 + let childFrame = gInspectee.querySelector("#childFrame"); 1.122 + childFrame.src = "data:text/html,<html>second new child</html>"; 1.123 + return waitForMutation(gWalker, isChildList); 1.124 + }).then(mutations => { 1.125 + mutations = assertSrcChange(mutations); 1.126 + mutations = assertFrameLoad(mutations); 1.127 + mutations = assertChildList(mutations); 1.128 + ok(!getUnloadedDoc(mutations), "Should not have gotten an unload."); 1.129 + 1.130 + is(mutations.length, 0, "Got the expected mutations."); 1.131 + 1.132 + assertOwnership(); 1.133 + }).then(() => { 1.134 + teardown(); 1.135 + }).then(runNextTest)); 1.136 + }); 1.137 +}); 1.138 + 1.139 + 1.140 +addTest(function loadNewChildTwiceAndCareAboutIt() { 1.141 + setup(() => { 1.142 + let beforeUnloadSize = 0; 1.143 + // Load a bunch of fronts for actors inside the child frame. 1.144 + promiseDone(loadChildSelector("#longlist div").then(() => { 1.145 + let childFrame = gInspectee.querySelector("#childFrame"); 1.146 + childFrame.src = "data:text/html,<html>new child</html>"; 1.147 + return waitForMutation(gWalker, isChildList); 1.148 + }).then(mutations => { 1.149 + // Read the new child 1.150 + return loadChildSelector("#longlist div"); 1.151 + }).then(() => { 1.152 + // Now change the source again, and expect the same results as loadNewChild. 1.153 + let childFrame = gInspectee.querySelector("#childFrame"); 1.154 + childFrame.src = "data:text/html,<html>second new child</html>"; 1.155 + return waitForMutation(gWalker, isChildList); 1.156 + }).then(mutations => { 1.157 + let unloaded = getUnloadedDoc(mutations); 1.158 + 1.159 + mutations = assertSrcChange(mutations); 1.160 + mutations = assertUnload(mutations); 1.161 + mutations = assertFrameLoad(mutations); 1.162 + mutations = assertChildList(mutations); 1.163 + 1.164 + is(mutations.length, 0, "Got the expected mutations."); 1.165 + 1.166 + assertOwnership(); 1.167 + 1.168 + return checkMissing(gClient, unloaded); 1.169 + }).then(() => { 1.170 + teardown(); 1.171 + }).then(runNextTest)); 1.172 + }); 1.173 +}); 1.174 + 1.175 +addTest(function testBack() { 1.176 + setup(() => { 1.177 + let beforeUnloadSize = 0; 1.178 + // Load a bunch of fronts for actors inside the child frame. 1.179 + promiseDone(loadChildSelector("#longlist div").then(() => { 1.180 + let childFrame = gInspectee.querySelector("#childFrame"); 1.181 + childFrame.src = "data:text/html,<html>new child</html>"; 1.182 + return waitForMutation(gWalker, isChildList); 1.183 + }).then(mutations => { 1.184 + // Read the new child 1.185 + return loadChildSelector("#longlist div"); 1.186 + }).then(() => { 1.187 + // Now use history.back to change the source, and expect the same results as loadNewChild. 1.188 + let childFrame = gInspectee.querySelector("#childFrame"); 1.189 + childFrame.contentWindow.history.back(); 1.190 + return waitForMutation(gWalker, isChildList); 1.191 + }).then(mutations => { 1.192 + let unloaded = getUnloadedDoc(mutations); 1.193 + mutations = assertSrcChange(mutations); 1.194 + mutations = assertUnload(mutations); 1.195 + mutations = assertFrameLoad(mutations); 1.196 + mutations = assertChildList(mutations); 1.197 + is(mutations.length, 0, "Got the expected mutations."); 1.198 + 1.199 + assertOwnership(); 1.200 + 1.201 + return checkMissing(gClient, unloaded); 1.202 + }).then(() => { 1.203 + teardown(); 1.204 + }).then(runNextTest)); 1.205 + }); 1.206 +}); 1.207 + 1.208 + </script> 1.209 +</head> 1.210 +<body> 1.211 +<a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=">Mozilla Bug </a> 1.212 +<a id="inspectorContent" target="_blank" href="inspector-traversal-data.html">Test Document</a> 1.213 +<p id="display"></p> 1.214 +<div id="content" style="display: none"> 1.215 + 1.216 +</div> 1.217 +<pre id="test"> 1.218 +</pre> 1.219 +</body> 1.220 +</html>