NaCl: Update revision in DEPS, r12770 -> r12773
[chromium-blink-merge.git] / chrome / browser / drive / fake_drive_service_unittest.cc
blobac80d30a557164dffc7522e9c3bbb27a6447018c
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
3 // found in the LICENSE file.
5 #include "chrome/browser/drive/fake_drive_service.h"
7 #include <string>
8 #include <vector>
10 #include "base/file_util.h"
11 #include "base/files/scoped_temp_dir.h"
12 #include "base/md5.h"
13 #include "base/run_loop.h"
14 #include "base/stl_util.h"
15 #include "base/strings/stringprintf.h"
16 #include "base/strings/utf_string_conversions.h"
17 #include "content/public/test/test_browser_thread_bundle.h"
18 #include "google_apis/drive/drive_api_parser.h"
19 #include "google_apis/drive/gdata_wapi_parser.h"
20 #include "google_apis/drive/gdata_wapi_requests.h"
21 #include "google_apis/drive/test_util.h"
22 #include "testing/gtest/include/gtest/gtest.h"
24 using google_apis::AboutResource;
25 using google_apis::AppList;
26 using google_apis::GDataErrorCode;
27 using google_apis::GDATA_NO_CONNECTION;
28 using google_apis::GDATA_OTHER_ERROR;
29 using google_apis::GetContentCallback;
30 using google_apis::HTTP_CREATED;
31 using google_apis::HTTP_NOT_FOUND;
32 using google_apis::HTTP_NO_CONTENT;
33 using google_apis::HTTP_PRECONDITION;
34 using google_apis::HTTP_RESUME_INCOMPLETE;
35 using google_apis::HTTP_SUCCESS;
36 using google_apis::Link;
37 using google_apis::ProgressCallback;
38 using google_apis::ResourceEntry;
39 using google_apis::ResourceList;
40 using google_apis::UploadRangeResponse;
41 namespace test_util = google_apis::test_util;
43 namespace drive {
45 namespace {
47 class FakeDriveServiceTest : public testing::Test {
48 protected:
49 // Returns the resource entry that matches |resource_id|.
50 scoped_ptr<ResourceEntry> FindEntry(const std::string& resource_id) {
51 GDataErrorCode error = GDATA_OTHER_ERROR;
52 scoped_ptr<ResourceEntry> resource_entry;
53 fake_service_.GetResourceEntry(
54 resource_id,
55 test_util::CreateCopyResultCallback(&error, &resource_entry));
56 base::RunLoop().RunUntilIdle();
57 return resource_entry.Pass();
60 // Returns true if the resource identified by |resource_id| exists.
61 bool Exists(const std::string& resource_id) {
62 scoped_ptr<ResourceEntry> resource_entry = FindEntry(resource_id);
63 return resource_entry && !resource_entry->deleted();
66 // Adds a new directory at |parent_resource_id| with the given name.
67 // Returns true on success.
68 bool AddNewDirectory(const std::string& parent_resource_id,
69 const std::string& directory_title) {
70 GDataErrorCode error = GDATA_OTHER_ERROR;
71 scoped_ptr<ResourceEntry> resource_entry;
72 fake_service_.AddNewDirectory(
73 parent_resource_id,
74 directory_title,
75 DriveServiceInterface::AddNewDirectoryOptions(),
76 test_util::CreateCopyResultCallback(&error, &resource_entry));
77 base::RunLoop().RunUntilIdle();
78 return error == HTTP_CREATED;
81 // Returns true if the resource identified by |resource_id| has a parent
82 // identified by |parent_id|.
83 bool HasParent(const std::string& resource_id, const std::string& parent_id) {
84 const GURL parent_url = FakeDriveService::GetFakeLinkUrl(parent_id);
85 scoped_ptr<ResourceEntry> resource_entry = FindEntry(resource_id);
86 if (resource_entry.get()) {
87 for (size_t i = 0; i < resource_entry->links().size(); ++i) {
88 if (resource_entry->links()[i]->type() == Link::LINK_PARENT &&
89 resource_entry->links()[i]->href() == parent_url)
90 return true;
93 return false;
96 int64 GetLargestChangeByAboutResource() {
97 GDataErrorCode error;
98 scoped_ptr<AboutResource> about_resource;
99 fake_service_.GetAboutResource(
100 test_util::CreateCopyResultCallback(&error, &about_resource));
101 base::RunLoop().RunUntilIdle();
102 return about_resource->largest_change_id();
105 content::TestBrowserThreadBundle thread_bundle_;
106 FakeDriveService fake_service_;
109 TEST_F(FakeDriveServiceTest, GetAllResourceList) {
110 ASSERT_TRUE(fake_service_.LoadResourceListForWapi(
111 "gdata/root_feed.json"));
113 GDataErrorCode error = GDATA_OTHER_ERROR;
114 scoped_ptr<ResourceList> resource_list;
115 fake_service_.GetAllResourceList(
116 test_util::CreateCopyResultCallback(&error, &resource_list));
117 base::RunLoop().RunUntilIdle();
119 EXPECT_EQ(HTTP_SUCCESS, error);
120 ASSERT_TRUE(resource_list);
121 // Do some sanity check.
122 EXPECT_EQ(14U, resource_list->entries().size());
123 EXPECT_EQ(1, fake_service_.resource_list_load_count());
126 TEST_F(FakeDriveServiceTest, GetAllResourceList_Offline) {
127 ASSERT_TRUE(fake_service_.LoadResourceListForWapi(
128 "gdata/root_feed.json"));
129 fake_service_.set_offline(true);
131 GDataErrorCode error = GDATA_OTHER_ERROR;
132 scoped_ptr<ResourceList> resource_list;
133 fake_service_.GetAllResourceList(
134 test_util::CreateCopyResultCallback(&error, &resource_list));
135 base::RunLoop().RunUntilIdle();
137 EXPECT_EQ(GDATA_NO_CONNECTION, error);
138 EXPECT_FALSE(resource_list);
141 TEST_F(FakeDriveServiceTest, GetResourceListInDirectory_InRootDirectory) {
142 ASSERT_TRUE(fake_service_.LoadResourceListForWapi(
143 "gdata/root_feed.json"));
145 GDataErrorCode error = GDATA_OTHER_ERROR;
146 scoped_ptr<ResourceList> resource_list;
147 fake_service_.GetResourceListInDirectory(
148 fake_service_.GetRootResourceId(),
149 test_util::CreateCopyResultCallback(&error, &resource_list));
150 base::RunLoop().RunUntilIdle();
152 EXPECT_EQ(HTTP_SUCCESS, error);
153 ASSERT_TRUE(resource_list);
154 // Do some sanity check. There are 8 entries in the root directory.
155 EXPECT_EQ(8U, resource_list->entries().size());
156 EXPECT_EQ(1, fake_service_.directory_load_count());
159 TEST_F(FakeDriveServiceTest, GetResourceListInDirectory_InNonRootDirectory) {
160 ASSERT_TRUE(fake_service_.LoadResourceListForWapi(
161 "gdata/root_feed.json"));
163 GDataErrorCode error = GDATA_OTHER_ERROR;
164 scoped_ptr<ResourceList> resource_list;
165 fake_service_.GetResourceListInDirectory(
166 "folder:1_folder_resource_id",
167 test_util::CreateCopyResultCallback(&error, &resource_list));
168 base::RunLoop().RunUntilIdle();
170 EXPECT_EQ(HTTP_SUCCESS, error);
171 ASSERT_TRUE(resource_list);
172 // Do some sanity check. There is three entries in 1_folder_resource_id
173 // directory.
174 EXPECT_EQ(3U, resource_list->entries().size());
175 EXPECT_EQ(1, fake_service_.directory_load_count());
178 TEST_F(FakeDriveServiceTest, GetResourceListInDirectory_Offline) {
179 ASSERT_TRUE(fake_service_.LoadResourceListForWapi(
180 "gdata/root_feed.json"));
181 fake_service_.set_offline(true);
183 GDataErrorCode error = GDATA_OTHER_ERROR;
184 scoped_ptr<ResourceList> resource_list;
185 fake_service_.GetResourceListInDirectory(
186 fake_service_.GetRootResourceId(),
187 test_util::CreateCopyResultCallback(&error, &resource_list));
188 base::RunLoop().RunUntilIdle();
190 EXPECT_EQ(GDATA_NO_CONNECTION, error);
191 EXPECT_FALSE(resource_list);
194 TEST_F(FakeDriveServiceTest, Search) {
195 ASSERT_TRUE(fake_service_.LoadResourceListForWapi(
196 "gdata/root_feed.json"));
198 GDataErrorCode error = GDATA_OTHER_ERROR;
199 scoped_ptr<ResourceList> resource_list;
200 fake_service_.Search(
201 "File", // search_query
202 test_util::CreateCopyResultCallback(&error, &resource_list));
203 base::RunLoop().RunUntilIdle();
205 EXPECT_EQ(HTTP_SUCCESS, error);
206 ASSERT_TRUE(resource_list);
207 // Do some sanity check. There are 4 entries that contain "File" in their
208 // titles.
209 EXPECT_EQ(4U, resource_list->entries().size());
212 TEST_F(FakeDriveServiceTest, Search_WithAttribute) {
213 ASSERT_TRUE(fake_service_.LoadResourceListForWapi(
214 "gdata/root_feed.json"));
216 GDataErrorCode error = GDATA_OTHER_ERROR;
217 scoped_ptr<ResourceList> resource_list;
218 fake_service_.Search(
219 "title:1.txt", // search_query
220 test_util::CreateCopyResultCallback(&error, &resource_list));
221 base::RunLoop().RunUntilIdle();
223 EXPECT_EQ(HTTP_SUCCESS, error);
224 ASSERT_TRUE(resource_list);
225 // Do some sanity check. There are 4 entries that contain "1.txt" in their
226 // titles.
227 EXPECT_EQ(4U, resource_list->entries().size());
230 TEST_F(FakeDriveServiceTest, Search_MultipleQueries) {
231 ASSERT_TRUE(fake_service_.LoadResourceListForWapi(
232 "gdata/root_feed.json"));
234 GDataErrorCode error = GDATA_OTHER_ERROR;
235 scoped_ptr<ResourceList> resource_list;
236 fake_service_.Search(
237 "Directory 1", // search_query
238 test_util::CreateCopyResultCallback(&error, &resource_list));
239 base::RunLoop().RunUntilIdle();
241 EXPECT_EQ(HTTP_SUCCESS, error);
242 ASSERT_TRUE(resource_list);
243 // There are 2 entries that contain both "Directory" and "1" in their titles.
244 EXPECT_EQ(2U, resource_list->entries().size());
246 fake_service_.Search(
247 "\"Directory 1\"", // search_query
248 test_util::CreateCopyResultCallback(&error, &resource_list));
249 base::RunLoop().RunUntilIdle();
251 EXPECT_EQ(HTTP_SUCCESS, error);
252 ASSERT_TRUE(resource_list);
253 // There is 1 entry that contain "Directory 1" in its title.
254 EXPECT_EQ(1U, resource_list->entries().size());
257 TEST_F(FakeDriveServiceTest, Search_Offline) {
258 ASSERT_TRUE(fake_service_.LoadResourceListForWapi(
259 "gdata/root_feed.json"));
260 fake_service_.set_offline(true);
262 GDataErrorCode error = GDATA_OTHER_ERROR;
263 scoped_ptr<ResourceList> resource_list;
264 fake_service_.Search(
265 "Directory 1", // search_query
266 test_util::CreateCopyResultCallback(&error, &resource_list));
267 base::RunLoop().RunUntilIdle();
269 EXPECT_EQ(GDATA_NO_CONNECTION, error);
270 EXPECT_FALSE(resource_list);
273 TEST_F(FakeDriveServiceTest, Search_Deleted) {
274 ASSERT_TRUE(fake_service_.LoadResourceListForWapi(
275 "gdata/root_feed.json"));
277 GDataErrorCode error = GDATA_OTHER_ERROR;
278 fake_service_.DeleteResource("file:2_file_resource_id",
279 std::string(), // etag
280 test_util::CreateCopyResultCallback(&error));
281 base::RunLoop().RunUntilIdle();
282 EXPECT_EQ(HTTP_NO_CONTENT, error);
284 error = GDATA_OTHER_ERROR;
285 scoped_ptr<ResourceList> resource_list;
286 fake_service_.Search(
287 "File", // search_query
288 test_util::CreateCopyResultCallback(&error, &resource_list));
289 base::RunLoop().RunUntilIdle();
291 EXPECT_EQ(HTTP_SUCCESS, error);
292 ASSERT_TRUE(resource_list);
293 // Do some sanity check. There are 4 entries that contain "File" in their
294 // titles and one of them is deleted.
295 EXPECT_EQ(3U, resource_list->entries().size());
298 TEST_F(FakeDriveServiceTest, Search_Trashed) {
299 ASSERT_TRUE(fake_service_.LoadResourceListForWapi(
300 "gdata/root_feed.json"));
302 GDataErrorCode error = GDATA_OTHER_ERROR;
303 fake_service_.TrashResource("file:2_file_resource_id",
304 test_util::CreateCopyResultCallback(&error));
305 base::RunLoop().RunUntilIdle();
306 EXPECT_EQ(HTTP_SUCCESS, error);
308 error = GDATA_OTHER_ERROR;
309 scoped_ptr<ResourceList> resource_list;
310 fake_service_.Search(
311 "File", // search_query
312 test_util::CreateCopyResultCallback(&error, &resource_list));
313 base::RunLoop().RunUntilIdle();
315 EXPECT_EQ(HTTP_SUCCESS, error);
316 ASSERT_TRUE(resource_list);
317 // Do some sanity check. There are 4 entries that contain "File" in their
318 // titles and one of them is deleted.
319 EXPECT_EQ(3U, resource_list->entries().size());
322 TEST_F(FakeDriveServiceTest, SearchByTitle) {
323 ASSERT_TRUE(fake_service_.LoadResourceListForWapi(
324 "gdata/root_feed.json"));
326 GDataErrorCode error = GDATA_OTHER_ERROR;
327 scoped_ptr<ResourceList> resource_list;
328 fake_service_.SearchByTitle(
329 "1.txt", // title
330 fake_service_.GetRootResourceId(), // directory_resource_id
331 test_util::CreateCopyResultCallback(&error, &resource_list));
332 base::RunLoop().RunUntilIdle();
334 EXPECT_EQ(HTTP_SUCCESS, error);
335 ASSERT_TRUE(resource_list);
336 // Do some sanity check. There are 2 entries that contain "1.txt" in their
337 // titles directly under the root directory.
338 EXPECT_EQ(2U, resource_list->entries().size());
341 TEST_F(FakeDriveServiceTest, SearchByTitle_EmptyDirectoryResourceId) {
342 ASSERT_TRUE(fake_service_.LoadResourceListForWapi(
343 "gdata/root_feed.json"));
345 GDataErrorCode error = GDATA_OTHER_ERROR;
346 scoped_ptr<ResourceList> resource_list;
347 fake_service_.SearchByTitle(
348 "1.txt", // title
349 "", // directory resource id
350 test_util::CreateCopyResultCallback(&error, &resource_list));
351 base::RunLoop().RunUntilIdle();
353 EXPECT_EQ(HTTP_SUCCESS, error);
354 ASSERT_TRUE(resource_list);
355 // Do some sanity check. There are 4 entries that contain "1.txt" in their
356 // titles.
357 EXPECT_EQ(4U, resource_list->entries().size());
360 TEST_F(FakeDriveServiceTest, SearchByTitle_Offline) {
361 ASSERT_TRUE(fake_service_.LoadResourceListForWapi(
362 "gdata/root_feed.json"));
363 fake_service_.set_offline(true);
365 GDataErrorCode error = GDATA_OTHER_ERROR;
366 scoped_ptr<ResourceList> resource_list;
367 fake_service_.SearchByTitle(
368 "Directory 1", // title
369 fake_service_.GetRootResourceId(), // directory_resource_id
370 test_util::CreateCopyResultCallback(&error, &resource_list));
371 base::RunLoop().RunUntilIdle();
373 EXPECT_EQ(GDATA_NO_CONNECTION, error);
374 EXPECT_FALSE(resource_list);
377 TEST_F(FakeDriveServiceTest, GetChangeList_NoNewEntries) {
378 ASSERT_TRUE(fake_service_.LoadResourceListForWapi(
379 "gdata/root_feed.json"));
380 // Load the account_metadata.json as well to add the largest changestamp
381 // (654321) to the existing entries.
382 ASSERT_TRUE(fake_service_.LoadAccountMetadataForWapi(
383 "gdata/account_metadata.json"));
385 GDataErrorCode error = GDATA_OTHER_ERROR;
386 scoped_ptr<ResourceList> resource_list;
387 fake_service_.GetChangeList(
388 654321 + 1, // start_changestamp
389 test_util::CreateCopyResultCallback(&error, &resource_list));
390 base::RunLoop().RunUntilIdle();
392 EXPECT_EQ(HTTP_SUCCESS, error);
393 ASSERT_TRUE(resource_list);
394 EXPECT_EQ(fake_service_.about_resource().largest_change_id(),
395 resource_list->largest_changestamp());
396 // This should be empty as the latest changestamp was passed to
397 // GetResourceList(), hence there should be no new entries.
398 EXPECT_EQ(0U, resource_list->entries().size());
399 // It's considered loaded even if the result is empty.
400 EXPECT_EQ(1, fake_service_.change_list_load_count());
403 TEST_F(FakeDriveServiceTest, GetChangeList_WithNewEntry) {
404 ASSERT_TRUE(fake_service_.LoadResourceListForWapi(
405 "gdata/root_feed.json"));
406 // Load the account_metadata.json as well to add the largest changestamp
407 // (654321) to the existing entries.
408 ASSERT_TRUE(fake_service_.LoadAccountMetadataForWapi(
409 "gdata/account_metadata.json"));
410 // Add a new directory in the root directory. The new directory will have
411 // the changestamp of 654322.
412 ASSERT_TRUE(AddNewDirectory(
413 fake_service_.GetRootResourceId(), "new directory"));
415 // Get the resource list newer than 654321.
416 GDataErrorCode error = GDATA_OTHER_ERROR;
417 scoped_ptr<ResourceList> resource_list;
418 fake_service_.GetChangeList(
419 654321 + 1, // start_changestamp
420 test_util::CreateCopyResultCallback(&error, &resource_list));
421 base::RunLoop().RunUntilIdle();
423 EXPECT_EQ(HTTP_SUCCESS, error);
424 ASSERT_TRUE(resource_list);
425 EXPECT_EQ(fake_service_.about_resource().largest_change_id(),
426 resource_list->largest_changestamp());
427 // The result should only contain the newly created directory.
428 ASSERT_EQ(1U, resource_list->entries().size());
429 EXPECT_EQ("new directory", resource_list->entries()[0]->title());
430 EXPECT_EQ(1, fake_service_.change_list_load_count());
433 TEST_F(FakeDriveServiceTest, GetChangeList_Offline) {
434 ASSERT_TRUE(fake_service_.LoadResourceListForWapi(
435 "gdata/root_feed.json"));
436 fake_service_.set_offline(true);
438 GDataErrorCode error = GDATA_OTHER_ERROR;
439 scoped_ptr<ResourceList> resource_list;
440 fake_service_.GetChangeList(
441 654321, // start_changestamp
442 test_util::CreateCopyResultCallback(&error, &resource_list));
443 base::RunLoop().RunUntilIdle();
445 EXPECT_EQ(GDATA_NO_CONNECTION, error);
446 EXPECT_FALSE(resource_list);
449 TEST_F(FakeDriveServiceTest, GetChangeList_DeletedEntry) {
450 ASSERT_TRUE(fake_service_.LoadResourceListForWapi(
451 "gdata/root_feed.json"));
452 // Load the account_metadata.json as well to add the largest changestamp
453 // (654321) to the existing entries.
454 ASSERT_TRUE(fake_service_.LoadAccountMetadataForWapi(
455 "gdata/account_metadata.json"));
456 ASSERT_TRUE(Exists("file:2_file_resource_id"));
458 GDataErrorCode error = GDATA_OTHER_ERROR;
459 fake_service_.DeleteResource("file:2_file_resource_id",
460 std::string(), // etag
461 test_util::CreateCopyResultCallback(&error));
462 base::RunLoop().RunUntilIdle();
463 ASSERT_EQ(HTTP_NO_CONTENT, error);
464 ASSERT_FALSE(Exists("file:2_file_resource_id"));
466 // Get the resource list newer than 654321.
467 error = GDATA_OTHER_ERROR;
468 scoped_ptr<ResourceList> resource_list;
469 fake_service_.GetChangeList(
470 654321 + 1, // start_changestamp
471 test_util::CreateCopyResultCallback(&error, &resource_list));
472 base::RunLoop().RunUntilIdle();
474 EXPECT_EQ(HTTP_SUCCESS, error);
475 ASSERT_TRUE(resource_list);
476 EXPECT_EQ(fake_service_.about_resource().largest_change_id(),
477 resource_list->largest_changestamp());
478 // The result should only contain the deleted file.
479 ASSERT_EQ(1U, resource_list->entries().size());
480 const ResourceEntry& entry = *resource_list->entries()[0];
481 EXPECT_EQ("file:2_file_resource_id", entry.resource_id());
482 EXPECT_TRUE(entry.title().empty());
483 EXPECT_TRUE(entry.deleted());
484 EXPECT_EQ(1, fake_service_.change_list_load_count());
487 TEST_F(FakeDriveServiceTest, GetChangeList_TrashedEntry) {
488 ASSERT_TRUE(fake_service_.LoadResourceListForWapi(
489 "gdata/root_feed.json"));
490 // Load the account_metadata.json as well to add the largest changestamp
491 // (654321) to the existing entries.
492 ASSERT_TRUE(fake_service_.LoadAccountMetadataForWapi(
493 "gdata/account_metadata.json"));
494 ASSERT_TRUE(Exists("file:2_file_resource_id"));
496 GDataErrorCode error = GDATA_OTHER_ERROR;
497 fake_service_.TrashResource("file:2_file_resource_id",
498 test_util::CreateCopyResultCallback(&error));
499 base::RunLoop().RunUntilIdle();
500 ASSERT_EQ(HTTP_SUCCESS, error);
501 ASSERT_FALSE(Exists("file:2_file_resource_id"));
503 // Get the resource list newer than 654321.
504 error = GDATA_OTHER_ERROR;
505 scoped_ptr<ResourceList> resource_list;
506 fake_service_.GetChangeList(
507 654321 + 1, // start_changestamp
508 test_util::CreateCopyResultCallback(&error, &resource_list));
509 base::RunLoop().RunUntilIdle();
511 EXPECT_EQ(HTTP_SUCCESS, error);
512 ASSERT_TRUE(resource_list);
513 EXPECT_EQ(fake_service_.about_resource().largest_change_id(),
514 resource_list->largest_changestamp());
515 // The result should only contain the trashed file.
516 ASSERT_EQ(1U, resource_list->entries().size());
517 const ResourceEntry& entry = *resource_list->entries()[0];
518 EXPECT_EQ("file:2_file_resource_id", entry.resource_id());
519 EXPECT_TRUE(entry.deleted());
520 EXPECT_EQ(1, fake_service_.change_list_load_count());
523 TEST_F(FakeDriveServiceTest, GetRemainingChangeList_GetAllResourceList) {
524 ASSERT_TRUE(fake_service_.LoadResourceListForWapi(
525 "gdata/root_feed.json"));
526 fake_service_.set_default_max_results(6);
528 GDataErrorCode error = GDATA_OTHER_ERROR;
529 scoped_ptr<ResourceList> resource_list;
530 fake_service_.GetAllResourceList(
531 test_util::CreateCopyResultCallback(&error, &resource_list));
532 base::RunLoop().RunUntilIdle();
533 EXPECT_EQ(HTTP_SUCCESS, error);
534 ASSERT_TRUE(resource_list);
536 // Do some sanity check.
537 // The number of results is 14 entries. Thus, it should split into three
538 // chunks: 6, 6, and then 2.
539 EXPECT_EQ(6U, resource_list->entries().size());
540 EXPECT_EQ(1, fake_service_.resource_list_load_count());
542 // Second page loading.
543 const google_apis::Link* next_link =
544 resource_list->GetLinkByType(Link::LINK_NEXT);
545 ASSERT_TRUE(next_link);
546 // Keep the next url before releasing the |resource_list|.
547 GURL next_url(next_link->href());
549 error = GDATA_OTHER_ERROR;
550 resource_list.reset();
551 fake_service_.GetRemainingChangeList(
552 next_url,
553 test_util::CreateCopyResultCallback(&error, &resource_list));
554 base::RunLoop().RunUntilIdle();
556 EXPECT_EQ(HTTP_SUCCESS, error);
557 ASSERT_TRUE(resource_list);
559 EXPECT_EQ(6U, resource_list->entries().size());
560 EXPECT_EQ(1, fake_service_.resource_list_load_count());
562 // Third page loading.
563 next_link = resource_list->GetLinkByType(Link::LINK_NEXT);
564 ASSERT_TRUE(next_link);
565 next_url = GURL(next_link->href());
567 error = GDATA_OTHER_ERROR;
568 resource_list.reset();
569 fake_service_.GetRemainingChangeList(
570 next_url,
571 test_util::CreateCopyResultCallback(&error, &resource_list));
572 base::RunLoop().RunUntilIdle();
574 EXPECT_EQ(HTTP_SUCCESS, error);
575 ASSERT_TRUE(resource_list);
577 EXPECT_EQ(2U, resource_list->entries().size());
578 EXPECT_EQ(1, fake_service_.resource_list_load_count());
581 TEST_F(FakeDriveServiceTest,
582 GetRemainingFileList_GetResourceListInDirectory) {
583 ASSERT_TRUE(fake_service_.LoadResourceListForWapi(
584 "gdata/root_feed.json"));
585 fake_service_.set_default_max_results(3);
587 GDataErrorCode error = GDATA_OTHER_ERROR;
588 scoped_ptr<ResourceList> resource_list;
589 fake_service_.GetResourceListInDirectory(
590 fake_service_.GetRootResourceId(),
591 test_util::CreateCopyResultCallback(&error, &resource_list));
592 base::RunLoop().RunUntilIdle();
593 EXPECT_EQ(HTTP_SUCCESS, error);
594 ASSERT_TRUE(resource_list);
596 // Do some sanity check.
597 // The number of results is 8 entries. Thus, it should split into three
598 // chunks: 3, 3, and then 2.
599 EXPECT_EQ(3U, resource_list->entries().size());
600 EXPECT_EQ(1, fake_service_.directory_load_count());
602 // Second page loading.
603 const google_apis::Link* next_link =
604 resource_list->GetLinkByType(Link::LINK_NEXT);
605 ASSERT_TRUE(next_link);
606 // Keep the next url before releasing the |resource_list|.
607 GURL next_url(next_link->href());
609 error = GDATA_OTHER_ERROR;
610 resource_list.reset();
611 fake_service_.GetRemainingFileList(
612 next_url,
613 test_util::CreateCopyResultCallback(&error, &resource_list));
614 base::RunLoop().RunUntilIdle();
616 EXPECT_EQ(HTTP_SUCCESS, error);
617 ASSERT_TRUE(resource_list);
619 EXPECT_EQ(3U, resource_list->entries().size());
620 EXPECT_EQ(1, fake_service_.directory_load_count());
622 // Third page loading.
623 next_link = resource_list->GetLinkByType(Link::LINK_NEXT);
624 ASSERT_TRUE(next_link);
625 next_url = GURL(next_link->href());
627 error = GDATA_OTHER_ERROR;
628 resource_list.reset();
629 fake_service_.GetRemainingFileList(
630 next_url,
631 test_util::CreateCopyResultCallback(&error, &resource_list));
632 base::RunLoop().RunUntilIdle();
634 EXPECT_EQ(HTTP_SUCCESS, error);
635 ASSERT_TRUE(resource_list);
637 EXPECT_EQ(2U, resource_list->entries().size());
638 EXPECT_EQ(1, fake_service_.directory_load_count());
641 TEST_F(FakeDriveServiceTest, GetRemainingFileList_Search) {
642 ASSERT_TRUE(fake_service_.LoadResourceListForWapi(
643 "gdata/root_feed.json"));
644 fake_service_.set_default_max_results(2);
646 GDataErrorCode error = GDATA_OTHER_ERROR;
647 scoped_ptr<ResourceList> resource_list;
648 fake_service_.Search(
649 "File", // search_query
650 test_util::CreateCopyResultCallback(&error, &resource_list));
651 base::RunLoop().RunUntilIdle();
652 EXPECT_EQ(HTTP_SUCCESS, error);
653 ASSERT_TRUE(resource_list);
655 // Do some sanity check.
656 // The number of results is 4 entries. Thus, it should split into two
657 // chunks: 2, and then 2
658 EXPECT_EQ(2U, resource_list->entries().size());
660 // Second page loading.
661 const google_apis::Link* next_link =
662 resource_list->GetLinkByType(Link::LINK_NEXT);
663 ASSERT_TRUE(next_link);
664 // Keep the next url before releasing the |resource_list|.
665 GURL next_url(next_link->href());
667 error = GDATA_OTHER_ERROR;
668 resource_list.reset();
669 fake_service_.GetRemainingFileList(
670 next_url,
671 test_util::CreateCopyResultCallback(&error, &resource_list));
672 base::RunLoop().RunUntilIdle();
674 EXPECT_EQ(HTTP_SUCCESS, error);
675 ASSERT_TRUE(resource_list);
677 EXPECT_EQ(2U, resource_list->entries().size());
680 TEST_F(FakeDriveServiceTest, GetRemainingChangeList_GetChangeList) {
681 ASSERT_TRUE(fake_service_.LoadResourceListForWapi(
682 "gdata/root_feed.json"));
683 fake_service_.set_default_max_results(2);
685 // Load the account_metadata.json as well to add the largest changestamp
686 // (654321) to the existing entries.
687 ASSERT_TRUE(fake_service_.LoadAccountMetadataForWapi(
688 "gdata/account_metadata.json"));
689 // Add 5 new directory in the root directory. The new directory will have
690 // the changestamp of 654326.
691 for (int i = 0; i < 5; ++i) {
692 ASSERT_TRUE(AddNewDirectory(
693 fake_service_.GetRootResourceId(),
694 base::StringPrintf("new directory %d", i)));
697 GDataErrorCode error = GDATA_OTHER_ERROR;
698 scoped_ptr<ResourceList> resource_list;
699 fake_service_.GetChangeList(
700 654321 + 1, // start_changestamp
701 test_util::CreateCopyResultCallback(&error, &resource_list));
702 base::RunLoop().RunUntilIdle();
703 EXPECT_EQ(HTTP_SUCCESS, error);
704 ASSERT_TRUE(resource_list);
706 // Do some sanity check.
707 // The number of results is 5 entries. Thus, it should split into three
708 // chunks: 2, 2 and then 1.
709 EXPECT_EQ(2U, resource_list->entries().size());
710 EXPECT_EQ(1, fake_service_.change_list_load_count());
712 // Second page loading.
713 const google_apis::Link* next_link =
714 resource_list->GetLinkByType(Link::LINK_NEXT);
715 ASSERT_TRUE(next_link);
716 // Keep the next url before releasing the |resource_list|.
717 GURL next_url(next_link->href());
719 error = GDATA_OTHER_ERROR;
720 resource_list.reset();
721 fake_service_.GetRemainingChangeList(
722 next_url,
723 test_util::CreateCopyResultCallback(&error, &resource_list));
724 base::RunLoop().RunUntilIdle();
726 EXPECT_EQ(HTTP_SUCCESS, error);
727 ASSERT_TRUE(resource_list);
729 EXPECT_EQ(2U, resource_list->entries().size());
730 EXPECT_EQ(1, fake_service_.change_list_load_count());
732 // Third page loading.
733 next_link = resource_list->GetLinkByType(Link::LINK_NEXT);
734 ASSERT_TRUE(next_link);
735 next_url = GURL(next_link->href());
737 error = GDATA_OTHER_ERROR;
738 resource_list.reset();
739 fake_service_.GetRemainingChangeList(
740 next_url,
741 test_util::CreateCopyResultCallback(&error, &resource_list));
742 base::RunLoop().RunUntilIdle();
744 EXPECT_EQ(HTTP_SUCCESS, error);
745 ASSERT_TRUE(resource_list);
747 EXPECT_EQ(1U, resource_list->entries().size());
748 EXPECT_EQ(1, fake_service_.change_list_load_count());
751 TEST_F(FakeDriveServiceTest, GetAboutResource) {
752 ASSERT_TRUE(fake_service_.LoadAccountMetadataForWapi(
753 "gdata/account_metadata.json"));
755 GDataErrorCode error = GDATA_OTHER_ERROR;
756 scoped_ptr<AboutResource> about_resource;
757 fake_service_.GetAboutResource(
758 test_util::CreateCopyResultCallback(&error, &about_resource));
759 base::RunLoop().RunUntilIdle();
761 EXPECT_EQ(HTTP_SUCCESS, error);
763 ASSERT_TRUE(about_resource);
764 // Do some sanity check.
765 EXPECT_EQ(fake_service_.GetRootResourceId(),
766 about_resource->root_folder_id());
767 EXPECT_EQ(1, fake_service_.about_resource_load_count());
770 TEST_F(FakeDriveServiceTest, GetAboutResource_Offline) {
771 ASSERT_TRUE(fake_service_.LoadAccountMetadataForWapi(
772 "gdata/account_metadata.json"));
773 fake_service_.set_offline(true);
775 GDataErrorCode error = GDATA_OTHER_ERROR;
776 scoped_ptr<AboutResource> about_resource;
777 fake_service_.GetAboutResource(
778 test_util::CreateCopyResultCallback(&error, &about_resource));
779 base::RunLoop().RunUntilIdle();
781 EXPECT_EQ(GDATA_NO_CONNECTION, error);
782 EXPECT_FALSE(about_resource);
785 TEST_F(FakeDriveServiceTest, GetAppList) {
786 ASSERT_TRUE(fake_service_.LoadAppListForDriveApi(
787 "drive/applist.json"));
789 GDataErrorCode error = GDATA_OTHER_ERROR;
790 scoped_ptr<AppList> app_list;
791 fake_service_.GetAppList(
792 test_util::CreateCopyResultCallback(&error, &app_list));
793 base::RunLoop().RunUntilIdle();
795 EXPECT_EQ(HTTP_SUCCESS, error);
797 ASSERT_TRUE(app_list);
798 EXPECT_EQ(1, fake_service_.app_list_load_count());
801 TEST_F(FakeDriveServiceTest, GetAppList_Offline) {
802 ASSERT_TRUE(fake_service_.LoadAppListForDriveApi(
803 "drive/applist.json"));
804 fake_service_.set_offline(true);
806 GDataErrorCode error = GDATA_OTHER_ERROR;
807 scoped_ptr<AppList> app_list;
808 fake_service_.GetAppList(
809 test_util::CreateCopyResultCallback(&error, &app_list));
810 base::RunLoop().RunUntilIdle();
812 EXPECT_EQ(GDATA_NO_CONNECTION, error);
813 EXPECT_FALSE(app_list);
816 TEST_F(FakeDriveServiceTest, GetResourceEntry_ExistingFile) {
817 ASSERT_TRUE(fake_service_.LoadResourceListForWapi(
818 "gdata/root_feed.json"));
820 const std::string kResourceId = "file:2_file_resource_id";
821 GDataErrorCode error = GDATA_OTHER_ERROR;
822 scoped_ptr<ResourceEntry> resource_entry;
823 fake_service_.GetResourceEntry(
824 kResourceId,
825 test_util::CreateCopyResultCallback(&error, &resource_entry));
826 base::RunLoop().RunUntilIdle();
828 EXPECT_EQ(HTTP_SUCCESS, error);
829 ASSERT_TRUE(resource_entry);
830 // Do some sanity check.
831 EXPECT_EQ(kResourceId, resource_entry->resource_id());
834 TEST_F(FakeDriveServiceTest, GetResourceEntry_NonexistingFile) {
835 ASSERT_TRUE(fake_service_.LoadResourceListForWapi(
836 "gdata/root_feed.json"));
838 const std::string kResourceId = "file:nonexisting_resource_id";
839 GDataErrorCode error = GDATA_OTHER_ERROR;
840 scoped_ptr<ResourceEntry> resource_entry;
841 fake_service_.GetResourceEntry(
842 kResourceId,
843 test_util::CreateCopyResultCallback(&error, &resource_entry));
844 base::RunLoop().RunUntilIdle();
846 EXPECT_EQ(HTTP_NOT_FOUND, error);
847 ASSERT_FALSE(resource_entry);
850 TEST_F(FakeDriveServiceTest, GetResourceEntry_Offline) {
851 ASSERT_TRUE(fake_service_.LoadResourceListForWapi(
852 "gdata/root_feed.json"));
853 fake_service_.set_offline(true);
855 const std::string kResourceId = "file:2_file_resource_id";
856 GDataErrorCode error = GDATA_OTHER_ERROR;
857 scoped_ptr<ResourceEntry> resource_entry;
858 fake_service_.GetResourceEntry(
859 kResourceId,
860 test_util::CreateCopyResultCallback(&error, &resource_entry));
861 base::RunLoop().RunUntilIdle();
863 EXPECT_EQ(GDATA_NO_CONNECTION, error);
864 EXPECT_FALSE(resource_entry);
867 TEST_F(FakeDriveServiceTest, GetShareUrl) {
868 ASSERT_TRUE(fake_service_.LoadResourceListForWapi(
869 "gdata/root_feed.json"));
871 const std::string kResourceId = "file:2_file_resource_id";
872 GDataErrorCode error = GDATA_OTHER_ERROR;
873 GURL share_url;
874 fake_service_.GetShareUrl(
875 kResourceId,
876 GURL(), // embed origin
877 test_util::CreateCopyResultCallback(&error, &share_url));
878 base::RunLoop().RunUntilIdle();
880 EXPECT_EQ(HTTP_SUCCESS, error);
881 EXPECT_FALSE(share_url.is_empty());
884 TEST_F(FakeDriveServiceTest, DeleteResource_ExistingFile) {
885 ASSERT_TRUE(fake_service_.LoadResourceListForWapi(
886 "gdata/root_feed.json"));
888 // Resource "file:2_file_resource_id" should now exist.
889 ASSERT_TRUE(Exists("file:2_file_resource_id"));
891 GDataErrorCode error = GDATA_OTHER_ERROR;
892 fake_service_.DeleteResource("file:2_file_resource_id",
893 std::string(), // etag
894 test_util::CreateCopyResultCallback(&error));
895 base::RunLoop().RunUntilIdle();
897 EXPECT_EQ(HTTP_NO_CONTENT, error);
898 // Resource "file:2_file_resource_id" should be gone now.
899 EXPECT_FALSE(Exists("file:2_file_resource_id"));
901 error = GDATA_OTHER_ERROR;
902 fake_service_.DeleteResource("file:2_file_resource_id",
903 std::string(), // etag
904 test_util::CreateCopyResultCallback(&error));
905 base::RunLoop().RunUntilIdle();
906 EXPECT_EQ(HTTP_NOT_FOUND, error);
907 EXPECT_FALSE(Exists("file:2_file_resource_id"));
910 TEST_F(FakeDriveServiceTest, DeleteResource_NonexistingFile) {
911 ASSERT_TRUE(fake_service_.LoadResourceListForWapi(
912 "gdata/root_feed.json"));
914 GDataErrorCode error = GDATA_OTHER_ERROR;
915 fake_service_.DeleteResource("file:nonexisting_resource_id",
916 std::string(), // etag
917 test_util::CreateCopyResultCallback(&error));
918 base::RunLoop().RunUntilIdle();
920 EXPECT_EQ(HTTP_NOT_FOUND, error);
923 TEST_F(FakeDriveServiceTest, DeleteResource_ETagMatch) {
924 ASSERT_TRUE(fake_service_.LoadResourceListForWapi(
925 "gdata/root_feed.json"));
927 // Resource "file:2_file_resource_id" should now exist.
928 scoped_ptr<ResourceEntry> entry = FindEntry("file:2_file_resource_id");
929 ASSERT_TRUE(entry);
930 ASSERT_FALSE(entry->deleted());
931 ASSERT_FALSE(entry->etag().empty());
933 GDataErrorCode error = GDATA_OTHER_ERROR;
934 fake_service_.DeleteResource("file:2_file_resource_id",
935 entry->etag() + "_mismatch",
936 test_util::CreateCopyResultCallback(&error));
937 base::RunLoop().RunUntilIdle();
939 EXPECT_EQ(HTTP_PRECONDITION, error);
940 // Resource "file:2_file_resource_id" should still exist.
941 EXPECT_TRUE(Exists("file:2_file_resource_id"));
943 error = GDATA_OTHER_ERROR;
944 fake_service_.DeleteResource("file:2_file_resource_id",
945 entry->etag(),
946 test_util::CreateCopyResultCallback(&error));
947 base::RunLoop().RunUntilIdle();
948 EXPECT_EQ(HTTP_NO_CONTENT, error);
949 // Resource "file:2_file_resource_id" should be gone now.
950 EXPECT_FALSE(Exists("file:2_file_resource_id"));
953 TEST_F(FakeDriveServiceTest, DeleteResource_Offline) {
954 ASSERT_TRUE(fake_service_.LoadResourceListForWapi(
955 "gdata/root_feed.json"));
956 fake_service_.set_offline(true);
958 GDataErrorCode error = GDATA_OTHER_ERROR;
959 fake_service_.DeleteResource("file:2_file_resource_id",
960 std::string(), // etag
961 test_util::CreateCopyResultCallback(&error));
962 base::RunLoop().RunUntilIdle();
964 EXPECT_EQ(GDATA_NO_CONNECTION, error);
967 TEST_F(FakeDriveServiceTest, TrashResource_ExistingFile) {
968 ASSERT_TRUE(fake_service_.LoadResourceListForWapi(
969 "gdata/root_feed.json"));
971 // Resource "file:2_file_resource_id" should now exist.
972 ASSERT_TRUE(Exists("file:2_file_resource_id"));
974 GDataErrorCode error = GDATA_OTHER_ERROR;
975 fake_service_.TrashResource("file:2_file_resource_id",
976 test_util::CreateCopyResultCallback(&error));
977 base::RunLoop().RunUntilIdle();
979 EXPECT_EQ(HTTP_SUCCESS, error);
980 // Resource "file:2_file_resource_id" should be gone now.
981 EXPECT_FALSE(Exists("file:2_file_resource_id"));
983 error = GDATA_OTHER_ERROR;
984 fake_service_.TrashResource("file:2_file_resource_id",
985 test_util::CreateCopyResultCallback(&error));
986 base::RunLoop().RunUntilIdle();
987 EXPECT_EQ(HTTP_NOT_FOUND, error);
988 EXPECT_FALSE(Exists("file:2_file_resource_id"));
991 TEST_F(FakeDriveServiceTest, TrashResource_NonexistingFile) {
992 ASSERT_TRUE(fake_service_.LoadResourceListForWapi(
993 "gdata/root_feed.json"));
995 GDataErrorCode error = GDATA_OTHER_ERROR;
996 fake_service_.TrashResource("file:nonexisting_resource_id",
997 test_util::CreateCopyResultCallback(&error));
998 base::RunLoop().RunUntilIdle();
1000 EXPECT_EQ(HTTP_NOT_FOUND, error);
1003 TEST_F(FakeDriveServiceTest, TrashResource_Offline) {
1004 ASSERT_TRUE(fake_service_.LoadResourceListForWapi(
1005 "gdata/root_feed.json"));
1006 fake_service_.set_offline(true);
1008 GDataErrorCode error = GDATA_OTHER_ERROR;
1009 fake_service_.TrashResource("file:2_file_resource_id",
1010 test_util::CreateCopyResultCallback(&error));
1011 base::RunLoop().RunUntilIdle();
1013 EXPECT_EQ(GDATA_NO_CONNECTION, error);
1016 TEST_F(FakeDriveServiceTest, DownloadFile_ExistingFile) {
1017 ASSERT_TRUE(fake_service_.LoadResourceListForWapi(
1018 "gdata/root_feed.json"));
1020 base::ScopedTempDir temp_dir;
1021 ASSERT_TRUE(temp_dir.CreateUniqueTempDir());
1023 std::vector<test_util::ProgressInfo> download_progress_values;
1025 const base::FilePath kOutputFilePath =
1026 temp_dir.path().AppendASCII("whatever.txt");
1027 GDataErrorCode error = GDATA_OTHER_ERROR;
1028 base::FilePath output_file_path;
1029 test_util::TestGetContentCallback get_content_callback;
1030 fake_service_.DownloadFile(
1031 kOutputFilePath,
1032 "file:2_file_resource_id",
1033 test_util::CreateCopyResultCallback(&error, &output_file_path),
1034 get_content_callback.callback(),
1035 base::Bind(&test_util::AppendProgressCallbackResult,
1036 &download_progress_values));
1037 base::RunLoop().RunUntilIdle();
1039 EXPECT_EQ(HTTP_SUCCESS, error);
1040 EXPECT_EQ(output_file_path, kOutputFilePath);
1041 std::string content;
1042 ASSERT_TRUE(base::ReadFileToString(output_file_path, &content));
1043 // The content is "x"s of the file size specified in root_feed.json.
1044 EXPECT_EQ("This is some test content.", content);
1045 ASSERT_TRUE(!download_progress_values.empty());
1046 EXPECT_TRUE(base::STLIsSorted(download_progress_values));
1047 EXPECT_LE(0, download_progress_values.front().first);
1048 EXPECT_GE(26, download_progress_values.back().first);
1049 EXPECT_EQ(content, get_content_callback.GetConcatenatedData());
1052 TEST_F(FakeDriveServiceTest, DownloadFile_NonexistingFile) {
1053 ASSERT_TRUE(fake_service_.LoadResourceListForWapi(
1054 "gdata/root_feed.json"));
1056 base::ScopedTempDir temp_dir;
1057 ASSERT_TRUE(temp_dir.CreateUniqueTempDir());
1059 const base::FilePath kOutputFilePath =
1060 temp_dir.path().AppendASCII("whatever.txt");
1061 GDataErrorCode error = GDATA_OTHER_ERROR;
1062 base::FilePath output_file_path;
1063 fake_service_.DownloadFile(
1064 kOutputFilePath,
1065 "file:non_existent_file_resource_id",
1066 test_util::CreateCopyResultCallback(&error, &output_file_path),
1067 GetContentCallback(),
1068 ProgressCallback());
1069 base::RunLoop().RunUntilIdle();
1071 EXPECT_EQ(HTTP_NOT_FOUND, error);
1074 TEST_F(FakeDriveServiceTest, DownloadFile_Offline) {
1075 ASSERT_TRUE(fake_service_.LoadResourceListForWapi(
1076 "gdata/root_feed.json"));
1077 fake_service_.set_offline(true);
1079 base::ScopedTempDir temp_dir;
1080 ASSERT_TRUE(temp_dir.CreateUniqueTempDir());
1082 const base::FilePath kOutputFilePath =
1083 temp_dir.path().AppendASCII("whatever.txt");
1084 GDataErrorCode error = GDATA_OTHER_ERROR;
1085 base::FilePath output_file_path;
1086 fake_service_.DownloadFile(
1087 kOutputFilePath,
1088 "file:2_file_resource_id",
1089 test_util::CreateCopyResultCallback(&error, &output_file_path),
1090 GetContentCallback(),
1091 ProgressCallback());
1092 base::RunLoop().RunUntilIdle();
1094 EXPECT_EQ(GDATA_NO_CONNECTION, error);
1097 TEST_F(FakeDriveServiceTest, CopyResource) {
1098 const base::Time::Exploded kModifiedDate = {2012, 7, 0, 19, 15, 59, 13, 123};
1100 ASSERT_TRUE(fake_service_.LoadResourceListForWapi(
1101 "gdata/root_feed.json"));
1102 ASSERT_TRUE(fake_service_.LoadAccountMetadataForWapi(
1103 "gdata/account_metadata.json"));
1105 int64 old_largest_change_id = GetLargestChangeByAboutResource();
1107 const std::string kResourceId = "file:2_file_resource_id";
1108 const std::string kParentResourceId = "folder:2_folder_resource_id";
1109 GDataErrorCode error = GDATA_OTHER_ERROR;
1110 scoped_ptr<ResourceEntry> resource_entry;
1111 fake_service_.CopyResource(
1112 kResourceId,
1113 kParentResourceId,
1114 "new title",
1115 base::Time::FromUTCExploded(kModifiedDate),
1116 test_util::CreateCopyResultCallback(&error, &resource_entry));
1117 base::RunLoop().RunUntilIdle();
1119 EXPECT_EQ(HTTP_SUCCESS, error);
1120 ASSERT_TRUE(resource_entry);
1121 // The copied entry should have the new resource ID and the title.
1122 EXPECT_NE(kResourceId, resource_entry->resource_id());
1123 EXPECT_EQ("new title", resource_entry->title());
1124 EXPECT_EQ(base::Time::FromUTCExploded(kModifiedDate),
1125 resource_entry->updated_time());
1126 EXPECT_TRUE(HasParent(resource_entry->resource_id(), kParentResourceId));
1127 // Should be incremented as a new hosted document was created.
1128 EXPECT_EQ(old_largest_change_id + 1,
1129 fake_service_.about_resource().largest_change_id());
1130 EXPECT_EQ(old_largest_change_id + 1, GetLargestChangeByAboutResource());
1133 TEST_F(FakeDriveServiceTest, CopyResource_NonExisting) {
1134 ASSERT_TRUE(fake_service_.LoadResourceListForWapi(
1135 "gdata/root_feed.json"));
1137 const std::string kResourceId = "document:nonexisting_resource_id";
1138 GDataErrorCode error = GDATA_OTHER_ERROR;
1139 scoped_ptr<ResourceEntry> resource_entry;
1140 fake_service_.CopyResource(
1141 kResourceId,
1142 "folder:1_folder_resource_id",
1143 "new title",
1144 base::Time(),
1145 test_util::CreateCopyResultCallback(&error, &resource_entry));
1146 base::RunLoop().RunUntilIdle();
1148 EXPECT_EQ(HTTP_NOT_FOUND, error);
1151 TEST_F(FakeDriveServiceTest, CopyResource_EmptyParentResourceId) {
1152 ASSERT_TRUE(fake_service_.LoadResourceListForWapi(
1153 "gdata/root_feed.json"));
1154 ASSERT_TRUE(fake_service_.LoadAccountMetadataForWapi(
1155 "gdata/account_metadata.json"));
1157 int64 old_largest_change_id = GetLargestChangeByAboutResource();
1159 const std::string kResourceId = "file:2_file_resource_id";
1160 GDataErrorCode error = GDATA_OTHER_ERROR;
1161 scoped_ptr<ResourceEntry> resource_entry;
1162 fake_service_.CopyResource(
1163 kResourceId,
1164 std::string(),
1165 "new title",
1166 base::Time(),
1167 test_util::CreateCopyResultCallback(&error, &resource_entry));
1168 base::RunLoop().RunUntilIdle();
1170 EXPECT_EQ(HTTP_SUCCESS, error);
1171 ASSERT_TRUE(resource_entry);
1172 // The copied entry should have the new resource ID and the title.
1173 EXPECT_NE(kResourceId, resource_entry->resource_id());
1174 EXPECT_EQ("new title", resource_entry->title());
1175 EXPECT_TRUE(HasParent(kResourceId, fake_service_.GetRootResourceId()));
1176 // Should be incremented as a new hosted document was created.
1177 EXPECT_EQ(old_largest_change_id + 1,
1178 fake_service_.about_resource().largest_change_id());
1179 EXPECT_EQ(old_largest_change_id + 1, GetLargestChangeByAboutResource());
1182 TEST_F(FakeDriveServiceTest, CopyResource_Offline) {
1183 ASSERT_TRUE(fake_service_.LoadResourceListForWapi(
1184 "gdata/root_feed.json"));
1185 fake_service_.set_offline(true);
1187 const std::string kResourceId = "file:2_file_resource_id";
1188 GDataErrorCode error = GDATA_OTHER_ERROR;
1189 scoped_ptr<ResourceEntry> resource_entry;
1190 fake_service_.CopyResource(
1191 kResourceId,
1192 "folder:1_folder_resource_id",
1193 "new title",
1194 base::Time(),
1195 test_util::CreateCopyResultCallback(&error, &resource_entry));
1196 base::RunLoop().RunUntilIdle();
1198 EXPECT_EQ(GDATA_NO_CONNECTION, error);
1199 EXPECT_FALSE(resource_entry);
1202 TEST_F(FakeDriveServiceTest, UpdateResource) {
1203 const base::Time::Exploded kModifiedDate = {2012, 7, 0, 19, 15, 59, 13, 123};
1204 const base::Time::Exploded kViewedDate = {2013, 8, 1, 20, 16, 00, 14, 234};
1206 ASSERT_TRUE(fake_service_.LoadResourceListForWapi(
1207 "gdata/root_feed.json"));
1208 ASSERT_TRUE(fake_service_.LoadAccountMetadataForWapi(
1209 "gdata/account_metadata.json"));
1211 int64 old_largest_change_id = GetLargestChangeByAboutResource();
1213 const std::string kResourceId = "file:2_file_resource_id";
1214 const std::string kParentResourceId = "folder:2_folder_resource_id";
1215 GDataErrorCode error = GDATA_OTHER_ERROR;
1216 scoped_ptr<ResourceEntry> resource_entry;
1217 fake_service_.UpdateResource(
1218 kResourceId,
1219 kParentResourceId,
1220 "new title",
1221 base::Time::FromUTCExploded(kModifiedDate),
1222 base::Time::FromUTCExploded(kViewedDate),
1223 test_util::CreateCopyResultCallback(&error, &resource_entry));
1224 base::RunLoop().RunUntilIdle();
1226 EXPECT_EQ(HTTP_SUCCESS, error);
1227 ASSERT_TRUE(resource_entry);
1228 // The updated entry should have the new title.
1229 EXPECT_EQ(kResourceId, resource_entry->resource_id());
1230 EXPECT_EQ("new title", resource_entry->title());
1231 EXPECT_EQ(base::Time::FromUTCExploded(kModifiedDate),
1232 resource_entry->updated_time());
1233 EXPECT_EQ(base::Time::FromUTCExploded(kViewedDate),
1234 resource_entry->last_viewed_time());
1235 EXPECT_TRUE(HasParent(kResourceId, kParentResourceId));
1236 // Should be incremented as a new hosted document was created.
1237 EXPECT_EQ(old_largest_change_id + 1,
1238 fake_service_.about_resource().largest_change_id());
1239 EXPECT_EQ(old_largest_change_id + 1, GetLargestChangeByAboutResource());
1242 TEST_F(FakeDriveServiceTest, UpdateResource_NonExisting) {
1243 ASSERT_TRUE(fake_service_.LoadResourceListForWapi(
1244 "gdata/root_feed.json"));
1246 const std::string kResourceId = "document:nonexisting_resource_id";
1247 GDataErrorCode error = GDATA_OTHER_ERROR;
1248 scoped_ptr<ResourceEntry> resource_entry;
1249 fake_service_.UpdateResource(
1250 kResourceId,
1251 "folder:1_folder_resource_id",
1252 "new title",
1253 base::Time(),
1254 base::Time(),
1255 test_util::CreateCopyResultCallback(&error, &resource_entry));
1256 base::RunLoop().RunUntilIdle();
1258 EXPECT_EQ(HTTP_NOT_FOUND, error);
1261 TEST_F(FakeDriveServiceTest, UpdateResource_EmptyParentResourceId) {
1262 ASSERT_TRUE(fake_service_.LoadResourceListForWapi(
1263 "gdata/root_feed.json"));
1264 ASSERT_TRUE(fake_service_.LoadAccountMetadataForWapi(
1265 "gdata/account_metadata.json"));
1267 int64 old_largest_change_id = GetLargestChangeByAboutResource();
1269 const std::string kResourceId = "file:2_file_resource_id";
1271 // Just make sure that the resource is under root.
1272 ASSERT_TRUE(HasParent(kResourceId, "fake_root"));
1274 GDataErrorCode error = GDATA_OTHER_ERROR;
1275 scoped_ptr<ResourceEntry> resource_entry;
1276 fake_service_.UpdateResource(
1277 kResourceId,
1278 std::string(),
1279 "new title",
1280 base::Time(),
1281 base::Time(),
1282 test_util::CreateCopyResultCallback(&error, &resource_entry));
1283 base::RunLoop().RunUntilIdle();
1285 EXPECT_EQ(HTTP_SUCCESS, error);
1286 ASSERT_TRUE(resource_entry);
1287 // The updated entry should have the new title.
1288 EXPECT_EQ(kResourceId, resource_entry->resource_id());
1289 EXPECT_EQ("new title", resource_entry->title());
1290 EXPECT_TRUE(HasParent(kResourceId, "fake_root"));
1291 // Should be incremented as a new hosted document was created.
1292 EXPECT_EQ(old_largest_change_id + 1,
1293 fake_service_.about_resource().largest_change_id());
1294 EXPECT_EQ(old_largest_change_id + 1, GetLargestChangeByAboutResource());
1297 TEST_F(FakeDriveServiceTest, UpdateResource_Offline) {
1298 ASSERT_TRUE(fake_service_.LoadResourceListForWapi(
1299 "gdata/root_feed.json"));
1300 fake_service_.set_offline(true);
1302 const std::string kResourceId = "file:2_file_resource_id";
1303 GDataErrorCode error = GDATA_OTHER_ERROR;
1304 scoped_ptr<ResourceEntry> resource_entry;
1305 fake_service_.UpdateResource(
1306 kResourceId,
1307 std::string(),
1308 "new title",
1309 base::Time(),
1310 base::Time(),
1311 test_util::CreateCopyResultCallback(&error, &resource_entry));
1312 base::RunLoop().RunUntilIdle();
1314 EXPECT_EQ(GDATA_NO_CONNECTION, error);
1315 EXPECT_FALSE(resource_entry);
1318 TEST_F(FakeDriveServiceTest, RenameResource_ExistingFile) {
1319 ASSERT_TRUE(fake_service_.LoadResourceListForWapi(
1320 "gdata/root_feed.json"));
1321 ASSERT_TRUE(fake_service_.LoadAccountMetadataForWapi(
1322 "gdata/account_metadata.json"));
1324 int64 old_largest_change_id = GetLargestChangeByAboutResource();
1326 const std::string kResourceId = "file:2_file_resource_id";
1328 GDataErrorCode error = GDATA_OTHER_ERROR;
1329 fake_service_.RenameResource(kResourceId,
1330 "new title",
1331 test_util::CreateCopyResultCallback(&error));
1332 base::RunLoop().RunUntilIdle();
1334 EXPECT_EQ(HTTP_SUCCESS, error);
1336 scoped_ptr<ResourceEntry> resource_entry = FindEntry(kResourceId);
1337 ASSERT_TRUE(resource_entry);
1338 EXPECT_EQ("new title", resource_entry->title());
1339 // Should be incremented as a file was renamed.
1340 EXPECT_EQ(old_largest_change_id + 1,
1341 fake_service_.about_resource().largest_change_id());
1342 EXPECT_EQ(old_largest_change_id + 1, GetLargestChangeByAboutResource());
1345 TEST_F(FakeDriveServiceTest, RenameResource_NonexistingFile) {
1346 ASSERT_TRUE(fake_service_.LoadResourceListForWapi(
1347 "gdata/root_feed.json"));
1349 const std::string kResourceId = "file:nonexisting_file";
1351 GDataErrorCode error = GDATA_OTHER_ERROR;
1352 fake_service_.RenameResource(kResourceId,
1353 "new title",
1354 test_util::CreateCopyResultCallback(&error));
1355 base::RunLoop().RunUntilIdle();
1357 EXPECT_EQ(HTTP_NOT_FOUND, error);
1360 TEST_F(FakeDriveServiceTest, RenameResource_Offline) {
1361 ASSERT_TRUE(fake_service_.LoadResourceListForWapi(
1362 "gdata/root_feed.json"));
1363 fake_service_.set_offline(true);
1365 const std::string kResourceId = "file:2_file_resource_id";
1367 GDataErrorCode error = GDATA_OTHER_ERROR;
1368 fake_service_.RenameResource(kResourceId,
1369 "new title",
1370 test_util::CreateCopyResultCallback(&error));
1371 base::RunLoop().RunUntilIdle();
1373 EXPECT_EQ(GDATA_NO_CONNECTION, error);
1376 TEST_F(FakeDriveServiceTest, AddResourceToDirectory_FileInRootDirectory) {
1377 ASSERT_TRUE(fake_service_.LoadResourceListForWapi(
1378 "gdata/root_feed.json"));
1379 ASSERT_TRUE(fake_service_.LoadAccountMetadataForWapi(
1380 "gdata/account_metadata.json"));
1382 int64 old_largest_change_id = GetLargestChangeByAboutResource();
1384 const std::string kResourceId = "file:2_file_resource_id";
1385 const std::string kOldParentResourceId = fake_service_.GetRootResourceId();
1386 const std::string kNewParentResourceId = "folder:1_folder_resource_id";
1388 // Here's the original parent link.
1389 EXPECT_TRUE(HasParent(kResourceId, kOldParentResourceId));
1390 EXPECT_FALSE(HasParent(kResourceId, kNewParentResourceId));
1392 GDataErrorCode error = GDATA_OTHER_ERROR;
1393 fake_service_.AddResourceToDirectory(
1394 kNewParentResourceId,
1395 kResourceId,
1396 test_util::CreateCopyResultCallback(&error));
1397 base::RunLoop().RunUntilIdle();
1399 EXPECT_EQ(HTTP_SUCCESS, error);
1401 // The parent link should now be changed.
1402 EXPECT_TRUE(HasParent(kResourceId, kOldParentResourceId));
1403 EXPECT_TRUE(HasParent(kResourceId, kNewParentResourceId));
1404 // Should be incremented as a file was moved.
1405 EXPECT_EQ(old_largest_change_id + 1,
1406 fake_service_.about_resource().largest_change_id());
1407 EXPECT_EQ(old_largest_change_id + 1, GetLargestChangeByAboutResource());
1410 TEST_F(FakeDriveServiceTest, AddResourceToDirectory_FileInNonRootDirectory) {
1411 ASSERT_TRUE(fake_service_.LoadResourceListForWapi(
1412 "gdata/root_feed.json"));
1413 ASSERT_TRUE(fake_service_.LoadAccountMetadataForWapi(
1414 "gdata/account_metadata.json"));
1416 int64 old_largest_change_id = GetLargestChangeByAboutResource();
1418 const std::string kResourceId = "file:subdirectory_file_1_id";
1419 const std::string kOldParentResourceId = "folder:1_folder_resource_id";
1420 const std::string kNewParentResourceId = "folder:2_folder_resource_id";
1422 // Here's the original parent link.
1423 EXPECT_TRUE(HasParent(kResourceId, kOldParentResourceId));
1424 EXPECT_FALSE(HasParent(kResourceId, kNewParentResourceId));
1426 GDataErrorCode error = GDATA_OTHER_ERROR;
1427 fake_service_.AddResourceToDirectory(
1428 kNewParentResourceId,
1429 kResourceId,
1430 test_util::CreateCopyResultCallback(&error));
1431 base::RunLoop().RunUntilIdle();
1433 EXPECT_EQ(HTTP_SUCCESS, error);
1435 // The parent link should now be changed.
1436 EXPECT_TRUE(HasParent(kResourceId, kOldParentResourceId));
1437 EXPECT_TRUE(HasParent(kResourceId, kNewParentResourceId));
1438 // Should be incremented as a file was moved.
1439 EXPECT_EQ(old_largest_change_id + 1,
1440 fake_service_.about_resource().largest_change_id());
1441 EXPECT_EQ(old_largest_change_id + 1, GetLargestChangeByAboutResource());
1444 TEST_F(FakeDriveServiceTest, AddResourceToDirectory_NonexistingFile) {
1445 ASSERT_TRUE(fake_service_.LoadResourceListForWapi(
1446 "gdata/root_feed.json"));
1448 const std::string kResourceId = "file:nonexisting_file";
1449 const std::string kNewParentResourceId = "folder:1_folder_resource_id";
1451 GDataErrorCode error = GDATA_OTHER_ERROR;
1452 fake_service_.AddResourceToDirectory(
1453 kNewParentResourceId,
1454 kResourceId,
1455 test_util::CreateCopyResultCallback(&error));
1456 base::RunLoop().RunUntilIdle();
1458 EXPECT_EQ(HTTP_NOT_FOUND, error);
1461 TEST_F(FakeDriveServiceTest, AddResourceToDirectory_OrphanFile) {
1462 ASSERT_TRUE(fake_service_.LoadResourceListForWapi(
1463 "gdata/root_feed.json"));
1464 ASSERT_TRUE(fake_service_.LoadAccountMetadataForWapi(
1465 "gdata/account_metadata.json"));
1467 int64 old_largest_change_id = GetLargestChangeByAboutResource();
1469 const std::string kResourceId = "file:1_orphanfile_resource_id";
1470 const std::string kNewParentResourceId = "folder:1_folder_resource_id";
1472 // The file does not belong to any directory, even to the root.
1473 EXPECT_FALSE(HasParent(kResourceId, kNewParentResourceId));
1474 EXPECT_FALSE(HasParent(kResourceId, fake_service_.GetRootResourceId()));
1476 GDataErrorCode error = GDATA_OTHER_ERROR;
1477 fake_service_.AddResourceToDirectory(
1478 kNewParentResourceId,
1479 kResourceId,
1480 test_util::CreateCopyResultCallback(&error));
1481 base::RunLoop().RunUntilIdle();
1483 EXPECT_EQ(HTTP_SUCCESS, error);
1485 // The parent link should now be changed.
1486 EXPECT_TRUE(HasParent(kResourceId, kNewParentResourceId));
1487 EXPECT_FALSE(HasParent(kResourceId, fake_service_.GetRootResourceId()));
1488 // Should be incremented as a file was moved.
1489 EXPECT_EQ(old_largest_change_id + 1,
1490 fake_service_.about_resource().largest_change_id());
1491 EXPECT_EQ(old_largest_change_id + 1, GetLargestChangeByAboutResource());
1494 TEST_F(FakeDriveServiceTest, AddResourceToDirectory_Offline) {
1495 ASSERT_TRUE(fake_service_.LoadResourceListForWapi(
1496 "gdata/root_feed.json"));
1497 fake_service_.set_offline(true);
1499 const std::string kResourceId = "file:2_file_resource_id";
1500 const std::string kNewParentResourceId = "folder:1_folder_resource_id";
1502 GDataErrorCode error = GDATA_OTHER_ERROR;
1503 fake_service_.AddResourceToDirectory(
1504 kNewParentResourceId,
1505 kResourceId,
1506 test_util::CreateCopyResultCallback(&error));
1507 base::RunLoop().RunUntilIdle();
1509 EXPECT_EQ(GDATA_NO_CONNECTION, error);
1512 TEST_F(FakeDriveServiceTest, RemoveResourceFromDirectory_ExistingFile) {
1513 ASSERT_TRUE(fake_service_.LoadResourceListForWapi(
1514 "gdata/root_feed.json"));
1515 ASSERT_TRUE(fake_service_.LoadAccountMetadataForWapi(
1516 "gdata/account_metadata.json"));
1518 int64 old_largest_change_id = GetLargestChangeByAboutResource();
1520 const std::string kResourceId = "file:subdirectory_file_1_id";
1521 const std::string kParentResourceId = "folder:1_folder_resource_id";
1523 scoped_ptr<ResourceEntry> resource_entry = FindEntry(kResourceId);
1524 ASSERT_TRUE(resource_entry);
1525 // The parent link should exist now.
1526 const google_apis::Link* parent_link =
1527 resource_entry->GetLinkByType(Link::LINK_PARENT);
1528 ASSERT_TRUE(parent_link);
1530 GDataErrorCode error = GDATA_OTHER_ERROR;
1531 fake_service_.RemoveResourceFromDirectory(
1532 kParentResourceId,
1533 kResourceId,
1534 test_util::CreateCopyResultCallback(&error));
1535 base::RunLoop().RunUntilIdle();
1537 EXPECT_EQ(HTTP_NO_CONTENT, error);
1539 resource_entry = FindEntry(kResourceId);
1540 ASSERT_TRUE(resource_entry);
1541 // The parent link should be gone now.
1542 parent_link = resource_entry->GetLinkByType(Link::LINK_PARENT);
1543 ASSERT_FALSE(parent_link);
1544 // Should be incremented as a file was moved to the root directory.
1545 EXPECT_EQ(old_largest_change_id + 1,
1546 fake_service_.about_resource().largest_change_id());
1547 EXPECT_EQ(old_largest_change_id + 1, GetLargestChangeByAboutResource());
1550 TEST_F(FakeDriveServiceTest, RemoveResourceFromDirectory_NonexistingFile) {
1551 ASSERT_TRUE(fake_service_.LoadResourceListForWapi(
1552 "gdata/root_feed.json"));
1554 const std::string kResourceId = "file:nonexisting_file";
1555 const std::string kParentResourceId = "folder:1_folder_resource_id";
1557 GDataErrorCode error = GDATA_OTHER_ERROR;
1558 fake_service_.RemoveResourceFromDirectory(
1559 kParentResourceId,
1560 kResourceId,
1561 test_util::CreateCopyResultCallback(&error));
1562 base::RunLoop().RunUntilIdle();
1564 EXPECT_EQ(HTTP_NOT_FOUND, error);
1567 TEST_F(FakeDriveServiceTest, RemoveResourceFromDirectory_OrphanFile) {
1568 ASSERT_TRUE(fake_service_.LoadResourceListForWapi(
1569 "gdata/root_feed.json"));
1571 const std::string kResourceId = "file:1_orphanfile_resource_id";
1572 const std::string kParentResourceId = fake_service_.GetRootResourceId();
1574 GDataErrorCode error = GDATA_OTHER_ERROR;
1575 fake_service_.RemoveResourceFromDirectory(
1576 kParentResourceId,
1577 kResourceId,
1578 test_util::CreateCopyResultCallback(&error));
1579 base::RunLoop().RunUntilIdle();
1581 EXPECT_EQ(HTTP_NOT_FOUND, error);
1584 TEST_F(FakeDriveServiceTest, RemoveResourceFromDirectory_Offline) {
1585 ASSERT_TRUE(fake_service_.LoadResourceListForWapi(
1586 "gdata/root_feed.json"));
1587 fake_service_.set_offline(true);
1589 const std::string kResourceId = "file:subdirectory_file_1_id";
1590 const std::string kParentResourceId = "folder:1_folder_resource_id";
1592 GDataErrorCode error = GDATA_OTHER_ERROR;
1593 fake_service_.RemoveResourceFromDirectory(
1594 kParentResourceId,
1595 kResourceId,
1596 test_util::CreateCopyResultCallback(&error));
1597 base::RunLoop().RunUntilIdle();
1599 EXPECT_EQ(GDATA_NO_CONNECTION, error);
1602 TEST_F(FakeDriveServiceTest, AddNewDirectory_EmptyParent) {
1603 ASSERT_TRUE(fake_service_.LoadResourceListForWapi(
1604 "gdata/root_feed.json"));
1605 ASSERT_TRUE(fake_service_.LoadAccountMetadataForWapi(
1606 "gdata/account_metadata.json"));
1608 int64 old_largest_change_id = GetLargestChangeByAboutResource();
1610 GDataErrorCode error = GDATA_OTHER_ERROR;
1611 scoped_ptr<ResourceEntry> resource_entry;
1612 fake_service_.AddNewDirectory(
1613 std::string(),
1614 "new directory",
1615 DriveServiceInterface::AddNewDirectoryOptions(),
1616 test_util::CreateCopyResultCallback(&error, &resource_entry));
1617 base::RunLoop().RunUntilIdle();
1619 EXPECT_EQ(HTTP_CREATED, error);
1620 ASSERT_TRUE(resource_entry);
1621 EXPECT_TRUE(resource_entry->is_folder());
1622 EXPECT_EQ("resource_id_1", resource_entry->resource_id());
1623 EXPECT_EQ("new directory", resource_entry->title());
1624 EXPECT_TRUE(HasParent(resource_entry->resource_id(),
1625 fake_service_.GetRootResourceId()));
1626 // Should be incremented as a new directory was created.
1627 EXPECT_EQ(old_largest_change_id + 1,
1628 fake_service_.about_resource().largest_change_id());
1629 EXPECT_EQ(old_largest_change_id + 1, GetLargestChangeByAboutResource());
1632 TEST_F(FakeDriveServiceTest, AddNewDirectory_ToRootDirectory) {
1633 ASSERT_TRUE(fake_service_.LoadResourceListForWapi(
1634 "gdata/root_feed.json"));
1635 ASSERT_TRUE(fake_service_.LoadAccountMetadataForWapi(
1636 "gdata/account_metadata.json"));
1638 int64 old_largest_change_id = GetLargestChangeByAboutResource();
1640 GDataErrorCode error = GDATA_OTHER_ERROR;
1641 scoped_ptr<ResourceEntry> resource_entry;
1642 fake_service_.AddNewDirectory(
1643 fake_service_.GetRootResourceId(),
1644 "new directory",
1645 DriveServiceInterface::AddNewDirectoryOptions(),
1646 test_util::CreateCopyResultCallback(&error, &resource_entry));
1647 base::RunLoop().RunUntilIdle();
1649 EXPECT_EQ(HTTP_CREATED, error);
1650 ASSERT_TRUE(resource_entry);
1651 EXPECT_TRUE(resource_entry->is_folder());
1652 EXPECT_EQ("resource_id_1", resource_entry->resource_id());
1653 EXPECT_EQ("new directory", resource_entry->title());
1654 EXPECT_TRUE(HasParent(resource_entry->resource_id(),
1655 fake_service_.GetRootResourceId()));
1656 // Should be incremented as a new directory was created.
1657 EXPECT_EQ(old_largest_change_id + 1,
1658 fake_service_.about_resource().largest_change_id());
1659 EXPECT_EQ(old_largest_change_id + 1, GetLargestChangeByAboutResource());
1662 TEST_F(FakeDriveServiceTest, AddNewDirectory_ToRootDirectoryOnEmptyFileSystem) {
1663 ASSERT_TRUE(fake_service_.LoadResourceListForWapi(
1664 "gdata/empty_feed.json"));
1665 ASSERT_TRUE(fake_service_.LoadAccountMetadataForWapi(
1666 "gdata/account_metadata.json"));
1668 int64 old_largest_change_id = GetLargestChangeByAboutResource();
1670 GDataErrorCode error = GDATA_OTHER_ERROR;
1671 scoped_ptr<ResourceEntry> resource_entry;
1672 fake_service_.AddNewDirectory(
1673 fake_service_.GetRootResourceId(),
1674 "new directory",
1675 DriveServiceInterface::AddNewDirectoryOptions(),
1676 test_util::CreateCopyResultCallback(&error, &resource_entry));
1677 base::RunLoop().RunUntilIdle();
1679 EXPECT_EQ(HTTP_CREATED, error);
1680 ASSERT_TRUE(resource_entry);
1681 EXPECT_TRUE(resource_entry->is_folder());
1682 EXPECT_EQ("resource_id_1", resource_entry->resource_id());
1683 EXPECT_EQ("new directory", resource_entry->title());
1684 EXPECT_TRUE(HasParent(resource_entry->resource_id(),
1685 fake_service_.GetRootResourceId()));
1686 // Should be incremented as a new directory was created.
1687 EXPECT_EQ(old_largest_change_id + 1,
1688 fake_service_.about_resource().largest_change_id());
1689 EXPECT_EQ(old_largest_change_id + 1, GetLargestChangeByAboutResource());
1692 TEST_F(FakeDriveServiceTest, AddNewDirectory_ToNonRootDirectory) {
1693 ASSERT_TRUE(fake_service_.LoadResourceListForWapi(
1694 "gdata/root_feed.json"));
1695 ASSERT_TRUE(fake_service_.LoadAccountMetadataForWapi(
1696 "gdata/account_metadata.json"));
1698 int64 old_largest_change_id = GetLargestChangeByAboutResource();
1700 const std::string kParentResourceId = "folder:1_folder_resource_id";
1702 GDataErrorCode error = GDATA_OTHER_ERROR;
1703 scoped_ptr<ResourceEntry> resource_entry;
1704 fake_service_.AddNewDirectory(
1705 kParentResourceId,
1706 "new directory",
1707 DriveServiceInterface::AddNewDirectoryOptions(),
1708 test_util::CreateCopyResultCallback(&error, &resource_entry));
1709 base::RunLoop().RunUntilIdle();
1711 EXPECT_EQ(HTTP_CREATED, error);
1712 ASSERT_TRUE(resource_entry);
1713 EXPECT_TRUE(resource_entry->is_folder());
1714 EXPECT_EQ("resource_id_1", resource_entry->resource_id());
1715 EXPECT_EQ("new directory", resource_entry->title());
1716 EXPECT_TRUE(HasParent(resource_entry->resource_id(), kParentResourceId));
1717 // Should be incremented as a new directory was created.
1718 EXPECT_EQ(old_largest_change_id + 1,
1719 fake_service_.about_resource().largest_change_id());
1720 EXPECT_EQ(old_largest_change_id + 1, GetLargestChangeByAboutResource());
1723 TEST_F(FakeDriveServiceTest, AddNewDirectory_ToNonexistingDirectory) {
1724 ASSERT_TRUE(fake_service_.LoadResourceListForWapi(
1725 "gdata/root_feed.json"));
1727 const std::string kParentResourceId = "folder:nonexisting_resource_id";
1729 GDataErrorCode error = GDATA_OTHER_ERROR;
1730 scoped_ptr<ResourceEntry> resource_entry;
1731 fake_service_.AddNewDirectory(
1732 kParentResourceId,
1733 "new directory",
1734 DriveServiceInterface::AddNewDirectoryOptions(),
1735 test_util::CreateCopyResultCallback(&error, &resource_entry));
1736 base::RunLoop().RunUntilIdle();
1738 EXPECT_EQ(HTTP_NOT_FOUND, error);
1739 EXPECT_FALSE(resource_entry);
1742 TEST_F(FakeDriveServiceTest, AddNewDirectory_Offline) {
1743 ASSERT_TRUE(fake_service_.LoadResourceListForWapi(
1744 "gdata/root_feed.json"));
1745 fake_service_.set_offline(true);
1747 GDataErrorCode error = GDATA_OTHER_ERROR;
1748 scoped_ptr<ResourceEntry> resource_entry;
1749 fake_service_.AddNewDirectory(
1750 fake_service_.GetRootResourceId(),
1751 "new directory",
1752 DriveServiceInterface::AddNewDirectoryOptions(),
1753 test_util::CreateCopyResultCallback(&error, &resource_entry));
1754 base::RunLoop().RunUntilIdle();
1756 EXPECT_EQ(GDATA_NO_CONNECTION, error);
1757 EXPECT_FALSE(resource_entry);
1760 TEST_F(FakeDriveServiceTest, InitiateUploadNewFile_Offline) {
1761 ASSERT_TRUE(fake_service_.LoadResourceListForWapi(
1762 "gdata/root_feed.json"));
1763 fake_service_.set_offline(true);
1765 GDataErrorCode error = GDATA_OTHER_ERROR;
1766 GURL upload_location;
1767 fake_service_.InitiateUploadNewFile(
1768 "test/foo",
1770 "folder:1_folder_resource_id",
1771 "new file.foo",
1772 FakeDriveService::InitiateUploadNewFileOptions(),
1773 test_util::CreateCopyResultCallback(&error, &upload_location));
1774 base::RunLoop().RunUntilIdle();
1776 EXPECT_EQ(GDATA_NO_CONNECTION, error);
1777 EXPECT_TRUE(upload_location.is_empty());
1780 TEST_F(FakeDriveServiceTest, InitiateUploadNewFile_NotFound) {
1781 ASSERT_TRUE(fake_service_.LoadResourceListForWapi(
1782 "gdata/root_feed.json"));
1784 GDataErrorCode error = GDATA_OTHER_ERROR;
1785 GURL upload_location;
1786 fake_service_.InitiateUploadNewFile(
1787 "test/foo",
1789 "non_existent",
1790 "new file.foo",
1791 FakeDriveService::InitiateUploadNewFileOptions(),
1792 test_util::CreateCopyResultCallback(&error, &upload_location));
1793 base::RunLoop().RunUntilIdle();
1795 EXPECT_EQ(HTTP_NOT_FOUND, error);
1796 EXPECT_TRUE(upload_location.is_empty());
1799 TEST_F(FakeDriveServiceTest, InitiateUploadNewFile) {
1800 ASSERT_TRUE(fake_service_.LoadResourceListForWapi(
1801 "gdata/root_feed.json"));
1803 GDataErrorCode error = GDATA_OTHER_ERROR;
1804 GURL upload_location;
1805 fake_service_.InitiateUploadNewFile(
1806 "test/foo",
1808 "folder:1_folder_resource_id",
1809 "new file.foo",
1810 FakeDriveService::InitiateUploadNewFileOptions(),
1811 test_util::CreateCopyResultCallback(&error, &upload_location));
1812 base::RunLoop().RunUntilIdle();
1814 EXPECT_EQ(HTTP_SUCCESS, error);
1815 EXPECT_FALSE(upload_location.is_empty());
1816 EXPECT_NE(GURL("https://1_folder_resumable_create_media_link?mode=newfile"),
1817 upload_location);
1820 TEST_F(FakeDriveServiceTest, InitiateUploadExistingFile_Offline) {
1821 ASSERT_TRUE(fake_service_.LoadResourceListForWapi(
1822 "gdata/root_feed.json"));
1823 fake_service_.set_offline(true);
1825 GDataErrorCode error = GDATA_OTHER_ERROR;
1826 GURL upload_location;
1827 fake_service_.InitiateUploadExistingFile(
1828 "test/foo",
1830 "file:2_file_resource_id",
1831 FakeDriveService::InitiateUploadExistingFileOptions(),
1832 test_util::CreateCopyResultCallback(&error, &upload_location));
1833 base::RunLoop().RunUntilIdle();
1835 EXPECT_EQ(GDATA_NO_CONNECTION, error);
1836 EXPECT_TRUE(upload_location.is_empty());
1839 TEST_F(FakeDriveServiceTest, InitiateUploadExistingFile_NotFound) {
1840 ASSERT_TRUE(fake_service_.LoadResourceListForWapi(
1841 "gdata/root_feed.json"));
1843 GDataErrorCode error = GDATA_OTHER_ERROR;
1844 GURL upload_location;
1845 fake_service_.InitiateUploadExistingFile(
1846 "test/foo",
1848 "non_existent",
1849 FakeDriveService::InitiateUploadExistingFileOptions(),
1850 test_util::CreateCopyResultCallback(&error, &upload_location));
1851 base::RunLoop().RunUntilIdle();
1853 EXPECT_EQ(HTTP_NOT_FOUND, error);
1854 EXPECT_TRUE(upload_location.is_empty());
1857 TEST_F(FakeDriveServiceTest, InitiateUploadExistingFile_WrongETag) {
1858 ASSERT_TRUE(fake_service_.LoadResourceListForWapi(
1859 "gdata/root_feed.json"));
1861 FakeDriveService::InitiateUploadExistingFileOptions options;
1862 options.etag = "invalid_etag";
1864 GDataErrorCode error = GDATA_OTHER_ERROR;
1865 GURL upload_location;
1866 fake_service_.InitiateUploadExistingFile(
1867 "text/plain",
1869 "file:2_file_resource_id",
1870 options,
1871 test_util::CreateCopyResultCallback(&error, &upload_location));
1872 base::RunLoop().RunUntilIdle();
1874 EXPECT_EQ(HTTP_PRECONDITION, error);
1875 EXPECT_TRUE(upload_location.is_empty());
1878 TEST_F(FakeDriveServiceTest, InitiateUpload_ExistingFile) {
1879 ASSERT_TRUE(fake_service_.LoadResourceListForWapi(
1880 "gdata/root_feed.json"));
1882 FakeDriveService::InitiateUploadExistingFileOptions options;
1883 options.etag = "\"HhMOFgxXHit7ImBr\"";
1885 GDataErrorCode error = GDATA_OTHER_ERROR;
1886 GURL upload_location;
1887 fake_service_.InitiateUploadExistingFile(
1888 "text/plain",
1890 "file:2_file_resource_id",
1891 options,
1892 test_util::CreateCopyResultCallback(&error, &upload_location));
1893 base::RunLoop().RunUntilIdle();
1895 EXPECT_EQ(HTTP_SUCCESS, error);
1896 EXPECT_TRUE(upload_location.is_valid());
1899 TEST_F(FakeDriveServiceTest, ResumeUpload_Offline) {
1900 ASSERT_TRUE(fake_service_.LoadResourceListForWapi(
1901 "gdata/root_feed.json"));
1903 GDataErrorCode error = GDATA_OTHER_ERROR;
1904 GURL upload_location;
1905 fake_service_.InitiateUploadNewFile(
1906 "test/foo",
1908 "folder:1_folder_resource_id",
1909 "new file.foo",
1910 FakeDriveService::InitiateUploadNewFileOptions(),
1911 test_util::CreateCopyResultCallback(&error, &upload_location));
1912 base::RunLoop().RunUntilIdle();
1914 EXPECT_EQ(HTTP_SUCCESS, error);
1915 EXPECT_FALSE(upload_location.is_empty());
1916 EXPECT_NE(GURL("https://1_folder_resumable_create_media_link"),
1917 upload_location);
1919 fake_service_.set_offline(true);
1921 UploadRangeResponse response;
1922 scoped_ptr<ResourceEntry> entry;
1923 fake_service_.ResumeUpload(
1924 upload_location,
1925 0, 13, 15, "test/foo",
1926 base::FilePath(),
1927 test_util::CreateCopyResultCallback(&response, &entry),
1928 ProgressCallback());
1929 base::RunLoop().RunUntilIdle();
1931 EXPECT_EQ(GDATA_NO_CONNECTION, response.code);
1932 EXPECT_FALSE(entry.get());
1935 TEST_F(FakeDriveServiceTest, ResumeUpload_NotFound) {
1936 ASSERT_TRUE(fake_service_.LoadResourceListForWapi(
1937 "gdata/root_feed.json"));
1939 GDataErrorCode error = GDATA_OTHER_ERROR;
1940 GURL upload_location;
1941 fake_service_.InitiateUploadNewFile(
1942 "test/foo",
1944 "folder:1_folder_resource_id",
1945 "new file.foo",
1946 FakeDriveService::InitiateUploadNewFileOptions(),
1947 test_util::CreateCopyResultCallback(&error, &upload_location));
1948 base::RunLoop().RunUntilIdle();
1950 ASSERT_EQ(HTTP_SUCCESS, error);
1952 UploadRangeResponse response;
1953 scoped_ptr<ResourceEntry> entry;
1954 fake_service_.ResumeUpload(
1955 GURL("https://foo.com/"),
1956 0, 13, 15, "test/foo",
1957 base::FilePath(),
1958 test_util::CreateCopyResultCallback(&response, &entry),
1959 ProgressCallback());
1960 base::RunLoop().RunUntilIdle();
1962 EXPECT_EQ(HTTP_NOT_FOUND, response.code);
1963 EXPECT_FALSE(entry.get());
1966 TEST_F(FakeDriveServiceTest, ResumeUpload_ExistingFile) {
1967 base::ScopedTempDir temp_dir;
1968 ASSERT_TRUE(temp_dir.CreateUniqueTempDir());
1969 base::FilePath local_file_path =
1970 temp_dir.path().Append(FILE_PATH_LITERAL("File 1.txt"));
1971 std::string contents("hogefugapiyo");
1972 ASSERT_TRUE(test_util::WriteStringToFile(local_file_path, contents));
1974 ASSERT_TRUE(fake_service_.LoadResourceListForWapi(
1975 "gdata/root_feed.json"));
1977 FakeDriveService::InitiateUploadExistingFileOptions options;
1978 options.etag = "\"HhMOFgxXHit7ImBr\"";
1980 GDataErrorCode error = GDATA_OTHER_ERROR;
1981 GURL upload_location;
1982 fake_service_.InitiateUploadExistingFile(
1983 "text/plain",
1984 contents.size(),
1985 "file:2_file_resource_id",
1986 options,
1987 test_util::CreateCopyResultCallback(&error, &upload_location));
1988 base::RunLoop().RunUntilIdle();
1990 ASSERT_EQ(HTTP_SUCCESS, error);
1992 UploadRangeResponse response;
1993 scoped_ptr<ResourceEntry> entry;
1994 std::vector<test_util::ProgressInfo> upload_progress_values;
1995 fake_service_.ResumeUpload(
1996 upload_location,
1997 0, contents.size() / 2, contents.size(), "text/plain",
1998 local_file_path,
1999 test_util::CreateCopyResultCallback(&response, &entry),
2000 base::Bind(&test_util::AppendProgressCallbackResult,
2001 &upload_progress_values));
2002 base::RunLoop().RunUntilIdle();
2004 EXPECT_EQ(HTTP_RESUME_INCOMPLETE, response.code);
2005 EXPECT_FALSE(entry.get());
2006 ASSERT_TRUE(!upload_progress_values.empty());
2007 EXPECT_TRUE(base::STLIsSorted(upload_progress_values));
2008 EXPECT_LE(0, upload_progress_values.front().first);
2009 EXPECT_GE(static_cast<int64>(contents.size() / 2),
2010 upload_progress_values.back().first);
2012 upload_progress_values.clear();
2013 fake_service_.ResumeUpload(
2014 upload_location,
2015 contents.size() / 2, contents.size(), contents.size(), "text/plain",
2016 local_file_path,
2017 test_util::CreateCopyResultCallback(&response, &entry),
2018 base::Bind(&test_util::AppendProgressCallbackResult,
2019 &upload_progress_values));
2020 base::RunLoop().RunUntilIdle();
2022 EXPECT_EQ(HTTP_SUCCESS, response.code);
2023 EXPECT_TRUE(entry.get());
2024 EXPECT_EQ(static_cast<int64>(contents.size()),
2025 entry->file_size());
2026 EXPECT_TRUE(Exists(entry->resource_id()));
2027 ASSERT_TRUE(!upload_progress_values.empty());
2028 EXPECT_TRUE(base::STLIsSorted(upload_progress_values));
2029 EXPECT_LE(0, upload_progress_values.front().first);
2030 EXPECT_GE(static_cast<int64>(contents.size() - contents.size() / 2),
2031 upload_progress_values.back().first);
2032 EXPECT_EQ(base::MD5String(contents), entry->file_md5());
2035 TEST_F(FakeDriveServiceTest, ResumeUpload_NewFile) {
2036 base::ScopedTempDir temp_dir;
2037 ASSERT_TRUE(temp_dir.CreateUniqueTempDir());
2038 base::FilePath local_file_path =
2039 temp_dir.path().Append(FILE_PATH_LITERAL("new file.foo"));
2040 std::string contents("hogefugapiyo");
2041 ASSERT_TRUE(test_util::WriteStringToFile(local_file_path, contents));
2043 ASSERT_TRUE(fake_service_.LoadResourceListForWapi(
2044 "gdata/root_feed.json"));
2046 GDataErrorCode error = GDATA_OTHER_ERROR;
2047 GURL upload_location;
2048 fake_service_.InitiateUploadNewFile(
2049 "test/foo",
2050 contents.size(),
2051 "folder:1_folder_resource_id",
2052 "new file.foo",
2053 FakeDriveService::InitiateUploadNewFileOptions(),
2054 test_util::CreateCopyResultCallback(&error, &upload_location));
2055 base::RunLoop().RunUntilIdle();
2057 EXPECT_EQ(HTTP_SUCCESS, error);
2058 EXPECT_FALSE(upload_location.is_empty());
2059 EXPECT_NE(GURL("https://1_folder_resumable_create_media_link"),
2060 upload_location);
2062 UploadRangeResponse response;
2063 scoped_ptr<ResourceEntry> entry;
2064 std::vector<test_util::ProgressInfo> upload_progress_values;
2065 fake_service_.ResumeUpload(
2066 upload_location,
2067 0, contents.size() / 2, contents.size(), "test/foo",
2068 local_file_path,
2069 test_util::CreateCopyResultCallback(&response, &entry),
2070 base::Bind(&test_util::AppendProgressCallbackResult,
2071 &upload_progress_values));
2072 base::RunLoop().RunUntilIdle();
2074 EXPECT_EQ(HTTP_RESUME_INCOMPLETE, response.code);
2075 EXPECT_FALSE(entry.get());
2076 ASSERT_TRUE(!upload_progress_values.empty());
2077 EXPECT_TRUE(base::STLIsSorted(upload_progress_values));
2078 EXPECT_LE(0, upload_progress_values.front().first);
2079 EXPECT_GE(static_cast<int64>(contents.size() / 2),
2080 upload_progress_values.back().first);
2082 upload_progress_values.clear();
2083 fake_service_.ResumeUpload(
2084 upload_location,
2085 contents.size() / 2, contents.size(), contents.size(), "test/foo",
2086 local_file_path,
2087 test_util::CreateCopyResultCallback(&response, &entry),
2088 base::Bind(&test_util::AppendProgressCallbackResult,
2089 &upload_progress_values));
2090 base::RunLoop().RunUntilIdle();
2092 EXPECT_EQ(HTTP_CREATED, response.code);
2093 EXPECT_TRUE(entry.get());
2094 EXPECT_EQ(static_cast<int64>(contents.size()), entry->file_size());
2095 EXPECT_TRUE(Exists(entry->resource_id()));
2096 ASSERT_TRUE(!upload_progress_values.empty());
2097 EXPECT_TRUE(base::STLIsSorted(upload_progress_values));
2098 EXPECT_LE(0, upload_progress_values.front().first);
2099 EXPECT_GE(static_cast<int64>(contents.size() - contents.size() / 2),
2100 upload_progress_values.back().first);
2101 EXPECT_EQ(base::MD5String(contents), entry->file_md5());
2104 TEST_F(FakeDriveServiceTest, AddNewFile_ToRootDirectory) {
2105 ASSERT_TRUE(fake_service_.LoadResourceListForWapi(
2106 "gdata/root_feed.json"));
2107 ASSERT_TRUE(fake_service_.LoadAccountMetadataForWapi(
2108 "gdata/account_metadata.json"));
2110 int64 old_largest_change_id = GetLargestChangeByAboutResource();
2112 const std::string kContentType = "text/plain";
2113 const std::string kContentData = "This is some test content.";
2114 const std::string kTitle = "new file";
2116 GDataErrorCode error = GDATA_OTHER_ERROR;
2117 scoped_ptr<ResourceEntry> resource_entry;
2118 fake_service_.AddNewFile(
2119 kContentType,
2120 kContentData,
2121 fake_service_.GetRootResourceId(),
2122 kTitle,
2123 false, // shared_with_me
2124 test_util::CreateCopyResultCallback(&error, &resource_entry));
2125 base::RunLoop().RunUntilIdle();
2127 EXPECT_EQ(HTTP_CREATED, error);
2128 ASSERT_TRUE(resource_entry);
2129 EXPECT_TRUE(resource_entry->is_file());
2130 EXPECT_EQ(kContentType, resource_entry->content_mime_type());
2131 EXPECT_EQ(static_cast<int64>(kContentData.size()),
2132 resource_entry->file_size());
2133 EXPECT_EQ("resource_id_1", resource_entry->resource_id());
2134 EXPECT_EQ(kTitle, resource_entry->title());
2135 EXPECT_TRUE(HasParent(resource_entry->resource_id(),
2136 fake_service_.GetRootResourceId()));
2137 // Should be incremented as a new directory was created.
2138 EXPECT_EQ(old_largest_change_id + 1,
2139 fake_service_.about_resource().largest_change_id());
2140 EXPECT_EQ(old_largest_change_id + 1, GetLargestChangeByAboutResource());
2141 EXPECT_EQ(base::MD5String(kContentData), resource_entry->file_md5());
2144 TEST_F(FakeDriveServiceTest, AddNewFile_ToRootDirectoryOnEmptyFileSystem) {
2145 ASSERT_TRUE(fake_service_.LoadResourceListForWapi(
2146 "gdata/empty_feed.json"));
2147 ASSERT_TRUE(fake_service_.LoadAccountMetadataForWapi(
2148 "gdata/account_metadata.json"));
2150 int64 old_largest_change_id = GetLargestChangeByAboutResource();
2152 const std::string kContentType = "text/plain";
2153 const std::string kContentData = "This is some test content.";
2154 const std::string kTitle = "new file";
2156 GDataErrorCode error = GDATA_OTHER_ERROR;
2157 scoped_ptr<ResourceEntry> resource_entry;
2158 fake_service_.AddNewFile(
2159 kContentType,
2160 kContentData,
2161 fake_service_.GetRootResourceId(),
2162 kTitle,
2163 false, // shared_with_me
2164 test_util::CreateCopyResultCallback(&error, &resource_entry));
2165 base::RunLoop().RunUntilIdle();
2167 EXPECT_EQ(HTTP_CREATED, error);
2168 ASSERT_TRUE(resource_entry);
2169 EXPECT_TRUE(resource_entry->is_file());
2170 EXPECT_EQ(kContentType, resource_entry->content_mime_type());
2171 EXPECT_EQ(static_cast<int64>(kContentData.size()),
2172 resource_entry->file_size());
2173 EXPECT_EQ("resource_id_1", resource_entry->resource_id());
2174 EXPECT_EQ(kTitle, resource_entry->title());
2175 EXPECT_TRUE(HasParent(resource_entry->resource_id(),
2176 fake_service_.GetRootResourceId()));
2177 // Should be incremented as a new directory was created.
2178 EXPECT_EQ(old_largest_change_id + 1,
2179 fake_service_.about_resource().largest_change_id());
2180 EXPECT_EQ(old_largest_change_id + 1, GetLargestChangeByAboutResource());
2181 EXPECT_EQ(base::MD5String(kContentData), resource_entry->file_md5());
2184 TEST_F(FakeDriveServiceTest, AddNewFile_ToNonRootDirectory) {
2185 ASSERT_TRUE(fake_service_.LoadResourceListForWapi(
2186 "gdata/root_feed.json"));
2187 ASSERT_TRUE(fake_service_.LoadAccountMetadataForWapi(
2188 "gdata/account_metadata.json"));
2190 int64 old_largest_change_id = GetLargestChangeByAboutResource();
2192 const std::string kContentType = "text/plain";
2193 const std::string kContentData = "This is some test content.";
2194 const std::string kTitle = "new file";
2195 const std::string kParentResourceId = "folder:1_folder_resource_id";
2197 GDataErrorCode error = GDATA_OTHER_ERROR;
2198 scoped_ptr<ResourceEntry> resource_entry;
2199 fake_service_.AddNewFile(
2200 kContentType,
2201 kContentData,
2202 kParentResourceId,
2203 kTitle,
2204 false, // shared_with_me
2205 test_util::CreateCopyResultCallback(&error, &resource_entry));
2206 base::RunLoop().RunUntilIdle();
2208 EXPECT_EQ(HTTP_CREATED, error);
2209 ASSERT_TRUE(resource_entry);
2210 EXPECT_TRUE(resource_entry->is_file());
2211 EXPECT_EQ(kContentType, resource_entry->content_mime_type());
2212 EXPECT_EQ(static_cast<int64>(kContentData.size()),
2213 resource_entry->file_size());
2214 EXPECT_EQ("resource_id_1", resource_entry->resource_id());
2215 EXPECT_EQ(kTitle, resource_entry->title());
2216 EXPECT_TRUE(HasParent(resource_entry->resource_id(), kParentResourceId));
2217 // Should be incremented as a new directory was created.
2218 EXPECT_EQ(old_largest_change_id + 1,
2219 fake_service_.about_resource().largest_change_id());
2220 EXPECT_EQ(old_largest_change_id + 1, GetLargestChangeByAboutResource());
2221 EXPECT_EQ(base::MD5String(kContentData), resource_entry->file_md5());
2224 TEST_F(FakeDriveServiceTest, AddNewFile_ToNonexistingDirectory) {
2225 ASSERT_TRUE(fake_service_.LoadResourceListForWapi(
2226 "gdata/root_feed.json"));
2228 const std::string kContentType = "text/plain";
2229 const std::string kContentData = "This is some test content.";
2230 const std::string kTitle = "new file";
2231 const std::string kParentResourceId = "folder:nonexisting_resource_id";
2233 GDataErrorCode error = GDATA_OTHER_ERROR;
2234 scoped_ptr<ResourceEntry> resource_entry;
2235 fake_service_.AddNewFile(
2236 kContentType,
2237 kContentData,
2238 kParentResourceId,
2239 kTitle,
2240 false, // shared_with_me
2241 test_util::CreateCopyResultCallback(&error, &resource_entry));
2242 base::RunLoop().RunUntilIdle();
2244 EXPECT_EQ(HTTP_NOT_FOUND, error);
2245 EXPECT_FALSE(resource_entry);
2248 TEST_F(FakeDriveServiceTest, AddNewFile_Offline) {
2249 ASSERT_TRUE(fake_service_.LoadResourceListForWapi(
2250 "gdata/root_feed.json"));
2251 fake_service_.set_offline(true);
2253 const std::string kContentType = "text/plain";
2254 const std::string kContentData = "This is some test content.";
2255 const std::string kTitle = "new file";
2257 GDataErrorCode error = GDATA_OTHER_ERROR;
2258 scoped_ptr<ResourceEntry> resource_entry;
2259 fake_service_.AddNewFile(
2260 kContentType,
2261 kContentData,
2262 fake_service_.GetRootResourceId(),
2263 kTitle,
2264 false, // shared_with_me
2265 test_util::CreateCopyResultCallback(&error, &resource_entry));
2266 base::RunLoop().RunUntilIdle();
2268 EXPECT_EQ(GDATA_NO_CONNECTION, error);
2269 EXPECT_FALSE(resource_entry);
2272 TEST_F(FakeDriveServiceTest, AddNewFile_SharedWithMeLabel) {
2273 ASSERT_TRUE(fake_service_.LoadResourceListForWapi(
2274 "gdata/root_feed.json"));
2275 ASSERT_TRUE(fake_service_.LoadAccountMetadataForWapi(
2276 "gdata/account_metadata.json"));
2278 const std::string kContentType = "text/plain";
2279 const std::string kContentData = "This is some test content.";
2280 const std::string kTitle = "new file";
2282 int64 old_largest_change_id = GetLargestChangeByAboutResource();
2284 GDataErrorCode error = GDATA_OTHER_ERROR;
2285 scoped_ptr<ResourceEntry> resource_entry;
2286 fake_service_.AddNewFile(
2287 kContentType,
2288 kContentData,
2289 fake_service_.GetRootResourceId(),
2290 kTitle,
2291 true, // shared_with_me
2292 test_util::CreateCopyResultCallback(&error, &resource_entry));
2293 base::RunLoop().RunUntilIdle();
2295 EXPECT_EQ(HTTP_CREATED, error);
2296 ASSERT_TRUE(resource_entry);
2297 EXPECT_TRUE(resource_entry->is_file());
2298 EXPECT_EQ(kContentType, resource_entry->content_mime_type());
2299 EXPECT_EQ(static_cast<int64>(kContentData.size()),
2300 resource_entry->file_size());
2301 EXPECT_EQ("resource_id_1", resource_entry->resource_id());
2302 EXPECT_EQ(kTitle, resource_entry->title());
2303 EXPECT_TRUE(HasParent(resource_entry->resource_id(),
2304 fake_service_.GetRootResourceId()));
2305 ASSERT_EQ(1U, resource_entry->labels().size());
2306 EXPECT_EQ("shared-with-me", resource_entry->labels()[0]);
2307 // Should be incremented as a new directory was created.
2308 EXPECT_EQ(old_largest_change_id + 1,
2309 fake_service_.about_resource().largest_change_id());
2310 EXPECT_EQ(old_largest_change_id + 1, GetLargestChangeByAboutResource());
2311 EXPECT_EQ(base::MD5String(kContentData), resource_entry->file_md5());
2314 TEST_F(FakeDriveServiceTest, SetLastModifiedTime_ExistingFile) {
2315 ASSERT_TRUE(fake_service_.LoadResourceListForWapi(
2316 "gdata/root_feed.json"));
2318 const std::string kResourceId = "file:2_file_resource_id";
2319 base::Time time;
2320 ASSERT_TRUE(base::Time::FromString("1 April 2013 12:34:56", &time));
2322 GDataErrorCode error = GDATA_OTHER_ERROR;
2323 scoped_ptr<ResourceEntry> resource_entry;
2324 fake_service_.SetLastModifiedTime(
2325 kResourceId,
2326 time,
2327 test_util::CreateCopyResultCallback(&error, &resource_entry));
2328 base::RunLoop().RunUntilIdle();
2330 EXPECT_EQ(HTTP_SUCCESS, error);
2331 ASSERT_TRUE(resource_entry);
2332 EXPECT_EQ(time, resource_entry->updated_time());
2335 TEST_F(FakeDriveServiceTest, SetLastModifiedTime_NonexistingFile) {
2336 ASSERT_TRUE(fake_service_.LoadResourceListForWapi(
2337 "gdata/root_feed.json"));
2339 const std::string kResourceId = "file:nonexisting_resource_id";
2340 base::Time time;
2341 ASSERT_TRUE(base::Time::FromString("1 April 2013 12:34:56", &time));
2343 GDataErrorCode error = GDATA_OTHER_ERROR;
2344 scoped_ptr<ResourceEntry> resource_entry;
2345 fake_service_.SetLastModifiedTime(
2346 kResourceId,
2347 time,
2348 test_util::CreateCopyResultCallback(&error, &resource_entry));
2349 base::RunLoop().RunUntilIdle();
2351 EXPECT_EQ(HTTP_NOT_FOUND, error);
2352 EXPECT_FALSE(resource_entry);
2355 TEST_F(FakeDriveServiceTest, SetLastModifiedTime_Offline) {
2356 ASSERT_TRUE(fake_service_.LoadResourceListForWapi(
2357 "gdata/root_feed.json"));
2358 fake_service_.set_offline(true);
2360 const std::string kResourceId = "file:2_file_resource_id";
2361 base::Time time;
2362 ASSERT_TRUE(base::Time::FromString("1 April 2013 12:34:56", &time));
2364 GDataErrorCode error = GDATA_OTHER_ERROR;
2365 scoped_ptr<ResourceEntry> resource_entry;
2366 fake_service_.SetLastModifiedTime(
2367 kResourceId,
2368 time,
2369 test_util::CreateCopyResultCallback(&error, &resource_entry));
2370 base::RunLoop().RunUntilIdle();
2372 EXPECT_EQ(GDATA_NO_CONNECTION, error);
2373 EXPECT_FALSE(resource_entry);
2376 } // namespace
2378 } // namespace drive