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
|
/* 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.
*/
// make SOLO_TEST=message-header/test-return-receipt.js mozmill-one
var MODULE_NAME = "test-return-receipt";
var RELATIVE_ROOT = "../shared-modules";
var MODULE_REQUIRES = ["folder-display-helpers", "window-helpers",
"notificationbox-helpers"];
var folder;
var kBoxId = "msgNotificationBar";
var kNotificationValue = "mdnRequested";
function setupModule(module) {
collector.getModule("folder-display-helpers").installInto(module);
collector.getModule("window-helpers").installInto(module);
collector.getModule("notificationbox-helpers").installInto(module);
folder = 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" }
});
add_message_to_folder(folder, msg0);
// ... and one that doesn't request a return receipt.
let msg1 = create_message();
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" }
});
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" }
});
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" }
});
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" }
});
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" }
});
add_message_to_folder(folder, msg6);
}
/** Utility to select a message. */
function gotoMsg(row) {
be_in_folder(folder);
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) {
let msgNotBar = mc.e("msgNotificationBar");
assert_notification_displayed(mc, kBoxId, kNotificationValue, shouldShow);
}
/**
* Utility function to make sure the notification contains a certain text.
*/
function assert_mdn_text_contains(text, shouldContain) {
let nb = mc.window.document.getElementById(kBoxId);
let notificationText = nb.currentNotification.label;
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.
*/
function test_no_mdn_for_normal_msgs() {
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.
*/
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.
*/
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.
*/
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.
*/
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.
*/
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.
*/
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);
}
|