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
authorJared Wein <jwein@mozilla.com>
Sat, 28 Sep 2019 02:55:26 -0400
changeset 555495 4b5d122c045dd17e44a00dee9428e4fa9ddd2f15
parent 555494 58738da1986f2cfc22174957e597de1d22af5b43
child 555496 233ae8d44b8e56d0d1d9273e20b1fadbc2a35a17
push id2165
push userffxbld-merge
push dateMon, 14 Oct 2019 16:30:58 +0000
treeherdermozilla-release@0eae18af659f [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersMattN
bugs1583398
milestone70.0
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
browser/components/aboutlogins/tests/browser/browser_breachAlertDismissals.js
browser/components/aboutlogins/tests/browser/browser_breachAlertShowingForAddedLogin.js
browser/components/aboutlogins/tests/browser/head.js
--- a/browser/components/aboutlogins/tests/browser/browser_breachAlertDismissals.js
+++ b/browser/components/aboutlogins/tests/browser/browser_breachAlertDismissals.js
@@ -1,53 +1,39 @@
 /* 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,
     url: "about:logins",
   });
   registerCleanupFunction(() => {
     BrowserTestUtils.removeTab(gBrowser.selectedTab);
     Services.logins.removeAllLogins();
   });
 });
 
 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");
     let breachAlertVisible = await ContentTaskUtils.waitForCondition(() => {
       return !breachAlert.hidden;
     }, "Waiting for breach alert to be visible");
     ok(
       breachAlertVisible,
--- a/browser/components/aboutlogins/tests/browser/browser_breachAlertShowingForAddedLogin.js
+++ b/browser/components/aboutlogins/tests/browser/browser_breachAlertShowingForAddedLogin.js
@@ -1,63 +1,47 @@
 /* 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();
   });
 });
 
 add_task(async function test_added_login_shows_breach_warning() {
   let browser = gBrowser.selectedBrowser;
   await ContentTask.spawn(browser, null, async () => {
     let loginList = Cu.waiveXrays(content.document.querySelector("login-list"));
     is(
       loginList._loginGuidsSortedOrder.length,
       0,
       "the login list should be empty"
     );
   });
 
+  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"));
     is(
       loginList._loginGuidsSortedOrder.length,
       1,
       "one login should be in the list"
     );
--- a/browser/components/aboutlogins/tests/browser/head.js
+++ b/browser/components/aboutlogins/tests/browser/head.js
@@ -1,11 +1,18 @@
 /* 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,
   "init"
 );
 
 let TEST_LOGIN1 = new nsLoginInfo(
   "https://example.com",
@@ -50,8 +57,30 @@ async function addLogin(login) {
     matchData.setPropertyAsAUTF8String("guid", login.guid);
     if (!Services.logins.searchLogins(matchData).length) {
       return;
     }
     Services.logins.removeLogin(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();
+  });
+});