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 "components/drive/file_system/open_file_operation.h" | 5 #include "components/drive/file_system/open_file_operation.h" |
6 | 6 |
| 7 #include <stdint.h> |
| 8 |
7 #include <map> | 9 #include <map> |
8 | 10 |
9 #include "base/files/file_path.h" | 11 #include "base/files/file_path.h" |
10 #include "base/files/file_util.h" | 12 #include "base/files/file_util.h" |
11 #include "base/memory/scoped_ptr.h" | 13 #include "base/memory/scoped_ptr.h" |
12 #include "base/task_runner_util.h" | 14 #include "base/task_runner_util.h" |
13 #include "components/drive/drive.pb.h" | 15 #include "components/drive/drive.pb.h" |
14 #include "components/drive/file_cache.h" | 16 #include "components/drive/file_cache.h" |
15 #include "components/drive/file_change.h" | 17 #include "components/drive/file_change.h" |
16 #include "components/drive/file_errors.h" | 18 #include "components/drive/file_errors.h" |
(...skipping 16 matching lines...) Expand all Loading... |
33 } | 35 } |
34 | 36 |
35 scoped_ptr<OpenFileOperation> operation_; | 37 scoped_ptr<OpenFileOperation> operation_; |
36 }; | 38 }; |
37 | 39 |
38 TEST_F(OpenFileOperationTest, OpenExistingFile) { | 40 TEST_F(OpenFileOperationTest, OpenExistingFile) { |
39 const base::FilePath file_in_root( | 41 const base::FilePath file_in_root( |
40 FILE_PATH_LITERAL("drive/root/File 1.txt")); | 42 FILE_PATH_LITERAL("drive/root/File 1.txt")); |
41 ResourceEntry src_entry; | 43 ResourceEntry src_entry; |
42 ASSERT_EQ(FILE_ERROR_OK, GetLocalResourceEntry(file_in_root, &src_entry)); | 44 ASSERT_EQ(FILE_ERROR_OK, GetLocalResourceEntry(file_in_root, &src_entry)); |
43 const int64 file_size = src_entry.file_info().size(); | 45 const int64_t file_size = src_entry.file_info().size(); |
44 | 46 |
45 FileError error = FILE_ERROR_FAILED; | 47 FileError error = FILE_ERROR_FAILED; |
46 base::FilePath file_path; | 48 base::FilePath file_path; |
47 base::Closure close_callback; | 49 base::Closure close_callback; |
48 operation_->OpenFile( | 50 operation_->OpenFile( |
49 file_in_root, | 51 file_in_root, |
50 OPEN_FILE, | 52 OPEN_FILE, |
51 std::string(), // mime_type | 53 std::string(), // mime_type |
52 google_apis::test_util::CreateCopyResultCallback( | 54 google_apis::test_util::CreateCopyResultCallback( |
53 &error, &file_path, &close_callback)); | 55 &error, &file_path, &close_callback)); |
54 content::RunAllBlockingPoolTasksUntilIdle(); | 56 content::RunAllBlockingPoolTasksUntilIdle(); |
55 | 57 |
56 EXPECT_EQ(FILE_ERROR_OK, error); | 58 EXPECT_EQ(FILE_ERROR_OK, error); |
57 ASSERT_TRUE(base::PathExists(file_path)); | 59 ASSERT_TRUE(base::PathExists(file_path)); |
58 int64 local_file_size; | 60 int64_t local_file_size; |
59 ASSERT_TRUE(base::GetFileSize(file_path, &local_file_size)); | 61 ASSERT_TRUE(base::GetFileSize(file_path, &local_file_size)); |
60 EXPECT_EQ(file_size, local_file_size); | 62 EXPECT_EQ(file_size, local_file_size); |
61 | 63 |
62 ASSERT_FALSE(close_callback.is_null()); | 64 ASSERT_FALSE(close_callback.is_null()); |
63 close_callback.Run(); | 65 close_callback.Run(); |
64 EXPECT_EQ(1U, delegate()->updated_local_ids().count(src_entry.local_id())); | 66 EXPECT_EQ(1U, delegate()->updated_local_ids().count(src_entry.local_id())); |
65 } | 67 } |
66 | 68 |
67 TEST_F(OpenFileOperationTest, OpenNonExistingFile) { | 69 TEST_F(OpenFileOperationTest, OpenNonExistingFile) { |
68 const base::FilePath file_in_root( | 70 const base::FilePath file_in_root( |
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
116 std::string(), // mime_type | 118 std::string(), // mime_type |
117 google_apis::test_util::CreateCopyResultCallback( | 119 google_apis::test_util::CreateCopyResultCallback( |
118 &error, &file_path, &close_callback)); | 120 &error, &file_path, &close_callback)); |
119 content::RunAllBlockingPoolTasksUntilIdle(); | 121 content::RunAllBlockingPoolTasksUntilIdle(); |
120 | 122 |
121 EXPECT_EQ(1U, delegate()->get_changed_files().size()); | 123 EXPECT_EQ(1U, delegate()->get_changed_files().size()); |
122 EXPECT_TRUE(delegate()->get_changed_files().count(file_in_root)); | 124 EXPECT_TRUE(delegate()->get_changed_files().count(file_in_root)); |
123 | 125 |
124 EXPECT_EQ(FILE_ERROR_OK, error); | 126 EXPECT_EQ(FILE_ERROR_OK, error); |
125 ASSERT_TRUE(base::PathExists(file_path)); | 127 ASSERT_TRUE(base::PathExists(file_path)); |
126 int64 local_file_size; | 128 int64_t local_file_size; |
127 ASSERT_TRUE(base::GetFileSize(file_path, &local_file_size)); | 129 ASSERT_TRUE(base::GetFileSize(file_path, &local_file_size)); |
128 EXPECT_EQ(0, local_file_size); // Should be an empty file. | 130 EXPECT_EQ(0, local_file_size); // Should be an empty file. |
129 | 131 |
130 ASSERT_FALSE(close_callback.is_null()); | 132 ASSERT_FALSE(close_callback.is_null()); |
131 close_callback.Run(); | 133 close_callback.Run(); |
132 EXPECT_EQ(1U, | 134 EXPECT_EQ(1U, |
133 delegate()->updated_local_ids().count(GetLocalId(file_in_root))); | 135 delegate()->updated_local_ids().count(GetLocalId(file_in_root))); |
134 } | 136 } |
135 | 137 |
136 TEST_F(OpenFileOperationTest, OpenOrCreateExistingFile) { | 138 TEST_F(OpenFileOperationTest, OpenOrCreateExistingFile) { |
137 const base::FilePath file_in_root( | 139 const base::FilePath file_in_root( |
138 FILE_PATH_LITERAL("drive/root/File 1.txt")); | 140 FILE_PATH_LITERAL("drive/root/File 1.txt")); |
139 ResourceEntry src_entry; | 141 ResourceEntry src_entry; |
140 ASSERT_EQ(FILE_ERROR_OK, GetLocalResourceEntry(file_in_root, &src_entry)); | 142 ASSERT_EQ(FILE_ERROR_OK, GetLocalResourceEntry(file_in_root, &src_entry)); |
141 const int64 file_size = src_entry.file_info().size(); | 143 const int64_t file_size = src_entry.file_info().size(); |
142 | 144 |
143 FileError error = FILE_ERROR_FAILED; | 145 FileError error = FILE_ERROR_FAILED; |
144 base::FilePath file_path; | 146 base::FilePath file_path; |
145 base::Closure close_callback; | 147 base::Closure close_callback; |
146 operation_->OpenFile( | 148 operation_->OpenFile( |
147 file_in_root, | 149 file_in_root, |
148 OPEN_OR_CREATE_FILE, | 150 OPEN_OR_CREATE_FILE, |
149 std::string(), // mime_type | 151 std::string(), // mime_type |
150 google_apis::test_util::CreateCopyResultCallback( | 152 google_apis::test_util::CreateCopyResultCallback( |
151 &error, &file_path, &close_callback)); | 153 &error, &file_path, &close_callback)); |
152 content::RunAllBlockingPoolTasksUntilIdle(); | 154 content::RunAllBlockingPoolTasksUntilIdle(); |
153 | 155 |
154 // Notified because 'available offline' status of the existing file changes. | 156 // Notified because 'available offline' status of the existing file changes. |
155 EXPECT_EQ(1U, delegate()->get_changed_files().size()); | 157 EXPECT_EQ(1U, delegate()->get_changed_files().size()); |
156 EXPECT_TRUE(delegate()->get_changed_files().count(file_in_root)); | 158 EXPECT_TRUE(delegate()->get_changed_files().count(file_in_root)); |
157 | 159 |
158 EXPECT_EQ(FILE_ERROR_OK, error); | 160 EXPECT_EQ(FILE_ERROR_OK, error); |
159 ASSERT_TRUE(base::PathExists(file_path)); | 161 ASSERT_TRUE(base::PathExists(file_path)); |
160 int64 local_file_size; | 162 int64_t local_file_size; |
161 ASSERT_TRUE(base::GetFileSize(file_path, &local_file_size)); | 163 ASSERT_TRUE(base::GetFileSize(file_path, &local_file_size)); |
162 EXPECT_EQ(file_size, local_file_size); | 164 EXPECT_EQ(file_size, local_file_size); |
163 | 165 |
164 ASSERT_FALSE(close_callback.is_null()); | 166 ASSERT_FALSE(close_callback.is_null()); |
165 close_callback.Run(); | 167 close_callback.Run(); |
166 EXPECT_EQ(1U, delegate()->updated_local_ids().count(src_entry.local_id())); | 168 EXPECT_EQ(1U, delegate()->updated_local_ids().count(src_entry.local_id())); |
167 | 169 |
168 ResourceEntry result_entry; | 170 ResourceEntry result_entry; |
169 EXPECT_EQ(FILE_ERROR_OK, GetLocalResourceEntry(file_in_root, &result_entry)); | 171 EXPECT_EQ(FILE_ERROR_OK, GetLocalResourceEntry(file_in_root, &result_entry)); |
170 EXPECT_TRUE(result_entry.file_specific_info().cache_state().is_present()); | 172 EXPECT_TRUE(result_entry.file_specific_info().cache_state().is_present()); |
(...skipping 10 matching lines...) Expand all Loading... |
181 operation_->OpenFile( | 183 operation_->OpenFile( |
182 file_in_root, | 184 file_in_root, |
183 OPEN_OR_CREATE_FILE, | 185 OPEN_OR_CREATE_FILE, |
184 std::string(), // mime_type | 186 std::string(), // mime_type |
185 google_apis::test_util::CreateCopyResultCallback( | 187 google_apis::test_util::CreateCopyResultCallback( |
186 &error, &file_path, &close_callback)); | 188 &error, &file_path, &close_callback)); |
187 content::RunAllBlockingPoolTasksUntilIdle(); | 189 content::RunAllBlockingPoolTasksUntilIdle(); |
188 | 190 |
189 EXPECT_EQ(FILE_ERROR_OK, error); | 191 EXPECT_EQ(FILE_ERROR_OK, error); |
190 ASSERT_TRUE(base::PathExists(file_path)); | 192 ASSERT_TRUE(base::PathExists(file_path)); |
191 int64 local_file_size; | 193 int64_t local_file_size; |
192 ASSERT_TRUE(base::GetFileSize(file_path, &local_file_size)); | 194 ASSERT_TRUE(base::GetFileSize(file_path, &local_file_size)); |
193 EXPECT_EQ(0, local_file_size); // Should be an empty file. | 195 EXPECT_EQ(0, local_file_size); // Should be an empty file. |
194 | 196 |
195 ASSERT_FALSE(close_callback.is_null()); | 197 ASSERT_FALSE(close_callback.is_null()); |
196 close_callback.Run(); | 198 close_callback.Run(); |
197 EXPECT_EQ(1U, | 199 EXPECT_EQ(1U, |
198 delegate()->updated_local_ids().count(GetLocalId(file_in_root))); | 200 delegate()->updated_local_ids().count(GetLocalId(file_in_root))); |
199 } | 201 } |
200 | 202 |
201 TEST_F(OpenFileOperationTest, OpenFileTwice) { | 203 TEST_F(OpenFileOperationTest, OpenFileTwice) { |
202 const base::FilePath file_in_root( | 204 const base::FilePath file_in_root( |
203 FILE_PATH_LITERAL("drive/root/File 1.txt")); | 205 FILE_PATH_LITERAL("drive/root/File 1.txt")); |
204 ResourceEntry src_entry; | 206 ResourceEntry src_entry; |
205 ASSERT_EQ(FILE_ERROR_OK, GetLocalResourceEntry(file_in_root, &src_entry)); | 207 ASSERT_EQ(FILE_ERROR_OK, GetLocalResourceEntry(file_in_root, &src_entry)); |
206 const int64 file_size = src_entry.file_info().size(); | 208 const int64_t file_size = src_entry.file_info().size(); |
207 | 209 |
208 FileError error = FILE_ERROR_FAILED; | 210 FileError error = FILE_ERROR_FAILED; |
209 base::FilePath file_path; | 211 base::FilePath file_path; |
210 base::Closure close_callback; | 212 base::Closure close_callback; |
211 operation_->OpenFile( | 213 operation_->OpenFile( |
212 file_in_root, | 214 file_in_root, |
213 OPEN_FILE, | 215 OPEN_FILE, |
214 std::string(), // mime_type | 216 std::string(), // mime_type |
215 google_apis::test_util::CreateCopyResultCallback( | 217 google_apis::test_util::CreateCopyResultCallback( |
216 &error, &file_path, &close_callback)); | 218 &error, &file_path, &close_callback)); |
217 content::RunAllBlockingPoolTasksUntilIdle(); | 219 content::RunAllBlockingPoolTasksUntilIdle(); |
218 | 220 |
219 EXPECT_EQ(FILE_ERROR_OK, error); | 221 EXPECT_EQ(FILE_ERROR_OK, error); |
220 ASSERT_TRUE(base::PathExists(file_path)); | 222 ASSERT_TRUE(base::PathExists(file_path)); |
221 int64 local_file_size; | 223 int64_t local_file_size; |
222 ASSERT_TRUE(base::GetFileSize(file_path, &local_file_size)); | 224 ASSERT_TRUE(base::GetFileSize(file_path, &local_file_size)); |
223 EXPECT_EQ(file_size, local_file_size); | 225 EXPECT_EQ(file_size, local_file_size); |
224 | 226 |
225 // Open again. | 227 // Open again. |
226 error = FILE_ERROR_FAILED; | 228 error = FILE_ERROR_FAILED; |
227 base::Closure close_callback2; | 229 base::Closure close_callback2; |
228 operation_->OpenFile( | 230 operation_->OpenFile( |
229 file_in_root, | 231 file_in_root, |
230 OPEN_FILE, | 232 OPEN_FILE, |
231 std::string(), // mime_type | 233 std::string(), // mime_type |
(...skipping 16 matching lines...) Expand all Loading... |
248 EXPECT_TRUE(delegate()->updated_local_ids().empty()); | 250 EXPECT_TRUE(delegate()->updated_local_ids().empty()); |
249 | 251 |
250 close_callback2.Run(); | 252 close_callback2.Run(); |
251 | 253 |
252 // Here, all the clients close the file, so it should be uploaded then. | 254 // Here, all the clients close the file, so it should be uploaded then. |
253 EXPECT_EQ(1U, delegate()->updated_local_ids().count(src_entry.local_id())); | 255 EXPECT_EQ(1U, delegate()->updated_local_ids().count(src_entry.local_id())); |
254 } | 256 } |
255 | 257 |
256 } // namespace file_system | 258 } // namespace file_system |
257 } // namespace drive | 259 } // namespace drive |
OLD | NEW |