Chromium Code Reviews| Index: chrome/test/data/webui/polymer_browser_test_base.js |
| diff --git a/chrome/test/data/webui/polymer_browser_test_base.js b/chrome/test/data/webui/polymer_browser_test_base.js |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..dc6b94c3bfdc4de60891ddd32f2547b2814e6422 |
| --- /dev/null |
| +++ b/chrome/test/data/webui/polymer_browser_test_base.js |
| @@ -0,0 +1,85 @@ |
| +// Copyright 2015 The Chromium Authors. All rights reserved. |
| +// Use of this source code is governed by a BSD-style license that can be |
| +// found in the LICENSE file. |
| + |
| +/** |
| + * @fileoverview Framework for running JavaScript tests of Polymer elements. |
| + */ |
| + |
| +/** |
| + * Test fixture for Polymer element testing. |
| + * @constructor |
| + * @extends testing.Test |
| + */ |
| +function PolymerTest() { |
| +} |
| + |
| +PolymerTest.prototype = { |
| + __proto__: testing.Test.prototype, |
| + |
| + /** |
| + * Navigate to a WebUI to satisfy BrowserTest conditions. Override to load a |
| + * more useful WebUI. |
| + * @override |
| + */ |
| + browsePreload: 'chrome://chrome-urls/', |
| + |
| + /** |
| + * The mocha adapter assumes all tests are async. |
| + * @override |
| + * @final |
| + */ |
| + isAsync: true, |
| + |
| + /** |
| + * @override |
| + * @final |
| + */ |
| + extraLibraries: ['../../../../third_party/mocha/mocha.js', |
| + 'mocha_adapter.js'], |
| + |
| + setUp: function() { |
| + // Import Polymer before running tests. |
| + suiteSetup(function(done) { |
| + var link = document.createElement('link'); |
| + link.rel = 'import'; |
| + 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?
|
| + link.onload = function() { |
| + done(); |
| + }; |
|
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
|
| + link.onerror = function() { |
| + done(new Error('Failed to load Polymer!')); |
| + }; |
| + document.head.appendChild(link); |
| + }); |
| + }, |
| +}; |
| + |
| +/** |
| + * A helper method to run a function asynchronously. |
| + * @param {Function} fn |
| + */ |
| +PolymerTest.async = function(fn) { |
| + setTimeout(function() { |
|
Dan Beam
2015/06/02 18:11:16
setTimeout(fn);?
michaelpg
2015/06/02 19:32:59
Removed.
|
| + fn(); |
| + }); |
| +}; |
| + |
| +/** |
| + * Imports the HTML file, then calls |done| on success or throws an error. |
| + * @param {String} href The URL to load. |
| + * @param {Function} done The done callback. |
| + */ |
| +PolymerTest.importHref = function(href, done) { |
| + Polymer.Base.importHref( |
| + href, |
| + 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
|
| + function() { throw new Error('Failed to load ' + href); }); |
| +}; |
| + |
| +/** |
| + * 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
|
| + */ |
| +PolymerTest.clear = function() { |
| + document.body.innerHTML = ''; |
| +}; |