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

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

Issue 29367181: Issue 4726 - Add tests for the element hiding emulation content script (Closed) Base URL: https://bitbucket.org/fhd/adblockpluscore
Left Patch Set: Add license header Created Jan. 10, 2017, 9:16 a.m.
Right Patch Set: Wrap and indent QUnit.test invocations consistently Created Jan. 19, 2017, 9:55 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
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 // We are currently limited to ECMAScript 5 in this file, because it is being
19 // used in the browser tests. See https://issues.adblockplus.org/ticket/4796
20
18 QUnit.module("Element hiding emulation", 21 QUnit.module("Element hiding emulation",
19 { 22 {
20 before: function() 23 before: function()
21 { 24 {
22 // The URL object in PhantomJS 2.1.7 does not implement any properties, so 25 // The URL object in PhantomJS 2.1.7 does not implement any properties, so
23 // we need a polyfill. 26 // we need a polyfill.
24 if (!URL || !("origin" in URL)) 27 if (!URL || !("origin" in URL))
25 { 28 {
26 var doc = document.implementation.createHTMLDocument(); 29 var doc = document.implementation.createHTMLDocument();
27 var anchor = doc.createElement("a"); 30 var anchor = doc.createElement("a");
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
61 if (!document.getElementById(id)) 64 if (!document.getElementById(id))
62 return id; 65 return id;
63 return findUniqueId(); 66 return findUniqueId();
64 } 67 }
65 68
66 function insertStyleRule(rule) 69 function insertStyleRule(rule)
67 { 70 {
68 var styleElement; 71 var styleElement;
69 var styleElements = document.head.getElementsByTagName("style"); 72 var styleElements = document.head.getElementsByTagName("style");
70 if (styleElements.length) 73 if (styleElements.length)
74 {
71 styleElement = styleElements[0]; 75 styleElement = styleElements[0];
76 }
72 else 77 else
73 { 78 {
74 styleElement = document.createElement("style"); 79 styleElement = document.createElement("style");
75 document.head.appendChild(styleElement); 80 document.head.appendChild(styleElement);
76 } 81 }
77 styleElement.sheet.insertRule(rule, styleElement.sheet.cssRules.length); 82 styleElement.sheet.insertRule(rule, styleElement.sheet.cssRules.length);
78 } 83 }
79 84
80 function createElementWithStyle(styleBlock) 85 function createElementWithStyle(styleBlock)
81 { 86 {
(...skipping 26 matching lines...) Expand all
108 } 113 }
109 ); 114 );
110 115
111 elemHideEmulation.load(function() 116 elemHideEmulation.load(function()
112 { 117 {
113 elemHideEmulation.apply(); 118 elemHideEmulation.apply();
114 callback(); 119 callback();
115 }); 120 });
116 } 121 }
117 122
118 QUnit.test("Verbatim property selector", function(assert) 123 QUnit.test(
119 { 124 "Verbatim property selector",
120 var done = assert.async(); 125 function(assert)
121 var toHide = createElementWithStyle("{background-color: #000}"); 126 {
122 applyElemHideEmulation(["[-abp-properties='background-color: rgb(0, 0, 0)']"], 127 var done = assert.async();
123 function() 128 var toHide = createElementWithStyle("{background-color: #000}");
124 { 129 applyElemHideEmulation(
125 assert.hidden(toHide); 130 ["[-abp-properties='background-color: rgb(0, 0, 0)']"],
126 done(); 131 function()
127 }); 132 {
128 }); 133 assert.hidden(toHide);
129 134 done();
130 QUnit.test("Property selector with wildcard", function(assert) 135 }
131 { 136 );
132 var done = assert.async(); 137 }
133 var toHide = createElementWithStyle("{background-color: #000}"); 138 );
134 applyElemHideEmulation(["[-abp-properties='*color: rgb(0, 0, 0)']"], 139
135 function() 140 QUnit.test(
136 { 141 "Property selector with wildcard",
137 assert.hidden(toHide); 142 function(assert)
138 done(); 143 {
139 }); 144 var done = assert.async();
140 }); 145 var toHide = createElementWithStyle("{background-color: #000}");
141 146 applyElemHideEmulation(
142 QUnit.test("Property selector with regular expression", function(assert) 147 ["[-abp-properties='*color: rgb(0, 0, 0)']"],
143 { 148 function()
144 var done = assert.async(); 149 {
145 var toHide = createElementWithStyle("{background-color: #000}"); 150 assert.hidden(toHide);
146 applyElemHideEmulation(["[-abp-properties='/.*color: rgb\\(0, 0, 0\\)/']"], 151 done();
147 function() 152 }
148 { 153 );
149 assert.hidden(toHide); 154 }
150 done(); 155 );
151 }); 156
152 }); 157 QUnit.test(
153 158 "Property selector with regular expression",
154 QUnit.test("Property selector with regular expression containing escaped brace", 159 function(assert)
155 function(assert) 160 {
156 { 161 var done = assert.async();
157 var done = assert.async(); 162 var toHide = createElementWithStyle("{background-color: #000}");
158 var toHide = createElementWithStyle("{background-color: #000}"); 163 applyElemHideEmulation(
159 applyElemHideEmulation( 164 ["[-abp-properties='/.*color: rgb\\(0, 0, 0\\)/']"],
160 ["[-abp-properties='/background.\\x7B 0,6\\x7D : rgb\\(0, 0, 0\\)/']"], 165 function()
161 function() 166 {
162 { 167 assert.hidden(toHide);
163 assert.hidden(toHide); 168 done();
164 done(); 169 }
165 }); 170 );
166 }); 171 }
167 172 );
168 QUnit.test("Property selector with regular expression containing improperly \ 173
169 escaped brace", 174 QUnit.test(
170 function(assert) 175 "Property selector with regular expression containing escaped brace",
171 { 176 function(assert)
172 var done = assert.async(); 177 {
173 var toHide = createElementWithStyle("{background-color: #000}"); 178 var done = assert.async();
174 applyElemHideEmulation( 179 var toHide = createElementWithStyle("{background-color: #000}");
175 ["[-abp-properties='/background.\\x7B0,6\\x7D: rgb\\(0, 0, 0\\)/']"], 180 applyElemHideEmulation(
176 function() 181 ["[-abp-properties='/background.\\x7B 0,6\\x7D : rgb\\(0, 0, 0\\)/']"],
177 { 182 function()
178 assert.visible(toHide); 183 {
179 done(); 184 assert.hidden(toHide);
180 }); 185 done();
181 }); 186 }
182 187 );
183 QUnit.test("Property selector works for dynamically changed property", 188 }
184 function(assert) 189 );
185 { 190
186 var done = assert.async(); 191 QUnit.test(
187 var toHide = createElementWithStyle("{}"); 192 "Property selector with regular expression containing improperly escaped \
188 applyElemHideEmulation(["[-abp-properties='background-color: rgb(0, 0, 0)']"], 193 brace",
189 function() 194 function(assert)
190 { 195 {
191 assert.visible(toHide); 196 var done = assert.async();
192 insertStyleRule("#" + toHide.id + " {background-color: #000}"); 197 var toHide = createElementWithStyle("{background-color: #000}");
193 setTimeout(function() 198 applyElemHideEmulation(
194 { 199 ["[-abp-properties='/background.\\x7B0,6\\x7D: rgb\\(0, 0, 0\\)/']"],
195 assert.hidden(toHide); 200 function()
196 done(); 201 {
197 }); 202 assert.visible(toHide);
198 }); 203 done();
199 }); 204 }
205 );
206 }
207 );
208
209 QUnit.test(
210 "Property selector works for dynamically changed property",
211 function(assert)
212 {
213 var done = assert.async();
214 var toHide = createElementWithStyle("{}");
215 applyElemHideEmulation(
216 ["[-abp-properties='background-color: rgb(0, 0, 0)']"],
217 function()
218 {
219 assert.visible(toHide);
220 insertStyleRule("#" + toHide.id + " {background-color: #000}");
221 setTimeout(function()
222 {
223 assert.hidden(toHide);
224 done();
225 });
226 }
227 );
228 }
229 );
LEFTRIGHT

Powered by Google App Engine
This is Rietveld