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

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

Issue 29383960: Issue 3143 - Filter elements with :-abp-has() (Closed) Base URL: https://hg.adblockplus.org/adblockpluscore
Left Patch Set: Reworked patch following the feedback Created May 25, 2017, 12:58 p.m.
Right Patch Set: Fix reportError and the error message Created June 13, 2017, 1:52 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 | « chrome/content/elemHideEmulation.js ('k') | no next file » | 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
(...skipping 14 matching lines...) Expand all
25 let myUrl = document.currentScript.src; 25 let myUrl = document.currentScript.src;
26 26
27 exports.tearDown = function(callback) 27 exports.tearDown = function(callback)
28 { 28 {
29 let styleElements = document.head.getElementsByTagName("style"); 29 let styleElements = document.head.getElementsByTagName("style");
30 while (styleElements.length) 30 while (styleElements.length)
31 styleElements[0].parentNode.removeChild(styleElements[0]); 31 styleElements[0].parentNode.removeChild(styleElements[0]);
32 32
33 let child; 33 let child;
34 while (child = document.body.firstChild) 34 while (child = document.body.firstChild)
35 document.body.removeChild(child); 35 child.parentNode.removeChild(child);
36 36
37 callback(); 37 callback();
38 }; 38 };
39 39
40 function unexpectedError(error) 40 function unexpectedError(error)
41 { 41 {
42 console.error(error); 42 console.error(error);
43 this.ok(false, "Unexpected error: " + error); 43 this.ok(false, "Unexpected error: " + error);
44 } 44 }
45 45
(...skipping 24 matching lines...) Expand all
70 if (styleElements.length) 70 if (styleElements.length)
71 styleElement = styleElements[0]; 71 styleElement = styleElements[0];
72 else 72 else
73 { 73 {
74 styleElement = document.createElement("style"); 74 styleElement = document.createElement("style");
75 document.head.appendChild(styleElement); 75 document.head.appendChild(styleElement);
76 } 76 }
77 styleElement.sheet.insertRule(rule, styleElement.sheet.cssRules.length); 77 styleElement.sheet.insertRule(rule, styleElement.sheet.cssRules.length);
78 } 78 }
79 79
80 // insert a <div> with a unique id and and empty CSS rule 80 // insert a <div> with a unique id and a CSS rule
81 // for the the selector matching the id. 81 // for the the selector matching the id.
82 function createElementWithStyle(styleBlock, parent) 82 function createElementWithStyle(styleBlock, parent)
83 { 83 {
84 let element = document.createElement("div"); 84 let element = document.createElement("div");
85 element.id = findUniqueId(); 85 element.id = findUniqueId();
86 if (!parent) 86 if (!parent)
87 document.body.appendChild(element); 87 document.body.appendChild(element);
88 else 88 else
89 parent.appendChild(element); 89 parent.appendChild(element);
90 insertStyleRule("#" + element.id + " " + styleBlock); 90 insertStyleRule("#" + element.id + " " + styleBlock);
91 return element; 91 return element;
92 } 92 }
93 93
94 // Will ensure the class ElemHideEmulation is loaded 94 // Will ensure the class ElemHideEmulation is loaded.
95 // and then will call the callback. 95 // NOTE: if it never loads, this will probably hang.
96 // NOTE: if it never loads, this will probably hang in an infinite
97 // loop
98 function loadElemHideEmulation() 96 function loadElemHideEmulation()
99 { 97 {
100 if (typeof ElemHideEmulation == "undefined") 98 if (typeof ElemHideEmulation == "undefined")
101 { 99 {
102 return loadScript(myUrl + "/../../../lib/common.js").then(() => 100 return loadScript(myUrl + "/../../../lib/common.js").then(() =>
103 { 101 {
104 return loadScript(myUrl + "/../../../chrome/content/elemHideEmulation.js") ; 102 return loadScript(myUrl + "/../../../chrome/content/elemHideEmulation.js") ;
105 }).then(() => 103 }).then(() =>
106 { 104 {
107 return loadElemHideEmulation(); 105 return loadElemHideEmulation();
108 }); 106 });
109 } 107 }
110 108
111 return Promise.resolve(); 109 return Promise.resolve();
112 } 110 }
113 111
114 // instantiate a ElemHideEmulation with @selectors. 112 // Create a new ElemHideEmulation instance with @selectors.
115 function applyElemHideEmulation(selectors) 113 function applyElemHideEmulation(selectors)
116 { 114 {
117 return loadElemHideEmulation().then(() => 115 return loadElemHideEmulation().then(() =>
118 { 116 {
119 let elemHideEmulation = new ElemHideEmulation( 117 let elemHideEmulation = new ElemHideEmulation(
120 window, 118 window,
121 callback => 119 callback =>
122 { 120 {
123 let patterns = []; 121 let patterns = [];
124 selectors.forEach(selector => 122 selectors.forEach(selector =>
125 { 123 {
126 patterns.push({selector}); 124 patterns.push({selector});
127 }); 125 });
128 callback(patterns); 126 callback(patterns);
129 }, 127 },
130 newSelectors => 128 newSelectors =>
131 { 129 {
132 if (!newSelectors.length) 130 if (!newSelectors.length)
133 return; 131 return;
134 let selector = newSelectors.join(", "); 132 let selector = newSelectors.join(", ");
135 insertStyleRule(selector + "{display: none !important;}"); 133 insertStyleRule(selector + "{display: none !important;}");
134 },
135 elems =>
136 {
137 for (let elem of elems)
138 elem.style.display = "none";
136 } 139 }
137 ); 140 );
138 141
139 elemHideEmulation.apply(); 142 elemHideEmulation.apply();
140 return Promise.resolve(); 143 return Promise.resolve(elemHideEmulation);
141 }); 144 });
142 } 145 }
143 146
147 // internals testing
148
144 exports.testParseSelectorContent = function(test) 149 exports.testParseSelectorContent = function(test)
145 { 150 {
146 loadElemHideEmulation().then(() => 151 loadElemHideEmulation().then(() =>
147 { 152 {
148 let parsed = parseSelectorContent("> div) > div"); 153 let parsed = parseSelectorContent(":-abp-has(> div) > div", 10);
154 test.equal(parsed.text, "> div");
155 test.equal(parsed.end, 15);
156
157 parsed = parseSelectorContent("> div) > div", 0);
149 test.equal(parsed.text, "> div"); 158 test.equal(parsed.text, "> div");
150 test.equal(parsed.end, 5); 159 test.equal(parsed.end, 5);
151 160
152 parsed = parseSelectorContent("\"> div\") > div");
153 test.equal(parsed.text, "\"> div\"");
154 test.equal(parsed.end, 7);
155 parsed = parseSelectorContent(" \"> div\" ) > div");
156 test.equal(parsed.text, " \"> div\" ");
157 test.equal(parsed.end, 9);
158
159 // simple quoted content
160 parsed = parseSelectorContent("\"> div\") > div", true);
161 test.equal(parsed.text, "> div");
162 test.equal(parsed.end, 7);
163 // quoted content with whitespace around.
164 parsed = parseSelectorContent(" \"> div\" ) > div", true);
165 test.equal(parsed.text, "> div");
166 test.equal(parsed.end, 9);
167
168 // parens not closed. 161 // parens not closed.
169 parsed = parseSelectorContent("> div > div"); 162 parsed = parseSelectorContent("> div > div", 0);
170 test.equal(parsed, null); 163 test.equal(parsed, null);
171 }).catch(unexpectedError.bind(test)).then(() => test.done()); 164 }).catch(unexpectedError.bind(test)).then(() => test.done());
172 }; 165 };
173 166
174 exports.testParseSelector = function(test) 167 exports.testParseSelector = function(test)
175 { 168 {
176 loadElemHideEmulation().then(() => 169 loadElemHideEmulation().then(() =>
177 { 170 {
178 let selectors = parseSelector(""); 171 let selectors = parseSelector("");
179 test.equal(selectors.length, 0); 172 test.equal(selectors.length, 0);
(...skipping 12 matching lines...) Expand all
192 test.ok(selectors[2] instanceof PlainSelector); 185 test.ok(selectors[2] instanceof PlainSelector);
193 186
194 selector = "div > div:-abp-has(> div.inside) > div"; 187 selector = "div > div:-abp-has(> div.inside) > div";
195 selectors = parseSelector(selector); 188 selectors = parseSelector(selector);
196 189
197 test.equal(selectors.length, 3); 190 test.equal(selectors.length, 3);
198 test.ok(selectors[0] instanceof PlainSelector); 191 test.ok(selectors[0] instanceof PlainSelector);
199 test.ok(selectors[1] instanceof HasSelector); 192 test.ok(selectors[1] instanceof HasSelector);
200 test.ok(selectors[2] instanceof PlainSelector); 193 test.ok(selectors[2] instanceof PlainSelector);
201 194
202 selector = "div > :-abp-has(> div.inside) > :-abp-properties('background-col or: rgb(0, 0, 0)')"; 195 selector = "div > :-abp-has(> div.inside) > :-abp-properties(background-colo r: rgb(0, 0, 0))";
203 selectors = parseSelector(selector); 196 selectors = parseSelector(selector);
204 197
205 test.equal(selectors.length, 4); 198 test.equal(selectors.length, 4);
206 test.ok(selectors[0] instanceof PlainSelector); 199 test.ok(selectors[0] instanceof PlainSelector);
207 test.ok(selectors[1] instanceof HasSelector); 200 test.ok(selectors[1] instanceof HasSelector);
208 test.ok(selectors[2] instanceof PlainSelector); 201 test.ok(selectors[2] instanceof PlainSelector);
209 test.ok(selectors[3] instanceof PropsSelector); 202 test.ok(selectors[3] instanceof PropsSelector);
210 203
211 selector = "div > :-abp-has(> div.inside > :-abp-properties('background-colo r: rgb(0, 0, 0)')"; 204 selector = "div > :-abp-has(> div.inside > :-abp-properties(background-color : rgb(0, 0, 0))";
212 selectors = parseSelector(selector); 205 selectors = parseSelector(selector);
213 test.equal(selectors, null); 206 test.equal(selectors, null);
214 207
215 // -abp-has-unsupported() is unknown. Ensure we fail parsing. 208 // -abp-has-unsupported() is unknown. Ensure we fail parsing.
216 selector = 'div[arial-label="Story"]:-abp-has(> div > div > span > span:-abp -unsupported("Suggested Post"))'; 209 selector = 'div[arial-label="Story"]:-abp-has(> div > div > span > span:-abp -unsupported("Suggested Post"))';
217 selectors = parseSelector(selector); 210 selectors = parseSelector(selector);
218 test.equal(selectors, null); 211 test.equal(selectors, null);
219 }).catch(unexpectedError.bind(test)).then(() => test.done()); 212 }).catch(unexpectedError.bind(test)).then(() => test.done());
220 }; 213 };
221 214
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
262 { 255 {
263 test.equal(makeSelector(nodes.middle, ""), 256 test.equal(makeSelector(nodes.middle, ""),
264 ":root > BODY:nth-child(2) > DIV:nth-child(1) > DIV:nth-child(1)" ); 257 ":root > BODY:nth-child(2) > DIV:nth-child(1) > DIV:nth-child(1)" );
265 test.equal(makeSelector(nodes.toHide, ""), 258 test.equal(makeSelector(nodes.toHide, ""),
266 ":root > BODY:nth-child(2) > DIV:nth-child(1) > DIV:nth-child(2) > DIV:nth-child(1)"); 259 ":root > BODY:nth-child(2) > DIV:nth-child(1) > DIV:nth-child(2) > DIV:nth-child(1)");
267 }).catch(unexpectedError.bind(test)).then(() => test.done()); 260 }).catch(unexpectedError.bind(test)).then(() => test.done());
268 }; 261 };
269 262
270 exports.testPlainSelector = function(test) 263 exports.testPlainSelector = function(test)
271 { 264 {
272 let nodes = buildDom(document); 265 buildDom(document);
273 266
274 loadElemHideEmulation().then(() => 267 loadElemHideEmulation().then(() =>
275 { 268 {
276 let selector = new PlainSelector("div > div"); 269 let selector = new PlainSelector("div > div");
277 270
278 let iter = selector.getSelectors("foo > "); 271 let iter = selector.getSelectors("foo > ");
279 let value = iter.next(); 272 let value = iter.next();
280 test.equal(value.value[0], "foo > div > div"); 273 test.equal(value.value[0], "foo > div > div");
281 test.ok(iter.next().done); 274 test.ok(iter.next().done);
282
283 iter = selector.getElements("", document, [document.sheet]);
284 value = iter.next();
285 test.ok(!value.done);
286 test.equal(value.value, nodes.middle);
287 value = iter.next();
288 test.ok(!value.done);
289 test.equal(value.value.id, "middle1");
290 value = iter.next();
291 test.ok(!value.done);
292 test.equal(value.value, nodes.inside);
293 }).catch(unexpectedError.bind(test)).then(() => test.done()); 275 }).catch(unexpectedError.bind(test)).then(() => test.done());
294 }; 276 };
295 277
296 exports.testHasSelector = function(test) 278 exports.testHasSelector = function(test)
297 { 279 {
298 buildDom(document); 280 buildDom(document);
299 281
300 loadElemHideEmulation().then(() => 282 loadElemHideEmulation().then(() =>
301 { 283 {
302 let selector = new HasSelector("> div.inside"); 284 let selector = new HasSelector("> div.inside");
303 285
304 let iter = selector.getSelectors("", document, document.sheet); 286 let iter = selector.getSelectors("", document, document.sheet);
305 let value = iter.next(); 287 let value = iter.next();
306 test.ok(!value.done); 288 test.ok(!value.done);
307 test.equal(value.value[0], 289 test.equal(value.value[0],
308 ":root > BODY:nth-child(2) > DIV:nth-child(1) > DIV:nth-child(1) > DIV:nth-child(1)"); 290 ":root > BODY:nth-child(2) > DIV:nth-child(1) > DIV:nth-child(1) > DIV:nth-child(1)");
309 291
310 iter = selector.getElements("", document, document.sheet); 292 iter = selector.getElements("", document, document.sheet);
311 value = iter.next(); 293 value = iter.next();
312 test.ok(!value.done); 294 test.ok(!value.done);
313 test.equal(value.value.id, "middle1"); 295 test.equal(value.value.id, "middle1");
314 value = iter.next(); 296 value = iter.next();
315 test.ok(!value.done); 297 test.ok(!value.done);
316 test.equal(value.value.id, "sibling21"); 298 test.equal(value.value.id, "sibling21");
317 value = iter.next(); 299 value = iter.next();
318 test.ok(value.done); 300 test.ok(value.done);
319 }).catch(unexpectedError.bind(test)).then(() => test.done()); 301
320 }; 302 selector = new HasSelector(":-abp-has(> div.inside)");
321 303
322 exports.testNestedHasSelector = function(test) 304 test.ok(selector._innerSelectors);
323 {
324 buildDom(document);
325
326 loadElemHideEmulation().then(() =>
327 {
328 let selector = new HasSelector(":-abp-has(> div.inside)");
329
330 test.ok(!selector._innerSelectors);
331 }).catch(unexpectedError.bind(test)).then(() => test.done()); 305 }).catch(unexpectedError.bind(test)).then(() => test.done());
332 }; 306 };
333 307
334 exports.testSplitStyleRule = function(test) 308 exports.testSplitStyleRule = function(test)
335 { 309 {
336 loadElemHideEmulation().then(() => 310 loadElemHideEmulation().then(() =>
337 { 311 {
338 let selectors = splitSelector("div:-abp-has(div) > [-abp-properties='backgro und-color: rgb(0, 0, 0)'] > span"); 312 let selectors = splitSelector("div:-abp-has(div) > [-abp-properties='backgro und-color: rgb(0, 0, 0)'] > span");
339 test.ok(selectors); 313 test.ok(selectors);
340 test.equal(selectors.length, 1, "There is only one selector"); 314 test.equal(selectors.length, 1, "There is only one selector");
341 315
342 selectors = splitSelector("div:-abp-has(div), [-abp-properties='background-c olor: rgb(0, 0, 0)']"); 316 selectors = splitSelector("div:-abp-has(div), [-abp-properties='background-c olor: rgb(0, 0, 0)']");
343 test.ok(selectors); 317 test.ok(selectors);
344 test.equal(selectors.length, 2, "There are two selectors"); 318 test.equal(selectors.length, 2, "There are two selectors");
345 }).catch(unexpectedError.bind(test)).then(() => test.done()); 319 }).catch(unexpectedError.bind(test)).then(() => test.done());
346 }; 320 };
347 321
322 // API testing
323
348 exports.testVerbatimPropertySelector = function(test) 324 exports.testVerbatimPropertySelector = function(test)
349 { 325 {
350 let toHide = createElementWithStyle("{background-color: #000}"); 326 let toHide = createElementWithStyle("{background-color: #000}");
351 applyElemHideEmulation( 327 applyElemHideEmulation(
352 [":-abp-properties('background-color: rgb(0, 0, 0)')"] 328 [":-abp-properties(background-color: rgb(0, 0, 0))"]
353 ).then(() => 329 ).then(() =>
354 { 330 {
355 expectHidden(test, toHide); 331 expectHidden(test, toHide);
356 }).catch(unexpectedError.bind(test)).then(() => test.done()); 332 }).catch(unexpectedError.bind(test)).then(() => test.done());
357 }; 333 };
358 334
359 exports.testVerbatimPropertySelectorWithPrefix = function(test) 335 exports.testVerbatimPropertySelectorWithPrefix = function(test)
360 { 336 {
361 let parent = createElementWithStyle("{background-color: #000}"); 337 let parent = createElementWithStyle("{background-color: #000}");
362 let toHide = createElementWithStyle("{background-color: #000}", parent); 338 let toHide = createElementWithStyle("{background-color: #000}", parent);
363 applyElemHideEmulation( 339 applyElemHideEmulation(
364 ["div > :-abp-properties('background-color: rgb(0, 0, 0)')"] 340 ["div > :-abp-properties(background-color: rgb(0, 0, 0))"]
365 ).then(() => 341 ).then(() =>
366 { 342 {
367 expectVisible(test, parent); 343 expectVisible(test, parent);
368 expectHidden(test, toHide); 344 expectHidden(test, toHide);
369 }).catch(unexpectedError.bind(test)).then(() => test.done()); 345 }).catch(unexpectedError.bind(test)).then(() => test.done());
370 }; 346 };
371 347
372 exports.testVerbatimPropertySelectorWithPrefixNoMatch = function(test) 348 exports.testVerbatimPropertySelectorWithPrefixNoMatch = function(test)
373 { 349 {
374 let parent = createElementWithStyle("{background-color: #000}"); 350 let parent = createElementWithStyle("{background-color: #000}");
375 let toHide = createElementWithStyle("{background-color: #fff}", parent); 351 let toHide = createElementWithStyle("{background-color: #fff}", parent);
376 applyElemHideEmulation( 352 applyElemHideEmulation(
377 ["div > :-abp-properties('background-color: rgb(0, 0, 0)')"] 353 ["div > :-abp-properties(background-color: rgb(0, 0, 0))"]
378 ).then(() => 354 ).then(() =>
379 { 355 {
380 expectVisible(test, parent); 356 expectVisible(test, parent);
381 expectVisible(test, toHide); 357 expectVisible(test, toHide);
382 }).catch(unexpectedError.bind(test)).then(() => test.done()); 358 }).catch(unexpectedError.bind(test)).then(() => test.done());
383 }; 359 };
384 360
385 exports.testVerbatimPropertySelectorWithSuffix = function(test) 361 exports.testVerbatimPropertySelectorWithSuffix = function(test)
386 { 362 {
387 let parent = createElementWithStyle("{background-color: #000}"); 363 let parent = createElementWithStyle("{background-color: #000}");
388 let toHide = createElementWithStyle("{background-color: #000}", parent); 364 let toHide = createElementWithStyle("{background-color: #000}", parent);
389 applyElemHideEmulation( 365 applyElemHideEmulation(
390 [":-abp-properties('background-color: rgb(0, 0, 0)') > div"] 366 [":-abp-properties(background-color: rgb(0, 0, 0)) > div"]
391 ).then(() => 367 ).then(() =>
392 { 368 {
393 expectVisible(test, parent); 369 expectVisible(test, parent);
394 expectHidden(test, toHide); 370 expectHidden(test, toHide);
395 }).catch(unexpectedError.bind(test)).then(() => test.done()); 371 }).catch(unexpectedError.bind(test)).then(() => test.done());
396 }; 372 };
397 373
398 exports.testVerbatimPropertyPseudoSelectorWithPrefixAndSuffix = function(test) 374 exports.testVerbatimPropertyPseudoSelectorWithPrefixAndSuffix = function(test)
399 { 375 {
400 let parent = createElementWithStyle("{background-color: #000}"); 376 let parent = createElementWithStyle("{background-color: #000}");
401 let middle = createElementWithStyle("{background-color: #000}", parent); 377 let middle = createElementWithStyle("{background-color: #000}", parent);
402 let toHide = createElementWithStyle("{background-color: #000}", middle); 378 let toHide = createElementWithStyle("{background-color: #000}", middle);
403 applyElemHideEmulation( 379 applyElemHideEmulation(
404 ["div > :-abp-properties('background-color: rgb(0, 0, 0)') > div"] 380 ["div > :-abp-properties(background-color: rgb(0, 0, 0)) > div"]
405 ).then(() => 381 ).then(() =>
406 { 382 {
407 expectVisible(test, parent); 383 expectVisible(test, parent);
408 expectVisible(test, middle); 384 expectVisible(test, middle);
409 expectHidden(test, toHide); 385 expectHidden(test, toHide);
410 }).catch(unexpectedError.bind(test)).then(() => test.done()); 386 }).catch(unexpectedError.bind(test)).then(() => test.done());
411 }; 387 };
412 388
413 exports.testPropertySelectorWithWildcard = function(test) 389 exports.testPropertySelectorWithWildcard = function(test)
414 { 390 {
415 let toHide = createElementWithStyle("{background-color: #000}"); 391 let toHide = createElementWithStyle("{background-color: #000}");
416 applyElemHideEmulation( 392 applyElemHideEmulation(
417 [":-abp-properties('*color: rgb(0, 0, 0)')"] 393 [":-abp-properties(*color: rgb(0, 0, 0))"]
418 ).then(() => 394 ).then(() =>
419 { 395 {
420 expectHidden(test, toHide); 396 expectHidden(test, toHide);
421 }).catch(unexpectedError.bind(test)).then(() => test.done()); 397 }).catch(unexpectedError.bind(test)).then(() => test.done());
422 }; 398 };
423 399
424 exports.testPropertySelectorWithRegularExpression = function(test) 400 exports.testPropertySelectorWithRegularExpression = function(test)
425 { 401 {
426 let toHide = createElementWithStyle("{background-color: #000}"); 402 let toHide = createElementWithStyle("{background-color: #000}");
427 applyElemHideEmulation( 403 applyElemHideEmulation(
428 [":-abp-properties('/.*color: rgb\\(0, 0, 0\\)/')"] 404 [":-abp-properties(/.*color: rgb\\(0, 0, 0\\)/)"]
429 ).then(() => 405 ).then(() =>
430 { 406 {
431 expectHidden(test, toHide); 407 expectHidden(test, toHide);
432 }).catch(unexpectedError.bind(test)).then(() => test.done()); 408 }).catch(unexpectedError.bind(test)).then(() => test.done());
433 }; 409 };
434 410
435 exports.testPropertySelectorWithEscapedBrace = function(test) 411 exports.testPropertySelectorWithEscapedBrace = function(test)
436 { 412 {
437 let toHide = createElementWithStyle("{background-color: #000}"); 413 let toHide = createElementWithStyle("{background-color: #000}");
438 applyElemHideEmulation( 414 applyElemHideEmulation(
439 [":-abp-properties('/background.\\x7B 0,6\\x7D : rgb\\(0, 0, 0\\)/')"] 415 [":-abp-properties(/background.\\x7B 0,6\\x7D : rgb\\(0, 0, 0\\)/)"]
440 ).then(() => 416 ).then(() =>
441 { 417 {
442 expectHidden(test, toHide); 418 expectHidden(test, toHide);
443 }).catch(unexpectedError.bind(test)).then(() => test.done()); 419 }).catch(unexpectedError.bind(test)).then(() => test.done());
444 }; 420 };
445 421
446 exports.testPropertySelectorWithImproperlyEscapedBrace = function(test) 422 exports.testPropertySelectorWithImproperlyEscapedBrace = function(test)
447 { 423 {
448 let toHide = createElementWithStyle("{background-color: #000}"); 424 let toHide = createElementWithStyle("{background-color: #000}");
449 applyElemHideEmulation( 425 applyElemHideEmulation(
450 [":-abp-properties('/background.\\x7B0,6\\x7D: rgb\\(0, 0, 0\\)/')"] 426 [":-abp-properties(/background.\\x7B0,6\\x7D: rgb\\(0, 0, 0\\)/)"]
451 ).then(() => 427 ).then(() =>
452 { 428 {
453 expectVisible(test, toHide); 429 expectVisible(test, toHide);
454 }).catch(unexpectedError.bind(test)).then(() => test.done()); 430 }).catch(unexpectedError.bind(test)).then(() => test.done());
455 }; 431 };
456 432
457 exports.testDynamicallyChangedProperty = function(test) 433 exports.testDynamicallyChangedProperty = function(test)
458 { 434 {
459 let toHide = createElementWithStyle("{}"); 435 let toHide = createElementWithStyle("{}");
460 applyElemHideEmulation( 436 applyElemHideEmulation(
461 [":-abp-properties('background-color: rgb(0, 0, 0)')"] 437 [":-abp-properties(background-color: rgb(0, 0, 0))"]
462 ).then(() => 438 ).then(() =>
463 { 439 {
464 expectVisible(test, toHide); 440 expectVisible(test, toHide);
465 insertStyleRule("#" + toHide.id + " {background-color: #000}"); 441 insertStyleRule("#" + toHide.id + " {background-color: #000}");
466 return new Promise((resolve, reject) => 442 return new Promise((resolve, reject) =>
467 { 443 {
468 window.setTimeout(() => 444 window.setTimeout(() =>
469 { 445 {
470 expectHidden(test, toHide); 446 expectHidden(test, toHide);
471 resolve(); 447 resolve();
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after
544 ["div:-abp-has(div) + div > div"] 520 ["div:-abp-has(div) + div > div"]
545 ).then(() => 521 ).then(() =>
546 { 522 {
547 expectVisible(test, parent); 523 expectVisible(test, parent);
548 expectVisible(test, middle); 524 expectVisible(test, middle);
549 expectVisible(test, sibling); 525 expectVisible(test, sibling);
550 expectHidden(test, toHide); 526 expectHidden(test, toHide);
551 }).catch(unexpectedError.bind(test)).then(() => test.done()); 527 }).catch(unexpectedError.bind(test)).then(() => test.done());
552 }; 528 };
553 529
530 function runTestPseudoClassHasSelectorWithHasAndWithSuffixSibling(test, selector )
531 {
532 document.body.innerHTML = `<div id="parent">
533 <div id="middle">
534 <div id="middle1"><div id="inside" class="inside"></div></div>
535 </div>
536 <div id="sibling">
537 <div id="tohide">to hide</div>
538 </div>
539 <div id="sibling2">
540 <div id="sibling21"><div id="sibling211" class="inside"></div></div>
541 </div>
542 </div>`;
543 let parent = document.getElementById("parent");
544 let middle = document.getElementById("middle");
545 let inside = document.getElementById("inside");
546 let sibling = document.getElementById("sibling");
547 let sibling2 = document.getElementById("sibling2");
548 let toHide = document.getElementById("tohide");
549
550 insertStyleRule(".inside {}");
551
552 applyElemHideEmulation(
553 [selector]
554 ).then(() =>
555 {
556 expectVisible(test, parent);
557 expectVisible(test, middle);
558 expectVisible(test, inside);
559 expectVisible(test, sibling);
560 expectVisible(test, sibling2);
561 expectHidden(test, toHide);
562 }).catch(unexpectedError.bind(test)).then(() => test.done());
563 }
564
565 exports.testPseudoClassHasSelectorWithHasAndWithSuffixSibling = function(test)
566 {
567 runTestPseudoClassHasSelectorWithHasAndWithSuffixSibling(test, "div:-abp-has(: -abp-has(div.inside)) + div > div");
568 };
569
570 exports.testPseudoClassHasSelectorWithHasAndWithSuffixSibling2 = function(test)
571 {
572 runTestPseudoClassHasSelectorWithHasAndWithSuffixSibling(test, "div:-abp-has(: -abp-has(> div.inside)) + div > div");
573 };
574
554 exports.testPseudoClassHasSelectorWithPropSelector = function(test) 575 exports.testPseudoClassHasSelectorWithPropSelector = function(test)
555 { 576 {
556 let parent = createElementWithStyle("{}"); 577 let parent = createElementWithStyle("{}");
557 let child = createElementWithStyle("{background-color: #000}", parent); 578 let child = createElementWithStyle("{background-color: #000}", parent);
558 applyElemHideEmulation( 579 applyElemHideEmulation(
559 ["div:-abp-has(:-abp-properties(\"background-color: rgb(0, 0, 0)\"))"] 580 ["div:-abp-has(:-abp-properties(background-color: rgb(0, 0, 0)))"]
560 ).then(() => 581 ).then(() =>
561 { 582 {
562 expectVisible(test, child); 583 expectVisible(test, child);
563 expectHidden(test, parent); 584 expectHidden(test, parent);
564 }).catch(unexpectedError.bind(test)).then(() => test.done()); 585 }).catch(unexpectedError.bind(test)).then(() => test.done());
565 }; 586 };
566
LEFTRIGHT

Powered by Google App Engine
This is Rietveld