Commit 3e8d7592 authored by Robert Ma's avatar Robert Ma Committed by Commit Bot

[WPT] Refactor credential-management to use test-only-api.js

With necessary changes to make Mojo lite bindings available in WPT:
* Release mojo/public/mojom/base/*.mojom*.js (mojo_bindings_lite.js was
  already released).
* Add an optional `lite` param to loadMojoResources().

Fixed: 1123987, 1126628
Change-Id: I35d37aa848e7a6333e6185450280c44afd6438c8
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2410676Reviewed-by: default avatarMichael Moss <mmoss@chromium.org>
Reviewed-by: default avatarReilly Grant <reillyg@chromium.org>
Commit-Queue: Robert Ma <robertma@chromium.org>
Cr-Commit-Position: refs/heads/master@{#807253}
parent 7cfe51d0
...@@ -313,7 +313,8 @@ FILES = [ ...@@ -313,7 +313,8 @@ FILES = [
'archive': 'mojojs.zip', 'archive': 'mojojs.zip',
}, },
{ {
'filename': 'gen/mojo/public/mojom/base/*.mojom.js', # including *.mojom-lite.js, too
'filename': 'gen/mojo/public/mojom/base/*.mojom*.js',
'buildtype': ['dev', 'official'], 'buildtype': ['dev', 'official'],
'archive': 'mojojs.zip', 'archive': 'mojojs.zip',
}, },
...@@ -328,6 +329,12 @@ FILES = [ ...@@ -328,6 +329,12 @@ FILES = [
'buildtype': ['dev', 'official'], 'buildtype': ['dev', 'official'],
'archive': 'mojojs.zip', 'archive': 'mojojs.zip',
}, },
# MojoJS support data (credential-management):
{
'filename': 'gen/third_party/blink/public/mojom/sms/sms_receiver.mojom-lite.js',
'buildtype': ['dev', 'official'],
'archive': 'mojojs.zip',
},
# MojoJS support data (idle-detection): # MojoJS support data (idle-detection):
{ {
'filename': 'gen/third_party/blink/public/mojom/idle/idle_manager.mojom.js', 'filename': 'gen/third_party/blink/public/mojom/idle/idle_manager.mojom.js',
......
...@@ -3,7 +3,8 @@ ...@@ -3,7 +3,8 @@
<title>Tests OTPCredential</title> <title>Tests OTPCredential</title>
<script src="/resources/testharness.js"></script> <script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script> <script src="/resources/testharnessreport.js"></script>
<script src="./support/otpcredential-helper.js"></script> <script src="/resources/test-only-api.js"></script>
<script src="support/otpcredential-helper.js"></script>
<script> <script>
'use strict'; 'use strict';
......
...@@ -8,10 +8,13 @@ and the underlying operating system and mock its behavior. ...@@ -8,10 +8,13 @@ and the underlying operating system and mock its behavior.
Usage: Usage:
1. Include `<script src="./support/otpcredential-helper.js"></script>` in your 1. Include the following in your test:
test ```html
2. Set expectations <script src="/resources/test-only-api.js"></script>
<script src="support/otpcredential-helper.js"></script>
``` ```
2. Set expectations
```javascript
await expect(receive).andReturn(() => { await expect(receive).andReturn(() => {
// mock behavior // mock behavior
}) })
......
...@@ -8,45 +8,32 @@ ...@@ -8,45 +8,32 @@
// these tests the browser must be run with these options: // these tests the browser must be run with these options:
// // --enable-blink-features=MojoJS,MojoJSTest // // --enable-blink-features=MojoJS,MojoJSTest
async function loadChromiumResources() { const Status = {};
if (!window.MojoInterfaceInterceptor) {
// Do nothing on non-Chromium-based browsers or when the Mojo bindings are
// not present in the global namespace.
return;
}
async function loadChromiumResources() {
const resources = [ const resources = [
'/gen/layout_test_data/mojo/public/js/mojo_bindings_lite.js',
'/gen/mojo/public/mojom/base/time.mojom-lite.js', '/gen/mojo/public/mojom/base/time.mojom-lite.js',
'/gen/third_party/blink/public/mojom/sms/sms_receiver.mojom-lite.js', '/gen/third_party/blink/public/mojom/sms/sms_receiver.mojom-lite.js',
'/resources/chromium/mock-sms-receiver.js',
]; ];
await Promise.all(resources.map(path => { await loadMojoResources(resources, true);
const script = document.createElement('script'); await loadScript('/resources/chromium/mock-sms-receiver.js');
script.src = path;
script.async = false;
const promise = new Promise((resolve, reject) => {
script.onload = resolve;
script.onerror = reject;
});
document.head.appendChild(script);
return promise;
}));
Status.kSuccess = blink.mojom.SmsStatus.kSuccess; Status.kSuccess = blink.mojom.SmsStatus.kSuccess;
Status.kTimeout = blink.mojom.SmsStatus.kTimeout; Status.kTimeout = blink.mojom.SmsStatus.kTimeout;
Status.kCancelled = blink.mojom.SmsStatus.kCancelled; Status.kCancelled = blink.mojom.SmsStatus.kCancelled;
}; };
const Status = {};
async function create_sms_provider() { async function create_sms_provider() {
if (typeof SmsProvider === 'undefined') { if (typeof SmsProvider === 'undefined') {
await loadChromiumResources(); if (isChromiumBased) {
await loadChromiumResources();
} else {
throw new Error('Mojo testing interface is not available.');
}
} }
if (typeof SmsProvider == 'undefined') { if (typeof SmsProvider === 'undefined') {
throw new Error('Mojo testing interface is not available.'); throw new Error('Failed to set up SmsProvider.');
} }
return new SmsProvider(); return new SmsProvider();
} }
......
<!doctype html> <!doctype html>
<script src="./otpcredential-helper.js"></script> <script src="/resources/test-only-api.js"></script>
<script src="otpcredential-helper.js"></script>
<script> <script>
'use strict'; 'use strict';
......
...@@ -47,11 +47,14 @@ function loadScript(path) { ...@@ -47,11 +47,14 @@ function loadScript(path) {
* Only call this function if isChromiumBased === true. * Only call this function if isChromiumBased === true.
* *
* @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' or
* does not matter. Do not include mojo_bindings.js in this list. * '/gen/../*.mojom-lite.js' (requires `lite` to be true); the order does not
* matter. Do not include 'mojo_bindings.js' or 'mojo_bindings_lite.js'.
* @param {boolean=} lite - Whether the lite bindings (*.mojom-lite.js) are used
* (default is false).
* @returns {Promise} * @returns {Promise}
*/ */
async function loadMojoResources(resources) { async function loadMojoResources(resources, lite = false) {
if (!isChromiumBased) { if (!isChromiumBased) {
throw new Error('MojoJS not enabled; start Chrome with --enable-blink-features=MojoJS,MojoJSTest'); throw new Error('MojoJS not enabled; start Chrome with --enable-blink-features=MojoJS,MojoJSTest');
} }
...@@ -70,13 +73,26 @@ async function loadMojoResources(resources) { ...@@ -70,13 +73,26 @@ async function loadMojoResources(resources) {
if (path.endsWith('/mojo_bindings.js')) { if (path.endsWith('/mojo_bindings.js')) {
throw new Error('Do not load mojo_bindings.js explicitly.'); throw new Error('Do not load mojo_bindings.js explicitly.');
} }
if (! /^\/gen\/.*\.mojom\.js$/.test(path)) { if (path.endsWith('/mojo_bindings_lite.js')) {
throw new Error(`Unrecognized resource path: ${path}`); throw new Error('Do not load mojo_bindings_lite.js explicitly.');
}
if (lite) {
if (! /^\/gen\/.*\.mojom-lite\.js$/.test(path)) {
throw new Error(`Unrecognized resource path: ${path}`);
}
} else {
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'); if (lite) {
mojo.config.autoLoadMojomDeps = false; await loadScript(genPrefix + '/gen/layout_test_data/mojo/public/js/mojo_bindings_lite.js');
} else {
await loadScript(genPrefix + '/gen/layout_test_data/mojo/public/js/mojo_bindings.js');
mojo.config.autoLoadMojomDeps = false;
}
for (const path of resources) { for (const path of resources) {
await loadScript(genPrefix + path); await loadScript(genPrefix + path);
......
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