summaryrefslogtreecommitdiffstats
path: root/browser/components/extensions/test/browser/browser_ext_commands_execute_sidebar_action.js
blob: 0f96138d0971554c10fb958784f1b3cae230bdcd (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
/* -*- Mode: indent-tabs-mode: nil; js-indent-level: 2 -*- */
/* vim: set sts=2 sw=2 et tw=80: */
"use strict";

add_task(async function test_execute_sidebar_action() {
  let extension = ExtensionTestUtils.loadExtension({
    manifest: {
      commands: {
        _execute_sidebar_action: {
          suggested_key: {
            default: "Alt+Shift+J",
          },
        },
      },
      sidebar_action: {
        default_panel: "sidebar.html",
      },
    },
    // We want to confirm that sidebar is not shown on every extension start,
    // so we use an explicit APP_STARTUP.
    startupReason: "APP_STARTUP",
    files: {
      "sidebar.html": `
        <!DOCTYPE html>
        <html>
          <head>
            <meta charset="utf-8">
            <script src="sidebar.js"></script>
          </head>
        </html>
      `,

      "sidebar.js": function () {
        browser.runtime.sendMessage("from-sidebar-action");
      },
    },
    background() {
      browser.runtime.onMessage.addListener(msg => {
        if (msg == "from-sidebar-action") {
          browser.test.notifyPass("execute-sidebar-action-opened");
        }
      });
    },
  });

  await extension.startup();
  await SimpleTest.promiseFocus(window);
  ok(
    document.getElementById("sidebar-box").hidden,
    `Sidebar box is not visible after "not-first" startup.`
  );
  // Send the key to open the sidebar.
  EventUtils.synthesizeKey("j", { altKey: true, shiftKey: true });
  await extension.awaitFinish("execute-sidebar-action-opened");
  await extension.unload();
});