Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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 "components/translate/core/browser/translate_manager.h" | 5 #include "components/translate/core/browser/translate_manager.h" |
| 6 | 6 |
| 7 #include "base/json/json_reader.h" | 7 #include "base/json/json_reader.h" |
| 8 #include "base/memory/ptr_util.h" | 8 #include "base/memory/ptr_util.h" |
| 9 #include "base/run_loop.h" | 9 #include "base/run_loop.h" |
| 10 #include "base/test/histogram_tester.h" | 10 #include "base/test/histogram_tester.h" |
| (...skipping 289 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 300 | 300 |
| 301 // In the online case, InitiateTranslation will proceed past early out tests. | 301 // In the online case, InitiateTranslation will proceed past early out tests. |
| 302 network_notifier_.SimulateOnline(); | 302 network_notifier_.SimulateOnline(); |
| 303 translate_manager_->InitiateTranslation("de"); | 303 translate_manager_->InitiateTranslation("de"); |
| 304 histogram_tester.ExpectUniqueSample( | 304 histogram_tester.ExpectUniqueSample( |
| 305 kMetricName, | 305 kMetricName, |
| 306 translate::TranslateBrowserMetrics::INITIATION_STATUS_DISABLED_BY_PREFS, | 306 translate::TranslateBrowserMetrics::INITIATION_STATUS_DISABLED_BY_PREFS, |
| 307 1); | 307 1); |
| 308 } | 308 } |
| 309 | 309 |
| 310 // The test measures that Translate is not triggered for a zh-TW page for a | |
| 311 // zh-CN user. | |
| 312 TEST_F(TranslateManagerTest, | |
| 313 DontTranslateZhTraditionalPageForZhSimplifiedLocale) { | |
| 314 TranslateManager::SetIgnoreMissingKeyForTesting(true); | |
| 315 translate_manager_.reset(new translate::TranslateManager( | |
| 316 &mock_translate_client_, kAcceptLanguages)); | |
| 317 | |
| 318 const char kMetricName[] = "Translate.InitiationStatus.v2"; | |
| 319 base::HistogramTester histogram_tester; | |
| 320 | |
| 321 prefs_.SetBoolean(prefs::kEnableTranslate, false); | |
|
groby-ooo-7-16
2017/01/25 01:52:07
I'm surprised the tests work for translate being d
| |
| 322 | |
| 323 const std::string locale = "zh-TW"; | |
| 324 const std::string page_lang = "zh-CN"; | |
| 325 manager_->set_application_locale(locale); | |
| 326 translate_manager_->GetLanguageState().LanguageDetermined(page_lang, true); | |
| 327 | |
| 328 // In the offline case, Initiate will early-out before even hitting the API | |
|
groby-ooo-7-16
2017/01/25 01:52:07
Might want to fix the comment :)
| |
| 329 // key test. | |
| 330 network_notifier_.SimulateOffline(); | |
|
groby-ooo-7-16
2017/01/25 01:52:07
And remove SimulateOffline
| |
| 331 translate_manager_->InitiateTranslation(page_lang); | |
| 332 histogram_tester.ExpectTotalCount(kMetricName, 0); | |
| 333 | |
| 334 // In the online case, InitiateTranslation will proceed past early out tests. | |
| 335 network_notifier_.SimulateOnline(); | |
|
groby-ooo-7-16
2017/01/25 01:52:07
See above
| |
| 336 translate_manager_->InitiateTranslation(page_lang); | |
| 337 histogram_tester.ExpectUniqueSample( | |
| 338 kMetricName, | |
| 339 translate::TranslateBrowserMetrics::INITIATION_STATUS_SIMILAR_LANGUAGES, | |
| 340 1); | |
| 341 } | |
| 342 | |
| 343 // The test measures that Translate is not triggered for a zh-CN page for a | |
| 344 // zh-TW user. | |
| 345 TEST_F(TranslateManagerTest, | |
| 346 DontTranslateZhSimplifiedPageForZhTraditionalLocale) { | |
| 347 TranslateManager::SetIgnoreMissingKeyForTesting(true); | |
| 348 translate_manager_.reset(new translate::TranslateManager( | |
| 349 &mock_translate_client_, kAcceptLanguages)); | |
| 350 | |
| 351 const char kMetricName[] = "Translate.InitiationStatus.v2"; | |
| 352 base::HistogramTester histogram_tester; | |
| 353 | |
| 354 prefs_.SetBoolean(prefs::kEnableTranslate, false); | |
| 355 | |
| 356 const std::string locale = "zh-CN"; | |
| 357 const std::string page_lang = "zh-TW"; | |
| 358 manager_->set_application_locale(locale); | |
| 359 translate_manager_->GetLanguageState().LanguageDetermined(page_lang, true); | |
| 360 | |
| 361 // In the offline case, Initiate will early-out before even hitting the API | |
| 362 // key test. | |
|
groby-ooo-7-16
2017/01/25 01:52:07
See previous test
| |
| 363 network_notifier_.SimulateOffline(); | |
| 364 translate_manager_->InitiateTranslation(page_lang); | |
| 365 histogram_tester.ExpectTotalCount(kMetricName, 0); | |
| 366 | |
| 367 // In the online case, InitiateTranslation will proceed past early out tests. | |
| 368 network_notifier_.SimulateOnline(); | |
| 369 translate_manager_->InitiateTranslation(page_lang); | |
| 370 histogram_tester.ExpectUniqueSample( | |
| 371 kMetricName, | |
| 372 translate::TranslateBrowserMetrics::INITIATION_STATUS_SIMILAR_LANGUAGES, | |
| 373 1); | |
| 374 } | |
| 375 | |
| 310 // Utility function to set the threshold params | 376 // Utility function to set the threshold params |
| 311 void ChangeThresholdInParams( | 377 void ChangeThresholdInParams( |
| 312 const char* initiate_translation_confidence_threshold, | 378 const char* initiate_translation_confidence_threshold, |
| 313 const char* initiate_translation_probability_threshold, | 379 const char* initiate_translation_probability_threshold, |
| 314 const char* target_language_confidence_threshold, | 380 const char* target_language_confidence_threshold, |
| 315 const char* target_language_probability_threshold) { | 381 const char* target_language_probability_threshold) { |
| 316 ASSERT_TRUE(variations::AssociateVariationParams( | 382 ASSERT_TRUE(variations::AssociateVariationParams( |
| 317 kTrialName, "Enabled", {{"initiate_translation_ulp_confidence_threshold", | 383 kTrialName, "Enabled", {{"initiate_translation_ulp_confidence_threshold", |
| 318 initiate_translation_confidence_threshold}, | 384 initiate_translation_confidence_threshold}, |
| 319 {"initiate_translation_ulp_probability_threshold", | 385 {"initiate_translation_ulp_probability_threshold", |
| (...skipping 125 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 445 // 0.79 and lower than 0.8 and the probability threshold is lower than both | 511 // 0.79 and lower than 0.8 and the probability threshold is lower than both |
| 446 // the one with "fr" (0.6) and "pt-PT" (0.4). | 512 // the one with "fr" (0.6) and "pt-PT" (0.4). |
| 447 EXPECT_TRUE(CallLanguageInULP("fr")); | 513 EXPECT_TRUE(CallLanguageInULP("fr")); |
| 448 EXPECT_TRUE(CallLanguageInULP("pt")); | 514 EXPECT_TRUE(CallLanguageInULP("pt")); |
| 449 EXPECT_FALSE(CallLanguageInULP("zh-TW")); | 515 EXPECT_FALSE(CallLanguageInULP("zh-TW")); |
| 450 } | 516 } |
| 451 | 517 |
| 452 } // namespace testing | 518 } // namespace testing |
| 453 | 519 |
| 454 } // namespace translate | 520 } // namespace translate |
| OLD | NEW |