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: Created Dec. 11, 2016, 12:12 p.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 /*
2 * This file is part of Adblock Plus <https://adblockplus.org/>,
3 * Copyright (C) 2006-2017 Eyeo GmbH
4 *
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
7 * published by the Free Software Foundation.
8 *
9 * Adblock Plus is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 *
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/>.
16 */
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
1 QUnit.module("Element hiding emulation", 21 QUnit.module("Element hiding emulation",
2 { 22 {
3 before: function() 23 before: function()
4 { 24 {
5 // 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
6 // we need a polyfill. 26 // we need a polyfill.
7 if (!URL || !("origin" in URL)) 27 if (!URL || !("origin" in URL))
8 { 28 {
9 var doc = document.implementation.createHTMLDocument(); 29 var doc = document.implementation.createHTMLDocument();
10 var anchor = doc.createElement("a"); 30 var anchor = doc.createElement("a");
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
44 if (!document.getElementById(id)) 64 if (!document.getElementById(id))
45 return id; 65 return id;
46 return findUniqueId(); 66 return findUniqueId();
47 } 67 }
48 68
49 function insertStyleRule(rule) 69 function insertStyleRule(rule)
50 { 70 {
51 var styleElement; 71 var styleElement;
52 var styleElements = document.head.getElementsByTagName("style"); 72 var styleElements = document.head.getElementsByTagName("style");
53 if (styleElements.length) 73 if (styleElements.length)
74 {
54 styleElement = styleElements[0]; 75 styleElement = styleElements[0];
76 }
55 else 77 else
56 { 78 {
57 styleElement = document.createElement("style"); 79 styleElement = document.createElement("style");
58 document.head.appendChild(styleElement); 80 document.head.appendChild(styleElement);
59 } 81 }
60 styleElement.sheet.insertRule(rule, styleElement.sheet.cssRules.length); 82 styleElement.sheet.insertRule(rule, styleElement.sheet.cssRules.length);
61 } 83 }
62 84
63 function createElementWithStyle(styleBlock) 85 function createElementWithStyle(styleBlock)
64 { 86 {
(...skipping 26 matching lines...) Expand all
91 } 113 }
92 ); 114 );
93 115
94 elemHideEmulation.load(function() 116 elemHideEmulation.load(function()
95 { 117 {
96 elemHideEmulation.apply(); 118 elemHideEmulation.apply();
97 callback(); 119 callback();
98 }); 120 });
99 } 121 }
100 122
101 QUnit.test("Verbatim property selector", function(assert) 123 QUnit.test(
102 { 124 "Verbatim property selector",
103 var done = assert.async(); 125 function(assert)
104 var toHide = createElementWithStyle("{background-color: #000}"); 126 {
105 applyElemHideEmulation(["[-abp-properties='background-color: rgb(0, 0, 0)']"], 127 var done = assert.async();
106 function() 128 var toHide = createElementWithStyle("{background-color: #000}");
Felix Dahlke 2016/12/11 12:13:49 Not so sure about this indentation style - suggest
107 { 129 applyElemHideEmulation(
108 assert.hidden(toHide); 130 ["[-abp-properties='background-color: rgb(0, 0, 0)']"],
109 done(); 131 function()
110 }); 132 {
111 }); 133 assert.hidden(toHide);
112 134 done();
113 QUnit.test("Property selector with wildcard", function(assert) 135 }
114 { 136 );
115 var done = assert.async(); 137 }
116 var toHide = createElementWithStyle("{background-color: #000}"); 138 );
117 applyElemHideEmulation(["[-abp-properties='*color: rgb(0, 0, 0)']"], 139
118 function() 140 QUnit.test(
119 { 141 "Property selector with wildcard",
120 assert.hidden(toHide); 142 function(assert)
121 done(); 143 {
122 }); 144 var done = assert.async();
123 }); 145 var toHide = createElementWithStyle("{background-color: #000}");
124 146 applyElemHideEmulation(
125 QUnit.test("Property selector with regular expression", function(assert) 147 ["[-abp-properties='*color: rgb(0, 0, 0)']"],
126 { 148 function()
127 var done = assert.async(); 149 {
128 var toHide = createElementWithStyle("{background-color: #000}"); 150 assert.hidden(toHide);
129 applyElemHideEmulation(["[-abp-properties='/.*color: rgb\\(0, 0, 0\\)/']"], 151 done();
130 function() 152 }
131 { 153 );
132 assert.hidden(toHide); 154 }
133 done(); 155 );
134 }); 156
135 }); 157 QUnit.test(
136 158 "Property selector with regular expression",
137 QUnit.test("Property selector works for dynamically changed property", 159 function(assert)
138 function(assert) 160 {
139 { 161 var done = assert.async();
140 var done = assert.async(); 162 var toHide = createElementWithStyle("{background-color: #000}");
141 var toHide = createElementWithStyle("{}"); 163 applyElemHideEmulation(
142 applyElemHideEmulation(["[-abp-properties='background-color: rgb(0, 0, 0)']"], 164 ["[-abp-properties='/.*color: rgb\\(0, 0, 0\\)/']"],
143 function() 165 function()
144 { 166 {
145 assert.visible(toHide); 167 assert.hidden(toHide);
146 insertStyleRule("#" + toHide.id + " {background-color: #000}"); 168 done();
147 setTimeout(function() 169 }
148 { 170 );
149 assert.hidden(toHide); 171 }
150 done(); 172 );
151 }); 173
152 }); 174 QUnit.test(
153 }); 175 "Property selector with regular expression containing escaped brace",
176 function(assert)
177 {
178 var done = assert.async();
179 var toHide = createElementWithStyle("{background-color: #000}");
180 applyElemHideEmulation(
181 ["[-abp-properties='/background.\\x7B 0,6\\x7D : rgb\\(0, 0, 0\\)/']"],
182 function()
183 {
184 assert.hidden(toHide);
185 done();
186 }
187 );
188 }
189 );
190
191 QUnit.test(
192 "Property selector with regular expression containing improperly escaped \
193 brace",
194 function(assert)
195 {
196 var done = assert.async();
197 var toHide = createElementWithStyle("{background-color: #000}");
198 applyElemHideEmulation(
199 ["[-abp-properties='/background.\\x7B0,6\\x7D: rgb\\(0, 0, 0\\)/']"],
200 function()
201 {
202 assert.visible(toHide);
203 done();
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