From 226f994feca843b12b1976e4bd4050809c4cc481 Mon Sep 17 00:00:00 2001 From: Arnaud Mandy Date: Wed, 9 Sep 2020 04:33:49 -0700 Subject: [PATCH] WPT: Refactor contacts tests to use test-only-api.js use of test-only-api.js in preparation for launching official MojoJS support in WPT. This would not change the test results on Chromium waterfall (everything should continue to pass) or upstream WPT (tests currently fail because MojoJS isn't enabled). Bug: 1123989 Change-Id: Ib7fed092b37243b82fbbf38d871bb75728cb7744 Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2395395 Commit-Queue: Arnaud Mandy Reviewed-by: Finnur Thorarinsson Reviewed-by: Robert Ma Cr-Commit-Position: refs/heads/master@{#805272} --- contacts/contacts-select.https.window.js | 1 + contacts/resources/helpers.js | 36 +++++++----------------- 2 files changed, 11 insertions(+), 26 deletions(-) diff --git a/contacts/contacts-select.https.window.js b/contacts/contacts-select.https.window.js index c93d711ed5205f..850217aadfa7e6 100644 --- a/contacts/contacts-select.https.window.js +++ b/contacts/contacts-select.https.window.js @@ -1,3 +1,4 @@ +// META: script=/resources/test-only-api.js // META: script=/resources/testdriver.js // META: script=/resources/testdriver-vendor.js // META: script=resources/helpers.js diff --git a/contacts/resources/helpers.js b/contacts/resources/helpers.js index 88b2f1656ee720..c67d684652884c 100644 --- a/contacts/resources/helpers.js +++ b/contacts/resources/helpers.js @@ -8,31 +8,16 @@ // these tests the browser must be run with these options: // // --enable-blink-features=MojoJS,MojoJSTest -const loadChromiumResources = async () => { - 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 = [ - '/gen/layout_test_data/mojo/public/js/mojo_bindings.js', + const chromiumResources = [ '/gen/third_party/blink/public/mojom/contacts/contacts_manager.mojom.js', - '/resources/chromium/contacts_manager_mock.js', + '/gen/components/payments/mojom/payment_request_data.mojom.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(chromiumResources); + await loadScript('/resources/chromium/contacts_manager_mock.js'); +} // User Agents must provide their own implementation of `WebContacts`, // which must contain the following this interface: @@ -42,12 +27,11 @@ const loadChromiumResources = async () => { // } async function createWebContactsTest() { if (typeof WebContactsTest === 'undefined') { - await loadChromiumResources(); + if (isChromiumBased) { + await loadChromiumResources(); + } } - assert_true( - typeof WebContactsTest !== 'undefined', - 'Mojo testing interface is not available.' - ); + assert_implements(WebContactsTest, 'WebContactsTest is unavailable.'); return new WebContactsTest(); }