1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/chrome/test/unit/test_resolve_uris.js Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,93 @@ 1.4 +/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- 1.5 + * This Source Code Form is subject to the terms of the Mozilla Public 1.6 + * License, v. 2.0. If a copy of the MPL was not distributed with this 1.7 + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ 1.8 + 1.9 +// head_crtestutils.js doesn't get included in the child by default 1.10 +if (typeof registerManifests === "undefined") { 1.11 + load("../unit/head_crtestutils.js"); 1.12 +} 1.13 + 1.14 +let manifestFile = do_get_file("../unit/data/test_resolve_uris.manifest"); 1.15 + 1.16 +let manifests = [ manifestFile ]; 1.17 +registerManifests(manifests); 1.18 + 1.19 +let ios = Cc["@mozilla.org/network/io-service;1"]. 1.20 + getService(Ci.nsIIOService); 1.21 + 1.22 +function do_run_test() 1.23 +{ 1.24 + let cr = Cc["@mozilla.org/chrome/chrome-registry;1"]. 1.25 + getService(Ci.nsIChromeRegistry); 1.26 + 1.27 + // If we don't have libxul or e10s then we don't have process separation, so 1.28 + // we don't need to worry about checking for new chrome. 1.29 + var appInfo = Cc["@mozilla.org/xre/app-info;1"]; 1.30 + if (!appInfo || 1.31 + (appInfo.getService(Ci.nsIXULRuntime).processType == 1.32 + Ci.nsIXULRuntime.PROCESS_TYPE_DEFAULT)) { 1.33 + cr.checkForNewChrome(); 1.34 + } 1.35 + 1.36 + // See if our various things were able to register 1.37 + let registrationTypes = [ 1.38 + "content", 1.39 + "locale", 1.40 + "skin", 1.41 + "override", 1.42 + "resource", 1.43 + ]; 1.44 + 1.45 + for (let j = 0; j < registrationTypes.length; j++) { 1.46 + let type = registrationTypes[j]; 1.47 + dump("Testing type '" + type + "'\n"); 1.48 + let expectedURI = "resource://foo/foo-" + type + "/"; 1.49 + let sourceURI = "chrome://foo/" + type + "/"; 1.50 + switch (type) { 1.51 + case "content": 1.52 + expectedURI += "foo.xul"; 1.53 + break; 1.54 + case "locale": 1.55 + expectedURI += "foo.dtd"; 1.56 + break; 1.57 + case "skin": 1.58 + expectedURI += "foo.css"; 1.59 + break; 1.60 + case "override": 1.61 + sourceURI = "chrome://good-package/content/override-me.xul"; 1.62 + expectedURI += "override-me.xul"; 1.63 + break; 1.64 + case "resource": 1.65 + expectedURI = ios.newFileURI(manifestFile.parent).spec; 1.66 + sourceURI = "resource://foo/"; 1.67 + break; 1.68 + }; 1.69 + try { 1.70 + sourceURI = ios.newURI(sourceURI, null, null); 1.71 + let uri; 1.72 + if (type == "resource") { 1.73 + // resources go about a slightly different way than everything else 1.74 + let rph = ios.getProtocolHandler("resource"). 1.75 + QueryInterface(Ci.nsIResProtocolHandler); 1.76 + uri = rph.resolveURI(sourceURI); 1.77 + } 1.78 + else { 1.79 + uri = cr.convertChromeURL(sourceURI).spec; 1.80 + } 1.81 + 1.82 + do_check_eq(expectedURI, uri); 1.83 + } 1.84 + catch (e) { 1.85 + dump(e + "\n"); 1.86 + do_throw("Should have registered a handler for type '" + 1.87 + type + "'\n"); 1.88 + } 1.89 + } 1.90 +} 1.91 + 1.92 +if (typeof run_test === "undefined") { 1.93 + run_test = function() { 1.94 + do_run_test(); 1.95 + }; 1.96 +}