diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-19 01:47:29 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-19 01:47:29 +0000 |
commit | 0ebf5bdf043a27fd3dfb7f92e0cb63d88954c44d (patch) | |
tree | a31f07c9bcca9d56ce61e9a1ffd30ef350d513aa /toolkit/components/places/tests/unit/test_frecency_origins_recalc.js | |
parent | Initial commit. (diff) | |
download | firefox-esr-0ebf5bdf043a27fd3dfb7f92e0cb63d88954c44d.tar.xz firefox-esr-0ebf5bdf043a27fd3dfb7f92e0cb63d88954c44d.zip |
Adding upstream version 115.8.0esr.upstream/115.8.0esr
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'toolkit/components/places/tests/unit/test_frecency_origins_recalc.js')
-rw-r--r-- | toolkit/components/places/tests/unit/test_frecency_origins_recalc.js | 62 |
1 files changed, 62 insertions, 0 deletions
diff --git a/toolkit/components/places/tests/unit/test_frecency_origins_recalc.js b/toolkit/components/places/tests/unit/test_frecency_origins_recalc.js new file mode 100644 index 0000000000..b96f9ecb58 --- /dev/null +++ b/toolkit/components/places/tests/unit/test_frecency_origins_recalc.js @@ -0,0 +1,62 @@ +/* Any copyright is dedicated to the Public Domain. + http://creativecommons.org/publicdomain/zero/1.0/ */ + +// Tests that recalc_frecency in the moz_origins table works is consistent. + +// This test does not completely cover origins frecency recalculation because +// the current system uses temp tables and triggers to make the recalculation, +// but it's likely that will change in the future and then we can add to this. + +add_task(async function test() { + // test recalc_frecency is set to 1 when frecency of a page changes. + // Add a couple visits, then remove one of them. + const now = new Date(); + const url = "https://mozilla.org/test/"; + await PlacesTestUtils.addVisits([ + { + url, + visitDate: now, + }, + { + url, + visitDate: new Date(new Date().setDate(now.getDate() - 30)), + }, + ]); + // TODO: use PlacesTestUtils.getDatabaseValue once available. + let db = await PlacesUtils.promiseDBConnection(); + Assert.equal( + ( + await db.execute(`SELECT recalc_frecency FROM moz_origins`) + )[0].getResultByIndex(0), + 0, + "Should have been calculated already" + ); + Assert.equal( + ( + await db.execute(`SELECT recalc_alt_frecency FROM moz_origins`) + )[0].getResultByIndex(0), + 1, + "Should not have been calculated" + ); + + // Remove only one visit (otherwise the page would be orphaned). + await PlacesUtils.history.removeVisitsByFilter({ + beginDate: new Date(now.valueOf() - 10000), + endDate: new Date(now.valueOf() + 10000), + }); + Assert.equal( + ( + await db.execute(`SELECT recalc_frecency FROM moz_origins`) + )[0].getResultByIndex(0), + 0, + "Should have been calculated already" + ); + Assert.equal( + ( + await db.execute(`SELECT recalc_alt_frecency FROM moz_origins`) + )[0].getResultByIndex(0), + 1, + "Should not have been calculated yet" + ); + // test recalc_frecency is set back to 0 when frecency of the origin is set +}); |