| OLD | NEW |
| 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/bind.h" | 5 #include "base/bind.h" |
| 6 #include "base/file_util.h" | 6 #include "base/file_util.h" |
| 7 #include "base/files/file_path.h" | 7 #include "base/files/file_path.h" |
| 8 #include "base/memory/ref_counted.h" | 8 #include "base/memory/ref_counted.h" |
| 9 #include "base/memory/scoped_ptr.h" | 9 #include "base/memory/scoped_ptr.h" |
| 10 #include "base/path_service.h" | 10 #include "base/path_service.h" |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 42 virtual ~CrxDownloaderTest(); | 42 virtual ~CrxDownloaderTest(); |
| 43 | 43 |
| 44 // Overrides from testing::Test. | 44 // Overrides from testing::Test. |
| 45 virtual void SetUp() OVERRIDE; | 45 virtual void SetUp() OVERRIDE; |
| 46 virtual void TearDown() OVERRIDE; | 46 virtual void TearDown() OVERRIDE; |
| 47 | 47 |
| 48 void Quit(); | 48 void Quit(); |
| 49 void RunThreads(); | 49 void RunThreads(); |
| 50 void RunThreadsUntilIdle(); | 50 void RunThreadsUntilIdle(); |
| 51 | 51 |
| 52 void DownloadComplete(int crx_context, | 52 void DownloadComplete(int crx_context, const CrxDownloader::Result& result); |
| 53 int error, | |
| 54 const base::FilePath& response); | |
| 55 | 53 |
| 56 protected: | 54 protected: |
| 57 scoped_ptr<CrxDownloader> crx_downloader_; | 55 scoped_ptr<CrxDownloader> crx_downloader_; |
| 58 | 56 |
| 59 int crx_context_; | 57 int crx_context_; |
| 60 int error_; | 58 int error_; |
| 59 base::FilePath response_; |
| 61 | 60 |
| 62 int num_calls_; | 61 int num_calls_; |
| 63 | 62 |
| 64 // A magic value for the context to be used in the tests. | 63 // A magic value for the context to be used in the tests. |
| 65 static const int kExpectedContext = 0xaabb; | 64 static const int kExpectedContext = 0xaabb; |
| 66 | 65 |
| 67 private: | 66 private: |
| 68 scoped_refptr<base::SequencedTaskRunner> blocking_task_runner_; | 67 scoped_refptr<base::SequencedTaskRunner> blocking_task_runner_; |
| 69 scoped_refptr<net::TestURLRequestContextGetter> context_; | 68 scoped_refptr<net::TestURLRequestContextGetter> context_; |
| 70 content::TestBrowserThreadBundle thread_bundle_; | 69 content::TestBrowserThreadBundle thread_bundle_; |
| (...skipping 15 matching lines...) Expand all Loading... |
| 86 thread_bundle_(content::TestBrowserThreadBundle::IO_MAINLOOP) { | 85 thread_bundle_(content::TestBrowserThreadBundle::IO_MAINLOOP) { |
| 87 } | 86 } |
| 88 | 87 |
| 89 CrxDownloaderTest::~CrxDownloaderTest() { | 88 CrxDownloaderTest::~CrxDownloaderTest() { |
| 90 context_ = 0; | 89 context_ = 0; |
| 91 } | 90 } |
| 92 | 91 |
| 93 void CrxDownloaderTest::SetUp() { | 92 void CrxDownloaderTest::SetUp() { |
| 94 num_calls_ = 0; | 93 num_calls_ = 0; |
| 95 crx_downloader_.reset(CrxDownloader::Create( | 94 crx_downloader_.reset(CrxDownloader::Create( |
| 95 false, // Do not use the background downloader in these tests. |
| 96 context_.get(), | 96 context_.get(), |
| 97 blocking_task_runner_, | 97 blocking_task_runner_, |
| 98 base::Bind(&CrxDownloaderTest::DownloadComplete, | 98 base::Bind(&CrxDownloaderTest::DownloadComplete, |
| 99 base::Unretained(this), | 99 base::Unretained(this), |
| 100 kExpectedContext))); | 100 kExpectedContext))); |
| 101 } | 101 } |
| 102 | 102 |
| 103 void CrxDownloaderTest::TearDown() { | 103 void CrxDownloaderTest::TearDown() { |
| 104 } | 104 } |
| 105 | 105 |
| 106 void CrxDownloaderTest::Quit() { | 106 void CrxDownloaderTest::Quit() { |
| 107 quit_closure_.Run(); | 107 quit_closure_.Run(); |
| 108 } | 108 } |
| 109 | 109 |
| 110 void CrxDownloaderTest::DownloadComplete(int crx_context, | 110 void CrxDownloaderTest::DownloadComplete( |
| 111 int error, | 111 int crx_context, |
| 112 const base::FilePath& response) { | 112 const CrxDownloader::Result& result) { |
| 113 ++num_calls_; | 113 ++num_calls_; |
| 114 crx_context_ = crx_context; | 114 crx_context_ = crx_context; |
| 115 error_ = error; | 115 error_ = result.error; |
| 116 response_ = result.response; |
| 116 Quit(); | 117 Quit(); |
| 117 } | 118 } |
| 118 | 119 |
| 119 void CrxDownloaderTest::RunThreads() { | 120 void CrxDownloaderTest::RunThreads() { |
| 120 base::RunLoop runloop; | 121 base::RunLoop runloop; |
| 121 quit_closure_ = runloop.QuitClosure(); | 122 quit_closure_ = runloop.QuitClosure(); |
| 122 runloop.Run(); | 123 runloop.Run(); |
| 123 | 124 |
| 124 // Since some tests need to drain currently enqueued tasks such as network | 125 // Since some tests need to drain currently enqueued tasks such as network |
| 125 // intercepts on the IO thread, run the threads until they are | 126 // intercepts on the IO thread, run the threads until they are |
| (...skipping 162 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 288 RunThreads(); | 289 RunThreads(); |
| 289 EXPECT_EQ(0, interceptor.GetHitCount()); | 290 EXPECT_EQ(0, interceptor.GetHitCount()); |
| 290 EXPECT_NE(0, error_); | 291 EXPECT_NE(0, error_); |
| 291 EXPECT_EQ(kExpectedContext, crx_context_); | 292 EXPECT_EQ(kExpectedContext, crx_context_); |
| 292 | 293 |
| 293 EXPECT_EQ(1, num_calls_); | 294 EXPECT_EQ(1, num_calls_); |
| 294 } | 295 } |
| 295 | 296 |
| 296 } // namespace component_updater | 297 } // namespace component_updater |
| 297 | 298 |
| OLD | NEW |