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: Run browser tests via our test runner Created Jan. 10, 2017, 9:10 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 /*
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}");
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 with regular expression containing escaped brace", 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("{background-color: #000}"); 163 applyElemHideEmulation(
142 applyElemHideEmulation( 164 ["[-abp-properties='/.*color: rgb\\(0, 0, 0\\)/']"],
143 ["[-abp-properties='/background.\\x7B 0,6\\x7D : rgb\\(0, 0, 0\\)/']"], 165 function()
144 function() 166 {
145 { 167 assert.hidden(toHide);
146 assert.hidden(toHide); 168 done();
147 done(); 169 }
148 }); 170 );
149 }); 171 }
150 172 );
151 QUnit.test("Property selector with regular expression containing improperly \ 173
152 escaped brace", 174 QUnit.test(
153 function(assert) 175 "Property selector with regular expression containing escaped brace",
154 { 176 function(assert)
155 var done = assert.async(); 177 {
156 var toHide = createElementWithStyle("{background-color: #000}"); 178 var done = assert.async();
157 applyElemHideEmulation( 179 var toHide = createElementWithStyle("{background-color: #000}");
158 ["[-abp-properties='/background.\\x7B0,6\\x7D: rgb\\(0, 0, 0\\)/']"], 180 applyElemHideEmulation(
159 function() 181 ["[-abp-properties='/background.\\x7B 0,6\\x7D : rgb\\(0, 0, 0\\)/']"],
160 { 182 function()
161 assert.visible(toHide); 183 {
162 done(); 184 assert.hidden(toHide);
163 }); 185 done();
164 }); 186 }
165 187 );
166 QUnit.test("Property selector works for dynamically changed property", 188 }
167 function(assert) 189 );
168 { 190
169 var done = assert.async(); 191 QUnit.test(
170 var toHide = createElementWithStyle("{}"); 192 "Property selector with regular expression containing improperly escaped \
171 applyElemHideEmulation(["[-abp-properties='background-color: rgb(0, 0, 0)']"], 193 brace",
172 function() 194 function(assert)
173 { 195 {
174 assert.visible(toHide); 196 var done = assert.async();
175 insertStyleRule("#" + toHide.id + " {background-color: #000}"); 197 var toHide = createElementWithStyle("{background-color: #000}");
176 setTimeout(function() 198 applyElemHideEmulation(
177 { 199 ["[-abp-properties='/background.\\x7B0,6\\x7D: rgb\\(0, 0, 0\\)/']"],
178 assert.hidden(toHide); 200 function()
179 done(); 201 {
180 }); 202 assert.visible(toHide);
181 }); 203 done();
182 }); 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