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

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

Issue 21097005: Fix up some tests for copy-or-move validator and nearby. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: enum simplification Created 7 years, 4 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 (c) 2013 The Chromium Authors. All rights reserved. 1 // Copyright (c) 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/scoped_temp_dir.h" 10 #include "base/files/scoped_temp_dir.h"
(...skipping 28 matching lines...) Expand all
39 39
40 class TestValidatorFactory : public CopyOrMoveFileValidatorFactory { 40 class TestValidatorFactory : public CopyOrMoveFileValidatorFactory {
41 public: 41 public:
42 // A factory that creates validators that accept everything or nothing. 42 // A factory that creates validators that accept everything or nothing.
43 TestValidatorFactory() {} 43 TestValidatorFactory() {}
44 virtual ~TestValidatorFactory() {} 44 virtual ~TestValidatorFactory() {}
45 45
46 virtual CopyOrMoveFileValidator* CreateCopyOrMoveFileValidator( 46 virtual CopyOrMoveFileValidator* CreateCopyOrMoveFileValidator(
47 const FileSystemURL& /*src_url*/, 47 const FileSystemURL& /*src_url*/,
48 const base::FilePath& /*platform_path*/) OVERRIDE { 48 const base::FilePath& /*platform_path*/) OVERRIDE {
49 // Move arg management to TestValidator?
49 return new TestValidator(true, true, std::string("2")); 50 return new TestValidator(true, true, std::string("2"));
50 } 51 }
51 52
52 private: 53 private:
53 class TestValidator : public CopyOrMoveFileValidator { 54 class TestValidator : public CopyOrMoveFileValidator {
54 public: 55 public:
55 explicit TestValidator(bool pre_copy_valid, 56 explicit TestValidator(bool pre_copy_valid,
56 bool post_copy_valid, 57 bool post_copy_valid,
57 const std::string& reject_string) 58 const std::string& reject_string)
58 : result_(pre_copy_valid ? base::PLATFORM_FILE_OK 59 : result_(pre_copy_valid ? base::PLATFORM_FILE_OK
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
106 107
107 ~CopyOrMoveOperationTestHelper() { 108 ~CopyOrMoveOperationTestHelper() {
108 file_system_context_ = NULL; 109 file_system_context_ = NULL;
109 quota_manager_proxy_->SimulateQuotaManagerDestroyed(); 110 quota_manager_proxy_->SimulateQuotaManagerDestroyed();
110 quota_manager_ = NULL; 111 quota_manager_ = NULL;
111 quota_manager_proxy_ = NULL; 112 quota_manager_proxy_ = NULL;
112 base::MessageLoop::current()->RunUntilIdle(); 113 base::MessageLoop::current()->RunUntilIdle();
113 } 114 }
114 115
115 void SetUp() { 116 void SetUp() {
117 SetUp(true, true);
118 }
119
120 void SetUpNoValidator() {
121 SetUp(true, false);
122 }
123
124 void SetUp(bool require_copy_or_move_validator,
125 bool init_copy_or_move_validator) {
116 ASSERT_TRUE(base_.CreateUniqueTempDir()); 126 ASSERT_TRUE(base_.CreateUniqueTempDir());
117 base::FilePath base_dir = base_.path(); 127 base::FilePath base_dir = base_.path();
118 quota_manager_ = 128 quota_manager_ =
119 new quota::MockQuotaManager(false /* is_incognito */, 129 new quota::MockQuotaManager(false /* is_incognito */,
120 base_dir, 130 base_dir,
121 base::MessageLoopProxy::current().get(), 131 base::MessageLoopProxy::current().get(),
122 base::MessageLoopProxy::current().get(), 132 base::MessageLoopProxy::current().get(),
123 NULL /* special storage policy */); 133 NULL /* special storage policy */);
124 quota_manager_proxy_ = new quota::MockQuotaManagerProxy( 134 quota_manager_proxy_ = new quota::MockQuotaManagerProxy(
125 quota_manager_.get(), base::MessageLoopProxy::current().get()); 135 quota_manager_.get(), base::MessageLoopProxy::current().get());
126 file_system_context_ = 136 file_system_context_ =
127 CreateFileSystemContextForTesting(quota_manager_proxy_.get(), base_dir); 137 CreateFileSystemContextForTesting(quota_manager_proxy_.get(), base_dir);
128 138
129 // Prepare the origin's root directory. 139 // Prepare the origin's root directory.
130 FileSystemBackend* backend = 140 FileSystemBackend* backend =
131 file_system_context_->GetFileSystemBackend(src_type_); 141 file_system_context_->GetFileSystemBackend(src_type_);
132 backend->OpenFileSystem(origin_, src_type_, 142 backend->OpenFileSystem(origin_, src_type_,
133 OPEN_FILE_SYSTEM_CREATE_IF_NONEXISTENT, 143 OPEN_FILE_SYSTEM_CREATE_IF_NONEXISTENT,
134 base::Bind(&ExpectOk)); 144 base::Bind(&ExpectOk));
135 backend = file_system_context_->GetFileSystemBackend(dest_type_); 145 backend = file_system_context_->GetFileSystemBackend(dest_type_);
136 if (dest_type_ == kFileSystemTypeTest) { 146 if (dest_type_ == kFileSystemTypeTest) {
137 TestFileSystemBackend* test_backend = 147 TestFileSystemBackend* test_backend =
138 static_cast<TestFileSystemBackend*>(backend); 148 static_cast<TestFileSystemBackend*>(backend);
139 scoped_ptr<CopyOrMoveFileValidatorFactory> factory( 149 scoped_ptr<CopyOrMoveFileValidatorFactory> factory(
140 new TestValidatorFactory); 150 new TestValidatorFactory);
141 test_backend->set_require_copy_or_move_validator(true); 151 test_backend->set_require_copy_or_move_validator(
142 test_backend->InitializeCopyOrMoveFileValidatorFactory(factory.Pass()); 152 require_copy_or_move_validator);
153 if (init_copy_or_move_validator)
154 test_backend->InitializeCopyOrMoveFileValidatorFactory(factory.Pass());
143 } 155 }
144 backend->OpenFileSystem(origin_, dest_type_, 156 backend->OpenFileSystem(origin_, dest_type_,
145 OPEN_FILE_SYSTEM_CREATE_IF_NONEXISTENT, 157 OPEN_FILE_SYSTEM_CREATE_IF_NONEXISTENT,
146 base::Bind(&ExpectOk)); 158 base::Bind(&ExpectOk));
147 base::MessageLoop::current()->RunUntilIdle(); 159 base::MessageLoop::current()->RunUntilIdle();
148 160
149 // Grant relatively big quota initially. 161 // Grant relatively big quota initially.
150 quota_manager_->SetQuota(origin_, 162 quota_manager_->SetQuota(origin_,
151 FileSystemTypeToQuotaStorageType(src_type_), 163 FileSystemTypeToQuotaStorageType(src_type_),
152 1024 * 1024); 164 1024 * 1024);
(...skipping 369 matching lines...) Expand 10 before | Expand all | Expand 10 after
522 test::TestCaseRecord kMoveDirResultCases[] = { 534 test::TestCaseRecord kMoveDirResultCases[] = {
523 {false, FILE_PATH_LITERAL("file 0"), 38}, 535 {false, FILE_PATH_LITERAL("file 0"), 38},
524 {false, FILE_PATH_LITERAL("file 3"), 0}, 536 {false, FILE_PATH_LITERAL("file 3"), 0},
525 }; 537 };
526 538
527 helper.VerifyTestCaseFiles(dest, 539 helper.VerifyTestCaseFiles(dest,
528 kMoveDirResultCases, 540 kMoveDirResultCases,
529 arraysize(kMoveDirResultCases)); 541 arraysize(kMoveDirResultCases));
530 } 542 }
531 543
544 TEST(LocalFileSystemCopyOrMoveOperationTest, CopySingleFileNoValidator) {
545 CopyOrMoveOperationTestHelper helper(GURL("http://foo"),
546 kFileSystemTypeTemporary,
547 kFileSystemTypeTest);
548 helper.SetUpNoValidator();
549
550 FileSystemURL src = helper.SourceURL("a");
551 FileSystemURL dest = helper.DestURL("b");
552
553 // Set up a source file.
554 ASSERT_EQ(base::PLATFORM_FILE_OK, helper.CreateFile(src, 10));
555
556 // The copy attempt should fail with a security error -- getting
557 // the factory returns a security error, and the copy operation must
558 // respect that.
559 ASSERT_EQ(base::PLATFORM_FILE_ERROR_SECURITY, helper.Copy(src, dest));
560 }
561
532 } // namespace fileapi 562 } // namespace fileapi
OLDNEW
« no previous file with comments | « webkit/browser/fileapi/copy_or_move_operation_delegate.cc ('k') | webkit/browser/fileapi/test_file_system_backend.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698