Bug 1246220: Update test_bug337744 (r=mcmanus)
authorChristoph Kerschbaumer <mozilla@christophkerschbaumer.com>
Fri, 12 Feb 2016 17:18:29 -0800
changeset 331734 9ecae2e500e4404ab3fd59a1cd3d94d38bdf011c
parent 331733 4aa0fb77ae721ca147c76c55d1458b0d308ccaca
child 331735 28b6f5924ce2296a626a573a06cb4be4cfd125cd
push id11066
push userbmo:jyavenard@mozilla.com
push dateThu, 18 Feb 2016 05:12:29 +0000
reviewersmcmanus
bugs1246220, 337744
milestone47.0a1
Bug 1246220: Update test_bug337744 (r=mcmanus)
netwerk/test/unit/test_bug337744.js
--- a/netwerk/test/unit/test_bug337744.js
+++ b/netwerk/test/unit/test_bug337744.js
@@ -1,41 +1,59 @@
 /* verify that certain invalid URIs are not parsed by the resource
    protocol handler */
 
+Cu.import("resource://gre/modules/NetUtil.jsm");
+
 const specs = [
   "resource:////",
   "resource:///http://www.mozilla.org/",
   "resource:///file:///",
   "resource:///..\\",
   "resource:///..\\..\\",
   "resource:///..%5C",
   "resource:///..%5c"
 ];
 
+var ssm = Cc["@mozilla.org/scriptsecuritymanager;1"]
+            .getService(Ci.nsIScriptSecurityManager);
+// create some fake principal that has not engough
+// privileges to access any resource: uri.
+var uri = NetUtil.newURI("http://www.example.com", null, null);
+var principal = ssm.createCodebasePrincipal(uri, {});
+
 function check_for_exception(spec)
 {
-  var ios =
-    Cc["@mozilla.org/network/io-service;1"].
-    getService(Ci.nsIIOService);
+  var channelURI = NetUtil.newURI(spec, null, null);
+
+  var channel = NetUtil.newChannel({
+    uri: NetUtil.newURI(spec, null, null),
+    loadingPrincipal: principal,
+    securityFlags: Ci.nsILoadInfo.SEC_ALLOW_CROSS_ORIGIN_DATA_IS_NULL,
+    contentPolicyType: Ci.nsIContentPolicy.TYPE_OTHER
+  });
 
   try {
-    var channel = ios.newChannel2(spec,
-                                  null,
-                                  null,
-                                  null,      // aLoadingNode
-                                  Services.scriptSecurityManager.getSystemPrincipal(),
-                                  null,      // aTriggeringPrincipal
-                                  Ci.nsILoadInfo.SEC_NORMAL,
-                                  Ci.nsIContentPolicy.TYPE_OTHER);
+    channel.asyncOpen2(null);
+    do_check_true(false, "asyncOpen2() of URI: " + spec + "should throw");
   }
   catch (e) {
-    return;
+    // make sure we get the right error code in the exception
+    // ERROR code for NS_ERROR_DOM_BAD_URI is 1012
+    do_check_eq(e.code, 1012);
   }
 
-  do_throw("Successfully opened invalid URI: '" + spec + "'");
+  try {
+    channel.open2();
+    do_check_true(false, "Open2() of uri: " + spec + "should throw");
+  }
+  catch (e) {
+    // make sure we get the right error code in the exception
+    // ERROR code for NS_ERROR_DOM_BAD_URI is 1012
+    do_check_eq(e.code, 1012);
+  }
 }
 
 function run_test() {
   for (var spec of specs) {
     check_for_exception(spec);
   }
 }