Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(159)

Side by Side Diff: content/browser/fileapi/recursive_operation_delegate_unittest.cc

Issue 145303002: Convert Media Galleries to use base::File (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Rebase Created 6 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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 "webkit/browser/fileapi/recursive_operation_delegate.h" 5 #include "webkit/browser/fileapi/recursive_operation_delegate.h"
6 6
7 #include <vector> 7 #include <vector>
8 8
9 #include "base/basictypes.h" 9 #include "base/basictypes.h"
10 #include "base/bind.h" 10 #include "base/bind.h"
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
64 RecordLogEntry(LogEntry::PROCESS_FILE, url); 64 RecordLogEntry(LogEntry::PROCESS_FILE, url);
65 operation_runner()->GetMetadata( 65 operation_runner()->GetMetadata(
66 url, 66 url,
67 base::Bind(&LoggingRecursiveOperation::DidGetMetadata, 67 base::Bind(&LoggingRecursiveOperation::DidGetMetadata,
68 weak_factory_.GetWeakPtr(), callback)); 68 weak_factory_.GetWeakPtr(), callback));
69 } 69 }
70 70
71 virtual void ProcessDirectory(const FileSystemURL& url, 71 virtual void ProcessDirectory(const FileSystemURL& url,
72 const StatusCallback& callback) OVERRIDE { 72 const StatusCallback& callback) OVERRIDE {
73 RecordLogEntry(LogEntry::PROCESS_DIRECTORY, url); 73 RecordLogEntry(LogEntry::PROCESS_DIRECTORY, url);
74 callback.Run(base::PLATFORM_FILE_OK); 74 callback.Run(base::File::FILE_OK);
75 } 75 }
76 76
77 virtual void PostProcessDirectory(const FileSystemURL& url, 77 virtual void PostProcessDirectory(const FileSystemURL& url,
78 const StatusCallback& callback) OVERRIDE { 78 const StatusCallback& callback) OVERRIDE {
79 RecordLogEntry(LogEntry::POST_PROCESS_DIRECTORY, url); 79 RecordLogEntry(LogEntry::POST_PROCESS_DIRECTORY, url);
80 callback.Run(base::PLATFORM_FILE_OK); 80 callback.Run(base::File::FILE_OK);
81 } 81 }
82 82
83 private: 83 private:
84 void RecordLogEntry(LogEntry::Type type, const FileSystemURL& url) { 84 void RecordLogEntry(LogEntry::Type type, const FileSystemURL& url) {
85 LogEntry entry; 85 LogEntry entry;
86 entry.type = type; 86 entry.type = type;
87 entry.url = url; 87 entry.url = url;
88 log_entries_.push_back(entry); 88 log_entries_.push_back(entry);
89 } 89 }
90 90
91 void DidGetMetadata(const StatusCallback& callback, 91 void DidGetMetadata(const StatusCallback& callback,
92 base::PlatformFileError result, 92 base::File::Error result,
93 const base::PlatformFileInfo& file_info) { 93 const base::File::Info& file_info) {
94 if (result != base::PLATFORM_FILE_OK) { 94 if (result != base::File::FILE_OK) {
95 callback.Run(result); 95 callback.Run(result);
96 return; 96 return;
97 } 97 }
98 98
99 callback.Run(file_info.is_directory ? 99 callback.Run(file_info.is_directory ?
100 base::PLATFORM_FILE_ERROR_NOT_A_FILE : 100 base::File::FILE_ERROR_NOT_A_FILE :
101 base::PLATFORM_FILE_OK); 101 base::File::FILE_OK);
102 } 102 }
103 103
104 FileSystemURL root_; 104 FileSystemURL root_;
105 StatusCallback callback_; 105 StatusCallback callback_;
106 std::vector<LogEntry> log_entries_; 106 std::vector<LogEntry> log_entries_;
107 107
108 base::WeakPtrFactory<LoggingRecursiveOperation> weak_factory_; 108 base::WeakPtrFactory<LoggingRecursiveOperation> weak_factory_;
109 DISALLOW_COPY_AND_ASSIGN(LoggingRecursiveOperation); 109 DISALLOW_COPY_AND_ASSIGN(LoggingRecursiveOperation);
110 }; 110 };
111 111
112 void ReportStatus(base::PlatformFileError* out_error, 112 void ReportStatus(base::File::Error* out_error,
113 base::PlatformFileError error) { 113 base::File::Error error) {
114 DCHECK(out_error); 114 DCHECK(out_error);
115 *out_error = error; 115 *out_error = error;
116 } 116 }
117 117
118 // To test the Cancel() during operation, calls Cancel() of |operation| 118 // To test the Cancel() during operation, calls Cancel() of |operation|
119 // after |counter| times message posting. 119 // after |counter| times message posting.
120 void CallCancelLater(fileapi::RecursiveOperationDelegate* operation, 120 void CallCancelLater(fileapi::RecursiveOperationDelegate* operation,
121 int counter) { 121 int counter) {
122 if (counter > 0) { 122 if (counter > 0) {
123 base::MessageLoopProxy::current()->PostTask( 123 base::MessageLoopProxy::current()->PostTask(
(...skipping 30 matching lines...) Expand all
154 return sandbox_file_system_.file_util(); 154 return sandbox_file_system_.file_util();
155 } 155 }
156 156
157 FileSystemURL URLForPath(const std::string& path) const { 157 FileSystemURL URLForPath(const std::string& path) const {
158 return sandbox_file_system_.CreateURLFromUTF8(path); 158 return sandbox_file_system_.CreateURLFromUTF8(path);
159 } 159 }
160 160
161 FileSystemURL CreateFile(const std::string& path) { 161 FileSystemURL CreateFile(const std::string& path) {
162 FileSystemURL url = URLForPath(path); 162 FileSystemURL url = URLForPath(path);
163 bool created = false; 163 bool created = false;
164 EXPECT_EQ(base::PLATFORM_FILE_OK, 164 EXPECT_EQ(base::File::FILE_OK,
165 file_util()->EnsureFileExists(NewContext().get(), 165 file_util()->EnsureFileExists(NewContext().get(),
166 url, &created)); 166 url, &created));
167 EXPECT_TRUE(created); 167 EXPECT_TRUE(created);
168 return url; 168 return url;
169 } 169 }
170 170
171 FileSystemURL CreateDirectory(const std::string& path) { 171 FileSystemURL CreateDirectory(const std::string& path) {
172 FileSystemURL url = URLForPath(path); 172 FileSystemURL url = URLForPath(path);
173 EXPECT_EQ(base::PLATFORM_FILE_OK, 173 EXPECT_EQ(base::File::FILE_OK,
174 file_util()->CreateDirectory(NewContext().get(), url, 174 file_util()->CreateDirectory(NewContext().get(), url,
175 false /* exclusive */, true)); 175 false /* exclusive */, true));
176 return url; 176 return url;
177 } 177 }
178 178
179 private: 179 private:
180 base::MessageLoop message_loop_; 180 base::MessageLoop message_loop_;
181 181
182 // Common temp base for nondestructive uses. 182 // Common temp base for nondestructive uses.
183 base::ScopedTempDir base_; 183 base::ScopedTempDir base_;
184 SandboxFileSystemTestHelper sandbox_file_system_; 184 SandboxFileSystemTestHelper sandbox_file_system_;
185 }; 185 };
186 186
187 TEST_F(RecursiveOperationDelegateTest, RootIsFile) { 187 TEST_F(RecursiveOperationDelegateTest, RootIsFile) {
188 FileSystemURL src_file(CreateFile("src")); 188 FileSystemURL src_file(CreateFile("src"));
189 189
190 base::PlatformFileError error = base::PLATFORM_FILE_ERROR_FAILED; 190 base::File::Error error = base::File::FILE_ERROR_FAILED;
191 scoped_ptr<FileSystemOperationContext> context = NewContext(); 191 scoped_ptr<FileSystemOperationContext> context = NewContext();
192 scoped_ptr<LoggingRecursiveOperation> operation( 192 scoped_ptr<LoggingRecursiveOperation> operation(
193 new LoggingRecursiveOperation( 193 new LoggingRecursiveOperation(
194 context->file_system_context(), src_file, 194 context->file_system_context(), src_file,
195 base::Bind(&ReportStatus, &error))); 195 base::Bind(&ReportStatus, &error)));
196 operation->RunRecursively(); 196 operation->RunRecursively();
197 base::RunLoop().RunUntilIdle(); 197 base::RunLoop().RunUntilIdle();
198 ASSERT_EQ(base::PLATFORM_FILE_OK, error); 198 ASSERT_EQ(base::File::FILE_OK, error);
199 199
200 const std::vector<LoggingRecursiveOperation::LogEntry>& log_entries = 200 const std::vector<LoggingRecursiveOperation::LogEntry>& log_entries =
201 operation->log_entries(); 201 operation->log_entries();
202 ASSERT_EQ(1U, log_entries.size()); 202 ASSERT_EQ(1U, log_entries.size());
203 const LoggingRecursiveOperation::LogEntry& entry = log_entries[0]; 203 const LoggingRecursiveOperation::LogEntry& entry = log_entries[0];
204 EXPECT_EQ(LoggingRecursiveOperation::LogEntry::PROCESS_FILE, entry.type); 204 EXPECT_EQ(LoggingRecursiveOperation::LogEntry::PROCESS_FILE, entry.type);
205 EXPECT_EQ(src_file, entry.url); 205 EXPECT_EQ(src_file, entry.url);
206 } 206 }
207 207
208 TEST_F(RecursiveOperationDelegateTest, RootIsDirectory) { 208 TEST_F(RecursiveOperationDelegateTest, RootIsDirectory) {
209 FileSystemURL src_root(CreateDirectory("src")); 209 FileSystemURL src_root(CreateDirectory("src"));
210 FileSystemURL src_dir1(CreateDirectory("src/dir1")); 210 FileSystemURL src_dir1(CreateDirectory("src/dir1"));
211 FileSystemURL src_file1(CreateFile("src/file1")); 211 FileSystemURL src_file1(CreateFile("src/file1"));
212 FileSystemURL src_file2(CreateFile("src/dir1/file2")); 212 FileSystemURL src_file2(CreateFile("src/dir1/file2"));
213 FileSystemURL src_file3(CreateFile("src/dir1/file3")); 213 FileSystemURL src_file3(CreateFile("src/dir1/file3"));
214 214
215 base::PlatformFileError error = base::PLATFORM_FILE_ERROR_FAILED; 215 base::File::Error error = base::File::FILE_ERROR_FAILED;
216 scoped_ptr<FileSystemOperationContext> context = NewContext(); 216 scoped_ptr<FileSystemOperationContext> context = NewContext();
217 scoped_ptr<LoggingRecursiveOperation> operation( 217 scoped_ptr<LoggingRecursiveOperation> operation(
218 new LoggingRecursiveOperation( 218 new LoggingRecursiveOperation(
219 context->file_system_context(), src_root, 219 context->file_system_context(), src_root,
220 base::Bind(&ReportStatus, &error))); 220 base::Bind(&ReportStatus, &error)));
221 operation->RunRecursively(); 221 operation->RunRecursively();
222 base::RunLoop().RunUntilIdle(); 222 base::RunLoop().RunUntilIdle();
223 ASSERT_EQ(base::PLATFORM_FILE_OK, error); 223 ASSERT_EQ(base::File::FILE_OK, error);
224 224
225 const std::vector<LoggingRecursiveOperation::LogEntry>& log_entries = 225 const std::vector<LoggingRecursiveOperation::LogEntry>& log_entries =
226 operation->log_entries(); 226 operation->log_entries();
227 ASSERT_EQ(8U, log_entries.size()); 227 ASSERT_EQ(8U, log_entries.size());
228 228
229 EXPECT_EQ(LoggingRecursiveOperation::LogEntry::PROCESS_FILE, 229 EXPECT_EQ(LoggingRecursiveOperation::LogEntry::PROCESS_FILE,
230 log_entries[0].type); 230 log_entries[0].type);
231 EXPECT_EQ(src_root, log_entries[0].url); 231 EXPECT_EQ(src_root, log_entries[0].url);
232 232
233 EXPECT_EQ(LoggingRecursiveOperation::LogEntry::PROCESS_DIRECTORY, 233 EXPECT_EQ(LoggingRecursiveOperation::LogEntry::PROCESS_DIRECTORY,
(...skipping 27 matching lines...) Expand all
261 log_entries[7].type); 261 log_entries[7].type);
262 EXPECT_EQ(src_root, log_entries[7].url); 262 EXPECT_EQ(src_root, log_entries[7].url);
263 } 263 }
264 264
265 TEST_F(RecursiveOperationDelegateTest, Cancel) { 265 TEST_F(RecursiveOperationDelegateTest, Cancel) {
266 FileSystemURL src_root(CreateDirectory("src")); 266 FileSystemURL src_root(CreateDirectory("src"));
267 FileSystemURL src_dir1(CreateDirectory("src/dir1")); 267 FileSystemURL src_dir1(CreateDirectory("src/dir1"));
268 FileSystemURL src_file1(CreateFile("src/file1")); 268 FileSystemURL src_file1(CreateFile("src/file1"));
269 FileSystemURL src_file2(CreateFile("src/dir1/file2")); 269 FileSystemURL src_file2(CreateFile("src/dir1/file2"));
270 270
271 base::PlatformFileError error = base::PLATFORM_FILE_ERROR_FAILED; 271 base::File::Error error = base::File::FILE_ERROR_FAILED;
272 scoped_ptr<FileSystemOperationContext> context = NewContext(); 272 scoped_ptr<FileSystemOperationContext> context = NewContext();
273 scoped_ptr<LoggingRecursiveOperation> operation( 273 scoped_ptr<LoggingRecursiveOperation> operation(
274 new LoggingRecursiveOperation( 274 new LoggingRecursiveOperation(
275 context->file_system_context(), src_root, 275 context->file_system_context(), src_root,
276 base::Bind(&ReportStatus, &error))); 276 base::Bind(&ReportStatus, &error)));
277 operation->RunRecursively(); 277 operation->RunRecursively();
278 278
279 // Invoke Cancel(), after 5 times message posting. 279 // Invoke Cancel(), after 5 times message posting.
280 CallCancelLater(operation.get(), 5); 280 CallCancelLater(operation.get(), 5);
281 base::RunLoop().RunUntilIdle(); 281 base::RunLoop().RunUntilIdle();
282 ASSERT_EQ(base::PLATFORM_FILE_ERROR_ABORT, error); 282 ASSERT_EQ(base::File::FILE_ERROR_ABORT, error);
283 } 283 }
284 284
285 } // namespace content 285 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698