OLD | NEW |
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-present eyeo GmbH | 3 * Copyright (C) 2006-present 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 |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
48 window.setTimeout(resolve, delay); | 48 window.setTimeout(resolve, delay); |
49 }); | 49 }); |
50 } | 50 } |
51 | 51 |
52 function unexpectedError(error) | 52 function unexpectedError(error) |
53 { | 53 { |
54 console.error(error); | 54 console.error(error); |
55 this.ok(false, "Unexpected error: " + error); | 55 this.ok(false, "Unexpected error: " + error); |
56 } | 56 } |
57 | 57 |
58 function expectHidden(test, element) | 58 function expectHidden(test, element, id) |
59 { | 59 { |
60 test.equal(window.getComputedStyle(element).display, "none", | 60 let withId = ""; |
61 "The element's display property should be set to 'none'"); | 61 if (typeof id != "undefined") |
| 62 withId = ` with ID '${id}'`; |
| 63 |
| 64 test.equal( |
| 65 window.getComputedStyle(element).display, "none", |
| 66 `The element${withId}'s display property should be set to 'none'`); |
62 } | 67 } |
63 | 68 |
64 function expectVisible(test, element) | 69 function expectVisible(test, element, id) |
65 { | 70 { |
66 test.notEqual(window.getComputedStyle(element).display, "none", | 71 let withId = ""; |
67 "The element's display property should not be set to 'none'"); | 72 if (typeof id != "undefined") |
| 73 withId = ` with ID '${id}'`; |
| 74 |
| 75 test.notEqual( |
| 76 window.getComputedStyle(element).display, "none", |
| 77 `The element${withId}'s display property should not be set to 'none'`); |
68 } | 78 } |
69 | 79 |
70 function findUniqueId() | 80 function findUniqueId() |
71 { | 81 { |
72 let id = "elemHideEmulationTest-" + Math.floor(Math.random() * 10000); | 82 let id = "elemHideEmulationTest-" + Math.floor(Math.random() * 10000); |
73 if (!testDocument.getElementById(id)) | 83 if (!testDocument.getElementById(id)) |
74 return id; | 84 return id; |
75 return findUniqueId(); | 85 return findUniqueId(); |
76 } | 86 } |
77 | 87 |
(...skipping 275 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
353 }).catch(unexpectedError.bind(test)).then(() => test.done()); | 363 }).catch(unexpectedError.bind(test)).then(() => test.done()); |
354 }; | 364 }; |
355 | 365 |
356 function compareExpectations(test, elems, expectations) | 366 function compareExpectations(test, elems, expectations) |
357 { | 367 { |
358 for (let elem in expectations) | 368 for (let elem in expectations) |
359 { | 369 { |
360 if (elems[elem]) | 370 if (elems[elem]) |
361 { | 371 { |
362 if (expectations[elem]) | 372 if (expectations[elem]) |
363 expectVisible(test, elems[elem]); | 373 expectVisible(test, elems[elem], elem); |
364 else | 374 else |
365 expectHidden(test, elems[elem]); | 375 expectHidden(test, elems[elem], elem); |
366 } | 376 } |
367 } | 377 } |
368 } | 378 } |
369 | 379 |
370 function runTestPseudoClassHasSelectorWithHasAndWithSuffixSibling(test, selector
, expectations) | 380 function runTestPseudoClassHasSelectorWithHasAndWithSuffixSibling(test, selector
, expectations) |
371 { | 381 { |
372 testDocument.body.innerHTML = `<div id="parent"> | 382 testDocument.body.innerHTML = `<div id="parent"> |
373 <div id="middle"> | 383 <div id="middle"> |
374 <div id="middle1"><div id="inside" class="inside"></div></div> | 384 <div id="middle1"><div id="inside" class="inside"></div></div> |
375 </div> | 385 </div> |
(...skipping 306 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
682 expectVisible(test, child2); | 692 expectVisible(test, child2); |
683 return timeout(REFRESH_INTERVAL); | 693 return timeout(REFRESH_INTERVAL); |
684 }).then(() => | 694 }).then(() => |
685 { | 695 { |
686 expectHidden(test, parent); | 696 expectHidden(test, parent); |
687 expectVisible(test, child); | 697 expectVisible(test, child); |
688 expectHidden(test, sibling); | 698 expectHidden(test, sibling); |
689 expectVisible(test, child2); | 699 expectVisible(test, child2); |
690 }).catch(unexpectedError.bind(test)).then(() => test.done()); | 700 }).catch(unexpectedError.bind(test)).then(() => test.done()); |
691 }; | 701 }; |
OLD | NEW |