1 // Copyright 2013 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 package org.chromium.chrome.browser.translate;
7 import android.test.FlakyTest;
9 import org.chromium.chrome.browser.infobar.InfoBar;
10 import org.chromium.chrome.browser.infobar.InfoBarContainer;
11 import org.chromium.chrome.shell.ChromeShellTestBase;
12 import org.chromium.chrome.test.util.InfoBarTestAnimationListener;
13 import org.chromium.chrome.test.util.InfoBarUtil;
14 import org.chromium.chrome.test.util.TestHttpServerClient;
15 import org.chromium.chrome.test.util.TranslateUtil;
17 import java.util.List;
20 * Tests for the translate infobar, assumes it runs on a system with language
21 * preferences set to English.
23 public class TranslateInfoBarTest extends ChromeShellTestBase {
24 private static final String TRANSLATE_PAGE = "chrome/test/data/translate/fr_test.html";
26 private InfoBarTestAnimationListener mListener;
29 protected void setUp() throws Exception {
31 InfoBarContainer container = getActivity().getActiveTab().getInfoBarContainer();
32 mListener = new InfoBarTestAnimationListener();
33 container.setAnimationListener(mListener);
36 private static final String NEVER_TRANSLATE_MESSAGE =
37 "Would you like Google Chrome to offer to translate French pages from this" +
41 * Test the translate language panel.
43 * @Feature({"Browser", "Main"})
44 * http://crbug.com/311197
47 public void testTranslateLanguagePanel() throws InterruptedException {
48 List<InfoBar> infoBars = getActivity().getActiveTab().getInfoBarContainer().getInfoBars();
49 loadUrlWithSanitization(TestHttpServerClient.getUrl(TRANSLATE_PAGE));
50 assertTrue("InfoBar not opened.", mListener.addInfoBarAnimationFinished());
51 InfoBar infoBar = infoBars.get(0);
52 assertTrue(InfoBarUtil.hasPrimaryButton(infoBar));
53 assertTrue(InfoBarUtil.hasSecondaryButton(infoBar));
54 assertTrue("Language Panel not opened.", TranslateUtil.openLanguagePanel(this, infoBar));
58 * Test the "never translate" panel.
60 * @Feature({"Browser", "Main"})
61 * http://crbug.com/311197
64 public void testTranslateNeverPanel() throws InterruptedException {
65 List<InfoBar> infoBars = getActivity().getActiveTab().getInfoBarContainer().getInfoBars();
66 loadUrlWithSanitization(TestHttpServerClient.getUrl(TRANSLATE_PAGE));
67 assertTrue("InfoBar not opened.", mListener.addInfoBarAnimationFinished());
68 InfoBar infoBar = infoBars.get(0);
70 assertTrue(InfoBarUtil.clickCloseButton(infoBar));
71 assertTrue(mListener.removeInfoBarAnimationFinished());
73 // Reload the page so the infobar shows again
74 loadUrlWithSanitization(TestHttpServerClient.getUrl(TRANSLATE_PAGE));
75 assertTrue("InfoBar not opened", mListener.addInfoBarAnimationFinished());
76 infoBar = infoBars.get(0);
77 assertTrue(InfoBarUtil.clickCloseButton(infoBar));
79 assertTrue("Never Panel not opened.",
80 TranslateUtil.verifyInfoBarText(infoBar, NEVER_TRANSLATE_MESSAGE));