Bug 1525976 - Implement a basic browser-chrome mochitest for Firefox Monitor. r=johannh
authorNihanth Subramanya <nhnt11@gmail.com>
Sat, 27 Apr 2019 21:39:39 +0000
changeset 530768 19bf83121d3138bfd7718e93ce8b05e478b079b7
parent 530767 f3c896ea6e1693af54eb6515aad514869d68f057
child 530769 d42051b63b49d203bfa0abb1e20818d65731c000
push id11265
push userffxbld-merge
push dateMon, 13 May 2019 10:53:39 +0000
treeherdermozilla-beta@77e0fe8dbdd3 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersjohannh
bugs1525976
milestone68.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
@@ -20,10 +20,12 @@ FINAL_TARGET_FILES.features['fxmonitor@m
 ]
 
 FINAL_TARGET_FILES.features['fxmonitor@mozilla.org']['privileged'] += [
   'privileged/api.js',
   'privileged/FirefoxMonitor.css',
   'privileged/schema.json'
 ]
 
+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"]],
+  });
+});