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: Now we properly upgrade to the new syntax for [-abp-properties=] Created May 4, 2017, 6:45 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
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 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-properties('background-color: rgb(0, 0, 0)')"; 174 let selector = "div > :-abp-properties('background-color: rgb(0, 0, 0)')";
158 selectors = parseSelector(selector); 175 selectors = parseSelector(selector);
159 test.equal(selectors.length, 2); 176 test.equal(selectors.length, 2);
160 test.ok(selectors[0] instanceof PlainSelector); 177 test.ok(selectors[0] instanceof PlainSelector);
161 test.ok(selectors[1] instanceof PropsSelector); 178 test.ok(selectors[1] instanceof PropsSelector);
162 179
163 selector = "div > :-abp-has(> div.inside) > div"; 180 selector = "div > :-abp-has(> div.inside) > div";
164 selectors = parseSelector(selector); 181 selectors = parseSelector(selector);
165 test.equal(selectors.length, 3); 182 test.equal(selectors.length, 3);
166 test.ok(selectors[0] instanceof PlainSelector); 183 test.ok(selectors[0] instanceof PlainSelector);
167 test.ok(selectors[1] instanceof HasSelector); 184 test.ok(selectors[1] instanceof HasSelector);
168 test.ok(selectors[2] instanceof PlainSelector); 185 test.ok(selectors[2] instanceof PlainSelector);
169 186
170 selector = "div > div:-abp-has(> div.inside) > div"; 187 selector = "div > div:-abp-has(> div.inside) > div";
171 selectors = parseSelector(selector); 188 selectors = parseSelector(selector);
172 189
173 test.equal(selectors.length, 3); 190 test.equal(selectors.length, 3);
174 test.ok(selectors[0] instanceof PlainSelector); 191 test.ok(selectors[0] instanceof PlainSelector);
175 test.ok(selectors[1] instanceof HasSelector); 192 test.ok(selectors[1] instanceof HasSelector);
176 test.ok(selectors[2] instanceof PlainSelector); 193 test.ok(selectors[2] instanceof PlainSelector);
177 194
178 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))";
179 selectors = parseSelector(selector); 196 selectors = parseSelector(selector);
180 197
181 test.equal(selectors.length, 4); 198 test.equal(selectors.length, 4);
182 test.ok(selectors[0] instanceof PlainSelector); 199 test.ok(selectors[0] instanceof PlainSelector);
183 test.ok(selectors[1] instanceof HasSelector); 200 test.ok(selectors[1] instanceof HasSelector);
184 test.ok(selectors[2] instanceof PlainSelector); 201 test.ok(selectors[2] instanceof PlainSelector);
185 test.ok(selectors[3] instanceof PropsSelector); 202 test.ok(selectors[3] instanceof PropsSelector);
186 203
187 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))";
188 selectors = parseSelector(selector); 205 selectors = parseSelector(selector);
189 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);
190 test.equal(selectors, null); 211 test.equal(selectors, null);
191 }).catch(unexpectedError.bind(test)).then(() => test.done()); 212 }).catch(unexpectedError.bind(test)).then(() => test.done());
192 }; 213 };
193 214
194 function buildDom(doc) 215 function buildDom(doc)
195 { 216 {
196 doc.body.innerHTML = `<div id="parent"> 217 doc.body.innerHTML = `<div id="parent">
197 <div id="middle"> 218 <div id="middle">
198 <div id="middle1"><div id="inside" class="inside"></div></div> 219 <div id="middle1"><div id="inside" class="inside"></div></div>
199 </div> 220 </div>
200 <div id="sibling"> 221 <div id="sibling">
201 <div id="tohide">to hide</div> 222 <div id="tohide">to hide</div>
202 </div> 223 </div>
203 <div id="sibling2"> 224 <div id="sibling2">
204 <div id="sibling21"><div id="sibling211" class="inside"></div></div> 225 <div id="sibling21"><div id="sibling211" class="inside"></div></div>
205 </div> 226 </div>
206 </div>`; 227 </div>`;
207 let parent = document.getElementById("parent"); 228 let parent = document.getElementById("parent");
208 let middle = document.getElementById("middle"); 229 let middle = document.getElementById("middle");
230 let middle1 = document.getElementById("middle1");
209 let inside = document.getElementById("inside"); 231 let inside = document.getElementById("inside");
210 let sibling = document.getElementById("sibling"); 232 let sibling = document.getElementById("sibling");
211 let sibling2 = document.getElementById("sibling2"); 233 let sibling2 = document.getElementById("sibling2");
212 let toHide = document.getElementById("tohide"); 234 let toHide = document.getElementById("tohide");
213 return {parent, middle, inside, sibling, sibling2, toHide}; 235 return {parent, middle, middle1, inside, sibling, sibling2, toHide};
214 } 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 };
215 262
216 exports.testPlainSelector = function(test) 263 exports.testPlainSelector = function(test)
217 { 264 {
218 let nodes = buildDom(document); 265 buildDom(document);
219 266
220 loadElemHideEmulation().then(() => 267 loadElemHideEmulation().then(() =>
221 { 268 {
222 let selector = new PlainSelector("div > div"); 269 let selector = new PlainSelector("div > div");
223 270
224 let iter = selector.getSelectors("foo > "); 271 let iter = selector.getSelectors("foo > ");
225 let value = iter.next(); 272 let value = iter.next();
226 test.equal(value.value[0], "foo > div > div"); 273 test.equal(value.value[0], "foo > div > div");
227 test.ok(iter.next().done); 274 test.ok(iter.next().done);
228
229 iter = selector.getElements("", document, [document.sheet]);
230 value = iter.next();
231 test.ok(!value.done);
232 test.equal(value.value, nodes.middle);
233 value = iter.next();
234 test.ok(!value.done);
235 test.equal(value.value.id, "middle1");
236 value = iter.next();
237 test.ok(!value.done);
238 test.equal(value.value, nodes.inside);
239 }).catch(unexpectedError.bind(test)).then(() => test.done()); 275 }).catch(unexpectedError.bind(test)).then(() => test.done());
240 }; 276 };
241 277
242 exports.testHasSelector = function(test) 278 exports.testHasSelector = function(test)
243 { 279 {
244 buildDom(document); 280 buildDom(document);
245 281
246 loadElemHideEmulation().then(() => 282 loadElemHideEmulation().then(() =>
247 { 283 {
248 let selector = new HasSelector("> div.inside"); 284 let selector = new HasSelector("> div.inside");
249 285
250 let iter = selector.getSelectors("", document, document.sheet); 286 let iter = selector.getSelectors("", document, document.sheet);
251 let value = iter.next(); 287 let value = iter.next();
252 test.ok(!value.done); 288 test.ok(!value.done);
253 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)");
254 291
255 iter = selector.getElements("", document, document.sheet); 292 iter = selector.getElements("", document, document.sheet);
256 value = iter.next(); 293 value = iter.next();
257 test.ok(!value.done); 294 test.ok(!value.done);
258 test.equal(value.value.id, "middle1"); 295 test.equal(value.value.id, "middle1");
259 value = iter.next(); 296 value = iter.next();
260 test.ok(!value.done); 297 test.ok(!value.done);
261 test.equal(value.value.id, "sibling21"); 298 test.equal(value.value.id, "sibling21");
262 value = iter.next(); 299 value = iter.next();
263 test.ok(value.done); 300 test.ok(value.done);
301
302 selector = new HasSelector(":-abp-has(> div.inside)");
303
304 test.ok(selector._innerSelectors);
264 }).catch(unexpectedError.bind(test)).then(() => test.done()); 305 }).catch(unexpectedError.bind(test)).then(() => test.done());
265 }; 306 };
266 307
267 exports.testSplitStyleRule = function(test) 308 exports.testSplitStyleRule = function(test)
268 { 309 {
269 loadElemHideEmulation().then(() => 310 loadElemHideEmulation().then(() =>
270 { 311 {
271 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");
272 test.ok(selectors); 313 test.ok(selectors);
273 test.equal(selectors.length, 1, "There is only one selector"); 314 test.equal(selectors.length, 1, "There is only one selector");
274 315
275 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)']");
276 test.ok(selectors); 317 test.ok(selectors);
277 test.equal(selectors.length, 2, "There are two selectors"); 318 test.equal(selectors.length, 2, "There are two selectors");
278 }).catch(unexpectedError.bind(test)).then(() => test.done()); 319 }).catch(unexpectedError.bind(test)).then(() => test.done());
279 }; 320 };
280 321
322 // API testing
323
281 exports.testVerbatimPropertySelector = function(test) 324 exports.testVerbatimPropertySelector = function(test)
282 { 325 {
283 let toHide = createElementWithStyle("{background-color: #000}"); 326 let toHide = createElementWithStyle("{background-color: #000}");
284 applyElemHideEmulation( 327 applyElemHideEmulation(
285 [":-abp-properties('background-color: rgb(0, 0, 0)')"] 328 [":-abp-properties(background-color: rgb(0, 0, 0))"]
286 ).then(() => 329 ).then(() =>
287 { 330 {
288 expectHidden(test, toHide); 331 expectHidden(test, toHide);
289 }).catch(unexpectedError.bind(test)).then(() => test.done()); 332 }).catch(unexpectedError.bind(test)).then(() => test.done());
290 }; 333 };
291 334
292 exports.testVerbatimPropertySelectorWithPrefix = function(test) 335 exports.testVerbatimPropertySelectorWithPrefix = function(test)
293 { 336 {
294 let parent = createElementWithStyle("{background-color: #000}"); 337 let parent = createElementWithStyle("{background-color: #000}");
295 let toHide = createElementWithStyle("{background-color: #000}", parent); 338 let toHide = createElementWithStyle("{background-color: #000}", parent);
296 applyElemHideEmulation( 339 applyElemHideEmulation(
297 ["div > :-abp-properties('background-color: rgb(0, 0, 0)')"] 340 ["div > :-abp-properties(background-color: rgb(0, 0, 0))"]
298 ).then(() => 341 ).then(() =>
299 { 342 {
300 expectVisible(test, parent); 343 expectVisible(test, parent);
301 expectHidden(test, toHide); 344 expectHidden(test, toHide);
302 }).catch(unexpectedError.bind(test)).then(() => test.done()); 345 }).catch(unexpectedError.bind(test)).then(() => test.done());
303 }; 346 };
304 347
305 exports.testVerbatimPropertySelectorWithPrefixNoMatch = function(test) 348 exports.testVerbatimPropertySelectorWithPrefixNoMatch = function(test)
306 { 349 {
307 let parent = createElementWithStyle("{background-color: #000}"); 350 let parent = createElementWithStyle("{background-color: #000}");
308 let toHide = createElementWithStyle("{background-color: #fff}", parent); 351 let toHide = createElementWithStyle("{background-color: #fff}", parent);
309 applyElemHideEmulation( 352 applyElemHideEmulation(
310 ["div > :-abp-properties('background-color: rgb(0, 0, 0)')"] 353 ["div > :-abp-properties(background-color: rgb(0, 0, 0))"]
311 ).then(() => 354 ).then(() =>
312 { 355 {
313 expectVisible(test, parent); 356 expectVisible(test, parent);
314 expectVisible(test, toHide); 357 expectVisible(test, toHide);
315 }).catch(unexpectedError.bind(test)).then(() => test.done()); 358 }).catch(unexpectedError.bind(test)).then(() => test.done());
316 }; 359 };
317 360
318 exports.testVerbatimPropertySelectorWithSuffix = function(test) 361 exports.testVerbatimPropertySelectorWithSuffix = function(test)
319 { 362 {
320 let parent = createElementWithStyle("{background-color: #000}"); 363 let parent = createElementWithStyle("{background-color: #000}");
321 let toHide = createElementWithStyle("{background-color: #000}", parent); 364 let toHide = createElementWithStyle("{background-color: #000}", parent);
322 applyElemHideEmulation( 365 applyElemHideEmulation(
323 [":-abp-properties('background-color: rgb(0, 0, 0)') > div"] 366 [":-abp-properties(background-color: rgb(0, 0, 0)) > div"]
324 ).then(() => 367 ).then(() =>
325 { 368 {
326 expectVisible(test, parent); 369 expectVisible(test, parent);
327 expectHidden(test, toHide); 370 expectHidden(test, toHide);
328 }).catch(unexpectedError.bind(test)).then(() => test.done()); 371 }).catch(unexpectedError.bind(test)).then(() => test.done());
329 }; 372 };
330 373
331 exports.testVerbatimPropertyPseudoSelectorWithPrefixAndSuffix = function(test) 374 exports.testVerbatimPropertyPseudoSelectorWithPrefixAndSuffix = function(test)
332 { 375 {
333 let parent = createElementWithStyle("{background-color: #000}"); 376 let parent = createElementWithStyle("{background-color: #000}");
334 let middle = createElementWithStyle("{background-color: #000}", parent); 377 let middle = createElementWithStyle("{background-color: #000}", parent);
335 let toHide = createElementWithStyle("{background-color: #000}", middle); 378 let toHide = createElementWithStyle("{background-color: #000}", middle);
336 applyElemHideEmulation( 379 applyElemHideEmulation(
337 ["div > :-abp-properties('background-color: rgb(0, 0, 0)') > div"] 380 ["div > :-abp-properties(background-color: rgb(0, 0, 0)) > div"]
338 ).then(() => 381 ).then(() =>
339 { 382 {
340 expectVisible(test, parent); 383 expectVisible(test, parent);
341 expectVisible(test, middle); 384 expectVisible(test, middle);
342 expectHidden(test, toHide); 385 expectHidden(test, toHide);
343 }).catch(unexpectedError.bind(test)).then(() => test.done()); 386 }).catch(unexpectedError.bind(test)).then(() => test.done());
344 }; 387 };
345 388
346 exports.testPropertySelectorWithWildcard = function(test) 389 exports.testPropertySelectorWithWildcard = function(test)
347 { 390 {
348 let toHide = createElementWithStyle("{background-color: #000}"); 391 let toHide = createElementWithStyle("{background-color: #000}");
349 applyElemHideEmulation( 392 applyElemHideEmulation(
350 [":-abp-properties('*color: rgb(0, 0, 0)')"] 393 [":-abp-properties(*color: rgb(0, 0, 0))"]
351 ).then(() => 394 ).then(() =>
352 { 395 {
353 expectHidden(test, toHide); 396 expectHidden(test, toHide);
354 }).catch(unexpectedError.bind(test)).then(() => test.done()); 397 }).catch(unexpectedError.bind(test)).then(() => test.done());
355 }; 398 };
356 399
357 exports.testPropertySelectorWithRegularExpression = function(test) 400 exports.testPropertySelectorWithRegularExpression = function(test)
358 { 401 {
359 let toHide = createElementWithStyle("{background-color: #000}"); 402 let toHide = createElementWithStyle("{background-color: #000}");
360 applyElemHideEmulation( 403 applyElemHideEmulation(
361 [":-abp-properties('/.*color: rgb\\(0, 0, 0\\)/')"] 404 [":-abp-properties(/.*color: rgb\\(0, 0, 0\\)/)"]
362 ).then(() => 405 ).then(() =>
363 { 406 {
364 expectHidden(test, toHide); 407 expectHidden(test, toHide);
365 }).catch(unexpectedError.bind(test)).then(() => test.done()); 408 }).catch(unexpectedError.bind(test)).then(() => test.done());
366 }; 409 };
367 410
368 exports.testPropertySelectorWithEscapedBrace = function(test) 411 exports.testPropertySelectorWithEscapedBrace = function(test)
369 { 412 {
370 let toHide = createElementWithStyle("{background-color: #000}"); 413 let toHide = createElementWithStyle("{background-color: #000}");
371 applyElemHideEmulation( 414 applyElemHideEmulation(
372 [":-abp-properties('/background.\\x7B 0,6\\x7D : rgb\\(0, 0, 0\\)/')"] 415 [":-abp-properties(/background.\\x7B 0,6\\x7D : rgb\\(0, 0, 0\\)/)"]
373 ).then(() => 416 ).then(() =>
374 { 417 {
375 expectHidden(test, toHide); 418 expectHidden(test, toHide);
376 }).catch(unexpectedError.bind(test)).then(() => test.done()); 419 }).catch(unexpectedError.bind(test)).then(() => test.done());
377 }; 420 };
378 421
379 exports.testPropertySelectorWithImproperlyEscapedBrace = function(test) 422 exports.testPropertySelectorWithImproperlyEscapedBrace = function(test)
380 { 423 {
381 let toHide = createElementWithStyle("{background-color: #000}"); 424 let toHide = createElementWithStyle("{background-color: #000}");
382 applyElemHideEmulation( 425 applyElemHideEmulation(
383 [":-abp-properties('/background.\\x7B0,6\\x7D: rgb\\(0, 0, 0\\)/')"] 426 [":-abp-properties(/background.\\x7B0,6\\x7D: rgb\\(0, 0, 0\\)/)"]
384 ).then(() => 427 ).then(() =>
385 { 428 {
386 expectVisible(test, toHide); 429 expectVisible(test, toHide);
387 }).catch(unexpectedError.bind(test)).then(() => test.done()); 430 }).catch(unexpectedError.bind(test)).then(() => test.done());
388 }; 431 };
389 432
390 exports.testDynamicallyChangedProperty = function(test) 433 exports.testDynamicallyChangedProperty = function(test)
391 { 434 {
392 let toHide = createElementWithStyle("{}"); 435 let toHide = createElementWithStyle("{}");
393 applyElemHideEmulation( 436 applyElemHideEmulation(
394 [":-abp-properties('background-color: rgb(0, 0, 0)')"] 437 [":-abp-properties(background-color: rgb(0, 0, 0))"]
395 ).then(() => 438 ).then(() =>
396 { 439 {
397 expectVisible(test, toHide); 440 expectVisible(test, toHide);
398 insertStyleRule("#" + toHide.id + " {background-color: #000}"); 441 insertStyleRule("#" + toHide.id + " {background-color: #000}");
399 return new Promise((resolve, reject) => 442 return new Promise((resolve, reject) =>
400 { 443 {
401 window.setTimeout(() => 444 window.setTimeout(() =>
402 { 445 {
403 expectHidden(test, toHide); 446 expectHidden(test, toHide);
404 resolve(); 447 resolve();
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after
480 expectVisible(test, parent); 523 expectVisible(test, parent);
481 expectVisible(test, middle); 524 expectVisible(test, middle);
482 expectVisible(test, sibling); 525 expectVisible(test, sibling);
483 expectHidden(test, toHide); 526 expectHidden(test, toHide);
484 }).catch(unexpectedError.bind(test)).then(() => test.done()); 527 }).catch(unexpectedError.bind(test)).then(() => test.done());
485 }; 528 };
486 529
487 function runTestPseudoClassHasSelectorWithHasAndWithSuffixSibling(test, selector ) 530 function runTestPseudoClassHasSelectorWithHasAndWithSuffixSibling(test, selector )
488 { 531 {
489 document.body.innerHTML = `<div id="parent"> 532 document.body.innerHTML = `<div id="parent">
490 <div id="middle"> 533 <div id="middle">
491 <div id="middle1"><div id="inside" class="inside"></div></div> 534 <div id="middle1"><div id="inside" class="inside"></div></div>
492 </div> 535 </div>
493 <div id="sibling"> 536 <div id="sibling">
494 <div id="tohide">to hide</div> 537 <div id="tohide">to hide</div>
495 </div> 538 </div>
496 <div id="sibling2"> 539 <div id="sibling2">
497 <div id="sibling21"><div id="sibling211" class="inside"></div></div> 540 <div id="sibling21"><div id="sibling211" class="inside"></div></div>
498 </div> 541 </div>
499 </div>`; 542 </div>`;
500 let parent = document.getElementById("parent"); 543 let parent = document.getElementById("parent");
501 let middle = document.getElementById("middle"); 544 let middle = document.getElementById("middle");
502 let inside = document.getElementById("inside"); 545 let inside = document.getElementById("inside");
503 let sibling = document.getElementById("sibling"); 546 let sibling = document.getElementById("sibling");
504 let sibling2 = document.getElementById("sibling2"); 547 let sibling2 = document.getElementById("sibling2");
505 let toHide = document.getElementById("tohide"); 548 let toHide = document.getElementById("tohide");
506 549
507 insertStyleRule(".inside {}"); 550 insertStyleRule(".inside {}");
508 551
509 applyElemHideEmulation( 552 applyElemHideEmulation(
(...skipping 17 matching lines...) Expand all
527 exports.testPseudoClassHasSelectorWithHasAndWithSuffixSibling2 = function(test) 570 exports.testPseudoClassHasSelectorWithHasAndWithSuffixSibling2 = function(test)
528 { 571 {
529 runTestPseudoClassHasSelectorWithHasAndWithSuffixSibling(test, "div:-abp-has(: -abp-has(> div.inside)) + div > div"); 572 runTestPseudoClassHasSelectorWithHasAndWithSuffixSibling(test, "div:-abp-has(: -abp-has(> div.inside)) + div > div");
530 }; 573 };
531 574
532 exports.testPseudoClassHasSelectorWithPropSelector = function(test) 575 exports.testPseudoClassHasSelectorWithPropSelector = function(test)
533 { 576 {
534 let parent = createElementWithStyle("{}"); 577 let parent = createElementWithStyle("{}");
535 let child = createElementWithStyle("{background-color: #000}", parent); 578 let child = createElementWithStyle("{background-color: #000}", parent);
536 applyElemHideEmulation( 579 applyElemHideEmulation(
537 ["div:-abp-has(:-abp-properties(\"background-color: rgb(0, 0, 0)\"))"] 580 ["div:-abp-has(:-abp-properties(background-color: rgb(0, 0, 0)))"]
538 ).then(() => 581 ).then(() =>
539 { 582 {
540 expectVisible(test, child); 583 expectVisible(test, child);
541 expectHidden(test, parent); 584 expectHidden(test, parent);
542 }).catch(unexpectedError.bind(test)).then(() => test.done()); 585 }).catch(unexpectedError.bind(test)).then(() => test.done());
543 }; 586 };
LEFTRIGHT

Powered by Google App Engine
This is Rietveld