summaryrefslogtreecommitdiffstats
path: root/comm/mail/test/browser/folder-display/browser_recentMenu.js
blob: d87b119b0f4a806fb8c30acffe34b320d9cc7880 (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
/* 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 tests the move/copy to recent folder menus to make sure
 * that they get updated when messages are moved to folders, and
 * don't get updated when we archive.
 */

"use strict";

var utils = ChromeUtils.import("resource://testing-common/mozmill/utils.jsm");
var {
  archive_selected_messages,
  be_in_folder,
  create_folder,
  get_special_folder,
  make_message_sets_in_folders,
  mc,
  press_delete,
  right_click_on_row,
  select_click_row,
} = ChromeUtils.import(
  "resource://testing-common/mozmill/FolderDisplayHelpers.jsm"
);
var {
  click_menus_in_sequence,
  close_popup_sequence,
  click_appmenu_in_sequence,
} = ChromeUtils.import("resource://testing-common/mozmill/WindowHelpers.jsm");
var { MailUtils } = ChromeUtils.import("resource:///modules/MailUtils.jsm");
var { MailServices } = ChromeUtils.import(
  "resource:///modules/MailServices.jsm"
);

var folder1, folder2;
var gInitRecentMenuCount;

add_setup(async function () {
  // Ensure that there are no updated folders to ensure the recent folder
  // is empty.
  for (let folder of MailServices.accounts.allFolders) {
    folder.setStringProperty("MRMTime", "0");
  }

  // Try to make these folders first in alphabetic order
  folder1 = await create_folder("aaafolder1");
  folder2 = await create_folder("aaafolder2");

  await make_message_sets_in_folders([folder1], [{ count: 3 }]);
});

add_task(async function test_move_message() {
  await be_in_folder(folder1);
  let msgHdr = select_click_row(0);
  // This will cause the initial build of the move recent context menu,
  // which should be empty and disabled.
  await right_click_on_row(0);
  let popups = await click_menus_in_sequence(
    getMailContext(),
    [{ id: "mailContext-moveMenu" }, { label: "Recent" }],
    true
  );
  let recentMenu = popups[popups.length - 2].querySelector('[label="Recent"]');
  Assert.equal(recentMenu.getAttribute("disabled"), "true");
  gInitRecentMenuCount = recentMenu.itemCount;
  Assert.equal(gInitRecentMenuCount, 0);
  let hiddenPromise = BrowserTestUtils.waitForEvent(
    getMailContext(),
    "popuphidden"
  );
  close_popup_sequence(popups);
  await hiddenPromise;
  await new Promise(resolve => requestAnimationFrame(resolve));
  let copyListener = {
    copyDone: false,
    OnStartCopy() {},
    OnProgress(aProgress, aProgressMax) {},
    SetMessageKey(aKey) {},
    SetMessageId(aMessageId) {},
    OnStopCopy(aStatus) {
      this.copyDone = true;
    },
  };
  MailServices.copy.copyMessages(
    folder1,
    [msgHdr],
    folder2,
    true,
    copyListener,
    mc.window.msgWindow,
    true
  );
  utils.waitFor(
    () => copyListener.copyDone,
    "Timeout waiting for copy to complete",
    10000,
    100
  );
  // We've moved a message to aaafolder2 - it should appear in recent list now.
  // Clicking the menuitem by label is not localizable, but Recent doesn't have an
  // id we can use.
  select_click_row(0);
  await right_click_on_row(0);
  popups = await click_menus_in_sequence(
    getMailContext(),
    [{ id: "mailContext-moveMenu" }, { label: "Recent" }],
    true
  );
  let recentChildren = popups[popups.length - 1].children;
  Assert.equal(
    recentChildren.length,
    gInitRecentMenuCount + 1,
    "recent menu should have one more child after move"
  );
  Assert.equal(
    recentChildren[0].label,
    "aaafolder2",
    "recent menu child should be aaafolder2 after move"
  );
  hiddenPromise = BrowserTestUtils.waitForEvent(
    getMailContext(),
    "popuphidden"
  );
  close_popup_sequence(popups);
  await hiddenPromise;
  await new Promise(resolve => requestAnimationFrame(resolve));
});

add_task(async function test_delete_message() {
  press_delete(mc);
  // We've deleted a message - we should still just have folder2 in the menu.
  select_click_row(0); // TODO shouldn't need to do this
  await right_click_on_row(0);
  let popups = await click_menus_in_sequence(
    getMailContext(),
    [{ id: "mailContext-moveMenu" }, { label: "Recent" }],
    true
  );
  let recentChildren = popups[popups.length - 1].children;
  Assert.equal(
    recentChildren.length,
    gInitRecentMenuCount + 1,
    "delete shouldn't add anything to recent menu"
  );
  Assert.equal(
    recentChildren[0].label,
    "aaafolder2",
    "recent menu should still be aaafolder2 after delete"
  );
  let hiddenPromise = BrowserTestUtils.waitForEvent(
    getMailContext(),
    "popuphidden"
  );
  close_popup_sequence(popups);
  await hiddenPromise;
  await new Promise(resolve => requestAnimationFrame(resolve));
});

add_task(async function test_archive_message() {
  archive_selected_messages();
  // We've archived a message - we should still just have folder2 in the menu.
  let archive = await get_special_folder(
    Ci.nsMsgFolderFlags.Archive,
    false,
    false
  );
  await be_in_folder(archive.descendants[0]);
  select_click_row(0);
  await right_click_on_row(0);
  let popups = await click_menus_in_sequence(
    getMailContext(),
    [{ id: "mailContext-moveMenu" }, { label: "Recent" }],
    true
  );
  let recentChildren = popups[popups.length - 1].children;
  Assert.equal(
    recentChildren.length,
    gInitRecentMenuCount + 1,
    "archive shouldn't add anything to recent menu"
  );
  Assert.equal(
    recentChildren[0].label,
    "aaafolder2",
    "recent menu should still be aaafolder2 after archive"
  );
  let hiddenPromise = BrowserTestUtils.waitForEvent(
    getMailContext(),
    "popuphidden"
  );
  close_popup_sequence(popups);
  await hiddenPromise;
  await new Promise(resolve => requestAnimationFrame(resolve));
});