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

Side by Side Diff: test/browser/elemHideEmulation.js

Issue 29448560: Issue 5249 - Implement :-abp-contains() (Closed) Base URL: https://hg.adblockplus.org/adblockpluscore/
Patch Set: Updated and rebased Created June 8, 2017, 12:19 a.m.
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View unified diff | Download patch
« no previous file with comments | « chrome/content/elemHideEmulation.js ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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, splitSelector,
21 parseSelectorContent, 21 parseSelectorContent,
22 parseSelector, positionInParent, makeSelector, 22 parseSelector, positionInParent, makeSelector,
23 PlainSelector, HasSelector, PropsSelector */ 23 PlainSelector, HasSelector, PropsSelector, ContainsSelector */
24 24
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;
(...skipping 169 matching lines...) Expand 10 before | Expand all | Expand 10 after
203 test.equal(selectors.length, 4); 203 test.equal(selectors.length, 4);
204 test.ok(selectors[0] instanceof PlainSelector); 204 test.ok(selectors[0] instanceof PlainSelector);
205 test.ok(selectors[1] instanceof HasSelector); 205 test.ok(selectors[1] instanceof HasSelector);
206 test.ok(selectors[2] instanceof PlainSelector); 206 test.ok(selectors[2] instanceof PlainSelector);
207 test.ok(selectors[3] instanceof PropsSelector); 207 test.ok(selectors[3] instanceof PropsSelector);
208 208
209 selector = "div > :-abp-has(> div.inside > :-abp-properties(background-color : rgb(0, 0, 0))"; 209 selector = "div > :-abp-has(> div.inside > :-abp-properties(background-color : rgb(0, 0, 0))";
210 selectors = parseSelector(selector); 210 selectors = parseSelector(selector);
211 test.equal(selectors, null); 211 test.equal(selectors, null);
212 212
213 selector = 'div[arial-label="Story"]:-abp-has(> div > div > span > span:-abp -contains(Suggested Post))';
214 selectors = parseSelector(selector);
215 test.equal(selectors.length, 2);
216 test.ok(selectors[0] instanceof PlainSelector);
217 test.ok(selectors[1] instanceof HasSelector);
218
219 selectors = selectors[1]._innerSelectors;
220 test.equals(selectors.length, 2);
221 test.ok(selectors[0] instanceof PlainSelector);
222 test.ok(selectors[1] instanceof ContainsSelector);
223 test.equals(selectors[1]._text, "Suggested Post");
224
213 // -abp-has-unsupported() is unknown. Ensure we fail parsing. 225 // -abp-has-unsupported() is unknown. Ensure we fail parsing.
214 selector = 'div[arial-label="Story"]:-abp-has(> div > div > span > span:-abp -unsupported("Suggested Post"))'; 226 selector = 'div[arial-label="Story"]:-abp-has(> div > div > span > span:-abp -unsupported("Suggested Post"))';
215 selectors = parseSelector(selector); 227 selectors = parseSelector(selector);
216 test.equal(selectors, null); 228 test.equal(selectors, null);
217 }).catch(unexpectedError.bind(test)).then(() => test.done()); 229 }).catch(unexpectedError.bind(test)).then(() => test.done());
218 }; 230 };
219 231
220 function buildDom(doc) 232 function buildDom(doc)
221 { 233 {
222 doc.body.innerHTML = `<div id="parent"> 234 doc.body.innerHTML = `<div id="parent">
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after
303 test.equal(value.value.id, "sibling21"); 315 test.equal(value.value.id, "sibling21");
304 value = iter.next(); 316 value = iter.next();
305 test.ok(value.done); 317 test.ok(value.done);
306 318
307 selector = new HasSelector(":-abp-has(> div.inside)"); 319 selector = new HasSelector(":-abp-has(> div.inside)");
308 320
309 test.ok(selector._innerSelectors); 321 test.ok(selector._innerSelectors);
310 }).catch(unexpectedError.bind(test)).then(() => test.done()); 322 }).catch(unexpectedError.bind(test)).then(() => test.done());
311 }; 323 };
312 324
325 exports.testContainsSelector = function(test)
326 {
327 let {toHide} = buildDom(document);
328
329 loadElemHideEmulation().then(() =>
330 {
331 let selector = new ContainsSelector("to hide");
332
333 let iter = selector.getSelectors("", document, document.sheet);
334 let value = iter.next();
335 test.ok(!value.done);
336 test.equal(value.value[0],
337 ":root > BODY:nth-child(2) > DIV:nth-child(1) > DIV:nth-child(2) > DIV:nth-child(1)");
338
339 iter = selector.getElements("", document, document.sheet);
340 value = iter.next();
341 test.ok(!value.done);
342 test.equal(value.value, toHide);
343 value = iter.next();
344 test.ok(value.done);
345 }).catch(unexpectedError.bind(test)).then(() => test.done());
346 };
347
313 exports.testSplitStyleRule = function(test) 348 exports.testSplitStyleRule = function(test)
314 { 349 {
315 loadElemHideEmulation().then(() => 350 loadElemHideEmulation().then(() =>
316 { 351 {
317 let selectors = splitSelector("div:-abp-has(div) > [-abp-properties='backgro und-color: rgb(0, 0, 0)'] > span"); 352 let selectors = splitSelector("div:-abp-has(div) > [-abp-properties='backgro und-color: rgb(0, 0, 0)'] > span");
318 test.ok(selectors); 353 test.ok(selectors);
319 test.equal(selectors.length, 1, "There is only one selector"); 354 test.equal(selectors.length, 1, "There is only one selector");
320 355
321 selectors = splitSelector("div:-abp-has(div), [-abp-properties='background-c olor: rgb(0, 0, 0)']"); 356 selectors = splitSelector("div:-abp-has(div), [-abp-properties='background-c olor: rgb(0, 0, 0)']");
322 test.ok(selectors); 357 test.ok(selectors);
(...skipping 257 matching lines...) Expand 10 before | Expand all | Expand 10 after
580 let parent = createElementWithStyle("{}"); 615 let parent = createElementWithStyle("{}");
581 let child = createElementWithStyle("{background-color: #000}", parent); 616 let child = createElementWithStyle("{background-color: #000}", parent);
582 applyElemHideEmulation( 617 applyElemHideEmulation(
583 ["div:-abp-has(:-abp-properties(background-color: rgb(0, 0, 0)))"] 618 ["div:-abp-has(:-abp-properties(background-color: rgb(0, 0, 0)))"]
584 ).then(() => 619 ).then(() =>
585 { 620 {
586 expectVisible(test, child); 621 expectVisible(test, child);
587 expectHidden(test, parent); 622 expectHidden(test, parent);
588 }).catch(unexpectedError.bind(test)).then(() => test.done()); 623 }).catch(unexpectedError.bind(test)).then(() => test.done());
589 }; 624 };
OLDNEW
« no previous file with comments | « chrome/content/elemHideEmulation.js ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld