Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2014 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/translate/translate_manager.h" | |
|
droger
2014/03/04 15:58:33
Nit: this should not be at the top.
danakj
2014/03/04 16:01:51
I thought it should, since this file is testing th
droger
2014/03/04 16:10:25
My opinion is that this file is not testing the Tr
danakj
2014/03/04 16:12:21
OK, removed.
| |
| 6 | |
| 5 #include <algorithm> | 7 #include <algorithm> |
| 6 #include <set> | 8 #include <set> |
| 7 #include <vector> | 9 #include <vector> |
| 8 | 10 |
| 9 #include "base/command_line.h" | |
| 10 #include "base/memory/scoped_ptr.h" | 11 #include "base/memory/scoped_ptr.h" |
| 11 #include "base/prefs/pref_change_registrar.h" | 12 #include "base/prefs/pref_change_registrar.h" |
| 12 #include "base/prefs/pref_service.h" | 13 #include "base/prefs/pref_service.h" |
| 13 #include "base/strings/stringprintf.h" | 14 #include "base/strings/stringprintf.h" |
| 14 #include "chrome/app/chrome_command_ids.h" | 15 #include "chrome/app/chrome_command_ids.h" |
| 15 #include "chrome/browser/chrome_notification_types.h" | 16 #include "chrome/browser/chrome_notification_types.h" |
| 16 #include "chrome/browser/extensions/test_extension_system.h" | 17 #include "chrome/browser/extensions/test_extension_system.h" |
| 17 #include "chrome/browser/infobars/infobar.h" | 18 #include "chrome/browser/infobars/infobar.h" |
| 18 #include "chrome/browser/infobars/infobar_service.h" | 19 #include "chrome/browser/infobars/infobar_service.h" |
| 19 #include "chrome/browser/prefs/session_startup_pref.h" | |
| 20 #include "chrome/browser/renderer_context_menu/render_view_context_menu.h" | 20 #include "chrome/browser/renderer_context_menu/render_view_context_menu.h" |
| 21 #include "chrome/browser/translate/translate_infobar_delegate.h" | 21 #include "chrome/browser/translate/translate_infobar_delegate.h" |
| 22 #include "chrome/browser/translate/translate_manager.h" | 22 #include "chrome/browser/translate/translate_manager.h" |
| 23 #include "chrome/browser/translate/translate_service.h" | 23 #include "chrome/browser/translate/translate_service.h" |
| 24 #include "chrome/browser/translate/translate_tab_helper.h" | 24 #include "chrome/browser/translate/translate_tab_helper.h" |
| 25 #include "chrome/browser/ui/browser.h" | |
| 26 #include "chrome/browser/ui/tabs/tab_strip_model.h" | |
| 27 #include "chrome/browser/ui/translate/translate_bubble_factory.h" | 25 #include "chrome/browser/ui/translate/translate_bubble_factory.h" |
| 28 #include "chrome/browser/ui/translate/translate_bubble_model.h" | 26 #include "chrome/browser/ui/translate/translate_bubble_model.h" |
| 29 #include "chrome/browser/ui/translate/translate_bubble_model_impl.h" | 27 #include "chrome/browser/ui/translate/translate_bubble_model_impl.h" |
| 30 #include "chrome/common/chrome_switches.h" | 28 #include "chrome/common/chrome_switches.h" |
| 31 #include "chrome/common/pref_names.h" | 29 #include "chrome/common/pref_names.h" |
| 32 #include "chrome/common/render_messages.h" | 30 #include "chrome/common/render_messages.h" |
| 33 #include "chrome/common/url_constants.h" | 31 #include "chrome/common/url_constants.h" |
| 34 #include "chrome/test/base/chrome_render_view_host_test_harness.h" | 32 #include "chrome/test/base/chrome_render_view_host_test_harness.h" |
| 35 #include "chrome/test/base/in_process_browser_test.h" | |
| 36 #include "chrome/test/base/testing_browser_process.h" | 33 #include "chrome/test/base/testing_browser_process.h" |
| 37 #include "chrome/test/base/testing_profile.h" | 34 #include "chrome/test/base/testing_profile.h" |
| 38 #include "chrome/test/base/ui_test_utils.h" | |
| 39 #include "components/translate/core/browser/translate_accept_languages.h" | 35 #include "components/translate/core/browser/translate_accept_languages.h" |
| 40 #include "components/translate/core/browser/translate_download_manager.h" | 36 #include "components/translate/core/browser/translate_download_manager.h" |
| 41 #include "components/translate/core/browser/translate_language_list.h" | 37 #include "components/translate/core/browser/translate_language_list.h" |
| 42 #include "components/translate/core/browser/translate_prefs.h" | 38 #include "components/translate/core/browser/translate_prefs.h" |
| 43 #include "components/translate/core/browser/translate_script.h" | 39 #include "components/translate/core/browser/translate_script.h" |
| 44 #include "components/translate/core/common/language_detection_details.h" | 40 #include "components/translate/core/common/language_detection_details.h" |
| 45 #include "components/translate/core/common/translate_pref_names.h" | 41 #include "components/translate/core/common/translate_pref_names.h" |
| 46 #include "content/public/browser/navigation_details.h" | 42 #include "content/public/browser/navigation_details.h" |
| 47 #include "content/public/browser/navigation_entry.h" | 43 #include "content/public/browser/navigation_entry.h" |
| 48 #include "content/public/browser/notification_details.h" | 44 #include "content/public/browser/notification_details.h" |
| 49 #include "content/public/browser/notification_registrar.h" | 45 #include "content/public/browser/notification_registrar.h" |
| 50 #include "content/public/browser/web_contents.h" | 46 #include "content/public/browser/web_contents.h" |
| 47 #include "content/public/common/url_constants.h" | |
| 51 #include "content/public/test/mock_render_process_host.h" | 48 #include "content/public/test/mock_render_process_host.h" |
| 52 #include "content/public/test/test_renderer_host.h" | 49 #include "content/public/test/test_renderer_host.h" |
| 53 #include "net/url_request/test_url_fetcher_factory.h" | 50 #include "net/url_request/test_url_fetcher_factory.h" |
| 54 #include "net/url_request/url_fetcher_delegate.h" | 51 #include "net/url_request/url_fetcher_delegate.h" |
| 55 #include "testing/gmock/include/gmock/gmock.h" | 52 #include "testing/gmock/include/gmock/gmock.h" |
| 56 #include "third_party/WebKit/public/web/WebContextMenuData.h" | 53 #include "third_party/WebKit/public/web/WebContextMenuData.h" |
| 57 | 54 #include "url/gurl.h" |
| 58 | 55 |
| 59 // An observer that keeps track of whether a navigation entry was committed. | 56 // An observer that keeps track of whether a navigation entry was committed. |
| 60 class NavEntryCommittedObserver : public content::NotificationObserver { | 57 class NavEntryCommittedObserver : public content::NotificationObserver { |
| 61 public: | 58 public: |
| 62 explicit NavEntryCommittedObserver(content::WebContents* web_contents) { | 59 explicit NavEntryCommittedObserver(content::WebContents* web_contents) { |
| 63 registrar_.Add(this, content::NOTIFICATION_NAV_ENTRY_COMMITTED, | 60 registrar_.Add(this, |
| 61 content::NOTIFICATION_NAV_ENTRY_COMMITTED, | |
| 64 content::Source<content::NavigationController>( | 62 content::Source<content::NavigationController>( |
| 65 &web_contents->GetController())); | 63 &web_contents->GetController())); |
| 66 } | 64 } |
| 67 | 65 |
| 68 virtual void Observe(int type, | 66 virtual void Observe(int type, |
| 69 const content::NotificationSource& source, | 67 const content::NotificationSource& source, |
| 70 const content::NotificationDetails& details) OVERRIDE { | 68 const content::NotificationDetails& details) OVERRIDE { |
| 71 DCHECK(type == content::NOTIFICATION_NAV_ENTRY_COMMITTED); | 69 DCHECK(type == content::NOTIFICATION_NAV_ENTRY_COMMITTED); |
| 72 details_ = | 70 details_ = |
| 73 *(content::Details<content::LoadCommittedDetails>(details).ptr()); | 71 *(content::Details<content::LoadCommittedDetails>(details).ptr()); |
| 74 } | 72 } |
| 75 | 73 |
| 76 const content::LoadCommittedDetails& load_committed_details() const { | 74 const content::LoadCommittedDetails& load_committed_details() const { |
| 77 return details_; | 75 return details_; |
| 78 } | 76 } |
| 79 | 77 |
| 80 private: | 78 private: |
| 81 content::LoadCommittedDetails details_; | 79 content::LoadCommittedDetails details_; |
| 82 content::NotificationRegistrar registrar_; | 80 content::NotificationRegistrar registrar_; |
| 83 | 81 |
| 84 DISALLOW_COPY_AND_ASSIGN(NavEntryCommittedObserver); | 82 DISALLOW_COPY_AND_ASSIGN(NavEntryCommittedObserver); |
| 85 }; | 83 }; |
| 86 | 84 |
| 87 class TranslateManagerBrowserTest : public ChromeRenderViewHostTestHarness, | 85 class TranslateManagerRenderViewHostTest |
| 88 public content::NotificationObserver { | 86 : public ChromeRenderViewHostTestHarness, |
| 87 public content::NotificationObserver { | |
| 89 public: | 88 public: |
| 90 TranslateManagerBrowserTest() | 89 TranslateManagerRenderViewHostTest() |
| 91 : pref_callback_( | 90 : pref_callback_( |
| 92 base::Bind(&TranslateManagerBrowserTest::OnPreferenceChanged, | 91 base::Bind(&TranslateManagerRenderViewHostTest::OnPreferenceChanged, |
| 93 base::Unretained(this))) { | 92 base::Unretained(this))) {} |
| 94 } | |
| 95 | 93 |
| 96 // Simulates navigating to a page and getting the page contents and language | 94 // Simulates navigating to a page and getting the page contents and language |
| 97 // for that navigation. | 95 // for that navigation. |
| 98 void SimulateNavigation(const GURL& url, | 96 void SimulateNavigation(const GURL& url, |
| 99 const std::string& lang, | 97 const std::string& lang, |
| 100 bool page_translatable) { | 98 bool page_translatable) { |
| 101 NavigateAndCommit(url); | 99 NavigateAndCommit(url); |
| 102 SimulateOnTranslateLanguageDetermined(lang, page_translatable); | 100 SimulateOnTranslateLanguageDetermined(lang, page_translatable); |
| 103 } | 101 } |
| 104 | 102 |
| (...skipping 12 matching lines...) Expand all Loading... | |
| 117 const std::string& target_lang, | 115 const std::string& target_lang, |
| 118 TranslateErrors::Type error) { | 116 TranslateErrors::Type error) { |
| 119 content::RenderViewHostTester::TestOnMessageReceived( | 117 content::RenderViewHostTester::TestOnMessageReceived( |
| 120 rvh(), | 118 rvh(), |
| 121 ChromeViewHostMsg_PageTranslated( | 119 ChromeViewHostMsg_PageTranslated( |
| 122 routing_id, 0, source_lang, target_lang, error)); | 120 routing_id, 0, source_lang, target_lang, error)); |
| 123 } | 121 } |
| 124 | 122 |
| 125 void SimulateOnPageTranslated(const std::string& source_lang, | 123 void SimulateOnPageTranslated(const std::string& source_lang, |
| 126 const std::string& target_lang) { | 124 const std::string& target_lang) { |
| 127 SimulateOnPageTranslated(0, source_lang, target_lang, | 125 SimulateOnPageTranslated( |
| 128 TranslateErrors::NONE); | 126 0, source_lang, target_lang, TranslateErrors::NONE); |
| 129 } | 127 } |
| 130 | 128 |
| 131 bool GetTranslateMessage(int* page_id, | 129 bool GetTranslateMessage(int* page_id, |
| 132 std::string* original_lang, | 130 std::string* original_lang, |
| 133 std::string* target_lang) { | 131 std::string* target_lang) { |
| 134 const IPC::Message* message = | 132 const IPC::Message* message = process()->sink().GetFirstMessageMatching( |
| 135 process()->sink().GetFirstMessageMatching( | 133 ChromeViewMsg_TranslatePage::ID); |
| 136 ChromeViewMsg_TranslatePage::ID); | |
| 137 if (!message) | 134 if (!message) |
| 138 return false; | 135 return false; |
| 139 Tuple4<int, std::string, std::string, std::string> translate_param; | 136 Tuple4<int, std::string, std::string, std::string> translate_param; |
| 140 ChromeViewMsg_TranslatePage::Read(message, &translate_param); | 137 ChromeViewMsg_TranslatePage::Read(message, &translate_param); |
| 141 if (page_id) | 138 if (page_id) |
| 142 *page_id = translate_param.a; | 139 *page_id = translate_param.a; |
| 143 // Ignore translate_param.b which is the script injected in the page. | 140 // Ignore translate_param.b which is the script injected in the page. |
| 144 if (original_lang) | 141 if (original_lang) |
| 145 *original_lang = translate_param.c; | 142 *original_lang = translate_param.c; |
| 146 if (target_lang) | 143 if (target_lang) |
| 147 *target_lang = translate_param.d; | 144 *target_lang = translate_param.d; |
| 148 return true; | 145 return true; |
| 149 } | 146 } |
| 150 | 147 |
| 151 InfoBarService* infobar_service() { | 148 InfoBarService* infobar_service() { |
| 152 return InfoBarService::FromWebContents(web_contents()); | 149 return InfoBarService::FromWebContents(web_contents()); |
| 153 } | 150 } |
| 154 | 151 |
| 155 // Returns the translate infobar if there is 1 infobar and it is a translate | 152 // Returns the translate infobar if there is 1 infobar and it is a translate |
| 156 // infobar. | 153 // infobar. |
| 157 TranslateInfoBarDelegate* GetTranslateInfoBar() { | 154 TranslateInfoBarDelegate* GetTranslateInfoBar() { |
| 158 return (infobar_service()->infobar_count() == 1) ? | 155 return (infobar_service()->infobar_count() == 1) |
| 159 infobar_service()->infobar_at(0)->delegate()-> | 156 ? infobar_service() |
| 160 AsTranslateInfoBarDelegate() : NULL; | 157 ->infobar_at(0) |
| 158 ->delegate() | |
| 159 ->AsTranslateInfoBarDelegate() | |
| 160 : NULL; | |
| 161 } | 161 } |
| 162 | 162 |
| 163 // If there is 1 infobar and it is a translate infobar, closes it and returns | 163 // If there is 1 infobar and it is a translate infobar, closes it and returns |
| 164 // true. Returns false otherwise. | 164 // true. Returns false otherwise. |
| 165 bool CloseTranslateInfoBar() { | 165 bool CloseTranslateInfoBar() { |
| 166 InfoBarDelegate* infobar = GetTranslateInfoBar(); | 166 InfoBarDelegate* infobar = GetTranslateInfoBar(); |
| 167 if (!infobar) | 167 if (!infobar) |
| 168 return false; | 168 return false; |
| 169 infobar->InfoBarDismissed(); // Simulates closing the infobar. | 169 infobar->InfoBarDismissed(); // Simulates closing the infobar. |
| 170 infobar_service()->RemoveInfoBar(infobar_service()->infobar_at(0)); | 170 infobar_service()->RemoveInfoBar(infobar_service()->infobar_at(0)); |
| (...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 218 const content::NotificationDetails& details) { | 218 const content::NotificationDetails& details) { |
| 219 DCHECK_EQ(chrome::NOTIFICATION_TAB_CONTENTS_INFOBAR_REMOVED, type); | 219 DCHECK_EQ(chrome::NOTIFICATION_TAB_CONTENTS_INFOBAR_REMOVED, type); |
| 220 removed_infobars_.insert( | 220 removed_infobars_.insert( |
| 221 content::Details<InfoBar::RemovedDetails>(details)->first->delegate()); | 221 content::Details<InfoBar::RemovedDetails>(details)->first->delegate()); |
| 222 } | 222 } |
| 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 | |
| 229 // it needs to manage its own TestingBrowserProcess. | |
| 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. | |
| 232 TestingBrowserProcess::CreateInstance(); | |
| 233 | |
| 234 TranslateService::Initialize(); | 228 TranslateService::Initialize(); |
| 235 TranslateService::SetUseInfobar(true); | 229 TranslateService::SetUseInfobar(true); |
| 236 | 230 |
| 237 // Clears the translate script so it is fetched everytime and sets the | 231 // 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 | 232 // expiration delay to a large value by default (in case it was zeroed in a |
| 239 // previous test). | 233 // previous test). |
| 240 TranslateDownloadManager* download_manager = | 234 TranslateDownloadManager* download_manager = |
| 241 TranslateDownloadManager::GetInstance(); | 235 TranslateDownloadManager::GetInstance(); |
| 242 download_manager->ClearTranslateScriptForTesting(); | 236 download_manager->ClearTranslateScriptForTesting(); |
| 243 download_manager->SetTranslateScriptExpirationDelay(60 * 60 * 1000); | 237 download_manager->SetTranslateScriptExpirationDelay(60 * 60 * 1000); |
| 244 | 238 |
| 245 ChromeRenderViewHostTestHarness::SetUp(); | 239 ChromeRenderViewHostTestHarness::SetUp(); |
| 246 InfoBarService::CreateForWebContents(web_contents()); | 240 InfoBarService::CreateForWebContents(web_contents()); |
| 247 TranslateTabHelper::CreateForWebContents(web_contents()); | 241 TranslateTabHelper::CreateForWebContents(web_contents()); |
| 248 TranslateManager* manager = | 242 TranslateManager* manager = |
| 249 TranslateTabHelper::GetManagerFromWebContents(web_contents()); | 243 TranslateTabHelper::GetManagerFromWebContents(web_contents()); |
| 250 manager->set_translate_max_reload_attemps(0); | 244 manager->set_translate_max_reload_attemps(0); |
| 251 | 245 |
| 252 notification_registrar_.Add(this, | 246 notification_registrar_.Add( |
| 247 this, | |
| 253 chrome::NOTIFICATION_TAB_CONTENTS_INFOBAR_REMOVED, | 248 chrome::NOTIFICATION_TAB_CONTENTS_INFOBAR_REMOVED, |
| 254 content::Source<InfoBarService>(infobar_service())); | 249 content::Source<InfoBarService>(infobar_service())); |
| 255 } | 250 } |
| 256 | 251 |
| 257 virtual void TearDown() { | 252 virtual void TearDown() { |
| 258 process()->sink().ClearMessages(); | 253 process()->sink().ClearMessages(); |
| 259 | 254 |
| 260 notification_registrar_.Remove(this, | 255 notification_registrar_.Remove( |
| 256 this, | |
| 261 chrome::NOTIFICATION_TAB_CONTENTS_INFOBAR_REMOVED, | 257 chrome::NOTIFICATION_TAB_CONTENTS_INFOBAR_REMOVED, |
| 262 content::Source<InfoBarService>(infobar_service())); | 258 content::Source<InfoBarService>(infobar_service())); |
| 263 | 259 |
| 264 ChromeRenderViewHostTestHarness::TearDown(); | 260 ChromeRenderViewHostTestHarness::TearDown(); |
| 265 TestingBrowserProcess::DeleteInstance(); | |
| 266 } | 261 } |
| 267 | 262 |
| 268 void SetApplicationLocale(const std::string& locale) { | 263 void SetApplicationLocale(const std::string& locale) { |
| 269 g_browser_process->SetApplicationLocale(locale); | 264 g_browser_process->SetApplicationLocale(locale); |
| 270 TranslateDownloadManager::GetInstance()->set_application_locale( | 265 TranslateDownloadManager::GetInstance()->set_application_locale( |
| 271 g_browser_process->GetApplicationLocale()); | 266 g_browser_process->GetApplicationLocale()); |
| 272 } | 267 } |
| 273 | 268 |
| 274 void SimulateTranslateScriptURLFetch(bool success) { | 269 void SimulateTranslateScriptURLFetch(bool success) { |
| 275 net::TestURLFetcher* fetcher = | 270 net::TestURLFetcher* fetcher = |
| 276 url_fetcher_factory_.GetFetcherByID(TranslateScript::kFetcherId); | 271 url_fetcher_factory_.GetFetcherByID(TranslateScript::kFetcherId); |
| 277 ASSERT_TRUE(fetcher); | 272 ASSERT_TRUE(fetcher); |
| 278 net::URLRequestStatus status; | 273 net::URLRequestStatus status; |
| 279 status.set_status(success ? net::URLRequestStatus::SUCCESS : | 274 status.set_status(success ? net::URLRequestStatus::SUCCESS |
| 280 net::URLRequestStatus::FAILED); | 275 : net::URLRequestStatus::FAILED); |
| 281 fetcher->set_url(fetcher->GetOriginalURL()); | 276 fetcher->set_url(fetcher->GetOriginalURL()); |
| 282 fetcher->set_status(status); | 277 fetcher->set_status(status); |
| 283 fetcher->set_response_code(success ? 200 : 500); | 278 fetcher->set_response_code(success ? 200 : 500); |
| 284 fetcher->delegate()->OnURLFetchComplete(fetcher); | 279 fetcher->delegate()->OnURLFetchComplete(fetcher); |
| 285 } | 280 } |
| 286 | 281 |
| 287 void SimulateSupportedLanguagesURLFetch( | 282 void SimulateSupportedLanguagesURLFetch( |
| 288 bool success, | 283 bool success, |
| 289 const std::vector<std::string>& languages, | 284 const std::vector<std::string>& languages, |
| 290 bool use_alpha_languages, | 285 bool use_alpha_languages, |
| 291 const std::vector<std::string>& alpha_languages) { | 286 const std::vector<std::string>& alpha_languages) { |
| 292 net::URLRequestStatus status; | 287 net::URLRequestStatus status; |
| 293 status.set_status(success ? net::URLRequestStatus::SUCCESS : | 288 status.set_status(success ? net::URLRequestStatus::SUCCESS |
| 294 net::URLRequestStatus::FAILED); | 289 : net::URLRequestStatus::FAILED); |
| 295 | 290 |
| 296 std::string data; | 291 std::string data; |
| 297 if (success) { | 292 if (success) { |
| 298 data = base::StringPrintf( | 293 data = |
| 299 "%s{\"sl\": {\"bla\": \"bla\"}, \"%s\": {", | 294 base::StringPrintf("%s{\"sl\": {\"bla\": \"bla\"}, \"%s\": {", |
| 300 TranslateLanguageList::kLanguageListCallbackName, | 295 TranslateLanguageList::kLanguageListCallbackName, |
| 301 TranslateLanguageList::kTargetLanguagesKey); | 296 TranslateLanguageList::kTargetLanguagesKey); |
| 302 const char* comma = ""; | 297 const char* comma = ""; |
| 303 for (size_t i = 0; i < languages.size(); ++i) { | 298 for (size_t i = 0; i < languages.size(); ++i) { |
| 304 data += base::StringPrintf( | 299 data += base::StringPrintf( |
| 305 "%s\"%s\": \"UnusedFullName\"", comma, languages[i].c_str()); | 300 "%s\"%s\": \"UnusedFullName\"", comma, languages[i].c_str()); |
| 306 if (i == 0) | 301 if (i == 0) |
| 307 comma = ","; | 302 comma = ","; |
| 308 } | 303 } |
| 309 | 304 |
| 310 if (use_alpha_languages) { | 305 if (use_alpha_languages) { |
| 311 data += base::StringPrintf("},\"%s\": {", | 306 data += base::StringPrintf("},\"%s\": {", |
| 312 TranslateLanguageList::kAlphaLanguagesKey); | 307 TranslateLanguageList::kAlphaLanguagesKey); |
| 313 comma = ""; | 308 comma = ""; |
| 314 for (size_t i = 0; i < alpha_languages.size(); ++i) { | 309 for (size_t i = 0; i < alpha_languages.size(); ++i) { |
| 315 data += base::StringPrintf("%s\"%s\": 1", comma, | 310 data += base::StringPrintf( |
| 316 alpha_languages[i].c_str()); | 311 "%s\"%s\": 1", comma, alpha_languages[i].c_str()); |
| 317 if (i == 0) | 312 if (i == 0) |
| 318 comma = ","; | 313 comma = ","; |
| 319 } | 314 } |
| 320 } | 315 } |
| 321 | 316 |
| 322 data += "}})"; | 317 data += "}})"; |
| 323 } | 318 } |
| 324 net::TestURLFetcher* fetcher = | 319 net::TestURLFetcher* fetcher = |
| 325 url_fetcher_factory_.GetFetcherByID(TranslateLanguageList::kFetcherId); | 320 url_fetcher_factory_.GetFetcherByID(TranslateLanguageList::kFetcherId); |
| 326 ASSERT_TRUE(fetcher != NULL); | 321 ASSERT_TRUE(fetcher != NULL); |
| (...skipping 11 matching lines...) Expand all Loading... | |
| 338 PrefChangeRegistrar::NamedChangeCallback pref_callback_; | 333 PrefChangeRegistrar::NamedChangeCallback pref_callback_; |
| 339 | 334 |
| 340 private: | 335 private: |
| 341 content::NotificationRegistrar notification_registrar_; | 336 content::NotificationRegistrar notification_registrar_; |
| 342 net::TestURLFetcherFactory url_fetcher_factory_; | 337 net::TestURLFetcherFactory url_fetcher_factory_; |
| 343 | 338 |
| 344 // The infobars that have been removed. | 339 // The infobars that have been removed. |
| 345 // WARNING: the pointers point to deleted objects, use only for comparison. | 340 // WARNING: the pointers point to deleted objects, use only for comparison. |
| 346 std::set<InfoBarDelegate*> removed_infobars_; | 341 std::set<InfoBarDelegate*> removed_infobars_; |
| 347 | 342 |
| 348 DISALLOW_COPY_AND_ASSIGN(TranslateManagerBrowserTest); | 343 DISALLOW_COPY_AND_ASSIGN(TranslateManagerRenderViewHostTest); |
| 349 }; | 344 }; |
| 350 | 345 |
| 351 class MockTranslateBubbleFactory : public TranslateBubbleFactory { | 346 class MockTranslateBubbleFactory : public TranslateBubbleFactory { |
| 352 public: | 347 public: |
| 353 MockTranslateBubbleFactory() { | 348 MockTranslateBubbleFactory() {} |
| 354 } | |
| 355 | 349 |
| 356 virtual void ShowImplementation(BrowserWindow* window, | 350 virtual void ShowImplementation(BrowserWindow* window, |
| 357 content::WebContents* web_contents, | 351 content::WebContents* web_contents, |
| 358 TranslateTabHelper::TranslateStep step, | 352 TranslateTabHelper::TranslateStep step, |
| 359 TranslateErrors::Type error_type) OVERRIDE { | 353 TranslateErrors::Type error_type) OVERRIDE { |
| 360 if (model_) { | 354 if (model_) { |
| 361 model_->SetViewState( | 355 model_->SetViewState( |
| 362 TranslateBubbleModelImpl::TranslateStepToViewState(step)); | 356 TranslateBubbleModelImpl::TranslateStepToViewState(step)); |
| 363 return; | 357 return; |
| 364 } | 358 } |
| 365 | 359 |
| 366 TranslateTabHelper* translate_tab_helper = | 360 TranslateTabHelper* translate_tab_helper = |
| 367 TranslateTabHelper::FromWebContents(web_contents); | 361 TranslateTabHelper::FromWebContents(web_contents); |
| 368 std::string source_language = | 362 std::string source_language = |
| 369 translate_tab_helper->GetLanguageState().original_language(); | 363 translate_tab_helper->GetLanguageState().original_language(); |
| 370 std::string target_language = TranslateDownloadManager::GetLanguageCode( | 364 std::string target_language = TranslateDownloadManager::GetLanguageCode( |
| 371 g_browser_process->GetApplicationLocale()); | 365 g_browser_process->GetApplicationLocale()); |
| 372 scoped_ptr<TranslateUIDelegate> ui_delegate( | 366 scoped_ptr<TranslateUIDelegate> ui_delegate(new TranslateUIDelegate( |
| 373 new TranslateUIDelegate(web_contents, | 367 web_contents, source_language, target_language)); |
| 374 source_language, | |
| 375 target_language)); | |
| 376 model_.reset(new TranslateBubbleModelImpl(step, ui_delegate.Pass())); | 368 model_.reset(new TranslateBubbleModelImpl(step, ui_delegate.Pass())); |
| 377 } | 369 } |
| 378 | 370 |
| 379 TranslateBubbleModel* model() { return model_.get(); } | 371 TranslateBubbleModel* model() { return model_.get(); } |
| 380 | 372 |
| 381 private: | 373 private: |
| 382 scoped_ptr<TranslateBubbleModel> model_; | 374 scoped_ptr<TranslateBubbleModel> model_; |
| 383 | 375 |
| 384 DISALLOW_COPY_AND_ASSIGN(MockTranslateBubbleFactory); | 376 DISALLOW_COPY_AND_ASSIGN(MockTranslateBubbleFactory); |
| 385 }; | 377 }; |
| (...skipping 19 matching lines...) Expand all Loading... | |
| 405 params.writing_direction_right_to_left = 0; | 397 params.writing_direction_right_to_left = 0; |
| 406 #endif // OS_MACOSX | 398 #endif // OS_MACOSX |
| 407 params.edit_flags = blink::WebContextMenuData::CanTranslate; | 399 params.edit_flags = blink::WebContextMenuData::CanTranslate; |
| 408 return new TestRenderViewContextMenu(web_contents->GetMainFrame(), params); | 400 return new TestRenderViewContextMenu(web_contents->GetMainFrame(), params); |
| 409 } | 401 } |
| 410 | 402 |
| 411 bool IsItemPresent(int id) { | 403 bool IsItemPresent(int id) { |
| 412 return menu_model_.GetIndexOfCommandId(id) != -1; | 404 return menu_model_.GetIndexOfCommandId(id) != -1; |
| 413 } | 405 } |
| 414 | 406 |
| 415 virtual void PlatformInit() OVERRIDE { } | 407 virtual void PlatformInit() OVERRIDE {} |
| 416 virtual void PlatformCancel() OVERRIDE { } | 408 virtual void PlatformCancel() OVERRIDE {} |
| 417 virtual bool GetAcceleratorForCommandId( | 409 virtual bool GetAcceleratorForCommandId(int command_id, |
| 418 int command_id, | 410 ui::Accelerator* accelerator) |
| 419 ui::Accelerator* accelerator) OVERRIDE { return false; } | 411 OVERRIDE { |
| 412 return false; | |
| 413 } | |
| 420 | 414 |
| 421 private: | 415 private: |
| 422 TestRenderViewContextMenu(content::RenderFrameHost* render_frame_host, | 416 TestRenderViewContextMenu(content::RenderFrameHost* render_frame_host, |
| 423 const content::ContextMenuParams& params) | 417 const content::ContextMenuParams& params) |
| 424 : RenderViewContextMenu(render_frame_host, params) { | 418 : RenderViewContextMenu(render_frame_host, params) {} |
| 425 } | |
| 426 | 419 |
| 427 DISALLOW_COPY_AND_ASSIGN(TestRenderViewContextMenu); | 420 DISALLOW_COPY_AND_ASSIGN(TestRenderViewContextMenu); |
| 428 }; | 421 }; |
| 429 | 422 |
| 430 } // namespace | 423 } // namespace |
| 431 | 424 |
| 432 TEST_F(TranslateManagerBrowserTest, NormalTranslate) { | 425 TEST_F(TranslateManagerRenderViewHostTest, NormalTranslate) { |
| 433 SimulateNavigation(GURL("http://www.google.fr"), "fr", true); | 426 SimulateNavigation(GURL("http://www.google.fr"), "fr", true); |
| 434 | 427 |
| 435 // We should have an infobar. | 428 // We should have an infobar. |
| 436 TranslateInfoBarDelegate* infobar = GetTranslateInfoBar(); | 429 TranslateInfoBarDelegate* infobar = GetTranslateInfoBar(); |
| 437 ASSERT_TRUE(infobar != NULL); | 430 ASSERT_TRUE(infobar != NULL); |
| 438 EXPECT_EQ(TranslateTabHelper::BEFORE_TRANSLATE, infobar->translate_step()); | 431 EXPECT_EQ(TranslateTabHelper::BEFORE_TRANSLATE, infobar->translate_step()); |
| 439 | 432 |
| 440 // Simulate clicking translate. | 433 // Simulate clicking translate. |
| 441 process()->sink().ClearMessages(); | 434 process()->sink().ClearMessages(); |
| 442 infobar->Translate(); | 435 infobar->Translate(); |
| (...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 499 EXPECT_EQ(TranslateTabHelper::BEFORE_TRANSLATE, infobar->translate_step()); | 492 EXPECT_EQ(TranslateTabHelper::BEFORE_TRANSLATE, infobar->translate_step()); |
| 500 infobar->UpdateTargetLanguageIndex(1); | 493 infobar->UpdateTargetLanguageIndex(1); |
| 501 infobar->ToggleAlwaysTranslate(); | 494 infobar->ToggleAlwaysTranslate(); |
| 502 ReloadAndWait(true); | 495 ReloadAndWait(true); |
| 503 infobar = GetTranslateInfoBar(); | 496 infobar = GetTranslateInfoBar(); |
| 504 ASSERT_TRUE(infobar != NULL); | 497 ASSERT_TRUE(infobar != NULL); |
| 505 EXPECT_EQ(TranslateTabHelper::TRANSLATING, infobar->translate_step()); | 498 EXPECT_EQ(TranslateTabHelper::TRANSLATING, infobar->translate_step()); |
| 506 EXPECT_EQ(new_target_lang, infobar->target_language_code()); | 499 EXPECT_EQ(new_target_lang, infobar->target_language_code()); |
| 507 } | 500 } |
| 508 | 501 |
| 509 TEST_F(TranslateManagerBrowserTest, TranslateScriptNotAvailable) { | 502 TEST_F(TranslateManagerRenderViewHostTest, TranslateScriptNotAvailable) { |
| 510 SimulateNavigation(GURL("http://www.google.fr"), "fr", true); | 503 SimulateNavigation(GURL("http://www.google.fr"), "fr", true); |
| 511 | 504 |
| 512 // We should have an infobar. | 505 // We should have an infobar. |
| 513 TranslateInfoBarDelegate* infobar = GetTranslateInfoBar(); | 506 TranslateInfoBarDelegate* infobar = GetTranslateInfoBar(); |
| 514 ASSERT_TRUE(infobar != NULL); | 507 ASSERT_TRUE(infobar != NULL); |
| 515 EXPECT_EQ(TranslateTabHelper::BEFORE_TRANSLATE, infobar->translate_step()); | 508 EXPECT_EQ(TranslateTabHelper::BEFORE_TRANSLATE, infobar->translate_step()); |
| 516 | 509 |
| 517 // Simulate clicking translate. | 510 // Simulate clicking translate. |
| 518 process()->sink().ClearMessages(); | 511 process()->sink().ClearMessages(); |
| 519 infobar->Translate(); | 512 infobar->Translate(); |
| 520 SimulateTranslateScriptURLFetch(false); | 513 SimulateTranslateScriptURLFetch(false); |
| 521 | 514 |
| 522 // We should not have sent any message to translate to the renderer. | 515 // We should not have sent any message to translate to the renderer. |
| 523 EXPECT_FALSE(GetTranslateMessage(NULL, NULL, NULL)); | 516 EXPECT_FALSE(GetTranslateMessage(NULL, NULL, NULL)); |
| 524 | 517 |
| 525 // And we should have an error infobar showing. | 518 // And we should have an error infobar showing. |
| 526 infobar = GetTranslateInfoBar(); | 519 infobar = GetTranslateInfoBar(); |
| 527 ASSERT_TRUE(infobar != NULL); | 520 ASSERT_TRUE(infobar != NULL); |
| 528 EXPECT_EQ(TranslateTabHelper::TRANSLATE_ERROR, infobar->translate_step()); | 521 EXPECT_EQ(TranslateTabHelper::TRANSLATE_ERROR, infobar->translate_step()); |
| 529 } | 522 } |
| 530 | 523 |
| 531 // Ensures we deal correctly with pages for which the browser does not recognize | 524 // Ensures we deal correctly with pages for which the browser does not recognize |
| 532 // the language (the translate server may or not detect the language). | 525 // the language (the translate server may or not detect the language). |
| 533 TEST_F(TranslateManagerBrowserTest, TranslateUnknownLanguage) { | 526 TEST_F(TranslateManagerRenderViewHostTest, TranslateUnknownLanguage) { |
| 534 // Simulate navigating to a page ("und" is the string returned by the CLD for | 527 // Simulate navigating to a page ("und" is the string returned by the CLD for |
| 535 // languages it does not recognize). | 528 // languages it does not recognize). |
| 536 SimulateNavigation(GURL("http://www.google.mys"), "und", true); | 529 SimulateNavigation(GURL("http://www.google.mys"), "und", true); |
| 537 | 530 |
| 538 // We should not have an infobar as we don't know the language. | 531 // We should not have an infobar as we don't know the language. |
| 539 ASSERT_TRUE(GetTranslateInfoBar() == NULL); | 532 ASSERT_TRUE(GetTranslateInfoBar() == NULL); |
| 540 | 533 |
| 541 // Translate the page anyway throught the context menu. | 534 // Translate the page anyway throught the context menu. |
| 542 scoped_ptr<TestRenderViewContextMenu> menu( | 535 scoped_ptr<TestRenderViewContextMenu> menu( |
| 543 TestRenderViewContextMenu::CreateContextMenu(web_contents())); | 536 TestRenderViewContextMenu::CreateContextMenu(web_contents())); |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 576 ASSERT_TRUE(infobar != NULL); | 569 ASSERT_TRUE(infobar != NULL); |
| 577 EXPECT_EQ(TranslateTabHelper::TRANSLATE_ERROR, infobar->translate_step()); | 570 EXPECT_EQ(TranslateTabHelper::TRANSLATE_ERROR, infobar->translate_step()); |
| 578 EXPECT_EQ(TranslateErrors::IDENTICAL_LANGUAGES, infobar->error_type()); | 571 EXPECT_EQ(TranslateErrors::IDENTICAL_LANGUAGES, infobar->error_type()); |
| 579 | 572 |
| 580 // Let's run the same steps again but this time the server fails to detect the | 573 // Let's run the same steps again but this time the server fails to detect the |
| 581 // page's language (it returns an empty string). | 574 // page's language (it returns an empty string). |
| 582 SimulateNavigation(GURL("http://www.google.com"), "und", true); | 575 SimulateNavigation(GURL("http://www.google.com"), "und", true); |
| 583 menu.reset(TestRenderViewContextMenu::CreateContextMenu(web_contents())); | 576 menu.reset(TestRenderViewContextMenu::CreateContextMenu(web_contents())); |
| 584 menu->Init(); | 577 menu->Init(); |
| 585 menu->ExecuteCommand(IDC_CONTENT_CONTEXT_TRANSLATE, 0); | 578 menu->ExecuteCommand(IDC_CONTENT_CONTEXT_TRANSLATE, 0); |
| 586 SimulateOnPageTranslated(2, std::string(), "en", | 579 SimulateOnPageTranslated( |
| 587 TranslateErrors::UNKNOWN_LANGUAGE); | 580 2, std::string(), "en", TranslateErrors::UNKNOWN_LANGUAGE); |
| 588 infobar = GetTranslateInfoBar(); | 581 infobar = GetTranslateInfoBar(); |
| 589 ASSERT_TRUE(infobar != NULL); | 582 ASSERT_TRUE(infobar != NULL); |
| 590 EXPECT_EQ(TranslateTabHelper::TRANSLATE_ERROR, infobar->translate_step()); | 583 EXPECT_EQ(TranslateTabHelper::TRANSLATE_ERROR, infobar->translate_step()); |
| 591 EXPECT_EQ(TranslateErrors::UNKNOWN_LANGUAGE, infobar->error_type()); | 584 EXPECT_EQ(TranslateErrors::UNKNOWN_LANGUAGE, infobar->error_type()); |
| 592 } | 585 } |
| 593 | 586 |
| 594 // Tests that we show/don't show an info-bar for the languages. | 587 // Tests that we show/don't show an info-bar for the languages. |
| 595 TEST_F(TranslateManagerBrowserTest, TestLanguages) { | 588 TEST_F(TranslateManagerRenderViewHostTest, TestLanguages) { |
| 596 std::vector<std::string> languages; | 589 std::vector<std::string> languages; |
| 597 languages.push_back("en"); | 590 languages.push_back("en"); |
| 598 languages.push_back("ja"); | 591 languages.push_back("ja"); |
| 599 languages.push_back("fr"); | 592 languages.push_back("fr"); |
| 600 languages.push_back("ht"); | 593 languages.push_back("ht"); |
| 601 languages.push_back("xx"); | 594 languages.push_back("xx"); |
| 602 languages.push_back("zh"); | 595 languages.push_back("zh"); |
| 603 languages.push_back("zh-CN"); | 596 languages.push_back("zh-CN"); |
| 604 languages.push_back("und"); | 597 languages.push_back("und"); |
| 605 | 598 |
| 606 GURL url("http://www.google.com"); | 599 GURL url("http://www.google.com"); |
| 607 for (size_t i = 0; i < languages.size(); ++i) { | 600 for (size_t i = 0; i < languages.size(); ++i) { |
| 608 std::string lang = languages[i]; | 601 std::string lang = languages[i]; |
| 609 SCOPED_TRACE(::testing::Message() << "Iteration " << i << | 602 SCOPED_TRACE(::testing::Message() << "Iteration " << i |
| 610 " language=" << lang); | 603 << " language=" << lang); |
| 611 | 604 |
| 612 // We should not have a translate infobar. | 605 // We should not have a translate infobar. |
| 613 TranslateInfoBarDelegate* infobar = GetTranslateInfoBar(); | 606 TranslateInfoBarDelegate* infobar = GetTranslateInfoBar(); |
| 614 ASSERT_TRUE(infobar == NULL); | 607 ASSERT_TRUE(infobar == NULL); |
| 615 | 608 |
| 616 SimulateNavigation(url, lang, true); | 609 SimulateNavigation(url, lang, true); |
| 617 | 610 |
| 618 // Verify we have/don't have an info-bar as expected. | 611 // Verify we have/don't have an info-bar as expected. |
| 619 infobar = GetTranslateInfoBar(); | 612 infobar = GetTranslateInfoBar(); |
| 620 bool expected = | 613 bool expected = |
| 621 TranslateDownloadManager::IsSupportedLanguage(lang) && lang != "en"; | 614 TranslateDownloadManager::IsSupportedLanguage(lang) && lang != "en"; |
| 622 EXPECT_EQ(expected, infobar != NULL); | 615 EXPECT_EQ(expected, infobar != NULL); |
| 623 | 616 |
| 624 if (infobar != NULL) | 617 if (infobar != NULL) |
| 625 EXPECT_TRUE(CloseTranslateInfoBar()); | 618 EXPECT_TRUE(CloseTranslateInfoBar()); |
| 626 } | 619 } |
| 627 } | 620 } |
| 628 | 621 |
| 629 // Test the fetching of languages from the translate server | 622 // Test the fetching of languages from the translate server |
| 630 TEST_F(TranslateManagerBrowserTest, FetchLanguagesFromTranslateServer) { | 623 TEST_F(TranslateManagerRenderViewHostTest, FetchLanguagesFromTranslateServer) { |
| 631 std::vector<std::string> server_languages; | 624 std::vector<std::string> server_languages; |
| 632 // A list of languages to fake being returned by the translate server. | 625 // A list of languages to fake being returned by the translate server. |
| 633 server_languages.push_back("aa"); | 626 server_languages.push_back("aa"); |
| 634 server_languages.push_back("ak"); | 627 server_languages.push_back("ak"); |
| 635 server_languages.push_back("ab"); | 628 server_languages.push_back("ab"); |
| 636 server_languages.push_back("en-CA"); | 629 server_languages.push_back("en-CA"); |
| 637 server_languages.push_back("zh"); | 630 server_languages.push_back("zh"); |
| 638 server_languages.push_back("yi"); | 631 server_languages.push_back("yi"); |
| 639 server_languages.push_back("fr-FR"); | 632 server_languages.push_back("fr-FR"); |
| 640 server_languages.push_back("xx"); | 633 server_languages.push_back("xx"); |
| 641 | 634 |
| 642 std::vector<std::string> alpha_languages; | 635 std::vector<std::string> alpha_languages; |
| 643 alpha_languages.push_back("aa"); | 636 alpha_languages.push_back("aa"); |
| 644 alpha_languages.push_back("yi"); | 637 alpha_languages.push_back("yi"); |
| 645 | 638 |
| 646 // First, get the default languages list. Note that calling | 639 // First, get the default languages list. Note that calling |
| 647 // GetSupportedLanguages() invokes RequestLanguageList() internally. | 640 // GetSupportedLanguages() invokes RequestLanguageList() internally. |
| 648 std::vector<std::string> default_supported_languages; | 641 std::vector<std::string> default_supported_languages; |
| 649 TranslateDownloadManager::GetSupportedLanguages(&default_supported_languages); | 642 TranslateDownloadManager::GetSupportedLanguages(&default_supported_languages); |
| 650 // To make sure we got the defaults and don't confuse them with the mocks. | 643 // To make sure we got the defaults and don't confuse them with the mocks. |
| 651 ASSERT_NE(default_supported_languages.size(), server_languages.size()); | 644 ASSERT_NE(default_supported_languages.size(), server_languages.size()); |
| 652 | 645 |
| 653 // Check that we still get the defaults until the URLFetch has completed. | 646 // Check that we still get the defaults until the URLFetch has completed. |
| 654 std::vector<std::string> current_supported_languages; | 647 std::vector<std::string> current_supported_languages; |
| 655 TranslateDownloadManager::GetSupportedLanguages(¤t_supported_languages); | 648 TranslateDownloadManager::GetSupportedLanguages(¤t_supported_languages); |
| 656 EXPECT_EQ(default_supported_languages, current_supported_languages); | 649 EXPECT_EQ(default_supported_languages, current_supported_languages); |
| 657 | 650 |
| 658 // Also check that it didn't change if we failed the URL fetch. | 651 // Also check that it didn't change if we failed the URL fetch. |
| 659 SimulateSupportedLanguagesURLFetch(false, std::vector<std::string>(), | 652 SimulateSupportedLanguagesURLFetch( |
| 660 true, std::vector<std::string>()); | 653 false, std::vector<std::string>(), true, std::vector<std::string>()); |
| 661 current_supported_languages.clear(); | 654 current_supported_languages.clear(); |
| 662 TranslateDownloadManager::GetSupportedLanguages(¤t_supported_languages); | 655 TranslateDownloadManager::GetSupportedLanguages(¤t_supported_languages); |
| 663 EXPECT_EQ(default_supported_languages, current_supported_languages); | 656 EXPECT_EQ(default_supported_languages, current_supported_languages); |
| 664 | 657 |
| 665 // Now check that we got the appropriate set of languages from the server. | 658 // Now check that we got the appropriate set of languages from the server. |
| 666 SimulateSupportedLanguagesURLFetch(true, server_languages, | 659 SimulateSupportedLanguagesURLFetch( |
| 667 true, alpha_languages); | 660 true, server_languages, true, alpha_languages); |
| 668 current_supported_languages.clear(); | 661 current_supported_languages.clear(); |
| 669 TranslateDownloadManager::GetSupportedLanguages(¤t_supported_languages); | 662 TranslateDownloadManager::GetSupportedLanguages(¤t_supported_languages); |
| 670 // "xx" can't be displayed in the Translate inforbar, so this is eliminated. | 663 // "xx" can't be displayed in the Translate inforbar, so this is eliminated. |
| 671 EXPECT_EQ(server_languages.size() - 1, current_supported_languages.size()); | 664 EXPECT_EQ(server_languages.size() - 1, current_supported_languages.size()); |
| 672 // Not sure we need to guarantee the order of languages, so we find them. | 665 // Not sure we need to guarantee the order of languages, so we find them. |
| 673 for (size_t i = 0; i < server_languages.size(); ++i) { | 666 for (size_t i = 0; i < server_languages.size(); ++i) { |
| 674 const std::string& lang = server_languages[i]; | 667 const std::string& lang = server_languages[i]; |
| 675 if (lang == "xx") | 668 if (lang == "xx") |
| 676 continue; | 669 continue; |
| 677 EXPECT_NE(current_supported_languages.end(), | 670 EXPECT_NE(current_supported_languages.end(), |
| 678 std::find(current_supported_languages.begin(), | 671 std::find(current_supported_languages.begin(), |
| 679 current_supported_languages.end(), | 672 current_supported_languages.end(), |
| 680 lang)); | 673 lang)); |
| 681 bool is_alpha = std::find(alpha_languages.begin(), | 674 bool is_alpha = |
| 682 alpha_languages.end(), | 675 std::find(alpha_languages.begin(), alpha_languages.end(), lang) != |
| 683 lang) != alpha_languages.end(); | 676 alpha_languages.end(); |
| 684 EXPECT_EQ(TranslateDownloadManager::IsAlphaLanguage(lang), is_alpha); | 677 EXPECT_EQ(TranslateDownloadManager::IsAlphaLanguage(lang), is_alpha); |
| 685 } | 678 } |
| 686 } | 679 } |
| 687 | 680 |
| 688 // Test the fetching of languages from the translate server without 'al' | 681 // Test the fetching of languages from the translate server without 'al' |
| 689 // parameter. | 682 // parameter. |
| 690 TEST_F(TranslateManagerBrowserTest, | 683 TEST_F(TranslateManagerRenderViewHostTest, |
| 691 FetchLanguagesFromTranslateServerWithoutAlpha) { | 684 FetchLanguagesFromTranslateServerWithoutAlpha) { |
| 692 std::vector<std::string> server_languages; | 685 std::vector<std::string> server_languages; |
| 693 server_languages.push_back("aa"); | 686 server_languages.push_back("aa"); |
| 694 server_languages.push_back("ak"); | 687 server_languages.push_back("ak"); |
| 695 server_languages.push_back("ab"); | 688 server_languages.push_back("ab"); |
| 696 server_languages.push_back("en-CA"); | 689 server_languages.push_back("en-CA"); |
| 697 server_languages.push_back("zh"); | 690 server_languages.push_back("zh"); |
| 698 server_languages.push_back("yi"); | 691 server_languages.push_back("yi"); |
| 699 server_languages.push_back("fr-FR"); | 692 server_languages.push_back("fr-FR"); |
| 700 server_languages.push_back("xx"); | 693 server_languages.push_back("xx"); |
| 701 | 694 |
| 702 std::vector<std::string> alpha_languages; | 695 std::vector<std::string> alpha_languages; |
| 703 alpha_languages.push_back("aa"); | 696 alpha_languages.push_back("aa"); |
| 704 alpha_languages.push_back("yi"); | 697 alpha_languages.push_back("yi"); |
| 705 | 698 |
| 706 // call GetSupportedLanguages to call RequestLanguageList internally. | 699 // call GetSupportedLanguages to call RequestLanguageList internally. |
| 707 std::vector<std::string> default_supported_languages; | 700 std::vector<std::string> default_supported_languages; |
| 708 TranslateDownloadManager::GetSupportedLanguages(&default_supported_languages); | 701 TranslateDownloadManager::GetSupportedLanguages(&default_supported_languages); |
| 709 | 702 |
| 710 SimulateSupportedLanguagesURLFetch(true, server_languages, | 703 SimulateSupportedLanguagesURLFetch( |
| 711 false, alpha_languages); | 704 true, server_languages, false, alpha_languages); |
| 712 | 705 |
| 713 std::vector<std::string> current_supported_languages; | 706 std::vector<std::string> current_supported_languages; |
| 714 TranslateDownloadManager::GetSupportedLanguages(¤t_supported_languages); | 707 TranslateDownloadManager::GetSupportedLanguages(¤t_supported_languages); |
| 715 | 708 |
| 716 // "xx" can't be displayed in the Translate inforbar, so this is eliminated. | 709 // "xx" can't be displayed in the Translate inforbar, so this is eliminated. |
| 717 EXPECT_EQ(server_languages.size() - 1, current_supported_languages.size()); | 710 EXPECT_EQ(server_languages.size() - 1, current_supported_languages.size()); |
| 718 | 711 |
| 719 for (size_t i = 0; i < server_languages.size(); ++i) { | 712 for (size_t i = 0; i < server_languages.size(); ++i) { |
| 720 const std::string& lang = server_languages[i]; | 713 const std::string& lang = server_languages[i]; |
| 721 if (lang == "xx") | 714 if (lang == "xx") |
| 722 continue; | 715 continue; |
| 723 EXPECT_NE(current_supported_languages.end(), | 716 EXPECT_NE(current_supported_languages.end(), |
| 724 std::find(current_supported_languages.begin(), | 717 std::find(current_supported_languages.begin(), |
| 725 current_supported_languages.end(), | 718 current_supported_languages.end(), |
| 726 lang)); | 719 lang)); |
| 727 EXPECT_FALSE(TranslateDownloadManager::IsAlphaLanguage(lang)); | 720 EXPECT_FALSE(TranslateDownloadManager::IsAlphaLanguage(lang)); |
| 728 } | 721 } |
| 729 } | 722 } |
| 730 | 723 |
| 731 // Tests auto-translate on page. | 724 // Tests auto-translate on page. |
| 732 TEST_F(TranslateManagerBrowserTest, AutoTranslateOnNavigate) { | 725 TEST_F(TranslateManagerRenderViewHostTest, AutoTranslateOnNavigate) { |
| 733 SimulateNavigation(GURL("http://www.google.fr"), "fr", true); | 726 SimulateNavigation(GURL("http://www.google.fr"), "fr", true); |
| 734 | 727 |
| 735 // Simulate the user translating. | 728 // Simulate the user translating. |
| 736 TranslateInfoBarDelegate* infobar = GetTranslateInfoBar(); | 729 TranslateInfoBarDelegate* infobar = GetTranslateInfoBar(); |
| 737 ASSERT_TRUE(infobar != NULL); | 730 ASSERT_TRUE(infobar != NULL); |
| 738 infobar->Translate(); | 731 infobar->Translate(); |
| 739 // Simulate the translate script being retrieved. | 732 // Simulate the translate script being retrieved. |
| 740 SimulateTranslateScriptURLFetch(true); | 733 SimulateTranslateScriptURLFetch(true); |
| 741 SimulateOnPageTranslated("fr", "en"); | 734 SimulateOnPageTranslated("fr", "en"); |
| 742 | 735 |
| (...skipping 11 matching lines...) Expand all Loading... | |
| 754 | 747 |
| 755 // Now navigate to a page in a different language. | 748 // Now navigate to a page in a different language. |
| 756 process()->sink().ClearMessages(); | 749 process()->sink().ClearMessages(); |
| 757 SimulateNavigation(GURL("http://news.google.es"), "es", true); | 750 SimulateNavigation(GURL("http://news.google.es"), "es", true); |
| 758 | 751 |
| 759 // This should not have triggered a translate. | 752 // This should not have triggered a translate. |
| 760 EXPECT_FALSE(GetTranslateMessage(&page_id, &original_lang, &target_lang)); | 753 EXPECT_FALSE(GetTranslateMessage(&page_id, &original_lang, &target_lang)); |
| 761 } | 754 } |
| 762 | 755 |
| 763 // Tests that multiple OnPageContents do not cause multiple infobars. | 756 // Tests that multiple OnPageContents do not cause multiple infobars. |
| 764 TEST_F(TranslateManagerBrowserTest, MultipleOnPageContents) { | 757 TEST_F(TranslateManagerRenderViewHostTest, MultipleOnPageContents) { |
| 765 SimulateNavigation(GURL("http://www.google.fr"), "fr", true); | 758 SimulateNavigation(GURL("http://www.google.fr"), "fr", true); |
| 766 | 759 |
| 767 // Simulate clicking 'Nope' (don't translate). | 760 // Simulate clicking 'Nope' (don't translate). |
| 768 EXPECT_TRUE(DenyTranslation()); | 761 EXPECT_TRUE(DenyTranslation()); |
| 769 EXPECT_EQ(0U, infobar_service()->infobar_count()); | 762 EXPECT_EQ(0U, infobar_service()->infobar_count()); |
| 770 | 763 |
| 771 // Send a new PageContents, we should not show an infobar. | 764 // Send a new PageContents, we should not show an infobar. |
| 772 SimulateOnTranslateLanguageDetermined("fr", true); | 765 SimulateOnTranslateLanguageDetermined("fr", true); |
| 773 EXPECT_EQ(0U, infobar_service()->infobar_count()); | 766 EXPECT_EQ(0U, infobar_service()->infobar_count()); |
| 774 | 767 |
| 775 // Do the same steps but simulate closing the infobar this time. | 768 // Do the same steps but simulate closing the infobar this time. |
| 776 SimulateNavigation(GURL("http://www.youtube.fr"), "fr", true); | 769 SimulateNavigation(GURL("http://www.youtube.fr"), "fr", true); |
| 777 EXPECT_TRUE(CloseTranslateInfoBar()); | 770 EXPECT_TRUE(CloseTranslateInfoBar()); |
| 778 EXPECT_EQ(0U, infobar_service()->infobar_count()); | 771 EXPECT_EQ(0U, infobar_service()->infobar_count()); |
| 779 SimulateOnTranslateLanguageDetermined("fr", true); | 772 SimulateOnTranslateLanguageDetermined("fr", true); |
| 780 EXPECT_EQ(0U, infobar_service()->infobar_count()); | 773 EXPECT_EQ(0U, infobar_service()->infobar_count()); |
| 781 } | 774 } |
| 782 | 775 |
| 783 // Test that reloading the page brings back the infobar if the | 776 // Test that reloading the page brings back the infobar if the |
| 784 // reload succeeded and does not bring it back the reload fails. | 777 // reload succeeded and does not bring it back the reload fails. |
| 785 TEST_F(TranslateManagerBrowserTest, Reload) { | 778 TEST_F(TranslateManagerRenderViewHostTest, Reload) { |
| 786 SimulateNavigation(GURL("http://www.google.fr"), "fr", true); | 779 SimulateNavigation(GURL("http://www.google.fr"), "fr", true); |
| 787 | 780 |
| 788 EXPECT_TRUE(CloseTranslateInfoBar()); | 781 EXPECT_TRUE(CloseTranslateInfoBar()); |
| 789 | 782 |
| 790 // Reload should bring back the infobar if the reload succeeds. | 783 // Reload should bring back the infobar if the reload succeeds. |
| 791 ReloadAndWait(true); | 784 ReloadAndWait(true); |
| 792 EXPECT_TRUE(GetTranslateInfoBar() != NULL); | 785 EXPECT_TRUE(GetTranslateInfoBar() != NULL); |
| 793 EXPECT_TRUE(CloseTranslateInfoBar()); | 786 EXPECT_TRUE(CloseTranslateInfoBar()); |
| 794 | 787 |
| 795 // ...But not show it if the reload fails. | 788 // ...But not show it if the reload fails. |
| 796 ReloadAndWait(false); | 789 ReloadAndWait(false); |
| 797 EXPECT_TRUE(GetTranslateInfoBar() == NULL); | 790 EXPECT_TRUE(GetTranslateInfoBar() == NULL); |
| 798 | 791 |
| 799 // If we set reload attempts to a high value, we will not see the infobar | 792 // If we set reload attempts to a high value, we will not see the infobar |
| 800 // immediately. | 793 // immediately. |
| 801 TranslateManager* manager = | 794 TranslateManager* manager = |
| 802 TranslateTabHelper::GetManagerFromWebContents(web_contents()); | 795 TranslateTabHelper::GetManagerFromWebContents(web_contents()); |
| 803 manager->set_translate_max_reload_attemps(100); | 796 manager->set_translate_max_reload_attemps(100); |
| 804 ReloadAndWait(true); | 797 ReloadAndWait(true); |
| 805 EXPECT_TRUE(GetTranslateInfoBar() == NULL); | 798 EXPECT_TRUE(GetTranslateInfoBar() == NULL); |
| 806 } | 799 } |
| 807 | 800 |
| 808 // Test that reloading the page by way of typing again the URL in the | 801 // Test that reloading the page by way of typing again the URL in the |
| 809 // location bar brings back the infobar. | 802 // location bar brings back the infobar. |
| 810 TEST_F(TranslateManagerBrowserTest, ReloadFromLocationBar) { | 803 TEST_F(TranslateManagerRenderViewHostTest, ReloadFromLocationBar) { |
| 811 GURL url("http://www.google.fr"); | 804 GURL url("http://www.google.fr"); |
| 812 SimulateNavigation(url, "fr", true); | 805 SimulateNavigation(url, "fr", true); |
| 813 | 806 |
| 814 EXPECT_TRUE(CloseTranslateInfoBar()); | 807 EXPECT_TRUE(CloseTranslateInfoBar()); |
| 815 | 808 |
| 816 // Create a pending navigation and simulate a page load. That should be the | 809 // Create a pending navigation and simulate a page load. That should be the |
| 817 // equivalent of typing the URL again in the location bar. | 810 // equivalent of typing the URL again in the location bar. |
| 818 NavEntryCommittedObserver nav_observer(web_contents()); | 811 NavEntryCommittedObserver nav_observer(web_contents()); |
| 819 web_contents()->GetController().LoadURL(url, content::Referrer(), | 812 web_contents()->GetController().LoadURL( |
| 820 content::PAGE_TRANSITION_TYPED, | 813 url, content::Referrer(), content::PAGE_TRANSITION_TYPED, std::string()); |
| 821 std::string()); | |
| 822 rvh_tester()->SendNavigate(0, url); | 814 rvh_tester()->SendNavigate(0, url); |
| 823 | 815 |
| 824 // Test that we are really getting a same page navigation, the test would be | 816 // Test that we are really getting a same page navigation, the test would be |
| 825 // useless if it was not the case. | 817 // useless if it was not the case. |
| 826 const content::LoadCommittedDetails& nav_details = | 818 const content::LoadCommittedDetails& nav_details = |
| 827 nav_observer.load_committed_details(); | 819 nav_observer.load_committed_details(); |
| 828 EXPECT_TRUE(nav_details.entry != NULL); // There was a navigation. | 820 EXPECT_TRUE(nav_details.entry != NULL); // There was a navigation. |
| 829 EXPECT_EQ(content::NAVIGATION_TYPE_SAME_PAGE, nav_details.type); | 821 EXPECT_EQ(content::NAVIGATION_TYPE_SAME_PAGE, nav_details.type); |
| 830 | 822 |
| 831 // The TranslateManager class processes the navigation entry committed | 823 // The TranslateManager class processes the navigation entry committed |
| 832 // notification in a posted task; process that task. | 824 // notification in a posted task; process that task. |
| 833 base::MessageLoop::current()->RunUntilIdle(); | 825 base::MessageLoop::current()->RunUntilIdle(); |
| 834 EXPECT_TRUE(GetTranslateInfoBar() != NULL); | 826 EXPECT_TRUE(GetTranslateInfoBar() != NULL); |
| 835 } | 827 } |
| 836 | 828 |
| 837 // Tests that a closed translate infobar does not reappear when navigating | 829 // Tests that a closed translate infobar does not reappear when navigating |
| 838 // in-page. | 830 // in-page. |
| 839 TEST_F(TranslateManagerBrowserTest, CloseInfoBarInPageNavigation) { | 831 TEST_F(TranslateManagerRenderViewHostTest, CloseInfoBarInPageNavigation) { |
| 840 SimulateNavigation(GURL("http://www.google.fr"), "fr", true); | 832 SimulateNavigation(GURL("http://www.google.fr"), "fr", true); |
| 841 | 833 |
| 842 EXPECT_TRUE(CloseTranslateInfoBar()); | 834 EXPECT_TRUE(CloseTranslateInfoBar()); |
| 843 | 835 |
| 844 // Navigate in page, no infobar should be shown. | 836 // Navigate in page, no infobar should be shown. |
| 845 SimulateNavigation(GURL("http://www.google.fr/#ref1"), "fr", true); | 837 SimulateNavigation(GURL("http://www.google.fr/#ref1"), "fr", true); |
| 846 EXPECT_TRUE(GetTranslateInfoBar() == NULL); | 838 EXPECT_TRUE(GetTranslateInfoBar() == NULL); |
| 847 | 839 |
| 848 // Navigate out of page, a new infobar should show. | 840 // Navigate out of page, a new infobar should show. |
| 849 SimulateNavigation(GURL("http://www.google.fr/foot"), "fr", true); | 841 SimulateNavigation(GURL("http://www.google.fr/foot"), "fr", true); |
| 850 EXPECT_TRUE(GetTranslateInfoBar() != NULL); | 842 EXPECT_TRUE(GetTranslateInfoBar() != NULL); |
| 851 } | 843 } |
| 852 | 844 |
| 853 // Tests that a closed translate infobar does not reappear when navigating | 845 // Tests that a closed translate infobar does not reappear when navigating |
| 854 // in a subframe. (http://crbug.com/48215) | 846 // in a subframe. (http://crbug.com/48215) |
| 855 TEST_F(TranslateManagerBrowserTest, CloseInfoBarInSubframeNavigation) { | 847 TEST_F(TranslateManagerRenderViewHostTest, CloseInfoBarInSubframeNavigation) { |
| 856 SimulateNavigation(GURL("http://www.google.fr"), "fr", true); | 848 SimulateNavigation(GURL("http://www.google.fr"), "fr", true); |
| 857 | 849 |
| 858 EXPECT_TRUE(CloseTranslateInfoBar()); | 850 EXPECT_TRUE(CloseTranslateInfoBar()); |
| 859 | 851 |
| 860 // Simulate a sub-frame auto-navigating. | 852 // Simulate a sub-frame auto-navigating. |
| 861 rvh_tester()->SendNavigateWithTransition( | 853 rvh_tester()->SendNavigateWithTransition( |
| 862 1, GURL("http://pub.com"), content::PAGE_TRANSITION_AUTO_SUBFRAME); | 854 1, GURL("http://pub.com"), content::PAGE_TRANSITION_AUTO_SUBFRAME); |
| 863 EXPECT_TRUE(GetTranslateInfoBar() == NULL); | 855 EXPECT_TRUE(GetTranslateInfoBar() == NULL); |
| 864 | 856 |
| 865 // Simulate the user navigating in a sub-frame. | 857 // Simulate the user navigating in a sub-frame. |
| 866 rvh_tester()->SendNavigateWithTransition( | 858 rvh_tester()->SendNavigateWithTransition( |
| 867 2, GURL("http://pub.com"), content::PAGE_TRANSITION_MANUAL_SUBFRAME); | 859 2, GURL("http://pub.com"), content::PAGE_TRANSITION_MANUAL_SUBFRAME); |
| 868 EXPECT_TRUE(GetTranslateInfoBar() == NULL); | 860 EXPECT_TRUE(GetTranslateInfoBar() == NULL); |
| 869 | 861 |
| 870 // Navigate out of page, a new infobar should show. | 862 // Navigate out of page, a new infobar should show. |
| 871 SimulateNavigation(GURL("http://www.google.fr/foot"), "fr", true); | 863 SimulateNavigation(GURL("http://www.google.fr/foot"), "fr", true); |
| 872 EXPECT_TRUE(GetTranslateInfoBar() != NULL); | 864 EXPECT_TRUE(GetTranslateInfoBar() != NULL); |
| 873 } | 865 } |
| 874 | 866 |
| 875 // Tests that denying translation is sticky when navigating in page. | 867 // Tests that denying translation is sticky when navigating in page. |
| 876 TEST_F(TranslateManagerBrowserTest, DenyTranslateInPageNavigation) { | 868 TEST_F(TranslateManagerRenderViewHostTest, DenyTranslateInPageNavigation) { |
| 877 SimulateNavigation(GURL("http://www.google.fr"), "fr", true); | 869 SimulateNavigation(GURL("http://www.google.fr"), "fr", true); |
| 878 | 870 |
| 879 // Simulate clicking 'Nope' (don't translate). | 871 // Simulate clicking 'Nope' (don't translate). |
| 880 EXPECT_TRUE(DenyTranslation()); | 872 EXPECT_TRUE(DenyTranslation()); |
| 881 | 873 |
| 882 // Navigate in page, no infobar should be shown. | 874 // Navigate in page, no infobar should be shown. |
| 883 SimulateNavigation(GURL("http://www.google.fr/#ref1"), "fr", true); | 875 SimulateNavigation(GURL("http://www.google.fr/#ref1"), "fr", true); |
| 884 EXPECT_TRUE(GetTranslateInfoBar() == NULL); | 876 EXPECT_TRUE(GetTranslateInfoBar() == NULL); |
| 885 | 877 |
| 886 // Navigate out of page, a new infobar should show. | 878 // Navigate out of page, a new infobar should show. |
| 887 SimulateNavigation(GURL("http://www.google.fr/foot"), "fr", true); | 879 SimulateNavigation(GURL("http://www.google.fr/foot"), "fr", true); |
| 888 EXPECT_TRUE(GetTranslateInfoBar() != NULL); | 880 EXPECT_TRUE(GetTranslateInfoBar() != NULL); |
| 889 } | 881 } |
| 890 | 882 |
| 891 // Tests that after translating and closing the infobar, the infobar does not | 883 // Tests that after translating and closing the infobar, the infobar does not |
| 892 // return when navigating in page. | 884 // return when navigating in page. |
| 893 TEST_F(TranslateManagerBrowserTest, TranslateCloseInfoBarInPageNavigation) { | 885 TEST_F(TranslateManagerRenderViewHostTest, |
| 886 TranslateCloseInfoBarInPageNavigation) { | |
| 894 SimulateNavigation(GURL("http://www.google.fr"), "fr", true); | 887 SimulateNavigation(GURL("http://www.google.fr"), "fr", true); |
| 895 | 888 |
| 896 // Simulate the user translating. | 889 // Simulate the user translating. |
| 897 TranslateInfoBarDelegate* infobar = GetTranslateInfoBar(); | 890 TranslateInfoBarDelegate* infobar = GetTranslateInfoBar(); |
| 898 ASSERT_TRUE(infobar != NULL); | 891 ASSERT_TRUE(infobar != NULL); |
| 899 infobar->Translate(); | 892 infobar->Translate(); |
| 900 // Simulate the translate script being retrieved. | 893 // Simulate the translate script being retrieved. |
| 901 SimulateTranslateScriptURLFetch(true); | 894 SimulateTranslateScriptURLFetch(true); |
| 902 SimulateOnPageTranslated("fr", "en"); | 895 SimulateOnPageTranslated("fr", "en"); |
| 903 | 896 |
| 904 EXPECT_TRUE(CloseTranslateInfoBar()); | 897 EXPECT_TRUE(CloseTranslateInfoBar()); |
| 905 | 898 |
| 906 // Navigate in page, no infobar should be shown. | 899 // Navigate in page, no infobar should be shown. |
| 907 SimulateNavigation(GURL("http://www.google.fr/#ref1"), "fr", true); | 900 SimulateNavigation(GURL("http://www.google.fr/#ref1"), "fr", true); |
| 908 EXPECT_TRUE(GetTranslateInfoBar() == NULL); | 901 EXPECT_TRUE(GetTranslateInfoBar() == NULL); |
| 909 | 902 |
| 910 // Navigate out of page, a new infobar should show. | 903 // Navigate out of page, a new infobar should show. |
| 911 // Note that we navigate to a page in a different language so we don't trigger | 904 // Note that we navigate to a page in a different language so we don't trigger |
| 912 // the auto-translate feature (it would translate the page automatically and | 905 // the auto-translate feature (it would translate the page automatically and |
| 913 // the before translate inforbar would not be shown). | 906 // the before translate inforbar would not be shown). |
| 914 SimulateNavigation(GURL("http://www.google.de"), "de", true); | 907 SimulateNavigation(GURL("http://www.google.de"), "de", true); |
| 915 EXPECT_TRUE(GetTranslateInfoBar() != NULL); | 908 EXPECT_TRUE(GetTranslateInfoBar() != NULL); |
| 916 } | 909 } |
| 917 | 910 |
| 918 // Tests that the after translate the infobar still shows when navigating | 911 // Tests that the after translate the infobar still shows when navigating |
| 919 // in-page. | 912 // in-page. |
| 920 TEST_F(TranslateManagerBrowserTest, TranslateInPageNavigation) { | 913 TEST_F(TranslateManagerRenderViewHostTest, TranslateInPageNavigation) { |
| 921 SimulateNavigation(GURL("http://www.google.fr"), "fr", true); | 914 SimulateNavigation(GURL("http://www.google.fr"), "fr", true); |
| 922 | 915 |
| 923 // Simulate the user translating. | 916 // Simulate the user translating. |
| 924 TranslateInfoBarDelegate* infobar = GetTranslateInfoBar(); | 917 TranslateInfoBarDelegate* infobar = GetTranslateInfoBar(); |
| 925 ASSERT_TRUE(infobar != NULL); | 918 ASSERT_TRUE(infobar != NULL); |
| 926 infobar->Translate(); | 919 infobar->Translate(); |
| 927 SimulateTranslateScriptURLFetch(true); | 920 SimulateTranslateScriptURLFetch(true); |
| 928 SimulateOnPageTranslated("fr", "en"); | 921 SimulateOnPageTranslated("fr", "en"); |
| 929 // The after translate infobar is showing. | 922 // The after translate infobar is showing. |
| 930 infobar = GetTranslateInfoBar(); | 923 infobar = GetTranslateInfoBar(); |
| 931 ASSERT_TRUE(infobar != NULL); | 924 ASSERT_TRUE(infobar != NULL); |
| 932 | 925 |
| 933 // Navigate out of page, a new infobar should show. | 926 // Navigate out of page, a new infobar should show. |
| 934 // See note in TranslateCloseInfoBarInPageNavigation test on why it is | 927 // See note in TranslateCloseInfoBarInPageNavigation test on why it is |
| 935 // important to navigate to a page in a different language for this test. | 928 // important to navigate to a page in a different language for this test. |
| 936 SimulateNavigation(GURL("http://www.google.de"), "de", true); | 929 SimulateNavigation(GURL("http://www.google.de"), "de", true); |
| 937 // The old infobar is gone. | 930 // The old infobar is gone. |
| 938 EXPECT_TRUE(CheckInfoBarRemovedAndReset(infobar)); | 931 EXPECT_TRUE(CheckInfoBarRemovedAndReset(infobar)); |
| 939 // And there is a new one. | 932 // And there is a new one. |
| 940 EXPECT_TRUE(GetTranslateInfoBar() != NULL); | 933 EXPECT_TRUE(GetTranslateInfoBar() != NULL); |
| 941 } | 934 } |
| 942 | 935 |
| 943 // Tests that no translate infobar is shown when navigating to a page in an | 936 // Tests that no translate infobar is shown when navigating to a page in an |
| 944 // unsupported language. | 937 // unsupported language. |
| 945 TEST_F(TranslateManagerBrowserTest, CLDReportsUnsupportedPageLanguage) { | 938 TEST_F(TranslateManagerRenderViewHostTest, CLDReportsUnsupportedPageLanguage) { |
| 946 // Simulate navigating to a page and getting an unsupported language. | 939 // Simulate navigating to a page and getting an unsupported language. |
| 947 SimulateNavigation(GURL("http://www.google.com"), "qbz", true); | 940 SimulateNavigation(GURL("http://www.google.com"), "qbz", true); |
| 948 | 941 |
| 949 // No info-bar should be shown. | 942 // No info-bar should be shown. |
| 950 EXPECT_TRUE(GetTranslateInfoBar() == NULL); | 943 EXPECT_TRUE(GetTranslateInfoBar() == NULL); |
| 951 } | 944 } |
| 952 | 945 |
| 953 // Tests that we deal correctly with unsupported languages returned by the | 946 // Tests that we deal correctly with unsupported languages returned by the |
| 954 // server. | 947 // server. |
| 955 // The translation server might return a language we don't support. | 948 // The translation server might return a language we don't support. |
| 956 TEST_F(TranslateManagerBrowserTest, ServerReportsUnsupportedLanguage) { | 949 TEST_F(TranslateManagerRenderViewHostTest, ServerReportsUnsupportedLanguage) { |
| 957 SimulateNavigation(GURL("http://mail.google.fr"), "fr", true); | 950 SimulateNavigation(GURL("http://mail.google.fr"), "fr", true); |
| 958 TranslateInfoBarDelegate* infobar = GetTranslateInfoBar(); | 951 TranslateInfoBarDelegate* infobar = GetTranslateInfoBar(); |
| 959 ASSERT_TRUE(infobar != NULL); | 952 ASSERT_TRUE(infobar != NULL); |
| 960 process()->sink().ClearMessages(); | 953 process()->sink().ClearMessages(); |
| 961 infobar->Translate(); | 954 infobar->Translate(); |
| 962 SimulateTranslateScriptURLFetch(true); | 955 SimulateTranslateScriptURLFetch(true); |
| 963 // Simulate the render notifying the translation has been done, but it | 956 // Simulate the render notifying the translation has been done, but it |
| 964 // reports a language we don't support. | 957 // reports a language we don't support. |
| 965 SimulateOnPageTranslated("qbz", "en"); | 958 SimulateOnPageTranslated("qbz", "en"); |
| 966 | 959 |
| 967 // An error infobar should be showing to report that we don't support this | 960 // An error infobar should be showing to report that we don't support this |
| 968 // language. | 961 // language. |
| 969 infobar = GetTranslateInfoBar(); | 962 infobar = GetTranslateInfoBar(); |
| 970 ASSERT_TRUE(infobar != NULL); | 963 ASSERT_TRUE(infobar != NULL); |
| 971 EXPECT_EQ(TranslateTabHelper::TRANSLATE_ERROR, infobar->translate_step()); | 964 EXPECT_EQ(TranslateTabHelper::TRANSLATE_ERROR, infobar->translate_step()); |
| 972 | 965 |
| 973 // This infobar should have a button (so the string should not be empty). | 966 // This infobar should have a button (so the string should not be empty). |
| 974 ASSERT_FALSE(infobar->GetMessageInfoBarButtonText().empty()); | 967 ASSERT_FALSE(infobar->GetMessageInfoBarButtonText().empty()); |
| 975 | 968 |
| 976 // Pressing the button on that infobar should revert to the original language. | 969 // Pressing the button on that infobar should revert to the original language. |
| 977 process()->sink().ClearMessages(); | 970 process()->sink().ClearMessages(); |
| 978 infobar->MessageInfoBarButtonPressed(); | 971 infobar->MessageInfoBarButtonPressed(); |
| 979 const IPC::Message* message = | 972 const IPC::Message* message = process()->sink().GetFirstMessageMatching( |
| 980 process()->sink().GetFirstMessageMatching( | 973 ChromeViewMsg_RevertTranslation::ID); |
| 981 ChromeViewMsg_RevertTranslation::ID); | |
| 982 EXPECT_TRUE(message != NULL); | 974 EXPECT_TRUE(message != NULL); |
| 983 // And it should have removed the infobar. | 975 // And it should have removed the infobar. |
| 984 EXPECT_TRUE(GetTranslateInfoBar() == NULL); | 976 EXPECT_TRUE(GetTranslateInfoBar() == NULL); |
| 985 } | 977 } |
| 986 | 978 |
| 987 // Tests that no translate infobar is shown and context menu is disabled, when | 979 // Tests that no translate infobar is shown and context menu is disabled, when |
| 988 // Chrome is in a language that the translate server does not support. | 980 // Chrome is in a language that the translate server does not support. |
| 989 TEST_F(TranslateManagerBrowserTest, UnsupportedUILanguage) { | 981 TEST_F(TranslateManagerRenderViewHostTest, UnsupportedUILanguage) { |
| 990 std::string original_lang = g_browser_process->GetApplicationLocale(); | 982 std::string original_lang = g_browser_process->GetApplicationLocale(); |
| 991 SetApplicationLocale("qbz"); | 983 SetApplicationLocale("qbz"); |
| 992 | 984 |
| 993 // Make sure that the accept language list only contains unsupported languages | 985 // Make sure that the accept language list only contains unsupported languages |
| 994 Profile* profile = | 986 Profile* profile = |
| 995 Profile::FromBrowserContext(web_contents()->GetBrowserContext()); | 987 Profile::FromBrowserContext(web_contents()->GetBrowserContext()); |
| 996 PrefService* prefs = profile->GetPrefs(); | 988 PrefService* prefs = profile->GetPrefs(); |
| 997 prefs->SetString(prefs::kAcceptLanguages, "qbz"); | 989 prefs->SetString(prefs::kAcceptLanguages, "qbz"); |
| 998 | 990 |
| 999 // Simulate navigating to a page in a language supported by the translate | 991 // Simulate navigating to a page in a language supported by the translate |
| 1000 // server. | 992 // server. |
| 1001 SimulateNavigation(GURL("http://www.google.com"), "en", true); | 993 SimulateNavigation(GURL("http://www.google.com"), "en", true); |
| 1002 | 994 |
| 1003 // No info-bar should be shown. | 995 // No info-bar should be shown. |
| 1004 EXPECT_TRUE(GetTranslateInfoBar() == NULL); | 996 EXPECT_TRUE(GetTranslateInfoBar() == NULL); |
| 1005 | 997 |
| 1006 // And the context menu option should be disabled too. | 998 // And the context menu option should be disabled too. |
| 1007 scoped_ptr<TestRenderViewContextMenu> menu( | 999 scoped_ptr<TestRenderViewContextMenu> menu( |
| 1008 TestRenderViewContextMenu::CreateContextMenu(web_contents())); | 1000 TestRenderViewContextMenu::CreateContextMenu(web_contents())); |
| 1009 menu->Init(); | 1001 menu->Init(); |
| 1010 EXPECT_TRUE(menu->IsItemPresent(IDC_CONTENT_CONTEXT_TRANSLATE)); | 1002 EXPECT_TRUE(menu->IsItemPresent(IDC_CONTENT_CONTEXT_TRANSLATE)); |
| 1011 EXPECT_FALSE(menu->IsCommandIdEnabled(IDC_CONTENT_CONTEXT_TRANSLATE)); | 1003 EXPECT_FALSE(menu->IsCommandIdEnabled(IDC_CONTENT_CONTEXT_TRANSLATE)); |
| 1012 | 1004 |
| 1013 SetApplicationLocale(original_lang); | 1005 SetApplicationLocale(original_lang); |
| 1014 } | 1006 } |
| 1015 | 1007 |
| 1016 // Tests that the first supported accept language is selected | 1008 // Tests that the first supported accept language is selected |
| 1017 TEST_F(TranslateManagerBrowserTest, TranslateAcceptLanguage) { | 1009 TEST_F(TranslateManagerRenderViewHostTest, TranslateAcceptLanguage) { |
| 1018 // Set locate to non-existant language | 1010 // Set locate to non-existant language |
| 1019 std::string original_lang = g_browser_process->GetApplicationLocale(); | 1011 std::string original_lang = g_browser_process->GetApplicationLocale(); |
| 1020 SetApplicationLocale("qbz"); | 1012 SetApplicationLocale("qbz"); |
| 1021 | 1013 |
| 1022 // Set Qbz and French as the only accepted languages | 1014 // Set Qbz and French as the only accepted languages |
| 1023 Profile* profile = | 1015 Profile* profile = |
| 1024 Profile::FromBrowserContext(web_contents()->GetBrowserContext()); | 1016 Profile::FromBrowserContext(web_contents()->GetBrowserContext()); |
| 1025 PrefService* prefs = profile->GetPrefs(); | 1017 PrefService* prefs = profile->GetPrefs(); |
| 1026 prefs->SetString(prefs::kAcceptLanguages, "qbz,fr"); | 1018 prefs->SetString(prefs::kAcceptLanguages, "qbz,fr"); |
| 1027 | 1019 |
| 1028 // Go to a German page | 1020 // Go to a German page |
| 1029 SimulateNavigation(GURL("http://google.de"), "de", true); | 1021 SimulateNavigation(GURL("http://google.de"), "de", true); |
| 1030 | 1022 |
| 1031 // Expect the infobar to pop up | 1023 // Expect the infobar to pop up |
| 1032 EXPECT_TRUE(GetTranslateInfoBar() != NULL); | 1024 EXPECT_TRUE(GetTranslateInfoBar() != NULL); |
| 1033 | 1025 |
| 1034 // Set Qbz and English-US as the only accepted languages to test the country | 1026 // Set Qbz and English-US as the only accepted languages to test the country |
| 1035 // code removal code which was causing a crash as filed in Issue 90106, | 1027 // code removal code which was causing a crash as filed in Issue 90106, |
| 1036 // a crash caused by a language with a country code that wasn't recognized. | 1028 // a crash caused by a language with a country code that wasn't recognized. |
| 1037 prefs->SetString(prefs::kAcceptLanguages, "qbz,en-us"); | 1029 prefs->SetString(prefs::kAcceptLanguages, "qbz,en-us"); |
| 1038 | 1030 |
| 1039 // Go to a German page | 1031 // Go to a German page |
| 1040 SimulateNavigation(GURL("http://google.de"), "de", true); | 1032 SimulateNavigation(GURL("http://google.de"), "de", true); |
| 1041 | 1033 |
| 1042 // Expect the infobar to pop up | 1034 // Expect the infobar to pop up |
| 1043 EXPECT_TRUE(GetTranslateInfoBar() != NULL); | 1035 EXPECT_TRUE(GetTranslateInfoBar() != NULL); |
| 1044 } | 1036 } |
| 1045 | 1037 |
| 1046 // Tests that the translate enabled preference is honored. | 1038 // Tests that the translate enabled preference is honored. |
| 1047 TEST_F(TranslateManagerBrowserTest, TranslateEnabledPref) { | 1039 TEST_F(TranslateManagerRenderViewHostTest, TranslateEnabledPref) { |
| 1048 // Make sure the pref allows translate. | 1040 // Make sure the pref allows translate. |
| 1049 Profile* profile = | 1041 Profile* profile = |
| 1050 Profile::FromBrowserContext(web_contents()->GetBrowserContext()); | 1042 Profile::FromBrowserContext(web_contents()->GetBrowserContext()); |
| 1051 PrefService* prefs = profile->GetPrefs(); | 1043 PrefService* prefs = profile->GetPrefs(); |
| 1052 prefs->SetBoolean(prefs::kEnableTranslate, true); | 1044 prefs->SetBoolean(prefs::kEnableTranslate, true); |
| 1053 | 1045 |
| 1054 SimulateNavigation(GURL("http://www.google.fr"), "fr", true); | 1046 SimulateNavigation(GURL("http://www.google.fr"), "fr", true); |
| 1055 | 1047 |
| 1056 // An infobar should be shown. | 1048 // An infobar should be shown. |
| 1057 TranslateInfoBarDelegate* infobar = GetTranslateInfoBar(); | 1049 TranslateInfoBarDelegate* infobar = GetTranslateInfoBar(); |
| 1058 EXPECT_TRUE(infobar != NULL); | 1050 EXPECT_TRUE(infobar != NULL); |
| 1059 | 1051 |
| 1060 // Disable translate. | 1052 // Disable translate. |
| 1061 prefs->SetBoolean(prefs::kEnableTranslate, false); | 1053 prefs->SetBoolean(prefs::kEnableTranslate, false); |
| 1062 | 1054 |
| 1063 // Navigate to a new page, that should close the previous infobar. | 1055 // Navigate to a new page, that should close the previous infobar. |
| 1064 GURL url("http://www.youtube.fr"); | 1056 GURL url("http://www.youtube.fr"); |
| 1065 NavigateAndCommit(url); | 1057 NavigateAndCommit(url); |
| 1066 infobar = GetTranslateInfoBar(); | 1058 infobar = GetTranslateInfoBar(); |
| 1067 EXPECT_TRUE(infobar == NULL); | 1059 EXPECT_TRUE(infobar == NULL); |
| 1068 | 1060 |
| 1069 // Simulate getting the page contents and language, that should not trigger | 1061 // Simulate getting the page contents and language, that should not trigger |
| 1070 // a translate infobar. | 1062 // a translate infobar. |
| 1071 SimulateOnTranslateLanguageDetermined("fr", true); | 1063 SimulateOnTranslateLanguageDetermined("fr", true); |
| 1072 infobar = GetTranslateInfoBar(); | 1064 infobar = GetTranslateInfoBar(); |
| 1073 EXPECT_TRUE(infobar == NULL); | 1065 EXPECT_TRUE(infobar == NULL); |
| 1074 } | 1066 } |
| 1075 | 1067 |
| 1076 // Tests the "Never translate <language>" pref. | 1068 // Tests the "Never translate <language>" pref. |
| 1077 TEST_F(TranslateManagerBrowserTest, NeverTranslateLanguagePref) { | 1069 TEST_F(TranslateManagerRenderViewHostTest, NeverTranslateLanguagePref) { |
| 1078 GURL url("http://www.google.fr"); | 1070 GURL url("http://www.google.fr"); |
| 1079 SimulateNavigation(url, "fr", true); | 1071 SimulateNavigation(url, "fr", true); |
| 1080 | 1072 |
| 1081 // An infobar should be shown. | 1073 // An infobar should be shown. |
| 1082 EXPECT_TRUE(GetTranslateInfoBar() != NULL); | 1074 EXPECT_TRUE(GetTranslateInfoBar() != NULL); |
| 1083 | 1075 |
| 1084 // Select never translate this language. | 1076 // Select never translate this language. |
| 1085 Profile* profile = | 1077 Profile* profile = |
| 1086 Profile::FromBrowserContext(web_contents()->GetBrowserContext()); | 1078 Profile::FromBrowserContext(web_contents()->GetBrowserContext()); |
| 1087 PrefService* prefs = profile->GetPrefs(); | 1079 PrefService* prefs = profile->GetPrefs(); |
| 1088 PrefChangeRegistrar registrar; | 1080 PrefChangeRegistrar registrar; |
| 1089 registrar.Init(prefs); | 1081 registrar.Init(prefs); |
| 1090 registrar.Add(TranslatePrefs::kPrefTranslateBlockedLanguages, | 1082 registrar.Add(TranslatePrefs::kPrefTranslateBlockedLanguages, pref_callback_); |
| 1091 pref_callback_); | |
| 1092 scoped_ptr<TranslatePrefs> translate_prefs( | 1083 scoped_ptr<TranslatePrefs> translate_prefs( |
| 1093 TranslateTabHelper::CreateTranslatePrefs(prefs)); | 1084 TranslateTabHelper::CreateTranslatePrefs(prefs)); |
| 1094 EXPECT_FALSE(translate_prefs->IsBlockedLanguage("fr")); | 1085 EXPECT_FALSE(translate_prefs->IsBlockedLanguage("fr")); |
| 1095 TranslateAcceptLanguages* accept_languages = | 1086 TranslateAcceptLanguages* accept_languages = |
| 1096 TranslateTabHelper::GetTranslateAcceptLanguages(profile); | 1087 TranslateTabHelper::GetTranslateAcceptLanguages(profile); |
| 1097 EXPECT_TRUE(translate_prefs->CanTranslateLanguage(accept_languages, "fr")); | 1088 EXPECT_TRUE(translate_prefs->CanTranslateLanguage(accept_languages, "fr")); |
| 1098 SetPrefObserverExpectation(TranslatePrefs::kPrefTranslateBlockedLanguages); | 1089 SetPrefObserverExpectation(TranslatePrefs::kPrefTranslateBlockedLanguages); |
| 1099 translate_prefs->BlockLanguage("fr"); | 1090 translate_prefs->BlockLanguage("fr"); |
| 1100 EXPECT_TRUE(translate_prefs->IsBlockedLanguage("fr")); | 1091 EXPECT_TRUE(translate_prefs->IsBlockedLanguage("fr")); |
| 1101 EXPECT_FALSE(translate_prefs->IsSiteBlacklisted(url.host())); | 1092 EXPECT_FALSE(translate_prefs->IsSiteBlacklisted(url.host())); |
| (...skipping 15 matching lines...) Expand all Loading... | |
| 1117 EXPECT_TRUE(translate_prefs->CanTranslateLanguage(accept_languages, "fr")); | 1108 EXPECT_TRUE(translate_prefs->CanTranslateLanguage(accept_languages, "fr")); |
| 1118 | 1109 |
| 1119 // Navigate to a page in French. | 1110 // Navigate to a page in French. |
| 1120 SimulateNavigation(url, "fr", true); | 1111 SimulateNavigation(url, "fr", true); |
| 1121 | 1112 |
| 1122 // There should be a translate infobar. | 1113 // There should be a translate infobar. |
| 1123 EXPECT_TRUE(GetTranslateInfoBar() != NULL); | 1114 EXPECT_TRUE(GetTranslateInfoBar() != NULL); |
| 1124 } | 1115 } |
| 1125 | 1116 |
| 1126 // Tests the "Never translate this site" pref. | 1117 // Tests the "Never translate this site" pref. |
| 1127 TEST_F(TranslateManagerBrowserTest, NeverTranslateSitePref) { | 1118 TEST_F(TranslateManagerRenderViewHostTest, NeverTranslateSitePref) { |
| 1128 GURL url("http://www.google.fr"); | 1119 GURL url("http://www.google.fr"); |
| 1129 std::string host(url.host()); | 1120 std::string host(url.host()); |
| 1130 SimulateNavigation(url, "fr", true); | 1121 SimulateNavigation(url, "fr", true); |
| 1131 | 1122 |
| 1132 // An infobar should be shown. | 1123 // An infobar should be shown. |
| 1133 EXPECT_TRUE(GetTranslateInfoBar() != NULL); | 1124 EXPECT_TRUE(GetTranslateInfoBar() != NULL); |
| 1134 | 1125 |
| 1135 // Select never translate this site. | 1126 // Select never translate this site. |
| 1136 Profile* profile = | 1127 Profile* profile = |
| 1137 Profile::FromBrowserContext(web_contents()->GetBrowserContext()); | 1128 Profile::FromBrowserContext(web_contents()->GetBrowserContext()); |
| (...skipping 27 matching lines...) Expand all Loading... | |
| 1165 EXPECT_TRUE(translate_prefs->CanTranslateLanguage(accept_languages, "fr")); | 1156 EXPECT_TRUE(translate_prefs->CanTranslateLanguage(accept_languages, "fr")); |
| 1166 | 1157 |
| 1167 // Navigate to a page in French. | 1158 // Navigate to a page in French. |
| 1168 SimulateNavigation(url, "fr", true); | 1159 SimulateNavigation(url, "fr", true); |
| 1169 | 1160 |
| 1170 // There should be a translate infobar. | 1161 // There should be a translate infobar. |
| 1171 EXPECT_TRUE(GetTranslateInfoBar() != NULL); | 1162 EXPECT_TRUE(GetTranslateInfoBar() != NULL); |
| 1172 } | 1163 } |
| 1173 | 1164 |
| 1174 // Tests the "Always translate this language" pref. | 1165 // Tests the "Always translate this language" pref. |
| 1175 TEST_F(TranslateManagerBrowserTest, AlwaysTranslateLanguagePref) { | 1166 TEST_F(TranslateManagerRenderViewHostTest, AlwaysTranslateLanguagePref) { |
| 1176 // Select always translate French to English. | 1167 // Select always translate French to English. |
| 1177 Profile* profile = | 1168 Profile* profile = |
| 1178 Profile::FromBrowserContext(web_contents()->GetBrowserContext()); | 1169 Profile::FromBrowserContext(web_contents()->GetBrowserContext()); |
| 1179 PrefService* prefs = profile->GetPrefs(); | 1170 PrefService* prefs = profile->GetPrefs(); |
| 1180 PrefChangeRegistrar registrar; | 1171 PrefChangeRegistrar registrar; |
| 1181 registrar.Init(prefs); | 1172 registrar.Init(prefs); |
| 1182 registrar.Add(TranslatePrefs::kPrefTranslateWhitelists, pref_callback_); | 1173 registrar.Add(TranslatePrefs::kPrefTranslateWhitelists, pref_callback_); |
| 1183 scoped_ptr<TranslatePrefs> translate_prefs( | 1174 scoped_ptr<TranslatePrefs> translate_prefs( |
| 1184 TranslateTabHelper::CreateTranslatePrefs(prefs)); | 1175 TranslateTabHelper::CreateTranslatePrefs(prefs)); |
| 1185 SetPrefObserverExpectation(TranslatePrefs::kPrefTranslateWhitelists); | 1176 SetPrefObserverExpectation(TranslatePrefs::kPrefTranslateWhitelists); |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1224 SetPrefObserverExpectation(TranslatePrefs::kPrefTranslateWhitelists); | 1215 SetPrefObserverExpectation(TranslatePrefs::kPrefTranslateWhitelists); |
| 1225 translate_prefs->RemoveLanguagePairFromWhitelist("fr", "en"); | 1216 translate_prefs->RemoveLanguagePairFromWhitelist("fr", "en"); |
| 1226 SimulateNavigation(GURL("http://www.google.fr"), "fr", true); | 1217 SimulateNavigation(GURL("http://www.google.fr"), "fr", true); |
| 1227 EXPECT_FALSE(GetTranslateMessage(&page_id, &original_lang, &target_lang)); | 1218 EXPECT_FALSE(GetTranslateMessage(&page_id, &original_lang, &target_lang)); |
| 1228 infobar = GetTranslateInfoBar(); | 1219 infobar = GetTranslateInfoBar(); |
| 1229 ASSERT_TRUE(infobar != NULL); | 1220 ASSERT_TRUE(infobar != NULL); |
| 1230 EXPECT_EQ(TranslateTabHelper::BEFORE_TRANSLATE, infobar->translate_step()); | 1221 EXPECT_EQ(TranslateTabHelper::BEFORE_TRANSLATE, infobar->translate_step()); |
| 1231 } | 1222 } |
| 1232 | 1223 |
| 1233 // Context menu. | 1224 // Context menu. |
| 1234 TEST_F(TranslateManagerBrowserTest, ContextMenu) { | 1225 TEST_F(TranslateManagerRenderViewHostTest, ContextMenu) { |
| 1235 // Blacklist www.google.fr and French for translation. | 1226 // Blacklist www.google.fr and French for translation. |
| 1236 GURL url("http://www.google.fr"); | 1227 GURL url("http://www.google.fr"); |
| 1237 Profile* profile = | 1228 Profile* profile = |
| 1238 Profile::FromBrowserContext(web_contents()->GetBrowserContext()); | 1229 Profile::FromBrowserContext(web_contents()->GetBrowserContext()); |
| 1239 scoped_ptr<TranslatePrefs> translate_prefs( | 1230 scoped_ptr<TranslatePrefs> translate_prefs( |
| 1240 TranslateTabHelper::CreateTranslatePrefs(profile->GetPrefs())); | 1231 TranslateTabHelper::CreateTranslatePrefs(profile->GetPrefs())); |
| 1241 translate_prefs->BlockLanguage("fr"); | 1232 translate_prefs->BlockLanguage("fr"); |
| 1242 translate_prefs->BlacklistSite(url.host()); | 1233 translate_prefs->BlacklistSite(url.host()); |
| 1243 EXPECT_TRUE(translate_prefs->IsBlockedLanguage("fr")); | 1234 EXPECT_TRUE(translate_prefs->IsBlockedLanguage("fr")); |
| 1244 EXPECT_TRUE(translate_prefs->IsSiteBlacklisted(url.host())); | 1235 EXPECT_TRUE(translate_prefs->IsSiteBlacklisted(url.host())); |
| (...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1333 SimulateNavigation(url, "qbz", true); | 1324 SimulateNavigation(url, "qbz", true); |
| 1334 menu.reset(TestRenderViewContextMenu::CreateContextMenu(web_contents())); | 1325 menu.reset(TestRenderViewContextMenu::CreateContextMenu(web_contents())); |
| 1335 menu->Init(); | 1326 menu->Init(); |
| 1336 EXPECT_TRUE(menu->IsItemPresent(IDC_CONTENT_CONTEXT_TRANSLATE)); | 1327 EXPECT_TRUE(menu->IsItemPresent(IDC_CONTENT_CONTEXT_TRANSLATE)); |
| 1337 EXPECT_TRUE(menu->IsCommandIdEnabled(IDC_CONTENT_CONTEXT_TRANSLATE)); | 1328 EXPECT_TRUE(menu->IsCommandIdEnabled(IDC_CONTENT_CONTEXT_TRANSLATE)); |
| 1338 } | 1329 } |
| 1339 | 1330 |
| 1340 // Tests that an extra always/never translate button is shown on the "before | 1331 // Tests that an extra always/never translate button is shown on the "before |
| 1341 // translate" infobar when the translation is accepted/declined 3 times, | 1332 // translate" infobar when the translation is accepted/declined 3 times, |
| 1342 // only when not in incognito mode. | 1333 // only when not in incognito mode. |
| 1343 TEST_F(TranslateManagerBrowserTest, BeforeTranslateExtraButtons) { | 1334 TEST_F(TranslateManagerRenderViewHostTest, BeforeTranslateExtraButtons) { |
| 1344 Profile* profile = | 1335 Profile* profile = |
| 1345 Profile::FromBrowserContext(web_contents()->GetBrowserContext()); | 1336 Profile::FromBrowserContext(web_contents()->GetBrowserContext()); |
| 1346 scoped_ptr<TranslatePrefs> translate_prefs( | 1337 scoped_ptr<TranslatePrefs> translate_prefs( |
| 1347 TranslateTabHelper::CreateTranslatePrefs(profile->GetPrefs())); | 1338 TranslateTabHelper::CreateTranslatePrefs(profile->GetPrefs())); |
| 1348 translate_prefs->ResetTranslationAcceptedCount("fr"); | 1339 translate_prefs->ResetTranslationAcceptedCount("fr"); |
| 1349 translate_prefs->ResetTranslationDeniedCount("fr"); | 1340 translate_prefs->ResetTranslationDeniedCount("fr"); |
| 1350 translate_prefs->ResetTranslationAcceptedCount("de"); | 1341 translate_prefs->ResetTranslationAcceptedCount("de"); |
| 1351 translate_prefs->ResetTranslationDeniedCount("de"); | 1342 translate_prefs->ResetTranslationDeniedCount("de"); |
| 1352 | 1343 |
| 1353 // We'll do 4 times in incognito mode first to make sure the button is not | 1344 // We'll do 4 times in incognito mode first to make sure the button is not |
| 1354 // shown in that case, then 4 times in normal mode. | 1345 // shown in that case, then 4 times in normal mode. |
| 1355 TranslateInfoBarDelegate* infobar; | 1346 TranslateInfoBarDelegate* infobar; |
| 1356 TestingProfile* test_profile = | 1347 TestingProfile* test_profile = |
| 1357 static_cast<TestingProfile*>(web_contents()->GetBrowserContext()); | 1348 static_cast<TestingProfile*>(web_contents()->GetBrowserContext()); |
| 1358 static_cast<extensions::TestExtensionSystem*>( | 1349 static_cast<extensions::TestExtensionSystem*>( |
| 1359 extensions::ExtensionSystem::Get(test_profile))-> | 1350 extensions::ExtensionSystem::Get(test_profile))->CreateProcessManager(); |
| 1360 CreateProcessManager(); | |
| 1361 test_profile->ForceIncognito(true); | 1351 test_profile->ForceIncognito(true); |
| 1362 for (int i = 0; i < 8; ++i) { | 1352 for (int i = 0; i < 8; ++i) { |
| 1363 SCOPED_TRACE(::testing::Message() << "Iteration " << i << | 1353 SCOPED_TRACE(::testing::Message() << "Iteration " << i << " incognito mode=" |
| 1364 " incognito mode=" << test_profile->IsOffTheRecord()); | 1354 << test_profile->IsOffTheRecord()); |
| 1365 SimulateNavigation(GURL("http://www.google.fr"), "fr", true); | 1355 SimulateNavigation(GURL("http://www.google.fr"), "fr", true); |
| 1366 infobar = GetTranslateInfoBar(); | 1356 infobar = GetTranslateInfoBar(); |
| 1367 ASSERT_TRUE(infobar != NULL); | 1357 ASSERT_TRUE(infobar != NULL); |
| 1368 EXPECT_EQ(TranslateTabHelper::BEFORE_TRANSLATE, infobar->translate_step()); | 1358 EXPECT_EQ(TranslateTabHelper::BEFORE_TRANSLATE, infobar->translate_step()); |
| 1369 if (i < 7) { | 1359 if (i < 7) { |
| 1370 EXPECT_FALSE(infobar->ShouldShowAlwaysTranslateShortcut()); | 1360 EXPECT_FALSE(infobar->ShouldShowAlwaysTranslateShortcut()); |
| 1371 infobar->Translate(); | 1361 infobar->Translate(); |
| 1372 process()->sink().ClearMessages(); | 1362 process()->sink().ClearMessages(); |
| 1373 } else { | 1363 } else { |
| 1374 EXPECT_TRUE(infobar->ShouldShowAlwaysTranslateShortcut()); | 1364 EXPECT_TRUE(infobar->ShouldShowAlwaysTranslateShortcut()); |
| (...skipping 10 matching lines...) Expand all Loading... | |
| 1385 // That should have triggered a page translate. | 1375 // That should have triggered a page translate. |
| 1386 int page_id = 0; | 1376 int page_id = 0; |
| 1387 std::string original_lang, target_lang; | 1377 std::string original_lang, target_lang; |
| 1388 EXPECT_TRUE(GetTranslateMessage(&page_id, &original_lang, &target_lang)); | 1378 EXPECT_TRUE(GetTranslateMessage(&page_id, &original_lang, &target_lang)); |
| 1389 process()->sink().ClearMessages(); | 1379 process()->sink().ClearMessages(); |
| 1390 | 1380 |
| 1391 // Now test that declining the translation causes a "never translate" button | 1381 // Now test that declining the translation causes a "never translate" button |
| 1392 // to be shown (in non incognito mode only). | 1382 // to be shown (in non incognito mode only). |
| 1393 test_profile->ForceIncognito(true); | 1383 test_profile->ForceIncognito(true); |
| 1394 for (int i = 0; i < 8; ++i) { | 1384 for (int i = 0; i < 8; ++i) { |
| 1395 SCOPED_TRACE(::testing::Message() << "Iteration " << i << | 1385 SCOPED_TRACE(::testing::Message() << "Iteration " << i << " incognito mode=" |
| 1396 " incognito mode=" << test_profile->IsOffTheRecord()); | 1386 << test_profile->IsOffTheRecord()); |
| 1397 SimulateNavigation(GURL("http://www.google.de"), "de", true); | 1387 SimulateNavigation(GURL("http://www.google.de"), "de", true); |
| 1398 infobar = GetTranslateInfoBar(); | 1388 infobar = GetTranslateInfoBar(); |
| 1399 ASSERT_TRUE(infobar != NULL); | 1389 ASSERT_TRUE(infobar != NULL); |
| 1400 EXPECT_EQ(TranslateTabHelper::BEFORE_TRANSLATE, infobar->translate_step()); | 1390 EXPECT_EQ(TranslateTabHelper::BEFORE_TRANSLATE, infobar->translate_step()); |
| 1401 if (i < 7) { | 1391 if (i < 7) { |
| 1402 EXPECT_FALSE(infobar->ShouldShowNeverTranslateShortcut()); | 1392 EXPECT_FALSE(infobar->ShouldShowNeverTranslateShortcut()); |
| 1403 infobar->TranslationDeclined(); | 1393 infobar->TranslationDeclined(); |
| 1404 } else { | 1394 } else { |
| 1405 EXPECT_TRUE(infobar->ShouldShowNeverTranslateShortcut()); | 1395 EXPECT_TRUE(infobar->ShouldShowNeverTranslateShortcut()); |
| 1406 } | 1396 } |
| 1407 if (i == 3) | 1397 if (i == 3) |
| 1408 test_profile->ForceIncognito(false); | 1398 test_profile->ForceIncognito(false); |
| 1409 } | 1399 } |
| 1410 // Simulate the user pressing "Never translate French". | 1400 // Simulate the user pressing "Never translate French". |
| 1411 infobar->NeverTranslatePageLanguage(); | 1401 infobar->NeverTranslatePageLanguage(); |
| 1412 EXPECT_TRUE(translate_prefs->IsBlockedLanguage("de")); | 1402 EXPECT_TRUE(translate_prefs->IsBlockedLanguage("de")); |
| 1413 // No translation should have occured and the infobar should be gone. | 1403 // No translation should have occured and the infobar should be gone. |
| 1414 EXPECT_FALSE(GetTranslateMessage(&page_id, &original_lang, &target_lang)); | 1404 EXPECT_FALSE(GetTranslateMessage(&page_id, &original_lang, &target_lang)); |
| 1415 process()->sink().ClearMessages(); | 1405 process()->sink().ClearMessages(); |
| 1416 ASSERT_TRUE(GetTranslateInfoBar() == NULL); | 1406 ASSERT_TRUE(GetTranslateInfoBar() == NULL); |
| 1417 } | 1407 } |
| 1418 | 1408 |
| 1419 // Tests that we don't show a translate infobar when a page instructs that it | 1409 // Tests that we don't show a translate infobar when a page instructs that it |
| 1420 // should not be translated. | 1410 // should not be translated. |
| 1421 TEST_F(TranslateManagerBrowserTest, NonTranslatablePage) { | 1411 TEST_F(TranslateManagerRenderViewHostTest, NonTranslatablePage) { |
| 1422 SimulateNavigation(GURL("http://mail.google.fr"), "fr", false); | 1412 SimulateNavigation(GURL("http://mail.google.fr"), "fr", false); |
| 1423 | 1413 |
| 1424 // We should not have an infobar. | 1414 // We should not have an infobar. |
| 1425 EXPECT_TRUE(GetTranslateInfoBar() == NULL); | 1415 EXPECT_TRUE(GetTranslateInfoBar() == NULL); |
| 1426 | 1416 |
| 1427 // The context menu is enabled to allow users to force translation. | 1417 // The context menu is enabled to allow users to force translation. |
| 1428 scoped_ptr<TestRenderViewContextMenu> menu( | 1418 scoped_ptr<TestRenderViewContextMenu> menu( |
| 1429 TestRenderViewContextMenu::CreateContextMenu(web_contents())); | 1419 TestRenderViewContextMenu::CreateContextMenu(web_contents())); |
| 1430 menu->Init(); | 1420 menu->Init(); |
| 1431 EXPECT_TRUE(menu->IsItemPresent(IDC_CONTENT_CONTEXT_TRANSLATE)); | 1421 EXPECT_TRUE(menu->IsItemPresent(IDC_CONTENT_CONTEXT_TRANSLATE)); |
| 1432 EXPECT_TRUE(menu->IsCommandIdEnabled(IDC_CONTENT_CONTEXT_TRANSLATE)); | 1422 EXPECT_TRUE(menu->IsCommandIdEnabled(IDC_CONTENT_CONTEXT_TRANSLATE)); |
| 1433 } | 1423 } |
| 1434 | 1424 |
| 1435 // Tests that the script is expired and refetched as expected. | 1425 // Tests that the script is expired and refetched as expected. |
| 1436 TEST_F(TranslateManagerBrowserTest, ScriptExpires) { | 1426 TEST_F(TranslateManagerRenderViewHostTest, ScriptExpires) { |
| 1437 ExpireTranslateScriptImmediately(); | 1427 ExpireTranslateScriptImmediately(); |
| 1438 | 1428 |
| 1439 SimulateNavigation(GURL("http://www.google.fr"), "fr", true); | 1429 SimulateNavigation(GURL("http://www.google.fr"), "fr", true); |
| 1440 TranslateInfoBarDelegate* infobar = GetTranslateInfoBar(); | 1430 TranslateInfoBarDelegate* infobar = GetTranslateInfoBar(); |
| 1441 ASSERT_TRUE(infobar != NULL); | 1431 ASSERT_TRUE(infobar != NULL); |
| 1442 process()->sink().ClearMessages(); | 1432 process()->sink().ClearMessages(); |
| 1443 infobar->Translate(); | 1433 infobar->Translate(); |
| 1444 SimulateTranslateScriptURLFetch(true); | 1434 SimulateTranslateScriptURLFetch(true); |
| 1445 SimulateOnPageTranslated("fr", "en"); | 1435 SimulateOnPageTranslated("fr", "en"); |
| 1446 | 1436 |
| 1447 // A task should have been posted to clear the script, run it. | 1437 // A task should have been posted to clear the script, run it. |
| 1448 base::MessageLoop::current()->RunUntilIdle(); | 1438 base::MessageLoop::current()->RunUntilIdle(); |
| 1449 | 1439 |
| 1450 // Do another navigation and translation. | 1440 // Do another navigation and translation. |
| 1451 SimulateNavigation(GURL("http://www.google.es"), "es", true); | 1441 SimulateNavigation(GURL("http://www.google.es"), "es", true); |
| 1452 infobar = GetTranslateInfoBar(); | 1442 infobar = GetTranslateInfoBar(); |
| 1453 ASSERT_TRUE(infobar != NULL); | 1443 ASSERT_TRUE(infobar != NULL); |
| 1454 process()->sink().ClearMessages(); | 1444 process()->sink().ClearMessages(); |
| 1455 infobar->Translate(); | 1445 infobar->Translate(); |
| 1456 // If we don't simulate the URL fetch, the TranslateManager should be waiting | 1446 // If we don't simulate the URL fetch, the TranslateManager should be waiting |
| 1457 // for the script and no message should have been sent to the renderer. | 1447 // for the script and no message should have been sent to the renderer. |
| 1458 EXPECT_TRUE( | 1448 EXPECT_TRUE(process()->sink().GetFirstMessageMatching( |
| 1459 process()->sink().GetFirstMessageMatching( | 1449 ChromeViewMsg_TranslatePage::ID) == NULL); |
| 1460 ChromeViewMsg_TranslatePage::ID) == NULL); | |
| 1461 // Now simulate the URL fetch. | 1450 // Now simulate the URL fetch. |
| 1462 SimulateTranslateScriptURLFetch(true); | 1451 SimulateTranslateScriptURLFetch(true); |
| 1463 // Now the message should have been sent. | 1452 // Now the message should have been sent. |
| 1464 int page_id = 0; | 1453 int page_id = 0; |
| 1465 std::string original_lang, target_lang; | 1454 std::string original_lang, target_lang; |
| 1466 EXPECT_TRUE(GetTranslateMessage(&page_id, &original_lang, &target_lang)); | 1455 EXPECT_TRUE(GetTranslateMessage(&page_id, &original_lang, &target_lang)); |
| 1467 EXPECT_EQ("es", original_lang); | 1456 EXPECT_EQ("es", original_lang); |
| 1468 EXPECT_EQ("en", target_lang); | 1457 EXPECT_EQ("en", target_lang); |
| 1469 } | 1458 } |
| 1470 | 1459 |
| 1471 TEST_F(TranslateManagerBrowserTest, DownloadsAndHistoryNotTranslated) { | 1460 TEST_F(TranslateManagerRenderViewHostTest, DownloadsAndHistoryNotTranslated) { |
| 1472 ASSERT_FALSE(TranslateManager::IsTranslatableURL( | 1461 ASSERT_FALSE( |
| 1473 GURL(chrome::kChromeUIDownloadsURL))); | 1462 TranslateManager::IsTranslatableURL(GURL(chrome::kChromeUIDownloadsURL))); |
| 1474 ASSERT_FALSE(TranslateManager::IsTranslatableURL( | 1463 ASSERT_FALSE( |
| 1475 GURL(chrome::kChromeUIHistoryURL))); | 1464 TranslateManager::IsTranslatableURL(GURL(chrome::kChromeUIHistoryURL))); |
| 1476 } | 1465 } |
| 1477 | 1466 |
| 1478 #if defined(USE_AURA) | 1467 #if defined(USE_AURA) |
| 1479 | 1468 |
| 1480 TEST_F(TranslateManagerBrowserTest, BubbleNormalTranslate) { | 1469 TEST_F(TranslateManagerRenderViewHostTest, BubbleNormalTranslate) { |
| 1481 // Prepare for the bubble | 1470 // Prepare for the bubble |
| 1482 TranslateService::SetUseInfobar(false); | 1471 TranslateService::SetUseInfobar(false); |
| 1483 MockTranslateBubbleFactory* factory = new MockTranslateBubbleFactory; | 1472 MockTranslateBubbleFactory* factory = new MockTranslateBubbleFactory; |
| 1484 scoped_ptr<TranslateBubbleFactory> factory_ptr(factory); | 1473 scoped_ptr<TranslateBubbleFactory> factory_ptr(factory); |
| 1485 TranslateBubbleFactory::SetFactory(factory); | 1474 TranslateBubbleFactory::SetFactory(factory); |
| 1486 | 1475 |
| 1487 SimulateNavigation(GURL("http://www.google.fr"), "fr", true); | 1476 SimulateNavigation(GURL("http://www.google.fr"), "fr", true); |
| 1488 | 1477 |
| 1489 // Check the bubble exists instead of the infobar. | 1478 // Check the bubble exists instead of the infobar. |
| 1490 TranslateInfoBarDelegate* infobar = GetTranslateInfoBar(); | 1479 TranslateInfoBarDelegate* infobar = GetTranslateInfoBar(); |
| (...skipping 20 matching lines...) Expand all Loading... | |
| 1511 // Simulate the render notifying the translation has been done. | 1500 // Simulate the render notifying the translation has been done. |
| 1512 SimulateOnPageTranslated("fr", "en"); | 1501 SimulateOnPageTranslated("fr", "en"); |
| 1513 | 1502 |
| 1514 // Check the bubble shows "Translated." | 1503 // Check the bubble shows "Translated." |
| 1515 bubble = factory->model(); | 1504 bubble = factory->model(); |
| 1516 ASSERT_TRUE(bubble != NULL); | 1505 ASSERT_TRUE(bubble != NULL); |
| 1517 EXPECT_EQ(TranslateBubbleModel::VIEW_STATE_AFTER_TRANSLATE, | 1506 EXPECT_EQ(TranslateBubbleModel::VIEW_STATE_AFTER_TRANSLATE, |
| 1518 bubble->GetViewState()); | 1507 bubble->GetViewState()); |
| 1519 } | 1508 } |
| 1520 | 1509 |
| 1521 TEST_F(TranslateManagerBrowserTest, BubbleTranslateScriptNotAvailable) { | 1510 TEST_F(TranslateManagerRenderViewHostTest, BubbleTranslateScriptNotAvailable) { |
| 1522 // Prepare for the bubble | 1511 // Prepare for the bubble |
| 1523 TranslateService::SetUseInfobar(false); | 1512 TranslateService::SetUseInfobar(false); |
| 1524 MockTranslateBubbleFactory* factory = new MockTranslateBubbleFactory; | 1513 MockTranslateBubbleFactory* factory = new MockTranslateBubbleFactory; |
| 1525 scoped_ptr<TranslateBubbleFactory> factory_ptr(factory); | 1514 scoped_ptr<TranslateBubbleFactory> factory_ptr(factory); |
| 1526 TranslateBubbleFactory::SetFactory(factory); | 1515 TranslateBubbleFactory::SetFactory(factory); |
| 1527 | 1516 |
| 1528 SimulateNavigation(GURL("http://www.google.fr"), "fr", true); | 1517 SimulateNavigation(GURL("http://www.google.fr"), "fr", true); |
| 1529 | 1518 |
| 1530 // Check the bubble exists instead of the infobar. | 1519 // Check the bubble exists instead of the infobar. |
| 1531 TranslateInfoBarDelegate* infobar = GetTranslateInfoBar(); | 1520 TranslateInfoBarDelegate* infobar = GetTranslateInfoBar(); |
| 1532 ASSERT_TRUE(infobar == NULL); | 1521 ASSERT_TRUE(infobar == NULL); |
| 1533 TranslateBubbleModel* bubble = factory->model(); | 1522 TranslateBubbleModel* bubble = factory->model(); |
| 1534 ASSERT_TRUE(bubble != NULL); | 1523 ASSERT_TRUE(bubble != NULL); |
| 1535 EXPECT_EQ(TranslateBubbleModel::VIEW_STATE_BEFORE_TRANSLATE, | 1524 EXPECT_EQ(TranslateBubbleModel::VIEW_STATE_BEFORE_TRANSLATE, |
| 1536 bubble->GetViewState()); | 1525 bubble->GetViewState()); |
| 1537 | 1526 |
| 1538 // Simulate clicking translate. | 1527 // Simulate clicking translate. |
| 1539 process()->sink().ClearMessages(); | 1528 process()->sink().ClearMessages(); |
| 1540 bubble->Translate(); | 1529 bubble->Translate(); |
| 1541 SimulateTranslateScriptURLFetch(false); | 1530 SimulateTranslateScriptURLFetch(false); |
| 1542 | 1531 |
| 1543 // We should not have sent any message to translate to the renderer. | 1532 // We should not have sent any message to translate to the renderer. |
| 1544 EXPECT_FALSE(GetTranslateMessage(NULL, NULL, NULL)); | 1533 EXPECT_FALSE(GetTranslateMessage(NULL, NULL, NULL)); |
| 1545 | 1534 |
| 1546 // And we should have an error infobar showing. | 1535 // And we should have an error infobar showing. |
| 1547 bubble = factory->model(); | 1536 bubble = factory->model(); |
| 1548 ASSERT_TRUE(bubble != NULL); | 1537 ASSERT_TRUE(bubble != NULL); |
| 1549 EXPECT_EQ(TranslateBubbleModel::VIEW_STATE_ERROR, | 1538 EXPECT_EQ(TranslateBubbleModel::VIEW_STATE_ERROR, bubble->GetViewState()); |
| 1550 bubble->GetViewState()); | |
| 1551 } | 1539 } |
| 1552 | 1540 |
| 1553 TEST_F(TranslateManagerBrowserTest, BubbleUnknownLanguage) { | 1541 TEST_F(TranslateManagerRenderViewHostTest, BubbleUnknownLanguage) { |
| 1554 // Prepare for the bubble | 1542 // Prepare for the bubble |
| 1555 TranslateService::SetUseInfobar(false); | 1543 TranslateService::SetUseInfobar(false); |
| 1556 MockTranslateBubbleFactory* factory = new MockTranslateBubbleFactory; | 1544 MockTranslateBubbleFactory* factory = new MockTranslateBubbleFactory; |
| 1557 scoped_ptr<TranslateBubbleFactory> factory_ptr(factory); | 1545 scoped_ptr<TranslateBubbleFactory> factory_ptr(factory); |
| 1558 TranslateBubbleFactory::SetFactory(factory); | 1546 TranslateBubbleFactory::SetFactory(factory); |
| 1559 | 1547 |
| 1560 // Simulate navigating to a page ("und" is the string returned by the CLD for | 1548 // Simulate navigating to a page ("und" is the string returned by the CLD for |
| 1561 // languages it does not recognize). | 1549 // languages it does not recognize). |
| 1562 SimulateNavigation(GURL("http://www.google.mys"), "und", true); | 1550 SimulateNavigation(GURL("http://www.google.mys"), "und", true); |
| 1563 | 1551 |
| 1564 // We should not have a bubble as we don't know the language. | 1552 // We should not have a bubble as we don't know the language. |
| 1565 ASSERT_TRUE(factory->model() == NULL); | 1553 ASSERT_TRUE(factory->model() == NULL); |
| 1566 | 1554 |
| 1567 // Translate the page anyway throught the context menu. | 1555 // Translate the page anyway throught the context menu. |
| 1568 scoped_ptr<TestRenderViewContextMenu> menu( | 1556 scoped_ptr<TestRenderViewContextMenu> menu( |
| 1569 TestRenderViewContextMenu::CreateContextMenu(web_contents())); | 1557 TestRenderViewContextMenu::CreateContextMenu(web_contents())); |
| 1570 menu->Init(); | 1558 menu->Init(); |
| 1571 menu->ExecuteCommand(IDC_CONTENT_CONTEXT_TRANSLATE, 0); | 1559 menu->ExecuteCommand(IDC_CONTENT_CONTEXT_TRANSLATE, 0); |
| 1572 | 1560 |
| 1573 // Check the bubble exists instead of the infobar. | 1561 // Check the bubble exists instead of the infobar. |
| 1574 TranslateInfoBarDelegate* infobar = GetTranslateInfoBar(); | 1562 TranslateInfoBarDelegate* infobar = GetTranslateInfoBar(); |
| 1575 ASSERT_TRUE(infobar == NULL); | 1563 ASSERT_TRUE(infobar == NULL); |
| 1576 TranslateBubbleModel* bubble = factory->model(); | 1564 TranslateBubbleModel* bubble = factory->model(); |
| 1577 ASSERT_TRUE(bubble != NULL); | 1565 ASSERT_TRUE(bubble != NULL); |
| 1578 EXPECT_EQ(TranslateBubbleModel::VIEW_STATE_TRANSLATING, | 1566 EXPECT_EQ(TranslateBubbleModel::VIEW_STATE_TRANSLATING, |
| 1579 bubble->GetViewState()); | 1567 bubble->GetViewState()); |
| 1580 } | 1568 } |
| 1581 | 1569 |
| 1582 #endif // defined(USE_AURA) | 1570 #endif // defined(USE_AURA) |
| 1583 | |
| 1584 // Test is flaky on Win http://crbug.com/166334 | |
| 1585 #if defined(OS_WIN) | |
| 1586 #define MAYBE_PRE_TranslateSessionRestore DISABLED_PRE_TranslateSessionRestore | |
| 1587 #else | |
| 1588 #define MAYBE_PRE_TranslateSessionRestore PRE_TranslateSessionRestore | |
| 1589 #endif | |
| 1590 // Test that session restore restores the translate infobar and other translate | |
| 1591 // settings. | |
| 1592 IN_PROC_BROWSER_TEST_F(InProcessBrowserTest, | |
| 1593 MAYBE_PRE_TranslateSessionRestore) { | |
| 1594 SessionStartupPref pref(SessionStartupPref::LAST); | |
| 1595 SessionStartupPref::SetStartupPref(browser()->profile(), pref); | |
| 1596 | |
| 1597 content::WebContents* current_web_contents = | |
| 1598 browser()->tab_strip_model()->GetActiveWebContents(); | |
| 1599 TranslateTabHelper* translate_tab_helper = | |
| 1600 TranslateTabHelper::FromWebContents(current_web_contents); | |
| 1601 content::Source<content::WebContents> source(current_web_contents); | |
| 1602 | |
| 1603 ui_test_utils::WindowedNotificationObserverWithDetails< | |
| 1604 LanguageDetectionDetails> | |
| 1605 fr_language_detected_signal(chrome::NOTIFICATION_TAB_LANGUAGE_DETERMINED, | |
| 1606 source); | |
| 1607 | |
| 1608 GURL french_url = ui_test_utils::GetTestUrl( | |
| 1609 base::FilePath(), base::FilePath(FILE_PATH_LITERAL("french_page.html"))); | |
| 1610 ui_test_utils::NavigateToURL(browser(), french_url); | |
| 1611 fr_language_detected_signal.Wait(); | |
| 1612 LanguageDetectionDetails details; | |
| 1613 EXPECT_TRUE(fr_language_detected_signal.GetDetailsFor( | |
| 1614 source.map_key(), &details)); | |
| 1615 EXPECT_EQ("fr", details.adopted_language); | |
| 1616 EXPECT_EQ("fr", translate_tab_helper->GetLanguageState().original_language()); | |
| 1617 } | |
| 1618 | |
| 1619 #if defined (OS_WIN) | |
| 1620 #define MAYBE_TranslateSessionRestore DISABLED_TranslateSessionRestore | |
| 1621 #else | |
| 1622 #define MAYBE_TranslateSessionRestore TranslateSessionRestore | |
| 1623 #endif | |
| 1624 IN_PROC_BROWSER_TEST_F(InProcessBrowserTest, MAYBE_TranslateSessionRestore) { | |
| 1625 content::WebContents* current_web_contents = | |
| 1626 browser()->tab_strip_model()->GetActiveWebContents(); | |
| 1627 content::Source<content::WebContents> source(current_web_contents); | |
| 1628 | |
| 1629 ui_test_utils::WindowedNotificationObserverWithDetails< | |
| 1630 LanguageDetectionDetails> | |
| 1631 fr_language_detected_signal(chrome::NOTIFICATION_TAB_LANGUAGE_DETERMINED, | |
| 1632 source); | |
| 1633 fr_language_detected_signal.Wait(); | |
| 1634 } | |
| OLD | NEW |