Bug 1149682: Don't cache (or show) sponsored suggested links. r=adw, a=sylvestre
authorMarina Samuel <msamuel@mozilla.com>
Wed, 01 Apr 2015 17:34:21 -0400
changeset 258204 98144ed917cb
parent 258203 96e8fba7c4c4
child 258205 daf8a9291a9b
push id4619
push useredilee@gmail.com
push date2015-04-02 05:50 +0000
treeherdermozilla-beta@daf8a9291a9b [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersadw, sylvestre
bugs1149682
milestone38.0
Bug 1149682: Don't cache (or show) sponsored suggested links. r=adw, a=sylvestre
browser/modules/DirectoryLinksProvider.jsm
browser/modules/test/xpcshell/test_DirectoryLinksProvider.js
--- a/browser/modules/DirectoryLinksProvider.jsm
+++ b/browser/modules/DirectoryLinksProvider.jsm
@@ -207,18 +207,18 @@ let DirectoryLinksProvider = {
   _removePrefsObserver: function DirectoryLinksProvider_removeObserver() {
     for (let pref in this._observedPrefs) {
       let prefName = this._observedPrefs[pref];
       Services.prefs.removeObserver(prefName, this);
     }
   },
 
   _cacheSuggestedLinks: function(link) {
-    if (!link.frecent_sites) {
-      // Don't cache links that don't have the expected 'frecent_sites'.
+    if (!link.frecent_sites || "sponsored" == link.type) {
+      // Don't cache links that don't have the expected 'frecent_sites' or are sponsored.
       return;
     }
     for (let suggestedSite of link.frecent_sites) {
       let suggestedMap = this._suggestedLinks.get(suggestedSite) || new Map();
       suggestedMap.set(link.url, link);
       this._suggestedLinks.set(suggestedSite, suggestedMap);
     }
   },
--- a/browser/modules/test/xpcshell/test_DirectoryLinksProvider.js
+++ b/browser/modules/test/xpcshell/test_DirectoryLinksProvider.js
@@ -60,46 +60,54 @@ const BinaryInputStream = CC("@mozilla.o
                               "nsIBinaryInputStream",
                               "setInputStream");
 
 let gLastRequestPath;
 
 let suggestedTile1 = {
   url: "http://turbotax.com",
   type: "affiliate",
-  lastVisitDate: 3,
+  lastVisitDate: 4,
   frecent_sites: [
     "taxact.com",
     "hrblock.com",
     "1040.com",
     "taxslayer.com"
   ]
 };
 let suggestedTile2 = {
   url: "http://irs.gov",
   type: "affiliate",
-  lastVisitDate: 2,
+  lastVisitDate: 3,
   frecent_sites: [
     "taxact.com",
     "hrblock.com",
     "freetaxusa.com",
     "taxslayer.com"
   ]
 };
 let suggestedTile3 = {
   url: "http://hrblock.com",
   type: "affiliate",
-  lastVisitDate: 1,
+  lastVisitDate: 2,
   frecent_sites: [
     "taxact.com",
     "freetaxusa.com",
     "1040.com",
     "taxslayer.com"
   ]
 };
+let suggestedTile4 = {
+  url: "http://sponsoredtile.com",
+  type: "sponsored",
+  lastVisitDate: 1,
+  frecent_sites: [
+    "sponsoredtarget.com"
+  ]
+}
 let someOtherSite = {url: "http://someothersite.com", title: "Not_A_Suggested_Site"};
 
 function getHttpHandler(path) {
   let code = 200;
   let body = JSON.stringify(kHttpHandlerData[path]);
   if (path == kFailPath) {
     code = 204;
   }
@@ -336,17 +344,17 @@ add_task(function test_updateSuggestedTi
 
   // Cleanup
   yield promiseCleanDirectoryLinksProvider();
   NewTabUtils.isTopPlacesSite = origIsTopPlacesSite;
   NewTabUtils.getProviderLinks = origGetProviderLinks;
 });
 
 add_task(function test_suggestedLinksMap() {
-  let data = {"suggested": [suggestedTile1, suggestedTile2, suggestedTile3], "directory": [someOtherSite]};
+  let data = {"suggested": [suggestedTile1, suggestedTile2, suggestedTile3, suggestedTile4], "directory": [someOtherSite]};
   let dataURI = 'data:application/json,' + JSON.stringify(data);
 
   yield promiseSetupDirectoryLinksProvider({linksURL: dataURI});
   let links = yield fetchData();
 
   // Ensure the suggested tiles were not considered directory tiles.
   do_check_eq(links.length, 1);
   let expected_data = [{url: "http://someothersite.com", title: "Not_A_Suggested_Site", frecency: DIRECTORY_FRECENCY, lastVisitDate: 1}];
@@ -355,16 +363,17 @@ add_task(function test_suggestedLinksMap
   // Check for correctly saved suggested tiles data.
   expected_data = {
     "taxact.com": [suggestedTile1, suggestedTile2, suggestedTile3],
     "hrblock.com": [suggestedTile1, suggestedTile2],
     "1040.com": [suggestedTile1, suggestedTile3],
     "taxslayer.com": [suggestedTile1, suggestedTile2, suggestedTile3],
     "freetaxusa.com": [suggestedTile2, suggestedTile3],
   };
+  do_check_eq([...DirectoryLinksProvider._suggestedLinks.keys()].indexOf("sponsoredtarget.com"), -1);
 
   DirectoryLinksProvider._suggestedLinks.forEach((suggestedLinks, site) => {
     let suggestedLinksItr = suggestedLinks.values();
     for (let link of expected_data[site]) {
       isIdentical(suggestedLinksItr.next().value, link);
     }
   })
 
@@ -477,17 +486,17 @@ add_task(function test_frequencyCappedSi
   Services.prefs.setCharPref(kPingUrlPref, "");
   let origIsTopPlacesSite = NewTabUtils.isTopPlacesSite;
   NewTabUtils.isTopPlacesSite = () => true;
 
   let testUrl = "http://frequency.capped/link";
   let targets = ["top.site.com"];
   let data = {
     suggested: [{
-      type: "sponsored",
+      type: "affiliate",
       frecent_sites: targets,
       url: testUrl
     }],
     directory: [{
       type: "organic",
       url: "http://directory.site/"
     }]
   };
@@ -520,25 +529,25 @@ add_task(function test_frequencyCappedSi
 
   function checkFirstTypeAndLength(type, length) {
     let links = gLinks.getLinks();
     do_check_eq(links[0].type, type);
     do_check_eq(links.length, length);
   }
 
   // Make sure we get 5 views of the link before it is removed
-  checkFirstTypeAndLength("sponsored", 2);
+  checkFirstTypeAndLength("affiliate", 2);
   synthesizeAction("view");
-  checkFirstTypeAndLength("sponsored", 2);
+  checkFirstTypeAndLength("affiliate", 2);
   synthesizeAction("view");
-  checkFirstTypeAndLength("sponsored", 2);
+  checkFirstTypeAndLength("affiliate", 2);
   synthesizeAction("view");
-  checkFirstTypeAndLength("sponsored", 2);
+  checkFirstTypeAndLength("affiliate", 2);
   synthesizeAction("view");
-  checkFirstTypeAndLength("sponsored", 2);
+  checkFirstTypeAndLength("affiliate", 2);
   synthesizeAction("view");
   checkFirstTypeAndLength("organic", 1);
 
   // Cleanup.
   NewTabUtils.isTopPlacesSite = origIsTopPlacesSite;
   gLinks.removeProvider(DirectoryLinksProvider);
   DirectoryLinksProvider.removeObserver(gLinks);
   Services.prefs.setCharPref(kPingUrlPref, kPingUrl);
@@ -548,17 +557,17 @@ add_task(function test_frequencyCappedSi
   Services.prefs.setCharPref(kPingUrlPref, "");
   let origIsTopPlacesSite = NewTabUtils.isTopPlacesSite;
   NewTabUtils.isTopPlacesSite = () => true;
 
   let testUrl = "http://frequency.capped/link";
   let targets = ["top.site.com"];
   let data = {
     suggested: [{
-      type: "sponsored",
+      type: "affiliate",
       frecent_sites: targets,
       url: testUrl
     }],
     directory: [{
       type: "organic",
       url: "http://directory.site/"
     }]
   };
@@ -591,19 +600,19 @@ add_task(function test_frequencyCappedSi
 
   function checkFirstTypeAndLength(type, length) {
     let links = gLinks.getLinks();
     do_check_eq(links[0].type, type);
     do_check_eq(links.length, length);
   }
 
   // Make sure the link disappears after the first click
-  checkFirstTypeAndLength("sponsored", 2);
+  checkFirstTypeAndLength("affiliate", 2);
   synthesizeAction("view");
-  checkFirstTypeAndLength("sponsored", 2);
+  checkFirstTypeAndLength("affiliate", 2);
   synthesizeAction("click");
   checkFirstTypeAndLength("organic", 1);
 
   // Cleanup.
   NewTabUtils.isTopPlacesSite = origIsTopPlacesSite;
   gLinks.removeProvider(DirectoryLinksProvider);
   DirectoryLinksProvider.removeObserver(gLinks);
   Services.prefs.setCharPref(kPingUrlPref, kPingUrl);