summaryrefslogtreecommitdiffstats
path: root/comm/mailnews/mime/test/unit/test_text_attachment.js
blob: bea9d5c31a5d5ce6d8000031fd2745c708856aad (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
/* 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/. */

/**
 * This test verifies that we don't display text attachments inline
 * when mail.inline_attachments is false.
 */

var { MessageGenerator, SyntheticMessageSet } = ChromeUtils.import(
  "resource://testing-common/mailnews/MessageGenerator.jsm"
);
var { MessageInjection } = ChromeUtils.import(
  "resource://testing-common/mailnews/MessageInjection.jsm"
);
var { PromiseTestUtils } = ChromeUtils.import(
  "resource://testing-common/mailnews/PromiseTestUtils.jsm"
);

const TEXT_ATTACHMENT = "inline text attachment";

var messenger = Cc["@mozilla.org/messenger;1"].createInstance(Ci.nsIMessenger);
var msgGen = new MessageGenerator();
var inbox;
var messageInjection = new MessageInjection({ mode: "local" });
var msgWindow = Cc["@mozilla.org/messenger/msgwindow;1"].createInstance(
  Ci.nsIMsgWindow
);

add_setup(function () {
  inbox = messageInjection.getInboxFolder();
});

add_task(async function test_message_attachments_no_inline() {
  Services.prefs.setBoolPref("mail.inline_attachments", false);
  Services.prefs.setBoolPref("mail.inline_attachments.text", true);
  await test_message_attachments({
    // text attachment
    attachments: [
      {
        body: TEXT_ATTACHMENT,
        filename: "test.txt",
        format: "",
      },
    ],
  });
});

add_task(async function test_message_attachments_no_inline_text() {
  Services.prefs.setBoolPref("mail.inline_attachments", true);
  Services.prefs.setBoolPref("mail.inline_attachments.text", false);
  await PromiseTestUtils.promiseDelay(100);
  await test_message_attachments({
    // text attachment
    attachments: [
      {
        body: TEXT_ATTACHMENT,
        filename: "test.txt",
        format: "",
      },
    ],
  });
});

async function test_message_attachments(info) {
  let synMsg = msgGen.makeMessage(info);
  let synSet = new SyntheticMessageSet([synMsg]);
  await messageInjection.addSetsToFolders([inbox], [synSet]);

  let msgURI = synSet.getMsgURI(0);
  let msgService = MailServices.messageServiceFromURI(msgURI);

  let streamListener = new PromiseTestUtils.PromiseStreamListener();

  msgService.streamMessage(
    msgURI,
    streamListener,
    msgWindow,
    null,
    true, // have them create the converter
    // additional uri payload, note that "header=" is prepended automatically
    "filter",
    false
  );

  let data = await streamListener.promise;
  // check that text attachment contents didn't end up inline.
  Assert.ok(!data.includes(TEXT_ATTACHMENT));
}