Commit 44803ec9 authored by Brandon Wylie's avatar Brandon Wylie Committed by Commit Bot

Revert "Migrate remaining usages of ChromeActivityTestRule"

This reverts commit fd165f29.

Reason for revert: Failing build on ToT:
         new ChromeActivityTestRule<>(ChromeActivity.class);
         ^
reason: cannot infer type-variable(s) T

Original change's description:
> 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: Andrew Grieve <agrieve@chromium.org>
> Cr-Commit-Position: refs/heads/master@{#811949}

TBR=mthiesse@chromium.org,agrieve@chromium.org

Change-Id: I5970dcbad4685e2ae423b0bf5bdcd8beb7b00396
No-Presubmit: true
No-Tree-Checks: true
No-Try: true
Bug: 989569
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2441672Reviewed-by: default avatarBrandon Wylie <wylieb@chromium.org>
Commit-Queue: Brandon Wylie <wylieb@chromium.org>
Cr-Commit-Position: refs/heads/master@{#812334}
parent 3b275b91
......@@ -10,6 +10,7 @@ import android.support.test.InstrumentationRegistry;
import androidx.test.filters.LargeTest;
import org.hamcrest.Matchers;
import org.junit.After;
import org.junit.Assert;
import org.junit.Before;
......@@ -22,18 +23,21 @@ import org.chromium.base.test.util.CommandLineFlags;
import org.chromium.base.test.util.DisableIf;
import org.chromium.base.test.util.DisabledTest;
import org.chromium.chrome.browser.ChromeTabbedActivity;
import org.chromium.chrome.browser.ShortcutHelper;
import org.chromium.chrome.browser.flags.ChromeSwitches;
import org.chromium.chrome.browser.tab.Tab;
import org.chromium.chrome.browser.webapps.WebApkActivityLifecycleUmaTracker;
import org.chromium.chrome.browser.webapps.WebApkActivityTestRule;
import org.chromium.chrome.browser.webapps.WebappActivity;
import org.chromium.chrome.test.ChromeActivityTestRule;
import org.chromium.chrome.test.ChromeJUnit4ClassRunner;
import org.chromium.chrome.test.ChromeTabbedActivityTestRule;
import org.chromium.chrome.test.util.ApplicationTestUtils;
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.TestThreadUtils;
import org.chromium.net.test.EmbeddedTestServer;
import org.chromium.webapk.lib.common.WebApkConstants;
/**
* Tests for startup timing histograms.
......@@ -59,7 +63,8 @@ public class StartupLoadingMetricsTest {
public ChromeTabbedActivityTestRule mTabbedActivityTestRule =
new ChromeTabbedActivityTestRule();
@Rule
public WebApkActivityTestRule mWebApkActivityTestRule = new WebApkActivityTestRule();
public ChromeActivityTestRule<WebappActivity> mWebApkActivityTestRule =
new ChromeActivityTestRule<>(WebappActivity.class);
private String mTestPage;
private String mTestPage2;
......@@ -113,14 +118,34 @@ public class StartupLoadingMetricsTest {
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.
*/
@Test
@LargeTest
public void testWebApkStartRecorded() throws Exception {
runAndWaitForPageLoadMetricsRecorded(
() -> mWebApkActivityTestRule.startWebApkActivity(mTestPage));
runAndWaitForPageLoadMetricsRecorded(() -> startWebApkActivity(mTestPage));
assertHistogramsRecorded(1, WEBAPK_SUFFIX);
loadUrlAndWaitForPageLoadMetricsRecorded(mWebApkActivityTestRule, mTestPage2);
assertHistogramsRecorded(1, WEBAPK_SUFFIX);
......@@ -190,8 +215,7 @@ public class StartupLoadingMetricsTest {
@Test
@LargeTest
public void testWebApkErrorPageNotRecorded() throws Exception {
runAndWaitForPageLoadMetricsRecorded(
() -> mWebApkActivityTestRule.startWebApkActivity(mErrorPage));
runAndWaitForPageLoadMetricsRecorded(() -> startWebApkActivity(mErrorPage));
assertHistogramsRecorded(0, WEBAPK_SUFFIX);
loadUrlAndWaitForPageLoadMetricsRecorded(mWebApkActivityTestRule, mTestPage2);
assertHistogramsRecorded(0, WEBAPK_SUFFIX);
......
......@@ -52,26 +52,8 @@ public class WebApkActivityTestRule extends ChromeActivityTestRule<WebappActivit
BrowserServicesIntentDataProvider webApkIntentDataProvider) {
WebappInfo webApkInfo = WebappInfo.create(webApkIntentDataProvider);
Intent intent = createIntent(webApkInfo);
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) {
WebappActivity.setIntentDataProviderForTesting(webApkIntentDataProvider);
final WebappActivity webApkActivity =
(WebappActivity) InstrumentationRegistry.getInstrumentation().startActivitySync(
intent);
......@@ -82,8 +64,9 @@ public class WebApkActivityTestRule extends ChromeActivityTestRule<WebappActivit
Criteria.checkThat(webApkActivity.getActivityTab(), Matchers.notNullValue());
}, STARTUP_TIMEOUT, CriteriaHelper.DEFAULT_POLLING_INTERVAL);
ChromeTabUtils.waitForTabPageLoaded(webApkActivity.getActivityTab(), startUrl);
ChromeTabUtils.waitForTabPageLoaded(webApkActivity.getActivityTab(), webApkInfo.url());
WebappActivityTestRule.waitUntilSplashHides(webApkActivity);
return webApkActivity;
}
......
......@@ -95,7 +95,11 @@ public class ChromeActivityTestRule<T extends ChromeActivity> extends ActivityTe
@Rule
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);
}
......
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