Bug 1583398 - Store breaches in the remote store for tests when expected, and otherwise prevent all of the fxmonitor logspam when running aboutlogins mochitest-browser tests. r=MattN

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

--HG--
extra : moz-landing-system : lando
This commit is contained in:
Jared Wein 2019-10-03 15:32:47 +00:00
parent e6cfc97a49
commit c439f9c236
3 changed files with 55 additions and 56 deletions

View File

@ -1,26 +1,21 @@
/* Any copyright is dedicated to the Public Domain.
* http://creativecommons.org/publicdomain/zero/1.0/ */
let { LoginBreaches } = ChromeUtils.import(
"resource:///modules/LoginBreaches.jsm"
);
const TEST_BREACHES = [
{
AddedDate: "2019-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",
},
];
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() {
TEST_LOGIN3.QueryInterface(Ci.nsILoginMetaInfo).timePasswordChanged = 123456;
TEST_LOGIN3 = await addLogin(TEST_LOGIN3);
await BrowserTestUtils.openNewForegroundTab({
gBrowser,
@ -34,15 +29,6 @@ add_task(async function setup() {
add_task(async function test_show_login() {
let browser = gBrowser.selectedBrowser;
TEST_LOGIN3.timePasswordChanged = 12345;
let testBreaches = await LoginBreaches.getPotentialBreachesByLoginGUID(
[TEST_LOGIN3],
TEST_BREACHES
);
browser.messageManager.sendAsyncMessage(
"AboutLogins:SetBreaches",
testBreaches
);
await ContentTask.spawn(browser, null, async () => {
let loginItem = Cu.waiveXrays(content.document.querySelector("login-item"));
let breachAlert = loginItem.shadowRoot.querySelector(".breach-alert");

View File

@ -1,42 +1,25 @@
/* Any copyright is dedicated to the Public Domain.
* http://creativecommons.org/publicdomain/zero/1.0/ */
let { LoginBreaches } = ChromeUtils.import(
"resource:///modules/LoginBreaches.jsm"
);
const TEST_BREACHES = [
{
AddedDate: "2019-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",
},
];
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 oldGetPotentialBreachesByLoginGUID =
LoginBreaches.getPotentialBreachesByLoginGUID;
LoginBreaches.getPotentialBreachesByLoginGUID = logins => {
if (!logins.length) {
return new Map();
}
let breaches = new Map();
breaches.set(logins[0].guid, TEST_BREACHES[0]);
return breaches;
};
await BrowserTestUtils.openNewForegroundTab({
gBrowser,
url: "about:logins",
});
registerCleanupFunction(() => {
LoginBreaches.getPotentialBreachesByLoginGUID = oldGetPotentialBreachesByLoginGUID;
BrowserTestUtils.removeTab(gBrowser.selectedTab);
Services.logins.removeAllLogins();
});
@ -53,6 +36,7 @@ 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

@ -1,6 +1,13 @@
/* Any copyright is dedicated to the Public Domain.
* http://creativecommons.org/publicdomain/zero/1.0/ */
let { LoginBreaches } = ChromeUtils.import(
"resource:///modules/LoginBreaches.jsm"
);
let { RemoteSettings } = ChromeUtils.import(
"resource://services-settings/remote-settings.js"
);
let nsLoginInfo = new Components.Constructor(
"@mozilla.org/login-manager/loginInfo;1",
Ci.nsILoginInfo,
@ -55,3 +62,25 @@ async function addLogin(login) {
});
return login;
}
let EXPECTED_BREACH = null;
add_task(async function setup() {
const collection = await RemoteSettings(
LoginBreaches.REMOTE_SETTINGS_COLLECTION
).openCollection();
if (EXPECTED_BREACH) {
await collection.create(EXPECTED_BREACH, {
useRecordId: true,
});
}
await collection.db.saveLastModified(42);
if (EXPECTED_BREACH) {
await RemoteSettings(LoginBreaches.REMOTE_SETTINGS_COLLECTION).emit(
"sync",
{ data: { current: [EXPECTED_BREACH] } }
);
}
registerCleanupFunction(async () => {
await collection.clear();
});
});