Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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 /** | 5 /** |
| 6 * @fileoverview Tests for chrome://bluetooth-internals | 6 * @fileoverview Tests for chrome://bluetooth-internals |
| 7 */ | 7 */ |
| 8 | 8 |
| 9 /** @const {string} Path to source root. */ | 9 /** @const {string} Path to source root. */ |
| 10 var ROOT_PATH = '../../../../'; | 10 var ROOT_PATH = '../../../../'; |
| (...skipping 209 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 220 address: "CC:CC:84:96:92:84", | 220 address: "CC:CC:84:96:92:84", |
| 221 name: "CCC", | 221 name: "CCC", |
| 222 name_for_display: "CCC", | 222 name_for_display: "CCC", |
| 223 }; | 223 }; |
| 224 }, | 224 }, |
| 225 }; | 225 }; |
| 226 | 226 |
| 227 TEST_F('BluetoothInternalsTest', 'Startup_BluetoothInternals', function() { | 227 TEST_F('BluetoothInternalsTest', 'Startup_BluetoothInternals', function() { |
| 228 var adapterFactory = null; | 228 var adapterFactory = null; |
| 229 var deviceTable = null; | 229 var deviceTable = null; |
| 230 var sidebarNode = null; | |
| 230 | 231 |
| 231 var fakeDeviceInfo1 = this.fakeDeviceInfo1; | 232 var fakeDeviceInfo1 = this.fakeDeviceInfo1; |
| 232 var fakeDeviceInfo2 = this.fakeDeviceInfo2; | 233 var fakeDeviceInfo2 = this.fakeDeviceInfo2; |
| 233 var fakeDeviceInfo3 = this.fakeDeviceInfo3; | 234 var fakeDeviceInfo3 = this.fakeDeviceInfo3; |
| 234 | 235 |
| 235 // Before tests are run, make sure setup completes. | 236 // Before tests are run, make sure setup completes. |
| 236 var setupPromise = this.setupResolver.promise.then(function() { | 237 var setupPromise = this.setupResolver.promise.then(function() { |
| 237 adapterFactory = this.adapterFactory; | 238 adapterFactory = this.adapterFactory; |
| 238 }.bind(this)); | 239 }.bind(this)); |
| 239 | 240 |
| 240 | |
| 241 suite('BluetoothInternalsUITest', function() { | 241 suite('BluetoothInternalsUITest', function() { |
| 242 var EXPECTED_DEVICES = 2; | 242 var EXPECTED_DEVICES = 2; |
| 243 | 243 |
| 244 suiteSetup(function() { | 244 suiteSetup(function() { |
| 245 return setupPromise.then(function() { | 245 return setupPromise.then(function() { |
| 246 return Promise.all([ | 246 return Promise.all([ |
| 247 adapterFactory.whenCalled('getAdapter'), | 247 adapterFactory.whenCalled('getAdapter'), |
| 248 adapterFactory.adapter.proxy.whenCalled('getInfo'), | 248 adapterFactory.adapter.proxy.whenCalled('getInfo'), |
| 249 adapterFactory.adapter.proxy.whenCalled('getDevices'), | 249 adapterFactory.adapter.proxy.whenCalled('getDevices'), |
| 250 adapterFactory.adapter.proxy.whenCalled('setClient'), | 250 adapterFactory.adapter.proxy.whenCalled('setClient'), |
| 251 ]); | 251 ]); |
| 252 }); | 252 }); |
| 253 }); | 253 }); |
| 254 | 254 |
| 255 setup(function() { | 255 setup(function() { |
| 256 deviceTable = document.querySelector('#devices table'); | 256 deviceTable = document.querySelector('#devices table'); |
| 257 sidebarNode = document.querySelector('#sidebar'); | |
| 257 devices.splice(0, devices.length); | 258 devices.splice(0, devices.length); |
| 258 adapterBroker.adapterClient_.deviceAdded(fakeDeviceInfo1()); | 259 adapterBroker.adapterClient_.deviceAdded(fakeDeviceInfo1()); |
| 259 adapterBroker.adapterClient_.deviceAdded(fakeDeviceInfo2()); | 260 adapterBroker.adapterClient_.deviceAdded(fakeDeviceInfo2()); |
| 260 }); | 261 }); |
| 261 | 262 |
| 262 teardown(function() { | 263 teardown(function() { |
| 263 adapterFactory.reset(); | 264 adapterFactory.reset(); |
| 265 sidebarObj.close(); | |
| 264 }); | 266 }); |
| 265 | 267 |
| 266 /** | 268 /** |
| 267 * Updates device info and verifies the contents of the device table. | 269 * Updates device info and verifies the contents of the device table. |
| 268 * @param {!device_collection.DeviceInfo} deviceInfo | 270 * @param {!device_collection.DeviceInfo} deviceInfo |
| 269 */ | 271 */ |
| 270 function changeDevice(deviceInfo) { | 272 function changeDevice(deviceInfo) { |
| 271 var deviceRow = deviceTable.querySelector('#' + escapeDeviceAddress( | 273 var deviceRow = deviceTable.querySelector('#' + escapeDeviceAddress( |
| 272 deviceInfo.address)); | 274 deviceInfo.address)); |
| 273 var nameForDisplayColumn = deviceRow.children[0]; | 275 var nameForDisplayColumn = deviceRow.children[0]; |
| (...skipping 143 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 417 var newDeviceInfo2 = fakeDeviceInfo3(); | 419 var newDeviceInfo2 = fakeDeviceInfo3(); |
| 418 newDeviceInfo2.rssi = null; | 420 newDeviceInfo2.rssi = null; |
| 419 adapterBroker.adapterClient_.deviceChanged(newDeviceInfo2); | 421 adapterBroker.adapterClient_.deviceChanged(newDeviceInfo2); |
| 420 expectEquals('-42', rssiColumn.textContent); | 422 expectEquals('-42', rssiColumn.textContent); |
| 421 | 423 |
| 422 var newDeviceInfo3 = fakeDeviceInfo3(); | 424 var newDeviceInfo3 = fakeDeviceInfo3(); |
| 423 newDeviceInfo3.rssi = {value: -17}; | 425 newDeviceInfo3.rssi = {value: -17}; |
| 424 adapterBroker.adapterClient_.deviceChanged(newDeviceInfo3); | 426 adapterBroker.adapterClient_.deviceChanged(newDeviceInfo3); |
| 425 expectEquals('-17', rssiColumn.textContent); | 427 expectEquals('-17', rssiColumn.textContent); |
| 426 }); | 428 }); |
| 429 | |
| 430 /* Sidebar Tests */ | |
| 431 test('Sidebar_Setup', function() { | |
| 432 var sidebarItems = Array.from( | |
| 433 sidebarNode.querySelectorAll('.sidebar-content li')); | |
| 434 | |
| 435 ['devices'].forEach(function(pageName) { | |
| 436 var foundItem = sidebarItems.find(function(item) { | |
|
dpapad
2016/12/14 00:32:05
Nit: You can use Array#some here, as follows
expe
mbrunson
2016/12/14 02:34:35
Done.
| |
| 437 return item.dataset.pageName === pageName; | |
| 438 }); | |
| 439 | |
| 440 expectTrue(!!foundItem); | |
| 441 }); | |
| 442 }); | |
| 443 | |
| 444 test('Sidebar_DefaultState', function() { | |
| 445 // Sidebar should be closed by default. | |
| 446 expectFalse(sidebarNode.classList.contains('open')); | |
| 447 }); | |
| 448 | |
| 449 test('Sidebar_OpenClose', function() { | |
| 450 sidebarObj.open(); | |
| 451 expectTrue(sidebarNode.classList.contains('open')); | |
| 452 sidebarObj.close(); | |
| 453 expectFalse(sidebarNode.classList.contains('open')); | |
| 454 }); | |
| 455 | |
| 456 test('Sidebar_OpenTwice', function() { | |
| 457 // Multiple calls to open shouldn't change the state. | |
| 458 sidebarObj.open(); | |
| 459 sidebarObj.open(); | |
| 460 expectTrue(sidebarNode.classList.contains('open')); | |
| 461 }); | |
| 462 | |
| 463 test('Sidebar_CloseTwice', function() { | |
| 464 // Multiple calls to close shouldn't change the state. | |
| 465 sidebarObj.close(); | |
| 466 sidebarObj.close(); | |
| 467 expectFalse(sidebarNode.classList.contains('open')); | |
| 468 }); | |
| 427 }); | 469 }); |
| 428 | 470 |
| 429 // Run all registered tests. | 471 // Run all registered tests. |
| 430 mocha.run(); | 472 mocha.run(); |
| 431 }); | 473 }); |
| OLD | NEW |