layout/inspector/tests/chrome/test_bug708874.xul

Wed, 31 Dec 2014 06:09:35 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:09:35 +0100
changeset 0
6474c204b198
permissions
-rw-r--r--

Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.

michael@0 1 <?xml version="1.0"?>
michael@0 2 <?xml-stylesheet type="text/css" href="chrome://global/skin"?>
michael@0 3 <?xml-stylesheet type="text/css" href="chrome://mochikit/content/tests/SimpleTest/test.css"?>
michael@0 4 <?xml-stylesheet type="text/css" href="test_bug708874.css"?>
michael@0 5 <!--
michael@0 6 https://bugzilla.mozilla.org/show_bug.cgi?id=708874
michael@0 7 -->
michael@0 8 <window title="Mozilla Bug 708874"
michael@0 9 xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul"
michael@0 10 onload="RunTests();">
michael@0 11 <script type="application/javascript" src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js"/>
michael@0 12 <script type="application/javascript">
michael@0 13 <![CDATA[
michael@0 14
michael@0 15 /** Test for Bug 708874 - API for locking pseudo-class state of an element **/
michael@0 16
michael@0 17 var DOMUtils = Components.classes["@mozilla.org/inspector/dom-utils;1"]
michael@0 18 .getService(Components.interfaces.inIDOMUtils);
michael@0 19 var DOMWindowUtils = window.QueryInterface(Components.interfaces.nsIInterfaceRequestor)
michael@0 20 .getInterface(Components.interfaces.nsIDOMWindowUtils);
michael@0 21
michael@0 22 var defaultColor = "rgb(0, 0, 0)";
michael@0 23 var disabledColor = "rgb(40, 0, 0)";
michael@0 24
michael@0 25 function RunTests() {
michael@0 26 testLockEnabled();
michael@0 27 testLockDisabled();
michael@0 28 testVisited();
michael@0 29 testMultiple();
michael@0 30 testInvalid();
michael@0 31 testNotElement();
michael@0 32 }
michael@0 33
michael@0 34 function testLockEnabled() {
michael@0 35 var button = document.getElementById("test-button");
michael@0 36
michael@0 37 /* starting state is enabled */
michael@0 38 button.removeAttribute("disabled");
michael@0 39
michael@0 40 is(DOMUtils.hasPseudoClassLock(button, ":disabled"), false,
michael@0 41 "doesn't have lock at start");
michael@0 42
michael@0 43 is(window.getComputedStyle(button).color, defaultColor,
michael@0 44 "color is default color before locking on");
michael@0 45
michael@0 46 is(button.mozMatchesSelector(":disabled"), false,
michael@0 47 "doesn't match selector at start");
michael@0 48
michael@0 49 /* lock */
michael@0 50 DOMUtils.addPseudoClassLock(button, ":disabled");
michael@0 51
michael@0 52 is(DOMUtils.hasPseudoClassLock(button, ":disabled"), true,
michael@0 53 "hasPseudoClassLock is true after locking");
michael@0 54
michael@0 55 is(window.getComputedStyle(button).color, disabledColor,
michael@0 56 ":disabled style applied after adding lock");
michael@0 57
michael@0 58 is(button.mozMatchesSelector(":disabled"), true,
michael@0 59 "matches selector after adding lock");
michael@0 60
michael@0 61 /* change state to disabled */
michael@0 62 button.setAttribute("disabled", "disabled");
michael@0 63
michael@0 64 is(window.getComputedStyle(button).color, disabledColor,
michael@0 65 ":disabled style still applied after really disabling");
michael@0 66
michael@0 67 is(button.mozMatchesSelector(":disabled"), true,
michael@0 68 "matches selector after adding lock");
michael@0 69
michael@0 70 /* remove lock */
michael@0 71 DOMUtils.removePseudoClassLock(button, ":disabled");
michael@0 72
michael@0 73 is(DOMUtils.hasPseudoClassLock(button, ":disabled"), false,
michael@0 74 "hasPseudoClassLock is false after removing on lock");
michael@0 75
michael@0 76 is(window.getComputedStyle(button).color, disabledColor,
michael@0 77 ":disabled style still applied after removing lock");
michael@0 78
michael@0 79 is(button.mozMatchesSelector(":disabled"), true,
michael@0 80 "matches selector after removing lock");
michael@0 81
michael@0 82 /* change state to enabled */
michael@0 83 button.removeAttribute("disabled");
michael@0 84
michael@0 85 is(window.getComputedStyle(button).color, defaultColor,
michael@0 86 "back to default style after un-disabling");
michael@0 87
michael@0 88 is(button.mozMatchesSelector(":disabled"), false,
michael@0 89 "doesn't match selector after enabling");
michael@0 90 }
michael@0 91
michael@0 92
michael@0 93 function testLockDisabled() {
michael@0 94 var button = document.getElementById("test-button");
michael@0 95
michael@0 96 /* starting state is disabled */
michael@0 97 button.setAttribute("disabled", "disabled");
michael@0 98
michael@0 99 is(DOMUtils.hasPseudoClassLock(button, ":disabled"), false,
michael@0 100 "doesn't have lock at start");
michael@0 101
michael@0 102 is(window.getComputedStyle(button).color, disabledColor,
michael@0 103 "color is :disabled color before locking");
michael@0 104
michael@0 105 is(button.mozMatchesSelector(":disabled"), true,
michael@0 106 "matches selector before locking");
michael@0 107
michael@0 108 /* lock */
michael@0 109 DOMUtils.addPseudoClassLock(button, ":disabled");
michael@0 110
michael@0 111 is(DOMUtils.hasPseudoClassLock(button, ":disabled"), true,
michael@0 112 "hasPseudoClassLock is true after locking");
michael@0 113
michael@0 114 is(window.getComputedStyle(button).color, disabledColor,
michael@0 115 ":disabled style still applied after adding on lock");
michael@0 116
michael@0 117 is(button.mozMatchesSelector(":disabled"), true,
michael@0 118 "matches selector after locking");
michael@0 119
michael@0 120 /* change state to enabled */
michael@0 121 button.removeAttribute("disabled");
michael@0 122
michael@0 123 is(window.getComputedStyle(button).color, disabledColor,
michael@0 124 ":disabled style applied after enabling");
michael@0 125
michael@0 126 is(button.mozMatchesSelector(":disabled"), true,
michael@0 127 "matches selector after enabling with lock on");
michael@0 128
michael@0 129 /* remove lock */
michael@0 130 DOMUtils.removePseudoClassLock(button, ":disabled");
michael@0 131
michael@0 132 is(DOMUtils.hasPseudoClassLock(button, ":disabled"), false,
michael@0 133 "hasPseudoClassLock is false after removing on lock");
michael@0 134
michael@0 135 is(window.getComputedStyle(button).color, defaultColor,
michael@0 136 "default style applied after removing lock");
michael@0 137
michael@0 138 is(button.mozMatchesSelector(":disabled"), false,
michael@0 139 "doesn't match selector after unlocking");
michael@0 140
michael@0 141 /* change state to disabled */
michael@0 142 button.setAttribute("disabled", "disabled");
michael@0 143
michael@0 144 is(window.getComputedStyle(button).color, disabledColor,
michael@0 145 ":disabled style applied after disabling after unlocking");
michael@0 146
michael@0 147 is(button.mozMatchesSelector(":disabled"), true,
michael@0 148 "matches selector again after disabling");
michael@0 149 }
michael@0 150
michael@0 151 function testVisited() {
michael@0 152 var link = document.getElementById("test-link");
michael@0 153 var visitedColor = "rgb(20, 0, 0)";
michael@0 154 var unvisitedColor = "rgb(30, 0, 0)";
michael@0 155
michael@0 156 /* lock visited */
michael@0 157 DOMUtils.addPseudoClassLock(link, ":visited");
michael@0 158
michael@0 159 is(DOMUtils.hasPseudoClassLock(link, ":visited"), true,
michael@0 160 "hasPseudoClassLock is true after adding lock");
michael@0 161
michael@0 162 var color = DOMWindowUtils.getVisitedDependentComputedStyle(link,
michael@0 163 null, "color");
michael@0 164 is(color, visitedColor, "color is :visited color after locking");
michael@0 165
michael@0 166 /* lock unvisited */
michael@0 167 DOMUtils.addPseudoClassLock(link, ":link");
michael@0 168
michael@0 169 is(DOMUtils.hasPseudoClassLock(link, ":link"), true,
michael@0 170 "hasPseudoClassLock is true after adding :link lock");
michael@0 171
michael@0 172 is(DOMUtils.hasPseudoClassLock(link, ":visited"), false,
michael@0 173 "hasPseudoClassLock is false for :visited after adding :link lock");
michael@0 174
michael@0 175 var color = DOMWindowUtils.getVisitedDependentComputedStyle(link,
michael@0 176 null, "color");
michael@0 177 is(color, unvisitedColor, "color is :link color after locking :link");
michael@0 178
michael@0 179 /* lock visited back on */
michael@0 180 DOMUtils.addPseudoClassLock(link, ":visited");
michael@0 181
michael@0 182 is(DOMUtils.hasPseudoClassLock(link, ":visited"), true,
michael@0 183 "hasPseudoClassLock is true after adding :visited lock");
michael@0 184
michael@0 185 is(DOMUtils.hasPseudoClassLock(link, ":link"), false,
michael@0 186 "hasPseudoClassLock is false for :link after adding :visited lock");
michael@0 187
michael@0 188 var color = DOMWindowUtils.getVisitedDependentComputedStyle(link,
michael@0 189 null, "color");
michael@0 190 is(color, visitedColor, "color is :visited color after locking back on");
michael@0 191 }
michael@0 192
michael@0 193 function testMultiple() {
michael@0 194 var div = document.getElementById("test-div");
michael@0 195
michael@0 196 var styles = {
michael@0 197 ":hover": {
michael@0 198 property: "color",
michael@0 199 value: "rgb(10, 0, 0)",
michael@0 200 defaultValue: "rgb(0, 0, 0)"
michael@0 201 },
michael@0 202 ":active": {
michael@0 203 property: "font-family",
michael@0 204 value: "Arial",
michael@0 205 defaultValue: "serif"
michael@0 206 },
michael@0 207 ":focus": {
michael@0 208 property: "font-weight",
michael@0 209 value: "800",
michael@0 210 defaultValue: "400"
michael@0 211 }
michael@0 212 };
michael@0 213
michael@0 214 for (var pseudo in styles) {
michael@0 215 DOMUtils.addPseudoClassLock(div, pseudo);
michael@0 216 }
michael@0 217
michael@0 218 for (var pseudo in styles) {
michael@0 219 is(DOMUtils.hasPseudoClassLock(div, pseudo), true,
michael@0 220 "hasPseudoClassLock is true after locking");
michael@0 221
michael@0 222 var style = styles[pseudo];
michael@0 223 is(window.getComputedStyle(div).getPropertyValue(style.property),
michael@0 224 style.value, "style for pseudo-class is applied after locking");
michael@0 225
michael@0 226 is(div.mozMatchesSelector(pseudo), true,
michael@0 227 "matches selector after locking");
michael@0 228 }
michael@0 229
michael@0 230 DOMUtils.clearPseudoClassLocks(div);
michael@0 231
michael@0 232 for (var pseudo in styles) {
michael@0 233 is(DOMUtils.hasPseudoClassLock(div, pseudo), false,
michael@0 234 "hasPseudoClassLock is false after clearing");
michael@0 235
michael@0 236 is(window.getComputedStyle(div).getPropertyValue(style.property),
michael@0 237 style.defaultValue, "style is back to default after clearing");
michael@0 238
michael@0 239 is(div.mozMatchesSelector(pseudo), false,
michael@0 240 "doesn't match selector after unlocking");
michael@0 241 }
michael@0 242 }
michael@0 243
michael@0 244 function testInvalid() {
michael@0 245 var div = document.getElementById("test-div");
michael@0 246 var pseudos = ["not a valid pseudo-class", ":moz-any-link", ":first-child"];
michael@0 247
michael@0 248 for (var i = 0; i < pseudos.length; i++) {
michael@0 249 var pseudo = pseudos[i];
michael@0 250
michael@0 251 // basically make sure these don't crash the browser.
michael@0 252 DOMUtils.addPseudoClassLock(div, pseudo);
michael@0 253
michael@0 254 is(DOMUtils.hasPseudoClassLock(div, pseudo), false);
michael@0 255
michael@0 256 DOMUtils.removePseudoClassLock(div, pseudo);
michael@0 257 }
michael@0 258 }
michael@0 259
michael@0 260 function testNotElement() {
michael@0 261 var values = [null, undefined, {}];
michael@0 262 try {
michael@0 263 for each (value in values); {
michael@0 264 DOMUtils.hasPseudoClassLock(value, ":hover");
michael@0 265 DOMUtils.addPseudoClassLock(value, ":hover");
michael@0 266 DOMUtils.removePseudoClassLock(value, ":hover");
michael@0 267 DOMUtils.clearPseudoClassLocks(value);
michael@0 268 }
michael@0 269 } catch(e) {
michael@0 270 // just make sure we don't crash on non-elements
michael@0 271 }
michael@0 272 }
michael@0 273 ]]>
michael@0 274 </script>
michael@0 275
michael@0 276 <body xmlns="http://www.w3.org/1999/xhtml">
michael@0 277 <a href="https://bugzilla.mozilla.org/show_bug.cgi?id=708874"
michael@0 278 target="_blank">Mozilla Bug 708874</a>
michael@0 279
michael@0 280 <a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=708874">
michael@0 281 Mozilla Bug 708874 - API for locking pseudo-class state of an element
michael@0 282 </a>
michael@0 283
michael@0 284 <a id="test-link" href="http://notavisitedwebsite.com">
michael@0 285 test link
michael@0 286 </a>
michael@0 287
michael@0 288 <div id="test-div">
michael@0 289 test div
michael@0 290 </div>
michael@0 291
michael@0 292 <button id="test-button">
michael@0 293 test button
michael@0 294 </button>
michael@0 295 </body>
michael@0 296
michael@0 297 </window>

mercurial