Skip to content

Commit

Permalink
Migrate IntentsTestRule to BaseActivityTestRule
Browse files Browse the repository at this point in the history
Use BaseActivityTestRule instead and explicitly trigger
Intents#init/release when appropriate. In most cases the rule is just
used for intent recording and intercepting purposes only without even
launching the activity so just delete it.

Bug: 1238144
Change-Id: I0a183478941ab19bb828693e087d7df355dd8e4f
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/3086526
Reviewed-by: Michael Thiessen <[email protected]>
Commit-Queue: Hazem Ashmawy <[email protected]>
Cr-Commit-Position: refs/heads/master@{#910793}
  • Loading branch information
HazemSamir authored and Chromium LUCI CQ committed Aug 11, 2021
1 parent dc2221e commit 928e452
Show file tree
Hide file tree
Showing 5 changed files with 12 additions and 34 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@
import androidx.recyclerview.widget.RecyclerView;
import androidx.test.espresso.contrib.RecyclerViewActions;
import androidx.test.espresso.intent.Intents;
import androidx.test.espresso.intent.rule.IntentsTestRule;
import androidx.test.filters.MediumTest;

import org.junit.After;
Expand All @@ -52,7 +51,6 @@
import org.chromium.base.test.util.MinAndroidSdkLevel;
import org.chromium.base.test.util.Restriction;
import org.chromium.chrome.browser.ChromeTabbedActivity;
import org.chromium.chrome.browser.app.ChromeActivity;
import org.chromium.chrome.browser.flags.ChromeFeatureList;
import org.chromium.chrome.browser.flags.ChromeSwitches;
import org.chromium.chrome.browser.price_tracking.PriceDropNotificationManager;
Expand Down Expand Up @@ -92,14 +90,8 @@ public class PriceAlertsMessageCardTest {
public ChromeRenderTestRule mRenderTestRule =
ChromeRenderTestRule.Builder.withPublicCorpus().build();

@Rule
public IntentsTestRule<ChromeActivity> mIntentTestRule =
new IntentsTestRule<>(ChromeActivity.class, false, false);

@Before
public void setUp() {
// Since we don't use IntentsTestRule to start an Activity, we have to call init() here.
// IntentsTestRule will call release() regardless of whether an Activity was started.
Intents.init();
PriceTrackingUtilities.setIsSignedInAndSyncEnabledForTesting(true);
mMockNotificationManager = new MockNotificationManagerProxy();
Expand All @@ -119,6 +111,7 @@ public void tearDown() {
PriceTrackingUtilities.setIsSignedInAndSyncEnabledForTesting(null);
PriceDropNotificationManager.setNotificationManagerForTesting(null);
ActivityTestUtils.clearActivityOrientation(mActivityTestRule.getActivity());
Intents.release();
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@

import androidx.test.espresso.NoMatchingRootException;
import androidx.test.espresso.intent.Intents;
import androidx.test.espresso.intent.rule.IntentsTestRule;
import androidx.test.filters.MediumTest;

import org.junit.After;
Expand All @@ -49,7 +48,6 @@
import org.chromium.base.test.util.FlakyTest;
import org.chromium.base.test.util.Restriction;
import org.chromium.chrome.browser.ChromeTabbedActivity;
import org.chromium.chrome.browser.app.ChromeActivity;
import org.chromium.chrome.browser.flags.ChromeFeatureList;
import org.chromium.chrome.browser.flags.ChromeSwitches;
import org.chromium.chrome.tab_ui.R;
Expand Down Expand Up @@ -92,14 +90,8 @@ public class PriceTrackingDialogTest {
.setRevision(RENDER_TEST_REVISION)
.build();

@Rule
public IntentsTestRule<ChromeActivity> mIntentTestRule =
new IntentsTestRule<>(ChromeActivity.class, false, false);

@Before
public void setUp() throws Exception {
// Since we don't use IntentsTestRule to start an Activity, we have to call init() here.
// IntentsTestRule will call release() regardless of whether an Activity was started.
Intents.init();
PriceTrackingUtilities.setIsSignedInAndSyncEnabledForTesting(true);
mActivityTestRule.startMainActivityOnBlankPage();
Expand All @@ -114,6 +106,7 @@ public void setUp() throws Exception {
public void tearDown() {
PriceTrackingUtilities.setIsSignedInAndSyncEnabledForTesting(null);
ActivityTestUtils.clearActivityOrientation(mActivityTestRule.getActivity());
Intents.release();
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,6 @@
import androidx.test.espresso.Espresso;
import androidx.test.espresso.contrib.RecyclerViewActions;
import androidx.test.espresso.intent.Intents;
import androidx.test.espresso.intent.rule.IntentsTestRule;
import androidx.test.filters.MediumTest;

import org.junit.After;
Expand All @@ -93,7 +92,6 @@
import org.chromium.base.test.util.FlakyTest;
import org.chromium.base.test.util.Restriction;
import org.chromium.chrome.browser.ChromeTabbedActivity;
import org.chromium.chrome.browser.app.ChromeActivity;
import org.chromium.chrome.browser.compositor.layouts.Layout;
import org.chromium.chrome.browser.flags.ChromeFeatureList;
import org.chromium.chrome.browser.flags.ChromeSwitches;
Expand Down Expand Up @@ -144,10 +142,6 @@ public class TabGridDialogTest {
public ChromeRenderTestRule mRenderTestRule =
ChromeRenderTestRule.Builder.withPublicCorpus().build();

@Rule
public IntentsTestRule<ChromeActivity> mShareActivityTestRule =
new IntentsTestRule<>(ChromeActivity.class, false, false);

@BeforeClass
public static void setUpBeforeActivityLaunched() {
ChromeNightModeTestUtils.setUpNightModeBeforeChromeActivityLaunched();
Expand All @@ -161,8 +155,6 @@ public void setupNightMode(boolean nightModeEnabled) {

@Before
public void setUp() {
// Since we don't use IntentsTestRule to start an Activity, we have to call init() here.
// IntentsTestRule will call release() regardless of whether an Activity was started.
Intents.init();
TabUiFeatureUtilities.setTabManagementModuleSupportedForTesting(true);
mActivityTestRule.startMainActivityOnBlankPage();
Expand All @@ -176,6 +168,7 @@ public void setUp() {
public void tearDown() {
TabUiFeatureUtilities.setTabManagementModuleSupportedForTesting(null);
ActivityTestUtils.clearActivityOrientation(mActivityTestRule.getActivity());
Intents.release();
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,16 @@

import androidx.recyclerview.widget.RecyclerView;
import androidx.test.espresso.intent.Intents;
import androidx.test.espresso.intent.rule.IntentsTestRule;
import androidx.test.filters.SmallTest;

import org.junit.Assert;
import org.junit.After;
import org.junit.Assert;
import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
import org.junit.runner.RunWith;

import org.chromium.base.test.BaseActivityTestRule;
import org.chromium.base.test.params.ParameterAnnotations;
import org.chromium.base.test.params.ParameterProvider;
import org.chromium.base.test.params.ParameterSet;
Expand Down Expand Up @@ -58,8 +58,8 @@
public class HistoryActivityScrollingTest {
// clang-format on
@Rule
public IntentsTestRule<HistoryActivity> mActivityTestRule =
new IntentsTestRule<>(HistoryActivity.class, false, false);
public BaseActivityTestRule<HistoryActivity> mActivityTestRule =
new BaseActivityTestRule<>(HistoryActivity.class);

@ParameterAnnotations.ClassParameter
private static List<ParameterSet> sClassParams = new TestParamsProvider().getParameters();
Expand Down Expand Up @@ -153,15 +153,13 @@ public void setUp() throws Exception {

@After
public void tearDown() {
if (mActivityTestRule.getActivity() == null) {
// IntentsTestRule assumes the Activity was started when tearing down the rule, so we
// need to work around that.
Intents.init();
}
Intents.release();
}

private void launchHistoryActivity() {
HistoryActivity activity = mActivityTestRule.launchActivity(null);
mActivityTestRule.launchActivity(null);
HistoryActivity activity = mActivityTestRule.getActivity();
Intents.init();
TestThreadUtils.runOnUiThreadBlocking(() -> {
mHistoryManager = activity.getHistoryManagerForTests();
mAdapter = mHistoryManager.getContentManagerForTests().getAdapter();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@
@CommandLineFlags.Add({ChromeSwitches.DISABLE_FIRST_RUN_EXPERIENCE})
@Restriction(UiRestriction.RESTRICTION_TYPE_PHONE)
public class HistoryActivityTest {
// TODO(crbug.com/1238144): Migrate to BaseActivityTestRule.
@Rule
public final IntentsTestRule<HistoryActivity> mActivityTestRule =
new IntentsTestRule<>(HistoryActivity.class, false, false);
Expand Down

0 comments on commit 928e452

Please sign in to comment.