Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(513)

Side by Side Diff: chrome/test/data/webui/settings/fake_bluetooth.js

Issue 2801403002: MD Settings: Bluetooth: Fix adapter state and discovery (Closed)
Patch Set: Use CHECK instead of early exit Created 3 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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
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
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 });
OLDNEW
« no previous file with comments | « chrome/test/data/webui/settings/bluetooth_page_tests.js ('k') | chrome/test/data/webui/settings/fake_bluetooth_private.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698