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

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

Issue 1159623009: content: Remove use of MessageLoopProxy and deprecated MessageLoop APIs (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Test build fix. 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 <map> 5 #include <map>
6 #include <queue> 6 #include <queue>
7 7
8 #include "base/basictypes.h" 8 #include "base/basictypes.h"
9 #include "base/bind.h" 9 #include "base/bind.h"
10 #include "base/files/file_util.h" 10 #include "base/files/file_util.h"
11 #include "base/files/scoped_temp_dir.h" 11 #include "base/files/scoped_temp_dir.h"
12 #include "base/message_loop/message_loop.h" 12 #include "base/location.h"
13 #include "base/run_loop.h" 13 #include "base/run_loop.h"
14 #include "base/single_thread_task_runner.h"
14 #include "base/stl_util.h" 15 #include "base/stl_util.h"
16 #include "base/thread_task_runner_handle.h"
15 #include "content/browser/quota/mock_quota_manager.h" 17 #include "content/browser/quota/mock_quota_manager.h"
16 #include "content/browser/quota/mock_quota_manager_proxy.h" 18 #include "content/browser/quota/mock_quota_manager_proxy.h"
17 #include "content/public/test/async_file_test_helper.h" 19 #include "content/public/test/async_file_test_helper.h"
18 #include "content/public/test/test_file_system_backend.h" 20 #include "content/public/test/test_file_system_backend.h"
19 #include "content/public/test/test_file_system_context.h" 21 #include "content/public/test/test_file_system_context.h"
20 #include "content/test/fileapi_test_file_set.h" 22 #include "content/test/fileapi_test_file_set.h"
21 #include "storage/browser/fileapi/copy_or_move_file_validator.h" 23 #include "storage/browser/fileapi/copy_or_move_file_validator.h"
22 #include "storage/browser/fileapi/copy_or_move_operation_delegate.h" 24 #include "storage/browser/fileapi/copy_or_move_operation_delegate.h"
23 #include "storage/browser/fileapi/file_stream_reader.h" 25 #include "storage/browser/fileapi/file_stream_reader.h"
24 #include "storage/browser/fileapi/file_stream_writer.h" 26 #include "storage/browser/fileapi/file_stream_writer.h"
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
72 base::File::FILE_ERROR_SECURITY), 74 base::File::FILE_ERROR_SECURITY),
73 write_result_(post_copy_valid ? base::File::FILE_OK : 75 write_result_(post_copy_valid ? base::File::FILE_OK :
74 base::File::FILE_ERROR_SECURITY), 76 base::File::FILE_ERROR_SECURITY),
75 reject_string_(reject_string) { 77 reject_string_(reject_string) {
76 } 78 }
77 ~TestValidator() override {} 79 ~TestValidator() override {}
78 80
79 void StartPreWriteValidation( 81 void StartPreWriteValidation(
80 const ResultCallback& result_callback) override { 82 const ResultCallback& result_callback) override {
81 // Post the result since a real validator must do work asynchronously. 83 // Post the result since a real validator must do work asynchronously.
82 base::MessageLoop::current()->PostTask( 84 base::ThreadTaskRunnerHandle::Get()->PostTask(
83 FROM_HERE, base::Bind(result_callback, result_)); 85 FROM_HERE, base::Bind(result_callback, result_));
84 } 86 }
85 87
86 void StartPostWriteValidation( 88 void StartPostWriteValidation(
87 const base::FilePath& dest_platform_path, 89 const base::FilePath& dest_platform_path,
88 const ResultCallback& result_callback) override { 90 const ResultCallback& result_callback) override {
89 base::File::Error result = write_result_; 91 base::File::Error result = write_result_;
90 std::string unsafe = dest_platform_path.BaseName().AsUTF8Unsafe(); 92 std::string unsafe = dest_platform_path.BaseName().AsUTF8Unsafe();
91 if (unsafe.find(reject_string_) != std::string::npos) { 93 if (unsafe.find(reject_string_) != std::string::npos) {
92 result = base::File::FILE_ERROR_SECURITY; 94 result = base::File::FILE_ERROR_SECURITY;
93 } 95 }
94 // Post the result since a real validator must do work asynchronously. 96 // Post the result since a real validator must do work asynchronously.
95 base::MessageLoop::current()->PostTask( 97 base::ThreadTaskRunnerHandle::Get()->PostTask(
96 FROM_HERE, base::Bind(result_callback, result)); 98 FROM_HERE, base::Bind(result_callback, result));
97 } 99 }
98 100
99 private: 101 private:
100 base::File::Error result_; 102 base::File::Error result_;
101 base::File::Error write_result_; 103 base::File::Error write_result_;
102 std::string reject_string_; 104 std::string reject_string_;
103 105
104 DISALLOW_COPY_AND_ASSIGN(TestValidator); 106 DISALLOW_COPY_AND_ASSIGN(TestValidator);
105 }; 107 };
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
140 142
141 class ScopedThreadStopper { 143 class ScopedThreadStopper {
142 public: 144 public:
143 ScopedThreadStopper(base::Thread* thread) : thread_(thread) { 145 ScopedThreadStopper(base::Thread* thread) : thread_(thread) {
144 } 146 }
145 147
146 ~ScopedThreadStopper() { 148 ~ScopedThreadStopper() {
147 if (thread_) { 149 if (thread_) {
148 // Give another chance for deleted streams to perform Close. 150 // Give another chance for deleted streams to perform Close.
149 base::RunLoop run_loop; 151 base::RunLoop run_loop;
150 thread_->message_loop_proxy()->PostTaskAndReply( 152 thread_->task_runner()->PostTaskAndReply(
151 FROM_HERE, base::Bind(&base::DoNothing), run_loop.QuitClosure()); 153 FROM_HERE, base::Bind(&base::DoNothing), run_loop.QuitClosure());
152 run_loop.Run(); 154 run_loop.Run();
153 thread_->Stop(); 155 thread_->Stop();
154 } 156 }
155 } 157 }
156 158
157 bool is_valid() const { return thread_; } 159 bool is_valid() const { return thread_; }
158 160
159 private: 161 private:
160 base::Thread* thread_; 162 base::Thread* thread_;
(...skipping 23 matching lines...) Expand all
184 186
185 void SetUpNoValidator() { 187 void SetUpNoValidator() {
186 SetUp(true, false); 188 SetUp(true, false);
187 } 189 }
188 190
189 void SetUp(bool require_copy_or_move_validator, 191 void SetUp(bool require_copy_or_move_validator,
190 bool init_copy_or_move_validator) { 192 bool init_copy_or_move_validator) {
191 ASSERT_TRUE(base_.CreateUniqueTempDir()); 193 ASSERT_TRUE(base_.CreateUniqueTempDir());
192 base::FilePath base_dir = base_.path(); 194 base::FilePath base_dir = base_.path();
193 quota_manager_ = 195 quota_manager_ =
194 new MockQuotaManager(false /* is_incognito */, 196 new MockQuotaManager(false /* is_incognito */, base_dir,
195 base_dir, 197 base::ThreadTaskRunnerHandle::Get().get(),
196 base::MessageLoopProxy::current().get(), 198 base::ThreadTaskRunnerHandle::Get().get(),
197 base::MessageLoopProxy::current().get(), 199 NULL /* special storage policy */);
198 NULL /* special storage policy */);
199 quota_manager_proxy_ = new MockQuotaManagerProxy( 200 quota_manager_proxy_ = new MockQuotaManagerProxy(
200 quota_manager_.get(), base::MessageLoopProxy::current().get()); 201 quota_manager_.get(), base::ThreadTaskRunnerHandle::Get().get());
201 file_system_context_ = 202 file_system_context_ =
202 CreateFileSystemContextForTesting(quota_manager_proxy_.get(), base_dir); 203 CreateFileSystemContextForTesting(quota_manager_proxy_.get(), base_dir);
203 204
204 // Prepare the origin's root directory. 205 // Prepare the origin's root directory.
205 storage::FileSystemBackend* backend = 206 storage::FileSystemBackend* backend =
206 file_system_context_->GetFileSystemBackend(src_type_); 207 file_system_context_->GetFileSystemBackend(src_type_);
207 backend->ResolveURL( 208 backend->ResolveURL(
208 FileSystemURL::CreateForTest(origin_, src_type_, base::FilePath()), 209 FileSystemURL::CreateForTest(origin_, src_type_, base::FilePath()),
209 storage::OPEN_FILE_SYSTEM_CREATE_IF_NONEXISTENT, 210 storage::OPEN_FILE_SYSTEM_CREATE_IF_NONEXISTENT,
210 base::Bind(&ExpectOk)); 211 base::Bind(&ExpectOk));
(...skipping 510 matching lines...) Expand 10 before | Expand all | Expand 10 after
721 const char kTestData[] = "abcdefghijklmnopqrstuvwxyz0123456789"; 722 const char kTestData[] = "abcdefghijklmnopqrstuvwxyz0123456789";
722 base::WriteFile(source_path, kTestData, 723 base::WriteFile(source_path, kTestData,
723 arraysize(kTestData) - 1); // Exclude trailing '\0'. 724 arraysize(kTestData) - 1); // Exclude trailing '\0'.
724 725
725 base::MessageLoopForIO message_loop; 726 base::MessageLoopForIO message_loop;
726 base::Thread file_thread("file_thread"); 727 base::Thread file_thread("file_thread");
727 ASSERT_TRUE(file_thread.Start()); 728 ASSERT_TRUE(file_thread.Start());
728 ScopedThreadStopper thread_stopper(&file_thread); 729 ScopedThreadStopper thread_stopper(&file_thread);
729 ASSERT_TRUE(thread_stopper.is_valid()); 730 ASSERT_TRUE(thread_stopper.is_valid());
730 731
731 scoped_refptr<base::MessageLoopProxy> task_runner = 732 scoped_refptr<base::SingleThreadTaskRunner> task_runner =
732 file_thread.message_loop_proxy(); 733 file_thread.task_runner();
733 734
734 scoped_ptr<storage::FileStreamReader> reader( 735 scoped_ptr<storage::FileStreamReader> reader(
735 storage::FileStreamReader::CreateForLocalFile( 736 storage::FileStreamReader::CreateForLocalFile(
736 task_runner.get(), source_path, 0, base::Time())); 737 task_runner.get(), source_path, 0, base::Time()));
737 738
738 scoped_ptr<FileStreamWriter> writer(FileStreamWriter::CreateForLocalFile( 739 scoped_ptr<FileStreamWriter> writer(FileStreamWriter::CreateForLocalFile(
739 task_runner.get(), dest_path, 0, FileStreamWriter::CREATE_NEW_FILE)); 740 task_runner.get(), dest_path, 0, FileStreamWriter::CREATE_NEW_FILE));
740 741
741 std::vector<int64> progress; 742 std::vector<int64> progress;
742 CopyOrMoveOperationDelegate::StreamCopyHelper helper( 743 CopyOrMoveOperationDelegate::StreamCopyHelper helper(
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
777 base::WriteFile(source_path, kTestData, 778 base::WriteFile(source_path, kTestData,
778 arraysize(kTestData) - 1); // Exclude trailing '\0'. 779 arraysize(kTestData) - 1); // Exclude trailing '\0'.
779 780
780 781
781 base::MessageLoopForIO message_loop; 782 base::MessageLoopForIO message_loop;
782 base::Thread file_thread("file_thread"); 783 base::Thread file_thread("file_thread");
783 ASSERT_TRUE(file_thread.Start()); 784 ASSERT_TRUE(file_thread.Start());
784 ScopedThreadStopper thread_stopper(&file_thread); 785 ScopedThreadStopper thread_stopper(&file_thread);
785 ASSERT_TRUE(thread_stopper.is_valid()); 786 ASSERT_TRUE(thread_stopper.is_valid());
786 787
787 scoped_refptr<base::MessageLoopProxy> task_runner = 788 scoped_refptr<base::SingleThreadTaskRunner> task_runner =
788 file_thread.message_loop_proxy(); 789 file_thread.task_runner();
789 790
790 scoped_ptr<storage::FileStreamReader> reader( 791 scoped_ptr<storage::FileStreamReader> reader(
791 storage::FileStreamReader::CreateForLocalFile( 792 storage::FileStreamReader::CreateForLocalFile(
792 task_runner.get(), source_path, 0, base::Time())); 793 task_runner.get(), source_path, 0, base::Time()));
793 794
794 scoped_ptr<FileStreamWriter> writer(FileStreamWriter::CreateForLocalFile( 795 scoped_ptr<FileStreamWriter> writer(FileStreamWriter::CreateForLocalFile(
795 task_runner.get(), dest_path, 0, FileStreamWriter::CREATE_NEW_FILE)); 796 task_runner.get(), dest_path, 0, FileStreamWriter::CREATE_NEW_FILE));
796 797
797 std::vector<int64> progress; 798 std::vector<int64> progress;
798 CopyOrMoveOperationDelegate::StreamCopyHelper helper( 799 CopyOrMoveOperationDelegate::StreamCopyHelper helper(
(...skipping 29 matching lines...) Expand all
828 const char kTestData[] = "abcdefghijklmnopqrstuvwxyz0123456789"; 829 const char kTestData[] = "abcdefghijklmnopqrstuvwxyz0123456789";
829 base::WriteFile(source_path, kTestData, 830 base::WriteFile(source_path, kTestData,
830 arraysize(kTestData) - 1); // Exclude trailing '\0'. 831 arraysize(kTestData) - 1); // Exclude trailing '\0'.
831 832
832 base::MessageLoopForIO message_loop; 833 base::MessageLoopForIO message_loop;
833 base::Thread file_thread("file_thread"); 834 base::Thread file_thread("file_thread");
834 ASSERT_TRUE(file_thread.Start()); 835 ASSERT_TRUE(file_thread.Start());
835 ScopedThreadStopper thread_stopper(&file_thread); 836 ScopedThreadStopper thread_stopper(&file_thread);
836 ASSERT_TRUE(thread_stopper.is_valid()); 837 ASSERT_TRUE(thread_stopper.is_valid());
837 838
838 scoped_refptr<base::MessageLoopProxy> task_runner = 839 scoped_refptr<base::SingleThreadTaskRunner> task_runner =
839 file_thread.message_loop_proxy(); 840 file_thread.task_runner();
840 841
841 scoped_ptr<storage::FileStreamReader> reader( 842 scoped_ptr<storage::FileStreamReader> reader(
842 storage::FileStreamReader::CreateForLocalFile( 843 storage::FileStreamReader::CreateForLocalFile(
843 task_runner.get(), source_path, 0, base::Time())); 844 task_runner.get(), source_path, 0, base::Time()));
844 845
845 scoped_ptr<FileStreamWriter> writer(FileStreamWriter::CreateForLocalFile( 846 scoped_ptr<FileStreamWriter> writer(FileStreamWriter::CreateForLocalFile(
846 task_runner.get(), dest_path, 0, FileStreamWriter::CREATE_NEW_FILE)); 847 task_runner.get(), dest_path, 0, FileStreamWriter::CREATE_NEW_FILE));
847 848
848 std::vector<int64> progress; 849 std::vector<int64> progress;
849 CopyOrMoveOperationDelegate::StreamCopyHelper helper( 850 CopyOrMoveOperationDelegate::StreamCopyHelper helper(
850 reader.Pass(), writer.Pass(), 851 reader.Pass(), writer.Pass(),
851 storage::FlushPolicy::NO_FLUSH_ON_COMPLETION, 852 storage::FlushPolicy::NO_FLUSH_ON_COMPLETION,
852 10, // buffer size 853 10, // buffer size
853 base::Bind(&RecordFileProgressCallback, base::Unretained(&progress)), 854 base::Bind(&RecordFileProgressCallback, base::Unretained(&progress)),
854 base::TimeDelta()); // For testing, we need all the progress. 855 base::TimeDelta()); // For testing, we need all the progress.
855 856
856 // Call Cancel() later. 857 // Call Cancel() later.
857 base::MessageLoopProxy::current()->PostTask( 858 base::ThreadTaskRunnerHandle::Get()->PostTask(
858 FROM_HERE, 859 FROM_HERE,
859 base::Bind(&CopyOrMoveOperationDelegate::StreamCopyHelper::Cancel, 860 base::Bind(&CopyOrMoveOperationDelegate::StreamCopyHelper::Cancel,
860 base::Unretained(&helper))); 861 base::Unretained(&helper)));
861 862
862 base::File::Error error = base::File::FILE_ERROR_FAILED; 863 base::File::Error error = base::File::FILE_ERROR_FAILED;
863 base::RunLoop run_loop; 864 base::RunLoop run_loop;
864 helper.Run(base::Bind(&AssignAndQuit, &run_loop, &error)); 865 helper.Run(base::Bind(&AssignAndQuit, &run_loop, &error));
865 run_loop.Run(); 866 run_loop.Run();
866 867
867 EXPECT_EQ(base::File::FILE_ERROR_ABORT, error); 868 EXPECT_EQ(base::File::FILE_ERROR_ABORT, error);
868 } 869 }
869 870
870 } // namespace content 871 } // namespace content
OLDNEW
« no previous file with comments | « content/browser/fileapi/copy_or_move_file_validator_unittest.cc ('k') | content/browser/fileapi/dragged_file_util_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698