summaryrefslogtreecommitdiffstats
path: root/comm/mailnews/news/test/unit/test_newsAutocomplete.js
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/news/test/unit/test_newsAutocomplete.js
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/news/test/unit/test_newsAutocomplete.js')
-rw-r--r--comm/mailnews/news/test/unit/test_newsAutocomplete.js107
1 files changed, 107 insertions, 0 deletions
diff --git a/comm/mailnews/news/test/unit/test_newsAutocomplete.js b/comm/mailnews/news/test/unit/test_newsAutocomplete.js
new file mode 100644
index 0000000000..29fecb3d9d
--- /dev/null
+++ b/comm/mailnews/news/test/unit/test_newsAutocomplete.js
@@ -0,0 +1,107 @@
+/* -*- Mode: JavaScript; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
+/* ***** BEGIN LICENSE BLOCK *****
+ *
+ * Any copyright is dedicated to the Public Domain.
+ * http://creativecommons.org/licenses/publicdomain/
+ *
+ * ***** END LICENSE BLOCK ***** */
+
+var { MailServices } = ChromeUtils.import(
+ "resource:///modules/MailServices.jsm"
+);
+
+function acObserver() {}
+
+acObserver.prototype = {
+ _search: null,
+ _result: null,
+
+ onSearchResult(aSearch, aResult) {
+ this._search = aSearch;
+ this._result = aResult;
+ },
+};
+
+function run_test() {
+ setupLocalServer(119);
+
+ // create identity
+ let identity = MailServices.accounts.createIdentity();
+ _account.addIdentity(identity);
+
+ let acs = Cc["@mozilla.org/autocomplete/search;1?name=news"].getService(
+ Ci.nsIAutoCompleteSearch
+ );
+ let obs;
+
+ let paramsN = JSON.stringify({
+ idKey: identity.key,
+ accountKey: _account.key,
+ type: "addr_newsgroups",
+ });
+ let paramsF = JSON.stringify({
+ idKey: identity.key,
+ accountKey: _account.key,
+ type: "addr_followup",
+ });
+ let paramsMail = JSON.stringify({
+ idKey: identity.key,
+ accountKey: _account.key,
+ type: "addr_to",
+ });
+
+ // misc.test is not subscribed
+ obs = new acObserver();
+ acs.startSearch("misc", paramsN, null, obs);
+ Assert.ok(obs._result == null || obs._result.matchCount == 0);
+
+ obs = new acObserver();
+ acs.startSearch("misc", paramsF, null, obs);
+ Assert.ok(obs._result == null || obs._result.matchCount == 0);
+
+ obs = new acObserver();
+ acs.startSearch("misc", paramsMail, null, obs);
+ Assert.ok(obs._result == null || obs._result.matchCount == 0);
+
+ // test.filter is subscribed
+ obs = new acObserver();
+ acs.startSearch("filter", paramsN, null, obs);
+ Assert.equal(obs._result.matchCount, 1);
+
+ obs = new acObserver();
+ acs.startSearch("filter", paramsF, null, obs);
+ Assert.equal(obs._result.matchCount, 1);
+
+ // ... but no auto-complete should occur for addr_to
+ obs = new acObserver();
+ acs.startSearch("filter", paramsMail, null, obs);
+ Assert.ok(obs._result == null || obs._result.matchCount == 0);
+
+ // test.subscribe.empty and test.subscribe.simple are subscribed
+ obs = new acObserver();
+ acs.startSearch("subscribe", paramsN, null, obs);
+ Assert.equal(obs._result.matchCount, 2);
+
+ obs = new acObserver();
+ acs.startSearch("subscribe", paramsF, null, obs);
+ Assert.equal(obs._result.matchCount, 2);
+
+ // ... but no auto-complete should occur for addr_to
+ obs = new acObserver();
+ acs.startSearch("subscribe", paramsMail, null, obs);
+ Assert.ok(obs._result == null || obs._result.matchCount == 0);
+
+ // test.subscribe.empty is subscribed, test.empty is not
+ obs = new acObserver();
+ acs.startSearch("empty", paramsN, null, obs);
+ Assert.equal(obs._result.matchCount, 1);
+
+ obs = new acObserver();
+ acs.startSearch("empty", paramsF, null, obs);
+ Assert.equal(obs._result.matchCount, 1);
+
+ let thread = gThreadManager.currentThread;
+ while (thread.hasPendingEvents()) {
+ thread.processNextEvent(true);
+ }
+}