Chromium Code Reviews| 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 |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..663004be38f85c5f7e8f3db571adad1cafe0f759 |
| --- /dev/null |
| +++ b/chrome/browser/profiles/profile_downloader_unittest.cc |
| @@ -0,0 +1,76 @@ |
| +// Copyright (c) 2011 The Chromium Authors. All rights reserved. |
| +// Use of this source code is governed by a BSD-style license that can be |
| +// found in the LICENSE file. |
| + |
| +#include "chrome/browser/profiles/profile_downloader.h" |
| + |
| +#include "base/utf_string_conversions.h" |
| +#include "testing/gtest/include/gtest/gtest.h" |
| + |
| +namespace { |
| + |
| +std::string GetJSonData(const std::string& name, const std::string& url) { |
| + std::stringstream stream; |
| + stream << "{ "; |
| + if (!name.empty()) |
| + stream << "\"name\": \"" << name << "\", "; |
| + if (!url.empty()) |
| + stream << "\"picture\": \"" << url << "\", "; |
| + stream << "\"locale\": \"en-US\" }"; |
| + return stream.str(); |
| +} |
| + |
|
Ivan Korotkov
2011/12/04 15:08:52
Please add tests for IsDefaultImageURL as well.
sail
2011/12/05 19:26:12
Done.
|
| +void VerifyWithNameAndURL(const std::string& name, |
| + const std::string& url, |
| + const std::string& expected_url, |
| + bool is_valid) { |
| + string16 parsed_name; |
| + std::string parsed_url; |
| + bool result = ProfileDownloader::GetProfileNameAndImageURL( |
| + GetJSonData(name, url), &parsed_name, &parsed_url, 32); |
| + 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); |
| +} |
| + |
| +} // namespace |
| + |
| +TEST(ProfileDownloaderTest, ParseData) { |
| + // URL without size specified. |
| + VerifyWithNameAndURL( |
| + "Pat Smith", |
| + "https://example.com/--Abc/AAAAAAAAAAI/AAAAAAAAACQ/Efg/photo.jpg", |
| + "https://example.com/--Abc/AAAAAAAAAAI/AAAAAAAAACQ/Efg/s32-c/photo.jpg", |
| + true); |
| + |
| + // URL with size specified. |
| + VerifyWithNameAndURL( |
| + "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", |
| + true); |
| + |
| + // URL with unknown format. |
| + VerifyWithNameAndURL( |
| + "Pat Smith", |
| + "http://lh0.ggpht.com/-abcd1aBCDEf/AAAA/AAA_A/", |
| + "http://lh0.ggpht.com/-abcd1aBCDEf/AAAA/AAA_A/", |
| + true); |
| + |
| + // Data with only name. |
| + VerifyWithNameAndURL("Pat Smith", "", "", true); |
| + |
| + // Data with only URL. |
| + VerifyWithNameAndURL( |
| + "", |
| + "https://example.com/--Abc/AAAAAAAAAAI/AAAAAAAAACQ/Efg/photo.jpg", |
| + "https://example.com/--Abc/AAAAAAAAAAI/AAAAAAAAACQ/Efg/s32-c/photo.jpg", |
| + true); |
| + |
| + // Data without name or URL. |
| + VerifyWithNameAndURL("", "", "", false); |
| + |
| + // Data with an invalid URL. |
| + VerifyWithNameAndURL( "Pat Smith", "invalid url", "", false); |
| +} |