Bug 1529729 - Change Saved Logins menu items to open a pref-controlled URI, if set. r=jaws
authorMatthew Noorenberghe <mozilla@noorenberghe.ca>
Thu, 14 Mar 2019 04:53:47 +0000
changeset 521828 30dfd6603f7983fcdc0f970cf80de64c1424f527
parent 521827 082a7bbf945ae8c936b9718050f63b8e82489029
child 521829 e4a6f915841ad2c6b709d3de756cf5dd1b78a5db
push id10867
push userdvarga@mozilla.com
push dateThu, 14 Mar 2019 15:20:45 +0000
treeherdermozilla-beta@abad13547875 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersjaws
bugs1529729
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 1529729 - Change Saved Logins menu items to open a pref-controlled URI, if set. r=jaws If `signon.management.overrideURI` is set, open that URI in a new tab instead of opening passwordManager.xul in a window. Differential Revision: https://phabricator.services.mozilla.com/D23204
toolkit/components/passwordmgr/LoginHelper.jsm
toolkit/components/passwordmgr/test/browser/browser.ini
toolkit/components/passwordmgr/test/browser/browser_autocomplete_footer.js
toolkit/components/passwordmgr/test/browser/browser_openPasswordManager.js
--- a/toolkit/components/passwordmgr/LoginHelper.jsm
+++ b/toolkit/components/passwordmgr/LoginHelper.jsm
@@ -23,37 +23,38 @@ const {XPCOMUtils} = ChromeUtils.import(
 
 /**
  * Contains functions shared by different Login Manager components.
  */
 var LoginHelper = {
   debug: null,
   enabled: null,
   formlessCaptureEnabled: null,
+  insecureAutofill: null,
+  managementURI: null,
+  privateBrowsingCaptureEnabled: null,
   schemeUpgrades: null,
-  insecureAutofill: null,
-  privateBrowsingCaptureEnabled: null,
   showAutoCompleteFooter: null,
 
   init() {
     // Watch for pref changes to update cached pref values.
     Services.prefs.addObserver("signon.", () => this.updateSignonPrefs());
     this.updateSignonPrefs();
   },
 
   updateSignonPrefs() {
     this.autofillForms = Services.prefs.getBoolPref("signon.autofillForms");
     this.autofillAutocompleteOff = Services.prefs.getBoolPref("signon.autofillForms.autocompleteOff");
     this.debug = Services.prefs.getBoolPref("signon.debug");
     this.enabled = Services.prefs.getBoolPref("signon.rememberSignons");
     this.formlessCaptureEnabled = Services.prefs.getBoolPref("signon.formlessCapture.enabled");
     this.insecureAutofill = Services.prefs.getBoolPref("signon.autofillForms.http");
+    this.managementURI = Services.prefs.getStringPref("signon.management.overrideURI", null);
     this.privateBrowsingCaptureEnabled =
       Services.prefs.getBoolPref("signon.privateBrowsingCapture.enabled");
-
     this.schemeUpgrades = Services.prefs.getBoolPref("signon.schemeUpgrades");
     this.showAutoCompleteFooter = Services.prefs.getBoolPref("signon.showAutoCompleteFooter");
     this.storeWhenAutocompleteOff = Services.prefs.getBoolPref("signon.storeWhenAutocompleteOff");
   },
 
   createLogger(aLogPrefix) {
     let getMaxLogLevel = () => {
       return this.debug ? "Debug" : "Warn";
@@ -593,19 +594,25 @@ var LoginHelper = {
 
   /**
    * Open the password manager window.
    *
    * @param {Window} window
    *                 the window from where we want to open the dialog
    *
    * @param {string} [filterString=""]
-   *                 the filterString parameter to pass to the login manager dialog
+   *                 the domain (not origin) to pass to the login manager dialog
+   *                 to pre-filter the results
    */
   openPasswordManager(window, filterString = "") {
+    if (this.managementURI && window.openTrustedLinkIn) {
+      let managementURL = this.managementURI.replace("%DOMAIN%", window.encodeURIComponent(filterString));
+      window.openTrustedLinkIn(managementURL, "tab");
+      return;
+    }
     let win = Services.wm.getMostRecentWindow("Toolkit:PasswordManager");
     if (win) {
       win.setFilter(filterString);
       win.focus();
     } else {
       window.openDialog("chrome://passwordmgr/content/passwordManager.xul",
                         "Toolkit:PasswordManager", "",
                         {filterString});
--- a/toolkit/components/passwordmgr/test/browser/browser.ini
+++ b/toolkit/components/passwordmgr/test/browser/browser.ini
@@ -66,16 +66,17 @@ skip-if = verify
 [browser_insecurePasswordConsoleWarning.js]
 skip-if = verify
 [browser_master_password_autocomplete.js]
 [browser_notifications.js]
 [browser_notifications_username.js]
 [browser_notifications_password.js]
 [browser_notifications_2.js]
 skip-if = os == "linux" # Bug 1272849 Main action button disabled state intermittent
+[browser_openPasswordManager.js]
 [browser_passwordmgr_editing.js]
 skip-if = os == "linux"
 [browser_context_menu.js]
 [browser_context_menu_iframe.js]
 [browser_passwordmgr_contextmenu.js]
 subsuite = clipboard
 [browser_passwordmgr_fields.js]
 [browser_passwordmgr_observers.js]
--- a/toolkit/components/passwordmgr/test/browser/browser_autocomplete_footer.js
+++ b/toolkit/components/passwordmgr/test/browser/browser_autocomplete_footer.js
@@ -1,13 +1,12 @@
 "use strict";
 
 const TEST_HOSTNAME = "https://example.com";
 const BASIC_FORM_PAGE_PATH = DIRECTORY_PATH + "form_basic.html";
-const PWMGR_DLG = "chrome://passwordmgr/content/passwordManager.xul";
 
 function loginList() {
   return [
     LoginTestUtils.testData.formLogin({
       hostname: "https://example.com",
       formSubmitURL: "https://example.com",
       username: "username",
       password: "password",
new file mode 100644
--- /dev/null
+++ b/toolkit/components/passwordmgr/test/browser/browser_openPasswordManager.js
@@ -0,0 +1,60 @@
+const PREF_MANAGEMENT_URI = "signon.management.overrideURI";
+
+function resetPrefs() {
+  Services.prefs.clearUserPref(PREF_MANAGEMENT_URI);
+}
+
+registerCleanupFunction(resetPrefs);
+
+add_task(async function test_noFilter() {
+  LoginHelper.openPasswordManager(window);
+  await TestUtils.waitForCondition(() => {
+    return Services.wm.getMostRecentWindow("Toolkit:PasswordManager") !== null;
+  }, "Waiting for the password manager dialog to open");
+  let win = Services.wm.getMostRecentWindow("Toolkit:PasswordManager");
+  ok(win, "Login dialog was opened");
+  await BrowserTestUtils.closeWindow(win);
+  await TestUtils.waitForCondition(() => {
+    return Services.wm.getMostRecentWindow("Toolkit:PasswordManager") === null;
+  }, "Waiting for the password manager dialog to close");
+});
+
+add_task(async function test_filter() {
+  // Greek IDN for example.test
+  let domain = "παράδειγμα.δοκιμή";
+  LoginHelper.openPasswordManager(window, domain);
+  await TestUtils.waitForCondition(() => {
+    return Services.wm.getMostRecentWindow("Toolkit:PasswordManager") !== null;
+  }, "Waiting for the password manager dialog to open");
+  let win = Services.wm.getMostRecentWindow("Toolkit:PasswordManager");
+  await TestUtils.waitForCondition(() => {
+    return win.document.getElementById("filter").value == domain;
+  }, "Waiting for the search string to filter logins");
+  ok(win, "Login dialog was opened with a domain filter");
+  await BrowserTestUtils.closeWindow(win);
+  await TestUtils.waitForCondition(() => {
+    return Services.wm.getMostRecentWindow("Toolkit:PasswordManager") === null;
+  }, "Waiting for the password manager dialog to close");
+});
+
+add_task(async function test_management_overrideURI_noFilter() {
+  Services.prefs.setStringPref(PREF_MANAGEMENT_URI, "about:logins?filter=%DOMAIN%");
+  let tabOpenPromise = BrowserTestUtils.waitForNewTab(gBrowser, "about:logins?filter=");
+  LoginHelper.openPasswordManager(window);
+  let tab = await tabOpenPromise;
+  ok(tab, "Got the new tab");
+  BrowserTestUtils.removeTab(tab);
+  resetPrefs();
+});
+
+
+add_task(async function test_management_overrideURI_filter() {
+  Services.prefs.setStringPref(PREF_MANAGEMENT_URI, "about:logins?filter=%DOMAIN%");
+  let tabOpenPromise = BrowserTestUtils.waitForNewTab(gBrowser, "about:logins?filter=%CF%80%CE%B1%CF%81%CE%AC%CE%B4%CE%B5%CE%B9%CE%B3%CE%BC%CE%B1.%CE%B4%CE%BF%CE%BA%CE%B9%CE%BC%CE%AE");
+  // Greek IDN for example.test
+  LoginHelper.openPasswordManager(window, "παράδειγμα.δοκιμή");
+  let tab = await tabOpenPromise;
+  ok(tab, "Got the new tab with a domain filter");
+  BrowserTestUtils.removeTab(tab);
+  resetPrefs();
+});