| OLD | NEW |
| (Empty) |
| 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 | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 /** @fileoverview Suite of tests for settings-bluetooth-page. */ | |
| 6 | |
| 7 GEN_INCLUDE(['settings_page_browsertest.js']); | |
| 8 | |
| 9 var bluetoothPage = bluetoothPage || {}; | |
| 10 | |
| 11 /** | |
| 12 * @constructor | |
| 13 * @extends {SettingsPageBrowserTest} | |
| 14 */ | |
| 15 function SettingsBluetoothPageBrowserTest() { | |
| 16 } | |
| 17 | |
| 18 SettingsBluetoothPageBrowserTest.prototype = { | |
| 19 __proto__: SettingsPageBrowserTest.prototype, | |
| 20 | |
| 21 /** @override */ | |
| 22 extraLibraries: PolymerTest.getLibraries(ROOT_PATH).concat([ | |
| 23 '../fake_chrome_event.js', | |
| 24 'fake_bluetooth.js', | |
| 25 'fake_bluetooth_private.js' | |
| 26 ]), | |
| 27 | |
| 28 /** @type {Bluetooth} */ | |
| 29 bluetoothApi_: undefined, | |
| 30 | |
| 31 /** @type {BluetoothPrivate} */ | |
| 32 bluetoothPrivateApi_: undefined, | |
| 33 | |
| 34 /** @override */ | |
| 35 preLoad: function() { | |
| 36 SettingsPageBrowserTest.prototype.preLoad.call(this); | |
| 37 settingsHidePagesByDefaultForTest = true; | |
| 38 this.bluetoothApi_ = new settings.FakeBluetooth(); | |
| 39 this.bluetoothPrivateApi_ = | |
| 40 new settings.FakeBluetoothPrivate(this.bluetoothApi_); | |
| 41 // Set globals to override Settings Bluetooth Page apis. | |
| 42 bluetoothPage.bluetoothApiForTest = this.bluetoothApi_; | |
| 43 bluetoothPage.bluetoothPrivateApiForTest = this.bluetoothPrivateApi_; | |
| 44 } | |
| 45 }; | |
| 46 | |
| 47 // Times out on debug builders and may time out on memory bots because | |
| 48 // the Settings page can take several seconds to load in a Release build | |
| 49 // and several times that in a Debug build. See https://crbug.com/558434. | |
| 50 GEN('#if defined(MEMORY_SANITIZER) || !defined(NDEBUG)'); | |
| 51 GEN('#define MAYBE_Bluetooth DISABLED_Bluetooth'); | |
| 52 GEN('#else'); | |
| 53 GEN('#define MAYBE_Bluetooth Bluetooth'); | |
| 54 GEN('#endif'); | |
| 55 | |
| 56 // Runs bluetooth tests. | |
| 57 TEST_F('SettingsBluetoothPageBrowserTest', 'MAYBE_Bluetooth', function() { | |
| 58 // Differentiate |this| in the Test from |this| in suite() and test(), see | |
| 59 // comment at the top of mocha_adapter.js. | |
| 60 var self = this; | |
| 61 | |
| 62 self.toggleAdvanced(); | |
| 63 var page = self.getPage('basic'); | |
| 64 assertTrue(!!page); | |
| 65 page.set('pageVisibility.bluetooth', true); | |
| 66 Polymer.dom.flush(); | |
| 67 | |
| 68 /** @type {!Array<!chrome.bluetooth.Device>} */ var fakeDevices_ = [ | |
| 69 { | |
| 70 address: '10:00:00:00:00:01', | |
| 71 name: 'FakePairedDevice1', | |
| 72 paired: true, | |
| 73 connected: true, | |
| 74 }, | |
| 75 { | |
| 76 address: '10:00:00:00:00:02', | |
| 77 name: 'FakePairedDevice2', | |
| 78 paired: true, | |
| 79 connected: false, | |
| 80 connecting: true, | |
| 81 }, | |
| 82 { | |
| 83 address: '00:00:00:00:00:01', | |
| 84 name: 'FakeUnPairedDevice1', | |
| 85 paired: false, | |
| 86 }, | |
| 87 { | |
| 88 address: '00:00:00:00:00:02', | |
| 89 name: 'FakeUnPairedDevice2', | |
| 90 paired: false, | |
| 91 }, | |
| 92 ]; | |
| 93 | |
| 94 suite('SettingsBluetoothPage', function() { | |
| 95 test('enable', function() { | |
| 96 assertFalse(self.bluetoothApi_.adapterState.powered); | |
| 97 var bluetoothSection = self.getSection(page, 'bluetooth'); | |
| 98 assertTrue(!!bluetoothSection); | |
| 99 var bluetooth = | |
| 100 bluetoothSection.querySelector('settings-bluetooth-page'); | |
| 101 assertTrue(!!bluetooth); | |
| 102 expectFalse(bluetooth.bluetoothEnabled_); | |
| 103 var enable = bluetooth.$.enableBluetooth; | |
| 104 assertTrue(!!enable); | |
| 105 expectFalse(enable.checked); | |
| 106 // Test that tapping the enable checkbox changes its value and calls | |
| 107 // bluetooth.setAdapterState with powered = false. | |
| 108 MockInteractions.tap(enable); | |
| 109 Polymer.dom.flush(); | |
| 110 expectTrue(enable.checked); | |
| 111 expectTrue(self.bluetoothApi_.adapterState.powered); | |
| 112 // Confirm that 'bluetoothEnabled' remains set to true. | |
| 113 expectTrue(bluetooth.bluetoothEnabled_); | |
| 114 // Set 'bluetoothEnabled' directly and confirm that the checkbox | |
| 115 // toggles. | |
| 116 bluetooth.bluetoothEnabled_ = false; | |
| 117 Polymer.dom.flush(); | |
| 118 expectFalse(enable.checked); | |
| 119 }); | |
| 120 | |
| 121 test('device list', function() { | |
| 122 var bluetoothSection = self.getSection(page, 'bluetooth'); | |
| 123 var bluetooth = | |
| 124 bluetoothSection.querySelector('settings-bluetooth-page'); | |
| 125 assertTrue(!!bluetooth); | |
| 126 var deviceList = bluetooth.$.deviceList; | |
| 127 assertTrue(!!deviceList); | |
| 128 // Set enabled, with default (empty) device list. | |
| 129 self.bluetoothApi_.setEnabled(true); | |
| 130 Polymer.dom.flush(); | |
| 131 // Ensure that initially the 'no devices' element is visible. | |
| 132 expectFalse(deviceList.hidden); | |
| 133 var noDevices = deviceList.querySelector('.no-devices'); | |
| 134 assertTrue(!!noDevices); | |
| 135 expectFalse(noDevices.hidden); | |
| 136 // Set some devices (triggers onDeviceAdded events). 'no devices' element | |
| 137 // should be hidden. | |
| 138 self.bluetoothApi_.setDevicesForTest(fakeDevices_); | |
| 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(); | |
| 145 expectTrue(noDevices.hidden); | |
| 146 // Confirm that there are two paired devices in the list. | |
| 147 var devices = deviceList.querySelectorAll('bluetooth-device-list-item'); | |
| 148 assertEquals(2, devices.length); | |
| 149 // Check the state of each device. | |
| 150 assertTrue(devices[0].device.connected); | |
| 151 assertFalse(devices[1].device.connected); | |
| 152 assertTrue(devices[1].device.connecting); | |
| 153 }); | |
| 154 | |
| 155 test('device dialog', function() { | |
| 156 var bluetoothSection = self.getSection(page, 'bluetooth'); | |
| 157 var bluetooth = | |
| 158 bluetoothSection.querySelector('settings-bluetooth-page'); | |
| 159 assertTrue(!!bluetooth); | |
| 160 self.bluetoothApi_.setEnabled(true); | |
| 161 | |
| 162 // Tap the 'add device' button. | |
| 163 MockInteractions.tap(bluetooth.$$('.primary-button')); | |
| 164 Polymer.dom.flush(); | |
| 165 // Ensure the dialog appears. | |
| 166 var dialog = bluetooth.$$('#deviceDialog'); | |
| 167 assertTrue(!!dialog); | |
| 168 assertTrue(dialog.$.dialog.open); | |
| 169 assertEquals(dialog.deviceList.length, 4); | |
| 170 | |
| 171 // Ensure the dialog has the expected devices. | |
| 172 var devicesIronList = dialog.$$('#dialogDeviceList iron-list'); | |
| 173 assertTrue(!!devicesIronList); | |
| 174 devicesIronList.notifyResize(); | |
| 175 Polymer.dom.flush(); | |
| 176 var devices = | |
| 177 devicesIronList.querySelectorAll('bluetooth-device-list-item'); | |
| 178 assertEquals(devices.length, 2); | |
| 179 | |
| 180 // Select a device. | |
| 181 MockInteractions.tap(devices[0].$$('div')); | |
| 182 Polymer.dom.flush(); | |
| 183 // Ensure the pairing dialog is shown. | |
| 184 assertTrue(!!dialog.$$('#pairing')); | |
| 185 | |
| 186 // Ensure the device wass connected to. | |
| 187 expectEquals(1, self.bluetoothPrivateApi_.connectedDevices_.size); | |
| 188 | |
| 189 // Close the dialog. | |
| 190 dialog.close(); | |
| 191 Polymer.dom.flush(); | |
| 192 assertFalse(dialog.$.dialog.open); | |
| 193 }); | |
| 194 }); | |
| 195 | |
| 196 // Run all registered tests. | |
| 197 mocha.run(); | |
| 198 }); | |
| OLD | NEW |