Bug 1126184: Part 3: Mochitest fixes for suggested tiles. r=adw, a=sylvestre
authorMarina Samuel <msamuel@mozilla.com>
Fri, 13 Mar 2015 11:45:38 -0400
changeset 258190 1a007e477655
parent 258189 48564fb0e663
child 258191 e9021ea8d7ca
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
bugs1126184
milestone38.0
Bug 1126184: Part 3: Mochitest fixes for suggested tiles. r=adw, a=sylvestre
browser/base/content/test/newtab/browser_newtab_drag_drop.js
browser/base/content/test/newtab/browser_newtab_drag_drop_ext.js
browser/base/content/test/newtab/browser_newtab_drop_preview.js
browser/modules/DirectoryLinksProvider.jsm
toolkit/modules/NewTabUtils.jsm
--- a/browser/base/content/test/newtab/browser_newtab_drag_drop.js
+++ b/browser/base/content/test/newtab/browser_newtab_drag_drop.js
@@ -4,16 +4,17 @@
 /*
  * These tests make sure that dragging and dropping sites works as expected.
  * Sites contained in the grid need to shift around to indicate the result
  * of the drag-and-drop operation. If the grid is full and we're dragging
  * a new site into it another one gets pushed out.
  */
 function runTests() {
   requestLongerTimeout(2);
+  yield addNewTabPageTab();
 
   // test a simple drag-and-drop scenario
   yield setLinks("0,1,2,3,4,5,6,7,8");
   setPinnedLinks("");
 
   yield addNewTabPageTab();
   checkGrid("0,1,2,3,4,5,6,7,8");
 
--- a/browser/base/content/test/newtab/browser_newtab_drag_drop_ext.js
+++ b/browser/base/content/test/newtab/browser_newtab_drag_drop_ext.js
@@ -8,16 +8,17 @@ const PREF_NEWTAB_COLUMNS = "browser.new
  * Sites contained in the grid need to shift around to indicate the result
  * of the drag-and-drop operation. If the grid is full and we're dragging
  * a new site into it another one gets pushed out.
  * This is a continuation of browser_newtab_drag_drop.js
  * to decrease test run time, focusing on external sites.
  */
 function runTests() {
   registerCleanupFunction(_ => Services.prefs.clearUserPref(PREF_NEWTAB_COLUMNS));
+  yield addNewTabPageTab();
 
   // drag a new site onto the very first cell
   yield setLinks("0,1,2,3,4,5,6,7,8");
   setPinnedLinks(",,,,,,,7,8");
 
   yield addNewTabPageTab();
   checkGrid("0,1,2,3,4,5,6,7p,8p");
 
--- a/browser/base/content/test/newtab/browser_newtab_drop_preview.js
+++ b/browser/base/content/test/newtab/browser_newtab_drop_preview.js
@@ -1,16 +1,18 @@
 /* Any copyright is dedicated to the Public Domain.
    http://creativecommons.org/publicdomain/zero/1.0/ */
 
 /*
  * These tests ensure that the drop preview correctly arranges sites when
  * dragging them around.
  */
 function runTests() {
+  yield addNewTabPageTab();
+
   // the first three sites are pinned - make sure they're re-arranged correctly
   yield setLinks("0,1,2,3,4,5,6,7,8");
   setPinnedLinks("0,1,2,,,5");
 
   yield addNewTabPageTab();
   checkGrid("0p,1p,2p,3,4,5p,6,7,8");
 
   let cw = getContentWindow();
--- a/browser/modules/DirectoryLinksProvider.jsm
+++ b/browser/modules/DirectoryLinksProvider.jsm
@@ -526,16 +526,22 @@ let DirectoryLinksProvider = {
    * Chooses and returns a related tile based on a user's top sites
    * that we have an available related tile for.
    *
    * @return the chosen related tile, or undefined if there isn't one
    */
   _updateRelatedTile: function() {
     let sortedLinks = NewTabUtils.getProviderLinks(this);
 
+    if (!sortedLinks) {
+      // If NewTabUtils.links.resetCache() is called before getting here,
+      // sortedLinks may be undefined.
+      return;
+    }
+
     // Delete the current related tile, if one exists.
     let initialLength = sortedLinks.length;
     this.maxNumLinks = initialLength;
     if (initialLength) {
       let mostFrecentLink = sortedLinks[0];
       if ("related" == mostFrecentLink.type) {
         this._callObservers("onLinkChanged", {
           url: mostFrecentLink.url,
--- a/toolkit/modules/NewTabUtils.jsm
+++ b/toolkit/modules/NewTabUtils.jsm
@@ -931,17 +931,17 @@ let Links = {
   /**
    * Merges the cached lists of links from all providers whose lists are cached.
    * @return The merged list.
    */
   _getMergedProviderLinks: function Links__getMergedProviderLinks() {
     // Build a list containing a copy of each provider's sortedLinks list.
     let linkLists = [];
     for (let links of this._providers.values()) {
-      if (links) {
+      if (links && links.sortedLinks) {
         linkLists.push(links.sortedLinks.slice());
       }
     }
 
     function getNextLink() {
       let minLinks = null;
       for (let links of linkLists) {
         if (links.length &&