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

Delta Between Two Patch Sets: test/browser/elemHideEmulation.js

Issue 29373596: Issue 4838 - Use nodeunit framework for integration tests running in browser (Closed) Base URL: https://hg.adblockplus.org/adblockpluscore
Left Patch Set: Isolate module scopes to avoid naming conflicts Created Jan. 25, 2017, 9:53 a.m.
Right Patch Set: Addressed comments and added additional minor changes Created Feb. 24, 2017, 9:17 a.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 | « test/browser/elemHideEmulation.html ('k') | test_runner.js » ('j') | 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
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
42 42
43 callback(); 43 callback();
44 }; 44 };
45 45
46 exports.tearDown = function(callback) 46 exports.tearDown = function(callback)
47 { 47 {
48 var styleElements = document.head.getElementsByTagName("style"); 48 var styleElements = document.head.getElementsByTagName("style");
49 while (styleElements.length) 49 while (styleElements.length)
50 styleElements[0].parentNode.removeChild(styleElements[0]); 50 styleElements[0].parentNode.removeChild(styleElements[0]);
51 callback(); 51 callback();
52 } 52 };
53 53
54 function expectHidden(test, element) 54 function expectHidden(test, element)
55 { 55 {
56 test.equal(window.getComputedStyle(element).display, "none", 56 test.equal(window.getComputedStyle(element).display, "none",
57 "The element's display property should be set to 'none'"); 57 "The element's display property should be set to 'none'");
58 }; 58 }
59 59
60 function expectVisible(test, element) 60 function expectVisible(test, element)
61 { 61 {
62 test.notEqual(window.getComputedStyle(element).display, "none", 62 test.notEqual(window.getComputedStyle(element).display, "none",
63 "The element's display property should not be set to 'none'"); 63 "The element's display property should not be set to 'none'");
64 }; 64 }
65 65
66 function findUniqueId() 66 function findUniqueId()
67 { 67 {
68 var id = "elemHideEmulationTest-" + Math.floor(Math.random() * 10000); 68 var id = "elemHideEmulationTest-" + Math.floor(Math.random() * 10000);
69 if (!document.getElementById(id)) 69 if (!document.getElementById(id))
70 return id; 70 return id;
71 return findUniqueId(); 71 return findUniqueId();
72 } 72 }
73 73
74 function insertStyleRule(rule) 74 function insertStyleRule(rule)
75 { 75 {
76 var styleElement; 76 var styleElement;
77 var styleElements = document.head.getElementsByTagName("style"); 77 var styleElements = document.head.getElementsByTagName("style");
78 if (styleElements.length) 78 if (styleElements.length)
79 {
80 styleElement = styleElements[0]; 79 styleElement = styleElements[0];
81 }
82 else 80 else
83 { 81 {
84 styleElement = document.createElement("style"); 82 styleElement = document.createElement("style");
85 document.head.appendChild(styleElement); 83 document.head.appendChild(styleElement);
86 } 84 }
87 styleElement.sheet.insertRule(rule, styleElement.sheet.cssRules.length); 85 styleElement.sheet.insertRule(rule, styleElement.sheet.cssRules.length);
88 } 86 }
89 87
90 function createElementWithStyle(styleBlock) 88 function createElementWithStyle(styleBlock)
91 { 89 {
92 var element = document.createElement("div"); 90 var element = document.createElement("div");
93 element.id = findUniqueId(); 91 element.id = findUniqueId();
94 document.body.appendChild(element); 92 document.body.appendChild(element);
95 insertStyleRule("#" + element.id + " " + styleBlock); 93 insertStyleRule("#" + element.id + " " + styleBlock);
96 return element; 94 return element;
97 } 95 }
98 96
99 function applyElemHideEmulation(selectors, callback) 97 function applyElemHideEmulation(selectors, callback)
100 { 98 {
101 if (typeof ElemHideEmulation == "undefined") 99 if (typeof ElemHideEmulation == "undefined")
102 { 100 {
103 loadScript(myUrl + "/../../../lib/common.js", function() 101 loadScript(myUrl + "/../../../lib/common.js", function()
104 { 102 {
105 loadScript(myUrl + "/../../../chrome/content/elemHideEmulation.js", functi on() 103 loadScript(myUrl + "/../../../chrome/content/elemHideEmulation.js",
Felix Dahlke 2017/01/30 14:37:59 Can you wrap this to stay within 80 columns?
Wladimir Palant 2017/02/24 09:18:55 Done. And while at it, I've done some linting in o
106 { 104 function()
107 applyElemHideEmulation(selectors, callback); 105 {
108 }); 106 applyElemHideEmulation(selectors, callback);
107 });
109 }); 108 });
110 return; 109 return;
111 } 110 }
112 111
113 var elemHideEmulation = new ElemHideEmulation( 112 var elemHideEmulation = new ElemHideEmulation(
114 window, 113 window,
115 function(callback) 114 function(callback)
116 { 115 {
117 var patterns = []; 116 var patterns = [];
118 selectors.forEach(function(selector) 117 selectors.forEach(function(selector)
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after
195 applyElemHideEmulation( 194 applyElemHideEmulation(
196 ["[-abp-properties='/background.\\x7B0,6\\x7D: rgb\\(0, 0, 0\\)/']"], 195 ["[-abp-properties='/background.\\x7B0,6\\x7D: rgb\\(0, 0, 0\\)/']"],
197 function() 196 function()
198 { 197 {
199 expectVisible(test, toHide); 198 expectVisible(test, toHide);
200 test.done(); 199 test.done();
201 } 200 }
202 ); 201 );
203 }; 202 };
204 203
205 exports.testPropertySelectorWithDynamicallyChangedProperty = function(test) 204 exports.testDynamicallyChangedProperty = function(test)
Felix Dahlke 2017/01/30 14:37:59 I found this easier to understand with "works for"
Wladimir Palant 2017/02/24 09:18:55 Done.
206 { 205 {
207 var toHide = createElementWithStyle("{}"); 206 var toHide = createElementWithStyle("{}");
208 applyElemHideEmulation( 207 applyElemHideEmulation(
209 ["[-abp-properties='background-color: rgb(0, 0, 0)']"], 208 ["[-abp-properties='background-color: rgb(0, 0, 0)']"],
210 function() 209 function()
211 { 210 {
212 expectVisible(test, toHide); 211 expectVisible(test, toHide);
213 insertStyleRule("#" + toHide.id + " {background-color: #000}"); 212 insertStyleRule("#" + toHide.id + " {background-color: #000}");
214 window.setTimeout(function() 213 window.setTimeout(function()
215 { 214 {
216 expectHidden(test, toHide); 215 expectHidden(test, toHide);
217 test.done(); 216 test.done();
218 }, 0); 217 }, 0);
219 } 218 }
220 ); 219 );
221 }; 220 };
LEFTRIGHT

Powered by Google App Engine
This is Rietveld