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

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

Issue 1304353004: Test that the right events are sent to the Bluetooth chooser. (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@pinned
Patch Set: Give expected_count a default. Created 5 years, 3 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
« no previous file with comments | « LayoutTests/bluetooth/requestDevice.html ('k') | 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 '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
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 if (expected_count === undefined) {
64 expected_count = 0;
65 }
66 return new Promise((resolve, reject) => {
67 let events = [];
68 let accumulate_events = new_events => {
69 events.push(...new_events);
70 if (events.length >= expected_count) {
71 resolve(events);
72 } else {
73 testRunner.getBluetoothManualChooserEvents(accumulate_events);
74 }
75 };
76 testRunner.getBluetoothManualChooserEvents(accumulate_events);
77 });
78 }
79
60 // errorUUID(alias) returns a UUID with the top 32 bits of 80 // errorUUID(alias) returns a UUID with the top 32 bits of
61 // '00000000-97e5-4cd7-b9f1-f5a427670c59' replaced with the bits of |alias|. 81 // '00000000-97e5-4cd7-b9f1-f5a427670c59' replaced with the bits of |alias|.
62 // For example, errorUUID(0xDEADBEEF) returns 82 // For example, errorUUID(0xDEADBEEF) returns
63 // 'deadbeef-97e5-4cd7-b9f1-f5a427670c59'. The bottom 96 bits of error UUIDs 83 // 'deadbeef-97e5-4cd7-b9f1-f5a427670c59'. The bottom 96 bits of error UUIDs
64 // were generated as a type 4 (random) UUID. 84 // were generated as a type 4 (random) UUID.
65 function errorUUID(uuidAlias) { 85 function errorUUID(uuidAlias) {
66 // Make the number positive. 86 // Make the number positive.
67 uuidAlias >>>= 0; 87 uuidAlias >>>= 0;
68 // Append the alias as a hex number. 88 // Append the alias as a hex number.
69 var strAlias = '0000000' + uuidAlias.toString(16); 89 var strAlias = '0000000' + uuidAlias.toString(16);
70 // Get last 8 digits of strAlias. 90 // Get last 8 digits of strAlias.
71 strAlias = strAlias.substr(-8); 91 strAlias = strAlias.substr(-8);
72 // Append Base Error UUID 92 // Append Base Error UUID
73 return strAlias + '-97e5-4cd7-b9f1-f5a427670c59'; 93 return strAlias + '-97e5-4cd7-b9f1-f5a427670c59';
74 } 94 }
75 95
76 // Function to test that a promise rejects with the expected error type and 96 // Function to test that a promise rejects with the expected error type and
77 // message. 97 // message.
78 function assert_promise_rejects_with_message(promise, expected, description) { 98 function assert_promise_rejects_with_message(promise, expected, description) {
79 return promise.then(() => { 99 return promise.then(() => {
80 assert_unreached('Promise should have rejected: ' + description); 100 assert_unreached('Promise should have rejected: ' + description);
81 }, error => { 101 }, error => {
82 assert_equals(error.name, expected.name, 'Unexpected Error Name:'); 102 assert_equals(error.name, expected.name, 'Unexpected Error Name:');
83 if (expected.message) { 103 if (expected.message) {
84 assert_equals(error.message, expected.message, 'Unexpected Error Message:' ); 104 assert_equals(error.message, expected.message, 'Unexpected Error Message:' );
85 } 105 }
86 }); 106 });
87 } 107 }
108
109 // Parses add-device(name)=id lines in
110 // testRunner.getBluetoothManualChooserEvents() output, and exposes the name->id
111 // mapping.
112 class AddDeviceEventSet {
113 constructor() {
114 this._idsByName = new Map();
115 this._addDeviceRegex = /^add-device\(([^)]+)\)=(.+)$/;
116 }
117 assert_add_device_event(event, description) {
118 let match = this._addDeviceRegex.exec(event);
119 assert_true(!!match, event + "isn't an add-device event: " + description);
120 this._idsByName.set(match[1], match[2]);
121 }
122 has(name) {
123 return this._idsByName.has(name);
124 }
125 get(name) {
126 return this._idsByName.get(name);
127 }
128 }
OLDNEW
« no previous file with comments | « LayoutTests/bluetooth/requestDevice.html ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698