| OLD | NEW |
| 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 Loading... |
| 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. In a vulcanized build, this retains the |
| 192 * inlined tags so stylesheets and dom-modules are not discarded. |
| 192 */ | 193 */ |
| 193 PolymerTest.clearBody = function() { | 194 PolymerTest.clearBody = function() { |
| 195 // Save the div where vulcanize inlines content before clearing the page. |
| 196 var vulcanizeDiv = document.querySelector('body > div[hidden][by-vulcanize]'); |
| 194 document.body.innerHTML = ''; | 197 document.body.innerHTML = ''; |
| 198 if (vulcanizeDiv) |
| 199 document.body.appendChild(vulcanizeDiv); |
| 195 }; | 200 }; |
| 196 | 201 |
| 197 /** | 202 /** |
| 198 * Helper function to return the list of extra libraries relative to basePath. | 203 * Helper function to return the list of extra libraries relative to basePath. |
| 199 */ | 204 */ |
| 200 PolymerTest.getLibraries = function(basePath) { | 205 PolymerTest.getLibraries = function(basePath) { |
| 201 // Ensure basePath ends in '/'. | 206 // Ensure basePath ends in '/'. |
| 202 if (basePath.length && basePath[basePath.length - 1] != '/') | 207 if (basePath.length && basePath[basePath.length - 1] != '/') |
| 203 basePath += '/'; | 208 basePath += '/'; |
| 204 | 209 |
| 205 return PolymerTest.prototype.extraLibraries.map(function(library) { | 210 return PolymerTest.prototype.extraLibraries.map(function(library) { |
| 206 return basePath + library; | 211 return basePath + library; |
| 207 }); | 212 }); |
| 208 }; | 213 }; |
| 209 | 214 |
| 210 /* | 215 /* |
| 211 * Waits for queued up tasks to finish before proceeding. Inspired by: | 216 * 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 | 217 * https://github.com/Polymer/web-component-tester/blob/master/browser/environme
nt/helpers.js#L97 |
| 213 */ | 218 */ |
| 214 PolymerTest.flushTasks = function() { | 219 PolymerTest.flushTasks = function() { |
| 215 Polymer.dom.flush(); | 220 Polymer.dom.flush(); |
| 216 // Promises have microtask timing, so we use setTimeout to explicity force a | 221 // Promises have microtask timing, so we use setTimeout to explicity force a |
| 217 // new task. | 222 // new task. |
| 218 return new Promise(function(resolve, reject) { | 223 return new Promise(function(resolve, reject) { |
| 219 window.setTimeout(resolve, 0); | 224 window.setTimeout(resolve, 0); |
| 220 }); | 225 }); |
| 221 }; | 226 }; |
| OLD | NEW |