Chromium Code Reviews| 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 | |
| 234 // TODO: update comment. | |
|
blundell
2014/02/18 09:21:46
Address this :).
droger
2014/02/18 10:16:51
Ooops. Done.
| |
| 235 | |
| 233 // Access the TranslateManager singleton so it is created before we call | 236 // Access the TranslateManager singleton so it is created before we call |
| 234 // ChromeRenderViewHostTestHarness::SetUp() to match what's done in Chrome, | 237 // ChromeRenderViewHostTestHarness::SetUp() to match what's done in Chrome, |
| 235 // where the TranslateManager is created before the WebContents. This | 238 // where the TranslateManager is created before the WebContents. This |
| 236 // matters as they both register for similar events and we want the | 239 // matters as they both register for similar events and we want the |
| 237 // notifications to happen in the same sequence (TranslateManager first, | 240 // notifications to happen in the same sequence (TranslateManager first, |
| 238 // WebContents second). Also clears the translate script so it is fetched | 241 // 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 | 242 // everytime and sets the expiration delay to a large value by default (in |
| 240 // case it was zeroed in a previous test). | 243 // case it was zeroed in a previous test). |
| 241 TranslateService::Initialize(); | 244 TranslateService::Initialize(); |
| 242 TranslateDownloadManager* download_manager = | 245 TranslateDownloadManager* download_manager = |
| 243 TranslateDownloadManager::GetInstance(); | 246 TranslateDownloadManager::GetInstance(); |
| 244 download_manager->ClearTranslateScriptForTesting(); | 247 download_manager->ClearTranslateScriptForTesting(); |
| 245 download_manager->SetTranslateScriptExpirationDelay(60 * 60 * 1000); | 248 download_manager->SetTranslateScriptExpirationDelay(60 * 60 * 1000); |
| 246 TranslateManager::GetInstance()->set_translate_max_reload_attemps(0); | |
| 247 TranslateService::SetUseInfobar(true); | 249 TranslateService::SetUseInfobar(true); |
| 248 | 250 |
| 249 ChromeRenderViewHostTestHarness::SetUp(); | 251 ChromeRenderViewHostTestHarness::SetUp(); |
| 250 InfoBarService::CreateForWebContents(web_contents()); | 252 InfoBarService::CreateForWebContents(web_contents()); |
| 251 TranslateTabHelper::CreateForWebContents(web_contents()); | 253 TranslateTabHelper::CreateForWebContents(web_contents()); |
| 254 TranslateManager* manager = | |
| 255 TranslateTabHelper::GetManagerFromWebContents(web_contents()); | |
| 256 manager->set_translate_max_reload_attemps(0); | |
| 252 | 257 |
| 253 notification_registrar_.Add(this, | 258 notification_registrar_.Add(this, |
| 254 chrome::NOTIFICATION_TAB_CONTENTS_INFOBAR_REMOVED, | 259 chrome::NOTIFICATION_TAB_CONTENTS_INFOBAR_REMOVED, |
| 255 content::Source<InfoBarService>(infobar_service())); | 260 content::Source<InfoBarService>(infobar_service())); |
| 256 } | 261 } |
| 257 | 262 |
| 258 virtual void TearDown() { | 263 virtual void TearDown() { |
| 259 process()->sink().ClearMessages(); | 264 process()->sink().ClearMessages(); |
| 260 | 265 |
| 261 notification_registrar_.Remove(this, | 266 notification_registrar_.Remove(this, |
| (...skipping 530 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 792 ReloadAndWait(true); | 797 ReloadAndWait(true); |
| 793 EXPECT_TRUE(GetTranslateInfoBar() != NULL); | 798 EXPECT_TRUE(GetTranslateInfoBar() != NULL); |
| 794 EXPECT_TRUE(CloseTranslateInfoBar()); | 799 EXPECT_TRUE(CloseTranslateInfoBar()); |
| 795 | 800 |
| 796 // ...But not show it if the reload fails. | 801 // ...But not show it if the reload fails. |
| 797 ReloadAndWait(false); | 802 ReloadAndWait(false); |
| 798 EXPECT_TRUE(GetTranslateInfoBar() == NULL); | 803 EXPECT_TRUE(GetTranslateInfoBar() == NULL); |
| 799 | 804 |
| 800 // If we set reload attempts to a high value, we will not see the infobar | 805 // If we set reload attempts to a high value, we will not see the infobar |
| 801 // immediately. | 806 // immediately. |
| 802 TranslateManager::GetInstance()->set_translate_max_reload_attemps(100); | 807 TranslateManager* manager = |
| 808 TranslateTabHelper::GetManagerFromWebContents(web_contents()); | |
| 809 manager->set_translate_max_reload_attemps(100); | |
| 803 ReloadAndWait(true); | 810 ReloadAndWait(true); |
| 804 EXPECT_TRUE(GetTranslateInfoBar() == NULL); | 811 EXPECT_TRUE(GetTranslateInfoBar() == NULL); |
| 805 } | 812 } |
| 806 | 813 |
| 807 // Test that reloading the page by way of typing again the URL in the | 814 // Test that reloading the page by way of typing again the URL in the |
| 808 // location bar brings back the infobar. | 815 // location bar brings back the infobar. |
| 809 TEST_F(TranslateManagerBrowserTest, ReloadFromLocationBar) { | 816 TEST_F(TranslateManagerBrowserTest, ReloadFromLocationBar) { |
| 810 GURL url("http://www.google.fr"); | 817 GURL url("http://www.google.fr"); |
| 811 SimulateNavigation(url, "fr", true); | 818 SimulateNavigation(url, "fr", true); |
| 812 | 819 |
| (...skipping 811 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1624 content::WebContents* current_web_contents = | 1631 content::WebContents* current_web_contents = |
| 1625 browser()->tab_strip_model()->GetActiveWebContents(); | 1632 browser()->tab_strip_model()->GetActiveWebContents(); |
| 1626 content::Source<content::WebContents> source(current_web_contents); | 1633 content::Source<content::WebContents> source(current_web_contents); |
| 1627 | 1634 |
| 1628 ui_test_utils::WindowedNotificationObserverWithDetails< | 1635 ui_test_utils::WindowedNotificationObserverWithDetails< |
| 1629 LanguageDetectionDetails> | 1636 LanguageDetectionDetails> |
| 1630 fr_language_detected_signal(chrome::NOTIFICATION_TAB_LANGUAGE_DETERMINED, | 1637 fr_language_detected_signal(chrome::NOTIFICATION_TAB_LANGUAGE_DETERMINED, |
| 1631 source); | 1638 source); |
| 1632 fr_language_detected_signal.Wait(); | 1639 fr_language_detected_signal.Wait(); |
| 1633 } | 1640 } |
| OLD | NEW |