michael@0: /* This Source Code Form is subject to the terms of the Mozilla Public michael@0: * License, v. 2.0. If a copy of the MPL was not distributed with this michael@0: * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ michael@0: michael@0: function test() { michael@0: waitForExplicitFinish(); michael@0: michael@0: let pwmgr = Cc["@mozilla.org/login-manager;1"]. michael@0: getService(Ci.nsILoginManager); michael@0: pwmgr.removeAllLogins(); michael@0: michael@0: // Add some initial logins michael@0: let urls = [ michael@0: "http://example.com/", michael@0: "http://mozilla.org/", michael@0: "http://spreadfirefox.com/", michael@0: "https://developer.mozilla.org/", michael@0: "http://hg.mozilla.org/" michael@0: ]; michael@0: let nsLoginInfo = new Components.Constructor("@mozilla.org/login-manager/loginInfo;1", michael@0: Ci.nsILoginInfo, "init"); michael@0: let logins = [ michael@0: new nsLoginInfo(urls[0], urls[0], null, "o", "hai", "u1", "p1"), michael@0: new nsLoginInfo(urls[1], urls[1], null, "ehsan", "coded", "u2", "p2"), michael@0: new nsLoginInfo(urls[2], urls[2], null, "this", "awesome", "u3", "p3"), michael@0: new nsLoginInfo(urls[3], urls[3], null, "array of", "logins", "u4", "p4"), michael@0: new nsLoginInfo(urls[4], urls[4], null, "then", "i wrote the test", "u5", "p5") michael@0: ]; michael@0: logins.forEach(function (login) pwmgr.addLogin(login)); michael@0: michael@0: // Open the password manager dialog michael@0: const PWMGR_DLG = "chrome://passwordmgr/content/passwordManager.xul"; michael@0: let pwmgrdlg = window.openDialog(PWMGR_DLG, "Toolkit:PasswordManager", ""); michael@0: SimpleTest.waitForFocus(doTest, pwmgrdlg); michael@0: michael@0: // Test if "Copy Username" and "Copy Password" works michael@0: function doTest() { michael@0: let doc = pwmgrdlg.document; michael@0: let selection = doc.getElementById("signonsTree").view.selection; michael@0: let menuitem = doc.getElementById("context-copyusername"); michael@0: michael@0: function copyField() { michael@0: selection.selectAll(); michael@0: is(isMenuitemEnabled(), false, "Copy should be disabled"); michael@0: michael@0: selection.select(0); michael@0: is(isMenuitemEnabled(), true, "Copy should be enabled"); michael@0: michael@0: selection.clearSelection(); michael@0: is(isMenuitemEnabled(), false, "Copy should be disabled"); michael@0: michael@0: selection.select(2); michael@0: is(isMenuitemEnabled(), true, "Copy should be enabled"); michael@0: menuitem.doCommand(); michael@0: } michael@0: michael@0: function isMenuitemEnabled() { michael@0: doc.defaultView.UpdateCopyPassword(); michael@0: return !menuitem.getAttribute("disabled"); michael@0: } michael@0: michael@0: function cleanUp() { michael@0: Services.ww.registerNotification(function (aSubject, aTopic, aData) { michael@0: Services.ww.unregisterNotification(arguments.callee); michael@0: pwmgr.removeAllLogins(); michael@0: finish(); michael@0: }); michael@0: pwmgrdlg.close(); michael@0: } michael@0: michael@0: function testPassword() { michael@0: menuitem = doc.getElementById("context-copypassword"); michael@0: info("Testing Copy Password"); michael@0: waitForClipboard("coded", copyField, cleanUp, cleanUp); michael@0: } michael@0: michael@0: info("Testing Copy Username"); michael@0: waitForClipboard("ehsan", copyField, testPassword, testPassword); michael@0: } michael@0: }