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 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
76 | 76 |
77 virtual void SetUpOnMainThread() OVERRIDE { | 77 virtual void SetUpOnMainThread() OVERRIDE { |
78 ASSERT_TRUE(test_server_.Start()); | 78 ASSERT_TRUE(test_server_.Start()); |
79 service_.reset(new GDataContactsService(browser()->profile())); | 79 service_.reset(new GDataContactsService(browser()->profile())); |
80 service_->Initialize(); | 80 service_->Initialize(); |
81 service_->auth_service_for_testing()->set_access_token_for_testing( | 81 service_->auth_service_for_testing()->set_access_token_for_testing( |
82 net::TestServer::kGDataAuthToken); | 82 net::TestServer::kGDataAuthToken); |
83 service_->set_rewrite_photo_url_callback_for_testing( | 83 service_->set_rewrite_photo_url_callback_for_testing( |
84 base::Bind(&GDataContactsServiceTest::RewritePhotoUrl, | 84 base::Bind(&GDataContactsServiceTest::RewritePhotoUrl, |
85 base::Unretained(this))); | 85 base::Unretained(this))); |
| 86 service_->set_photo_download_timer_interval_for_testing( |
| 87 base::TimeDelta::FromMilliseconds(10)); |
86 } | 88 } |
87 | 89 |
88 virtual void CleanUpOnMainThread() { | 90 virtual void CleanUpOnMainThread() { |
89 service_.reset(); | 91 service_.reset(); |
90 } | 92 } |
91 | 93 |
92 protected: | 94 protected: |
93 GDataContactsService* service() { return service_.get(); } | 95 GDataContactsService* service() { return service_.get(); } |
94 | 96 |
95 // Downloads contacts from |feed_filename| (within the chromeos/gdata/contacts | 97 // Downloads contacts from |feed_filename| (within the chromeos/gdata/contacts |
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
152 // Test that we report failure for feeds that are broken in various ways. | 154 // Test that we report failure for feeds that are broken in various ways. |
153 IN_PROC_BROWSER_TEST_F(GDataContactsServiceTest, BrokenFeeds) { | 155 IN_PROC_BROWSER_TEST_F(GDataContactsServiceTest, BrokenFeeds) { |
154 scoped_ptr<ScopedVector<contacts::Contact> > contacts; | 156 scoped_ptr<ScopedVector<contacts::Contact> > contacts; |
155 EXPECT_FALSE(Download("some_bogus_file", base::Time(), &contacts)); | 157 EXPECT_FALSE(Download("some_bogus_file", base::Time(), &contacts)); |
156 EXPECT_FALSE(Download("empty.txt", base::Time(), &contacts)); | 158 EXPECT_FALSE(Download("empty.txt", base::Time(), &contacts)); |
157 EXPECT_FALSE(Download("not_json.txt", base::Time(), &contacts)); | 159 EXPECT_FALSE(Download("not_json.txt", base::Time(), &contacts)); |
158 EXPECT_FALSE(Download("not_dictionary.json", base::Time(), &contacts)); | 160 EXPECT_FALSE(Download("not_dictionary.json", base::Time(), &contacts)); |
159 EXPECT_FALSE(Download("no_feed.json", base::Time(), &contacts)); | 161 EXPECT_FALSE(Download("no_feed.json", base::Time(), &contacts)); |
160 EXPECT_FALSE(Download("no_category.json", base::Time(), &contacts)); | 162 EXPECT_FALSE(Download("no_category.json", base::Time(), &contacts)); |
161 EXPECT_FALSE(Download("wrong_category.json", base::Time(), &contacts)); | 163 EXPECT_FALSE(Download("wrong_category.json", base::Time(), &contacts)); |
162 EXPECT_FALSE(Download("feed_photo_404.json", base::Time(), &contacts)); | 164 |
| 165 // Missing photos should be allowed, though (as this can occur in production). |
| 166 EXPECT_TRUE(Download("feed_photo_404.json", base::Time(), &contacts)); |
| 167 ASSERT_EQ(static_cast<size_t>(1), contacts->size()); |
| 168 EXPECT_FALSE((*contacts)[0]->has_raw_untrusted_photo()); |
163 } | 169 } |
164 | 170 |
165 // Check that we're able to download an empty feed and a normal-looking feed | 171 // Check that we're able to download an empty feed and a normal-looking feed |
166 // with two regular contacts and one deleted one. | 172 // with two regular contacts and one deleted one. |
167 IN_PROC_BROWSER_TEST_F(GDataContactsServiceTest, Download) { | 173 IN_PROC_BROWSER_TEST_F(GDataContactsServiceTest, Download) { |
168 scoped_ptr<ScopedVector<contacts::Contact> > contacts; | 174 scoped_ptr<ScopedVector<contacts::Contact> > contacts; |
169 EXPECT_TRUE(Download("no_entries.json", base::Time(), &contacts)); | 175 EXPECT_TRUE(Download("no_entries.json", base::Time(), &contacts)); |
170 EXPECT_TRUE(contacts->empty()); | 176 EXPECT_TRUE(contacts->empty()); |
171 | 177 |
172 EXPECT_TRUE(Download("feed.json", base::Time(), &contacts)); | 178 EXPECT_TRUE(Download("feed.json", base::Time(), &contacts)); |
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
231 EXPECT_EQ(contacts::test::VarContactsToString( | 237 EXPECT_EQ(contacts::test::VarContactsToString( |
232 3, contact1.get(), contact2.get(), contact3.get()), | 238 3, contact1.get(), contact2.get(), contact3.get()), |
233 contacts::test::ContactsToString(*contacts)); | 239 contacts::test::ContactsToString(*contacts)); |
234 } | 240 } |
235 | 241 |
236 // Download a feed containing more photos than we're able to download in | 242 // Download a feed containing more photos than we're able to download in |
237 // parallel to check that we still end up with all the photos. | 243 // parallel to check that we still end up with all the photos. |
238 IN_PROC_BROWSER_TEST_F(GDataContactsServiceTest, ParallelPhotoDownload) { | 244 IN_PROC_BROWSER_TEST_F(GDataContactsServiceTest, ParallelPhotoDownload) { |
239 // The feed used for this test contains 8 contacts. | 245 // The feed used for this test contains 8 contacts. |
240 const int kNumContacts = 8; | 246 const int kNumContacts = 8; |
241 service()->set_max_simultaneous_photo_downloads_for_testing(2); | 247 service()->set_max_photo_downloads_per_second_for_testing(6); |
242 scoped_ptr<ScopedVector<contacts::Contact> > contacts; | 248 scoped_ptr<ScopedVector<contacts::Contact> > contacts; |
243 EXPECT_TRUE(Download("feed_multiple_photos.json", base::Time(), &contacts)); | 249 EXPECT_TRUE(Download("feed_multiple_photos.json", base::Time(), &contacts)); |
244 ASSERT_EQ(static_cast<size_t>(kNumContacts), contacts->size()); | 250 ASSERT_EQ(static_cast<size_t>(kNumContacts), contacts->size()); |
245 | 251 |
246 ScopedVector<contacts::Contact> expected_contacts; | 252 ScopedVector<contacts::Contact> expected_contacts; |
247 for (int i = 0; i < kNumContacts; ++i) { | 253 for (int i = 0; i < kNumContacts; ++i) { |
248 contacts::Contact* contact = new contacts::Contact; | 254 contacts::Contact* contact = new contacts::Contact; |
249 InitContact(base::StringPrintf("http://example.com/%d", i + 1), | 255 InitContact(base::StringPrintf("http://example.com/%d", i + 1), |
250 "2012-06-04T15:53:36.023Z", | 256 "2012-06-04T15:53:36.023Z", |
251 false, "", "", "", "", "", "", contact); | 257 false, "", "", "", "", "", "", contact); |
252 contacts::test::SetPhoto(gfx::Size(kPhotoSize, kPhotoSize), contact); | 258 contacts::test::SetPhoto(gfx::Size(kPhotoSize, kPhotoSize), contact); |
253 expected_contacts.push_back(contact); | 259 expected_contacts.push_back(contact); |
254 } | 260 } |
255 EXPECT_EQ(contacts::test::ContactsToString(expected_contacts), | 261 EXPECT_EQ(contacts::test::ContactsToString(expected_contacts), |
256 contacts::test::ContactsToString(*contacts)); | 262 contacts::test::ContactsToString(*contacts)); |
257 } | 263 } |
258 | 264 |
259 } // namespace gdata | 265 } // namespace gdata |
OLD | NEW |