OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 <algorithm> | 5 #include <algorithm> |
6 #include <set> | 6 #include <set> |
7 #include <vector> | 7 #include <vector> |
8 | 8 |
9 #include "base/command_line.h" | 9 #include "base/command_line.h" |
10 #include "base/memory/scoped_ptr.h" | 10 #include "base/memory/scoped_ptr.h" |
(...skipping 212 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
223 | 223 |
224 MOCK_METHOD1(OnPreferenceChanged, void(const std::string&)); | 224 MOCK_METHOD1(OnPreferenceChanged, void(const std::string&)); |
225 | 225 |
226 protected: | 226 protected: |
227 virtual void SetUp() { | 227 virtual void SetUp() { |
228 // This test is a unit test but runs in the browser_tests suite. Therefore | 228 // This test is a unit test but runs in the browser_tests suite. Therefore |
229 // it needs to manage its own TestingBrowserProcess. | 229 // it needs to manage its own TestingBrowserProcess. |
230 // TODO(jamescook): Figure out how to move this suite back to unit_tests. | 230 // TODO(jamescook): Figure out how to move this suite back to unit_tests. |
231 // Right now it fails to get the translate infobar if you run it there. | 231 // Right now it fails to get the translate infobar if you run it there. |
232 TestingBrowserProcess::CreateInstance(); | 232 TestingBrowserProcess::CreateInstance(); |
233 // Access the TranslateManager singleton so it is created before we call | 233 |
234 // ChromeRenderViewHostTestHarness::SetUp() to match what's done in Chrome, | |
235 // where the TranslateManager is created before the WebContents. This | |
236 // matters as they both register for similar events and we want the | |
237 // notifications to happen in the same sequence (TranslateManager first, | |
238 // WebContents second). Also clears the translate script so it is fetched | |
239 // everytime and sets the expiration delay to a large value by default (in | |
240 // case it was zeroed in a previous test). | |
241 TranslateService::Initialize(); | 234 TranslateService::Initialize(); |
| 235 TranslateService::SetUseInfobar(true); |
| 236 |
| 237 // Clears the translate script so it is fetched everytime and sets the |
| 238 // expiration delay to a large value by default (in case it was zeroed in a |
| 239 // previous test). |
242 TranslateDownloadManager* download_manager = | 240 TranslateDownloadManager* download_manager = |
243 TranslateDownloadManager::GetInstance(); | 241 TranslateDownloadManager::GetInstance(); |
244 download_manager->ClearTranslateScriptForTesting(); | 242 download_manager->ClearTranslateScriptForTesting(); |
245 download_manager->SetTranslateScriptExpirationDelay(60 * 60 * 1000); | 243 download_manager->SetTranslateScriptExpirationDelay(60 * 60 * 1000); |
246 TranslateManager::GetInstance()->set_translate_max_reload_attemps(0); | |
247 TranslateService::SetUseInfobar(true); | |
248 | 244 |
249 ChromeRenderViewHostTestHarness::SetUp(); | 245 ChromeRenderViewHostTestHarness::SetUp(); |
250 InfoBarService::CreateForWebContents(web_contents()); | 246 InfoBarService::CreateForWebContents(web_contents()); |
251 TranslateTabHelper::CreateForWebContents(web_contents()); | 247 TranslateTabHelper::CreateForWebContents(web_contents()); |
| 248 TranslateManager* manager = |
| 249 TranslateTabHelper::GetManagerFromWebContents(web_contents()); |
| 250 manager->set_translate_max_reload_attemps(0); |
252 | 251 |
253 notification_registrar_.Add(this, | 252 notification_registrar_.Add(this, |
254 chrome::NOTIFICATION_TAB_CONTENTS_INFOBAR_REMOVED, | 253 chrome::NOTIFICATION_TAB_CONTENTS_INFOBAR_REMOVED, |
255 content::Source<InfoBarService>(infobar_service())); | 254 content::Source<InfoBarService>(infobar_service())); |
256 } | 255 } |
257 | 256 |
258 virtual void TearDown() { | 257 virtual void TearDown() { |
259 process()->sink().ClearMessages(); | 258 process()->sink().ClearMessages(); |
260 | 259 |
261 notification_registrar_.Remove(this, | 260 notification_registrar_.Remove(this, |
(...skipping 530 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
792 ReloadAndWait(true); | 791 ReloadAndWait(true); |
793 EXPECT_TRUE(GetTranslateInfoBar() != NULL); | 792 EXPECT_TRUE(GetTranslateInfoBar() != NULL); |
794 EXPECT_TRUE(CloseTranslateInfoBar()); | 793 EXPECT_TRUE(CloseTranslateInfoBar()); |
795 | 794 |
796 // ...But not show it if the reload fails. | 795 // ...But not show it if the reload fails. |
797 ReloadAndWait(false); | 796 ReloadAndWait(false); |
798 EXPECT_TRUE(GetTranslateInfoBar() == NULL); | 797 EXPECT_TRUE(GetTranslateInfoBar() == NULL); |
799 | 798 |
800 // If we set reload attempts to a high value, we will not see the infobar | 799 // If we set reload attempts to a high value, we will not see the infobar |
801 // immediately. | 800 // immediately. |
802 TranslateManager::GetInstance()->set_translate_max_reload_attemps(100); | 801 TranslateManager* manager = |
| 802 TranslateTabHelper::GetManagerFromWebContents(web_contents()); |
| 803 manager->set_translate_max_reload_attemps(100); |
803 ReloadAndWait(true); | 804 ReloadAndWait(true); |
804 EXPECT_TRUE(GetTranslateInfoBar() == NULL); | 805 EXPECT_TRUE(GetTranslateInfoBar() == NULL); |
805 } | 806 } |
806 | 807 |
807 // Test that reloading the page by way of typing again the URL in the | 808 // Test that reloading the page by way of typing again the URL in the |
808 // location bar brings back the infobar. | 809 // location bar brings back the infobar. |
809 TEST_F(TranslateManagerBrowserTest, ReloadFromLocationBar) { | 810 TEST_F(TranslateManagerBrowserTest, ReloadFromLocationBar) { |
810 GURL url("http://www.google.fr"); | 811 GURL url("http://www.google.fr"); |
811 SimulateNavigation(url, "fr", true); | 812 SimulateNavigation(url, "fr", true); |
812 | 813 |
(...skipping 811 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1624 content::WebContents* current_web_contents = | 1625 content::WebContents* current_web_contents = |
1625 browser()->tab_strip_model()->GetActiveWebContents(); | 1626 browser()->tab_strip_model()->GetActiveWebContents(); |
1626 content::Source<content::WebContents> source(current_web_contents); | 1627 content::Source<content::WebContents> source(current_web_contents); |
1627 | 1628 |
1628 ui_test_utils::WindowedNotificationObserverWithDetails< | 1629 ui_test_utils::WindowedNotificationObserverWithDetails< |
1629 LanguageDetectionDetails> | 1630 LanguageDetectionDetails> |
1630 fr_language_detected_signal(chrome::NOTIFICATION_TAB_LANGUAGE_DETERMINED, | 1631 fr_language_detected_signal(chrome::NOTIFICATION_TAB_LANGUAGE_DETERMINED, |
1631 source); | 1632 source); |
1632 fr_language_detected_signal.Wait(); | 1633 fr_language_detected_signal.Wait(); |
1633 } | 1634 } |
OLD | NEW |