tor-browser

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

test_ext_pageAction_shutdown.js (2560B)


      1 /* -*- Mode: indent-tabs-mode: nil; js-indent-level: 2 -*- */
      2 /* vim: set sts=2 sw=2 et tw=80: */
      3 "use strict";
      4 
      5 // Load lazy so we create the app info first.
      6 ChromeUtils.defineESModuleGetters(this, {
      7  PageActions: "resource:///modules/PageActions.sys.mjs",
      8 });
      9 
     10 const { AddonTestUtils } = ChromeUtils.importESModule(
     11  "resource://testing-common/AddonTestUtils.sys.mjs"
     12 );
     13 
     14 const { createAppInfo, promiseShutdownManager, promiseStartupManager } =
     15  AddonTestUtils;
     16 
     17 AddonTestUtils.init(this);
     18 AddonTestUtils.overrideCertDB();
     19 
     20 createAppInfo("xpcshell@tests.mozilla.org", "XPCShell", "1", "58");
     21 
     22 // This is copied and pasted from ext-browser.js and used in ext-pageAction.js.
     23 // It's used as the PageActions action ID.
     24 function makeWidgetId(id) {
     25  id = id.toLowerCase();
     26  // FIXME: This allows for collisions.
     27  return id.replace(/[^a-z0-9_-]/g, "_");
     28 }
     29 
     30 // Tests that the pinnedToUrlbar property of the PageActions.Action object
     31 // backing the extension's page action persists across app restarts.
     32 add_task(async function testAppShutdown() {
     33  let extensionData = {
     34    useAddonManager: "permanent",
     35    manifest: {
     36      page_action: {
     37        default_title: "test_ext_pageAction_shutdown.js",
     38        browser_style: false,
     39      },
     40    },
     41  };
     42 
     43  // Simulate starting up the app.
     44  PageActions.init();
     45  await promiseStartupManager();
     46 
     47  let extension = ExtensionTestUtils.loadExtension(extensionData);
     48  await extension.startup();
     49 
     50  // Get the PageAction.Action object.  Its pinnedToUrlbar should have been
     51  // initialized to true in ext-pageAction.js, when it's created.
     52  let actionID = makeWidgetId(extension.id);
     53  let action = PageActions.actionForID(actionID);
     54  Assert.equal(action.pinnedToUrlbar, true);
     55 
     56  // Simulate restarting the app without first unloading the extension.
     57  await promiseShutdownManager();
     58  PageActions._reset();
     59  await promiseStartupManager();
     60  await extension.awaitStartup();
     61 
     62  // Get the action.  Its pinnedToUrlbar should remain true.
     63  action = PageActions.actionForID(actionID);
     64  Assert.equal(action.pinnedToUrlbar, true);
     65 
     66  // Now set its pinnedToUrlbar to false.
     67  action.pinnedToUrlbar = false;
     68 
     69  // Simulate restarting the app again without first unloading the extension.
     70  await promiseShutdownManager();
     71  PageActions._reset();
     72  await promiseStartupManager();
     73  await extension.awaitStartup();
     74 
     75  action = PageActions.actionForID(actionID);
     76  Assert.equal(action.pinnedToUrlbar, true);
     77 
     78  // Now unload the extension and quit the app.
     79  await extension.unload();
     80  await promiseShutdownManager();
     81 });