1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/chrome/test/unit/test_bug397073.js Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,87 @@ 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_bug397073.manifest") 1.11 +]; 1.12 + 1.13 + 1.14 +registerManifests(MANIFESTS); 1.15 + 1.16 +var XULAppInfo = { 1.17 + vendor: "Mozilla", 1.18 + name: "XPCShell", 1.19 + ID: "{39885e5f-f6b4-4e2a-87e5-6259ecf79011}", 1.20 + version: "5", 1.21 + appBuildID: "2007010101", 1.22 + platformVersion: "1.9", 1.23 + platformBuildID: "2007010101", 1.24 + inSafeMode: false, 1.25 + logConsoleErrors: true, 1.26 + OS: "XPCShell", 1.27 + XPCOMABI: "noarch-spidermonkey", 1.28 + 1.29 + QueryInterface: function QueryInterface(iid) { 1.30 + if (iid.equals(Ci.nsIXULAppInfo) 1.31 + || iid.equals(Ci.nsIXULRuntime) 1.32 + || iid.equals(Ci.nsISupports)) 1.33 + return this; 1.34 + 1.35 + throw Components.results.NS_ERROR_NO_INTERFACE; 1.36 + } 1.37 +}; 1.38 + 1.39 +var XULAppInfoFactory = { 1.40 + createInstance: function (outer, iid) { 1.41 + if (outer != null) 1.42 + throw Components.results.NS_ERROR_NO_AGGREGATION; 1.43 + return XULAppInfo.QueryInterface(iid); 1.44 + } 1.45 +}; 1.46 +var registrar = Components.manager.QueryInterface(Ci.nsIComponentRegistrar); 1.47 +registrar.registerFactory(XULAPPINFO_CID, "XULAppInfo", 1.48 + XULAPPINFO_CONTRACTID, XULAppInfoFactory); 1.49 + 1.50 +var gIOS = Cc["@mozilla.org/network/io-service;1"] 1.51 + .getService(Ci.nsIIOService); 1.52 +var chromeReg = Cc["@mozilla.org/chrome/chrome-registry;1"] 1.53 + .getService(Ci.nsIChromeRegistry); 1.54 +chromeReg.checkForNewChrome(); 1.55 + 1.56 +var target = gIOS.newFileURI(do_get_file("data")); 1.57 +target = target.spec + "test/test.xul"; 1.58 + 1.59 +function test_succeeded_mapping(namespace) 1.60 +{ 1.61 + var uri = gIOS.newURI("chrome://" + namespace + "/content/test.xul", 1.62 + null, null); 1.63 + try { 1.64 + var result = chromeReg.convertChromeURL(uri); 1.65 + do_check_eq(result.spec, target); 1.66 + } 1.67 + catch (ex) { 1.68 + do_throw(namespace); 1.69 + } 1.70 +} 1.71 + 1.72 +function test_failed_mapping(namespace) 1.73 +{ 1.74 + var uri = gIOS.newURI("chrome://" + namespace + "/content/test.xul", 1.75 + null, null); 1.76 + try { 1.77 + var result = chromeReg.convertChromeURL(uri); 1.78 + do_throw(namespace); 1.79 + } 1.80 + catch (ex) { 1.81 + } 1.82 +} 1.83 + 1.84 +function run_test() 1.85 +{ 1.86 + test_succeeded_mapping("test1"); 1.87 + test_succeeded_mapping("test2"); 1.88 + 1.89 + test_failed_mapping("test3"); 1.90 +}