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

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

Issue 137923003: Change fileapi namespace to content for files that are moved under content/ (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: build fix 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 "base/basictypes.h" 5 #include "base/basictypes.h"
6 #include "base/bind.h" 6 #include "base/bind.h"
7 #include "base/files/file_path.h" 7 #include "base/files/file_path.h"
8 #include "base/files/scoped_temp_dir.h" 8 #include "base/files/scoped_temp_dir.h"
9 #include "base/run_loop.h" 9 #include "base/run_loop.h"
10 #include "content/public/test/test_file_system_backend.h" 10 #include "content/public/test/test_file_system_backend.h"
11 #include "content/public/test/test_file_system_context.h" 11 #include "content/public/test/test_file_system_context.h"
12 #include "testing/gtest/include/gtest/gtest.h" 12 #include "testing/gtest/include/gtest/gtest.h"
13 #include "webkit/browser/fileapi/async_file_test_helper.h" 13 #include "webkit/browser/fileapi/async_file_test_helper.h"
14 #include "webkit/browser/fileapi/copy_or_move_file_validator.h" 14 #include "webkit/browser/fileapi/copy_or_move_file_validator.h"
15 #include "webkit/browser/fileapi/external_mount_points.h" 15 #include "webkit/browser/fileapi/external_mount_points.h"
16 #include "webkit/browser/fileapi/file_system_backend.h" 16 #include "webkit/browser/fileapi/file_system_backend.h"
17 #include "webkit/browser/fileapi/file_system_context.h" 17 #include "webkit/browser/fileapi/file_system_context.h"
18 #include "webkit/browser/fileapi/file_system_url.h" 18 #include "webkit/browser/fileapi/file_system_url.h"
19 #include "webkit/browser/fileapi/isolated_context.h" 19 #include "webkit/browser/fileapi/isolated_context.h"
20 #include "webkit/browser/quota/mock_special_storage_policy.h" 20 #include "webkit/browser/quota/mock_special_storage_policy.h"
21 #include "webkit/common/blob/shareable_file_reference.h" 21 #include "webkit/common/blob/shareable_file_reference.h"
22 #include "webkit/common/fileapi/file_system_util.h" 22 #include "webkit/common/fileapi/file_system_util.h"
23 23
24 namespace fileapi { 24 using fileapi::AsyncFileTestHelper;
25 using fileapi::CopyOrMoveFileValidator;
26 using fileapi::CopyOrMoveFileValidatorFactory;
27 using fileapi::FileSystemType;
28 using fileapi::FileSystemURL;
29
30 namespace content {
25 31
26 namespace { 32 namespace {
27 33
28 const FileSystemType kNoValidatorType = kFileSystemTypeTemporary; 34 const FileSystemType kNoValidatorType = fileapi::kFileSystemTypeTemporary;
29 const FileSystemType kWithValidatorType = kFileSystemTypeTest; 35 const FileSystemType kWithValidatorType = fileapi::kFileSystemTypeTest;
30 36
31 void ExpectOk(const GURL& origin_url, 37 void ExpectOk(const GURL& origin_url,
32 const std::string& name, 38 const std::string& name,
33 base::PlatformFileError error) { 39 base::PlatformFileError error) {
34 ASSERT_EQ(base::PLATFORM_FILE_OK, error); 40 ASSERT_EQ(base::PLATFORM_FILE_OK, error);
35 } 41 }
36 42
37 class CopyOrMoveFileValidatorTestHelper { 43 class CopyOrMoveFileValidatorTestHelper {
38 public: 44 public:
39 CopyOrMoveFileValidatorTestHelper( 45 CopyOrMoveFileValidatorTestHelper(
40 const GURL& origin, 46 const GURL& origin,
41 FileSystemType src_type, 47 FileSystemType src_type,
42 FileSystemType dest_type) 48 FileSystemType dest_type)
43 : origin_(origin), 49 : origin_(origin),
44 src_type_(src_type), 50 src_type_(src_type),
45 dest_type_(dest_type) {} 51 dest_type_(dest_type) {}
46 52
47 ~CopyOrMoveFileValidatorTestHelper() { 53 ~CopyOrMoveFileValidatorTestHelper() {
48 file_system_context_ = NULL; 54 file_system_context_ = NULL;
49 base::RunLoop().RunUntilIdle(); 55 base::RunLoop().RunUntilIdle();
50 } 56 }
51 57
52 void SetUp() { 58 void SetUp() {
53 ASSERT_TRUE(base_.CreateUniqueTempDir()); 59 ASSERT_TRUE(base_.CreateUniqueTempDir());
54 base::FilePath base_dir = base_.path(); 60 base::FilePath base_dir = base_.path();
55 61
56 file_system_context_ = CreateFileSystemContextForTesting(NULL, base_dir); 62 file_system_context_ = CreateFileSystemContextForTesting(NULL, base_dir);
57 63
58 // Set up TestFileSystemBackend to require CopyOrMoveFileValidator. 64 // Set up TestFileSystemBackend to require CopyOrMoveFileValidator.
59 FileSystemBackend* test_file_system_backend = 65 fileapi::FileSystemBackend* test_file_system_backend =
60 file_system_context_->GetFileSystemBackend(kWithValidatorType); 66 file_system_context_->GetFileSystemBackend(kWithValidatorType);
61 static_cast<TestFileSystemBackend*>(test_file_system_backend)-> 67 static_cast<TestFileSystemBackend*>(test_file_system_backend)->
62 set_require_copy_or_move_validator(true); 68 set_require_copy_or_move_validator(true);
63 69
64 // Sets up source. 70 // Sets up source.
65 FileSystemBackend* src_file_system_backend = 71 fileapi::FileSystemBackend* src_file_system_backend =
66 file_system_context_->GetFileSystemBackend(src_type_); 72 file_system_context_->GetFileSystemBackend(src_type_);
67 src_file_system_backend->OpenFileSystem( 73 src_file_system_backend->OpenFileSystem(
68 origin_, src_type_, 74 origin_, src_type_,
69 OPEN_FILE_SYSTEM_CREATE_IF_NONEXISTENT, 75 fileapi::OPEN_FILE_SYSTEM_CREATE_IF_NONEXISTENT,
70 base::Bind(&ExpectOk)); 76 base::Bind(&ExpectOk));
71 base::RunLoop().RunUntilIdle(); 77 base::RunLoop().RunUntilIdle();
72 ASSERT_EQ(base::PLATFORM_FILE_OK, CreateDirectory(SourceURL(""))); 78 ASSERT_EQ(base::PLATFORM_FILE_OK, CreateDirectory(SourceURL("")));
73 79
74 // Sets up dest. 80 // Sets up dest.
75 DCHECK_EQ(kWithValidatorType, dest_type_); 81 DCHECK_EQ(kWithValidatorType, dest_type_);
76 ASSERT_EQ(base::PLATFORM_FILE_OK, CreateDirectory(DestURL(""))); 82 ASSERT_EQ(base::PLATFORM_FILE_OK, CreateDirectory(DestURL("")));
77 83
78 copy_src_ = SourceURL("copy_src.jpg"); 84 copy_src_ = SourceURL("copy_src.jpg");
79 move_src_ = SourceURL("move_src.jpg"); 85 move_src_ = SourceURL("move_src.jpg");
80 copy_dest_ = DestURL("copy_dest.jpg"); 86 copy_dest_ = DestURL("copy_dest.jpg");
81 move_dest_ = DestURL("move_dest.jpg"); 87 move_dest_ = DestURL("move_dest.jpg");
82 88
83 ASSERT_EQ(base::PLATFORM_FILE_OK, CreateFile(copy_src_, 10)); 89 ASSERT_EQ(base::PLATFORM_FILE_OK, CreateFile(copy_src_, 10));
84 ASSERT_EQ(base::PLATFORM_FILE_OK, CreateFile(move_src_, 10)); 90 ASSERT_EQ(base::PLATFORM_FILE_OK, CreateFile(move_src_, 10));
85 91
86 ASSERT_TRUE(FileExists(copy_src_, 10)); 92 ASSERT_TRUE(FileExists(copy_src_, 10));
87 ASSERT_TRUE(FileExists(move_src_, 10)); 93 ASSERT_TRUE(FileExists(move_src_, 10));
88 ASSERT_FALSE(FileExists(copy_dest_, 10)); 94 ASSERT_FALSE(FileExists(copy_dest_, 10));
89 ASSERT_FALSE(FileExists(move_dest_, 10)); 95 ASSERT_FALSE(FileExists(move_dest_, 10));
90 } 96 }
91 97
92 void SetMediaCopyOrMoveFileValidatorFactory( 98 void SetMediaCopyOrMoveFileValidatorFactory(
93 scoped_ptr<CopyOrMoveFileValidatorFactory> factory) { 99 scoped_ptr<fileapi::CopyOrMoveFileValidatorFactory> factory) {
94 TestFileSystemBackend* backend = static_cast<TestFileSystemBackend*>( 100 TestFileSystemBackend* backend = static_cast<TestFileSystemBackend*>(
95 file_system_context_->GetFileSystemBackend(kWithValidatorType)); 101 file_system_context_->GetFileSystemBackend(kWithValidatorType));
96 backend->InitializeCopyOrMoveFileValidatorFactory(factory.Pass()); 102 backend->InitializeCopyOrMoveFileValidatorFactory(factory.Pass());
97 } 103 }
98 104
99 void CopyTest(base::PlatformFileError expected) { 105 void CopyTest(base::PlatformFileError expected) {
100 ASSERT_TRUE(FileExists(copy_src_, 10)); 106 ASSERT_TRUE(FileExists(copy_src_, 10));
101 ASSERT_FALSE(FileExists(copy_dest_, 10)); 107 ASSERT_FALSE(FileExists(copy_dest_, 10));
102 108
103 EXPECT_EQ(expected, 109 EXPECT_EQ(expected,
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after
163 base::ScopedTempDir base_; 169 base::ScopedTempDir base_;
164 170
165 const GURL origin_; 171 const GURL origin_;
166 172
167 const FileSystemType src_type_; 173 const FileSystemType src_type_;
168 const FileSystemType dest_type_; 174 const FileSystemType dest_type_;
169 std::string src_fsid_; 175 std::string src_fsid_;
170 std::string dest_fsid_; 176 std::string dest_fsid_;
171 177
172 base::MessageLoop message_loop_; 178 base::MessageLoop message_loop_;
173 scoped_refptr<FileSystemContext> file_system_context_; 179 scoped_refptr<fileapi::FileSystemContext> file_system_context_;
174 180
175 FileSystemURL copy_src_; 181 FileSystemURL copy_src_;
176 FileSystemURL copy_dest_; 182 FileSystemURL copy_dest_;
177 FileSystemURL move_src_; 183 FileSystemURL move_src_;
178 FileSystemURL move_dest_; 184 FileSystemURL move_dest_;
179 185
180 DISALLOW_COPY_AND_ASSIGN(CopyOrMoveFileValidatorTestHelper); 186 DISALLOW_COPY_AND_ASSIGN(CopyOrMoveFileValidatorTestHelper);
181 }; 187 };
182 188
183 // For TestCopyOrMoveFileValidatorFactory 189 // For TestCopyOrMoveFileValidatorFactory
184 enum Validity { 190 enum Validity {
185 VALID, 191 VALID,
186 PRE_WRITE_INVALID, 192 PRE_WRITE_INVALID,
187 POST_WRITE_INVALID 193 POST_WRITE_INVALID
188 }; 194 };
189 195
190 class TestCopyOrMoveFileValidatorFactory 196 class TestCopyOrMoveFileValidatorFactory
191 : public CopyOrMoveFileValidatorFactory { 197 : public fileapi::CopyOrMoveFileValidatorFactory {
192 public: 198 public:
193 // A factory that creates validators that accept everything or nothing. 199 // A factory that creates validators that accept everything or nothing.
194 // TODO(gbillock): switch args to enum or something 200 // TODO(gbillock): switch args to enum or something
195 explicit TestCopyOrMoveFileValidatorFactory(Validity validity) 201 explicit TestCopyOrMoveFileValidatorFactory(Validity validity)
196 : validity_(validity) {} 202 : validity_(validity) {}
197 virtual ~TestCopyOrMoveFileValidatorFactory() {} 203 virtual ~TestCopyOrMoveFileValidatorFactory() {}
198 204
199 virtual CopyOrMoveFileValidator* CreateCopyOrMoveFileValidator( 205 virtual fileapi::CopyOrMoveFileValidator* CreateCopyOrMoveFileValidator(
200 const FileSystemURL& /*src_url*/, 206 const FileSystemURL& /*src_url*/,
201 const base::FilePath& /*platform_path*/) OVERRIDE { 207 const base::FilePath& /*platform_path*/) OVERRIDE {
202 return new TestCopyOrMoveFileValidator(validity_); 208 return new TestCopyOrMoveFileValidator(validity_);
203 } 209 }
204 210
205 private: 211 private:
206 class TestCopyOrMoveFileValidator : public CopyOrMoveFileValidator { 212 class TestCopyOrMoveFileValidator : public CopyOrMoveFileValidator {
207 public: 213 public:
208 explicit TestCopyOrMoveFileValidator(Validity validity) 214 explicit TestCopyOrMoveFileValidator(Validity validity)
209 : result_(validity == VALID || validity == POST_WRITE_INVALID 215 : result_(validity == VALID || validity == POST_WRITE_INVALID
(...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after
316 kWithValidatorType); 322 kWithValidatorType);
317 helper.SetUp(); 323 helper.SetUp();
318 scoped_ptr<CopyOrMoveFileValidatorFactory> factory( 324 scoped_ptr<CopyOrMoveFileValidatorFactory> factory(
319 new TestCopyOrMoveFileValidatorFactory(POST_WRITE_INVALID)); 325 new TestCopyOrMoveFileValidatorFactory(POST_WRITE_INVALID));
320 helper.SetMediaCopyOrMoveFileValidatorFactory(factory.Pass()); 326 helper.SetMediaCopyOrMoveFileValidatorFactory(factory.Pass());
321 327
322 helper.CopyTest(base::PLATFORM_FILE_ERROR_SECURITY); 328 helper.CopyTest(base::PLATFORM_FILE_ERROR_SECURITY);
323 helper.MoveTest(base::PLATFORM_FILE_ERROR_SECURITY); 329 helper.MoveTest(base::PLATFORM_FILE_ERROR_SECURITY);
324 } 330 }
325 331
326 } // namespace fileapi 332 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698