Index: chrome/android/javatests/src/org/chromium/chrome/browser/appmenu/AppMenuTest.java |
diff --git a/chrome/android/javatests/src/org/chromium/chrome/browser/appmenu/AppMenuTest.java b/chrome/android/javatests/src/org/chromium/chrome/browser/appmenu/AppMenuTest.java |
index 470592cd508657580eacdffcb91643ec09129ae9..d8bc7697c73dd29bbec97b8538bad3cb3472e013 100644 |
--- a/chrome/android/javatests/src/org/chromium/chrome/browser/appmenu/AppMenuTest.java |
+++ b/chrome/android/javatests/src/org/chromium/chrome/browser/appmenu/AppMenuTest.java |
@@ -6,6 +6,7 @@ package org.chromium.chrome.browser.appmenu; |
import android.app.Activity; |
import android.content.pm.ActivityInfo; |
+import android.support.test.InstrumentationRegistry; |
import android.support.test.filters.SmallTest; |
import android.view.KeyEvent; |
import android.view.MenuItem; |
@@ -13,15 +14,24 @@ import android.view.View; |
import android.widget.ListPopupWindow; |
import android.widget.ListView; |
+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.annotations.SuppressFBWarnings; |
+import org.chromium.base.test.util.CommandLineFlags; |
import org.chromium.base.test.util.DisabledTest; |
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.ChromeActivity; |
+import org.chromium.chrome.browser.ChromeSwitches; |
import org.chromium.chrome.browser.ChromeTabbedActivity; |
-import org.chromium.chrome.test.ChromeActivityTestCaseBase; |
+import org.chromium.chrome.test.ChromeActivityTestRule; |
+import org.chromium.chrome.test.ChromeJUnit4ClassRunner; |
import org.chromium.chrome.test.util.ChromeTabUtils; |
import org.chromium.content.browser.test.util.Criteria; |
import org.chromium.content.browser.test.util.CriteriaHelper; |
@@ -31,8 +41,15 @@ import java.util.concurrent.Callable; |
/** |
* Tests AppMenu popup |
*/ |
+@RunWith(ChromeJUnit4ClassRunner.class) |
@RetryOnFailure |
-public class AppMenuTest extends ChromeActivityTestCaseBase<ChromeActivity> { |
+@CommandLineFlags.Add({ChromeSwitches.DISABLE_FIRST_RUN_EXPERIENCE, |
+ ChromeActivityTestRule.DISABLE_NETWORK_PREDICTION_FLAG}) |
+public class AppMenuTest { |
+ @Rule |
+ public ChromeActivityTestRule<ChromeActivity> mActivityTestRule = |
+ new ChromeActivityTestRule<>(ChromeActivity.class); |
+ |
private static final String TEST_URL = UrlUtils.encodeHtmlDataUri("<html>foo</html>"); |
private AppMenu mAppMenu; |
@@ -59,19 +76,10 @@ public class AppMenuTest extends ChromeActivityTestCaseBase<ChromeActivity> { |
} |
} |
- public AppMenuTest() { |
- super(ChromeActivity.class); |
- } |
- |
- @Override |
- public void startMainActivity() throws InterruptedException { |
- startMainActivityWithURL(TEST_URL); |
- } |
- |
- @Override |
- protected void setUp() throws Exception { |
+ @Before |
+ public void setUp() throws Exception { |
// We need list selection; ensure we are not in touch mode. |
- getInstrumentation().setInTouchMode(false); |
+ InstrumentationRegistry.getInstrumentation().setInTouchMode(false); |
ChromeActivity.setAppMenuHandlerFactoryForTesting( |
new ChromeActivity.AppMenuHandlerFactory() { |
@@ -84,10 +92,10 @@ public class AppMenuTest extends ChromeActivityTestCaseBase<ChromeActivity> { |
} |
}); |
- super.setUp(); |
+ mActivityTestRule.startMainActivityWithURL(TEST_URL); |
showAppMenuAndAssertMenuShown(); |
- mAppMenu = getActivity().getAppMenuHandler().getAppMenu(); |
+ mAppMenu = mActivityTestRule.getActivity().getAppMenuHandler().getAppMenu(); |
ThreadUtils.runOnUiThread(new Runnable() { |
@Override |
public void run() { |
@@ -100,19 +108,21 @@ public class AppMenuTest extends ChromeActivityTestCaseBase<ChromeActivity> { |
return getCurrentFocusedRow(); |
} |
})); |
- getInstrumentation().waitForIdleSync(); |
+ InstrumentationRegistry.getInstrumentation().waitForIdleSync(); |
} |
/** |
* Verify opening a new tab from the menu. |
*/ |
+ @Test |
@SmallTest |
@Feature({"Browser", "Main"}) |
public void testMenuNewTab() throws InterruptedException { |
- final int tabCountBefore = getActivity().getCurrentTabModel().getCount(); |
- ChromeTabUtils.newTabFromMenu(getInstrumentation(), (ChromeTabbedActivity) getActivity()); |
- final int tabCountAfter = getActivity().getCurrentTabModel().getCount(); |
- assertTrue("Expected: " + (tabCountBefore + 1) + " Got: " + tabCountAfter, |
+ final int tabCountBefore = mActivityTestRule.getActivity().getCurrentTabModel().getCount(); |
+ ChromeTabUtils.newTabFromMenu(InstrumentationRegistry.getInstrumentation(), |
+ (ChromeTabbedActivity) mActivityTestRule.getActivity()); |
+ final int tabCountAfter = mActivityTestRule.getActivity().getCurrentTabModel().getCount(); |
+ Assert.assertTrue("Expected: " + (tabCountBefore + 1) + " Got: " + tabCountAfter, |
tabCountBefore + 1 == tabCountAfter); |
} |
@@ -120,20 +130,22 @@ public class AppMenuTest extends ChromeActivityTestCaseBase<ChromeActivity> { |
* Test bounds when accessing the menu through the keyboard. |
* Make sure that the menu stays open when trying to move past the first and last items. |
*/ |
+ @Test |
@SmallTest |
@Feature({"Browser", "Main"}) |
public void testKeyboardMenuBoundaries() { |
moveToBoundary(false, true); |
- assertEquals(getCount() - 1, getCurrentFocusedRow()); |
+ Assert.assertEquals(getCount() - 1, getCurrentFocusedRow()); |
moveToBoundary(true, true); |
- assertEquals(0, getCurrentFocusedRow()); |
+ Assert.assertEquals(0, getCurrentFocusedRow()); |
moveToBoundary(false, true); |
- assertEquals(getCount() - 1, getCurrentFocusedRow()); |
+ Assert.assertEquals(getCount() - 1, getCurrentFocusedRow()); |
} |
/** |
* Test that typing ENTER immediately opening the menu works. |
*/ |
+ @Test |
@SmallTest |
@Feature({"Browser", "Main"}) |
public void testKeyboardMenuEnterOnOpen() { |
@@ -143,11 +155,12 @@ public class AppMenuTest extends ChromeActivityTestCaseBase<ChromeActivity> { |
/** |
* Test that hitting ENTER past the top item doesn't crash Chrome. |
*/ |
+ @Test |
@SmallTest |
@Feature({"Browser", "Main"}) |
public void testKeyboardEnterAfterMovePastTopItem() { |
moveToBoundary(true, true); |
- assertEquals(0, getCurrentFocusedRow()); |
+ Assert.assertEquals(0, getCurrentFocusedRow()); |
hitEnterAndAssertAppMenuDismissed(); |
} |
@@ -155,11 +168,12 @@ public class AppMenuTest extends ChromeActivityTestCaseBase<ChromeActivity> { |
* Test that hitting ENTER past the bottom item doesn't crash Chrome. |
* Catches regressions for http://crbug.com/181067 |
*/ |
+ @Test |
@SmallTest |
@Feature({"Browser", "Main"}) |
public void testKeyboardEnterAfterMovePastBottomItem() { |
moveToBoundary(false, true); |
- assertEquals(getCount() - 1, getCurrentFocusedRow()); |
+ Assert.assertEquals(getCount() - 1, getCurrentFocusedRow()); |
hitEnterAndAssertAppMenuDismissed(); |
} |
@@ -167,26 +181,30 @@ public class AppMenuTest extends ChromeActivityTestCaseBase<ChromeActivity> { |
* Test that hitting ENTER on the top item actually triggers the top item. |
* Catches regressions for https://crbug.com/191239 for shrunken menus. |
*/ |
+ @Test |
@SmallTest |
@Feature({"Browser", "Main"}) |
public void testKeyboardMenuEnterOnTopItemLandscape() { |
- getActivity().setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE); |
+ mActivityTestRule.getActivity().setRequestedOrientation( |
+ ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE); |
showAppMenuAndAssertMenuShown(); |
moveToBoundary(true, false); |
- assertEquals(0, getCurrentFocusedRow()); |
+ Assert.assertEquals(0, getCurrentFocusedRow()); |
hitEnterAndAssertAppMenuDismissed(); |
} |
/** |
* Test that hitting ENTER on the top item doesn't crash Chrome. |
*/ |
+ @Test |
@SmallTest |
@Feature({"Browser", "Main"}) |
public void testKeyboardMenuEnterOnTopItemPortrait() { |
- getActivity().setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT); |
+ mActivityTestRule.getActivity().setRequestedOrientation( |
+ ActivityInfo.SCREEN_ORIENTATION_PORTRAIT); |
showAppMenuAndAssertMenuShown(); |
moveToBoundary(true, false); |
- assertEquals(0, getCurrentFocusedRow()); |
+ Assert.assertEquals(0, getCurrentFocusedRow()); |
hitEnterAndAssertAppMenuDismissed(); |
} |
@@ -197,11 +215,14 @@ public class AppMenuTest extends ChromeActivityTestCaseBase<ChromeActivity> { |
@SmallTest |
@Feature({"Browser", "Main"}) |
*/ |
+ @Test |
@DisabledTest(message = "crbug.com/458193") |
public void testChangingOrientationHidesMenu() { |
- getActivity().setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE); |
+ mActivityTestRule.getActivity().setRequestedOrientation( |
+ ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE); |
showAppMenuAndAssertMenuShown(); |
- getActivity().setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT); |
+ mActivityTestRule.getActivity().setRequestedOrientation( |
+ ActivityInfo.SCREEN_ORIENTATION_PORTRAIT); |
CriteriaHelper.pollInstrumentationThread(new Criteria("AppMenu did not dismiss") { |
@Override |
public boolean isSatisfied() { |
@@ -226,7 +247,7 @@ public class AppMenuTest extends ChromeActivityTestCaseBase<ChromeActivity> { |
} |
private void hitEnterAndAssertAppMenuDismissed() { |
- getInstrumentation().waitForIdleSync(); |
+ InstrumentationRegistry.getInstrumentation().waitForIdleSync(); |
pressKey(KeyEvent.KEYCODE_ENTER); |
CriteriaHelper.pollInstrumentationThread(new Criteria("AppMenu did not dismiss") { |
@Override |
@@ -264,7 +285,7 @@ public class AppMenuTest extends ChromeActivityTestCaseBase<ChromeActivity> { |
} |
// The menu should stay open. |
- assertTrue(mAppMenu.isShowing()); |
+ Assert.assertTrue(mAppMenu.isShowing()); |
} |
private void pressKey(final int keycode) { |
@@ -276,7 +297,7 @@ public class AppMenuTest extends ChromeActivityTestCaseBase<ChromeActivity> { |
view.dispatchKeyEvent(new KeyEvent(KeyEvent.ACTION_UP, keycode)); |
} |
}); |
- getInstrumentation().waitForIdleSync(); |
+ InstrumentationRegistry.getInstrumentation().waitForIdleSync(); |
} |
private int getCurrentFocusedRow() { |