Commit 268b8fbd authored by Robert Ma's avatar Robert Ma Committed by Commit Bot

[WPT] Use assert_implements better in webusb, webxr

With https://github.com/web-platform-tests/rfcs/pull/28, we can now use
assert_* freely in any (including the first) test function without
worrying about turning the test into a single-page test accidentally.
This CL takes advantage of that and makes better use of
assert_implements to convey failure messages.

Change-Id: I328fdbb31195b02e3f97e16cc9f1f1cacbe03f7c
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2359163
Commit-Queue: Robert Ma <robertma@chromium.org>
Auto-Submit: Robert Ma <robertma@chromium.org>
Reviewed-by: default avatarAlexander Cooper <alcooper@chromium.org>
Cr-Commit-Position: refs/heads/master@{#799080}
parent b34efcf1
...@@ -33,15 +33,15 @@ async function loadChromiumResources() { ...@@ -33,15 +33,15 @@ async function loadChromiumResources() {
function usb_test(func, name, properties) { function usb_test(func, name, properties) {
promise_test(async () => { promise_test(async () => {
assert_implements(navigator.usb, 'missing navigator.usb');
if (navigator.usb.test === undefined) { if (navigator.usb.test === undefined) {
// Try loading a polyfill for the WebUSB Testing API. // Try loading a polyfill for the WebUSB Testing API.
if (isChromiumBased) { if (isChromiumBased) {
await loadChromiumResources(); await loadChromiumResources();
await loadScript('/resources/chromium/webusb-test.js'); await loadScript('/resources/chromium/webusb-test.js');
} else {
assert_implements(false, "missing navigator.usb.test");
} }
} }
assert_implements(navigator.usb.test, 'missing navigator.usb.test after initialization');
await navigator.usb.test.initialize(); await navigator.usb.test.initialize();
try { try {
......
...@@ -18,6 +18,8 @@ function xr_promise_test(name, func, properties) { ...@@ -18,6 +18,8 @@ function xr_promise_test(name, func, properties) {
// Perform any required test setup: // Perform any required test setup:
xr_debug(name, 'setup'); xr_debug(name, 'setup');
assert_implements(navigator.xr, 'missing navigator.xr');
// Only set up once. // Only set up once.
if (!navigator.xr.test) { if (!navigator.xr.test) {
// Load test-only API helpers. // Load test-only API helpers.
...@@ -37,8 +39,6 @@ function xr_promise_test(name, func, properties) { ...@@ -37,8 +39,6 @@ function xr_promise_test(name, func, properties) {
} else if (isWebKitBased) { } else if (isWebKitBased) {
// WebKit setup // WebKit setup
await setupWebKitWebXRTestAPI(); await setupWebKitWebXRTestAPI();
} else {
assert_implements(false, "missing navigator.xr.test");
} }
} }
...@@ -47,11 +47,7 @@ function xr_promise_test(name, func, properties) { ...@@ -47,11 +47,7 @@ function xr_promise_test(name, func, properties) {
// setup properly. Either way, the fact that xr_promise_test is being used // setup properly. Either way, the fact that xr_promise_test is being used
// means that the tests expect navigator.xr.test to be set. By rejecting now // means that the tests expect navigator.xr.test to be set. By rejecting now
// we can hopefully provide a clearer indication of what went wrong. // we can hopefully provide a clearer indication of what went wrong.
if (!navigator.xr.test) { assert_implements(navigator.xr.test, 'missing navigator.xr.test, even after attempted load');
// We can't use assert_true here because it causes the wpt testharness
// to treat this as a test page and not as a test.
return Promise.reject("No navigator.xr.test object found, even after attempted load");
}
// Ensure that any devices are disconnected when done. If this were done in // Ensure that any devices are disconnected when done. If this were done in
// a .then() for the success case, a test that expected failure would // a .then() for the success case, a test that expected failure would
......
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