mobile/android/components/extensions/test/mochitest/test_ext_tabs_reload.html
author Alastor Wu <alwu@mozilla.com>
Tue, 10 Dec 2019 18:30:36 +0000
changeset 506291 1fb1ca98f23b29d1a8a287ad2db326c84df04c57
parent 470011 c83490ca7185506ddf5e9828f8159930c03d15a0
permissions -rw-r--r--
Bug 1602617 - part2 : reuse same event source all the time. r=MeFisto94 Because we won't change platform dynamically, so we should be able to keep same the event source all the time and use `Open()` and `Close()` to control if we need to monitor media keys event or not. Differential Revision: https://phabricator.services.mozilla.com/D56499

<!DOCTYPE HTML>
<html>
<head>
  <title>Tabs reload Test</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" href="/tests/SimpleTest/test.css"/>
</head>
<body>

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

add_task(async function() {
  let extension = ExtensionTestUtils.loadExtension({
    manifest: {
      "permissions": ["tabs"],
    },

    files: {
      "tab.js": function() {
        browser.runtime.sendMessage("tab-loaded");
      },
      "tab.html":
        `<head>
          <meta charset="utf-8">
          <script src="tab.js"><\/script>
        </head>`,
    },

    async background() {
      let tabLoadedCount = 0;

      let tab = await browser.tabs.create({url: "tab.html", active: true});

      browser.runtime.onMessage.addListener(msg => {
        if (msg == "tab-loaded") {
          tabLoadedCount++;

          if (tabLoadedCount == 1) {
            // Reload the tab once passing no arguments.
            return browser.tabs.reload();
          }

          if (tabLoadedCount == 2) {
            // Reload the tab again with explicit arguments.
            return browser.tabs.reload(tab.id, {
              bypassCache: false,
            });
          }

          if (tabLoadedCount == 3) {
            browser.test.notifyPass("tabs.reload");
          }
        }
      });
    },
  });

  await extension.startup();
  await extension.awaitFinish("tabs.reload");
  await extension.unload();
});
</script>

</body>
</html>