| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 "chrome/browser/extensions/api/image_writer_private/error_messages.h" | 5 #include "chrome/browser/extensions/api/image_writer_private/error_messages.h" |
| 6 #include "chrome/browser/extensions/api/image_writer_private/test_utils.h" | 6 #include "chrome/browser/extensions/api/image_writer_private/test_utils.h" |
| 7 #include "chrome/browser/extensions/api/image_writer_private/write_from_url_oper
ation.h" | 7 #include "chrome/browser/extensions/api/image_writer_private/write_from_url_oper
ation.h" |
| 8 #include "chrome/test/base/testing_profile.h" | 8 #include "chrome/test/base/testing_profile.h" |
| 9 #include "content/public/browser/browser_thread.h" | 9 #include "content/public/browser/browser_thread.h" |
| 10 #include "net/url_request/test_url_request_interceptor.h" | 10 #include "net/url_request/test_url_request_interceptor.h" |
| (...skipping 25 matching lines...) Expand all Loading... |
| 36 GURL url, | 36 GURL url, |
| 37 const std::string& hash, | 37 const std::string& hash, |
| 38 const std::string& storage_unit_id) | 38 const std::string& storage_unit_id) |
| 39 : WriteFromUrlOperation(manager_, | 39 : WriteFromUrlOperation(manager_, |
| 40 extension_id, | 40 extension_id, |
| 41 request_context, | 41 request_context, |
| 42 url, | 42 url, |
| 43 hash, | 43 hash, |
| 44 storage_unit_id) {} | 44 storage_unit_id) {} |
| 45 | 45 |
| 46 virtual void StartImpl() OVERRIDE {} | 46 virtual void StartImpl() override {} |
| 47 | 47 |
| 48 // Expose stages for testing. | 48 // Expose stages for testing. |
| 49 void GetDownloadTarget(const base::Closure& continuation) { | 49 void GetDownloadTarget(const base::Closure& continuation) { |
| 50 WriteFromUrlOperation::GetDownloadTarget(continuation); | 50 WriteFromUrlOperation::GetDownloadTarget(continuation); |
| 51 } | 51 } |
| 52 | 52 |
| 53 void Download(const base::Closure& continuation) { | 53 void Download(const base::Closure& continuation) { |
| 54 WriteFromUrlOperation::Download(continuation); | 54 WriteFromUrlOperation::Download(continuation); |
| 55 } | 55 } |
| 56 | 56 |
| 57 void VerifyDownload(const base::Closure& continuation) { | 57 void VerifyDownload(const base::Closure& continuation) { |
| 58 WriteFromUrlOperation::VerifyDownload(continuation); | 58 WriteFromUrlOperation::VerifyDownload(continuation); |
| 59 } | 59 } |
| 60 | 60 |
| 61 // Helpers to set-up state for intermediate stages. | 61 // Helpers to set-up state for intermediate stages. |
| 62 void SetImagePath(const base::FilePath image_path) { | 62 void SetImagePath(const base::FilePath image_path) { |
| 63 image_path_ = image_path; | 63 image_path_ = image_path; |
| 64 } | 64 } |
| 65 | 65 |
| 66 base::FilePath GetImagePath() { return image_path_; } | 66 base::FilePath GetImagePath() { return image_path_; } |
| 67 | 67 |
| 68 private: | 68 private: |
| 69 virtual ~OperationForTest() {}; | 69 virtual ~OperationForTest() {}; |
| 70 }; | 70 }; |
| 71 | 71 |
| 72 class ImageWriterWriteFromUrlOperationTest : public ImageWriterUnitTestBase { | 72 class ImageWriterWriteFromUrlOperationTest : public ImageWriterUnitTestBase { |
| 73 protected: | 73 protected: |
| 74 ImageWriterWriteFromUrlOperationTest() : manager_(&test_profile_) {} | 74 ImageWriterWriteFromUrlOperationTest() : manager_(&test_profile_) {} |
| 75 | 75 |
| 76 virtual void SetUp() OVERRIDE { | 76 virtual void SetUp() override { |
| 77 ImageWriterUnitTestBase::SetUp(); | 77 ImageWriterUnitTestBase::SetUp(); |
| 78 | 78 |
| 79 // Turn on interception and set up our dummy file. | 79 // Turn on interception and set up our dummy file. |
| 80 net::URLFetcher::SetEnableInterceptionForTests(true); | 80 net::URLFetcher::SetEnableInterceptionForTests(true); |
| 81 get_interceptor_.reset(new GetInterceptor( | 81 get_interceptor_.reset(new GetInterceptor( |
| 82 BrowserThread::GetMessageLoopProxyForThread(BrowserThread::IO), | 82 BrowserThread::GetMessageLoopProxyForThread(BrowserThread::IO), |
| 83 BrowserThread::GetBlockingPool()->GetTaskRunnerWithShutdownBehavior( | 83 BrowserThread::GetBlockingPool()->GetTaskRunnerWithShutdownBehavior( |
| 84 base::SequencedWorkerPool::SKIP_ON_SHUTDOWN))); | 84 base::SequencedWorkerPool::SKIP_ON_SHUTDOWN))); |
| 85 get_interceptor_->SetResponse(GURL(kTestImageUrl), | 85 get_interceptor_->SetResponse(GURL(kTestImageUrl), |
| 86 test_utils_.GetImagePath()); | 86 test_utils_.GetImagePath()); |
| 87 } | 87 } |
| 88 | 88 |
| 89 virtual void TearDown() OVERRIDE { | 89 virtual void TearDown() override { |
| 90 ImageWriterUnitTestBase::TearDown(); | 90 ImageWriterUnitTestBase::TearDown(); |
| 91 | 91 |
| 92 // Remember to turn off global interception. | 92 // Remember to turn off global interception. |
| 93 net::URLFetcher::SetEnableInterceptionForTests(false); | 93 net::URLFetcher::SetEnableInterceptionForTests(false); |
| 94 } | 94 } |
| 95 | 95 |
| 96 scoped_refptr<OperationForTest> CreateOperation(const GURL& url, | 96 scoped_refptr<OperationForTest> CreateOperation(const GURL& url, |
| 97 const std::string& hash) { | 97 const std::string& hash) { |
| 98 scoped_refptr<OperationForTest> operation( | 98 scoped_refptr<OperationForTest> operation( |
| 99 new OperationForTest(manager_.AsWeakPtr(), | 99 new OperationForTest(manager_.AsWeakPtr(), |
| (...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 210 | 210 |
| 211 base::RunLoop().RunUntilIdle(); | 211 base::RunLoop().RunUntilIdle(); |
| 212 | 212 |
| 213 operation->Cancel(); | 213 operation->Cancel(); |
| 214 } | 214 } |
| 215 | 215 |
| 216 } // namespace | 216 } // namespace |
| 217 | 217 |
| 218 } // namespace image_writer | 218 } // namespace image_writer |
| 219 } // namespace extensions | 219 } // namespace extensions |
| OLD | NEW |