Source code
Revision control
Copy as Markdown
Other Tools
Test Info: Errors
- This test gets skipped with pattern: verify OR os == 'linux' && (asan || tsan)
- This test failed 1 times in the preceding 30 days. quicksearch this test
- Manifest: toolkit/components/places/tests/browser/browser.toml
/**
* Any copyright is dedicated to the Public Domain.
*/
"use strict";
const TEST_PAGE = `data:text/html,
add_setup(async function () {
await SpecialPowers.pushPrefEnv({
set: [
// Enable restriction feature.
["places.history.floodingPrevention.enabled", true],
// Restrict from the second visit.
["places.history.floodingPrevention.restrictionCount", 1],
["places.history.floodingPrevention.restrictionExpireSeconds", 4],
// Not apply flooding prevention until some seconds elapse after user
// interaction begins.
[
"places.history.floodingPrevention.maxSecondsFromLastUserInteraction",
4,
],
// To enable UserActivation by EventUtils.synthesizeMouseAtCenter() in
// ContentTask.spawn() in synthesizeVisitByUser().
["test.events.async.enabled", true],
],
});
await clearHistoryAndHistoryCache();
});
add_task(async function basic() {
await BrowserTestUtils.withNewTab(
{ gBrowser, url: TEST_PAGE },
async browser => {
info("Sanity check");
visitCount: 0,
isVisited: false,
});
visitCount: 0,
isVisited: false,
});
visitCount: 0,
isVisited: false,
});
visitCount: 0,
isVisited: false,
});
visitCount: 1,
isVisited: true,
});
info(
);
visitCount: 3,
isVisited: true,
});
await waitForPrefSeconds("maxSecondsFromLastUserInteraction");
info(
);
visitCount: 4,
isVisited: true,
});
info("Visit again, but it should be restricted");
visitCount: 4,
isVisited: true,
});
info("Check other");
// eslint-disable-next-line @microsoft/sdl/no-insecure-url
visitCount: 0,
isVisited: false,
});
visitCount: 0,
isVisited: false,
});
visitCount: 0,
isVisited: false,
});
}
);
await clearHistoryAndHistoryCache();
});
add_task(async function expireRestriction() {
await BrowserTestUtils.withNewTab(
{ gBrowser, url: TEST_PAGE },
async browser => {
visitCount: 1,
isVisited: true,
});
info(
);
visitCount: 3,
isVisited: true,
});
await waitForPrefSeconds("maxSecondsFromLastUserInteraction");
info(
);
visitCount: 4,
isVisited: true,
});
await waitForPrefSeconds("restrictionExpireSeconds");
info("Visit again, it should not be restricted");
visitCount: 5,
isVisited: true,
});
}
);
await clearHistoryAndHistoryCache();
});
add_task(async function userInputAlwaysAcceptable() {
await BrowserTestUtils.withNewTab(
{ gBrowser, url: TEST_PAGE },
async browser => {
info("Visit by user");
visitCount: 1,
isVisited: true,
});
visitCount: 2,
isVisited: true,
});
await waitForPrefSeconds("maxSecondsFromLastUserInteraction");
info("Visit by user input");
visitCount: 3,
isVisited: true,
});
visitCount: 4,
isVisited: true,
});
}
);
await clearHistoryAndHistoryCache();
});
add_task(async function disable() {
await SpecialPowers.pushPrefEnv({
set: [["places.history.floodingPrevention.enabled", false]],
});
await BrowserTestUtils.withNewTab(
{ gBrowser, url: TEST_PAGE },
async browser => {
info("Any visits are stored");
for (let i = 0; i < 3; i++) {
visitCount: i + 1,
isVisited: true,
});
}
}
);
await clearHistoryAndHistoryCache();
});
async function waitForPrefSeconds(pref) {
info(`Wait until elapsing ${pref}`);
return new Promise(r =>
// eslint-disable-next-line mozilla/no-arbitrary-setTimeout
setTimeout(
r,
Services.prefs.getIntPref(`places.history.floodingPrevention.${pref}`) *
1000 +
100
)
);
}