toolkit/components/passwordmgr/test/browser/browser_passwordmgrcopypwd.js

Sat, 03 Jan 2015 20:18:00 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Sat, 03 Jan 2015 20:18:00 +0100
branch
TOR_BUG_3246
changeset 7
129ffea94266
permissions
-rw-r--r--

Conditionally enable double key logic according to:
private browsing mode or privacy.thirdparty.isolate preference and
implement in GetCookieStringCommon and FindCookie where it counts...
With some reservations of how to convince FindCookie users to test
condition and pass a nullptr when disabling double key logic.

michael@0 1 /* This Source Code Form is subject to the terms of the Mozilla Public
michael@0 2 * License, v. 2.0. If a copy of the MPL was not distributed with this
michael@0 3 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
michael@0 4
michael@0 5 function test() {
michael@0 6 waitForExplicitFinish();
michael@0 7
michael@0 8 let pwmgr = Cc["@mozilla.org/login-manager;1"].
michael@0 9 getService(Ci.nsILoginManager);
michael@0 10 pwmgr.removeAllLogins();
michael@0 11
michael@0 12 // Add some initial logins
michael@0 13 let urls = [
michael@0 14 "http://example.com/",
michael@0 15 "http://mozilla.org/",
michael@0 16 "http://spreadfirefox.com/",
michael@0 17 "https://developer.mozilla.org/",
michael@0 18 "http://hg.mozilla.org/"
michael@0 19 ];
michael@0 20 let nsLoginInfo = new Components.Constructor("@mozilla.org/login-manager/loginInfo;1",
michael@0 21 Ci.nsILoginInfo, "init");
michael@0 22 let logins = [
michael@0 23 new nsLoginInfo(urls[0], urls[0], null, "o", "hai", "u1", "p1"),
michael@0 24 new nsLoginInfo(urls[1], urls[1], null, "ehsan", "coded", "u2", "p2"),
michael@0 25 new nsLoginInfo(urls[2], urls[2], null, "this", "awesome", "u3", "p3"),
michael@0 26 new nsLoginInfo(urls[3], urls[3], null, "array of", "logins", "u4", "p4"),
michael@0 27 new nsLoginInfo(urls[4], urls[4], null, "then", "i wrote the test", "u5", "p5")
michael@0 28 ];
michael@0 29 logins.forEach(function (login) pwmgr.addLogin(login));
michael@0 30
michael@0 31 // Open the password manager dialog
michael@0 32 const PWMGR_DLG = "chrome://passwordmgr/content/passwordManager.xul";
michael@0 33 let pwmgrdlg = window.openDialog(PWMGR_DLG, "Toolkit:PasswordManager", "");
michael@0 34 SimpleTest.waitForFocus(doTest, pwmgrdlg);
michael@0 35
michael@0 36 // Test if "Copy Username" and "Copy Password" works
michael@0 37 function doTest() {
michael@0 38 let doc = pwmgrdlg.document;
michael@0 39 let selection = doc.getElementById("signonsTree").view.selection;
michael@0 40 let menuitem = doc.getElementById("context-copyusername");
michael@0 41
michael@0 42 function copyField() {
michael@0 43 selection.selectAll();
michael@0 44 is(isMenuitemEnabled(), false, "Copy should be disabled");
michael@0 45
michael@0 46 selection.select(0);
michael@0 47 is(isMenuitemEnabled(), true, "Copy should be enabled");
michael@0 48
michael@0 49 selection.clearSelection();
michael@0 50 is(isMenuitemEnabled(), false, "Copy should be disabled");
michael@0 51
michael@0 52 selection.select(2);
michael@0 53 is(isMenuitemEnabled(), true, "Copy should be enabled");
michael@0 54 menuitem.doCommand();
michael@0 55 }
michael@0 56
michael@0 57 function isMenuitemEnabled() {
michael@0 58 doc.defaultView.UpdateCopyPassword();
michael@0 59 return !menuitem.getAttribute("disabled");
michael@0 60 }
michael@0 61
michael@0 62 function cleanUp() {
michael@0 63 Services.ww.registerNotification(function (aSubject, aTopic, aData) {
michael@0 64 Services.ww.unregisterNotification(arguments.callee);
michael@0 65 pwmgr.removeAllLogins();
michael@0 66 finish();
michael@0 67 });
michael@0 68 pwmgrdlg.close();
michael@0 69 }
michael@0 70
michael@0 71 function testPassword() {
michael@0 72 menuitem = doc.getElementById("context-copypassword");
michael@0 73 info("Testing Copy Password");
michael@0 74 waitForClipboard("coded", copyField, cleanUp, cleanUp);
michael@0 75 }
michael@0 76
michael@0 77 info("Testing Copy Username");
michael@0 78 waitForClipboard("ehsan", copyField, testPassword, testPassword);
michael@0 79 }
michael@0 80 }

mercurial