Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code

Delta Between Two Patch Sets: test/browser/elemHideEmulation.js

Issue 29517687: Issue 5079, 5516 - Use webpack for browser tests, modules for content scripts (Closed)
Left Patch Set: Created Aug. 16, 2017, 3:40 p.m.
Right Patch Set: Addressed nits Created Aug. 17, 2017, 1:25 p.m.
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
Left: Side by side diff | Download
Right: Side by side diff | Download
« no previous file with change/comment | « test/browser/_bootstrap.js ('k') | test_runner.js » ('j') | no next file with change/comment »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
LEFTRIGHT
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 const {ElemHideEmulation} = require("content/elemHideEmulation"); 20 const {ElemHideEmulation} = require("../../lib/content/elemHideEmulation");
Wladimir Palant 2017/08/17 10:05:38 require("../../lib/content/elemHideEmulation")? Su
kzar 2017/08/17 12:40:22 Done.
21 21
22 exports.tearDown = function(callback) 22 exports.tearDown = function(callback)
23 { 23 {
24 let styleElements = document.head.getElementsByTagName("style"); 24 let styleElements = document.head.getElementsByTagName("style");
25 while (styleElements.length) 25 while (styleElements.length)
26 styleElements[0].parentNode.removeChild(styleElements[0]); 26 styleElements[0].parentNode.removeChild(styleElements[0]);
27 27
28 let child; 28 let child;
29 while (child = document.body.firstChild) 29 while (child = document.body.firstChild)
30 child.parentNode.removeChild(child); 30 child.parentNode.removeChild(child);
31 31
32 callback(); 32 callback();
33 }; 33 };
34
35 function unexpectedError(error)
36 {
37 console.error(error);
38 this.ok(false, "Unexpected error: " + error);
39 }
34 40
35 function expectHidden(test, element) 41 function expectHidden(test, element)
36 { 42 {
37 test.equal(window.getComputedStyle(element).display, "none", 43 test.equal(window.getComputedStyle(element).display, "none",
38 "The element's display property should be set to 'none'"); 44 "The element's display property should be set to 'none'");
39 } 45 }
40 46
41 function expectVisible(test, element) 47 function expectVisible(test, element)
42 { 48 {
43 test.notEqual(window.getComputedStyle(element).display, "none", 49 test.notEqual(window.getComputedStyle(element).display, "none",
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
76 document.body.appendChild(element); 82 document.body.appendChild(element);
77 else 83 else
78 parent.appendChild(element); 84 parent.appendChild(element);
79 insertStyleRule("#" + element.id + " " + styleBlock); 85 insertStyleRule("#" + element.id + " " + styleBlock);
80 return element; 86 return element;
81 } 87 }
82 88
83 // Create a new ElemHideEmulation instance with @selectors. 89 // Create a new ElemHideEmulation instance with @selectors.
84 function applyElemHideEmulation(selectors) 90 function applyElemHideEmulation(selectors)
85 { 91 {
86 let elemHideEmulation = new ElemHideEmulation( 92 return Promise.resolve().then(() =>
87 window, 93 {
88 callback => 94 let elemHideEmulation = new ElemHideEmulation(
89 { 95 window,
90 let patterns = []; 96 callback =>
91 selectors.forEach(selector =>
92 { 97 {
93 patterns.push({selector}); 98 let patterns = [];
94 }); 99 selectors.forEach(selector =>
95 callback(patterns); 100 {
96 }, 101 patterns.push({selector});
97 newSelectors => 102 });
98 { 103 callback(patterns);
99 if (!newSelectors.length) 104 },
100 return; 105 newSelectors =>
101 let selector = newSelectors.join(", "); 106 {
102 insertStyleRule(selector + "{display: none !important;}"); 107 if (!newSelectors.length)
103 }, 108 return;
104 elems => 109 let selector = newSelectors.join(", ");
105 { 110 insertStyleRule(selector + "{display: none !important;}");
106 for (let elem of elems) 111 },
107 elem.style.display = "none"; 112 elems =>
108 } 113 {
109 ); 114 for (let elem of elems)
110 115 elem.style.display = "none";
111 return elemHideEmulation.apply(); 116 }
Wladimir Palant 2017/08/17 10:05:39 elemHideEmulation.apply() doesn't return any resul
kzar 2017/08/17 12:40:22 Done.
117 );
118
119 elemHideEmulation.apply();
120 return elemHideEmulation;
121 });
112 } 122 }
113 123
114 exports.testVerbatimPropertySelector = function(test) 124 exports.testVerbatimPropertySelector = function(test)
115 { 125 {
116 let toHide = createElementWithStyle("{background-color: #000}"); 126 let toHide = createElementWithStyle("{background-color: #000}");
117 applyElemHideEmulation( 127 applyElemHideEmulation(
118 [":-abp-properties(background-color: rgb(0, 0, 0))"] 128 [":-abp-properties(background-color: rgb(0, 0, 0))"]
119 ); 129 ).then(() =>
120 expectHidden(test, toHide); 130 {
121 test.done(); 131 expectHidden(test, toHide);
132 }).catch(unexpectedError.bind(test)).then(() => test.done());
122 }; 133 };
123 134
124 exports.testVerbatimPropertySelectorWithPrefix = function(test) 135 exports.testVerbatimPropertySelectorWithPrefix = function(test)
125 { 136 {
126 let parent = createElementWithStyle("{background-color: #000}"); 137 let parent = createElementWithStyle("{background-color: #000}");
127 let toHide = createElementWithStyle("{background-color: #000}", parent); 138 let toHide = createElementWithStyle("{background-color: #000}", parent);
128 applyElemHideEmulation( 139 applyElemHideEmulation(
129 ["div > :-abp-properties(background-color: rgb(0, 0, 0))"] 140 ["div > :-abp-properties(background-color: rgb(0, 0, 0))"]
130 ); 141 ).then(() =>
131 expectVisible(test, parent); 142 {
132 expectHidden(test, toHide); 143 expectVisible(test, parent);
133 test.done(); 144 expectHidden(test, toHide);
145 }).catch(unexpectedError.bind(test)).then(() => test.done());
134 }; 146 };
135 147
136 exports.testVerbatimPropertySelectorWithPrefixNoMatch = function(test) 148 exports.testVerbatimPropertySelectorWithPrefixNoMatch = function(test)
137 { 149 {
138 let parent = createElementWithStyle("{background-color: #000}"); 150 let parent = createElementWithStyle("{background-color: #000}");
139 let toHide = createElementWithStyle("{background-color: #fff}", parent); 151 let toHide = createElementWithStyle("{background-color: #fff}", parent);
140 applyElemHideEmulation( 152 applyElemHideEmulation(
141 ["div > :-abp-properties(background-color: rgb(0, 0, 0))"] 153 ["div > :-abp-properties(background-color: rgb(0, 0, 0))"]
142 ); 154 ).then(() =>
143 expectVisible(test, parent); 155 {
144 expectVisible(test, toHide); 156 expectVisible(test, parent);
145 test.done(); 157 expectVisible(test, toHide);
158 }).catch(unexpectedError.bind(test)).then(() => test.done());
146 }; 159 };
147 160
148 exports.testVerbatimPropertySelectorWithSuffix = function(test) 161 exports.testVerbatimPropertySelectorWithSuffix = function(test)
149 { 162 {
150 let parent = createElementWithStyle("{background-color: #000}"); 163 let parent = createElementWithStyle("{background-color: #000}");
151 let toHide = createElementWithStyle("{background-color: #000}", parent); 164 let toHide = createElementWithStyle("{background-color: #000}", parent);
152 applyElemHideEmulation( 165 applyElemHideEmulation(
153 [":-abp-properties(background-color: rgb(0, 0, 0)) > div"] 166 [":-abp-properties(background-color: rgb(0, 0, 0)) > div"]
154 ); 167 ).then(() =>
155 expectVisible(test, parent); 168 {
156 expectHidden(test, toHide); 169 expectVisible(test, parent);
157 test.done(); 170 expectHidden(test, toHide);
171 }).catch(unexpectedError.bind(test)).then(() => test.done());
158 }; 172 };
159 173
160 exports.testVerbatimPropertyPseudoSelectorWithPrefixAndSuffix = function(test) 174 exports.testVerbatimPropertyPseudoSelectorWithPrefixAndSuffix = function(test)
161 { 175 {
162 let parent = createElementWithStyle("{background-color: #000}"); 176 let parent = createElementWithStyle("{background-color: #000}");
163 let middle = createElementWithStyle("{background-color: #000}", parent); 177 let middle = createElementWithStyle("{background-color: #000}", parent);
164 let toHide = createElementWithStyle("{background-color: #000}", middle); 178 let toHide = createElementWithStyle("{background-color: #000}", middle);
165 applyElemHideEmulation( 179 applyElemHideEmulation(
166 ["div > :-abp-properties(background-color: rgb(0, 0, 0)) > div"] 180 ["div > :-abp-properties(background-color: rgb(0, 0, 0)) > div"]
167 ); 181 ).then(() =>
168 expectVisible(test, parent); 182 {
169 expectVisible(test, middle); 183 expectVisible(test, parent);
170 expectHidden(test, toHide); 184 expectVisible(test, middle);
171 test.done(); 185 expectHidden(test, toHide);
186 }).catch(unexpectedError.bind(test)).then(() => test.done());
172 }; 187 };
173 188
174 exports.testPropertySelectorWithWildcard = function(test) 189 exports.testPropertySelectorWithWildcard = function(test)
175 { 190 {
176 let toHide = createElementWithStyle("{background-color: #000}"); 191 let toHide = createElementWithStyle("{background-color: #000}");
177 applyElemHideEmulation( 192 applyElemHideEmulation(
178 [":-abp-properties(*color: rgb(0, 0, 0))"] 193 [":-abp-properties(*color: rgb(0, 0, 0))"]
179 ); 194 ).then(() =>
180 expectHidden(test, toHide); 195 {
181 test.done(); 196 expectHidden(test, toHide);
197 }).catch(unexpectedError.bind(test)).then(() => test.done());
182 }; 198 };
183 199
184 exports.testPropertySelectorWithRegularExpression = function(test) 200 exports.testPropertySelectorWithRegularExpression = function(test)
185 { 201 {
186 let toHide = createElementWithStyle("{background-color: #000}"); 202 let toHide = createElementWithStyle("{background-color: #000}");
187 applyElemHideEmulation( 203 applyElemHideEmulation(
188 [":-abp-properties(/.*color: rgb\\(0, 0, 0\\)/)"] 204 [":-abp-properties(/.*color: rgb\\(0, 0, 0\\)/)"]
189 ); 205 ).then(() =>
190 expectHidden(test, toHide); 206 {
191 test.done(); 207 expectHidden(test, toHide);
208 }).catch(unexpectedError.bind(test)).then(() => test.done());
192 }; 209 };
193 210
194 exports.testPropertySelectorWithEscapedBrace = function(test) 211 exports.testPropertySelectorWithEscapedBrace = function(test)
195 { 212 {
196 let toHide = createElementWithStyle("{background-color: #000}"); 213 let toHide = createElementWithStyle("{background-color: #000}");
197 applyElemHideEmulation( 214 applyElemHideEmulation(
198 [":-abp-properties(/background.\\x7B 0,6\\x7D : rgb\\(0, 0, 0\\)/)"] 215 [":-abp-properties(/background.\\x7B 0,6\\x7D : rgb\\(0, 0, 0\\)/)"]
199 ); 216 ).then(() =>
200 expectHidden(test, toHide); 217 {
201 test.done(); 218 expectHidden(test, toHide);
219 }).catch(unexpectedError.bind(test)).then(() => test.done());
202 }; 220 };
203 221
204 exports.testPropertySelectorWithImproperlyEscapedBrace = function(test) 222 exports.testPropertySelectorWithImproperlyEscapedBrace = function(test)
205 { 223 {
206 let toHide = createElementWithStyle("{background-color: #000}"); 224 let toHide = createElementWithStyle("{background-color: #000}");
207 applyElemHideEmulation( 225 applyElemHideEmulation(
208 [":-abp-properties(/background.\\x7B0,6\\x7D: rgb\\(0, 0, 0\\)/)"] 226 [":-abp-properties(/background.\\x7B0,6\\x7D: rgb\\(0, 0, 0\\)/)"]
209 ); 227 ).then(() =>
210 expectVisible(test, toHide); 228 {
211 test.done(); 229 expectVisible(test, toHide);
230 }).catch(unexpectedError.bind(test)).then(() => test.done());
212 }; 231 };
213 232
214 exports.testDynamicallyChangedProperty = function(test) 233 exports.testDynamicallyChangedProperty = function(test)
215 { 234 {
216 let toHide = createElementWithStyle("{}"); 235 let toHide = createElementWithStyle("{}");
217 applyElemHideEmulation( 236 applyElemHideEmulation(
218 [":-abp-properties(background-color: rgb(0, 0, 0))"] 237 [":-abp-properties(background-color: rgb(0, 0, 0))"]
219 ); 238 ).then(() =>
220 239 {
221 expectVisible(test, toHide); 240 expectVisible(test, toHide);
222 insertStyleRule("#" + toHide.id + " {background-color: #000}"); 241 insertStyleRule("#" + toHide.id + " {background-color: #000}");
223 242 return new Promise((resolve, reject) =>
224 // Re-evaluation will only happen after a few seconds 243 {
225 expectVisible(test, toHide); 244 // Re-evaluation will only happen after a few seconds
226 window.setTimeout(() => 245 expectVisible(test, toHide);
227 { 246 window.setTimeout(() =>
228 expectHidden(test, toHide); 247 {
229 test.done(); 248 expectHidden(test, toHide);
230 }, 4000); 249 resolve();
250 }, 4000);
251 });
252 }).catch(unexpectedError.bind(test)).then(() => test.done());
231 }; 253 };
232 254
233 exports.testPseudoClassWithPropBeforeSelector = function(test) 255 exports.testPseudoClassWithPropBeforeSelector = function(test)
234 { 256 {
235 let parent = createElementWithStyle("{}"); 257 let parent = createElementWithStyle("{}");
236 let child = createElementWithStyle("{background-color: #000}", parent); 258 let child = createElementWithStyle("{background-color: #000}", parent);
237 insertStyleRule(`#${child.id}::before {content: "publicite"}`); 259 insertStyleRule(`#${child.id}::before {content: "publicite"}`);
238 260
239 applyElemHideEmulation( 261 applyElemHideEmulation(
240 ["div:-abp-properties(content: \"publicite\")"] 262 ["div:-abp-properties(content: \"publicite\")"]
241 ); 263 ).then(() =>
242 expectHidden(test, child); 264 {
243 expectVisible(test, parent); 265 expectHidden(test, child);
244 test.done(); 266 expectVisible(test, parent);
267 }).catch(unexpectedError.bind(test)).then(() => test.done());
245 }; 268 };
246 269
247 exports.testPseudoClassHasSelector = function(test) 270 exports.testPseudoClassHasSelector = function(test)
248 { 271 {
249 let toHide = createElementWithStyle("{}"); 272 let toHide = createElementWithStyle("{}");
250 applyElemHideEmulation( 273 applyElemHideEmulation(
251 ["div:-abp-has(div)"] 274 ["div:-abp-has(div)"]
252 ); 275 ).then(() =>
253 expectVisible(test, toHide); 276 {
254 test.done(); 277 expectVisible(test, toHide);
278 }).catch(unexpectedError.bind(test)).then(() => test.done());
255 }; 279 };
256 280
257 exports.testPseudoClassHasSelectorWithPrefix = function(test) 281 exports.testPseudoClassHasSelectorWithPrefix = function(test)
258 { 282 {
259 let parent = createElementWithStyle("{}"); 283 let parent = createElementWithStyle("{}");
260 let child = createElementWithStyle("{}", parent); 284 let child = createElementWithStyle("{}", parent);
261 applyElemHideEmulation( 285 applyElemHideEmulation(
262 ["div:-abp-has(div)"] 286 ["div:-abp-has(div)"]
263 ); 287 ).then(() =>
264 expectHidden(test, parent); 288 {
265 expectVisible(test, child); 289 expectHidden(test, parent);
266 test.done(); 290 expectVisible(test, child);
291 }).catch(unexpectedError.bind(test)).then(() => test.done());
267 }; 292 };
268 293
269 exports.testPseudoClassHasSelectorWithSuffix = function(test) 294 exports.testPseudoClassHasSelectorWithSuffix = function(test)
270 { 295 {
271 let parent = createElementWithStyle("{}"); 296 let parent = createElementWithStyle("{}");
272 let middle = createElementWithStyle("{}", parent); 297 let middle = createElementWithStyle("{}", parent);
273 let child = createElementWithStyle("{}", middle); 298 let child = createElementWithStyle("{}", middle);
274 applyElemHideEmulation( 299 applyElemHideEmulation(
275 ["div:-abp-has(div) > div"] 300 ["div:-abp-has(div) > div"]
276 ); 301 ).then(() =>
277 expectVisible(test, parent); 302 {
278 expectHidden(test, middle); 303 expectVisible(test, parent);
279 expectHidden(test, child); 304 expectHidden(test, middle);
280 test.done(); 305 expectHidden(test, child);
306 }).catch(unexpectedError.bind(test)).then(() => test.done());
281 }; 307 };
282 308
283 exports.testPseudoClassHasSelectorWithSuffixSibling = function(test) 309 exports.testPseudoClassHasSelectorWithSuffixSibling = function(test)
284 { 310 {
285 let parent = createElementWithStyle("{}"); 311 let parent = createElementWithStyle("{}");
286 let middle = createElementWithStyle("{}", parent); 312 let middle = createElementWithStyle("{}", parent);
287 let toHide = createElementWithStyle("{}"); 313 let toHide = createElementWithStyle("{}");
288 applyElemHideEmulation( 314 applyElemHideEmulation(
289 ["div:-abp-has(div) + div"] 315 ["div:-abp-has(div) + div"]
290 ); 316 ).then(() =>
291 expectVisible(test, parent); 317 {
292 expectVisible(test, middle); 318 expectVisible(test, parent);
293 expectHidden(test, toHide); 319 expectVisible(test, middle);
294 test.done(); 320 expectHidden(test, toHide);
321 }).catch(unexpectedError.bind(test)).then(() => test.done());
295 }; 322 };
296 323
297 exports.testPseudoClassHasSelectorWithSuffixSiblingChild = function(test) 324 exports.testPseudoClassHasSelectorWithSuffixSiblingChild = function(test)
298 { 325 {
299 // <div> 326 // <div>
300 // <div></div> 327 // <div></div>
301 // <div> 328 // <div>
302 // <div>to hide</div> 329 // <div>to hide</div>
303 // </div> 330 // </div>
304 // </div> 331 // </div>
305 let parent = createElementWithStyle("{}"); 332 let parent = createElementWithStyle("{}");
306 let middle = createElementWithStyle("{}", parent); 333 let middle = createElementWithStyle("{}", parent);
307 let sibling = createElementWithStyle("{}"); 334 let sibling = createElementWithStyle("{}");
308 let toHide = createElementWithStyle("{}", sibling); 335 let toHide = createElementWithStyle("{}", sibling);
309 applyElemHideEmulation( 336 applyElemHideEmulation(
310 ["div:-abp-has(div) + div > div"] 337 ["div:-abp-has(div) + div > div"]
311 ); 338 ).then(() =>
312 expectVisible(test, parent); 339 {
313 expectVisible(test, middle); 340 expectVisible(test, parent);
314 expectVisible(test, sibling); 341 expectVisible(test, middle);
315 expectHidden(test, toHide); 342 expectVisible(test, sibling);
316 test.done(); 343 expectHidden(test, toHide);
344 }).catch(unexpectedError.bind(test)).then(() => test.done());
317 }; 345 };
318 346
319 function runTestPseudoClassHasSelectorWithHasAndWithSuffixSibling(test, selector ) 347 function runTestPseudoClassHasSelectorWithHasAndWithSuffixSibling(test, selector )
320 { 348 {
321 document.body.innerHTML = `<div id="parent"> 349 document.body.innerHTML = `<div id="parent">
322 <div id="middle"> 350 <div id="middle">
323 <div id="middle1"><div id="inside" class="inside"></div></div> 351 <div id="middle1"><div id="inside" class="inside"></div></div>
324 </div> 352 </div>
325 <div id="sibling"> 353 <div id="sibling">
326 <div id="tohide">to hide</div> 354 <div id="tohide">to hide</div>
327 </div> 355 </div>
328 <div id="sibling2"> 356 <div id="sibling2">
329 <div id="sibling21"><div id="sibling211" class="inside"></div></div> 357 <div id="sibling21"><div id="sibling211" class="inside"></div></div>
330 </div> 358 </div>
331 </div>`; 359 </div>`;
332 let parent = document.getElementById("parent"); 360 let parent = document.getElementById("parent");
333 let middle = document.getElementById("middle"); 361 let middle = document.getElementById("middle");
334 let inside = document.getElementById("inside"); 362 let inside = document.getElementById("inside");
335 let sibling = document.getElementById("sibling"); 363 let sibling = document.getElementById("sibling");
336 let sibling2 = document.getElementById("sibling2"); 364 let sibling2 = document.getElementById("sibling2");
337 let toHide = document.getElementById("tohide"); 365 let toHide = document.getElementById("tohide");
338 366
339 insertStyleRule(".inside {}"); 367 insertStyleRule(".inside {}");
340 368
341 applyElemHideEmulation( 369 applyElemHideEmulation(
342 [selector] 370 [selector]
343 ); 371 ).then(() =>
344 expectVisible(test, parent); 372 {
345 expectVisible(test, middle); 373 expectVisible(test, parent);
346 expectVisible(test, inside); 374 expectVisible(test, middle);
347 expectVisible(test, sibling); 375 expectVisible(test, inside);
348 expectVisible(test, sibling2); 376 expectVisible(test, sibling);
349 expectHidden(test, toHide); 377 expectVisible(test, sibling2);
350 test.done(); 378 expectHidden(test, toHide);
379 }).catch(unexpectedError.bind(test)).then(() => test.done());
351 } 380 }
352 381
353 exports.testPseudoClassHasSelectorWithHasAndWithSuffixSibling = function(test) 382 exports.testPseudoClassHasSelectorWithHasAndWithSuffixSibling = function(test)
354 { 383 {
355 runTestPseudoClassHasSelectorWithHasAndWithSuffixSibling(test, "div:-abp-has(: -abp-has(div.inside)) + div > div"); 384 runTestPseudoClassHasSelectorWithHasAndWithSuffixSibling(test, "div:-abp-has(: -abp-has(div.inside)) + div > div");
356 }; 385 };
357 386
358 exports.testPseudoClassContains = function(test) 387 exports.testPseudoClassContains = function(test)
359 { 388 {
360 document.body.innerHTML = `<div id="parent"> 389 document.body.innerHTML = `<div id="parent">
361 <div id="middle"> 390 <div id="middle">
362 <div id="middle1"><div id="inside" class="inside"></div></div> 391 <div id="middle1"><div id="inside" class="inside"></div></div>
363 </div> 392 </div>
364 <div id="sibling"> 393 <div id="sibling">
365 <div id="tohide">to hide</div> 394 <div id="tohide">to hide</div>
366 </div> 395 </div>
367 <div id="sibling2"> 396 <div id="sibling2">
368 <div id="sibling21"><div id="sibling211" class="inside"></div></div> 397 <div id="sibling21"><div id="sibling211" class="inside"></div></div>
369 </div> 398 </div>
370 </div>`; 399 </div>`;
371 let parent = document.getElementById("parent"); 400 let parent = document.getElementById("parent");
372 let middle = document.getElementById("middle"); 401 let middle = document.getElementById("middle");
373 let inside = document.getElementById("inside"); 402 let inside = document.getElementById("inside");
374 let sibling = document.getElementById("sibling"); 403 let sibling = document.getElementById("sibling");
375 let sibling2 = document.getElementById("sibling2"); 404 let sibling2 = document.getElementById("sibling2");
376 let toHide = document.getElementById("tohide"); 405 let toHide = document.getElementById("tohide");
377 406
378 applyElemHideEmulation( 407 applyElemHideEmulation(
379 ["#parent div:-abp-contains(to hide)"] 408 ["#parent div:-abp-contains(to hide)"]
380 ); 409 ).then(() =>
381 expectVisible(test, parent); 410 {
382 expectVisible(test, middle); 411 expectVisible(test, parent);
383 expectVisible(test, inside); 412 expectVisible(test, middle);
384 expectHidden(test, sibling); 413 expectVisible(test, inside);
385 expectVisible(test, sibling2); 414 expectHidden(test, sibling);
386 expectHidden(test, toHide); 415 expectVisible(test, sibling2);
387 test.done(); 416 expectHidden(test, toHide);
417 }).catch(unexpectedError.bind(test)).then(() => test.done());
388 }; 418 };
389 419
390 exports.testPseudoClassHasSelectorWithPropSelector = function(test) 420 exports.testPseudoClassHasSelectorWithPropSelector = function(test)
391 { 421 {
392 let parent = createElementWithStyle("{}"); 422 let parent = createElementWithStyle("{}");
393 let child = createElementWithStyle("{background-color: #000}", parent); 423 let child = createElementWithStyle("{background-color: #000}", parent);
394 applyElemHideEmulation( 424 applyElemHideEmulation(
395 ["div:-abp-has(:-abp-properties(background-color: rgb(0, 0, 0)))"] 425 ["div:-abp-has(:-abp-properties(background-color: rgb(0, 0, 0)))"]
396 ); 426 ).then(() =>
397 expectVisible(test, child); 427 {
398 expectHidden(test, parent); 428 expectVisible(test, child);
399 test.done(); 429 expectHidden(test, parent);
430 }).catch(unexpectedError.bind(test)).then(() => test.done());
400 }; 431 };
401 432
402 exports.testPseudoClassHasSelectorWithPropSelector2 = function(test) 433 exports.testPseudoClassHasSelectorWithPropSelector2 = function(test)
403 { 434 {
404 let parent = createElementWithStyle("{}"); 435 let parent = createElementWithStyle("{}");
405 let child = createElementWithStyle("{}", parent); 436 let child = createElementWithStyle("{}", parent);
406 insertStyleRule("body #" + parent.id + " > div { background-color: #000}"); 437 insertStyleRule("body #" + parent.id + " > div { background-color: #000}");
407 applyElemHideEmulation( 438 applyElemHideEmulation(
408 ["div:-abp-has(:-abp-properties(background-color: rgb(0, 0, 0)))"] 439 ["div:-abp-has(:-abp-properties(background-color: rgb(0, 0, 0)))"]
409 ); 440 ).then(() =>
410 expectVisible(test, child); 441 {
411 expectHidden(test, parent); 442 expectVisible(test, child);
412 test.done(); 443 expectHidden(test, parent);
413 }; 444 }).catch(unexpectedError.bind(test)).then(() => test.done());
445 };
LEFTRIGHT

Powered by Google App Engine
This is Rietveld