3 // Sometimes we need to test that using either the name, alias, or UUID
4 // produces the same result. The following objects help us do that.
7 name: 'generic_access',
8 uuid: '00001800-0000-1000-8000-00805f9b34fb'
12 name: 'gap.device_name',
13 uuid: '00002a00-0000-1000-8000-00805f9b34fb'
15 var reconnection_address = {
17 name: 'gap.reconnection_address',
18 uuid: '00002a03-0000-1000-8000-00805f9b34fb'
23 uuid: '0000180d-0000-1000-8000-00805f9b34fb'
28 uuid: '00001808-0000-1000-8000-00805f9b34fb'
30 var battery_service = {
32 name: 'battery_service',
33 uuid: '0000180f-0000-1000-8000-00805f9b34fb'
37 name: 'battery_level',
38 uuid: '00002a19-0000-1000-8000-00805f9b34fb'
41 // TODO(jyasskin): Upstream this to testharness.js: https://crbug.com/509058.
42 function callWithKeyDown(functionCalledOnKeyPress) {
43 return new Promise(resolve => {
44 function onKeyPress() {
45 document.removeEventListener('keypress', onKeyPress, false);
46 resolve(functionCalledOnKeyPress());
48 document.addEventListener('keypress', onKeyPress, false);
50 eventSender.keyDown(' ', []);
54 // Calls requestDevice() in a context that's 'allowed to show a popup'.
55 function requestDeviceWithKeyDown() {
57 return callWithKeyDown(() => navigator.bluetooth.requestDevice.apply(navigator.bluetooth, args));
60 // errorUUID(alias) returns a UUID with the top 32 bits of
61 // '00000000-97e5-4cd7-b9f1-f5a427670c59' replaced with the bits of |alias|.
62 // For example, errorUUID(0xDEADBEEF) returns
63 // 'deadbeef-97e5-4cd7-b9f1-f5a427670c59'. The bottom 96 bits of error UUIDs
64 // were generated as a type 4 (random) UUID.
65 function errorUUID(uuidAlias) {
66 // Make the number positive.
68 // Append the alias as a hex number.
69 var strAlias = '0000000' + uuidAlias.toString(16);
70 // Get last 8 digits of strAlias.
71 strAlias = strAlias.substr(-8);
72 // Append Base Error UUID
73 return strAlias + '-97e5-4cd7-b9f1-f5a427670c59';
76 // Function to test that a promise rejects with the expected error type and
78 function assert_promise_rejects_with_message(promise, expected, description) {
79 return promise.then(() => {
80 assert_unreached('Promise should have rejected: ' + description);
82 assert_equals(error.name, expected.name, 'Unexpected Error Name:');
83 if (expected.message) {
84 assert_equals(error.message, expected.message, 'Unexpected Error Message:');