tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

test_ext_tabs_getCurrent.html (2143B)


      1 <!DOCTYPE HTML>
      2 <html>
      3 <head>
      4  <meta charset="utf-8">
      5  <title>Tabs getCurrent Test</title>
      6  <script type="text/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
      7  <script type="text/javascript" src="/tests/SimpleTest/ExtensionTestUtils.js"></script>
      8  <script type="text/javascript" src="head.js"></script>
      9  <link rel="stylesheet" href="/tests/SimpleTest/test.css"/>
     10 </head>
     11 <body>
     12 
     13 <script type="text/javascript">
     14 "use strict";
     15 
     16 add_task(async function() {
     17  const extension = ExtensionTestUtils.loadExtension({
     18    manifest: {
     19      "permissions": ["tabs"],
     20    },
     21 
     22    files: {
     23      "tab.js": function() {
     24        const url = document.location.href;
     25 
     26        browser.tabs.getCurrent().then(currentTab => {
     27          browser.test.assertEq(currentTab.url, url, "getCurrent in non-active background tab");
     28 
     29          // Activate the tab.
     30          browser.tabs.onActivated.addListener(function listener({tabId}) {
     31            if (tabId == currentTab.id) {
     32              browser.tabs.onActivated.removeListener(listener);
     33 
     34              browser.tabs.getCurrent().then(currentTab => {
     35                browser.test.assertEq(currentTab.id, tabId, "in active background tab");
     36                browser.test.assertEq(currentTab.url, url, "getCurrent in non-active background tab");
     37 
     38                browser.test.sendMessage("tab-finished");
     39              });
     40            }
     41          });
     42          browser.tabs.update(currentTab.id, {active: true});
     43        });
     44      },
     45 
     46      "tab.html": `<head><meta charset="utf-8"><script src="tab.js"><\/script></head>`,
     47    },
     48 
     49    background: function() {
     50      browser.tabs.getCurrent().then(tab => {
     51        browser.test.assertEq(tab, undefined, "getCurrent in background script");
     52        browser.test.sendMessage("background-finished");
     53      });
     54 
     55      browser.tabs.create({url: "tab.html", active: false});
     56    },
     57  });
     58 
     59  await extension.startup();
     60 
     61  await extension.awaitMessage("background-finished");
     62  await extension.awaitMessage("tab-finished");
     63 
     64  // The extension tab is automatically closed when the extension unloads.
     65  await extension.unload();
     66 });
     67 </script>
     68 
     69 </body>
     70 </html>