summaryrefslogtreecommitdiffstats
path: root/toolkit/components/passwordmgr/test/browser/browser_basicAuth_switchTab.js
blob: 8e993388e73de2e12c0ce1f3f1aef3806910fd01 (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
/* 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/. */

add_task(async function test_auth_switchtab() {
  let tab = BrowserTestUtils.addTab(gBrowser);
  isnot(tab, gBrowser.selectedTab, "New tab shouldn't be selected");

  let authPromptShown = PromptTestUtils.waitForPrompt(tab.linkedBrowser, {
    modalType: Ci.nsIPrompt.MODAL_TYPE_TAB,
    promptType: "promptUserAndPass",
  });

  let loadPromise = BrowserTestUtils.browserLoaded(tab.linkedBrowser);
  BrowserTestUtils.startLoadingURIString(
    tab.linkedBrowser,
    "https://example.com/browser/toolkit/components/passwordmgr/test/browser/authenticate.sjs"
  );

  // Wait for the basic auth prompt
  let dialog = await authPromptShown;

  Assert.equal(gBrowser.selectedTab, tab, "Should have selected the new tab");

  // Cancel the auth prompt
  PromptTestUtils.handlePrompt(dialog, { buttonNumClick: 1 });

  // After closing the prompt the load should finish
  await loadPromise;

  gBrowser.removeTab(tab);
});