Update To 11.40.268.0
[platform/framework/web/crosswalk.git] / src / chrome / android / javatests / src / org / chromium / chrome / browser / translate / TranslateInfoBarTest.java
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.
4
5 package org.chromium.chrome.browser.translate;
6
7 import android.test.FlakyTest;
8
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;
16
17 import java.util.List;
18
19 /**
20  * Tests for the translate infobar, assumes it runs on a system with language
21  * preferences set to English.
22  */
23 public class TranslateInfoBarTest extends ChromeShellTestBase {
24     private static final String TRANSLATE_PAGE = "chrome/test/data/translate/fr_test.html";
25
26     private InfoBarTestAnimationListener mListener;
27
28     @Override
29     protected void setUp() throws Exception {
30         super.setUp();
31         InfoBarContainer container = getActivity().getActiveTab().getInfoBarContainer();
32         mListener =  new InfoBarTestAnimationListener();
33         container.setAnimationListener(mListener);
34     }
35
36     private static final String NEVER_TRANSLATE_MESSAGE =
37             "Would you like Google Chrome to offer to translate French pages from this" +
38             " site next time?";
39
40     /**
41      * Test the translate language panel.
42      * @MediumTest
43      * @Feature({"Browser", "Main"})
44      * http://crbug.com/311197
45      */
46     @FlakyTest
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));
55     }
56
57     /**
58      * Test the "never translate" panel.
59      * @MediumTest
60      * @Feature({"Browser", "Main"})
61      * http://crbug.com/311197
62      */
63     @FlakyTest
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);
69
70         assertTrue(InfoBarUtil.clickCloseButton(infoBar));
71         assertTrue(mListener.removeInfoBarAnimationFinished());
72
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));
78
79         assertTrue("Never Panel not opened.",
80                 TranslateUtil.verifyInfoBarText(infoBar, NEVER_TRANSLATE_MESSAGE));
81     }
82 }