summaryrefslogtreecommitdiffstats
path: root/comm/mail/test/browser/composition/browser_emlActions.js
blob: cf24be0b239dbb7183cfe9088bf39a645395c0e2 (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
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
/* 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 actions such as replying to an .eml works properly.
 */

"use strict";

var {
  close_compose_window,
  get_compose_body,
  open_compose_with_forward,
  open_compose_with_reply,
  save_compose_message,
} = ChromeUtils.import("resource://testing-common/mozmill/ComposeHelpers.jsm");
var {
  be_in_folder,
  get_special_folder,
  open_message_from_file,
  press_delete,
  select_click_row,
} = ChromeUtils.import(
  "resource://testing-common/mozmill/FolderDisplayHelpers.jsm"
);
var { close_window } = ChromeUtils.import(
  "resource://testing-common/mozmill/WindowHelpers.jsm"
);

var { MailServices } = ChromeUtils.import(
  "resource:///modules/MailServices.jsm"
);

var gDrafts;

add_setup(async function () {
  gDrafts = await get_special_folder(Ci.nsMsgFolderFlags.Drafts, true);
});

/**
 * Test that replying to an opened .eml message works, and that the reply can
 * be saved as a draft.
 */
add_task(async function test_reply_to_eml_save_as_draft() {
  // Open an .eml file.
  let file = new FileUtils.File(getTestFilePath("data/testmsg.eml"));
  let msgc = await open_message_from_file(file);

  let replyWin = open_compose_with_reply(msgc);

  // Ctrl+S saves as draft.
  await save_compose_message(replyWin.window);
  close_compose_window(replyWin);

  await TestUtils.waitForCondition(
    () => gDrafts.getTotalMessages(false) == 1,
    "message saved to drafts folder"
  );

  // Drafts folder should exist now.
  await be_in_folder(gDrafts);
  let draftMsg = select_click_row(0);
  if (!draftMsg) {
    throw new Error("No draft saved!");
  }
  press_delete(); // Delete the draft.

  close_window(msgc); // close base .eml message
});

/**
 * Test that forwarding an opened .eml message works, and that the forward can
 * be saved as a draft.
 */
add_task(async function test_forward_eml_save_as_draft() {
  // Open an .eml file.
  let file = new FileUtils.File(getTestFilePath("data/testmsg.eml"));
  let msgc = await open_message_from_file(file);

  let replyWin = open_compose_with_forward(msgc);

  await save_compose_message(replyWin.window);
  close_compose_window(replyWin);

  await TestUtils.waitForCondition(
    () => gDrafts.getTotalMessages(false) == 1,
    "message saved to drafts folder"
  );

  // Drafts folder should exist now.
  await be_in_folder(gDrafts);
  let draftMsg = select_click_row(0);
  if (!draftMsg) {
    throw new Error("No draft saved!");
  }
  press_delete(); // Delete the draft.

  close_window(msgc); // close base .eml message
});

/**
 * Test that MIME encoded subject is decoded when replying to an opened .eml.
 */
add_task(async function test_reply_eml_subject() {
  // Open an .eml file whose subject is encoded.
  let file = new FileUtils.File(
    getTestFilePath("data/mime-encoded-subject.eml")
  );
  let msgc = await open_message_from_file(file);

  let replyWin = open_compose_with_reply(msgc);

  Assert.equal(
    replyWin.window.document.getElementById("msgSubject").value,
    "Re: \u2200a\u220aA"
  );
  close_compose_window(replyWin); // close compose window
  close_window(msgc); // close base .eml message
});

/**
 * Test that replying to a base64 encoded .eml works.
 */
add_task(async function test_reply_to_base64_eml() {
  // Open an .eml file.
  let file = new FileUtils.File(getTestFilePath("data/base64-encoded-msg.eml"));
  let msgc = await open_message_from_file(file);
  let compWin = open_compose_with_reply(msgc);
  let bodyText = get_compose_body(compWin).textContent;
  const TXT = "You have decoded this text from base64.";
  Assert.ok(bodyText.includes(TXT), "body should contain the decoded text");
  close_compose_window(compWin);
  close_window(msgc);
});

/**
 * Test that forwarding a base64 encoded .eml works.
 */
add_task(async function test_forward_base64_eml() {
  // Open an .eml file.
  let file = new FileUtils.File(getTestFilePath("data/base64-encoded-msg.eml"));
  let msgc = await open_message_from_file(file);
  let compWin = open_compose_with_forward(msgc);
  let bodyText = get_compose_body(compWin).textContent;
  const TXT = "You have decoded this text from base64.";
  Assert.ok(bodyText.includes(TXT), "body should contain the decoded text");
  close_compose_window(compWin);
  close_window(msgc);
});

/**
 * Test that replying and forwarding an evil meta msg works.
 */
add_task(async function test_reply_fwd_to_evil_meta() {
  // Open an .eml file.
  let file = new FileUtils.File(getTestFilePath("data/evil-meta-msg.eml"));
  let msgc = await open_message_from_file(file);

  const TXT = "KABOOM!";

  let reWin = open_compose_with_reply(msgc);
  let reText = get_compose_body(reWin).textContent;
  Assert.ok(reText.includes(TXT), "re body should contain the text");
  close_compose_window(reWin);

  let fwdWin = open_compose_with_forward(msgc);
  let fwdText = get_compose_body(fwdWin).textContent;
  Assert.ok(fwdText.includes(TXT), "fwd body should contain the text");
  close_compose_window(fwdWin);

  close_window(msgc);
});

/**
 * Test that forwarding an opened .eml message works with catchAll enabled.
 */
add_task(async function test_forward_eml_catchall() {
  // Open an .eml file.
  let file = new FileUtils.File(getTestFilePath("data/testmsg.eml"));
  let msgc = await open_message_from_file(file);

  MailServices.accounts.defaultAccount.defaultIdentity.catchAll = true;

  let replyWin = open_compose_with_forward(msgc);
  let bodyText = get_compose_body(replyWin).textContent;
  const message = "Because they're stupid, that's why";
  Assert.ok(bodyText.includes(message), "Correct message body");

  MailServices.accounts.defaultAccount.defaultIdentity.catchAll = false;

  close_compose_window(replyWin); // close compose window
  close_window(msgc); // close base .eml message
});