summaryrefslogtreecommitdiffstats
path: root/toolkit/components/places/tests/unit/test_frecency_decay.js
diff options
context:
space:
mode:
Diffstat (limited to 'toolkit/components/places/tests/unit/test_frecency_decay.js')
-rw-r--r--toolkit/components/places/tests/unit/test_frecency_decay.js52
1 files changed, 52 insertions, 0 deletions
diff --git a/toolkit/components/places/tests/unit/test_frecency_decay.js b/toolkit/components/places/tests/unit/test_frecency_decay.js
new file mode 100644
index 0000000000..e7ae3cca9a
--- /dev/null
+++ b/toolkit/components/places/tests/unit/test_frecency_decay.js
@@ -0,0 +1,52 @@
+const PREF_FREC_DECAY_RATE_DEF = 0.975;
+
+/**
+ * Promises that the pages-rank-changed event has been seen.
+ *
+ * @returns {Promise} A promise which is resolved when the notification is seen.
+ */
+function promiseRankingChanged() {
+ return PlacesTestUtils.waitForNotification(
+ "pages-rank-changed",
+ () => true,
+ "places"
+ );
+}
+
+add_task(async function setup() {
+ Services.prefs.setCharPref(
+ "places.frecency.decayRate",
+ PREF_FREC_DECAY_RATE_DEF
+ );
+});
+
+add_task(async function test_frecency_decay() {
+ let unvisitedBookmarkFrecency = Services.prefs.getIntPref(
+ "places.frecency.unvisitedBookmarkBonus"
+ );
+
+ // Add a bookmark and check its frecency.
+ let url = "http://example.com/b";
+ let promiseOne = promiseRankingChanged();
+ await PlacesUtils.bookmarks.insert({
+ url,
+ parentGuid: PlacesUtils.bookmarks.unfiledGuid,
+ });
+ await promiseOne;
+
+ // Trigger DecayFrecency.
+ let promiseMany = promiseRankingChanged();
+ PlacesUtils.history
+ .QueryInterface(Ci.nsIObserver)
+ .observe(null, "idle-daily", "");
+ await promiseMany;
+
+ // Now check the new frecency is correct.
+ let newFrecency = await PlacesTestUtils.fieldInDB(url, "frecency");
+
+ Assert.equal(
+ newFrecency,
+ Math.round(unvisitedBookmarkFrecency * PREF_FREC_DECAY_RATE_DEF),
+ "Frecencies should match"
+ );
+});