OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 "content/public/test/test_file_error_injector.h" | 5 #include "content/public/test/test_file_error_injector.h" |
6 | 6 |
7 #include <vector> | 7 #include <vector> |
8 | 8 |
9 #include "base/compiler_specific.h" | 9 #include "base/compiler_specific.h" |
10 #include "base/logging.h" | 10 #include "base/logging.h" |
(...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
123 // one (as happens during download resumption), then the DestructionCallback | 123 // one (as happens during download resumption), then the DestructionCallback |
124 // for the old DownloadFile is run before the ConstructionCallback for the | 124 // for the old DownloadFile is run before the ConstructionCallback for the |
125 // next DownloadFile. | 125 // next DownloadFile. |
126 BrowserThread::PostTask( | 126 BrowserThread::PostTask( |
127 BrowserThread::FILE, | 127 BrowserThread::FILE, |
128 FROM_HERE, | 128 FROM_HERE, |
129 base::Bind(ctor_callback, source_url_)); | 129 base::Bind(ctor_callback, source_url_)); |
130 } | 130 } |
131 | 131 |
132 DownloadFileWithErrors::~DownloadFileWithErrors() { | 132 DownloadFileWithErrors::~DownloadFileWithErrors() { |
133 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); | 133 DCHECK_CURRENTLY_ON(BrowserThread::FILE); |
134 destruction_callback_.Run(source_url_); | 134 destruction_callback_.Run(source_url_); |
135 } | 135 } |
136 | 136 |
137 void DownloadFileWithErrors::Initialize( | 137 void DownloadFileWithErrors::Initialize( |
138 const InitializeCallback& callback) { | 138 const InitializeCallback& callback) { |
139 DownloadInterruptReason error_to_return = DOWNLOAD_INTERRUPT_REASON_NONE; | 139 DownloadInterruptReason error_to_return = DOWNLOAD_INTERRUPT_REASON_NONE; |
140 InitializeCallback callback_to_use = callback; | 140 InitializeCallback callback_to_use = callback; |
141 | 141 |
142 // Replace callback if the error needs to be overwritten. | 142 // Replace callback if the error needs to be overwritten. |
143 if (OverwriteError( | 143 if (OverwriteError( |
(...skipping 210 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
354 created_factory_); | 354 created_factory_); |
355 | 355 |
356 download_manager_->SetDownloadFileFactoryForTesting( | 356 download_manager_->SetDownloadFileFactoryForTesting( |
357 download_file_factory.Pass()); | 357 download_file_factory.Pass()); |
358 } | 358 } |
359 | 359 |
360 TestFileErrorInjector::~TestFileErrorInjector() { | 360 TestFileErrorInjector::~TestFileErrorInjector() { |
361 } | 361 } |
362 | 362 |
363 bool TestFileErrorInjector::AddError(const FileErrorInfo& error_info) { | 363 bool TestFileErrorInjector::AddError(const FileErrorInfo& error_info) { |
364 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 364 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
365 DCHECK_LE(0, error_info.operation_instance); | 365 DCHECK_LE(0, error_info.operation_instance); |
366 DCHECK(injected_errors_.find(error_info.url) == injected_errors_.end()); | 366 DCHECK(injected_errors_.find(error_info.url) == injected_errors_.end()); |
367 | 367 |
368 // Creates an empty entry if necessary. | 368 // Creates an empty entry if necessary. |
369 injected_errors_[error_info.url] = error_info; | 369 injected_errors_[error_info.url] = error_info; |
370 | 370 |
371 return true; | 371 return true; |
372 } | 372 } |
373 | 373 |
374 void TestFileErrorInjector::ClearErrors() { | 374 void TestFileErrorInjector::ClearErrors() { |
375 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 375 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
376 injected_errors_.clear(); | 376 injected_errors_.clear(); |
377 } | 377 } |
378 | 378 |
379 bool TestFileErrorInjector::InjectErrors() { | 379 bool TestFileErrorInjector::InjectErrors() { |
380 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 380 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
381 | 381 |
382 ClearFoundFiles(); | 382 ClearFoundFiles(); |
383 | 383 |
384 DCHECK_EQ(static_cast<DownloadFileFactory*>(created_factory_), | 384 DCHECK_EQ(static_cast<DownloadFileFactory*>(created_factory_), |
385 download_manager_->GetDownloadFileFactoryForTesting()); | 385 download_manager_->GetDownloadFileFactoryForTesting()); |
386 | 386 |
387 created_factory_->ClearErrors(); | 387 created_factory_->ClearErrors(); |
388 | 388 |
389 for (ErrorMap::const_iterator it = injected_errors_.begin(); | 389 for (ErrorMap::const_iterator it = injected_errors_.begin(); |
390 it != injected_errors_.end(); ++it) | 390 it != injected_errors_.end(); ++it) |
391 created_factory_->AddError(it->second); | 391 created_factory_->AddError(it->second); |
392 | 392 |
393 return true; | 393 return true; |
394 } | 394 } |
395 | 395 |
396 size_t TestFileErrorInjector::CurrentFileCount() const { | 396 size_t TestFileErrorInjector::CurrentFileCount() const { |
397 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 397 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
398 return files_.size(); | 398 return files_.size(); |
399 } | 399 } |
400 | 400 |
401 size_t TestFileErrorInjector::TotalFileCount() const { | 401 size_t TestFileErrorInjector::TotalFileCount() const { |
402 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 402 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
403 return found_files_.size(); | 403 return found_files_.size(); |
404 } | 404 } |
405 | 405 |
406 | 406 |
407 bool TestFileErrorInjector::HadFile(const GURL& url) const { | 407 bool TestFileErrorInjector::HadFile(const GURL& url) const { |
408 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 408 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
409 | 409 |
410 return (found_files_.find(url) != found_files_.end()); | 410 return (found_files_.find(url) != found_files_.end()); |
411 } | 411 } |
412 | 412 |
413 void TestFileErrorInjector::ClearFoundFiles() { | 413 void TestFileErrorInjector::ClearFoundFiles() { |
414 found_files_.clear(); | 414 found_files_.clear(); |
415 } | 415 } |
416 | 416 |
417 void TestFileErrorInjector::DownloadFileCreated(GURL url) { | 417 void TestFileErrorInjector::DownloadFileCreated(GURL url) { |
418 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 418 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
419 DCHECK(files_.find(url) == files_.end()); | 419 DCHECK(files_.find(url) == files_.end()); |
420 | 420 |
421 files_.insert(url); | 421 files_.insert(url); |
422 found_files_.insert(url); | 422 found_files_.insert(url); |
423 } | 423 } |
424 | 424 |
425 void TestFileErrorInjector::DestroyingDownloadFile(GURL url) { | 425 void TestFileErrorInjector::DestroyingDownloadFile(GURL url) { |
426 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 426 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
427 DCHECK(files_.find(url) != files_.end()); | 427 DCHECK(files_.find(url) != files_.end()); |
428 | 428 |
429 files_.erase(url); | 429 files_.erase(url); |
430 } | 430 } |
431 | 431 |
432 void TestFileErrorInjector::RecordDownloadFileConstruction(const GURL& url) { | 432 void TestFileErrorInjector::RecordDownloadFileConstruction(const GURL& url) { |
433 BrowserThread::PostTask( | 433 BrowserThread::PostTask( |
434 BrowserThread::UI, | 434 BrowserThread::UI, |
435 FROM_HERE, | 435 FROM_HERE, |
436 base::Bind(&TestFileErrorInjector::DownloadFileCreated, this, url)); | 436 base::Bind(&TestFileErrorInjector::DownloadFileCreated, this, url)); |
(...skipping 29 matching lines...) Expand all Loading... |
466 case FILE_OPERATION_RENAME_ANNOTATE: | 466 case FILE_OPERATION_RENAME_ANNOTATE: |
467 return "RENAME_ANNOTATE"; | 467 return "RENAME_ANNOTATE"; |
468 default: | 468 default: |
469 break; | 469 break; |
470 } | 470 } |
471 | 471 |
472 return "Unknown"; | 472 return "Unknown"; |
473 } | 473 } |
474 | 474 |
475 } // namespace content | 475 } // namespace content |
OLD | NEW |