summaryrefslogtreecommitdiffstats
path: root/toolkit/components/places/tests/favicons/test_incremental_vacuum.js
blob: ab93121d472d22ee9b6b83f1b2facaab5ff3f120 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
/* Any copyright is dedicated to the Public Domain.
 * http://creativecommons.org/publicdomain/zero/1.0/ */

// Tests incremental vacuum of the favicons database.

const { PlacesDBUtils } = ChromeUtils.importESModule(
  "resource://gre/modules/PlacesDBUtils.sys.mjs"
);

add_task(async function () {
  let icon = {
    file: do_get_file("noise.png"),
    mimetype: "image/png",
  };

  let url = "http://foo.bar/";
  await PlacesTestUtils.addVisits(url);
  for (let i = 0; i < 10; ++i) {
    let iconUri = NetUtil.newURI("http://mozilla.org/" + i);
    let data = readFileData(icon.file);
    PlacesUtils.favicons.replaceFaviconData(iconUri, data, icon.mimetype);
    await setFaviconForPage(url, iconUri);
  }

  let promise = TestUtils.topicObserved("places-favicons-expired");
  PlacesUtils.favicons.expireAllFavicons();
  await promise;

  let db = await PlacesUtils.promiseDBConnection();
  let state = (
    await db.execute("PRAGMA favicons.auto_vacuum")
  )[0].getResultByIndex(0);
  Assert.equal(state, 2, "auto_vacuum should be incremental");
  let count = (
    await db.execute("PRAGMA favicons.freelist_count")
  )[0].getResultByIndex(0);
  info(`Found ${count} freelist pages`);
  let log = await PlacesDBUtils.incrementalVacuum();
  info(log);
  let newCount = (
    await db.execute("PRAGMA favicons.freelist_count")
  )[0].getResultByIndex(0);
  info(`Found ${newCount} freelist pages`);
  Assert.ok(
    newCount < count,
    "The number of freelist pages should have reduced"
  );
});