michael@0: /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- michael@0: * vim: sw=2 ts=2 sts=2 tw=78 expandtab : 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: let manifests = [ michael@0: do_get_file("data/test_data_protocol_registration.manifest"), michael@0: ]; michael@0: registerManifests(manifests); michael@0: michael@0: let XULAppInfoFactory = { michael@0: // These two are used when we register all our factories (and unregister) michael@0: CID: XULAPPINFO_CID, michael@0: scheme: "XULAppInfo", michael@0: contractID: XULAPPINFO_CONTRACTID, michael@0: createInstance: function (outer, iid) { michael@0: if (outer != null) michael@0: throw Cr.NS_ERROR_NO_AGGREGATION; michael@0: return XULAppInfo.QueryInterface(iid); michael@0: } michael@0: }; michael@0: michael@0: function run_test() michael@0: { michael@0: // Add our XULAppInfo factory michael@0: let factories = [XULAppInfoFactory]; michael@0: michael@0: // Register our factories michael@0: for (let i = 0; i < factories.length; i++) { michael@0: let factory = factories[i]; michael@0: Components.manager.QueryInterface(Ci.nsIComponentRegistrar) michael@0: .registerFactory(factory.CID, "test-" + factory.scheme, michael@0: factory.contractID, factory); michael@0: } michael@0: michael@0: // Check for new chrome michael@0: let cr = Cc["@mozilla.org/chrome/chrome-registry;1"]. michael@0: getService(Ci.nsIChromeRegistry); michael@0: cr.checkForNewChrome(); michael@0: michael@0: // Check that our override worked michael@0: let expectedURI = "data:application/vnd.mozilla.xul+xml,"; michael@0: let sourceURI = "chrome://good-package/content/test.xul"; michael@0: try { michael@0: let ios = Cc["@mozilla.org/network/io-service;1"]. michael@0: getService(Ci.nsIIOService); michael@0: sourceURI = ios.newURI(sourceURI, null, null); michael@0: // this throws for packages that are not registered michael@0: let uri = cr.convertChromeURL(sourceURI).spec; michael@0: michael@0: do_check_eq(expectedURI, uri); michael@0: } michael@0: catch (e) { michael@0: dump(e + "\n"); michael@0: do_throw("Should have registered our URI!"); michael@0: } michael@0: michael@0: // Unregister our factories so we do not leak michael@0: for (let i = 0; i < factories.length; i++) { michael@0: let factory = factories[i]; michael@0: Components.manager.QueryInterface(Ci.nsIComponentRegistrar) michael@0: .unregisterFactory(factory.CID, factory); michael@0: } michael@0: }