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 24 matching lines...) Expand all Loading... | |
35 * Files that need not be compiled. Should be overridden to use correct | 35 * Files that need not be compiled. Should be overridden to use correct |
36 * relative paths with PolymerTest.getLibraries. | 36 * relative paths with PolymerTest.getLibraries. |
37 * @override | 37 * @override |
38 */ | 38 */ |
39 extraLibraries: [ | 39 extraLibraries: [ |
40 'ui/webui/resources/js/cr.js', | 40 'ui/webui/resources/js/cr.js', |
41 'third_party/mocha/mocha.js', | 41 'third_party/mocha/mocha.js', |
42 'chrome/test/data/webui/mocha_adapter.js', | 42 'chrome/test/data/webui/mocha_adapter.js', |
43 ], | 43 ], |
44 | 44 |
45 /** Time when preLoad starts, i.e. before the browsePreload page is loaded. */ | |
46 preloadTime: 0, | |
47 | |
48 /** Time when test setup starts. */ | |
49 setupTime: 0, | |
50 | |
51 /** Time when test run starts. */ | |
52 runTime: 0, | |
53 | |
54 /** @override */ | |
55 preLoad: function() { | |
56 this.preloadTime = window.performance.now(); | |
57 testing.Test.prototype.preLoad.call(this); | |
58 }, | |
59 | |
45 /** @override */ | 60 /** @override */ |
46 setUp: function() { | 61 setUp: function() { |
62 this.setupTime = window.performance.now(); | |
47 testing.Test.prototype.setUp.call(this); | 63 testing.Test.prototype.setUp.call(this); |
48 | 64 |
49 // List of imported URLs for debugging purposes. | 65 // List of imported URLs for debugging purposes. |
50 PolymerTest.importUrls_ = []; | 66 PolymerTest.importUrls_ = []; |
51 | 67 |
52 // Importing a URL like "chrome://md-settings/foo" redirects to the base | 68 // Importing a URL like "chrome://md-settings/foo" redirects to the base |
53 // ("chrome://md-settings") page, which due to how browsePreload works can | 69 // ("chrome://md-settings") page, which due to how browsePreload works can |
54 // result in duplicate imports. Wrap document.registerElement so failures | 70 // result in duplicate imports. Wrap document.registerElement so failures |
55 // caused by re-registering Polymer elements are caught; otherwise Chrome | 71 // caused by re-registering Polymer elements are caught; otherwise Chrome |
56 // simply throws "Script error" which is unhelpful. | 72 // simply throws "Script error" which is unhelpful. |
(...skipping 26 matching lines...) Expand all Loading... | |
83 } | 99 } |
84 if (typeof TestHelpers != 'object') { | 100 if (typeof TestHelpers != 'object') { |
85 promises.push( | 101 promises.push( |
86 PolymerTest.importHtml( | 102 PolymerTest.importHtml( |
87 'chrome://resources/polymer/v1_0/iron-test-helpers/' + | 103 'chrome://resources/polymer/v1_0/iron-test-helpers/' + |
88 'iron-test-helpers.html')); | 104 'iron-test-helpers.html')); |
89 } | 105 } |
90 return Promise.all(promises); | 106 return Promise.all(promises); |
91 }); | 107 }); |
92 }, | 108 }, |
109 | |
110 /** @override */ | |
111 runTest: function(testBody) { | |
112 this.runTime = window.performance.now(); | |
113 testing.Test.prototype.runTest.call(this, testBody); | |
114 }, | |
115 | |
116 /** @override */ | |
117 tearDown: function() { | |
118 var endTime = window.performance.now(); | |
119 var delta = this.setupTime - this.preloadTime; | |
120 console.log('Page load time: ' + delta + " ms"); | |
michaelpg
2015/11/24 23:26:19
Turns out floats are really annoying to read...
C
| |
121 delta = endTime - this.runTime; | |
122 console.log('Test run time: ' + delta + " ms"); | |
123 delta = endTime - this.preloadTime; | |
124 console.log('Total time: ' + delta + " ms"); | |
125 testing.Test.prototype.tearDown.call(this); | |
Dan Beam
2015/11/23 23:10:51
nit: can we use console.time() + console.timeEnd()
stevenjb
2015/11/23 23:24:41
I was thinking that later we might want to do some
| |
126 } | |
93 }; | 127 }; |
94 | 128 |
95 /** | 129 /** |
96 * Imports the HTML file. | 130 * Imports the HTML file. |
97 * @param {string} src The URL to load. | 131 * @param {string} src The URL to load. |
98 * @return {Promise} A promise that is resolved/rejected on success/failure. | 132 * @return {Promise} A promise that is resolved/rejected on success/failure. |
99 */ | 133 */ |
100 PolymerTest.importHtml = function(src) { | 134 PolymerTest.importHtml = function(src) { |
101 PolymerTest.importUrls_.push(src); | 135 PolymerTest.importUrls_.push(src); |
102 var link = document.createElement('link'); | 136 var link = document.createElement('link'); |
(...skipping 19 matching lines...) Expand all Loading... | |
122 */ | 156 */ |
123 PolymerTest.getLibraries = function(basePath) { | 157 PolymerTest.getLibraries = function(basePath) { |
124 // Ensure basePath ends in '/'. | 158 // Ensure basePath ends in '/'. |
125 if (basePath.length && basePath[basePath.length - 1] != '/') | 159 if (basePath.length && basePath[basePath.length - 1] != '/') |
126 basePath += '/'; | 160 basePath += '/'; |
127 | 161 |
128 return PolymerTest.prototype.extraLibraries.map(function(library) { | 162 return PolymerTest.prototype.extraLibraries.map(function(library) { |
129 return basePath + library; | 163 return basePath + library; |
130 }); | 164 }); |
131 }; | 165 }; |
OLD | NEW |