summaryrefslogtreecommitdiffstats
path: root/browser/components/migration/tests/browser/browser_dialog_cancel_close.js
blob: 87f27cdb8d962c51f429a7a6949117f733f48528 (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
/* Any copyright is dedicated to the Public Domain.
   http://creativecommons.org/publicdomain/zero/1.0/ */

"use strict";

/**
 * Tests that pressing "Cancel" from the selection page of the migration
 * dialog closes the dialog when opened in about:preferences as an HTML5
 * dialog.
 */
add_task(async function test_cancel_close() {
  await withMigrationWizardDialog(async prefsWin => {
    let dialog = prefsWin.document.querySelector("#migrationWizardDialog");
    let wizard = dialog.querySelector("migration-wizard");
    let shadow = wizard.openOrClosedShadowRoot;
    let cancelButton = shadow.querySelector(
      'div[name="page-selection"] .cancel-close'
    );
    let dialogClosed = BrowserTestUtils.waitForEvent(dialog, "close");
    cancelButton.click();
    await dialogClosed;
    Assert.ok(true, "Clicking the cancel button closed the dialog.");
  });
});

/**
 * Tests that pressing "Cancel" from the selection page of the migration
 * dialog closes the dialog when opened in stand-alone window.
 */
add_task(async function test_cancel_close() {
  let promiseWinLoaded = BrowserTestUtils.domWindowOpened().then(win => {
    return BrowserTestUtils.waitForEvent(win, "MigrationWizard:Ready");
  });

  let win = Services.ww.openWindow(
    window,
    DIALOG_URL,
    "_blank",
    "dialog,centerscreen",
    { onResize: () => {} }
  );
  await promiseWinLoaded;

  win.sizeToContent();
  let wizard = win.document.querySelector("#wizard");
  let shadow = wizard.openOrClosedShadowRoot;
  let cancelButton = shadow.querySelector(
    'div[name="page-selection"] .cancel-close'
  );

  let windowClosed = BrowserTestUtils.windowClosed(win);
  cancelButton.click();
  await windowClosed;
  Assert.ok(true, "Window was closed.");
});