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

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

Issue 1568703002: Add Bluetooth settings dialog tests (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: .. Created 4 years, 11 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 {boolean} */ this.enabled = false; 15 /** @type {!chrome.bluettoth.AdapterState} */ this.adapterState = {
16 address: '00:11:22:33:44:55:66',
17 name: 'Fake Adapter',
18 powered: false,
19 available: true,
20 discovering: false
21 };
16 22
17 /** @type {!Array<!chrome.bluetooth.Device>} */ this.devices = []; 23 /** @type {!Array<!chrome.bluetooth.Device>} */ this.devices = [];
18 } 24 }
19 25
20 FakeBluetooth.prototype = { 26 FakeBluetooth.prototype = {
21 // Public testing methods. 27 // Public testing methods.
22 /** 28 /**
29 * @param {boolean} enabled
30 */
31 setEnabled: function(enabled) {
32 this.adapterState.powered = enabled;
33 this.onAdapterStateChanged.callListeners(this.adapterState);
34 },
35
36 /**
23 * @param {!Array<!chrome.bluetooth.Device>} devices 37 * @param {!Array<!chrome.bluetooth.Device>} devices
24 */ 38 */
25 setDevicesForTest: function(devices) { 39 setDevicesForTest: function(devices) {
26 for (var d of this.devices) 40 for (var d of this.devices)
27 this.onDeviceRemoved.callListeners(d); 41 this.onDeviceRemoved.callListeners(d);
28 this.devices = devices; 42 this.devices = devices;
29 for (var d of this.devices) 43 for (var d of this.devices)
30 this.onDeviceAdded.callListeners(d); 44 this.onDeviceAdded.callListeners(d);
31 }, 45 },
32 46
33 // Bluetooth overrides. 47 // Bluetooth overrides.
34 /** @override */ 48 /** @override */
35 getAdapterState: function(callback) { 49 getAdapterState: function(callback) {
36 setTimeout(function() { 50 setTimeout(function() {
37 callback({ 51 callback(this.adapterState);
38 address: '00:11:22:33:44:55:66',
39 name: 'Fake Adapter',
40 powered: this.enabled,
41 available: true,
42 discovering: false
43 });
44 }.bind(this)); 52 }.bind(this));
45 }, 53 },
46 54
47 /** @override */ 55 /** @override */
48 getDevice: assertNotReached, 56 getDevice: assertNotReached,
49 57
50 /** @override */ 58 /** @override */
51 getDevices: function(callback) { 59 getDevices: function(callback) {
52 setTimeout(function() { 60 setTimeout(function() {
53 callback(this.devices); 61 callback(this.devices);
(...skipping 14 matching lines...) Expand all
68 76
69 /** @override */ 77 /** @override */
70 onDeviceChanged: new FakeChromeEvent(), 78 onDeviceChanged: new FakeChromeEvent(),
71 79
72 /** @override */ 80 /** @override */
73 onDeviceRemoved: new FakeChromeEvent(), 81 onDeviceRemoved: new FakeChromeEvent(),
74 }; 82 };
75 83
76 return {FakeBluetooth: FakeBluetooth}; 84 return {FakeBluetooth: FakeBluetooth};
77 }); 85 });
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698