Bug 1290014 - Add additional unit tests. r=ahunt,Grisha
authorSebastian Kaspari <s.kaspari@gmail.com>
Thu, 18 Aug 2016 14:10:49 +0200
changeset 312472 a87ed908d84b5d3a6d3a8dbed171608ff4d6b33c
parent 312471 9b852e0472ff46f4e8a4c0888fd7d2925c001efd
child 312473 f11ee12c87bbfeab4b25b4b30c9aa0f7aefc982c
push id20447
push userkwierso@gmail.com
push dateFri, 02 Sep 2016 20:36:44 +0000
treeherderfx-team@969397f22187 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersahunt, Grisha
bugs1290014
milestone51.0a1
Bug 1290014 - Add additional unit tests. r=ahunt,Grisha MozReview-Commit-ID: Ib5OI7eb2sq
mobile/android/tests/background/junit4/src/org/mozilla/gecko/icons/TestIconRequestBuilder.java
mobile/android/tests/background/junit4/src/org/mozilla/gecko/icons/TestIconTask.java
--- a/mobile/android/tests/background/junit4/src/org/mozilla/gecko/icons/TestIconRequestBuilder.java
+++ b/mobile/android/tests/background/junit4/src/org/mozilla/gecko/icons/TestIconRequestBuilder.java
@@ -2,16 +2,17 @@
    http://creativecommons.org/publicdomain/zero/1.0/ */
 
 package org.mozilla.gecko.icons;
 
 import org.junit.Assert;
 
 import org.junit.Test;
 import org.junit.runner.RunWith;
+import org.mozilla.gecko.GeckoAppShell;
 import org.mozilla.gecko.background.testhelpers.TestRunner;
 import org.robolectric.RuntimeEnvironment;
 
 @RunWith(TestRunner.class)
 public class TestIconRequestBuilder {
     private static final String TEST_PAGE_URL_1 = "http://www.mozilla.org";
     private static final String TEST_PAGE_URL_2 = "http://www.example.org";
     private static final String TEST_ICON_URL_1 = "http://www.mozilla.org/favicon.ico";
@@ -132,9 +133,27 @@ public class TestIconRequestBuilder {
         Assert.assertFalse(request.shouldRunOnBackgroundThread());
 
         request.modify()
                 .executeCallbackOnBackgroundThread()
                 .deferBuild();
 
         Assert.assertTrue(request.shouldRunOnBackgroundThread());
     }
+
+    @Test
+    public void testForLauncherIcon() {
+        // This code will call into GeckoAppShell to determine the launcher icon size for this configuration
+        GeckoAppShell.setApplicationContext(RuntimeEnvironment.application);
+
+        IconRequest request = Icons.with(RuntimeEnvironment.application)
+                .pageUrl(TEST_PAGE_URL_1)
+                .build();
+
+        Assert.assertEquals(32, request.getTargetSize());
+
+        request.modify()
+                .forLauncherIcon()
+                .deferBuild();
+
+        Assert.assertEquals(48, request.getTargetSize());
+    }
 }
--- a/mobile/android/tests/background/junit4/src/org/mozilla/gecko/icons/TestIconTask.java
+++ b/mobile/android/tests/background/junit4/src/org/mozilla/gecko/icons/TestIconTask.java
@@ -459,16 +459,55 @@ public class TestIconTask {
         }
 
         // Verify that no processors are called
         for (Processor processor : processors) {
             verify(processor, never()).process(eq(request), any(IconResponse.class));
         }
     }
 
+    @Test
+    public void testNoLoadersOrProcessorsAreExecutedForPrepareOnlyTasks() {
+        final List<Preparer> preparers = createListOfPreparers();
+        final List<IconLoader> loaders = createListWithSuccessfulLoader();
+        final List<Processor> processors = createListOfProcessors();
+        final IconLoader generator = createGenerator();
+
+        final IconRequest request = createIconRequest()
+                .modify()
+                .prepareOnly()
+                .build();
+
+        final IconTask task = new IconTask(
+                request,
+                preparers,
+                loaders,
+                processors,
+                generator);
+
+        IconResponse response = task.call();
+
+        Assert.assertNull(response);
+
+        // Verify that all preparers are called
+        for (Preparer preparer : preparers) {
+            verify(preparer).prepare(request);
+        }
+
+        // Verify that no loaders are called
+        for (IconLoader loader : loaders) {
+            verify(loader, never()).load(request);
+        }
+
+        // Verify that no processors are called
+        for (Processor processor : processors) {
+            verify(processor, never()).process(eq(request), any(IconResponse.class));
+        }
+    }
+
     public List<IconLoader> createListWithSuccessfulLoader() {
         return Arrays.asList(
                 createFailingLoader(),
                 createFailingLoader(),
                 createSuccessfulLoader(mock(Bitmap.class)),
                 createFailingLoader());
     }