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

Powered by Google App Engine
This is Rietveld