summaryrefslogtreecommitdiffstats
path: root/browser/extensions/formautofill/test/browser/browser_autocomplete_footer.js
blob: 1e7ba523e8cd8862958845bc9dd18906f968b8a5 (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
"use strict";

const URL = BASE_URL + "autocomplete_basic.html";

const l10n = new Localization(["toolkit/formautofill/formAutofill.ftl"], true);

add_setup(async function setup_storage() {
  await setStorage(
    TEST_ADDRESS_2,
    TEST_ADDRESS_3,
    TEST_ADDRESS_4,
    TEST_ADDRESS_5,
    TEST_CREDIT_CARD_1
  );
});

add_task(async function test_footer_has_correct_button_text_on_address() {
  await BrowserTestUtils.withNewTab(
    { gBrowser, url: URL },
    async function (browser) {
      const {
        autoCompletePopup: { richlistbox: itemsBox },
      } = browser;

      await openPopupOn(browser, "#organization");
      const footer = itemsBox.querySelector(
        ".autofill-footer-row.autofill-button"
      );
      Assert.equal(
        footer.innerText,
        l10n.formatValueSync("autofill-manage-addresses-label")
      );
      await closePopup(browser);
    }
  );
});

add_task(async function test_footer_has_correct_button_text_on_credit_card() {
  await BrowserTestUtils.withNewTab(
    { gBrowser, url: CREDITCARD_FORM_URL },
    async function (browser) {
      const {
        autoCompletePopup: { richlistbox: itemsBox },
      } = browser;

      await openPopupOn(browser, "#cc-number");
      const footer = itemsBox.querySelector(
        ".autofill-footer-row.autofill-button"
      );
      Assert.equal(
        footer.innerText,
        l10n.formatValueSync("autofill-manage-payment-methods-label")
      );
      await closePopup(browser);
    }
  );
});

add_task(async function test_press_enter_on_footer() {
  await BrowserTestUtils.withNewTab(
    { gBrowser, url: URL },
    async function (browser) {
      const {
        autoCompletePopup: { richlistbox: itemsBox },
      } = browser;

      await openPopupOn(browser, "#organization");
      // Navigate to the footer and press enter.
      const listItemElems = itemsBox.querySelectorAll(
        ".autocomplete-richlistitem"
      );
      const prefTabPromise = BrowserTestUtils.waitForNewTab(
        gBrowser,
        PRIVACY_PREF_URL,
        true
      );
      for (let i = 0; i < listItemElems.length; i++) {
        if (!listItemElems[i].collapsed) {
          await BrowserTestUtils.synthesizeKey("VK_DOWN", {}, browser);
        }
      }
      await BrowserTestUtils.synthesizeKey("VK_RETURN", {}, browser);
      info(`expecting tab: about:preferences#privacy opened`);
      const prefTab = await prefTabPromise;
      info(`expecting tab: about:preferences#privacy removed`);
      BrowserTestUtils.removeTab(prefTab);
      ok(
        true,
        "Tab: preferences#privacy was successfully opened by pressing enter on the footer"
      );

      await closePopup(browser);
    }
  );
});

add_task(async function test_click_on_footer() {
  await BrowserTestUtils.withNewTab(
    { gBrowser, url: URL },
    async function (browser) {
      const {
        autoCompletePopup: { richlistbox: itemsBox },
      } = browser;

      await openPopupOn(browser, "#organization");
      // Click on the footer
      let optionButton = itemsBox.querySelector(
        ".autocomplete-richlistitem:last-child"
      );
      while (optionButton.collapsed) {
        optionButton = optionButton.previousElementSibling;
      }
      optionButton = optionButton._optionButton;

      const prefTabPromise = BrowserTestUtils.waitForNewTab(
        gBrowser,
        PRIVACY_PREF_URL,
        true
      );
      // Make sure dropdown is visible before continuing mouse synthesizing.
      await BrowserTestUtils.waitForCondition(() =>
        BrowserTestUtils.isVisible(optionButton)
      );
      await EventUtils.synthesizeMouseAtCenter(optionButton, {});
      info(`expecting tab: about:preferences#privacy opened`);
      const prefTab = await prefTabPromise;
      info(`expecting tab: about:preferences#privacy removed`);
      BrowserTestUtils.removeTab(prefTab);
      ok(
        true,
        "Tab: preferences#privacy was successfully opened by clicking on the footer"
      );

      await closePopup(browser);
    }
  );
});

add_task(async function test_phishing_warning_single_category() {
  await BrowserTestUtils.withNewTab(
    { gBrowser, url: URL },
    async function (browser) {
      const {
        autoCompletePopup: { richlistbox: itemsBox },
      } = browser;

      await openPopupOn(browser, "#tel");
      const warningBox = itemsBox.querySelector(
        ".autocomplete-richlistitem:last-child"
      )._warningTextBox;
      ok(warningBox, "Got phishing warning box");
      await expectWarningText(browser, "Also autofills address");
      await closePopup(browser);
    }
  );
});

add_task(async function test_phishing_warning_complex_categories() {
  await BrowserTestUtils.withNewTab(
    { gBrowser, url: URL },
    async function (browser) {
      await openPopupOn(browser, "#street-address");

      await expectWarningText(browser, "Also autofills organization, email");
      await BrowserTestUtils.synthesizeKey("VK_DOWN", {}, browser);
      await expectWarningText(browser, "Autofills address");
      await BrowserTestUtils.synthesizeKey("VK_DOWN", {}, browser);
      await BrowserTestUtils.synthesizeKey("VK_DOWN", {}, browser);
      await expectWarningText(browser, "Also autofills organization, email");
      await BrowserTestUtils.synthesizeKey("VK_DOWN", {}, browser);
      await expectWarningText(browser, "Also autofills organization, email");

      await closePopup(browser);
    }
  );
});