fedcm-accounts-push-caches-pictures.tentative.https.html (3110B)
1 <!DOCTYPE html> 2 <title>Federated Credential Management API Accounts Push tests.</title> 3 <link rel="help" href="https://fedidcg.github.io/FedCM"> 4 <script src="/resources/testharness.js"></script> 5 <script src="/resources/testharnessreport.js"></script> 6 <script src="/resources/testdriver.js"></script> 7 <script src="/resources/testdriver-vendor.js"></script> 8 9 <body> 10 11 <script type="module"> 12 import {fedcm_test, 13 request_options_with_mediation_required, 14 setup_accounts_push, mark_signed_out, 15 fedcm_get_and_select_first_account} from '../support/fedcm-helper.sub.js'; 16 17 const successful_picture_counter_path = `/fedcm/support/account_picture_get_count.py`; 18 const uncached_picture_counter_path = `/fedcm/support/account_picture_uncached_get_count.py`; 19 20 async function wait_for_fetch_count(counter_path) { 21 const counter_response = await fetch(counter_path); 22 const counter_text = await counter_response.text(); 23 return counter_text === "1"; 24 } 25 26 fedcm_test(async t => { 27 // Get and clear the count to ensure the counters start at 0. 28 await fetch(successful_picture_counter_path); 29 await fetch(uncached_picture_counter_path); 30 31 // Opens a window that then invokes navigator.login.setStatus with two pushed 32 // accounts with different picture URLs; one successful picture response, and 33 // one uncacheable response. Register the cleanup handler, which uses the 34 // setStatus API to set the state to 'logged-out' 35 t.add_cleanup(() => { 36 mark_signed_out(); 37 }); 38 await setup_accounts_push(); 39 40 await t.step_wait(() => wait_for_fetch_count(successful_picture_counter_path), 41 "Cacheable picture should be retrieved when " + 42 "navigator.login.setStatus is called", 43 /*timeout=*/1_000, /*interval=*/200); 44 await t.step_wait(() => wait_for_fetch_count(uncached_picture_counter_path), 45 "Uncacheable picture should be retrieved when " + 46 "navigator.login.setStatus is called", 47 /*timeout=*/1_000, /*interval=*/200); 48 49 const cred = await fedcm_get_and_select_first_account(t, 50 request_options_with_mediation_required("manifest_accounts_push.json")); 51 assert_equals(cred.token, "account_id=john_doe"); 52 assert_equals(cred.isAutoSelected, false); 53 54 const successful_counter_response = await fetch(successful_picture_counter_path); 55 const successful_counter_text = await successful_counter_response.text(); 56 assert_equals(successful_counter_text, "0", 57 "Cacheable picture should not be requested when " + 58 "navigator.credentials.get is called"); 59 60 // ... even if the response during navigator.login.setStatus was uncacheable. 61 const error_counter_response = await fetch(uncached_picture_counter_path); 62 const error_counter_text = await error_counter_response.text(); 63 assert_equals(error_counter_text, "0", 64 "Picture should not be requested even on a cache miss when " + 65 "navigator.credentials.get is called"); 66 }, "Pictures should be retrieved when accounts are pushed, not when " + 67 "credential request is made."); 68 69 </script>