summaryrefslogtreecommitdiffstats
path: root/comm/mail/test/browser/composition/browser_replySignature.js
blob: 6053171468a63e2a797532cc0acfb81d5129e3b1 (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
/* 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 the mail.strip_sig_on_reply pref.
 */

"use strict";

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

var sig = "roses are red";
var folder;

add_setup(async function () {
  folder = await create_folder("SigStripTest");
  registerCleanupFunction(() => folder.deleteSelf(null));

  let msg = create_message({
    subject: "msg with signature; format=flowed",
    body: {
      body:
        "get with the flow! get with the flow! get with the flow! " +
        "get with the \n flow! get with the flow!\n-- \n" +
        sig +
        "\n",
      contentType: "text/plain",
      charset: "UTF-8",
      format: "flowed",
    },
  });
  await add_message_to_folder([folder], msg);
  let msg2 = create_message({
    subject: "msg with signature; format not flowed",
    body: {
      body:
        "not flowed! not flowed! not flowed! \n" +
        "not flowed!\n-- \n" +
        sig +
        "\n",
      contentType: "text/plain",
      charset: "UTF-8",
      format: "",
    },
  });
  await add_message_to_folder([folder], msg2);
});

/** Test sig strip true for format flowed. */
add_task(async function test_sig_strip_true_ff() {
  Services.prefs.setBoolPref("mail.strip_sig_on_reply", true);
  await check_sig_strip_works(0, true);
  Services.prefs.clearUserPref("mail.strip_sig_on_reply");
});

/** Test sig strip false for format flowed. */
add_task(async function test_sig_strip_false_ff() {
  Services.prefs.setBoolPref("mail.strip_sig_on_reply", false);
  await check_sig_strip_works(0, false);
  Services.prefs.clearUserPref("mail.strip_sig_on_reply");
});

/** Test sig strip true for non-format flowed. */
add_task(async function test_sig_strip_true_nonff() {
  Services.prefs.setBoolPref("mail.strip_sig_on_reply", true);
  await check_sig_strip_works(1, true);
  Services.prefs.clearUserPref("mail.strip_sig_on_reply");
});

/** Test sig strip false for non-format flowed. */
add_task(async function test_sig_strip_false_nonff() {
  Services.prefs.setBoolPref("mail.strip_sig_on_reply", false);
  await check_sig_strip_works(1, false);
  Services.prefs.clearUserPref("mail.strip_sig_on_reply");
});

/**
 * Helper function to check signature stripping works as it should.
 *
 * @param aRow the row index of the message to test
 * @param aShouldStrip true if the signature should be stripped
 */
async function check_sig_strip_works(aRow, aShouldStrip) {
  await be_in_folder(folder);
  let msg = select_click_row(aRow);
  assert_selected_and_displayed(mc, msg);

  let rwc = open_compose_with_reply();
  let body = get_compose_body(rwc);

  if (aShouldStrip && body.textContent.includes(sig)) {
    throw new Error("signature was not stripped; body=" + body.textContent);
  } else if (!aShouldStrip && !body.textContent.includes(sig)) {
    throw new Error("signature stripped; body=" + body.textContent);
  }
  close_compose_window(rwc);

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