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

Unified 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « LayoutTests/bluetooth/requestDevice.html ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: LayoutTests/bluetooth/resources/bluetooth-helpers.js
diff --git a/LayoutTests/bluetooth/resources/bluetooth-helpers.js b/LayoutTests/bluetooth/resources/bluetooth-helpers.js
index 064880493c829a79d49516cd89c63e9b8beff53e..af4654d4c0362ffed62de3c4d7e9d3b70792c096 100644
--- a/LayoutTests/bluetooth/resources/bluetooth-helpers.js
+++ b/LayoutTests/bluetooth/resources/bluetooth-helpers.js
@@ -57,6 +57,26 @@ function requestDeviceWithKeyDown() {
return callWithKeyDown(() => navigator.bluetooth.requestDevice.apply(navigator.bluetooth, args));
}
+// Calls testRunner.getBluetoothManualChooserEvents() until it's returned
+// |expected_count| events. Or just once if |expected_count| is undefined.
+function getBluetoothManualChooserEvents(expected_count) {
+ if (expected_count === undefined) {
+ expected_count = 0;
+ }
+ return new Promise((resolve, reject) => {
+ let events = [];
+ let accumulate_events = new_events => {
+ events.push(...new_events);
+ if (events.length >= expected_count) {
+ resolve(events);
+ } else {
+ testRunner.getBluetoothManualChooserEvents(accumulate_events);
+ }
+ };
+ testRunner.getBluetoothManualChooserEvents(accumulate_events);
+ });
+}
+
// errorUUID(alias) returns a UUID with the top 32 bits of
// '00000000-97e5-4cd7-b9f1-f5a427670c59' replaced with the bits of |alias|.
// For example, errorUUID(0xDEADBEEF) returns
@@ -85,3 +105,24 @@ function assert_promise_rejects_with_message(promise, expected, description) {
}
});
}
+
+// Parses add-device(name)=id lines in
+// testRunner.getBluetoothManualChooserEvents() output, and exposes the name->id
+// mapping.
+class AddDeviceEventSet {
+ constructor() {
+ this._idsByName = new Map();
+ this._addDeviceRegex = /^add-device\(([^)]+)\)=(.+)$/;
+ }
+ assert_add_device_event(event, description) {
+ let match = this._addDeviceRegex.exec(event);
+ assert_true(!!match, event + "isn't an add-device event: " + description);
+ this._idsByName.set(match[1], match[2]);
+ }
+ has(name) {
+ return this._idsByName.has(name);
+ }
+ get(name) {
+ return this._idsByName.get(name);
+ }
+}
« 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