- add sources.
[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 import android.test.suitebuilder.annotation.MediumTest;
9
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;
18
19 import java.util.List;
20
21 /**
22  * Tests for the translate infobar, assumes it runs on a system with language
23  * preferences set to English.
24  */
25 public class TranslateInfoBarTest extends ChromiumTestShellTestBase {
26     private static final String TRANSLATE_PAGE = "chrome/test/data/translate/fr_test.html";
27
28     private InfoBarTestAnimationListener mListener;
29
30     @Override
31     protected void setUp() throws Exception {
32         super.setUp();
33         InfoBarContainer container = getActivity().getActiveTab().getInfoBarContainer();
34         mListener =  new InfoBarTestAnimationListener();
35         container.setAnimationListener(mListener);
36     }
37
38     private static final String NEVER_TRANSLATE_MESSAGE =
39         "Would you like Google Chrome to offer to translate French pages from this" +
40         " site next time?";
41
42     /**
43      * Test the translate language panel.
44      * @MediumTest
45      * @Feature({"Browser", "Main"})
46      * http://crbug.com/311197
47      */
48     @FlakyTest
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));
57     }
58
59
60     /**
61      * Test the "never translate" panel.
62      * @MediumTest
63      * @Feature({"Browser", "Main"})
64      * http://crbug.com/311197
65      */
66     @FlakyTest
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);
72
73         assertTrue(InfoBarUtil.clickCloseButton(this, infoBar));
74         assertTrue(mListener.removeInfoBarAnimationFinished());
75
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));
81
82        assertTrue("Never Panel not opened.",
83            TranslateUtil.verifyInfoBarText(infoBar, NEVER_TRANSLATE_MESSAGE));
84     }
85 }