| Left: | ||
| Right: |
| OLD | NEW |
|---|---|
| 1 /* | 1 /* |
| 2 * This file is part of Adblock Plus <https://adblockplus.org/>, | 2 * This file is part of Adblock Plus <https://adblockplus.org/>, |
| 3 * Copyright (C) 2006-2017 eyeo GmbH | 3 * Copyright (C) 2006-2017 eyeo GmbH |
| 4 * | 4 * |
| 5 * Adblock Plus is free software: you can redistribute it and/or modify | 5 * Adblock Plus is free software: you can redistribute it and/or modify |
| 6 * it under the terms of the GNU General Public License version 3 as | 6 * it under the terms of the GNU General Public License version 3 as |
| 7 * published by the Free Software Foundation. | 7 * published by the Free Software Foundation. |
| 8 * | 8 * |
| 9 * Adblock Plus is distributed in the hope that it will be useful, | 9 * Adblock Plus is distributed in the hope that it will be useful, |
| 10 * but WITHOUT ANY WARRANTY; without even the implied warranty of | 10 * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | 11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 12 * GNU General Public License for more details. | 12 * GNU General Public License for more details. |
| 13 * | 13 * |
| 14 * You should have received a copy of the GNU General Public License | 14 * You should have received a copy of the GNU General Public License |
| 15 * along with Adblock Plus. If not, see <http://www.gnu.org/licenses/>. | 15 * along with Adblock Plus. If not, see <http://www.gnu.org/licenses/>. |
| 16 */ | 16 */ |
| 17 | 17 |
| 18 "use strict"; | 18 "use strict"; |
| 19 | 19 |
| 20 /* globals ElemHideEmulation */ | 20 const {ElemHideEmulation} = require("content/elemHideEmulation"); |
|
Wladimir Palant
2017/08/17 10:05:38
require("../../lib/content/elemHideEmulation")? Su
kzar
2017/08/17 12:40:22
Done.
| |
| 21 | |
| 22 let myUrl = document.currentScript.src; | |
| 23 | 21 |
| 24 exports.tearDown = function(callback) | 22 exports.tearDown = function(callback) |
| 25 { | 23 { |
| 26 let styleElements = document.head.getElementsByTagName("style"); | 24 let styleElements = document.head.getElementsByTagName("style"); |
| 27 while (styleElements.length) | 25 while (styleElements.length) |
| 28 styleElements[0].parentNode.removeChild(styleElements[0]); | 26 styleElements[0].parentNode.removeChild(styleElements[0]); |
| 29 | 27 |
| 30 let child; | 28 let child; |
| 31 while (child = document.body.firstChild) | 29 while (child = document.body.firstChild) |
| 32 child.parentNode.removeChild(child); | 30 child.parentNode.removeChild(child); |
| 33 | 31 |
| 34 callback(); | 32 callback(); |
| 35 }; | 33 }; |
| 36 | 34 |
| 37 function unexpectedError(error) | |
| 38 { | |
| 39 console.error(error); | |
| 40 this.ok(false, "Unexpected error: " + error); | |
| 41 } | |
| 42 | |
| 43 function expectHidden(test, element) | 35 function expectHidden(test, element) |
| 44 { | 36 { |
| 45 test.equal(window.getComputedStyle(element).display, "none", | 37 test.equal(window.getComputedStyle(element).display, "none", |
| 46 "The element's display property should be set to 'none'"); | 38 "The element's display property should be set to 'none'"); |
| 47 } | 39 } |
| 48 | 40 |
| 49 function expectVisible(test, element) | 41 function expectVisible(test, element) |
| 50 { | 42 { |
| 51 test.notEqual(window.getComputedStyle(element).display, "none", | 43 test.notEqual(window.getComputedStyle(element).display, "none", |
| 52 "The element's display property should not be set to 'none'"); | 44 "The element's display property should not be set to 'none'"); |
| (...skipping 14 matching lines...) Expand all Loading... | |
| 67 if (styleElements.length) | 59 if (styleElements.length) |
| 68 styleElement = styleElements[0]; | 60 styleElement = styleElements[0]; |
| 69 else | 61 else |
| 70 { | 62 { |
| 71 styleElement = document.createElement("style"); | 63 styleElement = document.createElement("style"); |
| 72 document.head.appendChild(styleElement); | 64 document.head.appendChild(styleElement); |
| 73 } | 65 } |
| 74 styleElement.sheet.insertRule(rule, styleElement.sheet.cssRules.length); | 66 styleElement.sheet.insertRule(rule, styleElement.sheet.cssRules.length); |
| 75 } | 67 } |
| 76 | 68 |
| 77 // insert a <div> with a unique id and a CSS rule | 69 // Insert a <div> with a unique id and a CSS rule |
| 78 // for the the selector matching the id. | 70 // for the the selector matching the id. |
| 79 function createElementWithStyle(styleBlock, parent) | 71 function createElementWithStyle(styleBlock, parent) |
| 80 { | 72 { |
| 81 let element = document.createElement("div"); | 73 let element = document.createElement("div"); |
| 82 element.id = findUniqueId(); | 74 element.id = findUniqueId(); |
| 83 if (!parent) | 75 if (!parent) |
| 84 document.body.appendChild(element); | 76 document.body.appendChild(element); |
| 85 else | 77 else |
| 86 parent.appendChild(element); | 78 parent.appendChild(element); |
| 87 insertStyleRule("#" + element.id + " " + styleBlock); | 79 insertStyleRule("#" + element.id + " " + styleBlock); |
| 88 return element; | 80 return element; |
| 89 } | 81 } |
| 90 | 82 |
| 91 // Will ensure the class ElemHideEmulation is loaded. | |
| 92 // Pass true when it calls itself. | |
| 93 function loadElemHideEmulation(inside) | |
| 94 { | |
| 95 if (typeof ElemHideEmulation == "undefined") | |
| 96 { | |
| 97 if (inside) | |
| 98 return Promise.reject("Failed to load ElemHideEmulation."); | |
| 99 | |
| 100 return loadScript(myUrl + "/../../../lib/common.js").then(() => | |
| 101 { | |
| 102 return loadScript(myUrl + "/../../../chrome/content/elemHideEmulation.js") ; | |
| 103 }).then(() => | |
| 104 { | |
| 105 return loadElemHideEmulation(true); | |
| 106 }); | |
| 107 } | |
| 108 | |
| 109 return Promise.resolve(); | |
| 110 } | |
| 111 | |
| 112 // Create a new ElemHideEmulation instance with @selectors. | 83 // Create a new ElemHideEmulation instance with @selectors. |
| 113 function applyElemHideEmulation(selectors) | 84 function applyElemHideEmulation(selectors) |
| 114 { | 85 { |
| 115 return loadElemHideEmulation().then(() => | 86 let elemHideEmulation = new ElemHideEmulation( |
| 116 { | 87 window, |
| 117 let elemHideEmulation = new ElemHideEmulation( | 88 callback => |
| 118 window, | 89 { |
| 119 callback => | 90 let patterns = []; |
| 91 selectors.forEach(selector => | |
| 120 { | 92 { |
| 121 let patterns = []; | 93 patterns.push({selector}); |
| 122 selectors.forEach(selector => | 94 }); |
| 123 { | 95 callback(patterns); |
| 124 patterns.push({selector}); | 96 }, |
| 125 }); | 97 newSelectors => |
| 126 callback(patterns); | 98 { |
| 127 }, | 99 if (!newSelectors.length) |
| 128 newSelectors => | 100 return; |
| 129 { | 101 let selector = newSelectors.join(", "); |
| 130 if (!newSelectors.length) | 102 insertStyleRule(selector + "{display: none !important;}"); |
| 131 return; | 103 }, |
| 132 let selector = newSelectors.join(", "); | 104 elems => |
| 133 insertStyleRule(selector + "{display: none !important;}"); | 105 { |
| 134 }, | 106 for (let elem of elems) |
| 135 elems => | 107 elem.style.display = "none"; |
| 136 { | 108 } |
| 137 for (let elem of elems) | 109 ); |
| 138 elem.style.display = "none"; | |
| 139 } | |
| 140 ); | |
| 141 | 110 |
| 142 elemHideEmulation.apply(); | 111 return elemHideEmulation.apply(); |
|
Wladimir Palant
2017/08/17 10:05:39
elemHideEmulation.apply() doesn't return any resul
kzar
2017/08/17 12:40:22
Done.
| |
| 143 return Promise.resolve(elemHideEmulation); | |
| 144 }); | |
| 145 } | 112 } |
| 146 | 113 |
| 147 exports.testVerbatimPropertySelector = function(test) | 114 exports.testVerbatimPropertySelector = function(test) |
| 148 { | 115 { |
| 149 let toHide = createElementWithStyle("{background-color: #000}"); | 116 let toHide = createElementWithStyle("{background-color: #000}"); |
| 150 applyElemHideEmulation( | 117 applyElemHideEmulation( |
| 151 [":-abp-properties(background-color: rgb(0, 0, 0))"] | 118 [":-abp-properties(background-color: rgb(0, 0, 0))"] |
| 152 ).then(() => | 119 ); |
| 153 { | 120 expectHidden(test, toHide); |
| 154 expectHidden(test, toHide); | 121 test.done(); |
| 155 }).catch(unexpectedError.bind(test)).then(() => test.done()); | |
| 156 }; | 122 }; |
| 157 | 123 |
| 158 exports.testVerbatimPropertySelectorWithPrefix = function(test) | 124 exports.testVerbatimPropertySelectorWithPrefix = function(test) |
| 159 { | 125 { |
| 160 let parent = createElementWithStyle("{background-color: #000}"); | 126 let parent = createElementWithStyle("{background-color: #000}"); |
| 161 let toHide = createElementWithStyle("{background-color: #000}", parent); | 127 let toHide = createElementWithStyle("{background-color: #000}", parent); |
| 162 applyElemHideEmulation( | 128 applyElemHideEmulation( |
| 163 ["div > :-abp-properties(background-color: rgb(0, 0, 0))"] | 129 ["div > :-abp-properties(background-color: rgb(0, 0, 0))"] |
| 164 ).then(() => | 130 ); |
| 165 { | 131 expectVisible(test, parent); |
| 166 expectVisible(test, parent); | 132 expectHidden(test, toHide); |
| 167 expectHidden(test, toHide); | 133 test.done(); |
| 168 }).catch(unexpectedError.bind(test)).then(() => test.done()); | |
| 169 }; | 134 }; |
| 170 | 135 |
| 171 exports.testVerbatimPropertySelectorWithPrefixNoMatch = function(test) | 136 exports.testVerbatimPropertySelectorWithPrefixNoMatch = function(test) |
| 172 { | 137 { |
| 173 let parent = createElementWithStyle("{background-color: #000}"); | 138 let parent = createElementWithStyle("{background-color: #000}"); |
| 174 let toHide = createElementWithStyle("{background-color: #fff}", parent); | 139 let toHide = createElementWithStyle("{background-color: #fff}", parent); |
| 175 applyElemHideEmulation( | 140 applyElemHideEmulation( |
| 176 ["div > :-abp-properties(background-color: rgb(0, 0, 0))"] | 141 ["div > :-abp-properties(background-color: rgb(0, 0, 0))"] |
| 177 ).then(() => | 142 ); |
| 178 { | 143 expectVisible(test, parent); |
| 179 expectVisible(test, parent); | 144 expectVisible(test, toHide); |
| 180 expectVisible(test, toHide); | 145 test.done(); |
| 181 }).catch(unexpectedError.bind(test)).then(() => test.done()); | |
| 182 }; | 146 }; |
| 183 | 147 |
| 184 exports.testVerbatimPropertySelectorWithSuffix = function(test) | 148 exports.testVerbatimPropertySelectorWithSuffix = function(test) |
| 185 { | 149 { |
| 186 let parent = createElementWithStyle("{background-color: #000}"); | 150 let parent = createElementWithStyle("{background-color: #000}"); |
| 187 let toHide = createElementWithStyle("{background-color: #000}", parent); | 151 let toHide = createElementWithStyle("{background-color: #000}", parent); |
| 188 applyElemHideEmulation( | 152 applyElemHideEmulation( |
| 189 [":-abp-properties(background-color: rgb(0, 0, 0)) > div"] | 153 [":-abp-properties(background-color: rgb(0, 0, 0)) > div"] |
| 190 ).then(() => | 154 ); |
| 191 { | 155 expectVisible(test, parent); |
| 192 expectVisible(test, parent); | 156 expectHidden(test, toHide); |
| 193 expectHidden(test, toHide); | 157 test.done(); |
| 194 }).catch(unexpectedError.bind(test)).then(() => test.done()); | |
| 195 }; | 158 }; |
| 196 | 159 |
| 197 exports.testVerbatimPropertyPseudoSelectorWithPrefixAndSuffix = function(test) | 160 exports.testVerbatimPropertyPseudoSelectorWithPrefixAndSuffix = function(test) |
| 198 { | 161 { |
| 199 let parent = createElementWithStyle("{background-color: #000}"); | 162 let parent = createElementWithStyle("{background-color: #000}"); |
| 200 let middle = createElementWithStyle("{background-color: #000}", parent); | 163 let middle = createElementWithStyle("{background-color: #000}", parent); |
| 201 let toHide = createElementWithStyle("{background-color: #000}", middle); | 164 let toHide = createElementWithStyle("{background-color: #000}", middle); |
| 202 applyElemHideEmulation( | 165 applyElemHideEmulation( |
| 203 ["div > :-abp-properties(background-color: rgb(0, 0, 0)) > div"] | 166 ["div > :-abp-properties(background-color: rgb(0, 0, 0)) > div"] |
| 204 ).then(() => | 167 ); |
| 205 { | 168 expectVisible(test, parent); |
| 206 expectVisible(test, parent); | 169 expectVisible(test, middle); |
| 207 expectVisible(test, middle); | 170 expectHidden(test, toHide); |
| 208 expectHidden(test, toHide); | 171 test.done(); |
| 209 }).catch(unexpectedError.bind(test)).then(() => test.done()); | |
| 210 }; | 172 }; |
| 211 | 173 |
| 212 exports.testPropertySelectorWithWildcard = function(test) | 174 exports.testPropertySelectorWithWildcard = function(test) |
| 213 { | 175 { |
| 214 let toHide = createElementWithStyle("{background-color: #000}"); | 176 let toHide = createElementWithStyle("{background-color: #000}"); |
| 215 applyElemHideEmulation( | 177 applyElemHideEmulation( |
| 216 [":-abp-properties(*color: rgb(0, 0, 0))"] | 178 [":-abp-properties(*color: rgb(0, 0, 0))"] |
| 217 ).then(() => | 179 ); |
| 218 { | 180 expectHidden(test, toHide); |
| 219 expectHidden(test, toHide); | 181 test.done(); |
| 220 }).catch(unexpectedError.bind(test)).then(() => test.done()); | |
| 221 }; | 182 }; |
| 222 | 183 |
| 223 exports.testPropertySelectorWithRegularExpression = function(test) | 184 exports.testPropertySelectorWithRegularExpression = function(test) |
| 224 { | 185 { |
| 225 let toHide = createElementWithStyle("{background-color: #000}"); | 186 let toHide = createElementWithStyle("{background-color: #000}"); |
| 226 applyElemHideEmulation( | 187 applyElemHideEmulation( |
| 227 [":-abp-properties(/.*color: rgb\\(0, 0, 0\\)/)"] | 188 [":-abp-properties(/.*color: rgb\\(0, 0, 0\\)/)"] |
| 228 ).then(() => | 189 ); |
| 229 { | 190 expectHidden(test, toHide); |
| 230 expectHidden(test, toHide); | 191 test.done(); |
| 231 }).catch(unexpectedError.bind(test)).then(() => test.done()); | |
| 232 }; | 192 }; |
| 233 | 193 |
| 234 exports.testPropertySelectorWithEscapedBrace = function(test) | 194 exports.testPropertySelectorWithEscapedBrace = function(test) |
| 235 { | 195 { |
| 236 let toHide = createElementWithStyle("{background-color: #000}"); | 196 let toHide = createElementWithStyle("{background-color: #000}"); |
| 237 applyElemHideEmulation( | 197 applyElemHideEmulation( |
| 238 [":-abp-properties(/background.\\x7B 0,6\\x7D : rgb\\(0, 0, 0\\)/)"] | 198 [":-abp-properties(/background.\\x7B 0,6\\x7D : rgb\\(0, 0, 0\\)/)"] |
| 239 ).then(() => | 199 ); |
| 240 { | 200 expectHidden(test, toHide); |
| 241 expectHidden(test, toHide); | 201 test.done(); |
| 242 }).catch(unexpectedError.bind(test)).then(() => test.done()); | |
| 243 }; | 202 }; |
| 244 | 203 |
| 245 exports.testPropertySelectorWithImproperlyEscapedBrace = function(test) | 204 exports.testPropertySelectorWithImproperlyEscapedBrace = function(test) |
| 246 { | 205 { |
| 247 let toHide = createElementWithStyle("{background-color: #000}"); | 206 let toHide = createElementWithStyle("{background-color: #000}"); |
| 248 applyElemHideEmulation( | 207 applyElemHideEmulation( |
| 249 [":-abp-properties(/background.\\x7B0,6\\x7D: rgb\\(0, 0, 0\\)/)"] | 208 [":-abp-properties(/background.\\x7B0,6\\x7D: rgb\\(0, 0, 0\\)/)"] |
| 250 ).then(() => | 209 ); |
| 251 { | 210 expectVisible(test, toHide); |
| 252 expectVisible(test, toHide); | 211 test.done(); |
| 253 }).catch(unexpectedError.bind(test)).then(() => test.done()); | |
| 254 }; | 212 }; |
| 255 | 213 |
| 256 exports.testDynamicallyChangedProperty = function(test) | 214 exports.testDynamicallyChangedProperty = function(test) |
| 257 { | 215 { |
| 258 let toHide = createElementWithStyle("{}"); | 216 let toHide = createElementWithStyle("{}"); |
| 259 applyElemHideEmulation( | 217 applyElemHideEmulation( |
| 260 [":-abp-properties(background-color: rgb(0, 0, 0))"] | 218 [":-abp-properties(background-color: rgb(0, 0, 0))"] |
| 261 ).then(() => | 219 ); |
| 220 | |
| 221 expectVisible(test, toHide); | |
| 222 insertStyleRule("#" + toHide.id + " {background-color: #000}"); | |
| 223 | |
| 224 // Re-evaluation will only happen after a few seconds | |
| 225 expectVisible(test, toHide); | |
| 226 window.setTimeout(() => | |
| 262 { | 227 { |
| 263 expectVisible(test, toHide); | 228 expectHidden(test, toHide); |
| 264 insertStyleRule("#" + toHide.id + " {background-color: #000}"); | 229 test.done(); |
| 265 return new Promise((resolve, reject) => | 230 }, 4000); |
| 266 { | |
| 267 // Re-evaluation will only happen after a few seconds | |
| 268 expectVisible(test, toHide); | |
| 269 window.setTimeout(() => | |
| 270 { | |
| 271 expectHidden(test, toHide); | |
| 272 resolve(); | |
| 273 }, 4000); | |
| 274 }); | |
| 275 }).catch(unexpectedError.bind(test)).then(() => test.done()); | |
| 276 }; | 231 }; |
| 277 | 232 |
| 278 exports.testPseudoClassWithPropBeforeSelector = function(test) | 233 exports.testPseudoClassWithPropBeforeSelector = function(test) |
| 279 { | 234 { |
| 280 let parent = createElementWithStyle("{}"); | 235 let parent = createElementWithStyle("{}"); |
| 281 let child = createElementWithStyle("{background-color: #000}", parent); | 236 let child = createElementWithStyle("{background-color: #000}", parent); |
| 282 insertStyleRule(`#${child.id}::before {content: "publicite"}`); | 237 insertStyleRule(`#${child.id}::before {content: "publicite"}`); |
| 283 | 238 |
| 284 applyElemHideEmulation( | 239 applyElemHideEmulation( |
| 285 ["div:-abp-properties(content: \"publicite\")"] | 240 ["div:-abp-properties(content: \"publicite\")"] |
| 286 ).then(() => | 241 ); |
| 287 { | 242 expectHidden(test, child); |
| 288 expectHidden(test, child); | 243 expectVisible(test, parent); |
| 289 expectVisible(test, parent); | 244 test.done(); |
| 290 }).catch(unexpectedError.bind(test)).then(() => test.done()); | |
| 291 }; | 245 }; |
| 292 | 246 |
| 293 exports.testPseudoClassHasSelector = function(test) | 247 exports.testPseudoClassHasSelector = function(test) |
| 294 { | 248 { |
| 295 let toHide = createElementWithStyle("{}"); | 249 let toHide = createElementWithStyle("{}"); |
| 296 applyElemHideEmulation( | 250 applyElemHideEmulation( |
| 297 ["div:-abp-has(div)"] | 251 ["div:-abp-has(div)"] |
| 298 ).then(() => | 252 ); |
| 299 { | 253 expectVisible(test, toHide); |
| 300 expectVisible(test, toHide); | 254 test.done(); |
| 301 }).catch(unexpectedError.bind(test)).then(() => test.done()); | |
| 302 }; | 255 }; |
| 303 | 256 |
| 304 exports.testPseudoClassHasSelectorWithPrefix = function(test) | 257 exports.testPseudoClassHasSelectorWithPrefix = function(test) |
| 305 { | 258 { |
| 306 let parent = createElementWithStyle("{}"); | 259 let parent = createElementWithStyle("{}"); |
| 307 let child = createElementWithStyle("{}", parent); | 260 let child = createElementWithStyle("{}", parent); |
| 308 applyElemHideEmulation( | 261 applyElemHideEmulation( |
| 309 ["div:-abp-has(div)"] | 262 ["div:-abp-has(div)"] |
| 310 ).then(() => | 263 ); |
| 311 { | 264 expectHidden(test, parent); |
| 312 expectHidden(test, parent); | 265 expectVisible(test, child); |
| 313 expectVisible(test, child); | 266 test.done(); |
| 314 }).catch(unexpectedError.bind(test)).then(() => test.done()); | |
| 315 }; | 267 }; |
| 316 | 268 |
| 317 exports.testPseudoClassHasSelectorWithSuffix = function(test) | 269 exports.testPseudoClassHasSelectorWithSuffix = function(test) |
| 318 { | 270 { |
| 319 let parent = createElementWithStyle("{}"); | 271 let parent = createElementWithStyle("{}"); |
| 320 let middle = createElementWithStyle("{}", parent); | 272 let middle = createElementWithStyle("{}", parent); |
| 321 let child = createElementWithStyle("{}", middle); | 273 let child = createElementWithStyle("{}", middle); |
| 322 applyElemHideEmulation( | 274 applyElemHideEmulation( |
| 323 ["div:-abp-has(div) > div"] | 275 ["div:-abp-has(div) > div"] |
| 324 ).then(() => | 276 ); |
| 325 { | 277 expectVisible(test, parent); |
| 326 expectVisible(test, parent); | 278 expectHidden(test, middle); |
| 327 expectHidden(test, middle); | 279 expectHidden(test, child); |
| 328 expectHidden(test, child); | 280 test.done(); |
| 329 }).catch(unexpectedError.bind(test)).then(() => test.done()); | |
| 330 }; | 281 }; |
| 331 | 282 |
| 332 exports.testPseudoClassHasSelectorWithSuffixSibling = function(test) | 283 exports.testPseudoClassHasSelectorWithSuffixSibling = function(test) |
| 333 { | 284 { |
| 334 let parent = createElementWithStyle("{}"); | 285 let parent = createElementWithStyle("{}"); |
| 335 let middle = createElementWithStyle("{}", parent); | 286 let middle = createElementWithStyle("{}", parent); |
| 336 let toHide = createElementWithStyle("{}"); | 287 let toHide = createElementWithStyle("{}"); |
| 337 applyElemHideEmulation( | 288 applyElemHideEmulation( |
| 338 ["div:-abp-has(div) + div"] | 289 ["div:-abp-has(div) + div"] |
| 339 ).then(() => | 290 ); |
| 340 { | 291 expectVisible(test, parent); |
| 341 expectVisible(test, parent); | 292 expectVisible(test, middle); |
| 342 expectVisible(test, middle); | 293 expectHidden(test, toHide); |
| 343 expectHidden(test, toHide); | 294 test.done(); |
| 344 }).catch(unexpectedError.bind(test)).then(() => test.done()); | |
| 345 }; | 295 }; |
| 346 | 296 |
| 347 exports.testPseudoClassHasSelectorWithSuffixSiblingChild = function(test) | 297 exports.testPseudoClassHasSelectorWithSuffixSiblingChild = function(test) |
| 348 { | 298 { |
| 349 // <div> | 299 // <div> |
| 350 // <div></div> | 300 // <div></div> |
| 351 // <div> | 301 // <div> |
| 352 // <div>to hide</div> | 302 // <div>to hide</div> |
| 353 // </div> | 303 // </div> |
| 354 // </div> | 304 // </div> |
| 355 let parent = createElementWithStyle("{}"); | 305 let parent = createElementWithStyle("{}"); |
| 356 let middle = createElementWithStyle("{}", parent); | 306 let middle = createElementWithStyle("{}", parent); |
| 357 let sibling = createElementWithStyle("{}"); | 307 let sibling = createElementWithStyle("{}"); |
| 358 let toHide = createElementWithStyle("{}", sibling); | 308 let toHide = createElementWithStyle("{}", sibling); |
| 359 applyElemHideEmulation( | 309 applyElemHideEmulation( |
| 360 ["div:-abp-has(div) + div > div"] | 310 ["div:-abp-has(div) + div > div"] |
| 361 ).then(() => | 311 ); |
| 362 { | 312 expectVisible(test, parent); |
| 363 expectVisible(test, parent); | 313 expectVisible(test, middle); |
| 364 expectVisible(test, middle); | 314 expectVisible(test, sibling); |
| 365 expectVisible(test, sibling); | 315 expectHidden(test, toHide); |
| 366 expectHidden(test, toHide); | 316 test.done(); |
| 367 }).catch(unexpectedError.bind(test)).then(() => test.done()); | |
| 368 }; | 317 }; |
| 369 | 318 |
| 370 function runTestPseudoClassHasSelectorWithHasAndWithSuffixSibling(test, selector ) | 319 function runTestPseudoClassHasSelectorWithHasAndWithSuffixSibling(test, selector ) |
| 371 { | 320 { |
| 372 document.body.innerHTML = `<div id="parent"> | 321 document.body.innerHTML = `<div id="parent"> |
| 373 <div id="middle"> | 322 <div id="middle"> |
| 374 <div id="middle1"><div id="inside" class="inside"></div></div> | 323 <div id="middle1"><div id="inside" class="inside"></div></div> |
| 375 </div> | 324 </div> |
| 376 <div id="sibling"> | 325 <div id="sibling"> |
| 377 <div id="tohide">to hide</div> | 326 <div id="tohide">to hide</div> |
| 378 </div> | 327 </div> |
| 379 <div id="sibling2"> | 328 <div id="sibling2"> |
| 380 <div id="sibling21"><div id="sibling211" class="inside"></div></div> | 329 <div id="sibling21"><div id="sibling211" class="inside"></div></div> |
| 381 </div> | 330 </div> |
| 382 </div>`; | 331 </div>`; |
| 383 let parent = document.getElementById("parent"); | 332 let parent = document.getElementById("parent"); |
| 384 let middle = document.getElementById("middle"); | 333 let middle = document.getElementById("middle"); |
| 385 let inside = document.getElementById("inside"); | 334 let inside = document.getElementById("inside"); |
| 386 let sibling = document.getElementById("sibling"); | 335 let sibling = document.getElementById("sibling"); |
| 387 let sibling2 = document.getElementById("sibling2"); | 336 let sibling2 = document.getElementById("sibling2"); |
| 388 let toHide = document.getElementById("tohide"); | 337 let toHide = document.getElementById("tohide"); |
| 389 | 338 |
| 390 insertStyleRule(".inside {}"); | 339 insertStyleRule(".inside {}"); |
| 391 | 340 |
| 392 applyElemHideEmulation( | 341 applyElemHideEmulation( |
| 393 [selector] | 342 [selector] |
| 394 ).then(() => | 343 ); |
| 395 { | 344 expectVisible(test, parent); |
| 396 expectVisible(test, parent); | 345 expectVisible(test, middle); |
| 397 expectVisible(test, middle); | 346 expectVisible(test, inside); |
| 398 expectVisible(test, inside); | 347 expectVisible(test, sibling); |
| 399 expectVisible(test, sibling); | 348 expectVisible(test, sibling2); |
| 400 expectVisible(test, sibling2); | 349 expectHidden(test, toHide); |
| 401 expectHidden(test, toHide); | 350 test.done(); |
| 402 }).catch(unexpectedError.bind(test)).then(() => test.done()); | |
| 403 } | 351 } |
| 404 | 352 |
| 405 exports.testPseudoClassHasSelectorWithHasAndWithSuffixSibling = function(test) | 353 exports.testPseudoClassHasSelectorWithHasAndWithSuffixSibling = function(test) |
| 406 { | 354 { |
| 407 runTestPseudoClassHasSelectorWithHasAndWithSuffixSibling(test, "div:-abp-has(: -abp-has(div.inside)) + div > div"); | 355 runTestPseudoClassHasSelectorWithHasAndWithSuffixSibling(test, "div:-abp-has(: -abp-has(div.inside)) + div > div"); |
| 408 }; | 356 }; |
| 409 | 357 |
| 410 exports.testPseudoClassContains = function(test) | 358 exports.testPseudoClassContains = function(test) |
| 411 { | 359 { |
| 412 document.body.innerHTML = `<div id="parent"> | 360 document.body.innerHTML = `<div id="parent"> |
| 413 <div id="middle"> | 361 <div id="middle"> |
| 414 <div id="middle1"><div id="inside" class="inside"></div></div> | 362 <div id="middle1"><div id="inside" class="inside"></div></div> |
| 415 </div> | 363 </div> |
| 416 <div id="sibling"> | 364 <div id="sibling"> |
| 417 <div id="tohide">to hide</div> | 365 <div id="tohide">to hide</div> |
| 418 </div> | 366 </div> |
| 419 <div id="sibling2"> | 367 <div id="sibling2"> |
| 420 <div id="sibling21"><div id="sibling211" class="inside"></div></div> | 368 <div id="sibling21"><div id="sibling211" class="inside"></div></div> |
| 421 </div> | 369 </div> |
| 422 </div>`; | 370 </div>`; |
| 423 let parent = document.getElementById("parent"); | 371 let parent = document.getElementById("parent"); |
| 424 let middle = document.getElementById("middle"); | 372 let middle = document.getElementById("middle"); |
| 425 let inside = document.getElementById("inside"); | 373 let inside = document.getElementById("inside"); |
| 426 let sibling = document.getElementById("sibling"); | 374 let sibling = document.getElementById("sibling"); |
| 427 let sibling2 = document.getElementById("sibling2"); | 375 let sibling2 = document.getElementById("sibling2"); |
| 428 let toHide = document.getElementById("tohide"); | 376 let toHide = document.getElementById("tohide"); |
| 429 | 377 |
| 430 applyElemHideEmulation( | 378 applyElemHideEmulation( |
| 431 ["#parent div:-abp-contains(to hide)"] | 379 ["#parent div:-abp-contains(to hide)"] |
| 432 ).then(() => | 380 ); |
| 433 { | 381 expectVisible(test, parent); |
| 434 expectVisible(test, parent); | 382 expectVisible(test, middle); |
| 435 expectVisible(test, middle); | 383 expectVisible(test, inside); |
| 436 expectVisible(test, inside); | 384 expectHidden(test, sibling); |
| 437 expectHidden(test, sibling); | 385 expectVisible(test, sibling2); |
| 438 expectVisible(test, sibling2); | 386 expectHidden(test, toHide); |
| 439 expectHidden(test, toHide); | 387 test.done(); |
| 440 }).catch(unexpectedError.bind(test)).then(() => test.done()); | |
| 441 }; | 388 }; |
| 442 | 389 |
| 443 exports.testPseudoClassHasSelectorWithPropSelector = function(test) | 390 exports.testPseudoClassHasSelectorWithPropSelector = function(test) |
| 444 { | 391 { |
| 445 let parent = createElementWithStyle("{}"); | 392 let parent = createElementWithStyle("{}"); |
| 446 let child = createElementWithStyle("{background-color: #000}", parent); | 393 let child = createElementWithStyle("{background-color: #000}", parent); |
| 447 applyElemHideEmulation( | 394 applyElemHideEmulation( |
| 448 ["div:-abp-has(:-abp-properties(background-color: rgb(0, 0, 0)))"] | 395 ["div:-abp-has(:-abp-properties(background-color: rgb(0, 0, 0)))"] |
| 449 ).then(() => | 396 ); |
| 450 { | 397 expectVisible(test, child); |
| 451 expectVisible(test, child); | 398 expectHidden(test, parent); |
| 452 expectHidden(test, parent); | 399 test.done(); |
| 453 }).catch(unexpectedError.bind(test)).then(() => test.done()); | |
| 454 }; | 400 }; |
| 455 | 401 |
| 456 exports.testPseudoClassHasSelectorWithPropSelector2 = function(test) | 402 exports.testPseudoClassHasSelectorWithPropSelector2 = function(test) |
| 457 { | 403 { |
| 458 let parent = createElementWithStyle("{}"); | 404 let parent = createElementWithStyle("{}"); |
| 459 let child = createElementWithStyle("{}", parent); | 405 let child = createElementWithStyle("{}", parent); |
| 460 insertStyleRule("body #" + parent.id + " > div { background-color: #000}"); | 406 insertStyleRule("body #" + parent.id + " > div { background-color: #000}"); |
| 461 applyElemHideEmulation( | 407 applyElemHideEmulation( |
| 462 ["div:-abp-has(:-abp-properties(background-color: rgb(0, 0, 0)))"] | 408 ["div:-abp-has(:-abp-properties(background-color: rgb(0, 0, 0)))"] |
| 463 ).then(() => | 409 ); |
| 464 { | 410 expectVisible(test, child); |
| 465 expectVisible(test, child); | 411 expectHidden(test, parent); |
| 466 expectHidden(test, parent); | 412 test.done(); |
| 467 }).catch(unexpectedError.bind(test)).then(() => test.done()); | |
| 468 }; | 413 }; |
| OLD | NEW |