mirror of
https://gitlab.winehq.org/wine/wine-gecko.git
synced 2024-09-13 09:24:08 -07:00
132 lines
4.5 KiB
HTML
132 lines
4.5 KiB
HTML
<!DOCTYPE HTML>
|
|
<html>
|
|
<head>
|
|
<title>Test bug 627616</title>
|
|
<script type="text/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
|
|
<script type="text/javascript" src="prompt_common.js"></script>
|
|
<link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" />
|
|
</head>
|
|
<body>
|
|
<script class="testbody" type="text/javascript">
|
|
SimpleTest.waitForExplicitFinish();
|
|
|
|
var Cc = SpecialPowers.Cc;
|
|
|
|
testNum = 1;
|
|
|
|
var login, login2;
|
|
|
|
var resolveCallback = SpecialPowers.wrapCallbackObject({
|
|
|
|
QueryInterface : function (iid) {
|
|
const interfaces = [Ci.nsIProtocolProxyCallback, Ci.nsISupports];
|
|
|
|
if (!interfaces.some( function(v) { return iid.equals(v) } ))
|
|
throw Components.results.NS_ERROR_NO_INTERFACE;
|
|
return this;
|
|
},
|
|
|
|
onProxyAvailable : function (req, uri, pi, status) {
|
|
init2(SpecialPowers.wrap(pi).host, SpecialPowers.wrap(pi).port);
|
|
}
|
|
});
|
|
|
|
function init1() {
|
|
var ios = Cc["@mozilla.org/network/io-service;1"].getService(Ci.nsIIOService);
|
|
var pps = Cc["@mozilla.org/network/protocol-proxy-service;1"].getService();
|
|
|
|
var uri = ios.newURI("http://example.com", null, null);
|
|
pps.asyncResolve(uri, 0, resolveCallback);
|
|
}
|
|
|
|
function init2(proxyHost, proxyPort) {
|
|
|
|
var mozproxy = "moz-proxy://" + proxyHost + ":" + proxyPort;
|
|
|
|
var pwmgr = Cc["@mozilla.org/login-manager;1"].getService(Ci.nsILoginManager);
|
|
login = Cc["@mozilla.org/login-manager/loginInfo;1"].createInstance(Ci.nsILoginInfo);
|
|
login.init(mozproxy, null, "proxy_realm", "proxy_user", "proxy_pass", "", "");
|
|
pwmgr.addLogin(login);
|
|
|
|
login2 = Cc["@mozilla.org/login-manager/loginInfo;1"].createInstance(Ci.nsILoginInfo);
|
|
login2.init("http://mochi.test:8888", null, "mochirealm", "user1name", "user1pass", "", "");
|
|
pwmgr.addLogin(login2);
|
|
startCallbackTimer();
|
|
}
|
|
function cleanup() {
|
|
var pwmgr = Cc["@mozilla.org/login-manager;1"].getService(Ci.nsILoginManager);
|
|
pwmgr.removeLogin(login);
|
|
pwmgr.removeLogin(login2);
|
|
timer.cancel();
|
|
}
|
|
|
|
function makeXHR(expectedStatus, expectedText, extra) {
|
|
var xhr = new XMLHttpRequest();
|
|
xhr.open("GET", "authenticate.sjs?" +
|
|
"proxy_user=proxy_user&" +
|
|
"proxy_pass=proxy_pass&" +
|
|
"proxy_realm=proxy_realm&" +
|
|
"user=user1name&" +
|
|
"pass=user1pass&" +
|
|
"realm=mochirealm&" +
|
|
extra || "");
|
|
xhr.onloadend = function() {
|
|
is(xhr.status, expectedStatus, "xhr.status");
|
|
is(xhr.statusText, expectedText, "xhr.statusText");
|
|
runNextTest();
|
|
}
|
|
return xhr;
|
|
}
|
|
|
|
function testNonAnonymousCredentials() {
|
|
var xhr = makeXHR(200, "OK");
|
|
xhr.send();
|
|
}
|
|
|
|
function testAnonymousCredentials() {
|
|
// Test that an anonymous request correctly performs proxy authentication
|
|
var xhr = makeXHR(401, "Authentication required");
|
|
SpecialPowers.wrap(xhr).channel.loadFlags |= Ci.nsIChannel.LOAD_ANONYMOUS;
|
|
xhr.send();
|
|
}
|
|
|
|
function testAnonymousNoAuth() {
|
|
// Next, test that an anonymous request still does not include any non-proxy
|
|
// authentication headers.
|
|
var xhr = makeXHR(200, "Authorization header not found", "anonymous=1");
|
|
SpecialPowers.wrap(xhr).channel.loadFlags |= Ci.nsIChannel.LOAD_ANONYMOUS;
|
|
xhr.send();
|
|
}
|
|
|
|
var gExpectedDialogs = 0;
|
|
var gCurrentTest;
|
|
function runNextTest() {
|
|
is(gExpectedDialogs, 0, "received expected number of auth dialogs");
|
|
Cc["@mozilla.org/network/http-auth-manager;1"].getService(SpecialPowers.Ci.nsIHttpAuthManager).clearAll();
|
|
if (pendingTests.length > 0) {
|
|
({expectedDialogs: gExpectedDialogs,
|
|
test: gCurrentTest}) = pendingTests.shift();
|
|
gCurrentTest.call(this);
|
|
} else {
|
|
cleanup();
|
|
SimpleTest.finish();
|
|
}
|
|
}
|
|
|
|
var pendingTests = [{expectedDialogs: 2, test: testNonAnonymousCredentials},
|
|
{expectedDialogs: 1, test: testAnonymousCredentials},
|
|
{expectedDialogs: 0, test: testAnonymousNoAuth}];
|
|
init1();
|
|
runNextTest();
|
|
|
|
function handleDialog(doc, testNum)
|
|
{
|
|
var dialog = doc.getElementById("commonDialog");
|
|
dialog.acceptDialog();
|
|
gExpectedDialogs--;
|
|
startCallbackTimer();
|
|
}
|
|
</script>
|
|
</body>
|
|
</html>
|