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 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
79 name: 'FakePairedDevice2', | 79 name: 'FakePairedDevice2', |
80 paired: true, | 80 paired: true, |
81 connected: false, | 81 connected: false, |
82 connecting: true, | 82 connecting: true, |
83 }, | 83 }, |
84 { | 84 { |
85 address: '00:00:00:00:00:01', | 85 address: '00:00:00:00:00:01', |
86 name: 'FakeUnPairedDevice1', | 86 name: 'FakeUnPairedDevice1', |
87 paired: false, | 87 paired: false, |
88 }, | 88 }, |
| 89 { |
| 90 address: '00:00:00:00:00:02', |
| 91 name: 'FakeUnPairedDevice2', |
| 92 paired: false, |
| 93 }, |
89 ]; | 94 ]; |
90 | 95 |
91 suite('SettingsBluetoothPage', function() { | 96 suite('SettingsBluetoothPage', function() { |
92 test('enable', function() { | 97 test('enable', function() { |
93 assertFalse(self.bluetoothApi_.enabled); | 98 assertFalse(self.bluetoothApi_.adapterState.powered); |
94 var bluetoothSection = self.getSection(advanced, 'bluetooth'); | 99 var bluetoothSection = self.getSection(advanced, 'bluetooth'); |
95 assertTrue(!!bluetoothSection); | 100 assertTrue(!!bluetoothSection); |
96 var bluetooth = | 101 var bluetooth = |
97 bluetoothSection.querySelector('settings-bluetooth-page'); | 102 bluetoothSection.querySelector('settings-bluetooth-page'); |
98 assertTrue(!!bluetooth); | 103 assertTrue(!!bluetooth); |
99 expectFalse(bluetooth.bluetoothEnabled); | 104 expectFalse(bluetooth.bluetoothEnabled); |
100 var enable = bluetooth.$.enableBluetooth; | 105 var enable = bluetooth.$.enableBluetooth; |
101 assertTrue(!!enable); | 106 assertTrue(!!enable); |
102 expectFalse(enable.checked); | 107 expectFalse(enable.checked); |
103 // Test that tapping the enable checkbox changes its value and calls | 108 // Test that tapping the enable checkbox changes its value and calls |
104 // bluetooth.setAdapterState with powered = false. | 109 // bluetooth.setAdapterState with powered = false. |
105 MockInteractions.tap(enable); | 110 MockInteractions.tap(enable); |
| 111 Polymer.dom.flush(); |
106 expectTrue(enable.checked); | 112 expectTrue(enable.checked); |
107 expectTrue(self.bluetoothApi_.enabled); | 113 expectTrue(self.bluetoothApi_.adapterState.powered); |
108 // Confirm that 'bluetoothEnabled' remains set to true. | 114 // Confirm that 'bluetoothEnabled' remains set to true. |
109 Polymer.dom.flush(); | |
110 expectTrue(bluetooth.bluetoothEnabled); | 115 expectTrue(bluetooth.bluetoothEnabled); |
111 // Set 'bluetoothEnabled' directly and confirm that the checkbox | 116 // Set 'bluetoothEnabled' directly and confirm that the checkbox |
112 // toggles. | 117 // toggles. |
113 bluetooth.bluetoothEnabled = false; | 118 bluetooth.bluetoothEnabled = false; |
114 Polymer.dom.flush(); | 119 Polymer.dom.flush(); |
115 expectFalse(enable.checked); | 120 expectFalse(enable.checked); |
116 }); | 121 }); |
117 | 122 |
118 test('device list', function() { | 123 test('device list', function() { |
119 var bluetoothSection = self.getSection(advanced, 'bluetooth'); | 124 var bluetoothSection = self.getSection(advanced, 'bluetooth'); |
120 var bluetooth = | 125 var bluetooth = |
121 bluetoothSection.querySelector('settings-bluetooth-page'); | 126 bluetoothSection.querySelector('settings-bluetooth-page'); |
122 assertTrue(!!bluetooth); | 127 assertTrue(!!bluetooth); |
123 var deviceList = bluetooth.$.deviceList; | 128 var deviceList = bluetooth.$.deviceList; |
124 assertTrue(!!deviceList); | 129 assertTrue(!!deviceList); |
125 // Set enabled, with default (empty) device list. | 130 // Set enabled, with default (empty) device list. |
126 self.bluetoothApi_.enabled = true; | 131 self.bluetoothApi_.setEnabled(true); |
127 bluetooth.bluetoothEnabled = true; | |
128 Polymer.dom.flush(); | 132 Polymer.dom.flush(); |
129 // Ensure that initially the 'device list empty' span is visible. | 133 // Ensure that initially the 'device list empty' span is visible. |
130 expectFalse(deviceList.hidden); | 134 expectFalse(deviceList.hidden); |
131 var noDevices = deviceList.querySelector('span'); | 135 var noDevices = deviceList.querySelector('span'); |
132 assertTrue(!!noDevices); | 136 assertTrue(!!noDevices); |
133 expectFalse(noDevices.hidden); | 137 expectFalse(noDevices.hidden); |
134 // Set some devices (triggers onDeviceAdded events). 'empty' span should | 138 // Set some devices (triggers onDeviceAdded events). 'empty' span should |
135 // be hidden. | 139 // be hidden. |
136 self.bluetoothApi_.setDevicesForTest(fakeDevices_); | 140 self.bluetoothApi_.setDevicesForTest(fakeDevices_); |
137 Polymer.dom.flush(); | 141 Polymer.dom.flush(); |
138 expectTrue(noDevices.hidden); | 142 expectTrue(noDevices.hidden); |
139 // Confirm that there are two paired devices in the list. | 143 // Confirm that there are two paired devices in the list. |
140 var devices = deviceList.querySelectorAll('bluetooth-device-list-item'); | 144 var devices = deviceList.querySelectorAll('bluetooth-device-list-item'); |
141 assertEquals(2, devices.length); | 145 assertEquals(2, devices.length); |
142 // Check the state of each device. | 146 // Check the state of each device. |
143 assertTrue(devices[0].device.connected); | 147 assertTrue(devices[0].device.connected); |
144 assertFalse(devices[1].device.connected); | 148 assertFalse(devices[1].device.connected); |
145 assertTrue(devices[1].device.connecting); | 149 assertTrue(devices[1].device.connecting); |
146 }); | 150 }); |
| 151 |
| 152 test('device dialog', function() { |
| 153 var bluetoothSection = self.getSection(advanced, 'bluetooth'); |
| 154 var bluetooth = |
| 155 bluetoothSection.querySelector('settings-bluetooth-page'); |
| 156 assertTrue(!!bluetooth); |
| 157 self.bluetoothApi_.setEnabled(true); |
| 158 |
| 159 // Tap the 'add device' button. |
| 160 MockInteractions.tap(bluetooth.$.addDevice); |
| 161 Polymer.dom.flush(); |
| 162 // Ensure the dialog appears. |
| 163 var dialog = bluetooth.$.deviceDialog; |
| 164 assertTrue(!!dialog); |
| 165 assertTrue(dialog.opened); |
| 166 var addDialog = bluetooth.$$('settings-bluetooth-add-device-dialog'); |
| 167 assertTrue(!!addDialog); |
| 168 // Ensure the dialog has the expected devices. |
| 169 var devicesDiv = addDialog.$.dialogDeviceList; |
| 170 var devices = devicesDiv.querySelectorAll('bluetooth-device-list-item'); |
| 171 assertEquals(2, devices.length); |
| 172 |
| 173 // Select a device. |
| 174 MockInteractions.tap(devices[0].$$('div')); |
| 175 Polymer.dom.flush(); |
| 176 // Ensure the pairing dialog is shown. |
| 177 var pairDialog = bluetooth.$$('settings-bluetooth-pair-device-dialog'); |
| 178 assertTrue(!!pairDialog); |
| 179 // Ensure the device is connected to. |
| 180 expectEquals(1, self.bluetoothPrivateApi_.connectedDevices_.size); |
| 181 var deviceAddress = |
| 182 self.bluetoothPrivateApi_.connectedDevices_.keys().next().value; |
| 183 |
| 184 // Close the dialog. |
| 185 MockInteractions.tap(pairDialog.$.close); |
| 186 Polymer.dom.flush(); |
| 187 expectFalse(dialog.opened); |
| 188 var response = self.bluetoothPrivateApi_.pairingResponses_[deviceAddress]; |
| 189 assertTrue(!!response); |
| 190 expectEquals(chrome.bluetoothPrivate.PairingResponse.CANCEL, |
| 191 response.response); |
| 192 }); |
147 }); | 193 }); |
148 | 194 |
149 // Run all registered tests. | 195 // Run all registered tests. |
150 mocha.run(); | 196 mocha.run(); |
151 }); | 197 }); |
OLD | NEW |