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

Side by Side Diff: webkit/browser/fileapi/copy_or_move_file_validator_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: Add missing test 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 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/message_loop/message_loop.h" 9 #include "base/message_loop/message_loop.h"
10 #include "testing/gtest/include/gtest/gtest.h" 10 #include "testing/gtest/include/gtest/gtest.h"
(...skipping 165 matching lines...) Expand 10 before | Expand all | Expand 10 after
176 FileSystemURL copy_dest_; 176 FileSystemURL copy_dest_;
177 FileSystemURL move_src_; 177 FileSystemURL move_src_;
178 FileSystemURL move_dest_; 178 FileSystemURL move_dest_;
179 179
180 DISALLOW_COPY_AND_ASSIGN(CopyOrMoveFileValidatorTestHelper); 180 DISALLOW_COPY_AND_ASSIGN(CopyOrMoveFileValidatorTestHelper);
181 }; 181 };
182 182
183 class TestCopyOrMoveFileValidatorFactory 183 class TestCopyOrMoveFileValidatorFactory
184 : public CopyOrMoveFileValidatorFactory { 184 : public CopyOrMoveFileValidatorFactory {
185 public: 185 public:
186 enum Validity {
187 VALID,
188 PRE_WRITE_INVALID,
189 POST_WRITE_INVALID
190 };
kinuko 2013/08/01 07:37:24 nit: since we're in a test code, it might make the
Greg Billock 2013/08/01 16:23:05 sounds good. I'll keep the enum to move complexity
191
186 // A factory that creates validators that accept everything or nothing. 192 // A factory that creates validators that accept everything or nothing.
187 explicit TestCopyOrMoveFileValidatorFactory(bool all_valid, 193 // TODO(gbillock): switch args to enum or something
188 bool all_valid_write) 194 explicit TestCopyOrMoveFileValidatorFactory(Validity validity)
189 : all_valid_(all_valid), 195 : validity_(validity) {}
190 all_valid_write_(all_valid_write) {}
191 virtual ~TestCopyOrMoveFileValidatorFactory() {} 196 virtual ~TestCopyOrMoveFileValidatorFactory() {}
192 197
193 virtual CopyOrMoveFileValidator* CreateCopyOrMoveFileValidator( 198 virtual CopyOrMoveFileValidator* CreateCopyOrMoveFileValidator(
194 const FileSystemURL& /*src_url*/, 199 const FileSystemURL& /*src_url*/,
195 const base::FilePath& /*platform_path*/) OVERRIDE { 200 const base::FilePath& /*platform_path*/) OVERRIDE {
196 return new TestCopyOrMoveFileValidator(all_valid_, all_valid_write_); 201 return new TestCopyOrMoveFileValidator(validity_);
197 } 202 }
198 203
199 private: 204 private:
200 class TestCopyOrMoveFileValidator : public CopyOrMoveFileValidator { 205 class TestCopyOrMoveFileValidator : public CopyOrMoveFileValidator {
201 public: 206 public:
202 explicit TestCopyOrMoveFileValidator(bool pre_copy_valid, 207 explicit TestCopyOrMoveFileValidator(
203 bool post_copy_valid) 208 TestCopyOrMoveFileValidatorFactory::Validity validity)
204 : result_(pre_copy_valid ? base::PLATFORM_FILE_OK 209 : result_(validity == VALID || validity == POST_WRITE_INVALID
205 : base::PLATFORM_FILE_ERROR_SECURITY), 210 ? base::PLATFORM_FILE_OK
206 write_result_(post_copy_valid ? base::PLATFORM_FILE_OK 211 : base::PLATFORM_FILE_ERROR_SECURITY),
207 : base::PLATFORM_FILE_ERROR_SECURITY) { 212 write_result_(validity == VALID || validity == PRE_WRITE_INVALID
213 ? base::PLATFORM_FILE_OK
214 : base::PLATFORM_FILE_ERROR_SECURITY) {
208 } 215 }
209 virtual ~TestCopyOrMoveFileValidator() {} 216 virtual ~TestCopyOrMoveFileValidator() {}
210 217
211 virtual void StartPreWriteValidation( 218 virtual void StartPreWriteValidation(
212 const ResultCallback& result_callback) OVERRIDE { 219 const ResultCallback& result_callback) OVERRIDE {
213 // Post the result since a real validator must do work asynchronously. 220 // Post the result since a real validator must do work asynchronously.
214 base::MessageLoop::current()->PostTask( 221 base::MessageLoop::current()->PostTask(
215 FROM_HERE, base::Bind(result_callback, result_)); 222 FROM_HERE, base::Bind(result_callback, result_));
216 } 223 }
217 224
218 virtual void StartPostWriteValidation( 225 virtual void StartPostWriteValidation(
219 const base::FilePath& dest_platform_path, 226 const base::FilePath& dest_platform_path,
220 const ResultCallback& result_callback) OVERRIDE { 227 const ResultCallback& result_callback) OVERRIDE {
221 // Post the result since a real validator must do work asynchronously. 228 // Post the result since a real validator must do work asynchronously.
222 base::MessageLoop::current()->PostTask( 229 base::MessageLoop::current()->PostTask(
223 FROM_HERE, base::Bind(result_callback, write_result_)); 230 FROM_HERE, base::Bind(result_callback, write_result_));
224 } 231 }
225 232
226 private: 233 private:
227 base::PlatformFileError result_; 234 base::PlatformFileError result_;
228 base::PlatformFileError write_result_; 235 base::PlatformFileError write_result_;
229 236
230 DISALLOW_COPY_AND_ASSIGN(TestCopyOrMoveFileValidator); 237 DISALLOW_COPY_AND_ASSIGN(TestCopyOrMoveFileValidator);
231 }; 238 };
232 239
233 bool all_valid_; 240 Validity validity_;
234 bool all_valid_write_;
235 241
236 DISALLOW_COPY_AND_ASSIGN(TestCopyOrMoveFileValidatorFactory); 242 DISALLOW_COPY_AND_ASSIGN(TestCopyOrMoveFileValidatorFactory);
237 }; 243 };
238 244
239 } // namespace 245 } // namespace
240 246
241 TEST(CopyOrMoveFileValidatorTest, NoValidatorWithinSameFSType) { 247 TEST(CopyOrMoveFileValidatorTest, NoValidatorWithinSameFSType) {
242 // Within a file system type, validation is not expected, so it should 248 // Within a file system type, validation is not expected, so it should
243 // work for kWithValidatorType without a validator set. 249 // work for kWithValidatorType without a validator set.
244 CopyOrMoveFileValidatorTestHelper helper(GURL("http://foo"), 250 CopyOrMoveFileValidatorTestHelper helper(GURL("http://foo"),
(...skipping 14 matching lines...) Expand all
259 helper.CopyTest(base::PLATFORM_FILE_ERROR_SECURITY); 265 helper.CopyTest(base::PLATFORM_FILE_ERROR_SECURITY);
260 helper.MoveTest(base::PLATFORM_FILE_ERROR_SECURITY); 266 helper.MoveTest(base::PLATFORM_FILE_ERROR_SECURITY);
261 } 267 }
262 268
263 TEST(CopyOrMoveFileValidatorTest, AcceptAll) { 269 TEST(CopyOrMoveFileValidatorTest, AcceptAll) {
264 CopyOrMoveFileValidatorTestHelper helper(GURL("http://foo"), 270 CopyOrMoveFileValidatorTestHelper helper(GURL("http://foo"),
265 kNoValidatorType, 271 kNoValidatorType,
266 kWithValidatorType); 272 kWithValidatorType);
267 helper.SetUp(); 273 helper.SetUp();
268 scoped_ptr<CopyOrMoveFileValidatorFactory> factory( 274 scoped_ptr<CopyOrMoveFileValidatorFactory> factory(
269 new TestCopyOrMoveFileValidatorFactory(true, true /*accept_all*/)); 275 new TestCopyOrMoveFileValidatorFactory(
276 TestCopyOrMoveFileValidatorFactory::VALID));
270 helper.SetMediaCopyOrMoveFileValidatorFactory(factory.Pass()); 277 helper.SetMediaCopyOrMoveFileValidatorFactory(factory.Pass());
271 278
272 helper.CopyTest(base::PLATFORM_FILE_OK); 279 helper.CopyTest(base::PLATFORM_FILE_OK);
273 helper.MoveTest(base::PLATFORM_FILE_OK); 280 helper.MoveTest(base::PLATFORM_FILE_OK);
274 } 281 }
275 282
276 TEST(CopyOrMoveFileValidatorTest, AcceptNone) { 283 TEST(CopyOrMoveFileValidatorTest, AcceptNone) {
277 CopyOrMoveFileValidatorTestHelper helper(GURL("http://foo"), 284 CopyOrMoveFileValidatorTestHelper helper(GURL("http://foo"),
278 kNoValidatorType, 285 kNoValidatorType,
279 kWithValidatorType); 286 kWithValidatorType);
280 helper.SetUp(); 287 helper.SetUp();
281 scoped_ptr<CopyOrMoveFileValidatorFactory> factory( 288 scoped_ptr<CopyOrMoveFileValidatorFactory> factory(
282 new TestCopyOrMoveFileValidatorFactory(false, false /*accept_all*/)); 289 new TestCopyOrMoveFileValidatorFactory(
290 TestCopyOrMoveFileValidatorFactory::PRE_WRITE_INVALID));
283 helper.SetMediaCopyOrMoveFileValidatorFactory(factory.Pass()); 291 helper.SetMediaCopyOrMoveFileValidatorFactory(factory.Pass());
284 292
285 helper.CopyTest(base::PLATFORM_FILE_ERROR_SECURITY); 293 helper.CopyTest(base::PLATFORM_FILE_ERROR_SECURITY);
286 helper.MoveTest(base::PLATFORM_FILE_ERROR_SECURITY); 294 helper.MoveTest(base::PLATFORM_FILE_ERROR_SECURITY);
287 } 295 }
288 296
289 TEST(CopyOrMoveFileValidatorTest, OverrideValidator) { 297 TEST(CopyOrMoveFileValidatorTest, OverrideValidator) {
290 // Once set, you can not override the validator. 298 // Once set, you can not override the validator.
291 CopyOrMoveFileValidatorTestHelper helper(GURL("http://foo"), 299 CopyOrMoveFileValidatorTestHelper helper(GURL("http://foo"),
292 kNoValidatorType, 300 kNoValidatorType,
293 kWithValidatorType); 301 kWithValidatorType);
294 helper.SetUp(); 302 helper.SetUp();
295 scoped_ptr<CopyOrMoveFileValidatorFactory> reject_factory( 303 scoped_ptr<CopyOrMoveFileValidatorFactory> reject_factory(
296 new TestCopyOrMoveFileValidatorFactory(false, false /*accept_all*/)); 304 new TestCopyOrMoveFileValidatorFactory(
305 TestCopyOrMoveFileValidatorFactory::PRE_WRITE_INVALID));
297 helper.SetMediaCopyOrMoveFileValidatorFactory(reject_factory.Pass()); 306 helper.SetMediaCopyOrMoveFileValidatorFactory(reject_factory.Pass());
298 307
299 scoped_ptr<CopyOrMoveFileValidatorFactory> accept_factory( 308 scoped_ptr<CopyOrMoveFileValidatorFactory> accept_factory(
300 new TestCopyOrMoveFileValidatorFactory(true, true /*accept_all*/)); 309 new TestCopyOrMoveFileValidatorFactory(
310 TestCopyOrMoveFileValidatorFactory::VALID));
301 helper.SetMediaCopyOrMoveFileValidatorFactory(accept_factory.Pass()); 311 helper.SetMediaCopyOrMoveFileValidatorFactory(accept_factory.Pass());
302 312
303 helper.CopyTest(base::PLATFORM_FILE_ERROR_SECURITY); 313 helper.CopyTest(base::PLATFORM_FILE_ERROR_SECURITY);
304 helper.MoveTest(base::PLATFORM_FILE_ERROR_SECURITY); 314 helper.MoveTest(base::PLATFORM_FILE_ERROR_SECURITY);
305 } 315 }
306 316
307 TEST(CopyOrMoveFileValidatorTest, RejectPostWrite) { 317 TEST(CopyOrMoveFileValidatorTest, RejectPostWrite) {
308 CopyOrMoveFileValidatorTestHelper helper(GURL("http://foo"), 318 CopyOrMoveFileValidatorTestHelper helper(GURL("http://foo"),
309 kNoValidatorType, 319 kNoValidatorType,
310 kWithValidatorType); 320 kWithValidatorType);
311 helper.SetUp(); 321 helper.SetUp();
312 scoped_ptr<CopyOrMoveFileValidatorFactory> factory( 322 scoped_ptr<CopyOrMoveFileValidatorFactory> factory(
313 // accept pre-copy, reject post-copy 323 new TestCopyOrMoveFileValidatorFactory(
314 new TestCopyOrMoveFileValidatorFactory(true, false)); 324 TestCopyOrMoveFileValidatorFactory::POST_WRITE_INVALID));
315 helper.SetMediaCopyOrMoveFileValidatorFactory(factory.Pass()); 325 helper.SetMediaCopyOrMoveFileValidatorFactory(factory.Pass());
316 326
317 helper.CopyTest(base::PLATFORM_FILE_ERROR_SECURITY); 327 helper.CopyTest(base::PLATFORM_FILE_ERROR_SECURITY);
318 helper.MoveTest(base::PLATFORM_FILE_ERROR_SECURITY); 328 helper.MoveTest(base::PLATFORM_FILE_ERROR_SECURITY);
319 } 329 }
320 330
321 } // namespace fileapi 331 } // namespace fileapi
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698