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

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

Issue 2782553004: Move TestingPrefService to use unique_ptr<Value> (Closed)
Patch Set: comments 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 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 222 matching lines...) Expand 10 before | Expand all | Expand 10 after
233 int error_code = 0; 233 int error_code = 0;
234 std::string error_msg; 234 std::string error_msg;
235 int error_line = 0; 235 int error_line = 0;
236 int error_column = 0; 236 int error_column = 0;
237 std::unique_ptr<base::Value> profile(base::JSONReader::ReadAndReturnError( 237 std::unique_ptr<base::Value> profile(base::JSONReader::ReadAndReturnError(
238 json1, 0, &error_code, &error_msg, &error_line, &error_column)); 238 json1, 0, &error_code, &error_msg, &error_line, &error_column));
239 ASSERT_EQ(0, error_code) << error_msg << " at " << error_line << ":" 239 ASSERT_EQ(0, error_code) << error_msg << " at " << error_line << ":"
240 << error_column << std::endl 240 << error_column << std::endl
241 << json1; 241 << json1;
242 242
243 prefs_->SetUserPref(TranslatePrefs::kPrefLanguageProfile, profile.release()); 243 prefs_->SetUserPref(TranslatePrefs::kPrefLanguageProfile, std::move(profile));
244 244
245 TranslatePrefs::LanguageAndProbabilityList list; 245 TranslatePrefs::LanguageAndProbabilityList list;
246 EXPECT_EQ(0.8, translate_prefs_->GetReadingFromUserLanguageProfile(&list)); 246 EXPECT_EQ(0.8, translate_prefs_->GetReadingFromUserLanguageProfile(&list));
247 EXPECT_EQ(2UL, list.size()); 247 EXPECT_EQ(2UL, list.size());
248 // the order in the ULP is wrong, and our code will sort it and make the 248 // the order in the ULP is wrong, and our code will sort it and make the
249 // larger 249 // larger
250 // one first. 250 // one first.
251 EXPECT_EQ("fr", list[0].first); 251 EXPECT_EQ("fr", list[0].first);
252 EXPECT_EQ(0.6, list[0].second); 252 EXPECT_EQ(0.6, list[0].second);
253 EXPECT_EQ("en", list[1].first); // the "en-AU" should be normalize to "en" 253 EXPECT_EQ("en", list[1].first); // the "en-AU" should be normalize to "en"
(...skipping 27 matching lines...) Expand all
281 "}"; 281 "}";
282 282
283 profile.reset(base::JSONReader::ReadAndReturnError(json2, 0, &error_code, 283 profile.reset(base::JSONReader::ReadAndReturnError(json2, 0, &error_code,
284 &error_msg, &error_line, 284 &error_msg, &error_line,
285 &error_column) 285 &error_column)
286 .release()); 286 .release());
287 ASSERT_EQ(0, error_code) << error_msg << " at " << error_line << ":" 287 ASSERT_EQ(0, error_code) << error_msg << " at " << error_line << ":"
288 << error_column << std::endl 288 << error_column << std::endl
289 << json2; 289 << json2;
290 290
291 prefs_->SetUserPref(TranslatePrefs::kPrefLanguageProfile, profile.release()); 291 prefs_->SetUserPref(TranslatePrefs::kPrefLanguageProfile, std::move(profile));
292 292
293 list.clear(); 293 list.clear();
294 EXPECT_EQ(0.3, translate_prefs_->GetReadingFromUserLanguageProfile(&list)); 294 EXPECT_EQ(0.3, translate_prefs_->GetReadingFromUserLanguageProfile(&list));
295 EXPECT_EQ(2UL, list.size()); 295 EXPECT_EQ(2UL, list.size());
296 EXPECT_EQ("zh-TW", list[0].first); 296 EXPECT_EQ("zh-TW", list[0].first);
297 EXPECT_EQ(0.4, list[0].second); 297 EXPECT_EQ(0.4, list[0].second);
298 EXPECT_EQ("pt", list[1].first); // the "pt-BR" should be normalize to "pt" 298 EXPECT_EQ("pt", list[1].first); // the "pt-BR" should be normalize to "pt"
299 EXPECT_EQ(0.1, list[1].second); 299 EXPECT_EQ(0.1, list[1].second);
300 300
301 // Case 3: Language Code normalization and reordering. 301 // Case 3: Language Code normalization and reordering.
(...skipping 16 matching lines...) Expand all
318 " }\n" 318 " }\n"
319 "}"; 319 "}";
320 profile.reset(base::JSONReader::ReadAndReturnError(json3, 0, &error_code, 320 profile.reset(base::JSONReader::ReadAndReturnError(json3, 0, &error_code,
321 &error_msg, &error_line, 321 &error_msg, &error_line,
322 &error_column) 322 &error_column)
323 .release()); 323 .release());
324 ASSERT_EQ(0, error_code) << error_msg << " at " << error_line << ":" 324 ASSERT_EQ(0, error_code) << error_msg << " at " << error_line << ":"
325 << error_column << std::endl 325 << error_column << std::endl
326 << json3; 326 << json3;
327 327
328 prefs_->SetUserPref(TranslatePrefs::kPrefLanguageProfile, profile.release()); 328 prefs_->SetUserPref(TranslatePrefs::kPrefLanguageProfile, std::move(profile));
329 329
330 list.clear(); 330 list.clear();
331 EXPECT_EQ(0.8, translate_prefs_->GetReadingFromUserLanguageProfile(&list)); 331 EXPECT_EQ(0.8, translate_prefs_->GetReadingFromUserLanguageProfile(&list));
332 EXPECT_EQ(2UL, list.size()); 332 EXPECT_EQ(2UL, list.size());
333 EXPECT_EQ("en", list[0].first); // en-US and en-GB will be normalize into en 333 EXPECT_EQ("en", list[0].first); // en-US and en-GB will be normalize into en
334 EXPECT_EQ(0.6, 334 EXPECT_EQ(0.6,
335 list[0].second); // and their probability will add to gether be 0.6 335 list[0].second); // and their probability will add to gether be 0.6
336 EXPECT_EQ("fr", list[1].first); // fr will move down to the 2nd one 336 EXPECT_EQ("fr", list[1].first); // fr will move down to the 2nd one
337 EXPECT_EQ(0.4, list[1].second); 337 EXPECT_EQ(0.4, list[1].second);
338 } 338 }
339 339
340 } // namespace translate 340 } // namespace translate
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698