| 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. |
| 11 * @constructor | 11 * @constructor |
| 12 * @extends testing.Test | 12 * @extends testing.Test |
| 13 */ | 13 */ |
| 14 function PolymerTest() { | 14 function PolymerTest() {} |
| 15 } | |
| 16 | 15 |
| 17 PolymerTest.prototype = { | 16 PolymerTest.prototype = { |
| 18 __proto__: testing.Test.prototype, | 17 __proto__: testing.Test.prototype, |
| 19 | 18 |
| 20 /** | 19 /** |
| 21 * Navigate to a WebUI to satisfy BrowserTest conditions. Override to load a | 20 * Navigate to a WebUI to satisfy BrowserTest conditions. Override to load a |
| 22 * more useful WebUI. | 21 * more useful WebUI. |
| 23 * @override | 22 * @override |
| 24 */ | 23 */ |
| 25 browsePreload: 'chrome://chrome-urls/', | 24 browsePreload: 'chrome://chrome-urls/', |
| (...skipping 10 matching lines...) Expand all Loading... |
| 36 * relative paths with PolymerTest.getLibraries. | 35 * relative paths with PolymerTest.getLibraries. |
| 37 * @override | 36 * @override |
| 38 */ | 37 */ |
| 39 extraLibraries: [ | 38 extraLibraries: [ |
| 40 'ui/webui/resources/js/cr.js', | 39 'ui/webui/resources/js/cr.js', |
| 41 'ui/webui/resources/js/promise_resolver.js', | 40 'ui/webui/resources/js/promise_resolver.js', |
| 42 'third_party/mocha/mocha.js', | 41 'third_party/mocha/mocha.js', |
| 43 'chrome/test/data/webui/mocha_adapter.js', | 42 'chrome/test/data/webui/mocha_adapter.js', |
| 44 ], | 43 ], |
| 45 | 44 |
| 46 /** Time when preLoad starts, i.e. before the browsePreload page is loaded. */ | |
| 47 preloadTime: 0, | |
| 48 | |
| 49 /** Time when test run starts. */ | |
| 50 runTime: 0, | |
| 51 | |
| 52 /** @override */ | |
| 53 preLoad: function() { | |
| 54 this.preloadTime = window.performance.now(); | |
| 55 testing.Test.prototype.preLoad.call(this); | |
| 56 }, | |
| 57 | |
| 58 /** @override */ | 45 /** @override */ |
| 59 setUp: function() { | 46 setUp: function() { |
| 60 testing.Test.prototype.setUp.call(this); | 47 testing.Test.prototype.setUp.call(this); |
| 61 | 48 |
| 62 // List of imported URLs for debugging purposes. | 49 // List of imported URLs for debugging purposes. |
| 63 PolymerTest.importUrls_ = []; | 50 PolymerTest.importUrls_ = []; |
| 64 PolymerTest.scriptUrls_ = []; | 51 PolymerTest.scriptUrls_ = []; |
| 65 | 52 |
| 66 // Importing a URL like "chrome://md-settings/foo" redirects to the base | 53 // Importing a URL like "chrome://md-settings/foo" redirects to the base |
| 67 // ("chrome://md-settings") page, which due to how browsePreload works can | 54 // ("chrome://md-settings") page, which due to how browsePreload works can |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 102 promises.push( | 89 promises.push( |
| 103 PolymerTest.loadScript( | 90 PolymerTest.loadScript( |
| 104 'chrome://resources/polymer/v1_0/iron-test-helpers/' + | 91 'chrome://resources/polymer/v1_0/iron-test-helpers/' + |
| 105 'mock-interactions.js')); | 92 'mock-interactions.js')); |
| 106 } | 93 } |
| 107 return Promise.all(promises); | 94 return Promise.all(promises); |
| 108 }); | 95 }); |
| 109 }, | 96 }, |
| 110 | 97 |
| 111 /** @override */ | 98 /** @override */ |
| 112 runTest: function(testBody) { | |
| 113 this.runTime = window.performance.now(); | |
| 114 testing.Test.prototype.runTest.call(this, testBody); | |
| 115 }, | |
| 116 | |
| 117 /** @override */ | |
| 118 tearDown: function() { | 99 tearDown: function() { |
| 119 // Note: We do this in tearDown() so that we have a chance to stamp all the | 100 // Note: We do this in tearDown() so that we have a chance to stamp all the |
| 120 // dom-if templates, add elements through interaction, etc. | 101 // dom-if templates, add elements through interaction, etc. |
| 121 PolymerTest.testIronIcons(document.body); | 102 PolymerTest.testIronIcons(document.body); |
| 122 | 103 |
| 123 var endTime = window.performance.now(); | |
| 124 var delta = this.runTime - this.preloadTime; | |
| 125 console.log('Page load time: ' + delta.toFixed(0) + " ms"); | |
| 126 delta = endTime - this.runTime; | |
| 127 console.log('Test run time: ' + delta.toFixed(0) + " ms"); | |
| 128 delta = endTime - this.preloadTime; | |
| 129 console.log('Total time: ' + delta.toFixed(0) + " ms"); | |
| 130 testing.Test.prototype.tearDown.call(this); | 104 testing.Test.prototype.tearDown.call(this); |
| 131 } | 105 } |
| 132 }; | 106 }; |
| 133 | 107 |
| 134 /** | 108 /** |
| 135 * Tests that any iron-icon child of an HTML element has a corresponding | 109 * Tests that any iron-icon child of an HTML element has a corresponding |
| 136 * non-empty svg element. | 110 * non-empty svg element. |
| 137 * @param {!HTMLElement} e The element to check the iron icons in. | 111 * @param {!HTMLElement} e The element to check the iron icons in. |
| 138 */ | 112 */ |
| 139 PolymerTest.testIronIcons = function(e) { | 113 PolymerTest.testIronIcons = function(e) { |
| (...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 217 * https://github.com/Polymer/web-component-tester/blob/master/browser/environme
nt/helpers.js#L97 | 191 * https://github.com/Polymer/web-component-tester/blob/master/browser/environme
nt/helpers.js#L97 |
| 218 */ | 192 */ |
| 219 PolymerTest.flushTasks = function() { | 193 PolymerTest.flushTasks = function() { |
| 220 Polymer.dom.flush(); | 194 Polymer.dom.flush(); |
| 221 // Promises have microtask timing, so we use setTimeout to explicity force a | 195 // Promises have microtask timing, so we use setTimeout to explicity force a |
| 222 // new task. | 196 // new task. |
| 223 return new Promise(function(resolve, reject) { | 197 return new Promise(function(resolve, reject) { |
| 224 window.setTimeout(resolve, 0); | 198 window.setTimeout(resolve, 0); |
| 225 }); | 199 }); |
| 226 }; | 200 }; |
| OLD | NEW |