chrome/test/unit/test_data_protocol_registration.js

Tue, 06 Jan 2015 21:39:09 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Tue, 06 Jan 2015 21:39:09 +0100
branch
TOR_BUG_9701
changeset 8
97036ab72558
permissions
-rw-r--r--

Conditionally force memory storage according to privacy.thirdparty.isolate;
This solves Tor bug #9701, complying with disk avoidance documented in
https://www.torproject.org/projects/torbrowser/design/#disk-avoidance.

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

mercurial