Bug 1547882 - Fix test_bug337744.js that expects no %2f in the query of resource URLs r=kmag,kershaw
authorValentin Gosu <valentin.gosu@gmail.com>
Fri, 10 May 2019 13:56:27 +0000
changeset 532207 18861619a4b332b44fb1602d42dbba56cca25bdd
parent 532206 948aaa76cfe97ca7339cac48c1b4ffb49ef01c31
child 532208 55089d0bf0701221a363514e12592e8bc07405db
push id11265
push userffxbld-merge
push dateMon, 13 May 2019 10:53:39 +0000
treeherdermozilla-beta@77e0fe8dbdd3 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerskmag, kershaw
bugs1547882, 337744
milestone68.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
Bug 1547882 - Fix test_bug337744.js that expects no %2f in the query of resource URLs r=kmag,kershaw Differential Revision: https://phabricator.services.mozilla.com/D30351
netwerk/test/unit/test_bug337744.js
--- a/netwerk/test/unit/test_bug337744.js
+++ b/netwerk/test/unit/test_bug337744.js
@@ -1,11 +1,12 @@
 /* verify that certain invalid URIs are not parsed by the resource
    protocol handler */
 
+"use strict";
 
 const specs = [
   "resource://res-test//",
   "resource://res-test/?foo=http:",
   "resource://res-test/?foo=" + encodeURIComponent("http://example.com/"),
   "resource://res-test/?foo=" + encodeURIComponent("x\\y"),
   "resource://res-test/..%2F",
   "resource://res-test/..%2f",
@@ -34,58 +35,41 @@ function get_channel(spec)
 
   var channel = NetUtil.newChannel({
     uri: NetUtil.newURI(spec),
     loadingPrincipal: principal,
     securityFlags: Ci.nsILoadInfo.SEC_ALLOW_CROSS_ORIGIN_DATA_IS_NULL,
     contentPolicyType: Ci.nsIContentPolicy.TYPE_OTHER
   });
 
-  try {
-    channel.asyncOpen(null);
-    ok(false, "asyncOpen() 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
-    equal(e.code, 1012);
-  }
-
-  try {
-    channel.open();
-    ok(false, "Open() 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
-    equal(e.code, 1012);
-  }
+  Assert.throws(() => { channel.asyncOpen(null); }, /NS_ERROR_DOM_BAD_URI/, `asyncOpen() of uri: ${spec} should throw`);
+  Assert.throws(() => { channel.open(); }, /NS_ERROR_DOM_BAD_URI/, `Open() of uri: ${spec} should throw`);
 
   return channel;
 }
 
 function check_safe_resolution(spec, rootURI)
 {
   info(`Testing URL "${spec}"`);
 
   let channel = get_channel(spec);
 
   ok(channel.name.startsWith(rootURI), `URL resolved safely to ${channel.name}`);
-  ok(!/%2f/i.test(channel.name), `URL contains no escaped / characters`);
+  let startOfQuery = channel.name.indexOf("?");
+  if (startOfQuery == -1) {
+    ok(!/%2f/i.test(channel.name), `URL contains no escaped / characters`);
+  } else {
+    // Escaped slashes are allowed in the query or hash part of the URL
+    ok(!channel.name.replace(/\?.*/, "").includes("%2f"), `URL contains no escaped slashes before the query ${channel.name}`);
+  }
 }
 
 function check_resolution_error(spec)
 {
-  try {
-    get_channel(spec);
-    ok(false, "Expected an error");
-  } catch (e) {
-    equal(e.result, Cr.NS_ERROR_MALFORMED_URI,
-          "Expected a malformed URI error");
-  }
+  Assert.throws(() => { get_channel(spec); }, /NS_ERROR_MALFORMED_URI/, "Expected a malformed URI error");
 }
 
 function run_test() {
   // resource:/// and resource://gre/ are resolved specially, so we need
   // to create a temporary resource package to test the standard logic
   // with.
 
   let resProto = Cc['@mozilla.org/network/protocol;1?name=resource'].getService(Ci.nsIResProtocolHandler);