diff --git a/credential-management/otpcredential-get-basics.https.html b/credential-management/otpcredential-get-basics.https.html index aca48227ce839a..edeb42a0f57920 100644 --- a/credential-management/otpcredential-get-basics.https.html +++ b/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/credential-management/support/otpcredential-helper.js b/credential-management/support/otpcredential-helper.js index d5a7eb8c4715f0..3cf4510585d61c 100644 --- a/credential-management/support/otpcredential-helper.js +++ b/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/credential-management/support/otpcredential-iframe.html b/credential-management/support/otpcredential-iframe.html index 37fe6e1cd891b3..83f25d573c8ecc 100644 --- a/credential-management/support/otpcredential-iframe.html +++ b/credential-management/support/otpcredential-iframe.html @@ -1,5 +1,6 @@ - + +