Chromium Code Reviews| 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..415598ce550904511c7b79f0e7d9a97f9dc0ee85 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,24 @@ 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> ref = new AtomicReference<>(); |
|
Ted C
2017/04/27 18:05:27
ref is unnecessarily terse IMO.
maybe popupRefere
the real yoland
2017/04/28 02:03:29
Done
|
| 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(); |
| + ref.set(popup); |
| } |
| }); |
| @@ -255,37 +267,42 @@ public class NavigationPopupTest extends ChromeActivityTestCaseBase<ChromeActivi |
| ThreadUtils.runOnUiThreadBlocking(new Runnable() { |
| @Override |
| public void run() { |
| - popup.dismiss(); |
| + ref.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> ref = 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(); |
| + ref.set(popup); |
| } |
| }); |
| ThreadUtils.runOnUiThreadBlocking(new Runnable() { |
| @Override |
| public void run() { |
| - popup.performItemClick(1); |
| + ref.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.", ref.get().isShowing()); |
| + Assert.assertEquals( |
| + "Popup attempted to navigate to the wrong index", 5, controller.mNavigatedIndex); |
| } |
| } |