Bug 1258534 - Port test_bug599295.html to mochitest-plain so that it can be turned on in e10s mode; r=mrbkap

This commit is contained in:
Ehsan Akhgari 2016-03-19 14:35:52 -04:00
parent 77e528556e
commit 6536312ed8
5 changed files with 86 additions and 85 deletions

View File

@ -44,7 +44,6 @@ support-files = ../file_bug357450.js
[test_bug571390.xul]
[test_bug1098074_throw_from_ReceiveMessage.xul]
skip-if = buildapp == 'mulet'
[test_bug599295.html]
[test_bug616841.xul]
[test_bug635835.xul]
[test_bug650776.html]

View File

@ -1,84 +0,0 @@
<!DOCTYPE HTML>
<html>
<!--
https://bugzilla.mozilla.org/show_bug.cgi?id=599295
-->
<head>
<title>Test for Bug 599295</title>
<script type="application/javascript" src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js"></script>
<script type="application/javascript" src="chrome://mochikit/content/tests/SimpleTest/EventUtils.js"></script>
<script type="application/javascript" src="chrome://mochikit/content/tests/SimpleTest/ChromeUtils.js"></script>
<link rel="stylesheet" type="text/css" href="chrome://mochikit/content/tests/SimpleTest/test.css"/>
</head>
<body>
<a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=599295">Mozilla Bug 599295</a>
<style type="text/css">
#link1 a { -moz-user-select:none; }
</style>
<div id="link1"><a href="http://www.mozilla.org/">link1</a></div>
<div id="link2"><a href="http://www.mozilla.org/">link2</a></div>
<p id="display"></p>
<div id="content" style="display: none">
</div>
<pre id="test">
<script type="application/javascript">
/** Test for Bug 599295 **/
/* Do not allow a response to a CONNECT method, used to establish an
SSL tunnel over an HTTP proxy, to contain a redirect */
const BinaryInputStream =
Components.Constructor("@mozilla.org/binaryinputstream;1",
"nsIBinaryInputStream",
"setInputStream");
const Ci = Components.interfaces;
const Cu = Components.utils;
Cu.import("resource://gre/modules/NetUtil.jsm");
var listener = {
_httpstatus : 0,
onStartRequest: function(request, context) {
request.QueryInterface(Components.interfaces.nsIHttpChannel);
_httpstatus = request.responseStatus;
},
onDataAvailable: function(request, context, stream, offset, count) {
new BinaryInputStream(stream).readByteArray(count);
},
onStopRequest: function(request, context, status) {
/* testing here that the redirect was not followed. If it was followed
we would see a http status of 200 and status of NS_OK */
is(_httpstatus, 302, "http status 302");
is(status, Components.results.NS_ERROR_CONNECTION_REFUSED, "raised refused");
SimpleTest.finish();
}
};
function runTest() {
var uri = NetUtil.newURI("https://redirproxy.example.com/test");
var channel = NetUtil.newChannel({uri: uri, loadUsingSystemPrincipal: true});
/* Previously, necko would allow a 302 as part of a CONNECT response
if the LOAD_DOCUMENT_URI flag was set and the original document
URI had not yet been changed. */
channel.loadFlags |= Components.interfaces.nsIChannel.LOAD_DOCUMENT_URI;
channel.QueryInterface(Components.interfaces.nsIHttpChannelInternal);
channel.documentURI = uri;
channel.asyncOpen2(listener);
}
SimpleTest.waitForExplicitFinish();
SimpleTest.waitForFocus(runTest);
</script>
</pre>
</body>
</html>

View File

@ -621,6 +621,7 @@ skip-if = toolkit == 'android' #bug 687032
[test_bug592366.html]
[test_bug592829.html]
[test_bug597345.html]
[test_bug599295.html]
[test_bug599588.html]
[test_bug601803.html]
[test_bug602838.html]

View File

@ -0,0 +1,47 @@
<!DOCTYPE HTML>
<html>
<!--
https://bugzilla.mozilla.org/show_bug.cgi?id=599295
-->
<head>
<title>Test for Bug 599295</title>
<script type="application/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
<script type="application/javascript" src="/tests/SimpleTest/EventUtils.js"></script>
<link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/>
</head>
<body>
<a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=599295">Mozilla Bug 599295</a>
<pre id="test">
<script type="application/javascript">
/** Test for Bug 599295 **/
/* Do not allow a response to a CONNECT method, used to establish an
SSL tunnel over an HTTP proxy, to contain a redirect */
function runTest() {
/* Previously, necko would allow a 302 as part of a CONNECT response
if the LOAD_DOCUMENT_URI flag was set and the original document
URI had not yet been changed. */
SpecialPowers.loadChannelAndReturnStatus("https://redirproxy.example.com/test",
true)
.then(function({status, httpStatus}) {
/* testing here that the redirect was not followed. If it was followed
we would see a http status of 200 and status of NS_OK */
is(httpStatus, 302, "http status 302");
is(status, SpecialPowers.Cr.NS_ERROR_CONNECTION_REFUSED,
"raised refused");
SimpleTest.finish();
});
}
SimpleTest.waitForExplicitFinish();
SimpleTest.waitForFocus(runTest);
</script>
</pre>
</body>
</html>

View File

@ -19,6 +19,7 @@ Cu.import("chrome://specialpowers/content/MockPermissionPrompt.jsm");
Cu.import("resource://gre/modules/Services.jsm");
Cu.import("resource://gre/modules/PrivateBrowsingUtils.jsm");
Cu.import("resource://gre/modules/XPCOMUtils.jsm");
Cu.import("resource://gre/modules/NetUtil.jsm");
// We're loaded with "this" not set to the global in some cases, so we
// have to play some games to get at the global object here. Normally
@ -1960,6 +1961,43 @@ SpecialPowersAPI.prototype = {
let principal = this._getPrincipalFromArg(url);
return wrapIfUnwrapped(new content.window.CacheStorage(name, principal));
},
loadChannelAndReturnStatus: function(url, loadUsingSystemPrincipal) {
const BinaryInputStream =
Components.Constructor("@mozilla.org/binaryinputstream;1",
"nsIBinaryInputStream",
"setInputStream");
return new Promise(function(resolve) {
let listener = {
httpStatus : 0,
onStartRequest: function(request, context) {
request.QueryInterface(Ci.nsIHttpChannel);
this.httpStatus = request.responseStatus;
},
onDataAvailable: function(request, context, stream, offset, count) {
new BinaryInputStream(stream).readByteArray(count);
},
onStopRequest: function(request, context, status) {
/* testing here that the redirect was not followed. If it was followed
we would see a http status of 200 and status of NS_OK */
let httpStatus = this.httpStatus;
resolve({status, httpStatus});
}
};
let uri = NetUtil.newURI(url);
let channel = NetUtil.newChannel({uri, loadUsingSystemPrincipal});
channel.loadFlags |= Ci.nsIChannel.LOAD_DOCUMENT_URI;
channel.QueryInterface(Ci.nsIHttpChannelInternal);
channel.documentURI = uri;
channel.asyncOpen2(listener);
});
},
};
this.SpecialPowersAPI = SpecialPowersAPI;