summaryrefslogtreecommitdiffstats
path: root/comm/mail/test/browser/attachment/browser_attachment.js
blob: c24a15eff2cf40b94addd2301efd14d39f99eba0 (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
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
/* 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/. */

/**
 * Checks various attachments display correctly
 */

"use strict";

var { close_compose_window, open_compose_with_forward } = ChromeUtils.import(
  "resource://testing-common/mozmill/ComposeHelpers.jsm"
);
var {
  add_message_to_folder,
  assert_attachment_list_focused,
  assert_message_pane_focused,
  assert_selected_and_displayed,
  be_in_folder,
  close_popup,
  create_folder,
  create_message,
  get_about_message,
  mc,
  msgGen,
  plan_to_wait_for_folder_events,
  select_click_row,
  select_none,
  wait_for_folder_events,
  wait_for_message_display_completion,
  wait_for_popup_to_open,
} = ChromeUtils.import(
  "resource://testing-common/mozmill/FolderDisplayHelpers.jsm"
);
var { SyntheticPartLeaf, SyntheticPartMultiMixed } = ChromeUtils.import(
  "resource://testing-common/mailnews/MessageGenerator.jsm"
);

var {
  async_plan_for_new_window,
  close_window,
  plan_for_modal_dialog,
  wait_for_modal_dialog,
} = ChromeUtils.import("resource://testing-common/mozmill/WindowHelpers.jsm");

var folder;
var messages;

var textAttachment =
  "One of these days... people like me will rise up and overthrow you, and " +
  "the end of tyranny by the homeostatic machine will have arrived. The day " +
  "of human values and compassion and simple warmth will return, and when " +
  "that happens someone like myself who has gone through an ordeal and who " +
  "genuinely needs hot coffee to pick him up and keep him functioning when " +
  "he has to function will get the hot coffee whether he happens to have a " +
  "poscred readily available or not.";

var binaryAttachment = textAttachment;

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

  var attachedMessage = msgGen.makeMessage({
    body: { body: "I'm an attached email!" },
    attachments: [
      { body: textAttachment, filename: "inner attachment.txt", format: "" },
    ],
  });

  // create some messages that have various types of attachments
  messages = [
    // no attachment
    {},
    // text attachment
    {
      attachments: [{ body: textAttachment, filename: "ubik.txt", format: "" }],
    },
    // binary attachment; filename has 9 "1"s, which should be just within the
    // limit for showing the original name
    {
      attachments: [
        {
          body: binaryAttachment,
          contentType: "application/octet-stream",
          filename: "ubik-111111111.xxyyzz",
          format: "",
        },
      ],
    },
    // multiple attachments
    {
      attachments: [
        { body: textAttachment, filename: "ubik.txt", format: "" },
        {
          body: binaryAttachment,
          contentType: "application/octet-stream",
          filename: "ubik.xxyyzz",
          format: "",
        },
      ],
    },
    // attachment with a long name; the attachment bar should crop this
    {
      attachments: [
        {
          body: textAttachment,
          filename:
            "this-is-a-file-with-an-extremely-long-name-" +
            "that-seems-to-go-on-forever-seriously-you-" +
            "would-not-believe-how-long-this-name-is-it-" +
            "surely-exceeds-the-maximum-filename-length-" +
            "for-most-filesystems.txt",
          format: "",
        },
      ],
    },
    // a message with a text attachment and an email attachment, which in turn
    // has its own text attachment
    {
      bodyPart: new SyntheticPartMultiMixed([
        new SyntheticPartLeaf("I'm a message!"),
        new SyntheticPartLeaf(textAttachment, {
          filename: "outer attachment.txt",
          contentType: "text/plain",
          format: "",
        }),
        attachedMessage,
      ]),
    },
    // evilly-named attachment; spaces should be collapsed and trimmed on the
    // ends
    {
      attachments: [
        {
          body: textAttachment,
          contentType: "application/octet-stream",
          filename: " ubik  .txt                            .evil ",
          sanitizedFilename: "ubik .txt .evil",
          format: "",
        },
      ],
    },
    // another evilly-named attachment; filename has 10 "_"s, which should be
    // just enough to trigger the sanitizer
    {
      attachments: [
        {
          body: textAttachment,
          contentType: "application/octet-stream",
          filename: "ubik.txt__________.evil",
          sanitizedFilename: "ubik.txt_…_.evil",
          format: "",
        },
      ],
    },
    // No texdir change in the filename please.
    {
      attachments: [
        {
          body: textAttachment,
          filename: "ABC\u202EE.txt.zip",
          sanitizedFilename: "ABC.E.txt.zip",
        },
      ],
    },
  ];

  // Add another evilly-named attachment for Windows tests, to ensure that
  // trailing periods are stripped.
  if ("@mozilla.org/windows-registry-key;1" in Cc) {
    messages.push({
      attachments: [
        {
          body: textAttachment,
          contentType: "application/octet-stream",
          filename: "ubik.evil. . . . . . . . . ....",
          sanitizedFilename: "ubik.evil",
          format: "",
        },
      ],
    });
  }

  for (let i = 0; i < messages.length; i++) {
    await add_message_to_folder([folder], create_message(messages[i]));
  }
});

/**
 * Set the pref to ensure that the attachments pane starts out (un)expanded
 *
 * @param expand true if the attachment pane should start out expanded,
 *        false otherwise
 */
function ensure_starts_expanded(expand) {
  Services.prefs.setBoolPref(
    "mailnews.attachments.display.start_expanded",
    expand
  );
}

add_task(async function test_attachment_view_collapsed() {
  await be_in_folder(folder);

  select_click_row(0);
  assert_selected_and_displayed(0);

  if (
    !get_about_message().document.getElementById("attachmentView").collapsed
  ) {
    throw new Error("Attachment pane expanded when it shouldn't be!");
  }
});

add_task(async function test_attachment_view_expanded() {
  await be_in_folder(folder);

  for (let i = 1; i < messages.length; i++) {
    select_click_row(i);
    assert_selected_and_displayed(i);

    if (
      get_about_message().document.getElementById("attachmentView").collapsed
    ) {
      throw new Error(
        "Attachment pane collapsed (on message #" + i + " when it shouldn't be!"
      );
    }
  }
});

add_task(async function test_attachment_name_sanitization() {
  await be_in_folder(folder);

  let aboutMessage = get_about_message();
  let attachmentList = aboutMessage.document.getElementById("attachmentList");

  for (let i = 0; i < messages.length; i++) {
    if ("attachments" in messages[i]) {
      select_click_row(i);
      assert_selected_and_displayed(i);

      let attachments = messages[i].attachments;
      if (messages[i].attachments.length == 1) {
        Assert.equal(
          aboutMessage.document.getElementById("attachmentName").value,
          attachments[0].sanitizedFilename || attachments[0].filename
        );
      }

      for (let j = 0; j < attachments.length; j++) {
        Assert.equal(
          attachmentList.getItemAtIndex(j).getAttribute("name"),
          attachments[j].sanitizedFilename || attachments[j].filename
        );
      }
    }
  }
});

add_task(async function test_long_attachment_name() {
  await be_in_folder(folder);

  select_click_row(4);
  assert_selected_and_displayed(4);

  let aboutMessage = get_about_message();
  let messagepaneBox = aboutMessage.document.getElementById("messagepanebox");
  let attachmentBar = aboutMessage.document.getElementById("attachmentBar");

  Assert.ok(
    messagepaneBox.getBoundingClientRect().width >=
      attachmentBar.getBoundingClientRect().width,
    "Attachment bar has expanded off the edge of the window!"
  );
});

/**
 * Make sure that, when opening attached messages, we only show the attachments
 * "beneath" the attached message (as opposed to all attachments for the root
 * message).
 */
add_task(async function test_attached_message_attachments() {
  await be_in_folder(folder);

  select_click_row(5);
  assert_selected_and_displayed(5);

  // Make sure we have the expected number of attachments in the root message:
  // an outer text attachment, an attached email, and an inner text attachment.
  let aboutMessage = get_about_message();
  Assert.equal(
    aboutMessage.document.getElementById("attachmentList").itemCount,
    3
  );

  // Open the attached email.
  let newWindowPromise = async_plan_for_new_window("mail:messageWindow");
  aboutMessage.document
    .getElementById("attachmentList")
    .getItemAtIndex(1)
    .attachment.open();
  let msgc = await newWindowPromise;
  wait_for_message_display_completion(msgc, true);

  // Make sure we have the expected number of attachments in the attached
  // message: just an inner text attachment.
  Assert.equal(
    msgc.window.document.getElementById("attachmentList").itemCount,
    1
  );

  close_window(msgc);
}).skip();

add_task(async function test_attachment_name_click() {
  await be_in_folder(folder);

  select_click_row(1);
  assert_selected_and_displayed(1);

  let aboutMessage = get_about_message();
  let attachmentList = aboutMessage.document.getElementById("attachmentList");

  Assert.ok(
    attachmentList.collapsed,
    "Attachment list should start out collapsed!"
  );

  // Ensure the open dialog appears when clicking on the attachment name and
  // that the attachment list doesn't expand.
  plan_for_modal_dialog("unknownContentTypeWindow", function () {});
  EventUtils.synthesizeMouseAtCenter(
    aboutMessage.document.getElementById("attachmentName"),
    { clickCount: 1 },
    aboutMessage
  );
  wait_for_modal_dialog("unknownContentTypeWindow");
  Assert.ok(
    attachmentList.collapsed,
    "Attachment list should not expand when clicking on attachmentName!"
  );
});

/**
 * Test that right-clicking on a particular element opens the expected context
 * menu.
 *
 * @param elementId the id of the element to right click on
 * @param contextMenuId the id of the context menu that should appear
 */
async function subtest_attachment_right_click(elementId, contextMenuId) {
  let aboutMessage = get_about_message();
  let element = aboutMessage.document.getElementById(elementId);
  let contextMenu = aboutMessage.document.getElementById(contextMenuId);

  let shownPromise = BrowserTestUtils.waitForEvent(contextMenu, "popupshown");
  EventUtils.synthesizeMouseAtCenter(
    element,
    { type: "contextmenu" },
    aboutMessage
  );
  await shownPromise;
  let hiddenPromise = BrowserTestUtils.waitForEvent(contextMenu, "popuphidden");
  contextMenu.hidePopup();
  await hiddenPromise;
  await new Promise(resolve => requestAnimationFrame(resolve));
}

add_task(async function test_attachment_right_click_single() {
  await be_in_folder(folder);

  select_click_row(1);
  assert_selected_and_displayed(1);

  await subtest_attachment_right_click(
    "attachmentIcon",
    "attachmentItemContext"
  );
  await subtest_attachment_right_click(
    "attachmentCount",
    "attachmentItemContext"
  );
  await subtest_attachment_right_click(
    "attachmentName",
    "attachmentItemContext"
  );
  await subtest_attachment_right_click(
    "attachmentSize",
    "attachmentItemContext"
  );

  await subtest_attachment_right_click(
    "attachmentToggle",
    "attachment-toolbar-context-menu"
  );
  await subtest_attachment_right_click(
    "attachmentSaveAllSingle",
    "attachment-toolbar-context-menu"
  );
  await subtest_attachment_right_click(
    "attachmentBar",
    "attachment-toolbar-context-menu"
  );
});

add_task(async function test_attachment_right_click_multiple() {
  await be_in_folder(folder);

  select_click_row(3);
  assert_selected_and_displayed(3);

  await subtest_attachment_right_click(
    "attachmentIcon",
    "attachmentListContext"
  );
  await subtest_attachment_right_click(
    "attachmentCount",
    "attachmentListContext"
  );
  await subtest_attachment_right_click(
    "attachmentSize",
    "attachmentListContext"
  );

  await subtest_attachment_right_click(
    "attachmentToggle",
    "attachment-toolbar-context-menu"
  );
  await subtest_attachment_right_click(
    "attachmentSaveAllMultiple",
    "attachment-toolbar-context-menu"
  );
  await subtest_attachment_right_click(
    "attachmentBar",
    "attachment-toolbar-context-menu"
  );
});

/**
 * Test that clicking on various elements in the attachment bar toggles the
 * attachment list.
 *
 * @param elementId the id of the element to click
 */
function subtest_attachment_list_toggle(elementId) {
  let aboutMessage = get_about_message();
  let attachmentList = aboutMessage.document.getElementById("attachmentList");
  let element = aboutMessage.document.getElementById(elementId);

  EventUtils.synthesizeMouseAtCenter(element, { clickCount: 1 }, aboutMessage);
  Assert.ok(
    !attachmentList.collapsed,
    `Attachment list should be expanded after clicking ${elementId}!`
  );
  assert_attachment_list_focused();

  EventUtils.synthesizeMouseAtCenter(element, { clickCount: 1 }, aboutMessage);
  Assert.ok(
    attachmentList.collapsed,
    `Attachment list should be collapsed after clicking ${elementId} again!`
  );
  assert_message_pane_focused();
}

add_task(async function test_attachment_list_expansion() {
  await be_in_folder(folder);

  select_click_row(1);
  assert_selected_and_displayed(1);

  let aboutMessage = get_about_message();
  Assert.ok(
    aboutMessage.document.getElementById("attachmentList").collapsed,
    "Attachment list should start out collapsed!"
  );

  subtest_attachment_list_toggle("attachmentToggle");
  subtest_attachment_list_toggle("attachmentIcon");
  subtest_attachment_list_toggle("attachmentCount");
  subtest_attachment_list_toggle("attachmentSize");
  subtest_attachment_list_toggle("attachmentBar");

  // Ensure that clicking the "Save All" button doesn't expand the attachment
  // list.
  let dm = aboutMessage.document.querySelector(
    "#attachmentSaveAllSingle .toolbarbutton-menubutton-dropmarker"
  );
  EventUtils.synthesizeMouseAtCenter(dm, { clickCount: 1 }, aboutMessage);
  Assert.ok(
    aboutMessage.document.getElementById("attachmentList").collapsed,
    "Attachment list should be collapsed after clicking save button!"
  );
}).skip();

add_task(async function test_attachment_list_starts_expanded() {
  ensure_starts_expanded(true);
  await be_in_folder(folder);

  select_click_row(2);
  assert_selected_and_displayed(2);

  Assert.ok(
    !get_about_message().document.getElementById("attachmentList").collapsed,
    "Attachment list should start out expanded!"
  );
});

add_task(async function test_selected_attachments_are_cleared() {
  ensure_starts_expanded(false);
  await be_in_folder(folder);
  // First, select the message with two attachments.
  select_click_row(3);

  // Expand the attachment list.
  let aboutMessage = get_about_message();
  EventUtils.synthesizeMouseAtCenter(
    aboutMessage.document.getElementById("attachmentToggle"),
    { clickCount: 1 },
    aboutMessage
  );

  // Select both the attachments.
  let attachmentList = aboutMessage.document.getElementById("attachmentList");
  Assert.equal(
    attachmentList.selectedItems.length,
    1,
    "On first load the first item should be selected"
  );

  // We can just click on the first element, but the second one needs a
  // ctrl-click (or cmd-click for those Mac-heads among us).
  EventUtils.synthesizeMouseAtCenter(
    attachmentList.children[0],
    { clickCount: 1 },
    aboutMessage
  );
  EventUtils.synthesizeMouse(
    attachmentList.children[1],
    5,
    5,
    { accelKey: true },
    aboutMessage
  );

  Assert.equal(
    attachmentList.selectedItems.length,
    2,
    "We had the wrong number of selected items after selecting some!"
  );

  // Switch to the message with one attachment, and make sure there are no
  // selected attachments.
  select_click_row(2);

  // Expand the attachment list again.
  EventUtils.synthesizeMouseAtCenter(
    aboutMessage.document.getElementById("attachmentToggle"),
    { clickCount: 1 },
    aboutMessage
  );

  Assert.equal(
    attachmentList.selectedItems.length,
    1,
    "After loading a new message the first item should be selected"
  );
});

add_task(async function test_select_all_attachments_key() {
  await be_in_folder(folder);

  // First, select the message with two attachments.
  select_none();
  select_click_row(3);

  // Expand the attachment list.
  let aboutMessage = get_about_message();
  EventUtils.synthesizeMouseAtCenter(
    aboutMessage.document.getElementById("attachmentToggle"),
    { clickCount: 1 },
    aboutMessage
  );

  let attachmentList = aboutMessage.document.getElementById("attachmentList");
  attachmentList.focus();
  EventUtils.synthesizeKey("a", { accelKey: true }, aboutMessage);
  Assert.equal(
    attachmentList.selectedItems.length,
    2,
    "Should have selected all attachments!"
  );
});

add_task(async function test_delete_attachment_key() {
  await be_in_folder(folder);

  // First, select the message with two attachments.
  select_none();
  select_click_row(3);

  // Expand the attachment list.
  assert_selected_and_displayed(3);
  let aboutMessage = get_about_message();
  if (aboutMessage.document.getElementById("attachmentList").collapsed) {
    EventUtils.synthesizeMouseAtCenter(
      aboutMessage.document.getElementById("attachmentToggle"),
      { clickCount: 1 },
      aboutMessage
    );
  }
  let firstAttachment =
    aboutMessage.document.getElementById("attachmentList").firstElementChild;
  EventUtils.synthesizeMouseAtCenter(
    firstAttachment,
    { clickCount: 1 },
    aboutMessage
  );

  // Try deleting with the delete key
  let dialogPromise = BrowserTestUtils.promiseAlertDialog("cancel");
  firstAttachment.focus();
  EventUtils.synthesizeKey("VK_DELETE", {}, aboutMessage);
  await dialogPromise;

  // Try deleting with the shift-delete key combo.
  dialogPromise = BrowserTestUtils.promiseAlertDialog("cancel");
  firstAttachment.focus();
  EventUtils.synthesizeKey("VK_DELETE", { shiftKey: true }, aboutMessage);
  await dialogPromise;
}).skip();

add_task(async function test_attachments_compose_menu() {
  await be_in_folder(folder);

  // First, select the message with two attachments.
  select_none();
  select_click_row(3);

  let cwc = open_compose_with_forward();
  let attachment = cwc.window.document.getElementById("attachmentBucket");

  // On Linux and OSX, focus events don't seem to be sent to child elements properly if
  // the parent window is not focused.  This causes some random oranges for us.
  // We use the force_focus function to "cheat" a bit, and trigger the function
  // that focusing normally would fire.  We do normal focusing for Windows.
  function force_focus(aId) {
    let element = cwc.window.document.getElementById(aId);
    element.focus();

    if (["linux", "macosx"].includes(AppConstants.platform)) {
      // First, call the window's default controller's function.
      cwc.window.defaultController.isCommandEnabled("cmd_delete");

      // Walk up the DOM tree and call isCommandEnabled on the first controller
      // that supports "cmd_delete".
      while (element != cwc.window.document) {
        // NOTE: html elements (like body) don't have controllers.
        let numControllers = element.controllers?.getControllerCount() || 0;
        for (let i = 0; numControllers; i++) {
          let currController = element.controllers.getControllerAt(i);
          if (currController.supportsCommand("cmd_delete")) {
            currController.isCommandEnabled("cmd_delete");
            return;
          }
        }
        element = element.parentNode;
      }
    }
  }

  // Click on a portion of the attachmentBucket to focus on it. The last
  // attachment should be selected since we don't handle any action on an empty
  // bucket, and we always ensure that the last attached file is visible.
  force_focus("attachmentBucket");

  Assert.equal(
    "Remove Attachment",
    cwc.window.document.getElementById("cmd_delete").getAttribute("label"),
    "attachmentBucket with last attachment is focused!"
  );

  // We opened a message with 2 attachments, so index 1 should be focused.
  Assert.equal(attachment.selectedIndex, 1, "Last attachment is focused!");

  // Select 1 attachment, and
  // focus the subject to see the label change and to execute isCommandEnabled
  attachment.selectedIndex = 0;
  force_focus("msgSubject");
  Assert.equal(
    "Delete",
    cwc.window.document.getElementById("cmd_delete").getAttribute("label"),
    "attachmentBucket is not focused!"
  );

  // Focus back to the attachmentBucket
  force_focus("attachmentBucket");
  Assert.equal(
    "Remove Attachment",
    cwc.window.document.getElementById("cmd_delete").getAttribute("label"),
    "Only 1 attachment is selected!"
  );

  // Select multiple attachments, and focus the identity for the same purpose
  attachment.selectAll();
  force_focus("msgIdentity");
  Assert.equal(
    "Delete",
    cwc.window.document.getElementById("cmd_delete").getAttribute("label"),
    "attachmentBucket is not focused!"
  );

  // Focus back to the attachmentBucket
  force_focus("attachmentBucket");
  Assert.equal(
    "Remove Attachments",
    cwc.window.document.getElementById("cmd_delete").getAttribute("label"),
    "Multiple attachments are selected!"
  );

  close_compose_window(cwc);
});

add_task(async function test_delete_from_toolbar() {
  await be_in_folder(folder);

  // First, select the message with two attachments.
  select_none();
  select_click_row(3);

  // Expand the attachment list.
  assert_selected_and_displayed(3);
  let aboutMessage = get_about_message();
  if (aboutMessage.document.getElementById("attachmentList").collapsed) {
    EventUtils.synthesizeMouseAtCenter(
      aboutMessage.document.getElementById("attachmentToggle"),
      { clickCount: 1 },
      aboutMessage
    );
  }

  let firstAttachment =
    aboutMessage.document.getElementById("attachmentList").firstElementChild;
  EventUtils.synthesizeMouseAtCenter(
    firstAttachment,
    { clickCount: 1 },
    aboutMessage
  );

  // Make sure clicking the "Delete" toolbar button with an attachment focused
  // deletes the *message*.
  plan_to_wait_for_folder_events("DeleteOrMoveMsgCompleted");
  EventUtils.synthesizeMouseAtCenter(
    aboutMessage.document.getElementById("hdrTrashButton"),
    { clickCount: 1 },
    aboutMessage
  );
  wait_for_folder_events();
}).skip();

registerCleanupFunction(() => {
  // Remove created folders.
  folder.deleteSelf(null);
});