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

Side by Side Diff: third_party/WebKit/LayoutTests/resources/bluetooth/bluetooth-helpers.js

Issue 2874873003: bluetooth: Implement simulateGATTConnectionResponse() (Closed)
Patch Set: fix Created 3 years, 6 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 'use strict'; 1 'use strict';
2 2
3 // HCI Error Codes. Used for simulateGATT[Dis]ConnectionResponse.
4 // For a complete list of possible error codes see
5 // BT 4.2 Vol 2 Part D 1.3 List Of Error Codes.
6 const HCI_SUCCESS = 0x0000;
7 const HCI_CONNECTION_TIMEOUT = 0x0008;
8
3 // Bluetooth UUID constants: 9 // Bluetooth UUID constants:
4 // Services: 10 // Services:
5 var blocklist_test_service_uuid = "611c954a-263b-4f4a-aab6-01ddb953f985"; 11 var blocklist_test_service_uuid = "611c954a-263b-4f4a-aab6-01ddb953f985";
6 var request_disconnection_service_uuid = "01d7d889-7451-419f-aeb8-d65e7b9277af"; 12 var request_disconnection_service_uuid = "01d7d889-7451-419f-aeb8-d65e7b9277af";
7 // Characteristics: 13 // Characteristics:
8 var blocklist_exclude_reads_characteristic_uuid = 14 var blocklist_exclude_reads_characteristic_uuid =
9 "bad1c9a2-9a5b-4015-8b60-1579bbbf2135"; 15 "bad1c9a2-9a5b-4015-8b60-1579bbbf2135";
10 var request_disconnection_characteristic_uuid = 16 var request_disconnection_characteristic_uuid =
11 "01d7d88a-7451-419f-aeb8-d65e7b9277af"; 17 "01d7d88a-7451-419f-aeb8-d65e7b9277af";
12 // Descriptors: 18 // Descriptors:
(...skipping 396 matching lines...) Expand 10 before | Expand all | Expand 10 after
409 optionalServices: ['heart_rate'] 415 optionalServices: ['heart_rate']
410 }, { 416 }, {
411 filters: [{ services: services, namePrefix: 'Pre' }], 417 filters: [{ services: services, namePrefix: 'Pre' }],
412 optionalServices: ['heart_rate'] 418 optionalServices: ['heart_rate']
413 }, { 419 }, {
414 filters: [{ services: services, name: 'Name', namePrefix: 'Pre' }], 420 filters: [{ services: services, name: 'Name', namePrefix: 'Pre' }],
415 optionalServices: ['heart_rate'] 421 optionalServices: ['heart_rate']
416 }]; 422 }];
417 } 423 }
418 424
425 // Simulates a pre-connected device with |address|, |name| and
426 // |knownServiceUUIDs|.
419 function setUpPreconnectedDevice({ 427 function setUpPreconnectedDevice({
420 address = '00:00:00:00:00:00', name = 'LE Device', knownServiceUUIDs = []}) { 428 address = '00:00:00:00:00:00', name = 'LE Device', knownServiceUUIDs = []}) {
421 return navigator.bluetooth.test.simulateCentral({state: 'powered-on'}) 429 return navigator.bluetooth.test.simulateCentral({state: 'powered-on'})
422 .then(fake_central => fake_central.simulatePreconnectedPeripheral({ 430 .then(fake_central => fake_central.simulatePreconnectedPeripheral({
423 address: address, 431 address: address,
424 name: name, 432 name: name,
425 knownServiceUUIDs: knownServiceUUIDs, 433 knownServiceUUIDs: knownServiceUUIDs,
426 })); 434 }));
427 } 435 }
428 436
437 // Returns an array containing two FakePeripherals corresponding
438 // to the simulated devices.
429 function setUpHealthThermometerAndHeartRateDevices() { 439 function setUpHealthThermometerAndHeartRateDevices() {
430 return navigator.bluetooth.test.simulateCentral({state: 'powered-on'}) 440 return navigator.bluetooth.test.simulateCentral({state: 'powered-on'})
431 .then(fake_central => Promise.all([ 441 .then(fake_central => Promise.all([
432 fake_central.simulatePreconnectedPeripheral({ 442 fake_central.simulatePreconnectedPeripheral({
433 address: '09:09:09:09:09:09', 443 address: '09:09:09:09:09:09',
434 name: 'Health Thermometer', 444 name: 'Health Thermometer',
435 knownServiceUUIDs: ['generic_access', 'health_thermometer'], 445 knownServiceUUIDs: ['generic_access', 'health_thermometer'],
436 }), 446 }),
437 fake_central.simulatePreconnectedPeripheral({ 447 fake_central.simulatePreconnectedPeripheral({
438 address: '08:08:08:08:08:08', 448 address: '08:08:08:08:08:08',
439 name: 'Heart Rate', 449 name: 'Heart Rate',
440 knownServiceUUIDs: ['generic_access', 'heart_rate'], 450 knownServiceUUIDs: ['generic_access', 'heart_rate'],
441 })])); 451 })]));
442 } 452 }
453
454 // Returns a BluetoothDevice discovered using |options| and its
455 // corresponding FakePeripheral.
456 // The simulated device is called 'Health Thermometer' it has two known service
457 // UUIDs: 'generic_access' and 'health_thermometer'. The device has been
458 // connected to and its services have been discovered.
459 // TODO(crbug.com/719816): Add services, characteristics and descriptors,
460 // and discover all the attributes.
461 function getHealthThermometerDevice(options) {
462 return getDiscoveredHealthThermometerDevice(options)
463 .then(([device, fake_peripheral]) => {
464 return fake_peripheral.setNextGATTConnectionResponse({code: HCI_SUCCESS})
465 .then(() => device.gatt.connect())
466 .then(gatt => [gatt.device, fake_peripheral]);
467 });
468 }
469
470 // Similar to getHealthThermometerDevice() except the device
471 // is not connected and thus its services have not been
472 // discovered.
473 function getDiscoveredHealthThermometerDevice(
474 options = {filters: [{services: ['health_thermometer']}]}) {
475 return setUpPreconnectedDevice({
476 address: '09:09:09:09:09:09',
477 name: 'Health Thermometer',
478 knownServiceUUIDs: ['generic_access', 'health_thermometer'],
479 })
480 .then(fake_peripheral => {
481 return requestDeviceWithKeyDown(options)
482 .then(device => [device, fake_peripheral]);
483 });
484 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698