summaryrefslogtreecommitdiffstats
path: root/browser/components/aboutlogins/tests/browser/browser_noLoginsView.js
blob: b86304aac1b0cfda8315f0d97ce836f1f61b2d46 (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
/* Any copyright is dedicated to the Public Domain.
 * http://creativecommons.org/publicdomain/zero/1.0/ */

add_setup(async function () {
  await BrowserTestUtils.openNewForegroundTab({
    gBrowser,
    url: "about:logins",
  });
  registerCleanupFunction(() => {
    BrowserTestUtils.removeTab(gBrowser.selectedTab);
  });
});

add_task(async function test_no_logins_class() {
  let { platform } = AppConstants;
  let wizardPromise;

  // The import link is hidden on Linux, so we don't wait for the migration
  // wizard to open on that platform.
  if (AppConstants.platform != "linux") {
    wizardPromise = BrowserTestUtils.waitForMigrationWizard(window);
  }

  await SpecialPowers.spawn(
    gBrowser.selectedBrowser,
    [platform],
    async aPlatform => {
      let loginList = content.document.querySelector("login-list");

      Assert.ok(
        content.document.documentElement.classList.contains("no-logins"),
        "root should be in no logins view"
      );
      Assert.ok(
        loginList.classList.contains("no-logins"),
        "login-list should be in no logins view"
      );

      let loginIntro = Cu.waiveXrays(
        content.document.querySelector("login-intro")
      );
      let loginItem = content.document.querySelector("login-item");
      let loginListIntro = loginList.shadowRoot.querySelector(".intro");
      let loginListList = loginList.shadowRoot.querySelector("ol");

      Assert.ok(
        !ContentTaskUtils.is_hidden(loginIntro),
        "login-intro should be shown in no logins view"
      );
      Assert.ok(
        !ContentTaskUtils.is_hidden(loginListIntro),
        "login-list intro should be shown in no logins view"
      );

      Assert.ok(
        ContentTaskUtils.is_hidden(loginItem),
        "login-item should be hidden in no logins view"
      );
      Assert.ok(
        ContentTaskUtils.is_hidden(loginListList),
        "login-list logins list should be hidden in no logins view"
      );
      Assert.equal(
        content.document.l10n.getAttributes(
          loginIntro.shadowRoot.querySelector(".heading")
        ).id,
        "about-logins-login-intro-heading-logged-out2",
        "The default message should be the non-logged-in message"
      );
      Assert.ok(
        loginIntro.shadowRoot
          .querySelector("a.intro-help-link")
          .href.includes("password-manager-remember-delete-edit-logins"),
        "Check support href populated"
      );

      loginIntro.updateState(Cu.cloneInto({ loggedIn: true }, content));

      Assert.equal(
        content.document.l10n.getAttributes(
          loginIntro.shadowRoot.querySelector(".heading")
        ).id,
        "about-logins-login-intro-heading-logged-in",
        "When logged in the message should update"
      );

      let importClass = Services.prefs.getBoolPref(
        "signon.management.page.fileImport.enabled"
      )
        ? ".intro-import-text.file-import"
        : ".intro-import-text.no-file-import";
      Assert.equal(
        ContentTaskUtils.is_hidden(
          loginIntro.shadowRoot.querySelector(importClass)
        ),
        aPlatform == "linux",
        "the import link should be hidden on Linux builds"
      );
      if (aPlatform == "linux") {
        // End the test now for Linux since the link is hidden.
        return;
      }
      loginIntro.shadowRoot.querySelector(importClass + " > a").click();
      info("waiting for MigrationWizard to open");
    }
  );
  if (AppConstants.platform == "linux") {
    // End the test now for Linux since the link is hidden.
    return;
  }
  let wizard = await wizardPromise;
  Assert.ok(wizard, "Migrator window opened");
  await BrowserTestUtils.closeMigrationWizard(wizard);
});

add_task(
  async function login_selected_when_login_added_and_in_no_logins_view() {
    await SpecialPowers.spawn(gBrowser.selectedBrowser, [], async () => {
      let loginList = content.document.querySelector("login-list");
      let loginItem = content.document.querySelector("login-item");
      let loginIntro = content.document.querySelector("login-intro");
      Assert.ok(
        loginList.classList.contains("empty-search"),
        "login-list should be showing no logins view from a search with no results"
      );
      Assert.ok(
        loginList.classList.contains("no-logins"),
        "login-list should be showing no logins view since there are no saved logins"
      );
      Assert.ok(
        !loginList.classList.contains("create-login-selected"),
        "login-list should not be in create-login-selected mode"
      );
      Assert.ok(
        loginItem.classList.contains("no-logins"),
        "login-item should be marked as having no-logins"
      );
      Assert.ok(
        ContentTaskUtils.is_hidden(loginItem),
        "login-item should be hidden"
      );
      Assert.ok(
        !ContentTaskUtils.is_hidden(loginIntro),
        "login-intro should be visible"
      );
    });

    TEST_LOGIN1 = await addLogin(TEST_LOGIN1);

    await SpecialPowers.spawn(
      gBrowser.selectedBrowser,
      [TEST_LOGIN1.guid],
      async testLogin1Guid => {
        let loginList = content.document.querySelector("login-list");
        let loginItem = content.document.querySelector("login-item");
        let loginIntro = content.document.querySelector("login-intro");
        await ContentTaskUtils.waitForCondition(() => {
          return !loginList.classList.contains("no-logins");
        }, "waiting for login-list to leave the no-logins view");
        Assert.ok(
          !loginList.classList.contains("empty-search"),
          "login-list should not be showing no logins view since one login exists"
        );
        Assert.ok(
          !loginList.classList.contains("no-logins"),
          "login-list should not be showing no logins view since one login exists"
        );
        Assert.ok(
          !loginList.classList.contains("create-login-selected"),
          "login-list should not be in create-login-selected mode"
        );
        Assert.equal(
          loginList.shadowRoot.querySelector(
            ".login-list-item.selected[data-guid]"
          ).dataset.guid,
          testLogin1Guid,
          "the login that was just added should be selected"
        );
        Assert.ok(
          !loginItem.classList.contains("no-logins"),
          "login-item should not be marked as having no-logins"
        );
        Assert.equal(
          Cu.waiveXrays(loginItem)._login.guid,
          testLogin1Guid,
          "the login-item should have the newly added login selected"
        );
        Assert.ok(
          !ContentTaskUtils.is_hidden(loginItem),
          "login-item should be visible"
        );
        Assert.ok(
          ContentTaskUtils.is_hidden(loginIntro),
          "login-intro should be hidden"
        );
      }
    );
  }
);