summaryrefslogtreecommitdiffstats
path: root/toolkit/components/places/tests/unit/test_frecency_unvisited_bookmark.js
blob: ae7bd3d8135e8958a9f688512b0cd8df6d4efb92 (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
49
50
51
52
53
54
/* Any copyright is dedicated to the Public Domain.
   http://creativecommons.org/publicdomain/zero/1.0/ */

// Tests frecency of unvisited bookmarks.

add_task(async function () {
  // Randomly sorted by date.
  const now = new Date();
  const bookmarks = [
    {
      url: "https://example.com/1",
      date: new Date(new Date().setDate(now.getDate() - 30)),
    },
    {
      url: "https://example.com/2",
      date: new Date(new Date().setDate(now.getDate() - 1)),
    },
    {
      url: "https://example.com/3",
      date: new Date(new Date().setDate(now.getDate() - 100)),
    },
    {
      url: "https://example.com/1", // Same url but much older.
      date: new Date(new Date().setDate(now.getDate() - 120)),
    },
  ];

  for (let bookmark of bookmarks) {
    await PlacesUtils.bookmarks.insert({
      parentGuid: PlacesUtils.bookmarks.unfiledGuid,
      url: bookmark.url,
      dateAdded: bookmark.date,
    });
  }
  await PlacesFrecencyRecalculator.recalculateAnyOutdatedFrecencies();

  // The newest bookmark should have an higher frecency.
  Assert.greater(
    await PlacesTestUtils.getDatabaseValue("moz_places", "frecency", {
      url: bookmarks[1].url,
    }),
    await PlacesTestUtils.getDatabaseValue("moz_places", "frecency", {
      url: bookmarks[0].url,
    })
  );
  Assert.greater(
    await PlacesTestUtils.getDatabaseValue("moz_places", "frecency", {
      url: bookmarks[0].url,
    }),
    await PlacesTestUtils.getDatabaseValue("moz_places", "frecency", {
      url: bookmarks[2].url,
    })
  );
});