fedcm-iframe.html (1157B)
1 <!doctype html> 2 <script src="/resources/testdriver.js"></script> 3 <script src="/resources/testdriver-vendor.js"></script> 4 <script type="module"> 5 import {request_options_with_mediation_required, 6 fedcm_get_and_select_first_account} from './fedcm-helper.sub.js'; 7 8 // Loading fedcm-iframe.html in the test will make a FedCM call on load, and 9 // trigger a postMessage upon completion. 10 // 11 // message { 12 // string result: "Pass" | "Fail" 13 // string token: token.token 14 // string errorType: error.name 15 // } 16 17 window.onload = async () => { 18 window.test_driver.set_test_context(window.top); 19 // Use this variable to stop trying to select an account once the get() promise is resolved. 20 let cancelHelper = false; 21 try { 22 const cred = await fedcm_get_and_select_first_account(null, request_options_with_mediation_required()); 23 window.top.postMessage({result: "Pass", token: cred.token}, '*'); 24 } catch (error) { 25 window.top.postMessage({result: "Fail", errorType: error.name}, '*'); 26 } 27 // In case the get() call fails and no accounts may be selected, force the 28 // helper function to stop calling itself. 29 cancelHelper = true; 30 }; 31 32 </script>