Source code
Revision control
Copy as Markdown
Other Tools
Test Info: Warnings
- This test gets skipped with pattern: os == 'android'
- Manifest: toolkit/components/places/tests/expiration/xpcshell.toml
/* Any copyright is dedicated to the Public Domain.
/**
* Tests expiration of Places interactions data.
*/
// Number of days in the past where interactions will be expired.
const EXPIRE_DAYS = 60;
// Should be more recent than EXPIRED_DAYS.
const RECENT_DATE = new Date() - (EXPIRE_DAYS - 1) * 86400000;
add_task(async function setup() {
Services.prefs.setBoolPref("browser.places.interactions.enabled", true);
Services.prefs.setIntPref(
"browser.places.interactions.expireDays",
EXPIRE_DAYS
);
});
add_task(async function test_expire_interactions() {
// Add visits and metadata to 2 pages and force expiration.
await PlacesTestUtils.addVisits([
]);
// Insert dummy interactions for all the pages.
EXPIRE_DAYS + 10,
]);
0,
EXPIRE_DAYS + 10,
]);
0,
EXPIRE_DAYS / 2,
]);
info("Remove a page from history and check interactions are removed");
// Expire now.
await promiseForceExpirationStep(-1);
info("Test interactions expiration result");
await checkDummyInteractions(
1
);
// Clean up.
await PlacesUtils.history.clear();
});
async function addDummyInteractions(url, interactionDaysAgo) {
await PlacesTestUtils.addVisits(url);
await PlacesUtils.withConnectionWrapper(
"test_interactions_expiration.js: addDummyInteraction",
async db => {
await db.execute(
`INSERT INTO moz_places_metadata (place_id, created_at, updated_at) VALUES (
(SELECT id FROM moz_places WHERE url_hash = hash(:url)),
strftime('%s','now','localtime','-' || :days || ' day','start of day','utc') * 1000,
strftime('%s','now','localtime','-' || :days || ' day','start of day','utc') * 1000
)`,
interactionDaysAgo.map(days => ({ url, days }))
);
}
);
}
async function checkDummyInteractions(url, interactionsLen) {
info("Check interactions for " + url);
await PlacesUtils.withConnectionWrapper(
"test_interactions_expiration.js: addDummyInteraction",
async db => {
let rows = await db.execute(
`SELECT updated_at
FROM moz_places_metadata
WHERE place_id = (SELECT id FROM moz_places WHERE url_hash = hash(:url))
ORDER BY updated_at DESC`,
{ url }
);
let dates = rows.map(r => new Date(r.getResultByName("updated_at")));
Assert.equal(
rows.length,
interactionsLen,
"Found expected number of interactions"
);
Assert.ok(
dates.every(d => d > RECENT_DATE),
"All interactions are recent"
);
}
);
}