summaryrefslogtreecommitdiffstats
path: root/comm/mail/test/browser/message-reader/browser_bug594646.js
blob: 2d63629b6ca69e545df695bf33391ff2177cd813 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
/**
 * 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/.
 */

/**
 * Tests that opening an .eml file the body of the message is correct,
 * that it hasn't been UTF-8 mojibake'd.
 */

"use strict";

var { open_message_from_file } = ChromeUtils.import(
  "resource://testing-common/mozmill/FolderDisplayHelpers.jsm"
);
var { close_window } = ChromeUtils.import(
  "resource://testing-common/mozmill/WindowHelpers.jsm"
);

var gReferenceTextContent;

add_setup(async function () {
  gReferenceTextContent = await extract_eml_body_textcontent(
    "./bug594646_reference.eml"
  );
});

async function extract_eml_body_textcontent(eml) {
  let file = new FileUtils.File(getTestFilePath(`data/${eml}`));
  let msgc = await open_message_from_file(file);

  // Be sure to view message body as Original HTML
  msgc.window.MsgBodyAllowHTML();
  let textContent = msgc.window.content.document.documentElement.textContent;

  close_window(msgc);
  return textContent;
}

/**
 * Checks that the text content is equal for the .eml files.
 */
async function check_eml_textcontent(eml) {
  let textContent = await extract_eml_body_textcontent(eml);
  Assert.stringContains(textContent, "árvíztűrő tükörfúrógép");
  Assert.stringContains(textContent, "ÁRVÍZTŰRŐ TÜKÖRFÚRÓGÉP");
}

/**
 * This test exercises the bug for reversed http-equiv, content order:
 *  <head>
 *    <meta content="text/html; charset=ISO-8859-2"; http-equiv="content-type">
 *  </head>
 */
add_task(
  async function test_original_html_characters_head_meta_content_charset_httpEq() {
    await check_eml_textcontent("./bug594646_reversed_order_8bit.eml");
    await check_eml_textcontent("./bug594646_reversed_order_qp.eml");
    await check_eml_textcontent("./bug594646_reversed_order_b64.eml");
  }
);

/**
 * This test exercises the bug for newline delimited charset:
 *  <head>
 *    <meta http-equiv="content-type" content="text/html;
 *          charset=ISO-8859-2">
 *  </head>
 */
add_task(
  async function test_original_html_characters_head_meta_httpEq_content_newline_charset() {
    await check_eml_textcontent("./bug594646_newline_charset_8bit.eml");
    await check_eml_textcontent("./bug594646_newline_charset_qp.eml");
    await check_eml_textcontent("./bug594646_newline_charset_b64.eml");
  }
);

/**
 * This test exercises the bug for newline delimited and reverse ordered http-equiv:
 *  <head>
 *    <meta content="text/html; charset=ISO-8859-2"
 *          http-equiv="content-type">
 *  </head>
 */
add_task(
  async function test_original_html_characters_head_meta_content_charset_newline_httpEq() {
    await check_eml_textcontent("./bug594646_newline_httpequiv_8bit.eml");
    await check_eml_textcontent("./bug594646_newline_httpequiv_qp.eml");
    await check_eml_textcontent("./bug594646_newline_httpequiv_b64.eml");
  }
);