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/mailnews/compose/test/unit/test_detectAttachmentCharset.js | |
parent | Initial commit. (diff) | |
download | thunderbird-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/compose/test/unit/test_detectAttachmentCharset.js')
-rw-r--r-- | comm/mailnews/compose/test/unit/test_detectAttachmentCharset.js | 79 |
1 files changed, 79 insertions, 0 deletions
diff --git a/comm/mailnews/compose/test/unit/test_detectAttachmentCharset.js b/comm/mailnews/compose/test/unit/test_detectAttachmentCharset.js new file mode 100644 index 0000000000..27e879d018 --- /dev/null +++ b/comm/mailnews/compose/test/unit/test_detectAttachmentCharset.js @@ -0,0 +1,79 @@ +/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ +/* + * Test suite for auto-detecting attachment file charset. + */ + +function checkAttachmentCharset(expectedCharset) { + let msgData = mailTestUtils.loadMessageToString( + gDraftFolder, + mailTestUtils.firstMsgHdr(gDraftFolder) + ); + let attachmentData = getAttachmentFromContent(msgData); + + Assert.equal(expectedCharset, getContentCharset(attachmentData)); +} + +function getContentCharset(aContent) { + let found = aContent.match(/^Content-Type: text\/plain; charset=(.*?);/); + if (found) { + Assert.equal(found.length, 2); + return found[1]; + } + return null; +} + +async function testUTF8() { + await createMessage(do_get_file("data/test-UTF-8.txt")); + checkAttachmentCharset("UTF-8"); +} + +async function testUTF16BE() { + await createMessage(do_get_file("data/test-UTF-16BE.txt")); + checkAttachmentCharset("UTF-16BE"); +} + +async function testUTF16LE() { + await createMessage(do_get_file("data/test-UTF-16LE.txt")); + checkAttachmentCharset("UTF-16LE"); +} + +async function testShiftJIS() { + await createMessage(do_get_file("data/test-SHIFT_JIS.txt")); + checkAttachmentCharset("Shift_JIS"); +} + +async function testISO2022JP() { + await createMessage(do_get_file("data/test-ISO-2022-JP.txt")); + checkAttachmentCharset("ISO-2022-JP"); +} + +async function testKOI8R() { + // NOTE: KOI8-R is detected as KOI8-U which is a superset covering both + // Russian and Ukrainian (a few box-drawing characters are repurposed). + await createMessage(do_get_file("data/test-KOI8-R.txt")); + checkAttachmentCharset("KOI8-U"); +} + +async function testWindows1252() { + await createMessage(do_get_file("data/test-windows-1252.txt")); + checkAttachmentCharset("windows-1252"); +} + +var tests = [ + testUTF8, + testUTF16BE, + testUTF16LE, + testShiftJIS, + testISO2022JP, + testKOI8R, + testWindows1252, +]; + +function run_test() { + // Ensure we have at least one mail account + localAccountUtils.loadLocalMailAccount(); + Services.prefs.setIntPref("mail.strictly_mime.parm_folding", 0); + + tests.forEach(x => add_task(x)); + run_next_test(); +} |