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

Side by Side Diff: test/browser/elemHideEmulation.js

Issue 29984555: Issue 6959 - Use async/await in test/browser/elemHideEmulation.js (Closed) Base URL: https://hg.adblockplus.org/adblockpluscore/
Patch Set: Created Jan. 17, 2019, 6:34 a.m.
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 130 matching lines...) Expand 10 before | Expand all | Expand 10 after
141 // Insert a <div> with a unique id and a CSS rule 141 // Insert a <div> with a unique id and a CSS rule
142 // for the the selector matching the id. 142 // for the the selector matching the id.
143 function createElementWithStyle(styleBlock, parent) 143 function createElementWithStyle(styleBlock, parent)
144 { 144 {
145 let element = createElement(parent); 145 let element = createElement(parent);
146 insertStyleRule("#" + element.id + " " + styleBlock); 146 insertStyleRule("#" + element.id + " " + styleBlock);
147 return element; 147 return element;
148 } 148 }
149 149
150 // Create a new ElemHideEmulation instance with @selectors. 150 // Create a new ElemHideEmulation instance with @selectors.
151 function applyElemHideEmulation(selectors) 151 async function applyElemHideEmulation(selectors, test)
152 { 152 {
153 return Promise.resolve().then(() => 153 await Promise.resolve();
Manish Jethani 2019/01/17 08:03:33 This should not be necessary but I left it in for
154
155 let elemHideEmulation = null;
156
157 try
154 { 158 {
155 let elemHideEmulation = new ElemHideEmulation( 159 elemHideEmulation = new ElemHideEmulation(
156 elems => 160 elems =>
157 { 161 {
158 for (let elem of elems) 162 for (let elem of elems)
159 elem.style.display = "none"; 163 elem.style.display = "none";
160 } 164 }
161 ); 165 );
162 166
163 elemHideEmulation.document = testDocument; 167 elemHideEmulation.document = testDocument;
164 elemHideEmulation.MIN_INVOCATION_INTERVAL = REFRESH_INTERVAL / 2; 168 elemHideEmulation.MIN_INVOCATION_INTERVAL = REFRESH_INTERVAL / 2;
165 elemHideEmulation.apply(selectors.map( 169 elemHideEmulation.apply(selectors.map(
166 selector => ({selector, text: selector}) 170 selector => ({selector, text: selector})
167 )); 171 ));
168 return elemHideEmulation; 172 }
169 }); 173 catch (error)
174 {
175 if (!test)
Manish Jethani 2019/01/17 08:03:33 This should not be necessary if every call to this
Manish Jethani 2019/01/17 08:04:36 Removed now.
176 throw error;
177
178 unexpectedError.call(test, error);
179 return null;
180 }
181
182 return elemHideEmulation;
170 } 183 }
171 184
172 exports.testVerbatimPropertySelector = function(test) 185 exports.testVerbatimPropertySelector = async function(test)
173 { 186 {
174 let toHide = createElementWithStyle("{background-color: #000}"); 187 let toHide = createElementWithStyle("{background-color: #000}");
175 applyElemHideEmulation( 188
176 [":-abp-properties(background-color: rgb(0, 0, 0))"] 189 if (await applyElemHideEmulation(
177 ).then(() => 190 [":-abp-properties(background-color: rgb(0, 0, 0))"],
191 test
192 ))
178 { 193 {
179 expectHidden(test, toHide); 194 expectHidden(test, toHide);
180 }).catch(unexpectedError.bind(test)).then(() => test.done()); 195 }
196
197 test.done();
181 }; 198 };
182 199
183 exports.testVerbatimPropertySelectorWithPrefix = function(test) 200 exports.testVerbatimPropertySelectorWithPrefix = async function(test)
184 { 201 {
185 let parent = createElementWithStyle("{background-color: #000}"); 202 let parent = createElementWithStyle("{background-color: #000}");
186 let toHide = createElementWithStyle("{background-color: #000}", parent); 203 let toHide = createElementWithStyle("{background-color: #000}", parent);
187 applyElemHideEmulation( 204
188 ["div > :-abp-properties(background-color: rgb(0, 0, 0))"] 205 if (await applyElemHideEmulation(
189 ).then(() => 206 ["div > :-abp-properties(background-color: rgb(0, 0, 0))"],
207 test
208 ))
190 { 209 {
191 expectVisible(test, parent); 210 expectVisible(test, parent);
192 expectHidden(test, toHide); 211 expectHidden(test, toHide);
193 }).catch(unexpectedError.bind(test)).then(() => test.done()); 212 }
213
214 test.done();
194 }; 215 };
195 216
196 exports.testVerbatimPropertySelectorWithPrefixNoMatch = function(test) 217 exports.testVerbatimPropertySelectorWithPrefixNoMatch = function(test)
197 { 218 {
198 let parent = createElementWithStyle("{background-color: #000}"); 219 let parent = createElementWithStyle("{background-color: #000}");
199 let toHide = createElementWithStyle("{background-color: #fff}", parent); 220 let toHide = createElementWithStyle("{background-color: #fff}", parent);
200 applyElemHideEmulation( 221 applyElemHideEmulation(
201 ["div > :-abp-properties(background-color: rgb(0, 0, 0))"] 222 ["div > :-abp-properties(background-color: rgb(0, 0, 0))"]
202 ).then(() => 223 ).then(() =>
203 { 224 {
(...skipping 830 matching lines...) Expand 10 before | Expand all | Expand 10 after
1034 for (let element of [...testDocument.getElementsByTagName("div"), 1055 for (let element of [...testDocument.getElementsByTagName("div"),
1035 ...testDocument.getElementsByTagName("p")]) 1056 ...testDocument.getElementsByTagName("p")])
1036 { 1057 {
1037 if (element.id == "n2" || element.id == "n2_3") 1058 if (element.id == "n2" || element.id == "n2_3")
1038 expectProcessed(test, element, element.id); 1059 expectProcessed(test, element, element.id);
1039 else 1060 else
1040 expectNotProcessed(test, element, element.id); 1061 expectNotProcessed(test, element, element.id);
1041 } 1062 }
1042 }).catch(unexpectedError.bind(test)).then(() => test.done()); 1063 }).catch(unexpectedError.bind(test)).then(() => test.done());
1043 }; 1064 };
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld