1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/chrome/test/unit/test_data_protocol_registration.js Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,65 @@ 1.4 +/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- 1.5 + * vim: sw=2 ts=2 sts=2 tw=78 expandtab : 1.6 + * This Source Code Form is subject to the terms of the Mozilla Public 1.7 + * License, v. 2.0. If a copy of the MPL was not distributed with this 1.8 + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ 1.9 + 1.10 +let manifests = [ 1.11 + do_get_file("data/test_data_protocol_registration.manifest"), 1.12 +]; 1.13 +registerManifests(manifests); 1.14 + 1.15 +let XULAppInfoFactory = { 1.16 + // These two are used when we register all our factories (and unregister) 1.17 + CID: XULAPPINFO_CID, 1.18 + scheme: "XULAppInfo", 1.19 + contractID: XULAPPINFO_CONTRACTID, 1.20 + createInstance: function (outer, iid) { 1.21 + if (outer != null) 1.22 + throw Cr.NS_ERROR_NO_AGGREGATION; 1.23 + return XULAppInfo.QueryInterface(iid); 1.24 + } 1.25 +}; 1.26 + 1.27 +function run_test() 1.28 +{ 1.29 + // Add our XULAppInfo factory 1.30 + let factories = [XULAppInfoFactory]; 1.31 + 1.32 + // Register our factories 1.33 + for (let i = 0; i < factories.length; i++) { 1.34 + let factory = factories[i]; 1.35 + Components.manager.QueryInterface(Ci.nsIComponentRegistrar) 1.36 + .registerFactory(factory.CID, "test-" + factory.scheme, 1.37 + factory.contractID, factory); 1.38 + } 1.39 + 1.40 + // Check for new chrome 1.41 + let cr = Cc["@mozilla.org/chrome/chrome-registry;1"]. 1.42 + getService(Ci.nsIChromeRegistry); 1.43 + cr.checkForNewChrome(); 1.44 + 1.45 + // Check that our override worked 1.46 + let expectedURI = "data:application/vnd.mozilla.xul+xml,"; 1.47 + let sourceURI = "chrome://good-package/content/test.xul"; 1.48 + try { 1.49 + let ios = Cc["@mozilla.org/network/io-service;1"]. 1.50 + getService(Ci.nsIIOService); 1.51 + sourceURI = ios.newURI(sourceURI, null, null); 1.52 + // this throws for packages that are not registered 1.53 + let uri = cr.convertChromeURL(sourceURI).spec; 1.54 + 1.55 + do_check_eq(expectedURI, uri); 1.56 + } 1.57 + catch (e) { 1.58 + dump(e + "\n"); 1.59 + do_throw("Should have registered our URI!"); 1.60 + } 1.61 + 1.62 + // Unregister our factories so we do not leak 1.63 + for (let i = 0; i < factories.length; i++) { 1.64 + let factory = factories[i]; 1.65 + Components.manager.QueryInterface(Ci.nsIComponentRegistrar) 1.66 + .unregisterFactory(factory.CID, factory); 1.67 + } 1.68 +}