summaryrefslogtreecommitdiffstats
path: root/comm/mail/test/browser/newmailaccount/browser_newmailaccount.js
blob: a3fab8d4f3349b99c9e382d2bfee1984e141c95e (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
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
/* 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/. */

/**
 * Tests the new account provisioner workflow.
 */

"use strict";

var { MailServices } = ChromeUtils.import(
  "resource:///modules/MailServices.jsm"
);
var { gMockPromptService } = ChromeUtils.import(
  "resource://testing-common/mozmill/PromptHelpers.jsm"
);
var { wait_for_content_tab_load } = ChromeUtils.import(
  "resource://testing-common/mozmill/ContentTabHelpers.jsm"
);
var { mc } = ChromeUtils.import(
  "resource://testing-common/mozmill/FolderDisplayHelpers.jsm"
);
var { remove_email_account } = ChromeUtils.import(
  "resource://testing-common/mozmill/NewMailAccountHelpers.jsm"
);
var { openAccountProvisioner, openAccountSetup } = ChromeUtils.import(
  "resource://testing-common/mozmill/AccountManagerHelpers.jsm"
);
var { input_value } = ChromeUtils.import(
  "resource://testing-common/mozmill/KeyboardHelpers.jsm"
);
let { TelemetryTestUtils } = ChromeUtils.importESModule(
  "resource://testing-common/TelemetryTestUtils.sys.mjs"
);
var { click_through_appmenu, click_menus_in_sequence } = ChromeUtils.import(
  "resource://testing-common/mozmill/WindowHelpers.jsm"
);

// RELATIVE_ROOT messes with the collector, so we have to bring the path back
// so we get the right path for the resources.
var url =
  "http://mochi.test:8888/browser/comm/mail/test/browser/newmailaccount/html/";
var kProvisionerUrl =
  "chrome://messenger/content/newmailaccount/accountProvisioner.xhtml";
var kProvisionerEnabledPref = "mail.provider.enabled";
var kSuggestFromNamePref = "mail.provider.suggestFromName";
var kProviderListPref = "mail.provider.providerList";
var kDefaultServerPort = 4444;
var kDefaultServerRoot = "http://localhost:" + kDefaultServerPort;
var gDefaultEngine;

Services.prefs.setCharPref(kProviderListPref, url + "providerList");
Services.prefs.setCharPref(kSuggestFromNamePref, url + "suggestFromName");

// Here's a name that we'll type in later on. It's a global const because
// we'll be using it in several distinct modal dialog event loops.
var NAME = "Green Llama";

// Record what the original value of the mail.provider.enabled pref is so
// that we can put it back once the tests are done.
var gProvisionerEnabled = Services.prefs.getBoolPref(kProvisionerEnabledPref);
var gOldAcceptLangs = Services.locale.requestedLocales;
var gNumAccounts;

add_setup(async function () {
  requestLongerTimeout(2);

  // Make sure we enable the Account Provisioner.
  Services.prefs.setBoolPref(kProvisionerEnabledPref, true);
  // Restrict the user's language to just en-US
  Services.locale.requestedLocales = ["en-US"];
});

registerCleanupFunction(async function () {
  // Put the mail.provider.enabled pref back the way it was.
  Services.prefs.setBoolPref(kProvisionerEnabledPref, gProvisionerEnabled);
  // And same with the user languages
  Services.locale.requestedLocales = gOldAcceptLangs;

  // Some tests that open new windows don't return focus to the main window
  // in a way that satisfies mochitest, and the test times out.
  Services.focus.focusedWindow = window;
});

/**
 * Helper function that returns the number of accounts associated with the
 * current profile.
 */
function nAccounts() {
  return MailServices.accounts.accounts.length;
}

/**
 * Helper function to wait for the load of the account providers.
 *
 * @param {object} tab - The opened account provisioner tab.
 */
async function waitForLoadedProviders(tab) {
  let gProvisioner = await TestUtils.waitForCondition(
    () => tab.browser.contentWindow.gAccountProvisioner
  );

  // We got the correct amount of email and domain providers.
  await BrowserTestUtils.waitForCondition(
    () => gProvisioner.mailProviders.length == 4,
    "Correctly loaded 4 email providers"
  );
  await BrowserTestUtils.waitForCondition(
    () => gProvisioner.domainProviders.length == 3,
    "Correctly loaded 3 domain providers"
  );
}

/**
 * Test a full account creation with an email provider.
 */
add_task(async function test_account_creation_from_provisioner() {
  Services.telemetry.clearScalars();

  let tab = await openAccountProvisioner();
  let tabDocument = tab.browser.contentWindow.document;

  let mailInput = tabDocument.getElementById("mailName");
  // The focus is on the email input.
  await BrowserTestUtils.waitForCondition(
    () => tabDocument.activeElement == mailInput,
    "The mailForm input field has the focus"
  );

  await waitForLoadedProviders(tab);

  let scalars = TelemetryTestUtils.getProcessScalars("parent");
  Assert.equal(
    scalars["tb.account.opened_account_provisioner"],
    1,
    "Count of opened account provisioner must be correct"
  );

  // The application will prefill these fields with the account name, if present
  // so we need to select it before typing the new name to avoid mismatch in the
  // expected strings during testing.
  mailInput.select();
  // Fill the email input.
  input_value(mc, NAME);
  // Since we're focused inside a form, pressing "Enter" should submit it.
  EventUtils.synthesizeKey("VK_RETURN", {}, mc.window);

  let mailResults = tabDocument.getElementById("mailResultsArea");

  // Wait for the results to be loaded.
  await BrowserTestUtils.waitForCondition(
    () => mailResults.hasChildNodes(),
    "Mail results loaded"
  );
  // We should have a total of 15 addresses.
  await BrowserTestUtils.waitForCondition(
    () => mailResults.querySelectorAll(".result-item").length == 14,
    "All suggested emails were correctly loaded"
  );

  // The domain section should be hidden and the buttons should be updated.
  Assert.ok(
    tabDocument.getElementById("domainSearch").hidden &&
      !tabDocument.getElementById("mailSearchResults").hidden &&
      tabDocument.getElementById("cancelButton").hidden &&
      tabDocument.getElementById("existingButton").hidden &&
      !tabDocument.getElementById("backButton").hidden
  );

  // Go back and fill the domain input.
  let backButton = tabDocument.getElementById("backButton");
  backButton.scrollIntoView();
  EventUtils.synthesizeMouseAtCenter(backButton, {}, tab.browser.contentWindow);

  Assert.ok(tabDocument.getElementById("mailSearchResults").hidden);

  let domainName = tabDocument.getElementById("domainName");
  domainName.focus();
  domainName.select();
  // Fill the domain input.
  input_value(mc, NAME);
  // Since we're focused inside a form, pressing "Enter" should submit it.
  EventUtils.synthesizeKey("VK_RETURN", {}, mc.window);

  let domainResults = tabDocument.getElementById("domainResultsArea");
  // Wait for the results to be loaded.
  await BrowserTestUtils.waitForCondition(
    () => domainResults.hasChildNodes(),
    "Domain results loaded"
  );
  // We should have a total of 15 addresses.
  await BrowserTestUtils.waitForCondition(
    () => domainResults.querySelectorAll(".result-item").length == 14,
    "All suggested emails and domains were correctly loaded"
  );

  // The domain section should be hidden and the buttons should be updated.
  Assert.ok(
    !tabDocument.getElementById("domainSearch").hidden &&
      tabDocument.getElementById("mailSearchResults").hidden &&
      tabDocument.getElementById("cancelButton").hidden &&
      tabDocument.getElementById("existingButton").hidden &&
      !tabDocument.getElementById("backButton").hidden
  );

  // Go back and confirm both input fields maintained their values.
  backButton.scrollIntoView();
  EventUtils.synthesizeMouseAtCenter(backButton, {}, tab.browser.contentWindow);

  Assert.ok(
    tabDocument.getElementById("domainSearchResults").hidden &&
      tabDocument.getElementById("mailName").value == NAME &&
      tabDocument.getElementById("domainName").value == NAME
  );

  // Continue with the email form.
  tabDocument.getElementById("mailName").focus();
  EventUtils.synthesizeKey("VK_RETURN", {}, mc.window);

  // Wait for the results to be loaded.
  await BrowserTestUtils.waitForCondition(
    () => mailResults.hasChildNodes(),
    "Mail results loaded"
  );
  // We should have a total of 15 addresses.
  await BrowserTestUtils.waitForCondition(
    () => mailResults.querySelectorAll(".result-item").length == 14,
    "All suggested emails were correctly loaded"
  );

  // Select the first button with a price from the results list by pressing Tab
  // twice to move the focus on the first available price button.
  EventUtils.synthesizeKey("VK_TAB", {}, mc.window);
  EventUtils.synthesizeKey("VK_TAB", {}, mc.window);
  await BrowserTestUtils.waitForCondition(
    () =>
      tabDocument.activeElement ==
      mailResults.querySelector(".result-item > button"),
    "The first result button was focused"
  );
  EventUtils.synthesizeKey("VK_RETURN", {}, mc.window);

  // A special tab with the provisioner's API url should be loaded.
  wait_for_content_tab_load(undefined, function (aURL) {
    return aURL.schemeIs("http") && aURL.host == "mochi.test";
  });

  scalars = TelemetryTestUtils.getProcessScalars("parent", true);
  Assert.equal(
    scalars["tb.account.selected_account_from_provisioner"]["mochi.test"],
    1,
    "Count of selected email addresses from provisioner must be correct"
  );

  // Close the account provisioner tab, and then restore it.
  mc.window.document
    .getElementById("tabmail")
    .closeTab(mc.window.document.getElementById("tabmail").currentTabInfo);
  mc.window.document.getElementById("tabmail").undoCloseTab();
  // Wait for the page to be loaded again...
  wait_for_content_tab_load(undefined, function (aURL) {
    return aURL.schemeIs("http") && aURL.host == "mochi.test";
  });
  tab = mc.window.document.getElementById("tabmail").currentTabInfo;

  // Record how many accounts we start with.
  gNumAccounts = MailServices.accounts.accounts.length;

  // Simulate the purchase of an email account.
  BrowserTestUtils.synthesizeMouseAtCenter(
    "input[value=Send]",
    {},
    tab.browser
  );

  // The account setup tab should be open and selected.
  await BrowserTestUtils.waitForCondition(
    () =>
      mc.window.document.getElementById("tabmail").selectedTab.browser
        ?.currentURI?.spec == "about:accountsetup",
    "The Account Setup Tab was opened"
  );
  // A new account should have been created.
  Assert.equal(
    gNumAccounts + 1,
    MailServices.accounts.accounts.length,
    "New account successfully created"
  );

  await BrowserTestUtils.waitForCondition(
    () =>
      mc.window.document.getElementById("tabmail").selectedTab.browser
        ?.contentWindow.gAccountSetup?._currentModename == "success",
    "The success view was shown"
  );

  scalars = TelemetryTestUtils.getProcessScalars("parent", true);
  Assert.equal(
    scalars["tb.account.new_account_from_provisioner"]["mochi.test"],
    1,
    "Count of created accounts from provisioner must be correct"
  );

  // Clean it up.
  remove_email_account("green@example.com");
  // Close the account setup tab.
  mc.window.document
    .getElementById("tabmail")
    .closeTab(mc.window.document.getElementById("tabmail").currentTabInfo);
});

/**
 * Test the opening and closing workflow between account setup and provisioner.
 */
add_task(async function test_switch_between_account_provisioner_and_setup() {
  let tab = await openAccountProvisioner();
  let tabDocument = tab.browser.contentWindow.document;

  await waitForLoadedProviders(tab);

  // Close the tab.
  let closeButton = tabDocument.getElementById("cancelButton");
  closeButton.scrollIntoView();
  EventUtils.synthesizeMouseAtCenter(
    closeButton,
    {},
    tab.browser.contentWindow
  );

  // The account setup tab should NOT be opened.
  await BrowserTestUtils.waitForCondition(
    () =>
      mc.window.document.getElementById("tabmail").selectedTab.browser
        ?.currentURI?.spec != "about:accountsetup",
    "The Account Setup Tab was not opened"
  );

  tab = await openAccountProvisioner();
  tabDocument = tab.browser.contentWindow.document;

  await waitForLoadedProviders(
    mc.window.document.getElementById("tabmail").currentTabInfo
  );

  // Click on the "Use existing account" button.
  let existingAccountButton = tabDocument.getElementById("existingButton");
  existingAccountButton.scrollIntoView();
  EventUtils.synthesizeMouseAtCenter(
    existingAccountButton,
    {},
    tab.browser.contentWindow
  );

  // The account setup tab should be open and selected.
  await BrowserTestUtils.waitForCondition(
    () =>
      mc.window.document.getElementById("tabmail").selectedTab.browser
        ?.currentURI?.spec == "about:accountsetup",
    "The Account Setup Tab was opened"
  );

  // Close the account setup tab.
  mc.window.document
    .getElementById("tabmail")
    .closeTab(mc.window.document.getElementById("tabmail").currentTabInfo);
});

/**
 * Test opening the account provisioner from the menu bar.
 */
add_task(async function open_provisioner_from_menu_bar() {
  // Show menubar so we can click it.
  document.getElementById("toolbar-menubar").removeAttribute("autohide");

  EventUtils.synthesizeMouseAtCenter(
    mc.window.document.getElementById("menu_File"),
    {},
    mc.window
  );
  await click_menus_in_sequence(
    mc.window.document.getElementById("menu_FilePopup"),
    [{ id: "menu_New" }, { id: "newCreateEmailAccountMenuItem" }]
  );

  // The account Provisioner tab should be open and selected.
  await BrowserTestUtils.waitForCondition(
    () =>
      mc.window.document.getElementById("tabmail").selectedTab.browser
        ?.currentURI?.spec == "about:accountprovisioner",
    "The Account Provisioner Tab was opened"
  );
  await waitForLoadedProviders(
    mc.window.document.getElementById("tabmail").currentTabInfo
  );

  // Close the account provisioner tab.
  mc.window.document
    .getElementById("tabmail")
    .closeTab(mc.window.document.getElementById("tabmail").currentTabInfo);
}).__skipMe = AppConstants.platform == "macosx"; // Can't click menu bar on Mac.

/**
 * Test opening the account provisioner from the main app menu.
 */
add_task(async function open_provisioner_from_app_menu() {
  EventUtils.synthesizeMouseAtCenter(
    mc.window.document.getElementById("button-appmenu"),
    {},
    mc.window
  );
  click_through_appmenu(
    [{ id: "appmenu_new" }],
    {
      id: "appmenu_newCreateEmailAccountMenuItem",
    },
    mc.window
  );

  // The account Provisioner tab should be open and selected.
  await BrowserTestUtils.waitForCondition(
    () =>
      mc.window.document.getElementById("tabmail").selectedTab.browser
        ?.currentURI?.spec == "about:accountprovisioner",
    "The Account Provisioner Tab was opened"
  );
  await waitForLoadedProviders(
    mc.window.document.getElementById("tabmail").currentTabInfo
  );

  // Close the account provisioner tab.
  mc.window.document
    .getElementById("tabmail")
    .closeTab(mc.window.document.getElementById("tabmail").currentTabInfo);
}).skip();

/**
 * Test that names with HTML characters are escaped properly when displayed back
 * to the user.
 */
add_task(async function test_html_characters_and_ampersands() {
  let tab = await openAccountProvisioner();
  let tabDocument = tab.browser.contentWindow.document;

  await waitForLoadedProviders(tab);

  // Type a name with some HTML tags and an ampersand in there to see if we can
  // trip up account provisioner.
  const CLEVER_STRING =
    "<i>Hey, I'm ''clever &\"\" smart!<!-- Ain't I a stinkah? --></i>";

  // Fill the email input.
  input_value(mc, CLEVER_STRING);
  // Since we're focused inside a form, pressing "Enter" should submit it.
  EventUtils.synthesizeKey("VK_RETURN", {}, mc.window);

  let mailResults = tabDocument.getElementById("mailResultsArea");

  // Wait for the results to be loaded.
  await BrowserTestUtils.waitForCondition(
    () => mailResults.hasChildNodes(),
    "Mail results loaded"
  );

  let searchedTerms =
    tabDocument.getElementById("mailResultsTitle").textContent;
  Assert.notEqual(
    `One available address found for: "${CLEVER_STRING}"`,
    searchedTerms
  );

  // & should have been replaced with &amp;, and the greater than / less than
  // characters with &gt; and &lt; respectively.
  Assert.ok(
    searchedTerms.includes("&amp;"),
    "Should have eliminated ampersands"
  );
  Assert.ok(
    searchedTerms.includes("&gt;"),
    "Should have eliminated greater-than signs"
  );
  Assert.ok(
    searchedTerms.includes("&lt;"),
    "Should have eliminated less-than signs"
  );

  // Close the account provisioner tab.
  mc.window.document
    .getElementById("tabmail")
    .closeTab(mc.window.document.getElementById("tabmail").currentTabInfo);
});

/**
 * Test that if the search goes bad on the server-side we show an error.
 */
add_task(async function test_shows_error_on_bad_suggest_from_name() {
  let original = Services.prefs.getCharPref(kSuggestFromNamePref);
  Services.prefs.setCharPref(kSuggestFromNamePref, url + "badSuggestFromName");

  let tab = await openAccountProvisioner();

  await waitForLoadedProviders(tab);

  let notificationBox =
    tab.browser.contentWindow.gAccountProvisioner.notificationBox;

  let notificationShowed = BrowserTestUtils.waitForCondition(
    () =>
      notificationBox.getNotificationWithValue("accountProvisionerError") !=
      null,
    "Timeout waiting for error notification to be showed"
  );

  // Fill the email input.
  input_value(mc, "Boston Low");
  // Since we're focused inside a form, pressing "Enter" should submit it.
  EventUtils.synthesizeKey("VK_RETURN", {}, mc.window);

  // Wait for the error notification.
  await notificationShowed;

  // Close the account provisioner tab.
  mc.window.document
    .getElementById("tabmail")
    .closeTab(mc.window.document.getElementById("tabmail").currentTabInfo);
  Services.prefs.setCharPref(kSuggestFromNamePref, original);
});

/**
 * Tests that if a provider returns broken or erroneous XML back to the user
 * after account registration, we show an alert dialog.
 */
add_task(async function test_error_on_corrupt_XML() {
  // Register the prompt service to handle the alert() dialog.
  gMockPromptService.register();

  let tab = await openAccountProvisioner();
  let tabDocument = tab.browser.contentWindow.document;

  // Record how many accounts we start with.
  gNumAccounts = nAccounts();

  await waitForLoadedProviders(tab);

  // Fill the email input.
  input_value(mc, "corrupt@corrupt.invalid");
  // Since we're focused inside a form, pressing "Enter" should submit it.
  EventUtils.synthesizeKey("VK_RETURN", {}, mc.window);

  let mailResults = tabDocument.getElementById("mailResultsArea");

  // Wait for the results to be loaded.
  await BrowserTestUtils.waitForCondition(
    () => mailResults.hasChildNodes(),
    "Mail results loaded"
  );
  // We should have a total of 15 addresses.
  await BrowserTestUtils.waitForCondition(
    () => mailResults.querySelectorAll(".result-item").length == 14,
    "All suggested emails were correctly loaded"
  );

  let priceButton = tabDocument.querySelector(
    `.result-item[data-label="corrupt@corrupt.invalid"] .result-price`
  );
  priceButton.scrollIntoView();

  EventUtils.synthesizeMouseAtCenter(
    priceButton,
    {},
    tab.browser.contentWindow
  );

  // A special tab with the provisioner's API url should be loaded.
  wait_for_content_tab_load(undefined, function (aURL) {
    return aURL.schemeIs("http") && aURL.host == "mochi.test";
  });
  tab = mc.window.document.getElementById("tabmail").currentTabInfo;

  gMockPromptService.returnValue = true;

  // Simulate the purchase of an email account.
  BrowserTestUtils.synthesizeMouseAtCenter(
    "input[value=Send]",
    {},
    tab.browser
  );
  await BrowserTestUtils.waitForCondition(
    () =>
      mc.window.document.getElementById("tabmail").selectedTab.browser
        ?.currentURI?.spec == "about:accountprovisioner",
    "The Account Provisioner Tab was opened"
  );

  let promptState = gMockPromptService.promptState;
  Assert.equal("alert", promptState.method, "An alert was showed");

  Assert.equal(gNumAccounts, nAccounts(), "No new accounts have been created");

  // Clean up
  gMockPromptService.unregister();

  // Close the account setup tab.
  mc.window.document.getElementById("tabmail").closeTab(tab);
  mc.window.document
    .getElementById("tabmail")
    .closeTab(mc.window.document.getElementById("tabmail").currentTabInfo);
});

/**
 * Tests that when we pref off the Account Provisioner, the menuitem for it
 * becomes hidden, and the button to switch to it from the Existing Account
 * wizard also becomes hidden.  Note that this doesn't test explicitly
 * whether or not the Account Provisioner spawns when there are no accounts.
 * The tests in this file will fail if the Account Provisioner does not spawn
 * with no accounts, and when preffed off, if the Account Provisioner does
 * spawn (which it shouldn't), the instrumentation Mozmill test should fail.
 */
add_task(async function test_can_pref_off_account_provisioner() {
  // First, we'll disable the account provisioner.
  Services.prefs.setBoolPref("mail.provider.enabled", false);

  // Show menubar so we can click it.
  document.getElementById("toolbar-menubar").removeAttribute("autohide");

  EventUtils.synthesizeMouseAtCenter(
    mc.window.document.getElementById("menu_File"),
    {},
    mc.window
  );
  await click_menus_in_sequence(
    mc.window.document.getElementById("menu_FilePopup"),
    [{ id: "menu_New" }]
  );

  // Ensure that the "Get a new mail account" menuitem is no longer available.
  Assert.ok(
    mc.window.document.getElementById("newCreateEmailAccountMenuItem").hidden,
    "new account menu should be hidden"
  );

  // Close all existing tabs except the first mail tab to avoid errors.
  mc.window.document
    .getElementById("tabmail")
    .closeOtherTabs(mc.window.document.getElementById("tabmail").tabInfo[0]);

  // Open up the Account Hub.
  let tab = await openAccountSetup();
  // And make sure the Get a New Account button is hidden.
  Assert.ok(
    tab.browser.contentWindow.document.getElementById("provisionerButton")
      .hidden
  );
  // Close the Account Hub tab.
  mc.window.document.getElementById("tabmail").closeTab(tab);

  // Ok, now pref the Account Provisioner back on
  Services.prefs.setBoolPref("mail.provider.enabled", true);

  EventUtils.synthesizeMouseAtCenter(
    mc.window.document.getElementById("menu_File"),
    {},
    mc.window
  );
  await click_menus_in_sequence(
    mc.window.document.getElementById("menu_FilePopup"),
    [{ id: "menu_New" }]
  );
  Assert.ok(
    !mc.window.document.getElementById("newCreateEmailAccountMenuItem").hidden,
    "new account menu should show"
  );

  // Open up the Account Hub.
  tab = await openAccountSetup();
  // And make sure the Get a New Account button is hidden.
  Assert.ok(
    !tab.browser.contentWindow.document.getElementById("provisionerButton")
      .hidden
  );
  // Close the Account Hub tab.
  mc.window.document.getElementById("tabmail").closeTab(tab);
}).__skipMe = AppConstants.platform == "macosx"; // Can't click menu bar on Mac.