Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(91)

Side by Side Diff: chrome/test/data/webui/bluetooth_internals_browsertest.js

Issue 2567983007: bluetooth: Add adapter page to internals page. (Closed)
Patch Set: Update object fieldset comment Created 3 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
58 * 58 *
59 * @constructor 59 * @constructor
60 * @extends {TestBrowserProxyBase} 60 * @extends {TestBrowserProxyBase}
61 */ 61 */
62 var TestAdapterFactoryProxy = function() { 62 var TestAdapterFactoryProxy = function() {
63 settings.TestBrowserProxy.call(this, [ 63 settings.TestBrowserProxy.call(this, [
64 'getAdapter', 64 'getAdapter',
65 ]); 65 ]);
66 66
67 this.binding = new bindings.Binding(adapter.AdapterFactory, this); 67 this.binding = new bindings.Binding(adapter.AdapterFactory, this);
68 this.adapter = new TestAdapter(); 68 this.adapter = new TestAdapterProxy();
69 this.adapterBinding_ = new bindings.Binding(adapter.Adapter, 69 this.adapterBinding_ = new bindings.Binding(adapter.Adapter,
70 this.adapter); 70 this.adapter);
71 }; 71 };
72 72
73 TestAdapterFactoryProxy.prototype = { 73 TestAdapterFactoryProxy.prototype = {
74 __proto__: settings.TestBrowserProxy.prototype, 74 __proto__: settings.TestBrowserProxy.prototype,
75 getAdapter: function() { 75 getAdapter: function() {
76 this.methodCalled('getAdapter'); 76 this.methodCalled('getAdapter');
77 77
78 // Create message pipe bound to TestAdapter. 78 // Create message pipe bound to TestAdapter.
79 return Promise.resolve({ 79 return Promise.resolve({
80 adapter: this.adapterBinding_.createInterfacePtrAndBind(), 80 adapter: this.adapterBinding_.createInterfacePtrAndBind(),
81 }); 81 });
82 } 82 }
83 }; 83 };
84 84
85 /** 85 /**
86 * A test adapter for the chrome://bluetooth-internals page.
87 * Must be used to create message pipe handle from test code.
88 *
89 * @constructor
90 */
91 var TestAdapter = function() {
92 this.proxy = new TestAdapterProxy();
93 };
94
95 TestAdapter.prototype = {
96 getInfo: function() { return this.proxy.getInfo(); },
97 getDevices: function() { return this.proxy.getDevices(); },
98 setClient: function(client) { return this.proxy.setClient(client); }
99 };
100
101 /**
102 * A test adapter proxy for the chrome://bluetooth-internals page. 86 * A test adapter proxy for the chrome://bluetooth-internals page.
103 * 87 *
104 * @constructor 88 * @constructor
105 * @extends {TestBrowserProxyBase} 89 * @extends {TestBrowserProxyBase}
106 */ 90 */
107 var TestAdapterProxy = function() { 91 var TestAdapterProxy = function() {
108 settings.TestBrowserProxy.call(this, [ 92 settings.TestBrowserProxy.call(this, [
109 'getInfo', 93 'getInfo',
110 'getDevices', 94 'getDevices',
111 'setClient', 95 'setClient',
(...skipping 27 matching lines...) Expand all
139 setTestDevices: function(devices) { 123 setTestDevices: function(devices) {
140 this.devices_ = devices; 124 this.devices_ = devices;
141 } 125 }
142 }; 126 };
143 127
144 frameInterfaces.addInterfaceOverrideForTesting( 128 frameInterfaces.addInterfaceOverrideForTesting(
145 adapter.AdapterFactory.name, function(handle) { 129 adapter.AdapterFactory.name, function(handle) {
146 this.adapterFactory = new TestAdapterFactoryProxy(); 130 this.adapterFactory = new TestAdapterFactoryProxy();
147 this.adapterFactory.binding.bind(handle); 131 this.adapterFactory.binding.bind(handle);
148 132
149 this.adapterFactory.adapter.proxy.setTestDevices([ 133 this.adapterFactory.adapter.setTestDevices([
150 this.fakeDeviceInfo1(), 134 this.fakeDeviceInfo1(),
151 this.fakeDeviceInfo2(), 135 this.fakeDeviceInfo2(),
152 ]); 136 ]);
153 this.adapterFactory.adapter.proxy.setTestAdapter( 137 this.adapterFactory.adapter.setTestAdapter(
154 this.fakeAdapterInfo()); 138 this.fakeAdapterInfo());
155 139
156 this.setupResolver.resolve(); 140 this.setupResolver.resolve();
157 }.bind(this)); 141 }.bind(this));
158 142
159 }.bind(this)); 143 }.bind(this));
160 }.bind(this); 144 }.bind(this);
161 }, 145 },
162 146
163 /** 147 /**
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
212 fakeDeviceInfo3: function() { 196 fakeDeviceInfo3: function() {
213 return { 197 return {
214 address: "CC:CC:84:96:92:84", 198 address: "CC:CC:84:96:92:84",
215 name: "CCC", 199 name: "CCC",
216 name_for_display: "CCC", 200 name_for_display: "CCC",
217 }; 201 };
218 }, 202 },
219 }; 203 };
220 204
221 TEST_F('BluetoothInternalsTest', 'Startup_BluetoothInternals', function() { 205 TEST_F('BluetoothInternalsTest', 'Startup_BluetoothInternals', function() {
206 /** @const */ var PageManager = cr.ui.pageManager.PageManager;
207
222 var adapterFactory = null; 208 var adapterFactory = null;
209 var adapterFieldSet = null;
223 var deviceTable = null; 210 var deviceTable = null;
224 var sidebarNode = null; 211 var sidebarNode = null;
225 212
213 var fakeAdapterInfo = this.fakeAdapterInfo;
226 var fakeDeviceInfo1 = this.fakeDeviceInfo1; 214 var fakeDeviceInfo1 = this.fakeDeviceInfo1;
227 var fakeDeviceInfo2 = this.fakeDeviceInfo2; 215 var fakeDeviceInfo2 = this.fakeDeviceInfo2;
228 var fakeDeviceInfo3 = this.fakeDeviceInfo3; 216 var fakeDeviceInfo3 = this.fakeDeviceInfo3;
229 217
230 // Before tests are run, make sure setup completes. 218 // Before tests are run, make sure setup completes.
231 var setupPromise = this.setupResolver.promise.then(function() { 219 var setupPromise = this.setupResolver.promise.then(function() {
232 adapterFactory = this.adapterFactory; 220 adapterFactory = this.adapterFactory;
233 }.bind(this)); 221 }.bind(this));
234 222
235 suite('BluetoothInternalsUITest', function() { 223 suite('BluetoothInternalsUITest', function() {
236 var EXPECTED_DEVICES = 2; 224 var EXPECTED_DEVICES = 2;
237 225
238 suiteSetup(function() { 226 suiteSetup(function() {
239 return setupPromise.then(function() { 227 return setupPromise.then(function() {
240 return Promise.all([ 228 return Promise.all([
241 adapterFactory.whenCalled('getAdapter'), 229 adapterFactory.whenCalled('getAdapter'),
242 adapterFactory.adapter.proxy.whenCalled('getInfo'), 230 adapterFactory.adapter.whenCalled('getInfo'),
243 adapterFactory.adapter.proxy.whenCalled('getDevices'), 231 adapterFactory.adapter.whenCalled('getDevices'),
244 adapterFactory.adapter.proxy.whenCalled('setClient'), 232 adapterFactory.adapter.whenCalled('setClient'),
245 ]); 233 ]);
246 }); 234 });
247 }); 235 });
248 236
249 setup(function() { 237 setup(function() {
238 adapterFieldSet = document.querySelector('#adapter fieldset');
250 deviceTable = document.querySelector('#devices table'); 239 deviceTable = document.querySelector('#devices table');
251 sidebarNode = document.querySelector('#sidebar'); 240 sidebarNode = document.querySelector('#sidebar');
252 devices.splice(0, devices.length); 241 devices.splice(0, devices.length);
253 adapterBroker.adapterClient_.deviceAdded(fakeDeviceInfo1()); 242 adapterBroker.adapterClient_.deviceAdded(fakeDeviceInfo1());
254 adapterBroker.adapterClient_.deviceAdded(fakeDeviceInfo2()); 243 adapterBroker.adapterClient_.deviceAdded(fakeDeviceInfo2());
255 }); 244 });
256 245
257 teardown(function() { 246 teardown(function() {
258 adapterFactory.reset(); 247 adapterFactory.reset();
259 sidebarObj.close(); 248 sidebarObj.close();
260 snackbar.Snackbar.dismiss(true); 249 snackbar.Snackbar.dismiss(true);
250 PageManager.registeredPages['adapter'].setAdapterInfo(fakeAdapterInfo());
261 }); 251 });
262 252
263 /** 253 /**
264 * Updates device info and verifies the contents of the device table. 254 * Updates device info and verifies the contents of the device table.
265 * @param {!device_collection.DeviceInfo} deviceInfo 255 * @param {!device_collection.DeviceInfo} deviceInfo
266 */ 256 */
267 function changeDevice(deviceInfo) { 257 function changeDevice(deviceInfo) {
268 var deviceRow = deviceTable.querySelector('#' + escapeDeviceAddress( 258 var deviceRow = deviceTable.querySelector('#' + escapeDeviceAddress(
269 deviceInfo.address)); 259 deviceInfo.address));
270 var nameForDisplayColumn = deviceRow.children[0]; 260 var nameForDisplayColumn = deviceRow.children[0];
(...skipping 149 matching lines...) Expand 10 before | Expand all | Expand 10 after
420 newDeviceInfo3.rssi = {value: -17}; 410 newDeviceInfo3.rssi = {value: -17};
421 adapterBroker.adapterClient_.deviceChanged(newDeviceInfo3); 411 adapterBroker.adapterClient_.deviceChanged(newDeviceInfo3);
422 expectEquals('-17', rssiColumn.textContent); 412 expectEquals('-17', rssiColumn.textContent);
423 }); 413 });
424 414
425 /* Sidebar Tests */ 415 /* Sidebar Tests */
426 test('Sidebar_Setup', function() { 416 test('Sidebar_Setup', function() {
427 var sidebarItems = Array.from( 417 var sidebarItems = Array.from(
428 sidebarNode.querySelectorAll('.sidebar-content li')); 418 sidebarNode.querySelectorAll('.sidebar-content li'));
429 419
430 ['devices'].forEach(function(pageName) { 420 ['adapter', 'devices'].forEach(function(pageName) {
431 expectTrue(sidebarItems.some(function(item) { 421 expectTrue(sidebarItems.some(function(item) {
432 return item.dataset.pageName === pageName; 422 return item.dataset.pageName === pageName;
433 })); 423 }));
434 }); 424 });
435 }); 425 });
436 426
437 test('Sidebar_DefaultState', function() { 427 test('Sidebar_DefaultState', function() {
438 // Sidebar should be closed by default. 428 // Sidebar should be closed by default.
439 expectFalse(sidebarNode.classList.contains('open')); 429 expectFalse(sidebarNode.classList.contains('open'));
440 }); 430 });
(...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after
554 whenSnackbarShows(snackbar3).then(next); 544 whenSnackbarShows(snackbar3).then(next);
555 snackbar3.addEventListener('dismissed', next); 545 snackbar3.addEventListener('dismissed', next);
556 546
557 whenSnackbarShows(snackbar1).then(function() { 547 whenSnackbarShows(snackbar1).then(function() {
558 return snackbar.Snackbar.dismiss(true); 548 return snackbar.Snackbar.dismiss(true);
559 }).then(function() { 549 }).then(function() {
560 expectEquals(0, snackbar.Snackbar.queue_.length); 550 expectEquals(0, snackbar.Snackbar.queue_.length);
561 expectFalse(!!snackbar.Snackbar.current_); 551 expectFalse(!!snackbar.Snackbar.current_);
562 }).then(finishSnackbarTest); 552 }).then(finishSnackbarTest);
563 }); 553 });
554
555 /* AdapterPage Tests */
556 function checkAdapterFieldSet(adapterInfo) {
557 for (var propName in adapterInfo) {
558 var valueCell = adapterFieldSet.querySelector(
559 '[data-field="' + propName + '"]');
560 var value = adapterInfo[propName];
561
562 if (typeof(value) === 'boolean') {
563 expectEquals(value, valueCell.classList.contains('checked'));
564 } else if (typeof(value) === 'string') {
565 expectEquals(value, valueCell.textContent);
566 } else {
567 assert('boolean or string type expected but got ' + typeof(value));
568 }
569 }
570 }
571
572 test('AdapterPage_DefaultState', function() {
573 checkAdapterFieldSet(adapterFieldSet.value);
574 });
575
576 test('AdapterPage_AdapterChanged', function() {
577 var adapterInfo = adapterFieldSet.value;
578
579 adapterInfo.present = !adapterInfo.present;
580 adapterBroker.adapterClient_.presentChanged(adapterInfo.present);
581 checkAdapterFieldSet(adapterInfo);
582
583 adapterInfo.discovering = !adapterInfo.discovering;
584 adapterBroker.adapterClient_.discoveringChanged(adapterInfo.discovering);
585 checkAdapterFieldSet(adapterInfo);
586 });
587
588 test('AdapterPage_AdapterChanged_RepeatTwice', function() {
589 var adapterInfo = adapterFieldSet.value;
590
591 adapterInfo.present = !adapterInfo.present;
592 adapterBroker.adapterClient_.presentChanged(adapterInfo.present);
593 checkAdapterFieldSet(adapterInfo);
594 adapterBroker.adapterClient_.presentChanged(adapterInfo.present);
595 checkAdapterFieldSet(adapterInfo);
596
597 adapterInfo.discovering = !adapterInfo.discovering;
598 adapterBroker.adapterClient_.discoveringChanged(adapterInfo.discovering);
599 checkAdapterFieldSet(adapterInfo);
600 adapterBroker.adapterClient_.discoveringChanged(adapterInfo.discovering);
601 checkAdapterFieldSet(adapterInfo);
602 });
564 }); 603 });
565 604
566
567 // Run all registered tests. 605 // Run all registered tests.
568 mocha.run(); 606 mocha.run();
569 }); 607 });
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698