blob: 83f25d573c8ecc967635bb9239a3d0c0c1544d37 [file] [edit]
<!doctype html>
<script src="/resources/test-only-api.js"></script>
<script src="otpcredential-helper.js"></script>
<script>
'use strict';
// Loading otpcredential-iframe.html in the test will make an OTPCredentials
// call on load, and trigger a postMessage upon completion.
//
// message {
// string result: "Pass" | "Fail"
// string code: credentials.code
// string errorType: error.name
// }
// Intercept successful calls and return mocked value.
(async function() {
await expect(receive).andReturn(() => {
return Promise.resolve({
status: Status.kSuccess,
otp: "ABC123",
});
});
}());
window.onload = async () => {
try {
const credentials =
await navigator.credentials.get({otp: {transport: ["sms"]}});
window.parent.postMessage({result: "Pass", code: credentials.code}, '*');
} catch (error) {
window.parent.postMessage({result: "Fail", errorType: error.name}, '*');
}
}
</script>