Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(130)

Side by Side Diff: chrome/test/data/webui/web_component_test.js

Issue 1130553002: Web component test framework (wcTest.BrowserTest) (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@MochaAdapter
Patch Set: Created 5 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(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 web components.
7 */
8
9 // Namespace for web component tests.
10 var wcTest = (function() {
11 /**
12 * @constructor
13 * @extends testing.Test
14 */
15 function BrowserTest() {}
16
17 BrowserTest.prototype = {
18 __proto__: testing.Test.prototype,
19
20 /**
21 * @override
22 * Navigate to the test WebUI.
23 */
24 browsePreload: 'chrome://web-component-test/',
25
26 /**
27 * The Mocha adapter assumes all tests are async.
28 * @override
29 * @final
30 */
31 isAsync: true,
32 };
33
34 /**
35 * Chains asynchronous functions to avoid nested setTimeouts.
36 * @return {Promise} A promise resolved after a minimal timeout.
37 */
38 function async() {
39 return new Promise(function(resolve, reject) {
40 setTimeout(resolve);
41 });
42 }
43
44 /**
45 * Removes all content from the body.
46 */
47 function clear() {
48 document.body.innerHTML = '';
49 }
50
51 /**
52 * Imports HTML using a <link> element.
53 * @param {string} uri The URI of the source to import.
54 * @return {Promise} A promise fulfilled when the link loads or errors out.
55 */
56 function importHtml(uri) {
57 var link = document.createElement('link');
58 link.rel = 'import';
59 link.href = uri;
60 document.head.appendChild(link);
61 return new Promise(function(resolve, reject) {
62 link.onload = function() {
63 resolve();
64 };
65 link.onerror = function() {
66 reject(new Error('Failed to import: ' + uri));
67 };
68 });
69 }
70
71 return {
72 BrowserTest: BrowserTest,
73 async: async,
74 clear: clear,
75 importHtml: importHtml,
76 };
77 })();
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698