From 6bf0a5cb5034a7e684dcc3500e841785237ce2dd Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Sun, 7 Apr 2024 19:32:43 +0200 Subject: Adding upstream version 1:115.7.0. Signed-off-by: Daniel Baumann --- .../resources/TestJaMsgProtocolInfoComponent.jsm | 75 ++++++++++++++++++ .../jsaccount/test/unit/resources/readme.html | 62 +++++++++++++++ .../test/unit/resources/testComponents.manifest | 16 ++++ .../unit/resources/testJaBaseIncomingServer.jsm | 74 ++++++++++++++++++ .../resources/testJaBaseIncomingServerComponent.js | 20 +++++ .../test/unit/resources/testJaBaseMsgFolder.jsm | 70 +++++++++++++++++ .../unit/resources/testJaBaseMsgFolderComponent.js | 19 +++++ .../test/unit/resources/testJaFooUrlComponent.js | 88 ++++++++++++++++++++++ 8 files changed, 424 insertions(+) create mode 100644 comm/mailnews/jsaccount/test/unit/resources/TestJaMsgProtocolInfoComponent.jsm create mode 100644 comm/mailnews/jsaccount/test/unit/resources/readme.html create mode 100644 comm/mailnews/jsaccount/test/unit/resources/testComponents.manifest create mode 100644 comm/mailnews/jsaccount/test/unit/resources/testJaBaseIncomingServer.jsm create mode 100644 comm/mailnews/jsaccount/test/unit/resources/testJaBaseIncomingServerComponent.js create mode 100644 comm/mailnews/jsaccount/test/unit/resources/testJaBaseMsgFolder.jsm create mode 100644 comm/mailnews/jsaccount/test/unit/resources/testJaBaseMsgFolderComponent.js create mode 100644 comm/mailnews/jsaccount/test/unit/resources/testJaFooUrlComponent.js (limited to 'comm/mailnews/jsaccount/test/unit/resources') 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 @@ + + + + + JsAccount Usage and Architecture + + +

Overview of Testing Objects

+ This directory contains sample JS components to test the basic JsAccount + concepts, which can also serve as templates for new implementations.
+

Component Naming

+ 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.
+
+ Names are constructed with the following subparts:
+
+ (Ja)(AccountType)(Language)(ComponentType)(Role) +
+

Common parts of names

+ + Example: The C++ class that delegates the implementation of + nsIMsgMailNewsUrl (abbreviated as Url) to either a C++ or JS method is + called JaCppUrlDelegator. + + 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); + }, +}; -- cgit v1.2.3