From 1afd3a5c8e545041158cfd72de08e8ebe43817ce Mon Sep 17 00:00:00 2001 From: Nan Jiang Date: Mon, 5 Jul 2021 13:22:33 +0000 Subject: [PATCH] Bug 1718749 - Filter blocked sponsored top sites from RemoteSettings when Contile is enabled r=dao Differential Revision: https://phabricator.services.mozilla.com/D119019 --- .../components/newtab/lib/TopSitesFeed.jsm | 1 - .../newtab/test/unit/lib/TopSitesFeed.test.js | 21 ++++++++++++++++++- 2 files changed, 20 insertions(+), 2 deletions(-) diff --git a/browser/components/newtab/lib/TopSitesFeed.jsm b/browser/components/newtab/lib/TopSitesFeed.jsm index 75a0e0214e85..c7953ed1968b 100644 --- a/browser/components/newtab/lib/TopSitesFeed.jsm +++ b/browser/components/newtab/lib/TopSitesFeed.jsm @@ -363,7 +363,6 @@ this.TopSitesFeed = class TopSitesFeed { // Also drop those sponsored sites that were blocked by the user before // with the same hostname. if ( - !contileEnabled && siteData.sponsored_position && sponsoredBlocklist.includes(hostname) ) { diff --git a/browser/components/newtab/test/unit/lib/TopSitesFeed.test.js b/browser/components/newtab/test/unit/lib/TopSitesFeed.test.js index d39077054e9c..a180a563d752 100644 --- a/browser/components/newtab/test/unit/lib/TopSitesFeed.test.js +++ b/browser/components/newtab/test/unit/lib/TopSitesFeed.test.js @@ -2168,12 +2168,31 @@ describe("Top Sites Feed", () => { sandbox.restore(); }); - it("should filter all blocked sponsored tiles from RemoteSettings", async () => { + it("should filter all blocked sponsored tiles from RemoteSettings when Contile is disabled", async () => { sandbox.stub(feed, "_getRemoteConfig").resolves([ { url: "https://foo.com", title: "foo", sponsored_position: 1 }, { url: "https://bar.com", title: "bar", sponsored_position: 2 }, { url: "https://test.com", title: "test", sponsored_position: 3 }, ]); + global.Services.prefs.getStringPref + .withArgs(CONTILE_ENABLED_PREF) + .returns(false); + + await feed._readDefaults(); + + assert.equal(DEFAULT_TOP_SITES.length, 1); + assert.equal(DEFAULT_TOP_SITES[0].label, "test"); + }); + + it("should also filter all blocked sponsored tiles from RemoteSettings when Contile is enabled", async () => { + sandbox.stub(feed, "_getRemoteConfig").resolves([ + { url: "https://foo.com", title: "foo", sponsored_position: 1 }, + { url: "https://bar.com", title: "bar", sponsored_position: 2 }, + { url: "https://test.com", title: "test", sponsored_position: 3 }, + ]); + global.Services.prefs.getStringPref + .withArgs(CONTILE_ENABLED_PREF) + .returns(true); await feed._readDefaults();