Commit 45f5a4bc authored by Brandon Wylie's avatar Brandon Wylie Committed by Commit Bot

Reland "Migrate remaining usages of ChromeActivityTestRule"

This reverts commit 44803ec9.

Reason for revert: Fixed already

Original change's description:
> 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/+/2441672
> Reviewed-by: Brandon Wylie <wylieb@chromium.org>
> Commit-Queue: Brandon Wylie <wylieb@chromium.org>
> Cr-Commit-Position: refs/heads/master@{#812334}

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

# Not skipping CQ checks because this is a reland.

Bug: 989569
Change-Id: Ifc9054d915cacdef40394661472aff4653b123a2
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2441673Reviewed-by: default avatarBrandon Wylie <wylieb@chromium.org>
Reviewed-by: default avatarMichael Thiessen <mthiesse@chromium.org>
Commit-Queue: Brandon Wylie <wylieb@chromium.org>
Cr-Commit-Position: refs/heads/master@{#812428}
parent 22532c90
......@@ -10,7 +10,6 @@ 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;
......@@ -23,21 +22,18 @@ 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.WebappActivity;
import org.chromium.chrome.browser.webapps.WebApkActivityTestRule;
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.
......@@ -63,8 +59,7 @@ public class StartupLoadingMetricsTest {
public ChromeTabbedActivityTestRule mTabbedActivityTestRule =
new ChromeTabbedActivityTestRule();
@Rule
public ChromeActivityTestRule<WebappActivity> mWebApkActivityTestRule =
new ChromeActivityTestRule<>(WebappActivity.class);
public WebApkActivityTestRule mWebApkActivityTestRule = new WebApkActivityTestRule();
private String mTestPage;
private String mTestPage2;
......@@ -118,34 +113,14 @@ 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(() -> startWebApkActivity(mTestPage));
runAndWaitForPageLoadMetricsRecorded(
() -> mWebApkActivityTestRule.startWebApkActivity(mTestPage));
assertHistogramsRecorded(1, WEBAPK_SUFFIX);
loadUrlAndWaitForPageLoadMetricsRecorded(mWebApkActivityTestRule, mTestPage2);
assertHistogramsRecorded(1, WEBAPK_SUFFIX);
......@@ -215,7 +190,8 @@ public class StartupLoadingMetricsTest {
@Test
@LargeTest
public void testWebApkErrorPageNotRecorded() throws Exception {
runAndWaitForPageLoadMetricsRecorded(() -> startWebApkActivity(mErrorPage));
runAndWaitForPageLoadMetricsRecorded(
() -> mWebApkActivityTestRule.startWebApkActivity(mErrorPage));
assertHistogramsRecorded(0, WEBAPK_SUFFIX);
loadUrlAndWaitForPageLoadMetricsRecorded(mWebApkActivityTestRule, mTestPage2);
assertHistogramsRecorded(0, WEBAPK_SUFFIX);
......
......@@ -52,8 +52,26 @@ 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) {
final WebappActivity webApkActivity =
(WebappActivity) InstrumentationRegistry.getInstrumentation().startActivitySync(
intent);
......@@ -64,9 +82,8 @@ public class WebApkActivityTestRule extends ChromeActivityTestRule<WebappActivit
Criteria.checkThat(webApkActivity.getActivityTab(), Matchers.notNullValue());
}, STARTUP_TIMEOUT, CriteriaHelper.DEFAULT_POLLING_INTERVAL);
ChromeTabUtils.waitForTabPageLoaded(webApkActivity.getActivityTab(), webApkInfo.url());
ChromeTabUtils.waitForTabPageLoaded(webApkActivity.getActivityTab(), startUrl);
WebappActivityTestRule.waitUntilSplashHides(webApkActivity);
return webApkActivity;
}
......
......@@ -95,11 +95,7 @@ public class ChromeActivityTestRule<T extends ChromeActivity> extends ActivityTe
@Rule
private EmbeddedTestServerRule mTestServerRule = new EmbeddedTestServerRule();
/**
* @deprecated Please use a derived rule directly. ChromeActivity is never directly launched.
*/
@Deprecated
public ChromeActivityTestRule(Class<T> activityClass) {
protected 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