aboutsummaryrefslogtreecommitdiff
path: root/src/test/java
diff options
context:
space:
mode:
authorRalph Bergmann <ralph@the4thfloor.eu>2013-12-16 19:23:26 +0100
committerRalph Bergmann <ralph@the4thfloor.eu>2014-12-15 12:54:08 +0100
commitced8a98b9ffa3612656b7979f8933ae9cf19d657 (patch)
treeba375755aaaa02798bf436a9ac2b22f314404ca2 /src/test/java
parent1a39583f0ee06329f7918ed9a4c7d0e7cd342917 (diff)
downloadvolley-ced8a98b9ffa3612656b7979f8933ae9cf19d657.tar.gz
Use the view size and scale type to restrict NIV requests.
Change-Id: I77e705c09937f78af746cd73b6e6d94fd4ee2a03
Diffstat (limited to 'src/test/java')
-rw-r--r--src/test/java/com/android/volley/toolbox/ImageRequestTest.java86
-rw-r--r--src/test/java/com/android/volley/toolbox/NetworkImageViewTest.java3
2 files changed, 72 insertions, 17 deletions
diff --git a/src/test/java/com/android/volley/toolbox/ImageRequestTest.java b/src/test/java/com/android/volley/toolbox/ImageRequestTest.java
index 2f4495a..bd98e7d 100644
--- a/src/test/java/com/android/volley/toolbox/ImageRequestTest.java
+++ b/src/test/java/com/android/volley/toolbox/ImageRequestTest.java
@@ -18,7 +18,7 @@ package com.android.volley.toolbox;
import android.graphics.Bitmap;
import android.graphics.Bitmap.Config;
-
+import android.widget.ImageView.ScaleType;
import com.android.volley.NetworkResponse;
import com.android.volley.Response;
import org.junit.Test;
@@ -47,30 +47,84 @@ public class ImageRequestTest {
ShadowBitmapFactory.provideWidthAndHeightHints("fake", 1024, 500);
NetworkResponse jpeg = new NetworkResponse(jpegBytes);
- // No resize
- verifyResize(jpeg, 0, 0, 1024, 500);
+ // Scale the image uniformly (maintain the image's aspect ratio) so that
+ // both dimensions (width and height) of the image will be equal to or
+ // less than the corresponding dimension of the view.
+ ScaleType scalteType = ScaleType.CENTER_INSIDE;
// Exact sizes
- verifyResize(jpeg, 512, 250, 512, 250); // exactly half
- verifyResize(jpeg, 511, 249, 509, 249); // just under half
- verifyResize(jpeg, 1080, 500, 1024, 500); // larger
- verifyResize(jpeg, 500, 500, 500, 244); // keep same ratio
+ verifyResize(jpeg, 512, 250, scalteType, 512, 250); // exactly half
+ verifyResize(jpeg, 511, 249, scalteType, 509, 249); // just under half
+ verifyResize(jpeg, 1080, 500, scalteType, 1024, 500); // larger
+ verifyResize(jpeg, 500, 500, scalteType, 500, 244); // keep same ratio
// Specify only width, preserve aspect ratio
- verifyResize(jpeg, 512, 0, 512, 250);
- verifyResize(jpeg, 800, 0, 800, 390);
- verifyResize(jpeg, 1024, 0, 1024, 500);
+ verifyResize(jpeg, 512, 0, scalteType, 512, 250);
+ verifyResize(jpeg, 800, 0, scalteType, 800, 390);
+ verifyResize(jpeg, 1024, 0, scalteType, 1024, 500);
// Specify only height, preserve aspect ratio
- verifyResize(jpeg, 0, 250, 512, 250);
- verifyResize(jpeg, 0, 391, 800, 391);
- verifyResize(jpeg, 0, 500, 1024, 500);
+ verifyResize(jpeg, 0, 250, scalteType, 512, 250);
+ verifyResize(jpeg, 0, 391, scalteType, 800, 391);
+ verifyResize(jpeg, 0, 500, scalteType, 1024, 500);
+
+ // No resize
+ verifyResize(jpeg, 0, 0, scalteType, 1024, 500);
+
+
+ // Scale the image uniformly (maintain the image's aspect ratio) so that
+ // both dimensions (width and height) of the image will be equal to or
+ // larger than the corresponding dimension of the view.
+ scalteType = ScaleType.CENTER_CROP;
+
+ // Exact sizes
+ verifyResize(jpeg, 512, 250, scalteType, 512, 250);
+ verifyResize(jpeg, 511, 249, scalteType, 511, 249);
+ verifyResize(jpeg, 1080, 500, scalteType, 1024, 500);
+ verifyResize(jpeg, 500, 500, scalteType, 1024, 500);
+
+ // Specify only width
+ verifyResize(jpeg, 512, 0, scalteType, 512, 250);
+ verifyResize(jpeg, 800, 0, scalteType, 800, 390);
+ verifyResize(jpeg, 1024, 0, scalteType, 1024, 500);
+
+ // Specify only height
+ verifyResize(jpeg, 0, 250, scalteType, 512, 250);
+ verifyResize(jpeg, 0, 391, scalteType, 800, 391);
+ verifyResize(jpeg, 0, 500, scalteType, 1024, 500);
+
+ // No resize
+ verifyResize(jpeg, 0, 0, scalteType, 1024, 500);
+
+
+ // Scale in X and Y independently, so that src matches dst exactly. This
+ // may change the aspect ratio of the src.
+ scalteType = ScaleType.FIT_XY;
+
+ // Exact sizes
+ verifyResize(jpeg, 512, 250, scalteType, 512, 250);
+ verifyResize(jpeg, 511, 249, scalteType, 511, 249);
+ verifyResize(jpeg, 1080, 500, scalteType, 1024, 500);
+ verifyResize(jpeg, 500, 500, scalteType, 500, 500);
+
+ // Specify only width
+ verifyResize(jpeg, 512, 0, scalteType, 512, 500);
+ verifyResize(jpeg, 800, 0, scalteType, 800, 500);
+ verifyResize(jpeg, 1024, 0, scalteType, 1024, 500);
+
+ // Specify only height
+ verifyResize(jpeg, 0, 250, scalteType, 1024, 250);
+ verifyResize(jpeg, 0, 391, scalteType, 1024, 391);
+ verifyResize(jpeg, 0, 500, scalteType, 1024, 500);
+
+ // No resize
+ verifyResize(jpeg, 0, 0, scalteType, 1024, 500);
}
private void verifyResize(NetworkResponse networkResponse, int maxWidth, int maxHeight,
- int expectedWidth, int expectedHeight) {
- ImageRequest request = new ImageRequest(
- "", null, maxWidth, maxHeight, Config.RGB_565, null);
+ ScaleType scaleType, int expectedWidth, int expectedHeight) {
+ ImageRequest request = new ImageRequest("", null, maxWidth, maxHeight, scaleType,
+ Config.RGB_565, null);
Response<Bitmap> response = request.parseNetworkResponse(networkResponse);
assertNotNull(response);
assertTrue(response.isSuccess());
diff --git a/src/test/java/com/android/volley/toolbox/NetworkImageViewTest.java b/src/test/java/com/android/volley/toolbox/NetworkImageViewTest.java
index 48c81b6..bc2cc29 100644
--- a/src/test/java/com/android/volley/toolbox/NetworkImageViewTest.java
+++ b/src/test/java/com/android/volley/toolbox/NetworkImageViewTest.java
@@ -1,6 +1,7 @@
package com.android.volley.toolbox;
import android.view.ViewGroup.LayoutParams;
+import android.widget.ImageView.ScaleType;
import org.junit.Before;
import org.junit.Test;
@@ -43,7 +44,7 @@ public class NetworkImageViewTest {
public int lastMaxHeight;
public ImageContainer get(String requestUrl, ImageListener imageListener, int maxWidth,
- int maxHeight) {
+ int maxHeight, ScaleType scaleType) {
lastRequestUrl = requestUrl;
lastMaxWidth = maxWidth;
lastMaxHeight = maxHeight;