summaryrefslogtreecommitdiffstats
path: root/toolkit/components/passwordmgr/test/browser/browser_doorhanger_replace_dismissed_with_visible_while_opening.js
blob: 401e0add1ba19a44ac22a5f756718b19fdf6a89f (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
/**
 * Replacing a dismissed doorhanger with a visible one while it's opening.
 *
 * There are various races between popup notification callbacks to catch with this.
 * This can happen in the real world by blurring an edited login field by clicking on the login doorhanger.
 */

XPCOMUtils.defineLazyServiceGetter(
  this,
  "prompterSvc",
  "@mozilla.org/login-manager/prompter;1",
  Ci.nsILoginManagerPrompter
);

add_task(async function test_replaceDismissedWithVisibleWhileOpening() {
  await BrowserTestUtils.withNewTab(
    {
      gBrowser,
      url: "https://example.com",
    },
    async function load(browser) {
      info("Show a dismissed save doorhanger");
      prompterSvc.promptToSavePassword(
        browser,
        LoginTestUtils.testData.formLogin({}),
        true,
        false,
        null
      );
      let doorhanger = await waitForDoorhanger(browser, "password-save");
      Assert.ok(doorhanger, "Got doorhanger");
      EventUtils.synthesizeMouseAtCenter(doorhanger.anchorElement, {});
      await BrowserTestUtils.waitForEvent(
        PopupNotifications.panel,
        "popupshowing"
      );
      await checkDoorhangerUsernamePassword("the username", "the password");
      info(
        "Replace the doorhanger with a non-dismissed one immediately after clicking to open"
      );
      prompterSvc.promptToSavePassword(
        browser,
        LoginTestUtils.testData.formLogin({}),
        true,
        false,
        null
      );
      await Promise.race([
        BrowserTestUtils.waitForCondition(() => {
          if (
            document.getElementById("password-notification-username").value !=
              "the username" ||
            document.getElementById("password-notification-password").value !=
              "the password"
          ) {
            return Promise.reject("Field changed to incorrect values");
          }
          return false;
        }, "See if username/password values change to incorrect values"),
        // eslint-disable-next-line mozilla/no-arbitrary-setTimeout
        new Promise(resolve => setTimeout(resolve, 1000)),
      ]);
    }
  );
});