mirror of
https://gitlab.winehq.org/wine/wine-gecko.git
synced 2024-09-13 09:24:08 -07:00
Bug 1189428 - Add edit options to the password manager context menu. r=rittme,rchtara
This commit is contained in:
parent
61d6a04a99
commit
4c67c12461
@ -411,16 +411,44 @@ function CopyUsername() {
|
||||
Services.telemetry.getHistogramById("PWMGR_MANAGE_COPIED_USERNAME").add(1);
|
||||
}
|
||||
|
||||
function UpdateCopyPassword() {
|
||||
var singleSelection = (signonsTreeView.selection.count == 1);
|
||||
var passwordMenuitem = document.getElementById("context-copypassword");
|
||||
var usernameMenuitem = document.getElementById("context-copyusername");
|
||||
if (singleSelection) {
|
||||
usernameMenuitem.removeAttribute("disabled");
|
||||
passwordMenuitem.removeAttribute("disabled");
|
||||
function EditCellInSelectedRow(columnName) {
|
||||
let row = signonsTree.currentIndex;
|
||||
let columnElement = getColumnByName(columnName);
|
||||
signonsTree.startEditing(row, signonsTree.columns.getColumnFor(columnElement));
|
||||
}
|
||||
|
||||
function UpdateContextMenu() {
|
||||
let singleSelection = (signonsTreeView.selection.count == 1);
|
||||
let menuItems = new Map();
|
||||
let menupopup = document.getElementById("signonsTreeContextMenu");
|
||||
for (let menuItem of menupopup.querySelectorAll("menuitem")) {
|
||||
menuItems.set(menuItem.id, menuItem);
|
||||
}
|
||||
|
||||
if (!singleSelection) {
|
||||
for (let menuItem of menuItems.values()) {
|
||||
menuItem.setAttribute("disabled", "true");
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
let selectedRow = signonsTree.currentIndex;
|
||||
|
||||
// Disable "Copy Username" if the username is empty.
|
||||
if (signonsTreeView.getCellText(selectedRow, { id: "userCol" }) != "") {
|
||||
menuItems.get("context-copyusername").removeAttribute("disabled");
|
||||
} else {
|
||||
usernameMenuitem.setAttribute("disabled", "true");
|
||||
passwordMenuitem.setAttribute("disabled", "true");
|
||||
menuItems.get("context-copyusername").setAttribute("disabled", "true");
|
||||
}
|
||||
|
||||
menuItems.get("context-editusername").removeAttribute("disabled");
|
||||
menuItems.get("context-copypassword").removeAttribute("disabled");
|
||||
|
||||
// Disable "Edit Password" if the password column isn't showing.
|
||||
if (!document.getElementById("passwordCol").hidden) {
|
||||
menuItems.get("context-editpassword").removeAttribute("disabled");
|
||||
} else {
|
||||
menuItems.get("context-editpassword").setAttribute("disabled", "true");
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -31,15 +31,24 @@
|
||||
|
||||
<popupset id="signonsTreeContextSet">
|
||||
<menupopup id="signonsTreeContextMenu"
|
||||
onpopupshowing="UpdateCopyPassword()">
|
||||
onpopupshowing="UpdateContextMenu()">
|
||||
<menuitem id="context-copyusername"
|
||||
label="©UsernameCmd.label;"
|
||||
accesskey="©UsernameCmd.accesskey;"
|
||||
oncommand="CopyUsername()"/>
|
||||
<menuitem id="context-editusername"
|
||||
label="&editUsernameCmd.label;"
|
||||
accesskey="&editUsernameCmd.accesskey;"
|
||||
oncommand="EditCellInSelectedRow('username')"/>
|
||||
<menuseparator/>
|
||||
<menuitem id="context-copypassword"
|
||||
label="©PasswordCmd.label;"
|
||||
accesskey="©PasswordCmd.accesskey;"
|
||||
oncommand="CopyPassword()"/>
|
||||
<menuitem id="context-editpassword"
|
||||
label="&editPasswordCmd.label;"
|
||||
accesskey="&editPasswordCmd.accesskey;"
|
||||
oncommand="EditCellInSelectedRow('password')"/>
|
||||
</menupopup>
|
||||
</popupset>
|
||||
|
||||
|
@ -12,9 +12,9 @@ skip-if = true # Intermittent failures: Bug 1182296, bug 1148771
|
||||
[browser_passwordmgr_editing.js]
|
||||
skip-if = os == "linux"
|
||||
[browser_context_menu.js]
|
||||
[browser_passwordmgr_contextmenu.js]
|
||||
[browser_passwordmgr_fields.js]
|
||||
[browser_passwordmgr_observers.js]
|
||||
[browser_passwordmgr_sort.js]
|
||||
[browser_passwordmgr_switchtab.js]
|
||||
[browser_passwordmgrcopypwd.js]
|
||||
[browser_passwordmgrdlg.js]
|
||||
|
@ -5,9 +5,7 @@
|
||||
function test() {
|
||||
waitForExplicitFinish();
|
||||
|
||||
let pwmgr = Cc["@mozilla.org/login-manager;1"].
|
||||
getService(Ci.nsILoginManager);
|
||||
pwmgr.removeAllLogins();
|
||||
Services.logins.removeAllLogins();
|
||||
|
||||
// Add some initial logins
|
||||
let urls = [
|
||||
@ -20,13 +18,13 @@ function test() {
|
||||
let nsLoginInfo = new Components.Constructor("@mozilla.org/login-manager/loginInfo;1",
|
||||
Ci.nsILoginInfo, "init");
|
||||
let logins = [
|
||||
new nsLoginInfo(urls[0], urls[0], null, "o", "hai", "u1", "p1"),
|
||||
new nsLoginInfo(urls[0], urls[0], null, "", "o hai", "u1", "p1"),
|
||||
new nsLoginInfo(urls[1], urls[1], null, "ehsan", "coded", "u2", "p2"),
|
||||
new nsLoginInfo(urls[2], urls[2], null, "this", "awesome", "u3", "p3"),
|
||||
new nsLoginInfo(urls[3], urls[3], null, "array of", "logins", "u4", "p4"),
|
||||
new nsLoginInfo(urls[4], urls[4], null, "then", "i wrote the test", "u5", "p5")
|
||||
];
|
||||
logins.forEach(function (login) pwmgr.addLogin(login));
|
||||
logins.forEach(function (login) Services.logins.addLogin(login));
|
||||
|
||||
// Open the password manager dialog
|
||||
const PWMGR_DLG = "chrome://passwordmgr/content/passwordManager.xul";
|
||||
@ -40,40 +38,62 @@ function test() {
|
||||
let menuitem = doc.getElementById("context-copyusername");
|
||||
|
||||
function copyField() {
|
||||
info("Select all");
|
||||
selection.selectAll();
|
||||
is(isMenuitemEnabled(), false, "Copy should be disabled");
|
||||
assertMenuitemEnabled("copyusername", false);
|
||||
assertMenuitemEnabled("editusername", false);
|
||||
assertMenuitemEnabled("copypassword", false);
|
||||
assertMenuitemEnabled("editpassword", false);
|
||||
|
||||
info("Select the first row (with an empty username)");
|
||||
selection.select(0);
|
||||
is(isMenuitemEnabled(), true, "Copy should be enabled");
|
||||
assertMenuitemEnabled("copyusername", false, "empty username");
|
||||
assertMenuitemEnabled("editusername", true);
|
||||
assertMenuitemEnabled("copypassword", true);
|
||||
assertMenuitemEnabled("editpassword", false, "password column hidden");
|
||||
|
||||
info("Clear the selection");
|
||||
selection.clearSelection();
|
||||
is(isMenuitemEnabled(), false, "Copy should be disabled");
|
||||
assertMenuitemEnabled("copyusername", false);
|
||||
assertMenuitemEnabled("editusername", false);
|
||||
assertMenuitemEnabled("copypassword", false);
|
||||
assertMenuitemEnabled("editpassword", false);
|
||||
|
||||
info("Select the third row and making the password column visible");
|
||||
selection.select(2);
|
||||
is(isMenuitemEnabled(), true, "Copy should be enabled");
|
||||
doc.getElementById("passwordCol").hidden = false;
|
||||
assertMenuitemEnabled("copyusername", true);
|
||||
assertMenuitemEnabled("editusername", true);
|
||||
assertMenuitemEnabled("copypassword", true);
|
||||
assertMenuitemEnabled("editpassword", true, "password column visible");
|
||||
menuitem.doCommand();
|
||||
}
|
||||
|
||||
function isMenuitemEnabled() {
|
||||
doc.defaultView.UpdateCopyPassword();
|
||||
return !menuitem.getAttribute("disabled");
|
||||
function assertMenuitemEnabled(idSuffix, expected, reason = "") {
|
||||
doc.defaultView.UpdateContextMenu();
|
||||
let actual = !doc.getElementById("context-" + idSuffix).getAttribute("disabled");
|
||||
is(actual, expected, idSuffix + " should be " + (expected ? "enabled" : "disabled") +
|
||||
(reason ? ": " + reason : ""));
|
||||
}
|
||||
|
||||
function cleanUp() {
|
||||
Services.ww.registerNotification(function (aSubject, aTopic, aData) {
|
||||
Services.ww.unregisterNotification(arguments.callee);
|
||||
pwmgr.removeAllLogins();
|
||||
Services.logins.removeAllLogins();
|
||||
doc.getElementById("passwordCol").hidden = true;
|
||||
finish();
|
||||
});
|
||||
pwmgrdlg.close();
|
||||
}
|
||||
|
||||
|
||||
function testPassword() {
|
||||
menuitem = doc.getElementById("context-copypassword");
|
||||
info("Testing Copy Password");
|
||||
waitForClipboard("coded", copyField, cleanUp, cleanUp);
|
||||
waitForClipboard("coded", function copyPassword() {
|
||||
menuitem = doc.getElementById("context-copypassword");
|
||||
menuitem.doCommand();
|
||||
}, cleanUp, cleanUp);
|
||||
}
|
||||
|
||||
|
||||
info("Testing Copy Username");
|
||||
waitForClipboard("ehsan", copyField, testPassword, testPassword);
|
||||
}
|
@ -37,3 +37,9 @@
|
||||
|
||||
<!ENTITY copyUsernameCmd.label "Copy Username">
|
||||
<!ENTITY copyUsernameCmd.accesskey "U">
|
||||
|
||||
<!ENTITY editPasswordCmd.label "Edit Password">
|
||||
<!ENTITY editPasswordCmd.accesskey "E">
|
||||
|
||||
<!ENTITY editUsernameCmd.label "Edit Username">
|
||||
<!ENTITY editUsernameCmd.accesskey "d">
|
||||
|
Loading…
Reference in New Issue
Block a user