chrome/test/unit/test_data_protocol_registration.js

branch
TOR_BUG_9701
changeset 8
97036ab72558
equal deleted inserted replaced
-1:000000000000 0:76479a55ddb2
1 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
2 * vim: sw=2 ts=2 sts=2 tw=78 expandtab :
3 * This Source Code Form is subject to the terms of the Mozilla Public
4 * License, v. 2.0. If a copy of the MPL was not distributed with this
5 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
6
7 let manifests = [
8 do_get_file("data/test_data_protocol_registration.manifest"),
9 ];
10 registerManifests(manifests);
11
12 let XULAppInfoFactory = {
13 // These two are used when we register all our factories (and unregister)
14 CID: XULAPPINFO_CID,
15 scheme: "XULAppInfo",
16 contractID: XULAPPINFO_CONTRACTID,
17 createInstance: function (outer, iid) {
18 if (outer != null)
19 throw Cr.NS_ERROR_NO_AGGREGATION;
20 return XULAppInfo.QueryInterface(iid);
21 }
22 };
23
24 function run_test()
25 {
26 // Add our XULAppInfo factory
27 let factories = [XULAppInfoFactory];
28
29 // Register our factories
30 for (let i = 0; i < factories.length; i++) {
31 let factory = factories[i];
32 Components.manager.QueryInterface(Ci.nsIComponentRegistrar)
33 .registerFactory(factory.CID, "test-" + factory.scheme,
34 factory.contractID, factory);
35 }
36
37 // Check for new chrome
38 let cr = Cc["@mozilla.org/chrome/chrome-registry;1"].
39 getService(Ci.nsIChromeRegistry);
40 cr.checkForNewChrome();
41
42 // Check that our override worked
43 let expectedURI = "data:application/vnd.mozilla.xul+xml,";
44 let sourceURI = "chrome://good-package/content/test.xul";
45 try {
46 let ios = Cc["@mozilla.org/network/io-service;1"].
47 getService(Ci.nsIIOService);
48 sourceURI = ios.newURI(sourceURI, null, null);
49 // this throws for packages that are not registered
50 let uri = cr.convertChromeURL(sourceURI).spec;
51
52 do_check_eq(expectedURI, uri);
53 }
54 catch (e) {
55 dump(e + "\n");
56 do_throw("Should have registered our URI!");
57 }
58
59 // Unregister our factories so we do not leak
60 for (let i = 0; i < factories.length; i++) {
61 let factory = factories[i];
62 Components.manager.QueryInterface(Ci.nsIComponentRegistrar)
63 .unregisterFactory(factory.CID, factory);
64 }
65 }

mercurial