summaryrefslogtreecommitdiffstats
path: root/comm/mail/test/browser/folder-display/browser_tabsSimple.js
blob: d0a514c6169c11e11bc250e14192ab69743f77d9 (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/. */

/*
 * Test that opening new folder and message tabs has the expected result and
 * that closing them doesn't break anything.  sid0 added checks for focus
 * transitions at one point; I (asuth) am changing our test infrastructure to
 * cause more realistic focus changes so those changes now look sillier
 * because in many cases we are explicitly setting focus back after the thread
 * tree gains focus.
 */

"use strict";

var {
  assert_folder_tree_focused,
  assert_message_pane_focused,
  assert_messages_in_view,
  assert_nothing_selected,
  assert_selected_and_displayed,
  assert_thread_tree_focused,
  be_in_folder,
  close_tab,
  create_folder,
  focus_folder_tree,
  focus_message_pane,
  focus_thread_tree,
  make_message_sets_in_folders,
  mc,
  open_folder_in_new_tab,
  open_selected_message_in_new_tab,
  select_click_row,
  switch_tab,
  wait_for_blank_content_pane,
} = ChromeUtils.import(
  "resource://testing-common/mozmill/FolderDisplayHelpers.jsm"
);

var folderA, folderB, setA, setB;

add_setup(async function () {
  folderA = await create_folder("TabsSimpleA");
  folderB = await create_folder("TabsSimpleB");

  // We will verify we are seeing the right folder by checking that it has the
  //  right messages in it.
  [setA] = await make_message_sets_in_folders([folderA], [{}]);
  [setB] = await make_message_sets_in_folders([folderB], [{}]);
});

/** The tabs in our test. */
var tabFolderA, tabFolderB, tabMessageA, tabMessageB;
/** The message that we selected for tab display, to check it worked right. */
var messageA, messageB;

/**
 * Make sure the default tab works right.
 */
add_task(async function test_open_folder_a() {
  tabFolderA = await be_in_folder(folderA);
  assert_messages_in_view(setA);
  assert_nothing_selected();
  // Focus the folder tree here
  focus_folder_tree();
});

/**
 * Open tab b, make sure it works right.
 */
add_task(async function test_open_folder_b_in_tab() {
  tabFolderB = await open_folder_in_new_tab(folderB);
  wait_for_blank_content_pane();
  assert_messages_in_view(setB);
  assert_nothing_selected();
  focus_thread_tree();
});

/**
 * Go back to tab/folder A and make sure we change correctly.
 */
add_task(async function test_switch_to_tab_folder_a() {
  await switch_tab(tabFolderA);
  assert_messages_in_view(setA);
  assert_nothing_selected();
  assert_folder_tree_focused();
});

/**
 * Select a message in folder A and open it in a new window, making sure that
 *  the displayed message is the right one.
 */
add_task(async function test_open_message_a_in_tab() {
  // (this focuses the thread tree for tabFolderA...)
  messageA = select_click_row(0);
  // (...refocus the folder tree for our sticky check below)
  focus_folder_tree();
  tabMessageA = await open_selected_message_in_new_tab();
  assert_selected_and_displayed(messageA);
  assert_message_pane_focused();
});

/**
 * Go back to tab/folder B and make sure we change correctly.
 */
add_task(async function test_switch_to_tab_folder_b() {
  await switch_tab(tabFolderB);
  assert_messages_in_view(setB);
  assert_nothing_selected();
  assert_thread_tree_focused();
});

/**
 * Select a message in folder B and open it in a new window, making sure that
 *  the displayed message is the right one.
 */
add_task(async function test_open_message_b_in_tab() {
  messageB = select_click_row(0);
  // Let's focus the message pane now
  focus_message_pane();
  tabMessageB = await open_selected_message_in_new_tab();
  assert_selected_and_displayed(messageB);
  assert_message_pane_focused();
});

/**
 * Switch to message tab A.
 */
add_task(async function test_switch_to_message_a() {
  await switch_tab(tabMessageA);
  assert_selected_and_displayed(messageA);
  assert_message_pane_focused();
});

/**
 * Close message tab A (when it's in the foreground).
 */
add_task(function test_close_message_a() {
  close_tab();
  // our current tab is now undefined for the purposes of this test.
});

/**
 * Make sure all the other tabs are still happy.
 */
add_task(async function test_tabs_are_still_happy() {
  await switch_tab(tabFolderB);
  assert_messages_in_view(setB);
  assert_selected_and_displayed(messageB);
  assert_message_pane_focused();

  await switch_tab(tabMessageB);
  assert_selected_and_displayed(messageB);
  assert_message_pane_focused();

  await switch_tab(tabFolderA);
  assert_messages_in_view(setA);
  assert_selected_and_displayed(messageA);
  // focus restoration uses setTimeout(0) and so we need to give it a chance
  await new Promise(resolve => setTimeout(resolve));
  assert_folder_tree_focused();
});

/**
 * Close message tab B (when it's in the background).
 */
add_task(function test_close_message_b() {
  close_tab(tabMessageB);
  // we should still be on folder A
  assert_messages_in_view(setA);
  assert_selected_and_displayed(messageA);
  assert_folder_tree_focused();
});

/**
 * Switch to tab B, close it, make sure we end up on tab A.
 */
add_task(async function test_close_folder_b() {
  await switch_tab(tabFolderB);
  assert_messages_in_view(setB);
  assert_selected_and_displayed(messageB);
  assert_message_pane_focused();

  close_tab();
  assert_messages_in_view(setA);
  assert_selected_and_displayed(messageA);
  assert_folder_tree_focused();

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