Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(760)

Unified Diff: chrome/android/javatests/src/org/chromium/chrome/browser/ntp/snippets/ArticleSnippetsTest.java

Issue 2831823003: Convert ChromeActivityTestCaseBase direct children to JUnit4 (Closed)
Patch Set: rebase and convert newly added test Created 3 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: chrome/android/javatests/src/org/chromium/chrome/browser/ntp/snippets/ArticleSnippetsTest.java
diff --git a/chrome/android/javatests/src/org/chromium/chrome/browser/ntp/snippets/ArticleSnippetsTest.java b/chrome/android/javatests/src/org/chromium/chrome/browser/ntp/snippets/ArticleSnippetsTest.java
index b4c346da828b43b04091726f72d4813bc192bb77..0943a21ddcb6e3d9745f8231b346ed5f516a27e4 100644
--- a/chrome/android/javatests/src/org/chromium/chrome/browser/ntp/snippets/ArticleSnippetsTest.java
+++ b/chrome/android/javatests/src/org/chromium/chrome/browser/ntp/snippets/ArticleSnippetsTest.java
@@ -5,16 +5,24 @@
package org.chromium.chrome.browser.ntp.snippets;
import android.graphics.BitmapFactory;
+import android.support.test.InstrumentationRegistry;
import android.support.test.filters.MediumTest;
import android.util.TypedValue;
import android.view.ViewGroup;
import android.widget.FrameLayout;
+import org.junit.Before;
+import org.junit.Rule;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+
import org.chromium.base.ThreadUtils;
+import org.chromium.base.test.util.CommandLineFlags;
import org.chromium.base.test.util.Feature;
import org.chromium.base.test.util.RetryOnFailure;
import org.chromium.chrome.R;
import org.chromium.chrome.browser.ChromeActivity;
+import org.chromium.chrome.browser.ChromeSwitches;
import org.chromium.chrome.browser.favicon.FaviconHelper.FaviconImageCallback;
import org.chromium.chrome.browser.favicon.FaviconHelper.IconAvailabilityCallback;
import org.chromium.chrome.browser.favicon.LargeIconBridge.LargeIconCallback;
@@ -31,7 +39,8 @@ import org.chromium.chrome.browser.suggestions.SuggestionsUiDelegate;
import org.chromium.chrome.browser.widget.displaystyle.HorizontalDisplayStyle;
import org.chromium.chrome.browser.widget.displaystyle.UiConfig;
import org.chromium.chrome.browser.widget.displaystyle.VerticalDisplayStyle;
-import org.chromium.chrome.test.ChromeActivityTestCaseBase;
+import org.chromium.chrome.test.ChromeActivityTestRule;
+import org.chromium.chrome.test.ChromeJUnit4ClassRunner;
import org.chromium.chrome.test.util.RenderUtils.ViewRenderer;
import org.chromium.chrome.test.util.browser.suggestions.DummySuggestionsMetricsReporter;
import org.chromium.chrome.test.util.browser.suggestions.FakeSuggestionsSource;
@@ -42,7 +51,14 @@ import java.util.Arrays;
/**
* Tests for the appearance of Article Snippets.
*/
-public class ArticleSnippetsTest extends ChromeActivityTestCaseBase<ChromeActivity> {
+@RunWith(ChromeJUnit4ClassRunner.class)
+@CommandLineFlags.Add({ChromeSwitches.DISABLE_FIRST_RUN_EXPERIENCE,
+ ChromeActivityTestRule.DISABLE_NETWORK_PREDICTION_FLAG})
+public class ArticleSnippetsTest {
+ @Rule
+ public ChromeActivityTestRule<ChromeActivity> mActivityTestRule =
+ new ChromeActivityTestRule<>(ChromeActivity.class);
+
private ViewRenderer mViewRenderer;
private SuggestionsUiDelegate mUiDelegate;
@@ -53,10 +69,7 @@ public class ArticleSnippetsTest extends ChromeActivityTestCaseBase<ChromeActivi
private FrameLayout mContentView;
private UiConfig mUiConfig;
- public ArticleSnippetsTest() {
- super(ChromeActivity.class);
- }
-
+ @Test
@MediumTest
@Feature({"ArticleSnippets", "RenderTest"})
@RetryOnFailure
@@ -66,12 +79,12 @@ public class ArticleSnippetsTest extends ChromeActivityTestCaseBase<ChromeActivi
public void run() {
setupTestData();
- mContentView = new FrameLayout(getActivity());
+ mContentView = new FrameLayout(mActivityTestRule.getActivity());
mUiConfig = new UiConfig(mContentView);
- getActivity().setContentView(mContentView);
+ mActivityTestRule.getActivity().setContentView(mContentView);
- mRecyclerView = new SuggestionsRecyclerView(getActivity());
+ mRecyclerView = new SuggestionsRecyclerView(mActivityTestRule.getActivity());
mContentView.addView(mRecyclerView);
mAdapter = new NewTabPageAdapter(mUiDelegate, /* aboveTheFold = */ null, mUiConfig,
@@ -82,7 +95,7 @@ public class ArticleSnippetsTest extends ChromeActivityTestCaseBase<ChromeActivi
}
});
- getInstrumentation().waitForIdleSync();
+ InstrumentationRegistry.getInstrumentation().waitForIdleSync();
int first = mAdapter.getFirstCardPosition();
mViewRenderer.renderAndCompare(mRecyclerView.getChildAt(first), "short_snippet");
@@ -111,7 +124,7 @@ public class ArticleSnippetsTest extends ChromeActivityTestCaseBase<ChromeActivi
}
});
- getInstrumentation().waitForIdleSync();
+ InstrumentationRegistry.getInstrumentation().waitForIdleSync();
mViewRenderer.renderAndCompare(mRecyclerView.getChildAt(first), "short_snippet_narrow");
mViewRenderer.renderAndCompare(mRecyclerView.getChildAt(first + 1), "long_snippet_narrow");
@@ -132,8 +145,9 @@ public class ArticleSnippetsTest extends ChromeActivityTestCaseBase<ChromeActivi
1466614774, // Publish timestamp
10f, // Score
1466634774); // Fetch timestamp
- shortSnippet.setThumbnailBitmap(BitmapFactory.decodeResource(getActivity().getResources(),
- R.drawable.signin_promo_illustration));
+ shortSnippet.setThumbnailBitmap(
+ BitmapFactory.decodeResource(mActivityTestRule.getActivity().getResources(),
+ R.drawable.signin_promo_illustration));
SnippetArticle longSnippet = new SnippetArticle(fullCategory, "id2",
new String(new char[20]).replace("\0", "Snippet "),
@@ -175,16 +189,11 @@ public class ArticleSnippetsTest extends ChromeActivityTestCaseBase<ChromeActivi
minimalCategory, Arrays.asList(minimalSnippet, minimalSnippet2));
}
- @Override
- public void startMainActivity() throws InterruptedException {
- startMainActivityOnBlankPage();
- mViewRenderer = new ViewRenderer(getActivity(),
+ @Before
+ public void setUp() throws Exception {
+ mActivityTestRule.startMainActivityOnBlankPage();
+ mViewRenderer = new ViewRenderer(mActivityTestRule.getActivity(),
"chrome/test/data/android/render_tests", this.getClass().getSimpleName());
- }
-
- @Override
- protected void setUp() throws Exception {
- super.setUp();
mUiDelegate = new MockUiDelegate();
mSnippetsSource = new FakeSuggestionsSource();
}
@@ -205,8 +214,9 @@ public class ArticleSnippetsTest extends ChromeActivityTestCaseBase<ChromeActivi
public void run() {
// Return an arbitrary drawable.
faviconCallback.onFaviconAvailable(
- BitmapFactory.decodeResource(getActivity().getResources(),
- R.drawable.star_green),
+ BitmapFactory.decodeResource(
+ mActivityTestRule.getActivity().getResources(),
+ R.drawable.star_green),
url);
}
});

Powered by Google App Engine
This is Rietveld 408576698