Chromium Code Reviews| Index: chrome/android/javatests/src/org/chromium/chrome/browser/translate/TranslateCompactInfoBarTest.java |
| diff --git a/chrome/android/javatests/src/org/chromium/chrome/browser/translate/TranslateInfoBarTest.java b/chrome/android/javatests/src/org/chromium/chrome/browser/translate/TranslateCompactInfoBarTest.java |
| similarity index 55% |
| copy from chrome/android/javatests/src/org/chromium/chrome/browser/translate/TranslateInfoBarTest.java |
| copy to chrome/android/javatests/src/org/chromium/chrome/browser/translate/TranslateCompactInfoBarTest.java |
| index 599c190b3871e5b4cb92e3f5810330424f520937..4f0f26d89988bbf27c1f6526daad4a8f7652e139 100644 |
| --- a/chrome/android/javatests/src/org/chromium/chrome/browser/translate/TranslateInfoBarTest.java |
| +++ b/chrome/android/javatests/src/org/chromium/chrome/browser/translate/TranslateCompactInfoBarTest.java |
| @@ -4,6 +4,7 @@ |
| package org.chromium.chrome.browser.translate; |
| +import android.content.pm.ActivityInfo; |
| import android.support.test.InstrumentationRegistry; |
| import android.support.test.filters.MediumTest; |
| @@ -15,18 +16,17 @@ import org.junit.Test; |
| import org.junit.runner.RunWith; |
| 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.Restriction; |
| import org.chromium.chrome.browser.ChromeActivity; |
| import org.chromium.chrome.browser.ChromeSwitches; |
| import org.chromium.chrome.browser.infobar.InfoBar; |
| import org.chromium.chrome.browser.infobar.InfoBarContainer; |
| +import org.chromium.chrome.browser.infobar.TranslateCompactInfoBar; |
| import org.chromium.chrome.test.ChromeActivityTestRule; |
| import org.chromium.chrome.test.ChromeJUnit4ClassRunner; |
| import org.chromium.chrome.test.util.ChromeRestriction; |
| import org.chromium.chrome.test.util.InfoBarTestAnimationListener; |
| -import org.chromium.chrome.test.util.InfoBarUtil; |
| import org.chromium.chrome.test.util.TranslateUtil; |
| import org.chromium.net.test.EmbeddedTestServer; |
| @@ -35,24 +35,17 @@ import java.util.concurrent.TimeoutException; |
| /** |
| * Tests for the translate infobar, assumes it runs on a system with language |
| * preferences set to English. |
| - * |
| - * Note: these tests all currently fail because they depend on a newer version of Google Play |
| - * Services than is installed on the test devices. See http://crbug.com/514449 |
| */ |
| @RunWith(ChromeJUnit4ClassRunner.class) |
| @CommandLineFlags.Add({ChromeSwitches.DISABLE_FIRST_RUN_EXPERIENCE, |
| ChromeActivityTestRule.DISABLE_NETWORK_PREDICTION_FLAG}) |
| -public class TranslateInfoBarTest { |
| +public class TranslateCompactInfoBarTest { |
|
Marti Wong
2017/05/30 01:29:15
TranslateCompactInfoBarTest.java is created by cop
|
| @Rule |
| public ChromeActivityTestRule<ChromeActivity> mActivityTestRule = |
| new ChromeActivityTestRule<>(ChromeActivity.class); |
| private static final String TRANSLATE_PAGE = "/chrome/test/data/translate/fr_test.html"; |
| private static final String ENABLE_COMPACT_UI_FEATURE = "enable-features=TranslateCompactUI"; |
| - private static final String DISABLE_COMPACT_UI_FEATURE = "disable-features=TranslateCompactUI"; |
| - private static final String NEVER_TRANSLATE_MESSAGE = |
| - "Would you like Google Chrome to offer to translate French pages from this" |
| - + " site next time?"; |
| private InfoBarContainer mInfoBarContainer; |
| private InfoBarTestAnimationListener mListener; |
| @@ -62,7 +55,7 @@ public class TranslateInfoBarTest { |
| public void setUp() throws Exception { |
| mActivityTestRule.startMainActivityOnBlankPage(); |
| mInfoBarContainer = mActivityTestRule.getActivity().getActivityTab().getInfoBarContainer(); |
| - mListener = new InfoBarTestAnimationListener(); |
| + mListener = new InfoBarTestAnimationListener(); |
| mInfoBarContainer.addAnimationListener(mListener); |
| mTestServer = EmbeddedTestServer.createAndStartServer( |
| InstrumentationRegistry.getInstrumentation().getContext()); |
| @@ -74,7 +67,7 @@ public class TranslateInfoBarTest { |
| } |
| /** |
| - * Test the new translate compact UI. |
| + * Test that the new translate compact UI appears and has at least 2 tabs. |
| */ |
| @Test |
| @MediumTest |
| @@ -86,68 +79,60 @@ public class TranslateInfoBarTest { |
| mListener.addInfoBarAnimationFinished("InfoBar not opened."); |
| InfoBar infoBar = mInfoBarContainer.getInfoBarsForTesting().get(0); |
| TranslateUtil.assertCompactTranslateInfoBar(infoBar); |
| + TranslateUtil.assertHasAtLeastTwoLanguageTabs((TranslateCompactInfoBar) infoBar); |
|
Marti Wong
2017/05/30 01:29:15
In this CL, I just check if there is 2 tabs.
To te
mdjones
2017/05/30 16:50:41
I'm probably the wrong person to ask about this, b
Marti Wong
2017/05/31 04:10:18
Thanks for the advice.
|
| } |
| /** |
| - * Test the translate language panel. |
| + * Test the overflow menus of new translate compact UI. |
| */ |
| @Test |
| @MediumTest |
| @Feature({"Browser", "Main"}) |
| @Restriction(ChromeRestriction.RESTRICTION_TYPE_GOOGLE_PLAY_SERVICES) |
| - @CommandLineFlags.Add(DISABLE_COMPACT_UI_FEATURE) |
| - public void testTranslateLanguagePanel() throws InterruptedException, TimeoutException { |
| + @CommandLineFlags.Add(ENABLE_COMPACT_UI_FEATURE) |
| + public void testTranslateCompactInfoBarOverflowMenus() |
| + throws InterruptedException, TimeoutException { |
| mActivityTestRule.loadUrl(mTestServer.getURL(TRANSLATE_PAGE)); |
| mListener.addInfoBarAnimationFinished("InfoBar not opened."); |
| - InfoBar infoBar = mInfoBarContainer.getInfoBarsForTesting().get(0); |
| - Assert.assertTrue(InfoBarUtil.hasPrimaryButton(infoBar)); |
| - Assert.assertTrue(InfoBarUtil.hasSecondaryButton(infoBar)); |
| - TranslateUtil.openLanguagePanel(InstrumentationRegistry.getInstrumentation(), |
| - mActivityTestRule.getActivity(), infoBar); |
| + TranslateCompactInfoBar infoBar = |
| + (TranslateCompactInfoBar) mInfoBarContainer.getInfoBarsForTesting().get(0); |
| + TranslateUtil.hasMenuButton(infoBar); |
| + |
| + // 1. Click on menu button and make sure overflow menu appears |
| + TranslateUtil.clickMenuButtonAndAssertMenuShown(infoBar); |
| + |
| + // 2. Click on "More language" in the overflow menu and make sure language menu appears |
| + TranslateUtil.clickMoreLanguageButtonAndAssertLanguageMenuShown( |
| + InstrumentationRegistry.getInstrumentation(), infoBar); |
| } |
| /** |
| - * Test the "never translate" panel. |
| + * Tests that the overflow menu is dismissed when the orientation changes. |
| */ |
| @Test |
| @MediumTest |
| @Feature({"Browser", "Main"}) |
| @Restriction(ChromeRestriction.RESTRICTION_TYPE_GOOGLE_PLAY_SERVICES) |
| - @CommandLineFlags.Add(DISABLE_COMPACT_UI_FEATURE) |
| - public void testTranslateNeverPanel() throws InterruptedException, TimeoutException { |
| + @CommandLineFlags.Add(ENABLE_COMPACT_UI_FEATURE) |
| + public void testTabMenuDismissedOnOrientationChange() throws Exception { |
|
Marti Wong
2017/05/30 01:29:15
Please advice if we should merge the orientation t
mdjones
2017/05/30 16:50:41
Since these are testing two separate concepts, I t
Marti Wong
2017/05/31 04:10:18
Thanks!
|
| mActivityTestRule.loadUrl(mTestServer.getURL(TRANSLATE_PAGE)); |
| mListener.addInfoBarAnimationFinished("InfoBar not opened."); |
| - InfoBar infoBar = mInfoBarContainer.getInfoBarsForTesting().get(0); |
| - |
| - Assert.assertTrue(InfoBarUtil.clickCloseButton(infoBar)); |
| - mListener.removeInfoBarAnimationFinished("Infobar not removed."); |
| - |
| - // Reload the page so the infobar shows again |
| - mActivityTestRule.loadUrl(mTestServer.getURL(TRANSLATE_PAGE)); |
| - mListener.addInfoBarAnimationFinished("InfoBar not opened"); |
| - infoBar = mInfoBarContainer.getInfoBarsForTesting().get(0); |
| - Assert.assertTrue(InfoBarUtil.clickCloseButton(infoBar)); |
| - mListener.swapInfoBarAnimationFinished("InfoBar not swapped"); |
| - |
| - TranslateUtil.assertInfoBarText(infoBar, NEVER_TRANSLATE_MESSAGE); |
| - } |
| - |
| - /** |
| - * Test infobar transitions. |
| - * |
| - * @MediumTest |
| - * @Feature({"Browser", "Main"}) |
| - */ |
| - @Test |
| - @DisabledTest(message = "crbug.com/514449") |
| - public void testTranslateTransitions() throws InterruptedException, TimeoutException { |
| - mActivityTestRule.loadUrl(mTestServer.getURL(TRANSLATE_PAGE)); |
| - mListener.addInfoBarAnimationFinished("InfoBar not Added"); |
| - InfoBar infoBar = mActivityTestRule.getInfoBars().get(0); |
| - Assert.assertTrue(InfoBarUtil.hasPrimaryButton(infoBar)); |
| - Assert.assertTrue(InfoBarUtil.hasSecondaryButton(infoBar)); |
| - Assert.assertTrue(InfoBarUtil.clickPrimaryButton(infoBar)); |
| - mListener.swapInfoBarAnimationFinished("BEFORE -> TRANSLATING transition not Swapped."); |
| - mListener.swapInfoBarAnimationFinished("TRANSLATING -> ERROR transition not Swapped."); |
| + TranslateCompactInfoBar infoBar = |
| + (TranslateCompactInfoBar) mInfoBarContainer.getInfoBarsForTesting().get(0); |
| + TranslateUtil.hasMenuButton(infoBar); |
| + TranslateUtil.clickMenuButtonAndAssertMenuShown(infoBar); |
| + |
| + // 1. Set orientation to portrait |
| + mActivityTestRule.getActivity().setRequestedOrientation( |
| + ActivityInfo.SCREEN_ORIENTATION_PORTRAIT); |
| + InstrumentationRegistry.getInstrumentation().waitForIdleSync(); |
| + |
| + // 2. Check if overflow menu is dismissed |
| + Assert.assertFalse(infoBar.isLanguageMenuShowing()); |
| + |
| + // 3. Reset orientation |
| + mActivityTestRule.getActivity().setRequestedOrientation( |
| + ActivityInfo.SCREEN_ORIENTATION_PORTRAIT); |
| + InstrumentationRegistry.getInstrumentation().waitForIdleSync(); |
| } |
| } |