Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(278)

Side by Side Diff: chrome/browser/chromeos/gdata/gdata_contacts_service_browsertest.cc

Issue 10823182: contacts: Rate-limit GData photo requests and handle 404s. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 8 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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 141 matching lines...) Expand 10 before | Expand all | Expand 10 after
152 // Test that we report failure for feeds that are broken in various ways. 152 // Test that we report failure for feeds that are broken in various ways.
153 IN_PROC_BROWSER_TEST_F(GDataContactsServiceTest, BrokenFeeds) { 153 IN_PROC_BROWSER_TEST_F(GDataContactsServiceTest, BrokenFeeds) {
154 scoped_ptr<ScopedVector<contacts::Contact> > contacts; 154 scoped_ptr<ScopedVector<contacts::Contact> > contacts;
155 EXPECT_FALSE(Download("some_bogus_file", base::Time(), &contacts)); 155 EXPECT_FALSE(Download("some_bogus_file", base::Time(), &contacts));
156 EXPECT_FALSE(Download("empty.txt", base::Time(), &contacts)); 156 EXPECT_FALSE(Download("empty.txt", base::Time(), &contacts));
157 EXPECT_FALSE(Download("not_json.txt", base::Time(), &contacts)); 157 EXPECT_FALSE(Download("not_json.txt", base::Time(), &contacts));
158 EXPECT_FALSE(Download("not_dictionary.json", base::Time(), &contacts)); 158 EXPECT_FALSE(Download("not_dictionary.json", base::Time(), &contacts));
159 EXPECT_FALSE(Download("no_feed.json", base::Time(), &contacts)); 159 EXPECT_FALSE(Download("no_feed.json", base::Time(), &contacts));
160 EXPECT_FALSE(Download("no_category.json", base::Time(), &contacts)); 160 EXPECT_FALSE(Download("no_category.json", base::Time(), &contacts));
161 EXPECT_FALSE(Download("wrong_category.json", base::Time(), &contacts)); 161 EXPECT_FALSE(Download("wrong_category.json", base::Time(), &contacts));
162 EXPECT_FALSE(Download("feed_photo_404.json", base::Time(), &contacts)); 162
163 // Missing photos should be allowed, though (as this can occur in production).
164 EXPECT_TRUE(Download("feed_photo_404.json", base::Time(), &contacts));
165 ASSERT_EQ(static_cast<size_t>(1), contacts->size());
166 EXPECT_FALSE((*contacts)[0]->has_raw_untrusted_photo());
163 } 167 }
164 168
165 // Check that we're able to download an empty feed and a normal-looking feed 169 // Check that we're able to download an empty feed and a normal-looking feed
166 // with two regular contacts and one deleted one. 170 // with two regular contacts and one deleted one.
167 IN_PROC_BROWSER_TEST_F(GDataContactsServiceTest, Download) { 171 IN_PROC_BROWSER_TEST_F(GDataContactsServiceTest, Download) {
168 scoped_ptr<ScopedVector<contacts::Contact> > contacts; 172 scoped_ptr<ScopedVector<contacts::Contact> > contacts;
169 EXPECT_TRUE(Download("no_entries.json", base::Time(), &contacts)); 173 EXPECT_TRUE(Download("no_entries.json", base::Time(), &contacts));
170 EXPECT_TRUE(contacts->empty()); 174 EXPECT_TRUE(contacts->empty());
171 175
172 EXPECT_TRUE(Download("feed.json", base::Time(), &contacts)); 176 EXPECT_TRUE(Download("feed.json", base::Time(), &contacts));
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after
231 EXPECT_EQ(contacts::test::VarContactsToString( 235 EXPECT_EQ(contacts::test::VarContactsToString(
232 3, contact1.get(), contact2.get(), contact3.get()), 236 3, contact1.get(), contact2.get(), contact3.get()),
233 contacts::test::ContactsToString(*contacts)); 237 contacts::test::ContactsToString(*contacts));
234 } 238 }
235 239
236 // Download a feed containing more photos than we're able to download in 240 // 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. 241 // parallel to check that we still end up with all the photos.
238 IN_PROC_BROWSER_TEST_F(GDataContactsServiceTest, ParallelPhotoDownload) { 242 IN_PROC_BROWSER_TEST_F(GDataContactsServiceTest, ParallelPhotoDownload) {
239 // The feed used for this test contains 8 contacts. 243 // The feed used for this test contains 8 contacts.
240 const int kNumContacts = 8; 244 const int kNumContacts = 8;
241 service()->set_max_simultaneous_photo_downloads_for_testing(2); 245 service()->set_max_photo_downloads_per_second_for_testing(6);
Daniel Erat 2012/08/06 16:25:34 This means that the test will take at least a seco
satorux1 2012/08/06 20:57:08 Might want to add some comment? You might want to
Daniel Erat 2012/08/06 23:12:21 Done.
242 scoped_ptr<ScopedVector<contacts::Contact> > contacts; 246 scoped_ptr<ScopedVector<contacts::Contact> > contacts;
243 EXPECT_TRUE(Download("feed_multiple_photos.json", base::Time(), &contacts)); 247 EXPECT_TRUE(Download("feed_multiple_photos.json", base::Time(), &contacts));
244 ASSERT_EQ(static_cast<size_t>(kNumContacts), contacts->size()); 248 ASSERT_EQ(static_cast<size_t>(kNumContacts), contacts->size());
245 249
246 ScopedVector<contacts::Contact> expected_contacts; 250 ScopedVector<contacts::Contact> expected_contacts;
247 for (int i = 0; i < kNumContacts; ++i) { 251 for (int i = 0; i < kNumContacts; ++i) {
248 contacts::Contact* contact = new contacts::Contact; 252 contacts::Contact* contact = new contacts::Contact;
249 InitContact(base::StringPrintf("http://example.com/%d", i + 1), 253 InitContact(base::StringPrintf("http://example.com/%d", i + 1),
250 "2012-06-04T15:53:36.023Z", 254 "2012-06-04T15:53:36.023Z",
251 false, "", "", "", "", "", "", contact); 255 false, "", "", "", "", "", "", contact);
252 contacts::test::SetPhoto(gfx::Size(kPhotoSize, kPhotoSize), contact); 256 contacts::test::SetPhoto(gfx::Size(kPhotoSize, kPhotoSize), contact);
253 expected_contacts.push_back(contact); 257 expected_contacts.push_back(contact);
254 } 258 }
255 EXPECT_EQ(contacts::test::ContactsToString(expected_contacts), 259 EXPECT_EQ(contacts::test::ContactsToString(expected_contacts),
256 contacts::test::ContactsToString(*contacts)); 260 contacts::test::ContactsToString(*contacts));
257 } 261 }
258 262
259 } // namespace gdata 263 } // namespace gdata
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698