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