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

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

Issue 29448560: Issue 5249 - Implement :-abp-contains() (Closed) Base URL: https://hg.adblockplus.org/adblockpluscore/
Left Patch Set: Created May 25, 2017, 1:03 p.m.
Right Patch Set: Use includes() and improve test. Created June 28, 2017, 4:11 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
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, splitSelector, 20 /* globals ElemHideEmulation */
21 parseSelectorContent,
22 parseSelector, positionInParent, makeSelector,
23 PlainSelector, HasSelector, PropsSelector, ContainsSelector */
24 21
25 let myUrl = document.currentScript.src; 22 let myUrl = document.currentScript.src;
26 23
27 exports.tearDown = function(callback) 24 exports.tearDown = function(callback)
28 { 25 {
29 let styleElements = document.head.getElementsByTagName("style"); 26 let styleElements = document.head.getElementsByTagName("style");
30 while (styleElements.length) 27 while (styleElements.length)
31 styleElements[0].parentNode.removeChild(styleElements[0]); 28 styleElements[0].parentNode.removeChild(styleElements[0]);
32 29
33 let child; 30 let child;
34 while (child = document.body.firstChild) 31 while (child = document.body.firstChild)
35 document.body.removeChild(child); 32 child.parentNode.removeChild(child);
36 33
37 callback(); 34 callback();
38 }; 35 };
39 36
40 function unexpectedError(error) 37 function unexpectedError(error)
41 { 38 {
42 console.error(error); 39 console.error(error);
43 this.ok(false, "Unexpected error: " + error); 40 this.ok(false, "Unexpected error: " + error);
44 } 41 }
45 42
(...skipping 24 matching lines...) Expand all
70 if (styleElements.length) 67 if (styleElements.length)
71 styleElement = styleElements[0]; 68 styleElement = styleElements[0];
72 else 69 else
73 { 70 {
74 styleElement = document.createElement("style"); 71 styleElement = document.createElement("style");
75 document.head.appendChild(styleElement); 72 document.head.appendChild(styleElement);
76 } 73 }
77 styleElement.sheet.insertRule(rule, styleElement.sheet.cssRules.length); 74 styleElement.sheet.insertRule(rule, styleElement.sheet.cssRules.length);
78 } 75 }
79 76
80 // insert a <div> with a unique id and and empty CSS rule 77 // insert a <div> with a unique id and a CSS rule
81 // for the the selector matching the id. 78 // for the the selector matching the id.
82 function createElementWithStyle(styleBlock, parent) 79 function createElementWithStyle(styleBlock, parent)
83 { 80 {
84 let element = document.createElement("div"); 81 let element = document.createElement("div");
85 element.id = findUniqueId(); 82 element.id = findUniqueId();
86 if (!parent) 83 if (!parent)
87 document.body.appendChild(element); 84 document.body.appendChild(element);
88 else 85 else
89 parent.appendChild(element); 86 parent.appendChild(element);
90 insertStyleRule("#" + element.id + " " + styleBlock); 87 insertStyleRule("#" + element.id + " " + styleBlock);
91 return element; 88 return element;
92 } 89 }
93 90
94 // Will ensure the class ElemHideEmulation is loaded 91 // Will ensure the class ElemHideEmulation is loaded.
95 // and then will call the callback. 92 // 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() 93 function loadElemHideEmulation()
99 { 94 {
100 if (typeof ElemHideEmulation == "undefined") 95 if (typeof ElemHideEmulation == "undefined")
101 { 96 {
102 return loadScript(myUrl + "/../../../lib/common.js").then(() => 97 return loadScript(myUrl + "/../../../lib/common.js").then(() =>
103 { 98 {
104 return loadScript(myUrl + "/../../../chrome/content/elemHideEmulation.js") ; 99 return loadScript(myUrl + "/../../../chrome/content/elemHideEmulation.js") ;
105 }).then(() => 100 }).then(() =>
106 { 101 {
107 return loadElemHideEmulation(); 102 return loadElemHideEmulation();
108 }); 103 });
109 } 104 }
110 105
111 return Promise.resolve(); 106 return Promise.resolve();
112 } 107 }
113 108
114 // instantiate a ElemHideEmulation with @selectors. 109 // Create a new ElemHideEmulation instance with @selectors.
115 function applyElemHideEmulation(selectors) 110 function applyElemHideEmulation(selectors)
116 { 111 {
117 return loadElemHideEmulation().then(() => 112 return loadElemHideEmulation().then(() =>
118 { 113 {
119 let elemHideEmulation = new ElemHideEmulation( 114 let elemHideEmulation = new ElemHideEmulation(
120 window, 115 window,
121 callback => 116 callback =>
122 { 117 {
123 let patterns = []; 118 let patterns = [];
124 selectors.forEach(selector => 119 selectors.forEach(selector =>
125 { 120 {
126 patterns.push({selector}); 121 patterns.push({selector});
127 }); 122 });
128 callback(patterns); 123 callback(patterns);
129 }, 124 },
130 newSelectors => 125 newSelectors =>
131 { 126 {
132 if (!newSelectors.length) 127 if (!newSelectors.length)
133 return; 128 return;
134 let selector = newSelectors.join(", "); 129 let selector = newSelectors.join(", ");
135 insertStyleRule(selector + "{display: none !important;}"); 130 insertStyleRule(selector + "{display: none !important;}");
131 },
132 elems =>
133 {
134 for (let elem of elems)
135 elem.style.display = "none";
136 } 136 }
137 ); 137 );
138 138
139 elemHideEmulation.apply(); 139 elemHideEmulation.apply();
140 return Promise.resolve(); 140 return Promise.resolve(elemHideEmulation);
141 }); 141 });
142 } 142 }
143 143
144 exports.testParseSelectorContent = function(test)
145 {
146 loadElemHideEmulation().then(() =>
147 {
148 let parsed = parseSelectorContent("> div) > div");
149 test.equal(parsed.text, "> div");
150 test.equal(parsed.end, 5);
151
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.
169 parsed = parseSelectorContent("> div > div");
170 test.equal(parsed, null);
171 }).catch(unexpectedError.bind(test)).then(() => test.done());
172 };
173
174 exports.testParseSelector = function(test)
175 {
176 loadElemHideEmulation().then(() =>
177 {
178 let selectors = parseSelector("");
179 test.equal(selectors.length, 0);
180
181 let selector = "div > :-abp-properties('background-color: rgb(0, 0, 0)')";
182 selectors = parseSelector(selector);
183 test.equal(selectors.length, 2);
184 test.ok(selectors[0] instanceof PlainSelector);
185 test.ok(selectors[1] instanceof PropsSelector);
186
187 selector = "div > :-abp-has(> div.inside) > div";
188 selectors = parseSelector(selector);
189 test.equal(selectors.length, 3);
190 test.ok(selectors[0] instanceof PlainSelector);
191 test.ok(selectors[1] instanceof HasSelector);
192 test.ok(selectors[2] instanceof PlainSelector);
193
194 selector = "div > div:-abp-has(> div.inside) > div";
195 selectors = parseSelector(selector);
196
197 test.equal(selectors.length, 3);
198 test.ok(selectors[0] instanceof PlainSelector);
199 test.ok(selectors[1] instanceof HasSelector);
200 test.ok(selectors[2] instanceof PlainSelector);
201
202 selector = "div > :-abp-has(> div.inside) > :-abp-properties('background-col or: rgb(0, 0, 0)')";
203 selectors = parseSelector(selector);
204
205 test.equal(selectors.length, 4);
206 test.ok(selectors[0] instanceof PlainSelector);
207 test.ok(selectors[1] instanceof HasSelector);
208 test.ok(selectors[2] instanceof PlainSelector);
209 test.ok(selectors[3] instanceof PropsSelector);
210
211 selector = "div > :-abp-has(> div.inside > :-abp-properties('background-colo r: rgb(0, 0, 0)')";
212 selectors = parseSelector(selector);
213 test.equal(selectors, null);
214
215 selector = 'div[arial-label="Story"]:-abp-has(> div > div > span > span:-abp -contains("Suggested Post"))';
216 selectors = parseSelector(selector);
217 test.equal(selectors.length, 2);
218 test.ok(selectors[0] instanceof PlainSelector);
219 test.ok(selectors[1] instanceof HasSelector);
220
221 selectors = selectors[1]._innerSelectors;
222 test.equals(selectors.length, 2);
223 test.ok(selectors[0] instanceof PlainSelector);
224 test.ok(selectors[1] instanceof ContainsSelector);
225
226 // -abp-has-unsupported() is unknown. Ensure we fail parsing.
227 selector = 'div[arial-label="Story"]:-abp-has(> div > div > span > span:-abp -unsupported("Suggested Post"))';
228 selectors = parseSelector(selector);
229 test.equal(selectors, null);
230 }).catch(unexpectedError.bind(test)).then(() => test.done());
231 };
232
233 function buildDom(doc)
234 {
235 doc.body.innerHTML = `<div id="parent">
236 <div id="middle">
237 <div id="middle1"><div id="inside" class="inside"></div></div>
238 </div>
239 <div id="sibling">
240 <div id="tohide">to hide</div>
241 </div>
242 <div id="sibling2">
243 <div id="sibling21"><div id="sibling211" class="inside"></div></div>
244 </div>
245 </div>`;
246 let parent = document.getElementById("parent");
247 let middle = document.getElementById("middle");
248 let middle1 = document.getElementById("middle1");
249 let inside = document.getElementById("inside");
250 let sibling = document.getElementById("sibling");
251 let sibling2 = document.getElementById("sibling2");
252 let toHide = document.getElementById("tohide");
253 return {parent, middle, middle1, inside, sibling, sibling2, toHide};
254 }
255
256 exports.testPositionInParent = function(test)
257 {
258 let nodes = buildDom(document);
259
260 loadElemHideEmulation().then(() =>
261 {
262 test.equal(positionInParent(nodes.middle1), 1);
263 test.equal(positionInParent(nodes.inside), 1);
264 test.equal(positionInParent(nodes.sibling2), 3);
265 }).catch(unexpectedError.bind(test)).then(() => test.done());
266 };
267
268 exports.testMakeSelector = function(test)
269 {
270 let nodes = buildDom(document);
271
272 loadElemHideEmulation().then(() =>
273 {
274 test.equal(makeSelector(nodes.middle, ""),
275 ":root > BODY:nth-child(2) > DIV:nth-child(1) > DIV:nth-child(1)" );
276 test.equal(makeSelector(nodes.toHide, ""),
277 ":root > BODY:nth-child(2) > DIV:nth-child(1) > DIV:nth-child(2) > DIV:nth-child(1)");
278 }).catch(unexpectedError.bind(test)).then(() => test.done());
279 };
280
281 exports.testPlainSelector = function(test)
282 {
283 let nodes = buildDom(document);
284
285 loadElemHideEmulation().then(() =>
286 {
287 let selector = new PlainSelector("div > div");
288
289 let iter = selector.getSelectors("foo > ");
290 let value = iter.next();
291 test.equal(value.value[0], "foo > div > div");
292 test.ok(iter.next().done);
293
294 iter = selector.getElements("", document, [document.sheet]);
295 value = iter.next();
296 test.ok(!value.done);
297 test.equal(value.value, nodes.middle);
298 value = iter.next();
299 test.ok(!value.done);
300 test.equal(value.value.id, "middle1");
301 value = iter.next();
302 test.ok(!value.done);
303 test.equal(value.value, nodes.inside);
304 }).catch(unexpectedError.bind(test)).then(() => test.done());
305 };
306
307 exports.testHasSelector = function(test)
308 {
309 buildDom(document);
310
311 loadElemHideEmulation().then(() =>
312 {
313 let selector = new HasSelector("> div.inside");
314
315 let iter = selector.getSelectors("", document, document.sheet);
316 let value = iter.next();
317 test.ok(!value.done);
318 test.equal(value.value[0],
319 ":root > BODY:nth-child(2) > DIV:nth-child(1) > DIV:nth-child(1) > DIV:nth-child(1)");
320
321 iter = selector.getElements("", document, document.sheet);
322 value = iter.next();
323 test.ok(!value.done);
324 test.equal(value.value.id, "middle1");
325 value = iter.next();
326 test.ok(!value.done);
327 test.equal(value.value.id, "sibling21");
328 value = iter.next();
329 test.ok(value.done);
330 }).catch(unexpectedError.bind(test)).then(() => test.done());
331 };
332
333 exports.testNestedHasSelector = function(test)
334 {
335 buildDom(document);
336
337 loadElemHideEmulation().then(() =>
338 {
339 let selector = new HasSelector(":-abp-has(> div.inside)");
340
341 test.ok(!selector._innerSelectors);
342 }).catch(unexpectedError.bind(test)).then(() => test.done());
343 };
344
345 exports.testContainsSelector = function(test)
346 {
347 let {toHide} = buildDom(document);
348
349 loadElemHideEmulation().then(() =>
350 {
351 let selector = new ContainsSelector("to hide");
352
353 let iter = selector.getSelectors("", document, document.sheet);
354 let value = iter.next();
355 test.ok(!value.done);
356 test.equal(value.value[0],
357 ":root > BODY:nth-child(2) > DIV:nth-child(1) > DIV:nth-child(2) > DIV:nth-child(1)");
358
359 iter = selector.getElements("", document, document.sheet);
360 value = iter.next();
361 test.ok(!value.done);
362 test.equal(value.value, toHide);
363 value = iter.next();
364 test.ok(value.done);
365 }).catch(unexpectedError.bind(test)).then(() => test.done());
366 };
367
368 exports.testSplitStyleRule = function(test)
369 {
370 loadElemHideEmulation().then(() =>
371 {
372 let selectors = splitSelector("div:-abp-has(div) > [-abp-properties='backgro und-color: rgb(0, 0, 0)'] > span");
373 test.ok(selectors);
374 test.equal(selectors.length, 1, "There is only one selector");
375
376 selectors = splitSelector("div:-abp-has(div), [-abp-properties='background-c olor: rgb(0, 0, 0)']");
377 test.ok(selectors);
378 test.equal(selectors.length, 2, "There are two selectors");
379 }).catch(unexpectedError.bind(test)).then(() => test.done());
380 };
381
382 exports.testVerbatimPropertySelector = function(test) 144 exports.testVerbatimPropertySelector = function(test)
383 { 145 {
384 let toHide = createElementWithStyle("{background-color: #000}"); 146 let toHide = createElementWithStyle("{background-color: #000}");
385 applyElemHideEmulation( 147 applyElemHideEmulation(
386 [":-abp-properties('background-color: rgb(0, 0, 0)')"] 148 [":-abp-properties(background-color: rgb(0, 0, 0))"]
387 ).then(() => 149 ).then(() =>
388 { 150 {
389 expectHidden(test, toHide); 151 expectHidden(test, toHide);
390 }).catch(unexpectedError.bind(test)).then(() => test.done()); 152 }).catch(unexpectedError.bind(test)).then(() => test.done());
391 }; 153 };
392 154
393 exports.testVerbatimPropertySelectorWithPrefix = function(test) 155 exports.testVerbatimPropertySelectorWithPrefix = function(test)
394 { 156 {
395 let parent = createElementWithStyle("{background-color: #000}"); 157 let parent = createElementWithStyle("{background-color: #000}");
396 let toHide = createElementWithStyle("{background-color: #000}", parent); 158 let toHide = createElementWithStyle("{background-color: #000}", parent);
397 applyElemHideEmulation( 159 applyElemHideEmulation(
398 ["div > :-abp-properties('background-color: rgb(0, 0, 0)')"] 160 ["div > :-abp-properties(background-color: rgb(0, 0, 0))"]
399 ).then(() => 161 ).then(() =>
400 { 162 {
401 expectVisible(test, parent); 163 expectVisible(test, parent);
402 expectHidden(test, toHide); 164 expectHidden(test, toHide);
403 }).catch(unexpectedError.bind(test)).then(() => test.done()); 165 }).catch(unexpectedError.bind(test)).then(() => test.done());
404 }; 166 };
405 167
406 exports.testVerbatimPropertySelectorWithPrefixNoMatch = function(test) 168 exports.testVerbatimPropertySelectorWithPrefixNoMatch = function(test)
407 { 169 {
408 let parent = createElementWithStyle("{background-color: #000}"); 170 let parent = createElementWithStyle("{background-color: #000}");
409 let toHide = createElementWithStyle("{background-color: #fff}", parent); 171 let toHide = createElementWithStyle("{background-color: #fff}", parent);
410 applyElemHideEmulation( 172 applyElemHideEmulation(
411 ["div > :-abp-properties('background-color: rgb(0, 0, 0)')"] 173 ["div > :-abp-properties(background-color: rgb(0, 0, 0))"]
412 ).then(() => 174 ).then(() =>
413 { 175 {
414 expectVisible(test, parent); 176 expectVisible(test, parent);
415 expectVisible(test, toHide); 177 expectVisible(test, toHide);
416 }).catch(unexpectedError.bind(test)).then(() => test.done()); 178 }).catch(unexpectedError.bind(test)).then(() => test.done());
417 }; 179 };
418 180
419 exports.testVerbatimPropertySelectorWithSuffix = function(test) 181 exports.testVerbatimPropertySelectorWithSuffix = function(test)
420 { 182 {
421 let parent = createElementWithStyle("{background-color: #000}"); 183 let parent = createElementWithStyle("{background-color: #000}");
422 let toHide = createElementWithStyle("{background-color: #000}", parent); 184 let toHide = createElementWithStyle("{background-color: #000}", parent);
423 applyElemHideEmulation( 185 applyElemHideEmulation(
424 [":-abp-properties('background-color: rgb(0, 0, 0)') > div"] 186 [":-abp-properties(background-color: rgb(0, 0, 0)) > div"]
425 ).then(() => 187 ).then(() =>
426 { 188 {
427 expectVisible(test, parent); 189 expectVisible(test, parent);
428 expectHidden(test, toHide); 190 expectHidden(test, toHide);
429 }).catch(unexpectedError.bind(test)).then(() => test.done()); 191 }).catch(unexpectedError.bind(test)).then(() => test.done());
430 }; 192 };
431 193
432 exports.testVerbatimPropertyPseudoSelectorWithPrefixAndSuffix = function(test) 194 exports.testVerbatimPropertyPseudoSelectorWithPrefixAndSuffix = function(test)
433 { 195 {
434 let parent = createElementWithStyle("{background-color: #000}"); 196 let parent = createElementWithStyle("{background-color: #000}");
435 let middle = createElementWithStyle("{background-color: #000}", parent); 197 let middle = createElementWithStyle("{background-color: #000}", parent);
436 let toHide = createElementWithStyle("{background-color: #000}", middle); 198 let toHide = createElementWithStyle("{background-color: #000}", middle);
437 applyElemHideEmulation( 199 applyElemHideEmulation(
438 ["div > :-abp-properties('background-color: rgb(0, 0, 0)') > div"] 200 ["div > :-abp-properties(background-color: rgb(0, 0, 0)) > div"]
439 ).then(() => 201 ).then(() =>
440 { 202 {
441 expectVisible(test, parent); 203 expectVisible(test, parent);
442 expectVisible(test, middle); 204 expectVisible(test, middle);
443 expectHidden(test, toHide); 205 expectHidden(test, toHide);
444 }).catch(unexpectedError.bind(test)).then(() => test.done()); 206 }).catch(unexpectedError.bind(test)).then(() => test.done());
445 }; 207 };
446 208
447 exports.testPropertySelectorWithWildcard = function(test) 209 exports.testPropertySelectorWithWildcard = function(test)
448 { 210 {
449 let toHide = createElementWithStyle("{background-color: #000}"); 211 let toHide = createElementWithStyle("{background-color: #000}");
450 applyElemHideEmulation( 212 applyElemHideEmulation(
451 [":-abp-properties('*color: rgb(0, 0, 0)')"] 213 [":-abp-properties(*color: rgb(0, 0, 0))"]
452 ).then(() => 214 ).then(() =>
453 { 215 {
454 expectHidden(test, toHide); 216 expectHidden(test, toHide);
455 }).catch(unexpectedError.bind(test)).then(() => test.done()); 217 }).catch(unexpectedError.bind(test)).then(() => test.done());
456 }; 218 };
457 219
458 exports.testPropertySelectorWithRegularExpression = function(test) 220 exports.testPropertySelectorWithRegularExpression = function(test)
459 { 221 {
460 let toHide = createElementWithStyle("{background-color: #000}"); 222 let toHide = createElementWithStyle("{background-color: #000}");
461 applyElemHideEmulation( 223 applyElemHideEmulation(
462 [":-abp-properties('/.*color: rgb\\(0, 0, 0\\)/')"] 224 [":-abp-properties(/.*color: rgb\\(0, 0, 0\\)/)"]
463 ).then(() => 225 ).then(() =>
464 { 226 {
465 expectHidden(test, toHide); 227 expectHidden(test, toHide);
466 }).catch(unexpectedError.bind(test)).then(() => test.done()); 228 }).catch(unexpectedError.bind(test)).then(() => test.done());
467 }; 229 };
468 230
469 exports.testPropertySelectorWithEscapedBrace = function(test) 231 exports.testPropertySelectorWithEscapedBrace = function(test)
470 { 232 {
471 let toHide = createElementWithStyle("{background-color: #000}"); 233 let toHide = createElementWithStyle("{background-color: #000}");
472 applyElemHideEmulation( 234 applyElemHideEmulation(
473 [":-abp-properties('/background.\\x7B 0,6\\x7D : rgb\\(0, 0, 0\\)/')"] 235 [":-abp-properties(/background.\\x7B 0,6\\x7D : rgb\\(0, 0, 0\\)/)"]
474 ).then(() => 236 ).then(() =>
475 { 237 {
476 expectHidden(test, toHide); 238 expectHidden(test, toHide);
477 }).catch(unexpectedError.bind(test)).then(() => test.done()); 239 }).catch(unexpectedError.bind(test)).then(() => test.done());
478 }; 240 };
479 241
480 exports.testPropertySelectorWithImproperlyEscapedBrace = function(test) 242 exports.testPropertySelectorWithImproperlyEscapedBrace = function(test)
481 { 243 {
482 let toHide = createElementWithStyle("{background-color: #000}"); 244 let toHide = createElementWithStyle("{background-color: #000}");
483 applyElemHideEmulation( 245 applyElemHideEmulation(
484 [":-abp-properties('/background.\\x7B0,6\\x7D: rgb\\(0, 0, 0\\)/')"] 246 [":-abp-properties(/background.\\x7B0,6\\x7D: rgb\\(0, 0, 0\\)/)"]
485 ).then(() => 247 ).then(() =>
486 { 248 {
487 expectVisible(test, toHide); 249 expectVisible(test, toHide);
488 }).catch(unexpectedError.bind(test)).then(() => test.done()); 250 }).catch(unexpectedError.bind(test)).then(() => test.done());
489 }; 251 };
490 252
491 exports.testDynamicallyChangedProperty = function(test) 253 exports.testDynamicallyChangedProperty = function(test)
492 { 254 {
493 let toHide = createElementWithStyle("{}"); 255 let toHide = createElementWithStyle("{}");
494 applyElemHideEmulation( 256 applyElemHideEmulation(
495 [":-abp-properties('background-color: rgb(0, 0, 0)')"] 257 [":-abp-properties(background-color: rgb(0, 0, 0))"]
496 ).then(() => 258 ).then(() =>
497 { 259 {
498 expectVisible(test, toHide); 260 expectVisible(test, toHide);
499 insertStyleRule("#" + toHide.id + " {background-color: #000}"); 261 insertStyleRule("#" + toHide.id + " {background-color: #000}");
500 return new Promise((resolve, reject) => 262 return new Promise((resolve, reject) =>
501 { 263 {
502 window.setTimeout(() => 264 window.setTimeout(() =>
503 { 265 {
504 expectHidden(test, toHide); 266 expectHidden(test, toHide);
505 resolve(); 267 resolve();
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after
578 ["div:-abp-has(div) + div > div"] 340 ["div:-abp-has(div) + div > div"]
579 ).then(() => 341 ).then(() =>
580 { 342 {
581 expectVisible(test, parent); 343 expectVisible(test, parent);
582 expectVisible(test, middle); 344 expectVisible(test, middle);
583 expectVisible(test, sibling); 345 expectVisible(test, sibling);
584 expectHidden(test, toHide); 346 expectHidden(test, toHide);
585 }).catch(unexpectedError.bind(test)).then(() => test.done()); 347 }).catch(unexpectedError.bind(test)).then(() => test.done());
586 }; 348 };
587 349
350 function runTestPseudoClassHasSelectorWithHasAndWithSuffixSibling(test, selector )
351 {
352 document.body.innerHTML = `<div id="parent">
353 <div id="middle">
354 <div id="middle1"><div id="inside" class="inside"></div></div>
355 </div>
356 <div id="sibling">
357 <div id="tohide">to hide</div>
358 </div>
359 <div id="sibling2">
360 <div id="sibling21"><div id="sibling211" class="inside"></div></div>
361 </div>
362 </div>`;
363 let parent = document.getElementById("parent");
364 let middle = document.getElementById("middle");
365 let inside = document.getElementById("inside");
366 let sibling = document.getElementById("sibling");
367 let sibling2 = document.getElementById("sibling2");
368 let toHide = document.getElementById("tohide");
369
370 insertStyleRule(".inside {}");
371
372 applyElemHideEmulation(
373 [selector]
374 ).then(() =>
375 {
376 expectVisible(test, parent);
377 expectVisible(test, middle);
378 expectVisible(test, inside);
379 expectVisible(test, sibling);
380 expectVisible(test, sibling2);
381 expectHidden(test, toHide);
382 }).catch(unexpectedError.bind(test)).then(() => test.done());
383 }
384
385 exports.testPseudoClassHasSelectorWithHasAndWithSuffixSibling = function(test)
386 {
387 runTestPseudoClassHasSelectorWithHasAndWithSuffixSibling(test, "div:-abp-has(: -abp-has(div.inside)) + div > div");
388 };
389
390 exports.testPseudoClassHasSelectorWithHasAndWithSuffixSibling2 = function(test)
391 {
392 runTestPseudoClassHasSelectorWithHasAndWithSuffixSibling(test, "div:-abp-has(: -abp-has(> div.inside)) + div > div");
393 };
394
395 exports.testPseudoClassContains = function(test)
396 {
397 document.body.innerHTML = `<div id="parent">
398 <div id="middle">
399 <div id="middle1"><div id="inside" class="inside"></div></div>
400 </div>
401 <div id="sibling">
402 <div id="tohide">to hide</div>
403 </div>
404 <div id="sibling2">
405 <div id="sibling21"><div id="sibling211" class="inside"></div></div>
406 </div>
407 </div>`;
408 let parent = document.getElementById("parent");
409 let middle = document.getElementById("middle");
410 let inside = document.getElementById("inside");
411 let sibling = document.getElementById("sibling");
412 let sibling2 = document.getElementById("sibling2");
413 let toHide = document.getElementById("tohide");
414
415 applyElemHideEmulation(
416 ["#parent div:-abp-contains(to hide)"]
417 ).then(() =>
418 {
419 expectVisible(test, parent);
420 expectVisible(test, middle);
421 expectVisible(test, inside);
422 expectHidden(test, sibling);
423 expectVisible(test, sibling2);
424 expectHidden(test, toHide);
425 }).catch(unexpectedError.bind(test)).then(() => test.done());
426 };
427
588 exports.testPseudoClassHasSelectorWithPropSelector = function(test) 428 exports.testPseudoClassHasSelectorWithPropSelector = function(test)
589 { 429 {
590 let parent = createElementWithStyle("{}"); 430 let parent = createElementWithStyle("{}");
591 let child = createElementWithStyle("{background-color: #000}", parent); 431 let child = createElementWithStyle("{background-color: #000}", parent);
592 applyElemHideEmulation( 432 applyElemHideEmulation(
593 ["div:-abp-has(:-abp-properties(\"background-color: rgb(0, 0, 0)\"))"] 433 ["div:-abp-has(:-abp-properties(background-color: rgb(0, 0, 0)))"]
594 ).then(() => 434 ).then(() =>
595 { 435 {
596 expectVisible(test, child); 436 expectVisible(test, child);
597 expectHidden(test, parent); 437 expectHidden(test, parent);
598 }).catch(unexpectedError.bind(test)).then(() => test.done()); 438 }).catch(unexpectedError.bind(test)).then(() => test.done());
599 }; 439 };
600
LEFTRIGHT

Powered by Google App Engine
This is Rietveld