1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/chrome/test/unit/test_bug401153.js Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,81 @@ 1.4 +/* This Source Code Form is subject to the terms of the Mozilla Public 1.5 + * License, v. 2.0. If a copy of the MPL was not distributed with this 1.6 + * file, You can obtain one at http://mozilla.org/MPL/2.0/. 1.7 + */ 1.8 + 1.9 +var MANIFESTS = [ 1.10 + do_get_file("data/test_bug401153.manifest") 1.11 +]; 1.12 + 1.13 +registerManifests(MANIFESTS); 1.14 + 1.15 +var XULAppInfo = { 1.16 + vendor: "Mozilla", 1.17 + name: "XPCShell", 1.18 + ID: "{39885e5f-f6b4-4e2a-87e5-6259ecf79011}", 1.19 + version: "5", 1.20 + appBuildID: "2007010101", 1.21 + platformVersion: "1.9", 1.22 + platformBuildID: "2007010101", 1.23 + inSafeMode: false, 1.24 + logConsoleErrors: true, 1.25 + OS: "XPCShell", 1.26 + XPCOMABI: "noarch-spidermonkey", 1.27 + 1.28 + QueryInterface: function QueryInterface(iid) { 1.29 + if (iid.equals(Ci.nsIXULAppInfo) 1.30 + || iid.equals(Ci.nsIXULRuntime) 1.31 + || iid.equals(Ci.nsISupports)) 1.32 + return this; 1.33 + 1.34 + throw Components.results.NS_ERROR_NO_INTERFACE; 1.35 + } 1.36 +}; 1.37 + 1.38 +var XULAppInfoFactory = { 1.39 + createInstance: function (outer, iid) { 1.40 + if (outer != null) 1.41 + throw Components.results.NS_ERROR_NO_AGGREGATION; 1.42 + return XULAppInfo.QueryInterface(iid); 1.43 + } 1.44 +}; 1.45 +var registrar = Components.manager.QueryInterface(Ci.nsIComponentRegistrar); 1.46 +registrar.registerFactory(XULAPPINFO_CID, "XULAppInfo", 1.47 + XULAPPINFO_CONTRACTID, XULAppInfoFactory); 1.48 + 1.49 +var gIOS = Cc["@mozilla.org/network/io-service;1"] 1.50 + .getService(Ci.nsIIOService); 1.51 +var chromeReg = Cc["@mozilla.org/chrome/chrome-registry;1"] 1.52 + .getService(Ci.nsIChromeRegistry); 1.53 +chromeReg.checkForNewChrome(); 1.54 + 1.55 +var rph = gIOS.getProtocolHandler("resource") 1.56 + .QueryInterface(Ci.nsIResProtocolHandler); 1.57 + 1.58 +function test_succeeded_mapping(namespace, target) 1.59 +{ 1.60 + try { 1.61 + do_check_true(rph.hasSubstitution(namespace)); 1.62 + var uri = gIOS.newURI("resource://" + namespace, null, null); 1.63 + dump("### checking for " + target + ", getting " + rph.resolveURI(uri) + "\n"); 1.64 + do_check_eq(rph.resolveURI(uri), target); 1.65 + } 1.66 + catch (ex) { 1.67 + dump(ex + "\n"); 1.68 + do_throw(namespace); 1.69 + } 1.70 +} 1.71 + 1.72 +function test_failed_mapping(namespace) 1.73 +{ 1.74 + do_check_false(rph.hasSubstitution(namespace)); 1.75 +} 1.76 + 1.77 +function run_test() 1.78 +{ 1.79 + var data = gIOS.newFileURI(do_get_file("data")).spec; 1.80 + test_succeeded_mapping("test1", data + "test1/"); 1.81 + test_succeeded_mapping("test3", "jar:" + data + "test3.jar!/resources/"); 1.82 + test_failed_mapping("test4"); 1.83 + test_succeeded_mapping("test5", data + "test5/"); 1.84 +}