summaryrefslogtreecommitdiffstats
path: root/comm/mail/test/browser/message-header/browser_messageHeaderCustomize.js
blob: 67ca41258740e5281620c8eec460d75b8827f170 (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
/* 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 the message header customization features.
 */
var {
  add_message_to_folder,
  assert_selected_and_displayed,
  be_in_folder,
  close_popup,
  create_folder,
  create_message,
  gDefaultWindowHeight,
  get_smart_folder_named,
  get_about_3pane,
  get_about_message,
  inboxFolder,
  mc,
  msgGen,
  restore_default_window_size,
  select_click_row,
  select_none,
  wait_for_message_display_completion,
  wait_for_popup_to_open,
} = ChromeUtils.import(
  "resource://testing-common/mozmill/FolderDisplayHelpers.jsm"
);

let about3Pane = get_about_3pane();
let aboutMessage = get_about_message();

var { MailTelemetryForTests } = ChromeUtils.import(
  "resource:///modules/MailGlue.jsm"
);
var { TelemetryTestUtils } = ChromeUtils.importESModule(
  "resource://testing-common/TelemetryTestUtils.sys.mjs"
);

var gFolder;

add_setup(async function () {
  Services.xulStore.removeDocument(
    "chrome://messenger/content/messenger.xhtml"
  );
  Services.telemetry.clearScalars();

  let account = createAccount();
  gFolder = await createSubfolder(account.incomingServer.rootFolder, "test0");
  createMessages(gFolder, 1);

  registerCleanupFunction(() => {
    gFolder.deleteSelf(null);
    MailServices.accounts.removeAccount(account, true);
    Services.xulStore.removeDocument(
      "chrome://messenger/content/messenger.xhtml"
    );
  });
});

add_task(async function test_customize_toolbar_buttons() {
  be_in_folder(gFolder);
  select_click_row(0);

  let moreBtn = aboutMessage.document.getElementById("otherActionsButton");
  // Make sure we loaded the expected message.
  await assertVisibility(moreBtn, true, "The more button is visible");

  // Confirm we're starting from a clean state.
  let header = aboutMessage.document.getElementById("messageHeader");
  Assert.ok(
    header.classList.contains("message-header-show-recipient-avatar"),
    "The From recipient is showing the avatar"
  );
  let avatar = aboutMessage.document.querySelector(".recipient-avatar");
  await assertVisibility(avatar, true, "The recipient avatar is shown");

  Assert.ok(
    header.classList.contains("message-header-show-sender-full-address"),
    "The From recipient is showing the full address on two lines"
  );
  let multiLine = aboutMessage.document.querySelector(".recipient-multi-line");
  await assertVisibility(
    multiLine,
    true,
    "The recipient multi line is visible"
  );
  let singleLine = aboutMessage.document.querySelector(
    ".recipient-single-line"
  );
  await assertVisibility(
    singleLine,
    false,
    "he recipient single line is hidden"
  );

  Assert.ok(
    header.classList.contains("message-header-hide-label-column"),
    "The labels column is hidden"
  );

  let firstLabel = aboutMessage.document.querySelector(".message-header-label");
  Assert.equal(
    firstLabel.style.minWidth,
    "0px",
    "The first label has no min-width value"
  );
  await assertVisibility(firstLabel, false, "The labels column is hidden");

  Assert.ok(
    header.classList.contains("message-header-large-subject"),
    "The message header has a large subject"
  );
  Assert.ok(
    !header.classList.contains("message-header-buttons-only-icons"),
    "The message header buttons aren't showing only icons"
  );
  Assert.ok(
    !header.classList.contains("message-header-buttons-only-text"),
    "The message header buttons aren't showing only text"
  );

  MailTelemetryForTests.reportUIConfiguration();
  let scalarName = "tb.ui.configuration.message_header";
  let scalars = TelemetryTestUtils.getProcessScalars("parent", true);
  TelemetryTestUtils.assertScalarUnset(scalars, scalarName);

  let popup = aboutMessage.document.getElementById("otherActionsPopup");
  let popupShown = BrowserTestUtils.waitForEvent(popup, "popupshown");
  EventUtils.synthesizeMouseAtCenter(moreBtn, {}, aboutMessage);
  await popupShown;

  let panel = aboutMessage.document.getElementById(
    "messageHeaderCustomizationPanel"
  );
  let customizeBtn = aboutMessage.document.getElementById(
    "messageHeaderMoreMenuCustomize"
  );
  let panelShown = BrowserTestUtils.waitForEvent(panel, "popupshown");
  EventUtils.synthesizeMouseAtCenter(customizeBtn, {}, aboutMessage);
  await panelShown;

  let buttonStyle = aboutMessage.document.getElementById("headerButtonStyle");
  // Assert the options are in a default state.
  Assert.equal(
    buttonStyle.value,
    "default",
    "The buttons style is in the default state"
  );
  let subjectLarge = aboutMessage.document.getElementById("headerSubjectLarge");
  Assert.ok(subjectLarge.checked, "The subject field is in the default state");

  let showAvatar = aboutMessage.document.getElementById("headerShowAvatar");
  Assert.ok(
    showAvatar.checked,
    "The show avatar field is in the default state"
  );

  let showFullAddress = aboutMessage.document.getElementById(
    "headerShowFullAddress"
  );
  Assert.ok(
    showFullAddress.checked,
    "The show full address field is in the default state"
  );

  let hideLabels = aboutMessage.document.getElementById("headerHideLabels");
  Assert.ok(
    hideLabels.checked,
    "The hide labels field is in the default state"
  );

  let openMenuPopup = async function () {
    aboutMessage.document.getElementById("headerButtonStyle").focus();

    let menuPopupShown = BrowserTestUtils.waitForEvent(
      aboutMessage.document.querySelector("#headerButtonStyle menupopup"),
      "popupshown"
    );
    // Use the keyboard to open and cycle through the menulist items because the
    // mouse events are unreliable in tests.
    EventUtils.synthesizeMouseAtCenter(
      aboutMessage.document.getElementById("headerButtonStyle"),
      {},
      aboutMessage
    );
    await menuPopupShown;
  };

  // Cycle through the buttons style and confirm the style is properly applied.
  // Use the keyboard to open and cycle through the menulist items because the
  // mouse events are unreliable in tests.
  await openMenuPopup();
  EventUtils.sendKey("down", aboutMessage);
  EventUtils.sendKey("return", aboutMessage);

  await BrowserTestUtils.waitForCondition(
    () => header.classList.contains("message-header-buttons-only-text"),
    "The buttons are showing only text"
  );
  Assert.ok(
    header.classList.contains("message-header-large-subject"),
    "The subject line wasn't changed"
  );
  Assert.ok(
    header.classList.contains("message-header-show-recipient-avatar"),
    "The avatar visibility wasn't changed"
  );
  Assert.ok(
    header.classList.contains("message-header-show-sender-full-address"),
    "The full address visibility wasn't changed"
  );
  Assert.ok(
    header.classList.contains("message-header-hide-label-column"),
    "The labels column visibility wasn't changed"
  );

  await openMenuPopup();
  EventUtils.sendKey("down", aboutMessage);
  EventUtils.sendKey("return", aboutMessage);
  await BrowserTestUtils.waitForCondition(
    () => header.classList.contains("message-header-buttons-only-icons"),
    "The buttons are showing only icons"
  );
  Assert.ok(
    header.classList.contains("message-header-large-subject"),
    "The subject line wasn't changed"
  );

  await openMenuPopup();
  EventUtils.sendKey("up", aboutMessage);
  EventUtils.sendKey("up", aboutMessage);
  EventUtils.sendKey("return", aboutMessage);
  await BrowserTestUtils.waitForCondition(
    () =>
      !header.classList.contains("message-header-buttons-only-icons") &&
      !header.classList.contains("message-header-buttons-only-text") &&
      header.classList.contains("message-header-large-subject") &&
      header.classList.contains("message-header-show-recipient-avatar") &&
      header.classList.contains("message-header-show-sender-full-address") &&
      header.classList.contains("message-header-hide-label-column"),
    "The message header is clear of any custom style"
  );

  EventUtils.synthesizeMouseAtCenter(subjectLarge, {}, aboutMessage);
  await BrowserTestUtils.waitForCondition(
    () => !header.classList.contains("message-header-large-subject"),
    "The subject line was changed"
  );

  EventUtils.synthesizeMouseAtCenter(showAvatar, {}, aboutMessage);
  await BrowserTestUtils.waitForCondition(
    () => !header.classList.contains("message-header-show-recipient-avatar"),
    "The avatar style was changed"
  );
  await assertVisibility(avatar, false, "The recipient avatar is hidden");

  EventUtils.synthesizeMouseAtCenter(showFullAddress, {}, aboutMessage);
  await BrowserTestUtils.waitForCondition(
    () => !header.classList.contains("message-header-show-sender-full-address"),
    "The full address style was changed"
  );
  await assertVisibility(
    multiLine,
    false,
    "The recipient multi line is hidden"
  );
  await assertVisibility(
    singleLine,
    true,
    "The recipient single line is visible"
  );

  EventUtils.synthesizeMouseAtCenter(hideLabels, {}, aboutMessage);
  await BrowserTestUtils.waitForCondition(
    () => !header.classList.contains("message-header-hide-label-column"),
    "The labels column style was changed"
  );
  await assertVisibility(firstLabel, true, "The first label is visible");
  await BrowserTestUtils.waitForCondition(
    () => firstLabel.style.minWidth != "0px",
    "The first label has a min-width value"
  );

  await openMenuPopup();
  EventUtils.sendKey("down", aboutMessage);
  EventUtils.sendKey("down", aboutMessage);
  EventUtils.sendKey("return", aboutMessage);
  await BrowserTestUtils.waitForCondition(
    () => header.classList.contains("message-header-buttons-only-icons"),
    "The buttons are showing only icons"
  );
  await BrowserTestUtils.waitForCondition(
    () => !header.classList.contains("message-header-large-subject"),
    "The subject line edit was maintained"
  );

  let panelHidden = BrowserTestUtils.waitForEvent(panel, "popuphidden");
  EventUtils.synthesizeKey("VK_ESCAPE", {}, aboutMessage);
  await panelHidden;

  await BrowserTestUtils.waitForCondition(
    () =>
      Services.xulStore.hasValue(
        "chrome://messenger/content/messenger.xhtml",
        "messageHeader",
        "layout"
      ),
    "The customization data was saved"
  );

  MailTelemetryForTests.reportUIConfiguration();
  scalars = TelemetryTestUtils.getProcessScalars("parent", true);
  TelemetryTestUtils.assertKeyedScalar(scalars, scalarName, "subjectLarge", 0);
  TelemetryTestUtils.assertKeyedScalar(scalars, scalarName, "buttonStyle", 1);
  TelemetryTestUtils.assertKeyedScalar(scalars, scalarName, "hideLabels", 0);
  TelemetryTestUtils.assertKeyedScalar(scalars, scalarName, "showAvatar", 0);
  TelemetryTestUtils.assertKeyedScalar(
    scalars,
    scalarName,
    "showFullAddress",
    0
  );

  popupShown = BrowserTestUtils.waitForEvent(popup, "popupshown");
  EventUtils.synthesizeMouseAtCenter(moreBtn, {}, aboutMessage);
  await popupShown;

  panelShown = BrowserTestUtils.waitForEvent(panel, "popupshown");
  EventUtils.synthesizeMouseAtCenter(customizeBtn, {}, aboutMessage);
  await panelShown;

  await openMenuPopup();
  EventUtils.sendKey("up", aboutMessage);
  EventUtils.sendKey("up", aboutMessage);
  EventUtils.sendKey("return", aboutMessage);

  await BrowserTestUtils.waitForCondition(
    () =>
      !header.classList.contains("message-header-buttons-only-icons") &&
      !header.classList.contains("message-header-buttons-only-text"),
    "The buttons style was reverted to the default"
  );

  EventUtils.synthesizeMouseAtCenter(subjectLarge, {}, aboutMessage);
  EventUtils.synthesizeMouseAtCenter(showAvatar, {}, aboutMessage);
  EventUtils.synthesizeMouseAtCenter(showFullAddress, {}, aboutMessage);
  EventUtils.synthesizeMouseAtCenter(hideLabels, {}, aboutMessage);

  panelHidden = BrowserTestUtils.waitForEvent(panel, "popuphidden");
  EventUtils.synthesizeKey("VK_ESCAPE", {}, aboutMessage);
  await panelHidden;

  await BrowserTestUtils.waitForCondition(
    () => header.classList.contains("message-header-large-subject"),
    "The subject line is large again"
  );
  await assertVisibility(avatar, true, "The recipient avatar is visible");
  await assertVisibility(
    multiLine,
    true,
    "The recipient multi line is visible"
  );
  await assertVisibility(
    singleLine,
    false,
    "he recipient single line is hidden"
  );
  await BrowserTestUtils.waitForCondition(
    () => firstLabel.style.minWidth == "0px",
    "The first label has no min-width value"
  );
  await assertVisibility(firstLabel, false, "The labels column is hidden");

  MailTelemetryForTests.reportUIConfiguration();
  scalars = TelemetryTestUtils.getProcessScalars("parent", true);
  TelemetryTestUtils.assertKeyedScalar(scalars, scalarName, "subjectLarge", 1);
  TelemetryTestUtils.assertKeyedScalar(scalars, scalarName, "buttonStyle", 0);
  TelemetryTestUtils.assertKeyedScalar(scalars, scalarName, "hideLabels", 1);
  TelemetryTestUtils.assertKeyedScalar(scalars, scalarName, "showAvatar", 1);
  TelemetryTestUtils.assertKeyedScalar(
    scalars,
    scalarName,
    "showFullAddress",
    1
  );
});