summaryrefslogtreecommitdiffstats
path: root/toolkit/components/passwordmgr/test/browser/browser_doorhanger_target_blank.js
blob: 63ba1fa2a72c2b3ac4924d4821ab6a9f2d088e68 (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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
/**
 * Test capture popup notifications when the login form uses target="_blank"
 */

add_setup(async function () {
  await SimpleTest.promiseFocus(window);
});

add_task(async function test_saveTargetBlank() {
  // This test submits the form to a new tab using target="_blank".
  let url = "subtst_notifications_12_target_blank.html?notifyu3|notifyp3||";
  let notifShownPromise = BrowserTestUtils.waitForEvent(
    PopupNotifications.panel,
    "popupshown"
  );

  let submissionTabPromise = BrowserTestUtils.waitForNewTab(
    gBrowser,
    url => {
      info(url);
      return url.includes("formsubmit.sjs");
    },
    false,
    true
  );

  await BrowserTestUtils.withNewTab(
    {
      gBrowser,
      url: "http://mochi.test:8888" + DIRECTORY_PATH + url,
    },
    async function () {
      // For now the doorhanger appears in the previous tab but it should maybe
      // appear in the new tab from target="_blank"?
      BrowserTestUtils.removeTab(await submissionTabPromise);

      let notif = await TestUtils.waitForCondition(
        () =>
          getCaptureDoorhangerThatMayOpen(
            "password-save",
            PopupNotifications,
            gBrowser.selectedBrowser
          ),
        "Waiting for doorhanger"
      );
      Assert.ok(notif, "got notification popup");

      EventUtils.synthesizeMouseAtCenter(notif.anchorElement, {});
      await notifShownPromise;
      await checkDoorhangerUsernamePassword("notifyu3", "notifyp3");
      let storageChangedPromised = TestUtils.topicObserved(
        "passwordmgr-storage-changed",
        (subject, data) => data != "removeLogin"
      );

      clickDoorhangerButton(notif, REMEMBER_BUTTON);
      await storageChangedPromised;
      BrowserTestUtils.removeTab(gBrowser.selectedTab);
    }
  );

  // Check result of clicking Remember
  let logins = Services.logins.getAllLogins();
  Assert.equal(logins.length, 1, "Should only have 1 login now");
  let login = logins[0].QueryInterface(Ci.nsILoginMetaInfo);
  Assert.equal(
    login.username,
    "notifyu3",
    "Check the username used on the new entry"
  );
  Assert.equal(
    login.password,
    "notifyp3",
    "Check the password used on the new entry"
  );
  Assert.equal(login.timesUsed, 1, "Check times used on new entry");

  // Check for stale values in the doorhanger <input> after closing.
  let usernameField = document.getElementById("password-notification-username");
  todo_is(
    usernameField.value,
    "",
    "Check the username field doesn't have a stale value"
  );
  let passwordField = document.getElementById("password-notification-password");
  todo_is(
    passwordField.value,
    "",
    "Check the password field doesn't have a stale value"
  );

  // Cleanup
  Services.logins.removeLogin(login);
});