Chromium Code Reviews| Index: chrome/test/data/webui/settings/fake_bluetooth.js |
| diff --git a/chrome/test/data/webui/settings/fake_bluetooth.js b/chrome/test/data/webui/settings/fake_bluetooth.js |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..faf1f168ac04cde3e7aec3ab7398dc7bc6d6258f |
| --- /dev/null |
| +++ b/chrome/test/data/webui/settings/fake_bluetooth.js |
| @@ -0,0 +1,77 @@ |
| +// Copyright 2015 The Chromium Authors. All rights reserved. |
| +// Use of this source code is governed by a BSD-style license that can be |
| +// found in the LICENSE file. |
| + |
| +/** |
| + * @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.
|
| + */ |
| +cr.define('settings', function() { |
| + /** |
| + * Fake of the chrome.bluetooth API. |
| + * @constructor |
| + * @implements {Bluetooth} |
| + */ |
| + function FakeBluetooth() { |
| + 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
|
| + this.devices = []; |
| + |
| + 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
|
| + for (var d of this.devices) |
| + this.onDeviceRemoved.callListeners(d); |
| + this.devices = devices; |
| + for (var d of this.devices) |
| + this.onDeviceAdded.callListeners(d); |
| + }; |
| + } |
| + |
| + FakeBluetooth.prototype = { |
| + // Bluetooth overrides. |
| + /** |
| + * @param {function(!chrome.bluetooth.AdapterState):void} callback |
| + */ |
| + 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.
|
| + setTimeout(function() { |
| + callback({ |
| + address: '00:11:22:33:44:55:66', |
| + name: 'Fake Adapter', |
| + powered: this.enabled, |
| + available: true, |
| + discovering: false |
| + }); |
| + }.bind(this)); |
| + }, |
| + |
| + /** |
| + * @param {string} deviceAddress Address of device to get. |
| + * @param {function(!chrome.bluetooth.Device):void} callback |
| + */ |
| + 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
|
| + |
| + /** @param {function(!Array<!chrome.bluetooth.Device>):void} callback */ |
| + getDevices: function(callback) { |
| + setTimeout(function() { |
| + callback(this.devices); |
| + }.bind(this)); |
| + }, |
| + |
| + /** @param {function():void=} callback */ |
| + startDiscovery: assertNotReached, |
| + |
| + /** @param {function():void=} callback */ |
| + stopDiscovery: assertNotReached, |
| + |
| + /** @type {!FakeChromeEvent} */ |
| + onAdapterStateChanged: new FakeChromeEvent(), |
| + |
| + /** @type {!FakeChromeEvent} */ |
| + onDeviceAdded: new FakeChromeEvent(), |
| + |
| + /** @type {!FakeChromeEvent} */ |
| + onDeviceChanged: new FakeChromeEvent(), |
| + |
| + /** @type {!FakeChromeEvent} */ |
| + onDeviceRemoved: new FakeChromeEvent(), |
| + }; |
| + |
| + return {FakeBluetooth: FakeBluetooth}; |
| +}); |