Commit fd165f29 authored by Michael Thiessen's avatar Michael Thiessen Committed by Commit Bot

Migrate remaining usages of ChromeActivityTestRule

Bug: 989569
Change-Id: If9f2bf207142253262bca092ca7dad6975893322
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2437026
Commit-Queue: Michael Thiessen <mthiesse@chromium.org>
Reviewed-by: default avatarAndrew Grieve <agrieve@chromium.org>
Cr-Commit-Position: refs/heads/master@{#811949}
parent 579711bb
...@@ -10,7 +10,6 @@ import android.support.test.InstrumentationRegistry; ...@@ -10,7 +10,6 @@ import android.support.test.InstrumentationRegistry;
import androidx.test.filters.LargeTest; import androidx.test.filters.LargeTest;
import org.hamcrest.Matchers;
import org.junit.After; import org.junit.After;
import org.junit.Assert; import org.junit.Assert;
import org.junit.Before; import org.junit.Before;
...@@ -23,21 +22,18 @@ import org.chromium.base.test.util.CommandLineFlags; ...@@ -23,21 +22,18 @@ import org.chromium.base.test.util.CommandLineFlags;
import org.chromium.base.test.util.DisableIf; import org.chromium.base.test.util.DisableIf;
import org.chromium.base.test.util.DisabledTest; import org.chromium.base.test.util.DisabledTest;
import org.chromium.chrome.browser.ChromeTabbedActivity; import org.chromium.chrome.browser.ChromeTabbedActivity;
import org.chromium.chrome.browser.ShortcutHelper;
import org.chromium.chrome.browser.flags.ChromeSwitches; import org.chromium.chrome.browser.flags.ChromeSwitches;
import org.chromium.chrome.browser.tab.Tab; import org.chromium.chrome.browser.tab.Tab;
import org.chromium.chrome.browser.webapps.WebApkActivityLifecycleUmaTracker; import org.chromium.chrome.browser.webapps.WebApkActivityLifecycleUmaTracker;
import org.chromium.chrome.browser.webapps.WebappActivity; import org.chromium.chrome.browser.webapps.WebApkActivityTestRule;
import org.chromium.chrome.test.ChromeActivityTestRule; import org.chromium.chrome.test.ChromeActivityTestRule;
import org.chromium.chrome.test.ChromeJUnit4ClassRunner; import org.chromium.chrome.test.ChromeJUnit4ClassRunner;
import org.chromium.chrome.test.ChromeTabbedActivityTestRule; import org.chromium.chrome.test.ChromeTabbedActivityTestRule;
import org.chromium.chrome.test.util.ApplicationTestUtils; import org.chromium.chrome.test.util.ApplicationTestUtils;
import org.chromium.chrome.test.util.ChromeTabUtils; import org.chromium.chrome.test.util.ChromeTabUtils;
import org.chromium.content_public.browser.test.util.Criteria;
import org.chromium.content_public.browser.test.util.CriteriaHelper; import org.chromium.content_public.browser.test.util.CriteriaHelper;
import org.chromium.content_public.browser.test.util.TestThreadUtils; import org.chromium.content_public.browser.test.util.TestThreadUtils;
import org.chromium.net.test.EmbeddedTestServer; import org.chromium.net.test.EmbeddedTestServer;
import org.chromium.webapk.lib.common.WebApkConstants;
/** /**
* Tests for startup timing histograms. * Tests for startup timing histograms.
...@@ -63,8 +59,7 @@ public class StartupLoadingMetricsTest { ...@@ -63,8 +59,7 @@ public class StartupLoadingMetricsTest {
public ChromeTabbedActivityTestRule mTabbedActivityTestRule = public ChromeTabbedActivityTestRule mTabbedActivityTestRule =
new ChromeTabbedActivityTestRule(); new ChromeTabbedActivityTestRule();
@Rule @Rule
public ChromeActivityTestRule<WebappActivity> mWebApkActivityTestRule = public WebApkActivityTestRule mWebApkActivityTestRule = new WebApkActivityTestRule();
new ChromeActivityTestRule<>(WebappActivity.class);
private String mTestPage; private String mTestPage;
private String mTestPage2; private String mTestPage2;
...@@ -118,34 +113,14 @@ public class StartupLoadingMetricsTest { ...@@ -118,34 +113,14 @@ public class StartupLoadingMetricsTest {
FIRST_CONTENTFUL_PAINT_HISTOGRAM + histogramSuffix)); FIRST_CONTENTFUL_PAINT_HISTOGRAM + histogramSuffix));
} }
private void startWebApkActivity(final String startUrl) {
Intent intent =
new Intent(InstrumentationRegistry.getTargetContext(), WebappActivity.class);
intent.putExtra(WebApkConstants.EXTRA_WEBAPK_PACKAGE_NAME, "org.chromium.webapk.test");
intent.putExtra(ShortcutHelper.EXTRA_URL, startUrl);
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
WebappActivity webApkActivity =
(WebappActivity) InstrumentationRegistry.getInstrumentation().startActivitySync(
intent);
mWebApkActivityTestRule.setActivity(webApkActivity);
InstrumentationRegistry.getInstrumentation().waitForIdleSync();
CriteriaHelper.pollInstrumentationThread(() -> {
Criteria.checkThat(mWebApkActivityTestRule.getActivity().getActivityTab(),
Matchers.notNullValue());
}, 10000L, CriteriaHelper.DEFAULT_POLLING_INTERVAL);
ChromeTabUtils.waitForTabPageLoaded(
mWebApkActivityTestRule.getActivity().getActivityTab(), startUrl);
}
/** /**
* Tests that the startup loading histograms are recorded only once on startup. * Tests that the startup loading histograms are recorded only once on startup.
*/ */
@Test @Test
@LargeTest @LargeTest
public void testWebApkStartRecorded() throws Exception { public void testWebApkStartRecorded() throws Exception {
runAndWaitForPageLoadMetricsRecorded(() -> startWebApkActivity(mTestPage)); runAndWaitForPageLoadMetricsRecorded(
() -> mWebApkActivityTestRule.startWebApkActivity(mTestPage));
assertHistogramsRecorded(1, WEBAPK_SUFFIX); assertHistogramsRecorded(1, WEBAPK_SUFFIX);
loadUrlAndWaitForPageLoadMetricsRecorded(mWebApkActivityTestRule, mTestPage2); loadUrlAndWaitForPageLoadMetricsRecorded(mWebApkActivityTestRule, mTestPage2);
assertHistogramsRecorded(1, WEBAPK_SUFFIX); assertHistogramsRecorded(1, WEBAPK_SUFFIX);
...@@ -215,7 +190,8 @@ public class StartupLoadingMetricsTest { ...@@ -215,7 +190,8 @@ public class StartupLoadingMetricsTest {
@Test @Test
@LargeTest @LargeTest
public void testWebApkErrorPageNotRecorded() throws Exception { public void testWebApkErrorPageNotRecorded() throws Exception {
runAndWaitForPageLoadMetricsRecorded(() -> startWebApkActivity(mErrorPage)); runAndWaitForPageLoadMetricsRecorded(
() -> mWebApkActivityTestRule.startWebApkActivity(mErrorPage));
assertHistogramsRecorded(0, WEBAPK_SUFFIX); assertHistogramsRecorded(0, WEBAPK_SUFFIX);
loadUrlAndWaitForPageLoadMetricsRecorded(mWebApkActivityTestRule, mTestPage2); loadUrlAndWaitForPageLoadMetricsRecorded(mWebApkActivityTestRule, mTestPage2);
assertHistogramsRecorded(0, WEBAPK_SUFFIX); assertHistogramsRecorded(0, WEBAPK_SUFFIX);
......
...@@ -52,8 +52,26 @@ public class WebApkActivityTestRule extends ChromeActivityTestRule<WebappActivit ...@@ -52,8 +52,26 @@ public class WebApkActivityTestRule extends ChromeActivityTestRule<WebappActivit
BrowserServicesIntentDataProvider webApkIntentDataProvider) { BrowserServicesIntentDataProvider webApkIntentDataProvider) {
WebappInfo webApkInfo = WebappInfo.create(webApkIntentDataProvider); WebappInfo webApkInfo = WebappInfo.create(webApkIntentDataProvider);
Intent intent = createIntent(webApkInfo); Intent intent = createIntent(webApkInfo);
WebappActivity.setIntentDataProviderForTesting(webApkIntentDataProvider); WebappActivity.setIntentDataProviderForTesting(webApkIntentDataProvider);
return startWebApkActivity(intent, webApkInfo.url());
}
/**
* Launches a WebAPK Activity and waits for the page to have finished loading and for the splash
* screen to be hidden.
*/
public WebappActivity startWebApkActivity(final String startUrl) {
Intent intent =
new Intent(InstrumentationRegistry.getTargetContext(), WebappActivity.class);
intent.putExtra(WebApkConstants.EXTRA_WEBAPK_PACKAGE_NAME, "org.chromium.webapk.test");
intent.putExtra(ShortcutHelper.EXTRA_URL, startUrl);
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
return startWebApkActivity(intent, startUrl);
}
private WebappActivity startWebApkActivity(final Intent intent, final String startUrl) {
final WebappActivity webApkActivity = final WebappActivity webApkActivity =
(WebappActivity) InstrumentationRegistry.getInstrumentation().startActivitySync( (WebappActivity) InstrumentationRegistry.getInstrumentation().startActivitySync(
intent); intent);
...@@ -64,9 +82,8 @@ public class WebApkActivityTestRule extends ChromeActivityTestRule<WebappActivit ...@@ -64,9 +82,8 @@ public class WebApkActivityTestRule extends ChromeActivityTestRule<WebappActivit
Criteria.checkThat(webApkActivity.getActivityTab(), Matchers.notNullValue()); Criteria.checkThat(webApkActivity.getActivityTab(), Matchers.notNullValue());
}, STARTUP_TIMEOUT, CriteriaHelper.DEFAULT_POLLING_INTERVAL); }, STARTUP_TIMEOUT, CriteriaHelper.DEFAULT_POLLING_INTERVAL);
ChromeTabUtils.waitForTabPageLoaded(webApkActivity.getActivityTab(), webApkInfo.url()); ChromeTabUtils.waitForTabPageLoaded(webApkActivity.getActivityTab(), startUrl);
WebappActivityTestRule.waitUntilSplashHides(webApkActivity); WebappActivityTestRule.waitUntilSplashHides(webApkActivity);
return webApkActivity; return webApkActivity;
} }
......
...@@ -95,11 +95,7 @@ public class ChromeActivityTestRule<T extends ChromeActivity> extends ActivityTe ...@@ -95,11 +95,7 @@ public class ChromeActivityTestRule<T extends ChromeActivity> extends ActivityTe
@Rule @Rule
private EmbeddedTestServerRule mTestServerRule = new EmbeddedTestServerRule(); private EmbeddedTestServerRule mTestServerRule = new EmbeddedTestServerRule();
/** protected ChromeActivityTestRule(Class<T> activityClass) {
* @deprecated Please use a derived rule directly. ChromeActivity is never directly launched.
*/
@Deprecated
public ChromeActivityTestRule(Class<T> activityClass) {
this(activityClass, false); this(activityClass, false);
} }
......
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