toolkit/devtools/server/tests/mochitest/test_inspector-traversal.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 gClient = null;
michael@0 26 var gWalker = null;
michael@0 27 var checkActorIDs = [];
michael@0 28
michael@0 29 function assertOwnership() {
michael@0 30 assertOwnershipTrees(gWalker);
michael@0 31 }
michael@0 32 addTest(function setup() {
michael@0 33 let url = document.getElementById("inspectorContent").href;
michael@0 34 attachURL(url, function(err, client, tab, doc) {
michael@0 35 gInspectee = doc;
michael@0 36 let {InspectorFront} = devtools.require("devtools/server/actors/inspector");
michael@0 37 let inspector = InspectorFront(client, tab);
michael@0 38 promiseDone(inspector.getWalker().then(walker => {
michael@0 39 ok(walker, "getWalker() should return an actor.");
michael@0 40 gClient = client;
michael@0 41 gWalker = walker;
michael@0 42 }).then(runNextTest));
michael@0 43 });
michael@0 44 });
michael@0 45
michael@0 46 addTest(function testWalkerRoot() {
michael@0 47 // Make sure that refetching the root document of the walker returns the same
michael@0 48 // actor as the getWalker returned.
michael@0 49 promiseDone(gWalker.document().then(root => {
michael@0 50 ok(root === gWalker.rootNode, "Re-fetching the document node should match the root document node.");
michael@0 51 checkActorIDs.push(root.actorID);
michael@0 52 assertOwnership();
michael@0 53 }).then(runNextTest));
michael@0 54 });
michael@0 55
michael@0 56 addTest(function testInnerHTML() {
michael@0 57 promiseDone(gWalker.documentElement().then(docElement => {
michael@0 58 return gWalker.innerHTML(docElement);
michael@0 59 }).then(longstring => {
michael@0 60 return longstring.string();
michael@0 61 }).then(innerHTML => {
michael@0 62 ok(innerHTML === gInspectee.documentElement.innerHTML, "innerHTML should match");
michael@0 63 }).then(runNextTest));
michael@0 64 });
michael@0 65
michael@0 66 addTest(function testOuterHTML() {
michael@0 67 promiseDone(gWalker.documentElement().then(docElement => {
michael@0 68 return gWalker.outerHTML(docElement);
michael@0 69 }).then(longstring => {
michael@0 70 return longstring.string();
michael@0 71 }).then(outerHTML => {
michael@0 72 ok(outerHTML === gInspectee.documentElement.outerHTML, "outerHTML should match");
michael@0 73 }).then(runNextTest));
michael@0 74 });
michael@0 75
michael@0 76 addTest(function testSetOuterHTMLNode() {
michael@0 77 let newHTML = "<p id=\"edit-html-done\">after edit</p>";
michael@0 78 promiseDone(gWalker.querySelector(gWalker.rootNode, "#edit-html").then(node => {
michael@0 79 return gWalker.setOuterHTML(node, newHTML);
michael@0 80 }).then(() => {
michael@0 81 return gWalker.querySelector(gWalker.rootNode, "#edit-html-done");
michael@0 82 }).then(node => {
michael@0 83 return gWalker.outerHTML(node);
michael@0 84 }).then(longstring => {
michael@0 85 return longstring.string();
michael@0 86 }).then(outerHTML => {
michael@0 87 is(outerHTML, newHTML, "outerHTML has been updated");
michael@0 88 }).then(() => {
michael@0 89 return gWalker.querySelector(gWalker.rootNode, "#edit-html");
michael@0 90 }).then(node => {
michael@0 91 ok(!node, "The node with the old ID cannot be selected anymore");
michael@0 92 }).then(runNextTest));
michael@0 93 });
michael@0 94
michael@0 95 addTest(function testQuerySelector() {
michael@0 96 promiseDone(gWalker.querySelector(gWalker.rootNode, "#longlist").then(node => {
michael@0 97 is(node.getAttribute("data-test"), "exists", "should have found the right node");
michael@0 98 assertOwnership();
michael@0 99 }).then(() => {
michael@0 100 return gWalker.querySelector(gWalker.rootNode, "unknownqueryselector").then(node => {
michael@0 101 ok(!node, "Should not find a node here.");
michael@0 102 assertOwnership();
michael@0 103 });
michael@0 104 }).then(runNextTest));
michael@0 105 });
michael@0 106
michael@0 107 addTest(function testQuerySelectors() {
michael@0 108 let nodeList = null;
michael@0 109 let firstNode = null;
michael@0 110 let nodeListID = null;
michael@0 111 promiseDone(gWalker.querySelectorAll(gWalker.rootNode, "#longlist div").then(list => {
michael@0 112 nodeList = list;
michael@0 113 is(nodeList.length, 26, "Expect 26 div children.");
michael@0 114 assertOwnership();
michael@0 115 return nodeList.item(0);
michael@0 116 }).then(node => {
michael@0 117 firstNode = node;
michael@0 118 checkActorIDs.push(node.actorID);
michael@0 119 is(node.id, "a", "First child should be a");
michael@0 120 assertOwnership();
michael@0 121 return nodeList.items();
michael@0 122 }).then(nodes => {
michael@0 123 is(nodes.length, 26, "Expect 26 nodes");
michael@0 124 is(nodes[0], firstNode, "First node should be reused.");
michael@0 125 ok(nodes[0]._parent, "Parent node should be set.");
michael@0 126 ok(nodes[0]._next || nodes[0]._prev, "Siblings should be set.");
michael@0 127 ok(nodes[25]._next || nodes[25]._prev, "Siblings of " + nodes[25] + " should be set.");
michael@0 128 assertOwnership();
michael@0 129 return nodeList.items(-1);
michael@0 130 }).then(nodes => {
michael@0 131 is(nodes.length, 1, "Expect 1 node")
michael@0 132 is(nodes[0].id, "z", "Expect it to be the last node.");
michael@0 133 checkActorIDs.push(nodes[0].actorID);
michael@0 134 // Save the node list ID so we can ensure it was destroyed.
michael@0 135 nodeListID = nodeList.actorID;
michael@0 136 assertOwnership();
michael@0 137 return nodeList.release();
michael@0 138 }).then(() => {
michael@0 139 ok(!nodeList.actorID, "Actor should have been destroyed.");
michael@0 140 assertOwnership();
michael@0 141 return checkMissing(gClient, nodeListID);
michael@0 142 }).then(runNextTest));
michael@0 143 });
michael@0 144
michael@0 145 // Helper to check the response of requests that return hasFirst/hasLast/nodes
michael@0 146 // node lists (like `children` and `siblings`)
michael@0 147 function nodeArrayChecker(first, last, ids) {
michael@0 148 return function(response) {
michael@0 149 is(response.hasFirst, first, "Should " + (first ? "" : "not ") + " have the first node.");
michael@0 150 is(response.hasLast, last, "Should " + (last ? "" : "not ") + " have the last node.");
michael@0 151 is(response.nodes.length, ids.length, "Should have " + ids.length + " children listed.");
michael@0 152 let responseIds = '';
michael@0 153 for (node of response.nodes) {
michael@0 154 responseIds += node.id;
michael@0 155 }
michael@0 156 is(responseIds, ids, "Correct nodes were returned.");
michael@0 157 assertOwnership();
michael@0 158 }
michael@0 159 }
michael@0 160
michael@0 161 addTest(function testNoChildren() {
michael@0 162 promiseDone(gWalker.querySelector(gWalker.rootNode, "#empty").then(empty => {
michael@0 163 assertOwnership();
michael@0 164 return gWalker.children(empty).then(nodeArrayChecker(true, true, ""));
michael@0 165 }).then(runNextTest));
michael@0 166 });
michael@0 167
michael@0 168 addTest(function testLongListTraversal() {
michael@0 169 var longList;
michael@0 170 var allChildren;
michael@0 171 promiseDone(gWalker.querySelector(gWalker.rootNode, "#longlist").then(node => {
michael@0 172 longList = node;
michael@0 173 // First call with no options, expect all children.
michael@0 174 assertOwnership();
michael@0 175 return gWalker.children(longList).then(response => {
michael@0 176 nodeArrayChecker(true, true, "abcdefghijklmnopqrstuvwxyz")(response);
michael@0 177 allChildren = response.nodes;
michael@0 178 assertOwnership();
michael@0 179 });
michael@0 180 }).then(() => {
michael@0 181 // maxNodes should limit us to the first 5 nodes.
michael@0 182 assertOwnership();
michael@0 183 return gWalker.children(longList, { maxNodes: 5 }).then(nodeArrayChecker(true, false, 'abcde'));
michael@0 184 }).then(() => {
michael@0 185 assertOwnership();
michael@0 186 // maxNodes with the second item centered should still give us the first 5 nodes.
michael@0 187 return gWalker.children(longList, { maxNodes: 5, center: allChildren[1] }).then(
michael@0 188 nodeArrayChecker(true, false, 'abcde')
michael@0 189 );
michael@0 190 }).then(() => {
michael@0 191 // maxNodes with a center in the middle of the list should put that item in the middle
michael@0 192 let center = allChildren[13];
michael@0 193 is(center.id, 'n', "Make sure I know how to count letters.");
michael@0 194 return gWalker.children(longList, { maxNodes: 5, center: center }).then(
michael@0 195 nodeArrayChecker(false, false, 'lmnop')
michael@0 196 );
michael@0 197 }).then(() => {
michael@0 198 // maxNodes with the second-to-last item centered should give us the last 5 nodes.
michael@0 199 return gWalker.children(longList, { maxNodes: 5, center: allChildren[24] }).then(
michael@0 200 nodeArrayChecker(false, true, 'vwxyz')
michael@0 201 );
michael@0 202 }).then(() => {
michael@0 203 // maxNodes with a start in the middle should start at that node and fetch 5
michael@0 204 let start = allChildren[13];
michael@0 205 is(start.id, 'n', "Make sure I know how to count letters.")
michael@0 206 return gWalker.children(longList, { maxNodes: 5, start: start }).then(
michael@0 207 nodeArrayChecker(false, false, 'nopqr')
michael@0 208 );
michael@0 209 }).then(() => {
michael@0 210 // maxNodes near the end should only return what's left
michael@0 211 return gWalker.children(longList, { maxNodes: 5, start: allChildren[24] }).then(
michael@0 212 nodeArrayChecker(false, true, 'yz')
michael@0 213 );
michael@0 214 }).then(runNextTest));
michael@0 215 });
michael@0 216
michael@0 217 addTest(function testSiblings() {
michael@0 218 promiseDone(gWalker.querySelector(gWalker.rootNode, "#a").then(a => {
michael@0 219 return gWalker.siblings(a, { maxNodes: 5, center: a }).then(nodeArrayChecker(true, false, "abcde"));
michael@0 220 }).then(() => {
michael@0 221 return gWalker.siblings(gWalker.rootNode).then(response => {
michael@0 222 ok(response.hasFirst && response.hasLast, "Has first and last.");
michael@0 223 is(response.nodes.length, 1, "Has only the document element.");
michael@0 224 ok(response.nodes[0] === gWalker.rootNode, "Document element is its own sibling.");
michael@0 225 });
michael@0 226 }).then(runNextTest));
michael@0 227 });
michael@0 228
michael@0 229 addTest(function testNextSibling() {
michael@0 230 promiseDone(gWalker.querySelector(gWalker.rootNode, "#y").then(y => {
michael@0 231 is(y.id, "y", "Got the right node.");
michael@0 232 return gWalker.nextSibling(y);
michael@0 233 }).then(z => {
michael@0 234 is(z.id, "z", "nextSibling got the next node.");
michael@0 235 return gWalker.nextSibling(z);
michael@0 236 }).then(nothing => {
michael@0 237 is(nothing, null, "nextSibling on the last node returned null.");
michael@0 238 }).then(runNextTest));
michael@0 239 });
michael@0 240
michael@0 241 addTest(function testPreviousSibling() {
michael@0 242 promiseDone(gWalker.querySelector(gWalker.rootNode, "#b").then(b => {
michael@0 243 is(b.id, "b", "Got the right node.");
michael@0 244 return gWalker.previousSibling(b);
michael@0 245 }).then(a => {
michael@0 246 is(a.id, "a", "nextSibling got the next node.");
michael@0 247 return gWalker.previousSibling(a);
michael@0 248 }).then(nothing => {
michael@0 249 is(nothing, null, "previousSibling on the first node returned null.");
michael@0 250 }).then(runNextTest));
michael@0 251 });
michael@0 252
michael@0 253
michael@0 254 addTest(function testFrameTraversal() {
michael@0 255 promiseDone(gWalker.querySelector(gWalker.rootNode, "#childFrame").then(childFrame => {
michael@0 256 return gWalker.children(childFrame);
michael@0 257 }).then(children => {
michael@0 258 let nodes = children.nodes;
michael@0 259 ok(nodes.length, 1, "There should be only one child of the iframe");
michael@0 260 is(nodes[0].nodeType, Node.DOCUMENT_NODE, "iframe child should be a document node");
michael@0 261 return gWalker.querySelector(nodes[0], "#z");
michael@0 262 }).then(childDocumentZ => {
michael@0 263 return gWalker.parents(childDocumentZ);
michael@0 264 }).then(parents => {
michael@0 265 // Expected set of parent tag names for this item:
michael@0 266 let expectedParents = ['DIV', 'BODY', 'HTML', '#document', 'IFRAME', 'BODY', 'HTML', '#document'];
michael@0 267 for (let parent of parents) {
michael@0 268 let expected = expectedParents.shift();
michael@0 269 is(parent.nodeName, expected, "Got expected parent");
michael@0 270 }
michael@0 271 }).then(runNextTest));
michael@0 272 });
michael@0 273
michael@0 274 addTest(function testLongValue() {
michael@0 275 const testSummaryLength = 10;
michael@0 276 inspector.setValueSummaryLength(testSummaryLength);
michael@0 277 SimpleTest.registerCleanupFunction(function() {
michael@0 278 inspector.setValueSummaryLength(inspector.DEFAULT_VALUE_SUMMARY_LENGTH);
michael@0 279 });
michael@0 280
michael@0 281 let longstringText = gInspectee.getElementById("longstring").firstChild.nodeValue;
michael@0 282
michael@0 283 promiseDone(gWalker.querySelector(gWalker.rootNode, "#longstring").then(node => {
michael@0 284 // Now we need to get the text node child...
michael@0 285 return gWalker.children(node, { maxNodes: 1 });
michael@0 286 }).then(children => {
michael@0 287 let textNode = children.nodes[0];
michael@0 288 is(textNode.nodeType, Node.TEXT_NODE, "Value should be a text node");
michael@0 289 is(textNode.shortValue.length, 10, "Value summary should be limited to the summary value length");
michael@0 290 ok(textNode.incompleteValue, "Value should be incomplete");
michael@0 291 return textNode;
michael@0 292 }).then(textNode => {
michael@0 293 return textNode.getNodeValue();
michael@0 294 }).then(value => {
michael@0 295 return value.string();
michael@0 296 }).then(valueStr => {
michael@0 297 is(valueStr, longstringText, "Full node value should match the string from the document.");
michael@0 298 }).then(runNextTest));
michael@0 299 });
michael@0 300
michael@0 301 addTest(function testShortValue() {
michael@0 302 let shortstringText = gInspectee.getElementById("shortstring").firstChild.nodeValue;
michael@0 303
michael@0 304 promiseDone(gWalker.querySelector(gWalker.rootNode, "#shortstring").then(node => {
michael@0 305 // Now we need to get the text node child...
michael@0 306 return gWalker.children(node, { maxNodes: 1 });
michael@0 307 }).then(children => {
michael@0 308 let textNode = children.nodes[0];
michael@0 309 is(textNode.nodeType, Node.TEXT_NODE, "Value should be a text node");
michael@0 310 is(textNode.shortValue, shortstringText, "Value should be complete");
michael@0 311 ok(!textNode.incompleteValue, "Value should be complete");
michael@0 312 return textNode;
michael@0 313 }).then(textNode => {
michael@0 314 return textNode.getNodeValue();
michael@0 315 }).then(value => {
michael@0 316 return value.string();
michael@0 317 }).then(valueStr => {
michael@0 318 is(valueStr, shortstringText, "Full node value should match the string from the document.");
michael@0 319 }).then(runNextTest));
michael@0 320 });
michael@0 321
michael@0 322 addTest(function testReleaseWalker() {
michael@0 323 checkActorIDs.push(gWalker.actorID);
michael@0 324
michael@0 325 promiseDone(gWalker.release().then(() => {
michael@0 326 let promises = [checkMissing(gClient, id) for (id of checkActorIDs)];
michael@0 327 return promise.all(promises)
michael@0 328 }).then(runNextTest));
michael@0 329 });
michael@0 330
michael@0 331 addTest(function cleanup() {
michael@0 332 delete gWalker;
michael@0 333 delete gInspectee;
michael@0 334 delete gClient;
michael@0 335 runNextTest();
michael@0 336 });
michael@0 337
michael@0 338
michael@0 339 </script>
michael@0 340 </head>
michael@0 341 <body>
michael@0 342 <a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=">Mozilla Bug </a>
michael@0 343 <a id="inspectorContent" target="_blank" href="inspector-traversal-data.html">Test Document</a>
michael@0 344 <p id="display"></p>
michael@0 345 <div id="content" style="display: none">
michael@0 346
michael@0 347 </div>
michael@0 348 <pre id="test">
michael@0 349 </pre>
michael@0 350 </body>
michael@0 351 </html>

mercurial