resolve-flexible-tokens.https.html (3817B)
1 <!DOCTYPE html> 2 <title>FedCM: IdentityProvider.resolve() with flexible token formats</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 {fedcm_test, 12 request_options_with_mediation_required, 13 select_manifest, 14 fedcm_get_and_select_first_account} from '../support/fedcm-helper.sub.js'; 15 16 // Test 1: String token 17 fedcm_test(async t => { 18 const options = request_options_with_mediation_required('manifest_continue_on_flexible_tokens.json'); 19 options.identity.providers[0].params = { 20 accountId: "jane_doe", 21 tokenType: "string", 22 tokenValue: "account=jane_doe" 23 }; 24 25 await select_manifest(t, options); 26 const cred = await fedcm_get_and_select_first_account(t, options); 27 assert_equals(cred.token, "account=jane_doe"); 28 }, "IdentityProvider.resolve() with string token"); 29 30 // Test 2: Positive number token 31 fedcm_test(async t => { 32 const options = request_options_with_mediation_required('manifest_continue_on_flexible_tokens.json'); 33 options.identity.providers[0].params = { 34 accountId: "jane_doe", 35 tokenType: "number", 36 tokenValue: 42 37 }; 38 39 await select_manifest(t, options); 40 const cred = await fedcm_get_and_select_first_account(t, options); 41 assert_equals(cred.token, 42); 42 }, "IdentityProvider.resolve() with positive number token"); 43 44 // Test 3: Boolean token(true) 45 fedcm_test(async t => { 46 const options = request_options_with_mediation_required('manifest_continue_on_flexible_tokens.json'); 47 options.identity.providers[0].params = { 48 accountId: "jane_doe", 49 tokenType: "boolean", 50 tokenValue: true 51 }; 52 53 await select_manifest(t, options); 54 const cred = await fedcm_get_and_select_first_account(t, options); 55 assert_equals(cred.token, true); 56 }, "IdentityProvider.resolve() with boolean(true) token"); 57 58 // Test 4: Null token 59 fedcm_test(async t => { 60 const options = request_options_with_mediation_required('manifest_continue_on_flexible_tokens.json'); 61 options.identity.providers[0].params = { 62 accountId: "jane_doe", 63 tokenType: "null", 64 tokenValue: null 65 }; 66 67 await select_manifest(t, options); 68 const cred = await fedcm_get_and_select_first_account(t, options); 69 assert_equals(cred.token, null); 70 }, "IdentityProvider.resolve() with null token"); 71 72 // Test 5: Object token 73 fedcm_test(async t => { 74 const options = request_options_with_mediation_required('manifest_continue_on_flexible_tokens.json'); 75 options.identity.providers[0].params = { 76 accountId: "jane_doe", 77 tokenType: "object", 78 tokenValue: {id: 42, name: "test", active: true} 79 }; 80 81 await select_manifest(t, options); 82 const cred = await fedcm_get_and_select_first_account(t, options); 83 assert_equals(cred.token.id, 42); 84 assert_equals(cred.token.name, "test"); 85 assert_equals(cred.token.active, true); 86 }, "IdentityProvider.resolve() with object token"); 87 88 // Test 6: Array token 89 fedcm_test(async t => { 90 const options = request_options_with_mediation_required('manifest_continue_on_flexible_tokens.json'); 91 options.identity.providers[0].params = { 92 accountId: "jane_doe", 93 tokenType: "array", 94 tokenValue: [1, "test", true, null, {key: "value"}] 95 }; 96 97 await select_manifest(t, options); 98 const cred = await fedcm_get_and_select_first_account(t, options); 99 assert_equals(cred.token.length, 5); 100 assert_equals(cred.token[0], 1); 101 assert_equals(cred.token[1], "test"); 102 assert_equals(cred.token[2], true); 103 assert_equals(cred.token[3], null); 104 assert_equals(cred.token[4].key, "value"); 105 }, "IdentityProvider.resolve() with array token"); 106 107 </script>