gecko/toolkit/components/passwordmgr/test/test_0init.html

83 lines
2.5 KiB
HTML

<!DOCTYPE HTML>
<html>
<head>
<title>Test initialization for Login Manager</title>
<script type="text/javascript" src="/MochiKit/packed.js"></script>
<script type="text/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
<script type="text/javascript" src="pwmgr_common.js"></script>
<link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" />
</head>
<body>
Login Manager test: initialization.
<p id="display"></p>
<div id="content" style="display: none">
</div>
<pre id="test">
<script class="testbody" type="text/javascript">
/** Test for Login Manager: initialization **/
netscape.security.PrivilegeManager.enablePrivilege('UniversalXPConnect');
// Enable debug pref (for console output)
if (false) {
var prefs = Components.classes["@mozilla.org/preferences-service;1"].
getService(Components.interfaces.nsIPrefService);
prefs = prefs.getBranch("signon.");
prefs.setBoolPref("debug", true);
}
// Get the pwmgr service
var Cc_pwmgr = Components.classes["@mozilla.org/login-manager;1"];
ok(Cc_pwmgr != null, "Access Cc[@mozilla.org/login-manager;1]");
var Ci_pwmgr = Components.interfaces.nsILoginManager;
ok(Ci_pwmgr != null, "Access Ci.nsILoginManager");
var pwmgr = Cc_pwmgr.getService(Ci_pwmgr);
ok(pwmgr != null, "pwmgr getService()");
// Make sure it's not already initialized somehow
var logins = pwmgr.getAllLogins({});
ok(logins != null, "getAllLogins()");
is(logins.length, 0, "ensure no pre-existing logins");
if (logins.length != 0) { throw "aborting test init -- found existing logins"; }
var disabledHosts = pwmgr.getAllDisabledHosts({});
ok(disabledHosts != null, "getAllDisabledHosts()");
is(disabledHosts.length, 0, "ensure no pre-existing disabled hosts");
if (disabledHosts.length != 0) { throw "aborting test init -- found existing disabled hosts"; }
// Get nsLoginInfo constructor for simpler code
var nsLoginInfo = new Components.Constructor("@mozilla.org/login-manager/loginInfo;1", Components.interfaces.nsILoginInfo);
ok(nsLoginInfo != null, "nsLoginInfo constructor");
login = new nsLoginInfo();
ok(login != null, "Adding login");
login.init("http://localhost:8888", "http://localhost:8888", null,
"testuser", "testpass", "uname", "pword");
try {
pwmgr.addLogin(login);
} catch (e) {
ok(false, "addLogin threw: " + e);
}
// Simple check to see if everything was added fine.
var logins = pwmgr.getAllLogins({});
ok(logins != null, "getAllLogins()");
is(logins.length, 1, "check expected final number of logins");
</script>
</pre>
</body>
</html>