diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-07 17:32:43 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-07 17:32:43 +0000 |
commit | 6bf0a5cb5034a7e684dcc3500e841785237ce2dd (patch) | |
tree | a68f146d7fa01f0134297619fbe7e33db084e0aa /comm/mail/base/test/unit/test_attachmentChecker.js | |
parent | Initial commit. (diff) | |
download | thunderbird-upstream.tar.xz thunderbird-upstream.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 '')
-rw-r--r-- | comm/mail/base/test/unit/test_attachmentChecker.js | 121 |
1 files changed, 121 insertions, 0 deletions
diff --git a/comm/mail/base/test/unit/test_attachmentChecker.js b/comm/mail/base/test/unit/test_attachmentChecker.js new file mode 100644 index 0000000000..b727819231 --- /dev/null +++ b/comm/mail/base/test/unit/test_attachmentChecker.js @@ -0,0 +1,121 @@ +/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ +/* 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 suite for the attachmentChecker class + * + * Currently tested: + * - getAttachmentKeywords function. + */ + +// Globals + +var { AttachmentChecker } = ChromeUtils.import( + "resource:///modules/AttachmentChecker.jsm" +); + +/* + * UTILITIES + */ + +function assert(aBeTrue, aWhy) { + if (!aBeTrue) { + do_throw(aWhy); + } +} + +function assert_equal(aA, aB, aWhy) { + assert( + aA == aB, + aWhy + + " (" + + unescape(encodeURIComponent(aA)) + + " != " + + unescape(encodeURIComponent(aB)) + + ")." + ); +} + +/* + * TESTS + */ + +function test_getAttachmentKeywords(desc, mailData, keywords, expected) { + let result = AttachmentChecker.getAttachmentKeywords(mailData, keywords); + assert_equal(result, expected, desc + " not equal!"); +} + +var tests = [ + // Desc, mail body Data, keywords to search for, expected keywords found. + ["Simple keyword", "latte.ca", "latte", "latte"], + ["Extension", "testing document.pdf", ".pdf", "document.pdf"], + [ + "Two Extensions", + "testing document.pdf and test.pdf", + ".pdf", + "document.pdf,test.pdf", + ], + [ + "Two+one Extensions", + "testing document.pdf and test.pdf and again document.pdf", + ".pdf", + "document.pdf,test.pdf", + ], + ["Url", "testing http://document.pdf", ".pdf", ""], + ["Both", "testing http://document.pdf test.pdf", ".pdf", "test.pdf"], + ["Greek", "This is a Θεωρία test", "Θεωρία,is", "Θεωρία,is"], + ["Greek missing", "This a Θεωρίαω test", "Θεωρία", ""], + ["Greek and punctuation", "This a:Θεωρία-test", "Θεωρία", "Θεωρία"], + ["Greek and Japanese", "This a 添Θεωρία付 test", "Θεωρία", "Θεωρία"], + ["Japanese", "This is 添付! test", "Θεωρία,添付", "添付"], + ["More Japanese", "添付mailを送る", "添付,cv", "添付"], + ["Japanese and English", "添付mailを送る", "添付,mail", "添付,mail"], + ["Japanese and English Mixed", "添付mailを送る", "添付mail", "添付mail"], + ["Japanese and English Mixed missing", "添付mailing", "添付mail", ""], + ["Japanese trailers", "This is 添添付付! test", "Θεωρία,添付", "添付"], + ["Multi-lang", "cv添付Θεωρία", "Θεωρία,添付,cv", "Θεωρία,添付,cv"], + [ + "Should match", + "I've attached the http/test.pdf file", + ".pdf", + "http/test.pdf", + ], + ["Should still fail", "a https://test.pdf a", ".pdf", ""], + ["Should match Japanese", "a test.添付 a", ".添付", "test.添付"], + ["Should match Greek", "a test.Θεωρία a", ".Θεωρία", "test.Θεωρία"], + ["Should match once", "a test.pdf.doc a", ".pdf,.doc", "test.pdf.doc"], + [ + "Should not match kw in url", + "see https://example.org/attachment.cgi?id=1 test", + "attachment", + "", + ], + [ + "Should not match kw in url ending with kw", + "https://example.org/attachment", + "attachment", + "", + ], + [ + "Should match CV and attachment", + "got my CV as attachment", + "CV,attachment", + "CV,attachment", + ], +]; + +function run_test() { + do_test_pending(); + + for (var i in tests) { + if (typeof tests[i] == "function") { + tests[i](); + } else { + test_getAttachmentKeywords.apply(null, tests[i]); + } + } + + do_test_finished(); +} |