Commit 0879154d authored by jyasskin@chromium.org's avatar jyasskin@chromium.org

Add errors for various chooser failure modes, and remove assertions that are about to change.

NoBluetoothChooser
ChosenDeviceVanished
ChooserCancelled

1st of 3 patches:
1. This patch.
2. Wire up the chooser on the Chrome side. (https://codereview.chromium.org/1286063002/)
3. Update the test assertions and remove now-unused errors. (https://codereview.chromium.org/1284143006/)

BUG=500989

Review URL: https://codereview.chromium.org/1293593003

git-svn-id: svn://svn.chromium.org/blink/trunk@201175 bbb929c8-8fbe-4397-9dbb-9b2b20218538
parent 01804bf1
......@@ -21,11 +21,14 @@ 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');
return assert_promise_rejects_with_message(
requestDeviceWithKeyDown({filters: [{services: ['generic_access']}]}),
{name: 'NotFoundError', message: 'Couldn\'t start discovery session.'},
// TODO(jyasskin): Uncomment the message when it's changed on the Chrome side.
{name: 'NotFoundError', /*message: 'User cancelled the requestDevice() chooser.'*/},
'The adapter failed to start a discovery session.');
}, 'Discovery session fails to start.');
......@@ -37,19 +40,25 @@ 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');
return assert_promise_rejects_with_message(
requestDeviceWithKeyDown({filters: [{services: ['generic_access']}]}),
{name: 'NotFoundError', message: 'Bluetooth adapter is off.'},
// TODO(jyasskin): Uncomment the message when it's changed on the Chrome side.
{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(
requestDeviceWithKeyDown({filters: [{services: ['generic_access']}]}),
{name: 'NotFoundError', message: 'No Bluetooth devices in range.'},
// TODO(jyasskin): Uncomment the message when it's changed on the Chrome side.
{name: 'NotFoundError', /*message: 'User cancelled the requestDevice() chooser.'*/},
'No Bluetooth devices in range.');
}, 'Reject with NotFoundError if there are no devices around.');
......
......@@ -80,6 +80,8 @@ function assert_promise_rejects_with_message(promise, expected, description) {
assert_unreached('Promise should have rejected: ' + description);
}, error => {
assert_equals(error.name, expected.name, 'Unexpected Error Name:');
assert_equals(error.message, expected.message, 'Unexpected Error Message:');
if (expected.message) {
assert_equals(error.message, expected.message, 'Unexpected Error Message:');
}
});
}
......@@ -41,8 +41,11 @@ DOMException* BluetoothError::take(ScriptPromiseResolver*, const WebBluetoothErr
// NotFoundErrors:
MAP_ERROR(BluetoothAdapterOff, NotFoundError, "Bluetooth adapter is off.");
MAP_ERROR(NoBluetoothAdapter, NotFoundError, "Bluetooth adapter not available.");
MAP_ERROR(NoBluetoothChooser, NotFoundError, "Can't show Bluetooth chooser dialog.");
MAP_ERROR(DiscoverySessionStartFailed, NotFoundError, "Couldn't start discovery session.");
MAP_ERROR(DiscoverySessionStopFailed, NotFoundError, "Failed to stop discovery session.");
MAP_ERROR(ChosenDeviceVanished, NotFoundError, "User selected a device that doesn't exist anymore.");
MAP_ERROR(ChooserCancelled, NotFoundError, "User cancelled the requestDevice() chooser.");
MAP_ERROR(NoDevicesFound, NotFoundError, "No Bluetooth devices in range.");
MAP_ERROR(ServiceNotFound, NotFoundError, "Service not found in device.");
MAP_ERROR(CharacteristicNotFound, NotFoundError, "Characteristic not found in device.");
......
......@@ -36,9 +36,12 @@ enum class WebBluetoothError {
// NotFoundError:
BluetoothAdapterOff,
NoBluetoothAdapter,
NoBluetoothChooser,
DiscoverySessionStartFailed,
DiscoverySessionStopFailed,
NoDevicesFound,
ChosenDeviceVanished,
ChooserCancelled,
ServiceNotFound,
CharacteristicNotFound,
// NotSupportedError:
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment