diff options
Diffstat (limited to '')
-rw-r--r-- | comm/mailnews/mime/jsmime/test/unit/test_custom_headers.js | 43 |
1 files changed, 43 insertions, 0 deletions
diff --git a/comm/mailnews/mime/jsmime/test/unit/test_custom_headers.js b/comm/mailnews/mime/jsmime/test/unit/test_custom_headers.js new file mode 100644 index 0000000000..85c86628de --- /dev/null +++ b/comm/mailnews/mime/jsmime/test/unit/test_custom_headers.js @@ -0,0 +1,43 @@ +"use strict"; +define(function (require) { + var assert = require("assert"); + var jsmime = require("jsmime"); + + suite("Custom decoder support", function () { + function customDecoder(values) { + let value = values.join(""); + return atob(value); + } + function customEncoder(value) { + this.addText(btoa(value), true); + } + test("addStructuredEncoder", function () { + assert.equal( + "X-Base64: String\r\n", + jsmime.headeremitter.emitStructuredHeader("X-Base64", "String", {}) + ); + jsmime.headeremitter.addStructuredEncoder("X-Base64", customEncoder); + assert.equal( + "X-Base64: U3RyaW5n\r\n", + jsmime.headeremitter.emitStructuredHeader("X-Base64", "String", {}) + ); + assert.equal( + "X-Base64: U3RyaW5n\r\n", + jsmime.headeremitter.emitStructuredHeader("x-bASe64", "String", {}) + ); + }); + test("addStructuredDecoder", function () { + assert.throws(function () { + jsmime.headerparser.parseStructuredHeader("X-Base64", "U3RyaW5n"); + }, /Unknown structured header/); + jsmime.headerparser.addStructuredDecoder("X-Base64", customDecoder); + assert.equal( + "String", + jsmime.headerparser.parseStructuredHeader("X-Base64", "U3RyaW5n") + ); + assert.throws(function () { + jsmime.headerparser.addStructuredDecoder("To", customDecoder); + }, /Cannot override header/); + }); + }); +}); |