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

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

Issue 2532383005: bluetooth: Fix BluetoothInternalsTest timeout issue (Closed)
Patch Set: Change test structure Created 4 years 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
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 104 matching lines...) Expand 10 before | Expand all | Expand 10 after
115 115
116 this.adapterInfo_ = null; 116 this.adapterInfo_ = null;
117 this.devices_ = []; 117 this.devices_ = [];
118 }; 118 };
119 119
120 TestAdapterProxy.prototype = { 120 TestAdapterProxy.prototype = {
121 __proto__: settings.TestBrowserProxy.prototype, 121 __proto__: settings.TestBrowserProxy.prototype,
122 122
123 getInfo: function() { 123 getInfo: function() {
124 this.methodCalled('getInfo'); 124 this.methodCalled('getInfo');
125 return Promise.resolve({info: this.adapterInfo_}); 125 return Promise.resolve({info: this.adapterInfo_});
ortuno 2016/12/08 05:37:31 nit: tabbing.
mbrunson 2016/12/08 19:31:08 Done.
126 }, 126 },
127 127
128 getDevices: function() { 128 getDevices: function() {
129 this.methodCalled('getDevices'); 129 this.methodCalled('getDevices');
130 return Promise.resolve({devices: this.devices_}); 130 return Promise.resolve({devices: this.devices_});
ortuno 2016/12/08 05:37:31 nit: tabbing.
mbrunson 2016/12/08 19:31:08 Done.
131 }, 131 },
132 132
133 setClient: function(client) { 133 setClient: function(client) {
134 this.methodCalled('setClient', client); 134 this.methodCalled('setClient', client);
135 }, 135 },
136 136
137 setTestAdapter: function(adapterInfo) { 137 setTestAdapter: function(adapterInfo) {
138 this.adapterInfo_ = adapterInfo; 138 this.adapterInfo_ = adapterInfo;
139 }, 139 },
140 140
141 setTestDevices: function(devices) { 141 setTestDevices: function(devices) {
142 this.devices_ = devices; 142 this.devices_ = devices;
143 } 143 }
144 }; 144 };
145 145
146 frameInterfaces.addInterfaceOverrideForTesting( 146 frameInterfaces.addInterfaceOverrideForTesting(
147 adapter.AdapterFactory.name, 147 adapter.AdapterFactory.name,
148 function(handle) { 148 function(handle) {
149 var stub = connection.bindHandleToStub( 149 var stub = connection.bindHandleToStub(
150 handle, adapter.AdapterFactory); 150 handle, adapter.AdapterFactory);
151
151 this.adapterFactory = new TestAdapterFactoryProxy(); 152 this.adapterFactory = new TestAdapterFactoryProxy();
153
154 this.adapterFactory.adapter.proxy.setTestDevices([
155 this.fakeDeviceInfo1(),
156 this.fakeDeviceInfo2(),
157 ]);
158 this.adapterFactory.adapter.proxy.setTestAdapter(
159 this.fakeAdapterInfo());
160
152 bindings.StubBindings(stub).delegate = this.adapterFactory; 161 bindings.StubBindings(stub).delegate = this.adapterFactory;
153 162
154 this.setupResolver.resolve(); 163 this.setupResolver.resolve();
155 }.bind(this)); 164 }.bind(this));
165
156 }.bind(this)); 166 }.bind(this));
157 }.bind(this); 167 }.bind(this);
158 }, 168 },
169
170 /**
171 * Returns a copy of fake adapter info object.
172 * @return {!Object}
173 */
174 fakeAdapterInfo: function() {
175 return {
176 address: '02:1C:7E:6A:11:5A',
177 discoverable: false,
178 discovering: false,
179 initialized: true,
180 name: 'computer.example.com-0',
181 powered: true,
182 present: true,
183 };
184 },
185
186 /**
187 * Returns a copy of a fake device info object (variant 1).
188 * @return {!Object}
189 */
190 fakeDeviceInfo1: function() {
191 return {
192 address: "AA:AA:84:96:92:84",
193 name: "AAA",
194 name_for_display: "AAA",
195 rssi: {value: -40},
196 services: [],
197 };
198 },
199
200 /**
201 * Returns a copy of a fake device info object (variant 2).
202 * @return {!Object}
203 */
204 fakeDeviceInfo2: function() {
205 return {
206 address: "BB:BB:84:96:92:84",
207 name: "BBB",
208 name_for_display: "BBB",
209 rssi: null,
210 services: [],
211 };
212 },
213
214 /**
215 * Returns a copy of fake device info object. The returned device info lack
216 * rssi and services properties.
217 * @return {!Object}
218 */
219 fakeDeviceInfo3: function() {
220 return {
221 address: "CC:CC:84:96:92:84",
222 name: "CCC",
223 name_for_display: "CCC",
224 };
225 },
159 }; 226 };
160 227
161 // Times out. See https://crbug.com/667970. 228 TEST_F('BluetoothInternalsTest', 'Startup_BluetoothInternals', function() {
162 TEST_F('BluetoothInternalsTest', 'DISABLED_Startup_BluetoothInternals', 229 var adapterFactory = null;
163 function() { 230 var deviceTable = null;
164 var fakeAdapterInfo = {
165 address: '02:1C:7E:6A:11:5A',
166 discoverable: false,
167 discovering: false,
168 initialized: true,
169 name: 'computer.example.com-0',
170 powered: true,
171 present: true,
172 };
173 231
174 var fakeDeviceInfo1 = { 232 var fakeDeviceInfo1 = this.fakeDeviceInfo1;
175 address: "AA:AA:84:96:92:84", 233 var fakeDeviceInfo2 = this.fakeDeviceInfo2;
176 name: "AAA", 234 var fakeDeviceInfo3 = this.fakeDeviceInfo3;
177 name_for_display: "AAA",
178 rssi: {value: -40},
179 services: []
180 };
181
182 var fakeDeviceInfo2 = {
183 address: "BB:BB:84:96:92:84",
184 name: "BBB",
185 name_for_display: "BBB",
186 rssi: null,
187 services: []
188 };
189
190 var fakeDeviceInfo3 = {
191 address: "CC:CC:84:96:92:84",
192 name: "CCC",
193 name_for_display: "CCC",
194 };
195
196 var adapterFactory = null;
197 235
198 // Before tests are run, make sure setup completes. 236 // Before tests are run, make sure setup completes.
199 var setupPromise = this.setupResolver.promise.then(function() { 237 var setupPromise = this.setupResolver.promise.then(function() {
200 adapterFactory = this.adapterFactory; 238 adapterFactory = this.adapterFactory;
201 }.bind(this)); 239 }.bind(this));
202 240
203 241
204 suite('BluetoothInternalsUITest', function() { 242 suite('BluetoothInternalsUITest', function() {
205 var EXPECTED_DEVICES = 2; 243 var EXPECTED_DEVICES = 2;
206 244
207 suiteSetup(function() { 245 suiteSetup(function() {
208 return setupPromise.then(function() { 246 return setupPromise.then(function() {
209 adapterFactory.adapter.proxy.setTestDevices([
210 fakeDeviceInfo1,
211 fakeDeviceInfo2
212 ]);
213 adapterFactory.adapter.proxy.setTestAdapter(fakeAdapterInfo);
214
215 return Promise.all([ 247 return Promise.all([
216 adapterFactory.whenCalled('getAdapter'), 248 adapterFactory.whenCalled('getAdapter'),
217 adapterFactory.adapter.proxy.whenCalled('getInfo'), 249 adapterFactory.adapter.proxy.whenCalled('getInfo'),
218 adapterFactory.adapter.proxy.whenCalled('getDevices'), 250 adapterFactory.adapter.proxy.whenCalled('getDevices'),
219 adapterFactory.adapter.proxy.whenCalled('setClient'), 251 adapterFactory.adapter.proxy.whenCalled('setClient'),
220 ]); 252 ]);
221 }); 253 });
222 }); 254 });
223 255
224 setup(function() { 256 setup(function() {
257 deviceTable = document.querySelector('#devices table');
225 devices.splice(0, devices.length); 258 devices.splice(0, devices.length);
226 adapterBroker.adapterClient_.deviceAdded(fakeDeviceInfo1); 259 adapterBroker.adapterClient_.deviceAdded(fakeDeviceInfo1());
227 adapterBroker.adapterClient_.deviceAdded(fakeDeviceInfo2); 260 adapterBroker.adapterClient_.deviceAdded(fakeDeviceInfo2());
228 }); 261 });
229 262
230 teardown(function() { 263 teardown(function() {
231 adapterFactory.reset(); 264 adapterFactory.reset();
232 }); 265 });
233 266
234 /** 267 /**
235 * Updates device info and verifies the contents of the device table. 268 * Updates device info and verifies the contents of the device table.
236 * @param {!device_collection.DeviceInfo} deviceInfo 269 * @param {!device_collection.DeviceInfo} deviceInfo
237 */ 270 */
238 function changeDevice(deviceInfo) { 271 function changeDevice(deviceInfo) {
239 var deviceRow = document.querySelector('#' + escapeDeviceAddress( 272 var deviceRow = deviceTable.querySelector('#' + escapeDeviceAddress(
240 deviceInfo.address)); 273 deviceInfo.address));
241 var nameForDisplayColumn = deviceRow.children[0]; 274 var nameForDisplayColumn = deviceRow.children[0];
242 var addressColumn = deviceRow.children[1]; 275 var addressColumn = deviceRow.children[1];
243 var rssiColumn = deviceRow.children[2]; 276 var rssiColumn = deviceRow.children[2];
244 var servicesColumn = deviceRow.children[3]; 277 var servicesColumn = deviceRow.children[3];
245 278
246 expectTrue(!!nameForDisplayColumn); 279 expectTrue(!!nameForDisplayColumn);
247 expectTrue(!!addressColumn); 280 expectTrue(!!addressColumn);
248 expectTrue(!!rssiColumn); 281 expectTrue(!!rssiColumn);
249 expectTrue(!!servicesColumn); 282 expectTrue(!!servicesColumn);
(...skipping 23 matching lines...) Expand all
273 function escapeDeviceAddress(address) { 306 function escapeDeviceAddress(address) {
274 return address.replace(/:/g, '\\:'); 307 return address.replace(/:/g, '\\:');
275 } 308 }
276 309
277 /** 310 /**
278 * Expects whether device with |address| is removed. 311 * Expects whether device with |address| is removed.
279 * @param {string} address 312 * @param {string} address
280 * @param {boolean} expectRemoved 313 * @param {boolean} expectRemoved
281 */ 314 */
282 function expectDeviceRemoved(address, expectRemoved) { 315 function expectDeviceRemoved(address, expectRemoved) {
283 var removedRow = document.querySelector( 316 var removedRow = deviceTable.querySelector(
284 '#' + escapeDeviceAddress(address)); 317 '#' + escapeDeviceAddress(address));
285 318
286 expectEquals(expectRemoved, removedRow.classList.contains('removed')); 319 expectEquals(expectRemoved, removedRow.classList.contains('removed'));
287 } 320 }
288 321
289 /** 322 /**
290 * Tests whether a device is added successfully and not duplicated. 323 * Tests whether a device is added successfully and not duplicated.
291 */ 324 */
292 test('DeviceAdded', function() { 325 test('DeviceAdded', function() {
293 var devices = document.querySelectorAll('#device-table tbody tr'); 326 var devices = deviceTable.querySelectorAll('tbody tr');
294 expectEquals(EXPECTED_DEVICES, devices.length); 327 expectEquals(EXPECTED_DEVICES, devices.length);
295 328
296 // Copy device info because device collection will not copy this object. 329 // Copy device info because device collection will not copy this object.
297 var infoCopy = Object.assign({}, fakeDeviceInfo3); 330 var infoCopy = fakeDeviceInfo3();
298 adapterBroker.adapterClient_.deviceAdded(infoCopy); 331 adapterBroker.adapterClient_.deviceAdded(infoCopy);
299 332
300 // Same device shouldn't appear twice. 333 // Same device shouldn't appear twice.
301 adapterBroker.adapterClient_.deviceAdded(infoCopy); 334 adapterBroker.adapterClient_.deviceAdded(infoCopy);
302 335
303 devices = document.querySelectorAll('#device-table tbody tr'); 336 devices = deviceTable.querySelectorAll('tbody tr');
304 expectEquals(EXPECTED_DEVICES + 1, devices.length); 337 expectEquals(EXPECTED_DEVICES + 1, devices.length);
305 }); 338 });
306 339
307 /** 340 /**
308 * Tests whether a device is marked properly as removed. 341 * Tests whether a device is marked properly as removed.
309 */ 342 */
310 test('DeviceSetToRemoved', function() { 343 test('DeviceSetToRemoved', function() {
311 var devices = document.querySelectorAll('#device-table tbody tr'); 344 var devices = deviceTable.querySelectorAll('tbody tr');
312 expectEquals(EXPECTED_DEVICES, devices.length); 345 expectEquals(EXPECTED_DEVICES, devices.length);
313 adapterBroker.adapterClient_.deviceRemoved(fakeDeviceInfo2); 346
347 var fakeDevice = fakeDeviceInfo2();
348 adapterBroker.adapterClient_.deviceRemoved(fakeDevice);
314 349
315 // The number of rows shouldn't change. 350 // The number of rows shouldn't change.
316 devices = document.querySelectorAll('#device-table tbody tr'); 351 devices = deviceTable.querySelectorAll('tbody tr');
317 expectEquals(EXPECTED_DEVICES, devices.length); 352 expectEquals(EXPECTED_DEVICES, devices.length);
318 353
319 expectDeviceRemoved(fakeDeviceInfo2.address, true); 354 expectDeviceRemoved(fakeDevice.address, true);
320 }); 355 });
321 356
322 /** 357 /**
323 * Tests whether a changed device updates the device table properly. 358 * Tests whether a changed device updates the device table properly.
324 */ 359 */
325 test('DeviceChanged', function() { 360 test('DeviceChanged', function() {
326 var devices = document.querySelectorAll('#device-table tbody tr'); 361 var devices = deviceTable.querySelectorAll('tbody tr');
327 expectEquals(EXPECTED_DEVICES, devices.length); 362 expectEquals(EXPECTED_DEVICES, devices.length);
328 363
329 // Copy device info because device collection will not copy this object. 364 // Copy device info because device collection will not copy this object.
330 var newDeviceInfo = Object.assign({}, fakeDeviceInfo1); 365 var newDeviceInfo = fakeDeviceInfo1();
331 newDeviceInfo.name_for_display = 'DDDD'; 366 newDeviceInfo.name_for_display = 'DDDD';
332 newDeviceInfo.rssi = { value: -20 }; 367 newDeviceInfo.rssi = { value: -20 };
333 newDeviceInfo.services = ['service1', 'service2', 'service3']; 368 newDeviceInfo.services = ['service1', 'service2', 'service3'];
334 369
335 changeDevice(newDeviceInfo); 370 changeDevice(newDeviceInfo);
336 }); 371 });
337 372
338 /** 373 /**
339 * Tests the entire device cycle, added -> updated -> removed -> re-added. 374 * Tests the entire device cycle, added -> updated -> removed -> re-added.
340 */ 375 */
341 test('DeviceUpdateCycle', function() { 376 test('DeviceUpdateCycle', function() {
342 var devices = document.querySelectorAll('#device-table tbody tr'); 377 var devices = deviceTable.querySelectorAll('tbody tr');
343 expectEquals(EXPECTED_DEVICES, devices.length); 378 expectEquals(EXPECTED_DEVICES, devices.length);
344 379
345 // Copy device info because device collection will not copy this object. 380 // Copy device info because device collection will not copy this object.
346 var originalDeviceInfo = Object.assign({}, fakeDeviceInfo3); 381 var originalDeviceInfo = fakeDeviceInfo3();
347 adapterBroker.adapterClient_.deviceAdded(originalDeviceInfo); 382 adapterBroker.adapterClient_.deviceAdded(originalDeviceInfo);
348 383
349 var newDeviceInfo = Object.assign({}, fakeDeviceInfo3); 384 var newDeviceInfo = fakeDeviceInfo3();
350 newDeviceInfo.name_for_display = 'DDDD'; 385 newDeviceInfo.name_for_display = 'DDDD';
351 newDeviceInfo.rssi = { value: -20 }; 386 newDeviceInfo.rssi = { value: -20 };
352 newDeviceInfo.services = ['service1', 'service2', 'service3']; 387 newDeviceInfo.services = ['service1', 'service2', 'service3'];
353 388
354 changeDevice(newDeviceInfo); 389 changeDevice(newDeviceInfo);
355 changeDevice(originalDeviceInfo); 390 changeDevice(originalDeviceInfo);
356 391
357 adapterBroker.adapterClient_.deviceRemoved(originalDeviceInfo); 392 adapterBroker.adapterClient_.deviceRemoved(originalDeviceInfo);
358 expectDeviceRemoved(originalDeviceInfo.address, true); 393 expectDeviceRemoved(originalDeviceInfo.address, true);
359 394
360 adapterBroker.adapterClient_.deviceAdded(originalDeviceInfo); 395 adapterBroker.adapterClient_.deviceAdded(originalDeviceInfo);
361 expectDeviceRemoved(originalDeviceInfo.address, false); 396 expectDeviceRemoved(originalDeviceInfo.address, false);
362 }); 397 });
363 398
364 test('DeviceAddedRssiCheck', function() { 399 test('DeviceAddedRssiCheck', function() {
365 var devices = document.querySelectorAll('#device-table tbody tr'); 400 var devices = deviceTable.querySelectorAll('tbody tr');
366 expectEquals(EXPECTED_DEVICES, devices.length); 401 expectEquals(EXPECTED_DEVICES, devices.length);
367 402
368 // Copy device info because device collection will not copy this object. 403 // Copy device info because device collection will not copy this object.
369 var newDeviceInfo = Object.assign({}, fakeDeviceInfo3); 404 var newDeviceInfo = fakeDeviceInfo3();
370 adapterBroker.adapterClient_.deviceAdded(newDeviceInfo); 405 adapterBroker.adapterClient_.deviceAdded(newDeviceInfo);
371 406
372 var deviceRow = document.querySelector('#' + escapeDeviceAddress( 407 var deviceRow = deviceTable.querySelector('#' + escapeDeviceAddress(
373 newDeviceInfo.address)); 408 newDeviceInfo.address));
374 var rssiColumn = deviceRow.children[2]; 409 var rssiColumn = deviceRow.children[2];
375 expectEquals('Unknown', rssiColumn.textContent); 410 expectEquals('Unknown', rssiColumn.textContent);
376 411
377 var newDeviceInfo1 = Object.assign({}, fakeDeviceInfo3); 412 var newDeviceInfo1 = fakeDeviceInfo3();
378 newDeviceInfo1.rssi = {value: -42}; 413 newDeviceInfo1.rssi = {value: -42};
379 adapterBroker.adapterClient_.deviceChanged(newDeviceInfo1); 414 adapterBroker.adapterClient_.deviceChanged(newDeviceInfo1);
380 expectEquals('-42', rssiColumn.textContent); 415 expectEquals('-42', rssiColumn.textContent);
381 416
382 // Device table should keep last valid rssi value. 417 // Device table should keep last valid rssi value.
383 var newDeviceInfo2 = Object.assign({}, fakeDeviceInfo3); 418 var newDeviceInfo2 = fakeDeviceInfo3();
384 newDeviceInfo2.rssi = null; 419 newDeviceInfo2.rssi = null;
385 adapterBroker.adapterClient_.deviceChanged(newDeviceInfo2); 420 adapterBroker.adapterClient_.deviceChanged(newDeviceInfo2);
386 expectEquals('-42', rssiColumn.textContent); 421 expectEquals('-42', rssiColumn.textContent);
387 422
388 var newDeviceInfo3 = Object.assign({}, fakeDeviceInfo3); 423 var newDeviceInfo3 = fakeDeviceInfo3();
389 newDeviceInfo3.rssi = {value: -17}; 424 newDeviceInfo3.rssi = {value: -17};
390 adapterBroker.adapterClient_.deviceChanged(newDeviceInfo3); 425 adapterBroker.adapterClient_.deviceChanged(newDeviceInfo3);
391 expectEquals('-17', rssiColumn.textContent); 426 expectEquals('-17', rssiColumn.textContent);
392 }); 427 });
393 }); 428 });
394 429
395 // Run all registered tests. 430 // Run all registered tests.
396 mocha.run(); 431 mocha.run();
397 }); 432 });
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698