summaryrefslogtreecommitdiffstats
path: root/comm/mailnews/jsaccount/test
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-07 17:32:43 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-07 17:32:43 +0000
commit6bf0a5cb5034a7e684dcc3500e841785237ce2dd (patch)
treea68f146d7fa01f0134297619fbe7e33db084e0aa /comm/mailnews/jsaccount/test
parentInitial commit. (diff)
downloadthunderbird-6bf0a5cb5034a7e684dcc3500e841785237ce2dd.tar.xz
thunderbird-6bf0a5cb5034a7e684dcc3500e841785237ce2dd.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')
-rw-r--r--comm/mailnews/jsaccount/test/components.conf14
-rw-r--r--comm/mailnews/jsaccount/test/idl/moz.build15
-rw-r--r--comm/mailnews/jsaccount/test/idl/msgIFooUrl.idl17
-rw-r--r--comm/mailnews/jsaccount/test/moz.build15
-rw-r--r--comm/mailnews/jsaccount/test/unit/head_jsaccount.js60
-rw-r--r--comm/mailnews/jsaccount/test/unit/resources/TestJaMsgProtocolInfoComponent.jsm75
-rw-r--r--comm/mailnews/jsaccount/test/unit/resources/readme.html62
-rw-r--r--comm/mailnews/jsaccount/test/unit/resources/testComponents.manifest16
-rw-r--r--comm/mailnews/jsaccount/test/unit/resources/testJaBaseIncomingServer.jsm74
-rw-r--r--comm/mailnews/jsaccount/test/unit/resources/testJaBaseIncomingServerComponent.js20
-rw-r--r--comm/mailnews/jsaccount/test/unit/resources/testJaBaseMsgFolder.jsm70
-rw-r--r--comm/mailnews/jsaccount/test/unit/resources/testJaBaseMsgFolderComponent.js19
-rw-r--r--comm/mailnews/jsaccount/test/unit/resources/testJaFooUrlComponent.js88
-rw-r--r--comm/mailnews/jsaccount/test/unit/test_componentsExist.js90
-rw-r--r--comm/mailnews/jsaccount/test/unit/test_fooUrl.js93
-rw-r--r--comm/mailnews/jsaccount/test/unit/test_jaMsgFolder.js56
-rw-r--r--comm/mailnews/jsaccount/test/unit/xpcshell.ini10
17 files changed, 794 insertions, 0 deletions
diff --git a/comm/mailnews/jsaccount/test/components.conf b/comm/mailnews/jsaccount/test/components.conf
new file mode 100644
index 0000000000..63e26224b3
--- /dev/null
+++ b/comm/mailnews/jsaccount/test/components.conf
@@ -0,0 +1,14 @@
+# -*- Mode: python; indent-tabs-mode: nil; tab-width: 40 -*-
+# vim: set filetype=python:
+# 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/.
+
+Classes = [
+ {
+ "cid": "{74b9b9c3-9594-41c4-b9f0-326e5daac2e0}",
+ "contract_ids": ["@mozilla.org/messenger/protocol/info;1?type=testja"],
+ "jsm": "resource:///modules/jsaccount/TestJaMsgProtocolInfoComponent.jsm",
+ "constructor": "TestJaMsgProtocolInfo",
+ },
+]
diff --git a/comm/mailnews/jsaccount/test/idl/moz.build b/comm/mailnews/jsaccount/test/idl/moz.build
new file mode 100644
index 0000000000..9975e6125b
--- /dev/null
+++ b/comm/mailnews/jsaccount/test/idl/moz.build
@@ -0,0 +1,15 @@
+# -*- Mode: python; c-basic-offset: 4; indent-tabs-mode: nil; tab-width: 40 -*-
+# vim: set filetype=python:
+# Any copyright is dedicated to the Public Domain.
+# http://creativecommons.org/publicdomain/zero/1.0/
+
+XPIDL_SOURCES += [
+ "msgIFooUrl.idl",
+]
+
+XPIDL_MODULE = "testJsAccount"
+
+if "comm" in CONFIG["MOZ_BUILD_APP"]:
+ test_harness_base = TEST_HARNESS_FILES.xpcshell.comm
+else:
+ test_harness_base = TEST_HARNESS_FILES.xpcshell
diff --git a/comm/mailnews/jsaccount/test/idl/msgIFooUrl.idl b/comm/mailnews/jsaccount/test/idl/msgIFooUrl.idl
new file mode 100644
index 0000000000..9652a27cc5
--- /dev/null
+++ b/comm/mailnews/jsaccount/test/idl/msgIFooUrl.idl
@@ -0,0 +1,17 @@
+/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
+/* vim:set ts=2 sw=2 sts=2 et cindent: */
+/* Any copyright is dedicated to the Public Domain.
+ * http://creativecommons.org/publicdomain/zero/1.0/ */
+
+// This is a sample test interface implemented by the URL object.
+
+#include "nsISupports.idl"
+
+[scriptable, uuid(12CAD9FC-57FC-4AEE-A800-895A289237DD)]
+interface msgIFooUrl : nsISupports
+{
+ /// Foo id for item.
+ attribute AString itemId;
+ /// Does this url refer to an attachment?
+ readonly attribute boolean isAttachment;
+};
diff --git a/comm/mailnews/jsaccount/test/moz.build b/comm/mailnews/jsaccount/test/moz.build
new file mode 100644
index 0000000000..a3af38d313
--- /dev/null
+++ b/comm/mailnews/jsaccount/test/moz.build
@@ -0,0 +1,15 @@
+# -*- Mode: python; c-basic-offset: 4; indent-tabs-mode: nil; tab-width: 40 -*-
+# vim: set filetype=python:
+# Any copyright is dedicated to the Public Domain.
+# http://creativecommons.org/publicdomain/zero/1.0/
+
+TEST_DIRS += [
+ "idl",
+]
+
+XPCSHELL_TESTS_MANIFESTS += ["unit/xpcshell.ini"]
+
+TESTING_JS_MODULES.mailnews += [
+ "unit/resources/testJaBaseIncomingServer.jsm",
+ "unit/resources/testJaBaseMsgFolder.jsm",
+]
diff --git a/comm/mailnews/jsaccount/test/unit/head_jsaccount.js b/comm/mailnews/jsaccount/test/unit/head_jsaccount.js
new file mode 100644
index 0000000000..a3c37dea1f
--- /dev/null
+++ b/comm/mailnews/jsaccount/test/unit/head_jsaccount.js
@@ -0,0 +1,60 @@
+/* -*- 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/ */
+
+var CC = Components.Constructor;
+
+var { MailServices } = ChromeUtils.import(
+ "resource:///modules/MailServices.jsm"
+);
+var { XPCOMUtils } = ChromeUtils.importESModule(
+ "resource://gre/modules/XPCOMUtils.sys.mjs"
+);
+var { mailTestUtils } = ChromeUtils.import(
+ "resource://testing-common/mailnews/MailTestUtils.jsm"
+);
+var { localAccountUtils } = ChromeUtils.import(
+ "resource://testing-common/mailnews/LocalAccountUtils.jsm"
+);
+
+// Load the test components.
+let contracts = [
+ {
+ contractID: "@mozilla.org/jsaccount/testjafoourl;1",
+ classID: "{73F98539-A59F-4F6F-9A72-D83A08646C23}",
+ source: "resources/testJaFooUrlComponent.js",
+ },
+ {
+ contractID: "@mozilla.org/mail/folder-factory;1?name=testja",
+ classID: "{8508ddeb-3eab-4877-a420-297518f62371}",
+ source: "resources/testJaBaseMsgFolderComponent.js",
+ },
+ {
+ contractID: "@mozilla.org/messenger/server;1?type=testja",
+ classID: "{0eec03cd-da67-4949-ab2d-5fa4bdc68135}",
+ source: "resources/testJaBaseIncomingServerComponent.js",
+ },
+];
+
+let registrar = Components.manager.QueryInterface(Ci.nsIComponentRegistrar);
+for (let { contractID, classID, source } of contracts) {
+ let scope = {};
+ Services.scriptloader.loadSubScript(
+ Services.io.newFileURI(do_get_file(source)).spec,
+ scope
+ );
+ registrar.registerFactory(
+ Components.ID(classID),
+ "",
+ contractID,
+ scope.xpcomFactory
+ );
+}
+
+// Ensure the profile directory is set up.
+do_get_profile();
+
+registerCleanupFunction(function () {
+ load("../../../../mailnews/resources/mailShutdown.js");
+});
diff --git a/comm/mailnews/jsaccount/test/unit/resources/TestJaMsgProtocolInfoComponent.jsm b/comm/mailnews/jsaccount/test/unit/resources/TestJaMsgProtocolInfoComponent.jsm
new file mode 100644
index 0000000000..555f395220
--- /dev/null
+++ b/comm/mailnews/jsaccount/test/unit/resources/TestJaMsgProtocolInfoComponent.jsm
@@ -0,0 +1,75 @@
+/* -*- 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/ */
+
+// This file is the component definition for a demo base implementation of a
+// javascript nsIMsgProtocolInfo implementation.
+
+var EXPORTED_SYMBOLS = ["TestJaMsgProtocolInfo"];
+
+function TestJaMsgProtocolInfo() {
+ dump("testJaMsgProtocolInfo");
+ // nsIFile object to be used for the default local path.
+ this._defaultLocalPath = null;
+}
+
+TestJaMsgProtocolInfo.prototype = {
+ // Flag this item as CPP needs to delegate to JS.
+ _JsPrototypeToDelegate: true,
+
+ get defaultLocalPath() {
+ if (this._defaultLocalPath) {
+ return this._defaultLocalPath;
+ }
+ // Setup a default location, "TestFoo" directory in profile.
+ const NS_APP_USER_PROFILE_50_DIR = "ProfD";
+ let typedir = Services.dirsvc.get(NS_APP_USER_PROFILE_50_DIR, Ci.nsIFile);
+ typedir.append("TestFoo");
+ if (!typedir.exists()) {
+ typedir.create(Ci.nsIFile.DIRECTORY_TYPE, parseInt("0700", 8));
+ }
+ this._defaultLocalPath = typedir;
+ return typedir;
+ },
+ set defaultLocalPath(defaultLocalPath) {
+ this._defaultLocalPath = defaultLocalPath;
+ },
+ // serverIID is used in AccountWizard.js, if missing will just report an error.
+ get serverIID() {
+ return null;
+ },
+ get requiresUsername() {
+ return false;
+ },
+ get preflightPrettyNameWithEmailAddress() {
+ return false;
+ },
+ get canDelete() {
+ return true;
+ },
+ get canLoginAtStartUp() {
+ return false;
+ },
+ get canDuplicate() {
+ return false;
+ },
+ getDefaultServerPort: isSecure => 0,
+ get canGetMessages() {
+ return false;
+ },
+ get canGetIncomingMessages() {
+ return false;
+ },
+ get defaultDoBiff() {
+ return false;
+ },
+ get showComposeMsgLink() {
+ return false;
+ },
+ get foldersCreatedAsync() {
+ return false;
+ },
+
+ QueryInterface: ChromeUtils.generateQI(["nsIMsgProtocolInfo"]),
+};
diff --git a/comm/mailnews/jsaccount/test/unit/resources/readme.html b/comm/mailnews/jsaccount/test/unit/resources/readme.html
new file mode 100644
index 0000000000..e5490e7d41
--- /dev/null
+++ b/comm/mailnews/jsaccount/test/unit/resources/readme.html
@@ -0,0 +1,62 @@
+<!DOCTYPE html>
+<html>
+ <head>
+ <meta http-equiv="content-type" content="text/html; charset=utf-8">
+ <title>JsAccount Usage and Architecture</title>
+ </head>
+ <body>
+ <h2>Overview of Testing Objects </h2>
+ This directory contains sample JS components to test the basic JsAccount
+ concepts, which can also serve as templates for new implementations.<br>
+ <h3>Component Naming</h3>
+ Because there are many different components involved with different roles,
+ it will be helpful to keep things straight by using a specific naming
+ convention for objects.
+ For testing, we consider that we are creating a new account type "foo". For
+ the specific case of the JA implementation of an object that implements the
+ nsIMsgMailNewsUrl interface, we'll use the following naming convention.
+ Typically C++ classes and JS constructors are capitalized, class instances
+ are not.<br>
+ <br>
+ Names are constructed with the following subparts:<br>
+ <br>
+ (<strong>Ja)</strong>(<strong>AccountType</strong>)(<strong>Language</strong>)(<strong>ComponentType</strong>)(<strong>Role</strong>)
+ <br>
+ <h4>Common parts of names</h4>
+ <ul>
+ <li><strong>Ja</strong>: All objects or classes begin with Ja</li>
+ <li><strong>AccountType</strong>: the type of account being created (here
+ <strong>Foo</strong>), or <strong>Base</strong> for the generic
+ implementation that is the base class of all types. May be *blank* if
+ the object is used for both base types and specific types.</li>
+ <li>
+ <strong>Language</strong>: Use <strong>Cpp</strong> with objects and
+ classes implemented using C++, leave blank for JS versions.
+ </li>
+ <li>
+ <strong>ComponentType</strong>: the standard MailNews term for objects
+ that implement a particular interface. The legacy .cpp base components
+ are typically named:<br>
+ <strong>(nsMsg)(ComponentType</strong>).cpp<br>
+ for example <strong>nsMsgIncomingServer</strong>.cpp. This may be
+ shortened where appropriate, for example we use <strong>Url</strong>
+ instead of <strong>MailNewsUrl</strong> as the <strong>Ja</strong>
+ prefix implies that this is an implementation of MailNews objects.</li>
+ <li><strong>Role</strong>: the function of the object within the JA
+ architecture.</li>
+ <ul>
+ <li><strong>Constructor</strong>: Creates the object only. </li>
+ <li><strong>Delegator</strong>: Calls the appropriate object, either a
+ JS or C++ variant, that implements a particular XPCOM method.
+ </li>
+ <li> <strong>Properties</strong>: JavaScript object that establishes
+ properties of a JA implementation class. This is used for automatic
+ generation of a list of methods to delegate to the JavaScript classes.</li>
+ <li>(blank): Actual implementation.</li>
+ </ul>
+ </ul>
+ Example: The C++ class that delegates the implementation of
+ nsIMsgMailNewsUrl (abbreviated as Url) to either a C++ or JS method is
+ called <strong>JaCppUrlDelegator</strong>.
+ </body>
+</html>
diff --git a/comm/mailnews/jsaccount/test/unit/resources/testComponents.manifest b/comm/mailnews/jsaccount/test/unit/resources/testComponents.manifest
new file mode 100644
index 0000000000..22bacb7262
--- /dev/null
+++ b/comm/mailnews/jsaccount/test/unit/resources/testComponents.manifest
@@ -0,0 +1,16 @@
+# Any copyright is dedicated to the Public Domain.
+# http://creativecommons.org/publicdomain/zero/1.0/
+
+# Definitions of components used in testing of JsAccount
+
+# nsIMsgMailNewsUrl implementation of a demo base URL
+component {73F98539-A59F-4F6F-9A72-D83A08646C23} testJaFooUrlComponent.js
+contract @mozilla.org/jsaccount/testjafoourl;1 {73F98539-A59F-4F6F-9A72-D83A08646C23}
+
+# nsIMsgFolder implementation
+component {8508ddeb-3eab-4877-a420-297518f62371} testJaBaseMsgFolderComponent.js
+contract @mozilla.org/mail/folder-factory;1?name=testja {8508ddeb-3eab-4877-a420-297518f62371}
+
+# nsIMsgIncomingServer implementation
+component {0eec03cd-da67-4949-ab2d-5fa4bdc68135} testJaBaseIncomingServerComponent.js
+contract @mozilla.org/messenger/server;1?type=testja {0eec03cd-da67-4949-ab2d-5fa4bdc68135}
diff --git a/comm/mailnews/jsaccount/test/unit/resources/testJaBaseIncomingServer.jsm b/comm/mailnews/jsaccount/test/unit/resources/testJaBaseIncomingServer.jsm
new file mode 100644
index 0000000000..602df26c30
--- /dev/null
+++ b/comm/mailnews/jsaccount/test/unit/resources/testJaBaseIncomingServer.jsm
@@ -0,0 +1,74 @@
+/* -*- 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/ */
+
+/**
+ This file creates a JS-based override of the JaIncomingServer implementation. It
+ demos a minimal JS class, and is also used in testing the additional methods
+ added to JaIncomingServer.cpp that are not in nsMsgDBFolder.cpp
+ */
+
+const EXPORTED_SYMBOLS = [
+ "JaBaseIncomingServerProperties",
+ "JaBaseIncomingServer",
+];
+
+// A partial JavaScript implementation of the base server methods.
+
+const JaBaseIncomingServerProperties = {
+ baseContractID: "@mozilla.org/jacppincomingserverdelegator;1",
+ baseInterfaces: [
+ Ci.nsISupports,
+ Ci.nsIMsgIncomingServer,
+ Ci.nsIInterfaceRequestor,
+ Ci.msgIOverride,
+ Ci.nsISupportsWeakReference,
+ ],
+ delegateInterfaces: ["nsIMsgIncomingServer"],
+ contractID: "@mozilla.org/messenger/server;1?type=testja",
+ classID: Components.ID("{0eec03cd-da67-4949-ab2d-5fa4bdc68135}"),
+};
+
+function JaBaseIncomingServer(aDelegator, aBaseInterfaces) {
+ dump("JaBaseIncomingServer\n");
+ // Typical boilerplate to include in all implementations.
+
+ // Object delegating method calls to the appropriate XPCOM object.
+ // Weak because it owns us.
+ this.delegator = Cu.getWeakReference(aDelegator);
+
+ // Base implementation of methods with no overrides.
+ this.cppBase = aDelegator.cppBase;
+
+ // cppBase class sees all interfaces
+ aBaseInterfaces.forEach(iface => this.cppBase instanceof iface);
+}
+
+JaBaseIncomingServer.prototype = {
+ // Typical boilerplate to include in all implementations.
+
+ // Flag this item as CPP needs to delegate to JS.
+ _JsPrototypeToDelegate: true,
+
+ // QI to the (partially implemented only) interfaces.
+ QueryInterface: ChromeUtils.generateQI(
+ JaBaseIncomingServerProperties.delegateInterfaces
+ ),
+
+ // Used to access an instance as JS, bypassing XPCOM.
+ get wrappedJSObject() {
+ return this;
+ },
+
+ // Dynamically-generated list of delegate methods.
+ delegateList: null,
+
+ // nsIMsgIncomingServer overrides.
+ get localStoreType() {
+ return "testja";
+ },
+ get localDatabaseType() {
+ return "mailbox";
+ },
+};
diff --git a/comm/mailnews/jsaccount/test/unit/resources/testJaBaseIncomingServerComponent.js b/comm/mailnews/jsaccount/test/unit/resources/testJaBaseIncomingServerComponent.js
new file mode 100644
index 0000000000..dc2e6682bb
--- /dev/null
+++ b/comm/mailnews/jsaccount/test/unit/resources/testJaBaseIncomingServerComponent.js
@@ -0,0 +1,20 @@
+/* -*- 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/ */
+
+// This file is the component definition for a demo base implementation of a
+// javascript IncomingServer.
+
+const { JSAccountUtils } = ChromeUtils.import(
+ "resource:///modules/jsaccount/JSAccountUtils.jsm"
+);
+var { JaBaseIncomingServerProperties, JaBaseIncomingServer } =
+ ChromeUtils.import(
+ "resource://testing-common/mailnews/testJaBaseIncomingServer.jsm"
+ );
+
+var xpcomFactory = JSAccountUtils.jaFactory(
+ JaBaseIncomingServerProperties,
+ JaBaseIncomingServer
+);
diff --git a/comm/mailnews/jsaccount/test/unit/resources/testJaBaseMsgFolder.jsm b/comm/mailnews/jsaccount/test/unit/resources/testJaBaseMsgFolder.jsm
new file mode 100644
index 0000000000..7f56bbdaef
--- /dev/null
+++ b/comm/mailnews/jsaccount/test/unit/resources/testJaBaseMsgFolder.jsm
@@ -0,0 +1,70 @@
+/* -*- 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/ */
+
+/**
+ This file creates a JS-based override of the JaMsgFolder implementation. It
+ demos a minimal JS class, and is also used in testing the additional methods
+ added to JaMsgFolder.cpp that are not in nsMsgDBFolder.cpp
+ */
+
+const EXPORTED_SYMBOLS = ["JaBaseMsgFolderProperties", "JaBaseMsgFolder"];
+
+// A partial JavaScript implementation of the base server methods.
+
+const JaBaseMsgFolderProperties = {
+ baseContractID: "@mozilla.org/jacppmsgfolderdelegator;1",
+ baseInterfaces: [
+ Ci.nsISupports,
+ Ci.nsIMsgFolder,
+ Ci.nsIDBChangeListener,
+ Ci.nsIUrlListener,
+ Ci.nsIJunkMailClassificationListener,
+ Ci.nsIMsgTraitClassificationListener,
+ Ci.nsIInterfaceRequestor,
+ Ci.msgIOverride,
+ ],
+ delegateInterfaces: ["nsIMsgFolder"],
+ contractID: "@mozilla.org/mail/folder-factory;1?name=testja",
+ classID: Components.ID("{8508ddeb-3eab-4877-a420-297518f62371}"),
+};
+
+function JaBaseMsgFolder(aDelegator, aBaseInterfaces) {
+ // Typical boilerplate to include in all implementations.
+
+ // Object delegating method calls to the appropriate XPCOM object.
+ // Weak because it owns us.
+ this.delegator = Cu.getWeakReference(aDelegator);
+
+ // Base implementation of methods with no overrides.
+ this.cppBase = aDelegator.cppBase;
+
+ // cppBase class sees all interfaces
+ aBaseInterfaces.forEach(iface => this.cppBase instanceof iface);
+}
+
+JaBaseMsgFolder.prototype = {
+ // Typical boilerplate to include in all implementations.
+
+ // Flag this item as CPP needs to delegate to JS.
+ _JsPrototypeToDelegate: true,
+
+ // QI to the (partially implemented only) interfaces.
+ QueryInterface: ChromeUtils.generateQI(
+ JaBaseMsgFolderProperties.delegateInterfaces
+ ),
+
+ // Used to access an instance as JS, bypassing XPCOM.
+ get wrappedJSObject() {
+ return this;
+ },
+
+ // Dynamically-generated list of delegate methods.
+ delegateList: null,
+
+ // nsIMsgFolder overrides.
+ get incomingServerType() {
+ return "testja";
+ },
+};
diff --git a/comm/mailnews/jsaccount/test/unit/resources/testJaBaseMsgFolderComponent.js b/comm/mailnews/jsaccount/test/unit/resources/testJaBaseMsgFolderComponent.js
new file mode 100644
index 0000000000..8f71f71b6c
--- /dev/null
+++ b/comm/mailnews/jsaccount/test/unit/resources/testJaBaseMsgFolderComponent.js
@@ -0,0 +1,19 @@
+/* -*- 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/ */
+
+// This file is the component definition for a demo base implementation of a
+// javascript msgFolder.
+
+const { JSAccountUtils } = ChromeUtils.import(
+ "resource:///modules/jsaccount/JSAccountUtils.jsm"
+);
+var { JaBaseMsgFolderProperties, JaBaseMsgFolder } = ChromeUtils.import(
+ "resource://testing-common/mailnews/testJaBaseMsgFolder.jsm"
+);
+
+var xpcomFactory = JSAccountUtils.jaFactory(
+ JaBaseMsgFolderProperties,
+ JaBaseMsgFolder
+);
diff --git a/comm/mailnews/jsaccount/test/unit/resources/testJaFooUrlComponent.js b/comm/mailnews/jsaccount/test/unit/resources/testJaFooUrlComponent.js
new file mode 100644
index 0000000000..9ed4d4c15b
--- /dev/null
+++ b/comm/mailnews/jsaccount/test/unit/resources/testJaFooUrlComponent.js
@@ -0,0 +1,88 @@
+/* Any copyright is dedicated to the Public Domain.
+ http://creativecommons.org/publicdomain/zero/1.0/ */
+
+/**
+ One of the goals of JsAccount is to be able to incrementally extend a base
+ implementation, possibly adding a new interface. This code demonstrates
+ a mailnews URL extended for a hypthetical account type "foo".
+*/
+
+const { JSAccountUtils } = ChromeUtils.import(
+ "resource:///modules/jsaccount/JSAccountUtils.jsm"
+);
+const { JaBaseUrl, JaBaseUrlProperties } = ChromeUtils.import(
+ "resource:///modules/jsaccount/JaBaseUrl.jsm"
+);
+
+const ATTACHMENT_QUERY = "part=1.";
+
+var FooUrlProperties = {
+ // Extend the base properties.
+ __proto__: JaBaseUrlProperties,
+
+ contractID: "@mozilla.org/jsaccount/testjafoourl;1",
+ classID: Components.ID("{73F98539-A59F-4F6F-9A72-D83A08646C23}"),
+
+ // Add an additional interface only needed by this custom class.
+ extraInterfaces: [Ci.msgIFooUrl],
+};
+
+// Constructor
+var xpcomFactory = JSAccountUtils.jaFactory(FooUrlProperties, FooUrl);
+
+// Main class.
+function FooUrl(aDelegator, aBaseInterfaces) {
+ // Superclass constructor
+ JaBaseUrl.call(this, aDelegator, aBaseInterfaces);
+
+ // I'm not sure why I have to call this again, as it is called in the
+ // base constructor, but without it this method will not find the
+ // interfaces beyond nsISupports.
+ aBaseInterfaces.forEach(iface => this.cppBase instanceof iface);
+
+ // instance variables
+ this._urlType = -1; // unknown;
+ this._itemId = null;
+ this._hidden = "IAmHidden";
+}
+
+// Extend the base class methods.
+FooUrl.prototype = {
+ // Typical boilerplate to include in all implementations.
+
+ // Extended the JS URL object.
+ __proto__: JaBaseUrl.prototype,
+
+ // Delegate these methods to CPP.
+ _JsPrototypeToDelegate: true,
+
+ // InterfaceRequestor override, needed if extraInterfaces.
+
+ getInterface(iid) {
+ for (let iface of FooUrlProperties.extraInterfaces) {
+ if (iid.equals(iface)) {
+ return this;
+ }
+ }
+ return this.delegator.QueryInterface(iid);
+ },
+
+ // msgIFooUrl implementation
+
+ // Foo id for item.
+ // attribute AString itemId;
+ get itemId() {
+ return this._itemId;
+ },
+ set itemId(aVal) {
+ this._itemId = aVal;
+ },
+
+ // Does this url refer to an attachment?
+ // readonly attribute boolean isAttachment;
+ get isAttachment() {
+ // We look to see if the URL has an attachment query
+ let query = this.QueryInterface(Ci.nsIURL).query;
+ return query && query.includes(ATTACHMENT_QUERY);
+ },
+};
diff --git a/comm/mailnews/jsaccount/test/unit/test_componentsExist.js b/comm/mailnews/jsaccount/test/unit/test_componentsExist.js
new file mode 100644
index 0000000000..726281bccc
--- /dev/null
+++ b/comm/mailnews/jsaccount/test/unit/test_componentsExist.js
@@ -0,0 +1,90 @@
+/* -*- 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 that the components made available by JaAccount can be created with
+// each supported interface.
+
+let tests = [
+ // JaUrl
+ ["@mozilla.org/jacppurldelegator;1", "nsISupports"],
+ ["@mozilla.org/jacppurldelegator;1", "nsIMsgMailNewsUrl"],
+ ["@mozilla.org/jacppurldelegator;1", "nsIMsgMessageUrl"],
+ ["@mozilla.org/jacppurldelegator;1", "nsIURL"],
+ ["@mozilla.org/jacppurldelegator;1", "nsIURI"],
+ ["@mozilla.org/jacppurldelegator;1", "msgIOverride"],
+ ["@mozilla.org/jacppurldelegator;1", "nsIInterfaceRequestor"],
+ // (probably a url bug) ["@mozilla.org/jacppurldelegator;1", "nsISupportsWeakReference"],
+
+ // FooJaUrl
+ ["@mozilla.org/jsaccount/testjafoourl;1", "nsISupports"],
+ ["@mozilla.org/jsaccount/testjafoourl;1", "nsIMsgMailNewsUrl"],
+ ["@mozilla.org/jsaccount/testjafoourl;1", "nsIMsgMessageUrl"],
+ ["@mozilla.org/jsaccount/testjafoourl;1", "nsIURL"],
+ ["@mozilla.org/jsaccount/testjafoourl;1", "nsIURI"],
+ ["@mozilla.org/jsaccount/testjafoourl;1", "msgIOverride"],
+ ["@mozilla.org/jsaccount/testjafoourl;1", "nsIInterfaceRequestor"],
+ // JaAbDirectory
+ ["@mozilla.org/jacppabdirectorydelegator;1", "nsISupports"],
+ ["@mozilla.org/jacppabdirectorydelegator;1", "nsIAbDirectory"],
+ ["@mozilla.org/jacppabdirectorydelegator;1", "msgIOverride"],
+ ["@mozilla.org/jacppabdirectorydelegator;1", "nsIInterfaceRequestor"],
+ ["@mozilla.org/jacppabdirectorydelegator;1", "nsISupportsWeakReference"],
+ // JaCompose
+ ["@mozilla.org/jacppcomposedelegator;1", "nsISupports"],
+ ["@mozilla.org/jacppcomposedelegator;1", "nsIMsgCompose"],
+ ["@mozilla.org/jacppcomposedelegator;1", "nsIMsgSendListener"],
+ ["@mozilla.org/jacppcomposedelegator;1", "msgIOverride"],
+ ["@mozilla.org/jacppcomposedelegator;1", "nsIInterfaceRequestor"],
+ ["@mozilla.org/jacppcomposedelegator;1", "nsISupportsWeakReference"],
+ // JaIncomingServer
+ ["@mozilla.org/jacppincomingserverdelegator;1", "nsISupports"],
+ ["@mozilla.org/jacppincomingserverdelegator;1", "nsIMsgIncomingServer"],
+ ["@mozilla.org/jacppincomingserverdelegator;1", "msgIOverride"],
+ ["@mozilla.org/jacppincomingserverdelegator;1", "nsIInterfaceRequestor"],
+ ["@mozilla.org/jacppincomingserverdelegator;1", "nsISupportsWeakReference"],
+ // JaMsgFolder
+ ["@mozilla.org/jacppmsgfolderdelegator;1", "nsISupports"],
+ ["@mozilla.org/jacppmsgfolderdelegator;1", "nsIMsgFolder"],
+ ["@mozilla.org/jacppmsgfolderdelegator;1", "nsIDBChangeListener"],
+ ["@mozilla.org/jacppmsgfolderdelegator;1", "nsIUrlListener"],
+ [
+ "@mozilla.org/jacppmsgfolderdelegator;1",
+ "nsIJunkMailClassificationListener",
+ ],
+ [
+ "@mozilla.org/jacppmsgfolderdelegator;1",
+ "nsIMsgTraitClassificationListener",
+ ],
+ ["@mozilla.org/jacppmsgfolderdelegator;1", "msgIOverride"],
+ ["@mozilla.org/jacppmsgfolderdelegator;1", "nsISupportsWeakReference"],
+ // TestJaIncomingServer
+ ["@mozilla.org/messenger/server;1?type=testja", "nsISupports"],
+ ["@mozilla.org/messenger/server;1?type=testja", "nsIMsgIncomingServer"],
+ ["@mozilla.org/messenger/server;1?type=testja", "msgIOverride"],
+ ["@mozilla.org/messenger/server;1?type=testja", "nsISupportsWeakReference"],
+ // TestJaMsgProtocolInfo
+ ["@mozilla.org/messenger/protocol/info;1?type=testja", "nsISupports"],
+ ["@mozilla.org/messenger/protocol/info;1?type=testja", "nsIMsgProtocolInfo"],
+];
+
+function run_test() {
+ for (let [contractID, iface] of tests) {
+ dump(
+ "trying to create component " +
+ contractID +
+ " with interface " +
+ iface +
+ "\n"
+ );
+ try {
+ dump(Cc[contractID] + " " + Ci[iface] + "\n");
+ } catch (e) {
+ dump(e + "\n");
+ }
+
+ let comp = Cc[contractID].createInstance(Ci[iface]);
+ Assert.ok(comp instanceof Ci[iface]);
+ }
+}
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();
+ }
+}
diff --git a/comm/mailnews/jsaccount/test/unit/test_jaMsgFolder.js b/comm/mailnews/jsaccount/test/unit/test_jaMsgFolder.js
new file mode 100644
index 0000000000..30a8557b01
--- /dev/null
+++ b/comm/mailnews/jsaccount/test/unit/test_jaMsgFolder.js
@@ -0,0 +1,56 @@
+/* -*- 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/ */
+
+// This tests the additional methods added to JaMsgFolder.cpp that are not
+// in nsMsgDBFolder.cpp Although this code have been done creating the
+// delegator class directly, instead we use a JS component as a demo of
+// JS override classes.
+
+var { JaBaseMsgFolderProperties } = ChromeUtils.import(
+ "resource://testing-common/mailnews/testJaBaseMsgFolder.jsm"
+);
+var { MailUtils } = ChromeUtils.import("resource:///modules/MailUtils.jsm");
+var { MailServices } = ChromeUtils.import(
+ "resource:///modules/MailServices.jsm"
+);
+
+function run_test() {
+ let server = MailServices.accounts.createIncomingServer(
+ "foouser",
+ "foohost",
+ "testja"
+ );
+ Assert.ok(server instanceof Ci.msgIOverride);
+
+ // If you create a folder object directly, it will complain about not being registered.
+ // Use folder-lookup-service instead.
+ let testJaMsgFolder = MailUtils.getOrCreateFolder(
+ "testja://foouser@foohost/somefolder"
+ );
+ // let testJaMsgFolder = Cc[JaBaseMsgFolderProperties.contractID]
+ // .createInstance(Ci.msgIOverride);
+ Assert.ok(testJaMsgFolder instanceof Ci.nsIMsgFolder);
+
+ JaBaseMsgFolderProperties.baseInterfaces.forEach(iface => {
+ dump("testing interface " + iface + "(" + Ci[iface] + ")\n");
+ testJaMsgFolder.QueryInterface(Ci[iface]);
+ });
+
+ let db = testJaMsgFolder.msgDatabase;
+ Assert.ok(db instanceof Ci.nsIMsgDatabase);
+
+ // Make sure the DB actually works.
+ let dbFolder = db.folder;
+ Assert.ok(dbFolder instanceof Ci.nsIMsgFolder);
+ Assert.equal(dbFolder.URI, "testja://foouser@foohost/somefolder");
+ let fi = db.dBFolderInfo;
+ Assert.ok(fi instanceof Ci.nsIDBFolderInfo);
+ fi.setCharProperty("testProperty", "foobar");
+ Assert.equal(fi.getCharProperty("testProperty"), "foobar");
+ db.forceClosed();
+ db = null;
+
+ // Confirm that we can access XPCOM properties.
+}
diff --git a/comm/mailnews/jsaccount/test/unit/xpcshell.ini b/comm/mailnews/jsaccount/test/unit/xpcshell.ini
new file mode 100644
index 0000000000..69676b5d6f
--- /dev/null
+++ b/comm/mailnews/jsaccount/test/unit/xpcshell.ini
@@ -0,0 +1,10 @@
+# Any copyright is dedicated to the Public Domain.
+# http://creativecommons.org/publicdomain/zero/1.0/
+
+[DEFAULT]
+head = head_jsaccount.js
+tail =
+support-files = resources/*
+[test_componentsExist.js]
+[test_fooUrl.js]
+[test_jaMsgFolder.js]