| OLD | NEW |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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 /** | 5 /** |
| 6 * @fileoverview Fake implementation of chrome.bluetooth for testing. | 6 * @fileoverview Fake implementation of chrome.bluetooth for testing. |
| 7 */ | 7 */ |
| 8 cr.define('settings', function() { | 8 cr.define('settings', function() { |
| 9 /** | 9 /** |
| 10 * Fake of the chrome.bluetooth API. | 10 * Fake of the chrome.bluetooth API. |
| 11 * @constructor | 11 * @constructor |
| 12 * @implements {Bluetooth} | 12 * @implements {Bluetooth} |
| 13 */ | 13 */ |
| 14 function FakeBluetooth() { | 14 function FakeBluetooth() { |
| 15 /** @type {!chrome.bluetooth.AdapterState} */ this.adapterState = { | 15 /** @type {!chrome.bluetooth.AdapterState} */ this.adapterState_ = { |
| 16 address: '00:11:22:33:44:55:66', | 16 address: '00:11:22:33:44:55:66', |
| 17 name: 'Fake Adapter', | 17 name: 'Fake Adapter', |
| 18 powered: false, | 18 powered: false, |
| 19 available: true, | 19 available: true, |
| 20 discovering: false | 20 discovering: false |
| 21 }; | 21 }; |
| 22 | 22 |
| 23 /** @type {!Array<!chrome.bluetooth.Device>} */ this.devices = []; | 23 /** @type {!Array<!chrome.bluetooth.Device>} */ this.devices = []; |
| 24 } | 24 } |
| 25 | 25 |
| 26 FakeBluetooth.prototype = { | 26 FakeBluetooth.prototype = { |
| 27 // Public testing methods. | 27 // Public testing methods. |
| 28 /** @param {boolean} enabled */ | 28 /** @param {boolean} enabled */ |
| 29 setEnabled: function(enabled) { | 29 setEnabled: function(enabled) { |
| 30 this.adapterState.powered = enabled; | 30 this.setAdapterState({powered: enabled}); |
| 31 this.onAdapterStateChanged.callListeners(this.adapterState); | 31 }, |
| 32 |
| 33 /** @param {!chrome.bluetooth.AdapterState} state*/ |
| 34 setAdapterState: function(state) { |
| 35 Object.assign(this.adapterState_, state); |
| 36 this.onAdapterStateChanged.callListeners( |
| 37 Object.assign({}, this.adapterState_)); |
| 38 }, |
| 39 |
| 40 /** @return {!chrome.bluetooth.AdapterState} */ |
| 41 getAdapterStateForTest: function() { |
| 42 return Object.assign({}, this.adapterState_); |
| 32 }, | 43 }, |
| 33 | 44 |
| 34 /** @param {!Array<!chrome.bluetooth.Device>} devices */ | 45 /** @param {!Array<!chrome.bluetooth.Device>} devices */ |
| 35 setDevicesForTest: function(devices) { | 46 setDevicesForTest: function(devices) { |
| 36 for (var d of this.devices) | 47 for (var d of this.devices) |
| 37 this.onDeviceRemoved.callListeners(d); | 48 this.onDeviceRemoved.callListeners(d); |
| 38 this.devices = devices; | 49 this.devices = devices; |
| 39 for (var d of this.devices) | 50 for (var d of this.devices) |
| 40 this.onDeviceAdded.callListeners(d); | 51 this.onDeviceAdded.callListeners(d); |
| 41 }, | 52 }, |
| (...skipping 18 matching lines...) Expand all Loading... |
| 60 this.onDeviceAdded.callListeners(device); | 71 this.onDeviceAdded.callListeners(device); |
| 61 return; | 72 return; |
| 62 } | 73 } |
| 63 this.devices[index] = device; | 74 this.devices[index] = device; |
| 64 this.onDeviceChanged.callListeners(device); | 75 this.onDeviceChanged.callListeners(device); |
| 65 }, | 76 }, |
| 66 | 77 |
| 67 // Bluetooth overrides. | 78 // Bluetooth overrides. |
| 68 /** @override */ | 79 /** @override */ |
| 69 getAdapterState: function(callback) { | 80 getAdapterState: function(callback) { |
| 70 callback(this.adapterState); | 81 callback(Object.assign({}, this.adapterState_)); |
| 71 }, | 82 }, |
| 72 | 83 |
| 73 /** @override */ | 84 /** @override */ |
| 74 getDevice: assertNotReached, | 85 getDevice: assertNotReached, |
| 75 | 86 |
| 76 /** @override */ | 87 /** @override */ |
| 77 getDevices: function(callback) { | 88 getDevices: function(callback) { |
| 78 callback(this.devices); | 89 callback(this.devices); |
| 79 }, | 90 }, |
| 80 | 91 |
| (...skipping 13 matching lines...) Expand all Loading... |
| 94 | 105 |
| 95 /** @override */ | 106 /** @override */ |
| 96 onDeviceChanged: new FakeChromeEvent(), | 107 onDeviceChanged: new FakeChromeEvent(), |
| 97 | 108 |
| 98 /** @override */ | 109 /** @override */ |
| 99 onDeviceRemoved: new FakeChromeEvent(), | 110 onDeviceRemoved: new FakeChromeEvent(), |
| 100 }; | 111 }; |
| 101 | 112 |
| 102 return {FakeBluetooth: FakeBluetooth}; | 113 return {FakeBluetooth: FakeBluetooth}; |
| 103 }); | 114 }); |
| OLD | NEW |