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

Unified Diff: components/translate/core/browser/translate_prefs_unittest.cc

Issue 2200493002: using ulp to improve TranslateManager GetTargetLanguage() and InitiateTranslation() (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: add unit tests Created 4 years, 5 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 side-by-side diff with in-line comments
Download patch
Index: components/translate/core/browser/translate_prefs_unittest.cc
diff --git a/components/translate/core/browser/translate_prefs_unittest.cc b/components/translate/core/browser/translate_prefs_unittest.cc
index 881718d92d8e193fe97b1931146b68d3ed47de57..bdd1e770b03e10f8a17a09344353bb6cba252ad9 100644
--- a/components/translate/core/browser/translate_prefs_unittest.cc
+++ b/components/translate/core/browser/translate_prefs_unittest.cc
@@ -219,4 +219,96 @@ TEST_F(TranslatePrefTest, DenialTimeUpdate_SlidingWindow) {
now_ - base::TimeDelta::FromMinutes(2));
}
+TEST_F(TranslatePrefTest, ULPPrefs) {
+ // Mock the pref.
+ base::DictionaryValue profile;
groby-ooo-7-16 2016/08/02 00:38:21 I'd recommend building this as JSON, and then usin
ftang 2016/08/03 02:01:18 Done.
+ base::ListValue* list = nullptr;
+ base::DictionaryValue* lp = nullptr;
+
+ // Mock the reading
+ list = new base::ListValue();
+
+ // The first pair
+ lp = new base::DictionaryValue();
+ lp->SetString("language", "en");
+ lp->SetDouble("probability", 0.5);
+ list->Append(lp);
+
+ // The second pair
+ lp = new base::DictionaryValue();
+ lp->SetString("language", "fr");
+ lp->SetDouble("probability", 0.7);
+ list->Append(lp);
+
+ base::DictionaryValue* reading = new base::DictionaryValue();
+ reading->SetDouble("confidence", 0.8);
+ reading->Set("items", list);
+ profile.Set("reading", reading);
+
+ // Mock the writing
+ // For writing, let's introduce some problem in the data
+ list = new base::ListValue();
+
+ // The first writing list, no probability, won't be counted.
+ lp = new base::DictionaryValue();
+ lp->SetString("language", "th");
+ list->Append(lp);
+
+ // The second one is OK, will be counted
+ lp = new base::DictionaryValue();
+ lp->SetString("language", "zh-TW");
+ lp->SetDouble("probability", 0.4);
+ list->Append(lp);
+
+ // The third one has no language nor probability, won't be counted.
+ list->Append(new base::DictionaryValue());
+
+ // The forth one is OK, will be counted
+ lp = new base::DictionaryValue();
+ lp->SetString("language", "pt-BR");
+ lp->SetDouble("probability", 0.1);
+ list->Append(lp);
+
+ // The fifth one has no language, won't be counted.
+ lp = new base::DictionaryValue();
+ lp->SetDouble("probability", 0.05);
+ list->Append(lp);
+
+ base::DictionaryValue* writing = new base::DictionaryValue();
+ writing->SetDouble("confidence", 0.3);
+ writing->Set("items", list);
+ profile.Set("writing", writing);
+
+ // Mock the settings.
+ list = new base::ListValue();
+ list->AppendString("iw");
+ list->AppendString("pt-PT");
+ list->AppendString("zh");
+ profile.Set("settings", list);
+
+ prefs_->Set(TranslatePrefs::kPrefLanguageProfile, profile);
+
+ TranslatePrefs::LanguageProbabilityList rlist;
+ EXPECT_EQ(0.8, translate_prefs_->GetReadingFromUserLanguageProfile(&rlist));
+ EXPECT_EQ(2UL, rlist.size());
+ EXPECT_EQ("en", rlist[0].first);
+ EXPECT_EQ(0.5, rlist[0].second);
+ EXPECT_EQ("fr", rlist[1].first);
+ EXPECT_EQ(0.7, rlist[1].second);
+
+ TranslatePrefs::LanguageProbabilityList wlist;
+ EXPECT_EQ(0.3, translate_prefs_->GetWritingFromUserLanguageProfile(&wlist));
+ EXPECT_EQ(2UL, wlist.size());
+ EXPECT_EQ("zh-TW", wlist[0].first);
+ EXPECT_EQ(0.4, wlist[0].second);
+ EXPECT_EQ("pt-BR", wlist[1].first);
+ EXPECT_EQ(0.1, wlist[1].second);
+
+ std::vector<std::string> slist;
+ EXPECT_EQ(3, translate_prefs_->GetUniversialLanguageSettings(&slist));
+ EXPECT_EQ("iw", slist[0]);
+ EXPECT_EQ("pt-PT", slist[1]);
+ EXPECT_EQ("zh", slist[2]);
+}
+
} // namespace translate

Powered by Google App Engine
This is Rietveld 408576698