Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "chrome/browser/ui/views/translate/translate_bubble_view.h" | 5 #include "chrome/browser/ui/views/translate/translate_bubble_view.h" |
| 6 | 6 |
| 7 #include "base/command_line.h" | 7 #include "base/command_line.h" |
| 8 #include "chrome/browser/chrome_notification_types.h" | 8 #include "chrome/browser/chrome_notification_types.h" |
| 9 #include "chrome/browser/translate/translate_browser_test_utils.h" | |
| 9 #include "chrome/browser/ui/browser.h" | 10 #include "chrome/browser/ui/browser.h" |
| 10 #include "chrome/browser/ui/browser_commands.h" | 11 #include "chrome/browser/ui/browser_commands.h" |
| 11 #include "chrome/browser/ui/browser_tabstrip.h" | 12 #include "chrome/browser/ui/browser_tabstrip.h" |
| 12 #include "chrome/browser/ui/tabs/tab_strip_model.h" | 13 #include "chrome/browser/ui/tabs/tab_strip_model.h" |
| 13 #include "chrome/common/chrome_switches.h" | 14 #include "chrome/common/chrome_switches.h" |
| 14 #include "chrome/test/base/in_process_browser_test.h" | 15 #include "chrome/test/base/in_process_browser_test.h" |
| 15 #include "chrome/test/base/ui_test_utils.h" | 16 #include "chrome/test/base/ui_test_utils.h" |
| 16 #include "components/translate/core/common/language_detection_details.h" | 17 #include "components/translate/core/common/language_detection_details.h" |
| 17 #include "content/public/browser/notification_details.h" | 18 #include "content/public/browser/notification_details.h" |
| 18 | 19 |
| 19 class TranslateBubbleViewBrowserTest : public InProcessBrowserTest { | 20 class TranslateBubbleViewBrowserTest : public InProcessBrowserTest { |
| 20 public: | 21 public: |
| 21 TranslateBubbleViewBrowserTest() {} | 22 TranslateBubbleViewBrowserTest() {} |
| 22 virtual ~TranslateBubbleViewBrowserTest() {} | 23 virtual ~TranslateBubbleViewBrowserTest() {} |
| 23 | 24 |
| 24 private: | 25 private: |
| 25 DISALLOW_COPY_AND_ASSIGN(TranslateBubbleViewBrowserTest); | 26 DISALLOW_COPY_AND_ASSIGN(TranslateBubbleViewBrowserTest); |
| 26 }; | 27 }; |
| 27 | 28 |
| 28 IN_PROC_BROWSER_TEST_F(TranslateBubbleViewBrowserTest, | 29 IN_PROC_BROWSER_TEST_F(TranslateBubbleViewBrowserTest, |
| 29 CloseBrowserWithoutTranslating) { | 30 CloseBrowserWithoutTranslating) { |
| 31 test::ScopedCLDDynamicDataHarness dynamic_data_scope; | |
|
msw
2014/05/19 18:56:42
As I asked in https://codereview.chromium.org/2852
| |
| 32 ASSERT_NO_FATAL_FAILURE(dynamic_data_scope.Init()); | |
| 30 EXPECT_FALSE(TranslateBubbleView::IsShowing()); | 33 EXPECT_FALSE(TranslateBubbleView::IsShowing()); |
| 31 | 34 |
| 32 // Show a French page and wait until the bubble is shown. | 35 // Show a French page and wait until the bubble is shown. |
| 33 content::WebContents* current_web_contents = | 36 content::WebContents* current_web_contents = |
| 34 browser()->tab_strip_model()->GetActiveWebContents(); | 37 browser()->tab_strip_model()->GetActiveWebContents(); |
| 35 content::Source<content::WebContents> source(current_web_contents); | 38 content::Source<content::WebContents> source(current_web_contents); |
| 36 ui_test_utils::WindowedNotificationObserverWithDetails< | 39 ui_test_utils::WindowedNotificationObserverWithDetails< |
| 37 LanguageDetectionDetails> | 40 LanguageDetectionDetails> |
| 38 fr_language_detected_signal(chrome::NOTIFICATION_TAB_LANGUAGE_DETERMINED, | 41 fr_language_detected_signal(chrome::NOTIFICATION_TAB_LANGUAGE_DETERMINED, |
| 39 source); | 42 source); |
| 40 GURL french_url = ui_test_utils::GetTestUrl( | 43 GURL french_url = ui_test_utils::GetTestUrl( |
| 41 base::FilePath(), base::FilePath(FILE_PATH_LITERAL("french_page.html"))); | 44 base::FilePath(), base::FilePath(FILE_PATH_LITERAL("french_page.html"))); |
| 42 ui_test_utils::NavigateToURL(browser(), french_url); | 45 ui_test_utils::NavigateToURL(browser(), french_url); |
| 43 fr_language_detected_signal.Wait(); | 46 fr_language_detected_signal.Wait(); |
| 44 EXPECT_TRUE(TranslateBubbleView::IsShowing()); | 47 EXPECT_TRUE(TranslateBubbleView::IsShowing()); |
| 45 | 48 |
| 46 // Close the window without translating. | 49 // Close the window without translating. |
| 47 chrome::CloseWindow(browser()); | 50 chrome::CloseWindow(browser()); |
| 48 EXPECT_FALSE(TranslateBubbleView::IsShowing()); | 51 EXPECT_FALSE(TranslateBubbleView::IsShowing()); |
| 49 } | 52 } |
| 50 | 53 |
| 51 IN_PROC_BROWSER_TEST_F(TranslateBubbleViewBrowserTest, | 54 IN_PROC_BROWSER_TEST_F(TranslateBubbleViewBrowserTest, |
| 52 CloseLastTabWithoutTranslating) { | 55 CloseLastTabWithoutTranslating) { |
| 56 test::ScopedCLDDynamicDataHarness dynamic_data_scope; | |
| 57 ASSERT_NO_FATAL_FAILURE(dynamic_data_scope.Init()); | |
| 53 EXPECT_FALSE(TranslateBubbleView::IsShowing()); | 58 EXPECT_FALSE(TranslateBubbleView::IsShowing()); |
| 54 | 59 |
| 55 // Show a French page and wait until the bubble is shown. | 60 // Show a French page and wait until the bubble is shown. |
| 56 content::WebContents* current_web_contents = | 61 content::WebContents* current_web_contents = |
| 57 browser()->tab_strip_model()->GetActiveWebContents(); | 62 browser()->tab_strip_model()->GetActiveWebContents(); |
| 58 content::Source<content::WebContents> source(current_web_contents); | 63 content::Source<content::WebContents> source(current_web_contents); |
| 59 ui_test_utils::WindowedNotificationObserverWithDetails< | 64 ui_test_utils::WindowedNotificationObserverWithDetails< |
| 60 LanguageDetectionDetails> | 65 LanguageDetectionDetails> |
| 61 fr_language_detected_signal(chrome::NOTIFICATION_TAB_LANGUAGE_DETERMINED, | 66 fr_language_detected_signal(chrome::NOTIFICATION_TAB_LANGUAGE_DETERMINED, |
| 62 source); | 67 source); |
| 63 GURL french_url = ui_test_utils::GetTestUrl( | 68 GURL french_url = ui_test_utils::GetTestUrl( |
| 64 base::FilePath(), base::FilePath(FILE_PATH_LITERAL("french_page.html"))); | 69 base::FilePath(), base::FilePath(FILE_PATH_LITERAL("french_page.html"))); |
| 65 ui_test_utils::NavigateToURL(browser(), french_url); | 70 ui_test_utils::NavigateToURL(browser(), french_url); |
| 66 fr_language_detected_signal.Wait(); | 71 fr_language_detected_signal.Wait(); |
| 67 EXPECT_TRUE(TranslateBubbleView::IsShowing()); | 72 EXPECT_TRUE(TranslateBubbleView::IsShowing()); |
| 68 | 73 |
| 69 // Close the tab without translating. | 74 // Close the tab without translating. |
| 70 EXPECT_EQ(1, browser()->tab_strip_model()->count()); | 75 EXPECT_EQ(1, browser()->tab_strip_model()->count()); |
| 71 chrome::CloseWebContents(browser(), current_web_contents, false); | 76 chrome::CloseWebContents(browser(), current_web_contents, false); |
| 72 EXPECT_FALSE(TranslateBubbleView::IsShowing()); | 77 EXPECT_FALSE(TranslateBubbleView::IsShowing()); |
| 73 } | 78 } |
| 74 | 79 |
| 75 IN_PROC_BROWSER_TEST_F(TranslateBubbleViewBrowserTest, | 80 IN_PROC_BROWSER_TEST_F(TranslateBubbleViewBrowserTest, |
| 76 CloseAnotherTabWithoutTranslating) { | 81 CloseAnotherTabWithoutTranslating) { |
| 82 test::ScopedCLDDynamicDataHarness dynamic_data_scope; | |
| 83 ASSERT_NO_FATAL_FAILURE(dynamic_data_scope.Init()); | |
| 77 EXPECT_FALSE(TranslateBubbleView::IsShowing()); | 84 EXPECT_FALSE(TranslateBubbleView::IsShowing()); |
| 78 | 85 |
| 79 int active_index = browser()->tab_strip_model()->active_index(); | 86 int active_index = browser()->tab_strip_model()->active_index(); |
| 80 | 87 |
| 81 // Open another tab to load a French page on background. | 88 // Open another tab to load a French page on background. |
| 82 int french_index = active_index + 1; | 89 int french_index = active_index + 1; |
| 83 GURL french_url = ui_test_utils::GetTestUrl( | 90 GURL french_url = ui_test_utils::GetTestUrl( |
| 84 base::FilePath(), base::FilePath(FILE_PATH_LITERAL("french_page.html"))); | 91 base::FilePath(), base::FilePath(FILE_PATH_LITERAL("french_page.html"))); |
| 85 chrome::AddTabAt(browser(), french_url, french_index, false); | 92 chrome::AddTabAt(browser(), french_url, french_index, false); |
| 86 EXPECT_EQ(active_index, browser()->tab_strip_model()->active_index()); | 93 EXPECT_EQ(active_index, browser()->tab_strip_model()->active_index()); |
| (...skipping 16 matching lines...) Expand all Loading... | |
| 103 chrome::CloseWebContents(browser(), web_contents, false); | 110 chrome::CloseWebContents(browser(), web_contents, false); |
| 104 EXPECT_EQ(active_index, browser()->tab_strip_model()->active_index()); | 111 EXPECT_EQ(active_index, browser()->tab_strip_model()->active_index()); |
| 105 EXPECT_EQ(1, browser()->tab_strip_model()->count()); | 112 EXPECT_EQ(1, browser()->tab_strip_model()->count()); |
| 106 EXPECT_FALSE(TranslateBubbleView::IsShowing()); | 113 EXPECT_FALSE(TranslateBubbleView::IsShowing()); |
| 107 | 114 |
| 108 // Close the last tab. | 115 // Close the last tab. |
| 109 chrome::CloseWebContents(browser(), | 116 chrome::CloseWebContents(browser(), |
| 110 browser()->tab_strip_model()->GetActiveWebContents(), | 117 browser()->tab_strip_model()->GetActiveWebContents(), |
| 111 false); | 118 false); |
| 112 } | 119 } |
| OLD | NEW |