| OLD | NEW |
| 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 /** @fileoverview Suite of tests for settings-bluetooth-page. */ | 5 /** @fileoverview Suite of tests for settings-bluetooth-page. */ |
| 6 | 6 |
| 7 GEN_INCLUDE(['settings_page_browsertest.js']); | 7 GEN_INCLUDE(['settings_page_browsertest.js']); |
| 8 | 8 |
| 9 var bluetoothPage = bluetoothPage || {}; | 9 var bluetoothPage = bluetoothPage || {}; |
| 10 | 10 |
| (...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 130 Polymer.dom.flush(); | 130 Polymer.dom.flush(); |
| 131 // Ensure that initially the 'no devices' element is visible. | 131 // Ensure that initially the 'no devices' element is visible. |
| 132 expectFalse(deviceList.hidden); | 132 expectFalse(deviceList.hidden); |
| 133 var noDevices = deviceList.querySelector('.no-devices'); | 133 var noDevices = deviceList.querySelector('.no-devices'); |
| 134 assertTrue(!!noDevices); | 134 assertTrue(!!noDevices); |
| 135 expectFalse(noDevices.hidden); | 135 expectFalse(noDevices.hidden); |
| 136 // Set some devices (triggers onDeviceAdded events). 'no devices' element | 136 // Set some devices (triggers onDeviceAdded events). 'no devices' element |
| 137 // should be hidden. | 137 // should be hidden. |
| 138 self.bluetoothApi_.setDevicesForTest(fakeDevices_); | 138 self.bluetoothApi_.setDevicesForTest(fakeDevices_); |
| 139 Polymer.dom.flush(); | 139 Polymer.dom.flush(); |
| 140 assertEquals(bluetooth.deviceList.length, 4); |
| 141 var devicesIronList = bluetooth.$$('#deviceList iron-list'); |
| 142 assertTrue(!!devicesIronList); |
| 143 devicesIronList.notifyResize(); |
| 144 Polymer.dom.flush(); |
| 140 expectTrue(noDevices.hidden); | 145 expectTrue(noDevices.hidden); |
| 141 // Confirm that there are two paired devices in the list. | 146 // Confirm that there are two paired devices in the list. |
| 142 var devices = deviceList.querySelectorAll('bluetooth-device-list-item'); | 147 var devices = deviceList.querySelectorAll('bluetooth-device-list-item'); |
| 143 assertEquals(2, devices.length); | 148 assertEquals(2, devices.length); |
| 144 // Check the state of each device. | 149 // Check the state of each device. |
| 145 assertTrue(devices[0].device.connected); | 150 assertTrue(devices[0].device.connected); |
| 146 assertFalse(devices[1].device.connected); | 151 assertFalse(devices[1].device.connected); |
| 147 assertTrue(devices[1].device.connecting); | 152 assertTrue(devices[1].device.connecting); |
| 148 }); | 153 }); |
| 149 | 154 |
| 150 test('device dialog', function() { | 155 test('device dialog', function() { |
| 151 var bluetoothSection = self.getSection(advanced, 'bluetooth'); | 156 var bluetoothSection = self.getSection(advanced, 'bluetooth'); |
| 152 var bluetooth = | 157 var bluetooth = |
| 153 bluetoothSection.querySelector('settings-bluetooth-page'); | 158 bluetoothSection.querySelector('settings-bluetooth-page'); |
| 154 assertTrue(!!bluetooth); | 159 assertTrue(!!bluetooth); |
| 155 self.bluetoothApi_.setEnabled(true); | 160 self.bluetoothApi_.setEnabled(true); |
| 156 | 161 |
| 157 // Tap the 'add device' button. | 162 // Tap the 'add device' button. |
| 158 MockInteractions.tap(bluetooth.$$('.primary-button')); | 163 MockInteractions.tap(bluetooth.$$('.primary-button')); |
| 159 Polymer.dom.flush(); | 164 Polymer.dom.flush(); |
| 160 // Ensure the dialog appears. | 165 // Ensure the dialog appears. |
| 161 var dialog = bluetooth.$.deviceDialog; | 166 var dialog = bluetooth.$$('#deviceDialog'); |
| 162 assertTrue(!!dialog); | 167 assertTrue(!!dialog); |
| 163 assertTrue(dialog.$.dialog.open); | 168 assertTrue(dialog.$.dialog.open); |
| 169 assertEquals(dialog.deviceList.length, 4); |
| 164 | 170 |
| 165 // Ensure the dialog has the expected devices. | 171 // Ensure the dialog has the expected devices. |
| 166 var devicesDiv = dialog.$$('#dialogDeviceList'); | 172 var devicesIronList = dialog.$$('#dialogDeviceList iron-list'); |
| 167 assertTrue(!!devicesDiv); | 173 assertTrue(!!devicesIronList); |
| 168 var devices = devicesDiv.querySelectorAll('bluetooth-device-list-item'); | 174 devicesIronList.notifyResize(); |
| 169 assertEquals(2, devices.length); | 175 Polymer.dom.flush(); |
| 176 var devices = |
| 177 devicesIronList.querySelectorAll('bluetooth-device-list-item'); |
| 178 assertEquals(devices.length, 2); |
| 170 | 179 |
| 171 // Select a device. | 180 // Select a device. |
| 172 MockInteractions.tap(devices[0].$$('div')); | 181 MockInteractions.tap(devices[0].$$('div')); |
| 173 Polymer.dom.flush(); | 182 Polymer.dom.flush(); |
| 174 // Ensure the pairing dialog is shown. | 183 // Ensure the pairing dialog is shown. |
| 175 assertTrue(!!dialog.$$('#pairing')); | 184 assertTrue(!!dialog.$$('#pairing')); |
| 176 // Ensure the device is connected to. | 185 |
| 186 // Ensure the device wass connected to. |
| 177 expectEquals(1, self.bluetoothPrivateApi_.connectedDevices_.size); | 187 expectEquals(1, self.bluetoothPrivateApi_.connectedDevices_.size); |
| 178 var deviceAddress = | |
| 179 self.bluetoothPrivateApi_.connectedDevices_.keys().next().value; | |
| 180 | 188 |
| 181 // Close the dialog. | 189 // Close the dialog. |
| 182 var close = dialog.$.dialog.getCloseButton(); | 190 dialog.close(); |
| 183 assertTrue(!!close); | |
| 184 MockInteractions.tap(close); | |
| 185 Polymer.dom.flush(); | 191 Polymer.dom.flush(); |
| 186 expectFalse(dialog.$.dialog.open); | 192 assertFalse(dialog.$.dialog.open); |
| 187 var response = self.bluetoothPrivateApi_.pairingResponses_[deviceAddress]; | |
| 188 assertTrue(!!response); | |
| 189 expectEquals(chrome.bluetoothPrivate.PairingResponse.CANCEL, | |
| 190 response.response); | |
| 191 }); | 193 }); |
| 192 }); | 194 }); |
| 193 | 195 |
| 194 // Run all registered tests. | 196 // Run all registered tests. |
| 195 mocha.run(); | 197 mocha.run(); |
| 196 }); | 198 }); |
| OLD | NEW |