summaryrefslogtreecommitdiffstats
path: root/comm/mailnews/jsaccount/test/unit/resources
diff options
context:
space:
mode:
Diffstat (limited to 'comm/mailnews/jsaccount/test/unit/resources')
-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
8 files changed, 424 insertions, 0 deletions
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);
+ },
+};