Commit e35725fe authored by Gang Wu's avatar Gang Wu Committed by Commit Bot

[Feed] Remove arbitrary asset loading

Bug:893799

Change-Id: I63a74404f8b4e1782797c0da8acaec7c6050ad3d
Reviewed-on: https://chromium-review.googlesource.com/c/1294400
Commit-Queue: Gang Wu <gangwu@chromium.org>
Reviewed-by: default avatarSky Malice <skym@chromium.org>
Cr-Commit-Position: refs/heads/master@{#601779}
parent fca04e80
...@@ -143,6 +143,9 @@ public class FeedImageLoader implements ImageLoaderApi { ...@@ -143,6 +143,9 @@ public class FeedImageLoader implements ImageLoaderApi {
} }
/** /**
* Translate {@Link BundledAssets} to android drawable resource. This method only translate
* resource name defined in {@Link BundledAssets}.
*
* @param resourceName The name of the drawable asset. * @param resourceName The name of the drawable asset.
* @return The id of the drawable asset. May be 0 if it could not be found. * @return The id of the drawable asset. May be 0 if it could not be found.
*/ */
...@@ -152,10 +155,9 @@ public class FeedImageLoader implements ImageLoaderApi { ...@@ -152,10 +155,9 @@ public class FeedImageLoader implements ImageLoaderApi {
return R.drawable.offline_pin_round; return R.drawable.offline_pin_round;
case BundledAssets.VIDEO_INDICATOR_BADGE: case BundledAssets.VIDEO_INDICATOR_BADGE:
return R.drawable.ic_play_circle_filled_grey; return R.drawable.ic_play_circle_filled_grey;
default:
return mActivityContext.getResources().getIdentifier(
resourceName, DRAWABLE_RESOURCE_TYPE, mActivityContext.getPackageName());
} }
return 0;
} }
/** /**
......
...@@ -51,7 +51,10 @@ public class FeedImageLoaderTest { ...@@ -51,7 +51,10 @@ public class FeedImageLoaderTest {
private static final String HTTP_STRING3 = "http://www.test3.com"; private static final String HTTP_STRING3 = "http://www.test3.com";
private static final String ASSET_PREFIX = "asset://"; private static final String ASSET_PREFIX = "asset://";
private static final String ASSET_STRING = ASSET_PREFIX + "logo_avatar_anonymous"; private static final String OFFLINE_ASSET_STRING =
ASSET_PREFIX + BundledAssets.OFFLINE_INDICATOR_BADGE;
private static final String VIDEO_ASSET_STRING =
ASSET_PREFIX + BundledAssets.VIDEO_INDICATOR_BADGE;
private static final String BAD_ASSET_STRING = ASSET_PREFIX + "does_not_exist"; private static final String BAD_ASSET_STRING = ASSET_PREFIX + "does_not_exist";
private static final String OVERLAY_IMAGE_START = private static final String OVERLAY_IMAGE_START =
...@@ -160,8 +163,15 @@ public class FeedImageLoaderTest { ...@@ -160,8 +163,15 @@ public class FeedImageLoaderTest {
@Test @Test
@SmallTest @SmallTest
public void testLoadDrawableAsset() { public void testLoadOfflineBadge() {
loadDrawable(ASSET_STRING); loadDrawable(OFFLINE_ASSET_STRING);
verify(mConsumer, times(1)).accept(AdditionalMatchers.not(eq(null)));
}
@Test
@SmallTest
public void testLoadVideoBadge() {
loadDrawable(VIDEO_ASSET_STRING);
verify(mConsumer, times(1)).accept(AdditionalMatchers.not(eq(null))); verify(mConsumer, times(1)).accept(AdditionalMatchers.not(eq(null)));
} }
...@@ -175,14 +185,14 @@ public class FeedImageLoaderTest { ...@@ -175,14 +185,14 @@ public class FeedImageLoaderTest {
@Test @Test
@SmallTest @SmallTest
public void testLoadDrawableAssetFallback() { public void testLoadDrawableAssetFallback() {
loadDrawable(BAD_ASSET_STRING, ASSET_STRING); loadDrawable(BAD_ASSET_STRING, OFFLINE_ASSET_STRING);
verify(mConsumer, times(1)).accept(AdditionalMatchers.not(eq(null))); verify(mConsumer, times(1)).accept(AdditionalMatchers.not(eq(null)));
} }
@Test @Test
@SmallTest @SmallTest
public void testLoadDrawableAssetFirst() { public void testLoadDrawableAssetFirst() {
loadDrawable(ASSET_STRING, HTTP_STRING1); loadDrawable(VIDEO_ASSET_STRING, HTTP_STRING1);
verify(mBridge, times(0)) verify(mBridge, times(0))
.fetchImage(eq(HTTP_STRING1), eq(ImageLoaderApi.DIMENSION_UNKNOWN), .fetchImage(eq(HTTP_STRING1), eq(ImageLoaderApi.DIMENSION_UNKNOWN),
eq(ImageLoaderApi.DIMENSION_UNKNOWN), any()); eq(ImageLoaderApi.DIMENSION_UNKNOWN), any());
...@@ -257,18 +267,4 @@ public class FeedImageLoaderTest { ...@@ -257,18 +267,4 @@ public class FeedImageLoaderTest {
public void overlayImageTest_BadDirection() { public void overlayImageTest_BadDirection() {
loadDrawable(OVERLAY_IMAGE_BAD_DIRECTION); loadDrawable(OVERLAY_IMAGE_BAD_DIRECTION);
} }
@Test
@SmallTest
public void testLoadOfflineBadge() {
loadDrawable(ASSET_PREFIX + BundledAssets.OFFLINE_INDICATOR_BADGE);
verify(mConsumer, times(1)).accept(AdditionalMatchers.not(eq(null)));
}
@Test
@SmallTest
public void testLoadVideoBadge() {
loadDrawable(ASSET_PREFIX + BundledAssets.VIDEO_INDICATOR_BADGE);
verify(mConsumer, times(1)).accept(AdditionalMatchers.not(eq(null)));
}
} }
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment