From 60ddb0cfd153053712c7124b080774550a7c2610 Mon Sep 17 00:00:00 2001 From: Robert Ma Date: Tue, 22 Sep 2020 09:13:03 +0000 Subject: [PATCH] Bug 1665051 [wpt PR 25538] - [WPT] Refactor credential-management to use test-only-api.js, a=testonly Automatic update from web-platform-tests [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/+/2410676 Reviewed-by: Michael Moss Reviewed-by: Reilly Grant Commit-Queue: Robert Ma Cr-Commit-Position: refs/heads/master@{#807253} -- wpt-commits: 1d14e821b9586f250e6a31d550504e3d16a05ae7 wpt-pr: 25538 --- .../otpcredential-get-basics.https.html | 3 +- .../credential-management/support/README.md | 9 +++-- .../support/otpcredential-helper.js | 35 ++++++------------- .../support/otpcredential-iframe.html | 3 +- .../tests/resources/test-only-api.js | 30 ++++++++++++---- 5 files changed, 44 insertions(+), 36 deletions(-) diff --git a/testing/web-platform/tests/credential-management/otpcredential-get-basics.https.html b/testing/web-platform/tests/credential-management/otpcredential-get-basics.https.html index aca48227ce839..edeb42a0f5792 100644 --- a/testing/web-platform/tests/credential-management/otpcredential-get-basics.https.html +++ b/testing/web-platform/tests/credential-management/otpcredential-get-basics.https.html @@ -3,7 +3,8 @@ Tests OTPCredential - + + ` in your -test -2. Set expectations +1. Include the following in your test: +```html + + ``` +2. Set expectations +```javascript await expect(receive).andReturn(() => { // mock behavior }) diff --git a/testing/web-platform/tests/credential-management/support/otpcredential-helper.js b/testing/web-platform/tests/credential-management/support/otpcredential-helper.js index d5a7eb8c4715f..3cf4510585d61 100644 --- a/testing/web-platform/tests/credential-management/support/otpcredential-helper.js +++ b/testing/web-platform/tests/credential-management/support/otpcredential-helper.js @@ -8,45 +8,32 @@ // these tests the browser must be run with these options: // // --enable-blink-features=MojoJS,MojoJSTest -async function loadChromiumResources() { - if (!window.MojoInterfaceInterceptor) { - // Do nothing on non-Chromium-based browsers or when the Mojo bindings are - // not present in the global namespace. - return; - } +const Status = {}; +async function loadChromiumResources() { const resources = [ - '/gen/layout_test_data/mojo/public/js/mojo_bindings_lite.js', '/gen/mojo/public/mojom/base/time.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 => { - const script = document.createElement('script'); - script.src = path; - script.async = false; - const promise = new Promise((resolve, reject) => { - script.onload = resolve; - script.onerror = reject; - }); - document.head.appendChild(script); - return promise; - })); + await loadMojoResources(resources, true); + await loadScript('/resources/chromium/mock-sms-receiver.js'); Status.kSuccess = blink.mojom.SmsStatus.kSuccess; Status.kTimeout = blink.mojom.SmsStatus.kTimeout; Status.kCancelled = blink.mojom.SmsStatus.kCancelled; }; -const Status = {}; - async function create_sms_provider() { if (typeof SmsProvider === 'undefined') { - await loadChromiumResources(); + if (isChromiumBased) { + await loadChromiumResources(); + } else { + throw new Error('Mojo testing interface is not available.'); + } } - if (typeof SmsProvider == 'undefined') { - throw new Error('Mojo testing interface is not available.'); + if (typeof SmsProvider === 'undefined') { + throw new Error('Failed to set up SmsProvider.'); } return new SmsProvider(); } diff --git a/testing/web-platform/tests/credential-management/support/otpcredential-iframe.html b/testing/web-platform/tests/credential-management/support/otpcredential-iframe.html index 37fe6e1cd891b..83f25d573c8ec 100644 --- a/testing/web-platform/tests/credential-management/support/otpcredential-iframe.html +++ b/testing/web-platform/tests/credential-management/support/otpcredential-iframe.html @@ -1,5 +1,6 @@ - + +