| Index: chrome/test/android/javatests/src/org/chromium/chrome/test/util/TranslateUtil.java
|
| diff --git a/chrome/test/android/javatests/src/org/chromium/chrome/test/util/TranslateUtil.java b/chrome/test/android/javatests/src/org/chromium/chrome/test/util/TranslateUtil.java
|
| index e64931ca367a5aa8039fa1fcfb76542eead4b7e8..e4bd26e4e1f7536d687d07c2c6ec9403957b69e3 100644
|
| --- a/chrome/test/android/javatests/src/org/chromium/chrome/test/util/TranslateUtil.java
|
| +++ b/chrome/test/android/javatests/src/org/chromium/chrome/test/util/TranslateUtil.java
|
| @@ -16,10 +16,13 @@ import org.junit.Assert;
|
| import org.chromium.chrome.R;
|
| import org.chromium.chrome.browser.infobar.InfoBar;
|
| import org.chromium.chrome.browser.infobar.InfoBarCompactLayout;
|
| +import org.chromium.chrome.browser.infobar.TranslateCompactInfoBar;
|
| +import org.chromium.chrome.browser.infobar.translate.TranslateMenu;
|
| import org.chromium.chrome.browser.infobar.translate.TranslateTabLayout;
|
| +import org.chromium.content.browser.test.util.Criteria;
|
| +import org.chromium.content.browser.test.util.CriteriaHelper;
|
| import org.chromium.content.browser.test.util.TestTouchUtils;
|
|
|
| -
|
| /**
|
| * Utility functions for dealing with Translate InfoBars.
|
| */
|
| @@ -73,6 +76,73 @@ public class TranslateUtil {
|
| Assert.assertTrue(tabLayout instanceof TranslateTabLayout);
|
| }
|
|
|
| + public static void assertHasAtLeastTwoLanguageTabs(TranslateCompactInfoBar infoBar) {
|
| + View content = infoBar.getView().findViewById(R.id.translate_infobar_content);
|
| + Assert.assertNotNull(content);
|
| +
|
| + TranslateTabLayout tabLayout =
|
| + (TranslateTabLayout) content.findViewById(R.id.translate_infobar_tabs);
|
| + Assert.assertTrue(tabLayout.getTabCount() >= 2);
|
| + }
|
| +
|
| + /**
|
| + * Checks if the menu button exists on the InfoBar.
|
| + * @return True if the View was found.
|
| + */
|
| + public static boolean hasMenuButton(InfoBar infoBar) {
|
| + return InfoBarUtil.findButton(infoBar, R.id.translate_infobar_menu_button, false);
|
| + }
|
| +
|
| + /**
|
| + * Simulates clicking the menu button in the specified infobar.
|
| + * @return True if the View was found.
|
| + */
|
| + public static boolean clickMenuButton(InfoBar infoBar) {
|
| + return InfoBarUtil.findButton(infoBar, R.id.translate_infobar_menu_button, true);
|
| + }
|
| +
|
| + /**
|
| + * Simulates clicking the menu button and check if overflow menu is shown.
|
| + */
|
| + public static void clickMenuButtonAndAssertMenuShown(final TranslateCompactInfoBar infoBar) {
|
| + clickMenuButton(infoBar);
|
| + CriteriaHelper.pollInstrumentationThread(new Criteria("Overflow menu did not show") {
|
| + @Override
|
| + public boolean isSatisfied() {
|
| + return infoBar.isOverflowMenuShowing();
|
| + }
|
| + });
|
| + }
|
| +
|
| + /**
|
| + * Simulates clicking the 'More Language' menu item and check if language menu is shown.
|
| + */
|
| + public static void clickMoreLanguageButtonAndAssertLanguageMenuShown(
|
| + Instrumentation instrumentation, final TranslateCompactInfoBar infoBar) {
|
| + invokeOverflowMenuActionSync(
|
| + instrumentation, infoBar, TranslateMenu.ID_OVERFLOW_MORE_LANGUAGE);
|
| + CriteriaHelper.pollInstrumentationThread(new Criteria("Language menu did not show") {
|
| + @Override
|
| + public boolean isSatisfied() {
|
| + return infoBar.isLanguageMenuShowing();
|
| + }
|
| + });
|
| + }
|
| +
|
| + /**
|
| + * Execute a particular menu item from the overflow menu.
|
| + * The item is executed even if it is disabled or not visible.
|
| + */
|
| + public static void invokeOverflowMenuActionSync(
|
| + Instrumentation instrumentation, final TranslateCompactInfoBar infoBar, final int id) {
|
| + instrumentation.runOnMainSync(new Runnable() {
|
| + @Override
|
| + public void run() {
|
| + infoBar.onOverflowMenuItemClicked(id);
|
| + }
|
| + });
|
| + }
|
| +
|
| private static String findInfoBarText(View view) {
|
| TextView text = (TextView) view.findViewById(R.id.infobar_message);
|
| return text != null ? text.getText().toString() : null;
|
|
|