diff --git a/system-addon/lib/TopSitesFeed.jsm b/system-addon/lib/TopSitesFeed.jsm index 9069269842..2681692b67 100644 --- a/system-addon/lib/TopSitesFeed.jsm +++ b/system-addon/lib/TopSitesFeed.jsm @@ -26,7 +26,6 @@ this.TopSitesFeed = class TopSitesFeed { constructor() { this.lastUpdated = 0; this._tippyTopProvider = new TippyTopProvider(); - this._tippyTopProvider.init(); this.dedupe = new Dedupe(this._dedupeKey); } _dedupeKey(site) { @@ -137,8 +136,12 @@ this.TopSitesFeed = class TopSitesFeed { data: this._getPinnedWithData() })); } - onAction(action) { + async onAction(action) { switch (action.type) { + case at.INIT: + await this._tippyTopProvider.init(); + this.refresh(); + break; case at.NEW_TAB_LOAD: if ( // When a new tab is opened, if the last time we refreshed the data diff --git a/system-addon/test/unit/lib/TopSitesFeed.test.js b/system-addon/test/unit/lib/TopSitesFeed.test.js index 8963e99283..20ebade855 100644 --- a/system-addon/test/unit/lib/TopSitesFeed.test.js +++ b/system-addon/test/unit/lib/TopSitesFeed.test.js @@ -10,7 +10,7 @@ const FAKE_SCREENSHOT = "data123"; function FakeTippyTopProvider() {} FakeTippyTopProvider.prototype = { - init() {}, + async init() {}, processSite(site) { return site; } }; @@ -335,5 +335,10 @@ describe("Top Sites Feed", () => { assert.calledOnce(feed.store.dispatch); assert.propertyVal(feed.store.dispatch.firstCall.args[0], "type", at.TOP_SITES_UPDATED); }); + it("should call refresh on INIT action", async () => { + sinon.stub(feed, "refresh"); + await feed.onAction({type: at.INIT}); + assert.calledOnce(feed.refresh); + }); }); });