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;
8 import android.test.suitebuilder.annotation.MediumTest;
10 import org.chromium.base.test.util.Feature;
11 import org.chromium.chrome.browser.infobar.InfoBar;
12 import org.chromium.chrome.browser.infobar.InfoBarContainer;
13 import org.chromium.chrome.test.util.InfoBarTestAnimationListener;
14 import org.chromium.chrome.test.util.InfoBarUtil;
15 import org.chromium.chrome.test.util.TranslateUtil;
16 import org.chromium.chrome.test.util.TestHttpServerClient;
17 import org.chromium.chrome.testshell.ChromiumTestShellTestBase;
19 import java.util.List;
22 * Tests for the translate infobar, assumes it runs on a system with language
23 * preferences set to English.
25 public class TranslateInfoBarTest extends ChromiumTestShellTestBase {
26 private static final String TRANSLATE_PAGE = "chrome/test/data/translate/fr_test.html";
28 private InfoBarTestAnimationListener mListener;
31 protected void setUp() throws Exception {
33 InfoBarContainer container = getActivity().getActiveTab().getInfoBarContainer();
34 mListener = new InfoBarTestAnimationListener();
35 container.setAnimationListener(mListener);
38 private static final String NEVER_TRANSLATE_MESSAGE =
39 "Would you like Google Chrome to offer to translate French pages from this" +
43 * Test the translate language panel.
45 * @Feature({"Browser", "Main"})
46 * http://crbug.com/311197
49 public void testTranslateLanguagePanel() throws InterruptedException {
50 List<InfoBar> infoBars = getActivity().getActiveTab().getInfoBarContainer().getInfoBars();
51 loadUrlWithSanitization(TestHttpServerClient.getUrl(TRANSLATE_PAGE));
52 assertTrue("InfoBar not opened.", mListener.addInfoBarAnimationFinished());
53 InfoBar infoBar = infoBars.get(0);
54 assertTrue(InfoBarUtil.hasPrimaryButton(this, infoBar));
55 assertTrue(InfoBarUtil.hasSecondaryButton(this, infoBar));
56 assertTrue("Language Panel not opened.", TranslateUtil.openLanguagePanel(this, infoBar));
61 * Test the "never translate" panel.
63 * @Feature({"Browser", "Main"})
64 * http://crbug.com/311197
67 public void testTranslateNeverPanel() throws InterruptedException {
68 List<InfoBar> infoBars = getActivity().getActiveTab().getInfoBarContainer().getInfoBars();
69 loadUrlWithSanitization(TestHttpServerClient.getUrl(TRANSLATE_PAGE));
70 assertTrue("InfoBar not opened.", mListener.addInfoBarAnimationFinished());
71 InfoBar infoBar = infoBars.get(0);
73 assertTrue(InfoBarUtil.clickCloseButton(this, infoBar));
74 assertTrue(mListener.removeInfoBarAnimationFinished());
76 // Reload the page so the infobar shows again
77 loadUrlWithSanitization(TestHttpServerClient.getUrl(TRANSLATE_PAGE));
78 assertTrue("InfoBar not opened", mListener.addInfoBarAnimationFinished());
79 infoBar = infoBars.get(0);
80 assertTrue(InfoBarUtil.clickCloseButton(this, infoBar));
82 assertTrue("Never Panel not opened.",
83 TranslateUtil.verifyInfoBarText(infoBar, NEVER_TRANSLATE_MESSAGE));