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

Side by Side Diff: chrome/browser/profiles/profile_downloader_unittest.cc

Issue 257773002: Use new people.get api instead of oauth2/v1/userinfo. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fix PD tests Created 6 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 | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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 "chrome/browser/profiles/profile_downloader.h" 5 #include "chrome/browser/profiles/profile_downloader.h"
6 6
7 #include "base/json/json_reader.h"
8 #include "base/memory/scoped_ptr.h"
9 #include "base/strings/string_piece.h"
7 #include "base/strings/utf_string_conversions.h" 10 #include "base/strings/utf_string_conversions.h"
11 #include "base/values.h"
8 #include "testing/gtest/include/gtest/gtest.h" 12 #include "testing/gtest/include/gtest/gtest.h"
9 13
10 namespace { 14 namespace {
11 15
12 std::string GetJSonData(const std::string& full_name, 16 scoped_ptr<base::DictionaryValue> GetJSonData(const std::string& full_name,
noms (inactive) 2014/04/25 17:07:40 Can you do something here like in the ProfileDownl
Roger Tawa OOO till Jul 10th 2014/04/28 20:44:12 Done.
13 const std::string& given_name, 17 const std::string& given_name,
14 const std::string& url, 18 const std::string& url,
15 const std::string& locale) { 19 const std::string& locale) {
16 std::stringstream stream; 20 std::stringstream stream;
17 bool started = false; 21 bool started = false;
18 22
19 stream << "{ "; 23 stream << "{ ";
20 if (!full_name.empty()) { 24 if (!full_name.empty()) {
21 stream << "\"name\": \"" << full_name << "\""; 25 stream << "\"displayName\": \"" << full_name << "\"";
22 started = true; 26 started = true;
23 } 27 }
24 if (!given_name.empty()) { 28 if (!given_name.empty()) {
25 stream << (started ? ", " : "") << "\"given_name\": \"" << given_name 29 stream << (started ? ", " : "") << "\"name\": {";
26 << "\""; 30 stream << "\"givenName\": \"" << given_name
31 << "\"}";
27 started = true; 32 started = true;
28 } 33 }
29 if (!url.empty()) { 34 if (!url.empty()) {
30 stream << (started ? ", " : "") << "\"picture\": \"" << url << "\""; 35 stream << (started ? ", " : "") << "\"image\": {";
36 stream << "\"url\": \"" << url << "\"}";
31 started = true; 37 started = true;
32 } 38 }
33 39
34 if (!locale.empty()) 40 if (!locale.empty())
35 stream << (started ? ", " : "") << "\"locale\": \"" << locale << "\""; 41 stream << (started ? ", " : "") << "\"language\": \"" << locale << "\"";
36 42
37 stream << " }"; 43 stream << " }";
38 return stream.str(); 44 base::Value* value = base::JSONReader::Read(stream.str());
45 base::DictionaryValue* dict = NULL;
46 value->GetAsDictionary(&dict);
47 return make_scoped_ptr(dict);
39 } 48 }
40 49
41 } // namespace 50 } // namespace
42 51
43 class ProfileDownloaderTest : public testing::Test { 52 class ProfileDownloaderTest : public testing::Test {
44 protected: 53 protected:
45 ProfileDownloaderTest() { 54 ProfileDownloaderTest() {
46 } 55 }
47 56
48 virtual ~ProfileDownloaderTest() { 57 virtual ~ProfileDownloaderTest() {
49 } 58 }
50 59
51 void VerifyWithAccountData(const std::string& full_name, 60 void VerifyWithAccountData(const std::string& full_name,
52 const std::string& given_name, 61 const std::string& given_name,
53 const std::string& url, 62 const std::string& url,
54 const std::string& expected_url, 63 const std::string& expected_url,
55 const std::string& locale, 64 const std::string& locale,
56 bool is_valid) { 65 bool is_valid) {
57 base::string16 parsed_full_name; 66 base::string16 parsed_full_name;
58 base::string16 parsed_given_name; 67 base::string16 parsed_given_name;
59 std::string parsed_url; 68 std::string parsed_url;
60 std::string parsed_locale; 69 std::string parsed_locale;
70 scoped_ptr<base::DictionaryValue> dict(
71 GetJSonData(full_name, given_name, url, locale));
61 bool result = ProfileDownloader::ParseProfileJSON( 72 bool result = ProfileDownloader::ParseProfileJSON(
62 GetJSonData(full_name, given_name, url, locale), 73 dict.get(),
63 &parsed_full_name, 74 &parsed_full_name,
64 &parsed_given_name, 75 &parsed_given_name,
65 &parsed_url, 76 &parsed_url,
66 32, 77 32,
67 &parsed_locale); 78 &parsed_locale);
68 EXPECT_EQ(is_valid, result); 79 EXPECT_EQ(is_valid, result);
69 std::string parsed_full_name_utf8 = base::UTF16ToUTF8(parsed_full_name); 80 std::string parsed_full_name_utf8 = base::UTF16ToUTF8(parsed_full_name);
70 std::string parsed_given_name_utf8 = base::UTF16ToUTF8(parsed_given_name); 81 std::string parsed_given_name_utf8 = base::UTF16ToUTF8(parsed_given_name);
71 82
72 EXPECT_EQ(full_name, parsed_full_name_utf8); 83 EXPECT_EQ(full_name, parsed_full_name_utf8);
(...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after
163 // Not default G+ photo 174 // Not default G+ photo
164 EXPECT_FALSE(ProfileDownloader::IsDefaultProfileImageURL( 175 EXPECT_FALSE(ProfileDownloader::IsDefaultProfileImageURL(
165 "https://example.com/-4/AAAAAAAAAAI/AAAAAAAAAAA/G/photo.jpg")); 176 "https://example.com/-4/AAAAAAAAAAI/AAAAAAAAAAA/G/photo.jpg"));
166 // Not default with 6 components 177 // Not default with 6 components
167 EXPECT_FALSE(ProfileDownloader::IsDefaultProfileImageURL( 178 EXPECT_FALSE(ProfileDownloader::IsDefaultProfileImageURL(
168 "https://example.com/-4/AAAAAAAAAAI/AAAAAAAAACQ/Efg/photo.jpg")); 179 "https://example.com/-4/AAAAAAAAAAI/AAAAAAAAACQ/Efg/photo.jpg"));
169 // Not default with 7 components 180 // Not default with 7 components
170 EXPECT_FALSE(ProfileDownloader::IsDefaultProfileImageURL( 181 EXPECT_FALSE(ProfileDownloader::IsDefaultProfileImageURL(
171 "https://example.com/-4/AAAAAAAAAAI/AAAAAAAAACQ/Efg/s32-c/photo.jpg")); 182 "https://example.com/-4/AAAAAAAAAAI/AAAAAAAAACQ/Efg/s32-c/photo.jpg"));
172 } 183 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698