OLD | NEW |
---|---|
(Empty) | |
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 | |
3 // found in the LICENSE file. | |
4 | |
5 #include "chrome/browser/profiles/profile_downloader.h" | |
6 | |
7 #include "base/utf_string_conversions.h" | |
8 #include "testing/gtest/include/gtest/gtest.h" | |
9 | |
10 namespace { | |
11 | |
12 std::string GetJSonData(const std::string& name, const std::string& url) { | |
13 std::stringstream stream; | |
14 stream << "{ "; | |
15 if (!name.empty()) | |
16 stream << "\"name\": \"" << name << "\", "; | |
17 if (!url.empty()) | |
18 stream << "\"picture\": \"" << url << "\", "; | |
19 stream << "\"locale\": \"en-US\" }"; | |
20 return stream.str(); | |
21 } | |
22 | |
Ivan Korotkov
2011/12/04 15:08:52
Please add tests for IsDefaultImageURL as well.
sail
2011/12/05 19:26:12
Done.
| |
23 void VerifyWithNameAndURL(const std::string& name, | |
24 const std::string& url, | |
25 const std::string& expected_url, | |
26 bool is_valid) { | |
27 string16 parsed_name; | |
28 std::string parsed_url; | |
29 bool result = ProfileDownloader::GetProfileNameAndImageURL( | |
30 GetJSonData(name, url), &parsed_name, &parsed_url, 32); | |
31 EXPECT_EQ(is_valid, result); | |
32 std::string parsed_name_utf8 = UTF16ToUTF8(parsed_name); | |
33 EXPECT_EQ(name, parsed_name_utf8); | |
34 EXPECT_EQ(expected_url, parsed_url); | |
35 } | |
36 | |
37 } // namespace | |
38 | |
39 TEST(ProfileDownloaderTest, ParseData) { | |
40 // URL without size specified. | |
41 VerifyWithNameAndURL( | |
42 "Pat Smith", | |
43 "https://example.com/--Abc/AAAAAAAAAAI/AAAAAAAAACQ/Efg/photo.jpg", | |
44 "https://example.com/--Abc/AAAAAAAAAAI/AAAAAAAAACQ/Efg/s32-c/photo.jpg", | |
45 true); | |
46 | |
47 // URL with size specified. | |
48 VerifyWithNameAndURL( | |
49 "Pat Smith", | |
50 "http://lh0.ggpht.com/-abcd1aBCDEf/AAAA/AAA_A/abc12/s64-c/1234567890.jpg", | |
51 "http://lh0.ggpht.com/-abcd1aBCDEf/AAAA/AAA_A/abc12/s32-c/1234567890.jpg", | |
52 true); | |
53 | |
54 // URL with unknown format. | |
55 VerifyWithNameAndURL( | |
56 "Pat Smith", | |
57 "http://lh0.ggpht.com/-abcd1aBCDEf/AAAA/AAA_A/", | |
58 "http://lh0.ggpht.com/-abcd1aBCDEf/AAAA/AAA_A/", | |
59 true); | |
60 | |
61 // Data with only name. | |
62 VerifyWithNameAndURL("Pat Smith", "", "", true); | |
63 | |
64 // Data with only URL. | |
65 VerifyWithNameAndURL( | |
66 "", | |
67 "https://example.com/--Abc/AAAAAAAAAAI/AAAAAAAAACQ/Efg/photo.jpg", | |
68 "https://example.com/--Abc/AAAAAAAAAAI/AAAAAAAAACQ/Efg/s32-c/photo.jpg", | |
69 true); | |
70 | |
71 // Data without name or URL. | |
72 VerifyWithNameAndURL("", "", "", false); | |
73 | |
74 // Data with an invalid URL. | |
75 VerifyWithNameAndURL( "Pat Smith", "invalid url", "", false); | |
76 } | |
OLD | NEW |