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

add_task(async function test_first_time_save() {
  let addresses = await getAddresses();
  is(addresses.length, 0, "No address in storage");
  await SpecialPowers.pushPrefEnv({
    set: [
      [FTU_PREF, true],
      [ENABLED_AUTOFILL_ADDRESSES_PREF, true],
      [AUTOFILL_ADDRESSES_AVAILABLE_PREF, "on"],
      [ENABLED_AUTOFILL_ADDRESSES_CAPTURE_PREF, true],
    ],
  });

  let onAdded = waitForStorageChangedEvents("add");
  await BrowserTestUtils.withNewTab(
    { gBrowser, url: FORM_URL },
    async function (browser) {
      let onPopupShown = waitForPopupShown();
      let tabPromise = BrowserTestUtils.waitForNewTab(
        gBrowser,
        "about:preferences#privacy"
      );
      await focusUpdateSubmitForm(browser, {
        focusSelector: "#organization",
        newValues: {
          "#organization": "Sesame Street",
          "#street-address": "123 Sesame Street",
          "#tel": "1-345-345-3456",
        },
      });

      await onPopupShown;
      let cb = getDoorhangerCheckbox();
      ok(cb.hidden, "Sync checkbox should be hidden");
      // Open the panel via main button
      await clickDoorhangerButton(MAIN_BUTTON);
      let tab = await tabPromise;
      ok(tab, "Privacy panel opened");
      BrowserTestUtils.removeTab(tab);
    }
  );
  await onAdded;

  addresses = await getAddresses();
  is(addresses.length, 1, "Address saved");
  let ftuPref = SpecialPowers.getBoolPref(FTU_PREF);
  is(ftuPref, false, "First time use flag is false");
});

add_task(async function test_non_first_time_save() {
  await SpecialPowers.pushPrefEnv({
    set: [
      [ENABLED_AUTOFILL_ADDRESSES_PREF, true],
      [AUTOFILL_ADDRESSES_AVAILABLE_PREF, "on"],
      [ENABLED_AUTOFILL_ADDRESSES_CAPTURE_PREF, true],
    ],
  });
  let addresses = await getAddresses();
  let ftuPref = SpecialPowers.getBoolPref(FTU_PREF);
  is(ftuPref, false, "First time use flag is false");
  is(addresses.length, 1, "1 address in storage");

  let onAdded = waitForStorageChangedEvents("add");
  await BrowserTestUtils.withNewTab(
    { gBrowser, url: FORM_URL },
    async function (browser) {
      await focusUpdateSubmitForm(browser, {
        focusSelector: "#organization",
        newValues: {
          "#organization": "Mozilla",
          "#street-address": "331 E. Evelyn Avenue",
          "#tel": "1-650-903-0800",
        },
      });

      await sleep(1000);
      is(PopupNotifications.panel.state, "closed", "Doorhanger is hidden");
    }
  );
  await onAdded;

  addresses = await getAddresses();
  is(addresses.length, 2, "Another address saved");

  await SpecialPowers.popPrefEnv();
});

add_task(async function test_first_time_save_with_sync_account() {
  await SpecialPowers.pushPrefEnv({
    set: [
      [FTU_PREF, true],
      [ENABLED_AUTOFILL_ADDRESSES_PREF, true],
      [AUTOFILL_ADDRESSES_AVAILABLE_PREF, "on"],
      [SYNC_USERNAME_PREF, "foo@bar.com"],
      [SYNC_ADDRESSES_PREF, false],
    ],
  });

  let onAdded = waitForStorageChangedEvents("add");
  await BrowserTestUtils.withNewTab(
    { gBrowser, url: FORM_URL },
    async function (browser) {
      let onPopupShown = waitForPopupShown();
      let tabPromise = BrowserTestUtils.waitForNewTab(
        gBrowser,
        "about:preferences#privacy-address-autofill"
      );
      await focusUpdateSubmitForm(browser, {
        focusSelector: "#organization",
        newValues: {
          "#organization": "Foobar",
          "#email": "foo@bar.com",
          "#tel": "1-234-567-8900",
        },
      });

      await onPopupShown;
      let cb = getDoorhangerCheckbox();
      ok(!cb.hidden, "Sync checkbox should be visible");

      is(cb.checked, false, "Checkbox state should match addresses sync state");
      cb.click();
      is(
        SpecialPowers.getBoolPref(SYNC_ADDRESSES_PREF),
        true,
        "addresses sync should be enabled after checked"
      );
      // Open the panel via main button
      await clickDoorhangerButton(MAIN_BUTTON);
      let tab = await tabPromise;
      ok(tab, "Privacy panel opened");
      BrowserTestUtils.removeTab(tab);
    }
  );
  await onAdded;

  let ftuPref = SpecialPowers.getBoolPref(FTU_PREF);
  is(ftuPref, false, "First time use flag is false");

  await SpecialPowers.popPrefEnv();
});