Commit 5599375e authored by Robert Ma's avatar Robert Ma Committed by Commit Bot

[WPT] Only load *.mojom.js through loadMojoResources

* Load other resources separately
* Throw from loadMojoResources when a path is not /gen/.../*.mojom.js

Bug: 1116600
Change-Id: I4f9dbc4459583480ce202e65c789397422a282fe
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2358904Reviewed-by: default avatarReilly Grant <reillyg@chromium.org>
Commit-Queue: Robert Ma <robertma@chromium.org>
Cr-Commit-Position: refs/heads/master@{#798922}
parent 41badf1e
......@@ -29,6 +29,13 @@ function loadScript(path) {
* @returns {Promise<void>} Resolves when Chromium specific setup is complete.
*/
async function performChromiumSetup() {
const chromiumResources = [
'/gen/content/test/data/mojo_web_test_helper_test.mojom.js',
'/gen/device/bluetooth/public/mojom/uuid.mojom.js',
'/gen/url/mojom/origin.mojom.js',
'/gen/device/bluetooth/public/mojom/test/fake_bluetooth.mojom.js',
'/gen/content/shell/common/web_test/fake_bluetooth_chooser.mojom.js',
];
// Determine path prefixes.
let resPrefix = '/resources';
let extra = ['/resources/chromium/web-bluetooth-test.js'];
......@@ -47,13 +54,10 @@ async function performChromiumSetup() {
return;
}
await loadMojoResources([
'/gen/content/test/data/mojo_web_test_helper_test.mojom.js',
'/gen/device/bluetooth/public/mojom/uuid.mojom.js',
'/gen/url/mojom/origin.mojom.js',
'/gen/device/bluetooth/public/mojom/test/fake_bluetooth.mojom.js',
'/gen/content/shell/common/web_test/fake_bluetooth_chooser.mojom.js',
].concat(extra));
await loadMojoResources(chromiumResources);
for (const path of extra) {
await loadScript(path);
}
// Call setBluetoothFakeAdapter() to clean up any fake adapters left over by
// legacy tests. Legacy tests that use setBluetoothFakeAdapter() sometimes
......
......@@ -48,8 +48,7 @@ function loadScript(path) {
*
* @param {Array.<string>} resources - A list of scripts to load: Mojo JS
* bindings should be of the form '/gen/../*.mojom.js', the ordering of which
* does not matter. Do not include mojo_bindings.js in this list. You may
* include other non-mojom.js scripts for convenience.
* does not matter. Do not include mojo_bindings.js in this list.
* @returns {Promise}
*/
async function loadMojoResources(resources) {
......@@ -66,18 +65,20 @@ async function loadMojoResources(resources) {
genPrefix = 'file://';
}
// We want to load mojo_bindings.js separately to set mojo.config.
if (resources.some(p => p.endsWith('/mojo_bindings.js'))) {
throw new Error('Do not load mojo_bindings.js explicitly.');
for (const path of resources) {
// We want to load mojo_bindings.js separately to set mojo.config.
if (path.endsWith('/mojo_bindings.js')) {
throw new Error('Do not load mojo_bindings.js explicitly.');
}
if (! /^\/gen\/.*\.mojom\.js$/.test(path)) {
throw new Error(`Unrecognized resource path: ${path}`);
}
}
await loadScript(genPrefix + '/gen/layout_test_data/mojo/public/js/mojo_bindings.js');
mojo.config.autoLoadMojomDeps = false;
for (const path of resources) {
if (path.startsWith('/gen/')) {
await loadScript(genPrefix + path);
} else {
await loadScript(path);
}
await loadScript(genPrefix + path);
}
}
......@@ -200,7 +200,7 @@ function forEachWebxrObject(callback) {
// Code for loading test API in Chromium.
async function loadChromiumResources() {
let chromiumResources = [
const chromiumResources = [
'/gen/mojo/public/mojom/base/time.mojom.js',
'/gen/mojo/public/mojom/base/shared_memory.mojom.js',
'/gen/mojo/public/mojom/base/unguessable_token.mojom.js',
......@@ -217,22 +217,26 @@ async function loadChromiumResources() {
'/gen/ui/display/mojom/display.mojom.js',
'/gen/device/gamepad/public/mojom/gamepad.mojom.js',
'/gen/device/vr/public/mojom/vr_service.mojom.js',
];
let extraResources = [
'/resources/chromium/webxr-test-math-helper.js',
'/resources/chromium/webxr-test.js',
// Required only by resources/chromium/webxr-test.js
'/resources/testdriver.js',
'/resources/testdriver-vendor.js',
];
// This infrastructure is also used by Chromium-specific internal tests that
// may need additional resources (e.g. internal API extensions), this allows
// those tests to rely on this infrastructure while ensuring that no tests
// make it into public WPTs that rely on APIs outside of the webxr test API.
if (typeof(additionalChromiumResources) !== 'undefined') {
chromiumResources = chromiumResources.concat(additionalChromiumResources);
extraResources = extraResources.concat(additionalChromiumResources);
}
await loadMojoResources(chromiumResources);
for (const path of extraResources) {
await loadScript(path);
}
xr_debug = navigator.xr.test.Debug;
}
......
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