Index: LayoutTests/bluetooth/requestDevice.html |
diff --git a/LayoutTests/bluetooth/requestDevice.html b/LayoutTests/bluetooth/requestDevice.html |
index 834bc70756f228076fc087c42c09e290d99cef8e..f2e62d4f3bd450cbfd0bc4aa9610ff3ad5eddfc9 100644 |
--- a/LayoutTests/bluetooth/requestDevice.html |
+++ b/LayoutTests/bluetooth/requestDevice.html |
@@ -21,12 +21,18 @@ promise_test(() => { |
new TypeError()); |
}, 'RequestDeviceOptions requires a |filters| member.'); |
-// TODO(jyasskin): Add a test that the chooser is informed of a failed discovery |
-// session. |
promise_test(() => { |
testRunner.setBluetoothMockDataSet('FailStartDiscoveryAdapter'); |
+ testRunner.setBluetoothManualChooser(); |
+ var requestDevicePromise = |
+ requestDeviceWithKeyDown({filters: [{services: ['generic_access']}]}); |
+ assert_array_equals(testRunner.getBluetoothManualChooserEvents(), |
+ ['RunBluetoothChooser(file:///)', |
+ 'ShowDiscoveryState(DISCOVERING)', |
+ 'ShowDiscoveryState(FAILED_TO_START)']); |
+ testRunner.sendBluetoothManualChooserEvent('cancelled', ''); |
return assert_promise_rejects_with_message( |
- requestDeviceWithKeyDown({filters: [{services: ['generic_access']}]}), |
+ requestDevicePromise, |
{name: 'NotFoundError', message: 'User cancelled the requestDevice() chooser.'}, |
'The adapter failed to start a discovery session.'); |
}, 'Discovery session fails to start.'); |
@@ -39,18 +45,21 @@ promise_test(() => { |
'Bluetooth adapter is not present.'); |
}, 'Reject with NotFoundError if the adapter is not present.'); |
-// TODO(jyasskin): Add a test that the chooser is informed of a disabled |
-// Bluetooth adapter. |
promise_test(() => { |
testRunner.setBluetoothMockDataSet('NotPoweredAdapter'); |
+ testRunner.setBluetoothManualChooser(); |
+ var requestDevicePromise = |
+ requestDeviceWithKeyDown({filters: [{services: ['generic_access']}]}); |
+ assert_array_equals(testRunner.getBluetoothManualChooserEvents(), |
+ ['RunBluetoothChooser(file:///)', |
+ 'SetAdapterPresence(POWERED_OFF)']); |
+ testRunner.sendBluetoothManualChooserEvent('cancelled', ''); |
return assert_promise_rejects_with_message( |
- requestDeviceWithKeyDown({filters: [{services: ['generic_access']}]}), |
+ requestDevicePromise, |
{name: 'NotFoundError', message: 'User cancelled the requestDevice() chooser.'}, |
'Bluetooth adapter is not powered.'); |
}, 'Reject with NotFoundError if the adapter is off.'); |
-// TODO(jyasskin): Add a test that the chooser gets a full list of found |
-// devices. |
promise_test(() => { |
testRunner.setBluetoothMockDataSet('EmptyAdapter'); |
return assert_promise_rejects_with_message( |
@@ -123,6 +132,30 @@ promise_test(() => { |
promise_test(() => { |
testRunner.setBluetoothMockDataSet('GlucoseHeartRateAdapter'); |
+ testRunner.setBluetoothManualChooser(); |
+ var requestDevicePromise = requestDeviceWithKeyDown({ |
+ filters: [{services: ['glucose']}, |
+ {services: ['heart_rate']}] |
+ }); |
+ var deadline = Date.now() + 500; |
+ var events = testRunner.getBluetoothManualChooserEvents(); |
+ while (events.length < 5 && Date.now() < deadline) { |
+ Array.prototype.push.apply(events, testRunner.getBluetoothManualChooserEvents()); |
+ } |
+ assert_array_equals(events, |
+ ['RunBluetoothChooser(file:///)', |
+ 'AddDevice(00:00:00:00:00:03, Heart Rate Device)', |
+ 'AddDevice(00:00:00:00:00:02, Glucose Device)', |
+ 'ShowDiscoveryState(DISCOVERING)', |
+ 'ShowDiscoveryState(IDLE)', |
+ ]); |
+ testRunner.sendBluetoothManualChooserEvent('selected', '00:00:00:00:00:02'); |
+ return requestDevicePromise |
+ .then(device => assert_equals(device.name, 'Glucose Device')); |
+}, 'The chooser includes all devices.'); |
+ |
+promise_test(() => { |
+ testRunner.setBluetoothMockDataSet('GlucoseHeartRateAdapter'); |
return requestDeviceWithKeyDown({filters: [{services: ['glucose']}]}) |
.then(device => assert_equals(device.name, 'Glucose Device')); |
}, 'Simple filter selects matching device.'); |