Source code

Revision control

Copy as Markdown

Other Tools

Test Info: Warnings

/* Any copyright is dedicated to the Public Domain.
"use strict";
const { AboutNewTab } = ChromeUtils.importESModule(
"resource:///modules/AboutNewTab.sys.mjs"
);
const { UrlbarProviderTopSites } = ChromeUtils.importESModule(
"moz-src:///browser/components/urlbar/UrlbarProviderTopSites.sys.mjs"
);
add_setup(async function () {
Services.prefs.setBoolPref("browser.urlbar.suggest.topsites", true);
Services.prefs.setBoolPref(
"browser.newtabpage.activity-stream.feeds.system.topsites",
true
);
Services.prefs.setBoolPref(
"browser.urlbar.resultExplanations.featureGate",
true
);
registerCleanupFunction(async () => {
Services.prefs.clearUserPref("browser.urlbar.suggest.topsites");
Services.prefs.clearUserPref(
"browser.newtabpage.activity-stream.feeds.system.topsites"
);
Services.prefs.clearUserPref(
"browser.urlbar.resultExplanations.featureGate"
);
await PlacesUtils.history.clear();
});
});
add_task(async function noTrailingSlash() {
info("Add a visit for the canonical URL (with a trailing slash)");
let visitDate = new Date(Date.now() - 60 * 60 * 1000);
await PlacesTestUtils.addVisits({ uri: "https://example.org/", visitDate });
await doTest({
pinned: "https://example.org",
expectedVisitDate: visitDate,
});
});
add_task(async function redirectChain() {
info("Build a redirect chain of three URLs");
const PINNED_URL = "https://redirect-a.example/";
const HOP_URL = "https://redirect-b.example/";
const FINAL_URL = "https://redirect-c.example/";
let now = Date.now();
let finalVisitDate = new Date(now - 1000);
await PlacesTestUtils.addVisits([
{
uri: PINNED_URL,
transition: PlacesUtils.history.TRANSITIONS.LINK,
visitDate: new Date(now - 3000),
},
{
uri: HOP_URL,
transition: PlacesUtils.history.TRANSITIONS.REDIRECT_TEMPORARY,
referrer: PINNED_URL,
visitDate: new Date(now - 2000),
},
{
uri: FINAL_URL,
transition: PlacesUtils.history.TRANSITIONS.REDIRECT_PERMANENT,
referrer: HOP_URL,
visitDate: finalVisitDate,
},
]);
await doTest({
pinned: PINNED_URL,
expectedVisitDate: finalVisitDate,
});
});
async function doTest({ pinned, expectedVisitDate }) {
let sandbox = sinon.createSandbox();
sandbox
.stub(AboutNewTab, "getTopSites")
.returns([{ url: pinned, isPinned: true }]);
let provider = new UrlbarProviderTopSites();
let result;
await provider.startQuery(createContext(""), (_provider, r) => {
result = r;
});
Assert.equal(result.payload.lastVisit, expectedVisitDate.getTime());
sandbox.restore();
await PlacesUtils.history.clear();
}