Bug 1341527 - Add restrictions mocking to SuggestedSitePreparer test r=sebastian
authorAndrzej Hunt <ahunt@mozilla.com>
Thu, 23 Feb 2017 14:09:04 -0800
changeset 374436 a0d02ea2773152926486f5b39f6fe83954e5c400
parent 374435 9f67d8a507479b15022bce420752b6d7c456a01e
child 374437 90ac7081a45fbccba3cb35e0b49f098b50d0f11c
push id10863
push userjlorenzo@mozilla.com
push dateMon, 06 Mar 2017 23:02:23 +0000
treeherdermozilla-aurora@0931190cd725 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerssebastian
bugs1341527
milestone54.0a1
Bug 1341527 - Add restrictions mocking to SuggestedSitePreparer test r=sebastian MozReview-Commit-ID: 6Eii88A5IHN
mobile/android/tests/background/junit4/src/org/mozilla/gecko/icons/preparation/TestSuggestedSitePreparer.java
--- a/mobile/android/tests/background/junit4/src/org/mozilla/gecko/icons/preparation/TestSuggestedSitePreparer.java
+++ b/mobile/android/tests/background/junit4/src/org/mozilla/gecko/icons/preparation/TestSuggestedSitePreparer.java
@@ -1,25 +1,28 @@
 /* -*- Mode: Java; c-basic-offset: 4; tab-width: 20; indent-tabs-mode: nil; -*-
  * This Source Code Form is subject to the terms of the Mozilla Public
  * License, v. 2.0. If a copy of the MPL was not distributed with this
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 package org.mozilla.gecko.icons.preparation;
 
+import android.content.Context;
+import android.database.Cursor;
+
 import org.junit.Assert;
 import org.junit.Before;
 import org.junit.Test;
 import org.junit.runner.RunWith;
 import org.mozilla.gecko.background.testhelpers.TestRunner;
 import org.mozilla.gecko.db.BrowserDB;
 import org.mozilla.gecko.db.SuggestedSites;
+import org.mozilla.gecko.helpers.MockUserManager;
 import org.mozilla.gecko.icons.IconRequest;
 import org.mozilla.gecko.icons.Icons;
 import org.mozilla.gecko.icons.loader.SuggestedSiteLoader;
-import org.mozilla.gecko.restrictions.Restrictions;
 import org.robolectric.RuntimeEnvironment;
 
 import java.io.IOException;
 
 import static junit.framework.Assert.assertEquals;
 
 @RunWith(TestRunner.class)
 public class TestSuggestedSitePreparer {
@@ -27,20 +30,29 @@ public class TestSuggestedSitePreparer {
             "https://m.facebook.com/",
             "https://m.youtube.com/",
             "https://www.amazon.com/",
             "https://www.wikipedia.org/",
             "https://mobile.twitter.com/"
 
     };
 
+    private Context context;
+
     @Before
     public void setUp() throws IOException {
-        Restrictions.createConfiguration(RuntimeEnvironment.application);
-        BrowserDB.from(RuntimeEnvironment.application).setSuggestedSites(new SuggestedSites(RuntimeEnvironment.application));
+        context = MockUserManager.getContextWithMockedUserManager();
+
+        final SuggestedSites sites = new SuggestedSites(context);
+        BrowserDB.from(context).setSuggestedSites(sites);
+
+        // Force loading sites, so that SuggestedSites is correctly initialised. Without this, we
+        // won't be able to retrieve site data (i.e. icon locations and colours).
+        final Cursor sitesCursor = sites.get(200);
+        sitesCursor.close();
     }
 
     @Test
     public void testNonSuggestedURL() {
         final IconRequest request = Icons.with(RuntimeEnvironment.application)
                 .pageUrl("http://www.mozilla.org")
                 .build();