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

Unified Diff: remoting/webapp/browser_test/mock_identity.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
« no previous file with comments | « remoting/webapp/browser_test/mock_host_list_api.js ('k') | remoting/webapp/browser_test/mock_oauth2_api.js » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: remoting/webapp/browser_test/mock_identity.js
diff --git a/remoting/webapp/browser_test/mock_identity.js b/remoting/webapp/browser_test/mock_identity.js
new file mode 100644
index 0000000000000000000000000000000000000000..19f9a2b8e630cb2b164670849a2bee4d7e7fb64a
--- /dev/null
+++ b/remoting/webapp/browser_test/mock_identity.js
@@ -0,0 +1,110 @@
+// 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
+ * Mock implementation of chrome.identity.
+ */
+
+'use strict';
+
+/** @suppress {duplicate} */
+var remoting = remoting || {};
+
+/**
+ * @constructor
+ */
+remoting.MockIdentity = function() {
+ /**
+ * @type {remoting.MockIdentity.AccessToken}
+ * @private
+ */
+ this.accessToken_ = remoting.MockIdentity.AccessToken.NONE;
+};
+
+/**
+ * @param {Object} details
+ * @param {function(string)} callback
+ */
+remoting.MockIdentity.prototype.getAuthToken = function(details, callback) {
+ window.setTimeout(callback.bind(null, this.accessToken_), 0);
+};
+
+/**
+ * @param {Object} details
+ * @param {function()} callback
+ */
+remoting.MockIdentity.prototype.removeCachedAuthToken =
+ function(details, callback) {
+ window.setTimeout(callback, 0);
+};
+
+/**
+ * @param {Object} details
+ * @param {function()} callback
+ */
+remoting.MockIdentity.prototype.launchWebAuthFlow =
+ function(details, callback) {
+ // TODO(jamiewalch): Work out how to test third-party auth.
+ console.error('No mock implementation for launchWebAuthFlow.');
+};
+
+
+/** @enum {string} */
+remoting.MockIdentity.AccessToken = {
+ VALID: 'valid-token',
+ INVALID: 'invalid-token',
+ NONE: ''
+};
+
+/**
+ * @param {remoting.MockIdentity.AccessToken} accessToken
+ */
+remoting.MockIdentity.prototype.setAccessToken = function(accessToken) {
+ this.accessToken_ = accessToken;
+};
+
+/**
+ * @param {string} token
+ * @param {function()} onDone
+ * @param {function()} onError
+ * @param {Array.<*>} values
+ */
+remoting.MockIdentity.validateTokenAndCall =
+ function(token, onDone, onError, values) {
+ if (token == remoting.MockIdentity.AccessToken.VALID) {
+ window.setTimeout(
+ onDone.apply.bind(onDone, null, values),
+ 0);
+ } else {
+ window.setTimeout(
+ onError.bind(null, remoting.Error.AUTHENTICATION_FAILED),
+ 0);
+ }
+};
+
+/**
+ * @param {function()} onDone
+ * @param {function()} onError
+ * @param {Array.<*>} values
+ */
+remoting.MockIdentity.prototype.validateTokenAndCall =
+ function(onDone, onError, values) {
+ remoting.MockIdentity.validateTokenAndCall(
+ this.accessToken_, onDone, onError, values);
+};
+
+/**
+ * @param {boolean} active
+ */
+remoting.MockIdentity.setActive = function(active) {
+ chrome.identity = active ? remoting.mockIdentity
+ : remoting.savedIdentityApi;
+};
+
+/** @type {Object} */
+remoting.savedIdentityApi = chrome.identity;
+
+/** @type {remoting.MockIdentity} */
+remoting.mockIdentity = new remoting.MockIdentity();
« no previous file with comments | « remoting/webapp/browser_test/mock_host_list_api.js ('k') | remoting/webapp/browser_test/mock_oauth2_api.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698