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

const URL = BASE_URL + "autocomplete_basic.html";

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

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.is_visible(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, "Autofills phone");
      is(
        warningBox.ownerGlobal.getComputedStyle(warningBox).backgroundColor,
        "rgba(248, 232, 28, 0.2)",
        "Check warning text background color"
      );

      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);
    }
  );
});