summaryrefslogtreecommitdiffstats
path: root/testing/web-platform/tests/credential-management/fedcm-disconnect-iframe.sub.https.html
blob: 3d31be60b18b095889354ef4c916221633ad7ad3 (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
<!DOCTYPE html>
<title>Federated Credential Management API disconnect() tests in iframes.</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>

<body>

<script type="module">
import {alt_manifest_origin,
        alt_request_options_with_mediation_required,
        fedcm_test,
        fedcm_get_and_select_first_account} from './support/fedcm-helper.sub.js';

async function createIframeAndWaitForMessage(test, iframeUrl, allow = false) {
  const messageWatcher = new EventWatcher(test, window, "message");
  let iframe = document.createElement("iframe");
  iframe.src = iframeUrl;
  if (allow) {
    iframe.allow = "identity-credentials-get";
  }
  document.body.appendChild(iframe);
  const message = await messageWatcher.wait_for("message");
  return message.data;
}

fedcm_test(async t => {
  const message = await createIframeAndWaitForMessage(t, 'support/fedcm/disconnect-iframe.html');
  assert_equals(message.result, "Pass");
}, 'Same-origin iframe does not need explicit identity-credentials-get');

fedcm_test(async t => {
  const message = await createIframeAndWaitForMessage(t,
      'https://{{hosts[alt][]}}:{{ports[https][0]}}/credential-management/support/fedcm/disconnect-iframe.html?skip_get');
  assert_equals(message.result, "Failed disconnect");
  assert_equals(message.errorType, "NotAllowedError");
}, 'Cross-origin iframe fails disconnect() without explicit identity-credentials-get');

fedcm_test(async t => {
  const message = await createIframeAndWaitForMessage(t,
      'https://{{hosts[alt][]}}:{{ports[https][0]}}/credential-management/support/fedcm/disconnect-iframe.html',
      /*allow=*/true);
  assert_equals(message.result, "Pass");
}, 'Cross-origin iframe can disconnect with explicit identity-credentials-get');
</script>