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

Powered by Google App Engine
This is Rietveld