| 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 const std::string locale = "zh-TW"; | |
| 322 const std::string page_lang = "zh-CN"; | |
| 323 | |
| 324 network_notifier_.SimulateOnline(); | |
| 325 manager_->set_application_locale(locale); | |
| 326 ON_CALL(mock_translate_client_, IsTranslatableURL(_)) | |
| 327 .WillByDefault(Return(true)); | |
| 328 | |
| 329 EXPECT_EQ("zh-TW", translate_manager_->GetTargetLanguage(&translate_prefs_)); | |
| 330 translate_manager_->GetLanguageState().LanguageDetermined(page_lang, true); | |
| 331 translate_manager_->InitiateTranslation(page_lang); | |
| 332 | |
| 333 histogram_tester.ExpectUniqueSample( | |
| 334 kMetricName, | |
| 335 translate::TranslateBrowserMetrics::INITIATION_STATUS_SIMILAR_LANGUAGES, | |
| 336 1); | |
| 337 } | |
| 338 | |
| 339 // The test measures that Translate is not triggered for a zh-CN page for a | |
| 340 // zh-TW user. | |
| 341 TEST_F(TranslateManagerTest, | |
| 342 DontTranslateZhSimplifiedPageForZhTraditionalLocale) { | |
| 343 TranslateManager::SetIgnoreMissingKeyForTesting(true); | |
| 344 translate_manager_.reset(new translate::TranslateManager( | |
| 345 &mock_translate_client_, kAcceptLanguages)); | |
| 346 | |
| 347 const char kMetricName[] = "Translate.InitiationStatus.v2"; | |
| 348 base::HistogramTester histogram_tester; | |
| 349 | |
| 350 const std::string locale = "zh-CN"; | |
| 351 const std::string page_lang = "zh-TW"; | |
| 352 | |
| 353 network_notifier_.SimulateOnline(); | |
| 354 manager_->set_application_locale(locale); | |
| 355 ON_CALL(mock_translate_client_, IsTranslatableURL(_)) | |
| 356 .WillByDefault(Return(true)); | |
| 357 | |
| 358 EXPECT_EQ("zh-CN", translate_manager_->GetTargetLanguage(&translate_prefs_)); | |
| 359 translate_manager_->GetLanguageState().LanguageDetermined(page_lang, true); | |
| 360 translate_manager_->InitiateTranslation(page_lang); | |
| 361 | |
| 362 histogram_tester.ExpectUniqueSample( | |
| 363 kMetricName, | |
| 364 translate::TranslateBrowserMetrics::INITIATION_STATUS_SIMILAR_LANGUAGES, | |
| 365 1); | |
| 366 } | |
| 367 | |
| 368 // Utility function to set the threshold params | 310 // Utility function to set the threshold params |
| 369 void ChangeThresholdInParams( | 311 void ChangeThresholdInParams( |
| 370 const char* initiate_translation_confidence_threshold, | 312 const char* initiate_translation_confidence_threshold, |
| 371 const char* initiate_translation_probability_threshold, | 313 const char* initiate_translation_probability_threshold, |
| 372 const char* target_language_confidence_threshold, | 314 const char* target_language_confidence_threshold, |
| 373 const char* target_language_probability_threshold) { | 315 const char* target_language_probability_threshold) { |
| 374 ASSERT_TRUE(variations::AssociateVariationParams( | 316 ASSERT_TRUE(variations::AssociateVariationParams( |
| 375 kTrialName, "Enabled", {{"initiate_translation_ulp_confidence_threshold", | 317 kTrialName, "Enabled", {{"initiate_translation_ulp_confidence_threshold", |
| 376 initiate_translation_confidence_threshold}, | 318 initiate_translation_confidence_threshold}, |
| 377 {"initiate_translation_ulp_probability_threshold", | 319 {"initiate_translation_ulp_probability_threshold", |
| (...skipping 125 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 503 // 0.79 and lower than 0.8 and the probability threshold is lower than both | 445 // 0.79 and lower than 0.8 and the probability threshold is lower than both |
| 504 // the one with "fr" (0.6) and "pt-PT" (0.4). | 446 // the one with "fr" (0.6) and "pt-PT" (0.4). |
| 505 EXPECT_TRUE(CallLanguageInULP("fr")); | 447 EXPECT_TRUE(CallLanguageInULP("fr")); |
| 506 EXPECT_TRUE(CallLanguageInULP("pt")); | 448 EXPECT_TRUE(CallLanguageInULP("pt")); |
| 507 EXPECT_FALSE(CallLanguageInULP("zh-TW")); | 449 EXPECT_FALSE(CallLanguageInULP("zh-TW")); |
| 508 } | 450 } |
| 509 | 451 |
| 510 } // namespace testing | 452 } // namespace testing |
| 511 | 453 |
| 512 } // namespace translate | 454 } // namespace translate |
| OLD | NEW |