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