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 const std::string locale = "zh-TW"; | |
| 322 const std::string page_lang = "zh-CN"; | |
| 323 manager_->set_application_locale(locale); | |
| 324 translate_manager_->GetLanguageState().LanguageDetermined(page_lang, true); | |
| 325 | |
| 326 translate_manager_->InitiateTranslation(page_lang); | |
| 327 histogram_tester.ExpectTotalCount(kMetricName, 0); | |
|
groby-ooo-7-16
2017/01/25 16:20:10
That's the offending line, sorry for not spotting
| |
| 328 histogram_tester.ExpectUniqueSample( | |
| 329 kMetricName, | |
| 330 translate::TranslateBrowserMetrics::INITIATION_STATUS_SIMILAR_LANGUAGES, | |
| 331 1); | |
| 332 } | |
| 333 | |
| 334 // The test measures that Translate is not triggered for a zh-CN page for a | |
| 335 // zh-TW user. | |
| 336 TEST_F(TranslateManagerTest, | |
| 337 DontTranslateZhSimplifiedPageForZhTraditionalLocale) { | |
| 338 TranslateManager::SetIgnoreMissingKeyForTesting(true); | |
| 339 translate_manager_.reset(new translate::TranslateManager( | |
| 340 &mock_translate_client_, kAcceptLanguages)); | |
| 341 | |
| 342 const char kMetricName[] = "Translate.InitiationStatus.v2"; | |
| 343 base::HistogramTester histogram_tester; | |
| 344 | |
| 345 const std::string locale = "zh-CN"; | |
| 346 const std::string page_lang = "zh-TW"; | |
| 347 manager_->set_application_locale(locale); | |
| 348 translate_manager_->GetLanguageState().LanguageDetermined(page_lang, true); | |
| 349 | |
| 350 translate_manager_->InitiateTranslation(page_lang); | |
| 351 histogram_tester.ExpectTotalCount(kMetricName, 0); | |
| 352 histogram_tester.ExpectUniqueSample( | |
| 353 kMetricName, | |
| 354 translate::TranslateBrowserMetrics::INITIATION_STATUS_SIMILAR_LANGUAGES, | |
| 355 1); | |
| 356 } | |
| 357 | |
| 310 // Utility function to set the threshold params | 358 // Utility function to set the threshold params |
| 311 void ChangeThresholdInParams( | 359 void ChangeThresholdInParams( |
| 312 const char* initiate_translation_confidence_threshold, | 360 const char* initiate_translation_confidence_threshold, |
| 313 const char* initiate_translation_probability_threshold, | 361 const char* initiate_translation_probability_threshold, |
| 314 const char* target_language_confidence_threshold, | 362 const char* target_language_confidence_threshold, |
| 315 const char* target_language_probability_threshold) { | 363 const char* target_language_probability_threshold) { |
| 316 ASSERT_TRUE(variations::AssociateVariationParams( | 364 ASSERT_TRUE(variations::AssociateVariationParams( |
| 317 kTrialName, "Enabled", {{"initiate_translation_ulp_confidence_threshold", | 365 kTrialName, "Enabled", {{"initiate_translation_ulp_confidence_threshold", |
| 318 initiate_translation_confidence_threshold}, | 366 initiate_translation_confidence_threshold}, |
| 319 {"initiate_translation_ulp_probability_threshold", | 367 {"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 | 493 // 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). | 494 // the one with "fr" (0.6) and "pt-PT" (0.4). |
| 447 EXPECT_TRUE(CallLanguageInULP("fr")); | 495 EXPECT_TRUE(CallLanguageInULP("fr")); |
| 448 EXPECT_TRUE(CallLanguageInULP("pt")); | 496 EXPECT_TRUE(CallLanguageInULP("pt")); |
| 449 EXPECT_FALSE(CallLanguageInULP("zh-TW")); | 497 EXPECT_FALSE(CallLanguageInULP("zh-TW")); |
| 450 } | 498 } |
| 451 | 499 |
| 452 } // namespace testing | 500 } // namespace testing |
| 453 | 501 |
| 454 } // namespace translate | 502 } // namespace translate |
| OLD | NEW |