OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 function MockEventSource() { | 5 function MockEventSource() { |
6 this.listeners_ = []; | 6 this.listeners_ = []; |
7 } | 7 } |
8 | 8 |
9 /** | 9 /** |
10 * Add a listener. There is no remove. | 10 * Add a listener. There is no remove. |
11 * @param {function} listener A callback function. | 11 * @param {function} listener A callback function. |
12 */ | 12 */ |
13 MockEventSource.prototype.addListener = function(listener) { | 13 MockEventSource.prototype.addListener = function(listener) { |
14 this.listeners_.push(listener); | 14 this.listeners_.push(listener); |
15 }; | 15 }; |
16 | 16 |
17 /** | 17 /** |
18 * Notify listeners in a fresh call stack. | 18 * Notify listeners in a fresh call stack. |
19 * @param {Object...} var_args Arguments. | 19 * @param {Object...} var_args Arguments. |
20 */ | 20 */ |
21 MockEventSource.prototype.notify = function(var_args) { | 21 MockEventSource.prototype.notify = function(var_args) { |
22 setTimeout(function(args) { | 22 setTimeout(function(args) { |
23 for (var i = 0; i != this.listeners_.length; i++) { | 23 for (var i = 0; i != this.listeners_.length; i++) { |
24 this.listeners_[i].apply(null, args); | 24 this.listeners_[i].apply(null, args); |
25 } | 25 } |
26 }.bind(this, arguments), 0); | 26 }.bind(this, arguments), 0); |
27 }; | 27 }; |
28 | 28 |
| 29 function cloneShallow(object) { |
| 30 var clone = {}; |
| 31 for (var key in object) |
| 32 if (object.hasOwnProperty(key)) |
| 33 clone[key] = object[key]; |
| 34 return clone; |
| 35 } |
| 36 |
29 /** | 37 /** |
30 * Mock out the chrome.fileBrowserPrivate API for use in the harness. | 38 * Mock out the chrome.fileBrowserPrivate API for use in the harness. |
31 */ | 39 */ |
32 chrome.fileBrowserPrivate = { | 40 chrome.fileBrowserPrivate = { |
33 | 41 |
34 /** | 42 /** |
35 * Return a normal HTML5 filesystem api, rather than the real local | 43 * Return a normal HTML5 filesystem api, rather than the real local |
36 * filesystem. | 44 * filesystem. |
37 * | 45 * |
38 * You must start chrome with --allow-file-access-from-files and | 46 * You must start chrome with --allow-file-access-from-files and |
(...skipping 281 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
320 response.push({ | 328 response.push({ |
321 fileUrl: url, | 329 fileUrl: url, |
322 isHosted: url.match(/\.g(doc|slides|sheet|draw|table)$/i), | 330 isHosted: url.match(/\.g(doc|slides|sheet|draw|table)$/i), |
323 isPinned: (url in chrome.fileBrowserPrivate.pinned_) | 331 isPinned: (url in chrome.fileBrowserPrivate.pinned_) |
324 }); | 332 }); |
325 } | 333 } |
326 setTimeout(callback, 0, response); | 334 setTimeout(callback, 0, response); |
327 }, | 335 }, |
328 | 336 |
329 gdataPreferences_: { | 337 gdataPreferences_: { |
| 338 driveEnabled: true, |
330 cellularDisabled: true, | 339 cellularDisabled: true, |
331 hostedFilesDisabled: false | 340 hostedFilesDisabled: false |
332 }, | 341 }, |
333 | 342 |
334 onGDataPreferencesChanged: new MockEventSource(), | 343 onGDataPreferencesChanged: new MockEventSource(), |
335 | 344 |
336 getGDataPreferences: function(callback) { | 345 getGDataPreferences: function(callback) { |
337 setTimeout(callback, 0, chrome.fileBrowserPrivate.gdataPreferences_); | 346 setTimeout(callback, 0, cloneShallow( |
| 347 chrome.fileBrowserPrivate.gdataPreferences_)); |
338 }, | 348 }, |
339 | 349 |
340 setGDataPreferences: function(preferences) { | 350 setGDataPreferences: function(preferences) { |
341 for (var prop in preferences) { | 351 for (var prop in preferences) { |
342 chrome.fileBrowserPrivate.gdataPreferences_[prop] = preferences[prop]; | 352 chrome.fileBrowserPrivate.gdataPreferences_[prop] = preferences[prop]; |
343 } | 353 } |
344 chrome.fileBrowserPrivate.onGDataPreferencesChanged.notify(); | 354 chrome.fileBrowserPrivate.onGDataPreferencesChanged.notify(); |
345 }, | 355 }, |
346 | 356 |
347 networkConnectionState_: { | 357 networkConnectionState_: { |
348 type: 'cellular', | 358 type: 'cellular', |
349 online: true | 359 online: true |
350 }, | 360 }, |
351 | 361 |
352 onNetworkConnectionChanged: new MockEventSource(), | 362 onNetworkConnectionChanged: new MockEventSource(), |
353 | 363 |
354 getNetworkConnectionState: function(callback) { | 364 getNetworkConnectionState: function(callback) { |
355 setTimeout(callback, 0, chrome.fileBrowserPrivate.networkConnectionState_); | 365 setTimeout(callback, 0, cloneShallow( |
| 366 chrome.fileBrowserPrivate.networkConnectionState_)); |
356 }, | 367 }, |
357 | 368 |
358 setConnectionState_: function(state) { | 369 setConnectionState_: function(state) { |
359 chrome.fileBrowserPrivate.networkConnectionState_ = state; | 370 chrome.fileBrowserPrivate.networkConnectionState_ = state; |
360 chrome.fileBrowserPrivate.onNetworkConnectionChanged.notify(); | 371 chrome.fileBrowserPrivate.onNetworkConnectionChanged.notify(); |
361 }, | 372 }, |
362 | 373 |
363 pinGDataFile: function(urls, on, callback) { | 374 pinGDataFile: function(urls, on, callback) { |
364 for (var i = 0; i != urls.length; i++) { | 375 for (var i = 0; i != urls.length; i++) { |
365 var url = urls[i]; | 376 var url = urls[i]; |
(...skipping 16 matching lines...) Expand all Loading... |
382 isFullscreen: function(callback) { | 393 isFullscreen: function(callback) { |
383 setTimeout(callback, 0, document.webkitIsFullScreen); | 394 setTimeout(callback, 0, document.webkitIsFullScreen); |
384 }, | 395 }, |
385 | 396 |
386 /** | 397 /** |
387 * Return localized strings. | 398 * Return localized strings. |
388 */ | 399 */ |
389 getStrings: function(callback) { | 400 getStrings: function(callback) { |
390 // Keep this list in sync with the strings in generated_resources.grd and | 401 // Keep this list in sync with the strings in generated_resources.grd and |
391 // extension_file_browser_private_api.cc! | 402 // extension_file_browser_private_api.cc! |
392 callback({ | 403 setTimeout(callback, 0, { |
393 // These two are from locale_settings*.grd | 404 // These two are from locale_settings*.grd |
394 WEB_FONT_FAMILY: 'Open Sans,Chrome Droid Sans,' + | 405 WEB_FONT_FAMILY: 'Open Sans,Chrome Droid Sans,' + |
395 'Droid Sans Fallback,sans-serif', | 406 'Droid Sans Fallback,sans-serif', |
396 WEB_FONT_SIZE: '84%', | 407 WEB_FONT_SIZE: '84%', |
397 | 408 |
398 FILE_IS_DIRECTORY: 'Folder', | 409 FILE_IS_DIRECTORY: 'Folder', |
399 | 410 |
400 GDATA_DIRECTORY_LABEL: 'Google Drive', | 411 GDATA_DIRECTORY_LABEL: 'Google Drive', |
401 ENABLE_GDATA: '1', | 412 ENABLE_GDATA: '1', |
402 PDF_VIEW_ENABLED: 'true', | 413 PDF_VIEW_ENABLED: 'true', |
(...skipping 300 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
703 | 714 |
704 setWindowHeight: function(height) { | 715 setWindowHeight: function(height) { |
705 this.popup_.style.height = height + 'px'; | 716 this.popup_.style.height = height + 'px'; |
706 }, | 717 }, |
707 | 718 |
708 closeWindow: function() { | 719 closeWindow: function() { |
709 this.popup_.parentNode.removeChild(this.popup_); | 720 this.popup_.parentNode.removeChild(this.popup_); |
710 this.popup_ = null; | 721 this.popup_ = null; |
711 } | 722 } |
712 }; | 723 }; |
OLD | NEW |