fedcm-not-observed-by-service-worker.https.html (2217B)
1 <!DOCTYPE html> 2 <title>Federated Credential Management API network request 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 <script src="/service-workers/service-worker/resources/test-helpers.sub.js"></script> 9 10 <body> 11 12 <script type="module"> 13 import {fedcm_test, 14 request_options_with_mediation_required, 15 set_fedcm_cookie, 16 fedcm_get_and_select_first_account} from './support/fedcm-helper.sub.js'; 17 18 function loadUrlInIframe(url) { 19 let iframe = document.createElement("iframe"); 20 return new Promise(resolve => { 21 iframe.src = url; 22 iframe.onload = function() { resolve(iframe); }; 23 document.body.appendChild(iframe); 24 }); 25 } 26 27 fedcm_test(async t => { 28 const service_worker_url = 'support/fedcm/intercept_service_worker.js'; 29 const sw_scope_url = '/fedcm/support/fedcm/'; 30 // URL for querying number of page loads observed by service worker. 31 const query_sw_intercepts_url = 'support/fedcm/query_service_worker_intercepts.html'; 32 const page_in_sw_scope_url = 'support/fedcm/simple.html'; 33 34 const sw_registration = await service_worker_unregister_and_register( 35 t, service_worker_url, sw_scope_url); 36 t.add_cleanup(() => service_worker_unregister(t, sw_scope_url)); 37 await wait_for_state(t, sw_registration.installing, 'activated'); 38 39 // Verify that service worker works. 40 await loadUrlInIframe(page_in_sw_scope_url); 41 let query_sw_iframe = await loadUrlInIframe(query_sw_intercepts_url); 42 assert_equals(query_sw_iframe.contentDocument.body.textContent, "1"); 43 44 await set_fedcm_cookie(); 45 const cred = await fedcm_get_and_select_first_account(t, request_options_with_mediation_required()); 46 assert_equals(cred.token, "token"); 47 48 // Use cache buster query parameter to avoid cached response. 49 let query_sw_iframe2 = await loadUrlInIframe(query_sw_intercepts_url + "?2"); 50 assert_equals(query_sw_iframe2.contentDocument.body.textContent, "1"); 51 }, 'Test that service worker cannot observe fetches performed by FedCM API'); 52 53 </script>