Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 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 | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 /** | |
| 6 * @fileoverview Framework for running JavaScript tests of Polymer elements. | |
| 7 */ | |
| 8 | |
| 9 /** | |
| 10 * Test fixture for Polymer element testing. | |
| 11 * @constructor | |
| 12 * @extends testing.Test | |
| 13 */ | |
| 14 function PolymerTest() { | |
| 15 } | |
| 16 | |
| 17 PolymerTest.prototype = { | |
| 18 __proto__: testing.Test.prototype, | |
| 19 | |
| 20 /** | |
| 21 * Navigate to a WebUI to satisfy BrowserTest conditions. Override to load a | |
| 22 * more useful WebUI. | |
| 23 * @override | |
| 24 */ | |
| 25 browsePreload: 'chrome://chrome-urls/', | |
| 26 | |
| 27 /** | |
| 28 * The mocha adapter assumes all tests are async. | |
| 29 * @override | |
| 30 * @final | |
| 31 */ | |
| 32 isAsync: true, | |
| 33 | |
| 34 /** | |
| 35 * @override | |
| 36 * @final | |
| 37 */ | |
| 38 extraLibraries: ['../../../../third_party/mocha/mocha.js', | |
| 39 'mocha_adapter.js'], | |
| 40 | |
| 41 setUp: function() { | |
| 42 // Import Polymer before running tests. | |
| 43 suiteSetup(function(done) { | |
| 44 var link = document.createElement('link'); | |
| 45 link.rel = 'import'; | |
| 46 link.href = 'chrome://resources/polymer/v0_8/polymer/polymer.html'; | |
|
Dan Beam
2015/06/02 18:11:16
set .href after assigning onload and onerror
michaelpg
2015/06/02 19:32:59
Done, but does it really matter?
| |
| 47 link.onload = function() { | |
| 48 done(); | |
| 49 }; | |
|
Dan Beam
2015/06/02 18:11:16
i assume you're not doing link.onload = done; beca
michaelpg
2015/06/02 19:32:59
Yes, done is basically @param {?Error}, other argu
| |
| 50 link.onerror = function() { | |
| 51 done(new Error('Failed to load Polymer!')); | |
| 52 }; | |
| 53 document.head.appendChild(link); | |
| 54 }); | |
| 55 }, | |
| 56 }; | |
| 57 | |
| 58 /** | |
| 59 * A helper method to run a function asynchronously. | |
| 60 * @param {Function} fn | |
| 61 */ | |
| 62 PolymerTest.async = function(fn) { | |
| 63 setTimeout(function() { | |
|
Dan Beam
2015/06/02 18:11:16
setTimeout(fn);?
michaelpg
2015/06/02 19:32:59
Removed.
| |
| 64 fn(); | |
| 65 }); | |
| 66 }; | |
| 67 | |
| 68 /** | |
| 69 * Imports the HTML file, then calls |done| on success or throws an error. | |
| 70 * @param {String} href The URL to load. | |
| 71 * @param {Function} done The done callback. | |
| 72 */ | |
| 73 PolymerTest.importHref = function(href, done) { | |
| 74 Polymer.Base.importHref( | |
| 75 href, | |
| 76 function() { done(); }, | |
|
Dan Beam
2015/06/02 18:11:16
nit: could "done," work here?
michaelpg
2015/06/02 19:32:59
Nope, this callback is passed the load or error ev
| |
| 77 function() { throw new Error('Failed to load ' + href); }); | |
| 78 }; | |
| 79 | |
| 80 /** | |
| 81 * Removes all content from the <body>. | |
|
Dan Beam
2015/06/02 18:11:16
nit: clearBody or conversely: can we clear .docume
michaelpg
2015/06/02 19:32:59
Done. This doesn't "unload" HTML templates that we
Dan Beam
2015/06/02 20:44:32
yes, it does. that's why I asked. if you want to
michaelpg
2015/06/02 21:30:25
I see. That would probably be fine as long as the
| |
| 82 */ | |
| 83 PolymerTest.clear = function() { | |
| 84 document.body.innerHTML = ''; | |
| 85 }; | |
| OLD | NEW |