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

Side by Side Diff: remoting/webapp/js_proto/chrome_mocks.js

Issue 1013633003: remoting.Identity unit-tests and fixes. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fix jscompile errors. Created 5 years, 9 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
« no previous file with comments | « remoting/webapp/crd/js/identity_unittest.js ('k') | remoting/webapp/js_proto/sinon_proto.js » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 // This file contains various mock objects for the chrome platform to make 5 // This file contains various mock objects for the chrome platform to make
6 // unit testing easier. 6 // unit testing easier.
7 7
8 Entry = function() {}; 8 Entry = function() {};
9 9
10 var chromeMocks = {}; 10 var chromeMocks = {};
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after
97 var message_copy = base.deepCopy(message); 97 var message_copy = base.deepCopy(message);
98 chromeMocks.runtime.onMessage.mock$fire( 98 chromeMocks.runtime.onMessage.mock$fire(
99 message_copy, {id: extensionId}, responseCallback); 99 message_copy, {id: extensionId}, responseCallback);
100 }); 100 });
101 }; 101 };
102 102
103 /** @type {string} */ 103 /** @type {string} */
104 chromeMocks.runtime.id = 'extensionId'; 104 chromeMocks.runtime.id = 'extensionId';
105 105
106 /** @type {Object} */ 106 /** @type {Object} */
107 chromeMocks.storage = {}; 107 chromeMocks.runtime.lastError = {
108 /** @type {string|undefined} */
109 message: undefined
110 };
111
108 112
109 // Sample implementation of chrome.StorageArea according to 113 // Sample implementation of chrome.StorageArea according to
110 // https://developer.chrome.com/apps/storage#type-StorageArea 114 // https://developer.chrome.com/apps/storage#type-StorageArea
111 /** @constructor */ 115 /** @constructor */
112 chromeMocks.StorageArea = function() { 116 chromeMocks.StorageArea = function() {
113 /** @type {Object} */ 117 /** @type {Object} */
114 this.storage_ = {}; 118 this.storage_ = {};
115 }; 119 };
116 120
117 /** 121 /**
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
163 /** @param {string} key */ 167 /** @param {string} key */
164 function(key) { 168 function(key) {
165 delete this.storage_[key]; 169 delete this.storage_[key];
166 }, this); 170 }, this);
167 }; 171 };
168 172
169 chromeMocks.StorageArea.prototype.clear = function() { 173 chromeMocks.StorageArea.prototype.clear = function() {
170 this.storage_ = null; 174 this.storage_ = null;
171 }; 175 };
172 176
177 /** @type {Object} */
178 chromeMocks.storage = {};
179
173 /** @type {chromeMocks.StorageArea} */ 180 /** @type {chromeMocks.StorageArea} */
174 chromeMocks.storage.local = new chromeMocks.StorageArea(); 181 chromeMocks.storage.local = new chromeMocks.StorageArea();
175 182
183
184 /** @constructor */
185 chromeMocks.Identity = function() {
186 /** @private {string|undefined} */
187 this.token_ = undefined;
188 };
189
190 /**
191 * @param {Object} options
192 * @param {function(string=):void} callback
193 */
194 chromeMocks.Identity.prototype.getAuthToken = function(options, callback) {
195 // Don't use setTimeout because sinon mocks it.
196 window.requestAnimationFrame(callback.bind(null, this.token_));
197 };
198
199 /** @param {string} token */
200 chromeMocks.Identity.prototype.mock$setToken = function(token) {
201 this.token_ = token;
202 };
203
204 chromeMocks.Identity.prototype.mock$clearToken = function() {
205 this.token_ = undefined;
206 };
207
208 /** @type {chromeMocks.Identity} */
209 chromeMocks.identity = new chromeMocks.Identity();
210
211
176 var originals_ = null; 212 var originals_ = null;
177 213
178 /** 214 /**
179 * Activates a list of Chrome components to mock 215 * Activates a list of Chrome components to mock
180 * @param {Array<string>} components 216 * @param {Array<string>} components
181 */ 217 */
182 chromeMocks.activate = function(components) { 218 chromeMocks.activate = function(components) {
183 if (originals_) { 219 if (originals_) {
184 throw new Error('chromeMocks.activate() can only be called once.'); 220 throw new Error('chromeMocks.activate() can only be called once.');
185 } 221 }
(...skipping 11 matching lines...) Expand all
197 if (!originals_) { 233 if (!originals_) {
198 throw new Error('You must call activate() before restore().'); 234 throw new Error('You must call activate() before restore().');
199 } 235 }
200 for (var components in originals_) { 236 for (var components in originals_) {
201 chrome[components] = originals_[components]; 237 chrome[components] = originals_[components];
202 } 238 }
203 originals_ = null; 239 originals_ = null;
204 }; 240 };
205 241
206 })(); 242 })();
OLDNEW
« no previous file with comments | « remoting/webapp/crd/js/identity_unittest.js ('k') | remoting/webapp/js_proto/sinon_proto.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698