| Index: chrome/android/javatests/src/org/chromium/chrome/browser/webapps/WebappSplashScreenTest.java
|
| diff --git a/chrome/android/javatests/src/org/chromium/chrome/browser/webapps/WebappSplashScreenTest.java b/chrome/android/javatests/src/org/chromium/chrome/browser/webapps/WebappSplashScreenTest.java
|
| index 99db40daf48a13cac6da23fe56aaeb7efc146eb5..40e1060bbcdcdcd8e22e9b08b6fbe65578930b94 100644
|
| --- a/chrome/android/javatests/src/org/chromium/chrome/browser/webapps/WebappSplashScreenTest.java
|
| +++ b/chrome/android/javatests/src/org/chromium/chrome/browser/webapps/WebappSplashScreenTest.java
|
| @@ -7,64 +7,92 @@ package org.chromium.chrome.browser.webapps;
|
| import android.annotation.TargetApi;
|
| import android.graphics.Bitmap;
|
| import android.graphics.Color;
|
| -import android.graphics.drawable.BitmapDrawable;
|
| import android.os.Build;
|
| -import android.test.UiThreadTest;
|
| import android.test.suitebuilder.annotation.SmallTest;
|
| -import android.view.ViewGroup;
|
| -import android.widget.ImageView;
|
|
|
| import org.chromium.base.ObserverList.RewindableIterator;
|
| import org.chromium.base.ThreadUtils;
|
| +import org.chromium.base.metrics.RecordHistogram;
|
| import org.chromium.base.test.util.Feature;
|
| -import org.chromium.chrome.R;
|
| import org.chromium.chrome.browser.ShortcutHelper;
|
| import org.chromium.chrome.browser.ShortcutSource;
|
| +import org.chromium.chrome.browser.metrics.WebappUma;
|
| import org.chromium.chrome.browser.tab.TabObserver;
|
| -import org.chromium.content.browser.test.util.Criteria;
|
| -import org.chromium.content.browser.test.util.CriteriaHelper;
|
| import org.chromium.content_public.common.ScreenOrientationValues;
|
|
|
| /**
|
| - * Tests for splashscreen.
|
| + * Tests for splash screens.
|
| */
|
| public class WebappSplashScreenTest extends WebappActivityTestBase {
|
| - @UiThreadTest
|
| - @SmallTest
|
| - @Feature({"Webapps"})
|
| - public void testDoesntUseSmallWebappInfoIcons() {
|
| - int smallSize = getActivity().getResources().getDimensionPixelSize(
|
| - R.dimen.webapp_splash_image_min_size) - 1;
|
| - Bitmap image = Bitmap.createBitmap(smallSize, smallSize, Bitmap.Config.ARGB_8888);
|
| - setActivityWebappInfoFromBitmap(image);
|
| -
|
| - ViewGroup splashScreen = getActivity().createSplashScreen(null);
|
| - getActivity().setSplashScreenIconAndText(splashScreen, null, Color.WHITE);
|
| -
|
| - ImageView splashImage = (ImageView) splashScreen.findViewById(
|
| - R.id.webapp_splash_screen_icon);
|
| - assertNull(splashImage.getDrawable());
|
| +
|
| + private int getHistogramTotalCountFor(String histogram, int buckets) {
|
| + int count = 0;
|
| +
|
| + for (int i = 0; i < buckets; ++i) {
|
| + count += RecordHistogram.getHistogramValueCountForTesting(histogram, i);
|
| + }
|
| +
|
| + return count;
|
| }
|
|
|
| - @UiThreadTest
|
| - @SmallTest
|
| - @Feature({"Webapps"})
|
| - public void testUsesMinWebappInfoIcons() {
|
| - int minSizePx = getActivity().getResources().getDimensionPixelSize(
|
| - R.dimen.webapp_splash_image_min_size);
|
| - Bitmap image = Bitmap.createBitmap(minSizePx, minSizePx, Bitmap.Config.ARGB_8888);
|
| - setActivityWebappInfoFromBitmap(image);
|
| -
|
| - ViewGroup splashScreen = getActivity().createSplashScreen(null);
|
| - getActivity().setSplashScreenIconAndText(splashScreen, null, Color.WHITE);
|
| -
|
| - ImageView splashImage = (ImageView) splashScreen.findViewById(
|
| - R.id.webapp_splash_screen_icon);
|
| - BitmapDrawable drawable = (BitmapDrawable) splashImage.getDrawable();
|
| - assertEquals(minSizePx, drawable.getBitmap().getWidth());
|
| - assertEquals(minSizePx, drawable.getBitmap().getHeight());
|
| + private boolean hasHistogramEntry(String histogram, int maxValue) {
|
| + for (int i = 0; i < maxValue; ++i) {
|
| + if (RecordHistogram.getHistogramValueCountForTesting(histogram, i) > 0) {
|
| + return true;
|
| + }
|
| + }
|
| + return false;
|
| + }
|
| +
|
| + private void setActivityWebappInfoFromBitmap(Bitmap image) {
|
| + WebappInfo mockInfo = WebappInfo.create(WEBAPP_ID, "about:blank",
|
| + ShortcutHelper.encodeBitmapAsString(image), null, null,
|
| + ScreenOrientationValues.DEFAULT, ShortcutSource.UNKNOWN,
|
| + ShortcutHelper.MANIFEST_COLOR_INVALID_OR_MISSING,
|
| + ShortcutHelper.MANIFEST_COLOR_INVALID_OR_MISSING);
|
| + getActivity().getWebappInfo().copy(mockInfo);
|
| }
|
|
|
| + // TODO(mlamouri): disabling them because they hit an UMA assert. These
|
| + // tests are being replaced by better other tests in:
|
| + // https://codereview.chromium.org/1414873004
|
| + //
|
| + // @UiThreadTest
|
| + // @SmallTest
|
| + // @Feature({"Webapps"})
|
| + // public void testDoesntUseSmallWebappInfoIcons() {
|
| + // int smallSize = getActivity().getResources().getDimensionPixelSize(
|
| + // R.dimen.webapp_splash_image_min_size) - 1;
|
| + // Bitmap image = Bitmap.createBitmap(smallSize, smallSize, Bitmap.Config.ARGB_8888);
|
| + // setActivityWebappInfoFromBitmap(image);
|
| + //
|
| + // ViewGroup splashScreen = getActivity().createSplashScreen(null);
|
| + // getActivity().setSplashScreenIconAndText(splashScreen, null, Color.WHITE);
|
| + //
|
| + // ImageView splashImage = (ImageView) splashScreen.findViewById(
|
| + // R.id.webapp_splash_screen_icon);
|
| + // assertNull(splashImage.getDrawable());
|
| + // }
|
| + //
|
| + // @UiThreadTest
|
| + // @SmallTest
|
| + // @Feature({"Webapps"})
|
| + // public void testUsesMinWebappInfoIcons() {
|
| + // int minSizePx = getActivity().getResources().getDimensionPixelSize(
|
| + // R.dimen.webapp_splash_image_min_size);
|
| + // Bitmap image = Bitmap.createBitmap(minSizePx, minSizePx, Bitmap.Config.ARGB_8888);
|
| + // setActivityWebappInfoFromBitmap(image);
|
| + //
|
| + // ViewGroup splashScreen = getActivity().createSplashScreen(null);
|
| + // getActivity().setSplashScreenIconAndText(splashScreen, null, Color.WHITE);
|
| + //
|
| + // ImageView splashImage = (ImageView) splashScreen.findViewById(
|
| + // R.id.webapp_splash_screen_icon);
|
| + // BitmapDrawable drawable = (BitmapDrawable) splashImage.getDrawable();
|
| + // assertEquals(minSizePx, drawable.getBitmap().getWidth());
|
| + // assertEquals(minSizePx, drawable.getBitmap().getHeight());
|
| + // }
|
| +
|
| @SmallTest
|
| @Feature({"Webapps"})
|
| @TargetApi(Build.VERSION_CODES.LOLLIPOP)
|
| @@ -90,13 +118,7 @@ public class WebappSplashScreenTest extends WebappActivityTestBase {
|
| }
|
| });
|
|
|
| - // Waits for the splashscreen animation to finish.
|
| - assertTrue(CriteriaHelper.pollForCriteria(new Criteria() {
|
| - @Override
|
| - public boolean isSatisfied() {
|
| - return !getActivity().isSplashScreenVisibleForTest();
|
| - }
|
| - }));
|
| + assertTrue(waitUntilSplashscreenHides());
|
| }
|
|
|
| @SmallTest
|
| @@ -115,13 +137,7 @@ public class WebappSplashScreenTest extends WebappActivityTestBase {
|
| }
|
| });
|
|
|
| - // Waits for the splashscreen animation to finish.
|
| - assertTrue(CriteriaHelper.pollForCriteria(new Criteria() {
|
| - @Override
|
| - public boolean isSatisfied() {
|
| - return !getActivity().isSplashScreenVisibleForTest();
|
| - }
|
| - }));
|
| + assertTrue(waitUntilSplashscreenHides());
|
| }
|
|
|
| @SmallTest
|
| @@ -140,13 +156,7 @@ public class WebappSplashScreenTest extends WebappActivityTestBase {
|
| }
|
| });
|
|
|
| - // Waits for the splashscreen animation to finish.
|
| - assertTrue(CriteriaHelper.pollForCriteria(new Criteria() {
|
| - @Override
|
| - public boolean isSatisfied() {
|
| - return !getActivity().isSplashScreenVisibleForTest();
|
| - }
|
| - }));
|
| + assertTrue(waitUntilSplashscreenHides());
|
| }
|
|
|
| @SmallTest
|
| @@ -165,13 +175,7 @@ public class WebappSplashScreenTest extends WebappActivityTestBase {
|
| }
|
| });
|
|
|
| - // Waits for the splashscreen animation to finish.
|
| - assertTrue(CriteriaHelper.pollForCriteria(new Criteria() {
|
| - @Override
|
| - public boolean isSatisfied() {
|
| - return !getActivity().isSplashScreenVisibleForTest();
|
| - }
|
| - }));
|
| + assertTrue(waitUntilSplashscreenHides());
|
| }
|
|
|
| @SmallTest
|
| @@ -200,21 +204,68 @@ public class WebappSplashScreenTest extends WebappActivityTestBase {
|
| }
|
| });
|
|
|
| - // Waits for the splashscreen animation to finish.
|
| - assertTrue(CriteriaHelper.pollForCriteria(new Criteria() {
|
| - @Override
|
| - public boolean isSatisfied() {
|
| - return !getActivity().isSplashScreenVisibleForTest();
|
| - }
|
| - }));
|
| + assertTrue(waitUntilSplashscreenHides());
|
| }
|
|
|
| - private void setActivityWebappInfoFromBitmap(Bitmap image) {
|
| - WebappInfo mockInfo = WebappInfo.create(WEBAPP_ID, "about:blank",
|
| - ShortcutHelper.encodeBitmapAsString(image), null, null,
|
| - ScreenOrientationValues.DEFAULT, ShortcutSource.UNKNOWN,
|
| - ShortcutHelper.MANIFEST_COLOR_INVALID_OR_MISSING,
|
| - ShortcutHelper.MANIFEST_COLOR_INVALID_OR_MISSING);
|
| - getActivity().getWebappInfo().copy(mockInfo);
|
| + @SmallTest
|
| + @Feature({"Webapps"})
|
| + public void testUmaOnNativeLoad() {
|
| + // Tests UMA values.
|
| + assertEquals(1, RecordHistogram.getHistogramValueCountForTesting(
|
| + WebappUma.HISTOGRAM_SPLASHSCREEN_BACKGROUNDCOLOR,
|
| + WebappUma.SPLASHSCREEN_COLOR_STATUS_DEFAULT));
|
| + assertEquals(1, RecordHistogram.getHistogramValueCountForTesting(
|
| + WebappUma.HISTOGRAM_SPLASHSCREEN_THEMECOLOR,
|
| + WebappUma.SPLASHSCREEN_COLOR_STATUS_DEFAULT));
|
| + assertEquals(1, RecordHistogram.getHistogramValueCountForTesting(
|
| + WebappUma.HISTOGRAM_SPLASHSCREEN_ICON_TYPE,
|
| + WebappUma.SPLASHSCREEN_ICON_TYPE_NONE));
|
| +
|
| + // Tests UMA counts.
|
| + assertEquals(1, getHistogramTotalCountFor(WebappUma.HISTOGRAM_SPLASHSCREEN_BACKGROUNDCOLOR,
|
| + WebappUma.SPLASHSCREEN_COLOR_STATUS_MAX));
|
| + assertEquals(1, getHistogramTotalCountFor(WebappUma.HISTOGRAM_SPLASHSCREEN_THEMECOLOR,
|
| + WebappUma.SPLASHSCREEN_COLOR_STATUS_MAX));
|
| + assertEquals(1, getHistogramTotalCountFor(WebappUma.HISTOGRAM_SPLASHSCREEN_ICON_TYPE,
|
| + WebappUma.SPLASHSCREEN_ICON_TYPE_MAX));
|
| +
|
| + // Given that there is no icon, the ICON_SIZE UMA should not be recorded.
|
| + assertEquals(0, getHistogramTotalCountFor(WebappUma.HISTOGRAM_SPLASHSCREEN_ICON_SIZE, 50));
|
| +
|
| + // DURATION and HIDES UMA should not have been recorded yet.
|
| + assertFalse(hasHistogramEntry(WebappUma.HISTOGRAM_SPLASHSCREEN_DURATION, 3000));
|
| + assertEquals(0, getHistogramTotalCountFor(WebappUma.HISTOGRAM_SPLASHSCREEN_HIDES,
|
| + WebappUma.SPLASHSCREEN_HIDES_REASON_MAX));
|
| + }
|
| +
|
| + @SmallTest
|
| + @Feature({"Webapps"})
|
| + public void testUmaWhenSplashHides() throws InterruptedException {
|
| + ThreadUtils.runOnUiThread(new Runnable() {
|
| + @Override
|
| + public void run() {
|
| + RewindableIterator<TabObserver> observers =
|
| + getActivity().getActivityTab().getTabObservers();
|
| + while (observers.hasNext()) {
|
| + observers.next().didFirstVisuallyNonEmptyPaint(getActivity().getActivityTab());
|
| + }
|
| + }
|
| + });
|
| +
|
| + assertTrue(waitUntilSplashscreenHides());
|
| +
|
| + // DURATION and HIDES should now have a value.
|
| + assertTrue(hasHistogramEntry(WebappUma.HISTOGRAM_SPLASHSCREEN_DURATION, 3000));
|
| + assertEquals(1, getHistogramTotalCountFor(WebappUma.HISTOGRAM_SPLASHSCREEN_HIDES,
|
| + WebappUma.SPLASHSCREEN_HIDES_REASON_MAX));
|
| +
|
| + // The other UMA records should not have changed.
|
| + assertEquals(1, getHistogramTotalCountFor(WebappUma.HISTOGRAM_SPLASHSCREEN_BACKGROUNDCOLOR,
|
| + WebappUma.SPLASHSCREEN_COLOR_STATUS_MAX));
|
| + assertEquals(1, getHistogramTotalCountFor(WebappUma.HISTOGRAM_SPLASHSCREEN_THEMECOLOR,
|
| + WebappUma.SPLASHSCREEN_COLOR_STATUS_MAX));
|
| + assertEquals(1, getHistogramTotalCountFor(WebappUma.HISTOGRAM_SPLASHSCREEN_ICON_TYPE,
|
| + WebappUma.SPLASHSCREEN_ICON_TYPE_MAX));
|
| + assertEquals(0, getHistogramTotalCountFor(WebappUma.HISTOGRAM_SPLASHSCREEN_ICON_SIZE, 50));
|
| }
|
| }
|
|
|