Bug 1525976 - Implement a basic browser-chrome mochitest for Firefox Monitor. r=johannh
☠☠ backed out by 091fdeb8c9ca ☠ ☠
authorNihanth Subramanya <nhnt11@gmail.com>
Sun, 17 Mar 2019 20:32:55 +0000
changeset 525603 d8ead6a3396d08a4f5b38188ae5130a484b39ea3
parent 525602 7444d00f6a08178777d83c4a4ab61da6c88c2b69
child 525604 0699c6be752a56ecf666e4611959ac3be7a90841
push id2032
push userffxbld-merge
push dateMon, 13 May 2019 09:36:57 +0000
treeherdermozilla-release@455c1065dcbe [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersjohannh
bugs1525976
milestone67.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1525976 - Implement a basic browser-chrome mochitest for Firefox Monitor. r=johannh Differential Revision: https://phabricator.services.mozilla.com/D21551
browser/extensions/fxmonitor/moz.build
browser/extensions/fxmonitor/test/browser/.eslintrc.js
browser/extensions/fxmonitor/test/browser/browser.ini
browser/extensions/fxmonitor/test/browser/browser_fxmonitor_doorhanger.js
--- a/browser/extensions/fxmonitor/moz.build
+++ b/browser/extensions/fxmonitor/moz.build
@@ -27,10 +27,12 @@ FINAL_TARGET_FILES.features['fxmonitor@m
 ]
 
 FINAL_TARGET_FILES.features['fxmonitor@mozilla.org']['privileged']['subscripts'] += [
   'privileged/subscripts/EveryWindow.jsm',
   'privileged/subscripts/Globals.jsm',
   'privileged/subscripts/PanelUI.jsm'
 ]
 
+BROWSER_CHROME_MANIFESTS += ['test/browser/browser.ini']
+
 with Files('**'):
   BUG_COMPONENT = ('Firefox', 'Firefox Monitor')
new file mode 100644
--- /dev/null
+++ b/browser/extensions/fxmonitor/test/browser/.eslintrc.js
@@ -0,0 +1,7 @@
+"use strict";
+
+module.exports = {
+  "extends": [
+    "plugin:mozilla/browser-test"
+  ]
+};
new file mode 100644
--- /dev/null
+++ b/browser/extensions/fxmonitor/test/browser/browser.ini
@@ -0,0 +1,1 @@
+[browser_fxmonitor_doorhanger.js]
new file mode 100644
--- /dev/null
+++ b/browser/extensions/fxmonitor/test/browser/browser_fxmonitor_doorhanger.js
@@ -0,0 +1,47 @@
+"use strict";
+
+ChromeUtils.defineModuleGetter(this, "RemoteSettings",
+                               "resource://services-settings/remote-settings.js");
+
+const kNotificationId = "fxmonitor";
+const kRemoteSettingsKey = "fxmonitor-breaches";
+
+async function fxmonitorNotificationShown() {
+  await TestUtils.waitForCondition(() => {
+    return PopupNotifications.getNotification(kNotificationId);
+  });
+  ok(true, "Firefox Monitor PopupNotification was added.");
+}
+
+add_task(async function test_remotesettings_get() {
+  // Pre-populate the Remote Settings collection with a breach.
+  let collection = await RemoteSettings(kRemoteSettingsKey).openCollection();
+  let BreachDate = new Date();
+  let AddedDate = new Date();
+  await collection.create({
+    Domain: "example.com",
+    Name: "Example Site",
+    BreachDate: `${BreachDate.getFullYear()}-${BreachDate.getMonth()}-${BreachDate.getDate()}`,
+    AddedDate: `${AddedDate.getFullYear()}-${AddedDate.getMonth()}-${AddedDate.getDate()}`,
+    PwnCount: 1000000,
+  });
+  await collection.db.saveLastModified(1234567);
+
+  // Enable the extension.
+  await SpecialPowers.pushPrefEnv({
+    set: [["extensions.fxmonitor.enabled", true]],
+  });
+
+  // Open a tab and wait for the alert.
+  let tab = await BrowserTestUtils.openNewForegroundTab(gBrowser, "http://example.com");
+  await fxmonitorNotificationShown();
+
+  // Clean up.
+  BrowserTestUtils.removeTab(tab);
+  await collection.clear();
+  await SpecialPowers.pushPrefEnv({
+    clear: [["extensions.fxmonitor.enabled"],
+            ["extensions.fxmonitor.warnedHosts"],
+            ["extensions.fxmonitor.firstAlertShown"]],
+  });
+});