summaryrefslogtreecommitdiffstats
path: root/testing/web-platform/tests/credential-management/fedcm-button-and-other-account/fedcm-button-mode-priority.tentative.https.html
blob: b71e84db47e458f42931cfcbcc6e0100cd1d40d3 (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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
<!DOCTYPE html>
<title>Federated Credential Management API Button Mode priority 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 type="module">
import {request_options_with_mediation_required,
        fedcm_test,
        fedcm_get_and_select_first_account} from '../support/fedcm-helper.sub.js';

fedcm_test(async t => {
  let widget_test_options = request_options_with_mediation_required();
  let button_test_options = request_options_with_mediation_required("manifest_with_rp_mode.json");
  button_test_options.identity.mode = "button";

  return test_driver.bless('initiate FedCM request', async function() {
      let first_cred = await fedcm_get_and_select_first_account(t, button_test_options);
      assert_equals(first_cred.token, "mode=button");
      let second_cred = await fedcm_get_and_select_first_account(t, widget_test_options);
      assert_equals(second_cred.token, "token");
  });
}, "Test that the widget mode can succeed after the button mode.");

fedcm_test(async t => {
   let widget_test_options = request_options_with_mediation_required("manifest_with_rp_mode.json");
   let button_test_options = request_options_with_mediation_required("manifest_with_rp_mode.json");
   button_test_options.identity.mode = "button";

   let first_cred = navigator.credentials.get(widget_test_options);
   let rej = promise_rejects_dom(t, 'NetworkError', first_cred);

   return test_driver.bless('initiate FedCM request', async function() {
       let second_cred = await fedcm_get_and_select_first_account(t, button_test_options);
       assert_equals(second_cred.token, "mode=button");
       await rej;
   });
 }, "Test that the button mode can replace widget mode.");

fedcm_test(async t => {
  let button_test_options = request_options_with_mediation_required("manifest_with_rp_mode.json");
  button_test_options.identity.mode = "button";

  return test_driver.bless('initiate FedCM request', async function() {
      let first_cred = fedcm_get_and_select_first_account(t, button_test_options);
      let second_cred = navigator.credentials.get(button_test_options);
      let rej = promise_rejects_dom(t, 'NotAllowedError', second_cred);

      let cred = await first_cred;
      assert_equals(cred.token, "mode=button");
      await rej;
  });
}, "Test that the button mode cannot replace button mode.");

fedcm_test(async t => {
  let widget_test_options = request_options_with_mediation_required("manifest_with_rp_mode.json");
  let button_test_options = request_options_with_mediation_required("manifest_with_rp_mode.json");
  button_test_options.identity.mode = "button";

  return test_driver.bless('initiate FedCM request', async function() {
      let first_cred = fedcm_get_and_select_first_account(t, button_test_options);
      let second_cred = navigator.credentials.get(widget_test_options);
      let rej = promise_rejects_dom(t, 'NotAllowedError', second_cred);

      let cred = await first_cred;
      assert_equals(cred.token, "mode=button");
      await rej;
  });
}, "Test that the widget mode cannot replace button mode.");

</script>