<!DOCTYPE HTML>
<html>
<head>
  <meta charset="utf-8">
  <title>Action with MV3</title>
  <script type="text/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
  <script type="text/javascript" src="/tests/SimpleTest/ExtensionTestUtils.js"></script>
  <script type="text/javascript" src="head.js"></script>
  <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css">
</head>
<body>

<script type="text/javascript">
"use strict";

add_task(async function setup() {
  await SpecialPowers.pushPrefEnv({
    set: [["extensions.manifestV3.enabled", true]],
  });
});

add_task(async function test_action_onClicked() {
  const extension = ExtensionTestUtils.loadExtension({
    manifest: {
      manifest_version: 3,
      action: {},
    },
    background() {
      browser.action.onClicked.addListener(async () => {
        browser.test.notifyPass("action-clicked");
      });

      browser.test.sendMessage("background-ready");
    },
  });

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

  await AppTestDelegate.clickBrowserAction(window, extension);
  await extension.awaitFinish("action-clicked");
  await AppTestDelegate.closeBrowserAction(window, extension);

  await extension.unload();
});

</script>

</body>
</html>
