OLD | NEW |
---|---|
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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/chromeos/gdata/gdata_contacts_service.h" | 5 #include "chrome/browser/chromeos/gdata/gdata_contacts_service.h" |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/file_path.h" | 8 #include "base/file_path.h" |
9 #include "base/file_util.h" | 9 #include "base/file_util.h" |
10 #include "base/message_loop.h" | 10 #include "base/message_loop.h" |
(...skipping 151 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
162 EXPECT_FALSE(Download("not_json.txt", base::Time(), &contacts)); | 162 EXPECT_FALSE(Download("not_json.txt", base::Time(), &contacts)); |
163 EXPECT_FALSE(Download("not_dictionary.json", base::Time(), &contacts)); | 163 EXPECT_FALSE(Download("not_dictionary.json", base::Time(), &contacts)); |
164 EXPECT_FALSE(Download("no_feed.json", base::Time(), &contacts)); | 164 EXPECT_FALSE(Download("no_feed.json", base::Time(), &contacts)); |
165 EXPECT_FALSE(Download("no_category.json", base::Time(), &contacts)); | 165 EXPECT_FALSE(Download("no_category.json", base::Time(), &contacts)); |
166 EXPECT_FALSE(Download("wrong_category.json", base::Time(), &contacts)); | 166 EXPECT_FALSE(Download("wrong_category.json", base::Time(), &contacts)); |
167 | 167 |
168 // Missing photos should be allowed, though (as this can occur in production). | 168 // Missing photos should be allowed, though (as this can occur in production). |
169 EXPECT_TRUE(Download("feed_photo_404.json", base::Time(), &contacts)); | 169 EXPECT_TRUE(Download("feed_photo_404.json", base::Time(), &contacts)); |
170 ASSERT_EQ(static_cast<size_t>(1), contacts->size()); | 170 ASSERT_EQ(static_cast<size_t>(1), contacts->size()); |
171 EXPECT_FALSE((*contacts)[0]->has_raw_untrusted_photo()); | 171 EXPECT_FALSE((*contacts)[0]->has_raw_untrusted_photo()); |
172 } | |
173 | 172 |
174 // We should report failure when we're unable to download the contact group | 173 // We should report failure when we're unable to download the contact group |
175 // feed. | 174 // feed. |
176 IN_PROC_BROWSER_TEST_F(GDataContactsServiceTest, MissingGroupsFeed) { | 175 service_->clear_cached_my_contacts_group_id_for_testing(); |
177 scoped_ptr<ScopedVector<contacts::Contact> > contacts; | |
178 service_->set_groups_feed_url_for_testing( | 176 service_->set_groups_feed_url_for_testing( |
179 test_server_.GetURL(std::string(kFeedBaseUrl) + "404")); | 177 test_server_.GetURL(std::string(kFeedBaseUrl) + "404")); |
180 EXPECT_FALSE(Download("feed.json", base::Time(), &contacts)); | 178 EXPECT_FALSE(Download("feed.json", base::Time(), &contacts)); |
181 EXPECT_TRUE(service_->cached_my_contacts_group_id_for_testing().empty()); | 179 EXPECT_TRUE(service_->cached_my_contacts_group_id_for_testing().empty()); |
182 } | |
183 | 180 |
184 // We should also fail when the "My Contacts" group isn't listed in the group | 181 // We should also fail when the "My Contacts" group isn't listed in the group |
185 // feed. | 182 // feed. |
186 IN_PROC_BROWSER_TEST_F(GDataContactsServiceTest, NoMyContactsGroup) { | 183 service_->clear_cached_my_contacts_group_id_for_testing(); |
187 scoped_ptr<ScopedVector<contacts::Contact> > contacts; | |
188 service_->set_groups_feed_url_for_testing( | 184 service_->set_groups_feed_url_for_testing( |
189 test_server_.GetURL(std::string(kFeedBaseUrl) + | 185 test_server_.GetURL(std::string(kFeedBaseUrl) + |
190 "groups_no_my_contacts.json")); | 186 "groups_no_my_contacts.json")); |
191 EXPECT_FALSE(Download("feed.json", base::Time(), &contacts)); | 187 EXPECT_FALSE(Download("feed.json", base::Time(), &contacts)); |
192 EXPECT_TRUE(service_->cached_my_contacts_group_id_for_testing().empty()); | 188 EXPECT_TRUE(service_->cached_my_contacts_group_id_for_testing().empty()); |
193 } | 189 } |
194 | 190 |
195 // Check that we're able to download an empty feed and a normal-looking feed | 191 // Check that we're able to download an empty feed and a normal-looking feed |
196 // with two regular contacts and one deleted one. | 192 // with two regular contacts and one deleted one. |
197 IN_PROC_BROWSER_TEST_F(GDataContactsServiceTest, Download) { | 193 IN_PROC_BROWSER_TEST_F(GDataContactsServiceTest, Download) { |
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
285 InitContact(base::StringPrintf("http://example.com/%d", i + 1), | 281 InitContact(base::StringPrintf("http://example.com/%d", i + 1), |
286 "2012-06-04T15:53:36.023Z", | 282 "2012-06-04T15:53:36.023Z", |
287 false, "", "", "", "", "", "", contact); | 283 false, "", "", "", "", "", "", contact); |
288 contacts::test::SetPhoto(gfx::Size(kPhotoSize, kPhotoSize), contact); | 284 contacts::test::SetPhoto(gfx::Size(kPhotoSize, kPhotoSize), contact); |
289 expected_contacts.push_back(contact); | 285 expected_contacts.push_back(contact); |
290 } | 286 } |
291 EXPECT_EQ(contacts::test::ContactsToString(expected_contacts), | 287 EXPECT_EQ(contacts::test::ContactsToString(expected_contacts), |
292 contacts::test::ContactsToString(*contacts)); | 288 contacts::test::ContactsToString(*contacts)); |
293 } | 289 } |
294 | 290 |
291 IN_PROC_BROWSER_TEST_F(GDataContactsServiceTest, UnicodeStrings) { | |
292 scoped_ptr<ScopedVector<contacts::Contact> > contacts; | |
293 EXPECT_TRUE(Download("feed_unicode.json", base::Time(), &contacts)); | |
294 | |
295 // All of these expected values are hardcoded in the feed. | |
296 scoped_ptr<contacts::Contact> contact1(new contacts::Contact); | |
297 InitContact("http://example.com/1", "2012-06-04T15:53:36.023Z", | |
298 false, "安藤 忠雄", "忠雄", "", "安藤", "", "", | |
satorux1
2012/08/20 18:37:58
I think it's safer to escape them. multi-byte char
Daniel Erat
2012/08/20 19:09:43
Sure, was wondering about this too. Updated.
| |
299 contact1.get()); | |
300 scoped_ptr<contacts::Contact> contact2(new contacts::Contact); | |
301 InitContact("http://example.com/2", "2012-06-21T16:20:13.208Z", | |
302 false, "Bob Smith", "Bob", "", "Smith", "", "", | |
303 contact2.get()); | |
304 EXPECT_EQ(contacts::test::VarContactsToString( | |
305 2, contact1.get(), contact2.get()), | |
306 contacts::test::ContactsToString(*contacts)); | |
307 } | |
308 | |
295 } // namespace gdata | 309 } // namespace gdata |
OLD | NEW |