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

Unified Diff: remoting/webapp/crd/js/host_list_api.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: Added missing file. 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/crd/js/host_list_api.js
diff --git a/remoting/webapp/crd/js/host_list_api.js b/remoting/webapp/crd/js/host_list_api.js
index c9bb2cf22a3ad03a0b72b6c98a0eb6e231d57c22..b172376b2eebace31929ed6bc16c56c39f04b0e6 100644
--- a/remoting/webapp/crd/js/host_list_api.js
+++ b/remoting/webapp/crd/js/host_list_api.js
@@ -4,7 +4,7 @@
/**
* @fileoverview
- * REST API for host-list management.
+ * API for host-list management.
*/
'use strict';
@@ -12,7 +12,7 @@
/** @suppress {duplicate} */
var remoting = remoting || {};
-/** @constructor */
+/** @interface */
remoting.HostListApi = function() {
kelvinp 2015/01/08 22:54:41 Not part of the CL. Essentially the hostListApi i
};
@@ -23,16 +23,6 @@ remoting.HostListApi = function() {
* @param {function(remoting.Error):void} onError
*/
remoting.HostListApi.prototype.get = function(onDone, onError) {
- /** @type {function(XMLHttpRequest):void} */
- var parseHostListResponse =
- this.parseHostListResponse_.bind(this, onDone, onError)
- /** @param {string} token */
- var onToken = function(token) {
- var headers = { 'Authorization': 'OAuth ' + token };
- remoting.xhr.get(remoting.settings.DIRECTORY_API_BASE_URL + '/@me/hosts',
- parseHostListResponse, '', headers);
- };
- remoting.identity.callWithToken(onToken, onError);
};
/**
@@ -46,26 +36,6 @@ remoting.HostListApi.prototype.get = function(onDone, onError) {
*/
remoting.HostListApi.prototype.put =
function(hostId, hostName, hostPublicKey, onDone, onError) {
- /** @param {string} token */
- var onToken = function(token) {
- var headers = {
- 'Authorization': 'OAuth ' + token,
- 'Content-type' : 'application/json; charset=UTF-8'
- };
- var newHostDetails = {
- 'data': {
- 'hostId': hostId,
- 'hostName': hostName,
- 'publicKey': hostPublicKey
- }
- };
- remoting.xhr.put(
- remoting.settings.DIRECTORY_API_BASE_URL + '/@me/hosts/' + hostId,
- remoting.xhr.defaultResponse(onDone, onError),
- JSON.stringify(newHostDetails),
- headers);
- };
- remoting.identity.callWithToken(onToken, onError);
};
/**
@@ -76,43 +46,4 @@ remoting.HostListApi.prototype.put =
* @param {string} hostId
*/
remoting.HostListApi.prototype.remove = function(hostId, onDone, onError) {
- /** @param {string} token */
- var onToken = function(token) {
- var headers = { 'Authorization': 'OAuth ' + token };
- remoting.xhr.remove(
- remoting.settings.DIRECTORY_API_BASE_URL + '/@me/hosts/' + hostId,
- remoting.xhr.defaultResponse(onDone, onError),
- '', headers);
- };
- remoting.identity.callWithToken(onToken, onError);
};
-
-/**
- * Handle the results of the host list request. A success response will
- * include a JSON-encoded list of host descriptions, which is parsed and
- * passed to the callback.
- *
- * @param {function(Array.<remoting.Host>):void} onDone
- * @param {function(remoting.Error):void} onError
- * @param {XMLHttpRequest} xhr
- * @private
- */
-remoting.HostListApi.prototype.parseHostListResponse_ =
- function(onDone, onError, xhr) {
- if (xhr.status == 200) {
- var response = /** @type {{data: {items: Array}}} */
- (base.jsonParseSafe(xhr.responseText));
- if (!response || !response.data) {
- console.error('Invalid "hosts" response from server.');
- onError(remoting.Error.UNEXPECTED);
- } else {
- var hosts = response.data.items || [];
- onDone(hosts);
- }
- } else {
- onError(remoting.Error.fromHttpError(xhr.status));
- }
-};
-
-/** @type {remoting.HostListApi} */
-remoting.hostListApi = new remoting.HostListApi();

Powered by Google App Engine
This is Rietveld 408576698