summaryrefslogtreecommitdiffstats
path: root/comm/mailnews/jsaccount/test/unit/test_fooUrl.js
blob: 8526ef209347ac87e55aa7ff12522a03a3f8fcb8 (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
87
88
89
90
91
92
93
/* -*- indent-tabs-mode: nil; js-indent-level: 2 -*- */
/* vim: set ts=2 et sw=2 tw=80 filetype=javascript: */
/* Any copyright is dedicated to the Public Domain.
 * http://creativecommons.org/publicdomain/zero/1.0/ */

// Tests of override functionality using a demo "foo" type url.

var { JaBaseUrlProperties } = ChromeUtils.import(
  "resource:///modules/jsaccount/JaBaseUrl.jsm"
);

var extraInterfaces = [Ci.msgIFooUrl];

function newURL() {
  return Cc["@mozilla.org/jsaccount/testjafoourl;1"].createInstance(
    Ci.nsISupports
  );
}

var tests = [
  function testExists() {
    // test the existence of components and their interfaces.
    let url = newURL();
    for (let iface of JaBaseUrlProperties.baseInterfaces) {
      Assert.ok(url instanceof iface);
      let urlQI = url.QueryInterface(iface);
      // Since the URL wasn't properly initialised, that is, it has no spec
      // the following will crash. The underlying nsMsgMailNewsUrl
      // has no m_baseURL yet and hence GetSpec() triggered by the
      // Assert.uk(urlQI) will crash. So use this instead:
      Assert.ok(urlQI != null);
    }
    for (let iface of extraInterfaces) {
      let fooUrl = url.getInterface(iface);
      Assert.ok(fooUrl instanceof iface);
      Assert.ok(fooUrl.QueryInterface(iface) != null);
    }
  },
  function test_msgIOverride() {
    let url = newURL().QueryInterface(Ci.msgIOverride);

    // test of access to wrapped JS object.

    // Access the ._hidden attribute using the XPCOM interface,
    // where it is not defined.
    Assert.equal(typeof url.jsDelegate._hidden, "undefined");

    // Get the JS object, where _hidden IS defined.
    Assert.equal(url.jsDelegate.wrappedJSObject._hidden, "IAmHidden");
  },

  // We used to test nsIURI, nsIURL, and nsIMsgMailNewsUrl overrides, but those
  // can no longer be overridden.
  function test_nsIMsgMessageUrl() {
    let url = newURL().QueryInterface(Ci.nsIMsgMessageUrl);
    Assert.ok("originalSpec" in url);
    let appDir = Services.dirsvc.get("GreD", Ci.nsIFile);
    Assert.ok(appDir.path);
    // test attributes
    url.messageFile = appDir;
    Assert.equal(url.messageFile.path, appDir.path);
  },
  function test_msgIJaUrl() {
    let url = newURL().QueryInterface(Ci.msgIJaUrl);
    url.setUrlType(Ci.nsIMsgMailNewsUrl.eMove);
    Assert.ok(
      url
        .QueryInterface(Ci.nsIMsgMailNewsUrl)
        .IsUrlType(Ci.nsIMsgMailNewsUrl.eMove)
    );
  },
  function test_msgIFooUrl() {
    let url = newURL().QueryInterface(Ci.nsIInterfaceRequestor);
    let fooUrl = url.getInterface(Ci.msgIFooUrl);
    Assert.ok(fooUrl instanceof Ci.msgIFooUrl);

    fooUrl.itemId = "theItemId";
    Assert.equal(fooUrl.itemId, "theItemId");

    url.QueryInterface(Ci.msgIJaUrl).setSpec("https://foo.invalid/bar/");
    Assert.ok(!fooUrl.isAttachment);
    url
      .QueryInterface(Ci.msgIJaUrl)
      .setSpec("https://foo.invalid/bar?part=1.4&dummy=stuff");
    Assert.ok(fooUrl.isAttachment);
  },
];

function run_test() {
  for (var test of tests) {
    test();
  }
}