michael@0: /* This Source Code Form is subject to the terms of the Mozilla Public michael@0: * License, v. 2.0. If a copy of the MPL was not distributed with this michael@0: * file, You can obtain one at http://mozilla.org/MPL/2.0/. michael@0: */ michael@0: michael@0: var gIOS = Cc["@mozilla.org/network/io-service;1"] michael@0: .getService(Ci.nsIIOService); michael@0: michael@0: function test_uri(obj) michael@0: { michael@0: var uri = null; michael@0: var failed = false; michael@0: var message = ""; michael@0: try { michael@0: uri = gIOS.newURI(obj.uri, null, null); michael@0: if (!obj.result) { michael@0: failed = true; michael@0: message = obj.uri + " should not be accepted as a valid URI"; michael@0: } michael@0: } michael@0: catch (ex) { michael@0: if (obj.result) { michael@0: failed = true; michael@0: message = obj.uri + " should be accepted as a valid URI"; michael@0: } michael@0: } michael@0: if (failed) michael@0: do_throw(message); michael@0: if (obj.result) { michael@0: do_check_true(uri != null); michael@0: do_check_eq(uri.spec, obj.uri); michael@0: } michael@0: } michael@0: michael@0: function run_test() michael@0: { michael@0: var tests = [ michael@0: {uri: "chrome://blah/content/blah.xul", result: true}, michael@0: {uri: "chrome://blah/content/:/blah/blah.xul", result: false}, michael@0: {uri: "chrome://blah/content/%252e./blah/blah.xul", result: false}, michael@0: {uri: "chrome://blah/content/%252e%252e/blah/blah.xul", result: false}, michael@0: {uri: "chrome://blah/content/blah.xul?param=%252e./blah/", result: true}, michael@0: {uri: "chrome://blah/content/blah.xul?param=:/blah/", result: true}, michael@0: {uri: "chrome://blah/content/blah.xul?param=%252e%252e/blah/", result: true}, michael@0: ]; michael@0: for (var i = 0; i < tests.length; ++ i) michael@0: test_uri(tests[i]); michael@0: }