Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 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 | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 /** | |
| 6 * @fileoverview Fake implementations of chrome.bluetooth and for testing. | |
|
dpapad
2015/12/16 22:07:49
s/and//
stevenjb
2015/12/17 00:13:34
Done.
| |
| 7 */ | |
| 8 cr.define('settings', function() { | |
| 9 /** | |
| 10 * Fake of the chrome.bluetooth API. | |
| 11 * @constructor | |
| 12 * @implements {Bluetooth} | |
| 13 */ | |
| 14 function FakeBluetooth() { | |
| 15 this.enabled = false; | |
|
dpapad
2015/12/16 22:07:49
Should we add type annotations for all members? I
stevenjb
2015/12/17 00:13:34
Personally I think that typing everything quickly
dpapad
2015/12/17 01:12:54
If you don't add @private and/or rename it to this
stevenjb
2015/12/17 01:28:57
So, this isn't actually private, we do use it else
| |
| 16 this.devices = []; | |
| 17 | |
| 18 this.setDevicesForTest = function(devices) { | |
|
dpapad
2015/12/16 22:07:49
Can we move this on the prototype? Methods have no
stevenjb
2015/12/17 00:13:34
Sure. It seemed better to put just the API impleme
| |
| 19 for (var d of this.devices) | |
| 20 this.onDeviceRemoved.callListeners(d); | |
| 21 this.devices = devices; | |
| 22 for (var d of this.devices) | |
| 23 this.onDeviceAdded.callListeners(d); | |
| 24 }; | |
| 25 } | |
| 26 | |
| 27 FakeBluetooth.prototype = { | |
| 28 // Bluetooth overrides. | |
| 29 /** | |
| 30 * @param {function(!chrome.bluetooth.AdapterState):void} callback | |
| 31 */ | |
| 32 getAdapterState: function(callback) { | |
|
dpapad
2015/12/16 22:07:49
If these methods are overrides, why do we need to
stevenjb
2015/12/17 00:13:34
I didn't realize that. Done.
| |
| 33 setTimeout(function() { | |
| 34 callback({ | |
| 35 address: '00:11:22:33:44:55:66', | |
| 36 name: 'Fake Adapter', | |
| 37 powered: this.enabled, | |
| 38 available: true, | |
| 39 discovering: false | |
| 40 }); | |
| 41 }.bind(this)); | |
| 42 }, | |
| 43 | |
| 44 /** | |
| 45 * @param {string} deviceAddress Address of device to get. | |
| 46 * @param {function(!chrome.bluetooth.Device):void} callback | |
| 47 */ | |
| 48 getDevice: assertNotReached, | |
|
dschuyler
2015/12/16 22:15:01
If this were to fire (in error), how would the per
stevenjb
2015/12/17 00:13:34
I don't think that would help in a test where we h
| |
| 49 | |
| 50 /** @param {function(!Array<!chrome.bluetooth.Device>):void} callback */ | |
| 51 getDevices: function(callback) { | |
| 52 setTimeout(function() { | |
| 53 callback(this.devices); | |
| 54 }.bind(this)); | |
| 55 }, | |
| 56 | |
| 57 /** @param {function():void=} callback */ | |
| 58 startDiscovery: assertNotReached, | |
| 59 | |
| 60 /** @param {function():void=} callback */ | |
| 61 stopDiscovery: assertNotReached, | |
| 62 | |
| 63 /** @type {!FakeChromeEvent} */ | |
| 64 onAdapterStateChanged: new FakeChromeEvent(), | |
| 65 | |
| 66 /** @type {!FakeChromeEvent} */ | |
| 67 onDeviceAdded: new FakeChromeEvent(), | |
| 68 | |
| 69 /** @type {!FakeChromeEvent} */ | |
| 70 onDeviceChanged: new FakeChromeEvent(), | |
| 71 | |
| 72 /** @type {!FakeChromeEvent} */ | |
| 73 onDeviceRemoved: new FakeChromeEvent(), | |
| 74 }; | |
| 75 | |
| 76 return {FakeBluetooth: FakeBluetooth}; | |
| 77 }); | |
| OLD | NEW |