summaryrefslogtreecommitdiffstats
path: root/dom/credentialmanagement/identity/tests/browser/browser_single_concurrent_identity_request.js
blob: 2c3d91e521056dc90a8cd5b6b8823704521677fd (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
/* This Source Code Form is subject to the terms of the Mozilla Public
 * License, v. 2.0. If a copy of the MPL was not distributed with this file,
 * You can obtain one at http://mozilla.org/MPL/2.0/. */

"use strict";

const TEST_URL = "https://example.com/";

add_task(async function test_concurrent_identity_credential() {
  let tab = await BrowserTestUtils.openNewForegroundTab(gBrowser, TEST_URL);

  let requestCredential = async function () {
    let promise = content.navigator.credentials.get({
      identity: {
        providers: [
          {
            configURL:
              "https://example.net/tests/dom/credentialmanagement/identity/tests/browser/server_manifest.json",
            clientId: "browser",
            nonce: "nonce",
          },
        ],
      },
    });
    try {
      return await promise;
    } catch (err) {
      return err;
    }
  };

  ContentTask.spawn(tab.linkedBrowser, null, requestCredential);

  let secondRequest = ContentTask.spawn(
    tab.linkedBrowser,
    null,
    requestCredential
  );

  let concurrentResponse = await secondRequest;
  ok(concurrentResponse, "expect a result from the second request.");
  ok(concurrentResponse.name, "expect a DOMException which must have a name.");
  is(
    concurrentResponse.name,
    "InvalidStateError",
    "Expected 'InvalidStateError', but got '" + concurrentResponse.name + "'"
  );

  // Close tabs.
  await BrowserTestUtils.removeTab(tab);
});