diff options
Diffstat (limited to '')
-rw-r--r-- | comm/mailnews/compose/test/unit/test_nsIMsgCompFields.js | 62 |
1 files changed, 62 insertions, 0 deletions
diff --git a/comm/mailnews/compose/test/unit/test_nsIMsgCompFields.js b/comm/mailnews/compose/test/unit/test_nsIMsgCompFields.js new file mode 100644 index 0000000000..69c1b753b6 --- /dev/null +++ b/comm/mailnews/compose/test/unit/test_nsIMsgCompFields.js @@ -0,0 +1,62 @@ +/* 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 that nsIMsgCompFields works properly + +var nsMsgCompFields = Components.Constructor( + "@mozilla.org/messengercompose/composefields;1", + Ci.nsIMsgCompFields +); + +function check_headers(enumerator, container) { + let checkValues = new Set(container.map(header => header.toLowerCase())); + for (let value of enumerator) { + value = value.toLowerCase(); + Assert.ok(checkValues.has(value)); + checkValues.delete(value); + } + Assert.equal(checkValues.size, 0); +} + +function run_test() { + let fields = new nsMsgCompFields(); + Assert.ok(fields instanceof Ci.nsIMsgCompFields); + Assert.ok(fields instanceof Ci.msgIStructuredHeaders); + Assert.ok(fields instanceof Ci.msgIWritableStructuredHeaders); + check_headers(fields.headerNames, []); + Assert.ok(!fields.hasRecipients); + + // Try some basic headers + fields.setHeader("From", [{ name: "", email: "a@test.invalid" }]); + let from = fields.getHeader("from"); + Assert.equal(from.length, 1); + Assert.equal(from[0].email, "a@test.invalid"); + check_headers(fields.headerNames, ["From"]); + Assert.ok(!fields.hasRecipients); + + // Add a To header + fields.setHeader("To", [{ name: "", email: "b@test.invalid" }]); + check_headers(fields.headerNames, ["From", "To"]); + Assert.ok(fields.hasRecipients); + + // Delete a header... + fields.deleteHeader("from"); + Assert.equal(fields.getHeader("From"), undefined); + check_headers(fields.headerNames, ["To"]); + + // Subject should work and not convert to RFC 2047. + fields.subject = "\u79c1\u306f\u4ef6\u540d\u5348\u524d"; + Assert.equal(fields.subject, "\u79c1\u306f\u4ef6\u540d\u5348\u524d"); + Assert.equal( + fields.getHeader("Subject"), + "\u79c1\u306f\u4ef6\u540d\u5348\u524d" + ); + + // Check header synchronization. + fields.from = "a@test.invalid"; + Assert.equal(fields.from, "a@test.invalid"); + Assert.equal(fields.getHeader("From")[0].email, "a@test.invalid"); + fields.from = null; + Assert.equal(fields.getHeader("From"), undefined); +} |