mirror of
https://github.com/mozilla/gecko-dev.git
synced 2025-11-08 20:28:42 +02:00
Differential Revision: https://phabricator.services.mozilla.com/D7916 --HG-- rename : browser/components/newtab/content-src/asrouter/templates/SimpleSnippet/SimpleSnippet.schema.json => browser/components/newtab/content-src/asrouter/templates/NewsletterSnippet/NewsletterSnippet.schema.json extra : moz-landing-system : lando
53 lines
1.5 KiB
JavaScript
53 lines
1.5 KiB
JavaScript
import {CachedTargetingGetter} from "lib/ASRouterTargeting.jsm";
|
|
|
|
// Note that tests for the ASRouterTargeting environment can be found in
|
|
// test/functional/mochitest/browser_asrouter_targeting.js
|
|
|
|
describe("#CachedTargetingGetter", () => {
|
|
const sixHours = 6 * 60 * 60 * 1000;
|
|
let sandbox;
|
|
let clock;
|
|
let frecentStub;
|
|
let topsitesCache;
|
|
beforeEach(() => {
|
|
sandbox = sinon.sandbox.create();
|
|
clock = sinon.useFakeTimers();
|
|
frecentStub = sandbox.stub(global.NewTabUtils.activityStreamProvider, "getTopFrecentSites");
|
|
sandbox.stub(global.Cu, "reportError");
|
|
topsitesCache = new CachedTargetingGetter("getTopFrecentSites");
|
|
});
|
|
|
|
afterEach(() => {
|
|
sandbox.restore();
|
|
clock.restore();
|
|
});
|
|
|
|
it("should only make a request every 6 hours", async () => {
|
|
frecentStub.resolves();
|
|
clock.tick(sixHours);
|
|
|
|
await topsitesCache.get();
|
|
await topsitesCache.get();
|
|
|
|
assert.calledOnce(global.NewTabUtils.activityStreamProvider.getTopFrecentSites);
|
|
|
|
clock.tick(sixHours);
|
|
|
|
await topsitesCache.get();
|
|
|
|
assert.calledTwice(global.NewTabUtils.activityStreamProvider.getTopFrecentSites);
|
|
});
|
|
it("should report errors", async () => {
|
|
frecentStub.rejects(new Error("fake error"));
|
|
clock.tick(sixHours);
|
|
|
|
// assert.throws expect a function as the first parameter, try/catch is a
|
|
// workaround
|
|
try {
|
|
await topsitesCache.get();
|
|
assert.isTrue(false);
|
|
} catch (e) {
|
|
assert.calledOnce(global.Cu.reportError);
|
|
}
|
|
});
|
|
});
|