File: get.tentative.https.html

package info (click to toggle)
firefox 145.0-1
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 4,653,344 kB
  • sloc: cpp: 7,594,932; javascript: 6,459,612; ansic: 3,752,905; python: 1,403,433; xml: 629,811; asm: 438,677; java: 186,421; sh: 67,287; makefile: 19,169; objc: 13,086; perl: 12,982; yacc: 4,583; cs: 3,846; pascal: 3,448; lex: 1,720; ruby: 1,003; exp: 762; php: 436; lisp: 258; awk: 247; sql: 66; sed: 54; csh: 10
file content (273 lines) | stat: -rw-r--r-- 8,459 bytes parent folder | download | duplicates (4)
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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
<!DOCTYPE html>
<title>Digital Credential tests.</title>
<link rel="help" href="https://wicg.github.io/digital-credentials/" />
<script src="/common/get-host-info.sub.js"></script>
<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>
  <iframe id="same-origin"></iframe>
  <iframe id="cross-origin" allow="digital-credentials-get"></iframe>
</body>
<script type="module">
  import { makeGetOptions, sendMessage, loadIframe } from "./support/helper.js";

  const iframeSameOrigin = document.querySelector("iframe#same-origin");
  const iframeCrossOrigin = document.querySelector("iframe#cross-origin");

  promise_setup(async () => {
    const hostInfo = get_host_info();
    await Promise.all([
      loadIframe(
        iframeCrossOrigin,
        `${hostInfo.HTTPS_REMOTE_ORIGIN}/digital-credentials/support/iframe.html`
      ),
      loadIframe(iframeSameOrigin, "/digital-credentials/support/iframe.html"),
    ]);
  });

  promise_test(async (t) => {
    const invalidData = [null, undefined, "", 123, true, false];
    for (const data of invalidData) {
      const options = {
        digital: {
          requests: [
            {
              data,
              protocol: "openid4vp",
            },
          ],
        },
      };
      await promise_rejects_js(
        t,
        TypeError,
        navigator.credentials.get(options)
      );
    }
  }, "Type conversion happens on the data member of the DigitalCredentialGetRequest object.");

  promise_test(async (t) => {
    iframeSameOrigin.focus();
    for (const global of [window, iframeSameOrigin.contentWindow]) {
      await promise_rejects_dom(
        t,
        "NotSupportedError",
        global.DOMException,
        global.navigator.credentials.get()
      );

      await promise_rejects_dom(
        t,
        "NotSupportedError",
        global.DOMException,
        global.navigator.credentials.get({})
      );

      await promise_rejects_dom(
        t,
        "NotSupportedError",
        global.DOMException,
        global.navigator.credentials.get({ x: "y" })
      );

      await promise_rejects_dom(
        t,
        "NotSupportedError",
        global.DOMException,
        global.navigator.credentials.get({ x: "y", y: "z" })
      );

      await promise_rejects_dom(
        t,
        "NotSupportedError",
        global.DOMException,
        global.navigator.credentials.get({ mediation: "required" })
      );

      const abortController = new AbortController();
      const { signal } = abortController;

      await promise_rejects_dom(
        t,
        "NotSupportedError",
        global.DOMException,
        global.navigator.credentials.get({ signal })
      );

      await promise_rejects_dom(
        t,
        "NotSupportedError",
        global.DOMException,
        global.navigator.credentials.get({ signal, mediation: "required" })
      );
    }
  }, "Calling navigator.credentials.get() without a digital member same origin.");

  promise_test(async (t) => {
    for (const r of [undefined, []]) {
      const options = {
        digital: {
          requests: r
        },
      };
      await test_driver.bless("user activation");
      await promise_rejects_js(
        t,
        TypeError,
        navigator.credentials.get(options)
      );
    }
  }, "navigator.credentials.get() API rejects if there are no credential request.");

  promise_test(async (t) => {
    iframeSameOrigin.focus();
    const { contentWindow: iframeWindow } = iframeSameOrigin;
    for (const r of [undefined, []]) {
      const options = {
        digital: {
          requests: r
        },
      };
      await test_driver.bless("user activation");
      await promise_rejects_js(
        t,
        iframeWindow.TypeError,
        iframeWindow.navigator.credentials.get(options)
      );
    }
  }, "navigator.credentials.get() API rejects if there are no credential request for same-origin iframe.");

  promise_test(async (t) => {
    iframeCrossOrigin.focus();
    for (const r of [undefined, []]) {
      const options = {
        digital: {
          requests: r
        },
      };
      const result = await sendMessage(iframeCrossOrigin, {
        action: "get",
        options,
      });
      assert_equals(result.constructor, "TypeError");
    }
  }, "navigator.credentials.get() API rejects if there are no credential request in cross-origin iframe.");

  promise_test(async (t) => {
    const abortController = new AbortController();
    const { signal } = abortController;
    abortController.abort();
    for (const options of [{ signal }, { signal, ...makeGetOptions([]) }]) {
      await promise_rejects_dom(
        t,
        "AbortError",
        navigator.credentials.get(options)
      );
    }
  }, "navigator.credentials.get() promise is rejected if called with an aborted controller.");

  promise_test(async (t) => {
    iframeSameOrigin.focus();
    const { contentWindow: iframeWindow } = iframeSameOrigin;
    const abortController = new iframeWindow.AbortController();
    const { signal } = abortController;
    abortController.abort();
    for (const options of [{ signal }, { signal, ...makeGetOptions([]) }]) {
      await test_driver.bless("user activation");
      await promise_rejects_dom(
        t,
        "AbortError",
        iframeWindow.DOMException,
        iframeWindow.navigator.credentials.get(options)
      );
      assert_true(
        navigator.userActivation.isActive,
        "User activation is still active."
      );
    }
  }, "navigator.credentials.get() promise is rejected if called with an aborted controller in same-origin iframe.");

  promise_test(async (t) => {
    iframeCrossOrigin.focus();
    for (const options of [undefined, {}, makeGetOptions([])]) {
      const result = await sendMessage(iframeCrossOrigin, {
        abort: "before",
        action: "get",
        options,
      });
      assert_equals(result.constructor, "DOMException");
      assert_equals(result.name, "AbortError");
    }
  }, "navigator.credentials.get() promise is rejected if called with an aborted signal in cross-origin iframe.");

  promise_test(async (t) => {
    const abortController = new AbortController();
    const { signal } = abortController;
    const options = makeGetOptions("openid4vp");
    options.signal = signal;
    await test_driver.bless("user activation");
    const promise = promise_rejects_dom(
      t,
      "AbortError",
      DOMException,
      navigator.credentials.get(options)
    );
    abortController.abort();
    await promise;
  }, "navigator.credentials.get() promise is rejected if abort controller is aborted after call to get().");

  promise_test(async (t) => {
    iframeCrossOrigin.focus();
    const result = await sendMessage(iframeCrossOrigin, {
      abort: "after",
      action: "get",
      needsActivation: true,
      options: makeGetOptions("openid4vp"),
    });
    assert_equals(result.constructor, "DOMException");
    assert_equals(result.name, "AbortError");
  }, "navigator.credentials.get() promise is rejected if abort controller is aborted after call to get() in cross-origin iframe.");

  promise_test(async (t) => {
    /** @type sequence<CredentialMediationRequirement> */
    const disallowedMediations = ["conditional", "optional", "silent"];
    for (const mediation of disallowedMediations) {
      const options = makeGetOptions("default", mediation);
      await promise_rejects_js(
        t,
        TypeError,
        navigator.credentials.get(options)
      );
    }
  }, "Mediation is required to get a DigitalCredential.");

promise_test(async t => {
  const throwingValues = [
    BigInt(123),
    (() => { const o = {}; o.self = o; return o; })(),
    Symbol("foo")
  ];

  for (const badValue of throwingValues) {
    const options = makeGetOptions("openid4vp");
    options.digital.requests[0].data = badValue;

    await promise_rejects_js(
      t,
      TypeError,
      navigator.credentials.get(options),
      `Should throw for: ${String(badValue)}`
    );
  }
}, "Throws TypeError when request data is not JSON stringifiable.");

promise_test(async (t) => {
    await promise_rejects_js(
      t,
      TypeError,
      navigator.credentials.get({digital: {}}));
  }, "`requests` field is required in the options object.");
</script>