Bug 1149021 - Suggested tile with just an image shows a thumbnail instead [r=adw, a=sylvestre]
authorEd Lee <edilee@mozilla.com>
Sun, 29 Mar 2015 23:30:54 -0700
changeset 258201 da2535172770
parent 258200 1d9b014f0414
child 258202 311733df5675
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
bugs1149021
milestone38.0
Bug 1149021 - Suggested tile with just an image shows a thumbnail instead [r=adw, a=sylvestre] Use Object.assign to copy over base values into a new link with extra attributes.
browser/modules/DirectoryLinksProvider.jsm
browser/modules/test/xpcshell/test_DirectoryLinksProvider.js
--- a/browser/modules/DirectoryLinksProvider.jsm
+++ b/browser/modules/DirectoryLinksProvider.jsm
@@ -644,30 +644,26 @@ let DirectoryLinksProvider = {
     }
 
     let flattenedLinks = [...possibleLinks.values()];
 
     // Choose our suggested link at random
     let suggestedIndex = Math.floor(Math.random() * numLinks);
     let chosenSuggestedLink = flattenedLinks[suggestedIndex];
 
-    // Show the new directory tile.
-    this._callObservers("onLinkChanged", {
-      url: chosenSuggestedLink.url,
-      title: chosenSuggestedLink.title,
+    // Add the suggested link to the front with some extra values
+    this._callObservers("onLinkChanged", Object.assign({
       frecency: SUGGESTED_FRECENCY,
-      lastVisitDate: chosenSuggestedLink.lastVisitDate,
-      type: chosenSuggestedLink.type,
 
       // Choose the first site a user has visited as the target. In the future,
       // this should be the site with the highest frecency. However, we currently
       // store frecency by URL not by site.
       targetedSite: targetedSites.get(chosenSuggestedLink.url).length ?
         targetedSites.get(chosenSuggestedLink.url)[0] : null
-    });
+    }, chosenSuggestedLink));
     return chosenSuggestedLink;
    },
 
   /**
    * Return the object to its pre-init state
    */
   reset: function DirectoryLinksProvider_reset() {
     delete this.__linksURL;
--- a/browser/modules/test/xpcshell/test_DirectoryLinksProvider.js
+++ b/browser/modules/test/xpcshell/test_DirectoryLinksProvider.js
@@ -418,16 +418,66 @@ add_task(function test_topSitesWithSugge
   DirectoryLinksProvider._handleLinkChanged({url: "http://" + popped});
   isIdentical([...DirectoryLinksProvider._topSitesWithSuggestedLinks], expectedTopSitesWithSuggestedLinks);
 
   // Cleanup.
   NewTabUtils.isTopPlacesSite = origIsTopPlacesSite;
   NewTabUtils.getProviderLinks = origGetProviderLinks;
 });
 
+add_task(function test_suggestedAttributes() {
+  let origIsTopPlacesSite = NewTabUtils.isTopPlacesSite;
+  NewTabUtils.isTopPlacesSite = () => true;
+
+  let frecent_sites = ["top.site.com"];
+  let imageURI = "https://image/";
+  let title = "the title";
+  let type = "affiliate";
+  let url = "http://test.url/";
+  let data = {
+    suggested: [{
+      frecent_sites,
+      imageURI,
+      title,
+      type,
+      url
+    }]
+  };
+  let dataURI = "data:application/json," + escape(JSON.stringify(data));
+
+  yield promiseSetupDirectoryLinksProvider({linksURL: dataURI});
+
+  // Wait for links to get loaded
+  let gLinks = NewTabUtils.links;
+  gLinks.addProvider(DirectoryLinksProvider);
+  gLinks.populateCache();
+  yield new Promise(resolve => {
+    NewTabUtils.allPages.register({
+      observe: _ => _,
+      update() {
+        NewTabUtils.allPages.unregister(this);
+        resolve();
+      }
+    });
+  });
+
+  // Make sure we get the expected attributes on the suggested tile
+  let link = gLinks.getLinks()[0];
+  do_check_eq(link.imageURI, imageURI);
+  do_check_eq(link.targetedSite, frecent_sites[0]);
+  do_check_eq(link.title, title);
+  do_check_eq(link.type, type);
+  do_check_eq(link.url, url);
+
+  // Cleanup.
+  NewTabUtils.isTopPlacesSite = origIsTopPlacesSite;
+  gLinks.removeProvider(DirectoryLinksProvider);
+  DirectoryLinksProvider.removeObserver(gLinks);
+});
+
 add_task(function test_frequencyCappedSites_views() {
   Services.prefs.setCharPref(kPingUrlPref, "");
   let origIsTopPlacesSite = NewTabUtils.isTopPlacesSite;
   NewTabUtils.isTopPlacesSite = () => true;
 
   let testUrl = "http://frequency.capped/link";
   let targets = ["top.site.com"];
   let data = {