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

Remove Feed setup from ChromeTabbedActivityTestRule

The Feed setup isn't used by most tests and is required to happen once
per process init, which make batching tests that use
ChromeTabbedActivityTestRule more difficult.

There's already a rule to do what CTATestRule was doing, so I've
migrated the only test that seems to care about that setup to the
FeedDataInjectRule.

Bug: 989569
Change-Id: I8142a3904276a294356789f246d977c93f6e48a9
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2437691Reviewed-by: default avatarSky Malice <skym@chromium.org>
Commit-Queue: Michael Thiessen <mthiesse@chromium.org>
Cr-Commit-Position: refs/heads/master@{#811714}
parent 7f9f9dff
......@@ -41,8 +41,7 @@ import java.util.concurrent.TimeoutException;
* public FeedDataInjectRule mDataInjector = new FeedDataInjectRule();
*
* @Rule
* public ChromeActivityTestRule<ChromeTabbedActivity> mActivityTestRule =
* new ChromeActivityTestRule(ChromeTabbedActivity.class);
* public ChromeTabbedActivityTestRule mActivityTestRule = new ChromeTabbedActivityTestRule();
*
* @Test
* @Feature({"FeedNewTabPage"})
......@@ -58,13 +57,8 @@ import java.util.concurrent.TimeoutException;
* }
* }
* </pre>
*
* Note when using this test rule, do not also use ChromeTabbedActivityTestRule.
* ChromeTabbedActivityTestRule also try to set a default feed response file and
* it could results to strange behaviors in test, such as always see the same
* set of cards in each test case.
*/
final class FeedDataInjectRule extends TestWatcher {
public final class FeedDataInjectRule extends TestWatcher {
private static final String TAG = "FeedDataInjectRule";
private static final int FIRST_CARD_BASE_POSITION = 2;
......
......@@ -21,7 +21,6 @@ import androidx.test.espresso.contrib.RecyclerViewActions;
import androidx.test.espresso.matcher.RootMatchers;
import androidx.test.filters.MediumTest;
import org.junit.After;
import org.junit.Assert;
import org.junit.Before;
import org.junit.Rule;
......@@ -31,7 +30,8 @@ import org.junit.runner.RunWith;
import org.chromium.base.test.util.CallbackHelper;
import org.chromium.base.test.util.CommandLineFlags;
import org.chromium.base.test.util.Feature;
import org.chromium.chrome.browser.feed.FeedProcessScopeFactory;
import org.chromium.chrome.browser.feed.DataFilePath;
import org.chromium.chrome.browser.feed.FeedDataInjectRule;
import org.chromium.chrome.browser.feed.shared.stream.Stream;
import org.chromium.chrome.browser.flags.ChromeFeatureList;
import org.chromium.chrome.browser.flags.ChromeSwitches;
......@@ -64,8 +64,10 @@ import org.chromium.content_public.browser.test.util.TestThreadUtils;
private static final int FIRST_CARD_POSITION = 3;
@Rule
public ChromeTabbedActivityTestRule mActivityTestRule =
new ChromeTabbedActivityTestRule(FEED_TEST_RESPONSE_FILE_PATH);
public ChromeTabbedActivityTestRule mActivityTestRule = new ChromeTabbedActivityTestRule();
@Rule
public FeedDataInjectRule mFeedDataInjector = new FeedDataInjectRule(false);
@Rule
public SuggestionsDependenciesRule mSuggestionsDeps = new SuggestionsDependenciesRule();
......@@ -105,14 +107,10 @@ import org.chromium.content_public.browser.test.util.TestThreadUtils;
mStream.addOnContentChangedListener(mTestObserver);
}
@After
public void tearDown() {
FeedProcessScopeFactory.setTestNetworkClient(null);
}
@Test
@MediumTest
@Feature({"FeedNewTabPage"})
@DataFilePath(FEED_TEST_RESPONSE_FILE_PATH)
public void testShowTooltip() throws Exception {
int callCount = mTestObserver.firstCardShownCallback.getCallCount();
TestThreadUtils.runOnUiThreadBlocking(() -> mStream.triggerRefresh());
......
......@@ -4,55 +4,13 @@
package org.chromium.chrome.test;
import org.junit.runner.Description;
import org.junit.runners.model.Statement;
import org.chromium.base.test.util.UrlUtils;
import org.chromium.chrome.browser.ChromeTabbedActivity;
import org.chromium.chrome.browser.feed.FeedProcessScopeFactory;
import org.chromium.chrome.browser.feed.TestNetworkClient;
/**
* Custom ActivityTestRule for test using ChromeTabbedActivity
* Custom ActivityTestRule for tests using ChromeTabbedActivity
*/
public class ChromeTabbedActivityTestRule extends ChromeActivityTestRule<ChromeTabbedActivity> {
// Response file for Feed's network stub.
private static final String DEFAULT_FEED_TEST_RESPONSE_FILE_PATH =
"/chrome/test/data/android/feed/feed_large.gcl.bin";
private final String mFeedTestResponseFilePath;
public ChromeTabbedActivityTestRule() {
this(DEFAULT_FEED_TEST_RESPONSE_FILE_PATH);
}
/**
* @param feedTestResponseFilePath The file path of the response that the feed library returns
* in tests.
*/
public ChromeTabbedActivityTestRule(String feedTestResponseFilePath) {
super(ChromeTabbedActivity.class);
mFeedTestResponseFilePath = feedTestResponseFilePath;
}
@Override
public Statement apply(final Statement base, Description description) {
Statement tabbedActivityStatement = new Statement() {
@Override
public void evaluate() throws Throwable {
// Setup Feed stubs.
TestNetworkClient client = new TestNetworkClient();
client.setNetworkResponseFile(
UrlUtils.getIsolatedTestFilePath(mFeedTestResponseFilePath));
FeedProcessScopeFactory.setTestNetworkClient(client);
base.evaluate();
// Teardown the network stubs for Feed if they've been setup.
FeedProcessScopeFactory.setTestNetworkClient(null);
}
};
return super.apply(tabbedActivityStatement, description);
}
}
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