summaryrefslogtreecommitdiffstats
path: root/comm/mailnews/search/test/unit/test_searchChaining.js
diff options
context:
space:
mode:
Diffstat (limited to 'comm/mailnews/search/test/unit/test_searchChaining.js')
-rw-r--r--comm/mailnews/search/test/unit/test_searchChaining.js90
1 files changed, 90 insertions, 0 deletions
diff --git a/comm/mailnews/search/test/unit/test_searchChaining.js b/comm/mailnews/search/test/unit/test_searchChaining.js
new file mode 100644
index 0000000000..4bdbebab57
--- /dev/null
+++ b/comm/mailnews/search/test/unit/test_searchChaining.js
@@ -0,0 +1,90 @@
+/* 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/. */
+
+// Test of chaining of search scopes in a search session. In particular,
+// Bug 541969 made us not search an imap folder if the search scope before it
+// there was an empty local folder.
+
+// main test
+
+/* import-globals-from ../../../test/resources/MessageGenerator.jsm */
+load("../../../resources/MessageGenerator.jsm");
+
+var { IMAPPump, setupIMAPPump, teardownIMAPPump } = ChromeUtils.import(
+ "resource://testing-common/mailnews/IMAPpump.jsm"
+);
+var { ImapMessage } = ChromeUtils.import(
+ "resource://testing-common/mailnews/Imapd.jsm"
+);
+const { PromiseTestUtils } = ChromeUtils.import(
+ "resource://testing-common/mailnews/PromiseTestUtils.jsm"
+);
+
+async function setupFolder() {
+ // add a single message to the imap inbox.
+ let messages = [];
+ let messageGenerator = new MessageGenerator();
+ messages = messages.concat(messageGenerator.makeMessage());
+ let synthMessage = messages[0];
+
+ let msgURI = Services.io.newURI(
+ "data:text/plain;base64," + btoa(synthMessage.toMessageString())
+ );
+ let message = new ImapMessage(msgURI.spec, IMAPPump.mailbox.uidnext++, []);
+ IMAPPump.mailbox.addMessage(message);
+
+ // update folder to download header.
+ let listener = new PromiseTestUtils.PromiseUrlListener();
+ IMAPPump.inbox.updateFolderWithListener(null, listener);
+ await listener.promise;
+}
+
+async function searchTest() {
+ // Get the IMAP inbox...
+ var emptyLocal1 =
+ localAccountUtils.rootFolder.createLocalSubfolder("empty 1");
+
+ let searchSession = Cc[
+ "@mozilla.org/messenger/searchSession;1"
+ ].createInstance(Ci.nsIMsgSearchSession);
+
+ let searchTerm = searchSession.createTerm();
+ searchTerm.matchAll = true;
+ searchSession.appendTerm(searchTerm);
+ searchSession.addScopeTerm(Ci.nsMsgSearchScope.offlineMail, emptyLocal1);
+ searchSession.addScopeTerm(Ci.nsMsgSearchScope.onlineMail, IMAPPump.inbox);
+ let listener = new PromiseTestUtils.PromiseSearchNotify(
+ searchSession,
+ searchListener
+ );
+ searchSession.search(null);
+ await listener.promise;
+
+ // After the search completes, there still seem to be active URLs, so we
+ // have to wait before we are done and clear.
+ await PromiseTestUtils.promiseDelay(1000);
+}
+
+// nsIMsgSearchNotify implementation
+var searchListener = {
+ numTotalMessages: 0,
+ QueryInterface: ChromeUtils.generateQI(["nsIMsgSearchNotify"]),
+ onNewSearch() {
+ this.numTotalMessages = 0;
+ },
+ onSearchHit(dbHdr, folder) {
+ this.numTotalMessages++;
+ },
+ onSearchDone(status) {
+ Assert.equal(this.numTotalMessages, 1);
+ return true;
+ },
+};
+
+var tests = [setupIMAPPump, setupFolder, searchTest, teardownIMAPPump];
+
+function run_test() {
+ tests.forEach(x => add_task(x));
+ run_next_test();
+}