diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-07 17:32:43 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-07 17:32:43 +0000 |
commit | 6bf0a5cb5034a7e684dcc3500e841785237ce2dd (patch) | |
tree | a68f146d7fa01f0134297619fbe7e33db084e0aa /comm/mailnews/jsaccount/test/unit/test_fooUrl.js | |
parent | Initial commit. (diff) | |
download | thunderbird-upstream.tar.xz thunderbird-upstream.zip |
Adding upstream version 1:115.7.0.upstream/1%115.7.0upstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'comm/mailnews/jsaccount/test/unit/test_fooUrl.js')
-rw-r--r-- | comm/mailnews/jsaccount/test/unit/test_fooUrl.js | 93 |
1 files changed, 93 insertions, 0 deletions
diff --git a/comm/mailnews/jsaccount/test/unit/test_fooUrl.js b/comm/mailnews/jsaccount/test/unit/test_fooUrl.js new file mode 100644 index 0000000000..8526ef2093 --- /dev/null +++ b/comm/mailnews/jsaccount/test/unit/test_fooUrl.js @@ -0,0 +1,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(); + } +} |