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"
10 #include "base/file_util.h"
11 #include "base/files/scoped_temp_dir.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
;
47 class FakeDriveServiceTest
: public testing::Test
{
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(
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(
75 test_util::CreateCopyResultCallback(&error
, &resource_entry
));
76 base::RunLoop().RunUntilIdle();
77 return error
== HTTP_CREATED
;
80 // Returns true if the resource identified by |resource_id| has a parent
81 // identified by |parent_id|.
82 bool HasParent(const std::string
& resource_id
, const std::string
& parent_id
) {
83 const GURL parent_url
= FakeDriveService::GetFakeLinkUrl(parent_id
);
84 scoped_ptr
<ResourceEntry
> resource_entry
= FindEntry(resource_id
);
85 if (resource_entry
.get()) {
86 for (size_t i
= 0; i
< resource_entry
->links().size(); ++i
) {
87 if (resource_entry
->links()[i
]->type() == Link::LINK_PARENT
&&
88 resource_entry
->links()[i
]->href() == parent_url
)
95 int64
GetLargestChangeByAboutResource() {
97 scoped_ptr
<AboutResource
> about_resource
;
98 fake_service_
.GetAboutResource(
99 test_util::CreateCopyResultCallback(&error
, &about_resource
));
100 base::RunLoop().RunUntilIdle();
101 return about_resource
->largest_change_id();
104 content::TestBrowserThreadBundle thread_bundle_
;
105 FakeDriveService fake_service_
;
108 TEST_F(FakeDriveServiceTest
, GetAllResourceList
) {
109 ASSERT_TRUE(fake_service_
.LoadResourceListForWapi(
110 "gdata/root_feed.json"));
112 GDataErrorCode error
= GDATA_OTHER_ERROR
;
113 scoped_ptr
<ResourceList
> resource_list
;
114 fake_service_
.GetAllResourceList(
115 test_util::CreateCopyResultCallback(&error
, &resource_list
));
116 base::RunLoop().RunUntilIdle();
118 EXPECT_EQ(HTTP_SUCCESS
, error
);
119 ASSERT_TRUE(resource_list
);
120 // Do some sanity check.
121 EXPECT_EQ(14U, resource_list
->entries().size());
122 EXPECT_EQ(1, fake_service_
.resource_list_load_count());
125 TEST_F(FakeDriveServiceTest
, GetAllResourceList_Offline
) {
126 ASSERT_TRUE(fake_service_
.LoadResourceListForWapi(
127 "gdata/root_feed.json"));
128 fake_service_
.set_offline(true);
130 GDataErrorCode error
= GDATA_OTHER_ERROR
;
131 scoped_ptr
<ResourceList
> resource_list
;
132 fake_service_
.GetAllResourceList(
133 test_util::CreateCopyResultCallback(&error
, &resource_list
));
134 base::RunLoop().RunUntilIdle();
136 EXPECT_EQ(GDATA_NO_CONNECTION
, error
);
137 EXPECT_FALSE(resource_list
);
140 TEST_F(FakeDriveServiceTest
, GetResourceListInDirectory_InRootDirectory
) {
141 ASSERT_TRUE(fake_service_
.LoadResourceListForWapi(
142 "gdata/root_feed.json"));
144 GDataErrorCode error
= GDATA_OTHER_ERROR
;
145 scoped_ptr
<ResourceList
> resource_list
;
146 fake_service_
.GetResourceListInDirectory(
147 fake_service_
.GetRootResourceId(),
148 test_util::CreateCopyResultCallback(&error
, &resource_list
));
149 base::RunLoop().RunUntilIdle();
151 EXPECT_EQ(HTTP_SUCCESS
, error
);
152 ASSERT_TRUE(resource_list
);
153 // Do some sanity check. There are 8 entries in the root directory.
154 EXPECT_EQ(8U, resource_list
->entries().size());
155 EXPECT_EQ(1, fake_service_
.directory_load_count());
158 TEST_F(FakeDriveServiceTest
, GetResourceListInDirectory_InNonRootDirectory
) {
159 ASSERT_TRUE(fake_service_
.LoadResourceListForWapi(
160 "gdata/root_feed.json"));
162 GDataErrorCode error
= GDATA_OTHER_ERROR
;
163 scoped_ptr
<ResourceList
> resource_list
;
164 fake_service_
.GetResourceListInDirectory(
165 "folder:1_folder_resource_id",
166 test_util::CreateCopyResultCallback(&error
, &resource_list
));
167 base::RunLoop().RunUntilIdle();
169 EXPECT_EQ(HTTP_SUCCESS
, error
);
170 ASSERT_TRUE(resource_list
);
171 // Do some sanity check. There is three entries in 1_folder_resource_id
173 EXPECT_EQ(3U, resource_list
->entries().size());
174 EXPECT_EQ(1, fake_service_
.directory_load_count());
177 TEST_F(FakeDriveServiceTest
, GetResourceListInDirectory_Offline
) {
178 ASSERT_TRUE(fake_service_
.LoadResourceListForWapi(
179 "gdata/root_feed.json"));
180 fake_service_
.set_offline(true);
182 GDataErrorCode error
= GDATA_OTHER_ERROR
;
183 scoped_ptr
<ResourceList
> resource_list
;
184 fake_service_
.GetResourceListInDirectory(
185 fake_service_
.GetRootResourceId(),
186 test_util::CreateCopyResultCallback(&error
, &resource_list
));
187 base::RunLoop().RunUntilIdle();
189 EXPECT_EQ(GDATA_NO_CONNECTION
, error
);
190 EXPECT_FALSE(resource_list
);
193 TEST_F(FakeDriveServiceTest
, Search
) {
194 ASSERT_TRUE(fake_service_
.LoadResourceListForWapi(
195 "gdata/root_feed.json"));
197 GDataErrorCode error
= GDATA_OTHER_ERROR
;
198 scoped_ptr
<ResourceList
> resource_list
;
199 fake_service_
.Search(
200 "File", // search_query
201 test_util::CreateCopyResultCallback(&error
, &resource_list
));
202 base::RunLoop().RunUntilIdle();
204 EXPECT_EQ(HTTP_SUCCESS
, error
);
205 ASSERT_TRUE(resource_list
);
206 // Do some sanity check. There are 4 entries that contain "File" in their
208 EXPECT_EQ(4U, resource_list
->entries().size());
211 TEST_F(FakeDriveServiceTest
, Search_WithAttribute
) {
212 ASSERT_TRUE(fake_service_
.LoadResourceListForWapi(
213 "gdata/root_feed.json"));
215 GDataErrorCode error
= GDATA_OTHER_ERROR
;
216 scoped_ptr
<ResourceList
> resource_list
;
217 fake_service_
.Search(
218 "title:1.txt", // search_query
219 test_util::CreateCopyResultCallback(&error
, &resource_list
));
220 base::RunLoop().RunUntilIdle();
222 EXPECT_EQ(HTTP_SUCCESS
, error
);
223 ASSERT_TRUE(resource_list
);
224 // Do some sanity check. There are 4 entries that contain "1.txt" in their
226 EXPECT_EQ(4U, resource_list
->entries().size());
229 TEST_F(FakeDriveServiceTest
, Search_MultipleQueries
) {
230 ASSERT_TRUE(fake_service_
.LoadResourceListForWapi(
231 "gdata/root_feed.json"));
233 GDataErrorCode error
= GDATA_OTHER_ERROR
;
234 scoped_ptr
<ResourceList
> resource_list
;
235 fake_service_
.Search(
236 "Directory 1", // search_query
237 test_util::CreateCopyResultCallback(&error
, &resource_list
));
238 base::RunLoop().RunUntilIdle();
240 EXPECT_EQ(HTTP_SUCCESS
, error
);
241 ASSERT_TRUE(resource_list
);
242 // There are 2 entries that contain both "Directory" and "1" in their titles.
243 EXPECT_EQ(2U, resource_list
->entries().size());
245 fake_service_
.Search(
246 "\"Directory 1\"", // search_query
247 test_util::CreateCopyResultCallback(&error
, &resource_list
));
248 base::RunLoop().RunUntilIdle();
250 EXPECT_EQ(HTTP_SUCCESS
, error
);
251 ASSERT_TRUE(resource_list
);
252 // There is 1 entry that contain "Directory 1" in its title.
253 EXPECT_EQ(1U, resource_list
->entries().size());
256 TEST_F(FakeDriveServiceTest
, Search_Offline
) {
257 ASSERT_TRUE(fake_service_
.LoadResourceListForWapi(
258 "gdata/root_feed.json"));
259 fake_service_
.set_offline(true);
261 GDataErrorCode error
= GDATA_OTHER_ERROR
;
262 scoped_ptr
<ResourceList
> resource_list
;
263 fake_service_
.Search(
264 "Directory 1", // search_query
265 test_util::CreateCopyResultCallback(&error
, &resource_list
));
266 base::RunLoop().RunUntilIdle();
268 EXPECT_EQ(GDATA_NO_CONNECTION
, error
);
269 EXPECT_FALSE(resource_list
);
272 TEST_F(FakeDriveServiceTest
, Search_Deleted
) {
273 ASSERT_TRUE(fake_service_
.LoadResourceListForWapi(
274 "gdata/root_feed.json"));
276 GDataErrorCode error
= GDATA_OTHER_ERROR
;
277 fake_service_
.DeleteResource("file:2_file_resource_id",
278 std::string(), // etag
279 test_util::CreateCopyResultCallback(&error
));
280 base::RunLoop().RunUntilIdle();
281 EXPECT_EQ(HTTP_NO_CONTENT
, error
);
283 error
= GDATA_OTHER_ERROR
;
284 scoped_ptr
<ResourceList
> resource_list
;
285 fake_service_
.Search(
286 "File", // search_query
287 test_util::CreateCopyResultCallback(&error
, &resource_list
));
288 base::RunLoop().RunUntilIdle();
290 EXPECT_EQ(HTTP_SUCCESS
, error
);
291 ASSERT_TRUE(resource_list
);
292 // Do some sanity check. There are 4 entries that contain "File" in their
293 // titles and one of them is deleted.
294 EXPECT_EQ(3U, resource_list
->entries().size());
297 TEST_F(FakeDriveServiceTest
, Search_Trashed
) {
298 ASSERT_TRUE(fake_service_
.LoadResourceListForWapi(
299 "gdata/root_feed.json"));
301 GDataErrorCode error
= GDATA_OTHER_ERROR
;
302 fake_service_
.TrashResource("file:2_file_resource_id",
303 test_util::CreateCopyResultCallback(&error
));
304 base::RunLoop().RunUntilIdle();
305 EXPECT_EQ(HTTP_SUCCESS
, error
);
307 error
= GDATA_OTHER_ERROR
;
308 scoped_ptr
<ResourceList
> resource_list
;
309 fake_service_
.Search(
310 "File", // search_query
311 test_util::CreateCopyResultCallback(&error
, &resource_list
));
312 base::RunLoop().RunUntilIdle();
314 EXPECT_EQ(HTTP_SUCCESS
, error
);
315 ASSERT_TRUE(resource_list
);
316 // Do some sanity check. There are 4 entries that contain "File" in their
317 // titles and one of them is deleted.
318 EXPECT_EQ(3U, resource_list
->entries().size());
321 TEST_F(FakeDriveServiceTest
, SearchByTitle
) {
322 ASSERT_TRUE(fake_service_
.LoadResourceListForWapi(
323 "gdata/root_feed.json"));
325 GDataErrorCode error
= GDATA_OTHER_ERROR
;
326 scoped_ptr
<ResourceList
> resource_list
;
327 fake_service_
.SearchByTitle(
329 fake_service_
.GetRootResourceId(), // directory_resource_id
330 test_util::CreateCopyResultCallback(&error
, &resource_list
));
331 base::RunLoop().RunUntilIdle();
333 EXPECT_EQ(HTTP_SUCCESS
, error
);
334 ASSERT_TRUE(resource_list
);
335 // Do some sanity check. There are 2 entries that contain "1.txt" in their
336 // titles directly under the root directory.
337 EXPECT_EQ(2U, resource_list
->entries().size());
340 TEST_F(FakeDriveServiceTest
, SearchByTitle_EmptyDirectoryResourceId
) {
341 ASSERT_TRUE(fake_service_
.LoadResourceListForWapi(
342 "gdata/root_feed.json"));
344 GDataErrorCode error
= GDATA_OTHER_ERROR
;
345 scoped_ptr
<ResourceList
> resource_list
;
346 fake_service_
.SearchByTitle(
348 "", // directory resource id
349 test_util::CreateCopyResultCallback(&error
, &resource_list
));
350 base::RunLoop().RunUntilIdle();
352 EXPECT_EQ(HTTP_SUCCESS
, error
);
353 ASSERT_TRUE(resource_list
);
354 // Do some sanity check. There are 4 entries that contain "1.txt" in their
356 EXPECT_EQ(4U, resource_list
->entries().size());
359 TEST_F(FakeDriveServiceTest
, SearchByTitle_Offline
) {
360 ASSERT_TRUE(fake_service_
.LoadResourceListForWapi(
361 "gdata/root_feed.json"));
362 fake_service_
.set_offline(true);
364 GDataErrorCode error
= GDATA_OTHER_ERROR
;
365 scoped_ptr
<ResourceList
> resource_list
;
366 fake_service_
.SearchByTitle(
367 "Directory 1", // title
368 fake_service_
.GetRootResourceId(), // directory_resource_id
369 test_util::CreateCopyResultCallback(&error
, &resource_list
));
370 base::RunLoop().RunUntilIdle();
372 EXPECT_EQ(GDATA_NO_CONNECTION
, error
);
373 EXPECT_FALSE(resource_list
);
376 TEST_F(FakeDriveServiceTest
, GetChangeList_NoNewEntries
) {
377 ASSERT_TRUE(fake_service_
.LoadResourceListForWapi(
378 "gdata/root_feed.json"));
379 // Load the account_metadata.json as well to add the largest changestamp
380 // (654321) to the existing entries.
381 ASSERT_TRUE(fake_service_
.LoadAccountMetadataForWapi(
382 "gdata/account_metadata.json"));
384 GDataErrorCode error
= GDATA_OTHER_ERROR
;
385 scoped_ptr
<ResourceList
> resource_list
;
386 fake_service_
.GetChangeList(
387 654321 + 1, // start_changestamp
388 test_util::CreateCopyResultCallback(&error
, &resource_list
));
389 base::RunLoop().RunUntilIdle();
391 EXPECT_EQ(HTTP_SUCCESS
, error
);
392 ASSERT_TRUE(resource_list
);
393 EXPECT_EQ(fake_service_
.largest_changestamp(),
394 resource_list
->largest_changestamp());
395 // This should be empty as the latest changestamp was passed to
396 // GetResourceList(), hence there should be no new entries.
397 EXPECT_EQ(0U, resource_list
->entries().size());
398 // It's considered loaded even if the result is empty.
399 EXPECT_EQ(1, fake_service_
.change_list_load_count());
402 TEST_F(FakeDriveServiceTest
, GetChangeList_WithNewEntry
) {
403 ASSERT_TRUE(fake_service_
.LoadResourceListForWapi(
404 "gdata/root_feed.json"));
405 // Load the account_metadata.json as well to add the largest changestamp
406 // (654321) to the existing entries.
407 ASSERT_TRUE(fake_service_
.LoadAccountMetadataForWapi(
408 "gdata/account_metadata.json"));
409 // Add a new directory in the root directory. The new directory will have
410 // the changestamp of 654322.
411 ASSERT_TRUE(AddNewDirectory(
412 fake_service_
.GetRootResourceId(), "new directory"));
414 // Get the resource list newer than 654321.
415 GDataErrorCode error
= GDATA_OTHER_ERROR
;
416 scoped_ptr
<ResourceList
> resource_list
;
417 fake_service_
.GetChangeList(
418 654321 + 1, // start_changestamp
419 test_util::CreateCopyResultCallback(&error
, &resource_list
));
420 base::RunLoop().RunUntilIdle();
422 EXPECT_EQ(HTTP_SUCCESS
, error
);
423 ASSERT_TRUE(resource_list
);
424 EXPECT_EQ(fake_service_
.largest_changestamp(),
425 resource_list
->largest_changestamp());
426 // The result should only contain the newly created directory.
427 ASSERT_EQ(1U, resource_list
->entries().size());
428 EXPECT_EQ("new directory", resource_list
->entries()[0]->title());
429 EXPECT_EQ(1, fake_service_
.change_list_load_count());
432 TEST_F(FakeDriveServiceTest
, GetChangeList_Offline
) {
433 ASSERT_TRUE(fake_service_
.LoadResourceListForWapi(
434 "gdata/root_feed.json"));
435 fake_service_
.set_offline(true);
437 GDataErrorCode error
= GDATA_OTHER_ERROR
;
438 scoped_ptr
<ResourceList
> resource_list
;
439 fake_service_
.GetChangeList(
440 654321, // start_changestamp
441 test_util::CreateCopyResultCallback(&error
, &resource_list
));
442 base::RunLoop().RunUntilIdle();
444 EXPECT_EQ(GDATA_NO_CONNECTION
, error
);
445 EXPECT_FALSE(resource_list
);
448 TEST_F(FakeDriveServiceTest
, GetChangeList_DeletedEntry
) {
449 ASSERT_TRUE(fake_service_
.LoadResourceListForWapi(
450 "gdata/root_feed.json"));
451 // Load the account_metadata.json as well to add the largest changestamp
452 // (654321) to the existing entries.
453 ASSERT_TRUE(fake_service_
.LoadAccountMetadataForWapi(
454 "gdata/account_metadata.json"));
455 ASSERT_TRUE(Exists("file:2_file_resource_id"));
457 GDataErrorCode error
= GDATA_OTHER_ERROR
;
458 fake_service_
.DeleteResource("file:2_file_resource_id",
459 std::string(), // etag
460 test_util::CreateCopyResultCallback(&error
));
461 base::RunLoop().RunUntilIdle();
462 ASSERT_EQ(HTTP_NO_CONTENT
, error
);
463 ASSERT_FALSE(Exists("file:2_file_resource_id"));
465 // Get the resource list newer than 654321.
466 error
= GDATA_OTHER_ERROR
;
467 scoped_ptr
<ResourceList
> resource_list
;
468 fake_service_
.GetChangeList(
469 654321 + 1, // start_changestamp
470 test_util::CreateCopyResultCallback(&error
, &resource_list
));
471 base::RunLoop().RunUntilIdle();
473 EXPECT_EQ(HTTP_SUCCESS
, error
);
474 ASSERT_TRUE(resource_list
);
475 EXPECT_EQ(fake_service_
.largest_changestamp(),
476 resource_list
->largest_changestamp());
477 // The result should only contain the deleted file.
478 ASSERT_EQ(1U, resource_list
->entries().size());
479 const ResourceEntry
& entry
= *resource_list
->entries()[0];
480 EXPECT_EQ("file:2_file_resource_id", entry
.resource_id());
481 EXPECT_TRUE(entry
.title().empty());
482 EXPECT_TRUE(entry
.deleted());
483 EXPECT_EQ(1, fake_service_
.change_list_load_count());
486 TEST_F(FakeDriveServiceTest
, GetChangeList_TrashedEntry
) {
487 ASSERT_TRUE(fake_service_
.LoadResourceListForWapi(
488 "gdata/root_feed.json"));
489 // Load the account_metadata.json as well to add the largest changestamp
490 // (654321) to the existing entries.
491 ASSERT_TRUE(fake_service_
.LoadAccountMetadataForWapi(
492 "gdata/account_metadata.json"));
493 ASSERT_TRUE(Exists("file:2_file_resource_id"));
495 GDataErrorCode error
= GDATA_OTHER_ERROR
;
496 fake_service_
.TrashResource("file:2_file_resource_id",
497 test_util::CreateCopyResultCallback(&error
));
498 base::RunLoop().RunUntilIdle();
499 ASSERT_EQ(HTTP_SUCCESS
, error
);
500 ASSERT_FALSE(Exists("file:2_file_resource_id"));
502 // Get the resource list newer than 654321.
503 error
= GDATA_OTHER_ERROR
;
504 scoped_ptr
<ResourceList
> resource_list
;
505 fake_service_
.GetChangeList(
506 654321 + 1, // start_changestamp
507 test_util::CreateCopyResultCallback(&error
, &resource_list
));
508 base::RunLoop().RunUntilIdle();
510 EXPECT_EQ(HTTP_SUCCESS
, error
);
511 ASSERT_TRUE(resource_list
);
512 EXPECT_EQ(fake_service_
.largest_changestamp(),
513 resource_list
->largest_changestamp());
514 // The result should only contain the trashed file.
515 ASSERT_EQ(1U, resource_list
->entries().size());
516 const ResourceEntry
& entry
= *resource_list
->entries()[0];
517 EXPECT_EQ("file:2_file_resource_id", entry
.resource_id());
518 EXPECT_TRUE(entry
.deleted());
519 EXPECT_EQ(1, fake_service_
.change_list_load_count());
522 TEST_F(FakeDriveServiceTest
, GetRemainingChangeList_GetAllResourceList
) {
523 ASSERT_TRUE(fake_service_
.LoadResourceListForWapi(
524 "gdata/root_feed.json"));
525 fake_service_
.set_default_max_results(6);
527 GDataErrorCode error
= GDATA_OTHER_ERROR
;
528 scoped_ptr
<ResourceList
> resource_list
;
529 fake_service_
.GetAllResourceList(
530 test_util::CreateCopyResultCallback(&error
, &resource_list
));
531 base::RunLoop().RunUntilIdle();
532 EXPECT_EQ(HTTP_SUCCESS
, error
);
533 ASSERT_TRUE(resource_list
);
535 // Do some sanity check.
536 // The number of results is 14 entries. Thus, it should split into three
537 // chunks: 6, 6, and then 2.
538 EXPECT_EQ(6U, resource_list
->entries().size());
539 EXPECT_EQ(1, fake_service_
.resource_list_load_count());
541 // Second page loading.
542 const google_apis::Link
* next_link
=
543 resource_list
->GetLinkByType(Link::LINK_NEXT
);
544 ASSERT_TRUE(next_link
);
545 // Keep the next url before releasing the |resource_list|.
546 GURL
next_url(next_link
->href());
548 error
= GDATA_OTHER_ERROR
;
549 resource_list
.reset();
550 fake_service_
.GetRemainingChangeList(
552 test_util::CreateCopyResultCallback(&error
, &resource_list
));
553 base::RunLoop().RunUntilIdle();
555 EXPECT_EQ(HTTP_SUCCESS
, error
);
556 ASSERT_TRUE(resource_list
);
558 EXPECT_EQ(6U, resource_list
->entries().size());
559 EXPECT_EQ(1, fake_service_
.resource_list_load_count());
561 // Third page loading.
562 next_link
= resource_list
->GetLinkByType(Link::LINK_NEXT
);
563 ASSERT_TRUE(next_link
);
564 next_url
= GURL(next_link
->href());
566 error
= GDATA_OTHER_ERROR
;
567 resource_list
.reset();
568 fake_service_
.GetRemainingChangeList(
570 test_util::CreateCopyResultCallback(&error
, &resource_list
));
571 base::RunLoop().RunUntilIdle();
573 EXPECT_EQ(HTTP_SUCCESS
, error
);
574 ASSERT_TRUE(resource_list
);
576 EXPECT_EQ(2U, resource_list
->entries().size());
577 EXPECT_EQ(1, fake_service_
.resource_list_load_count());
580 TEST_F(FakeDriveServiceTest
,
581 GetRemainingFileList_GetResourceListInDirectory
) {
582 ASSERT_TRUE(fake_service_
.LoadResourceListForWapi(
583 "gdata/root_feed.json"));
584 fake_service_
.set_default_max_results(3);
586 GDataErrorCode error
= GDATA_OTHER_ERROR
;
587 scoped_ptr
<ResourceList
> resource_list
;
588 fake_service_
.GetResourceListInDirectory(
589 fake_service_
.GetRootResourceId(),
590 test_util::CreateCopyResultCallback(&error
, &resource_list
));
591 base::RunLoop().RunUntilIdle();
592 EXPECT_EQ(HTTP_SUCCESS
, error
);
593 ASSERT_TRUE(resource_list
);
595 // Do some sanity check.
596 // The number of results is 8 entries. Thus, it should split into three
597 // chunks: 3, 3, and then 2.
598 EXPECT_EQ(3U, resource_list
->entries().size());
599 EXPECT_EQ(1, fake_service_
.directory_load_count());
601 // Second page loading.
602 const google_apis::Link
* next_link
=
603 resource_list
->GetLinkByType(Link::LINK_NEXT
);
604 ASSERT_TRUE(next_link
);
605 // Keep the next url before releasing the |resource_list|.
606 GURL
next_url(next_link
->href());
608 error
= GDATA_OTHER_ERROR
;
609 resource_list
.reset();
610 fake_service_
.GetRemainingFileList(
612 test_util::CreateCopyResultCallback(&error
, &resource_list
));
613 base::RunLoop().RunUntilIdle();
615 EXPECT_EQ(HTTP_SUCCESS
, error
);
616 ASSERT_TRUE(resource_list
);
618 EXPECT_EQ(3U, resource_list
->entries().size());
619 EXPECT_EQ(1, fake_service_
.directory_load_count());
621 // Third page loading.
622 next_link
= resource_list
->GetLinkByType(Link::LINK_NEXT
);
623 ASSERT_TRUE(next_link
);
624 next_url
= GURL(next_link
->href());
626 error
= GDATA_OTHER_ERROR
;
627 resource_list
.reset();
628 fake_service_
.GetRemainingFileList(
630 test_util::CreateCopyResultCallback(&error
, &resource_list
));
631 base::RunLoop().RunUntilIdle();
633 EXPECT_EQ(HTTP_SUCCESS
, error
);
634 ASSERT_TRUE(resource_list
);
636 EXPECT_EQ(2U, resource_list
->entries().size());
637 EXPECT_EQ(1, fake_service_
.directory_load_count());
640 TEST_F(FakeDriveServiceTest
, GetRemainingFileList_Search
) {
641 ASSERT_TRUE(fake_service_
.LoadResourceListForWapi(
642 "gdata/root_feed.json"));
643 fake_service_
.set_default_max_results(2);
645 GDataErrorCode error
= GDATA_OTHER_ERROR
;
646 scoped_ptr
<ResourceList
> resource_list
;
647 fake_service_
.Search(
648 "File", // search_query
649 test_util::CreateCopyResultCallback(&error
, &resource_list
));
650 base::RunLoop().RunUntilIdle();
651 EXPECT_EQ(HTTP_SUCCESS
, error
);
652 ASSERT_TRUE(resource_list
);
654 // Do some sanity check.
655 // The number of results is 4 entries. Thus, it should split into two
656 // chunks: 2, and then 2
657 EXPECT_EQ(2U, resource_list
->entries().size());
659 // Second page loading.
660 const google_apis::Link
* next_link
=
661 resource_list
->GetLinkByType(Link::LINK_NEXT
);
662 ASSERT_TRUE(next_link
);
663 // Keep the next url before releasing the |resource_list|.
664 GURL
next_url(next_link
->href());
666 error
= GDATA_OTHER_ERROR
;
667 resource_list
.reset();
668 fake_service_
.GetRemainingFileList(
670 test_util::CreateCopyResultCallback(&error
, &resource_list
));
671 base::RunLoop().RunUntilIdle();
673 EXPECT_EQ(HTTP_SUCCESS
, error
);
674 ASSERT_TRUE(resource_list
);
676 EXPECT_EQ(2U, resource_list
->entries().size());
679 TEST_F(FakeDriveServiceTest
, GetRemainingChangeList_GetChangeList
) {
680 ASSERT_TRUE(fake_service_
.LoadResourceListForWapi(
681 "gdata/root_feed.json"));
682 fake_service_
.set_default_max_results(2);
684 // Load the account_metadata.json as well to add the largest changestamp
685 // (654321) to the existing entries.
686 ASSERT_TRUE(fake_service_
.LoadAccountMetadataForWapi(
687 "gdata/account_metadata.json"));
688 // Add 5 new directory in the root directory. The new directory will have
689 // the changestamp of 654326.
690 for (int i
= 0; i
< 5; ++i
) {
691 ASSERT_TRUE(AddNewDirectory(
692 fake_service_
.GetRootResourceId(),
693 base::StringPrintf("new directory %d", i
)));
696 GDataErrorCode error
= GDATA_OTHER_ERROR
;
697 scoped_ptr
<ResourceList
> resource_list
;
698 fake_service_
.GetChangeList(
699 654321 + 1, // start_changestamp
700 test_util::CreateCopyResultCallback(&error
, &resource_list
));
701 base::RunLoop().RunUntilIdle();
702 EXPECT_EQ(HTTP_SUCCESS
, error
);
703 ASSERT_TRUE(resource_list
);
705 // Do some sanity check.
706 // The number of results is 5 entries. Thus, it should split into three
707 // chunks: 2, 2 and then 1.
708 EXPECT_EQ(2U, resource_list
->entries().size());
709 EXPECT_EQ(1, fake_service_
.change_list_load_count());
711 // Second page loading.
712 const google_apis::Link
* next_link
=
713 resource_list
->GetLinkByType(Link::LINK_NEXT
);
714 ASSERT_TRUE(next_link
);
715 // Keep the next url before releasing the |resource_list|.
716 GURL
next_url(next_link
->href());
718 error
= GDATA_OTHER_ERROR
;
719 resource_list
.reset();
720 fake_service_
.GetRemainingChangeList(
722 test_util::CreateCopyResultCallback(&error
, &resource_list
));
723 base::RunLoop().RunUntilIdle();
725 EXPECT_EQ(HTTP_SUCCESS
, error
);
726 ASSERT_TRUE(resource_list
);
728 EXPECT_EQ(2U, resource_list
->entries().size());
729 EXPECT_EQ(1, fake_service_
.change_list_load_count());
731 // Third page loading.
732 next_link
= resource_list
->GetLinkByType(Link::LINK_NEXT
);
733 ASSERT_TRUE(next_link
);
734 next_url
= GURL(next_link
->href());
736 error
= GDATA_OTHER_ERROR
;
737 resource_list
.reset();
738 fake_service_
.GetRemainingChangeList(
740 test_util::CreateCopyResultCallback(&error
, &resource_list
));
741 base::RunLoop().RunUntilIdle();
743 EXPECT_EQ(HTTP_SUCCESS
, error
);
744 ASSERT_TRUE(resource_list
);
746 EXPECT_EQ(1U, resource_list
->entries().size());
747 EXPECT_EQ(1, fake_service_
.change_list_load_count());
750 TEST_F(FakeDriveServiceTest
, GetAboutResource
) {
751 ASSERT_TRUE(fake_service_
.LoadAccountMetadataForWapi(
752 "gdata/account_metadata.json"));
754 GDataErrorCode error
= GDATA_OTHER_ERROR
;
755 scoped_ptr
<AboutResource
> about_resource
;
756 fake_service_
.GetAboutResource(
757 test_util::CreateCopyResultCallback(&error
, &about_resource
));
758 base::RunLoop().RunUntilIdle();
760 EXPECT_EQ(HTTP_SUCCESS
, error
);
762 ASSERT_TRUE(about_resource
);
763 // Do some sanity check.
764 EXPECT_EQ(fake_service_
.GetRootResourceId(),
765 about_resource
->root_folder_id());
766 EXPECT_EQ(1, fake_service_
.about_resource_load_count());
769 TEST_F(FakeDriveServiceTest
, GetAboutResource_Offline
) {
770 ASSERT_TRUE(fake_service_
.LoadAccountMetadataForWapi(
771 "gdata/account_metadata.json"));
772 fake_service_
.set_offline(true);
774 GDataErrorCode error
= GDATA_OTHER_ERROR
;
775 scoped_ptr
<AboutResource
> about_resource
;
776 fake_service_
.GetAboutResource(
777 test_util::CreateCopyResultCallback(&error
, &about_resource
));
778 base::RunLoop().RunUntilIdle();
780 EXPECT_EQ(GDATA_NO_CONNECTION
, error
);
781 EXPECT_FALSE(about_resource
);
784 TEST_F(FakeDriveServiceTest
, GetAppList
) {
785 ASSERT_TRUE(fake_service_
.LoadAppListForDriveApi(
786 "drive/applist.json"));
788 GDataErrorCode error
= GDATA_OTHER_ERROR
;
789 scoped_ptr
<AppList
> app_list
;
790 fake_service_
.GetAppList(
791 test_util::CreateCopyResultCallback(&error
, &app_list
));
792 base::RunLoop().RunUntilIdle();
794 EXPECT_EQ(HTTP_SUCCESS
, error
);
796 ASSERT_TRUE(app_list
);
797 EXPECT_EQ(1, fake_service_
.app_list_load_count());
800 TEST_F(FakeDriveServiceTest
, GetAppList_Offline
) {
801 ASSERT_TRUE(fake_service_
.LoadAppListForDriveApi(
802 "drive/applist.json"));
803 fake_service_
.set_offline(true);
805 GDataErrorCode error
= GDATA_OTHER_ERROR
;
806 scoped_ptr
<AppList
> app_list
;
807 fake_service_
.GetAppList(
808 test_util::CreateCopyResultCallback(&error
, &app_list
));
809 base::RunLoop().RunUntilIdle();
811 EXPECT_EQ(GDATA_NO_CONNECTION
, error
);
812 EXPECT_FALSE(app_list
);
815 TEST_F(FakeDriveServiceTest
, GetResourceEntry_ExistingFile
) {
816 ASSERT_TRUE(fake_service_
.LoadResourceListForWapi(
817 "gdata/root_feed.json"));
819 const std::string kResourceId
= "file:2_file_resource_id";
820 GDataErrorCode error
= GDATA_OTHER_ERROR
;
821 scoped_ptr
<ResourceEntry
> resource_entry
;
822 fake_service_
.GetResourceEntry(
824 test_util::CreateCopyResultCallback(&error
, &resource_entry
));
825 base::RunLoop().RunUntilIdle();
827 EXPECT_EQ(HTTP_SUCCESS
, error
);
828 ASSERT_TRUE(resource_entry
);
829 // Do some sanity check.
830 EXPECT_EQ(kResourceId
, resource_entry
->resource_id());
833 TEST_F(FakeDriveServiceTest
, GetResourceEntry_NonexistingFile
) {
834 ASSERT_TRUE(fake_service_
.LoadResourceListForWapi(
835 "gdata/root_feed.json"));
837 const std::string kResourceId
= "file:nonexisting_resource_id";
838 GDataErrorCode error
= GDATA_OTHER_ERROR
;
839 scoped_ptr
<ResourceEntry
> resource_entry
;
840 fake_service_
.GetResourceEntry(
842 test_util::CreateCopyResultCallback(&error
, &resource_entry
));
843 base::RunLoop().RunUntilIdle();
845 EXPECT_EQ(HTTP_NOT_FOUND
, error
);
846 ASSERT_FALSE(resource_entry
);
849 TEST_F(FakeDriveServiceTest
, GetResourceEntry_Offline
) {
850 ASSERT_TRUE(fake_service_
.LoadResourceListForWapi(
851 "gdata/root_feed.json"));
852 fake_service_
.set_offline(true);
854 const std::string kResourceId
= "file:2_file_resource_id";
855 GDataErrorCode error
= GDATA_OTHER_ERROR
;
856 scoped_ptr
<ResourceEntry
> resource_entry
;
857 fake_service_
.GetResourceEntry(
859 test_util::CreateCopyResultCallback(&error
, &resource_entry
));
860 base::RunLoop().RunUntilIdle();
862 EXPECT_EQ(GDATA_NO_CONNECTION
, error
);
863 EXPECT_FALSE(resource_entry
);
866 TEST_F(FakeDriveServiceTest
, GetShareUrl
) {
867 ASSERT_TRUE(fake_service_
.LoadResourceListForWapi(
868 "gdata/root_feed.json"));
870 const std::string kResourceId
= "file:2_file_resource_id";
871 GDataErrorCode error
= GDATA_OTHER_ERROR
;
873 fake_service_
.GetShareUrl(
875 GURL(), // embed origin
876 test_util::CreateCopyResultCallback(&error
, &share_url
));
877 base::RunLoop().RunUntilIdle();
879 EXPECT_EQ(HTTP_SUCCESS
, error
);
880 EXPECT_FALSE(share_url
.is_empty());
883 TEST_F(FakeDriveServiceTest
, DeleteResource_ExistingFile
) {
884 ASSERT_TRUE(fake_service_
.LoadResourceListForWapi(
885 "gdata/root_feed.json"));
887 // Resource "file:2_file_resource_id" should now exist.
888 ASSERT_TRUE(Exists("file:2_file_resource_id"));
890 GDataErrorCode error
= GDATA_OTHER_ERROR
;
891 fake_service_
.DeleteResource("file:2_file_resource_id",
892 std::string(), // etag
893 test_util::CreateCopyResultCallback(&error
));
894 base::RunLoop().RunUntilIdle();
896 EXPECT_EQ(HTTP_NO_CONTENT
, error
);
897 // Resource "file:2_file_resource_id" should be gone now.
898 EXPECT_FALSE(Exists("file:2_file_resource_id"));
900 error
= GDATA_OTHER_ERROR
;
901 fake_service_
.DeleteResource("file:2_file_resource_id",
902 std::string(), // etag
903 test_util::CreateCopyResultCallback(&error
));
904 base::RunLoop().RunUntilIdle();
905 EXPECT_EQ(HTTP_NOT_FOUND
, error
);
906 EXPECT_FALSE(Exists("file:2_file_resource_id"));
909 TEST_F(FakeDriveServiceTest
, DeleteResource_NonexistingFile
) {
910 ASSERT_TRUE(fake_service_
.LoadResourceListForWapi(
911 "gdata/root_feed.json"));
913 GDataErrorCode error
= GDATA_OTHER_ERROR
;
914 fake_service_
.DeleteResource("file:nonexisting_resource_id",
915 std::string(), // etag
916 test_util::CreateCopyResultCallback(&error
));
917 base::RunLoop().RunUntilIdle();
919 EXPECT_EQ(HTTP_NOT_FOUND
, error
);
922 TEST_F(FakeDriveServiceTest
, DeleteResource_ETagMatch
) {
923 ASSERT_TRUE(fake_service_
.LoadResourceListForWapi(
924 "gdata/root_feed.json"));
926 // Resource "file:2_file_resource_id" should now exist.
927 scoped_ptr
<ResourceEntry
> entry
= FindEntry("file:2_file_resource_id");
929 ASSERT_FALSE(entry
->deleted());
930 ASSERT_FALSE(entry
->etag().empty());
932 GDataErrorCode error
= GDATA_OTHER_ERROR
;
933 fake_service_
.DeleteResource("file:2_file_resource_id",
934 entry
->etag() + "_mismatch",
935 test_util::CreateCopyResultCallback(&error
));
936 base::RunLoop().RunUntilIdle();
938 EXPECT_EQ(HTTP_PRECONDITION
, error
);
939 // Resource "file:2_file_resource_id" should still exist.
940 EXPECT_TRUE(Exists("file:2_file_resource_id"));
942 error
= GDATA_OTHER_ERROR
;
943 fake_service_
.DeleteResource("file:2_file_resource_id",
945 test_util::CreateCopyResultCallback(&error
));
946 base::RunLoop().RunUntilIdle();
947 EXPECT_EQ(HTTP_NO_CONTENT
, error
);
948 // Resource "file:2_file_resource_id" should be gone now.
949 EXPECT_FALSE(Exists("file:2_file_resource_id"));
952 TEST_F(FakeDriveServiceTest
, DeleteResource_Offline
) {
953 ASSERT_TRUE(fake_service_
.LoadResourceListForWapi(
954 "gdata/root_feed.json"));
955 fake_service_
.set_offline(true);
957 GDataErrorCode error
= GDATA_OTHER_ERROR
;
958 fake_service_
.DeleteResource("file:2_file_resource_id",
959 std::string(), // etag
960 test_util::CreateCopyResultCallback(&error
));
961 base::RunLoop().RunUntilIdle();
963 EXPECT_EQ(GDATA_NO_CONNECTION
, error
);
966 TEST_F(FakeDriveServiceTest
, TrashResource_ExistingFile
) {
967 ASSERT_TRUE(fake_service_
.LoadResourceListForWapi(
968 "gdata/root_feed.json"));
970 // Resource "file:2_file_resource_id" should now exist.
971 ASSERT_TRUE(Exists("file:2_file_resource_id"));
973 GDataErrorCode error
= GDATA_OTHER_ERROR
;
974 fake_service_
.TrashResource("file:2_file_resource_id",
975 test_util::CreateCopyResultCallback(&error
));
976 base::RunLoop().RunUntilIdle();
978 EXPECT_EQ(HTTP_SUCCESS
, error
);
979 // Resource "file:2_file_resource_id" should be gone now.
980 EXPECT_FALSE(Exists("file:2_file_resource_id"));
982 error
= GDATA_OTHER_ERROR
;
983 fake_service_
.TrashResource("file:2_file_resource_id",
984 test_util::CreateCopyResultCallback(&error
));
985 base::RunLoop().RunUntilIdle();
986 EXPECT_EQ(HTTP_NOT_FOUND
, error
);
987 EXPECT_FALSE(Exists("file:2_file_resource_id"));
990 TEST_F(FakeDriveServiceTest
, TrashResource_NonexistingFile
) {
991 ASSERT_TRUE(fake_service_
.LoadResourceListForWapi(
992 "gdata/root_feed.json"));
994 GDataErrorCode error
= GDATA_OTHER_ERROR
;
995 fake_service_
.TrashResource("file:nonexisting_resource_id",
996 test_util::CreateCopyResultCallback(&error
));
997 base::RunLoop().RunUntilIdle();
999 EXPECT_EQ(HTTP_NOT_FOUND
, error
);
1002 TEST_F(FakeDriveServiceTest
, TrashResource_Offline
) {
1003 ASSERT_TRUE(fake_service_
.LoadResourceListForWapi(
1004 "gdata/root_feed.json"));
1005 fake_service_
.set_offline(true);
1007 GDataErrorCode error
= GDATA_OTHER_ERROR
;
1008 fake_service_
.TrashResource("file:2_file_resource_id",
1009 test_util::CreateCopyResultCallback(&error
));
1010 base::RunLoop().RunUntilIdle();
1012 EXPECT_EQ(GDATA_NO_CONNECTION
, error
);
1015 TEST_F(FakeDriveServiceTest
, DownloadFile_ExistingFile
) {
1016 ASSERT_TRUE(fake_service_
.LoadResourceListForWapi(
1017 "gdata/root_feed.json"));
1019 base::ScopedTempDir temp_dir
;
1020 ASSERT_TRUE(temp_dir
.CreateUniqueTempDir());
1022 std::vector
<test_util::ProgressInfo
> download_progress_values
;
1024 const base::FilePath kOutputFilePath
=
1025 temp_dir
.path().AppendASCII("whatever.txt");
1026 GDataErrorCode error
= GDATA_OTHER_ERROR
;
1027 base::FilePath output_file_path
;
1028 test_util::TestGetContentCallback get_content_callback
;
1029 fake_service_
.DownloadFile(
1031 "file:2_file_resource_id",
1032 test_util::CreateCopyResultCallback(&error
, &output_file_path
),
1033 get_content_callback
.callback(),
1034 base::Bind(&test_util::AppendProgressCallbackResult
,
1035 &download_progress_values
));
1036 base::RunLoop().RunUntilIdle();
1038 EXPECT_EQ(HTTP_SUCCESS
, error
);
1039 EXPECT_EQ(output_file_path
, kOutputFilePath
);
1040 std::string content
;
1041 ASSERT_TRUE(base::ReadFileToString(output_file_path
, &content
));
1042 // The content is "x"s of the file size specified in root_feed.json.
1043 EXPECT_EQ("This is some test content.", content
);
1044 ASSERT_TRUE(!download_progress_values
.empty());
1045 EXPECT_TRUE(base::STLIsSorted(download_progress_values
));
1046 EXPECT_LE(0, download_progress_values
.front().first
);
1047 EXPECT_GE(26, download_progress_values
.back().first
);
1048 EXPECT_EQ(content
, get_content_callback
.GetConcatenatedData());
1051 TEST_F(FakeDriveServiceTest
, DownloadFile_NonexistingFile
) {
1052 ASSERT_TRUE(fake_service_
.LoadResourceListForWapi(
1053 "gdata/root_feed.json"));
1055 base::ScopedTempDir temp_dir
;
1056 ASSERT_TRUE(temp_dir
.CreateUniqueTempDir());
1058 const base::FilePath kOutputFilePath
=
1059 temp_dir
.path().AppendASCII("whatever.txt");
1060 GDataErrorCode error
= GDATA_OTHER_ERROR
;
1061 base::FilePath output_file_path
;
1062 fake_service_
.DownloadFile(
1064 "file:non_existent_file_resource_id",
1065 test_util::CreateCopyResultCallback(&error
, &output_file_path
),
1066 GetContentCallback(),
1067 ProgressCallback());
1068 base::RunLoop().RunUntilIdle();
1070 EXPECT_EQ(HTTP_NOT_FOUND
, error
);
1073 TEST_F(FakeDriveServiceTest
, DownloadFile_Offline
) {
1074 ASSERT_TRUE(fake_service_
.LoadResourceListForWapi(
1075 "gdata/root_feed.json"));
1076 fake_service_
.set_offline(true);
1078 base::ScopedTempDir temp_dir
;
1079 ASSERT_TRUE(temp_dir
.CreateUniqueTempDir());
1081 const base::FilePath kOutputFilePath
=
1082 temp_dir
.path().AppendASCII("whatever.txt");
1083 GDataErrorCode error
= GDATA_OTHER_ERROR
;
1084 base::FilePath output_file_path
;
1085 fake_service_
.DownloadFile(
1087 "file:2_file_resource_id",
1088 test_util::CreateCopyResultCallback(&error
, &output_file_path
),
1089 GetContentCallback(),
1090 ProgressCallback());
1091 base::RunLoop().RunUntilIdle();
1093 EXPECT_EQ(GDATA_NO_CONNECTION
, error
);
1096 TEST_F(FakeDriveServiceTest
, CopyResource
) {
1097 const base::Time::Exploded kModifiedDate
= {2012, 7, 0, 19, 15, 59, 13, 123};
1099 ASSERT_TRUE(fake_service_
.LoadResourceListForWapi(
1100 "gdata/root_feed.json"));
1101 ASSERT_TRUE(fake_service_
.LoadAccountMetadataForWapi(
1102 "gdata/account_metadata.json"));
1104 int64 old_largest_change_id
= GetLargestChangeByAboutResource();
1106 const std::string kResourceId
= "file:2_file_resource_id";
1107 const std::string kParentResourceId
= "folder:2_folder_resource_id";
1108 GDataErrorCode error
= GDATA_OTHER_ERROR
;
1109 scoped_ptr
<ResourceEntry
> resource_entry
;
1110 fake_service_
.CopyResource(
1114 base::Time::FromUTCExploded(kModifiedDate
),
1115 test_util::CreateCopyResultCallback(&error
, &resource_entry
));
1116 base::RunLoop().RunUntilIdle();
1118 EXPECT_EQ(HTTP_SUCCESS
, error
);
1119 ASSERT_TRUE(resource_entry
);
1120 // The copied entry should have the new resource ID and the title.
1121 EXPECT_NE(kResourceId
, resource_entry
->resource_id());
1122 EXPECT_EQ("new title", resource_entry
->title());
1123 EXPECT_EQ(base::Time::FromUTCExploded(kModifiedDate
),
1124 resource_entry
->updated_time());
1125 EXPECT_TRUE(HasParent(resource_entry
->resource_id(), kParentResourceId
));
1126 // Should be incremented as a new hosted document was created.
1127 EXPECT_EQ(old_largest_change_id
+ 1, fake_service_
.largest_changestamp());
1128 EXPECT_EQ(old_largest_change_id
+ 1, GetLargestChangeByAboutResource());
1131 TEST_F(FakeDriveServiceTest
, CopyResource_NonExisting
) {
1132 ASSERT_TRUE(fake_service_
.LoadResourceListForWapi(
1133 "gdata/root_feed.json"));
1135 const std::string kResourceId
= "document:nonexisting_resource_id";
1136 GDataErrorCode error
= GDATA_OTHER_ERROR
;
1137 scoped_ptr
<ResourceEntry
> resource_entry
;
1138 fake_service_
.CopyResource(
1140 "folder:1_folder_resource_id",
1143 test_util::CreateCopyResultCallback(&error
, &resource_entry
));
1144 base::RunLoop().RunUntilIdle();
1146 EXPECT_EQ(HTTP_NOT_FOUND
, error
);
1149 TEST_F(FakeDriveServiceTest
, CopyResource_EmptyParentResourceId
) {
1150 ASSERT_TRUE(fake_service_
.LoadResourceListForWapi(
1151 "gdata/root_feed.json"));
1152 ASSERT_TRUE(fake_service_
.LoadAccountMetadataForWapi(
1153 "gdata/account_metadata.json"));
1155 int64 old_largest_change_id
= GetLargestChangeByAboutResource();
1157 const std::string kResourceId
= "file:2_file_resource_id";
1158 GDataErrorCode error
= GDATA_OTHER_ERROR
;
1159 scoped_ptr
<ResourceEntry
> resource_entry
;
1160 fake_service_
.CopyResource(
1165 test_util::CreateCopyResultCallback(&error
, &resource_entry
));
1166 base::RunLoop().RunUntilIdle();
1168 EXPECT_EQ(HTTP_SUCCESS
, error
);
1169 ASSERT_TRUE(resource_entry
);
1170 // The copied entry should have the new resource ID and the title.
1171 EXPECT_NE(kResourceId
, resource_entry
->resource_id());
1172 EXPECT_EQ("new title", resource_entry
->title());
1173 EXPECT_TRUE(HasParent(kResourceId
, fake_service_
.GetRootResourceId()));
1174 // Should be incremented as a new hosted document was created.
1175 EXPECT_EQ(old_largest_change_id
+ 1, fake_service_
.largest_changestamp());
1176 EXPECT_EQ(old_largest_change_id
+ 1, GetLargestChangeByAboutResource());
1179 TEST_F(FakeDriveServiceTest
, CopyResource_Offline
) {
1180 ASSERT_TRUE(fake_service_
.LoadResourceListForWapi(
1181 "gdata/root_feed.json"));
1182 fake_service_
.set_offline(true);
1184 const std::string kResourceId
= "file:2_file_resource_id";
1185 GDataErrorCode error
= GDATA_OTHER_ERROR
;
1186 scoped_ptr
<ResourceEntry
> resource_entry
;
1187 fake_service_
.CopyResource(
1189 "folder:1_folder_resource_id",
1192 test_util::CreateCopyResultCallback(&error
, &resource_entry
));
1193 base::RunLoop().RunUntilIdle();
1195 EXPECT_EQ(GDATA_NO_CONNECTION
, error
);
1196 EXPECT_FALSE(resource_entry
);
1199 TEST_F(FakeDriveServiceTest
, UpdateResource
) {
1200 const base::Time::Exploded kModifiedDate
= {2012, 7, 0, 19, 15, 59, 13, 123};
1201 const base::Time::Exploded kViewedDate
= {2013, 8, 1, 20, 16, 00, 14, 234};
1203 ASSERT_TRUE(fake_service_
.LoadResourceListForWapi(
1204 "gdata/root_feed.json"));
1205 ASSERT_TRUE(fake_service_
.LoadAccountMetadataForWapi(
1206 "gdata/account_metadata.json"));
1208 int64 old_largest_change_id
= GetLargestChangeByAboutResource();
1210 const std::string kResourceId
= "file:2_file_resource_id";
1211 const std::string kParentResourceId
= "folder:2_folder_resource_id";
1212 GDataErrorCode error
= GDATA_OTHER_ERROR
;
1213 scoped_ptr
<ResourceEntry
> resource_entry
;
1214 fake_service_
.UpdateResource(
1218 base::Time::FromUTCExploded(kModifiedDate
),
1219 base::Time::FromUTCExploded(kViewedDate
),
1220 test_util::CreateCopyResultCallback(&error
, &resource_entry
));
1221 base::RunLoop().RunUntilIdle();
1223 EXPECT_EQ(HTTP_SUCCESS
, error
);
1224 ASSERT_TRUE(resource_entry
);
1225 // The updated entry should have the new title.
1226 EXPECT_EQ(kResourceId
, resource_entry
->resource_id());
1227 EXPECT_EQ("new title", resource_entry
->title());
1228 EXPECT_EQ(base::Time::FromUTCExploded(kModifiedDate
),
1229 resource_entry
->updated_time());
1230 EXPECT_EQ(base::Time::FromUTCExploded(kViewedDate
),
1231 resource_entry
->last_viewed_time());
1232 EXPECT_TRUE(HasParent(kResourceId
, kParentResourceId
));
1233 // Should be incremented as a new hosted document was created.
1234 EXPECT_EQ(old_largest_change_id
+ 1, fake_service_
.largest_changestamp());
1235 EXPECT_EQ(old_largest_change_id
+ 1, GetLargestChangeByAboutResource());
1238 TEST_F(FakeDriveServiceTest
, UpdateResource_NonExisting
) {
1239 ASSERT_TRUE(fake_service_
.LoadResourceListForWapi(
1240 "gdata/root_feed.json"));
1242 const std::string kResourceId
= "document:nonexisting_resource_id";
1243 GDataErrorCode error
= GDATA_OTHER_ERROR
;
1244 scoped_ptr
<ResourceEntry
> resource_entry
;
1245 fake_service_
.UpdateResource(
1247 "folder:1_folder_resource_id",
1251 test_util::CreateCopyResultCallback(&error
, &resource_entry
));
1252 base::RunLoop().RunUntilIdle();
1254 EXPECT_EQ(HTTP_NOT_FOUND
, error
);
1257 TEST_F(FakeDriveServiceTest
, UpdateResource_EmptyParentResourceId
) {
1258 ASSERT_TRUE(fake_service_
.LoadResourceListForWapi(
1259 "gdata/root_feed.json"));
1260 ASSERT_TRUE(fake_service_
.LoadAccountMetadataForWapi(
1261 "gdata/account_metadata.json"));
1263 int64 old_largest_change_id
= GetLargestChangeByAboutResource();
1265 const std::string kResourceId
= "file:2_file_resource_id";
1267 // Just make sure that the resource is under root.
1268 ASSERT_TRUE(HasParent(kResourceId
, "fake_root"));
1270 GDataErrorCode error
= GDATA_OTHER_ERROR
;
1271 scoped_ptr
<ResourceEntry
> resource_entry
;
1272 fake_service_
.UpdateResource(
1278 test_util::CreateCopyResultCallback(&error
, &resource_entry
));
1279 base::RunLoop().RunUntilIdle();
1281 EXPECT_EQ(HTTP_SUCCESS
, error
);
1282 ASSERT_TRUE(resource_entry
);
1283 // The updated entry should have the new title.
1284 EXPECT_EQ(kResourceId
, resource_entry
->resource_id());
1285 EXPECT_EQ("new title", resource_entry
->title());
1286 EXPECT_TRUE(HasParent(kResourceId
, "fake_root"));
1287 // Should be incremented as a new hosted document was created.
1288 EXPECT_EQ(old_largest_change_id
+ 1, fake_service_
.largest_changestamp());
1289 EXPECT_EQ(old_largest_change_id
+ 1, GetLargestChangeByAboutResource());
1292 TEST_F(FakeDriveServiceTest
, UpdateResource_Offline
) {
1293 ASSERT_TRUE(fake_service_
.LoadResourceListForWapi(
1294 "gdata/root_feed.json"));
1295 fake_service_
.set_offline(true);
1297 const std::string kResourceId
= "file:2_file_resource_id";
1298 GDataErrorCode error
= GDATA_OTHER_ERROR
;
1299 scoped_ptr
<ResourceEntry
> resource_entry
;
1300 fake_service_
.UpdateResource(
1306 test_util::CreateCopyResultCallback(&error
, &resource_entry
));
1307 base::RunLoop().RunUntilIdle();
1309 EXPECT_EQ(GDATA_NO_CONNECTION
, error
);
1310 EXPECT_FALSE(resource_entry
);
1313 TEST_F(FakeDriveServiceTest
, RenameResource_ExistingFile
) {
1314 ASSERT_TRUE(fake_service_
.LoadResourceListForWapi(
1315 "gdata/root_feed.json"));
1316 ASSERT_TRUE(fake_service_
.LoadAccountMetadataForWapi(
1317 "gdata/account_metadata.json"));
1319 int64 old_largest_change_id
= GetLargestChangeByAboutResource();
1321 const std::string kResourceId
= "file:2_file_resource_id";
1323 GDataErrorCode error
= GDATA_OTHER_ERROR
;
1324 fake_service_
.RenameResource(kResourceId
,
1326 test_util::CreateCopyResultCallback(&error
));
1327 base::RunLoop().RunUntilIdle();
1329 EXPECT_EQ(HTTP_SUCCESS
, error
);
1331 scoped_ptr
<ResourceEntry
> resource_entry
= FindEntry(kResourceId
);
1332 ASSERT_TRUE(resource_entry
);
1333 EXPECT_EQ("new title", resource_entry
->title());
1334 // Should be incremented as a file was renamed.
1335 EXPECT_EQ(old_largest_change_id
+ 1, fake_service_
.largest_changestamp());
1336 EXPECT_EQ(old_largest_change_id
+ 1, GetLargestChangeByAboutResource());
1339 TEST_F(FakeDriveServiceTest
, RenameResource_NonexistingFile
) {
1340 ASSERT_TRUE(fake_service_
.LoadResourceListForWapi(
1341 "gdata/root_feed.json"));
1343 const std::string kResourceId
= "file:nonexisting_file";
1345 GDataErrorCode error
= GDATA_OTHER_ERROR
;
1346 fake_service_
.RenameResource(kResourceId
,
1348 test_util::CreateCopyResultCallback(&error
));
1349 base::RunLoop().RunUntilIdle();
1351 EXPECT_EQ(HTTP_NOT_FOUND
, error
);
1354 TEST_F(FakeDriveServiceTest
, RenameResource_Offline
) {
1355 ASSERT_TRUE(fake_service_
.LoadResourceListForWapi(
1356 "gdata/root_feed.json"));
1357 fake_service_
.set_offline(true);
1359 const std::string kResourceId
= "file:2_file_resource_id";
1361 GDataErrorCode error
= GDATA_OTHER_ERROR
;
1362 fake_service_
.RenameResource(kResourceId
,
1364 test_util::CreateCopyResultCallback(&error
));
1365 base::RunLoop().RunUntilIdle();
1367 EXPECT_EQ(GDATA_NO_CONNECTION
, error
);
1370 TEST_F(FakeDriveServiceTest
, AddResourceToDirectory_FileInRootDirectory
) {
1371 ASSERT_TRUE(fake_service_
.LoadResourceListForWapi(
1372 "gdata/root_feed.json"));
1373 ASSERT_TRUE(fake_service_
.LoadAccountMetadataForWapi(
1374 "gdata/account_metadata.json"));
1376 int64 old_largest_change_id
= GetLargestChangeByAboutResource();
1378 const std::string kResourceId
= "file:2_file_resource_id";
1379 const std::string kOldParentResourceId
= fake_service_
.GetRootResourceId();
1380 const std::string kNewParentResourceId
= "folder:1_folder_resource_id";
1382 // Here's the original parent link.
1383 EXPECT_TRUE(HasParent(kResourceId
, kOldParentResourceId
));
1384 EXPECT_FALSE(HasParent(kResourceId
, kNewParentResourceId
));
1386 GDataErrorCode error
= GDATA_OTHER_ERROR
;
1387 fake_service_
.AddResourceToDirectory(
1388 kNewParentResourceId
,
1390 test_util::CreateCopyResultCallback(&error
));
1391 base::RunLoop().RunUntilIdle();
1393 EXPECT_EQ(HTTP_SUCCESS
, error
);
1395 // The parent link should now be changed.
1396 EXPECT_TRUE(HasParent(kResourceId
, kOldParentResourceId
));
1397 EXPECT_TRUE(HasParent(kResourceId
, kNewParentResourceId
));
1398 // Should be incremented as a file was moved.
1399 EXPECT_EQ(old_largest_change_id
+ 1, fake_service_
.largest_changestamp());
1400 EXPECT_EQ(old_largest_change_id
+ 1, GetLargestChangeByAboutResource());
1403 TEST_F(FakeDriveServiceTest
, AddResourceToDirectory_FileInNonRootDirectory
) {
1404 ASSERT_TRUE(fake_service_
.LoadResourceListForWapi(
1405 "gdata/root_feed.json"));
1406 ASSERT_TRUE(fake_service_
.LoadAccountMetadataForWapi(
1407 "gdata/account_metadata.json"));
1409 int64 old_largest_change_id
= GetLargestChangeByAboutResource();
1411 const std::string kResourceId
= "file:subdirectory_file_1_id";
1412 const std::string kOldParentResourceId
= "folder:1_folder_resource_id";
1413 const std::string kNewParentResourceId
= "folder:2_folder_resource_id";
1415 // Here's the original parent link.
1416 EXPECT_TRUE(HasParent(kResourceId
, kOldParentResourceId
));
1417 EXPECT_FALSE(HasParent(kResourceId
, kNewParentResourceId
));
1419 GDataErrorCode error
= GDATA_OTHER_ERROR
;
1420 fake_service_
.AddResourceToDirectory(
1421 kNewParentResourceId
,
1423 test_util::CreateCopyResultCallback(&error
));
1424 base::RunLoop().RunUntilIdle();
1426 EXPECT_EQ(HTTP_SUCCESS
, error
);
1428 // The parent link should now be changed.
1429 EXPECT_TRUE(HasParent(kResourceId
, kOldParentResourceId
));
1430 EXPECT_TRUE(HasParent(kResourceId
, kNewParentResourceId
));
1431 // Should be incremented as a file was moved.
1432 EXPECT_EQ(old_largest_change_id
+ 1, fake_service_
.largest_changestamp());
1433 EXPECT_EQ(old_largest_change_id
+ 1, GetLargestChangeByAboutResource());
1436 TEST_F(FakeDriveServiceTest
, AddResourceToDirectory_NonexistingFile
) {
1437 ASSERT_TRUE(fake_service_
.LoadResourceListForWapi(
1438 "gdata/root_feed.json"));
1440 const std::string kResourceId
= "file:nonexisting_file";
1441 const std::string kNewParentResourceId
= "folder:1_folder_resource_id";
1443 GDataErrorCode error
= GDATA_OTHER_ERROR
;
1444 fake_service_
.AddResourceToDirectory(
1445 kNewParentResourceId
,
1447 test_util::CreateCopyResultCallback(&error
));
1448 base::RunLoop().RunUntilIdle();
1450 EXPECT_EQ(HTTP_NOT_FOUND
, error
);
1453 TEST_F(FakeDriveServiceTest
, AddResourceToDirectory_OrphanFile
) {
1454 ASSERT_TRUE(fake_service_
.LoadResourceListForWapi(
1455 "gdata/root_feed.json"));
1456 ASSERT_TRUE(fake_service_
.LoadAccountMetadataForWapi(
1457 "gdata/account_metadata.json"));
1459 int64 old_largest_change_id
= GetLargestChangeByAboutResource();
1461 const std::string kResourceId
= "file:1_orphanfile_resource_id";
1462 const std::string kNewParentResourceId
= "folder:1_folder_resource_id";
1464 // The file does not belong to any directory, even to the root.
1465 EXPECT_FALSE(HasParent(kResourceId
, kNewParentResourceId
));
1466 EXPECT_FALSE(HasParent(kResourceId
, fake_service_
.GetRootResourceId()));
1468 GDataErrorCode error
= GDATA_OTHER_ERROR
;
1469 fake_service_
.AddResourceToDirectory(
1470 kNewParentResourceId
,
1472 test_util::CreateCopyResultCallback(&error
));
1473 base::RunLoop().RunUntilIdle();
1475 EXPECT_EQ(HTTP_SUCCESS
, error
);
1477 // The parent link should now be changed.
1478 EXPECT_TRUE(HasParent(kResourceId
, kNewParentResourceId
));
1479 EXPECT_FALSE(HasParent(kResourceId
, fake_service_
.GetRootResourceId()));
1480 // Should be incremented as a file was moved.
1481 EXPECT_EQ(old_largest_change_id
+ 1, fake_service_
.largest_changestamp());
1482 EXPECT_EQ(old_largest_change_id
+ 1, GetLargestChangeByAboutResource());
1485 TEST_F(FakeDriveServiceTest
, AddResourceToDirectory_Offline
) {
1486 ASSERT_TRUE(fake_service_
.LoadResourceListForWapi(
1487 "gdata/root_feed.json"));
1488 fake_service_
.set_offline(true);
1490 const std::string kResourceId
= "file:2_file_resource_id";
1491 const std::string kNewParentResourceId
= "folder:1_folder_resource_id";
1493 GDataErrorCode error
= GDATA_OTHER_ERROR
;
1494 fake_service_
.AddResourceToDirectory(
1495 kNewParentResourceId
,
1497 test_util::CreateCopyResultCallback(&error
));
1498 base::RunLoop().RunUntilIdle();
1500 EXPECT_EQ(GDATA_NO_CONNECTION
, error
);
1503 TEST_F(FakeDriveServiceTest
, RemoveResourceFromDirectory_ExistingFile
) {
1504 ASSERT_TRUE(fake_service_
.LoadResourceListForWapi(
1505 "gdata/root_feed.json"));
1506 ASSERT_TRUE(fake_service_
.LoadAccountMetadataForWapi(
1507 "gdata/account_metadata.json"));
1509 int64 old_largest_change_id
= GetLargestChangeByAboutResource();
1511 const std::string kResourceId
= "file:subdirectory_file_1_id";
1512 const std::string kParentResourceId
= "folder:1_folder_resource_id";
1514 scoped_ptr
<ResourceEntry
> resource_entry
= FindEntry(kResourceId
);
1515 ASSERT_TRUE(resource_entry
);
1516 // The parent link should exist now.
1517 const google_apis::Link
* parent_link
=
1518 resource_entry
->GetLinkByType(Link::LINK_PARENT
);
1519 ASSERT_TRUE(parent_link
);
1521 GDataErrorCode error
= GDATA_OTHER_ERROR
;
1522 fake_service_
.RemoveResourceFromDirectory(
1525 test_util::CreateCopyResultCallback(&error
));
1526 base::RunLoop().RunUntilIdle();
1528 EXPECT_EQ(HTTP_NO_CONTENT
, error
);
1530 resource_entry
= FindEntry(kResourceId
);
1531 ASSERT_TRUE(resource_entry
);
1532 // The parent link should be gone now.
1533 parent_link
= resource_entry
->GetLinkByType(Link::LINK_PARENT
);
1534 ASSERT_FALSE(parent_link
);
1535 // Should be incremented as a file was moved to the root directory.
1536 EXPECT_EQ(old_largest_change_id
+ 1, fake_service_
.largest_changestamp());
1537 EXPECT_EQ(old_largest_change_id
+ 1, GetLargestChangeByAboutResource());
1540 TEST_F(FakeDriveServiceTest
, RemoveResourceFromDirectory_NonexistingFile
) {
1541 ASSERT_TRUE(fake_service_
.LoadResourceListForWapi(
1542 "gdata/root_feed.json"));
1544 const std::string kResourceId
= "file:nonexisting_file";
1545 const std::string kParentResourceId
= "folder:1_folder_resource_id";
1547 GDataErrorCode error
= GDATA_OTHER_ERROR
;
1548 fake_service_
.RemoveResourceFromDirectory(
1551 test_util::CreateCopyResultCallback(&error
));
1552 base::RunLoop().RunUntilIdle();
1554 EXPECT_EQ(HTTP_NOT_FOUND
, error
);
1557 TEST_F(FakeDriveServiceTest
, RemoveResourceFromDirectory_OrphanFile
) {
1558 ASSERT_TRUE(fake_service_
.LoadResourceListForWapi(
1559 "gdata/root_feed.json"));
1561 const std::string kResourceId
= "file:1_orphanfile_resource_id";
1562 const std::string kParentResourceId
= fake_service_
.GetRootResourceId();
1564 GDataErrorCode error
= GDATA_OTHER_ERROR
;
1565 fake_service_
.RemoveResourceFromDirectory(
1568 test_util::CreateCopyResultCallback(&error
));
1569 base::RunLoop().RunUntilIdle();
1571 EXPECT_EQ(HTTP_NOT_FOUND
, error
);
1574 TEST_F(FakeDriveServiceTest
, RemoveResourceFromDirectory_Offline
) {
1575 ASSERT_TRUE(fake_service_
.LoadResourceListForWapi(
1576 "gdata/root_feed.json"));
1577 fake_service_
.set_offline(true);
1579 const std::string kResourceId
= "file:subdirectory_file_1_id";
1580 const std::string kParentResourceId
= "folder:1_folder_resource_id";
1582 GDataErrorCode error
= GDATA_OTHER_ERROR
;
1583 fake_service_
.RemoveResourceFromDirectory(
1586 test_util::CreateCopyResultCallback(&error
));
1587 base::RunLoop().RunUntilIdle();
1589 EXPECT_EQ(GDATA_NO_CONNECTION
, error
);
1592 TEST_F(FakeDriveServiceTest
, AddNewDirectory_EmptyParent
) {
1593 ASSERT_TRUE(fake_service_
.LoadResourceListForWapi(
1594 "gdata/root_feed.json"));
1595 ASSERT_TRUE(fake_service_
.LoadAccountMetadataForWapi(
1596 "gdata/account_metadata.json"));
1598 int64 old_largest_change_id
= GetLargestChangeByAboutResource();
1600 GDataErrorCode error
= GDATA_OTHER_ERROR
;
1601 scoped_ptr
<ResourceEntry
> resource_entry
;
1602 fake_service_
.AddNewDirectory(
1605 test_util::CreateCopyResultCallback(&error
, &resource_entry
));
1606 base::RunLoop().RunUntilIdle();
1608 EXPECT_EQ(HTTP_CREATED
, error
);
1609 ASSERT_TRUE(resource_entry
);
1610 EXPECT_TRUE(resource_entry
->is_folder());
1611 EXPECT_EQ("resource_id_1", resource_entry
->resource_id());
1612 EXPECT_EQ("new directory", resource_entry
->title());
1613 EXPECT_TRUE(HasParent(resource_entry
->resource_id(),
1614 fake_service_
.GetRootResourceId()));
1615 // Should be incremented as a new directory was created.
1616 EXPECT_EQ(old_largest_change_id
+ 1, fake_service_
.largest_changestamp());
1617 EXPECT_EQ(old_largest_change_id
+ 1, GetLargestChangeByAboutResource());
1620 TEST_F(FakeDriveServiceTest
, AddNewDirectory_ToRootDirectory
) {
1621 ASSERT_TRUE(fake_service_
.LoadResourceListForWapi(
1622 "gdata/root_feed.json"));
1623 ASSERT_TRUE(fake_service_
.LoadAccountMetadataForWapi(
1624 "gdata/account_metadata.json"));
1626 int64 old_largest_change_id
= GetLargestChangeByAboutResource();
1628 GDataErrorCode error
= GDATA_OTHER_ERROR
;
1629 scoped_ptr
<ResourceEntry
> resource_entry
;
1630 fake_service_
.AddNewDirectory(
1631 fake_service_
.GetRootResourceId(),
1633 test_util::CreateCopyResultCallback(&error
, &resource_entry
));
1634 base::RunLoop().RunUntilIdle();
1636 EXPECT_EQ(HTTP_CREATED
, error
);
1637 ASSERT_TRUE(resource_entry
);
1638 EXPECT_TRUE(resource_entry
->is_folder());
1639 EXPECT_EQ("resource_id_1", resource_entry
->resource_id());
1640 EXPECT_EQ("new directory", resource_entry
->title());
1641 EXPECT_TRUE(HasParent(resource_entry
->resource_id(),
1642 fake_service_
.GetRootResourceId()));
1643 // Should be incremented as a new directory was created.
1644 EXPECT_EQ(old_largest_change_id
+ 1, fake_service_
.largest_changestamp());
1645 EXPECT_EQ(old_largest_change_id
+ 1, GetLargestChangeByAboutResource());
1648 TEST_F(FakeDriveServiceTest
, AddNewDirectory_ToRootDirectoryOnEmptyFileSystem
) {
1649 ASSERT_TRUE(fake_service_
.LoadResourceListForWapi(
1650 "gdata/empty_feed.json"));
1651 ASSERT_TRUE(fake_service_
.LoadAccountMetadataForWapi(
1652 "gdata/account_metadata.json"));
1654 int64 old_largest_change_id
= GetLargestChangeByAboutResource();
1656 GDataErrorCode error
= GDATA_OTHER_ERROR
;
1657 scoped_ptr
<ResourceEntry
> resource_entry
;
1658 fake_service_
.AddNewDirectory(
1659 fake_service_
.GetRootResourceId(),
1661 test_util::CreateCopyResultCallback(&error
, &resource_entry
));
1662 base::RunLoop().RunUntilIdle();
1664 EXPECT_EQ(HTTP_CREATED
, error
);
1665 ASSERT_TRUE(resource_entry
);
1666 EXPECT_TRUE(resource_entry
->is_folder());
1667 EXPECT_EQ("resource_id_1", resource_entry
->resource_id());
1668 EXPECT_EQ("new directory", resource_entry
->title());
1669 EXPECT_TRUE(HasParent(resource_entry
->resource_id(),
1670 fake_service_
.GetRootResourceId()));
1671 // Should be incremented as a new directory was created.
1672 EXPECT_EQ(old_largest_change_id
+ 1, fake_service_
.largest_changestamp());
1673 EXPECT_EQ(old_largest_change_id
+ 1, GetLargestChangeByAboutResource());
1676 TEST_F(FakeDriveServiceTest
, AddNewDirectory_ToNonRootDirectory
) {
1677 ASSERT_TRUE(fake_service_
.LoadResourceListForWapi(
1678 "gdata/root_feed.json"));
1679 ASSERT_TRUE(fake_service_
.LoadAccountMetadataForWapi(
1680 "gdata/account_metadata.json"));
1682 int64 old_largest_change_id
= GetLargestChangeByAboutResource();
1684 const std::string kParentResourceId
= "folder:1_folder_resource_id";
1686 GDataErrorCode error
= GDATA_OTHER_ERROR
;
1687 scoped_ptr
<ResourceEntry
> resource_entry
;
1688 fake_service_
.AddNewDirectory(
1691 test_util::CreateCopyResultCallback(&error
, &resource_entry
));
1692 base::RunLoop().RunUntilIdle();
1694 EXPECT_EQ(HTTP_CREATED
, error
);
1695 ASSERT_TRUE(resource_entry
);
1696 EXPECT_TRUE(resource_entry
->is_folder());
1697 EXPECT_EQ("resource_id_1", resource_entry
->resource_id());
1698 EXPECT_EQ("new directory", resource_entry
->title());
1699 EXPECT_TRUE(HasParent(resource_entry
->resource_id(), kParentResourceId
));
1700 // Should be incremented as a new directory was created.
1701 EXPECT_EQ(old_largest_change_id
+ 1, fake_service_
.largest_changestamp());
1702 EXPECT_EQ(old_largest_change_id
+ 1, GetLargestChangeByAboutResource());
1705 TEST_F(FakeDriveServiceTest
, AddNewDirectory_ToNonexistingDirectory
) {
1706 ASSERT_TRUE(fake_service_
.LoadResourceListForWapi(
1707 "gdata/root_feed.json"));
1709 const std::string kParentResourceId
= "folder:nonexisting_resource_id";
1711 GDataErrorCode error
= GDATA_OTHER_ERROR
;
1712 scoped_ptr
<ResourceEntry
> resource_entry
;
1713 fake_service_
.AddNewDirectory(
1716 test_util::CreateCopyResultCallback(&error
, &resource_entry
));
1717 base::RunLoop().RunUntilIdle();
1719 EXPECT_EQ(HTTP_NOT_FOUND
, error
);
1720 EXPECT_FALSE(resource_entry
);
1723 TEST_F(FakeDriveServiceTest
, AddNewDirectory_Offline
) {
1724 ASSERT_TRUE(fake_service_
.LoadResourceListForWapi(
1725 "gdata/root_feed.json"));
1726 fake_service_
.set_offline(true);
1728 GDataErrorCode error
= GDATA_OTHER_ERROR
;
1729 scoped_ptr
<ResourceEntry
> resource_entry
;
1730 fake_service_
.AddNewDirectory(
1731 fake_service_
.GetRootResourceId(),
1733 test_util::CreateCopyResultCallback(&error
, &resource_entry
));
1734 base::RunLoop().RunUntilIdle();
1736 EXPECT_EQ(GDATA_NO_CONNECTION
, error
);
1737 EXPECT_FALSE(resource_entry
);
1740 TEST_F(FakeDriveServiceTest
, InitiateUploadNewFile_Offline
) {
1741 ASSERT_TRUE(fake_service_
.LoadResourceListForWapi(
1742 "gdata/root_feed.json"));
1743 fake_service_
.set_offline(true);
1745 GDataErrorCode error
= GDATA_OTHER_ERROR
;
1746 GURL upload_location
;
1747 fake_service_
.InitiateUploadNewFile(
1750 "folder:1_folder_resource_id",
1752 test_util::CreateCopyResultCallback(&error
, &upload_location
));
1753 base::RunLoop().RunUntilIdle();
1755 EXPECT_EQ(GDATA_NO_CONNECTION
, error
);
1756 EXPECT_TRUE(upload_location
.is_empty());
1759 TEST_F(FakeDriveServiceTest
, InitiateUploadNewFile_NotFound
) {
1760 ASSERT_TRUE(fake_service_
.LoadResourceListForWapi(
1761 "gdata/root_feed.json"));
1763 GDataErrorCode error
= GDATA_OTHER_ERROR
;
1764 GURL upload_location
;
1765 fake_service_
.InitiateUploadNewFile(
1770 test_util::CreateCopyResultCallback(&error
, &upload_location
));
1771 base::RunLoop().RunUntilIdle();
1773 EXPECT_EQ(HTTP_NOT_FOUND
, error
);
1774 EXPECT_TRUE(upload_location
.is_empty());
1777 TEST_F(FakeDriveServiceTest
, InitiateUploadNewFile
) {
1778 ASSERT_TRUE(fake_service_
.LoadResourceListForWapi(
1779 "gdata/root_feed.json"));
1781 GDataErrorCode error
= GDATA_OTHER_ERROR
;
1782 GURL upload_location
;
1783 fake_service_
.InitiateUploadNewFile(
1786 "folder:1_folder_resource_id",
1788 test_util::CreateCopyResultCallback(&error
, &upload_location
));
1789 base::RunLoop().RunUntilIdle();
1791 EXPECT_EQ(HTTP_SUCCESS
, error
);
1792 EXPECT_FALSE(upload_location
.is_empty());
1793 EXPECT_NE(GURL("https://1_folder_resumable_create_media_link?mode=newfile"),
1797 TEST_F(FakeDriveServiceTest
, InitiateUploadExistingFile_Offline
) {
1798 ASSERT_TRUE(fake_service_
.LoadResourceListForWapi(
1799 "gdata/root_feed.json"));
1800 fake_service_
.set_offline(true);
1802 GDataErrorCode error
= GDATA_OTHER_ERROR
;
1803 GURL upload_location
;
1804 fake_service_
.InitiateUploadExistingFile(
1807 "file:2_file_resource_id",
1808 std::string(), // etag
1809 test_util::CreateCopyResultCallback(&error
, &upload_location
));
1810 base::RunLoop().RunUntilIdle();
1812 EXPECT_EQ(GDATA_NO_CONNECTION
, error
);
1813 EXPECT_TRUE(upload_location
.is_empty());
1816 TEST_F(FakeDriveServiceTest
, InitiateUploadExistingFile_NotFound
) {
1817 ASSERT_TRUE(fake_service_
.LoadResourceListForWapi(
1818 "gdata/root_feed.json"));
1820 GDataErrorCode error
= GDATA_OTHER_ERROR
;
1821 GURL upload_location
;
1822 fake_service_
.InitiateUploadExistingFile(
1826 std::string(), // etag
1827 test_util::CreateCopyResultCallback(&error
, &upload_location
));
1828 base::RunLoop().RunUntilIdle();
1830 EXPECT_EQ(HTTP_NOT_FOUND
, error
);
1831 EXPECT_TRUE(upload_location
.is_empty());
1834 TEST_F(FakeDriveServiceTest
, InitiateUploadExistingFile_WrongETag
) {
1835 ASSERT_TRUE(fake_service_
.LoadResourceListForWapi(
1836 "gdata/root_feed.json"));
1838 GDataErrorCode error
= GDATA_OTHER_ERROR
;
1839 GURL upload_location
;
1840 fake_service_
.InitiateUploadExistingFile(
1843 "file:2_file_resource_id",
1845 test_util::CreateCopyResultCallback(&error
, &upload_location
));
1846 base::RunLoop().RunUntilIdle();
1848 EXPECT_EQ(HTTP_PRECONDITION
, error
);
1849 EXPECT_TRUE(upload_location
.is_empty());
1852 TEST_F(FakeDriveServiceTest
, InitiateUpload_ExistingFile
) {
1853 ASSERT_TRUE(fake_service_
.LoadResourceListForWapi(
1854 "gdata/root_feed.json"));
1856 GDataErrorCode error
= GDATA_OTHER_ERROR
;
1857 GURL upload_location
;
1858 fake_service_
.InitiateUploadExistingFile(
1861 "file:2_file_resource_id",
1862 "\"HhMOFgxXHit7ImBr\"",
1863 test_util::CreateCopyResultCallback(&error
, &upload_location
));
1864 base::RunLoop().RunUntilIdle();
1866 EXPECT_EQ(HTTP_SUCCESS
, error
);
1867 EXPECT_TRUE(upload_location
.is_valid());
1870 TEST_F(FakeDriveServiceTest
, ResumeUpload_Offline
) {
1871 ASSERT_TRUE(fake_service_
.LoadResourceListForWapi(
1872 "gdata/root_feed.json"));
1874 GDataErrorCode error
= GDATA_OTHER_ERROR
;
1875 GURL upload_location
;
1876 fake_service_
.InitiateUploadNewFile(
1879 "folder:1_folder_resource_id",
1881 test_util::CreateCopyResultCallback(&error
, &upload_location
));
1882 base::RunLoop().RunUntilIdle();
1884 EXPECT_EQ(HTTP_SUCCESS
, error
);
1885 EXPECT_FALSE(upload_location
.is_empty());
1886 EXPECT_NE(GURL("https://1_folder_resumable_create_media_link"),
1889 fake_service_
.set_offline(true);
1891 UploadRangeResponse response
;
1892 scoped_ptr
<ResourceEntry
> entry
;
1893 fake_service_
.ResumeUpload(
1895 0, 13, 15, "test/foo",
1897 test_util::CreateCopyResultCallback(&response
, &entry
),
1898 ProgressCallback());
1899 base::RunLoop().RunUntilIdle();
1901 EXPECT_EQ(GDATA_NO_CONNECTION
, response
.code
);
1902 EXPECT_FALSE(entry
.get());
1905 TEST_F(FakeDriveServiceTest
, ResumeUpload_NotFound
) {
1906 ASSERT_TRUE(fake_service_
.LoadResourceListForWapi(
1907 "gdata/root_feed.json"));
1909 GDataErrorCode error
= GDATA_OTHER_ERROR
;
1910 GURL upload_location
;
1911 fake_service_
.InitiateUploadNewFile(
1914 "folder:1_folder_resource_id",
1916 test_util::CreateCopyResultCallback(&error
, &upload_location
));
1917 base::RunLoop().RunUntilIdle();
1919 ASSERT_EQ(HTTP_SUCCESS
, error
);
1921 UploadRangeResponse response
;
1922 scoped_ptr
<ResourceEntry
> entry
;
1923 fake_service_
.ResumeUpload(
1924 GURL("https://foo.com/"),
1925 0, 13, 15, "test/foo",
1927 test_util::CreateCopyResultCallback(&response
, &entry
),
1928 ProgressCallback());
1929 base::RunLoop().RunUntilIdle();
1931 EXPECT_EQ(HTTP_NOT_FOUND
, response
.code
);
1932 EXPECT_FALSE(entry
.get());
1935 TEST_F(FakeDriveServiceTest
, ResumeUpload_ExistingFile
) {
1936 base::ScopedTempDir temp_dir
;
1937 ASSERT_TRUE(temp_dir
.CreateUniqueTempDir());
1938 base::FilePath local_file_path
=
1939 temp_dir
.path().Append(FILE_PATH_LITERAL("File 1.txt"));
1940 std::string
contents("hogefugapiyo");
1941 ASSERT_TRUE(test_util::WriteStringToFile(local_file_path
, contents
));
1943 ASSERT_TRUE(fake_service_
.LoadResourceListForWapi(
1944 "gdata/root_feed.json"));
1946 GDataErrorCode error
= GDATA_OTHER_ERROR
;
1947 GURL upload_location
;
1948 fake_service_
.InitiateUploadExistingFile(
1951 "file:2_file_resource_id",
1952 "\"HhMOFgxXHit7ImBr\"",
1953 test_util::CreateCopyResultCallback(&error
, &upload_location
));
1954 base::RunLoop().RunUntilIdle();
1956 ASSERT_EQ(HTTP_SUCCESS
, error
);
1958 UploadRangeResponse response
;
1959 scoped_ptr
<ResourceEntry
> entry
;
1960 std::vector
<test_util::ProgressInfo
> upload_progress_values
;
1961 fake_service_
.ResumeUpload(
1963 0, contents
.size() / 2, contents
.size(), "text/plain",
1965 test_util::CreateCopyResultCallback(&response
, &entry
),
1966 base::Bind(&test_util::AppendProgressCallbackResult
,
1967 &upload_progress_values
));
1968 base::RunLoop().RunUntilIdle();
1970 EXPECT_EQ(HTTP_RESUME_INCOMPLETE
, response
.code
);
1971 EXPECT_FALSE(entry
.get());
1972 ASSERT_TRUE(!upload_progress_values
.empty());
1973 EXPECT_TRUE(base::STLIsSorted(upload_progress_values
));
1974 EXPECT_LE(0, upload_progress_values
.front().first
);
1975 EXPECT_GE(static_cast<int64
>(contents
.size() / 2),
1976 upload_progress_values
.back().first
);
1978 upload_progress_values
.clear();
1979 fake_service_
.ResumeUpload(
1981 contents
.size() / 2, contents
.size(), contents
.size(), "text/plain",
1983 test_util::CreateCopyResultCallback(&response
, &entry
),
1984 base::Bind(&test_util::AppendProgressCallbackResult
,
1985 &upload_progress_values
));
1986 base::RunLoop().RunUntilIdle();
1988 EXPECT_EQ(HTTP_SUCCESS
, response
.code
);
1989 EXPECT_TRUE(entry
.get());
1990 EXPECT_EQ(static_cast<int64
>(contents
.size()),
1991 entry
->file_size());
1992 EXPECT_TRUE(Exists(entry
->resource_id()));
1993 ASSERT_TRUE(!upload_progress_values
.empty());
1994 EXPECT_TRUE(base::STLIsSorted(upload_progress_values
));
1995 EXPECT_LE(0, upload_progress_values
.front().first
);
1996 EXPECT_GE(static_cast<int64
>(contents
.size() - contents
.size() / 2),
1997 upload_progress_values
.back().first
);
1998 EXPECT_EQ(base::MD5String(contents
), entry
->file_md5());
2001 TEST_F(FakeDriveServiceTest
, ResumeUpload_NewFile
) {
2002 base::ScopedTempDir temp_dir
;
2003 ASSERT_TRUE(temp_dir
.CreateUniqueTempDir());
2004 base::FilePath local_file_path
=
2005 temp_dir
.path().Append(FILE_PATH_LITERAL("new file.foo"));
2006 std::string
contents("hogefugapiyo");
2007 ASSERT_TRUE(test_util::WriteStringToFile(local_file_path
, contents
));
2009 ASSERT_TRUE(fake_service_
.LoadResourceListForWapi(
2010 "gdata/root_feed.json"));
2012 GDataErrorCode error
= GDATA_OTHER_ERROR
;
2013 GURL upload_location
;
2014 fake_service_
.InitiateUploadNewFile(
2017 "folder:1_folder_resource_id",
2019 test_util::CreateCopyResultCallback(&error
, &upload_location
));
2020 base::RunLoop().RunUntilIdle();
2022 EXPECT_EQ(HTTP_SUCCESS
, error
);
2023 EXPECT_FALSE(upload_location
.is_empty());
2024 EXPECT_NE(GURL("https://1_folder_resumable_create_media_link"),
2027 UploadRangeResponse response
;
2028 scoped_ptr
<ResourceEntry
> entry
;
2029 std::vector
<test_util::ProgressInfo
> upload_progress_values
;
2030 fake_service_
.ResumeUpload(
2032 0, contents
.size() / 2, contents
.size(), "test/foo",
2034 test_util::CreateCopyResultCallback(&response
, &entry
),
2035 base::Bind(&test_util::AppendProgressCallbackResult
,
2036 &upload_progress_values
));
2037 base::RunLoop().RunUntilIdle();
2039 EXPECT_EQ(HTTP_RESUME_INCOMPLETE
, response
.code
);
2040 EXPECT_FALSE(entry
.get());
2041 ASSERT_TRUE(!upload_progress_values
.empty());
2042 EXPECT_TRUE(base::STLIsSorted(upload_progress_values
));
2043 EXPECT_LE(0, upload_progress_values
.front().first
);
2044 EXPECT_GE(static_cast<int64
>(contents
.size() / 2),
2045 upload_progress_values
.back().first
);
2047 upload_progress_values
.clear();
2048 fake_service_
.ResumeUpload(
2050 contents
.size() / 2, contents
.size(), contents
.size(), "test/foo",
2052 test_util::CreateCopyResultCallback(&response
, &entry
),
2053 base::Bind(&test_util::AppendProgressCallbackResult
,
2054 &upload_progress_values
));
2055 base::RunLoop().RunUntilIdle();
2057 EXPECT_EQ(HTTP_CREATED
, response
.code
);
2058 EXPECT_TRUE(entry
.get());
2059 EXPECT_EQ(static_cast<int64
>(contents
.size()), entry
->file_size());
2060 EXPECT_TRUE(Exists(entry
->resource_id()));
2061 ASSERT_TRUE(!upload_progress_values
.empty());
2062 EXPECT_TRUE(base::STLIsSorted(upload_progress_values
));
2063 EXPECT_LE(0, upload_progress_values
.front().first
);
2064 EXPECT_GE(static_cast<int64
>(contents
.size() - contents
.size() / 2),
2065 upload_progress_values
.back().first
);
2066 EXPECT_EQ(base::MD5String(contents
), entry
->file_md5());
2069 TEST_F(FakeDriveServiceTest
, AddNewFile_ToRootDirectory
) {
2070 ASSERT_TRUE(fake_service_
.LoadResourceListForWapi(
2071 "gdata/root_feed.json"));
2072 ASSERT_TRUE(fake_service_
.LoadAccountMetadataForWapi(
2073 "gdata/account_metadata.json"));
2075 int64 old_largest_change_id
= GetLargestChangeByAboutResource();
2077 const std::string kContentType
= "text/plain";
2078 const std::string kContentData
= "This is some test content.";
2079 const std::string kTitle
= "new file";
2081 GDataErrorCode error
= GDATA_OTHER_ERROR
;
2082 scoped_ptr
<ResourceEntry
> resource_entry
;
2083 fake_service_
.AddNewFile(
2086 fake_service_
.GetRootResourceId(),
2088 false, // shared_with_me
2089 test_util::CreateCopyResultCallback(&error
, &resource_entry
));
2090 base::RunLoop().RunUntilIdle();
2092 EXPECT_EQ(HTTP_CREATED
, error
);
2093 ASSERT_TRUE(resource_entry
);
2094 EXPECT_TRUE(resource_entry
->is_file());
2095 EXPECT_EQ(kContentType
, resource_entry
->content_mime_type());
2096 EXPECT_EQ(static_cast<int64
>(kContentData
.size()),
2097 resource_entry
->file_size());
2098 EXPECT_EQ("resource_id_1", resource_entry
->resource_id());
2099 EXPECT_EQ(kTitle
, resource_entry
->title());
2100 EXPECT_TRUE(HasParent(resource_entry
->resource_id(),
2101 fake_service_
.GetRootResourceId()));
2102 // Should be incremented as a new directory was created.
2103 EXPECT_EQ(old_largest_change_id
+ 1, fake_service_
.largest_changestamp());
2104 EXPECT_EQ(old_largest_change_id
+ 1, GetLargestChangeByAboutResource());
2105 EXPECT_EQ(base::MD5String(kContentData
), resource_entry
->file_md5());
2108 TEST_F(FakeDriveServiceTest
, AddNewFile_ToRootDirectoryOnEmptyFileSystem
) {
2109 ASSERT_TRUE(fake_service_
.LoadResourceListForWapi(
2110 "gdata/empty_feed.json"));
2111 ASSERT_TRUE(fake_service_
.LoadAccountMetadataForWapi(
2112 "gdata/account_metadata.json"));
2114 int64 old_largest_change_id
= GetLargestChangeByAboutResource();
2116 const std::string kContentType
= "text/plain";
2117 const std::string kContentData
= "This is some test content.";
2118 const std::string kTitle
= "new file";
2120 GDataErrorCode error
= GDATA_OTHER_ERROR
;
2121 scoped_ptr
<ResourceEntry
> resource_entry
;
2122 fake_service_
.AddNewFile(
2125 fake_service_
.GetRootResourceId(),
2127 false, // shared_with_me
2128 test_util::CreateCopyResultCallback(&error
, &resource_entry
));
2129 base::RunLoop().RunUntilIdle();
2131 EXPECT_EQ(HTTP_CREATED
, error
);
2132 ASSERT_TRUE(resource_entry
);
2133 EXPECT_TRUE(resource_entry
->is_file());
2134 EXPECT_EQ(kContentType
, resource_entry
->content_mime_type());
2135 EXPECT_EQ(static_cast<int64
>(kContentData
.size()),
2136 resource_entry
->file_size());
2137 EXPECT_EQ("resource_id_1", resource_entry
->resource_id());
2138 EXPECT_EQ(kTitle
, resource_entry
->title());
2139 EXPECT_TRUE(HasParent(resource_entry
->resource_id(),
2140 fake_service_
.GetRootResourceId()));
2141 // Should be incremented as a new directory was created.
2142 EXPECT_EQ(old_largest_change_id
+ 1, fake_service_
.largest_changestamp());
2143 EXPECT_EQ(old_largest_change_id
+ 1, GetLargestChangeByAboutResource());
2144 EXPECT_EQ(base::MD5String(kContentData
), resource_entry
->file_md5());
2147 TEST_F(FakeDriveServiceTest
, AddNewFile_ToNonRootDirectory
) {
2148 ASSERT_TRUE(fake_service_
.LoadResourceListForWapi(
2149 "gdata/root_feed.json"));
2150 ASSERT_TRUE(fake_service_
.LoadAccountMetadataForWapi(
2151 "gdata/account_metadata.json"));
2153 int64 old_largest_change_id
= GetLargestChangeByAboutResource();
2155 const std::string kContentType
= "text/plain";
2156 const std::string kContentData
= "This is some test content.";
2157 const std::string kTitle
= "new file";
2158 const std::string kParentResourceId
= "folder:1_folder_resource_id";
2160 GDataErrorCode error
= GDATA_OTHER_ERROR
;
2161 scoped_ptr
<ResourceEntry
> resource_entry
;
2162 fake_service_
.AddNewFile(
2167 false, // shared_with_me
2168 test_util::CreateCopyResultCallback(&error
, &resource_entry
));
2169 base::RunLoop().RunUntilIdle();
2171 EXPECT_EQ(HTTP_CREATED
, error
);
2172 ASSERT_TRUE(resource_entry
);
2173 EXPECT_TRUE(resource_entry
->is_file());
2174 EXPECT_EQ(kContentType
, resource_entry
->content_mime_type());
2175 EXPECT_EQ(static_cast<int64
>(kContentData
.size()),
2176 resource_entry
->file_size());
2177 EXPECT_EQ("resource_id_1", resource_entry
->resource_id());
2178 EXPECT_EQ(kTitle
, resource_entry
->title());
2179 EXPECT_TRUE(HasParent(resource_entry
->resource_id(), kParentResourceId
));
2180 // Should be incremented as a new directory was created.
2181 EXPECT_EQ(old_largest_change_id
+ 1, fake_service_
.largest_changestamp());
2182 EXPECT_EQ(old_largest_change_id
+ 1, GetLargestChangeByAboutResource());
2183 EXPECT_EQ(base::MD5String(kContentData
), resource_entry
->file_md5());
2186 TEST_F(FakeDriveServiceTest
, AddNewFile_ToNonexistingDirectory
) {
2187 ASSERT_TRUE(fake_service_
.LoadResourceListForWapi(
2188 "gdata/root_feed.json"));
2190 const std::string kContentType
= "text/plain";
2191 const std::string kContentData
= "This is some test content.";
2192 const std::string kTitle
= "new file";
2193 const std::string kParentResourceId
= "folder:nonexisting_resource_id";
2195 GDataErrorCode error
= GDATA_OTHER_ERROR
;
2196 scoped_ptr
<ResourceEntry
> resource_entry
;
2197 fake_service_
.AddNewFile(
2202 false, // shared_with_me
2203 test_util::CreateCopyResultCallback(&error
, &resource_entry
));
2204 base::RunLoop().RunUntilIdle();
2206 EXPECT_EQ(HTTP_NOT_FOUND
, error
);
2207 EXPECT_FALSE(resource_entry
);
2210 TEST_F(FakeDriveServiceTest
, AddNewFile_Offline
) {
2211 ASSERT_TRUE(fake_service_
.LoadResourceListForWapi(
2212 "gdata/root_feed.json"));
2213 fake_service_
.set_offline(true);
2215 const std::string kContentType
= "text/plain";
2216 const std::string kContentData
= "This is some test content.";
2217 const std::string kTitle
= "new file";
2219 GDataErrorCode error
= GDATA_OTHER_ERROR
;
2220 scoped_ptr
<ResourceEntry
> resource_entry
;
2221 fake_service_
.AddNewFile(
2224 fake_service_
.GetRootResourceId(),
2226 false, // shared_with_me
2227 test_util::CreateCopyResultCallback(&error
, &resource_entry
));
2228 base::RunLoop().RunUntilIdle();
2230 EXPECT_EQ(GDATA_NO_CONNECTION
, error
);
2231 EXPECT_FALSE(resource_entry
);
2234 TEST_F(FakeDriveServiceTest
, AddNewFile_SharedWithMeLabel
) {
2235 ASSERT_TRUE(fake_service_
.LoadResourceListForWapi(
2236 "gdata/root_feed.json"));
2237 ASSERT_TRUE(fake_service_
.LoadAccountMetadataForWapi(
2238 "gdata/account_metadata.json"));
2240 const std::string kContentType
= "text/plain";
2241 const std::string kContentData
= "This is some test content.";
2242 const std::string kTitle
= "new file";
2244 int64 old_largest_change_id
= GetLargestChangeByAboutResource();
2246 GDataErrorCode error
= GDATA_OTHER_ERROR
;
2247 scoped_ptr
<ResourceEntry
> resource_entry
;
2248 fake_service_
.AddNewFile(
2251 fake_service_
.GetRootResourceId(),
2253 true, // shared_with_me
2254 test_util::CreateCopyResultCallback(&error
, &resource_entry
));
2255 base::RunLoop().RunUntilIdle();
2257 EXPECT_EQ(HTTP_CREATED
, error
);
2258 ASSERT_TRUE(resource_entry
);
2259 EXPECT_TRUE(resource_entry
->is_file());
2260 EXPECT_EQ(kContentType
, resource_entry
->content_mime_type());
2261 EXPECT_EQ(static_cast<int64
>(kContentData
.size()),
2262 resource_entry
->file_size());
2263 EXPECT_EQ("resource_id_1", resource_entry
->resource_id());
2264 EXPECT_EQ(kTitle
, resource_entry
->title());
2265 EXPECT_TRUE(HasParent(resource_entry
->resource_id(),
2266 fake_service_
.GetRootResourceId()));
2267 ASSERT_EQ(1U, resource_entry
->labels().size());
2268 EXPECT_EQ("shared-with-me", resource_entry
->labels()[0]);
2269 // Should be incremented as a new directory was created.
2270 EXPECT_EQ(old_largest_change_id
+ 1, fake_service_
.largest_changestamp());
2271 EXPECT_EQ(old_largest_change_id
+ 1, GetLargestChangeByAboutResource());
2272 EXPECT_EQ(base::MD5String(kContentData
), resource_entry
->file_md5());
2275 TEST_F(FakeDriveServiceTest
, SetLastModifiedTime_ExistingFile
) {
2276 ASSERT_TRUE(fake_service_
.LoadResourceListForWapi(
2277 "gdata/root_feed.json"));
2279 const std::string kResourceId
= "file:2_file_resource_id";
2281 ASSERT_TRUE(base::Time::FromString("1 April 2013 12:34:56", &time
));
2283 GDataErrorCode error
= GDATA_OTHER_ERROR
;
2284 scoped_ptr
<ResourceEntry
> resource_entry
;
2285 fake_service_
.SetLastModifiedTime(
2288 test_util::CreateCopyResultCallback(&error
, &resource_entry
));
2289 base::RunLoop().RunUntilIdle();
2291 EXPECT_EQ(HTTP_SUCCESS
, error
);
2292 ASSERT_TRUE(resource_entry
);
2293 EXPECT_EQ(time
, resource_entry
->updated_time());
2296 TEST_F(FakeDriveServiceTest
, SetLastModifiedTime_NonexistingFile
) {
2297 ASSERT_TRUE(fake_service_
.LoadResourceListForWapi(
2298 "gdata/root_feed.json"));
2300 const std::string kResourceId
= "file:nonexisting_resource_id";
2302 ASSERT_TRUE(base::Time::FromString("1 April 2013 12:34:56", &time
));
2304 GDataErrorCode error
= GDATA_OTHER_ERROR
;
2305 scoped_ptr
<ResourceEntry
> resource_entry
;
2306 fake_service_
.SetLastModifiedTime(
2309 test_util::CreateCopyResultCallback(&error
, &resource_entry
));
2310 base::RunLoop().RunUntilIdle();
2312 EXPECT_EQ(HTTP_NOT_FOUND
, error
);
2313 EXPECT_FALSE(resource_entry
);
2316 TEST_F(FakeDriveServiceTest
, SetLastModifiedTime_Offline
) {
2317 ASSERT_TRUE(fake_service_
.LoadResourceListForWapi(
2318 "gdata/root_feed.json"));
2319 fake_service_
.set_offline(true);
2321 const std::string kResourceId
= "file:2_file_resource_id";
2323 ASSERT_TRUE(base::Time::FromString("1 April 2013 12:34:56", &time
));
2325 GDataErrorCode error
= GDATA_OTHER_ERROR
;
2326 scoped_ptr
<ResourceEntry
> resource_entry
;
2327 fake_service_
.SetLastModifiedTime(
2330 test_util::CreateCopyResultCallback(&error
, &resource_entry
));
2331 base::RunLoop().RunUntilIdle();
2333 EXPECT_EQ(GDATA_NO_CONNECTION
, error
);
2334 EXPECT_FALSE(resource_entry
);
2339 } // namespace drive