Fix for bug 740855 (Make tests that try to get XHR.channel use SpecialPowers). r=bz.
☠☠ backed out by d88f380468ee ☠ ☠
authorPeter Van der Beken <peterv@propagandism.org>
Fri, 30 Mar 2012 09:38:19 -0700
changeset 90737 cfd6bf0fe1e9ed29f72957d98eda997bc77806a3
parent 90736 61964245b303642e64d2e301ce67f87a61ac2d91
child 90738 7b813cc009ce70a20f1f1a029315560a12492d04
push id22382
push userbmo@edmorley.co.uk
push dateSat, 31 Mar 2012 21:44:34 +0000
treeherdermozilla-central@bbe5086163c9 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersbz
bugs740855
milestone14.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Fix for bug 740855 (Make tests that try to get XHR.channel use SpecialPowers). r=bz.
content/base/test/test_bug383430.html
content/base/test/test_bug393968.html
content/base/test/test_bug397234.html
content/base/test/test_bug413974.html
content/base/test/test_bug422537.html
content/base/test/test_bug431701.html
content/base/test/test_bug475156.html
content/base/test/test_xhr_forbidden_headers.html
--- a/content/base/test/test_bug383430.html
+++ b/content/base/test/test_bug383430.html
@@ -20,13 +20,13 @@ https://bugzilla.mozilla.org/show_bug.cg
 /** Test for Bug 383430 **/
 netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
 
 var req = new XMLHttpRequest();
 req.mozBackgroundRequest = true;
 req.open("GET", window.location.href);
 req.send(null);
 
-ok(req.channel.loadGroup == null, "loadGroup is null");
+ok(SpecialPowers.wrap(req).channel.loadGroup == null, "loadGroup is null");
 </script>
 </pre>
 </body>
 </html>
--- a/content/base/test/test_bug393968.html
+++ b/content/base/test/test_bug393968.html
@@ -18,18 +18,17 @@ https://bugzilla.mozilla.org/show_bug.cg
 <script class="testbody" type="text/javascript">
 
 /** Test for Bug 393968 **/
 var req = new XMLHttpRequest();
 req.open("POST", window.location.href);
 req.setRequestHeader("Content-Type", "text/plain; charset=us-ascii; boundary=01234567890");
 req.send("Some text");
 
-netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
-is(req.channel
+is(SpecialPowers.wrap(req).channel
       .QueryInterface(Components.interfaces.nsIHttpChannel)
       .getRequestHeader("Content-Type"),
    "text/plain; charset=UTF-8; boundary=01234567890",
    "Headers should match");
 
 </script>
 </pre>
 </body>
--- a/content/base/test/test_bug397234.html
+++ b/content/base/test/test_bug397234.html
@@ -19,18 +19,17 @@ https://bugzilla.mozilla.org/show_bug.cg
 
 /** Test for Bug 397234 **/
 var req = new XMLHttpRequest();
 req.open("POST", window.location.href);
 // Capitalization of charet param is on purpose!
 req.setRequestHeader("Content-Type", "text/plain; charset='uTf-8'");
 req.send("Some text");
 
-netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
-is(req.channel
+is(SpecialPowers.wrap(req).channel
       .QueryInterface(Components.interfaces.nsIHttpChannel)
       .getRequestHeader("Content-Type"),
    "text/plain; charset='uTf-8'",
    "Headers should match");
 
 </script>
 </pre>
 </body>
--- a/content/base/test/test_bug413974.html
+++ b/content/base/test/test_bug413974.html
@@ -18,18 +18,17 @@ https://bugzilla.mozilla.org/show_bug.cg
 <script class="testbody" type="text/javascript">
 
 /** Test for Bug 413974 **/
 var req = new XMLHttpRequest();
 req.open("POST", window.location.href);
 req.setRequestHeader("Content-Type", "text/plain; boundary=01234567890");
 req.send("Some text");
 
-netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
-is(req.channel
+is(SpecialPowers.wrap(req).channel
       .QueryInterface(Components.interfaces.nsIHttpChannel)
       .getRequestHeader("Content-Type"),
    "text/plain; charset=UTF-8; boundary=01234567890",
    "Charset should come before boundary");
 </script>
 </pre>
 </body>
 </html>
--- a/content/base/test/test_bug422537.html
+++ b/content/base/test/test_bug422537.html
@@ -31,17 +31,17 @@ var body = [
   "foo",
   isupports_string
 ];
 
 for each (var i in body) {
   var xhr = new XMLHttpRequest();
   xhr.open("POST", url, true);
   xhr.send(i);
-  var chan = xhr.channel;
+  var chan = SpecialPowers.wrap(xhr).channel;
   if (!(chan instanceof Components.interfaces.nsIUploadChannel))
     throw "Must be an upload channel";
   var stream = chan.uploadStream;
   if (!stream || !(stream instanceof Components.interfaces.nsISeekableStream))
     throw "Stream must be seekable";
   // the following is a no-op, but should not throw an exception
   stream.seek(Components.interfaces.nsISeekableStream.NS_SEEK_CUR, 0);
 }
--- a/content/base/test/test_bug431701.html
+++ b/content/base/test/test_bug431701.html
@@ -93,18 +93,17 @@ addLoadEvent(function() {
   for (var i = 0; i < tests.length; ++i) {
     doTest(i);
   }
 
   // Now check what xhr does
   var xhr = new XMLHttpRequest();
   xhr.open("POST", document.location.href);
   xhr.send(createDoc());
-  netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
-  is(xhr.channel.QueryInterface(Components.interfaces.nsIHttpChannel)
+  is(SpecialPowers.wrap(xhr).channel.QueryInterface(Components.interfaces.nsIHttpChannel)
                 .getRequestHeader("Content-Type"),
      "application/xml; charset=UTF-8", "Testing correct type on the wire");
   xhr.abort();
                      
   SimpleTest.finish();
 });
 
 
--- a/content/base/test/test_bug475156.html
+++ b/content/base/test/test_bug475156.html
@@ -12,18 +12,17 @@ https://bugzilla.mozilla.org/show_bug.cg
 <script class="testbody" type="text/javascript">
 
 SimpleTest.waitForExplicitFinish();
 
 var path = "http://mochi.test:8888/tests/content/base/test/";
 
 function fromCache(xhr)
 {
-  netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
-  var ch = xhr.channel.QueryInterface(Components.interfaces.nsICachingChannel);
+  var ch = SpecialPowers.wrap(xhr).channel.QueryInterface(Components.interfaces.nsICachingChannel);
   return ch.isFromCache();  
 }
 
 var tests = [
   // First just init the file with an ETag
   {
     init: function(xhr) 
     {
--- a/content/base/test/test_xhr_forbidden_headers.html
+++ b/content/base/test/test_xhr_forbidden_headers.html
@@ -50,37 +50,37 @@ var i, request;
 
 // Try setting headers in unprivileged context
 request = new XMLHttpRequest();
 request.open("GET", window.location.href);
 for (i = 0; i < headers.length; i++)
   request.setRequestHeader(headers[i], "test" + i);
 
 // Read out headers
-netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
-var channel = request.channel.QueryInterface(Components.interfaces.nsIHttpChannel);
+var channel = SpecialPowers.wrap(request).channel.QueryInterface(Components.interfaces.nsIHttpChannel);
 for (i = 0; i < headers.length; i++) {
   // Retrieving Content-Length will throw an exception
   var value = null;
   try {
     value = channel.getRequestHeader(headers[i]);
   }
   catch(e) {}
 
   isnot(value, "test" + i, "Setting " + headers[i] + " header in unprivileged context");
 }
 
 // Try setting headers in privileged context
+netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
 request = new XMLHttpRequest();
 request.open("GET", window.location.href);
 for (i = 0; i < headers.length; i++)
   request.setRequestHeader(headers[i], "test" + i);
 
 // Read out headers
-var channel = request.channel.QueryInterface(Components.interfaces.nsIHttpChannel);
+var channel = SpecialPowers.wrap(request).channel.QueryInterface(Components.interfaces.nsIHttpChannel);
 for (i = 0; i < headers.length; i++) {
   var value = channel.getRequestHeader(headers[i]);
   is(value, "test" + i, "Setting " + headers[i] + " header in privileged context");
 }
 </script>
 </pre>
 </body>
 </html>