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

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

Issue 2676103002: MD Settings: Move bluetooth UI from dialog to subpage (Closed)
Patch Set: Feedback Created 3 years, 10 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 /** 28 /** @param {boolean} enabled */
29 * @param {boolean} enabled
30 */
31 setEnabled: function(enabled) { 29 setEnabled: function(enabled) {
32 this.adapterState.powered = enabled; 30 this.adapterState.powered = enabled;
33 this.onAdapterStateChanged.callListeners(this.adapterState); 31 this.onAdapterStateChanged.callListeners(this.adapterState);
34 }, 32 },
35 33
36 /** 34 /** @param {!Array<!chrome.bluetooth.Device>} devices */
37 * @param {!Array<!chrome.bluetooth.Device>} devices
38 */
39 setDevicesForTest: function(devices) { 35 setDevicesForTest: function(devices) {
40 for (var d of this.devices) 36 for (var d of this.devices)
41 this.onDeviceRemoved.callListeners(d); 37 this.onDeviceRemoved.callListeners(d);
42 this.devices = devices; 38 this.devices = devices;
43 for (var d of this.devices) 39 for (var d of this.devices)
44 this.onDeviceAdded.callListeners(d); 40 this.onDeviceAdded.callListeners(d);
45 }, 41 },
46 42
43 /**
44 * @param {string}
45 * @return {!chrome.bluetooth.Device}
46 */
47 getDeviceForTest: function(address) {
48 return this.devices.find(function(d) {
49 return d.address == address;
50 });
51 },
52
53 /** @param {!chrome.bluetooth.Device} device */
54 updateDeviceForTest: function(device, opt_callback) {
55 var index = this.devices.findIndex(function(d) {
56 return d.address == device.address;
57 });
58 if (index == -1) {
59 this.devices.push(device);
60 this.onDeviceAdded.callListeners(device);
61 return;
62 }
63 this.devices[index] = device;
64 this.onDeviceChanged.callListeners(device);
65 },
66
47 // Bluetooth overrides. 67 // Bluetooth overrides.
48 /** @override */ 68 /** @override */
49 getAdapterState: function(callback) { 69 getAdapterState: function(callback) {
50 callback(this.adapterState); 70 callback(this.adapterState);
51 }, 71 },
52 72
53 /** @override */ 73 /** @override */
54 getDevice: assertNotReached, 74 getDevice: assertNotReached,
55 75
56 /** @override */ 76 /** @override */
(...skipping 17 matching lines...) Expand all
74 94
75 /** @override */ 95 /** @override */
76 onDeviceChanged: new FakeChromeEvent(), 96 onDeviceChanged: new FakeChromeEvent(),
77 97
78 /** @override */ 98 /** @override */
79 onDeviceRemoved: new FakeChromeEvent(), 99 onDeviceRemoved: new FakeChromeEvent(),
80 }; 100 };
81 101
82 return {FakeBluetooth: FakeBluetooth}; 102 return {FakeBluetooth: FakeBluetooth};
83 }); 103 });
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