| <!DOCTYPE html> |
| <html> |
| <head> |
| <title> |
| Check that parts of the Digital Credentials API exposure |
| is controlled via preference. |
| </title> |
| </head> |
| <script> |
| testRunner.dumpAsText(); |
| testRunner.waitUntilDone(); |
| |
| async function runTest() { |
| const iframe = document.querySelector("iframe"); |
| try { |
| await checkWindowObject(); |
| |
| window.internals.settings.setDigitalCredentialsEnabled(false); |
| |
| await new Promise((r) => { |
| iframe.onload = r; |
| iframe.src = "about:blank"; |
| }); |
| |
| await checkIFrame(iframe); |
| } catch (err) { |
| console.log(err); |
| } finally { |
| testRunner.notifyDone(); |
| } |
| |
| console.log("Test finished"); |
| } |
| |
| async function checkIFrame(iframe) { |
| const iframeWindow = iframe.contentWindow; |
| if ("identity" in iframeWindow.navigator) { |
| console.log("FAIL: identity disabled by preference."); |
| } |
| |
| if ("DigitalCredential" in iframeWindow) { |
| console.log( |
| "FAIL: DigitalCredential interface disabled by preference." |
| ); |
| } |
| |
| // We check that the "digital" is not web exposed by checking if the |
| // navigator.credentials.get() method rejects with an AbortError. |
| const abortController = new AbortController(); |
| abortController.abort(); |
| const digitalTypeCheckPromise = |
| iframeWindow.navigator.credentials.get({ |
| digital: "", // expects a dictionary |
| signal: abortController.signal, |
| }); |
| try { |
| await digitalTypeCheckPromise; |
| } catch (err) { |
| if (err.name !== "AbortError") { |
| console.log( |
| `FAIL: navigator.credentials.get() must reject with an AbortError. Got ${err.name} instead.` |
| ); |
| } |
| } |
| } |
| |
| async function checkWindowObject() { |
| if (window.navigator.credentials.requestIdentity) { |
| console.log( |
| "FAIL: navigator.credentials.requestIdentity() was removed from the spec!" |
| ); |
| } |
| |
| const { identity } = window.navigator; |
| if (!identity) { |
| console.log( |
| "FAIL: navigator.identity must be exposed. Was enabled by pref." |
| ); |
| } |
| |
| const isInstanceOfCredentialContainer = |
| identity instanceof window.CredentialsContainer; |
| if (!isInstanceOfCredentialContainer) { |
| console.log( |
| "FAIL: navigator.identity must be and instance of CredentialsContainer." |
| ); |
| } |
| |
| const isInstanceOfDigitalCredential = |
| window.DigitalCredential.prototype instanceof window.Credential; |
| if (!isInstanceOfDigitalCredential) { |
| console.log( |
| "FAIL: DigitalCredential's prototype interface must be an instance of Credential." |
| ); |
| } |
| |
| try { |
| await identity.get({ digital: "" }); |
| } catch (err) { |
| if (err.name !== "TypeError") { |
| console.log( |
| `FAIL: navigator.identity.get() must reject with an TypeError. Got ${err.name} instead.` |
| ); |
| } |
| } |
| } |
| </script> |
| <body onload="runTest()"> |
| <iframe></iframe> |
| </body> |
| </html> |