chrome/test/unit/test_resolve_uris.js

Wed, 31 Dec 2014 06:09:35 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:09:35 +0100
changeset 0
6474c204b198
permissions
-rw-r--r--

Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.

michael@0 1 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*-
michael@0 2 * This Source Code Form is subject to the terms of the Mozilla Public
michael@0 3 * License, v. 2.0. If a copy of the MPL was not distributed with this
michael@0 4 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
michael@0 5
michael@0 6 // head_crtestutils.js doesn't get included in the child by default
michael@0 7 if (typeof registerManifests === "undefined") {
michael@0 8 load("../unit/head_crtestutils.js");
michael@0 9 }
michael@0 10
michael@0 11 let manifestFile = do_get_file("../unit/data/test_resolve_uris.manifest");
michael@0 12
michael@0 13 let manifests = [ manifestFile ];
michael@0 14 registerManifests(manifests);
michael@0 15
michael@0 16 let ios = Cc["@mozilla.org/network/io-service;1"].
michael@0 17 getService(Ci.nsIIOService);
michael@0 18
michael@0 19 function do_run_test()
michael@0 20 {
michael@0 21 let cr = Cc["@mozilla.org/chrome/chrome-registry;1"].
michael@0 22 getService(Ci.nsIChromeRegistry);
michael@0 23
michael@0 24 // If we don't have libxul or e10s then we don't have process separation, so
michael@0 25 // we don't need to worry about checking for new chrome.
michael@0 26 var appInfo = Cc["@mozilla.org/xre/app-info;1"];
michael@0 27 if (!appInfo ||
michael@0 28 (appInfo.getService(Ci.nsIXULRuntime).processType ==
michael@0 29 Ci.nsIXULRuntime.PROCESS_TYPE_DEFAULT)) {
michael@0 30 cr.checkForNewChrome();
michael@0 31 }
michael@0 32
michael@0 33 // See if our various things were able to register
michael@0 34 let registrationTypes = [
michael@0 35 "content",
michael@0 36 "locale",
michael@0 37 "skin",
michael@0 38 "override",
michael@0 39 "resource",
michael@0 40 ];
michael@0 41
michael@0 42 for (let j = 0; j < registrationTypes.length; j++) {
michael@0 43 let type = registrationTypes[j];
michael@0 44 dump("Testing type '" + type + "'\n");
michael@0 45 let expectedURI = "resource://foo/foo-" + type + "/";
michael@0 46 let sourceURI = "chrome://foo/" + type + "/";
michael@0 47 switch (type) {
michael@0 48 case "content":
michael@0 49 expectedURI += "foo.xul";
michael@0 50 break;
michael@0 51 case "locale":
michael@0 52 expectedURI += "foo.dtd";
michael@0 53 break;
michael@0 54 case "skin":
michael@0 55 expectedURI += "foo.css";
michael@0 56 break;
michael@0 57 case "override":
michael@0 58 sourceURI = "chrome://good-package/content/override-me.xul";
michael@0 59 expectedURI += "override-me.xul";
michael@0 60 break;
michael@0 61 case "resource":
michael@0 62 expectedURI = ios.newFileURI(manifestFile.parent).spec;
michael@0 63 sourceURI = "resource://foo/";
michael@0 64 break;
michael@0 65 };
michael@0 66 try {
michael@0 67 sourceURI = ios.newURI(sourceURI, null, null);
michael@0 68 let uri;
michael@0 69 if (type == "resource") {
michael@0 70 // resources go about a slightly different way than everything else
michael@0 71 let rph = ios.getProtocolHandler("resource").
michael@0 72 QueryInterface(Ci.nsIResProtocolHandler);
michael@0 73 uri = rph.resolveURI(sourceURI);
michael@0 74 }
michael@0 75 else {
michael@0 76 uri = cr.convertChromeURL(sourceURI).spec;
michael@0 77 }
michael@0 78
michael@0 79 do_check_eq(expectedURI, uri);
michael@0 80 }
michael@0 81 catch (e) {
michael@0 82 dump(e + "\n");
michael@0 83 do_throw("Should have registered a handler for type '" +
michael@0 84 type + "'\n");
michael@0 85 }
michael@0 86 }
michael@0 87 }
michael@0 88
michael@0 89 if (typeof run_test === "undefined") {
michael@0 90 run_test = function() {
michael@0 91 do_run_test();
michael@0 92 };
michael@0 93 }

mercurial