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) { ...@@ -29,6 +29,13 @@ function loadScript(path) {
* @returns {Promise<void>} Resolves when Chromium specific setup is complete. * @returns {Promise<void>} Resolves when Chromium specific setup is complete.
*/ */
async function performChromiumSetup() { 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. // Determine path prefixes.
let resPrefix = '/resources'; let resPrefix = '/resources';
let extra = ['/resources/chromium/web-bluetooth-test.js']; let extra = ['/resources/chromium/web-bluetooth-test.js'];
...@@ -47,13 +54,10 @@ async function performChromiumSetup() { ...@@ -47,13 +54,10 @@ async function performChromiumSetup() {
return; return;
} }
await loadMojoResources([ await loadMojoResources(chromiumResources);
'/gen/content/test/data/mojo_web_test_helper_test.mojom.js', for (const path of extra) {
'/gen/device/bluetooth/public/mojom/uuid.mojom.js', await loadScript(path);
'/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));
// Call setBluetoothFakeAdapter() to clean up any fake adapters left over by // Call setBluetoothFakeAdapter() to clean up any fake adapters left over by
// legacy tests. Legacy tests that use setBluetoothFakeAdapter() sometimes // legacy tests. Legacy tests that use setBluetoothFakeAdapter() sometimes
......
...@@ -48,8 +48,7 @@ function loadScript(path) { ...@@ -48,8 +48,7 @@ function loadScript(path) {
* *
* @param {Array.<string>} resources - A list of scripts to load: Mojo JS * @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 * 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 * does not matter. Do not include mojo_bindings.js in this list.
* include other non-mojom.js scripts for convenience.
* @returns {Promise} * @returns {Promise}
*/ */
async function loadMojoResources(resources) { async function loadMojoResources(resources) {
...@@ -66,18 +65,20 @@ async function loadMojoResources(resources) { ...@@ -66,18 +65,20 @@ async function loadMojoResources(resources) {
genPrefix = 'file://'; genPrefix = 'file://';
} }
// We want to load mojo_bindings.js separately to set mojo.config. for (const path of resources) {
if (resources.some(p => p.endsWith('/mojo_bindings.js'))) { // We want to load mojo_bindings.js separately to set mojo.config.
throw new Error('Do not load mojo_bindings.js explicitly.'); 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'); await loadScript(genPrefix + '/gen/layout_test_data/mojo/public/js/mojo_bindings.js');
mojo.config.autoLoadMojomDeps = false; mojo.config.autoLoadMojomDeps = false;
for (const path of resources) { for (const path of resources) {
if (path.startsWith('/gen/')) { await loadScript(genPrefix + path);
await loadScript(genPrefix + path);
} else {
await loadScript(path);
}
} }
} }
...@@ -200,7 +200,7 @@ function forEachWebxrObject(callback) { ...@@ -200,7 +200,7 @@ function forEachWebxrObject(callback) {
// Code for loading test API in Chromium. // Code for loading test API in Chromium.
async function loadChromiumResources() { async function loadChromiumResources() {
let chromiumResources = [ const chromiumResources = [
'/gen/mojo/public/mojom/base/time.mojom.js', '/gen/mojo/public/mojom/base/time.mojom.js',
'/gen/mojo/public/mojom/base/shared_memory.mojom.js', '/gen/mojo/public/mojom/base/shared_memory.mojom.js',
'/gen/mojo/public/mojom/base/unguessable_token.mojom.js', '/gen/mojo/public/mojom/base/unguessable_token.mojom.js',
...@@ -217,22 +217,26 @@ async function loadChromiumResources() { ...@@ -217,22 +217,26 @@ async function loadChromiumResources() {
'/gen/ui/display/mojom/display.mojom.js', '/gen/ui/display/mojom/display.mojom.js',
'/gen/device/gamepad/public/mojom/gamepad.mojom.js', '/gen/device/gamepad/public/mojom/gamepad.mojom.js',
'/gen/device/vr/public/mojom/vr_service.mojom.js', '/gen/device/vr/public/mojom/vr_service.mojom.js',
];
let extraResources = [
'/resources/chromium/webxr-test-math-helper.js', '/resources/chromium/webxr-test-math-helper.js',
'/resources/chromium/webxr-test.js', '/resources/chromium/webxr-test.js',
// Required only by resources/chromium/webxr-test.js
'/resources/testdriver.js', '/resources/testdriver.js',
'/resources/testdriver-vendor.js', '/resources/testdriver-vendor.js',
]; ];
// This infrastructure is also used by Chromium-specific internal tests that // This infrastructure is also used by Chromium-specific internal tests that
// may need additional resources (e.g. internal API extensions), this allows // may need additional resources (e.g. internal API extensions), this allows
// those tests to rely on this infrastructure while ensuring that no tests // 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. // make it into public WPTs that rely on APIs outside of the webxr test API.
if (typeof(additionalChromiumResources) !== 'undefined') { if (typeof(additionalChromiumResources) !== 'undefined') {
chromiumResources = chromiumResources.concat(additionalChromiumResources); extraResources = extraResources.concat(additionalChromiumResources);
} }
await loadMojoResources(chromiumResources); await loadMojoResources(chromiumResources);
for (const path of extraResources) {
await loadScript(path);
}
xr_debug = navigator.xr.test.Debug; 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