Wed, 31 Dec 2014 06:09:35 +0100
Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.
michael@0 | 1 | /* vim: set ft=javascript ts=2 et sw=2 tw=80: */ |
michael@0 | 2 | /* Any copyright is dedicated to the Public Domain. |
michael@0 | 3 | http://creativecommons.org/publicdomain/zero/1.0/ */ |
michael@0 | 4 | |
michael@0 | 5 | "use strict"; |
michael@0 | 6 | |
michael@0 | 7 | // Test that pseudoelements are displayed correctly in the rule view |
michael@0 | 8 | |
michael@0 | 9 | const TEST_URI = TEST_URL_ROOT + "doc_pseudoelement.html"; |
michael@0 | 10 | |
michael@0 | 11 | let test = asyncTest(function*() { |
michael@0 | 12 | yield addTab(TEST_URI); |
michael@0 | 13 | let {toolbox, inspector, view} = yield openRuleView(); |
michael@0 | 14 | |
michael@0 | 15 | yield testTopLeft(inspector, view); |
michael@0 | 16 | yield testTopRight(inspector, view); |
michael@0 | 17 | yield testBottomRight(inspector, view); |
michael@0 | 18 | yield testBottomLeft(inspector, view); |
michael@0 | 19 | yield testParagraph(inspector, view); |
michael@0 | 20 | yield testBody(inspector, view); |
michael@0 | 21 | }); |
michael@0 | 22 | |
michael@0 | 23 | function* testTopLeft(inspector, view) { |
michael@0 | 24 | let { |
michael@0 | 25 | rules, |
michael@0 | 26 | element, |
michael@0 | 27 | elementStyle |
michael@0 | 28 | } = yield assertPseudoElementRulesNumbers("#topleft", inspector, view, { |
michael@0 | 29 | elementRulesNb: 4, |
michael@0 | 30 | afterRulesNb: 1, |
michael@0 | 31 | beforeRulesNb: 2, |
michael@0 | 32 | firstLineRulesNb: 0, |
michael@0 | 33 | firstLetterRulesNb: 0, |
michael@0 | 34 | selectionRulesNb: 0 |
michael@0 | 35 | }); |
michael@0 | 36 | |
michael@0 | 37 | let gutters = assertGutters(view); |
michael@0 | 38 | |
michael@0 | 39 | // Make sure that clicking on the twisty hides pseudo elements |
michael@0 | 40 | let expander = gutters[0].querySelector(".ruleview-expander"); |
michael@0 | 41 | ok (view.element.classList.contains("show-pseudo-elements"), "Pseudo Elements are expanded"); |
michael@0 | 42 | expander.click(); |
michael@0 | 43 | ok (!view.element.classList.contains("show-pseudo-elements"), "Pseudo Elements are collapsed by twisty"); |
michael@0 | 44 | expander.click(); |
michael@0 | 45 | ok (view.element.classList.contains("show-pseudo-elements"), "Pseudo Elements are expanded again"); |
michael@0 | 46 | |
michael@0 | 47 | // Make sure that dblclicking on the header container also toggles the pseudo elements |
michael@0 | 48 | EventUtils.synthesizeMouseAtCenter(gutters[0], {clickCount: 2}, inspector.sidebar.getWindowForTab("ruleview")); |
michael@0 | 49 | ok (!view.element.classList.contains("show-pseudo-elements"), "Pseudo Elements are collapsed by dblclicking"); |
michael@0 | 50 | |
michael@0 | 51 | let defaultView = element.ownerDocument.defaultView; |
michael@0 | 52 | let elementRule = rules.elementRules[0]; |
michael@0 | 53 | let elementRuleView = [].filter.call(view.element.children, e => { |
michael@0 | 54 | return e._ruleEditor && e._ruleEditor.rule === elementRule; |
michael@0 | 55 | })[0]._ruleEditor; |
michael@0 | 56 | |
michael@0 | 57 | let elementAfterRule = rules.afterRules[0]; |
michael@0 | 58 | let elementAfterRuleView = [].filter.call(view.element.children, (e) => { |
michael@0 | 59 | return e._ruleEditor && e._ruleEditor.rule === elementAfterRule; |
michael@0 | 60 | })[0]._ruleEditor; |
michael@0 | 61 | |
michael@0 | 62 | is |
michael@0 | 63 | ( |
michael@0 | 64 | convertTextPropsToString(elementAfterRule.textProps), |
michael@0 | 65 | "background: none repeat scroll 0% 0% red; content: \" \"; position: absolute; " + |
michael@0 | 66 | "border-radius: 50%; height: 32px; width: 32px; top: 50%; left: 50%; margin-top: -16px; margin-left: -16px", |
michael@0 | 67 | "TopLeft after properties are correct" |
michael@0 | 68 | ); |
michael@0 | 69 | |
michael@0 | 70 | let elementBeforeRule = rules.beforeRules[0]; |
michael@0 | 71 | let elementBeforeRuleView = [].filter.call(view.element.children, (e) => { |
michael@0 | 72 | return e._ruleEditor && e._ruleEditor.rule === elementBeforeRule; |
michael@0 | 73 | })[0]._ruleEditor; |
michael@0 | 74 | |
michael@0 | 75 | is |
michael@0 | 76 | ( |
michael@0 | 77 | convertTextPropsToString(elementBeforeRule.textProps), |
michael@0 | 78 | "top: 0px; left: 0px", |
michael@0 | 79 | "TopLeft before properties are correct" |
michael@0 | 80 | ); |
michael@0 | 81 | |
michael@0 | 82 | let firstProp = elementAfterRuleView.addProperty("background-color", "rgb(0, 255, 0)", ""); |
michael@0 | 83 | let secondProp = elementAfterRuleView.addProperty("padding", "100px", ""); |
michael@0 | 84 | |
michael@0 | 85 | is (firstProp, elementAfterRule.textProps[elementAfterRule.textProps.length - 2], |
michael@0 | 86 | "First added property is on back of array"); |
michael@0 | 87 | is (secondProp, elementAfterRule.textProps[elementAfterRule.textProps.length - 1], |
michael@0 | 88 | "Second added property is on back of array"); |
michael@0 | 89 | |
michael@0 | 90 | yield elementAfterRule._applyingModifications; |
michael@0 | 91 | |
michael@0 | 92 | is(defaultView.getComputedStyle(element, ":after").getPropertyValue("background-color"), |
michael@0 | 93 | "rgb(0, 255, 0)", "Added property should have been used."); |
michael@0 | 94 | is(defaultView.getComputedStyle(element, ":after").getPropertyValue("padding-top"), |
michael@0 | 95 | "100px", "Added property should have been used."); |
michael@0 | 96 | is(defaultView.getComputedStyle(element).getPropertyValue("padding-top"), |
michael@0 | 97 | "32px", "Added property should not apply to element"); |
michael@0 | 98 | |
michael@0 | 99 | secondProp.setEnabled(false); |
michael@0 | 100 | yield elementAfterRule._applyingModifications; |
michael@0 | 101 | |
michael@0 | 102 | is(defaultView.getComputedStyle(element, ":after").getPropertyValue("padding-top"), "0px", |
michael@0 | 103 | "Disabled property should have been used."); |
michael@0 | 104 | is(defaultView.getComputedStyle(element).getPropertyValue("padding-top"), "32px", |
michael@0 | 105 | "Added property should not apply to element"); |
michael@0 | 106 | |
michael@0 | 107 | secondProp.setEnabled(true); |
michael@0 | 108 | yield elementAfterRule._applyingModifications; |
michael@0 | 109 | |
michael@0 | 110 | is(defaultView.getComputedStyle(element, ":after").getPropertyValue("padding-top"), "100px", |
michael@0 | 111 | "Enabled property should have been used."); |
michael@0 | 112 | is(defaultView.getComputedStyle(element).getPropertyValue("padding-top"), "32px", |
michael@0 | 113 | "Added property should not apply to element"); |
michael@0 | 114 | |
michael@0 | 115 | let firstProp = elementRuleView.addProperty("background-color", "rgb(0, 0, 255)", ""); |
michael@0 | 116 | yield elementRule._applyingModifications; |
michael@0 | 117 | |
michael@0 | 118 | is(defaultView.getComputedStyle(element).getPropertyValue("background-color"), "rgb(0, 0, 255)", |
michael@0 | 119 | "Added property should have been used."); |
michael@0 | 120 | is(defaultView.getComputedStyle(element, ":after").getPropertyValue("background-color"), "rgb(0, 255, 0)", |
michael@0 | 121 | "Added prop does not apply to pseudo"); |
michael@0 | 122 | } |
michael@0 | 123 | |
michael@0 | 124 | function* testTopRight(inspector, view) { |
michael@0 | 125 | let { |
michael@0 | 126 | rules, |
michael@0 | 127 | element, |
michael@0 | 128 | elementStyle |
michael@0 | 129 | } = yield assertPseudoElementRulesNumbers("#topright", inspector, view, { |
michael@0 | 130 | elementRulesNb: 4, |
michael@0 | 131 | afterRulesNb: 1, |
michael@0 | 132 | beforeRulesNb: 2, |
michael@0 | 133 | firstLineRulesNb: 0, |
michael@0 | 134 | firstLetterRulesNb: 0, |
michael@0 | 135 | selectionRulesNb: 0 |
michael@0 | 136 | }); |
michael@0 | 137 | |
michael@0 | 138 | let gutters = assertGutters(view); |
michael@0 | 139 | |
michael@0 | 140 | let expander = gutters[0].querySelector(".ruleview-expander"); |
michael@0 | 141 | ok (!view.element.classList.contains("show-pseudo-elements"), "Pseudo Elements remain collapsed after switching element"); |
michael@0 | 142 | expander.scrollIntoView(); |
michael@0 | 143 | expander.click(); |
michael@0 | 144 | ok (view.element.classList.contains("show-pseudo-elements"), "Pseudo Elements are shown again after clicking twisty"); |
michael@0 | 145 | } |
michael@0 | 146 | |
michael@0 | 147 | function* testBottomRight(inspector, view) { |
michael@0 | 148 | yield assertPseudoElementRulesNumbers("#bottomright", inspector, view, { |
michael@0 | 149 | elementRulesNb: 4, |
michael@0 | 150 | afterRulesNb: 1, |
michael@0 | 151 | beforeRulesNb: 3, |
michael@0 | 152 | firstLineRulesNb: 0, |
michael@0 | 153 | firstLetterRulesNb: 0, |
michael@0 | 154 | selectionRulesNb: 0 |
michael@0 | 155 | }); |
michael@0 | 156 | } |
michael@0 | 157 | |
michael@0 | 158 | function* testBottomLeft(inspector, view) { |
michael@0 | 159 | yield assertPseudoElementRulesNumbers("#bottomleft", inspector, view, { |
michael@0 | 160 | elementRulesNb: 4, |
michael@0 | 161 | afterRulesNb: 1, |
michael@0 | 162 | beforeRulesNb: 2, |
michael@0 | 163 | firstLineRulesNb: 0, |
michael@0 | 164 | firstLetterRulesNb: 0, |
michael@0 | 165 | selectionRulesNb: 0 |
michael@0 | 166 | }); |
michael@0 | 167 | } |
michael@0 | 168 | |
michael@0 | 169 | function* testParagraph(inspector, view) { |
michael@0 | 170 | let { |
michael@0 | 171 | rules, |
michael@0 | 172 | element, |
michael@0 | 173 | elementStyle |
michael@0 | 174 | } = yield assertPseudoElementRulesNumbers("#bottomleft p", inspector, view, { |
michael@0 | 175 | elementRulesNb: 3, |
michael@0 | 176 | afterRulesNb: 0, |
michael@0 | 177 | beforeRulesNb: 0, |
michael@0 | 178 | firstLineRulesNb: 1, |
michael@0 | 179 | firstLetterRulesNb: 1, |
michael@0 | 180 | selectionRulesNb: 1 |
michael@0 | 181 | }); |
michael@0 | 182 | |
michael@0 | 183 | let gutters = assertGutters(view); |
michael@0 | 184 | |
michael@0 | 185 | let elementFirstLineRule = rules.firstLineRules[0]; |
michael@0 | 186 | let elementFirstLineRuleView = [].filter.call(view.element.children, (e) => { |
michael@0 | 187 | return e._ruleEditor && e._ruleEditor.rule === elementFirstLineRule; |
michael@0 | 188 | })[0]._ruleEditor; |
michael@0 | 189 | |
michael@0 | 190 | is |
michael@0 | 191 | ( |
michael@0 | 192 | convertTextPropsToString(elementFirstLineRule.textProps), |
michael@0 | 193 | "background: none repeat scroll 0% 0% blue", |
michael@0 | 194 | "Paragraph first-line properties are correct" |
michael@0 | 195 | ); |
michael@0 | 196 | |
michael@0 | 197 | let elementFirstLetterRule = rules.firstLetterRules[0]; |
michael@0 | 198 | let elementFirstLetterRuleView = [].filter.call(view.element.children, (e) => { |
michael@0 | 199 | return e._ruleEditor && e._ruleEditor.rule === elementFirstLetterRule; |
michael@0 | 200 | })[0]._ruleEditor; |
michael@0 | 201 | |
michael@0 | 202 | is |
michael@0 | 203 | ( |
michael@0 | 204 | convertTextPropsToString(elementFirstLetterRule.textProps), |
michael@0 | 205 | "color: red; font-size: 130%", |
michael@0 | 206 | "Paragraph first-letter properties are correct" |
michael@0 | 207 | ); |
michael@0 | 208 | |
michael@0 | 209 | let elementSelectionRule = rules.selectionRules[0]; |
michael@0 | 210 | let elementSelectionRuleView = [].filter.call(view.element.children, (e) => { |
michael@0 | 211 | return e._ruleEditor && e._ruleEditor.rule === elementSelectionRule; |
michael@0 | 212 | })[0]._ruleEditor; |
michael@0 | 213 | |
michael@0 | 214 | is |
michael@0 | 215 | ( |
michael@0 | 216 | convertTextPropsToString(elementSelectionRule.textProps), |
michael@0 | 217 | "color: white; background: none repeat scroll 0% 0% black", |
michael@0 | 218 | "Paragraph first-letter properties are correct" |
michael@0 | 219 | ); |
michael@0 | 220 | } |
michael@0 | 221 | |
michael@0 | 222 | function* testBody(inspector, view) { |
michael@0 | 223 | let {element, elementStyle} = yield testNode("body", inspector, view); |
michael@0 | 224 | |
michael@0 | 225 | let gutters = view.element.querySelectorAll(".theme-gutter"); |
michael@0 | 226 | is (gutters.length, 0, "There are no gutter headings"); |
michael@0 | 227 | } |
michael@0 | 228 | |
michael@0 | 229 | function convertTextPropsToString(textProps) { |
michael@0 | 230 | return textProps.map(t => t.name + ": " + t.value).join("; "); |
michael@0 | 231 | } |
michael@0 | 232 | |
michael@0 | 233 | function* testNode(selector, inspector, view) { |
michael@0 | 234 | let element = getNode(selector); |
michael@0 | 235 | yield selectNode(element, inspector); |
michael@0 | 236 | let elementStyle = view._elementStyle; |
michael@0 | 237 | return {element: element, elementStyle: elementStyle}; |
michael@0 | 238 | } |
michael@0 | 239 | |
michael@0 | 240 | function* assertPseudoElementRulesNumbers(selector, inspector, view, ruleNbs) { |
michael@0 | 241 | let {element, elementStyle} = yield testNode(selector, inspector, view); |
michael@0 | 242 | |
michael@0 | 243 | let rules = { |
michael@0 | 244 | elementRules: elementStyle.rules.filter(rule => !rule.pseudoElement), |
michael@0 | 245 | afterRules: elementStyle.rules.filter(rule => rule.pseudoElement === ":after"), |
michael@0 | 246 | beforeRules: elementStyle.rules.filter(rule => rule.pseudoElement === ":before"), |
michael@0 | 247 | firstLineRules: elementStyle.rules.filter(rule => rule.pseudoElement === ":first-line"), |
michael@0 | 248 | firstLetterRules: elementStyle.rules.filter(rule => rule.pseudoElement === ":first-letter"), |
michael@0 | 249 | selectionRules: elementStyle.rules.filter(rule => rule.pseudoElement === ":-moz-selection") |
michael@0 | 250 | }; |
michael@0 | 251 | |
michael@0 | 252 | is(rules.elementRules.length, ruleNbs.elementRulesNb, selector + |
michael@0 | 253 | " has the correct number of non pseudo element rules"); |
michael@0 | 254 | is(rules.afterRules.length, ruleNbs.afterRulesNb, selector + |
michael@0 | 255 | " has the correct number of :after rules"); |
michael@0 | 256 | is(rules.beforeRules.length, ruleNbs.beforeRulesNb, selector + |
michael@0 | 257 | " has the correct number of :before rules"); |
michael@0 | 258 | is(rules.firstLineRules.length, ruleNbs.firstLineRulesNb, selector + |
michael@0 | 259 | " has the correct number of :first-line rules"); |
michael@0 | 260 | is(rules.firstLetterRules.length, ruleNbs.firstLetterRulesNb, selector + |
michael@0 | 261 | " has the correct number of :first-letter rules"); |
michael@0 | 262 | is(rules.selectionRules.length, ruleNbs.selectionRulesNb, selector + |
michael@0 | 263 | " has the correct number of :selection rules"); |
michael@0 | 264 | |
michael@0 | 265 | return {rules: rules, element: element, elementStyle: elementStyle}; |
michael@0 | 266 | } |
michael@0 | 267 | |
michael@0 | 268 | function assertGutters(view) { |
michael@0 | 269 | let gutters = view.element.querySelectorAll(".theme-gutter"); |
michael@0 | 270 | is (gutters.length, 3, "There are 3 gutter headings"); |
michael@0 | 271 | is (gutters[0].textContent, "Pseudo-elements", "Gutter heading is correct"); |
michael@0 | 272 | is (gutters[1].textContent, "This Element", "Gutter heading is correct"); |
michael@0 | 273 | is (gutters[2].textContent, "Inherited from body", "Gutter heading is correct"); |
michael@0 | 274 | return gutters; |
michael@0 | 275 | } |