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

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: Fix broken test cases. 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_TERMINATE,
59 callback_);
60 }
57 61
58 void RunRecursivelyWithIgnoringError(const ErrorCallback& error_callback) { 62 void RunRecursivelyWithIgnoringError() {
59 StartRecursiveOperationWithIgnoringError(root_, error_callback, callback_); 63 StartRecursiveOperation(
64 root_, storage::FileSystemOperation::ERROR_BEHAVIOR_CONTINUE,
65 callback_);
60 } 66 }
61 67
62 void ProcessFile(const FileSystemURL& url, 68 void ProcessFile(const FileSystemURL& url,
63 const StatusCallback& callback) override { 69 const StatusCallback& callback) override {
64 RecordLogEntry(LogEntry::PROCESS_FILE, url); 70 RecordLogEntry(LogEntry::PROCESS_FILE, url);
65 71
66 if (error_url_.is_valid() && error_url_ == url) { 72 if (error_url_.is_valid() && error_url_ == url) {
67 callback.Run(base::File::FILE_ERROR_FAILED); 73 callback.Run(base::File::FILE_ERROR_FAILED);
68 return; 74 return;
69 } 75 }
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
117 base::WeakPtrFactory<LoggingRecursiveOperation> weak_factory_; 123 base::WeakPtrFactory<LoggingRecursiveOperation> weak_factory_;
118 DISALLOW_COPY_AND_ASSIGN(LoggingRecursiveOperation); 124 DISALLOW_COPY_AND_ASSIGN(LoggingRecursiveOperation);
119 }; 125 };
120 126
121 void ReportStatus(base::File::Error* out_error, 127 void ReportStatus(base::File::Error* out_error,
122 base::File::Error error) { 128 base::File::Error error) {
123 DCHECK(out_error); 129 DCHECK(out_error);
124 *out_error = error; 130 *out_error = error;
125 } 131 }
126 132
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| 133 // To test the Cancel() during operation, calls Cancel() of |operation|
137 // after |counter| times message posting. 134 // after |counter| times message posting.
138 void CallCancelLater(storage::RecursiveOperationDelegate* operation, 135 void CallCancelLater(storage::RecursiveOperationDelegate* operation,
139 int counter) { 136 int counter) {
140 if (counter > 0) { 137 if (counter > 0) {
141 base::ThreadTaskRunnerHandle::Get()->PostTask( 138 base::ThreadTaskRunnerHandle::Get()->PostTask(
142 FROM_HERE, 139 FROM_HERE,
143 base::Bind(&CallCancelLater, base::Unretained(operation), counter - 1)); 140 base::Bind(&CallCancelLater, base::Unretained(operation), counter - 1));
144 return; 141 return;
145 } 142 }
(...skipping 181 matching lines...) Expand 10 before | Expand all | Expand 10 after
327 324
328 EXPECT_EQ(LoggingRecursiveOperation::LogEntry::PROCESS_DIRECTORY, 325 EXPECT_EQ(LoggingRecursiveOperation::LogEntry::PROCESS_DIRECTORY,
329 log_entries[1].type); 326 log_entries[1].type);
330 EXPECT_EQ(src_root, log_entries[1].url); 327 EXPECT_EQ(src_root, log_entries[1].url);
331 328
332 EXPECT_EQ(LoggingRecursiveOperation::LogEntry::PROCESS_FILE, 329 EXPECT_EQ(LoggingRecursiveOperation::LogEntry::PROCESS_FILE,
333 log_entries[2].type); 330 log_entries[2].type);
334 EXPECT_EQ(src_file1, log_entries[2].url); 331 EXPECT_EQ(src_file1, log_entries[2].url);
335 } 332 }
336 333
337 TEST_F(RecursiveOperationDelegateTest, ContinueWithError) { 334 TEST_F(RecursiveOperationDelegateTest, ContinueWithError) {
mtomasz 2015/06/24 03:36:17 Can we add a similar test for ERROR_BEHAVIOR_TERMI
yawano 2015/06/24 03:38:48 We have one with the name of AbortWithError. It's
mtomasz 2015/06/24 03:44:30 Ah, sorry I missed it! lgtm!
338 FileSystemURL src_root(CreateDirectory("src")); 335 FileSystemURL src_root(CreateDirectory("src"));
339 FileSystemURL src_dir1(CreateDirectory("src/dir1")); 336 FileSystemURL src_dir1(CreateDirectory("src/dir1"));
340 FileSystemURL src_file1(CreateFile("src/file1")); 337 FileSystemURL src_file1(CreateFile("src/file1"));
341 FileSystemURL src_file2(CreateFile("src/dir1/file2")); 338 FileSystemURL src_file2(CreateFile("src/dir1/file2"));
342 FileSystemURL src_file3(CreateFile("src/dir1/file3")); 339 FileSystemURL src_file3(CreateFile("src/dir1/file3"));
343 340
344 base::File::Error error = base::File::FILE_ERROR_FAILED; 341 base::File::Error error = base::File::FILE_ERROR_FAILED;
345 std::vector<ErrorEntry> errors;
346 scoped_ptr<FileSystemOperationContext> context = NewContext(); 342 scoped_ptr<FileSystemOperationContext> context = NewContext();
347 scoped_ptr<LoggingRecursiveOperation> operation( 343 scoped_ptr<LoggingRecursiveOperation> operation(
348 new LoggingRecursiveOperation(context->file_system_context(), src_root, 344 new LoggingRecursiveOperation(context->file_system_context(), src_root,
349 base::Bind(&ReportStatus, &error))); 345 base::Bind(&ReportStatus, &error)));
350 operation->SetEntryToFail(src_file1); 346 operation->SetEntryToFail(src_file1);
351 operation->RunRecursivelyWithIgnoringError(base::Bind(&ReportError, &errors)); 347 operation->RunRecursivelyWithIgnoringError();
352 base::RunLoop().RunUntilIdle(); 348 base::RunLoop().RunUntilIdle();
353 349
354 // Error code should be base::File::FILE_ERROR_FAILED. 350 // Error code should be base::File::FILE_ERROR_FAILED.
355 ASSERT_EQ(base::File::FILE_ERROR_FAILED, error); 351 ASSERT_EQ(base::File::FILE_ERROR_FAILED, error);
356 352
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. 353 // Confirm that operation continues after the error.
363 const std::vector<LoggingRecursiveOperation::LogEntry>& log_entries = 354 const std::vector<LoggingRecursiveOperation::LogEntry>& log_entries =
364 operation->log_entries(); 355 operation->log_entries();
365 ASSERT_EQ(8U, log_entries.size()); 356 ASSERT_EQ(8U, log_entries.size());
366 357
367 EXPECT_EQ(LoggingRecursiveOperation::LogEntry::PROCESS_FILE, 358 EXPECT_EQ(LoggingRecursiveOperation::LogEntry::PROCESS_FILE,
368 log_entries[0].type); 359 log_entries[0].type);
369 EXPECT_EQ(src_root, log_entries[0].url); 360 EXPECT_EQ(src_root, log_entries[0].url);
370 361
371 EXPECT_EQ(LoggingRecursiveOperation::LogEntry::PROCESS_DIRECTORY, 362 EXPECT_EQ(LoggingRecursiveOperation::LogEntry::PROCESS_DIRECTORY,
(...skipping 19 matching lines...) Expand all
391 EXPECT_EQ(LoggingRecursiveOperation::LogEntry::POST_PROCESS_DIRECTORY, 382 EXPECT_EQ(LoggingRecursiveOperation::LogEntry::POST_PROCESS_DIRECTORY,
392 log_entries[6].type); 383 log_entries[6].type);
393 EXPECT_EQ(src_dir1, log_entries[6].url); 384 EXPECT_EQ(src_dir1, log_entries[6].url);
394 385
395 EXPECT_EQ(LoggingRecursiveOperation::LogEntry::POST_PROCESS_DIRECTORY, 386 EXPECT_EQ(LoggingRecursiveOperation::LogEntry::POST_PROCESS_DIRECTORY,
396 log_entries[7].type); 387 log_entries[7].type);
397 EXPECT_EQ(src_root, log_entries[7].url); 388 EXPECT_EQ(src_root, log_entries[7].url);
398 } 389 }
399 390
400 } // namespace content 391 } // 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