| OLD | NEW |
| (Empty) | |
| 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 |
| 3 // found in the LICENSE file. |
| 4 |
| 5 suite('Bluetooth', function() { |
| 6 var bluetoothPage = null; |
| 7 |
| 8 /** @type {Bluetooth} */ |
| 9 var bluetoothApi_; |
| 10 |
| 11 /** @type {BluetoothPrivate} */ |
| 12 var bluetoothPrivateApi_; |
| 13 |
| 14 /** @type {!Array<!chrome.bluetooth.Device>} */ var fakeDevices_ = [ |
| 15 { |
| 16 address: '10:00:00:00:00:01', |
| 17 name: 'FakePairedDevice1', |
| 18 paired: true, |
| 19 connected: true, |
| 20 }, |
| 21 { |
| 22 address: '10:00:00:00:00:02', |
| 23 name: 'FakePairedDevice2', |
| 24 paired: true, |
| 25 connected: false, |
| 26 connecting: true, |
| 27 }, |
| 28 { |
| 29 address: '00:00:00:00:00:01', |
| 30 name: 'FakeUnPairedDevice1', |
| 31 paired: false, |
| 32 }, |
| 33 { |
| 34 address: '00:00:00:00:00:02', |
| 35 name: 'FakeUnPairedDevice2', |
| 36 paired: false, |
| 37 }, |
| 38 ]; |
| 39 |
| 40 suiteSetup(function() { |
| 41 window.loadTimeData = new LoadTimeData; |
| 42 loadTimeData.data = { |
| 43 bluetoothEnabled: 'bluetoothEnabled', |
| 44 bluetoothDisabled: 'bluetoothDisabled', |
| 45 bluetoothOn: 'bluetoothOn', |
| 46 bluetoothOff: 'bluetoothOff', |
| 47 bluetoothConnected: 'bluetoothConnected', |
| 48 bluetoothDisconnect: 'bluetoothDisconnect', |
| 49 bluetoothPair: 'bluetoothPair', |
| 50 bluetoothStartConnecting: 'bluetoothStartConnecting', |
| 51 |
| 52 }; |
| 53 |
| 54 bluetoothApi_ = new settings.FakeBluetooth(); |
| 55 bluetoothPrivateApi_ = new settings.FakeBluetoothPrivate(bluetoothApi_); |
| 56 |
| 57 // Set globals to override Settings Bluetooth Page apis. |
| 58 bluetoothApis.bluetoothApiForTest = bluetoothApi_; |
| 59 bluetoothApis.bluetoothPrivateApiForTest = bluetoothPrivateApi_; |
| 60 |
| 61 // Disable animations so sub-pages open within one event loop. |
| 62 testing.Test.disableAnimationsAndTransitions(); |
| 63 }); |
| 64 |
| 65 setup(function() { |
| 66 PolymerTest.clearBody(); |
| 67 bluetoothPage = document.createElement('settings-bluetooth-page'); |
| 68 assertTrue(!!bluetoothPage); |
| 69 |
| 70 document.body.appendChild(bluetoothPage); |
| 71 Polymer.dom.flush(); |
| 72 }); |
| 73 |
| 74 teardown(function() { |
| 75 bluetoothPage.remove(); |
| 76 }); |
| 77 |
| 78 test('MainPage', function() { |
| 79 assertFalse(bluetoothApi_.adapterState.powered); |
| 80 assertFalse(bluetoothPage.bluetoothEnabled_); |
| 81 // Test that tapping the single settings-box div enables bluetooth. |
| 82 var div = bluetoothPage.$$('div.settings-box'); |
| 83 assertTrue(!!div); |
| 84 MockInteractions.tap(div); |
| 85 assertTrue(bluetoothPage.bluetoothEnabled_); |
| 86 assertTrue(bluetoothApi_.adapterState.powered); |
| 87 }); |
| 88 |
| 89 suite('SubPage', function() { |
| 90 var subpage; |
| 91 |
| 92 setup(function() { |
| 93 bluetoothPage.bluetoothEnabled_ = true; |
| 94 var div = bluetoothPage.$$('div.settings-box'); |
| 95 MockInteractions.tap(div); |
| 96 subpage = bluetoothPage.$$('settings-bluetooth-subpage'); |
| 97 assertTrue(!!subpage); |
| 98 }); |
| 99 |
| 100 test('toggle', function() { |
| 101 assertTrue(subpage.bluetoothEnabled); |
| 102 |
| 103 var enableButton = subpage.$.enableBluetooth; |
| 104 assertTrue(!!enableButton); |
| 105 assertTrue(enableButton.checked); |
| 106 |
| 107 subpage.bluetoothEnabled = false; |
| 108 assertFalse(enableButton.checked); |
| 109 assertFalse(bluetoothApi_.adapterState.powered);; |
| 110 assertFalse(bluetoothPage.bluetoothEnabled_); |
| 111 }); |
| 112 |
| 113 test('device list', function() { |
| 114 var deviceList = subpage.$.container; |
| 115 assertTrue(!!deviceList); |
| 116 assertTrue(deviceList.hidden); |
| 117 assertFalse(subpage.$.noDevices.hidden); |
| 118 |
| 119 bluetoothApi_.setDevicesForTest(fakeDevices_); |
| 120 Polymer.dom.flush(); |
| 121 assertEquals(4, subpage.deviceList_.length); |
| 122 assertTrue(subpage.$.noDevices.hidden); |
| 123 |
| 124 var devicesIronList = subpage.$$('#container > iron-list'); |
| 125 assertTrue(!!devicesIronList); |
| 126 devicesIronList.notifyResize(); |
| 127 Polymer.dom.flush(); |
| 128 var devices = deviceList.querySelectorAll('bluetooth-device-list-item'); |
| 129 assertEquals(2, devices.length); |
| 130 assertTrue(devices[0].device.connected); |
| 131 assertFalse(devices[1].device.connected); |
| 132 assertTrue(devices[1].device.connecting); |
| 133 }); |
| 134 |
| 135 test('device dialog', function() { |
| 136 // Tap the 'add device' button. |
| 137 MockInteractions.tap(subpage.$.pairButton); |
| 138 Polymer.dom.flush(); |
| 139 |
| 140 // Ensure the dialog appears. |
| 141 var dialog = subpage.$.deviceDialog; |
| 142 assertTrue(!!dialog); |
| 143 assertTrue(dialog.$.dialog.open); |
| 144 assertEquals(dialog.deviceList.length, 4); |
| 145 |
| 146 // Ensure the dialog has the expected devices. |
| 147 var devicesIronList = dialog.$$('#dialogDeviceList iron-list'); |
| 148 assertTrue(!!devicesIronList); |
| 149 devicesIronList.notifyResize(); |
| 150 Polymer.dom.flush(); |
| 151 var devices = |
| 152 devicesIronList.querySelectorAll('bluetooth-device-list-item'); |
| 153 assertEquals(devices.length, 2); |
| 154 |
| 155 // Select a device. |
| 156 MockInteractions.tap(devices[0].$$('div')); |
| 157 Polymer.dom.flush(); |
| 158 // Ensure the pairing dialog is shown. |
| 159 assertTrue(!!dialog.$$('#pairing')); |
| 160 |
| 161 // Ensure the device wass connected to. |
| 162 expectEquals(1, bluetoothPrivateApi_.connectedDevices_.size); |
| 163 |
| 164 // Close the dialog. |
| 165 dialog.close(); |
| 166 Polymer.dom.flush(); |
| 167 assertFalse(dialog.$.dialog.open); |
| 168 }); |
| 169 }); |
| 170 }); |
| OLD | NEW |