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

Side by Side 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: address comments 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 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/google_apis/fake_drive_service.h" 5 #include "chrome/browser/google_apis/fake_drive_service.h"
6 6
7 #include "base/file_util.h" 7 #include "base/file_util.h"
8 #include "base/files/scoped_temp_dir.h" 8 #include "base/files/scoped_temp_dir.h"
9 #include "base/message_loop.h" 9 #include "base/message_loop.h"
10 #include "base/utf_string_conversions.h" 10 #include "base/utf_string_conversions.h"
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after
79 &resource_list)); 79 &resource_list));
80 message_loop_.RunUntilIdle(); 80 message_loop_.RunUntilIdle();
81 81
82 EXPECT_EQ(HTTP_SUCCESS, error); 82 EXPECT_EQ(HTTP_SUCCESS, error);
83 ASSERT_TRUE(resource_list); 83 ASSERT_TRUE(resource_list);
84 // Do some sanity check. 84 // Do some sanity check.
85 EXPECT_EQ(12U, resource_list->entries().size()); 85 EXPECT_EQ(12U, resource_list->entries().size());
86 EXPECT_EQ(1, fake_service_.resource_list_load_count()); 86 EXPECT_EQ(1, fake_service_.resource_list_load_count());
87 } 87 }
88 88
89 TEST_F(FakeDriveServiceTest, GetResourceList_WithStartIndex) {
90 ASSERT_TRUE(fake_service_.LoadResourceListForWapi("gdata/root_feed.json"));
91
92 GDataErrorCode error = GDATA_OTHER_ERROR;
93 scoped_ptr<ResourceList> resource_list;
94 fake_service_.GetResourceList(
95 GURL("http://dummyurl/?start-offset=2"),
96 0, // start_changestamp
97 "", // search_query
98 false, // shared_with_me
99 "", // directory_resource_id
100 base::Bind(&test_util::CopyResultsFromGetResourceListCallback,
101 &error,
102 &resource_list));
103 message_loop_.RunUntilIdle();
104
105 EXPECT_EQ(HTTP_SUCCESS, error);
106 ASSERT_TRUE(resource_list);
107 // Because the start-offset was set to 2, the size should be 10 instead of
108 // 12 (the total number).
109 EXPECT_EQ(10U, resource_list->entries().size());
110 EXPECT_EQ(1, fake_service_.resource_list_load_count());
111 }
112
113 TEST_F(FakeDriveServiceTest, GetResourceList_WithStartIndexAndMaxResults) {
114 ASSERT_TRUE(fake_service_.LoadResourceListForWapi("gdata/root_feed.json"));
115
116 GDataErrorCode error = GDATA_OTHER_ERROR;
117 scoped_ptr<ResourceList> resource_list;
118 fake_service_.GetResourceList(
119 GURL("http://localhost/?start-offset=2&max-results=5"),
120 0, // start_changestamp
121 "", // search_query
122 false, // shared_with_me
123 "", // directory_resource_id
124 base::Bind(&test_util::CopyResultsFromGetResourceListCallback,
125 &error,
126 &resource_list));
127 message_loop_.RunUntilIdle();
128
129 EXPECT_EQ(HTTP_SUCCESS, error);
130 ASSERT_TRUE(resource_list);
131 // Because the max-results was set to 5, the size should be 5 instead of 10.
132 EXPECT_EQ(5U, resource_list->entries().size());
133 EXPECT_EQ(1, fake_service_.resource_list_load_count());
134 // The next link should be provided. The new start-offset should be
135 // 2 (original start index) + 5 (max results).
136 const google_apis::Link* next_link =
137 resource_list->GetLinkByType(Link::LINK_NEXT);
138 ASSERT_TRUE(next_link);
139 EXPECT_EQ(GURL("http://localhost/?start-offset=7&max-results=5"),
140 next_link->href());
141 }
142
143 TEST_F(FakeDriveServiceTest, GetResourceList_WithDefaultMaxResultsChanged) {
144 ASSERT_TRUE(fake_service_.LoadResourceListForWapi("gdata/root_feed.json"));
145 fake_service_.set_default_max_results(3);
146
147 GDataErrorCode error = GDATA_OTHER_ERROR;
148 scoped_ptr<ResourceList> resource_list;
149 fake_service_.GetResourceList(
150 GURL(),
151 0, // start_changestamp
152 "", // search_query
153 false, // shared_with_me
154 "", // directory_resource_id
155 base::Bind(&test_util::CopyResultsFromGetResourceListCallback,
156 &error,
157 &resource_list));
158 message_loop_.RunUntilIdle();
159
160 EXPECT_EQ(HTTP_SUCCESS, error);
161 ASSERT_TRUE(resource_list);
162 // Because the default max results was changed to 3, the size should be 3
163 // instead of 12 (the total number).
164 EXPECT_EQ(3U, resource_list->entries().size());
165 EXPECT_EQ(1, fake_service_.resource_list_load_count());
166 // The next link should be provided.
167 const google_apis::Link* next_link =
168 resource_list->GetLinkByType(Link::LINK_NEXT);
169 ASSERT_TRUE(next_link);
170 EXPECT_EQ(GURL("http://localhost/?start-offset=3&max-results=3"),
171 next_link->href());
172 }
173
89 TEST_F(FakeDriveServiceTest, GetResourceList_InRootDirectory) { 174 TEST_F(FakeDriveServiceTest, GetResourceList_InRootDirectory) {
90 ASSERT_TRUE(fake_service_.LoadResourceListForWapi("gdata/root_feed.json")); 175 ASSERT_TRUE(fake_service_.LoadResourceListForWapi("gdata/root_feed.json"));
91 176
92 GDataErrorCode error = GDATA_OTHER_ERROR; 177 GDataErrorCode error = GDATA_OTHER_ERROR;
93 scoped_ptr<ResourceList> resource_list; 178 scoped_ptr<ResourceList> resource_list;
94 fake_service_.GetResourceList( 179 fake_service_.GetResourceList(
95 GURL(), 180 GURL(),
96 0, // start_changestamp 181 0, // start_changestamp
97 "", // search_query 182 "", // search_query
98 false, // shared_with_me 183 false, // shared_with_me
(...skipping 760 matching lines...) Expand 10 before | Expand all | Expand 10 after
859 base::Bind(&test_util::CopyResultsFromGetResourceEntryCallback, 944 base::Bind(&test_util::CopyResultsFromGetResourceEntryCallback,
860 &error, 945 &error,
861 &resource_entry)); 946 &resource_entry));
862 message_loop_.RunUntilIdle(); 947 message_loop_.RunUntilIdle();
863 948
864 EXPECT_EQ(GDATA_NO_CONNECTION, error); 949 EXPECT_EQ(GDATA_NO_CONNECTION, error);
865 EXPECT_FALSE(resource_entry); 950 EXPECT_FALSE(resource_entry);
866 } 951 }
867 952
868 } // namespace google_apis 953 } // namespace google_apis
OLDNEW
« no previous file with comments | « chrome/browser/google_apis/fake_drive_service.cc ('k') | chrome/browser/google_apis/gdata_wapi_parser.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698