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

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

Issue 23095006: If user profile doesn't contain language setting, default to his Google account settings. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fix build. Created 7 years, 3 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 (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/strings/utf_string_conversions.h" 7 #include "base/strings/utf_string_conversions.h"
8 #include "testing/gtest/include/gtest/gtest.h" 8 #include "testing/gtest/include/gtest/gtest.h"
9 9
10 namespace { 10 namespace {
11 11
12 std::string GetJSonData(const std::string& name, const std::string& url) { 12 std::string GetJSonData(const std::string& name,
13 const std::string& url,
14 const std::string& locale) {
13 std::stringstream stream; 15 std::stringstream stream;
16 bool started = false;
17
14 stream << "{ "; 18 stream << "{ ";
15 if (!name.empty()) 19 if (!name.empty()) {
16 stream << "\"name\": \"" << name << "\", "; 20 stream << "\"name\": \"" << name << "\"";
17 if (!url.empty()) 21 started = true;
18 stream << "\"picture\": \"" << url << "\", "; 22 }
19 stream << "\"locale\": \"en-US\" }"; 23 if (!url.empty()) {
24 stream << (started ? ", " : "") << "\"picture\": \"" << url << "\"";
25 started = true;
26 }
27
28 if (!locale.empty())
29 stream << (started ? ", " : "") << "\"locale\": \"" << locale << "\"";
30
31 stream << " }";
20 return stream.str(); 32 return stream.str();
21 } 33 }
22 34
23 } // namespace 35 } // namespace
24 36
25 class ProfileDownloaderTest : public testing::Test { 37 class ProfileDownloaderTest : public testing::Test {
26 protected: 38 protected:
27 ProfileDownloaderTest() { 39 ProfileDownloaderTest() {
28 } 40 }
29 41
30 virtual ~ProfileDownloaderTest() { 42 virtual ~ProfileDownloaderTest() {
31 } 43 }
32 44
33 void VerifyWithNameAndURL(const std::string& name, 45 void VerifyWithAccountData(const std::string& name,
34 const std::string& url, 46 const std::string& url,
35 const std::string& expected_url, 47 const std::string& expected_url,
36 bool is_valid) { 48 const std::string& locale,
49 bool is_valid) {
37 string16 parsed_name; 50 string16 parsed_name;
38 std::string parsed_url; 51 std::string parsed_url;
39 bool result = ProfileDownloader::GetProfileNameAndImageURL( 52 std::string parsed_locale;
40 GetJSonData(name, url), &parsed_name, &parsed_url, 32); 53 bool result =
54 ProfileDownloader::ParseProfileJSON(GetJSonData(name, url, locale),
55 &parsed_name,
56 &parsed_url,
57 32,
58 &parsed_locale);
41 EXPECT_EQ(is_valid, result); 59 EXPECT_EQ(is_valid, result);
42 std::string parsed_name_utf8 = UTF16ToUTF8(parsed_name); 60 std::string parsed_name_utf8 = UTF16ToUTF8(parsed_name);
43 EXPECT_EQ(name, parsed_name_utf8); 61 EXPECT_EQ(name, parsed_name_utf8);
44 EXPECT_EQ(expected_url, parsed_url); 62 EXPECT_EQ(expected_url, parsed_url);
63 EXPECT_EQ(locale, parsed_locale);
45 } 64 }
46 }; 65 };
47 66
48 TEST_F(ProfileDownloaderTest, ParseData) { 67 TEST_F(ProfileDownloaderTest, ParseData) {
49 // URL without size specified. 68 // URL without size specified.
50 VerifyWithNameAndURL( 69 VerifyWithAccountData(
51 "Pat Smith", 70 "Pat Smith",
52 "https://example.com/--Abc/AAAAAAAAAAI/AAAAAAAAACQ/Efg/photo.jpg", 71 "https://example.com/--Abc/AAAAAAAAAAI/AAAAAAAAACQ/Efg/photo.jpg",
53 "https://example.com/--Abc/AAAAAAAAAAI/AAAAAAAAACQ/Efg/s32-c/photo.jpg", 72 "https://example.com/--Abc/AAAAAAAAAAI/AAAAAAAAACQ/Efg/s32-c/photo.jpg",
73 "en-US",
54 true); 74 true);
55 75
56 // URL with size specified. 76 // URL with size specified.
57 VerifyWithNameAndURL( 77 VerifyWithAccountData(
58 "Pat Smith", 78 "Pat Smith",
59 "http://lh0.ggpht.com/-abcd1aBCDEf/AAAA/AAA_A/abc12/s64-c/1234567890.jpg", 79 "http://lh0.ggpht.com/-abcd1aBCDEf/AAAA/AAA_A/abc12/s64-c/1234567890.jpg",
60 "http://lh0.ggpht.com/-abcd1aBCDEf/AAAA/AAA_A/abc12/s32-c/1234567890.jpg", 80 "http://lh0.ggpht.com/-abcd1aBCDEf/AAAA/AAA_A/abc12/s32-c/1234567890.jpg",
81 "en-US",
61 true); 82 true);
62 83
63 // URL with unknown format. 84 // URL with unknown format.
64 VerifyWithNameAndURL( 85 VerifyWithAccountData("Pat Smith",
86 "http://lh0.ggpht.com/-abcd1aBCDEf/AAAA/AAA_A/",
87 "http://lh0.ggpht.com/-abcd1aBCDEf/AAAA/AAA_A/",
88 "en-US",
89 true);
90
91 // Try different locales.
sail 2013/09/11 19:00:38 join these two comments into one sentence?
Alexander Alekseev 2013/09/18 20:21:19 Done.
92 // URL with size specified.
93 VerifyWithAccountData(
65 "Pat Smith", 94 "Pat Smith",
66 "http://lh0.ggpht.com/-abcd1aBCDEf/AAAA/AAA_A/", 95 "http://lh0.ggpht.com/-abcd1aBCDEf/AAAA/AAA_A/abc12/s64-c/1234567890.jpg",
67 "http://lh0.ggpht.com/-abcd1aBCDEf/AAAA/AAA_A/", 96 "http://lh0.ggpht.com/-abcd1aBCDEf/AAAA/AAA_A/abc12/s32-c/1234567890.jpg",
97 "jp",
68 true); 98 true);
69 99
100 // URL with unknown format.
101 VerifyWithAccountData("Pat Smith",
102 "http://lh0.ggpht.com/-abcd1aBCDEf/AAAA/AAA_A/",
103 "http://lh0.ggpht.com/-abcd1aBCDEf/AAAA/AAA_A/",
104 "fr",
105 true);
106
70 // Data with only name. 107 // Data with only name.
71 VerifyWithNameAndURL("Pat Smith", std::string(), std::string(), true); 108 VerifyWithAccountData(
109 "Pat Smith", std::string(), std::string(), std::string(), true);
72 110
73 // Data with only URL. 111 // Data with only URL.
74 VerifyWithNameAndURL( 112 VerifyWithAccountData(
75 std::string(), 113 std::string(),
76 "https://example.com/--Abc/AAAAAAAAAAI/AAAAAAAAACQ/Efg/photo.jpg", 114 "https://example.com/--Abc/AAAAAAAAAAI/AAAAAAAAACQ/Efg/photo.jpg",
77 "https://example.com/--Abc/AAAAAAAAAAI/AAAAAAAAACQ/Efg/s32-c/photo.jpg", 115 "https://example.com/--Abc/AAAAAAAAAAI/AAAAAAAAACQ/Efg/s32-c/photo.jpg",
116 std::string(),
78 true); 117 true);
79 118
80 // Data without name or URL. 119 // Data with only locale.
81 VerifyWithNameAndURL(std::string(), std::string(), std::string(), false); 120 VerifyWithAccountData(
121 std::string(), std::string(), std::string(), "fr", false);
122
123 // Data without name or URL or locale.
124 VerifyWithAccountData(
125 std::string(), std::string(), std::string(), std::string(), false);
82 126
83 // Data with an invalid URL. 127 // Data with an invalid URL.
84 VerifyWithNameAndURL(std::string(), "invalid url", std::string(), false); 128 VerifyWithAccountData(
129 std::string(), "invalid url", std::string(), std::string(), false);
85 } 130 }
86 131
87 TEST_F(ProfileDownloaderTest, DefaultURL) { 132 TEST_F(ProfileDownloaderTest, DefaultURL) {
88 // Empty URL should be default photo 133 // Empty URL should be default photo
89 EXPECT_TRUE(ProfileDownloader::IsDefaultProfileImageURL(std::string())); 134 EXPECT_TRUE(ProfileDownloader::IsDefaultProfileImageURL(std::string()));
90 // Picasa default photo 135 // Picasa default photo
91 EXPECT_TRUE(ProfileDownloader::IsDefaultProfileImageURL( 136 EXPECT_TRUE(ProfileDownloader::IsDefaultProfileImageURL(
92 "https://example.com/-4/AAAAAAAAAAA/AAAAAAAAAAE/G/s64-c/photo.jpg")); 137 "https://example.com/-4/AAAAAAAAAAA/AAAAAAAAAAE/G/s64-c/photo.jpg"));
93 // Not default G+ photo 138 // Not default G+ photo
94 EXPECT_FALSE(ProfileDownloader::IsDefaultProfileImageURL( 139 EXPECT_FALSE(ProfileDownloader::IsDefaultProfileImageURL(
95 "https://example.com/-4/AAAAAAAAAAI/AAAAAAAAAAA/G/photo.jpg")); 140 "https://example.com/-4/AAAAAAAAAAI/AAAAAAAAAAA/G/photo.jpg"));
96 // Not default with 6 components 141 // Not default with 6 components
97 EXPECT_FALSE(ProfileDownloader::IsDefaultProfileImageURL( 142 EXPECT_FALSE(ProfileDownloader::IsDefaultProfileImageURL(
98 "https://example.com/-4/AAAAAAAAAAI/AAAAAAAAACQ/Efg/photo.jpg")); 143 "https://example.com/-4/AAAAAAAAAAI/AAAAAAAAACQ/Efg/photo.jpg"));
99 // Not default with 7 components 144 // Not default with 7 components
100 EXPECT_FALSE(ProfileDownloader::IsDefaultProfileImageURL( 145 EXPECT_FALSE(ProfileDownloader::IsDefaultProfileImageURL(
101 "https://example.com/-4/AAAAAAAAAAI/AAAAAAAAACQ/Efg/s32-c/photo.jpg")); 146 "https://example.com/-4/AAAAAAAAAAI/AAAAAAAAACQ/Efg/s32-c/photo.jpg"));
102 } 147 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698