tor-browser

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

reload-test.js (2749B)


      1 /* This Source Code Form is subject to the terms of the Mozilla Public
      2 * License, v. 2.0. If a copy of the MPL was not distributed with this
      3 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
      4 
      5 "use strict";
      6 
      7 /* import-globals-from head.js */
      8 /* eslint no-unused-vars: [2, {"vars": "local"}] */
      9 
     10 /**
     11 * Generate a test Task to record allocation when reloading a test page
     12 * while having one particular DevTools panel opened
     13 *
     14 * @param String recordName
     15 *        Name of the test recorded into PerfHerder/Talos database
     16 * @param String toolId
     17 *        ID of the panel to open
     18 */
     19 function createPanelReloadTest(recordName, toolId) {
     20  return async function panelReloadTest() {
     21    const TEST_URL =
     22      "http://example.com/browser/devtools/client/framework/test/allocations/reloaded-page.html";
     23 
     24    async function testScript(toolbox) {
     25      const onTargetSwitched =
     26        toolbox.commands.targetCommand.once("switched-target");
     27      const onReloaded = toolbox.getCurrentPanel().once("reloaded");
     28 
     29      gBrowser.reloadTab(gBrowser.selectedTab);
     30 
     31      if (
     32        toolbox.commands.targetCommand.targetFront.targetForm
     33          .followWindowGlobalLifeCycle
     34      ) {
     35        info("Wait for target switched");
     36        await onTargetSwitched;
     37      }
     38 
     39      info("Wait for panel reload");
     40      await onReloaded;
     41 
     42      // eslint-disable-next-line mozilla/no-arbitrary-setTimeout
     43      await new Promise(resolve => setTimeout(resolve, 1000));
     44    }
     45 
     46    const tab = await addTab(TEST_URL);
     47 
     48    const { require } = ChromeUtils.importESModule(
     49      "resource://devtools/shared/loader/Loader.sys.mjs"
     50    );
     51    const {
     52      gDevTools,
     53    } = require("resource://devtools/client/framework/devtools.js");
     54    const toolbox = await gDevTools.showToolboxForTab(tab, {
     55      toolId,
     56    });
     57 
     58    // Run the test scenario first before recording in order to load all the
     59    // modules. Otherwise they get reported as "still allocated" objects,
     60    // whereas we do expect them to be kept in memory as they are loaded via
     61    // the main DevTools loader, which keeps the module loaded until the
     62    // shutdown of Firefox
     63    await testScript(toolbox);
     64    // Running it a second time is helpful for the debugger which allocates different objects
     65    // on the second run... which would be taken as leak otherwise.
     66    await testScript(toolbox);
     67 
     68    await startRecordingAllocations({
     69      alsoRecordContentProcess: true,
     70    });
     71 
     72    // Now, run the test script. This time, we record this run.
     73    for (let i = 0; i < 10; i++) {
     74      await testScript(toolbox);
     75    }
     76 
     77    await stopRecordingAllocations(recordName, {
     78      alsoRecordContentProcess: true,
     79    });
     80 
     81    await toolbox.destroy();
     82    gBrowser.removeTab(tab);
     83  };
     84 }