Bug 1258534 - Port test_bug599295.html to mochitest-plain so that it can be turned on in e10s mode; r=mrbkap
authorEhsan Akhgari <ehsan@mozilla.com>
Sat, 19 Mar 2016 14:35:52 -0400
changeset 289865 c0f5c3d87ac83880eec8cd9d4ac2139a57fab54c
parent 289864 93868635785885317c1509ed77561ea3a00acdd4
child 289866 917819510b3f7390a26805156fbcb9c5c04e1da6
push id19656
push usergwagner@mozilla.com
push dateMon, 04 Apr 2016 13:43:23 +0000
treeherderb2g-inbound@e99061fde28a [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersmrbkap
bugs1258534, 599295
milestone48.0a1
Bug 1258534 - Port test_bug599295.html to mochitest-plain so that it can be turned on in e10s mode; r=mrbkap
dom/base/test/chrome/chrome.ini
dom/base/test/chrome/test_bug599295.html
dom/base/test/mochitest.ini
dom/base/test/test_bug599295.html
testing/specialpowers/content/specialpowersAPI.js
--- a/dom/base/test/chrome/chrome.ini
+++ b/dom/base/test/chrome/chrome.ini
@@ -39,17 +39,16 @@ support-files = ../file_bug357450.js
 [test_bug421622.xul]
 [test_bug429785.xul]
 [test_bug430050.xul]
 [test_bug467123.xul]
 [test_bug549682.xul]
 [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]
 [test_bug650784.html]
 [test_bug682305.html]
 [test_bug683852.xul]
 [test_bug750096.html]
 [test_bug752226-3.xul]
deleted file mode 100644
--- a/dom/base/test/chrome/test_bug599295.html
+++ /dev/null
@@ -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>
-
--- a/dom/base/test/mochitest.ini
+++ b/dom/base/test/mochitest.ini
@@ -616,16 +616,17 @@ skip-if = (toolkit == 'gonk' && debug) #
 [test_bug587931.html]
 [test_bug588990.html]
 [test_bug590812.html]
 skip-if = toolkit == 'android' #bug 687032
 [test_bug590870.html]
 [test_bug592366.html]
 [test_bug592829.html]
 [test_bug597345.html]
+[test_bug599295.html]
 [test_bug599588.html]
 [test_bug601803.html]
 [test_bug602838.html]
 [test_bug604592.html]
 [test_bug604660.html]
 [test_bug605982.html]
 [test_bug606729.html]
 [test_bug614058.html]
new file mode 100644
--- /dev/null
+++ b/dom/base/test/test_bug599295.html
@@ -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>
+
--- a/testing/specialpowers/content/specialpowersAPI.js
+++ b/testing/specialpowers/content/specialpowersAPI.js
@@ -14,16 +14,17 @@ var Cc = Components.classes;
 var Cu = Components.utils;
 
 Cu.import("chrome://specialpowers/content/MockFilePicker.jsm");
 Cu.import("chrome://specialpowers/content/MockColorPicker.jsm");
 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
 // we'd try "this" from a function called with undefined this value,
 // but this whole file is in strict mode.  So instead fall back on
 // returning "this" from indirect eval, which returns the global.
 if (!(function() { var e = eval; return e("this"); })().File) {
     Cu.importGlobalProperties(["File"]);
@@ -1955,13 +1956,50 @@ SpecialPowersAPI.prototype = {
   allowMedia: function(window, enable) {
     this._getDocShell(window).allowMedia = enable;
   },
 
   createChromeCache: function(name, url) {
     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;
 this.bindDOMWindowUtils = bindDOMWindowUtils;
 this.getRawComponents = getRawComponents;