2010-01-21 11:35:03 -08:00
|
|
|
<!DOCTYPE HTML>
|
|
|
|
<html>
|
|
|
|
<head>
|
|
|
|
<title>Test for Login Manager</title>
|
|
|
|
<script type="text/javascript" src="/MochiKit/packed.js"></script>
|
|
|
|
<script type="text/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
|
|
|
|
<link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" />
|
|
|
|
</head>
|
|
|
|
<body>
|
|
|
|
Test for NPN_GetAuthenticationInfo
|
|
|
|
<p id="display"></p>
|
|
|
|
|
|
|
|
<div id="content">
|
|
|
|
<iframe id="iframe"></iframe>
|
|
|
|
</div>
|
|
|
|
|
|
|
|
<script class="testbody" type="text/javascript">
|
|
|
|
|
|
|
|
netscape.security.PrivilegeManager.enablePrivilege('UniversalXPConnect');
|
|
|
|
|
|
|
|
const Ci = Components.interfaces;
|
|
|
|
const Cc = Components.classes;
|
|
|
|
|
|
|
|
function iframeLoad() {
|
|
|
|
var plugin = iframe.contentDocument.getElementById("embedtest");
|
|
|
|
// valid request
|
2010-03-12 13:53:36 -08:00
|
|
|
is(plugin.getAuthInfo("http", "mochi.test", 8888, "basic", "testrealm"),
|
2010-01-21 11:35:03 -08:00
|
|
|
"user1|password1",
|
|
|
|
"correct user/pass retrieved");
|
|
|
|
try {
|
|
|
|
// invalid request -- wrong host
|
2010-01-26 09:22:49 -08:00
|
|
|
is(plugin.getAuthInfo("http", "example.com", 8888, "basic", "testrealm"),
|
2010-01-21 11:35:03 -08:00
|
|
|
"user1|password1",
|
|
|
|
"correct user/pass retrieved");
|
|
|
|
ok(false, "no exception was thrown");
|
|
|
|
}
|
|
|
|
catch (err) {
|
|
|
|
ok(true, "expected exception caught");
|
|
|
|
}
|
|
|
|
try {
|
|
|
|
// invalid request -- wrong port
|
2010-03-12 13:53:36 -08:00
|
|
|
is(plugin.getAuthInfo("http", "mochi.test", 90, "basic", "testrealm"),
|
2010-01-21 11:35:03 -08:00
|
|
|
"user1|password1",
|
|
|
|
"correct user/pass retrieved");
|
|
|
|
ok(false, "no exception was thrown");
|
|
|
|
}
|
|
|
|
catch (err) {
|
|
|
|
ok(true, "expected exception caught");
|
|
|
|
}
|
|
|
|
try {
|
|
|
|
// invalid request -- wrong realm
|
2010-03-12 13:53:36 -08:00
|
|
|
is(plugin.getAuthInfo("http", "mochi.test", 8888, "basic", "wrongrealm"),
|
2010-01-21 11:35:03 -08:00
|
|
|
"user1|password1",
|
|
|
|
"correct user/pass retrieved");
|
|
|
|
ok(false, "no exception was thrown");
|
|
|
|
}
|
|
|
|
catch (err) {
|
|
|
|
ok(true, "expected exception caught");
|
|
|
|
}
|
|
|
|
SimpleTest.finish();
|
|
|
|
}
|
|
|
|
|
|
|
|
SimpleTest.waitForExplicitFinish();
|
|
|
|
var iframe = document.getElementById("iframe");
|
|
|
|
var am = Cc["@mozilla.org/network/http-auth-manager;1"].
|
|
|
|
getService(Ci.nsIHttpAuthManager);
|
2010-03-12 13:53:36 -08:00
|
|
|
am.setAuthIdentity("http", "mochi.test", 8888, "basic", "testrealm", "",
|
|
|
|
"mochi.test", "user1", "password1");
|
2010-01-21 11:35:03 -08:00
|
|
|
iframe.onload = iframeLoad;
|
2010-03-12 13:53:36 -08:00
|
|
|
iframe.src = "http://mochi.test:8888/tests/toolkit/components/passwordmgr/" +
|
2010-01-21 11:35:03 -08:00
|
|
|
"test/authenticate.sjs?user=user1&pass=password1&realm=testrealm&plugin=1";
|
|
|
|
|
|
|
|
</script>
|
|
|
|
</body>
|
|
|
|
</html>
|