Commit 2313d949 authored by Ovidio Henriquez's avatar Ovidio Henriquez Committed by Commit Bot

bluetooth: web: test: Update request device test

This change updates the optional-services-present.html test to not use
setBluetoothFakeAdapter. This will help us migrate the tests to the wpt/
directory, since testRunner is not used anymore.

This change also updates the files in
https://chromium-review.googlesource.com/c/chromium/src/+/769346
to resolve the comments that were made after the CL was submitted.
To address the comments, assert_equals is used in
request-from-iframe.html instead of assert_unreached, and
callWithTrustedClick is placed before the onmessage listener.

BUG=509038

Change-Id: I95b846790f7f5b69cf3c76d16638b4d130d77bf8
Reviewed-on: https://chromium-review.googlesource.com/779700Reviewed-by: default avatarVincent Scheib <scheib@chromium.org>
Reviewed-by: default avatarConley Owens <cco3@chromium.org>
Commit-Queue: Ovidio Henriquez <odejesush@google.com>
Cr-Commit-Position: refs/heads/master@{#519875}
parent 482d7ad4
......@@ -6,20 +6,22 @@
<script src="../../../resources/bluetooth/bluetooth-helpers.js"></script>
<script>
'use strict';
bluetooth_test(() => {
return setBluetoothFakeAdapter('TwoHeartRateServicesAdapter')
.then(() => requestDeviceWithTrustedClick({
acceptAllDevices: true,
optionalServices: ['heart_rate']
}))
.then(device => device.gatt.connect())
.then(gattServer => gattServer.getPrimaryServices())
.then(services => {
assert_equals(services.length, 2);
services.forEach(service => {
assert_equals(service.uuid, BluetoothUUID.getService('heart_rate'));
});
})
}, 'requestDevice called with acceptAllDevices: true and with ' +
'optionalServices. Should get access to services.');
const test_desc = 'requestDevice called with acceptAllDevices: true and with ' +
'optionalServices. Should get access to services.';
bluetooth_test(() =>
getTwoHealthThermometerServicesDevice()
.then(() => requestDeviceWithTrustedClick({
acceptAllDevices: true,
optionalServices: ['health_thermometer']
}))
.then(device => device.gatt.connect())
.then(gattServer => gattServer.getPrimaryServices())
.then(services => {
assert_equals(services.length, 2);
services.forEach(service => {
assert_equals(service.uuid,
BluetoothUUID.getService('health_thermometer'));
});
}), test_desc);
</script>
......@@ -28,11 +28,7 @@ bluetooth_test(() => setUpHealthThermometerAndHeartRateDevices()
.then(() => new Promise(async (resolve) => {
let numMessages = 0;
window.onmessage = messageEvent => {
if (messageEvent.data !== 'Success') {
assert_unreached('Bad message, expected "Success": ' +
messageEvent.data);
}
assert_equals(messageEvent.data, 'Success');
if (++numMessages === iframes.length) {
resolve();
}
......
......@@ -22,15 +22,15 @@ bluetooth_test(() => getHealthThermometerDevice()
}))
// 2. Request the device from the iframe.
.then(() => new Promise(resolve => {
callWithTrustedClick(() => {
iframe.contentWindow.postMessage('Go', '*');
});
window.onmessage = messageEvent => {
assert_equals(messageEvent.data, 'SecurityError: requestDevice() ' +
'called from cross-origin iframe.');
resolve();
}
callWithTrustedClick(() => {
iframe.contentWindow.postMessage('Go', '*');
});
})), test_desc);
</script>
</body>
......@@ -22,15 +22,15 @@ async_test(test =>
}))
// 2. Request the device from the iframe.
.then(() => {
callWithTrustedClick(() => {
iframe.contentWindow.postMessage('Go', '*');
});
window.onmessage = messageEvent => test.step(() => {
assert_equals(messageEvent.data, 'SecurityError: requestDevice() ' +
'called from cross-origin iframe.');
test.done();
});
callWithTrustedClick(() => {
iframe.contentWindow.postMessage('Go', '*');
});
}), test_desc);
</script>
</body>
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