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

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

Issue 1194783002: Add fileManagerPrivate.onCopyError event. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Remove const and rename enum. Created 5 years, 6 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
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 "storage/browser/fileapi/recursive_operation_delegate.h" 5 #include "storage/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 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
46 root_(root), 46 root_(root),
47 callback_(callback), 47 callback_(callback),
48 weak_factory_(this) {} 48 weak_factory_(this) {}
49 ~LoggingRecursiveOperation() override {} 49 ~LoggingRecursiveOperation() override {}
50 50
51 const std::vector<LogEntry>& log_entries() const { return log_entries_; } 51 const std::vector<LogEntry>& log_entries() const { return log_entries_; }
52 52
53 // RecursiveOperationDelegate overrides. 53 // RecursiveOperationDelegate overrides.
54 void Run() override { NOTREACHED(); } 54 void Run() override { NOTREACHED(); }
55 55
56 void RunRecursively() override { StartRecursiveOperation(root_, callback_); } 56 void RunRecursively() override {
57 StartRecursiveOperation(
58 root_, storage::FileSystemOperation::ERROR_BEHAVIOR_ABORT, callback_);
59 }
57 60
58 void RunRecursivelyWithIgnoringError(const ErrorCallback& error_callback) { 61 void RunRecursivelyWithIgnoringError() {
59 StartRecursiveOperationWithIgnoringError(root_, error_callback, callback_); 62 StartRecursiveOperation(
63 root_, storage::FileSystemOperation::ERROR_BEHAVIOR_SKIP, callback_);
60 } 64 }
61 65
62 void ProcessFile(const FileSystemURL& url, 66 void ProcessFile(const FileSystemURL& url,
63 const StatusCallback& callback) override { 67 const StatusCallback& callback) override {
64 RecordLogEntry(LogEntry::PROCESS_FILE, url); 68 RecordLogEntry(LogEntry::PROCESS_FILE, url);
65 69
66 if (error_url_.is_valid() && error_url_ == url) { 70 if (error_url_.is_valid() && error_url_ == url) {
67 callback.Run(base::File::FILE_ERROR_FAILED); 71 callback.Run(base::File::FILE_ERROR_FAILED);
68 return; 72 return;
69 } 73 }
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
117 base::WeakPtrFactory<LoggingRecursiveOperation> weak_factory_; 121 base::WeakPtrFactory<LoggingRecursiveOperation> weak_factory_;
118 DISALLOW_COPY_AND_ASSIGN(LoggingRecursiveOperation); 122 DISALLOW_COPY_AND_ASSIGN(LoggingRecursiveOperation);
119 }; 123 };
120 124
121 void ReportStatus(base::File::Error* out_error, 125 void ReportStatus(base::File::Error* out_error,
122 base::File::Error error) { 126 base::File::Error error) {
123 DCHECK(out_error); 127 DCHECK(out_error);
124 *out_error = error; 128 *out_error = error;
125 } 129 }
126 130
127 typedef std::pair<FileSystemURL, base::File::Error> ErrorEntry;
128
129 void ReportError(std::vector<ErrorEntry>* out_errors,
130 const FileSystemURL& url,
131 base::File::Error error) {
132 DCHECK(out_errors);
133 out_errors->push_back(std::make_pair(url, error));
134 }
135
136 // To test the Cancel() during operation, calls Cancel() of |operation| 131 // To test the Cancel() during operation, calls Cancel() of |operation|
137 // after |counter| times message posting. 132 // after |counter| times message posting.
138 void CallCancelLater(storage::RecursiveOperationDelegate* operation, 133 void CallCancelLater(storage::RecursiveOperationDelegate* operation,
139 int counter) { 134 int counter) {
140 if (counter > 0) { 135 if (counter > 0) {
141 base::ThreadTaskRunnerHandle::Get()->PostTask( 136 base::ThreadTaskRunnerHandle::Get()->PostTask(
142 FROM_HERE, 137 FROM_HERE,
143 base::Bind(&CallCancelLater, base::Unretained(operation), counter - 1)); 138 base::Bind(&CallCancelLater, base::Unretained(operation), counter - 1));
144 return; 139 return;
145 } 140 }
(...skipping 189 matching lines...) Expand 10 before | Expand all | Expand 10 after
335 } 330 }
336 331
337 TEST_F(RecursiveOperationDelegateTest, ContinueWithError) { 332 TEST_F(RecursiveOperationDelegateTest, ContinueWithError) {
338 FileSystemURL src_root(CreateDirectory("src")); 333 FileSystemURL src_root(CreateDirectory("src"));
339 FileSystemURL src_dir1(CreateDirectory("src/dir1")); 334 FileSystemURL src_dir1(CreateDirectory("src/dir1"));
340 FileSystemURL src_file1(CreateFile("src/file1")); 335 FileSystemURL src_file1(CreateFile("src/file1"));
341 FileSystemURL src_file2(CreateFile("src/dir1/file2")); 336 FileSystemURL src_file2(CreateFile("src/dir1/file2"));
342 FileSystemURL src_file3(CreateFile("src/dir1/file3")); 337 FileSystemURL src_file3(CreateFile("src/dir1/file3"));
343 338
344 base::File::Error error = base::File::FILE_ERROR_FAILED; 339 base::File::Error error = base::File::FILE_ERROR_FAILED;
345 std::vector<ErrorEntry> errors;
346 scoped_ptr<FileSystemOperationContext> context = NewContext(); 340 scoped_ptr<FileSystemOperationContext> context = NewContext();
347 scoped_ptr<LoggingRecursiveOperation> operation( 341 scoped_ptr<LoggingRecursiveOperation> operation(
348 new LoggingRecursiveOperation(context->file_system_context(), src_root, 342 new LoggingRecursiveOperation(context->file_system_context(), src_root,
349 base::Bind(&ReportStatus, &error))); 343 base::Bind(&ReportStatus, &error)));
350 operation->SetEntryToFail(src_file1); 344 operation->SetEntryToFail(src_file1);
351 operation->RunRecursivelyWithIgnoringError(base::Bind(&ReportError, &errors)); 345 operation->RunRecursivelyWithIgnoringError();
352 base::RunLoop().RunUntilIdle(); 346 base::RunLoop().RunUntilIdle();
353 347
354 // Error code should be base::File::FILE_ERROR_FAILED. 348 // Error code should be base::File::FILE_ERROR_FAILED.
355 ASSERT_EQ(base::File::FILE_ERROR_FAILED, error); 349 ASSERT_EQ(base::File::FILE_ERROR_FAILED, error);
356 350
357 // Error callback should be called.
358 ASSERT_EQ(1U, errors.size());
359 ASSERT_EQ(src_file1, errors[0].first);
360 ASSERT_EQ(base::File::FILE_ERROR_FAILED, errors[0].second);
361
362 // Confirm that operation continues after the error. 351 // Confirm that operation continues after the error.
363 const std::vector<LoggingRecursiveOperation::LogEntry>& log_entries = 352 const std::vector<LoggingRecursiveOperation::LogEntry>& log_entries =
364 operation->log_entries(); 353 operation->log_entries();
365 ASSERT_EQ(8U, log_entries.size()); 354 ASSERT_EQ(8U, log_entries.size());
366 355
367 EXPECT_EQ(LoggingRecursiveOperation::LogEntry::PROCESS_FILE, 356 EXPECT_EQ(LoggingRecursiveOperation::LogEntry::PROCESS_FILE,
368 log_entries[0].type); 357 log_entries[0].type);
369 EXPECT_EQ(src_root, log_entries[0].url); 358 EXPECT_EQ(src_root, log_entries[0].url);
370 359
371 EXPECT_EQ(LoggingRecursiveOperation::LogEntry::PROCESS_DIRECTORY, 360 EXPECT_EQ(LoggingRecursiveOperation::LogEntry::PROCESS_DIRECTORY,
(...skipping 19 matching lines...) Expand all
391 EXPECT_EQ(LoggingRecursiveOperation::LogEntry::POST_PROCESS_DIRECTORY, 380 EXPECT_EQ(LoggingRecursiveOperation::LogEntry::POST_PROCESS_DIRECTORY,
392 log_entries[6].type); 381 log_entries[6].type);
393 EXPECT_EQ(src_dir1, log_entries[6].url); 382 EXPECT_EQ(src_dir1, log_entries[6].url);
394 383
395 EXPECT_EQ(LoggingRecursiveOperation::LogEntry::POST_PROCESS_DIRECTORY, 384 EXPECT_EQ(LoggingRecursiveOperation::LogEntry::POST_PROCESS_DIRECTORY,
396 log_entries[7].type); 385 log_entries[7].type);
397 EXPECT_EQ(src_root, log_entries[7].url); 386 EXPECT_EQ(src_root, log_entries[7].url);
398 } 387 }
399 388
400 } // namespace content 389 } // namespace content
OLDNEW
« no previous file with comments | « content/browser/fileapi/fileapi_message_filter.cc ('k') | content/public/test/async_file_test_helper.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698