1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/content/base/test/chrome/test_bug599295.html Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,81 @@ 1.4 +<!DOCTYPE HTML> 1.5 +<html> 1.6 +<!-- 1.7 +https://bugzilla.mozilla.org/show_bug.cgi?id=599295 1.8 +--> 1.9 +<head> 1.10 + <title>Test for Bug 599295</title> 1.11 + <script type="application/javascript" src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js"></script> 1.12 + <script type="application/javascript" src="chrome://mochikit/content/tests/SimpleTest/EventUtils.js"></script> 1.13 + <script type="application/javascript" src="chrome://mochikit/content/tests/SimpleTest/ChromeUtils.js"></script> 1.14 + <link rel="stylesheet" type="text/css" href="chrome://mochikit/content/tests/SimpleTest/test.css"/> 1.15 +</head> 1.16 +<body> 1.17 +<a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=599295">Mozilla Bug 599295</a> 1.18 +<style type="text/css"> 1.19 +#link1 a { -moz-user-select:none; } 1.20 +</style> 1.21 +<div id="link1"><a href="http://www.mozilla.org/">link1</a></div> 1.22 +<div id="link2"><a href="http://www.mozilla.org/">link2</a></div> 1.23 +<p id="display"></p> 1.24 +<div id="content" style="display: none"> 1.25 + 1.26 +</div> 1.27 +<pre id="test"> 1.28 +<script type="application/javascript"> 1.29 + 1.30 +/** Test for Bug 599295 **/ 1.31 + 1.32 +/* Do not allow a response to a CONNECT method, used to establish an 1.33 + SSL tunnel over an HTTP proxy, to contain a redirect */ 1.34 + 1.35 +const BinaryInputStream = 1.36 + Components.Constructor("@mozilla.org/binaryinputstream;1", 1.37 + "nsIBinaryInputStream", 1.38 + "setInputStream"); 1.39 +var listener = { 1.40 + _httpstatus : 0, 1.41 + 1.42 + onStartRequest: function(request, context) { 1.43 + request.QueryInterface(Components.interfaces.nsIHttpChannel); 1.44 + _httpstatus = request.responseStatus; 1.45 + }, 1.46 + 1.47 + onDataAvailable: function(request, context, stream, offset, count) { 1.48 + new BinaryInputStream(stream).readByteArray(count); 1.49 + }, 1.50 + 1.51 + onStopRequest: function(request, context, status) { 1.52 + /* testing here that the redirect was not followed. If it was followed 1.53 + we would see a http status of 200 and status of NS_OK */ 1.54 + 1.55 + is(_httpstatus, 302, "http status 302"); 1.56 + is(status, Components.results.NS_ERROR_CONNECTION_REFUSED, "raised refused"); 1.57 + SimpleTest.finish(); 1.58 + } 1.59 +}; 1.60 + 1.61 +function runTest() { 1.62 + var ios = Components.classes["@mozilla.org/network/io-service;1"]. 1.63 + getService(Components.interfaces.nsIIOService); 1.64 + var uri = ios.newURI("https://redirproxy.example.com/test", "", null); 1.65 + var channel = ios.newChannelFromURI(uri); 1.66 + 1.67 + /* Previously, necko would allow a 302 as part of a CONNECT response 1.68 + if the LOAD_DOCUMENT_URI flag was set and the original document 1.69 + URI had not yet been changed. */ 1.70 + 1.71 + channel.loadFlags |= Components.interfaces.nsIChannel.LOAD_DOCUMENT_URI; 1.72 + channel.QueryInterface(Components.interfaces.nsIHttpChannelInternal); 1.73 + channel.documentURI = uri; 1.74 + channel.asyncOpen(listener, null); 1.75 +} 1.76 + 1.77 +SimpleTest.waitForExplicitFinish(); 1.78 +SimpleTest.waitForFocus(runTest); 1.79 + 1.80 +</script> 1.81 +</pre> 1.82 +</body> 1.83 +</html> 1.84 +