Bug 1370218 - [Mac] Pressing backspace to remove a password in the password dialog (in preferences) should leave the dialog open. r?MattN
MozReview-Commit-ID: HtbUJUJgncK
--- a/browser/components/preferences/in-content-new/tests/browser.ini
+++ b/browser/components/preferences/in-content-new/tests/browser.ini
@@ -34,16 +34,17 @@ skip-if = os != "win" # This test tests
[browser_cookies_exceptions.js]
[browser_defaultbrowser_alwayscheck.js]
[browser_healthreport.js]
skip-if = true || !healthreport # Bug 1185403 for the "true"
[browser_homepages_filter_aboutpreferences.js]
[browser_layersacceleration.js]
[browser_masterpassword.js]
[browser_notifications_do_not_disturb.js]
+[browser_password_management.js]
[browser_performance.js]
skip-if = !e10s
[browser_performance_non_e10s.js]
skip-if = e10s
[browser_permissions_urlFieldHidden.js]
[browser_proxy_backup.js]
[browser_privacypane_1.js]
[browser_privacypane_3.js]
new file mode 100644
--- /dev/null
+++ b/browser/components/preferences/in-content-new/tests/browser_password_management.js
@@ -0,0 +1,73 @@
+"use strict";
+const PM_URL = "chrome://passwordmgr/content/passwordManager.xul";
+
+var passwordsDialog;
+
+add_task(async function test_setup() {
+ let pwmgr = Cc["@mozilla.org/login-manager;1"].
+ getService(Ci.nsILoginManager);
+ pwmgr.removeAllLogins();
+
+ // add login data
+ let nsLoginInfo = new Components.Constructor("@mozilla.org/login-manager/loginInfo;1",
+ Ci.nsILoginInfo, "init");
+ let login = new nsLoginInfo("http://example.com/", "http://example.com/", null,
+ "user", "password", "u1", "p1");
+ pwmgr.addLogin(login);
+
+ registerCleanupFunction(async function() {
+ pwmgr.removeAllLogins();
+ });
+});
+
+add_task(async function test_openPasswordSubDialog() {
+ // Undo the save password change.
+ registerCleanupFunction(async function() {
+ await ContentTask.spawn(gBrowser.selectedBrowser, null, function() {
+ let doc = content.document;
+ let savePasswordCheckBox = doc.getElementById("savePasswords");
+ if (savePasswordCheckBox.checked) {
+ savePasswordCheckBox.click();
+ }
+ });
+
+ gBrowser.removeCurrentTab();
+ });
+
+ await openPreferencesViaOpenPreferencesAPI("privacy", {leaveOpen: true});
+
+ let dialogOpened = promiseLoadSubDialog(PM_URL);
+
+ await ContentTask.spawn(gBrowser.selectedBrowser, null, function() {
+ let doc = content.document;
+ let savePasswordCheckBox = doc.getElementById("savePasswords");
+ Assert.ok(!savePasswordCheckBox.checked,
+ "Save Password CheckBox should be unchecked by default");
+ savePasswordCheckBox.click();
+
+ let showPasswordsButton = doc.getElementById("showPasswords");
+ showPasswordsButton.click();
+ });
+
+ passwordsDialog = await dialogOpened;
+});
+
+add_task(async function test_deletePasswordWithKey() {
+ let doc = passwordsDialog.document;
+
+ let tree = doc.getElementById("signonsTree");
+ Assert.equal(tree.view.rowCount, 1, "Row count should initially be 1");
+ tree.focus();
+ tree.view.selection.select(0);
+
+ if (AppConstants.platform == "macosx") {
+ EventUtils.synthesizeKey("VK_BACK_SPACE", {});
+ } else {
+ EventUtils.synthesizeKey("VK_DELETE", {});
+ }
+
+ await waitForCondition(() => tree.view.rowCount == 0);
+
+ is_element_visible(content.gSubDialog._dialogs[0]._box,
+ "Subdialog is visible after deleting an element");
+});
--- a/browser/components/preferences/in-content/tests/browser.ini
+++ b/browser/components/preferences/in-content/tests/browser.ini
@@ -24,16 +24,17 @@ skip-if = os != "win" # This test tests
[browser_connection.js]
[browser_connection_bug388287.js]
[browser_cookies_exceptions.js]
[browser_defaultbrowser_alwayscheck.js]
[browser_healthreport.js]
skip-if = true || !healthreport # Bug 1185403 for the "true"
[browser_homepages_filter_aboutpreferences.js]
[browser_notifications_do_not_disturb.js]
+[browser_password_management.js]
[browser_performance.js]
skip-if = !e10s
[browser_performance_non_e10s.js]
skip-if = e10s
[browser_permissions_urlFieldHidden.js]
[browser_proxy_backup.js]
[browser_privacypane_1.js]
[browser_privacypane_3.js]
new file mode 100644
--- /dev/null
+++ b/browser/components/preferences/in-content/tests/browser_password_management.js
@@ -0,0 +1,71 @@
+"use strict";
+const PM_URL = "chrome://passwordmgr/content/passwordManager.xul";
+
+var passwordsDialog;
+
+add_task(async function setup() {
+ Services.logins.removeAllLogins();
+
+ // add login data
+ let nsLoginInfo = new Components.Constructor("@mozilla.org/login-manager/loginInfo;1",
+ Ci.nsILoginInfo, "init");
+ let login = new nsLoginInfo("http://example.com/", "http://example.com/", null,
+ "user", "password", "u1", "p1");
+ Services.logins.addLogin(login);
+
+ registerCleanupFunction(async function() {
+ Services.logins.removeAllLogins();
+ });
+});
+
+add_task(async function test_openPasswordSubDialog() {
+ // Undo the save password change.
+ registerCleanupFunction(async function() {
+ await ContentTask.spawn(gBrowser.selectedBrowser, null, function() {
+ let doc = content.document;
+ let savePasswordCheckBox = doc.getElementById("savePasswords");
+ if (savePasswordCheckBox.checked) {
+ savePasswordCheckBox.click();
+ }
+ });
+
+ gBrowser.removeCurrentTab();
+ });
+
+ await openPreferencesViaOpenPreferencesAPI("security", null, {leaveOpen: true});
+
+ let dialogOpened = promiseLoadSubDialog(PM_URL);
+
+ await ContentTask.spawn(gBrowser.selectedBrowser, null, function() {
+ let doc = content.document;
+ let savePasswordCheckBox = doc.getElementById("savePasswords");
+ Assert.ok(!savePasswordCheckBox.checked,
+ "Save Password CheckBox should be unchecked by default");
+ savePasswordCheckBox.click();
+
+ let showPasswordsButton = doc.getElementById("showPasswords");
+ showPasswordsButton.click();
+ });
+
+ passwordsDialog = await dialogOpened;
+});
+
+add_task(async function test_deletePasswordWithKey() {
+ let doc = passwordsDialog.document;
+
+ let tree = doc.getElementById("signonsTree");
+ Assert.equal(tree.view.rowCount, 1, "Row count should initially be 1");
+ tree.focus();
+ tree.view.selection.select(0);
+
+ if (AppConstants.platform == "macosx") {
+ EventUtils.synthesizeKey("VK_BACK_SPACE", {});
+ } else {
+ EventUtils.synthesizeKey("VK_DELETE", {});
+ }
+
+ await waitForCondition(() => tree.view.rowCount == 0);
+
+ is_element_visible(content.gSubDialog._dialogs[0]._box,
+ "Subdialog is visible after deleting an element");
+});
--- a/toolkit/components/passwordmgr/content/passwordManager.js
+++ b/toolkit/components/passwordmgr/content/passwordManager.js
@@ -486,16 +486,17 @@ function HandleSignonKeyPress(e) {
// If editing is currently performed, don't do anything.
if (signonsTree.getAttribute("editing")) {
return;
}
if (e.keyCode == KeyboardEvent.DOM_VK_DELETE ||
(AppConstants.platform == "macosx" &&
e.keyCode == KeyboardEvent.DOM_VK_BACK_SPACE)) {
DeleteSignon();
+ e.preventDefault();
}
}
function getColumnByName(column) {
switch (column) {
case "hostname":
return document.getElementById("siteCol");
case "username":