Disable view source for Developer Tools.
[chromium-blink-merge.git] / chrome / browser / ui / views / translate / translate_bubble_view_browsertest.cc
blob9564c797e0d9a09919ebfdcad5d769171b1e54e3
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 #include "chrome/browser/ui/views/translate/translate_bubble_view.h"
7 #include "base/command_line.h"
8 #include "chrome/browser/chrome_notification_types.h"
9 #include "chrome/browser/ui/browser.h"
10 #include "chrome/browser/ui/browser_commands.h"
11 #include "chrome/browser/ui/browser_tabstrip.h"
12 #include "chrome/browser/ui/tabs/tab_strip_model.h"
13 #include "chrome/common/chrome_switches.h"
14 #include "chrome/test/base/in_process_browser_test.h"
15 #include "chrome/test/base/ui_test_utils.h"
16 #include "components/translate/core/common/language_detection_details.h"
17 #include "content/public/browser/notification_details.h"
19 class TranslateBubbleViewBrowserTest : public InProcessBrowserTest {
20 public:
21 TranslateBubbleViewBrowserTest() {}
22 virtual ~TranslateBubbleViewBrowserTest() {}
24 virtual void SetUpCommandLine(CommandLine* command_line) OVERRIDE {
25 command_line->AppendSwitch(switches::kEnableTranslateNewUX);
27 private:
28 DISALLOW_COPY_AND_ASSIGN(TranslateBubbleViewBrowserTest);
31 IN_PROC_BROWSER_TEST_F(TranslateBubbleViewBrowserTest,
32 CloseBrowserWithoutTranslating) {
33 EXPECT_FALSE(TranslateBubbleView::IsShowing());
35 // Show a French page and wait until the bubble is shown.
36 content::WebContents* current_web_contents =
37 browser()->tab_strip_model()->GetActiveWebContents();
38 content::Source<content::WebContents> source(current_web_contents);
39 ui_test_utils::WindowedNotificationObserverWithDetails<
40 LanguageDetectionDetails>
41 fr_language_detected_signal(chrome::NOTIFICATION_TAB_LANGUAGE_DETERMINED,
42 source);
43 GURL french_url = ui_test_utils::GetTestUrl(
44 base::FilePath(), base::FilePath(FILE_PATH_LITERAL("french_page.html")));
45 ui_test_utils::NavigateToURL(browser(), french_url);
46 fr_language_detected_signal.Wait();
47 EXPECT_TRUE(TranslateBubbleView::IsShowing());
49 // Close the window without translating.
50 chrome::CloseWindow(browser());
51 EXPECT_FALSE(TranslateBubbleView::IsShowing());
54 IN_PROC_BROWSER_TEST_F(TranslateBubbleViewBrowserTest,
55 CloseLastTabWithoutTranslating) {
56 EXPECT_FALSE(TranslateBubbleView::IsShowing());
58 // Show a French page and wait until the bubble is shown.
59 content::WebContents* current_web_contents =
60 browser()->tab_strip_model()->GetActiveWebContents();
61 content::Source<content::WebContents> source(current_web_contents);
62 ui_test_utils::WindowedNotificationObserverWithDetails<
63 LanguageDetectionDetails>
64 fr_language_detected_signal(chrome::NOTIFICATION_TAB_LANGUAGE_DETERMINED,
65 source);
66 GURL french_url = ui_test_utils::GetTestUrl(
67 base::FilePath(), base::FilePath(FILE_PATH_LITERAL("french_page.html")));
68 ui_test_utils::NavigateToURL(browser(), french_url);
69 fr_language_detected_signal.Wait();
70 EXPECT_TRUE(TranslateBubbleView::IsShowing());
72 // Close the tab without translating.
73 EXPECT_EQ(1, browser()->tab_strip_model()->count());
74 chrome::CloseWebContents(browser(), current_web_contents, false);
75 EXPECT_FALSE(TranslateBubbleView::IsShowing());
78 IN_PROC_BROWSER_TEST_F(TranslateBubbleViewBrowserTest,
79 CloseAnotherTabWithoutTranslating) {
80 EXPECT_FALSE(TranslateBubbleView::IsShowing());
82 int active_index = browser()->tab_strip_model()->active_index();
84 // Open another tab to load a French page on background.
85 int french_index = active_index + 1;
86 GURL french_url = ui_test_utils::GetTestUrl(
87 base::FilePath(), base::FilePath(FILE_PATH_LITERAL("french_page.html")));
88 chrome::AddTabAt(browser(), french_url, french_index, false);
89 EXPECT_EQ(active_index, browser()->tab_strip_model()->active_index());
90 EXPECT_EQ(2, browser()->tab_strip_model()->count());
92 // Wait until the language is detected.
93 content::WebContents* web_contents =
94 browser()->tab_strip_model()->GetWebContentsAt(french_index);
95 content::Source<content::WebContents> source(web_contents);
96 ui_test_utils::WindowedNotificationObserverWithDetails<
97 LanguageDetectionDetails>
98 fr_language_detected_signal(chrome::NOTIFICATION_TAB_LANGUAGE_DETERMINED,
99 source);
100 fr_language_detected_signal.Wait();
102 // The bubble is not shown because the tab is not activated.
103 EXPECT_FALSE(TranslateBubbleView::IsShowing());
105 // Close the French page tab immediately.
106 chrome::CloseWebContents(browser(), web_contents, false);
107 EXPECT_EQ(active_index, browser()->tab_strip_model()->active_index());
108 EXPECT_EQ(1, browser()->tab_strip_model()->count());
109 EXPECT_FALSE(TranslateBubbleView::IsShowing());
111 // Close the last tab.
112 chrome::CloseWebContents(browser(),
113 browser()->tab_strip_model()->GetActiveWebContents(),
114 false);