1 // Copyright 2013 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/chromeos/drive/sync/entry_update_performer.h"
7 #include "base/task_runner_util.h"
8 #include "chrome/browser/chromeos/drive/file_system/operation_test_base.h"
9 #include "chrome/browser/chromeos/drive/resource_metadata.h"
10 #include "chrome/browser/drive/drive_api_util.h"
11 #include "chrome/browser/drive/fake_drive_service.h"
12 #include "google_apis/drive/gdata_wapi_parser.h"
13 #include "google_apis/drive/test_util.h"
14 #include "testing/gtest/include/gtest/gtest.h"
19 class EntryUpdatePerformerTest
: public file_system::OperationTestBase
{
21 virtual void SetUp() OVERRIDE
{
22 OperationTestBase::SetUp();
23 performer_
.reset(new EntryUpdatePerformer(blocking_task_runner(),
29 scoped_ptr
<EntryUpdatePerformer
> performer_
;
32 TEST_F(EntryUpdatePerformerTest
, UpdateEntry
) {
33 base::FilePath
src_path(
34 FILE_PATH_LITERAL("drive/root/Directory 1/SubDirectory File 1.txt"));
35 base::FilePath
dest_path(
36 FILE_PATH_LITERAL("drive/root/Directory 1/Sub Directory Folder"));
38 ResourceEntry src_entry
, dest_entry
;
39 EXPECT_EQ(FILE_ERROR_OK
, GetLocalResourceEntry(src_path
, &src_entry
));
40 EXPECT_EQ(FILE_ERROR_OK
, GetLocalResourceEntry(dest_path
, &dest_entry
));
42 // Update local entry.
43 base::Time new_last_modified
= base::Time::FromInternalValue(
44 src_entry
.file_info().last_modified()) + base::TimeDelta::FromSeconds(1);
45 base::Time new_last_accessed
= base::Time::FromInternalValue(
46 src_entry
.file_info().last_accessed()) + base::TimeDelta::FromSeconds(2);
48 src_entry
.set_parent_local_id(dest_entry
.local_id());
49 src_entry
.set_title("Moved" + src_entry
.title());
50 src_entry
.mutable_file_info()->set_last_modified(
51 new_last_modified
.ToInternalValue());
52 src_entry
.mutable_file_info()->set_last_accessed(
53 new_last_accessed
.ToInternalValue());
54 src_entry
.set_metadata_edit_state(ResourceEntry::DIRTY
);
56 FileError error
= FILE_ERROR_FAILED
;
57 base::PostTaskAndReplyWithResult(
58 blocking_task_runner(),
60 base::Bind(&ResourceMetadata::RefreshEntry
,
61 base::Unretained(metadata()),
63 google_apis::test_util::CreateCopyResultCallback(&error
));
64 test_util::RunBlockingPoolTask();
65 EXPECT_EQ(FILE_ERROR_OK
, error
);
67 // Perform server side update.
68 error
= FILE_ERROR_FAILED
;
69 performer_
->UpdateEntry(
71 google_apis::test_util::CreateCopyResultCallback(&error
));
72 test_util::RunBlockingPoolTask();
73 EXPECT_EQ(FILE_ERROR_OK
, error
);
75 // Verify the file is updated on the server.
76 google_apis::GDataErrorCode gdata_error
= google_apis::GDATA_OTHER_ERROR
;
77 scoped_ptr
<google_apis::ResourceEntry
> gdata_entry
;
78 fake_service()->GetResourceEntry(
79 src_entry
.resource_id(),
80 google_apis::test_util::CreateCopyResultCallback(&gdata_error
,
82 test_util::RunBlockingPoolTask();
83 EXPECT_EQ(google_apis::HTTP_SUCCESS
, gdata_error
);
84 ASSERT_TRUE(gdata_entry
);
86 EXPECT_EQ(src_entry
.title(), gdata_entry
->title());
87 EXPECT_EQ(new_last_modified
, gdata_entry
->updated_time());
88 EXPECT_EQ(new_last_accessed
, gdata_entry
->last_viewed_time());
90 const google_apis::Link
* parent_link
=
91 gdata_entry
->GetLinkByType(google_apis::Link::LINK_PARENT
);
92 ASSERT_TRUE(parent_link
);
93 EXPECT_EQ(dest_entry
.resource_id(),
94 util::ExtractResourceIdFromUrl(parent_link
->href()));
97 TEST_F(EntryUpdatePerformerTest
, UpdateEntry_NotFound
) {
98 const std::string id
= "this ID should result in NOT_FOUND";
99 FileError error
= FILE_ERROR_FAILED
;
100 performer_
->UpdateEntry(
101 id
, google_apis::test_util::CreateCopyResultCallback(&error
));
102 test_util::RunBlockingPoolTask();
103 EXPECT_EQ(FILE_ERROR_NOT_FOUND
, error
);
106 } // namespace internal