Commit cebfe326 authored by Tao Bai's avatar Tao Bai Committed by Commit Bot

WebView integration test for heartbeat metrics in PageLoadMetrics

Bug: 995880
Change-Id: I02239e098b4e8928c2ae1eba872eb83f75a0b40f
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1876868
Commit-Queue: Tao Bai <michaelbai@chromium.org>
Reviewed-by: default avatarChangwan Ryu <changwan@chromium.org>
Cr-Commit-Position: refs/heads/master@{#709624}
parent ac98af14
......@@ -6,7 +6,9 @@ package org.chromium.android_webview.test;
import static org.junit.Assert.assertEquals;
import android.os.SystemClock;
import android.support.test.filters.SmallTest;
import android.view.KeyEvent;
import org.junit.After;
import org.junit.Before;
......@@ -14,11 +16,15 @@ import org.junit.Rule;
import org.junit.Test;
import org.chromium.android_webview.AwContents;
import org.chromium.base.metrics.RecordHistogram;
import org.chromium.base.test.util.Feature;
import org.chromium.base.test.util.MetricsUtils;
import org.chromium.blink.mojom.WebFeature;
import org.chromium.content_public.browser.test.util.TestThreadUtils;
import org.chromium.net.test.util.TestWebServer;
import java.util.concurrent.Callable;
/**
* Integration test for PageLoadMetrics.
*/
......@@ -52,13 +58,13 @@ public class AwPageLoadMetricsTest {
mTestContainerView.getAwContents(), mContentsClient.getOnPageFinishedHelper(), url);
}
@Test
@SmallTest
@Feature({"AndroidWebView"})
/**
* This test doesn't intent to cover all UseCounter metrics, and just test WebView integration
* works
*/
@Test
@SmallTest
@Feature({"AndroidWebView"})
public void testUseCounterMetrics() throws Throwable {
final String data = "<html><head></head><body><form></form></body></html>";
final String url = mWebServer.setResponse(MAIN_FRAME_FILE, data, null);
......@@ -71,4 +77,77 @@ public class AwPageLoadMetricsTest {
assertEquals(1, delta.getDelta());
assertEquals(1, form.getDelta());
}
/**
* This test covers WebView heartbeat metrics from CorePageLoadMetrics.
*/
@Test
@SmallTest
@Feature({"AndroidWebView"})
public void testHeartbeatMetrics() throws Throwable {
final String data = "<html><head></head><body><p>Hello World</p></body></html>";
final String url = mWebServer.setResponse(MAIN_FRAME_FILE, data, null);
int navigationToFirstPaint = RecordHistogram.getHistogramTotalCountForTesting(
"PageLoad.PaintTiming.NavigationToFirstPaint");
int navigationToFirstContentfulPaint = RecordHistogram.getHistogramTotalCountForTesting(
"PageLoad.PaintTiming.NavigationToFirstContentfulPaint");
int navigationToLargestContentfulPaint = RecordHistogram.getHistogramTotalCountForTesting(
"PageLoad.PaintTiming.NavigationToLargestContentfulPaint");
loadUrlSync(url);
AwActivityTestRule.pollInstrumentationThread(
() -> (1 + navigationToFirstPaint
== RecordHistogram.getHistogramTotalCountForTesting(
"PageLoad.PaintTiming.NavigationToFirstPaint")));
AwActivityTestRule.pollInstrumentationThread(
() -> (1 + navigationToFirstContentfulPaint
== RecordHistogram.getHistogramTotalCountForTesting(
"PageLoad.PaintTiming.NavigationToFirstContentfulPaint")));
// Flush NavigationToLargestContentfulPaint.
loadUrlSync("about:blank");
AwActivityTestRule.pollInstrumentationThread(
() -> (1 + navigationToLargestContentfulPaint
== RecordHistogram.getHistogramTotalCountForTesting(
"PageLoad.PaintTiming.NavigationToLargestContentfulPaint")));
}
/**
* This test covers WebView heartbeat metrics FirstInputDelay4.
*/
@Test
@SmallTest
@Feature({"AndroidWebView"})
public void testFirstInputDelay4() throws Throwable {
final String data = "<html><head></head><body><input type='text' id='text1'></body></html>";
final String url = mWebServer.setResponse(MAIN_FRAME_FILE, data, null);
int firstInputDelay4 = RecordHistogram.getHistogramTotalCountForTesting(
"PageLoad.InteractiveTiming.FirstInputDelay4");
loadUrlSync(url);
executeJavaScriptAndWaitForResult("document.getElementById('text1').select();");
dispatchDownAndUpKeyEvents(KeyEvent.KEYCODE_A);
AwActivityTestRule.pollInstrumentationThread(
() -> (1 + firstInputDelay4
== RecordHistogram.getHistogramTotalCountForTesting(
"PageLoad.InteractiveTiming.FirstInputDelay4")));
}
private String executeJavaScriptAndWaitForResult(String code) throws Throwable {
return mRule.executeJavaScriptAndWaitForResult(
mTestContainerView.getAwContents(), mContentsClient, code);
}
private void dispatchDownAndUpKeyEvents(final int code) throws Throwable {
dispatchKeyEvent(new KeyEvent(SystemClock.uptimeMillis(), SystemClock.uptimeMillis(),
KeyEvent.ACTION_DOWN, code, 0));
dispatchKeyEvent(new KeyEvent(SystemClock.uptimeMillis(), SystemClock.uptimeMillis(),
KeyEvent.ACTION_UP, code, 0));
}
private boolean dispatchKeyEvent(final KeyEvent event) throws Throwable {
return TestThreadUtils.runOnUiThreadBlocking(new Callable<Boolean>() {
@Override
public Boolean call() {
return mTestContainerView.dispatchKeyEvent(event);
}
});
}
}
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