toolkit/devtools/server/tests/mochitest/test_inspector-pseudoclass-lock.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 const DOMUtils = Components.classes["@mozilla.org/inspector/dom-utils;1"].
michael@0 19 getService(Components.interfaces.inIDOMUtils);
michael@0 20
michael@0 21 const KNOWN_PSEUDOCLASSES = [':hover', ':active', ':focus']
michael@0 22
michael@0 23 window.onload = function() {
michael@0 24 SimpleTest.waitForExplicitFinish();
michael@0 25 runNextTest();
michael@0 26 }
michael@0 27
michael@0 28 var gInspectee = null;
michael@0 29 var gWalker = null;
michael@0 30 var gClient = null;
michael@0 31 var gCleanupConnection = null;
michael@0 32
michael@0 33 function setup(callback) {
michael@0 34 let url = document.getElementById("inspectorContent").href;
michael@0 35 gCleanupConnection = attachURL(url, function(err, client, tab, doc) {
michael@0 36 gInspectee = doc;
michael@0 37 let {InspectorFront} = devtools.require("devtools/server/actors/inspector");
michael@0 38 let inspector = InspectorFront(client, tab);
michael@0 39 promiseDone(inspector.getWalker().then(walker => {
michael@0 40 gClient = client;
michael@0 41 gWalker = walker;
michael@0 42 }).then(callback));
michael@0 43 });
michael@0 44 }
michael@0 45
michael@0 46 function teardown() {
michael@0 47 gWalker = null;
michael@0 48 gClient = null;
michael@0 49 gInspectee = null;
michael@0 50 if (gCleanupConnection) {
michael@0 51 gCleanupConnection();
michael@0 52 gCleanupConnection = null;
michael@0 53 }
michael@0 54 }
michael@0 55
michael@0 56 function checkChange(change, expectation) {
michael@0 57 is(change.type, "pseudoClassLock", "Expect a pseudoclass lock change.");
michael@0 58 let target = change.target;
michael@0 59 if (expectation.id)
michael@0 60 is(target.id, expectation.id, "Expect a change on node id " + expectation.id);
michael@0 61 if (expectation.nodeName)
michael@0 62 is(target.nodeName, expectation.nodeName, "Expect a change on node name " + expectation.nodeName);
michael@0 63
michael@0 64 is(target.pseudoClassLocks.length, expectation.pseudos.length,
michael@0 65 "Expect " + expectation.pseudos.length + " pseudoclass locks.");
michael@0 66 for (let pseudo of expectation.pseudos) {
michael@0 67 ok(target.hasPseudoClassLock(pseudo), "Expect lock: " + pseudo);
michael@0 68 ok(DOMUtils.hasPseudoClassLock(target.rawNode(), pseudo), "Expect lock in dom: " + pseudo);
michael@0 69 }
michael@0 70
michael@0 71 for (let pseudo of KNOWN_PSEUDOCLASSES) {
michael@0 72 if (!expectation.pseudos.some(expected => pseudo === expected)) {
michael@0 73 ok(!target.hasPseudoClassLock(pseudo), "Don't expect lock: " + pseudo);
michael@0 74 ok(!DOMUtils.hasPseudoClassLock(target.rawNode(), pseudo), "Don't expect lock in dom: " + pseudo);
michael@0 75
michael@0 76 }
michael@0 77 }
michael@0 78 }
michael@0 79
michael@0 80 function checkMutations(mutations, expectations) {
michael@0 81 is(mutations.length, expectations.length, "Should get the right number of mutations.");
michael@0 82 for (let i = 0; i < mutations.length; i++) {
michael@0 83 checkChange(mutations[i] , expectations[i]);
michael@0 84 }
michael@0 85 }
michael@0 86
michael@0 87 addTest(function testPseudoClassLock() {
michael@0 88 let contentNode;
michael@0 89 let nodeFront;
michael@0 90 setup(() => {
michael@0 91 contentNode = gInspectee.querySelector("#b");
michael@0 92 return promiseDone(gWalker.querySelector(gWalker.rootNode, "#b").then(front => {
michael@0 93 nodeFront = front;
michael@0 94 // Lock the pseudoclass alone, no parents.
michael@0 95 gWalker.addPseudoClassLock(nodeFront, ':active');
michael@0 96 // Expect a single pseudoClassLock mutation.
michael@0 97 return promiseOnce(gWalker, "mutations");
michael@0 98 }).then(mutations => {
michael@0 99 is(mutations.length, 1, "Should get one mutations");
michael@0 100 is(mutations[0].target, nodeFront, "Should be the node we tried to apply to");
michael@0 101 checkChange(mutations[0], {
michael@0 102 id: "b",
michael@0 103 nodeName: "DIV",
michael@0 104 pseudos: [":active"]
michael@0 105 });
michael@0 106 }).then(() => {
michael@0 107 // Now add :hover, this time with parents.
michael@0 108 gWalker.addPseudoClassLock(nodeFront, ':hover', {parents: true});
michael@0 109 return promiseOnce(gWalker, "mutations");
michael@0 110 }).then(mutations => {
michael@0 111 let expectedMutations = [{
michael@0 112 id: 'b',
michael@0 113 nodeName: 'DIV',
michael@0 114 pseudos: [':hover', ':active'],
michael@0 115 },
michael@0 116 {
michael@0 117 id: 'longlist',
michael@0 118 nodeName: 'DIV',
michael@0 119 pseudos: [':hover']
michael@0 120 },
michael@0 121 {
michael@0 122 nodeName: 'BODY',
michael@0 123 pseudos: [':hover']
michael@0 124 },
michael@0 125 {
michael@0 126 nodeName: 'HTML',
michael@0 127 pseudos: [':hover']
michael@0 128 }];
michael@0 129 checkMutations(mutations, expectedMutations);
michael@0 130 }).then(() => {
michael@0 131 // Now remove the :hover on all parents
michael@0 132 gWalker.removePseudoClassLock(nodeFront, ':hover', {parents: true});
michael@0 133 return promiseOnce(gWalker, "mutations");
michael@0 134 }).then(mutations => {
michael@0 135 let expectedMutations = [{
michael@0 136 id: 'b',
michael@0 137 nodeName: 'DIV',
michael@0 138 // Should still have :active on the original node.
michael@0 139 pseudos: [':active']
michael@0 140 },
michael@0 141 {
michael@0 142 id: 'longlist',
michael@0 143 nodeName: 'DIV',
michael@0 144 pseudos: []
michael@0 145 },
michael@0 146 {
michael@0 147 nodeName: 'BODY',
michael@0 148 pseudos: []
michael@0 149 },
michael@0 150 {
michael@0 151 nodeName: 'HTML',
michael@0 152 pseudos: []
michael@0 153 }];
michael@0 154 checkMutations(mutations, expectedMutations);
michael@0 155 }).then(() => {
michael@0 156 // Now shut down the walker and make sure that clears up the remaining lock.
michael@0 157 return gWalker.release();
michael@0 158 }).then(() => {
michael@0 159 ok(!DOMUtils.hasPseudoClassLock(contentNode, ':active'), "Pseudoclass should have been removed during destruction.");
michael@0 160 teardown();
michael@0 161 }).then(runNextTest));
michael@0 162 });
michael@0 163 });
michael@0 164
michael@0 165 </script>
michael@0 166 </head>
michael@0 167 <body>
michael@0 168 <a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=">Mozilla Bug </a>
michael@0 169 <a id="inspectorContent" target="_blank" href="inspector-traversal-data.html">Test Document</a>
michael@0 170 <p id="display"></p>
michael@0 171 <div id="content" style="display: none">
michael@0 172
michael@0 173 </div>
michael@0 174 <pre id="test">
michael@0 175 </pre>
michael@0 176 </body>
michael@0 177 </html>

mercurial