Commit c1de4473 authored by Nate Fischer's avatar Nate Fischer Committed by Commit Bot

AW: add metric to track baseUrl scheme

This adds an UMA metric to track loadDataWithBaseURL's baseUrl scheme.
This logs if the URL is empty, if the scheme is one of several
well-known values, or if the scheme is some unknown value (possibly a
custom URL scheme).

This also adds integration tests to verify we record metrics.

R=isherman@chromium.org, torne@chromium.org

Bug: 901581
Test: run_webview_instrumentation_test_apk \
Test: --gtest_filter=LoadDataWithBaseUrlTest#testBaseUrlMetrics_*
Change-Id: Iaedf6836daeb185da7b1b26145d30fb46a363d21
Reviewed-on: https://chromium-review.googlesource.com/c/1321868
Commit-Queue: Nate Fischer <ntfschr@chromium.org>
Reviewed-by: default avatarIlya Sherman <isherman@chromium.org>
Reviewed-by: default avatarRichard Coles <torne@chromium.org>
Cr-Commit-Position: refs/heads/master@{#607281}
parent af97ca04
...@@ -138,6 +138,10 @@ public class AwContents implements SmartClipProvider { ...@@ -138,6 +138,10 @@ public class AwContents implements SmartClipProvider {
public static final String DATA_URI_HISTOGRAM_NAME = public static final String DATA_URI_HISTOGRAM_NAME =
"Android.WebView.LoadUrl.DataUriHasOctothorpe"; "Android.WebView.LoadUrl.DataUriHasOctothorpe";
@VisibleForTesting
public static final String DATA_BASE_URL_SCHEME_HISTOGRAM_NAME =
"Android.WebView.LoadDataWithBaseUrl.BaseUrl";
private static class ForceAuxiliaryBitmapRendering { private static class ForceAuxiliaryBitmapRendering {
private static final boolean sResult = lazyCheck(); private static final boolean sResult = lazyCheck();
private static boolean lazyCheck() { private static boolean lazyCheck() {
...@@ -145,8 +149,8 @@ public class AwContents implements SmartClipProvider { ...@@ -145,8 +149,8 @@ public class AwContents implements SmartClipProvider {
} }
} }
// Used to record the UMA histogram WebView.LoadDataWithBaseUrl.HistoryUrl. Since these values // Used to record the UMA histogram Android.WebView.LoadDataWithBaseUrl.HistoryUrl. Since these
// are persisted to logs, they should never be renumbered nor reused. // values are persisted to logs, they should never be renumbered nor reused.
@IntDef({HistoryUrl.EMPTY, HistoryUrl.BASEURL, HistoryUrl.DIFFERENT, HistoryUrl.COUNT}) @IntDef({HistoryUrl.EMPTY, HistoryUrl.BASEURL, HistoryUrl.DIFFERENT, HistoryUrl.COUNT})
@interface HistoryUrl { @interface HistoryUrl {
int EMPTY = 0; int EMPTY = 0;
...@@ -155,6 +159,31 @@ public class AwContents implements SmartClipProvider { ...@@ -155,6 +159,31 @@ public class AwContents implements SmartClipProvider {
int COUNT = 3; int COUNT = 3;
} }
// Used to record the UMA histogram Android.WebView.LoadDataWithBaseUrl.UrlScheme. Since these
// values are persisted to logs, they should never be renumbered nor reused.
@VisibleForTesting
@IntDef({UrlScheme.EMPTY, UrlScheme.UNKNOWN_SCHEME, UrlScheme.HTTP_SCHEME,
UrlScheme.HTTPS_SCHEME, UrlScheme.FILE_SCHEME, UrlScheme.FTP_SCHEME,
UrlScheme.DATA_SCHEME, UrlScheme.JAVASCRIPT_SCHEME, UrlScheme.ABOUT_SCHEME,
UrlScheme.CHROME_SCHEME, UrlScheme.BLOB_SCHEME, UrlScheme.CONTENT_SCHEME,
UrlScheme.INTENT_SCHEME})
public @interface UrlScheme {
int EMPTY = 0;
int UNKNOWN_SCHEME = 1;
int HTTP_SCHEME = 2;
int HTTPS_SCHEME = 3;
int FILE_SCHEME = 4;
int FTP_SCHEME = 5;
int DATA_SCHEME = 6;
int JAVASCRIPT_SCHEME = 7;
int ABOUT_SCHEME = 8;
int CHROME_SCHEME = 9;
int BLOB_SCHEME = 10;
int CONTENT_SCHEME = 11;
int INTENT_SCHEME = 12;
int COUNT = 13;
}
/** /**
* WebKit hit test related data structure. These are used to implement * WebKit hit test related data structure. These are used to implement
* getHitTestResult, requestFocusNodeHref, requestImageRef methods in WebView. * getHitTestResult, requestFocusNodeHref, requestImageRef methods in WebView.
...@@ -1656,6 +1685,11 @@ public class AwContents implements SmartClipProvider { ...@@ -1656,6 +1685,11 @@ public class AwContents implements SmartClipProvider {
"Android.WebView.LoadDataWithBaseUrl.HistoryUrl", value, HistoryUrl.COUNT); "Android.WebView.LoadDataWithBaseUrl.HistoryUrl", value, HistoryUrl.COUNT);
} }
private static void recordBaseUrl(@UrlScheme int value) {
RecordHistogram.recordEnumeratedHistogram(
DATA_BASE_URL_SCHEME_HISTOGRAM_NAME, value, UrlScheme.COUNT);
}
/** /**
* WebView.loadData. * WebView.loadData.
*/ */
...@@ -1691,6 +1725,34 @@ public class AwContents implements SmartClipProvider { ...@@ -1691,6 +1725,34 @@ public class AwContents implements SmartClipProvider {
recordHistoryUrl(HistoryUrl.DIFFERENT); recordHistoryUrl(HistoryUrl.DIFFERENT);
} }
if (baseUrl.equals(ContentUrlConstants.ABOUT_BLANK_DISPLAY_URL)) {
recordBaseUrl(UrlScheme.EMPTY);
} else if (baseUrl.startsWith("http:")) {
recordBaseUrl(UrlScheme.HTTP_SCHEME);
} else if (baseUrl.startsWith("https:")) {
recordBaseUrl(UrlScheme.HTTPS_SCHEME);
} else if (baseUrl.startsWith("file:")) {
recordBaseUrl(UrlScheme.FILE_SCHEME);
} else if (baseUrl.startsWith("ftp:")) {
recordBaseUrl(UrlScheme.FTP_SCHEME);
} else if (baseUrl.startsWith("data:")) {
recordBaseUrl(UrlScheme.DATA_SCHEME);
} else if (baseUrl.startsWith("javascript:")) {
recordBaseUrl(UrlScheme.JAVASCRIPT_SCHEME);
} else if (baseUrl.startsWith("about:")) {
recordBaseUrl(UrlScheme.ABOUT_SCHEME);
} else if (baseUrl.startsWith("chrome:")) {
recordBaseUrl(UrlScheme.CHROME_SCHEME);
} else if (baseUrl.startsWith("blob:")) {
recordBaseUrl(UrlScheme.BLOB_SCHEME);
} else if (baseUrl.startsWith("content:")) {
recordBaseUrl(UrlScheme.CONTENT_SCHEME);
} else if (baseUrl.startsWith("intent:")) {
recordBaseUrl(UrlScheme.INTENT_SCHEME);
} else {
recordBaseUrl(UrlScheme.UNKNOWN_SCHEME);
}
if (baseUrl.startsWith("data:")) { if (baseUrl.startsWith("data:")) {
// We record only for this branch, because the other branch assumes unencoded content. // We record only for this branch, because the other branch assumes unencoded content.
if (data != null && data.contains("#")) { if (data != null && data.contains("#")) {
......
...@@ -19,6 +19,7 @@ import org.chromium.android_webview.AwContents; ...@@ -19,6 +19,7 @@ import org.chromium.android_webview.AwContents;
import org.chromium.android_webview.AwCookieManager; import org.chromium.android_webview.AwCookieManager;
import org.chromium.android_webview.AwSettings; import org.chromium.android_webview.AwSettings;
import org.chromium.android_webview.test.util.CommonResources; import org.chromium.android_webview.test.util.CommonResources;
import org.chromium.base.metrics.RecordHistogram;
import org.chromium.base.test.util.Feature; import org.chromium.base.test.util.Feature;
import org.chromium.base.test.util.Restriction; import org.chromium.base.test.util.Restriction;
import org.chromium.content_public.browser.WebContents; import org.chromium.content_public.browser.WebContents;
...@@ -68,6 +69,7 @@ public class LoadDataWithBaseUrlTest { ...@@ -68,6 +69,7 @@ public class LoadDataWithBaseUrlTest {
private static final String SCRIPT_LOADED = "Loaded"; private static final String SCRIPT_LOADED = "Loaded";
private static final String SCRIPT_NOT_LOADED = "Not loaded"; private static final String SCRIPT_NOT_LOADED = "Not loaded";
private static final String SCRIPT_JS = "script_was_loaded = true;"; private static final String SCRIPT_JS = "script_was_loaded = true;";
private static final String SIMPLE_HTML = "<html><body></body></html>";
private String getScriptFileTestPageHtml(final String scriptUrl) { private String getScriptFileTestPageHtml(final String scriptUrl) {
return "<html>" return "<html>"
...@@ -507,4 +509,39 @@ public class LoadDataWithBaseUrlTest { ...@@ -507,4 +509,39 @@ public class LoadDataWithBaseUrlTest {
Assert.assertEquals( Assert.assertEquals(
CommonResources.ABOUT_TITLE, mActivityTestRule.getTitleOnUiThread(mAwContents)); CommonResources.ABOUT_TITLE, mActivityTestRule.getTitleOnUiThread(mAwContents));
} }
@Test
@SmallTest
@Feature({"AndroidWebView"})
public void testBaseUrlMetrics_empty() throws Throwable {
loadContentAndCheckMetrics(null, AwContents.UrlScheme.EMPTY);
}
@Test
@SmallTest
@Feature({"AndroidWebView"})
public void testBaseUrlMetrics_data() throws Throwable {
loadContentAndCheckMetrics("data:text/html", AwContents.UrlScheme.DATA_SCHEME);
}
@Test
@SmallTest
@Feature({"AndroidWebView"})
public void testBaseUrlMetrics_http() throws Throwable {
loadContentAndCheckMetrics("http://www.google.com/", AwContents.UrlScheme.HTTP_SCHEME);
}
private void loadContentAndCheckMetrics(String baseUrl, int expectedSchemeEnum)
throws Throwable {
Assert.assertEquals(0,
RecordHistogram.getHistogramTotalCountForTesting(
AwContents.DATA_BASE_URL_SCHEME_HISTOGRAM_NAME));
loadDataWithBaseUrlSync(SIMPLE_HTML, "text/html", false, baseUrl, null);
Assert.assertEquals(1,
RecordHistogram.getHistogramTotalCountForTesting(
AwContents.DATA_BASE_URL_SCHEME_HISTOGRAM_NAME));
Assert.assertEquals(1,
RecordHistogram.getHistogramValueCountForTesting(
AwContents.DATA_BASE_URL_SCHEME_HISTOGRAM_NAME, expectedSchemeEnum));
}
} }
...@@ -53284,6 +53284,22 @@ Full version information for the fingerprint enum values: ...@@ -53284,6 +53284,22 @@ Full version information for the fingerprint enum values:
<int value="1" label="WebViewClientCompat (via AndroidX)"/> <int value="1" label="WebViewClientCompat (via AndroidX)"/>
</enum> </enum>
<enum name="WebViewUrlScheme">
<int value="0" label="Empty URL"/>
<int value="1" label="Unknown scheme"/>
<int value="2" label="HTTP"/>
<int value="3" label="HTTPS"/>
<int value="4" label="File"/>
<int value="5" label="Ftp"/>
<int value="6" label="Data"/>
<int value="7" label="Javascript"/>
<int value="8" label="About"/>
<int value="9" label="Chrome"/>
<int value="10" label="Blob"/>
<int value="11" label="Content"/>
<int value="12" label="Intent"/>
</enum>
<enum name="WelcomeSignInPromptOutcome"> <enum name="WelcomeSignInPromptOutcome">
<int value="0" label="User navigated away from page"/> <int value="0" label="User navigated away from page"/>
<int value="1" label="User clicked the No Thanks button"/> <int value="1" label="User clicked the No Thanks button"/>
...@@ -2697,6 +2697,17 @@ uploading your change for review. ...@@ -2697,6 +2697,17 @@ uploading your change for review.
<summary>The number of bytes written for the tab metadata file.</summary> <summary>The number of bytes written for the tab metadata file.</summary>
</histogram> </histogram>
<histogram name="Android.WebView.LoadDataWithBaseUrl.BaseUrl"
enum="WebViewUrlScheme" expires_after="2019-05-05">
<owner>ntfschr@chromium.org</owner>
<owner>torne@chromium.org</owner>
<summary>
Records the scheme for the baseUrl parameter to loadDataWithBaseURL. This
also records if this value is &quot;empty&quot;, as determined by
TextUtils.isEmpty().
</summary>
</histogram>
<histogram name="Android.WebView.LoadDataWithBaseUrl.HistoryUrl" <histogram name="Android.WebView.LoadDataWithBaseUrl.HistoryUrl"
enum="HistoryUrlType"> enum="HistoryUrlType">
<owner>jamwalla@chromium.org</owner> <owner>jamwalla@chromium.org</owner>
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