summaryrefslogtreecommitdiffstats
path: root/comm/mail/test/browser/folder-display/browser_watchIgnoreThread.js
blob: b0036aee4d00eb02de64436ec90da1df8f20fe39 (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
/* 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 that "watch thread" and "ignore thread" works correctly.
 */

"use strict";

var {
  add_message_sets_to_folders,
  assert_not_shown,
  assert_selected_and_displayed,
  assert_visible,
  be_in_folder,
  create_folder,
  create_thread,
  expand_all_threads,
  inboxFolder,
  make_display_threaded,
  mc,
  select_click_row,
  wait_for_popup_to_open,
} = ChromeUtils.import(
  "resource://testing-common/mozmill/FolderDisplayHelpers.jsm"
);
var { click_menus_in_sequence } = ChromeUtils.import(
  "resource://testing-common/mozmill/WindowHelpers.jsm"
);

var folder;
var thread1, thread2, thread3;

add_setup(async function () {
  document.getElementById("toolbar-menubar").removeAttribute("autohide");
  folder = await create_folder("WatchIgnoreThreadTest");
  thread1 = create_thread(3);
  thread2 = create_thread(4);
  thread3 = create_thread(5);
  await add_message_sets_to_folders([folder], [thread1, thread2, thread3]);

  await be_in_folder(folder);
  make_display_threaded();
  expand_all_threads();

  registerCleanupFunction(() => {
    document.getElementById("toolbar-menubar").autohide = true;
  });
});

/**
 * Click one of the menu items in the View | Messages menu.
 *
 * @param {string} id - The id of the menu item to click.
 */
async function clickViewMessagesItem(id) {
  EventUtils.synthesizeMouseAtCenter(
    mc.window.document.getElementById("menu_View"),
    {},
    mc.window.document.getElementById("menu_View").ownerGlobal
  );
  await click_menus_in_sequence(
    mc.window.document.getElementById("menu_View_Popup"),
    [{ id: "viewMessagesMenu" }, { id }]
  );
}

/**
 * Test that Ignore Thread works as expected.
 */
add_task(async function test_ignore_thread() {
  let t1root = thread1.getMsgHdr(0);

  let t1second = select_click_row(1);
  assert_selected_and_displayed(t1second);

  // Ignore this thread.
  EventUtils.synthesizeKey("K", { shiftKey: false, accelKey: false });

  // The first msg in the next thread should now be selected.
  let t2root = thread2.getMsgHdr(0);
  assert_selected_and_displayed(t2root);

  // The ignored thread should still be visible (with an ignored icon).
  assert_visible(t1root);

  // Go to another folder then back. Ignored messages should now be hidden.
  await be_in_folder(inboxFolder);
  await be_in_folder(folder);
  select_click_row(0);
  assert_selected_and_displayed(t2root);
});

/**
 * Test that ignored threads are shown when the View | Threads |
 * Ignored Threads option is checked.
 */
add_task(async function test_view_threads_ignored_threads() {
  let t1root = thread1.getMsgHdr(0);
  let t2root = thread2.getMsgHdr(0);

  // Check "Ignored Threads" - the ignored messages should appear =>
  // the first row is the first message of the first thread.
  // await clickViewMessagesItem("viewIgnoredThreadsMenuItem");
  goDoCommand("cmd_viewIgnoredThreads");
  select_click_row(0);
  assert_selected_and_displayed(t1root);

  // Uncheck "Ignored Threads" - the ignored messages should get hidden.
  // await clickViewMessagesItem("viewIgnoredThreadsMenuItem");
  goDoCommand("cmd_viewIgnoredThreads");
  select_click_row(0);
  assert_selected_and_displayed(t2root);
  assert_not_shown(thread1.msgHdrList);
}).__skipMe = AppConstants.platform == "macosx";

/**
 * Test that Watch Thread makes the thread watched.
 */
add_task(async function test_watch_thread() {
  let t2second = select_click_row(1);
  let t3root = thread3.getMsgHdr(0);
  assert_selected_and_displayed(t2second);

  // Watch this thread.
  EventUtils.synthesizeKey("W", { shiftKey: false, accelKey: false });

  // Choose "Watched Threads with Unread".
  // await clickViewMessagesItem("viewWatchedThreadsWithUnreadMenuItem");
  goDoCommand("cmd_viewWatchedThreadsWithUnread");
  select_click_row(1);
  assert_selected_and_displayed(t2second);
  assert_not_shown(thread1.msgHdrList);
  assert_not_shown(thread3.msgHdrList);

  // Choose "All Messages" again.
  // await clickViewMessagesItem("viewAllMessagesMenuItem");
  goDoCommand("cmd_viewAllMsgs");
  assert_not_shown(thread1.msgHdrList); // still ignored (and now shown)
  select_click_row(thread2.msgHdrList.length);
  assert_selected_and_displayed(t3root);

  Assert.report(
    false,
    undefined,
    undefined,
    "Test ran to completion successfully"
  );
}).__skipMe = AppConstants.platform == "macosx";