michael@0: /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- 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: // head_crtestutils.js doesn't get included in the child by default michael@0: if (typeof registerManifests === "undefined") { michael@0: load("../unit/head_crtestutils.js"); michael@0: } michael@0: michael@0: let manifestFile = do_get_file("../unit/data/test_resolve_uris.manifest"); michael@0: michael@0: let manifests = [ manifestFile ]; michael@0: registerManifests(manifests); michael@0: michael@0: let ios = Cc["@mozilla.org/network/io-service;1"]. michael@0: getService(Ci.nsIIOService); michael@0: michael@0: function do_run_test() michael@0: { michael@0: let cr = Cc["@mozilla.org/chrome/chrome-registry;1"]. michael@0: getService(Ci.nsIChromeRegistry); michael@0: michael@0: // If we don't have libxul or e10s then we don't have process separation, so michael@0: // we don't need to worry about checking for new chrome. michael@0: var appInfo = Cc["@mozilla.org/xre/app-info;1"]; michael@0: if (!appInfo || michael@0: (appInfo.getService(Ci.nsIXULRuntime).processType == michael@0: Ci.nsIXULRuntime.PROCESS_TYPE_DEFAULT)) { michael@0: cr.checkForNewChrome(); michael@0: } michael@0: michael@0: // See if our various things were able to register michael@0: let registrationTypes = [ michael@0: "content", michael@0: "locale", michael@0: "skin", michael@0: "override", michael@0: "resource", michael@0: ]; michael@0: michael@0: for (let j = 0; j < registrationTypes.length; j++) { michael@0: let type = registrationTypes[j]; michael@0: dump("Testing type '" + type + "'\n"); michael@0: let expectedURI = "resource://foo/foo-" + type + "/"; michael@0: let sourceURI = "chrome://foo/" + type + "/"; michael@0: switch (type) { michael@0: case "content": michael@0: expectedURI += "foo.xul"; michael@0: break; michael@0: case "locale": michael@0: expectedURI += "foo.dtd"; michael@0: break; michael@0: case "skin": michael@0: expectedURI += "foo.css"; michael@0: break; michael@0: case "override": michael@0: sourceURI = "chrome://good-package/content/override-me.xul"; michael@0: expectedURI += "override-me.xul"; michael@0: break; michael@0: case "resource": michael@0: expectedURI = ios.newFileURI(manifestFile.parent).spec; michael@0: sourceURI = "resource://foo/"; michael@0: break; michael@0: }; michael@0: try { michael@0: sourceURI = ios.newURI(sourceURI, null, null); michael@0: let uri; michael@0: if (type == "resource") { michael@0: // resources go about a slightly different way than everything else michael@0: let rph = ios.getProtocolHandler("resource"). michael@0: QueryInterface(Ci.nsIResProtocolHandler); michael@0: uri = rph.resolveURI(sourceURI); michael@0: } michael@0: else { michael@0: uri = cr.convertChromeURL(sourceURI).spec; michael@0: } 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 a handler for type '" + michael@0: type + "'\n"); michael@0: } michael@0: } michael@0: } michael@0: michael@0: if (typeof run_test === "undefined") { michael@0: run_test = function() { michael@0: do_run_test(); michael@0: }; michael@0: }