summaryrefslogtreecommitdiffstats
path: root/chrome/test/unit/test_resolve_uris.js
blob: 638a0f9b094967eaafce08de8f151f07d8fac233 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
/* -*- indent-tabs-mode: nil; js-indent-level: 2 -*-
 * This Source Code Form is subject to the terms of the Mozilla Public
 * License, v. 2.0. If a copy of the MPL was not distributed with this
 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */

// head_crtestutils.js doesn't get included in the child by default
if (typeof registerManifests === "undefined") {
  load("../unit/head_crtestutils.js");
}

var manifestFile = do_get_file("../unit/data/test_resolve_uris.manifest");

var manifests = [manifestFile];
registerManifests(manifests);

function do_run_test() {
  let cr = Cc["@mozilla.org/chrome/chrome-registry;1"].getService(
    Ci.nsIChromeRegistry
  );

  // If we don't have libxul or e10s then we don't have process separation, so
  // we don't need to worry about checking for new chrome.
  var appInfo = Cc["@mozilla.org/xre/app-info;1"];
  if (
    !appInfo ||
    // eslint-disable-next-line mozilla/use-services
    appInfo.getService(Ci.nsIXULRuntime).processType ==
      Ci.nsIXULRuntime.PROCESS_TYPE_DEFAULT
  ) {
    cr.checkForNewChrome();
  }

  // See if our various things were able to register
  let registrationTypes = ["content", "locale", "skin", "override", "resource"];

  for (let j = 0; j < registrationTypes.length; j++) {
    let type = registrationTypes[j];
    dump("Testing type '" + type + "'\n");
    let expectedURI = "resource://foo/foo-" + type + "/";
    let sourceURI = "chrome://foo/" + type + "/";
    switch (type) {
      case "content":
        expectedURI += "foo.xul";
        break;
      case "locale":
        expectedURI += "foo.dtd";
        break;
      case "skin":
        expectedURI += "foo.css";
        break;
      case "override":
        sourceURI = "chrome://good-package/content/override-me.xul";
        expectedURI += "override-me.xul";
        break;
      case "resource":
        expectedURI = Services.io.newFileURI(manifestFile.parent).spec;
        sourceURI = "resource://foo/";
        break;
    }
    try {
      sourceURI = Services.io.newURI(sourceURI);
      let uri;
      if (type == "resource") {
        // resources go about a slightly different way than everything else
        let rph = Services.io
          .getProtocolHandler("resource")
          .QueryInterface(Ci.nsIResProtocolHandler);
        uri = rph.resolveURI(sourceURI);
      } else {
        uri = cr.convertChromeURL(sourceURI).spec;
      }

      Assert.equal(expectedURI, uri);
    } catch (e) {
      dump(e + "\n");
      do_throw("Should have registered a handler for type '" + type + "'\n");
    }
  }
}

if (typeof run_test === "undefined") {
  // eslint-disable-next-line no-global-assign
  run_test = function () {
    do_run_test();
  };
}