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

Side by Side Diff: chrome/test/data/webui/settings/bluetooth_page_tests.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 2017 The Chromium Authors. All rights reserved. 1 // Copyright 2017 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 suite('Bluetooth', function() { 5 suite('Bluetooth', function() {
6 var bluetoothPage = null; 6 var bluetoothPage = null;
7 7
8 /** @type {Bluetooth} */ 8 /** @type {Bluetooth} */
9 var bluetoothApi_; 9 var bluetoothApi_;
10 10
11 /** @type {BluetoothPrivate} */ 11 /** @type {BluetoothPrivate} */
12 var bluetoothPrivateApi_; 12 var bluetoothPrivateApi_;
13 13
14 /** @type {!Array<!chrome.bluetooth.Device>} */ var fakeDevices_ = [ 14 /** @type {!Array<!chrome.bluetooth.Device>} */ var fakeDevices_ = [
15 { 15 {
16 address: '10:00:00:00:00:01', 16 address: '10:00:00:00:00:01',
17 name: 'FakePairedDevice1', 17 name: 'FakePairedDevice1',
18 paired: true, 18 paired: true,
19 connected: true, 19 connected: true,
20 }, 20 },
21 { 21 {
22 address: '10:00:00:00:00:02', 22 address: '10:00:00:00:00:02',
23 name: 'FakePairedDevice2', 23 name: 'FakePairedDevice2',
24 paired: true, 24 paired: true,
25 connected: false, 25 connected: false,
26 connecting: true,
27 }, 26 },
28 { 27 {
29 address: '00:00:00:00:00:01', 28 address: '00:00:00:00:00:01',
30 name: 'FakeUnPairedDevice1', 29 name: 'FakeUnpairedDevice1',
31 paired: false, 30 paired: false,
32 }, 31 },
33 { 32 {
34 address: '00:00:00:00:00:02', 33 address: '00:00:00:00:00:02',
35 name: 'FakeUnPairedDevice2', 34 name: 'FakeUnpairedDevice2',
36 paired: false, 35 paired: false,
37 }, 36 },
38 ]; 37 ];
39 38
40 suiteSetup(function() { 39 suiteSetup(function() {
41 loadTimeData.overrideValues({ 40 loadTimeData.overrideValues({
42 bluetoothEnabled: 'bluetoothEnabled', 41 bluetoothEnabled: 'bluetoothEnabled',
43 bluetoothDisabled: 'bluetoothDisabled', 42 bluetoothDisabled: 'bluetoothDisabled',
44 bluetoothOn: 'bluetoothOn', 43 bluetoothOn: 'bluetoothOn',
45 bluetoothOff: 'bluetoothOff', 44 bluetoothOff: 'bluetoothOff',
(...skipping 12 matching lines...) Expand all
58 57
59 // Disable animations so sub-pages open within one event loop. 58 // Disable animations so sub-pages open within one event loop.
60 testing.Test.disableAnimationsAndTransitions(); 59 testing.Test.disableAnimationsAndTransitions();
61 }); 60 });
62 61
63 setup(function() { 62 setup(function() {
64 PolymerTest.clearBody(); 63 PolymerTest.clearBody();
65 bluetoothPage = document.createElement('settings-bluetooth-page'); 64 bluetoothPage = document.createElement('settings-bluetooth-page');
66 assertTrue(!!bluetoothPage); 65 assertTrue(!!bluetoothPage);
67 66
67 bluetoothApi_.setDevicesForTest([]);
68 document.body.appendChild(bluetoothPage); 68 document.body.appendChild(bluetoothPage);
69 Polymer.dom.flush(); 69 Polymer.dom.flush();
70 }); 70 });
71 71
72 teardown(function() { 72 teardown(function() {
73 bluetoothPage.remove(); 73 bluetoothPage.remove();
74 }); 74 });
75 75
76 test('MainPage', function() { 76 test('MainPage', function() {
77 assertFalse(bluetoothApi_.adapterState.powered); 77 assertFalse(bluetoothApi_.adapterState.powered);
(...skipping 23 matching lines...) Expand all
101 var enableButton = subpage.$.enableBluetooth; 101 var enableButton = subpage.$.enableBluetooth;
102 assertTrue(!!enableButton); 102 assertTrue(!!enableButton);
103 assertTrue(enableButton.checked); 103 assertTrue(enableButton.checked);
104 104
105 subpage.bluetoothEnabled = false; 105 subpage.bluetoothEnabled = false;
106 assertFalse(enableButton.checked); 106 assertFalse(enableButton.checked);
107 assertFalse(bluetoothApi_.adapterState.powered);; 107 assertFalse(bluetoothApi_.adapterState.powered);;
108 assertFalse(bluetoothPage.bluetoothEnabled_); 108 assertFalse(bluetoothPage.bluetoothEnabled_);
109 }); 109 });
110 110
111 test('device list', function() { 111 test('paired device list', function() {
112 var deviceList = subpage.$.container; 112 var pairedContainer = subpage.$.pairedContainer;
113 assertTrue(!!deviceList); 113 assertTrue(!!pairedContainer);
114 assertTrue(deviceList.hidden); 114 assertTrue(pairedContainer.hidden);
115 assertFalse(subpage.$.noDevices.hidden); 115 assertFalse(subpage.$.noPairedDevices.hidden);
116 116
117 bluetoothApi_.setDevicesForTest(fakeDevices_); 117 bluetoothApi_.setDevicesForTest(fakeDevices_);
118 Polymer.dom.flush(); 118 Polymer.dom.flush();
119 assertEquals(4, subpage.deviceList_.length); 119 assertEquals(4, subpage.deviceList_.length);
120 assertTrue(subpage.$.noDevices.hidden); 120 assertEquals(2, subpage.pairedDeviceList_.length);
121 assertTrue(subpage.$.noPairedDevices.hidden);
121 122
122 var devicesIronList = subpage.$$('#container > iron-list'); 123 var ironList = subpage.$.pairedDevices;
123 assertTrue(!!devicesIronList); 124 assertTrue(!!ironList);
124 devicesIronList.notifyResize(); 125 ironList.notifyResize();
125 Polymer.dom.flush(); 126 Polymer.dom.flush();
126 var devices = deviceList.querySelectorAll('bluetooth-device-list-item'); 127 var devices = ironList.querySelectorAll('bluetooth-device-list-item');
127 assertEquals(2, devices.length); 128 assertEquals(2, devices.length);
128 assertTrue(devices[0].device.connected); 129 assertTrue(devices[0].device.connected);
129 assertFalse(devices[1].device.connected); 130 assertFalse(devices[1].device.connected);
130 assertTrue(devices[1].device.connecting);
131 }); 131 });
132 132
133 test('device dialog', function() { 133 test('unpaired device list', function() {
134 // Tap the 'add device' button. 134 var unpairedContainer = subpage.$.unpairedContainer;
135 MockInteractions.tap(subpage.$.pairButton); 135 assertTrue(!!unpairedContainer);
136 assertTrue(unpairedContainer.hidden);
137 assertFalse(subpage.$.noUnpairedDevices.hidden);
138
139 bluetoothApi_.setDevicesForTest(fakeDevices_);
136 Polymer.dom.flush(); 140 Polymer.dom.flush();
141 assertEquals(4, subpage.deviceList_.length);
142 assertEquals(2, subpage.unpairedDeviceList_.length);
143 assertTrue(subpage.$.noUnpairedDevices.hidden);
137 144
138 // Ensure the dialog appears. 145 var ironList = subpage.$.unpairedDevices;
146 assertTrue(!!ironList);
147 ironList.notifyResize();
148 Polymer.dom.flush();
149 var devices = ironList.querySelectorAll('bluetooth-device-list-item');
150 assertEquals(2, devices.length);
151 assertFalse(devices[0].device.paired);
152 assertFalse(devices[1].device.paired);
153 });
154
155 test('pair device', function(done) {
156 bluetoothApi_.setDevicesForTest(fakeDevices_);
157 Polymer.dom.flush();
158 assertEquals(4, subpage.deviceList_.length);
159 assertEquals(2, subpage.pairedDeviceList_.length);
160 assertEquals(2, subpage.unpairedDeviceList_.length);
161
162 var address = subpage.unpairedDeviceList_[0].address;
163 bluetoothPrivateApi_.connect(address, function() {
164 Polymer.dom.flush();
165 assertEquals(3, subpage.pairedDeviceList_.length);
166 assertEquals(1, subpage.unpairedDeviceList_.length);
167 done();
168 });
169 });
170
171 test('pair dialog', function() {
172 bluetoothApi_.setDevicesForTest(fakeDevices_);
173 Polymer.dom.flush();
139 var dialog = subpage.$.deviceDialog; 174 var dialog = subpage.$.deviceDialog;
140 assertTrue(!!dialog); 175 assertTrue(!!dialog);
176 assertFalse(dialog.$.dialog.open);
177
178 // Simulate selecting an unpaired device; should show the pair dialog.
179 subpage.connectDevice_(subpage.unpairedDeviceList_[0]);
180 Polymer.dom.flush();
141 assertTrue(dialog.$.dialog.open); 181 assertTrue(dialog.$.dialog.open);
142 assertEquals(dialog.deviceList.length, 4);
143
144 // Ensure the dialog has the expected devices.
145 var devicesIronList = dialog.$$('#dialogDeviceList iron-list');
146 assertTrue(!!devicesIronList);
147 devicesIronList.notifyResize();
148 Polymer.dom.flush();
149 var devices =
150 devicesIronList.querySelectorAll('bluetooth-device-list-item');
151 assertEquals(devices.length, 2);
152
153 // Select a device.
154 MockInteractions.tap(devices[0].$$('div'));
155 Polymer.dom.flush();
156 // Ensure the pairing dialog is shown.
157 assertTrue(!!dialog.$$('#pairing'));
158
159 // Ensure the device wass connected to.
160 expectEquals(1, bluetoothPrivateApi_.connectedDevices_.size);
161
162 // Close the dialog.
163 dialog.close();
164 Polymer.dom.flush();
165 assertFalse(dialog.$.dialog.open);
166 }); 182 });
167 }); 183 });
168 }); 184 });
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698