| 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.bluetoothPrivate for testing. | 6 * @fileoverview Fake implementation of chrome.bluetoothPrivate 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 * @param {!Bluetooth} bluetoothApi | 11 * @param {!Bluetooth} bluetoothApi |
| 12 * @constructor | 12 * @constructor |
| 13 * @implements {BluetoothPrivate} | 13 * @implements {BluetoothPrivate} |
| 14 */ | 14 */ |
| 15 function FakeBluetoothPrivate(bluetoothApi) { | 15 function FakeBluetoothPrivate(bluetoothApi) { |
| 16 /** @private {!Bluetooth} */ this.bluetoothApi_ = bluetoothApi; | 16 /** @private {!Bluetooth} */ this.bluetoothApi_ = bluetoothApi; |
| 17 |
| 18 /** @type {!Set<string>} */ this.connectedDevices_ = new Set(); |
| 19 |
| 20 /** @type {!Object<!chrome.bluetoothPrivate.SetPairingResponseOptions>} */ |
| 21 this.pairingResponses_ = {}; |
| 17 } | 22 } |
| 18 | 23 |
| 19 FakeBluetoothPrivate.prototype = { | 24 FakeBluetoothPrivate.prototype = { |
| 20 /** @override */ | 25 /** @override */ |
| 21 setAdapterState: function(state, opt_callback) { | 26 setAdapterState: function(state, opt_callback) { |
| 22 this.bluetoothApi_.enabled = state.powered; | 27 this.bluetoothApi_.adapterState = state; |
| 23 if (opt_callback) | 28 if (opt_callback) |
| 24 setTimeout(opt_callback); | 29 setTimeout(opt_callback); |
| 25 }, | 30 }, |
| 26 | 31 |
| 27 /** @override */ | 32 /** @override */ |
| 28 setPairingResponse: assertNotReached, | 33 setPairingResponse: function(options, opt_callback) { |
| 34 this.pairingResponses_[options.device.address] = options; |
| 35 if (opt_callback) |
| 36 setTimeout(opt_callback); |
| 37 }, |
| 29 | 38 |
| 30 /** @override */ | 39 /** @override */ |
| 31 disconnectAll: assertNotReached, | 40 disconnectAll: assertNotReached, |
| 32 | 41 |
| 33 /** @override */ | 42 /** @override */ |
| 34 forgetDevice: assertNotReached, | 43 forgetDevice: assertNotReached, |
| 35 | 44 |
| 36 /** @override */ | 45 /** @override */ |
| 37 setDiscoveryFilter: assertNotReached, | 46 setDiscoveryFilter: assertNotReached, |
| 38 | 47 |
| 39 /** @override */ | 48 /** @override */ |
| 40 connect: assertNotReached, | 49 connect: function(address, opt_callback) { |
| 50 this.connectedDevices_.add(address); |
| 51 if (opt_callback) |
| 52 setTimeout(opt_callback); |
| 53 }, |
| 41 | 54 |
| 42 /** @override */ | 55 /** @override */ |
| 43 pair: assertNotReached, | 56 pair: assertNotReached, |
| 44 | 57 |
| 45 /** @type {!FakeChromeEvent} */ | 58 /** @type {!FakeChromeEvent} */ |
| 46 onPairing: new FakeChromeEvent(), | 59 onPairing: new FakeChromeEvent(), |
| 47 }; | 60 }; |
| 48 | 61 |
| 49 return {FakeBluetoothPrivate: FakeBluetoothPrivate}; | 62 return {FakeBluetoothPrivate: FakeBluetoothPrivate}; |
| 50 }); | 63 }); |
| OLD | NEW |