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

Unified 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 side-by-side diff with in-line comments
Download patch
Index: chrome/test/data/webui/web_component_test.js
diff --git a/chrome/test/data/webui/web_component_test.js b/chrome/test/data/webui/web_component_test.js
new file mode 100644
index 0000000000000000000000000000000000000000..6b5584953c6c2537f967345265551e99176321b5
--- /dev/null
+++ b/chrome/test/data/webui/web_component_test.js
@@ -0,0 +1,77 @@
+// 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 web components.
+ */
+
+// Namespace for web component tests.
+var wcTest = (function() {
+ /**
+ * @constructor
+ * @extends testing.Test
+ */
+ function BrowserTest() {}
+
+ BrowserTest.prototype = {
+ __proto__: testing.Test.prototype,
+
+ /**
+ * @override
+ * Navigate to the test WebUI.
+ */
+ browsePreload: 'chrome://web-component-test/',
+
+ /**
+ * The Mocha adapter assumes all tests are async.
+ * @override
+ * @final
+ */
+ isAsync: true,
+ };
+
+ /**
+ * Chains asynchronous functions to avoid nested setTimeouts.
+ * @return {Promise} A promise resolved after a minimal timeout.
+ */
+ function async() {
+ return new Promise(function(resolve, reject) {
+ setTimeout(resolve);
+ });
+ }
+
+ /**
+ * Removes all content from the body.
+ */
+ function clear() {
+ document.body.innerHTML = '';
+ }
+
+ /**
+ * Imports HTML using a <link> element.
+ * @param {string} uri The URI of the source to import.
+ * @return {Promise} A promise fulfilled when the link loads or errors out.
+ */
+ function importHtml(uri) {
+ var link = document.createElement('link');
+ link.rel = 'import';
+ link.href = uri;
+ document.head.appendChild(link);
+ return new Promise(function(resolve, reject) {
+ link.onload = function() {
+ resolve();
+ };
+ link.onerror = function() {
+ reject(new Error('Failed to import: ' + uri));
+ };
+ });
+ }
+
+ return {
+ BrowserTest: BrowserTest,
+ async: async,
+ clear: clear,
+ importHtml: importHtml,
+ };
+})();

Powered by Google App Engine
This is Rietveld 408576698