Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(436)

Side by Side Diff: components/translate/core/browser/translate_manager_unittest.cc

Issue 2802613004: fix target language issue under three locales (Hebrew[iw->he], Fillipion[tl->fil], and Nowreign[no-… (Closed)
Patch Set: Created 3 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 <utility> 7 #include <utility>
8 8
9 #include "base/json/json_reader.h" 9 #include "base/json/json_reader.h"
10 #include "base/memory/ptr_util.h" 10 #include "base/memory/ptr_util.h"
(...skipping 236 matching lines...) Expand 10 before | Expand all | Expand 10 after
247 TEST_F(TranslateManagerTest, GetTargetLanguageDefaultsToAppLocale) { 247 TEST_F(TranslateManagerTest, GetTargetLanguageDefaultsToAppLocale) {
248 // Ensure the locale is set to a supported language. 248 // Ensure the locale is set to a supported language.
249 ASSERT_TRUE(TranslateDownloadManager::IsSupportedLanguage("en")); 249 ASSERT_TRUE(TranslateDownloadManager::IsSupportedLanguage("en"));
250 manager_->set_application_locale("en"); 250 manager_->set_application_locale("en");
251 EXPECT_EQ("en", TranslateManager::GetTargetLanguage(&translate_prefs_)); 251 EXPECT_EQ("en", TranslateManager::GetTargetLanguage(&translate_prefs_));
252 252
253 // Try a second supported language. 253 // Try a second supported language.
254 ASSERT_TRUE(TranslateDownloadManager::IsSupportedLanguage("de")); 254 ASSERT_TRUE(TranslateDownloadManager::IsSupportedLanguage("de"));
255 manager_->set_application_locale("de"); 255 manager_->set_application_locale("de");
256 EXPECT_EQ("de", TranslateManager::GetTargetLanguage(&translate_prefs_)); 256 EXPECT_EQ("de", TranslateManager::GetTargetLanguage(&translate_prefs_));
257
258 // Try a those case of non standard code.
259 // 'he', 'fil', 'nb' => 'iw', 'tl', 'no'
260 ASSERT_TRUE(TranslateDownloadManager::IsSupportedLanguage("iw"));
261 ASSERT_FALSE(TranslateDownloadManager::IsSupportedLanguage("he"));
262 manager_->set_application_locale("he");
263 EXPECT_EQ("iw", TranslateManager::GetTargetLanguage(&translate_prefs_));
264
265 ASSERT_TRUE(TranslateDownloadManager::IsSupportedLanguage("tl"));
266 ASSERT_FALSE(TranslateDownloadManager::IsSupportedLanguage("fil"));
267 manager_->set_application_locale("fil");
268 EXPECT_EQ("tl", TranslateManager::GetTargetLanguage(&translate_prefs_));
269
270 ASSERT_TRUE(TranslateDownloadManager::IsSupportedLanguage("no"));
271 ASSERT_FALSE(TranslateDownloadManager::IsSupportedLanguage("nb"));
272 manager_->set_application_locale("nb");
273 EXPECT_EQ("no", TranslateManager::GetTargetLanguage(&translate_prefs_));
257 } 274 }
258 275
259 // If the application locale's language is not supported, the target language 276 // If the application locale's language is not supported, the target language
260 // falls back to the first supported language in |accept_languages_list|. If 277 // falls back to the first supported language in |accept_languages_list|. If
261 // none of the languages in |accept_language_list| is supported, the target 278 // none of the languages in |accept_language_list| is supported, the target
262 // language is empty. 279 // language is empty.
263 TEST_F(TranslateManagerTest, GetTargetLanguageAcceptLangFallback) { 280 TEST_F(TranslateManagerTest, GetTargetLanguageAcceptLangFallback) {
264 std::vector<std::string> accept_language_list; 281 std::vector<std::string> accept_language_list;
265 282
266 // Ensure locale is set to a not-supported language. 283 // Ensure locale is set to a not-supported language.
(...skipping 183 matching lines...) Expand 10 before | Expand all | Expand 10 after
450 // 0.79 and lower than 0.8 and the probability threshold is lower than both 467 // 0.79 and lower than 0.8 and the probability threshold is lower than both
451 // the one with "fr" (0.6) and "pt-PT" (0.4). 468 // the one with "fr" (0.6) and "pt-PT" (0.4).
452 EXPECT_TRUE(CallLanguageInULP("fr")); 469 EXPECT_TRUE(CallLanguageInULP("fr"));
453 EXPECT_TRUE(CallLanguageInULP("pt")); 470 EXPECT_TRUE(CallLanguageInULP("pt"));
454 EXPECT_FALSE(CallLanguageInULP("zh-TW")); 471 EXPECT_FALSE(CallLanguageInULP("zh-TW"));
455 } 472 }
456 473
457 } // namespace testing 474 } // namespace testing
458 475
459 } // namespace translate 476 } // namespace translate
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698