Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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_prefs.h" | 5 #include "components/translate/core/browser/translate_prefs.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 #include <string> | 8 #include <string> |
| 9 #include <utility> | 9 #include <utility> |
| 10 #include <vector> | 10 #include <vector> |
| (...skipping 201 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 212 | 212 |
| 213 update.AddDenialTime(now_); | 213 update.AddDenialTime(now_); |
| 214 EXPECT_EQ(update.GetOldestDenialTime(), | 214 EXPECT_EQ(update.GetOldestDenialTime(), |
| 215 now_ - base::TimeDelta::FromMinutes(3)); | 215 now_ - base::TimeDelta::FromMinutes(3)); |
| 216 | 216 |
| 217 update.AddDenialTime(now_); | 217 update.AddDenialTime(now_); |
| 218 EXPECT_EQ(update.GetOldestDenialTime(), | 218 EXPECT_EQ(update.GetOldestDenialTime(), |
| 219 now_ - base::TimeDelta::FromMinutes(2)); | 219 now_ - base::TimeDelta::FromMinutes(2)); |
| 220 } | 220 } |
| 221 | 221 |
| 222 TEST_F(TranslatePrefTest, ULPPrefs) { | |
| 223 // Mock the pref. | |
| 224 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.
| |
| 225 base::ListValue* list = nullptr; | |
| 226 base::DictionaryValue* lp = nullptr; | |
| 227 | |
| 228 // Mock the reading | |
| 229 list = new base::ListValue(); | |
| 230 | |
| 231 // The first pair | |
| 232 lp = new base::DictionaryValue(); | |
| 233 lp->SetString("language", "en"); | |
| 234 lp->SetDouble("probability", 0.5); | |
| 235 list->Append(lp); | |
| 236 | |
| 237 // The second pair | |
| 238 lp = new base::DictionaryValue(); | |
| 239 lp->SetString("language", "fr"); | |
| 240 lp->SetDouble("probability", 0.7); | |
| 241 list->Append(lp); | |
| 242 | |
| 243 base::DictionaryValue* reading = new base::DictionaryValue(); | |
| 244 reading->SetDouble("confidence", 0.8); | |
| 245 reading->Set("items", list); | |
| 246 profile.Set("reading", reading); | |
| 247 | |
| 248 // Mock the writing | |
| 249 // For writing, let's introduce some problem in the data | |
| 250 list = new base::ListValue(); | |
| 251 | |
| 252 // The first writing list, no probability, won't be counted. | |
| 253 lp = new base::DictionaryValue(); | |
| 254 lp->SetString("language", "th"); | |
| 255 list->Append(lp); | |
| 256 | |
| 257 // The second one is OK, will be counted | |
| 258 lp = new base::DictionaryValue(); | |
| 259 lp->SetString("language", "zh-TW"); | |
| 260 lp->SetDouble("probability", 0.4); | |
| 261 list->Append(lp); | |
| 262 | |
| 263 // The third one has no language nor probability, won't be counted. | |
| 264 list->Append(new base::DictionaryValue()); | |
| 265 | |
| 266 // The forth one is OK, will be counted | |
| 267 lp = new base::DictionaryValue(); | |
| 268 lp->SetString("language", "pt-BR"); | |
| 269 lp->SetDouble("probability", 0.1); | |
| 270 list->Append(lp); | |
| 271 | |
| 272 // The fifth one has no language, won't be counted. | |
| 273 lp = new base::DictionaryValue(); | |
| 274 lp->SetDouble("probability", 0.05); | |
| 275 list->Append(lp); | |
| 276 | |
| 277 base::DictionaryValue* writing = new base::DictionaryValue(); | |
| 278 writing->SetDouble("confidence", 0.3); | |
| 279 writing->Set("items", list); | |
| 280 profile.Set("writing", writing); | |
| 281 | |
| 282 // Mock the settings. | |
| 283 list = new base::ListValue(); | |
| 284 list->AppendString("iw"); | |
| 285 list->AppendString("pt-PT"); | |
| 286 list->AppendString("zh"); | |
| 287 profile.Set("settings", list); | |
| 288 | |
| 289 prefs_->Set(TranslatePrefs::kPrefLanguageProfile, profile); | |
| 290 | |
| 291 TranslatePrefs::LanguageProbabilityList rlist; | |
| 292 EXPECT_EQ(0.8, translate_prefs_->GetReadingFromUserLanguageProfile(&rlist)); | |
| 293 EXPECT_EQ(2UL, rlist.size()); | |
| 294 EXPECT_EQ("en", rlist[0].first); | |
| 295 EXPECT_EQ(0.5, rlist[0].second); | |
| 296 EXPECT_EQ("fr", rlist[1].first); | |
| 297 EXPECT_EQ(0.7, rlist[1].second); | |
| 298 | |
| 299 TranslatePrefs::LanguageProbabilityList wlist; | |
| 300 EXPECT_EQ(0.3, translate_prefs_->GetWritingFromUserLanguageProfile(&wlist)); | |
| 301 EXPECT_EQ(2UL, wlist.size()); | |
| 302 EXPECT_EQ("zh-TW", wlist[0].first); | |
| 303 EXPECT_EQ(0.4, wlist[0].second); | |
| 304 EXPECT_EQ("pt-BR", wlist[1].first); | |
| 305 EXPECT_EQ(0.1, wlist[1].second); | |
| 306 | |
| 307 std::vector<std::string> slist; | |
| 308 EXPECT_EQ(3, translate_prefs_->GetUniversialLanguageSettings(&slist)); | |
| 309 EXPECT_EQ("iw", slist[0]); | |
| 310 EXPECT_EQ("pt-PT", slist[1]); | |
| 311 EXPECT_EQ("zh", slist[2]); | |
| 312 } | |
| 313 | |
| 222 } // namespace translate | 314 } // namespace translate |
| OLD | NEW |