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

Unified Diff: chrome/android/javatests/src/org/chromium/chrome/browser/NavigationPopupTest.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/NavigationPopupTest.java
diff --git a/chrome/android/javatests/src/org/chromium/chrome/browser/NavigationPopupTest.java b/chrome/android/javatests/src/org/chromium/chrome/browser/NavigationPopupTest.java
index 682f709a0761ebb0640b03f7e547c9a5eee96699..d50d9ee5f189486ee032fe0bf78281af2752a3ce 100644
--- a/chrome/android/javatests/src/org/chromium/chrome/browser/NavigationPopupTest.java
+++ b/chrome/android/javatests/src/org/chromium/chrome/browser/NavigationPopupTest.java
@@ -8,12 +8,20 @@ import android.graphics.Bitmap;
import android.support.test.filters.MediumTest;
import android.support.test.filters.SmallTest;
+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.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.base.test.util.UrlUtils;
import org.chromium.chrome.browser.profiles.Profile;
-import org.chromium.chrome.test.ChromeActivityTestCaseBase;
+import org.chromium.chrome.test.ChromeActivityTestRule;
+import org.chromium.chrome.test.ChromeJUnit4ClassRunner;
import org.chromium.content.browser.test.util.Criteria;
import org.chromium.content.browser.test.util.CriteriaHelper;
import org.chromium.content_public.browser.LoadUrlParams;
@@ -21,23 +29,27 @@ import org.chromium.content_public.browser.NavigationController;
import org.chromium.content_public.browser.NavigationEntry;
import org.chromium.content_public.browser.NavigationHistory;
+import java.util.concurrent.atomic.AtomicReference;
+
/**
* Tests for the navigation popup.
*/
+@RunWith(ChromeJUnit4ClassRunner.class)
@RetryOnFailure
-public class NavigationPopupTest extends ChromeActivityTestCaseBase<ChromeActivity> {
+@CommandLineFlags.Add({ChromeSwitches.DISABLE_FIRST_RUN_EXPERIENCE,
+ ChromeActivityTestRule.DISABLE_NETWORK_PREDICTION_FLAG})
+public class NavigationPopupTest {
+ @Rule
+ public ChromeActivityTestRule<ChromeActivity> mActivityTestRule =
+ new ChromeActivityTestRule<>(ChromeActivity.class);
private static final int INVALID_NAVIGATION_INDEX = -1;
private Profile mProfile;
- public NavigationPopupTest() {
- super(ChromeActivity.class);
- }
-
- @Override
- protected void setUp() throws Exception {
- super.setUp();
+ @Before
+ public void setUp() throws Exception {
+ mActivityTestRule.startMainActivityOnBlankPage();
ThreadUtils.runOnUiThreadBlocking(new Runnable() {
@Override
public void run() {
@@ -46,11 +58,6 @@ public class NavigationPopupTest extends ChromeActivityTestCaseBase<ChromeActivi
});
}
- @Override
- public void startMainActivity() throws InterruptedException {
- startMainActivityOnBlankPage();
- }
-
// Exists solely to expose protected methods to this test.
private static class TestNavigationHistory extends NavigationHistory {
@Override
@@ -223,19 +230,25 @@ public class NavigationPopupTest extends ChromeActivityTestCaseBase<ChromeActivi
public void setEntryExtraData(int index, String key, String value) {}
}
+ @Test
@MediumTest
@Feature({"Navigation"})
public void testFaviconFetching() {
final TestNavigationController controller = new TestNavigationController();
- final NavigationPopup popup = new NavigationPopup(
- mProfile, getActivity(), controller, true);
- popup.setWidth(300);
- popup.setHeight(300);
- popup.setAnchorView(getActivity().getCurrentContentViewCore().getContainerView());
+ final AtomicReference<NavigationPopup> popupReference = new AtomicReference<>();
ThreadUtils.runOnUiThreadBlocking(new Runnable() {
@Override
public void run() {
+ NavigationPopup popup = new NavigationPopup(
+ mProfile, mActivityTestRule.getActivity(), controller, true);
+ popup.setWidth(300);
+ popup.setHeight(300);
+ popup.setAnchorView(mActivityTestRule.getActivity()
+ .getCurrentContentViewCore()
+ .getContainerView());
+
popup.show();
+ popupReference.set(popup);
}
});
@@ -255,37 +268,43 @@ public class NavigationPopupTest extends ChromeActivityTestCaseBase<ChromeActivi
ThreadUtils.runOnUiThreadBlocking(new Runnable() {
@Override
public void run() {
- popup.dismiss();
+ popupReference.get().dismiss();
}
});
}
+ @Test
@SmallTest
@Feature({"Navigation"})
public void testItemSelection() {
final TestNavigationController controller = new TestNavigationController();
- final NavigationPopup popup =
- new NavigationPopup(mProfile, getActivity(), controller, true);
- popup.setWidth(300);
- popup.setHeight(300);
- popup.setAnchorView(getActivity().getCurrentContentViewCore().getContainerView());
+ final AtomicReference<NavigationPopup> popupReference = new AtomicReference<>();
ThreadUtils.runOnUiThreadBlocking(new Runnable() {
@Override
public void run() {
+ NavigationPopup popup = new NavigationPopup(
+ mProfile, mActivityTestRule.getActivity(), controller, true);
+ popup.setWidth(300);
+ popup.setHeight(300);
+ popup.setAnchorView(mActivityTestRule.getActivity()
+ .getCurrentContentViewCore()
+ .getContainerView());
+
popup.show();
+ popupReference.set(popup);
}
});
ThreadUtils.runOnUiThreadBlocking(new Runnable() {
@Override
public void run() {
- popup.performItemClick(1);
+ popupReference.get().performItemClick(1);
}
});
- assertFalse("Popup did not hide as expected.", popup.isShowing());
- assertEquals("Popup attempted to navigate to the wrong index", 5,
- controller.mNavigatedIndex);
+ Assert.assertFalse("Popup did not hide as expected.", popupReference.get().isShowing());
+ Assert.assertEquals(
+ "Popup attempted to navigate to the wrong index", 5, controller.mNavigatedIndex);
}
}

Powered by Google App Engine
This is Rietveld 408576698