Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(486)

Side by Side Diff: chrome/test/data/webui/polymer_browser_test_base.js

Issue 2829383002: PolymerTest.clearBody: don't remove vulcanized styles (Closed)
Patch Set: Created 3 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
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 // Copyright 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 /** 5 /**
6 * @fileoverview Framework for running JavaScript tests of Polymer elements. 6 * @fileoverview Framework for running JavaScript tests of Polymer elements.
7 */ 7 */
8 8
9 /** 9 /**
10 * Test fixture for Polymer element testing. 10 * Test fixture for Polymer element testing.
(...skipping 170 matching lines...) Expand 10 before | Expand all | Expand 10 after
181 var promise = new Promise(function(resolve, reject) { 181 var promise = new Promise(function(resolve, reject) {
182 script.onload = resolve; 182 script.onload = resolve;
183 script.onerror = reject; 183 script.onerror = reject;
184 }); 184 });
185 script.src = src; 185 script.src = src;
186 document.head.appendChild(script); 186 document.head.appendChild(script);
187 return promise; 187 return promise;
188 }; 188 };
189 189
190 /** 190 /**
191 * Removes all content from the body. 191 * Removes all content from the body, save for the global <style> elements
192 * used by a vulcanized build.
192 */ 193 */
193 PolymerTest.clearBody = function() { 194 PolymerTest.clearBody = function() {
194 document.body.innerHTML = ''; 195 var vulcanizeDiv = document.querySelector('body > div[hidden][by-vulcanize]');
dpapad 2017/04/24 18:35:15 Would it be simpler to do the following? var toRe
dpapad 2017/04/25 01:11:09 Or maybe even better to use the following selector
196 document.body.innerHTML='';
197 if (!vulcanizeDiv)
198 return;
199
200 if (!vulcanizeDiv.hasAttribute('processed-by-test')) {
dpapad 2017/04/24 18:35:15 What is "processed-by-test"?
201 for (var child of vulcanizeDiv.children) {
202 if (child.tagName != 'STYLE')
203 child.remove();
204 }
205 vulcanizeDiv.setAttribute('processed-by-test', '');
206 }
207
208 document.body.appendChild(vulcanizeDiv);
195 }; 209 };
196 210
197 /** 211 /**
198 * Helper function to return the list of extra libraries relative to basePath. 212 * Helper function to return the list of extra libraries relative to basePath.
199 */ 213 */
200 PolymerTest.getLibraries = function(basePath) { 214 PolymerTest.getLibraries = function(basePath) {
201 // Ensure basePath ends in '/'. 215 // Ensure basePath ends in '/'.
202 if (basePath.length && basePath[basePath.length - 1] != '/') 216 if (basePath.length && basePath[basePath.length - 1] != '/')
203 basePath += '/'; 217 basePath += '/';
204 218
205 return PolymerTest.prototype.extraLibraries.map(function(library) { 219 return PolymerTest.prototype.extraLibraries.map(function(library) {
206 return basePath + library; 220 return basePath + library;
207 }); 221 });
208 }; 222 };
209 223
210 /* 224 /*
211 * Waits for queued up tasks to finish before proceeding. Inspired by: 225 * Waits for queued up tasks to finish before proceeding. Inspired by:
212 * https://github.com/Polymer/web-component-tester/blob/master/browser/environme nt/helpers.js#L97 226 * https://github.com/Polymer/web-component-tester/blob/master/browser/environme nt/helpers.js#L97
213 */ 227 */
214 PolymerTest.flushTasks = function() { 228 PolymerTest.flushTasks = function() {
215 Polymer.dom.flush(); 229 Polymer.dom.flush();
216 // Promises have microtask timing, so we use setTimeout to explicity force a 230 // Promises have microtask timing, so we use setTimeout to explicity force a
217 // new task. 231 // new task.
218 return new Promise(function(resolve, reject) { 232 return new Promise(function(resolve, reject) {
219 window.setTimeout(resolve, 0); 233 window.setTimeout(resolve, 0);
220 }); 234 });
221 }; 235 };
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 408576698