summaryrefslogtreecommitdiffstats
path: root/browser/components/reportbrokensite/test/browser/browser_keyboard_navigation.js
blob: 4c37866628b67989440073aac4b81e2f6bed5c75 (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
/* Any copyright is dedicated to the Public Domain.
 * http://creativecommons.org/publicdomain/zero/1.0/ */

/* Tests to ensure that sending or canceling reports with
 * the Send and Cancel buttons work (as well as the Okay button)
 */

"use strict";

add_common_setup();

requestLongerTimeout(2);

async function testPressingKey(key, tabToMatch, makePromise, followUp) {
  await BrowserTestUtils.withNewTab(
    REPORTABLE_PAGE_URL,
    async function (browser) {
      for (const menu of [AppMenu(), ProtectionsPanel(), HelpMenu()]) {
        info(
          `Opening RBS to test pressing ${key} for ${tabToMatch} on ${menu.menuDescription}`
        );
        const rbs = await menu.openReportBrokenSite();
        const promise = makePromise(rbs);
        if (tabToMatch) {
          if (await tabTo(tabToMatch)) {
            await pressKeyAndAwait(promise, key);
            followUp && (await followUp(rbs));
            await rbs.close();
            ok(true, `was able to activate ${tabToMatch} with keyboard`);
          } else {
            await rbs.close();
            ok(false, `could not tab to ${tabToMatch}`);
          }
        } else {
          await pressKeyAndAwait(promise, key);
          followUp && (await followUp(rbs));
          await rbs.close();
          ok(true, `was able to use keyboard`);
        }
      }
    }
  );
}

add_task(async function testSendMoreInfo() {
  ensureReportBrokenSitePreffedOn();
  ensureSendMoreInfoEnabled();
  await testPressingKey(
    "KEY_Enter",
    "#report-broken-site-popup-send-more-info-link",
    rbs => rbs.waitForSendMoreInfoTab(),
    () => gBrowser.removeCurrentTab()
  );
});

add_task(async function testCancel() {
  ensureReportBrokenSitePreffedOn();
  await testPressingKey(
    "KEY_Enter",
    "#report-broken-site-popup-cancel-button",
    rbs => BrowserTestUtils.waitForEvent(rbs.mainView, "ViewHiding")
  );
});

add_task(async function testSendAndOkay() {
  ensureReportBrokenSitePreffedOn();
  await testPressingKey(
    "KEY_Enter",
    "#report-broken-site-popup-send-button",
    rbs => rbs.awaitReportSentViewOpened(),
    async rbs => {
      await tabTo("#report-broken-site-popup-okay-button");
      const promise = BrowserTestUtils.waitForEvent(rbs.sentView, "ViewHiding");
      await pressKeyAndAwait(promise, "KEY_Enter");
    }
  );
});

add_task(async function testESCOnMain() {
  ensureReportBrokenSitePreffedOn();
  await testPressingKey("KEY_Escape", undefined, rbs =>
    BrowserTestUtils.waitForEvent(rbs.mainView, "ViewHiding")
  );
});

add_task(async function testESCOnSent() {
  ensureReportBrokenSitePreffedOn();
  await testPressingKey(
    "KEY_Enter",
    "#report-broken-site-popup-send-button",
    rbs => rbs.awaitReportSentViewOpened(),
    async rbs => {
      const promise = BrowserTestUtils.waitForEvent(rbs.sentView, "ViewHiding");
      await pressKeyAndAwait(promise, "KEY_Escape");
    }
  );
});

add_task(async function testBackButtons() {
  ensureReportBrokenSitePreffedOn();
  await BrowserTestUtils.withNewTab(
    REPORTABLE_PAGE_URL,
    async function (browser) {
      for (const menu of [AppMenu(), ProtectionsPanel()]) {
        await menu.openReportBrokenSite();
        await tabTo("#report-broken-site-popup-mainView .subviewbutton-back");
        const promise = BrowserTestUtils.waitForEvent(menu.popup, "ViewShown");
        await pressKeyAndAwait(promise, "KEY_Enter");
        menu.close();
      }
    }
  );
});