Loading browser/components/newtab/lib/TopSitesFeed.jsm +10 −5 Original line number Diff line number Diff line Loading @@ -74,6 +74,13 @@ ChromeUtils.defineModuleGetter( XPCOMUtils.defineLazyGlobalGetters(this, ["fetch"]); XPCOMUtils.defineLazyGetter(this, "log", () => { const { Logger } = ChromeUtils.import( "resource://messaging-system/lib/Logger.jsm" ); return new Logger("TopSitesFeed"); }); const DEFAULT_SITES_PREF = "default.sites"; const SHOWN_ON_NEWTAB_PREF = "feeds.topsites"; const DEFAULT_TOP_SITES = []; Loading Loading @@ -171,7 +178,7 @@ class ContileIntegration { let url = Services.prefs.getStringPref(CONTILE_ENDPOINT_PREF); const response = await fetch(url, { credentials: "omit" }); if (!response.ok) { Cu.reportError( log.warn( `Contile endpoint returned unexpected status: ${response.status}` ); } Loading @@ -188,7 +195,7 @@ class ContileIntegration { let { tiles } = body; tiles = this._filterBlockedSponsors(tiles); if (tiles.length > MAX_NUM_SPONSORED) { Cu.reportError( log.warn( `Contile provided more links than permitted. (${tiles.length} received, limit is ${MAX_NUM_SPONSORED})` ); tiles.length = MAX_NUM_SPONSORED; Loading @@ -197,9 +204,7 @@ class ContileIntegration { return true; } } catch (error) { Cu.reportError( `Failed to fetch data from Contile server: ${error.message}` ); log.warn(`Failed to fetch data from Contile server: ${error.message}`); } return false; } Loading browser/components/newtab/test/unit/lib/TopSitesFeed.test.js +9 −7 Original line number Diff line number Diff line Loading @@ -160,13 +160,15 @@ describe("Top Sites Feed", () => { } describe("#constructor", () => { it("should defineLazyGetter for _currentSearchHostname", () => { assert.calledOnce(global.XPCOMUtils.defineLazyGetter); assert.calledWith( global.XPCOMUtils.defineLazyGetter, feed, "_currentSearchHostname", sinon.match.func it("should defineLazyGetter for log and _currentSearchHostname", () => { assert.calledTwice(global.XPCOMUtils.defineLazyGetter); let spyCall = global.XPCOMUtils.defineLazyGetter.getCall(0); assert.ok(spyCall.calledWith(sinon.match.any, "log", sinon.match.func)); spyCall = global.XPCOMUtils.defineLazyGetter.getCall(1); assert.ok( spyCall.calledWith(feed, "_currentSearchHostname", sinon.match.func) ); }); }); Loading browser/components/newtab/test/unit/unit-entry.js +9 −0 Original line number Diff line number Diff line Loading @@ -66,6 +66,14 @@ class JSWindowActorChild { } } class Logger { constructor(name) { this.name = name; } warn() {} } const TEST_GLOBAL = { JSWindowActorParent, JSWindowActorChild, Loading Loading @@ -509,6 +517,7 @@ const TEST_GLOBAL = { gUUIDGenerator: { generateUUID: () => "{foo-123-foo}", }, Logger, }; TEST_GLOBAL.NimbusFeatures.pocketNewtab = TEST_GLOBAL.NimbusFeatures.newtab; overrider.set(TEST_GLOBAL); Loading Loading
browser/components/newtab/lib/TopSitesFeed.jsm +10 −5 Original line number Diff line number Diff line Loading @@ -74,6 +74,13 @@ ChromeUtils.defineModuleGetter( XPCOMUtils.defineLazyGlobalGetters(this, ["fetch"]); XPCOMUtils.defineLazyGetter(this, "log", () => { const { Logger } = ChromeUtils.import( "resource://messaging-system/lib/Logger.jsm" ); return new Logger("TopSitesFeed"); }); const DEFAULT_SITES_PREF = "default.sites"; const SHOWN_ON_NEWTAB_PREF = "feeds.topsites"; const DEFAULT_TOP_SITES = []; Loading Loading @@ -171,7 +178,7 @@ class ContileIntegration { let url = Services.prefs.getStringPref(CONTILE_ENDPOINT_PREF); const response = await fetch(url, { credentials: "omit" }); if (!response.ok) { Cu.reportError( log.warn( `Contile endpoint returned unexpected status: ${response.status}` ); } Loading @@ -188,7 +195,7 @@ class ContileIntegration { let { tiles } = body; tiles = this._filterBlockedSponsors(tiles); if (tiles.length > MAX_NUM_SPONSORED) { Cu.reportError( log.warn( `Contile provided more links than permitted. (${tiles.length} received, limit is ${MAX_NUM_SPONSORED})` ); tiles.length = MAX_NUM_SPONSORED; Loading @@ -197,9 +204,7 @@ class ContileIntegration { return true; } } catch (error) { Cu.reportError( `Failed to fetch data from Contile server: ${error.message}` ); log.warn(`Failed to fetch data from Contile server: ${error.message}`); } return false; } Loading
browser/components/newtab/test/unit/lib/TopSitesFeed.test.js +9 −7 Original line number Diff line number Diff line Loading @@ -160,13 +160,15 @@ describe("Top Sites Feed", () => { } describe("#constructor", () => { it("should defineLazyGetter for _currentSearchHostname", () => { assert.calledOnce(global.XPCOMUtils.defineLazyGetter); assert.calledWith( global.XPCOMUtils.defineLazyGetter, feed, "_currentSearchHostname", sinon.match.func it("should defineLazyGetter for log and _currentSearchHostname", () => { assert.calledTwice(global.XPCOMUtils.defineLazyGetter); let spyCall = global.XPCOMUtils.defineLazyGetter.getCall(0); assert.ok(spyCall.calledWith(sinon.match.any, "log", sinon.match.func)); spyCall = global.XPCOMUtils.defineLazyGetter.getCall(1); assert.ok( spyCall.calledWith(feed, "_currentSearchHostname", sinon.match.func) ); }); }); Loading
browser/components/newtab/test/unit/unit-entry.js +9 −0 Original line number Diff line number Diff line Loading @@ -66,6 +66,14 @@ class JSWindowActorChild { } } class Logger { constructor(name) { this.name = name; } warn() {} } const TEST_GLOBAL = { JSWindowActorParent, JSWindowActorChild, Loading Loading @@ -509,6 +517,7 @@ const TEST_GLOBAL = { gUUIDGenerator: { generateUUID: () => "{foo-123-foo}", }, Logger, }; TEST_GLOBAL.NimbusFeatures.pocketNewtab = TEST_GLOBAL.NimbusFeatures.newtab; overrider.set(TEST_GLOBAL); Loading