| Index: chrome/browser/profiles/profile_downloader_unittest.cc
|
| diff --git a/chrome/browser/profiles/profile_downloader_unittest.cc b/chrome/browser/profiles/profile_downloader_unittest.cc
|
| index 11646d34984bdb8d7ba3dd672ff00bea6a7cc33e..99c1c75e3d6990d4af13376deffd253bc62f617c 100644
|
| --- a/chrome/browser/profiles/profile_downloader_unittest.cc
|
| +++ b/chrome/browser/profiles/profile_downloader_unittest.cc
|
| @@ -9,14 +9,26 @@
|
|
|
| namespace {
|
|
|
| -std::string GetJSonData(const std::string& name, const std::string& url) {
|
| +std::string GetJSonData(const std::string& name,
|
| + const std::string& url,
|
| + const std::string& locale) {
|
| std::stringstream stream;
|
| + bool started = false;
|
| +
|
| stream << "{ ";
|
| - if (!name.empty())
|
| - stream << "\"name\": \"" << name << "\", ";
|
| - if (!url.empty())
|
| - stream << "\"picture\": \"" << url << "\", ";
|
| - stream << "\"locale\": \"en-US\" }";
|
| + if (!name.empty()) {
|
| + stream << "\"name\": \"" << name << "\"";
|
| + started = true;
|
| + }
|
| + if (!url.empty()) {
|
| + stream << (started ? ", " : "") << "\"picture\": \"" << url << "\"";
|
| + started = true;
|
| + }
|
| +
|
| + if (!locale.empty())
|
| + stream << (started ? ", " : "") << "\"locale\": \"" << locale << "\"";
|
| +
|
| + stream << " }";
|
| return stream.str();
|
| }
|
|
|
| @@ -30,58 +42,91 @@ class ProfileDownloaderTest : public testing::Test {
|
| virtual ~ProfileDownloaderTest() {
|
| }
|
|
|
| - void VerifyWithNameAndURL(const std::string& name,
|
| - const std::string& url,
|
| - const std::string& expected_url,
|
| - bool is_valid) {
|
| + void VerifyWithAccountData(const std::string& name,
|
| + const std::string& url,
|
| + const std::string& expected_url,
|
| + const std::string& locale,
|
| + bool is_valid) {
|
| string16 parsed_name;
|
| std::string parsed_url;
|
| - bool result = ProfileDownloader::GetProfileNameAndImageURL(
|
| - GetJSonData(name, url), &parsed_name, &parsed_url, 32);
|
| + std::string parsed_locale;
|
| + bool result =
|
| + ProfileDownloader::ParseProfileJSON(GetJSonData(name, url, locale),
|
| + &parsed_name,
|
| + &parsed_url,
|
| + 32,
|
| + &parsed_locale);
|
| EXPECT_EQ(is_valid, result);
|
| std::string parsed_name_utf8 = UTF16ToUTF8(parsed_name);
|
| EXPECT_EQ(name, parsed_name_utf8);
|
| EXPECT_EQ(expected_url, parsed_url);
|
| + EXPECT_EQ(locale, parsed_locale);
|
| }
|
| };
|
|
|
| TEST_F(ProfileDownloaderTest, ParseData) {
|
| // URL without size specified.
|
| - VerifyWithNameAndURL(
|
| + VerifyWithAccountData(
|
| "Pat Smith",
|
| "https://example.com/--Abc/AAAAAAAAAAI/AAAAAAAAACQ/Efg/photo.jpg",
|
| "https://example.com/--Abc/AAAAAAAAAAI/AAAAAAAAACQ/Efg/s32-c/photo.jpg",
|
| + "en-US",
|
| true);
|
|
|
| // URL with size specified.
|
| - VerifyWithNameAndURL(
|
| + VerifyWithAccountData(
|
| "Pat Smith",
|
| "http://lh0.ggpht.com/-abcd1aBCDEf/AAAA/AAA_A/abc12/s64-c/1234567890.jpg",
|
| "http://lh0.ggpht.com/-abcd1aBCDEf/AAAA/AAA_A/abc12/s32-c/1234567890.jpg",
|
| + "en-US",
|
| true);
|
|
|
| // URL with unknown format.
|
| - VerifyWithNameAndURL(
|
| + VerifyWithAccountData("Pat Smith",
|
| + "http://lh0.ggpht.com/-abcd1aBCDEf/AAAA/AAA_A/",
|
| + "http://lh0.ggpht.com/-abcd1aBCDEf/AAAA/AAA_A/",
|
| + "en-US",
|
| + true);
|
| +
|
| + // Try different locales.
|
| + // URL with size specified.
|
| + VerifyWithAccountData(
|
| "Pat Smith",
|
| - "http://lh0.ggpht.com/-abcd1aBCDEf/AAAA/AAA_A/",
|
| - "http://lh0.ggpht.com/-abcd1aBCDEf/AAAA/AAA_A/",
|
| + "http://lh0.ggpht.com/-abcd1aBCDEf/AAAA/AAA_A/abc12/s64-c/1234567890.jpg",
|
| + "http://lh0.ggpht.com/-abcd1aBCDEf/AAAA/AAA_A/abc12/s32-c/1234567890.jpg",
|
| + "jp",
|
| true);
|
|
|
| + // URL with unknown format.
|
| + VerifyWithAccountData("Pat Smith",
|
| + "http://lh0.ggpht.com/-abcd1aBCDEf/AAAA/AAA_A/",
|
| + "http://lh0.ggpht.com/-abcd1aBCDEf/AAAA/AAA_A/",
|
| + "fr",
|
| + true);
|
| +
|
| // Data with only name.
|
| - VerifyWithNameAndURL("Pat Smith", std::string(), std::string(), true);
|
| + VerifyWithAccountData(
|
| + "Pat Smith", std::string(), std::string(), std::string(), true);
|
|
|
| // Data with only URL.
|
| - VerifyWithNameAndURL(
|
| + VerifyWithAccountData(
|
| std::string(),
|
| "https://example.com/--Abc/AAAAAAAAAAI/AAAAAAAAACQ/Efg/photo.jpg",
|
| "https://example.com/--Abc/AAAAAAAAAAI/AAAAAAAAACQ/Efg/s32-c/photo.jpg",
|
| + std::string(),
|
| true);
|
|
|
| - // Data without name or URL.
|
| - VerifyWithNameAndURL(std::string(), std::string(), std::string(), false);
|
| + // Data with only locale.
|
| + VerifyWithAccountData(
|
| + std::string(), std::string(), std::string(), "fr", false);
|
| +
|
| + // Data without name or URL or locale.
|
| + VerifyWithAccountData(
|
| + std::string(), std::string(), std::string(), std::string(), false);
|
|
|
| // Data with an invalid URL.
|
| - VerifyWithNameAndURL(std::string(), "invalid url", std::string(), false);
|
| + VerifyWithAccountData(
|
| + std::string(), "invalid url", std::string(), std::string(), false);
|
| }
|
|
|
| TEST_F(ProfileDownloaderTest, DefaultURL) {
|
|
|