This source file includes following definitions.
- setUp
- testTranslateLanguagePanel
- testTranslateNeverPanel
package org.chromium.chrome.browser.translate;
import android.test.FlakyTest;
import org.chromium.chrome.browser.infobar.InfoBar;
import org.chromium.chrome.browser.infobar.InfoBarContainer;
import org.chromium.chrome.shell.ChromeShellTestBase;
import org.chromium.chrome.test.util.InfoBarTestAnimationListener;
import org.chromium.chrome.test.util.InfoBarUtil;
import org.chromium.chrome.test.util.TestHttpServerClient;
import org.chromium.chrome.test.util.TranslateUtil;
import java.util.List;
public class TranslateInfoBarTest extends ChromeShellTestBase {
private static final String TRANSLATE_PAGE = "chrome/test/data/translate/fr_test.html";
private InfoBarTestAnimationListener mListener;
@Override
protected void setUp() throws Exception {
super.setUp();
InfoBarContainer container = getActivity().getActiveTab().getInfoBarContainer();
mListener = new InfoBarTestAnimationListener();
container.setAnimationListener(mListener);
}
private static final String NEVER_TRANSLATE_MESSAGE =
"Would you like Google Chrome to offer to translate French pages from this" +
" site next time?";
@FlakyTest
public void testTranslateLanguagePanel() throws InterruptedException {
List<InfoBar> infoBars = getActivity().getActiveTab().getInfoBarContainer().getInfoBars();
loadUrlWithSanitization(TestHttpServerClient.getUrl(TRANSLATE_PAGE));
assertTrue("InfoBar not opened.", mListener.addInfoBarAnimationFinished());
InfoBar infoBar = infoBars.get(0);
assertTrue(InfoBarUtil.hasPrimaryButton(this, infoBar));
assertTrue(InfoBarUtil.hasSecondaryButton(this, infoBar));
assertTrue("Language Panel not opened.", TranslateUtil.openLanguagePanel(this, infoBar));
}
@FlakyTest
public void testTranslateNeverPanel() throws InterruptedException {
List<InfoBar> infoBars = getActivity().getActiveTab().getInfoBarContainer().getInfoBars();
loadUrlWithSanitization(TestHttpServerClient.getUrl(TRANSLATE_PAGE));
assertTrue("InfoBar not opened.", mListener.addInfoBarAnimationFinished());
InfoBar infoBar = infoBars.get(0);
assertTrue(InfoBarUtil.clickCloseButton(this, infoBar));
assertTrue(mListener.removeInfoBarAnimationFinished());
loadUrlWithSanitization(TestHttpServerClient.getUrl(TRANSLATE_PAGE));
assertTrue("InfoBar not opened", mListener.addInfoBarAnimationFinished());
infoBar = infoBars.get(0);
assertTrue(InfoBarUtil.clickCloseButton(this, infoBar));
assertTrue("Never Panel not opened.",
TranslateUtil.verifyInfoBarText(infoBar, NEVER_TRANSLATE_MESSAGE));
}
}