summaryrefslogtreecommitdiffstats
path: root/toolkit/components/places/tests/unit/test_frecency_zero_updated.js
blob: 44c329635ed24d44ae48fdfd35f01fe4c09f7388 (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
/* Any copyright is dedicated to the Public Domain.
   http://creativecommons.org/publicdomain/zero/1.0/ */

// Tests a zero frecency is correctly updated when inserting new valid visits.

add_task(async function () {
  const TEST_URI = NetUtil.newURI("http://example.com/");
  let bookmark = await PlacesUtils.bookmarks.insert({
    parentGuid: PlacesUtils.bookmarks.unfiledGuid,
    url: TEST_URI,
    title: "A title",
  });
  await PlacesFrecencyRecalculator.recalculateAnyOutdatedFrecencies();
  Assert.ok(
    (await PlacesTestUtils.getDatabaseValue("moz_places", "frecency", {
      url: TEST_URI,
    })) > 0
  );

  // Removing the bookmark should leave an orphan page with zero frecency.
  // Note this would usually be expired later by expiration.
  await PlacesUtils.bookmarks.remove(bookmark.guid);
  await PlacesFrecencyRecalculator.recalculateAnyOutdatedFrecencies();
  Assert.equal(
    await PlacesTestUtils.getDatabaseValue("moz_places", "frecency", {
      url: TEST_URI,
    }),
    0
  );

  // Now add a valid visit to the page, frecency should increase.
  await PlacesTestUtils.addVisits({ uri: TEST_URI });
  Assert.ok(
    (await PlacesTestUtils.getDatabaseValue("moz_places", "frecency", {
      url: TEST_URI,
    })) > 0
  );
});