OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "chrome/browser/chromeos/drive/file_system/open_file_operation.h" | 5 #include "chrome/browser/chromeos/drive/file_system/open_file_operation.h" |
6 | 6 |
7 #include <map> | 7 #include <map> |
8 | 8 |
9 #include "base/file_util.h" | 9 #include "base/file_util.h" |
10 #include "base/files/file_path.h" | 10 #include "base/files/file_path.h" |
(...skipping 10 matching lines...) Expand all Loading... |
21 | 21 |
22 namespace drive { | 22 namespace drive { |
23 namespace file_system { | 23 namespace file_system { |
24 | 24 |
25 class OpenFileOperationTest : public OperationTestBase { | 25 class OpenFileOperationTest : public OperationTestBase { |
26 protected: | 26 protected: |
27 virtual void SetUp() OVERRIDE { | 27 virtual void SetUp() OVERRIDE { |
28 OperationTestBase::SetUp(); | 28 OperationTestBase::SetUp(); |
29 | 29 |
30 operation_.reset(new OpenFileOperation( | 30 operation_.reset(new OpenFileOperation( |
31 blocking_task_runner(), observer(), scheduler(), metadata(), cache(), | 31 blocking_task_runner(), delegate(), scheduler(), metadata(), cache(), |
32 temp_dir())); | 32 temp_dir())); |
33 } | 33 } |
34 | 34 |
35 scoped_ptr<OpenFileOperation> operation_; | 35 scoped_ptr<OpenFileOperation> operation_; |
36 }; | 36 }; |
37 | 37 |
38 TEST_F(OpenFileOperationTest, OpenExistingFile) { | 38 TEST_F(OpenFileOperationTest, OpenExistingFile) { |
39 const base::FilePath file_in_root( | 39 const base::FilePath file_in_root( |
40 FILE_PATH_LITERAL("drive/root/File 1.txt")); | 40 FILE_PATH_LITERAL("drive/root/File 1.txt")); |
41 ResourceEntry src_entry; | 41 ResourceEntry src_entry; |
(...skipping 12 matching lines...) Expand all Loading... |
54 content::RunAllBlockingPoolTasksUntilIdle(); | 54 content::RunAllBlockingPoolTasksUntilIdle(); |
55 | 55 |
56 EXPECT_EQ(FILE_ERROR_OK, error); | 56 EXPECT_EQ(FILE_ERROR_OK, error); |
57 ASSERT_TRUE(base::PathExists(file_path)); | 57 ASSERT_TRUE(base::PathExists(file_path)); |
58 int64 local_file_size; | 58 int64 local_file_size; |
59 ASSERT_TRUE(base::GetFileSize(file_path, &local_file_size)); | 59 ASSERT_TRUE(base::GetFileSize(file_path, &local_file_size)); |
60 EXPECT_EQ(file_size, local_file_size); | 60 EXPECT_EQ(file_size, local_file_size); |
61 | 61 |
62 ASSERT_FALSE(close_callback.is_null()); | 62 ASSERT_FALSE(close_callback.is_null()); |
63 close_callback.Run(); | 63 close_callback.Run(); |
64 EXPECT_EQ(1U, observer()->updated_local_ids().count(src_entry.local_id())); | 64 EXPECT_EQ(1U, delegate()->updated_local_ids().count(src_entry.local_id())); |
65 } | 65 } |
66 | 66 |
67 TEST_F(OpenFileOperationTest, OpenNonExistingFile) { | 67 TEST_F(OpenFileOperationTest, OpenNonExistingFile) { |
68 const base::FilePath file_in_root( | 68 const base::FilePath file_in_root( |
69 FILE_PATH_LITERAL("drive/root/not-exist.txt")); | 69 FILE_PATH_LITERAL("drive/root/not-exist.txt")); |
70 | 70 |
71 FileError error = FILE_ERROR_FAILED; | 71 FileError error = FILE_ERROR_FAILED; |
72 base::FilePath file_path; | 72 base::FilePath file_path; |
73 base::Closure close_callback; | 73 base::Closure close_callback; |
74 operation_->OpenFile( | 74 operation_->OpenFile( |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
111 base::FilePath file_path; | 111 base::FilePath file_path; |
112 base::Closure close_callback; | 112 base::Closure close_callback; |
113 operation_->OpenFile( | 113 operation_->OpenFile( |
114 file_in_root, | 114 file_in_root, |
115 CREATE_FILE, | 115 CREATE_FILE, |
116 std::string(), // mime_type | 116 std::string(), // mime_type |
117 google_apis::test_util::CreateCopyResultCallback( | 117 google_apis::test_util::CreateCopyResultCallback( |
118 &error, &file_path, &close_callback)); | 118 &error, &file_path, &close_callback)); |
119 content::RunAllBlockingPoolTasksUntilIdle(); | 119 content::RunAllBlockingPoolTasksUntilIdle(); |
120 | 120 |
121 EXPECT_EQ(1U, observer()->get_changed_files().size()); | 121 EXPECT_EQ(1U, delegate()->get_changed_files().size()); |
122 EXPECT_TRUE(observer()->get_changed_files().count(file_in_root)); | 122 EXPECT_TRUE(delegate()->get_changed_files().count(file_in_root)); |
123 | 123 |
124 EXPECT_EQ(FILE_ERROR_OK, error); | 124 EXPECT_EQ(FILE_ERROR_OK, error); |
125 ASSERT_TRUE(base::PathExists(file_path)); | 125 ASSERT_TRUE(base::PathExists(file_path)); |
126 int64 local_file_size; | 126 int64 local_file_size; |
127 ASSERT_TRUE(base::GetFileSize(file_path, &local_file_size)); | 127 ASSERT_TRUE(base::GetFileSize(file_path, &local_file_size)); |
128 EXPECT_EQ(0, local_file_size); // Should be an empty file. | 128 EXPECT_EQ(0, local_file_size); // Should be an empty file. |
129 | 129 |
130 ASSERT_FALSE(close_callback.is_null()); | 130 ASSERT_FALSE(close_callback.is_null()); |
131 close_callback.Run(); | 131 close_callback.Run(); |
132 EXPECT_EQ(1U, | 132 EXPECT_EQ(1U, |
133 observer()->updated_local_ids().count(GetLocalId(file_in_root))); | 133 delegate()->updated_local_ids().count(GetLocalId(file_in_root))); |
134 } | 134 } |
135 | 135 |
136 TEST_F(OpenFileOperationTest, OpenOrCreateExistingFile) { | 136 TEST_F(OpenFileOperationTest, OpenOrCreateExistingFile) { |
137 const base::FilePath file_in_root( | 137 const base::FilePath file_in_root( |
138 FILE_PATH_LITERAL("drive/root/File 1.txt")); | 138 FILE_PATH_LITERAL("drive/root/File 1.txt")); |
139 ResourceEntry src_entry; | 139 ResourceEntry src_entry; |
140 ASSERT_EQ(FILE_ERROR_OK, GetLocalResourceEntry(file_in_root, &src_entry)); | 140 ASSERT_EQ(FILE_ERROR_OK, GetLocalResourceEntry(file_in_root, &src_entry)); |
141 const int64 file_size = src_entry.file_info().size(); | 141 const int64 file_size = src_entry.file_info().size(); |
142 | 142 |
143 FileError error = FILE_ERROR_FAILED; | 143 FileError error = FILE_ERROR_FAILED; |
144 base::FilePath file_path; | 144 base::FilePath file_path; |
145 base::Closure close_callback; | 145 base::Closure close_callback; |
146 operation_->OpenFile( | 146 operation_->OpenFile( |
147 file_in_root, | 147 file_in_root, |
148 OPEN_OR_CREATE_FILE, | 148 OPEN_OR_CREATE_FILE, |
149 std::string(), // mime_type | 149 std::string(), // mime_type |
150 google_apis::test_util::CreateCopyResultCallback( | 150 google_apis::test_util::CreateCopyResultCallback( |
151 &error, &file_path, &close_callback)); | 151 &error, &file_path, &close_callback)); |
152 content::RunAllBlockingPoolTasksUntilIdle(); | 152 content::RunAllBlockingPoolTasksUntilIdle(); |
153 | 153 |
154 // Notified because 'available offline' status of the existing file changes. | 154 // Notified because 'available offline' status of the existing file changes. |
155 EXPECT_EQ(1U, observer()->get_changed_files().size()); | 155 EXPECT_EQ(1U, delegate()->get_changed_files().size()); |
156 EXPECT_TRUE(observer()->get_changed_files().count(file_in_root)); | 156 EXPECT_TRUE(delegate()->get_changed_files().count(file_in_root)); |
157 | 157 |
158 EXPECT_EQ(FILE_ERROR_OK, error); | 158 EXPECT_EQ(FILE_ERROR_OK, error); |
159 ASSERT_TRUE(base::PathExists(file_path)); | 159 ASSERT_TRUE(base::PathExists(file_path)); |
160 int64 local_file_size; | 160 int64 local_file_size; |
161 ASSERT_TRUE(base::GetFileSize(file_path, &local_file_size)); | 161 ASSERT_TRUE(base::GetFileSize(file_path, &local_file_size)); |
162 EXPECT_EQ(file_size, local_file_size); | 162 EXPECT_EQ(file_size, local_file_size); |
163 | 163 |
164 ASSERT_FALSE(close_callback.is_null()); | 164 ASSERT_FALSE(close_callback.is_null()); |
165 close_callback.Run(); | 165 close_callback.Run(); |
166 EXPECT_EQ(1U, observer()->updated_local_ids().count(src_entry.local_id())); | 166 EXPECT_EQ(1U, delegate()->updated_local_ids().count(src_entry.local_id())); |
167 | 167 |
168 ResourceEntry result_entry; | 168 ResourceEntry result_entry; |
169 EXPECT_EQ(FILE_ERROR_OK, GetLocalResourceEntry(file_in_root, &result_entry)); | 169 EXPECT_EQ(FILE_ERROR_OK, GetLocalResourceEntry(file_in_root, &result_entry)); |
170 EXPECT_TRUE(result_entry.file_specific_info().cache_state().is_present()); | 170 EXPECT_TRUE(result_entry.file_specific_info().cache_state().is_present()); |
171 EXPECT_TRUE(result_entry.file_specific_info().cache_state().is_dirty()); | 171 EXPECT_TRUE(result_entry.file_specific_info().cache_state().is_dirty()); |
172 } | 172 } |
173 | 173 |
174 TEST_F(OpenFileOperationTest, OpenOrCreateNonExistingFile) { | 174 TEST_F(OpenFileOperationTest, OpenOrCreateNonExistingFile) { |
175 const base::FilePath file_in_root( | 175 const base::FilePath file_in_root( |
176 FILE_PATH_LITERAL("drive/root/not-exist.txt")); | 176 FILE_PATH_LITERAL("drive/root/not-exist.txt")); |
(...skipping 11 matching lines...) Expand all Loading... |
188 | 188 |
189 EXPECT_EQ(FILE_ERROR_OK, error); | 189 EXPECT_EQ(FILE_ERROR_OK, error); |
190 ASSERT_TRUE(base::PathExists(file_path)); | 190 ASSERT_TRUE(base::PathExists(file_path)); |
191 int64 local_file_size; | 191 int64 local_file_size; |
192 ASSERT_TRUE(base::GetFileSize(file_path, &local_file_size)); | 192 ASSERT_TRUE(base::GetFileSize(file_path, &local_file_size)); |
193 EXPECT_EQ(0, local_file_size); // Should be an empty file. | 193 EXPECT_EQ(0, local_file_size); // Should be an empty file. |
194 | 194 |
195 ASSERT_FALSE(close_callback.is_null()); | 195 ASSERT_FALSE(close_callback.is_null()); |
196 close_callback.Run(); | 196 close_callback.Run(); |
197 EXPECT_EQ(1U, | 197 EXPECT_EQ(1U, |
198 observer()->updated_local_ids().count(GetLocalId(file_in_root))); | 198 delegate()->updated_local_ids().count(GetLocalId(file_in_root))); |
199 } | 199 } |
200 | 200 |
201 TEST_F(OpenFileOperationTest, OpenFileTwice) { | 201 TEST_F(OpenFileOperationTest, OpenFileTwice) { |
202 const base::FilePath file_in_root( | 202 const base::FilePath file_in_root( |
203 FILE_PATH_LITERAL("drive/root/File 1.txt")); | 203 FILE_PATH_LITERAL("drive/root/File 1.txt")); |
204 ResourceEntry src_entry; | 204 ResourceEntry src_entry; |
205 ASSERT_EQ(FILE_ERROR_OK, GetLocalResourceEntry(file_in_root, &src_entry)); | 205 ASSERT_EQ(FILE_ERROR_OK, GetLocalResourceEntry(file_in_root, &src_entry)); |
206 const int64 file_size = src_entry.file_info().size(); | 206 const int64 file_size = src_entry.file_info().size(); |
207 | 207 |
208 FileError error = FILE_ERROR_FAILED; | 208 FileError error = FILE_ERROR_FAILED; |
(...skipping 29 matching lines...) Expand all Loading... |
238 ASSERT_TRUE(base::GetFileSize(file_path, &local_file_size)); | 238 ASSERT_TRUE(base::GetFileSize(file_path, &local_file_size)); |
239 EXPECT_EQ(file_size, local_file_size); | 239 EXPECT_EQ(file_size, local_file_size); |
240 | 240 |
241 ASSERT_FALSE(close_callback.is_null()); | 241 ASSERT_FALSE(close_callback.is_null()); |
242 ASSERT_FALSE(close_callback2.is_null()); | 242 ASSERT_FALSE(close_callback2.is_null()); |
243 | 243 |
244 close_callback.Run(); | 244 close_callback.Run(); |
245 | 245 |
246 // There still remains a client opening the file, so it shouldn't be | 246 // There still remains a client opening the file, so it shouldn't be |
247 // uploaded yet. | 247 // uploaded yet. |
248 EXPECT_TRUE(observer()->updated_local_ids().empty()); | 248 EXPECT_TRUE(delegate()->updated_local_ids().empty()); |
249 | 249 |
250 close_callback2.Run(); | 250 close_callback2.Run(); |
251 | 251 |
252 // Here, all the clients close the file, so it should be uploaded then. | 252 // Here, all the clients close the file, so it should be uploaded then. |
253 EXPECT_EQ(1U, observer()->updated_local_ids().count(src_entry.local_id())); | 253 EXPECT_EQ(1U, delegate()->updated_local_ids().count(src_entry.local_id())); |
254 } | 254 } |
255 | 255 |
256 } // namespace file_system | 256 } // namespace file_system |
257 } // namespace drive | 257 } // namespace drive |
OLD | NEW |