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/file_system/move_operation.h"
7 #include "chrome/browser/chromeos/drive/file_system/operation_test_base.h"
8 #include "components/drive/file_change.h"
9 #include "content/public/test/test_utils.h"
10 #include "google_apis/drive/test_util.h"
11 #include "testing/gtest/include/gtest/gtest.h"
14 namespace file_system
{
16 class MoveOperationTest
: public OperationTestBase
{
18 void SetUp() override
{
19 OperationTestBase::SetUp();
20 operation_
.reset(new MoveOperation(blocking_task_runner(),
25 scoped_ptr
<MoveOperation
> operation_
;
28 TEST_F(MoveOperationTest
, MoveFileInSameDirectory
) {
29 const base::FilePath
src_path(
30 FILE_PATH_LITERAL("drive/root/Directory 1/SubDirectory File 1.txt"));
31 const base::FilePath
dest_path(
32 FILE_PATH_LITERAL("drive/root/Directory 1/Test.log"));
34 ResourceEntry src_entry
, dest_entry
;
35 ASSERT_EQ(FILE_ERROR_OK
, GetLocalResourceEntry(src_path
, &src_entry
));
36 ASSERT_EQ(FILE_ERROR_NOT_FOUND
,
37 GetLocalResourceEntry(dest_path
, &dest_entry
));
39 FileError error
= FILE_ERROR_FAILED
;
40 operation_
->Move(src_path
,
42 google_apis::test_util::CreateCopyResultCallback(&error
));
43 content::RunAllBlockingPoolTasksUntilIdle();
44 EXPECT_EQ(FILE_ERROR_OK
, error
);
46 EXPECT_EQ(FILE_ERROR_OK
, GetLocalResourceEntry(dest_path
, &dest_entry
));
47 EXPECT_EQ(src_entry
.local_id(), dest_entry
.local_id());
48 EXPECT_EQ(ResourceEntry::DIRTY
, dest_entry
.metadata_edit_state());
49 EXPECT_EQ(FILE_ERROR_NOT_FOUND
, GetLocalResourceEntry(src_path
, &src_entry
));
51 EXPECT_EQ(2U, delegate()->get_changed_files().size());
52 EXPECT_TRUE(delegate()->get_changed_files().count(src_path
));
53 EXPECT_TRUE(delegate()->get_changed_files().count(dest_path
));
55 EXPECT_EQ(1U, delegate()->updated_local_ids().size());
56 EXPECT_TRUE(delegate()->updated_local_ids().count(src_entry
.local_id()));
59 TEST_F(MoveOperationTest
, MoveFileFromRootToSubDirectory
) {
60 base::FilePath
src_path(FILE_PATH_LITERAL("drive/root/File 1.txt"));
61 base::FilePath
dest_path(
62 FILE_PATH_LITERAL("drive/root/Directory 1/Test.log"));
64 ResourceEntry src_entry
, dest_entry
;
65 ASSERT_EQ(FILE_ERROR_OK
, GetLocalResourceEntry(src_path
, &src_entry
));
66 ASSERT_EQ(FILE_ERROR_NOT_FOUND
,
67 GetLocalResourceEntry(dest_path
, &dest_entry
));
69 FileError error
= FILE_ERROR_FAILED
;
70 operation_
->Move(src_path
,
72 google_apis::test_util::CreateCopyResultCallback(&error
));
73 content::RunAllBlockingPoolTasksUntilIdle();
74 EXPECT_EQ(FILE_ERROR_OK
, error
);
76 EXPECT_EQ(FILE_ERROR_OK
, GetLocalResourceEntry(dest_path
, &dest_entry
));
77 EXPECT_EQ(src_entry
.local_id(), dest_entry
.local_id());
78 EXPECT_EQ(ResourceEntry::DIRTY
, dest_entry
.metadata_edit_state());
79 EXPECT_EQ(FILE_ERROR_NOT_FOUND
, GetLocalResourceEntry(src_path
, &src_entry
));
81 EXPECT_EQ(2U, delegate()->get_changed_files().size());
82 EXPECT_TRUE(delegate()->get_changed_files().count(src_path
));
83 EXPECT_TRUE(delegate()->get_changed_files().count(dest_path
));
85 EXPECT_EQ(1U, delegate()->updated_local_ids().size());
86 EXPECT_TRUE(delegate()->updated_local_ids().count(src_entry
.local_id()));
89 TEST_F(MoveOperationTest
, MoveNotExistingFile
) {
90 base::FilePath
src_path(FILE_PATH_LITERAL("drive/root/Dummy file.txt"));
91 base::FilePath
dest_path(FILE_PATH_LITERAL("drive/root/Test.log"));
93 FileError error
= FILE_ERROR_OK
;
94 operation_
->Move(src_path
,
96 google_apis::test_util::CreateCopyResultCallback(&error
));
97 content::RunAllBlockingPoolTasksUntilIdle();
98 EXPECT_EQ(FILE_ERROR_NOT_FOUND
, error
);
101 EXPECT_EQ(FILE_ERROR_NOT_FOUND
, GetLocalResourceEntry(src_path
, &entry
));
102 EXPECT_EQ(FILE_ERROR_NOT_FOUND
, GetLocalResourceEntry(dest_path
, &entry
));
105 TEST_F(MoveOperationTest
, MoveFileToNonExistingDirectory
) {
106 base::FilePath
src_path(FILE_PATH_LITERAL("drive/root/File 1.txt"));
107 base::FilePath
dest_path(FILE_PATH_LITERAL("drive/root/Dummy/Test.log"));
109 FileError error
= FILE_ERROR_OK
;
110 operation_
->Move(src_path
,
112 google_apis::test_util::CreateCopyResultCallback(&error
));
113 content::RunAllBlockingPoolTasksUntilIdle();
114 EXPECT_EQ(FILE_ERROR_NOT_FOUND
, error
);
117 EXPECT_EQ(FILE_ERROR_OK
, GetLocalResourceEntry(src_path
, &entry
));
118 EXPECT_EQ(FILE_ERROR_NOT_FOUND
, GetLocalResourceEntry(dest_path
, &entry
));
121 // Test the case where the parent of |dest_file_path| is a existing file,
123 TEST_F(MoveOperationTest
, MoveFileToInvalidPath
) {
124 base::FilePath
src_path(FILE_PATH_LITERAL("drive/root/File 1.txt"));
125 base::FilePath
dest_path(
126 FILE_PATH_LITERAL("drive/root/Duplicate Name.txt/Test.log"));
128 FileError error
= FILE_ERROR_OK
;
129 operation_
->Move(src_path
,
131 google_apis::test_util::CreateCopyResultCallback(&error
));
132 content::RunAllBlockingPoolTasksUntilIdle();
133 EXPECT_EQ(FILE_ERROR_NOT_A_DIRECTORY
, error
);
136 EXPECT_EQ(FILE_ERROR_OK
, GetLocalResourceEntry(src_path
, &entry
));
137 EXPECT_EQ(FILE_ERROR_NOT_FOUND
, GetLocalResourceEntry(dest_path
, &entry
));
140 } // namespace file_system