fedcm-error-attribute.https.html (2855B)
1 <!DOCTYPE html> 2 <title>FedCM IdentityCredentialError.error attribute</title> 3 <meta name="timeout" content="long"> 4 <link rel="help" href="https://fedidcg.github.io/FedCM"> 5 <script src="/resources/testharness.js"></script> 6 <script src="/resources/testharnessreport.js"></script> 7 <script src="/resources/testdriver.js"></script> 8 <script src="/resources/testdriver-vendor.js"></script> 9 10 <script type="module"> 11 import {request_options_with_mediation_required, 12 fedcm_test, 13 select_manifest, 14 fedcm_get_and_select_first_account, 15 fedcm_error_dialog_click_button, 16 fedcm_error_dialog_dismiss} from '../support/fedcm-helper.sub.js'; 17 18 test(() => { 19 const errorInit = { 20 error: "invalid_request", 21 url: "https://example.com/error" 22 }; 23 24 const error = new IdentityCredentialError("Test error", errorInit); 25 26 assert_equals(error.error, "invalid_request", "error attribute should work"); 27 assert_equals(error.url, "https://example.com/error", "url should work"); 28 }, 'IdentityCredentialError.error attribute works'); 29 30 test(() => { 31 const errorInit = { 32 code: "unauthorized_client", 33 url: "https://example.com/error" 34 }; 35 36 const error = new IdentityCredentialError("Test error", errorInit); 37 38 // error attribute should be empty because code was ignored 39 assert_equals(error.error, "", "error should be empty when only code is provided and flag is enabled"); 40 assert_equals(error.url, "https://example.com/error", "url should work"); 41 }, 'Constructor ignores code field'); 42 43 // Error attribute in FedCM flow - dialog dismiss 44 fedcm_test(async t => { 45 let test_options = 46 request_options_with_mediation_required("manifest_id_assertion_endpoint_returns_error_format.json"); 47 await select_manifest(t, test_options); 48 49 try { 50 const cred = fedcm_get_and_select_first_account(t, test_options); 51 fedcm_error_dialog_dismiss(t); 52 await cred; 53 assert_unreached("IdentityCredentialError should be thrown"); 54 } catch (e) { 55 assert_equals(e.name, "IdentityCredentialError"); 56 assert_equals(e.error, "unauthorized_client", "error attribute works in FedCM flow"); 57 } 58 }, 'error attribute works in dialog dismiss workflow'); 59 60 // Error attribute in FedCM flow - button click 61 fedcm_test(async t => { 62 let test_options = request_options_with_mediation_required("manifest_id_assertion_endpoint_returns_error_format.json"); 63 await select_manifest(t, test_options); 64 65 try { 66 const cred = fedcm_get_and_select_first_account(t, test_options); 67 fedcm_error_dialog_click_button(t, "ErrorGotIt"); 68 await cred; 69 assert_unreached("IdentityCredentialError should be thrown"); 70 } catch (e) { 71 assert_equals(e.name, "IdentityCredentialError"); 72 assert_equals(e.error, "unauthorized_client", "error attribute works when button clicked"); 73 } 74 }, 'error attribute works in button click flow'); 75 76 </script>