Bug 1388396 - review: Add TestMinimumSizeProcessor. r=mcomella
authorMichael Comella <michael.l.comella@gmail.com>
Tue, 12 Sep 2017 11:33:33 -0700
changeset 430244 84a794ceb84b75cdbe365a7c7c6c430a7927a7b9
parent 430243 bca0b077f039e78fb8fdf6831adfa2d35ef57c88
child 430245 77a524d860a0c2acddbcfe823bf60b6249d42c99
push id7761
push userjlund@mozilla.com
push dateFri, 15 Sep 2017 00:19:52 +0000
treeherdermozilla-beta@c38455951db4 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersmcomella
bugs1388396
milestone57.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1388396 - review: Add TestMinimumSizeProcessor. r=mcomella MozReview-Commit-ID: ADaJL88YZLg
mobile/android/tests/background/junit4/src/org/mozilla/gecko/icons/processing/TestMinimumSizeProcessor.java
new file mode 100644
--- /dev/null
+++ b/mobile/android/tests/background/junit4/src/org/mozilla/gecko/icons/processing/TestMinimumSizeProcessor.java
@@ -0,0 +1,85 @@
+/* Any copyright is dedicated to the Public Domain.
+   http://creativecommons.org/publicdomain/zero/1.0/ */
+
+package org.mozilla.gecko.icons.processing;
+
+import android.graphics.Bitmap;
+import org.junit.Before;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.mockito.Mock;
+import org.mozilla.gecko.background.testhelpers.TestRunner;
+import org.mozilla.gecko.icons.IconRequest;
+import org.mozilla.gecko.icons.IconResponse;
+import org.robolectric.RuntimeEnvironment;
+
+import static org.mockito.Mockito.*;
+
+@RunWith(TestRunner.class)
+public class TestMinimumSizeProcessor {
+
+    private MinimumSizeProcessor processor;
+
+    @Before
+    public void setUp() {
+        processor = new MinimumSizeProcessor();
+    }
+
+    @Test
+    public void testProcessMinimumSizeZeroDoesNotReplaceSmallBitmap() throws Exception {
+        final IconResponse responseMock = getMockResponse(1);
+        processor.process(getMockRequest(0), responseMock);
+
+        verify(responseMock, never()).updateBitmap(any(Bitmap.class));
+        verify(responseMock, never()).updateColor(anyInt());
+    }
+
+    @Test
+    public void testProcessMinimumSizeZeroDoesNotReplaceLargeBitmap() throws Exception {
+        final IconResponse responseMock = getMockResponse(1000);
+        processor.process(getMockRequest(0), responseMock);
+
+        verify(responseMock, never()).updateBitmap(any(Bitmap.class));
+        verify(responseMock, never()).updateColor(anyInt());
+    }
+
+    @Test
+    public void testProcessMinimumSizeFiftyReplacesSmallerBitmap() throws Exception {
+        final IconResponse responseMock = getMockResponse(25);
+        processor.process(getMockRequest(50), responseMock);
+
+        verify(responseMock, atLeastOnce()).updateBitmap(any(Bitmap.class));
+        verify(responseMock, atLeastOnce()).updateColor(anyInt());
+    }
+
+    @Test
+    public void testProcessMinimumSizeFiftyDoesNotReplaceLargerBitmap() throws Exception {
+        final IconResponse responseMock = getMockResponse(1000);
+        processor.process(getMockRequest(50), responseMock);
+
+        verify(responseMock, never()).updateBitmap(any(Bitmap.class));
+        verify(responseMock, never()).updateColor(anyInt());
+    }
+
+    private IconRequest getMockRequest(final int minimumSizePx) {
+        final IconRequest requestMock = mock(IconRequest.class);
+
+        // Under testing.
+        when(requestMock.getMinimumSizePxAfterScaling()).thenReturn(minimumSizePx);
+
+        // Happened to be called.
+        when(requestMock.getPageUrl()).thenReturn("https://mozilla.org");
+        when(requestMock.getContext()).thenReturn(RuntimeEnvironment.application);
+        return requestMock;
+    }
+
+    private IconResponse getMockResponse(final int bitmapWidth) {
+        final Bitmap bitmapMock = mock(Bitmap.class);
+        when(bitmapMock.getWidth()).thenReturn(bitmapWidth);
+        when(bitmapMock.getHeight()).thenReturn(bitmapWidth); // not strictly necessary with the current impl.
+
+        final IconResponse responseMock = mock(IconResponse.class);
+        when(responseMock.getBitmap()).thenReturn(bitmapMock);
+        return responseMock;
+    }
+}
\ No newline at end of file