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/drive/drive_scheduler.h" | 5 #include "chrome/browser/chromeos/drive/drive_scheduler.h" |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/file_util.h" | 8 #include "base/file_util.h" |
9 #include "base/json/json_reader.h" | 9 #include "base/json/json_reader.h" |
10 #include "base/prefs/pref_service.h" | 10 #include "base/prefs/pref_service.h" |
(...skipping 144 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
155 | 155 |
156 scheduler_->GetAccountMetadata( | 156 scheduler_->GetAccountMetadata( |
157 google_apis::test_util::CreateCopyResultCallback( | 157 google_apis::test_util::CreateCopyResultCallback( |
158 &error, &account_metadata)); | 158 &error, &account_metadata)); |
159 google_apis::test_util::RunBlockingPoolTask(); | 159 google_apis::test_util::RunBlockingPoolTask(); |
160 | 160 |
161 ASSERT_EQ(google_apis::HTTP_SUCCESS, error); | 161 ASSERT_EQ(google_apis::HTTP_SUCCESS, error); |
162 ASSERT_TRUE(account_metadata); | 162 ASSERT_TRUE(account_metadata); |
163 } | 163 } |
164 | 164 |
165 | |
166 TEST_F(DriveSchedulerTest, GetResourceList) { | 165 TEST_F(DriveSchedulerTest, GetResourceList) { |
167 ConnectToWifi(); | 166 ConnectToWifi(); |
168 | 167 |
169 google_apis::GDataErrorCode error = google_apis::GDATA_OTHER_ERROR; | 168 google_apis::GDataErrorCode error = google_apis::GDATA_OTHER_ERROR; |
170 scoped_ptr<google_apis::ResourceList> resource_list; | 169 scoped_ptr<google_apis::ResourceList> resource_list; |
171 | 170 |
172 scheduler_->GetResourceList( | 171 scheduler_->GetResourceList( |
173 GURL("http://example.com/gdata/root_feed.json"), | 172 GURL("http://example.com/gdata/root_feed.json"), |
174 0, | 173 0, |
175 std::string(), | 174 std::string(), |
176 std::string(), | 175 std::string(), |
177 google_apis::test_util::CreateCopyResultCallback( | 176 google_apis::test_util::CreateCopyResultCallback( |
178 &error, &resource_list)); | 177 &error, &resource_list)); |
179 google_apis::test_util::RunBlockingPoolTask(); | 178 google_apis::test_util::RunBlockingPoolTask(); |
180 | 179 |
181 ASSERT_EQ(google_apis::HTTP_SUCCESS, error); | 180 ASSERT_EQ(google_apis::HTTP_SUCCESS, error); |
182 ASSERT_TRUE(resource_list); | 181 ASSERT_TRUE(resource_list); |
183 } | 182 } |
184 | 183 |
| 184 TEST_F(DriveSchedulerTest, GetAllResourceList) { |
| 185 ConnectToWifi(); |
| 186 |
| 187 google_apis::GDataErrorCode error = google_apis::GDATA_OTHER_ERROR; |
| 188 scoped_ptr<google_apis::ResourceList> resource_list; |
| 189 |
| 190 scheduler_->GetAllResourceList( |
| 191 google_apis::test_util::CreateCopyResultCallback( |
| 192 &error, &resource_list)); |
| 193 google_apis::test_util::RunBlockingPoolTask(); |
| 194 |
| 195 ASSERT_EQ(google_apis::HTTP_SUCCESS, error); |
| 196 ASSERT_TRUE(resource_list); |
| 197 } |
| 198 |
| 199 TEST_F(DriveSchedulerTest, GetResourceListInDirectory) { |
| 200 ConnectToWifi(); |
| 201 |
| 202 google_apis::GDataErrorCode error = google_apis::GDATA_OTHER_ERROR; |
| 203 scoped_ptr<google_apis::ResourceList> resource_list; |
| 204 |
| 205 scheduler_->GetResourceListInDirectory( |
| 206 fake_drive_service_->GetRootResourceId(), |
| 207 google_apis::test_util::CreateCopyResultCallback( |
| 208 &error, &resource_list)); |
| 209 google_apis::test_util::RunBlockingPoolTask(); |
| 210 |
| 211 ASSERT_EQ(google_apis::HTTP_SUCCESS, error); |
| 212 ASSERT_TRUE(resource_list); |
| 213 } |
| 214 |
| 215 TEST_F(DriveSchedulerTest, Search) { |
| 216 ConnectToWifi(); |
| 217 |
| 218 google_apis::GDataErrorCode error = google_apis::GDATA_OTHER_ERROR; |
| 219 scoped_ptr<google_apis::ResourceList> resource_list; |
| 220 |
| 221 scheduler_->Search( |
| 222 "File", // search query |
| 223 google_apis::test_util::CreateCopyResultCallback( |
| 224 &error, &resource_list)); |
| 225 google_apis::test_util::RunBlockingPoolTask(); |
| 226 |
| 227 ASSERT_EQ(google_apis::HTTP_SUCCESS, error); |
| 228 ASSERT_TRUE(resource_list); |
| 229 } |
| 230 |
| 231 TEST_F(DriveSchedulerTest, GetChangeList) { |
| 232 ConnectToWifi(); |
| 233 |
| 234 google_apis::GDataErrorCode error = google_apis::GDATA_OTHER_ERROR; |
| 235 |
| 236 // Create a new directory. |
| 237 // The loaded (initial) changestamp is 654321. Thus, by this operation, |
| 238 // it should become 654322. |
| 239 { |
| 240 scoped_ptr<google_apis::ResourceEntry> resource_entry; |
| 241 fake_drive_service_->AddNewDirectory( |
| 242 fake_drive_service_->GetRootResourceId(), |
| 243 "new directory", |
| 244 google_apis::test_util::CreateCopyResultCallback( |
| 245 &error, &resource_entry)); |
| 246 google_apis::test_util::RunBlockingPoolTask(); |
| 247 ASSERT_EQ(google_apis::HTTP_CREATED, error); |
| 248 } |
| 249 |
| 250 error = google_apis::GDATA_OTHER_ERROR; |
| 251 scoped_ptr<google_apis::ResourceList> resource_list; |
| 252 scheduler_->GetChangeList( |
| 253 654321 + 1, // start_changestamp |
| 254 google_apis::test_util::CreateCopyResultCallback( |
| 255 &error, &resource_list)); |
| 256 google_apis::test_util::RunBlockingPoolTask(); |
| 257 |
| 258 ASSERT_EQ(google_apis::HTTP_SUCCESS, error); |
| 259 ASSERT_TRUE(resource_list); |
| 260 } |
| 261 |
| 262 TEST_F(DriveSchedulerTest, ContinueGetResourceList) { |
| 263 ConnectToWifi(); |
| 264 fake_drive_service_->set_default_max_results(2); |
| 265 |
| 266 google_apis::GDataErrorCode error = google_apis::GDATA_OTHER_ERROR; |
| 267 scoped_ptr<google_apis::ResourceList> resource_list; |
| 268 |
| 269 scheduler_->GetAllResourceList( |
| 270 google_apis::test_util::CreateCopyResultCallback( |
| 271 &error, &resource_list)); |
| 272 google_apis::test_util::RunBlockingPoolTask(); |
| 273 |
| 274 ASSERT_EQ(google_apis::HTTP_SUCCESS, error); |
| 275 ASSERT_TRUE(resource_list); |
| 276 |
| 277 const google_apis::Link* next_link = |
| 278 resource_list->GetLinkByType(google_apis::Link::LINK_NEXT); |
| 279 ASSERT_TRUE(next_link); |
| 280 // Keep the next url before releasing the |resource_list|. |
| 281 GURL next_url(next_link->href()); |
| 282 |
| 283 error = google_apis::GDATA_OTHER_ERROR; |
| 284 resource_list.reset(); |
| 285 |
| 286 scheduler_->ContinueGetResourceList( |
| 287 next_url, |
| 288 google_apis::test_util::CreateCopyResultCallback( |
| 289 &error, &resource_list)); |
| 290 google_apis::test_util::RunBlockingPoolTask(); |
| 291 |
| 292 ASSERT_EQ(google_apis::HTTP_SUCCESS, error); |
| 293 ASSERT_TRUE(resource_list); |
| 294 } |
| 295 |
185 TEST_F(DriveSchedulerTest, GetResourceEntry) { | 296 TEST_F(DriveSchedulerTest, GetResourceEntry) { |
186 ConnectToWifi(); | 297 ConnectToWifi(); |
187 | 298 |
188 google_apis::GDataErrorCode error = google_apis::GDATA_OTHER_ERROR; | 299 google_apis::GDataErrorCode error = google_apis::GDATA_OTHER_ERROR; |
189 scoped_ptr<google_apis::ResourceEntry> entry; | 300 scoped_ptr<google_apis::ResourceEntry> entry; |
190 | 301 |
191 scheduler_->GetResourceEntry( | 302 scheduler_->GetResourceEntry( |
192 "file:2_file_resource_id", // resource ID | 303 "file:2_file_resource_id", // resource ID |
193 DriveClientContext(USER_INITIATED), | 304 DriveClientContext(USER_INITIATED), |
194 google_apis::test_util::CreateCopyResultCallback(&error, &entry)); | 305 google_apis::test_util::CreateCopyResultCallback(&error, &entry)); |
(...skipping 355 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
550 // Check the download | 661 // Check the download |
551 EXPECT_EQ(google_apis::HTTP_SUCCESS, download_error); | 662 EXPECT_EQ(google_apis::HTTP_SUCCESS, download_error); |
552 std::string content; | 663 std::string content; |
553 EXPECT_EQ(output_file_path, kOutputFilePath); | 664 EXPECT_EQ(output_file_path, kOutputFilePath); |
554 ASSERT_TRUE(file_util::ReadFileToString(output_file_path, &content)); | 665 ASSERT_TRUE(file_util::ReadFileToString(output_file_path, &content)); |
555 // The content is "x"s of the file size specified in root_feed.json. | 666 // The content is "x"s of the file size specified in root_feed.json. |
556 EXPECT_EQ("xxxxxxxxxx", content); | 667 EXPECT_EQ("xxxxxxxxxx", content); |
557 } | 668 } |
558 | 669 |
559 } // namespace drive | 670 } // namespace drive |
OLD | NEW |