Commit ebd4817a authored by Peter Kotwicz's avatar Peter Kotwicz Committed by Commit Bot

[Android WebAPK] Finish hooking up new-style splash screen

This CL merges ProvidedByWebApkSplashDelegate and
SameActivityWebappSplashDelegate. As a benefit of the merging,
new-style WebAPKs get:
- offline error dialog
- splash screen hiding functionality

BUG=817263
R=dominickn
TBR=yfriedman (for renaming SameActivityWebappSplashDelegate->WebappSplashDelegate)

Change-Id: I930817d457c51b45156cecf06ce23a94432fa613
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1608728
Commit-Queue: Peter Kotwicz <pkotwicz@chromium.org>
Reviewed-by: default avatarDominick Ng <dominickn@chromium.org>
Cr-Commit-Position: refs/heads/master@{#663078}
parent 20a9e582
......@@ -865,6 +865,7 @@ chrome_java_sources = [
"java/src/org/chromium/chrome/browser/metrics/UmaSessionStats.java",
"java/src/org/chromium/chrome/browser/metrics/UmaUtils.java",
"java/src/org/chromium/chrome/browser/metrics/VariationsSession.java",
"java/src/org/chromium/chrome/browser/metrics/WebappSplashUmaCache.java",
"java/src/org/chromium/chrome/browser/metrics/WebApkSplashscreenMetrics.java",
"java/src/org/chromium/chrome/browser/metrics/WebApkUma.java",
"java/src/org/chromium/chrome/browser/modaldialog/AppModalPresenter.java",
......@@ -1662,9 +1663,7 @@ chrome_java_sources = [
"java/src/org/chromium/chrome/browser/webapps/ChromeWebApkHost.java",
"java/src/org/chromium/chrome/browser/webapps/ChromeWebApkHostSignature.java",
"java/src/org/chromium/chrome/browser/webapps/GooglePlayWebApkInstallDelegate.java",
"java/src/org/chromium/chrome/browser/webapps/ProvidedByWebApkSplashDelegate.java",
"java/src/org/chromium/chrome/browser/webapps/SameActivityWebappSplashDelegate.java",
"java/src/org/chromium/chrome/browser/metrics/SameActivityWebappUmaCache.java",
"java/src/org/chromium/chrome/browser/webapps/WebappSplashDelegate.java",
"java/src/org/chromium/chrome/browser/webapps/SameTaskWebApkActivity.java",
"java/src/org/chromium/chrome/browser/webapps/SplashController.java",
"java/src/org/chromium/chrome/browser/webapps/SplashDelegate.java",
......
......@@ -13,10 +13,10 @@ import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
/**
* Used by SameActivityWebappSplashDelegate to cache webapp splash screen UMA values. Records UMA
* Used by {@link WebappSplashDelegate} to cache webapp splash screen UMA values. Records UMA
* when {@link #commitMetrics()} is called.
*/
public class SameActivityWebappUmaCache {
public class WebappSplashUmaCache {
// SplashColorStatus defined in tools/metrics/histograms/enums.xml.
// NUM_ENTRIES is intentionally included into @IntDef.
@IntDef({SplashColorStatus.DEFAULT, SplashColorStatus.CUSTOM, SplashColorStatus.NUM_ENTRIES})
......
// Copyright 2019 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
package org.chromium.chrome.browser.webapps;
import android.content.Context;
import android.graphics.Bitmap;
import android.net.Uri;
import android.view.View;
import android.widget.ImageView;
import org.chromium.base.ApiCompatibilityUtils;
import org.chromium.base.ContextUtils;
import org.chromium.base.FileUtils;
import org.chromium.base.StrictModeContext;
import org.chromium.chrome.R;
import org.chromium.chrome.browser.tab.Tab;
import org.chromium.chrome.browser.util.ColorUtils;
import org.chromium.webapk.lib.common.WebApkCommonUtils;
/** Delegate which uses splash screen screenshot from the WebAPK's content provider. */
public class ProvidedByWebApkSplashDelegate implements SplashDelegate {
private WebappInfo mWebappInfo;
public ProvidedByWebApkSplashDelegate(WebappInfo webappInfo) {
mWebappInfo = webappInfo;
}
@Override
public View buildSplashView() {
Context appContext = ContextUtils.getApplicationContext();
ImageView splashView = new ImageView(appContext);
int backgroundColor = ColorUtils.getOpaqueColor(
mWebappInfo.backgroundColor(ApiCompatibilityUtils.getColor(
appContext.getResources(), R.color.webapp_default_bg)));
splashView.setBackgroundColor(backgroundColor);
Bitmap splashBitmap = null;
try (StrictModeContext smc = StrictModeContext.allowDiskReads()) {
splashBitmap = FileUtils.queryBitmapFromContentProvider(appContext,
Uri.parse(WebApkCommonUtils.generateSplashContentProviderUri(
mWebappInfo.webApkPackageName())));
}
if (splashBitmap != null) {
splashView.setScaleType(ImageView.ScaleType.FIT_CENTER);
splashView.setImageBitmap(splashBitmap);
}
return splashView;
}
@Override
public void onSplashHidden(Tab tab, @SplashController.SplashHidesReason int reason,
long startTimestamp, long endTimestamp) {
// TODO(pkotwicz) implement.
}
@Override
public boolean shouldWaitForSubsequentPageLoadToHideSplash() {
return false;
}
}
......@@ -883,16 +883,10 @@ public class WebappActivity extends SingleTabActivity {
/** Inits the splash screen */
protected void initSplash() {
// Splash screen is shown after preInflationStartup() is run and the delegate is set.
if (mWebappInfo.isSplashProvidedByWebApk()) {
mSplashController.setConfig(new ProvidedByWebApkSplashDelegate(mWebappInfo),
true /* isWindowInitiallyTranslucent */, 0 /* splashHideAnimationDurationMs */);
} else {
mSplashController.setConfig(
new SameActivityWebappSplashDelegate(
this, getLifecycleDispatcher(), mTabObserverRegistrar, mWebappInfo),
false /* isWindowInitiallyTranslucent */,
SameActivityWebappSplashDelegate.HIDE_ANIMATION_DURATION_MS);
}
boolean isWindowInitiallyTranslucent = mWebappInfo.isSplashProvidedByWebApk();
mSplashController.setConfig(new WebappSplashDelegate(this, getLifecycleDispatcher(),
mTabObserverRegistrar, mWebappInfo),
isWindowInitiallyTranslucent, WebappSplashDelegate.HIDE_ANIMATION_DURATION_MS);
}
/** Sets the screen orientation. */
......
......@@ -8,28 +8,30 @@ import android.app.Activity;
import android.content.Context;
import android.content.res.Resources;
import android.graphics.Bitmap;
import android.net.Uri;
import android.util.DisplayMetrics;
import android.view.View;
import android.view.ViewGroup;
import android.widget.FrameLayout;
import android.widget.ImageView;
import org.chromium.base.ApiCompatibilityUtils;
import org.chromium.base.ContextUtils;
import org.chromium.base.FileUtils;
import org.chromium.base.StrictModeContext;
import org.chromium.base.metrics.RecordHistogram;
import org.chromium.chrome.R;
import org.chromium.chrome.browser.lifecycle.ActivityLifecycleDispatcher;
import org.chromium.chrome.browser.lifecycle.NativeInitObserver;
import org.chromium.chrome.browser.metrics.SameActivityWebappUmaCache;
import org.chromium.chrome.browser.metrics.WebappSplashUmaCache;
import org.chromium.chrome.browser.tab.Tab;
import org.chromium.chrome.browser.tab.TabObserverRegistrar;
import org.chromium.chrome.browser.util.ColorUtils;
import org.chromium.webapk.lib.common.WebApkCommonUtils;
import org.chromium.webapk.lib.common.splash.SplashLayout;
/**
* Delegate for when splash screen is shown by Chrome (as opposed to by external non-Chrome
* activity).
*/
public class SameActivityWebappSplashDelegate implements SplashDelegate, NativeInitObserver {
/** Delegate for splash screen for webapps and WebAPKs. */
public class WebappSplashDelegate implements SplashDelegate, NativeInitObserver {
public static final int HIDE_ANIMATION_DURATION_MS = 300;
public static final String HISTOGRAM_SPLASHSCREEN_DURATION = "Webapp.Splashscreen.Duration";
public static final String HISTOGRAM_SPLASHSCREEN_HIDES = "Webapp.Splashscreen.Hides";
......@@ -43,12 +45,11 @@ public class SameActivityWebappSplashDelegate implements SplashDelegate, NativeI
private WebappInfo mWebappInfo;
private SameActivityWebappUmaCache mUmaCache;
private WebappSplashUmaCache mWebappSplashUmaCache;
private WebApkSplashNetworkErrorObserver mWebApkNetworkErrorObserver;
public SameActivityWebappSplashDelegate(Activity activity,
ActivityLifecycleDispatcher lifecycleDispatcher,
public WebappSplashDelegate(Activity activity, ActivityLifecycleDispatcher lifecycleDispatcher,
TabObserverRegistrar tabObserverRegistrar, WebappInfo webappInfo) {
mActivity = activity;
mLifecycleDispatcher = lifecycleDispatcher;
......@@ -56,49 +57,30 @@ public class SameActivityWebappSplashDelegate implements SplashDelegate, NativeI
mWebappInfo = webappInfo;
mLifecycleDispatcher.register(this);
}
@Override
public View buildSplashView() {
if (mWebappInfo.isForWebApk()) {
mWebApkNetworkErrorObserver =
new WebApkSplashNetworkErrorObserver(mActivity, mWebappInfo.name());
mTabObserverRegistrar.registerTabObserver(mWebApkNetworkErrorObserver);
}
Context context = ContextUtils.getApplicationContext();
final int backgroundColor = ColorUtils.getOpaqueColor(mWebappInfo.backgroundColor(
ApiCompatibilityUtils.getColor(context.getResources(), R.color.webapp_default_bg)));
ViewGroup splashScreen = new FrameLayout(context);
splashScreen.setBackgroundColor(backgroundColor);
if (mWebappInfo.isForWebApk()) {
initializeLayout(
splashScreen, backgroundColor, ((WebApkInfo) mWebappInfo).splashIcon());
return splashScreen;
}
WebappDataStorage storage =
WebappRegistry.getInstance().getWebappDataStorage(mWebappInfo.id());
if (storage == null) {
initializeLayout(splashScreen, backgroundColor, null);
return splashScreen;
}
storage.getSplashScreenImage(new WebappDataStorage.FetchCallback<Bitmap>() {
@Override
public void onDataRetrieved(Bitmap splashImage) {
initializeLayout(splashScreen, backgroundColor, splashImage);
}
});
return splashScreen;
public void onFinishNativeInitialization() {
mNativeLoaded = true;
if (mWebappSplashUmaCache != null) mWebappSplashUmaCache.commitMetrics();
}
@Override
public void onFinishNativeInitialization() {
mNativeLoaded = true;
if (mUmaCache != null) mUmaCache.commitMetrics();
public View buildSplashView() {
Context appContext = ContextUtils.getApplicationContext();
int backgroundColor = ColorUtils.getOpaqueColor(
mWebappInfo.backgroundColor(ApiCompatibilityUtils.getColor(
appContext.getResources(), R.color.webapp_default_bg)));
if (mWebappInfo.isSplashProvidedByWebApk()) {
return buildSplashWithWebApkProvidedScreenshot(appContext, backgroundColor);
}
return buildSplashFromWebApkInfo(appContext, backgroundColor);
}
@Override
......@@ -109,7 +91,7 @@ public class SameActivityWebappSplashDelegate implements SplashDelegate, NativeI
tab.removeObserver(mWebApkNetworkErrorObserver);
mWebApkNetworkErrorObserver = null;
}
mLifecycleDispatcher.unregister(SameActivityWebappSplashDelegate.this);
mLifecycleDispatcher.unregister(this);
recordSplashHiddenUma(reason, startTimestamp, endTimestamp);
......@@ -122,8 +104,35 @@ public class SameActivityWebappSplashDelegate implements SplashDelegate, NativeI
&& mWebApkNetworkErrorObserver.isNetworkErrorDialogVisible();
}
/** Sets the splash screen layout and sets the splash screen's title and icon. */
private void initializeLayout(ViewGroup splashScreen, int backgroundColor, Bitmap splashImage) {
/** Builds splash screen from WebApkInfo. */
private View buildSplashFromWebApkInfo(Context appContext, int backgroundColor) {
ViewGroup splashScreen = new FrameLayout(appContext);
splashScreen.setBackgroundColor(backgroundColor);
if (mWebappInfo.isForWebApk()) {
initializeWebApkInfoSplashLayout(
splashScreen, backgroundColor, ((WebApkInfo) mWebappInfo).splashIcon());
return splashScreen;
}
WebappDataStorage storage =
WebappRegistry.getInstance().getWebappDataStorage(mWebappInfo.id());
if (storage == null) {
initializeWebApkInfoSplashLayout(splashScreen, backgroundColor, null);
return splashScreen;
}
storage.getSplashScreenImage(new WebappDataStorage.FetchCallback<Bitmap>() {
@Override
public void onDataRetrieved(Bitmap splashImage) {
initializeWebApkInfoSplashLayout(splashScreen, backgroundColor, splashImage);
}
});
return splashScreen;
}
private void initializeWebApkInfoSplashLayout(
ViewGroup splashScreen, int backgroundColor, Bitmap splashImage) {
Context context = ContextUtils.getApplicationContext();
Resources resources = context.getResources();
......@@ -143,45 +152,67 @@ public class SameActivityWebappSplashDelegate implements SplashDelegate, NativeI
selectedIconClassification, mWebappInfo.name(),
ColorUtils.shouldUseLightForegroundOnBackground(backgroundColor));
recordUma(resources, selectedIconClassification, selectedIcon, (splashImage != null));
}
/** Called once the splash screen is hidden to record UMA metrics. */
private void recordSplashHiddenUma(@SplashController.SplashHidesReason int reason,
long startTimestamp, long endTimestamp) {
RecordHistogram.recordEnumeratedHistogram(HISTOGRAM_SPLASHSCREEN_HIDES, reason,
SplashController.SplashHidesReason.NUM_ENTRIES);
RecordHistogram.recordMediumTimesHistogram(
HISTOGRAM_SPLASHSCREEN_DURATION, endTimestamp - startTimestamp);
recordWebApkInfoSplashUma(
resources, selectedIconClassification, selectedIcon, (splashImage != null));
}
/**
* Records splash screen UMA metrics.
* Records UMA metrics for splash screen built from WebApkInfo.
* @param resources
* @param selectedIconClassification.
* @param selectedIcon The icon used on the splash screen.
* @param usingDedicatedIcon Whether the PWA provides different icons for the splash screen and
* for the app icon.
*/
private void recordUma(Resources resources,
private void recordWebApkInfoSplashUma(Resources resources,
@SplashLayout.IconClassification int selectedIconClassification, Bitmap selectedIcon,
boolean usingDedicatedIcon) {
mUmaCache = new SameActivityWebappUmaCache();
mUmaCache.recordSplashscreenBackgroundColor(mWebappInfo.hasValidBackgroundColor()
? SameActivityWebappUmaCache.SplashColorStatus.CUSTOM
: SameActivityWebappUmaCache.SplashColorStatus.DEFAULT);
mUmaCache.recordSplashscreenThemeColor(mWebappInfo.hasValidThemeColor()
? SameActivityWebappUmaCache.SplashColorStatus.CUSTOM
: SameActivityWebappUmaCache.SplashColorStatus.DEFAULT);
mUmaCache.recordSplashscreenIconType(selectedIconClassification, usingDedicatedIcon);
mWebappSplashUmaCache = new WebappSplashUmaCache();
mWebappSplashUmaCache.recordSplashscreenBackgroundColor(
mWebappInfo.hasValidBackgroundColor()
? WebappSplashUmaCache.SplashColorStatus.CUSTOM
: WebappSplashUmaCache.SplashColorStatus.DEFAULT);
mWebappSplashUmaCache.recordSplashscreenThemeColor(mWebappInfo.hasValidThemeColor()
? WebappSplashUmaCache.SplashColorStatus.CUSTOM
: WebappSplashUmaCache.SplashColorStatus.DEFAULT);
mWebappSplashUmaCache.recordSplashscreenIconType(
selectedIconClassification, usingDedicatedIcon);
if (selectedIconClassification != SplashLayout.IconClassification.INVALID) {
DisplayMetrics displayMetrics = resources.getDisplayMetrics();
mUmaCache.recordSplashscreenIconSize(Math.round(
mWebappSplashUmaCache.recordSplashscreenIconSize(Math.round(
selectedIcon.getScaledWidth(displayMetrics) / displayMetrics.density));
}
if (mNativeLoaded) mUmaCache.commitMetrics();
if (mNativeLoaded) mWebappSplashUmaCache.commitMetrics();
}
/** Builds splash screen using screenshot provided by WebAPK. */
private View buildSplashWithWebApkProvidedScreenshot(Context appContext, int backgroundColor) {
ImageView splashView = new ImageView(appContext);
splashView.setBackgroundColor(backgroundColor);
Bitmap splashBitmap = null;
try (StrictModeContext smc = StrictModeContext.allowDiskReads()) {
splashBitmap = FileUtils.queryBitmapFromContentProvider(appContext,
Uri.parse(WebApkCommonUtils.generateSplashContentProviderUri(
mWebappInfo.webApkPackageName())));
}
if (splashBitmap != null) {
splashView.setScaleType(ImageView.ScaleType.FIT_CENTER);
splashView.setImageBitmap(splashBitmap);
}
return splashView;
}
/** Called once the splash screen is hidden to record UMA metrics. */
private void recordSplashHiddenUma(@SplashController.SplashHidesReason int reason,
long startTimestamp, long endTimestamp) {
RecordHistogram.recordEnumeratedHistogram(HISTOGRAM_SPLASHSCREEN_HIDES, reason,
SplashController.SplashHidesReason.NUM_ENTRIES);
RecordHistogram.recordMediumTimesHistogram(
HISTOGRAM_SPLASHSCREEN_DURATION, endTimestamp - startTimestamp);
}
}
......@@ -19,7 +19,7 @@ import org.chromium.base.test.util.CommandLineFlags;
import org.chromium.base.test.util.Feature;
import org.chromium.chrome.browser.ChromeSwitches;
import org.chromium.chrome.browser.ShortcutHelper;
import org.chromium.chrome.browser.metrics.SameActivityWebappUmaCache;
import org.chromium.chrome.browser.metrics.WebappSplashUmaCache;
import org.chromium.chrome.test.ChromeJUnit4ClassRunner;
/**
......@@ -47,7 +47,7 @@ public class WebappSplashScreenBackgroundColorTest {
Assert.assertEquals(1,
RecordHistogram.getHistogramValueCountForTesting(
SameActivityWebappUmaCache.HISTOGRAM_SPLASHSCREEN_BACKGROUNDCOLOR,
SameActivityWebappUmaCache.SplashColorStatus.CUSTOM));
WebappSplashUmaCache.HISTOGRAM_SPLASHSCREEN_BACKGROUNDCOLOR,
WebappSplashUmaCache.SplashColorStatus.CUSTOM));
}
}
......@@ -22,7 +22,7 @@ import org.chromium.base.test.util.Feature;
import org.chromium.chrome.R;
import org.chromium.chrome.browser.ChromeSwitches;
import org.chromium.chrome.browser.ShortcutHelper;
import org.chromium.chrome.browser.metrics.SameActivityWebappUmaCache;
import org.chromium.chrome.browser.metrics.WebappSplashUmaCache;
import org.chromium.chrome.test.ChromeJUnit4ClassRunner;
/**
......@@ -61,14 +61,14 @@ public class WebappSplashScreenHomescreenIconTest {
public void testUmaFallbackIcon() {
Assert.assertEquals(1,
RecordHistogram.getHistogramValueCountForTesting(
SameActivityWebappUmaCache.HISTOGRAM_SPLASHSCREEN_ICON_TYPE,
SameActivityWebappUmaCache.SplashIconType.FALLBACK));
WebappSplashUmaCache.HISTOGRAM_SPLASHSCREEN_ICON_TYPE,
WebappSplashUmaCache.SplashIconType.FALLBACK));
Bitmap icon = ShortcutHelper.decodeBitmapFromString(WebappActivityTestRule.TEST_ICON);
int sizeInDp = Math.round((float) icon.getWidth()
/ mActivityTestRule.getActivity().getResources().getDisplayMetrics().density);
Assert.assertEquals(1,
RecordHistogram.getHistogramValueCountForTesting(
SameActivityWebappUmaCache.HISTOGRAM_SPLASHSCREEN_ICON_SIZE, sizeInDp));
WebappSplashUmaCache.HISTOGRAM_SPLASHSCREEN_ICON_SIZE, sizeInDp));
}
}
......@@ -22,7 +22,7 @@ import org.chromium.base.test.util.Feature;
import org.chromium.chrome.R;
import org.chromium.chrome.browser.ChromeSwitches;
import org.chromium.chrome.browser.ShortcutHelper;
import org.chromium.chrome.browser.metrics.SameActivityWebappUmaCache;
import org.chromium.chrome.browser.metrics.WebappSplashUmaCache;
import org.chromium.chrome.test.ChromeJUnit4ClassRunner;
/**
......@@ -64,8 +64,8 @@ public class WebappSplashScreenIconTest {
public void testUmaCustomIcon() {
Assert.assertEquals(1,
RecordHistogram.getHistogramValueCountForTesting(
SameActivityWebappUmaCache.HISTOGRAM_SPLASHSCREEN_ICON_TYPE,
SameActivityWebappUmaCache.SplashIconType.CUSTOM));
WebappSplashUmaCache.HISTOGRAM_SPLASHSCREEN_ICON_TYPE,
WebappSplashUmaCache.SplashIconType.CUSTOM));
Bitmap icon =
ShortcutHelper.decodeBitmapFromString(WebappActivityTestRule.TEST_SPLASH_ICON);
......@@ -73,6 +73,6 @@ public class WebappSplashScreenIconTest {
/ mActivityTestRule.getActivity().getResources().getDisplayMetrics().density);
Assert.assertEquals(1,
RecordHistogram.getHistogramValueCountForTesting(
SameActivityWebappUmaCache.HISTOGRAM_SPLASHSCREEN_ICON_SIZE, sizeInDp));
WebappSplashUmaCache.HISTOGRAM_SPLASHSCREEN_ICON_SIZE, sizeInDp));
}
}
......@@ -32,7 +32,7 @@ import org.chromium.base.test.util.Feature;
import org.chromium.chrome.R;
import org.chromium.chrome.browser.ChromeSwitches;
import org.chromium.chrome.browser.ShortcutHelper;
import org.chromium.chrome.browser.metrics.SameActivityWebappUmaCache;
import org.chromium.chrome.browser.metrics.WebappSplashUmaCache;
import org.chromium.chrome.browser.tab.Tab;
import org.chromium.chrome.browser.tab.TabTestUtils;
import org.chromium.chrome.test.ChromeJUnit4ClassRunner;
......@@ -175,42 +175,39 @@ public class WebappSplashScreenTest {
// Tests UMA values.
Assert.assertEquals(1,
RecordHistogram.getHistogramValueCountForTesting(
SameActivityWebappUmaCache.HISTOGRAM_SPLASHSCREEN_BACKGROUNDCOLOR,
SameActivityWebappUmaCache.SplashColorStatus.DEFAULT));
WebappSplashUmaCache.HISTOGRAM_SPLASHSCREEN_BACKGROUNDCOLOR,
WebappSplashUmaCache.SplashColorStatus.DEFAULT));
Assert.assertEquals(1,
RecordHistogram.getHistogramValueCountForTesting(
SameActivityWebappUmaCache.HISTOGRAM_SPLASHSCREEN_THEMECOLOR,
SameActivityWebappUmaCache.SplashColorStatus.DEFAULT));
WebappSplashUmaCache.HISTOGRAM_SPLASHSCREEN_THEMECOLOR,
WebappSplashUmaCache.SplashColorStatus.DEFAULT));
Assert.assertEquals(1,
RecordHistogram.getHistogramValueCountForTesting(
SameActivityWebappUmaCache.HISTOGRAM_SPLASHSCREEN_ICON_TYPE,
SameActivityWebappUmaCache.SplashIconType.NONE));
WebappSplashUmaCache.HISTOGRAM_SPLASHSCREEN_ICON_TYPE,
WebappSplashUmaCache.SplashIconType.NONE));
// Tests UMA counts.
Assert.assertEquals(1,
getHistogramTotalCountFor(
SameActivityWebappUmaCache.HISTOGRAM_SPLASHSCREEN_BACKGROUNDCOLOR,
SameActivityWebappUmaCache.SplashColorStatus.NUM_ENTRIES));
WebappSplashUmaCache.HISTOGRAM_SPLASHSCREEN_BACKGROUNDCOLOR,
WebappSplashUmaCache.SplashColorStatus.NUM_ENTRIES));
Assert.assertEquals(1,
getHistogramTotalCountFor(
SameActivityWebappUmaCache.HISTOGRAM_SPLASHSCREEN_THEMECOLOR,
SameActivityWebappUmaCache.SplashColorStatus.NUM_ENTRIES));
getHistogramTotalCountFor(WebappSplashUmaCache.HISTOGRAM_SPLASHSCREEN_THEMECOLOR,
WebappSplashUmaCache.SplashColorStatus.NUM_ENTRIES));
Assert.assertEquals(1,
getHistogramTotalCountFor(
SameActivityWebappUmaCache.HISTOGRAM_SPLASHSCREEN_ICON_TYPE,
SameActivityWebappUmaCache.SplashIconType.NUM_ENTRIES));
getHistogramTotalCountFor(WebappSplashUmaCache.HISTOGRAM_SPLASHSCREEN_ICON_TYPE,
WebappSplashUmaCache.SplashIconType.NUM_ENTRIES));
// Given that there is no icon, the ICON_SIZE UMA should not be recorded.
Assert.assertEquals(0,
getHistogramTotalCountFor(
SameActivityWebappUmaCache.HISTOGRAM_SPLASHSCREEN_ICON_SIZE, 50));
WebappSplashUmaCache.HISTOGRAM_SPLASHSCREEN_ICON_SIZE, 50));
// DURATION and HIDES UMA should not have been recorded yet.
Assert.assertFalse(hasHistogramEntry(
SameActivityWebappSplashDelegate.HISTOGRAM_SPLASHSCREEN_DURATION, 3000));
Assert.assertFalse(
hasHistogramEntry(WebappSplashDelegate.HISTOGRAM_SPLASHSCREEN_DURATION, 3000));
Assert.assertEquals(0,
getHistogramTotalCountFor(
SameActivityWebappSplashDelegate.HISTOGRAM_SPLASHSCREEN_HIDES,
getHistogramTotalCountFor(WebappSplashDelegate.HISTOGRAM_SPLASHSCREEN_HIDES,
SplashController.SplashHidesReason.NUM_ENTRIES));
}
......@@ -226,29 +223,26 @@ public class WebappSplashScreenTest {
mActivityTestRule.waitUntilSplashscreenHides();
// DURATION and HIDES should now have a value.
Assert.assertTrue(hasHistogramEntry(
SameActivityWebappSplashDelegate.HISTOGRAM_SPLASHSCREEN_DURATION, 10000));
Assert.assertTrue(
hasHistogramEntry(WebappSplashDelegate.HISTOGRAM_SPLASHSCREEN_DURATION, 10000));
Assert.assertEquals(1,
getHistogramTotalCountFor(
SameActivityWebappSplashDelegate.HISTOGRAM_SPLASHSCREEN_HIDES,
getHistogramTotalCountFor(WebappSplashDelegate.HISTOGRAM_SPLASHSCREEN_HIDES,
SplashController.SplashHidesReason.NUM_ENTRIES));
// The other UMA records should not have changed.
Assert.assertEquals(1,
getHistogramTotalCountFor(
SameActivityWebappUmaCache.HISTOGRAM_SPLASHSCREEN_BACKGROUNDCOLOR,
SameActivityWebappUmaCache.SplashColorStatus.NUM_ENTRIES));
WebappSplashUmaCache.HISTOGRAM_SPLASHSCREEN_BACKGROUNDCOLOR,
WebappSplashUmaCache.SplashColorStatus.NUM_ENTRIES));
Assert.assertEquals(1,
getHistogramTotalCountFor(
SameActivityWebappUmaCache.HISTOGRAM_SPLASHSCREEN_THEMECOLOR,
SameActivityWebappUmaCache.SplashColorStatus.NUM_ENTRIES));
getHistogramTotalCountFor(WebappSplashUmaCache.HISTOGRAM_SPLASHSCREEN_THEMECOLOR,
WebappSplashUmaCache.SplashColorStatus.NUM_ENTRIES));
Assert.assertEquals(1,
getHistogramTotalCountFor(
SameActivityWebappUmaCache.HISTOGRAM_SPLASHSCREEN_ICON_TYPE,
SameActivityWebappUmaCache.SplashIconType.NUM_ENTRIES));
getHistogramTotalCountFor(WebappSplashUmaCache.HISTOGRAM_SPLASHSCREEN_ICON_TYPE,
WebappSplashUmaCache.SplashIconType.NUM_ENTRIES));
Assert.assertEquals(0,
getHistogramTotalCountFor(
SameActivityWebappUmaCache.HISTOGRAM_SPLASHSCREEN_ICON_SIZE, 50));
WebappSplashUmaCache.HISTOGRAM_SPLASHSCREEN_ICON_SIZE, 50));
}
@Test
......
......@@ -22,7 +22,7 @@ import org.chromium.base.test.util.DisabledTest;
import org.chromium.base.test.util.Feature;
import org.chromium.chrome.browser.ChromeSwitches;
import org.chromium.chrome.browser.ShortcutHelper;
import org.chromium.chrome.browser.metrics.SameActivityWebappUmaCache;
import org.chromium.chrome.browser.metrics.WebappSplashUmaCache;
import org.chromium.chrome.browser.tab.TabTestUtils;
import org.chromium.chrome.browser.util.ColorUtils;
import org.chromium.chrome.test.ChromeJUnit4ClassRunner;
......@@ -99,7 +99,7 @@ public class WebappSplashScreenThemeColorTest {
public void testUmaThemeColorCustom() {
Assert.assertEquals(1,
RecordHistogram.getHistogramValueCountForTesting(
SameActivityWebappUmaCache.HISTOGRAM_SPLASHSCREEN_THEMECOLOR,
SameActivityWebappUmaCache.SplashColorStatus.CUSTOM));
WebappSplashUmaCache.HISTOGRAM_SPLASHSCREEN_THEMECOLOR,
WebappSplashUmaCache.SplashColorStatus.CUSTOM));
}
}
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