tor-browser

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

browser_aboutSupport_places.js (4688B)


      1 /* Any copyright is dedicated to the Public Domain.
      2   http://creativecommons.org/publicdomain/zero/1.0/ */
      3 
      4 "use strict";
      5 
      6 const CORRUPT_FILE_PATH = PathUtils.join(
      7  PathUtils.profileDir,
      8  "places.sqlite.corrupt"
      9 );
     10 
     11 add_setup(async function setup() {
     12  registerCleanupFunction(async function () {
     13    Services.prefs.clearUserPref("places.database.lastMaintenance");
     14    Services.prefs.clearUserPref("storage.vacuum.last.places.sqlite");
     15    await IOUtils.remove(CORRUPT_FILE_PATH);
     16  });
     17 });
     18 
     19 add_task(async function test_places_db_stats_table() {
     20  await doTestOnAboutSupportPage(async function (browser) {
     21    const [initialToggleText, toggleTextAfterShow, toggleTextAfterHide] =
     22      await SpecialPowers.spawn(browser, [], async function () {
     23        const toggleButton = content.document.getElementById(
     24          "place-database-stats-toggle"
     25        );
     26        const getToggleText = () =>
     27          content.document.l10n.getAttributes(toggleButton).id;
     28        const toggleTexts = [];
     29        const table = content.document.getElementById(
     30          "place-database-stats-tbody"
     31        );
     32        await ContentTaskUtils.waitForCondition(
     33          () => ContentTaskUtils.isHidden(table),
     34          "Stats table is hidden initially"
     35        );
     36        toggleTexts.push(getToggleText());
     37        toggleButton.click();
     38        await ContentTaskUtils.waitForCondition(
     39          () => ContentTaskUtils.isVisible(table),
     40          "Stats table is shown after first toggle"
     41        );
     42        toggleTexts.push(getToggleText());
     43        toggleButton.click();
     44        await ContentTaskUtils.waitForCondition(
     45          () => ContentTaskUtils.isHidden(table),
     46          "Stats table is hidden after second toggle"
     47        );
     48        toggleTexts.push(getToggleText());
     49        return toggleTexts;
     50      });
     51    Assert.equal(initialToggleText, "place-database-stats-show");
     52    Assert.equal(toggleTextAfterShow, "place-database-stats-hide");
     53    Assert.equal(toggleTextAfterHide, "place-database-stats-show");
     54  });
     55 });
     56 
     57 add_task(async function test_lastMaintenanceDate() {
     58  const TEST_DATA = [
     59    {
     60      date: 0,
     61      expected: "Missing",
     62    },
     63    {
     64      date: Math.floor(new Date("2025-11-21T12:16:30").getTime() / 1000),
     65      expected: "11/21/2025, 12:16 PM",
     66    },
     67  ];
     68 
     69  for (const { date, expected } of TEST_DATA) {
     70    Services.prefs.setIntPref("places.database.lastMaintenance", date);
     71 
     72    await doTestOnAboutSupportPage(async function (browser) {
     73      await waitUntilContentLabelUpdated({
     74        browser,
     75        id: "place-database-last-idle-maintenance-data",
     76        expected,
     77      });
     78      Assert.ok(true, "The lastMaintenance is displayed correctly");
     79    });
     80  }
     81 });
     82 
     83 add_task(async function test_lastVacuumDate() {
     84  const TEST_DATA = [
     85    {
     86      date: 0,
     87      expected: "Missing",
     88    },
     89    {
     90      date: Math.floor(new Date("2025-11-21T12:16:30").getTime() / 1000),
     91      expected: "11/21/2025, 12:16 PM",
     92    },
     93  ];
     94 
     95  for (const { date, expected } of TEST_DATA) {
     96    Services.prefs.setIntPref("storage.vacuum.last.places.sqlite", date);
     97 
     98    await doTestOnAboutSupportPage(async function (browser) {
     99      await waitUntilContentLabelUpdated({
    100        browser,
    101        id: "place-database-last-vacuum-date",
    102        expected,
    103      });
    104      Assert.ok(true, "The lastVacuumDate is displayed correctly");
    105    });
    106  }
    107 });
    108 
    109 add_task(async function test_lastIntegrityCorruptionDate() {
    110  const TEST_DATA = [
    111    {
    112      // No corruption file.
    113      date: 0,
    114      expected: "Missing",
    115    },
    116    {
    117      date: new Date("2025-11-21T12:16:30").getTime(),
    118      expected: "11/21/2025, 12:16 PM",
    119    },
    120  ];
    121 
    122  for (const { date, expected } of TEST_DATA) {
    123    if (date) {
    124      await IOUtils.writeUTF8(CORRUPT_FILE_PATH, "test");
    125      await IOUtils.setModificationTime(CORRUPT_FILE_PATH, date);
    126    }
    127 
    128    await doTestOnAboutSupportPage(async function (browser) {
    129      await waitUntilContentLabelUpdated({
    130        browser,
    131        id: "place-database-last-integrity-corruption-date",
    132        expected,
    133      });
    134      Assert.ok(true, "The lastIntegrityCorruptionDate is displayed correctly");
    135    });
    136  }
    137 });
    138 
    139 async function doTestOnAboutSupportPage(func) {
    140  await BrowserTestUtils.withNewTab({ gBrowser, url: "about:support" }, func);
    141 }
    142 
    143 async function waitUntilContentLabelUpdated({ browser, id, expected }) {
    144  await SpecialPowers.spawn(browser, [id, expected], async (i, e) => {
    145    const target = content.document.getElementById(i);
    146    await ContentTaskUtils.waitForMutationCondition(
    147      target,
    148      {
    149        characterData: true,
    150        childList: true,
    151        subtree: true,
    152      },
    153      () => target.textContent == e
    154    );
    155  });
    156 }