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

Unified Diff: chrome/browser/google_apis/fake_drive_service_unittest.cc

Issue 12017026: drive: Add support for pagenation to FakeDriveService (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: polish Created 7 years, 11 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 side-by-side diff with in-line comments
Download patch
Index: chrome/browser/google_apis/fake_drive_service_unittest.cc
diff --git a/chrome/browser/google_apis/fake_drive_service_unittest.cc b/chrome/browser/google_apis/fake_drive_service_unittest.cc
index 4fb748d7fefa25503fa9f0c3c4dc88cd8bd72303..cd648bbcb37062ed3a0df82b1aabe5144135b57c 100644
--- a/chrome/browser/google_apis/fake_drive_service_unittest.cc
+++ b/chrome/browser/google_apis/fake_drive_service_unittest.cc
@@ -85,6 +85,91 @@ TEST_F(FakeDriveServiceTest, GetResourceList_All) {
EXPECT_EQ(1, fake_service_.resource_list_load_count());
}
+TEST_F(FakeDriveServiceTest, GetResourceList_WithStartIndex) {
+ ASSERT_TRUE(fake_service_.LoadResourceListForWapi("gdata/root_feed.json"));
+
+ GDataErrorCode error = GDATA_OTHER_ERROR;
+ scoped_ptr<ResourceList> resource_list;
+ fake_service_.GetResourceList(
+ GURL("http://dummyurl/?start-index=2"),
+ 0, // start_changestamp
+ "", // search_query
+ false, // shared_with_me
+ "", // directory_resource_id
+ base::Bind(&test_util::CopyResultsFromGetResourceListCallback,
+ &error,
+ &resource_list));
+ message_loop_.RunUntilIdle();
+
+ EXPECT_EQ(HTTP_SUCCESS, error);
+ ASSERT_TRUE(resource_list);
+ // Because the start-index was set to 2, the size should be 10 instead of
+ // 12 (the total number).
+ EXPECT_EQ(10U, resource_list->entries().size());
+ EXPECT_EQ(1, fake_service_.resource_list_load_count());
+}
+
+TEST_F(FakeDriveServiceTest, GetResourceList_WithStartIndexAndMaxResults) {
+ ASSERT_TRUE(fake_service_.LoadResourceListForWapi("gdata/root_feed.json"));
+
+ GDataErrorCode error = GDATA_OTHER_ERROR;
+ scoped_ptr<ResourceList> resource_list;
+ fake_service_.GetResourceList(
+ GURL("http://localhost/?start-index=2&max-results=5"),
+ 0, // start_changestamp
+ "", // search_query
+ false, // shared_with_me
+ "", // directory_resource_id
+ base::Bind(&test_util::CopyResultsFromGetResourceListCallback,
+ &error,
+ &resource_list));
+ message_loop_.RunUntilIdle();
+
+ EXPECT_EQ(HTTP_SUCCESS, error);
+ ASSERT_TRUE(resource_list);
+ // Because the max-results was set to 5, the size should be 5 instead of 10.
+ EXPECT_EQ(5U, resource_list->entries().size());
+ EXPECT_EQ(1, fake_service_.resource_list_load_count());
+ // The next link should be provided. The new start-index should be
+ // 2 (original start index) + 5 (max results).
+ const google_apis::Link* next_link =
+ resource_list->GetLinkByType(Link::LINK_NEXT);
+ ASSERT_TRUE(next_link);
+ EXPECT_EQ(GURL("http://localhost/?start-index=7&max-results=5"),
+ next_link->href());
+}
+
+TEST_F(FakeDriveServiceTest, GetResourceList_WithDefaultMaxResultsChanged) {
+ ASSERT_TRUE(fake_service_.LoadResourceListForWapi("gdata/root_feed.json"));
+ fake_service_.set_default_max_results(3);
+
+ GDataErrorCode error = GDATA_OTHER_ERROR;
+ scoped_ptr<ResourceList> resource_list;
+ fake_service_.GetResourceList(
+ GURL(),
+ 0, // start_changestamp
+ "", // search_query
+ false, // shared_with_me
+ "", // directory_resource_id
+ base::Bind(&test_util::CopyResultsFromGetResourceListCallback,
+ &error,
+ &resource_list));
+ message_loop_.RunUntilIdle();
+
+ EXPECT_EQ(HTTP_SUCCESS, error);
+ ASSERT_TRUE(resource_list);
+ // Because the default max results was changed to 3, the size should be 3
+ // instead of 12 (the total number).
+ EXPECT_EQ(3U, resource_list->entries().size());
+ EXPECT_EQ(1, fake_service_.resource_list_load_count());
+ // The next link should be provided.
+ const google_apis::Link* next_link =
+ resource_list->GetLinkByType(Link::LINK_NEXT);
+ ASSERT_TRUE(next_link);
+ EXPECT_EQ(GURL("http://localhost/?start-index=3&max-results=3"),
+ next_link->href());
+}
+
TEST_F(FakeDriveServiceTest, GetResourceList_InRootDirectory) {
ASSERT_TRUE(fake_service_.LoadResourceListForWapi("gdata/root_feed.json"));

Powered by Google App Engine
This is Rietveld 408576698