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

Unified Diff: remoting/webapp/browser_test/timeout_waiter.js

Issue 840023004: Implement mocks for identity and host-list, add a browser test to test the app in various failure m… (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Rebase Created 5 years, 11 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: remoting/webapp/browser_test/timeout_waiter.js
diff --git a/remoting/webapp/browser_test/timeout_waiter.js b/remoting/webapp/browser_test/timeout_waiter.js
new file mode 100644
index 0000000000000000000000000000000000000000..c858806f49638f4d47a61c1adeabafd5d95188fe
--- /dev/null
+++ b/remoting/webapp/browser_test/timeout_waiter.js
@@ -0,0 +1,90 @@
+// Copyright 2014 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
+ * Provide polling-based "wait for" functionality, and defines some useful
+ * predicates.
+ */
+
+'use strict';
+
+/** @suppress {duplicate} */
+var browserTest = browserTest || {};
+
+/** @enum {number} */
+browserTest.Timeout = {
+ NONE: -1,
+ DEFAULT: 5000
+};
+
+/** @interface */
+browserTest.Predicate = function() {};
+
+/** @return {boolean} */
+browserTest.Predicate.prototype.evaluate = function() {};
+
+/** @return {string} */
+browserTest.Predicate.prototype.description = function() {};
+
+/**
+ * @param {browserTest.Predicate} predicate
+ * @param {number=} opt_timeout Timeout in ms.
+ * @return {Promise}
+ */
+browserTest.waitFor = function(predicate, opt_timeout) {
+ return new Promise(function(fulfill, reject) {
+ if (opt_timeout === undefined) {
+ opt_timeout = browserTest.Timeout.DEFAULT;
+ }
+ var end = Number(new Date()) + opt_timeout;
+ var testPredicate = function() {
+ if (predicate.evaluate()) {
+ console.log(predicate.description() + ' satisfied.');
+ fulfill();
+ } else if (Number(new Date()) >= end) {
+ reject(new Error('Timed out (' + opt_timeout + 'ms) waiting for ' +
+ predicate.description()));
+ } else {
+ console.log(predicate.description() + ' not yet satisfied.');
+ window.setTimeout(testPredicate, 500);
+ }
+ };
+ testPredicate();
+ });
+};
+
+/**
+ * @param {string} id
+ * @return {browserTest.Predicate}
+ */
+browserTest.isVisible = function(id) {
+ var element = document.getElementById(id);
+ browserTest.expect(element, 'No such element: ' + id);
+ return {
+ evaluate: function() {
+ return element.getBoundingClientRect().width != 0;
+ },
+ description: function() {
+ return 'isVisible(' + id + ')';
+ }
+ };
+};
+
+/**
+ * @param {string} id
+ * @return {browserTest.Predicate}
+ */
+browserTest.isEnabled = function(id) {
+ var element = document.getElementById(id);
+ browserTest.expect(element, 'No such element: ' + id);
+ return {
+ evaluate: function() {
+ return !element.disabled;
+ },
+ description: function() {
+ return 'isEnabled(' + id + ')';
+ }
+ };
+};
« no previous file with comments | « remoting/webapp/browser_test/mock_oauth2_api.js ('k') | remoting/webapp/browser_test/unauthenticated_browser_test.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698