Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 'use strict'; | 1 'use strict'; |
| 2 | 2 |
| 3 // Sometimes we need to test that using either the name, alias, or UUID | 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. | 4 // produces the same result. The following objects help us do that. |
| 5 var generic_access = { | 5 var generic_access = { |
| 6 alias: 0x1800, | 6 alias: 0x1800, |
| 7 name: 'generic_access', | 7 name: 'generic_access', |
| 8 uuid: '00001800-0000-1000-8000-00805f9b34fb' | 8 uuid: '00001800-0000-1000-8000-00805f9b34fb' |
| 9 }; | 9 }; |
| 10 var device_name = { | 10 var device_name = { |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 50 eventSender.keyDown(' ', []); | 50 eventSender.keyDown(' ', []); |
| 51 }); | 51 }); |
| 52 } | 52 } |
| 53 | 53 |
| 54 // Calls requestDevice() in a context that's 'allowed to show a popup'. | 54 // Calls requestDevice() in a context that's 'allowed to show a popup'. |
| 55 function requestDeviceWithKeyDown() { | 55 function requestDeviceWithKeyDown() { |
| 56 let args = arguments; | 56 let args = arguments; |
| 57 return callWithKeyDown(() => navigator.bluetooth.requestDevice.apply(navigator .bluetooth, args)); | 57 return callWithKeyDown(() => navigator.bluetooth.requestDevice.apply(navigator .bluetooth, args)); |
| 58 } | 58 } |
| 59 | 59 |
| 60 // Calls testRunner.getBluetoothManualChooserEvents() until it's returned | |
| 61 // |expected_count| events. Or just once if |expected_count| is undefined. | |
| 62 function getBluetoothManualChooserEvents(expected_count) { | |
| 63 return new Promise((resolve, reject) => { | |
| 64 let events = []; | |
| 65 let accumulate_events = new_events => { | |
| 66 events.push(...new_events); | |
| 67 if (expected_count === undefined || events.length >= expected_count) { | |
|
ortuno
2015/09/22 19:00:02
Would it be better if the first line was:
expected
Jeffrey Yasskin
2015/09/22 20:01:34
Good idea. Done.
| |
| 68 resolve(events); | |
| 69 } else { | |
| 70 testRunner.getBluetoothManualChooserEvents(accumulate_events); | |
| 71 } | |
| 72 }; | |
| 73 testRunner.getBluetoothManualChooserEvents(accumulate_events); | |
| 74 }); | |
| 75 } | |
| 76 | |
| 60 // errorUUID(alias) returns a UUID with the top 32 bits of | 77 // errorUUID(alias) returns a UUID with the top 32 bits of |
| 61 // '00000000-97e5-4cd7-b9f1-f5a427670c59' replaced with the bits of |alias|. | 78 // '00000000-97e5-4cd7-b9f1-f5a427670c59' replaced with the bits of |alias|. |
| 62 // For example, errorUUID(0xDEADBEEF) returns | 79 // For example, errorUUID(0xDEADBEEF) returns |
| 63 // 'deadbeef-97e5-4cd7-b9f1-f5a427670c59'. The bottom 96 bits of error UUIDs | 80 // 'deadbeef-97e5-4cd7-b9f1-f5a427670c59'. The bottom 96 bits of error UUIDs |
| 64 // were generated as a type 4 (random) UUID. | 81 // were generated as a type 4 (random) UUID. |
| 65 function errorUUID(uuidAlias) { | 82 function errorUUID(uuidAlias) { |
| 66 // Make the number positive. | 83 // Make the number positive. |
| 67 uuidAlias >>>= 0; | 84 uuidAlias >>>= 0; |
| 68 // Append the alias as a hex number. | 85 // Append the alias as a hex number. |
| 69 var strAlias = '0000000' + uuidAlias.toString(16); | 86 var strAlias = '0000000' + uuidAlias.toString(16); |
| 70 // Get last 8 digits of strAlias. | 87 // Get last 8 digits of strAlias. |
| 71 strAlias = strAlias.substr(-8); | 88 strAlias = strAlias.substr(-8); |
| 72 // Append Base Error UUID | 89 // Append Base Error UUID |
| 73 return strAlias + '-97e5-4cd7-b9f1-f5a427670c59'; | 90 return strAlias + '-97e5-4cd7-b9f1-f5a427670c59'; |
| 74 } | 91 } |
| 75 | 92 |
| 76 // Function to test that a promise rejects with the expected error type and | 93 // Function to test that a promise rejects with the expected error type and |
| 77 // message. | 94 // message. |
| 78 function assert_promise_rejects_with_message(promise, expected, description) { | 95 function assert_promise_rejects_with_message(promise, expected, description) { |
| 79 return promise.then(() => { | 96 return promise.then(() => { |
| 80 assert_unreached('Promise should have rejected: ' + description); | 97 assert_unreached('Promise should have rejected: ' + description); |
| 81 }, error => { | 98 }, error => { |
| 82 assert_equals(error.name, expected.name, 'Unexpected Error Name:'); | 99 assert_equals(error.name, expected.name, 'Unexpected Error Name:'); |
| 83 if (expected.message) { | 100 if (expected.message) { |
| 84 assert_equals(error.message, expected.message, 'Unexpected Error Message:' ); | 101 assert_equals(error.message, expected.message, 'Unexpected Error Message:' ); |
| 85 } | 102 } |
| 86 }); | 103 }); |
| 87 } | 104 } |
| 105 | |
| 106 // Parses add-device(name)=id lines in | |
| 107 // testRunner.getBluetoothManualChooserEvents() output, and exposes the name->id | |
| 108 // mapping. | |
| 109 class AddDeviceEventSet { | |
| 110 constructor() { | |
| 111 this._idsByName = new Map(); | |
| 112 this._addDeviceRegex = /^add-device\(([^)]+)\)=(.+)$/; | |
| 113 } | |
| 114 assert_add_device_event(event, description) { | |
| 115 let match = this._addDeviceRegex.exec(event); | |
| 116 assert_true(!!match, event + "isn't an add-device event: " + description); | |
| 117 this._idsByName.set(match[1], match[2]); | |
| 118 } | |
| 119 has(name) { | |
| 120 return this._idsByName.has(name); | |
| 121 } | |
| 122 get(name) { | |
| 123 return this._idsByName.get(name); | |
| 124 } | |
| 125 } | |
| OLD | NEW |