summaryrefslogtreecommitdiffstats
path: root/comm/mail/test/browser/folder-display/browser_messagePaneVisibility.js
blob: 1cab2740e022a9c5f7cd1001aa9065c9c7f3fadf (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
/* 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 the message pane collapses properly, stays collapsed amongst tab
 *  changes, and that persistence works (to a first approximation).
 */

"use strict";

var {
  assert_message_pane_hidden,
  assert_message_pane_visible,
  be_in_folder,
  close_tab,
  create_folder,
  make_message_sets_in_folders,
  mc,
  open_folder_in_new_tab,
  open_selected_message_in_new_tab,
  select_click_row,
  switch_tab,
  toggle_message_pane,
} = ChromeUtils.import(
  "resource://testing-common/mozmill/FolderDisplayHelpers.jsm"
);

var folder;

add_setup(async function () {
  folder = await create_folder("MessagePaneVisibility");
  await make_message_sets_in_folders([folder], [{ count: 3 }]);
});

/**
 * By default, the message pane should be visible.  Make sure that this state of
 *  affairs is correct in terms of menu options, splitters, etc.
 */
add_task(async function test_message_pane_visible_state_is_right() {
  await be_in_folder(folder);
  assert_message_pane_visible();
  Assert.ok(true, "test_message_pane_visible_state_is_right ran to completion");
});

/**
 * Toggle the message off.
 */
add_task(function test_toggle_message_pane_off() {
  toggle_message_pane();
  assert_message_pane_hidden();
  Assert.ok(true, "test_toggle_message_pane_off ran to completion");
});

/**
 * Toggle the message pane on.
 */
add_task(function test_toggle_message_pane_on() {
  toggle_message_pane();
  assert_message_pane_visible();
  Assert.ok(true, "test_toggle_message_pane_on ran to completion");
});

/**
 * Make sure that the message tab isn't broken by being invoked from a folder tab
 *  with a collapsed message pane.
 */
add_task(
  async function test_collapsed_message_pane_does_not_break_message_tab() {
    await be_in_folder(folder);

    // - toggle message pane off
    toggle_message_pane();
    assert_message_pane_hidden();

    // - open message tab, make sure the message pane is visible
    select_click_row(0);
    let tabMessage = await open_selected_message_in_new_tab();

    // - close the tab, sanity check the transition was okay
    close_tab(tabMessage);
    assert_message_pane_hidden();

    // - restore the state...
    toggle_message_pane();

    Assert.ok(
      true,
      "test_collapsed_message_pane_does_not_break_message_tab ran to completion"
    );
  }
);

/**
 * Make sure that switching to message tabs or folder pane tabs with a different
 *  message pane state does not break.  This test should cover all transition
 *  states.
 */
add_task(async function test_message_pane_is_sticky() {
  let tabFolderA = await be_in_folder(folder);
  assert_message_pane_visible();

  // [folder+ => (new) message]
  select_click_row(0);
  let tabMessage = await open_selected_message_in_new_tab();

  // [message => folder+]
  await switch_tab(tabFolderA);
  assert_message_pane_visible();

  // [folder+ => (new) folder+]
  let tabFolderB = await open_folder_in_new_tab(folder);
  assert_message_pane_visible();

  // [folder pane toggle + => -]
  toggle_message_pane();
  assert_message_pane_hidden();

  // [folder- => folder+]
  await switch_tab(tabFolderA);
  assert_message_pane_visible();

  // (redundant) [ folder pane toggle + => -]
  toggle_message_pane();
  assert_message_pane_hidden();

  // [folder- => message]
  await switch_tab(tabMessage);

  // [message => folder-]
  close_tab(tabMessage);
  assert_message_pane_hidden();

  // [folder- => (new) folder-]
  // (we are testing inheritance here)
  let tabFolderC = await open_folder_in_new_tab(folder);
  assert_message_pane_hidden();

  // [folder- => folder-]
  close_tab(tabFolderC);
  // the tab we are on now doesn't matter, so we don't care
  assert_message_pane_hidden();
  await switch_tab(tabFolderB);

  // [ folder pane toggle - => + ]
  toggle_message_pane();
  assert_message_pane_visible();

  // [folder+ => folder-]
  close_tab(tabFolderB);
  assert_message_pane_hidden();

  // (redundant) [ folder pane toggle - => + ]
  toggle_message_pane();
  assert_message_pane_visible();

  Assert.ok(true, "test_message_pane_is_sticky ran to completion");
});

/**
 * Test that if we serialize and restore the tabs that the message pane is in
 *  the expected collapsed/non-collapsed state.  Because of the special "first
 *  tab" situation, we need to do this twice to test each case for the first
 *  tab.  For additional thoroughness we also flip the state we have the other
 *  tabs be in.
 */
add_task(async function test_message_pane_persistence_generally_works() {
  await be_in_folder(folder);

  let tabmail = mc.window.document.getElementById("tabmail");

  // helper to open tabs with the folder pane in the desired states (1 for
  //  visible, 0 for hidden)
  async function openTabs(aConfig) {
    for (let [iTab, messagePaneVisible] of aConfig.entries()) {
      if (iTab != 0) {
        await open_folder_in_new_tab(folder);
      }
      if (
        tabmail.currentAbout3Pane.paneLayout.messagePaneVisible !=
        messagePaneVisible
      ) {
        toggle_message_pane();
      }
    }
  }

  // close everything but the first tab.
  function closeTabs() {
    while (tabmail.tabInfo.length > 1) {
      close_tab(1);
    }
  }

  async function verifyTabs(aConfig) {
    for (let [iTab, messagePaneVisible] of aConfig.entries()) {
      info("tab " + iTab);

      await switch_tab(iTab);
      if (tabmail.currentAbout3Pane.document.readyState != "complete") {
        await BrowserTestUtils.waitForEvent(tabmail.currentAbout3Pane, "load");
        await new Promise(resolve =>
          tabmail.currentAbout3Pane.setTimeout(resolve)
        );
      }

      if (messagePaneVisible) {
        assert_message_pane_visible();
      } else {
        assert_message_pane_hidden();
      }
    }
  }

  let configs = [
    // 1st time: [+ - - + +]
    [1, 0, 0, 1, 1],
    // 2nd time: [- + + - -]
    [0, 1, 1, 0, 0],
  ];
  for (let config of configs) {
    await openTabs(config);
    await verifyTabs(config); // make sure openTabs did its job right
    let state = tabmail.persistTabs();
    closeTabs();

    Assert.equal(state.tabs[0].state.messagePaneVisible, config[0]);
    Assert.equal(state.tabs[1].state.messagePaneVisible, config[1]);
    Assert.equal(state.tabs[2].state.messagePaneVisible, config[2]);
    Assert.equal(state.tabs[3].state.messagePaneVisible, config[3]);
    Assert.equal(state.tabs[4].state.messagePaneVisible, config[4]);

    // toggle the state for the current tab so we can be sure that it knows how
    //  to change things.
    toggle_message_pane();

    tabmail.restoreTabs(state);
    await verifyTabs(config);
    closeTabs();

    // toggle the first tab again.  This sets - properly for the second pass and
    //  restores it to + for when we are done.
    toggle_message_pane();
  }

  Assert.ok(
    true,
    "test_message_pane_persistence_generally_works ran to completion"
  );
});