Bug 1583796 - Re-sort and render the login list when breach notifications are updated without acting like a user-initiated sort. r=sfoster

Differential Revision: https://phabricator.services.mozilla.com/D47982

--HG--
extra : moz-landing-system : lando
This commit is contained in:
Jared Wein 2019-10-03 16:04:39 +00:00
parent 7a8544e664
commit 20802e4942
6 changed files with 28 additions and 24 deletions

View File

@ -171,9 +171,7 @@ export default class LoginList extends HTMLElement {
break;
}
case "change": {
this._applySort();
this.render();
this._list.scrollTop = 0;
this._applySortAndScrollToTop();
const extra = { sort_key: this._sortSelect.value };
recordTelemetryEvent({ object: "list", method: "sort", extra });
break;
@ -348,11 +346,7 @@ export default class LoginList extends HTMLElement {
const breachedSortOptionElement = this._sortSelect.namedItem("breached");
breachedSortOptionElement.hidden = false;
this._sortSelect.selectedIndex = breachedSortOptionElement.index;
this._sortSelect.dispatchEvent(new CustomEvent("input", { bubbles: true }));
this._sortSelect.dispatchEvent(
new CustomEvent("change", { bubbles: true })
);
this.render();
this._applySortAndScrollToTop();
}
/**
@ -477,6 +471,12 @@ export default class LoginList extends HTMLElement {
});
}
_applySortAndScrollToTop() {
this._applySort();
this.render();
this._list.scrollTop = 0;
}
_updateVisibleLoginCount(count) {
if (count != document.l10n.getAttributes(this._count).args.count) {
document.l10n.setAttributes(this._count, "login-list-count", {

View File

@ -6,19 +6,23 @@ requestLongerTimeout(2);
ChromeUtils.import("resource://testing-common/TelemetryTestUtils.jsm", this);
ChromeUtils.import("resource://testing-common/LoginTestUtils.jsm", this);
EXPECTED_BREACH = {
AddedDate: "2018-12-20T23:56:26Z",
BreachDate: "2018-12-16",
Domain: "breached.example.com",
Name: "Breached",
PwnCount: 1643100,
DataClasses: ["Email addresses", "Usernames", "Passwords", "IP addresses"],
_status: "synced",
id: "047940fe-d2fd-4314-b636-b4a952ee0043",
last_modified: "1541615610052",
schema: "1541615609018",
};
add_task(async function setup() {
let storageChangedPromised = TestUtils.topicObserved(
"passwordmgr-storage-changed",
(_, data) => data == "addLogin"
);
TEST_LOGIN1 = Services.logins.addLogin(TEST_LOGIN1);
await storageChangedPromised;
storageChangedPromised = TestUtils.topicObserved(
"passwordmgr-storage-changed",
(_, data) => data == "addLogin"
);
TEST_LOGIN2 = Services.logins.addLogin(TEST_LOGIN2);
await storageChangedPromised;
TEST_LOGIN1 = await addLogin(TEST_LOGIN1);
TEST_LOGIN2 = await addLogin(TEST_LOGIN2);
TEST_LOGIN3 = await addLogin(TEST_LOGIN3);
await BrowserTestUtils.openNewForegroundTab({
gBrowser,
url: "about:logins",
@ -68,7 +72,7 @@ add_task(async function test_telemetry_events() {
let promiseNewTab = BrowserTestUtils.waitForNewTab(
gBrowser,
TEST_LOGIN2.origin + "/"
TEST_LOGIN3.origin + "/"
);
await ContentTask.spawn(gBrowser.selectedBrowser, null, async function() {
let loginItem = content.document.querySelector("login-item");
@ -76,7 +80,7 @@ add_task(async function test_telemetry_events() {
originInput.click();
});
let newTab = await promiseNewTab;
ok(true, "New tab opened to " + TEST_LOGIN2.origin);
ok(true, "New tab opened to " + TEST_LOGIN3.origin);
BrowserTestUtils.removeTab(newTab);
await LoginTestUtils.telemetry.waitForEventCount(5);

View File

@ -15,7 +15,6 @@ EXPECTED_BREACH = {
};
add_task(async function setup() {
TEST_LOGIN3.QueryInterface(Ci.nsILoginMetaInfo).timePasswordChanged = 123456;
TEST_LOGIN3 = await addLogin(TEST_LOGIN3);
await BrowserTestUtils.openNewForegroundTab({
gBrowser,

View File

@ -36,7 +36,6 @@ add_task(async function test_added_login_shows_breach_warning() {
);
});
TEST_LOGIN3.QueryInterface(Ci.nsILoginMetaInfo).timePasswordChanged = 123456;
TEST_LOGIN3 = await addLogin(TEST_LOGIN3);
await ContentTask.spawn(browser, TEST_LOGIN3.guid, async aTestLogin3Guid => {
let loginList = Cu.waiveXrays(content.document.querySelector("login-list"));

View File

@ -42,6 +42,7 @@ let TEST_LOGIN3 = new nsLoginInfo(
"breachedLogin",
"password"
);
TEST_LOGIN3.QueryInterface(Ci.nsILoginMetaInfo).timePasswordChanged = 123456;
async function addLogin(login) {
let storageChangedPromised = TestUtils.topicObserved(

View File

@ -544,6 +544,7 @@ this.LoginTestUtils.telemetry = {
}
events = events.filter(e => e[1] == category);
dump(`Waiting for ${count} events, got ${events.length}\n`);
return events.length == count ? events : null;
}, "waiting for telemetry event count of: " + count);
Assert.equal(events.length, count, "waiting for telemetry event count");