OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 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 <algorithm> | 5 #include <algorithm> |
6 #include <set> | 6 #include <set> |
7 #include <vector> | 7 #include <vector> |
8 | 8 |
9 #include "base/memory/scoped_ptr.h" | 9 #include "base/memory/scoped_ptr.h" |
10 #include "base/prefs/pref_change_registrar.h" | 10 #include "base/prefs/pref_change_registrar.h" |
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
96 bool page_translatable) { | 96 bool page_translatable) { |
97 if (rvh()->GetMainFrame()->GetLastCommittedURL() == url) | 97 if (rvh()->GetMainFrame()->GetLastCommittedURL() == url) |
98 Reload(); | 98 Reload(); |
99 else | 99 else |
100 NavigateAndCommit(url); | 100 NavigateAndCommit(url); |
101 SimulateOnTranslateLanguageDetermined(lang, page_translatable); | 101 SimulateOnTranslateLanguageDetermined(lang, page_translatable); |
102 } | 102 } |
103 | 103 |
104 void SimulateOnTranslateLanguageDetermined(const std::string& lang, | 104 void SimulateOnTranslateLanguageDetermined(const std::string& lang, |
105 bool page_translatable) { | 105 bool page_translatable) { |
106 LanguageDetectionDetails details; | 106 translate::LanguageDetectionDetails details; |
107 details.adopted_language = lang; | 107 details.adopted_language = lang; |
108 content::RenderViewHostTester::TestOnMessageReceived( | 108 content::RenderViewHostTester::TestOnMessageReceived( |
109 rvh(), | 109 rvh(), |
110 ChromeViewHostMsg_TranslateLanguageDetermined( | 110 ChromeViewHostMsg_TranslateLanguageDetermined( |
111 0, details, page_translatable)); | 111 0, details, page_translatable)); |
112 } | 112 } |
113 | 113 |
114 void SimulateOnPageTranslated(int routing_id, | 114 void SimulateOnPageTranslated(int routing_id, |
115 const std::string& source_lang, | 115 const std::string& source_lang, |
116 const std::string& target_lang, | 116 const std::string& target_lang, |
117 TranslateErrors::Type error) { | 117 translate::TranslateErrors::Type error) { |
118 content::RenderViewHostTester::TestOnMessageReceived( | 118 content::RenderViewHostTester::TestOnMessageReceived( |
119 rvh(), | 119 rvh(), |
120 ChromeViewHostMsg_PageTranslated( | 120 ChromeViewHostMsg_PageTranslated( |
121 routing_id, source_lang, target_lang, error)); | 121 routing_id, source_lang, target_lang, error)); |
122 } | 122 } |
123 | 123 |
124 void SimulateOnPageTranslated(const std::string& source_lang, | 124 void SimulateOnPageTranslated(const std::string& source_lang, |
125 const std::string& target_lang) { | 125 const std::string& target_lang) { |
126 SimulateOnPageTranslated( | 126 SimulateOnPageTranslated( |
127 0, source_lang, target_lang, TranslateErrors::NONE); | 127 0, source_lang, target_lang, translate::TranslateErrors::NONE); |
128 } | 128 } |
129 | 129 |
130 bool GetTranslateMessage(std::string* original_lang, | 130 bool GetTranslateMessage(std::string* original_lang, |
131 std::string* target_lang) { | 131 std::string* target_lang) { |
132 const IPC::Message* message = process()->sink().GetFirstMessageMatching( | 132 const IPC::Message* message = process()->sink().GetFirstMessageMatching( |
133 ChromeViewMsg_TranslatePage::ID); | 133 ChromeViewMsg_TranslatePage::ID); |
134 if (!message) | 134 if (!message) |
135 return false; | 135 return false; |
136 Tuple4<int, std::string, std::string, std::string> translate_param; | 136 Tuple4<int, std::string, std::string, std::string> translate_param; |
137 ChromeViewMsg_TranslatePage::Read(message, &translate_param); | 137 ChromeViewMsg_TranslatePage::Read(message, &translate_param); |
138 // Ignore translate_param.a which is the page seq no. | 138 // Ignore translate_param.a which is the page seq no. |
139 // Ignore translate_param.b which is the script injected in the page. | 139 // Ignore translate_param.b which is the script injected in the page. |
140 if (original_lang) | 140 if (original_lang) |
141 *original_lang = translate_param.c; | 141 *original_lang = translate_param.c; |
142 if (target_lang) | 142 if (target_lang) |
143 *target_lang = translate_param.d; | 143 *target_lang = translate_param.d; |
144 return true; | 144 return true; |
145 } | 145 } |
146 | 146 |
147 InfoBarService* infobar_service() { | 147 InfoBarService* infobar_service() { |
148 return InfoBarService::FromWebContents(web_contents()); | 148 return InfoBarService::FromWebContents(web_contents()); |
149 } | 149 } |
150 | 150 |
151 // Returns the translate infobar if there is 1 infobar and it is a translate | 151 // Returns the translate infobar if there is 1 infobar and it is a translate |
152 // infobar. | 152 // infobar. |
153 TranslateInfoBarDelegate* GetTranslateInfoBar() { | 153 translate::TranslateInfoBarDelegate* GetTranslateInfoBar() { |
154 return (infobar_service()->infobar_count() == 1) ? | 154 return (infobar_service()->infobar_count() == 1) ? |
155 infobar_service()->infobar_at(0)->delegate()-> | 155 infobar_service()->infobar_at(0)->delegate()-> |
156 AsTranslateInfoBarDelegate() : | 156 AsTranslateInfoBarDelegate() : |
157 NULL; | 157 NULL; |
158 } | 158 } |
159 | 159 |
160 // If there is 1 infobar and it is a translate infobar, closes it and returns | 160 // If there is 1 infobar and it is a translate infobar, closes it and returns |
161 // true. Returns false otherwise. | 161 // true. Returns false otherwise. |
162 bool CloseTranslateInfoBar() { | 162 bool CloseTranslateInfoBar() { |
163 infobars::InfoBarDelegate* infobar = GetTranslateInfoBar(); | 163 infobars::InfoBarDelegate* infobar = GetTranslateInfoBar(); |
164 if (!infobar) | 164 if (!infobar) |
165 return false; | 165 return false; |
166 infobar->InfoBarDismissed(); // Simulates closing the infobar. | 166 infobar->InfoBarDismissed(); // Simulates closing the infobar. |
167 infobar_service()->RemoveInfoBar(infobar_service()->infobar_at(0)); | 167 infobar_service()->RemoveInfoBar(infobar_service()->infobar_at(0)); |
168 return true; | 168 return true; |
169 } | 169 } |
170 | 170 |
171 // Checks whether |infobar| has been removed and clears the removed infobar | 171 // Checks whether |infobar| has been removed and clears the removed infobar |
172 // list. | 172 // list. |
173 bool CheckInfoBarRemovedAndReset(infobars::InfoBarDelegate* delegate) { | 173 bool CheckInfoBarRemovedAndReset(infobars::InfoBarDelegate* delegate) { |
174 bool found = removed_infobars_.count(delegate) != 0; | 174 bool found = removed_infobars_.count(delegate) != 0; |
175 removed_infobars_.clear(); | 175 removed_infobars_.clear(); |
176 return found; | 176 return found; |
177 } | 177 } |
178 | 178 |
179 void ExpireTranslateScriptImmediately() { | 179 void ExpireTranslateScriptImmediately() { |
180 TranslateDownloadManager::GetInstance()->SetTranslateScriptExpirationDelay( | 180 translate::TranslateDownloadManager::GetInstance() |
181 0); | 181 ->SetTranslateScriptExpirationDelay(0); |
182 } | 182 } |
183 | 183 |
184 // If there is 1 infobar and it is a translate infobar, deny translation and | 184 // If there is 1 infobar and it is a translate infobar, deny translation and |
185 // returns true. Returns false otherwise. | 185 // returns true. Returns false otherwise. |
186 bool DenyTranslation() { | 186 bool DenyTranslation() { |
187 TranslateInfoBarDelegate* infobar = GetTranslateInfoBar(); | 187 translate::TranslateInfoBarDelegate* infobar = GetTranslateInfoBar(); |
188 if (!infobar) | 188 if (!infobar) |
189 return false; | 189 return false; |
190 infobar->TranslationDeclined(); | 190 infobar->TranslationDeclined(); |
191 infobar_service()->RemoveInfoBar(infobar_service()->infobar_at(0)); | 191 infobar_service()->RemoveInfoBar(infobar_service()->infobar_at(0)); |
192 return true; | 192 return true; |
193 } | 193 } |
194 | 194 |
195 void ReloadAndWait(bool successful_reload) { | 195 void ReloadAndWait(bool successful_reload) { |
196 NavEntryCommittedObserver nav_observer(web_contents()); | 196 NavEntryCommittedObserver nav_observer(web_contents()); |
197 if (successful_reload) | 197 if (successful_reload) |
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
242 | 242 |
243 MOCK_METHOD1(OnPreferenceChanged, void(const std::string&)); | 243 MOCK_METHOD1(OnPreferenceChanged, void(const std::string&)); |
244 | 244 |
245 protected: | 245 protected: |
246 virtual void SetUp() { | 246 virtual void SetUp() { |
247 TranslateService::InitializeForTesting(); | 247 TranslateService::InitializeForTesting(); |
248 | 248 |
249 // Clears the translate script so it is fetched everytime and sets the | 249 // Clears the translate script so it is fetched everytime and sets the |
250 // expiration delay to a large value by default (in case it was zeroed in a | 250 // expiration delay to a large value by default (in case it was zeroed in a |
251 // previous test). | 251 // previous test). |
252 TranslateDownloadManager* download_manager = | 252 translate::TranslateDownloadManager* download_manager = |
253 TranslateDownloadManager::GetInstance(); | 253 translate::TranslateDownloadManager::GetInstance(); |
254 download_manager->ClearTranslateScriptForTesting(); | 254 download_manager->ClearTranslateScriptForTesting(); |
255 download_manager->SetTranslateScriptExpirationDelay(60 * 60 * 1000); | 255 download_manager->SetTranslateScriptExpirationDelay(60 * 60 * 1000); |
256 | 256 |
257 ChromeRenderViewHostTestHarness::SetUp(); | 257 ChromeRenderViewHostTestHarness::SetUp(); |
258 InfoBarService::CreateForWebContents(web_contents()); | 258 InfoBarService::CreateForWebContents(web_contents()); |
259 ChromeTranslateClient::CreateForWebContents(web_contents()); | 259 ChromeTranslateClient::CreateForWebContents(web_contents()); |
260 ChromeTranslateClient::FromWebContents(web_contents()) | 260 ChromeTranslateClient::FromWebContents(web_contents()) |
261 ->set_translate_max_reload_attempts(0); | 261 ->set_translate_max_reload_attempts(0); |
262 | 262 |
263 notification_registrar_.Add( | 263 notification_registrar_.Add( |
264 this, | 264 this, |
265 chrome::NOTIFICATION_TAB_CONTENTS_INFOBAR_REMOVED, | 265 chrome::NOTIFICATION_TAB_CONTENTS_INFOBAR_REMOVED, |
266 content::Source<InfoBarService>(infobar_service())); | 266 content::Source<InfoBarService>(infobar_service())); |
267 } | 267 } |
268 | 268 |
269 virtual void TearDown() { | 269 virtual void TearDown() { |
270 process()->sink().ClearMessages(); | 270 process()->sink().ClearMessages(); |
271 | 271 |
272 notification_registrar_.Remove( | 272 notification_registrar_.Remove( |
273 this, | 273 this, |
274 chrome::NOTIFICATION_TAB_CONTENTS_INFOBAR_REMOVED, | 274 chrome::NOTIFICATION_TAB_CONTENTS_INFOBAR_REMOVED, |
275 content::Source<InfoBarService>(infobar_service())); | 275 content::Source<InfoBarService>(infobar_service())); |
276 | 276 |
277 ChromeRenderViewHostTestHarness::TearDown(); | 277 ChromeRenderViewHostTestHarness::TearDown(); |
278 TranslateService::ShutdownForTesting(); | 278 TranslateService::ShutdownForTesting(); |
279 } | 279 } |
280 | 280 |
281 void SetApplicationLocale(const std::string& locale) { | 281 void SetApplicationLocale(const std::string& locale) { |
282 g_browser_process->SetApplicationLocale(locale); | 282 g_browser_process->SetApplicationLocale(locale); |
283 TranslateDownloadManager::GetInstance()->set_application_locale( | 283 translate::TranslateDownloadManager::GetInstance()->set_application_locale( |
284 g_browser_process->GetApplicationLocale()); | 284 g_browser_process->GetApplicationLocale()); |
285 } | 285 } |
286 | 286 |
287 void SimulateTranslateScriptURLFetch(bool success) { | 287 void SimulateTranslateScriptURLFetch(bool success) { |
288 net::TestURLFetcher* fetcher = | 288 net::TestURLFetcher* fetcher = url_fetcher_factory_.GetFetcherByID( |
289 url_fetcher_factory_.GetFetcherByID(TranslateScript::kFetcherId); | 289 translate::TranslateScript::kFetcherId); |
290 ASSERT_TRUE(fetcher); | 290 ASSERT_TRUE(fetcher); |
291 net::URLRequestStatus status; | 291 net::URLRequestStatus status; |
292 status.set_status(success ? net::URLRequestStatus::SUCCESS | 292 status.set_status(success ? net::URLRequestStatus::SUCCESS |
293 : net::URLRequestStatus::FAILED); | 293 : net::URLRequestStatus::FAILED); |
294 fetcher->set_url(fetcher->GetOriginalURL()); | 294 fetcher->set_url(fetcher->GetOriginalURL()); |
295 fetcher->set_status(status); | 295 fetcher->set_status(status); |
296 fetcher->set_response_code(success ? 200 : 500); | 296 fetcher->set_response_code(success ? 200 : 500); |
297 fetcher->delegate()->OnURLFetchComplete(fetcher); | 297 fetcher->delegate()->OnURLFetchComplete(fetcher); |
298 } | 298 } |
299 | 299 |
300 void SimulateSupportedLanguagesURLFetch( | 300 void SimulateSupportedLanguagesURLFetch( |
301 bool success, | 301 bool success, |
302 const std::vector<std::string>& languages, | 302 const std::vector<std::string>& languages, |
303 bool use_alpha_languages, | 303 bool use_alpha_languages, |
304 const std::vector<std::string>& alpha_languages) { | 304 const std::vector<std::string>& alpha_languages) { |
305 net::URLRequestStatus status; | 305 net::URLRequestStatus status; |
306 status.set_status(success ? net::URLRequestStatus::SUCCESS | 306 status.set_status(success ? net::URLRequestStatus::SUCCESS |
307 : net::URLRequestStatus::FAILED); | 307 : net::URLRequestStatus::FAILED); |
308 | 308 |
309 std::string data; | 309 std::string data; |
310 if (success) { | 310 if (success) { |
311 data = | 311 data = base::StringPrintf( |
312 base::StringPrintf("%s{\"sl\": {\"bla\": \"bla\"}, \"%s\": {", | 312 "%s{\"sl\": {\"bla\": \"bla\"}, \"%s\": {", |
313 TranslateLanguageList::kLanguageListCallbackName, | 313 translate::TranslateLanguageList::kLanguageListCallbackName, |
314 TranslateLanguageList::kTargetLanguagesKey); | 314 translate::TranslateLanguageList::kTargetLanguagesKey); |
315 const char* comma = ""; | 315 const char* comma = ""; |
316 for (size_t i = 0; i < languages.size(); ++i) { | 316 for (size_t i = 0; i < languages.size(); ++i) { |
317 data += base::StringPrintf( | 317 data += base::StringPrintf( |
318 "%s\"%s\": \"UnusedFullName\"", comma, languages[i].c_str()); | 318 "%s\"%s\": \"UnusedFullName\"", comma, languages[i].c_str()); |
319 if (i == 0) | 319 if (i == 0) |
320 comma = ","; | 320 comma = ","; |
321 } | 321 } |
322 | 322 |
323 if (use_alpha_languages) { | 323 if (use_alpha_languages) { |
324 data += base::StringPrintf("},\"%s\": {", | 324 data += base::StringPrintf( |
325 TranslateLanguageList::kAlphaLanguagesKey); | 325 "},\"%s\": {", |
| 326 translate::TranslateLanguageList::kAlphaLanguagesKey); |
326 comma = ""; | 327 comma = ""; |
327 for (size_t i = 0; i < alpha_languages.size(); ++i) { | 328 for (size_t i = 0; i < alpha_languages.size(); ++i) { |
328 data += base::StringPrintf( | 329 data += base::StringPrintf( |
329 "%s\"%s\": 1", comma, alpha_languages[i].c_str()); | 330 "%s\"%s\": 1", comma, alpha_languages[i].c_str()); |
330 if (i == 0) | 331 if (i == 0) |
331 comma = ","; | 332 comma = ","; |
332 } | 333 } |
333 } | 334 } |
334 | 335 |
335 data += "}})"; | 336 data += "}})"; |
336 } | 337 } |
337 net::TestURLFetcher* fetcher = | 338 net::TestURLFetcher* fetcher = url_fetcher_factory_.GetFetcherByID( |
338 url_fetcher_factory_.GetFetcherByID(TranslateLanguageList::kFetcherId); | 339 translate::TranslateLanguageList::kFetcherId); |
339 ASSERT_TRUE(fetcher != NULL); | 340 ASSERT_TRUE(fetcher != NULL); |
340 fetcher->set_url(fetcher->GetOriginalURL()); | 341 fetcher->set_url(fetcher->GetOriginalURL()); |
341 fetcher->set_status(status); | 342 fetcher->set_status(status); |
342 fetcher->set_response_code(success ? 200 : 500); | 343 fetcher->set_response_code(success ? 200 : 500); |
343 fetcher->SetResponseString(data); | 344 fetcher->SetResponseString(data); |
344 fetcher->delegate()->OnURLFetchComplete(fetcher); | 345 fetcher->delegate()->OnURLFetchComplete(fetcher); |
345 } | 346 } |
346 | 347 |
347 void SetPrefObserverExpectation(const char* path) { | 348 void SetPrefObserverExpectation(const char* path) { |
348 EXPECT_CALL(*this, OnPreferenceChanged(std::string(path))); | 349 EXPECT_CALL(*this, OnPreferenceChanged(std::string(path))); |
349 } | 350 } |
350 | 351 |
351 PrefChangeRegistrar::NamedChangeCallback pref_callback_; | 352 PrefChangeRegistrar::NamedChangeCallback pref_callback_; |
352 | 353 |
353 private: | 354 private: |
354 content::NotificationRegistrar notification_registrar_; | 355 content::NotificationRegistrar notification_registrar_; |
355 net::TestURLFetcherFactory url_fetcher_factory_; | 356 net::TestURLFetcherFactory url_fetcher_factory_; |
356 | 357 |
357 // The infobars that have been removed. | 358 // The infobars that have been removed. |
358 // WARNING: the pointers point to deleted objects, use only for comparison. | 359 // WARNING: the pointers point to deleted objects, use only for comparison. |
359 std::set<infobars::InfoBarDelegate*> removed_infobars_; | 360 std::set<infobars::InfoBarDelegate*> removed_infobars_; |
360 | 361 |
361 DISALLOW_COPY_AND_ASSIGN(TranslateManagerRenderViewHostTest); | 362 DISALLOW_COPY_AND_ASSIGN(TranslateManagerRenderViewHostTest); |
362 }; | 363 }; |
363 | 364 |
364 class MockTranslateBubbleFactory : public TranslateBubbleFactory { | 365 class MockTranslateBubbleFactory : public TranslateBubbleFactory { |
365 public: | 366 public: |
366 MockTranslateBubbleFactory() {} | 367 MockTranslateBubbleFactory() {} |
367 | 368 |
368 virtual void ShowImplementation(BrowserWindow* window, | 369 virtual void ShowImplementation( |
369 content::WebContents* web_contents, | 370 BrowserWindow* window, |
370 translate::TranslateStep step, | 371 content::WebContents* web_contents, |
371 TranslateErrors::Type error_type) OVERRIDE { | 372 translate::TranslateStep step, |
| 373 translate::TranslateErrors::Type error_type) OVERRIDE { |
372 if (model_) { | 374 if (model_) { |
373 model_->SetViewState( | 375 model_->SetViewState( |
374 TranslateBubbleModelImpl::TranslateStepToViewState(step)); | 376 TranslateBubbleModelImpl::TranslateStepToViewState(step)); |
375 return; | 377 return; |
376 } | 378 } |
377 | 379 |
378 ChromeTranslateClient* chrome_translate_client = | 380 ChromeTranslateClient* chrome_translate_client = |
379 ChromeTranslateClient::FromWebContents(web_contents); | 381 ChromeTranslateClient::FromWebContents(web_contents); |
380 std::string source_language = | 382 std::string source_language = |
381 chrome_translate_client->GetLanguageState().original_language(); | 383 chrome_translate_client->GetLanguageState().original_language(); |
382 std::string target_language = TranslateDownloadManager::GetLanguageCode( | 384 std::string target_language = |
383 g_browser_process->GetApplicationLocale()); | 385 translate::TranslateDownloadManager::GetLanguageCode( |
| 386 g_browser_process->GetApplicationLocale()); |
384 | 387 |
385 scoped_ptr<TranslateUIDelegate> ui_delegate(new TranslateUIDelegate( | 388 scoped_ptr<translate::TranslateUIDelegate> ui_delegate( |
386 chrome_translate_client->GetTranslateManager()->GetWeakPtr(), | 389 new translate::TranslateUIDelegate( |
387 source_language, | 390 chrome_translate_client->GetTranslateManager()->GetWeakPtr(), |
388 target_language)); | 391 source_language, |
| 392 target_language)); |
389 model_.reset(new TranslateBubbleModelImpl(step, ui_delegate.Pass())); | 393 model_.reset(new TranslateBubbleModelImpl(step, ui_delegate.Pass())); |
390 } | 394 } |
391 | 395 |
392 TranslateBubbleModel* model() { return model_.get(); } | 396 TranslateBubbleModel* model() { return model_.get(); } |
393 | 397 |
394 private: | 398 private: |
395 scoped_ptr<TranslateBubbleModel> model_; | 399 scoped_ptr<TranslateBubbleModel> model_; |
396 | 400 |
397 DISALLOW_COPY_AND_ASSIGN(MockTranslateBubbleFactory); | 401 DISALLOW_COPY_AND_ASSIGN(MockTranslateBubbleFactory); |
398 }; | 402 }; |
399 | 403 |
400 | 404 |
401 TEST_F(TranslateManagerRenderViewHostTest, NormalTranslate) { | 405 TEST_F(TranslateManagerRenderViewHostTest, NormalTranslate) { |
402 // See BubbleNormalTranslate for corresponding bubble UX testing. | 406 // See BubbleNormalTranslate for corresponding bubble UX testing. |
403 if (TranslateService::IsTranslateBubbleEnabled()) | 407 if (TranslateService::IsTranslateBubbleEnabled()) |
404 return; | 408 return; |
405 | 409 |
406 SimulateNavigation(GURL("http://www.google.fr"), "fr", true); | 410 SimulateNavigation(GURL("http://www.google.fr"), "fr", true); |
407 | 411 |
408 // We should have an infobar. | 412 // We should have an infobar. |
409 TranslateInfoBarDelegate* infobar = GetTranslateInfoBar(); | 413 translate::TranslateInfoBarDelegate* infobar = GetTranslateInfoBar(); |
410 ASSERT_TRUE(infobar != NULL); | 414 ASSERT_TRUE(infobar != NULL); |
411 EXPECT_EQ(translate::TRANSLATE_STEP_BEFORE_TRANSLATE, | 415 EXPECT_EQ(translate::TRANSLATE_STEP_BEFORE_TRANSLATE, |
412 infobar->translate_step()); | 416 infobar->translate_step()); |
413 | 417 |
414 // Simulate clicking translate. | 418 // Simulate clicking translate. |
415 process()->sink().ClearMessages(); | 419 process()->sink().ClearMessages(); |
416 infobar->Translate(); | 420 infobar->Translate(); |
417 | 421 |
418 // The "Translating..." infobar should be showing. | 422 // The "Translating..." infobar should be showing. |
419 infobar = GetTranslateInfoBar(); | 423 infobar = GetTranslateInfoBar(); |
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
482 } | 486 } |
483 | 487 |
484 TEST_F(TranslateManagerRenderViewHostTest, TranslateScriptNotAvailable) { | 488 TEST_F(TranslateManagerRenderViewHostTest, TranslateScriptNotAvailable) { |
485 // See BubbleTranslateScriptNotAvailable for corresponding bubble UX testing. | 489 // See BubbleTranslateScriptNotAvailable for corresponding bubble UX testing. |
486 if (TranslateService::IsTranslateBubbleEnabled()) | 490 if (TranslateService::IsTranslateBubbleEnabled()) |
487 return; | 491 return; |
488 | 492 |
489 SimulateNavigation(GURL("http://www.google.fr"), "fr", true); | 493 SimulateNavigation(GURL("http://www.google.fr"), "fr", true); |
490 | 494 |
491 // We should have an infobar. | 495 // We should have an infobar. |
492 TranslateInfoBarDelegate* infobar = GetTranslateInfoBar(); | 496 translate::TranslateInfoBarDelegate* infobar = GetTranslateInfoBar(); |
493 ASSERT_TRUE(infobar != NULL); | 497 ASSERT_TRUE(infobar != NULL); |
494 EXPECT_EQ(translate::TRANSLATE_STEP_BEFORE_TRANSLATE, | 498 EXPECT_EQ(translate::TRANSLATE_STEP_BEFORE_TRANSLATE, |
495 infobar->translate_step()); | 499 infobar->translate_step()); |
496 | 500 |
497 // Simulate clicking translate. | 501 // Simulate clicking translate. |
498 process()->sink().ClearMessages(); | 502 process()->sink().ClearMessages(); |
499 infobar->Translate(); | 503 infobar->Translate(); |
500 SimulateTranslateScriptURLFetch(false); | 504 SimulateTranslateScriptURLFetch(false); |
501 | 505 |
502 // We should not have sent any message to translate to the renderer. | 506 // We should not have sent any message to translate to the renderer. |
(...skipping 21 matching lines...) Expand all Loading... |
524 ASSERT_TRUE(GetTranslateInfoBar() == NULL); | 528 ASSERT_TRUE(GetTranslateInfoBar() == NULL); |
525 | 529 |
526 // Translate the page anyway throught the context menu. | 530 // Translate the page anyway throught the context menu. |
527 scoped_ptr<TestRenderViewContextMenu> menu(CreateContextMenu()); | 531 scoped_ptr<TestRenderViewContextMenu> menu(CreateContextMenu()); |
528 menu->Init(); | 532 menu->Init(); |
529 menu->ExecuteCommand(IDC_CONTENT_CONTEXT_TRANSLATE, 0); | 533 menu->ExecuteCommand(IDC_CONTENT_CONTEXT_TRANSLATE, 0); |
530 | 534 |
531 // To test that bug #49018 if fixed, make sure we deal correctly with errors. | 535 // To test that bug #49018 if fixed, make sure we deal correctly with errors. |
532 // Simulate a failure to fetch the translate script. | 536 // Simulate a failure to fetch the translate script. |
533 SimulateTranslateScriptURLFetch(false); | 537 SimulateTranslateScriptURLFetch(false); |
534 TranslateInfoBarDelegate* infobar = GetTranslateInfoBar(); | 538 translate::TranslateInfoBarDelegate* infobar = GetTranslateInfoBar(); |
535 ASSERT_TRUE(infobar != NULL); | 539 ASSERT_TRUE(infobar != NULL); |
536 EXPECT_EQ(translate::TRANSLATE_STEP_TRANSLATE_ERROR, | 540 EXPECT_EQ(translate::TRANSLATE_STEP_TRANSLATE_ERROR, |
537 infobar->translate_step()); | 541 infobar->translate_step()); |
538 EXPECT_TRUE(infobar->is_error()); | 542 EXPECT_TRUE(infobar->is_error()); |
539 infobar->MessageInfoBarButtonPressed(); | 543 infobar->MessageInfoBarButtonPressed(); |
540 SimulateTranslateScriptURLFetch(true); // This time succeed. | 544 SimulateTranslateScriptURLFetch(true); // This time succeed. |
541 | 545 |
542 // Simulate the render notifying the translation has been done, the server | 546 // Simulate the render notifying the translation has been done, the server |
543 // having detected the page was in a known and supported language. | 547 // having detected the page was in a known and supported language. |
544 SimulateOnPageTranslated("fr", "en"); | 548 SimulateOnPageTranslated("fr", "en"); |
545 | 549 |
546 // The after translate infobar should be showing. | 550 // The after translate infobar should be showing. |
547 infobar = GetTranslateInfoBar(); | 551 infobar = GetTranslateInfoBar(); |
548 ASSERT_TRUE(infobar != NULL); | 552 ASSERT_TRUE(infobar != NULL); |
549 EXPECT_EQ(translate::TRANSLATE_STEP_AFTER_TRANSLATE, | 553 EXPECT_EQ(translate::TRANSLATE_STEP_AFTER_TRANSLATE, |
550 infobar->translate_step()); | 554 infobar->translate_step()); |
551 EXPECT_EQ("fr", infobar->original_language_code()); | 555 EXPECT_EQ("fr", infobar->original_language_code()); |
552 EXPECT_EQ("en", infobar->target_language_code()); | 556 EXPECT_EQ("en", infobar->target_language_code()); |
553 | 557 |
554 // Let's run the same steps but this time the server detects the page is | 558 // Let's run the same steps but this time the server detects the page is |
555 // already in English. | 559 // already in English. |
556 SimulateNavigation(GURL("http://www.google.com"), "und", true); | 560 SimulateNavigation(GURL("http://www.google.com"), "und", true); |
557 menu.reset(CreateContextMenu()); | 561 menu.reset(CreateContextMenu()); |
558 menu->Init(); | 562 menu->Init(); |
559 menu->ExecuteCommand(IDC_CONTENT_CONTEXT_TRANSLATE, 0); | 563 menu->ExecuteCommand(IDC_CONTENT_CONTEXT_TRANSLATE, 0); |
560 SimulateOnPageTranslated(1, "en", "en", TranslateErrors::IDENTICAL_LANGUAGES); | 564 SimulateOnPageTranslated( |
| 565 1, "en", "en", translate::TranslateErrors::IDENTICAL_LANGUAGES); |
561 infobar = GetTranslateInfoBar(); | 566 infobar = GetTranslateInfoBar(); |
562 ASSERT_TRUE(infobar != NULL); | 567 ASSERT_TRUE(infobar != NULL); |
563 EXPECT_EQ(translate::TRANSLATE_STEP_TRANSLATE_ERROR, | 568 EXPECT_EQ(translate::TRANSLATE_STEP_TRANSLATE_ERROR, |
564 infobar->translate_step()); | 569 infobar->translate_step()); |
565 EXPECT_EQ(TranslateErrors::IDENTICAL_LANGUAGES, infobar->error_type()); | 570 EXPECT_EQ(translate::TranslateErrors::IDENTICAL_LANGUAGES, |
| 571 infobar->error_type()); |
566 | 572 |
567 // 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 |
568 // page's language (it returns an empty string). | 574 // page's language (it returns an empty string). |
569 SimulateNavigation(GURL("http://www.google.com"), "und", true); | 575 SimulateNavigation(GURL("http://www.google.com"), "und", true); |
570 menu.reset(CreateContextMenu()); | 576 menu.reset(CreateContextMenu()); |
571 menu->Init(); | 577 menu->Init(); |
572 menu->ExecuteCommand(IDC_CONTENT_CONTEXT_TRANSLATE, 0); | 578 menu->ExecuteCommand(IDC_CONTENT_CONTEXT_TRANSLATE, 0); |
573 SimulateOnPageTranslated( | 579 SimulateOnPageTranslated( |
574 2, std::string(), "en", TranslateErrors::UNKNOWN_LANGUAGE); | 580 2, std::string(), "en", translate::TranslateErrors::UNKNOWN_LANGUAGE); |
575 infobar = GetTranslateInfoBar(); | 581 infobar = GetTranslateInfoBar(); |
576 ASSERT_TRUE(infobar != NULL); | 582 ASSERT_TRUE(infobar != NULL); |
577 EXPECT_EQ(translate::TRANSLATE_STEP_TRANSLATE_ERROR, | 583 EXPECT_EQ(translate::TRANSLATE_STEP_TRANSLATE_ERROR, |
578 infobar->translate_step()); | 584 infobar->translate_step()); |
579 EXPECT_EQ(TranslateErrors::UNKNOWN_LANGUAGE, infobar->error_type()); | 585 EXPECT_EQ(translate::TranslateErrors::UNKNOWN_LANGUAGE, |
| 586 infobar->error_type()); |
580 } | 587 } |
581 | 588 |
582 // Tests that we show/don't show an info-bar for the languages. | 589 // Tests that we show/don't show an info-bar for the languages. |
583 TEST_F(TranslateManagerRenderViewHostTest, TestLanguages) { | 590 TEST_F(TranslateManagerRenderViewHostTest, TestLanguages) { |
584 // TODO(port): Test corresponding bubble translate UX: http://crbug.com/383235 | 591 // TODO(port): Test corresponding bubble translate UX: http://crbug.com/383235 |
585 if (TranslateService::IsTranslateBubbleEnabled()) | 592 if (TranslateService::IsTranslateBubbleEnabled()) |
586 return; | 593 return; |
587 | 594 |
588 std::vector<std::string> languages; | 595 std::vector<std::string> languages; |
589 languages.push_back("en"); | 596 languages.push_back("en"); |
590 languages.push_back("ja"); | 597 languages.push_back("ja"); |
591 languages.push_back("fr"); | 598 languages.push_back("fr"); |
592 languages.push_back("ht"); | 599 languages.push_back("ht"); |
593 languages.push_back("xx"); | 600 languages.push_back("xx"); |
594 languages.push_back("zh"); | 601 languages.push_back("zh"); |
595 languages.push_back("zh-CN"); | 602 languages.push_back("zh-CN"); |
596 languages.push_back("und"); | 603 languages.push_back("und"); |
597 | 604 |
598 GURL url("http://www.google.com"); | 605 GURL url("http://www.google.com"); |
599 for (size_t i = 0; i < languages.size(); ++i) { | 606 for (size_t i = 0; i < languages.size(); ++i) { |
600 std::string lang = languages[i]; | 607 std::string lang = languages[i]; |
601 SCOPED_TRACE(::testing::Message() << "Iteration " << i | 608 SCOPED_TRACE(::testing::Message() << "Iteration " << i |
602 << " language=" << lang); | 609 << " language=" << lang); |
603 | 610 |
604 // We should not have a translate infobar. | 611 // We should not have a translate infobar. |
605 TranslateInfoBarDelegate* infobar = GetTranslateInfoBar(); | 612 translate::TranslateInfoBarDelegate* infobar = GetTranslateInfoBar(); |
606 ASSERT_TRUE(infobar == NULL); | 613 ASSERT_TRUE(infobar == NULL); |
607 | 614 |
608 SimulateNavigation(url, lang, true); | 615 SimulateNavigation(url, lang, true); |
609 | 616 |
610 // Verify we have/don't have an info-bar as expected. | 617 // Verify we have/don't have an info-bar as expected. |
611 infobar = GetTranslateInfoBar(); | 618 infobar = GetTranslateInfoBar(); |
612 bool expected = | 619 bool expected = |
613 TranslateDownloadManager::IsSupportedLanguage(lang) && lang != "en"; | 620 translate::TranslateDownloadManager::IsSupportedLanguage(lang) && |
| 621 lang != "en"; |
614 EXPECT_EQ(expected, infobar != NULL); | 622 EXPECT_EQ(expected, infobar != NULL); |
615 | 623 |
616 if (infobar != NULL) | 624 if (infobar != NULL) |
617 EXPECT_TRUE(CloseTranslateInfoBar()); | 625 EXPECT_TRUE(CloseTranslateInfoBar()); |
618 } | 626 } |
619 } | 627 } |
620 | 628 |
621 // Test the fetching of languages from the translate server | 629 // Test the fetching of languages from the translate server |
622 TEST_F(TranslateManagerRenderViewHostTest, FetchLanguagesFromTranslateServer) { | 630 TEST_F(TranslateManagerRenderViewHostTest, FetchLanguagesFromTranslateServer) { |
623 std::vector<std::string> server_languages; | 631 std::vector<std::string> server_languages; |
624 // A list of languages to fake being returned by the translate server. | 632 // A list of languages to fake being returned by the translate server. |
625 server_languages.push_back("aa"); | 633 server_languages.push_back("aa"); |
626 server_languages.push_back("ak"); | 634 server_languages.push_back("ak"); |
627 server_languages.push_back("ab"); | 635 server_languages.push_back("ab"); |
628 server_languages.push_back("en-CA"); | 636 server_languages.push_back("en-CA"); |
629 server_languages.push_back("zh"); | 637 server_languages.push_back("zh"); |
630 server_languages.push_back("yi"); | 638 server_languages.push_back("yi"); |
631 server_languages.push_back("fr-FR"); | 639 server_languages.push_back("fr-FR"); |
632 server_languages.push_back("xx"); | 640 server_languages.push_back("xx"); |
633 | 641 |
634 std::vector<std::string> alpha_languages; | 642 std::vector<std::string> alpha_languages; |
635 alpha_languages.push_back("aa"); | 643 alpha_languages.push_back("aa"); |
636 alpha_languages.push_back("yi"); | 644 alpha_languages.push_back("yi"); |
637 | 645 |
638 // First, get the default languages list. Note that calling | 646 // First, get the default languages list. Note that calling |
639 // GetSupportedLanguages() invokes RequestLanguageList() internally. | 647 // GetSupportedLanguages() invokes RequestLanguageList() internally. |
640 std::vector<std::string> default_supported_languages; | 648 std::vector<std::string> default_supported_languages; |
641 TranslateDownloadManager::GetSupportedLanguages(&default_supported_languages); | 649 translate::TranslateDownloadManager::GetSupportedLanguages( |
| 650 &default_supported_languages); |
642 // To make sure we got the defaults and don't confuse them with the mocks. | 651 // To make sure we got the defaults and don't confuse them with the mocks. |
643 ASSERT_NE(default_supported_languages.size(), server_languages.size()); | 652 ASSERT_NE(default_supported_languages.size(), server_languages.size()); |
644 | 653 |
645 // Check that we still get the defaults until the URLFetch has completed. | 654 // Check that we still get the defaults until the URLFetch has completed. |
646 std::vector<std::string> current_supported_languages; | 655 std::vector<std::string> current_supported_languages; |
647 TranslateDownloadManager::GetSupportedLanguages(¤t_supported_languages); | 656 translate::TranslateDownloadManager::GetSupportedLanguages( |
| 657 ¤t_supported_languages); |
648 EXPECT_EQ(default_supported_languages, current_supported_languages); | 658 EXPECT_EQ(default_supported_languages, current_supported_languages); |
649 | 659 |
650 // Also check that it didn't change if we failed the URL fetch. | 660 // Also check that it didn't change if we failed the URL fetch. |
651 SimulateSupportedLanguagesURLFetch( | 661 SimulateSupportedLanguagesURLFetch( |
652 false, std::vector<std::string>(), true, std::vector<std::string>()); | 662 false, std::vector<std::string>(), true, std::vector<std::string>()); |
653 current_supported_languages.clear(); | 663 current_supported_languages.clear(); |
654 TranslateDownloadManager::GetSupportedLanguages(¤t_supported_languages); | 664 translate::TranslateDownloadManager::GetSupportedLanguages( |
| 665 ¤t_supported_languages); |
655 EXPECT_EQ(default_supported_languages, current_supported_languages); | 666 EXPECT_EQ(default_supported_languages, current_supported_languages); |
656 | 667 |
657 // Now check that we got the appropriate set of languages from the server. | 668 // Now check that we got the appropriate set of languages from the server. |
658 SimulateSupportedLanguagesURLFetch( | 669 SimulateSupportedLanguagesURLFetch( |
659 true, server_languages, true, alpha_languages); | 670 true, server_languages, true, alpha_languages); |
660 current_supported_languages.clear(); | 671 current_supported_languages.clear(); |
661 TranslateDownloadManager::GetSupportedLanguages(¤t_supported_languages); | 672 translate::TranslateDownloadManager::GetSupportedLanguages( |
| 673 ¤t_supported_languages); |
662 // "xx" can't be displayed in the Translate infobar, so this is eliminated. | 674 // "xx" can't be displayed in the Translate infobar, so this is eliminated. |
663 EXPECT_EQ(server_languages.size() - 1, current_supported_languages.size()); | 675 EXPECT_EQ(server_languages.size() - 1, current_supported_languages.size()); |
664 // Not sure we need to guarantee the order of languages, so we find them. | 676 // Not sure we need to guarantee the order of languages, so we find them. |
665 for (size_t i = 0; i < server_languages.size(); ++i) { | 677 for (size_t i = 0; i < server_languages.size(); ++i) { |
666 const std::string& lang = server_languages[i]; | 678 const std::string& lang = server_languages[i]; |
667 if (lang == "xx") | 679 if (lang == "xx") |
668 continue; | 680 continue; |
669 EXPECT_NE(current_supported_languages.end(), | 681 EXPECT_NE(current_supported_languages.end(), |
670 std::find(current_supported_languages.begin(), | 682 std::find(current_supported_languages.begin(), |
671 current_supported_languages.end(), | 683 current_supported_languages.end(), |
672 lang)); | 684 lang)); |
673 bool is_alpha = | 685 bool is_alpha = |
674 std::find(alpha_languages.begin(), alpha_languages.end(), lang) != | 686 std::find(alpha_languages.begin(), alpha_languages.end(), lang) != |
675 alpha_languages.end(); | 687 alpha_languages.end(); |
676 EXPECT_EQ(TranslateDownloadManager::IsAlphaLanguage(lang), is_alpha); | 688 EXPECT_EQ(translate::TranslateDownloadManager::IsAlphaLanguage(lang), |
| 689 is_alpha); |
677 } | 690 } |
678 } | 691 } |
679 | 692 |
680 // Test the fetching of languages from the translate server without 'al' | 693 // Test the fetching of languages from the translate server without 'al' |
681 // parameter. | 694 // parameter. |
682 TEST_F(TranslateManagerRenderViewHostTest, | 695 TEST_F(TranslateManagerRenderViewHostTest, |
683 FetchLanguagesFromTranslateServerWithoutAlpha) { | 696 FetchLanguagesFromTranslateServerWithoutAlpha) { |
684 std::vector<std::string> server_languages; | 697 std::vector<std::string> server_languages; |
685 server_languages.push_back("aa"); | 698 server_languages.push_back("aa"); |
686 server_languages.push_back("ak"); | 699 server_languages.push_back("ak"); |
687 server_languages.push_back("ab"); | 700 server_languages.push_back("ab"); |
688 server_languages.push_back("en-CA"); | 701 server_languages.push_back("en-CA"); |
689 server_languages.push_back("zh"); | 702 server_languages.push_back("zh"); |
690 server_languages.push_back("yi"); | 703 server_languages.push_back("yi"); |
691 server_languages.push_back("fr-FR"); | 704 server_languages.push_back("fr-FR"); |
692 server_languages.push_back("xx"); | 705 server_languages.push_back("xx"); |
693 | 706 |
694 std::vector<std::string> alpha_languages; | 707 std::vector<std::string> alpha_languages; |
695 alpha_languages.push_back("aa"); | 708 alpha_languages.push_back("aa"); |
696 alpha_languages.push_back("yi"); | 709 alpha_languages.push_back("yi"); |
697 | 710 |
698 // call GetSupportedLanguages to call RequestLanguageList internally. | 711 // call GetSupportedLanguages to call RequestLanguageList internally. |
699 std::vector<std::string> default_supported_languages; | 712 std::vector<std::string> default_supported_languages; |
700 TranslateDownloadManager::GetSupportedLanguages(&default_supported_languages); | 713 translate::TranslateDownloadManager::GetSupportedLanguages( |
| 714 &default_supported_languages); |
701 | 715 |
702 SimulateSupportedLanguagesURLFetch( | 716 SimulateSupportedLanguagesURLFetch( |
703 true, server_languages, false, alpha_languages); | 717 true, server_languages, false, alpha_languages); |
704 | 718 |
705 std::vector<std::string> current_supported_languages; | 719 std::vector<std::string> current_supported_languages; |
706 TranslateDownloadManager::GetSupportedLanguages(¤t_supported_languages); | 720 translate::TranslateDownloadManager::GetSupportedLanguages( |
| 721 ¤t_supported_languages); |
707 | 722 |
708 // "xx" can't be displayed in the Translate infobar, so this is eliminated. | 723 // "xx" can't be displayed in the Translate infobar, so this is eliminated. |
709 EXPECT_EQ(server_languages.size() - 1, current_supported_languages.size()); | 724 EXPECT_EQ(server_languages.size() - 1, current_supported_languages.size()); |
710 | 725 |
711 for (size_t i = 0; i < server_languages.size(); ++i) { | 726 for (size_t i = 0; i < server_languages.size(); ++i) { |
712 const std::string& lang = server_languages[i]; | 727 const std::string& lang = server_languages[i]; |
713 if (lang == "xx") | 728 if (lang == "xx") |
714 continue; | 729 continue; |
715 EXPECT_NE(current_supported_languages.end(), | 730 EXPECT_NE(current_supported_languages.end(), |
716 std::find(current_supported_languages.begin(), | 731 std::find(current_supported_languages.begin(), |
717 current_supported_languages.end(), | 732 current_supported_languages.end(), |
718 lang)); | 733 lang)); |
719 EXPECT_FALSE(TranslateDownloadManager::IsAlphaLanguage(lang)); | 734 EXPECT_FALSE(translate::TranslateDownloadManager::IsAlphaLanguage(lang)); |
720 } | 735 } |
721 } | 736 } |
722 | 737 |
723 // Tests auto-translate on page. | 738 // Tests auto-translate on page. |
724 TEST_F(TranslateManagerRenderViewHostTest, AutoTranslateOnNavigate) { | 739 TEST_F(TranslateManagerRenderViewHostTest, AutoTranslateOnNavigate) { |
725 // TODO(port): Test corresponding bubble translate UX: http://crbug.com/383235 | 740 // TODO(port): Test corresponding bubble translate UX: http://crbug.com/383235 |
726 if (TranslateService::IsTranslateBubbleEnabled()) | 741 if (TranslateService::IsTranslateBubbleEnabled()) |
727 return; | 742 return; |
728 | 743 |
729 SimulateNavigation(GURL("http://www.google.fr"), "fr", true); | 744 SimulateNavigation(GURL("http://www.google.fr"), "fr", true); |
730 | 745 |
731 // Simulate the user translating. | 746 // Simulate the user translating. |
732 TranslateInfoBarDelegate* infobar = GetTranslateInfoBar(); | 747 translate::TranslateInfoBarDelegate* infobar = GetTranslateInfoBar(); |
733 ASSERT_TRUE(infobar != NULL); | 748 ASSERT_TRUE(infobar != NULL); |
734 infobar->Translate(); | 749 infobar->Translate(); |
735 // Simulate the translate script being retrieved. | 750 // Simulate the translate script being retrieved. |
736 SimulateTranslateScriptURLFetch(true); | 751 SimulateTranslateScriptURLFetch(true); |
737 SimulateOnPageTranslated("fr", "en"); | 752 SimulateOnPageTranslated("fr", "en"); |
738 | 753 |
739 // Now navigate to a new page in the same language. | 754 // Now navigate to a new page in the same language. |
740 process()->sink().ClearMessages(); | 755 process()->sink().ClearMessages(); |
741 SimulateNavigation(GURL("http://news.google.fr"), "fr", true); | 756 SimulateNavigation(GURL("http://news.google.fr"), "fr", true); |
742 | 757 |
(...skipping 171 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
914 // return when navigating in page. | 929 // return when navigating in page. |
915 TEST_F(TranslateManagerRenderViewHostTest, | 930 TEST_F(TranslateManagerRenderViewHostTest, |
916 TranslateCloseInfoBarInPageNavigation) { | 931 TranslateCloseInfoBarInPageNavigation) { |
917 // TODO(port): Test corresponding bubble translate UX: http://crbug.com/383235 | 932 // TODO(port): Test corresponding bubble translate UX: http://crbug.com/383235 |
918 if (TranslateService::IsTranslateBubbleEnabled()) | 933 if (TranslateService::IsTranslateBubbleEnabled()) |
919 return; | 934 return; |
920 | 935 |
921 SimulateNavigation(GURL("http://www.google.fr"), "fr", true); | 936 SimulateNavigation(GURL("http://www.google.fr"), "fr", true); |
922 | 937 |
923 // Simulate the user translating. | 938 // Simulate the user translating. |
924 TranslateInfoBarDelegate* infobar = GetTranslateInfoBar(); | 939 translate::TranslateInfoBarDelegate* infobar = GetTranslateInfoBar(); |
925 ASSERT_TRUE(infobar != NULL); | 940 ASSERT_TRUE(infobar != NULL); |
926 infobar->Translate(); | 941 infobar->Translate(); |
927 // Simulate the translate script being retrieved. | 942 // Simulate the translate script being retrieved. |
928 SimulateTranslateScriptURLFetch(true); | 943 SimulateTranslateScriptURLFetch(true); |
929 SimulateOnPageTranslated("fr", "en"); | 944 SimulateOnPageTranslated("fr", "en"); |
930 | 945 |
931 EXPECT_TRUE(CloseTranslateInfoBar()); | 946 EXPECT_TRUE(CloseTranslateInfoBar()); |
932 | 947 |
933 // Navigate in page, no infobar should be shown. | 948 // Navigate in page, no infobar should be shown. |
934 SimulateNavigation(GURL("http://www.google.fr/#ref1"), "fr", true); | 949 SimulateNavigation(GURL("http://www.google.fr/#ref1"), "fr", true); |
(...skipping 10 matching lines...) Expand all Loading... |
945 // Tests that the after translate the infobar still shows when navigating | 960 // Tests that the after translate the infobar still shows when navigating |
946 // in-page. | 961 // in-page. |
947 TEST_F(TranslateManagerRenderViewHostTest, TranslateInPageNavigation) { | 962 TEST_F(TranslateManagerRenderViewHostTest, TranslateInPageNavigation) { |
948 // TODO(port): Test corresponding bubble translate UX: http://crbug.com/383235 | 963 // TODO(port): Test corresponding bubble translate UX: http://crbug.com/383235 |
949 if (TranslateService::IsTranslateBubbleEnabled()) | 964 if (TranslateService::IsTranslateBubbleEnabled()) |
950 return; | 965 return; |
951 | 966 |
952 SimulateNavigation(GURL("http://www.google.fr"), "fr", true); | 967 SimulateNavigation(GURL("http://www.google.fr"), "fr", true); |
953 | 968 |
954 // Simulate the user translating. | 969 // Simulate the user translating. |
955 TranslateInfoBarDelegate* infobar = GetTranslateInfoBar(); | 970 translate::TranslateInfoBarDelegate* infobar = GetTranslateInfoBar(); |
956 ASSERT_TRUE(infobar != NULL); | 971 ASSERT_TRUE(infobar != NULL); |
957 infobar->Translate(); | 972 infobar->Translate(); |
958 SimulateTranslateScriptURLFetch(true); | 973 SimulateTranslateScriptURLFetch(true); |
959 SimulateOnPageTranslated("fr", "en"); | 974 SimulateOnPageTranslated("fr", "en"); |
960 // The after translate infobar is showing. | 975 // The after translate infobar is showing. |
961 infobar = GetTranslateInfoBar(); | 976 infobar = GetTranslateInfoBar(); |
962 ASSERT_TRUE(infobar != NULL); | 977 ASSERT_TRUE(infobar != NULL); |
963 | 978 |
964 // Navigate out of page, a new infobar should show. | 979 // Navigate out of page, a new infobar should show. |
965 // See note in TranslateCloseInfoBarInPageNavigation test on why it is | 980 // See note in TranslateCloseInfoBarInPageNavigation test on why it is |
(...skipping 21 matching lines...) Expand all Loading... |
987 | 1002 |
988 // Tests that we deal correctly with unsupported languages returned by the | 1003 // Tests that we deal correctly with unsupported languages returned by the |
989 // server. | 1004 // server. |
990 // The translation server might return a language we don't support. | 1005 // The translation server might return a language we don't support. |
991 TEST_F(TranslateManagerRenderViewHostTest, ServerReportsUnsupportedLanguage) { | 1006 TEST_F(TranslateManagerRenderViewHostTest, ServerReportsUnsupportedLanguage) { |
992 // TODO(port): Test corresponding bubble translate UX: http://crbug.com/383235 | 1007 // TODO(port): Test corresponding bubble translate UX: http://crbug.com/383235 |
993 if (TranslateService::IsTranslateBubbleEnabled()) | 1008 if (TranslateService::IsTranslateBubbleEnabled()) |
994 return; | 1009 return; |
995 | 1010 |
996 SimulateNavigation(GURL("http://mail.google.fr"), "fr", true); | 1011 SimulateNavigation(GURL("http://mail.google.fr"), "fr", true); |
997 TranslateInfoBarDelegate* infobar = GetTranslateInfoBar(); | 1012 translate::TranslateInfoBarDelegate* infobar = GetTranslateInfoBar(); |
998 ASSERT_TRUE(infobar != NULL); | 1013 ASSERT_TRUE(infobar != NULL); |
999 process()->sink().ClearMessages(); | 1014 process()->sink().ClearMessages(); |
1000 infobar->Translate(); | 1015 infobar->Translate(); |
1001 SimulateTranslateScriptURLFetch(true); | 1016 SimulateTranslateScriptURLFetch(true); |
1002 // Simulate the render notifying the translation has been done, but it | 1017 // Simulate the render notifying the translation has been done, but it |
1003 // reports a language we don't support. | 1018 // reports a language we don't support. |
1004 SimulateOnPageTranslated("qbz", "en"); | 1019 SimulateOnPageTranslated("qbz", "en"); |
1005 | 1020 |
1006 // An error infobar should be showing to report that we don't support this | 1021 // An error infobar should be showing to report that we don't support this |
1007 // language. | 1022 // language. |
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1097 | 1112 |
1098 // Make sure the pref allows translate. | 1113 // Make sure the pref allows translate. |
1099 Profile* profile = | 1114 Profile* profile = |
1100 Profile::FromBrowserContext(web_contents()->GetBrowserContext()); | 1115 Profile::FromBrowserContext(web_contents()->GetBrowserContext()); |
1101 PrefService* prefs = profile->GetPrefs(); | 1116 PrefService* prefs = profile->GetPrefs(); |
1102 prefs->SetBoolean(prefs::kEnableTranslate, true); | 1117 prefs->SetBoolean(prefs::kEnableTranslate, true); |
1103 | 1118 |
1104 SimulateNavigation(GURL("http://www.google.fr"), "fr", true); | 1119 SimulateNavigation(GURL("http://www.google.fr"), "fr", true); |
1105 | 1120 |
1106 // An infobar should be shown. | 1121 // An infobar should be shown. |
1107 TranslateInfoBarDelegate* infobar = GetTranslateInfoBar(); | 1122 translate::TranslateInfoBarDelegate* infobar = GetTranslateInfoBar(); |
1108 EXPECT_TRUE(infobar != NULL); | 1123 EXPECT_TRUE(infobar != NULL); |
1109 | 1124 |
1110 // Disable translate. | 1125 // Disable translate. |
1111 prefs->SetBoolean(prefs::kEnableTranslate, false); | 1126 prefs->SetBoolean(prefs::kEnableTranslate, false); |
1112 | 1127 |
1113 // Navigate to a new page, that should close the previous infobar. | 1128 // Navigate to a new page, that should close the previous infobar. |
1114 GURL url("http://www.youtube.fr"); | 1129 GURL url("http://www.youtube.fr"); |
1115 NavigateAndCommit(url); | 1130 NavigateAndCommit(url); |
1116 infobar = GetTranslateInfoBar(); | 1131 infobar = GetTranslateInfoBar(); |
1117 EXPECT_TRUE(infobar == NULL); | 1132 EXPECT_TRUE(infobar == NULL); |
(...skipping 16 matching lines...) Expand all Loading... |
1134 | 1149 |
1135 // An infobar should be shown. | 1150 // An infobar should be shown. |
1136 EXPECT_TRUE(GetTranslateInfoBar() != NULL); | 1151 EXPECT_TRUE(GetTranslateInfoBar() != NULL); |
1137 | 1152 |
1138 // Select never translate this language. | 1153 // Select never translate this language. |
1139 Profile* profile = | 1154 Profile* profile = |
1140 Profile::FromBrowserContext(web_contents()->GetBrowserContext()); | 1155 Profile::FromBrowserContext(web_contents()->GetBrowserContext()); |
1141 PrefService* prefs = profile->GetPrefs(); | 1156 PrefService* prefs = profile->GetPrefs(); |
1142 PrefChangeRegistrar registrar; | 1157 PrefChangeRegistrar registrar; |
1143 registrar.Init(prefs); | 1158 registrar.Init(prefs); |
1144 registrar.Add(TranslatePrefs::kPrefTranslateBlockedLanguages, pref_callback_); | 1159 registrar.Add(translate::TranslatePrefs::kPrefTranslateBlockedLanguages, |
1145 scoped_ptr<TranslatePrefs> translate_prefs( | 1160 pref_callback_); |
| 1161 scoped_ptr<translate::TranslatePrefs> translate_prefs( |
1146 ChromeTranslateClient::CreateTranslatePrefs(prefs)); | 1162 ChromeTranslateClient::CreateTranslatePrefs(prefs)); |
1147 EXPECT_FALSE(translate_prefs->IsBlockedLanguage("fr")); | 1163 EXPECT_FALSE(translate_prefs->IsBlockedLanguage("fr")); |
1148 TranslateAcceptLanguages* accept_languages = | 1164 translate::TranslateAcceptLanguages* accept_languages = |
1149 ChromeTranslateClient::GetTranslateAcceptLanguages(profile); | 1165 ChromeTranslateClient::GetTranslateAcceptLanguages(profile); |
1150 EXPECT_TRUE(translate_prefs->CanTranslateLanguage(accept_languages, "fr")); | 1166 EXPECT_TRUE(translate_prefs->CanTranslateLanguage(accept_languages, "fr")); |
1151 SetPrefObserverExpectation(TranslatePrefs::kPrefTranslateBlockedLanguages); | 1167 SetPrefObserverExpectation( |
| 1168 translate::TranslatePrefs::kPrefTranslateBlockedLanguages); |
1152 translate_prefs->BlockLanguage("fr"); | 1169 translate_prefs->BlockLanguage("fr"); |
1153 EXPECT_TRUE(translate_prefs->IsBlockedLanguage("fr")); | 1170 EXPECT_TRUE(translate_prefs->IsBlockedLanguage("fr")); |
1154 EXPECT_FALSE(translate_prefs->IsSiteBlacklisted(url.host())); | 1171 EXPECT_FALSE(translate_prefs->IsSiteBlacklisted(url.host())); |
1155 EXPECT_FALSE(translate_prefs->CanTranslateLanguage(accept_languages, "fr")); | 1172 EXPECT_FALSE(translate_prefs->CanTranslateLanguage(accept_languages, "fr")); |
1156 | 1173 |
1157 EXPECT_TRUE(CloseTranslateInfoBar()); | 1174 EXPECT_TRUE(CloseTranslateInfoBar()); |
1158 | 1175 |
1159 // Navigate to a new page also in French. | 1176 // Navigate to a new page also in French. |
1160 SimulateNavigation(GURL("http://wwww.youtube.fr"), "fr", true); | 1177 SimulateNavigation(GURL("http://wwww.youtube.fr"), "fr", true); |
1161 | 1178 |
1162 // There should not be a translate infobar. | 1179 // There should not be a translate infobar. |
1163 EXPECT_TRUE(GetTranslateInfoBar() == NULL); | 1180 EXPECT_TRUE(GetTranslateInfoBar() == NULL); |
1164 | 1181 |
1165 // Remove the language from the blacklist. | 1182 // Remove the language from the blacklist. |
1166 SetPrefObserverExpectation(TranslatePrefs::kPrefTranslateBlockedLanguages); | 1183 SetPrefObserverExpectation( |
| 1184 translate::TranslatePrefs::kPrefTranslateBlockedLanguages); |
1167 translate_prefs->UnblockLanguage("fr"); | 1185 translate_prefs->UnblockLanguage("fr"); |
1168 EXPECT_FALSE(translate_prefs->IsBlockedLanguage("fr")); | 1186 EXPECT_FALSE(translate_prefs->IsBlockedLanguage("fr")); |
1169 EXPECT_FALSE(translate_prefs->IsSiteBlacklisted(url.host())); | 1187 EXPECT_FALSE(translate_prefs->IsSiteBlacklisted(url.host())); |
1170 EXPECT_TRUE(translate_prefs->CanTranslateLanguage(accept_languages, "fr")); | 1188 EXPECT_TRUE(translate_prefs->CanTranslateLanguage(accept_languages, "fr")); |
1171 | 1189 |
1172 // Navigate to a page in French. | 1190 // Navigate to a page in French. |
1173 SimulateNavigation(url, "fr", true); | 1191 SimulateNavigation(url, "fr", true); |
1174 | 1192 |
1175 // There should be a translate infobar. | 1193 // There should be a translate infobar. |
1176 EXPECT_TRUE(GetTranslateInfoBar() != NULL); | 1194 EXPECT_TRUE(GetTranslateInfoBar() != NULL); |
(...skipping 11 matching lines...) Expand all Loading... |
1188 | 1206 |
1189 // An infobar should be shown. | 1207 // An infobar should be shown. |
1190 EXPECT_TRUE(GetTranslateInfoBar() != NULL); | 1208 EXPECT_TRUE(GetTranslateInfoBar() != NULL); |
1191 | 1209 |
1192 // Select never translate this site. | 1210 // Select never translate this site. |
1193 Profile* profile = | 1211 Profile* profile = |
1194 Profile::FromBrowserContext(web_contents()->GetBrowserContext()); | 1212 Profile::FromBrowserContext(web_contents()->GetBrowserContext()); |
1195 PrefService* prefs = profile->GetPrefs(); | 1213 PrefService* prefs = profile->GetPrefs(); |
1196 PrefChangeRegistrar registrar; | 1214 PrefChangeRegistrar registrar; |
1197 registrar.Init(prefs); | 1215 registrar.Init(prefs); |
1198 registrar.Add(TranslatePrefs::kPrefTranslateSiteBlacklist, pref_callback_); | 1216 registrar.Add(translate::TranslatePrefs::kPrefTranslateSiteBlacklist, |
1199 scoped_ptr<TranslatePrefs> translate_prefs( | 1217 pref_callback_); |
| 1218 scoped_ptr<translate::TranslatePrefs> translate_prefs( |
1200 ChromeTranslateClient::CreateTranslatePrefs(prefs)); | 1219 ChromeTranslateClient::CreateTranslatePrefs(prefs)); |
1201 EXPECT_FALSE(translate_prefs->IsSiteBlacklisted(host)); | 1220 EXPECT_FALSE(translate_prefs->IsSiteBlacklisted(host)); |
1202 TranslateAcceptLanguages* accept_languages = | 1221 translate::TranslateAcceptLanguages* accept_languages = |
1203 ChromeTranslateClient::GetTranslateAcceptLanguages(profile); | 1222 ChromeTranslateClient::GetTranslateAcceptLanguages(profile); |
1204 EXPECT_TRUE(translate_prefs->CanTranslateLanguage(accept_languages, "fr")); | 1223 EXPECT_TRUE(translate_prefs->CanTranslateLanguage(accept_languages, "fr")); |
1205 SetPrefObserverExpectation(TranslatePrefs::kPrefTranslateSiteBlacklist); | 1224 SetPrefObserverExpectation( |
| 1225 translate::TranslatePrefs::kPrefTranslateSiteBlacklist); |
1206 translate_prefs->BlacklistSite(host); | 1226 translate_prefs->BlacklistSite(host); |
1207 EXPECT_TRUE(translate_prefs->IsSiteBlacklisted(host)); | 1227 EXPECT_TRUE(translate_prefs->IsSiteBlacklisted(host)); |
1208 EXPECT_TRUE(translate_prefs->CanTranslateLanguage(accept_languages, "fr")); | 1228 EXPECT_TRUE(translate_prefs->CanTranslateLanguage(accept_languages, "fr")); |
1209 | 1229 |
1210 EXPECT_TRUE(CloseTranslateInfoBar()); | 1230 EXPECT_TRUE(CloseTranslateInfoBar()); |
1211 | 1231 |
1212 // Navigate to a new page also on the same site. | 1232 // Navigate to a new page also on the same site. |
1213 SimulateNavigation(GURL("http://www.google.fr/hello"), "fr", true); | 1233 SimulateNavigation(GURL("http://www.google.fr/hello"), "fr", true); |
1214 | 1234 |
1215 // There should not be a translate infobar. | 1235 // There should not be a translate infobar. |
1216 EXPECT_TRUE(GetTranslateInfoBar() == NULL); | 1236 EXPECT_TRUE(GetTranslateInfoBar() == NULL); |
1217 | 1237 |
1218 // Remove the site from the blacklist. | 1238 // Remove the site from the blacklist. |
1219 SetPrefObserverExpectation(TranslatePrefs::kPrefTranslateSiteBlacklist); | 1239 SetPrefObserverExpectation( |
| 1240 translate::TranslatePrefs::kPrefTranslateSiteBlacklist); |
1220 translate_prefs->RemoveSiteFromBlacklist(host); | 1241 translate_prefs->RemoveSiteFromBlacklist(host); |
1221 EXPECT_FALSE(translate_prefs->IsSiteBlacklisted(host)); | 1242 EXPECT_FALSE(translate_prefs->IsSiteBlacklisted(host)); |
1222 EXPECT_TRUE(translate_prefs->CanTranslateLanguage(accept_languages, "fr")); | 1243 EXPECT_TRUE(translate_prefs->CanTranslateLanguage(accept_languages, "fr")); |
1223 | 1244 |
1224 // Navigate to a page in French. | 1245 // Navigate to a page in French. |
1225 SimulateNavigation(url, "fr", true); | 1246 SimulateNavigation(url, "fr", true); |
1226 | 1247 |
1227 // There should be a translate infobar. | 1248 // There should be a translate infobar. |
1228 EXPECT_TRUE(GetTranslateInfoBar() != NULL); | 1249 EXPECT_TRUE(GetTranslateInfoBar() != NULL); |
1229 } | 1250 } |
1230 | 1251 |
1231 // Tests the "Always translate this language" pref. | 1252 // Tests the "Always translate this language" pref. |
1232 TEST_F(TranslateManagerRenderViewHostTest, AlwaysTranslateLanguagePref) { | 1253 TEST_F(TranslateManagerRenderViewHostTest, AlwaysTranslateLanguagePref) { |
1233 // TODO(port): Test corresponding bubble translate UX: http://crbug.com/383235 | 1254 // TODO(port): Test corresponding bubble translate UX: http://crbug.com/383235 |
1234 if (TranslateService::IsTranslateBubbleEnabled()) | 1255 if (TranslateService::IsTranslateBubbleEnabled()) |
1235 return; | 1256 return; |
1236 | 1257 |
1237 // Select always translate French to English. | 1258 // Select always translate French to English. |
1238 Profile* profile = | 1259 Profile* profile = |
1239 Profile::FromBrowserContext(web_contents()->GetBrowserContext()); | 1260 Profile::FromBrowserContext(web_contents()->GetBrowserContext()); |
1240 PrefService* prefs = profile->GetPrefs(); | 1261 PrefService* prefs = profile->GetPrefs(); |
1241 PrefChangeRegistrar registrar; | 1262 PrefChangeRegistrar registrar; |
1242 registrar.Init(prefs); | 1263 registrar.Init(prefs); |
1243 registrar.Add(TranslatePrefs::kPrefTranslateWhitelists, pref_callback_); | 1264 registrar.Add(translate::TranslatePrefs::kPrefTranslateWhitelists, |
1244 scoped_ptr<TranslatePrefs> translate_prefs( | 1265 pref_callback_); |
| 1266 scoped_ptr<translate::TranslatePrefs> translate_prefs( |
1245 ChromeTranslateClient::CreateTranslatePrefs(prefs)); | 1267 ChromeTranslateClient::CreateTranslatePrefs(prefs)); |
1246 SetPrefObserverExpectation(TranslatePrefs::kPrefTranslateWhitelists); | 1268 SetPrefObserverExpectation( |
| 1269 translate::TranslatePrefs::kPrefTranslateWhitelists); |
1247 translate_prefs->WhitelistLanguagePair("fr", "en"); | 1270 translate_prefs->WhitelistLanguagePair("fr", "en"); |
1248 | 1271 |
1249 // Load a page in French. | 1272 // Load a page in French. |
1250 SimulateNavigation(GURL("http://www.google.fr"), "fr", true); | 1273 SimulateNavigation(GURL("http://www.google.fr"), "fr", true); |
1251 | 1274 |
1252 // It should have triggered an automatic translation to English. | 1275 // It should have triggered an automatic translation to English. |
1253 | 1276 |
1254 // The translating infobar should be showing. | 1277 // The translating infobar should be showing. |
1255 TranslateInfoBarDelegate* infobar = GetTranslateInfoBar(); | 1278 translate::TranslateInfoBarDelegate* infobar = GetTranslateInfoBar(); |
1256 ASSERT_TRUE(infobar != NULL); | 1279 ASSERT_TRUE(infobar != NULL); |
1257 EXPECT_EQ(translate::TRANSLATE_STEP_TRANSLATING, infobar->translate_step()); | 1280 EXPECT_EQ(translate::TRANSLATE_STEP_TRANSLATING, infobar->translate_step()); |
1258 SimulateTranslateScriptURLFetch(true); | 1281 SimulateTranslateScriptURLFetch(true); |
1259 std::string original_lang, target_lang; | 1282 std::string original_lang, target_lang; |
1260 EXPECT_TRUE(GetTranslateMessage(&original_lang, &target_lang)); | 1283 EXPECT_TRUE(GetTranslateMessage(&original_lang, &target_lang)); |
1261 EXPECT_EQ("fr", original_lang); | 1284 EXPECT_EQ("fr", original_lang); |
1262 EXPECT_EQ("en", target_lang); | 1285 EXPECT_EQ("en", target_lang); |
1263 process()->sink().ClearMessages(); | 1286 process()->sink().ClearMessages(); |
1264 | 1287 |
1265 // Try another language, it should not be autotranslated. | 1288 // Try another language, it should not be autotranslated. |
1266 SimulateNavigation(GURL("http://www.google.es"), "es", true); | 1289 SimulateNavigation(GURL("http://www.google.es"), "es", true); |
1267 EXPECT_FALSE(GetTranslateMessage(&original_lang, &target_lang)); | 1290 EXPECT_FALSE(GetTranslateMessage(&original_lang, &target_lang)); |
1268 EXPECT_TRUE(GetTranslateInfoBar() != NULL); | 1291 EXPECT_TRUE(GetTranslateInfoBar() != NULL); |
1269 EXPECT_TRUE(CloseTranslateInfoBar()); | 1292 EXPECT_TRUE(CloseTranslateInfoBar()); |
1270 | 1293 |
1271 // Let's switch to incognito mode, it should not be autotranslated in that | 1294 // Let's switch to incognito mode, it should not be autotranslated in that |
1272 // case either. | 1295 // case either. |
1273 TestingProfile* test_profile = | 1296 TestingProfile* test_profile = |
1274 static_cast<TestingProfile*>(web_contents()->GetBrowserContext()); | 1297 static_cast<TestingProfile*>(web_contents()->GetBrowserContext()); |
1275 test_profile->ForceIncognito(true); | 1298 test_profile->ForceIncognito(true); |
1276 SimulateNavigation(GURL("http://www.youtube.fr"), "fr", true); | 1299 SimulateNavigation(GURL("http://www.youtube.fr"), "fr", true); |
1277 EXPECT_FALSE(GetTranslateMessage(&original_lang, &target_lang)); | 1300 EXPECT_FALSE(GetTranslateMessage(&original_lang, &target_lang)); |
1278 EXPECT_TRUE(GetTranslateInfoBar() != NULL); | 1301 EXPECT_TRUE(GetTranslateInfoBar() != NULL); |
1279 EXPECT_TRUE(CloseTranslateInfoBar()); | 1302 EXPECT_TRUE(CloseTranslateInfoBar()); |
1280 test_profile->ForceIncognito(false); // Get back to non incognito. | 1303 test_profile->ForceIncognito(false); // Get back to non incognito. |
1281 | 1304 |
1282 // Now revert the always translate pref and make sure we go back to expected | 1305 // Now revert the always translate pref and make sure we go back to expected |
1283 // behavior, which is show a "before translate" infobar. | 1306 // behavior, which is show a "before translate" infobar. |
1284 SetPrefObserverExpectation(TranslatePrefs::kPrefTranslateWhitelists); | 1307 SetPrefObserverExpectation( |
| 1308 translate::TranslatePrefs::kPrefTranslateWhitelists); |
1285 translate_prefs->RemoveLanguagePairFromWhitelist("fr", "en"); | 1309 translate_prefs->RemoveLanguagePairFromWhitelist("fr", "en"); |
1286 SimulateNavigation(GURL("http://www.google.fr"), "fr", true); | 1310 SimulateNavigation(GURL("http://www.google.fr"), "fr", true); |
1287 EXPECT_FALSE(GetTranslateMessage(&original_lang, &target_lang)); | 1311 EXPECT_FALSE(GetTranslateMessage(&original_lang, &target_lang)); |
1288 infobar = GetTranslateInfoBar(); | 1312 infobar = GetTranslateInfoBar(); |
1289 ASSERT_TRUE(infobar != NULL); | 1313 ASSERT_TRUE(infobar != NULL); |
1290 EXPECT_EQ(translate::TRANSLATE_STEP_BEFORE_TRANSLATE, | 1314 EXPECT_EQ(translate::TRANSLATE_STEP_BEFORE_TRANSLATE, |
1291 infobar->translate_step()); | 1315 infobar->translate_step()); |
1292 } | 1316 } |
1293 | 1317 |
1294 // Context menu. | 1318 // Context menu. |
1295 TEST_F(TranslateManagerRenderViewHostTest, ContextMenu) { | 1319 TEST_F(TranslateManagerRenderViewHostTest, ContextMenu) { |
1296 // TODO(port): Test corresponding bubble translate UX: http://crbug.com/383235 | 1320 // TODO(port): Test corresponding bubble translate UX: http://crbug.com/383235 |
1297 if (TranslateService::IsTranslateBubbleEnabled()) | 1321 if (TranslateService::IsTranslateBubbleEnabled()) |
1298 return; | 1322 return; |
1299 | 1323 |
1300 // Blacklist www.google.fr and French for translation. | 1324 // Blacklist www.google.fr and French for translation. |
1301 GURL url("http://www.google.fr"); | 1325 GURL url("http://www.google.fr"); |
1302 Profile* profile = | 1326 Profile* profile = |
1303 Profile::FromBrowserContext(web_contents()->GetBrowserContext()); | 1327 Profile::FromBrowserContext(web_contents()->GetBrowserContext()); |
1304 scoped_ptr<TranslatePrefs> translate_prefs( | 1328 scoped_ptr<translate::TranslatePrefs> translate_prefs( |
1305 ChromeTranslateClient::CreateTranslatePrefs(profile->GetPrefs())); | 1329 ChromeTranslateClient::CreateTranslatePrefs(profile->GetPrefs())); |
1306 translate_prefs->BlockLanguage("fr"); | 1330 translate_prefs->BlockLanguage("fr"); |
1307 translate_prefs->BlacklistSite(url.host()); | 1331 translate_prefs->BlacklistSite(url.host()); |
1308 EXPECT_TRUE(translate_prefs->IsBlockedLanguage("fr")); | 1332 EXPECT_TRUE(translate_prefs->IsBlockedLanguage("fr")); |
1309 EXPECT_TRUE(translate_prefs->IsSiteBlacklisted(url.host())); | 1333 EXPECT_TRUE(translate_prefs->IsSiteBlacklisted(url.host())); |
1310 | 1334 |
1311 // Simulate navigating to a page in French. The translate menu should show but | 1335 // Simulate navigating to a page in French. The translate menu should show but |
1312 // should only be enabled when the page language has been received. | 1336 // should only be enabled when the page language has been received. |
1313 NavigateAndCommit(url); | 1337 NavigateAndCommit(url); |
1314 scoped_ptr<TestRenderViewContextMenu> menu(CreateContextMenu()); | 1338 scoped_ptr<TestRenderViewContextMenu> menu(CreateContextMenu()); |
1315 menu->Init(); | 1339 menu->Init(); |
1316 EXPECT_TRUE(menu->IsItemPresent(IDC_CONTENT_CONTEXT_TRANSLATE)); | 1340 EXPECT_TRUE(menu->IsItemPresent(IDC_CONTENT_CONTEXT_TRANSLATE)); |
1317 EXPECT_FALSE(menu->IsCommandIdEnabled(IDC_CONTENT_CONTEXT_TRANSLATE)); | 1341 EXPECT_FALSE(menu->IsCommandIdEnabled(IDC_CONTENT_CONTEXT_TRANSLATE)); |
1318 | 1342 |
1319 // Simulate receiving the language. | 1343 // Simulate receiving the language. |
1320 SimulateOnTranslateLanguageDetermined("fr", true); | 1344 SimulateOnTranslateLanguageDetermined("fr", true); |
1321 menu.reset(CreateContextMenu()); | 1345 menu.reset(CreateContextMenu()); |
1322 menu->Init(); | 1346 menu->Init(); |
1323 EXPECT_TRUE(menu->IsItemPresent(IDC_CONTENT_CONTEXT_TRANSLATE)); | 1347 EXPECT_TRUE(menu->IsItemPresent(IDC_CONTENT_CONTEXT_TRANSLATE)); |
1324 EXPECT_TRUE(menu->IsCommandIdEnabled(IDC_CONTENT_CONTEXT_TRANSLATE)); | 1348 EXPECT_TRUE(menu->IsCommandIdEnabled(IDC_CONTENT_CONTEXT_TRANSLATE)); |
1325 | 1349 |
1326 // Use the menu to translate the page. | 1350 // Use the menu to translate the page. |
1327 menu->ExecuteCommand(IDC_CONTENT_CONTEXT_TRANSLATE, 0); | 1351 menu->ExecuteCommand(IDC_CONTENT_CONTEXT_TRANSLATE, 0); |
1328 | 1352 |
1329 // That should have triggered a translation. | 1353 // That should have triggered a translation. |
1330 // The "translating..." infobar should be showing. | 1354 // The "translating..." infobar should be showing. |
1331 TranslateInfoBarDelegate* infobar = GetTranslateInfoBar(); | 1355 translate::TranslateInfoBarDelegate* infobar = GetTranslateInfoBar(); |
1332 ASSERT_TRUE(infobar != NULL); | 1356 ASSERT_TRUE(infobar != NULL); |
1333 EXPECT_EQ(translate::TRANSLATE_STEP_TRANSLATING, infobar->translate_step()); | 1357 EXPECT_EQ(translate::TRANSLATE_STEP_TRANSLATING, infobar->translate_step()); |
1334 SimulateTranslateScriptURLFetch(true); | 1358 SimulateTranslateScriptURLFetch(true); |
1335 std::string original_lang, target_lang; | 1359 std::string original_lang, target_lang; |
1336 EXPECT_TRUE(GetTranslateMessage(&original_lang, &target_lang)); | 1360 EXPECT_TRUE(GetTranslateMessage(&original_lang, &target_lang)); |
1337 EXPECT_EQ("fr", original_lang); | 1361 EXPECT_EQ("fr", original_lang); |
1338 EXPECT_EQ("en", target_lang); | 1362 EXPECT_EQ("en", target_lang); |
1339 process()->sink().ClearMessages(); | 1363 process()->sink().ClearMessages(); |
1340 | 1364 |
1341 // This should also have reverted the blacklisting of this site and language. | 1365 // This should also have reverted the blacklisting of this site and language. |
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1403 // Tests that an extra always/never translate button is shown on the "before | 1427 // Tests that an extra always/never translate button is shown on the "before |
1404 // translate" infobar when the translation is accepted/declined 3 times, | 1428 // translate" infobar when the translation is accepted/declined 3 times, |
1405 // only when not in incognito mode. | 1429 // only when not in incognito mode. |
1406 TEST_F(TranslateManagerRenderViewHostTest, BeforeTranslateExtraButtons) { | 1430 TEST_F(TranslateManagerRenderViewHostTest, BeforeTranslateExtraButtons) { |
1407 // TODO(port): Test corresponding bubble translate UX: http://crbug.com/383235 | 1431 // TODO(port): Test corresponding bubble translate UX: http://crbug.com/383235 |
1408 if (TranslateService::IsTranslateBubbleEnabled()) | 1432 if (TranslateService::IsTranslateBubbleEnabled()) |
1409 return; | 1433 return; |
1410 | 1434 |
1411 Profile* profile = | 1435 Profile* profile = |
1412 Profile::FromBrowserContext(web_contents()->GetBrowserContext()); | 1436 Profile::FromBrowserContext(web_contents()->GetBrowserContext()); |
1413 scoped_ptr<TranslatePrefs> translate_prefs( | 1437 scoped_ptr<translate::TranslatePrefs> translate_prefs( |
1414 ChromeTranslateClient::CreateTranslatePrefs(profile->GetPrefs())); | 1438 ChromeTranslateClient::CreateTranslatePrefs(profile->GetPrefs())); |
1415 translate_prefs->ResetTranslationAcceptedCount("fr"); | 1439 translate_prefs->ResetTranslationAcceptedCount("fr"); |
1416 translate_prefs->ResetTranslationDeniedCount("fr"); | 1440 translate_prefs->ResetTranslationDeniedCount("fr"); |
1417 translate_prefs->ResetTranslationAcceptedCount("de"); | 1441 translate_prefs->ResetTranslationAcceptedCount("de"); |
1418 translate_prefs->ResetTranslationDeniedCount("de"); | 1442 translate_prefs->ResetTranslationDeniedCount("de"); |
1419 | 1443 |
1420 // We'll do 4 times in incognito mode first to make sure the button is not | 1444 // We'll do 4 times in incognito mode first to make sure the button is not |
1421 // shown in that case, then 4 times in normal mode. | 1445 // shown in that case, then 4 times in normal mode. |
1422 TranslateInfoBarDelegate* infobar; | 1446 translate::TranslateInfoBarDelegate* infobar; |
1423 TestingProfile* test_profile = | 1447 TestingProfile* test_profile = |
1424 static_cast<TestingProfile*>(web_contents()->GetBrowserContext()); | 1448 static_cast<TestingProfile*>(web_contents()->GetBrowserContext()); |
1425 static_cast<extensions::TestExtensionSystem*>( | 1449 static_cast<extensions::TestExtensionSystem*>( |
1426 extensions::ExtensionSystem::Get(test_profile))->CreateProcessManager(); | 1450 extensions::ExtensionSystem::Get(test_profile))->CreateProcessManager(); |
1427 test_profile->ForceIncognito(true); | 1451 test_profile->ForceIncognito(true); |
1428 for (int i = 0; i < 8; ++i) { | 1452 for (int i = 0; i < 8; ++i) { |
1429 SCOPED_TRACE(::testing::Message() << "Iteration " << i << " incognito mode=" | 1453 SCOPED_TRACE(::testing::Message() << "Iteration " << i << " incognito mode=" |
1430 << test_profile->IsOffTheRecord()); | 1454 << test_profile->IsOffTheRecord()); |
1431 SimulateNavigation(GURL("http://www.google.fr"), "fr", true); | 1455 SimulateNavigation(GURL("http://www.google.fr"), "fr", true); |
1432 infobar = GetTranslateInfoBar(); | 1456 infobar = GetTranslateInfoBar(); |
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1504 | 1528 |
1505 // Tests that the script is expired and refetched as expected. | 1529 // Tests that the script is expired and refetched as expected. |
1506 TEST_F(TranslateManagerRenderViewHostTest, ScriptExpires) { | 1530 TEST_F(TranslateManagerRenderViewHostTest, ScriptExpires) { |
1507 // TODO(port): Test corresponding bubble translate UX: http://crbug.com/383235 | 1531 // TODO(port): Test corresponding bubble translate UX: http://crbug.com/383235 |
1508 if (TranslateService::IsTranslateBubbleEnabled()) | 1532 if (TranslateService::IsTranslateBubbleEnabled()) |
1509 return; | 1533 return; |
1510 | 1534 |
1511 ExpireTranslateScriptImmediately(); | 1535 ExpireTranslateScriptImmediately(); |
1512 | 1536 |
1513 SimulateNavigation(GURL("http://www.google.fr"), "fr", true); | 1537 SimulateNavigation(GURL("http://www.google.fr"), "fr", true); |
1514 TranslateInfoBarDelegate* infobar = GetTranslateInfoBar(); | 1538 translate::TranslateInfoBarDelegate* infobar = GetTranslateInfoBar(); |
1515 ASSERT_TRUE(infobar != NULL); | 1539 ASSERT_TRUE(infobar != NULL); |
1516 process()->sink().ClearMessages(); | 1540 process()->sink().ClearMessages(); |
1517 infobar->Translate(); | 1541 infobar->Translate(); |
1518 SimulateTranslateScriptURLFetch(true); | 1542 SimulateTranslateScriptURLFetch(true); |
1519 SimulateOnPageTranslated("fr", "en"); | 1543 SimulateOnPageTranslated("fr", "en"); |
1520 | 1544 |
1521 // A task should have been posted to clear the script, run it. | 1545 // A task should have been posted to clear the script, run it. |
1522 base::MessageLoop::current()->RunUntilIdle(); | 1546 base::MessageLoop::current()->RunUntilIdle(); |
1523 | 1547 |
1524 // Do another navigation and translation. | 1548 // Do another navigation and translation. |
(...skipping 27 matching lines...) Expand all Loading... |
1552 if (!TranslateService::IsTranslateBubbleEnabled()) | 1576 if (!TranslateService::IsTranslateBubbleEnabled()) |
1553 return; | 1577 return; |
1554 | 1578 |
1555 MockTranslateBubbleFactory* factory = new MockTranslateBubbleFactory; | 1579 MockTranslateBubbleFactory* factory = new MockTranslateBubbleFactory; |
1556 scoped_ptr<TranslateBubbleFactory> factory_ptr(factory); | 1580 scoped_ptr<TranslateBubbleFactory> factory_ptr(factory); |
1557 TranslateBubbleFactory::SetFactory(factory); | 1581 TranslateBubbleFactory::SetFactory(factory); |
1558 | 1582 |
1559 SimulateNavigation(GURL("http://www.google.fr"), "fr", true); | 1583 SimulateNavigation(GURL("http://www.google.fr"), "fr", true); |
1560 | 1584 |
1561 // Check the bubble exists instead of the infobar. | 1585 // Check the bubble exists instead of the infobar. |
1562 TranslateInfoBarDelegate* infobar = GetTranslateInfoBar(); | 1586 translate::TranslateInfoBarDelegate* infobar = GetTranslateInfoBar(); |
1563 ASSERT_TRUE(infobar == NULL); | 1587 ASSERT_TRUE(infobar == NULL); |
1564 TranslateBubbleModel* bubble = factory->model(); | 1588 TranslateBubbleModel* bubble = factory->model(); |
1565 ASSERT_TRUE(bubble != NULL); | 1589 ASSERT_TRUE(bubble != NULL); |
1566 EXPECT_EQ(TranslateBubbleModel::VIEW_STATE_BEFORE_TRANSLATE, | 1590 EXPECT_EQ(TranslateBubbleModel::VIEW_STATE_BEFORE_TRANSLATE, |
1567 bubble->GetViewState()); | 1591 bubble->GetViewState()); |
1568 | 1592 |
1569 // Simulate clicking translate. | 1593 // Simulate clicking translate. |
1570 process()->sink().ClearMessages(); | 1594 process()->sink().ClearMessages(); |
1571 bubble->Translate(); | 1595 bubble->Translate(); |
1572 | 1596 |
(...skipping 22 matching lines...) Expand all Loading... |
1595 if (!TranslateService::IsTranslateBubbleEnabled()) | 1619 if (!TranslateService::IsTranslateBubbleEnabled()) |
1596 return; | 1620 return; |
1597 | 1621 |
1598 MockTranslateBubbleFactory* factory = new MockTranslateBubbleFactory; | 1622 MockTranslateBubbleFactory* factory = new MockTranslateBubbleFactory; |
1599 scoped_ptr<TranslateBubbleFactory> factory_ptr(factory); | 1623 scoped_ptr<TranslateBubbleFactory> factory_ptr(factory); |
1600 TranslateBubbleFactory::SetFactory(factory); | 1624 TranslateBubbleFactory::SetFactory(factory); |
1601 | 1625 |
1602 SimulateNavigation(GURL("http://www.google.fr"), "fr", true); | 1626 SimulateNavigation(GURL("http://www.google.fr"), "fr", true); |
1603 | 1627 |
1604 // Check the bubble exists instead of the infobar. | 1628 // Check the bubble exists instead of the infobar. |
1605 TranslateInfoBarDelegate* infobar = GetTranslateInfoBar(); | 1629 translate::TranslateInfoBarDelegate* infobar = GetTranslateInfoBar(); |
1606 ASSERT_TRUE(infobar == NULL); | 1630 ASSERT_TRUE(infobar == NULL); |
1607 TranslateBubbleModel* bubble = factory->model(); | 1631 TranslateBubbleModel* bubble = factory->model(); |
1608 ASSERT_TRUE(bubble != NULL); | 1632 ASSERT_TRUE(bubble != NULL); |
1609 EXPECT_EQ(TranslateBubbleModel::VIEW_STATE_BEFORE_TRANSLATE, | 1633 EXPECT_EQ(TranslateBubbleModel::VIEW_STATE_BEFORE_TRANSLATE, |
1610 bubble->GetViewState()); | 1634 bubble->GetViewState()); |
1611 | 1635 |
1612 // Simulate clicking translate. | 1636 // Simulate clicking translate. |
1613 process()->sink().ClearMessages(); | 1637 process()->sink().ClearMessages(); |
1614 bubble->Translate(); | 1638 bubble->Translate(); |
1615 SimulateTranslateScriptURLFetch(false); | 1639 SimulateTranslateScriptURLFetch(false); |
(...skipping 22 matching lines...) Expand all Loading... |
1638 | 1662 |
1639 // We should not have a bubble as we don't know the language. | 1663 // We should not have a bubble as we don't know the language. |
1640 ASSERT_TRUE(factory->model() == NULL); | 1664 ASSERT_TRUE(factory->model() == NULL); |
1641 | 1665 |
1642 // Translate the page anyway throught the context menu. | 1666 // Translate the page anyway throught the context menu. |
1643 scoped_ptr<TestRenderViewContextMenu> menu(CreateContextMenu()); | 1667 scoped_ptr<TestRenderViewContextMenu> menu(CreateContextMenu()); |
1644 menu->Init(); | 1668 menu->Init(); |
1645 menu->ExecuteCommand(IDC_CONTENT_CONTEXT_TRANSLATE, 0); | 1669 menu->ExecuteCommand(IDC_CONTENT_CONTEXT_TRANSLATE, 0); |
1646 | 1670 |
1647 // Check the bubble exists instead of the infobar. | 1671 // Check the bubble exists instead of the infobar. |
1648 TranslateInfoBarDelegate* infobar = GetTranslateInfoBar(); | 1672 translate::TranslateInfoBarDelegate* infobar = GetTranslateInfoBar(); |
1649 ASSERT_TRUE(infobar == NULL); | 1673 ASSERT_TRUE(infobar == NULL); |
1650 TranslateBubbleModel* bubble = factory->model(); | 1674 TranslateBubbleModel* bubble = factory->model(); |
1651 ASSERT_TRUE(bubble != NULL); | 1675 ASSERT_TRUE(bubble != NULL); |
1652 EXPECT_EQ(TranslateBubbleModel::VIEW_STATE_TRANSLATING, | 1676 EXPECT_EQ(TranslateBubbleModel::VIEW_STATE_TRANSLATING, |
1653 bubble->GetViewState()); | 1677 bubble->GetViewState()); |
1654 } | 1678 } |
OLD | NEW |