Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(3214)

Unified Diff: chrome/android/javatests/src/org/chromium/chrome/browser/webapps/WebappSplashScreenTest.java

Issue 1391993004: WebApp splashscreen: add UMA to record how a splashscreen is constructed. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: review comments Created 5 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
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..b2efcc6b24b381a909d4b71001e8301af9536105 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
@@ -16,19 +16,48 @@ 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 {
+
+ private int getHistogramTotalCountFor(String histogram, int buckets) {
+ int count = 0;
+
+ for (int i = 0; i < buckets; ++i) {
+ count += RecordHistogram.getHistogramValueCountForTesting(histogram, i);
+ }
+
+ return count;
+ }
+
+ 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);
+ }
+
@UiThreadTest
@SmallTest
@Feature({"Webapps"})
@@ -90,13 +119,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 +138,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 +157,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 +176,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 +205,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(
+ HISTOGRAM_SPLASHSCREEN_BACKGROUNDCOLOR,
+ WebappUma.SPLASHSCREEN_COLOR_STATUS_DEFAULT));
+ assertEquals(1, RecordHistogram.getHistogramValueCountForTesting(
+ HISTOGRAM_SPLASHSCREEN_THEMECOLOR,
+ WebappUma.SPLASHSCREEN_COLOR_STATUS_DEFAULT));
+ assertEquals(1, RecordHistogram.getHistogramValueCountForTesting(
+ HISTOGRAM_SPLASHSCREEN_ICON_TYPE,
+ WebappUma.SPLASHSCREEN_ICON_TYPE_NONE));
+
+ // Tests UMA counts.
+ assertEquals(1, getHistogramTotalCountFor(HISTOGRAM_SPLASHSCREEN_BACKGROUNDCOLOR,
+ WebappUma.SPLASHSCREEN_COLOR_STATUS_MAX));
+ assertEquals(1, getHistogramTotalCountFor(HISTOGRAM_SPLASHSCREEN_THEMECOLOR,
+ WebappUma.SPLASHSCREEN_COLOR_STATUS_MAX));
+ assertEquals(1, getHistogramTotalCountFor(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(HISTOGRAM_SPLASHSCREEN_ICON_SIZE, 50));
+
+ // DURATION and HIDES UMA should not have been recorded yet.
+ assertFalse(hasHistogramEntry(HISTOGRAM_SPLASHSCREEN_DURATION, 3000));
+ assertEquals(0, getHistogramTotalCountFor(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(HISTOGRAM_SPLASHSCREEN_DURATION, 3000));
+ assertEquals(1, getHistogramTotalCountFor(HISTOGRAM_SPLASHSCREEN_HIDES,
+ WebappUma.SPLASHSCREEN_HIDES_REASON_MAX));
+
+ // The other UMA records should not have changed.
+ assertEquals(1, getHistogramTotalCountFor(HISTOGRAM_SPLASHSCREEN_BACKGROUNDCOLOR,
+ WebappUma.SPLASHSCREEN_COLOR_STATUS_MAX));
+ assertEquals(1, getHistogramTotalCountFor(HISTOGRAM_SPLASHSCREEN_THEMECOLOR,
+ WebappUma.SPLASHSCREEN_COLOR_STATUS_MAX));
+ assertEquals(1, getHistogramTotalCountFor(HISTOGRAM_SPLASHSCREEN_ICON_TYPE,
+ WebappUma.SPLASHSCREEN_ICON_TYPE_MAX));
+ assertEquals(0, getHistogramTotalCountFor(HISTOGRAM_SPLASHSCREEN_ICON_SIZE, 50));
}
}

Powered by Google App Engine
This is Rietveld 408576698