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.
6 * @fileoverview Framework for running JavaScript tests of Polymer elements.
10 * Test fixture for Polymer element testing.
12 * @extends testing.Test
14 function PolymerTest() {
17 PolymerTest.prototype = {
18 __proto__: testing.Test.prototype,
21 * Navigate to a WebUI to satisfy BrowserTest conditions. Override to load a
25 browsePreload: 'chrome://chrome-urls/',
28 * The mocha adapter assumes all tests are async.
35 * Files that need not be compiled. Should be overridden to use correct
36 * relative paths with PolymerTest.getLibraries.
40 'ui/webui/resources/js/cr.js',
41 'third_party/mocha/mocha.js',
42 'chrome/test/data/webui/mocha_adapter.js',
47 testing.Test.prototype.setUp.call(this);
49 // Import Polymer and iron-test-helpers before running tests.
50 suiteSetup(function() {
52 PolymerTest.importHtml(
53 'chrome://resources/polymer/v1_0/polymer/polymer.html'),
54 PolymerTest.importHtml(
55 'chrome://resources/polymer/v1_0/iron-test-helpers/' +
56 'iron-test-helpers.html'),
63 * Imports the HTML file.
64 * @param {string} src The URL to load.
65 * @return {Promise} A promise that is resolved/rejected on success/failure.
67 PolymerTest.importHtml = function(src) {
68 var link = document.createElement('link');
70 var promise = new Promise(function(resolve, reject) {
71 link.onload = resolve;
72 link.onerror = reject;
75 document.head.appendChild(link);
80 * Removes all content from the body.
82 PolymerTest.clearBody = function() {
83 document.body.innerHTML = '';
87 * Helper function to return the list of extra libraries relative to basePath.
89 PolymerTest.getLibraries = function(basePath) {
90 // Ensure basePath ends in '/'.
91 if (basePath.length && basePath[basePath.length - 1] != '/')
94 return PolymerTest.prototype.extraLibraries.map(function(library) {
95 return basePath + library;