Commit 2caad8cc authored by Alice Wang's avatar Alice Wang Committed by Commit Bot

[Signin][Android] Parameterize ProfileDataCacheRenderTests

Add more parameters to ProfileDataCacheRenderTests.

Bug: 967770
Change-Id: Ia32abccdfd067391f685ceae6f269c8264b7a4ba
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1859964
Commit-Queue: Alice Wang <aliceywang@chromium.org>
Reviewed-by: default avatarBoris Sazonov <bsazonov@chromium.org>
Cr-Commit-Position: refs/heads/master@{#706888}
parent ccadd0a1
...@@ -24,8 +24,12 @@ import org.junit.Rule; ...@@ -24,8 +24,12 @@ import org.junit.Rule;
import org.junit.Test; import org.junit.Test;
import org.junit.runner.RunWith; import org.junit.runner.RunWith;
import org.chromium.base.test.params.ParameterAnnotations.ClassParameter;
import org.chromium.base.test.params.ParameterAnnotations.UseRunnerDelegate;
import org.chromium.base.test.params.ParameterSet;
import org.chromium.base.test.params.ParameterizedRunner;
import org.chromium.base.test.util.Feature; import org.chromium.base.test.util.Feature;
import org.chromium.chrome.test.ChromeJUnit4ClassRunner; import org.chromium.chrome.test.ChromeJUnit4RunnerDelegate;
import org.chromium.chrome.test.ui.DummyUiActivityTestCase; import org.chromium.chrome.test.ui.DummyUiActivityTestCase;
import org.chromium.chrome.test.util.RenderTestRule; import org.chromium.chrome.test.util.RenderTestRule;
import org.chromium.components.signin.ProfileDataSource; import org.chromium.components.signin.ProfileDataSource;
...@@ -34,16 +38,26 @@ import org.chromium.content_public.browser.test.util.TestThreadUtils; ...@@ -34,16 +38,26 @@ import org.chromium.content_public.browser.test.util.TestThreadUtils;
import org.chromium.ui.widget.ChromeImageView; import org.chromium.ui.widget.ChromeImageView;
import java.io.IOException; import java.io.IOException;
import java.util.Arrays;
import java.util.List;
/** /**
* Tests for ProfileDataCache image scaling. Leverages RenderTest instead of reimplementing * Tests for ProfileDataCache image scaling. Leverages RenderTest instead of reimplementing
* bitmap comparison to simplify access to the compared images on buildbots (via result_details). * bitmap comparison to simplify access to the compared images on buildbots (via result_details).
*/ */
@RunWith(ChromeJUnit4ClassRunner.class) @RunWith(ParameterizedRunner.class)
@UseRunnerDelegate(ChromeJUnit4RunnerDelegate.class)
public class ProfileDataCacheRenderTest extends DummyUiActivityTestCase { public class ProfileDataCacheRenderTest extends DummyUiActivityTestCase {
// Anything different than logo_avatar_anonymous size should work. @ClassParameter
// TODO(https://crbug.com/967770): Make parameterized and test scaling to different sizes. private static final List<ParameterSet> sClassParams =
private static final @Px int IMAGE_SIZE = 64; Arrays.asList(new ParameterSet().value(64).name("ImageSize64"),
new ParameterSet().value(128).name("ImageSize128"));
private final @Px int mImageSize;
public ProfileDataCacheRenderTest(int imageSize) {
mImageSize = imageSize;
}
@Rule @Rule
public RenderTestRule mRenderTestRule = public RenderTestRule mRenderTestRule =
...@@ -66,7 +80,7 @@ public class ProfileDataCacheRenderTest extends DummyUiActivityTestCase { ...@@ -66,7 +80,7 @@ public class ProfileDataCacheRenderTest extends DummyUiActivityTestCase {
mProfileDataSource = new FakeProfileDataSource(); mProfileDataSource = new FakeProfileDataSource();
mProfileDataCache = mProfileDataCache =
new ProfileDataCache(getActivity(), IMAGE_SIZE, null, mProfileDataSource); new ProfileDataCache(getActivity(), mImageSize, null, mProfileDataSource);
// ProfileDataCache only populates the cache when an observer is added. // ProfileDataCache only populates the cache when an observer is added.
mProfileDataCache.addObserver(accountId -> {}); mProfileDataCache.addObserver(accountId -> {});
}); });
...@@ -76,17 +90,10 @@ public class ProfileDataCacheRenderTest extends DummyUiActivityTestCase { ...@@ -76,17 +90,10 @@ public class ProfileDataCacheRenderTest extends DummyUiActivityTestCase {
@MediumTest @MediumTest
@Feature("RenderTest") @Feature("RenderTest")
public void testPlaceholderIsScaled() throws IOException { public void testPlaceholderIsScaled() throws IOException {
TestThreadUtils.runOnUiThreadBlocking(() -> { TestThreadUtils.runOnUiThreadBlocking(
String accountName = "no.data.for.this.account@example.com"; () -> { checkImageIsScaled("no.data.for.this.account@example.com"); });
DisplayableProfileData displayableProfileData =
mProfileDataCache.getProfileDataOrDefault(accountName);
Drawable placeholderImage = displayableProfileData.getImage();
assertEquals(IMAGE_SIZE, placeholderImage.getIntrinsicHeight());
assertEquals(IMAGE_SIZE, placeholderImage.getIntrinsicWidth());
mImageView.setImageDrawable(placeholderImage);
});
mRenderTestRule.render(mImageView, "profile_data_cache_placeholder"); mRenderTestRule.render(mImageView, "profile_data_cache_placeholder" + mImageSize);
} }
@Test @Test
...@@ -98,16 +105,19 @@ public class ProfileDataCacheRenderTest extends DummyUiActivityTestCase { ...@@ -98,16 +105,19 @@ public class ProfileDataCacheRenderTest extends DummyUiActivityTestCase {
ProfileDataSource.ProfileData profileData = new ProfileDataSource.ProfileData( ProfileDataSource.ProfileData profileData = new ProfileDataSource.ProfileData(
accountName, createAvatar(), "Full Name", "Given Name"); accountName, createAvatar(), "Full Name", "Given Name");
mProfileDataSource.setProfileData(accountName, profileData); mProfileDataSource.setProfileData(accountName, profileData);
checkImageIsScaled(accountName);
DisplayableProfileData displayableProfileData =
mProfileDataCache.getProfileDataOrDefault(accountName);
Drawable placeholderImage = displayableProfileData.getImage();
assertEquals(IMAGE_SIZE, placeholderImage.getIntrinsicHeight());
assertEquals(IMAGE_SIZE, placeholderImage.getIntrinsicWidth());
mImageView.setImageDrawable(placeholderImage);
}); });
mRenderTestRule.render(mImageView, "profile_data_cache_avatar"); mRenderTestRule.render(mImageView, "profile_data_cache_avatar" + mImageSize);
}
private void checkImageIsScaled(String accountName) {
DisplayableProfileData displayableProfileData =
mProfileDataCache.getProfileDataOrDefault(accountName);
Drawable placeholderImage = displayableProfileData.getImage();
assertEquals(mImageSize, placeholderImage.getIntrinsicHeight());
assertEquals(mImageSize, placeholderImage.getIntrinsicWidth());
mImageView.setImageDrawable(placeholderImage);
} }
/** /**
...@@ -116,7 +126,7 @@ public class ProfileDataCacheRenderTest extends DummyUiActivityTestCase { ...@@ -116,7 +126,7 @@ public class ProfileDataCacheRenderTest extends DummyUiActivityTestCase {
*/ */
private Bitmap createAvatar() { private Bitmap createAvatar() {
final int avatarSize = 100; final int avatarSize = 100;
assertNotEquals("Should be different to test scaling", IMAGE_SIZE, avatarSize); assertNotEquals("Should be different to test scaling", mImageSize, avatarSize);
Bitmap result = Bitmap.createBitmap(avatarSize, avatarSize, Bitmap.Config.ARGB_8888); Bitmap result = Bitmap.createBitmap(avatarSize, avatarSize, Bitmap.Config.ARGB_8888);
Canvas canvas = new Canvas(result); Canvas canvas = new Canvas(result);
......
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