summaryrefslogtreecommitdiffstats
path: root/browser/components/extensions/test/browser/browser_ext_sidebarAction_click.js
blob: 621d2d1180c0553c6a7113dce3588a8567fb8a74 (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
/* -*- 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_sidebar_click_isAppTab_behavior() {
  function sidebarScript() {
    browser.tabs.onUpdated.addListener(function onUpdated(
      tabId,
      changeInfo,
      tab
    ) {
      if (
        changeInfo.status == "complete" &&
        tab.url == "http://mochi.test:8888/"
      ) {
        browser.tabs.remove(tab.id);
        browser.test.notifyPass("sidebar-click");
      }
    });
    window.addEventListener(
      "load",
      () => {
        browser.test.sendMessage("sidebar-ready");
      },
      { once: true }
    );
  }

  let extension = ExtensionTestUtils.loadExtension({
    manifest: {
      sidebar_action: {
        default_panel: "panel.html",
        browser_style: false,
      },
      permissions: ["tabs"],
    },
    useAddonManager: "temporary",

    files: {
      "panel.html": `
        <!DOCTYPE html>
        <html>
          <head>
          <meta charset="utf-8">
          </head>
          <script src="panel.js" type="text/javascript"></script>
          <a id="testlink" href="http://mochi.test:8888">Bugzilla</a>
        </html>`,
      "panel.js": sidebarScript,
    },
  });

  await extension.startup();
  await extension.awaitMessage("sidebar-ready");

  // This test fails if docShell.isAppTab has not been set to true.
  let content = SidebarUI.browser.contentWindow;

  // Wait for the layout to be flushed, otherwise this test may
  // fail intermittently if synthesizeMouseAtCenter is being called
  // while the sidebar is still opening and the browser window layout
  // being recomputed.
  await content.promiseDocumentFlushed(() => {});

  info("Clicking link in extension sidebar");
  await BrowserTestUtils.synthesizeMouseAtCenter(
    "#testlink",
    {},
    content.gBrowser.selectedBrowser
  );
  await extension.awaitFinish("sidebar-click");

  await extension.unload();
});