toolkit/devtools/server/tests/mochitest/test_inspector-mutations-childlist.html

Sat, 03 Jan 2015 20:18:00 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Sat, 03 Jan 2015 20:18:00 +0100
branch
TOR_BUG_3246
changeset 7
129ffea94266
permissions
-rw-r--r--

Conditionally enable double key logic according to:
private browsing mode or privacy.thirdparty.isolate preference and
implement in GetCookieStringCommon and FindCookie where it counts...
With some reservations of how to convince FindCookie users to test
condition and pass a nullptr when disabling double key logic.

michael@0 1 <!DOCTYPE HTML>
michael@0 2 <html>
michael@0 3 <!--
michael@0 4 https://bugzilla.mozilla.org/show_bug.cgi?id=
michael@0 5 -->
michael@0 6 <head>
michael@0 7 <meta charset="utf-8">
michael@0 8 <title>Test for Bug </title>
michael@0 9
michael@0 10 <script type="application/javascript" src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js"></script>
michael@0 11 <link rel="stylesheet" type="text/css" href="chrome://mochikit/content/tests/SimpleTest/test.css">
michael@0 12 <script type="application/javascript;version=1.8" src="inspector-helpers.js"></script>
michael@0 13 <script type="application/javascript;version=1.8">
michael@0 14 Components.utils.import("resource://gre/modules/devtools/Loader.jsm");
michael@0 15 const {Promise: promise} = Components.utils.import("resource://gre/modules/Promise.jsm", {});
michael@0 16
michael@0 17 const inspector = devtools.require("devtools/server/actors/inspector");
michael@0 18
michael@0 19 window.onload = function() {
michael@0 20 SimpleTest.waitForExplicitFinish();
michael@0 21 runNextTest();
michael@0 22 }
michael@0 23
michael@0 24 var gInspectee = null;
michael@0 25 var gWalker = null;
michael@0 26 var gClient = null;
michael@0 27 var gCleanupConnection = null;
michael@0 28
michael@0 29 function setup(callback) {
michael@0 30 let url = document.getElementById("inspectorContent").href;
michael@0 31 gCleanupConnection = attachURL(url, function(err, client, tab, doc) {
michael@0 32 gInspectee = doc;
michael@0 33 let {InspectorFront} = devtools.require("devtools/server/actors/inspector");
michael@0 34 let inspector = InspectorFront(client, tab);
michael@0 35 promiseDone(inspector.getWalker().then(walker => {
michael@0 36 gClient = client;
michael@0 37 gWalker = walker;
michael@0 38 }).then(callback));
michael@0 39 });
michael@0 40 }
michael@0 41
michael@0 42 function teardown() {
michael@0 43 gWalker = null;
michael@0 44 gClient = null;
michael@0 45 gInspectee = null;
michael@0 46 if (gCleanupConnection) {
michael@0 47 gCleanupConnection();
michael@0 48 gCleanupConnection = null;
michael@0 49 }
michael@0 50 }
michael@0 51
michael@0 52 function assertOwnership() {
michael@0 53 let num = assertOwnershipTrees(gWalker);
michael@0 54 }
michael@0 55
michael@0 56 function setParent(nodeSelector, newParentSelector) {
michael@0 57 let node = gInspectee.querySelector(nodeSelector);
michael@0 58 if (newParentSelector) {
michael@0 59 let newParent = gInspectee.querySelector(newParentSelector);
michael@0 60 newParent.appendChild(node);
michael@0 61 } else {
michael@0 62 node.parentNode.removeChild(node);
michael@0 63 }
michael@0 64 }
michael@0 65
michael@0 66 function loadSelector(selector) {
michael@0 67 return gWalker.querySelectorAll(gWalker.rootNode, selector).then(nodeList => {
michael@0 68 return nodeList.items();
michael@0 69 });
michael@0 70 }
michael@0 71
michael@0 72 function loadSelectors(selectors) {
michael@0 73 return promise.all([loadSelector(sel) for (sel of selectors)]);
michael@0 74 }
michael@0 75
michael@0 76 function doMoves(moves) {
michael@0 77 for (let move of moves) {
michael@0 78 setParent(move[0], move[1]);
michael@0 79 }
michael@0 80 }
michael@0 81
michael@0 82 /**
michael@0 83 * Test a set of tree rearrangements and make sure they cause the expected changes.
michael@0 84 */
michael@0 85
michael@0 86 var gDummySerial = 0;
michael@0 87
michael@0 88 function mutationTest(testSpec) {
michael@0 89 return function() {
michael@0 90 setup(() => {
michael@0 91 promiseDone(loadSelectors(testSpec.load || ["html"]).then(() => {
michael@0 92 gWalker.autoCleanup = !!testSpec.autoCleanup;
michael@0 93 if (testSpec.preCheck) {
michael@0 94 testSpec.preCheck();
michael@0 95 }
michael@0 96 doMoves(testSpec.moves || []);
michael@0 97
michael@0 98 // Some of these moves will trigger no mutation events,
michael@0 99 // so do a dummy change to the root node to trigger
michael@0 100 // a mutation event anyway.
michael@0 101 gInspectee.documentElement.setAttribute("data-dummy", gDummySerial++);
michael@0 102
michael@0 103 gWalker.once("mutations", (mutations) => {
michael@0 104 // Filter out our dummy mutation.
michael@0 105 let mutations = mutations.filter(change => {
michael@0 106 if (change.type == "attributes" &&
michael@0 107 change.attributeName == "data-dummy") {
michael@0 108 return false;
michael@0 109 }
michael@0 110 return true;
michael@0 111 });
michael@0 112 assertOwnership();
michael@0 113 if (testSpec.postCheck) {
michael@0 114 testSpec.postCheck(mutations);
michael@0 115 }
michael@0 116 teardown();
michael@0 117 runNextTest();
michael@0 118 });
michael@0 119 }));
michael@0 120 })
michael@0 121 }
michael@0 122 }
michael@0 123
michael@0 124 // Verify that our dummy mutation works.
michael@0 125 addTest(mutationTest({
michael@0 126 autoCleanup: false,
michael@0 127 postCheck: function(mutations) {
michael@0 128 is(mutations.length, 0, "Dummy mutation is filtered out.");
michael@0 129 }
michael@0 130 }));
michael@0 131
michael@0 132 // Test a simple move to a different location in the sibling list for the same
michael@0 133 // parent.
michael@0 134 addTest(mutationTest({
michael@0 135 autoCleanup: false,
michael@0 136 load: ["#longlist div"],
michael@0 137 moves: [
michael@0 138 ["#a", "#longlist"]
michael@0 139 ],
michael@0 140 postCheck: function(mutations) {
michael@0 141 let remove = mutations[0];
michael@0 142 is(remove.type, "childList", "First mutation should be a childList.")
michael@0 143 ok(remove.removed.length > 0, "First mutation should be a removal.")
michael@0 144 let add = mutations[1];
michael@0 145 is(add.type, "childList", "Second mutation should be a childList removal.")
michael@0 146 ok(add.added.length > 0, "Second mutation should be an addition.")
michael@0 147 let a = add.added[0];
michael@0 148 is(a.id, "a", "Added node should be #a");
michael@0 149 is(a.parentNode(), remove.target, "Should still be a child of longlist.");
michael@0 150 is(remove.target, add.target, "First and second mutations should be against the same node.");
michael@0 151 }
michael@0 152 }));
michael@0 153
michael@0 154 // Test a move to another location that is within our ownership tree.
michael@0 155 addTest(mutationTest({
michael@0 156 autoCleanup: false,
michael@0 157 load: ["#longlist div", "#longlist-sibling"],
michael@0 158 moves: [
michael@0 159 ["#a", "#longlist-sibling"]
michael@0 160 ],
michael@0 161 postCheck: function(mutations) {
michael@0 162 let remove = mutations[0];
michael@0 163 is(remove.type, "childList", "First mutation should be a childList.")
michael@0 164 ok(remove.removed.length > 0, "First mutation should be a removal.")
michael@0 165 let add = mutations[1];
michael@0 166 is(add.type, "childList", "Second mutation should be a childList removal.")
michael@0 167 ok(add.added.length > 0, "Second mutation should be an addition.")
michael@0 168 let a = add.added[0];
michael@0 169 is(a.id, "a", "Added node should be #a");
michael@0 170 is(a.parentNode(), add.target, "Should still be a child of longlist.");
michael@0 171 is(add.target.id, "longlist-sibling", "long-sibling should be the target.");
michael@0 172 }
michael@0 173 }));
michael@0 174
michael@0 175 // Move an unseen node with a seen parent into our ownership tree - should generate a
michael@0 176 // childList pair with no adds or removes.
michael@0 177 addTest(mutationTest({
michael@0 178 autoCleanup: false,
michael@0 179 load: ["#longlist"],
michael@0 180 moves: [
michael@0 181 ["#longlist-sibling", "#longlist"]
michael@0 182 ],
michael@0 183 postCheck: function(mutations) {
michael@0 184 is(mutations.length, 2, "Should generate two mutations");
michael@0 185 is(mutations[0].type, "childList", "Should be childList mutations.");
michael@0 186 is(mutations[0].added.length, 0, "Should have no adds.");
michael@0 187 is(mutations[0].removed.length, 0, "Should have no removes.");
michael@0 188 is(mutations[1].type, "childList", "Should be childList mutations.");
michael@0 189 is(mutations[1].added.length, 0, "Should have no adds.");
michael@0 190 is(mutations[1].removed.length, 0, "Should have no removes.");
michael@0 191 }
michael@0 192 }));
michael@0 193
michael@0 194 // Move an unseen node with an unseen parent into our ownership tree. Should only
michael@0 195 // generate one childList mutation with no adds or removes.
michael@0 196 addTest(mutationTest({
michael@0 197 autoCleanup: false,
michael@0 198 load: ["#longlist div"],
michael@0 199 moves: [
michael@0 200 ["#longlist-sibling-firstchild", "#longlist"]
michael@0 201 ],
michael@0 202 postCheck: function(mutations) {
michael@0 203 is(mutations.length, 1, "Should generate two mutations");
michael@0 204 is(mutations[0].type, "childList", "Should be childList mutations.");
michael@0 205 is(mutations[0].added.length, 0, "Should have no adds.");
michael@0 206 is(mutations[0].removed.length, 0, "Should have no removes.");
michael@0 207 }
michael@0 208 }));
michael@0 209
michael@0 210 // Move a node between unseen nodes, should generate no mutations.
michael@0 211 addTest(mutationTest({
michael@0 212 autoCleanup: false,
michael@0 213 load: ["html"],
michael@0 214 moves: [
michael@0 215 ["#longlist-sibling", "#longlist"]
michael@0 216 ],
michael@0 217 postCheck: function(mutations) {
michael@0 218 is(mutations.length, 0, "Should generate no mutations.");
michael@0 219 }
michael@0 220 }));
michael@0 221
michael@0 222 // Orphan a node and don't clean it up
michael@0 223 addTest(mutationTest({
michael@0 224 autoCleanup: false,
michael@0 225 load: ["#longlist div"],
michael@0 226 moves: [
michael@0 227 ["#longlist", null]
michael@0 228 ],
michael@0 229 postCheck: function(mutations) {
michael@0 230 is(mutations.length, 1, "Should generate one mutation.");
michael@0 231 let change = mutations[0];
michael@0 232 is(change.type, "childList", "Should be a childList.");
michael@0 233 is(change.removed.length, 1, "Should have removed a child.");
michael@0 234 let ownership = clientOwnershipTree(gWalker);
michael@0 235 is(ownership.orphaned.length, 1, "Should have one orphaned subtree.");
michael@0 236 is(ownershipTreeSize(ownership.orphaned[0]), 27, "Should have orphaned longlist and 26 children.");
michael@0 237 }
michael@0 238 }));
michael@0 239
michael@0 240 // Orphan a node, and do clean it up.
michael@0 241 addTest(mutationTest({
michael@0 242 autoCleanup: true,
michael@0 243 load: ["#longlist div"],
michael@0 244 moves: [
michael@0 245 ["#longlist", null]
michael@0 246 ],
michael@0 247 postCheck: function(mutations) {
michael@0 248 is(mutations.length, 1, "Should generate one mutation.");
michael@0 249 let change = mutations[0];
michael@0 250 is(change.type, "childList", "Should be a childList.");
michael@0 251 is(change.removed.length, 1, "Should have removed a child.");
michael@0 252 let ownership = clientOwnershipTree(gWalker);
michael@0 253 is(ownership.orphaned.length, 0, "Should have no orphaned subtrees.");
michael@0 254 }
michael@0 255 }));
michael@0 256
michael@0 257 // Orphan a node by moving it into the tree but out of our visible subtree.
michael@0 258 addTest(mutationTest({
michael@0 259 autoCleanup: false,
michael@0 260 load: ["#longlist div"],
michael@0 261 moves: [
michael@0 262 ["#longlist", "#longlist-sibling"]
michael@0 263 ],
michael@0 264 postCheck: function(mutations) {
michael@0 265 is(mutations.length, 1, "Should generate one mutation.");
michael@0 266 let change = mutations[0];
michael@0 267 is(change.type, "childList", "Should be a childList.");
michael@0 268 is(change.removed.length, 1, "Should have removed a child.");
michael@0 269 let ownership = clientOwnershipTree(gWalker);
michael@0 270 is(ownership.orphaned.length, 1, "Should have one orphaned subtree.");
michael@0 271 is(ownershipTreeSize(ownership.orphaned[0]), 27, "Should have orphaned longlist and 26 children.");
michael@0 272 }
michael@0 273 }));
michael@0 274
michael@0 275 // Orphan a node by moving it into the tree but out of our visible subtree, and clean it up.
michael@0 276 addTest(mutationTest({
michael@0 277 autoCleanup: true,
michael@0 278 load: ["#longlist div"],
michael@0 279 moves: [
michael@0 280 ["#longlist", "#longlist-sibling"]
michael@0 281 ],
michael@0 282 postCheck: function(mutations) {
michael@0 283 is(mutations.length, 1, "Should generate one mutation.");
michael@0 284 let change = mutations[0];
michael@0 285 is(change.type, "childList", "Should be a childList.");
michael@0 286 is(change.removed.length, 1, "Should have removed a child.");
michael@0 287 let ownership = clientOwnershipTree(gWalker);
michael@0 288 is(ownership.orphaned.length, 0, "Should have no orphaned subtrees.");
michael@0 289 }
michael@0 290 }));
michael@0 291
michael@0 292
michael@0 293 addTest(function cleanup() {
michael@0 294 delete gInspectee;
michael@0 295 delete gWalker;
michael@0 296 delete gClient;
michael@0 297 runNextTest();
michael@0 298 });
michael@0 299
michael@0 300
michael@0 301 </script>
michael@0 302 </head>
michael@0 303 <body>
michael@0 304 <a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=">Mozilla Bug </a>
michael@0 305 <a id="inspectorContent" target="_blank" href="inspector-traversal-data.html">Test Document</a>
michael@0 306 <p id="display"></p>
michael@0 307 <div id="content" style="display: none">
michael@0 308
michael@0 309 </div>
michael@0 310 <pre id="test">
michael@0 311 </pre>
michael@0 312 </body>
michael@0 313 </html>

mercurial