diff options
author | michaelpg <michaelpg@chromium.org> | 2015-06-02 20:21:39 -0700 |
---|---|---|
committer | Commit bot <commit-bot@chromium.org> | 2015-06-03 03:22:05 +0000 |
commit | 8247dfe6962829ae8122df4375099c036e39ac9e (patch) | |
tree | 6797b0932fd08e2db25de1eefb7f2364d766d952 /chrome/test/data/webui/polymer_browser_test_base.js | |
parent | cce953ffbf1b5fbf046576984396be07d9a850e4 (diff) | |
download | chromium_src-8247dfe6962829ae8122df4375099c036e39ac9e.zip chromium_src-8247dfe6962829ae8122df4375099c036e39ac9e.tar.gz chromium_src-8247dfe6962829ae8122df4375099c036e39ac9e.tar.bz2 |
Mocha adapter for Polymer browser tests.
A custom reporter enables mocha in WebUI browser tests. This is
used by a new BrowserTest base class, PolymerTest, to configure
mocha.
Relevant browser_tests sample output: http://pastebin.com/raw.php?i=EeHrmtWH
BUG=482770
Review URL: https://codereview.chromium.org/1124873002
Cr-Commit-Position: refs/heads/master@{#332537}
Diffstat (limited to 'chrome/test/data/webui/polymer_browser_test_base.js')
-rw-r--r-- | chrome/test/data/webui/polymer_browser_test_base.js | 78 |
1 files changed, 78 insertions, 0 deletions
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 0000000..e628eda --- /dev/null +++ b/chrome/test/data/webui/polymer_browser_test_base.js @@ -0,0 +1,78 @@ +// 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'], + + /** @override */ + setUp: function() { + testing.Test.prototype.setUp.call(this); + + // Import Polymer before running tests. + suiteSetup(function(done) { + var link = document.createElement('link'); + link.rel = 'import'; + link.onload = function() { + done(); + }; + link.onerror = function() { + done(new Error('Failed to load Polymer!')); + }; + link.href = 'chrome://resources/polymer/v0_8/polymer/polymer.html'; + document.head.appendChild(link); + }); + }, +}; + +/** + * 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(); }, + function() { throw new Error('Failed to load ' + href); }); +}; + +/** + * Removes all content from the body. + */ +PolymerTest.clearBody = function() { + document.body.innerHTML = ''; +}; |