summaryrefslogtreecommitdiffstats
path: root/toolkit/components/passwordmgr/test/browser/browser_doorhanger_dismissed_for_ccnumber.js
blob: eeaa211da8b42859699827dcda3718fa9fb34fe5 (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
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
"use strict";

const TEST_ORIGIN = "https://example.com";
const BASIC_FORM_PAGE_PATH = DIRECTORY_PATH + "form_basic.html";

add_task(async function test_doorhanger_dismissal_un() {
  let url = TEST_ORIGIN + BASIC_FORM_PAGE_PATH;
  await BrowserTestUtils.withNewTab(
    {
      gBrowser,
      url,
    },
    async function test_un_value_as_ccnumber(browser) {
      // If the username field has a credit card number and if
      // the password field is a three digit numberic value,
      // we automatically dismiss the save logins prompt on submission.

      let passwordFilledPromise = listenForTestNotification(
        "PasswordEditedOrGenerated"
      );
      await changeContentFormValues(browser, {
        "#form-basic-password": "123",
        // We are interested in the state of the doorhanger created and don't want a
        // false positive from the password-edited handling
        "#form-basic-username": "4111111111111111",
      });
      info("Waiting for passwordFilledPromise");
      await passwordFilledPromise;
      // reset doorhanger/notifications, we're only interested in the submit outcome
      await cleanupDoorhanger();
      await cleanupPasswordNotifications();
      // reset message cache so we can disambiguate between dismissed doorhanger from
      // password edited vs form submitted w. cc number as username
      await clearMessageCache(browser);

      let processedPromise = listenForTestNotification("ShowDoorhanger");
      await SpecialPowers.spawn(browser, [], async () => {
        content.document.getElementById("form-basic-submit").click();
      });
      info("Waiting for FormSubmit");
      await processedPromise;

      let notif = getCaptureDoorhanger("password-save");
      Assert.ok(notif, "got notification popup");
      Assert.ok(
        notif.dismissed,
        "notification popup was automatically dismissed"
      );
      await cleanupDoorhanger(notif);
    }
  );
});

add_task(async function test_doorhanger_dismissal_pw() {
  let url = TEST_ORIGIN + BASIC_FORM_PAGE_PATH;
  await BrowserTestUtils.withNewTab(
    {
      gBrowser,
      url,
    },
    async function test_pw_value_as_ccnumber(browser) {
      // If the password field has a credit card number and if
      // the password field is also tagged autocomplete="cc-number",
      // we automatically dismiss the save logins prompt on submission.

      let passwordFilledPromise = listenForTestNotification(
        "PasswordEditedOrGenerated"
      );
      await changeContentFormValues(browser, {
        "#form-basic-password": "4111111111111111",
        "#form-basic-username": "aaa",
      });
      await SpecialPowers.spawn(browser, [], async () => {
        content.document
          .getElementById("form-basic-password")
          .setAttribute("autocomplete", "cc-number");
      });
      await passwordFilledPromise;
      // reset doorhanger/notifications, we're only interested in the submit outcome
      await cleanupDoorhanger();
      await cleanupPasswordNotifications();
      // reset message cache so we can disambiguate between dismissed doorhanger from
      // password edited vs form submitted w. cc number as password
      await clearMessageCache(browser);

      let processedPromise = listenForTestNotification("ShowDoorhanger");
      await SpecialPowers.spawn(browser, [], async () => {
        content.document.getElementById("form-basic-submit").click();
      });
      await processedPromise;

      let notif = getCaptureDoorhanger("password-save");
      Assert.ok(notif, "got notification popup");
      Assert.ok(
        notif.dismissed,
        "notification popup was automatically dismissed"
      );
      await cleanupDoorhanger(notif);
    }
  );
});

add_task(async function test_doorhanger_shown_on_un_with_invalid_ccnumber() {
  let url = TEST_ORIGIN + BASIC_FORM_PAGE_PATH;
  await BrowserTestUtils.withNewTab(
    {
      gBrowser,
      url,
    },
    async function test_un_with_invalid_cc_number(browser) {
      // If the username field has a CC number that is invalid,
      // we show the doorhanger to save logins like we usually do.

      let passwordFilledPromise = listenForTestNotification(
        "PasswordEditedOrGenerated"
      );
      await changeContentFormValues(browser, {
        "#form-basic-password": "411",
        "#form-basic-username": "1234123412341234",
      });

      await passwordFilledPromise;
      // reset doorhanger/notifications, we're only interested in the submit outcome
      await cleanupDoorhanger();
      await cleanupPasswordNotifications();
      // reset message cache so we can disambiguate between dismissed doorhanger from
      // password edited vs form submitted w. cc number as password
      await clearMessageCache(browser);

      let processedPromise = listenForTestNotification("ShowDoorhanger");
      await SpecialPowers.spawn(browser, [], async () => {
        content.document.getElementById("form-basic-submit").click();
      });
      await processedPromise;

      let notif = await getCaptureDoorhangerThatMayOpen("password-save");
      Assert.ok(notif, "got notification popup");
      Assert.ok(
        !notif.dismissed,
        "notification popup was not automatically dismissed"
      );
      await cleanupDoorhanger(notif);
    }
  );
});

add_task(async function test_doorhanger_dismissal_on_change() {
  let url = TEST_ORIGIN + BASIC_FORM_PAGE_PATH;
  await BrowserTestUtils.withNewTab(
    {
      gBrowser,
      url,
    },
    async function test_change_in_pw(browser) {
      let nsLoginInfo = new Components.Constructor(
        "@mozilla.org/login-manager/loginInfo;1",
        Ci.nsILoginInfo,
        "init"
      );
      let login = new nsLoginInfo(
        TEST_ORIGIN,
        TEST_ORIGIN,
        null,
        "4111111111111111",
        "111", // password looks like a card security code
        "form-basic-username",
        "form-basic-password"
      );
      await Services.logins.addLoginAsync(login);

      let passwordFilledPromise = listenForTestNotification(
        "PasswordEditedOrGenerated"
      );

      await changeContentFormValues(browser, {
        "#form-basic-password": "222", // password looks like a card security code
        "#form-basic-username": "4111111111111111",
      });
      await passwordFilledPromise;
      // reset doorhanger/notifications, we're only interested in the submit outcome
      await cleanupDoorhanger();
      await cleanupPasswordNotifications();
      // reset message cache so we can disambiguate between dismissed doorhanger from
      // password edited vs form submitted w. cc number as username
      await clearMessageCache(browser);

      let processedPromise = listenForTestNotification("ShowDoorhanger");
      await SpecialPowers.spawn(browser, [], async () => {
        content.document.getElementById("form-basic-submit").click();
      });
      await processedPromise;

      let notif = getCaptureDoorhanger("password-change");
      Assert.ok(notif, "got notification popup");
      Assert.ok(
        notif.dismissed,
        "notification popup was automatically dismissed"
      );
      await cleanupDoorhanger(notif);
    }
  );
});