summaryrefslogtreecommitdiffstats
path: root/comm/mail/test/browser/message-header/browser_returnReceipt.js
blob: f48fa043137b1534f1866acc700ee1bd2bdd495d (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
195
196
197
198
199
200
201
202
203
204
205
206
207
208
/* 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 return receipt (MDN) stuff.
 */

"use strict";

var {
  add_message_to_folder,
  assert_selected_and_displayed,
  be_in_folder,
  create_folder,
  create_message,
  get_about_message,
  mc,
  select_click_row,
} = ChromeUtils.import(
  "resource://testing-common/mozmill/FolderDisplayHelpers.jsm"
);
var { assert_notification_displayed } = ChromeUtils.import(
  "resource://testing-common/mozmill/NotificationBoxHelpers.jsm"
);

var folder;

var kBoxId = "mail-notification-top";
var kNotificationValue = "mdnRequested";

add_setup(async function () {
  folder = await create_folder("ReturnReceiptTest");

  // Create a message that requests a return receipt.
  let msg0 = create_message({
    from: ["Ake", "ake@example.com"],
    clobberHeaders: { "Disposition-Notification-To": "ake@example.com" },
  });
  await add_message_to_folder([folder], msg0);

  // ... and one that doesn't request a return receipt.
  let msg1 = create_message();
  await add_message_to_folder([folder], msg1);

  // Create a message that requests a return receipt to a different address.
  let msg2 = create_message({
    from: ["Mimi", "me@example.org"],
    clobberHeaders: { "Disposition-Notification-To": "other@example.com" },
  });
  await add_message_to_folder([folder], msg2);

  // Create a message that requests a return receipt to different addresses.
  let msg3 = create_message({
    from: ["Bobby", "bob@example.org"],
    clobberHeaders: {
      "Disposition-Notification-To": "ex1@example.com, ex2@example.com",
    },
  });
  await add_message_to_folder([folder], msg3);

  // Create a message that requests a return receipt using non-standard header.
  let msg4 = create_message({
    from: ["Ake", "ake@example.com"],
    clobberHeaders: { "Return-Receipt-To": "ake@example.com" },
  });
  await add_message_to_folder([folder], msg4);

  // Create a message that requests a return receipt to a different address
  // using non-standard header.
  let msg5 = create_message({
    from: ["Mimi", "me@example.org"],
    clobberHeaders: { "Return-Receipt-To": "other@example.com" },
  });
  await add_message_to_folder([folder], msg5);

  // Create a message that requests a return receipt to different addresses
  // using non-standard header.
  let msg6 = create_message({
    from: ["Bobby", "bob@example.org"],
    clobberHeaders: { "Return-Receipt-To": "ex1@example.com, ex2@example.com" },
  });
  await add_message_to_folder([folder], msg6);

  await be_in_folder(folder);
});

/** Utility to select a message. */
function gotoMsg(row) {
  let curMessage = select_click_row(row);
  assert_selected_and_displayed(mc, curMessage);
}

/**
 * Utility to make sure the MDN bar is shown / not shown.
 */
function assert_mdn_shown(shouldShow) {
  assert_notification_displayed(
    get_about_message(),
    kBoxId,
    kNotificationValue,
    shouldShow
  );
}

/**
 * Utility function to make sure the notification contains a certain text.
 */
function assert_mdn_text_contains(text, shouldContain) {
  let nb = get_about_message().document.getElementById(kBoxId);
  let box = nb.querySelector(".notificationbox-stack")._notificationBox;
  let notificationText = box.currentNotification.messageText.textContent;
  if (shouldContain && !notificationText.includes(text)) {
    throw new Error(
      "mdnBar should contain text=" +
        text +
        "; notificationText=" +
        notificationText
    );
  }
  if (!shouldContain && notificationText.includes(text)) {
    throw new Error(
      "mdnBar shouldn't contain text=" +
        text +
        "; notificationText=" +
        notificationText
    );
  }
}

/**
 * Test that return receipts are not shown when Disposition-Notification-To
 * and Return-Receipt-To isn't set.
 */
add_task(function test_no_mdn_for_normal_msgs() {
  gotoMsg(0); // TODO this shouldn't be needed but the selection goes to 0 on focus.
  gotoMsg(1); // This message doesn't request a return receipt.
  assert_mdn_shown(false);
});

/**
 * Test that return receipts are shown when Disposition-Notification-To is set.
 */
add_task(function test_basic_mdn_shown() {
  gotoMsg(0); // This message requests a return receipt.
  assert_mdn_shown(true);
  assert_mdn_text_contains("ake@example.com", false); // only name should show
});

/**
 * Test that return receipts are shown when Return-Receipt-To is set.
 */
add_task(function test_basic_mdn_shown_nonrfc() {
  gotoMsg(4); // This message requests a return receipt.
  assert_mdn_shown(true);
  assert_mdn_text_contains("ake@example.com", false); // only name should show
});

/**
 * Test that return receipts warns when the mdn address is different.
 * The RFC compliant version.
 */
add_task(function test_mdn_when_from_and_disposition_to_differs() {
  gotoMsg(2); // Should display a notification with warning.
  assert_mdn_shown(true);
  assert_mdn_text_contains("other@example.com", true); // address should show
});

/**
 * Test that return receipts warns when the mdn address is different.
 * The RFC non-compliant version.
 */
add_task(function test_mdn_when_from_and_disposition_to_differs_nonrfc() {
  gotoMsg(5); // Should display a notification with warning.
  assert_mdn_shown(true);
  assert_mdn_text_contains("other@example.com", true); // address should show
});

/**
 * Test that return receipts warns when the mdn address consists of multiple
 * addresses.
 */
add_task(function test_mdn_when_disposition_to_multi() {
  gotoMsg(3);
  // Should display a notification with warning listing all the addresses.
  assert_mdn_shown(true);
  assert_mdn_text_contains("ex1@example.com", true);
  assert_mdn_text_contains("ex2@example.com", true);
});

/**
 * Test that return receipts warns when the mdn address consists of multiple
 * addresses. Non-RFC compliant version.
 */
add_task(function test_mdn_when_disposition_to_multi_nonrfc() {
  gotoMsg(6);
  // Should display a notification with warning listing all the addresses.
  assert_mdn_shown(true);
  assert_mdn_text_contains("ex1@example.com", true);
  assert_mdn_text_contains("ex2@example.com", true);

  Assert.report(
    false,
    undefined,
    undefined,
    "Test ran to completion successfully"
  );
});