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