| 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 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 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 if (!quit_closure_.is_null()) |
| 108 quit_closure_.Run(); |
| 108 } | 109 } |
| 109 | 110 |
| 110 void CrxDownloaderTest::DownloadComplete( | 111 void CrxDownloaderTest::DownloadComplete( |
| 111 int crx_context, | 112 int crx_context, |
| 112 const CrxDownloader::Result& result) { | 113 const CrxDownloader::Result& result) { |
| 113 ++num_calls_; | 114 ++num_calls_; |
| 114 crx_context_ = crx_context; | 115 crx_context_ = crx_context; |
| 115 error_ = result.error; | 116 error_ = result.error; |
| 116 response_ = result.response; | 117 response_ = result.response; |
| 117 Quit(); | 118 Quit(); |
| 118 } | 119 } |
| 119 | 120 |
| 120 void CrxDownloaderTest::RunThreads() { | 121 void CrxDownloaderTest::RunThreads() { |
| 121 base::RunLoop runloop; | 122 base::RunLoop runloop; |
| 122 quit_closure_ = runloop.QuitClosure(); | 123 quit_closure_ = runloop.QuitClosure(); |
| 123 runloop.Run(); | 124 runloop.Run(); |
| 124 | 125 |
| 125 // Since some tests need to drain currently enqueued tasks such as network | 126 // Since some tests need to drain currently enqueued tasks such as network |
| 126 // intercepts on the IO thread, run the threads until they are | 127 // intercepts on the IO thread, run the threads until they are |
| 127 // idle. The component updater service won't loop again until the loop count | 128 // idle. The component updater service won't loop again until the loop count |
| 128 // is set and the service is started. | 129 // is set and the service is started. |
| 129 RunThreadsUntilIdle(); | 130 RunThreadsUntilIdle(); |
| 130 } | 131 } |
| 131 | 132 |
| 132 void CrxDownloaderTest::RunThreadsUntilIdle() { | 133 void CrxDownloaderTest::RunThreadsUntilIdle() { |
| 133 base::RunLoop().RunUntilIdle(); | 134 base::RunLoop().RunUntilIdle(); |
| 134 } | 135 } |
| 135 | 136 |
| 137 // Tests that starting a download without a url results in an error. |
| 138 TEST_F(CrxDownloaderTest, NoUrl) { |
| 139 std::vector<GURL> urls; |
| 140 crx_downloader_->StartDownload(urls); |
| 141 |
| 142 RunThreadsUntilIdle(); |
| 143 EXPECT_EQ(-1, error_); |
| 144 EXPECT_EQ(kExpectedContext, crx_context_); |
| 145 |
| 146 EXPECT_EQ(1, num_calls_); |
| 147 } |
| 148 |
| 136 // Tests that downloading from one url is successful. | 149 // Tests that downloading from one url is successful. |
| 137 TEST_F(CrxDownloaderTest, OneUrl) { | 150 TEST_F(CrxDownloaderTest, OneUrl) { |
| 138 const GURL expected_crx_url = | 151 const GURL expected_crx_url = |
| 139 GURL("http://localhost/download/jebgalgnebhfojomionfpkfelancnnkf.crx"); | 152 GURL("http://localhost/download/jebgalgnebhfojomionfpkfelancnnkf.crx"); |
| 140 | 153 |
| 141 GetInterceptor interceptor; | 154 GetInterceptor interceptor; |
| 142 interceptor.SetResponse( | 155 interceptor.SetResponse( |
| 143 expected_crx_url, | 156 expected_crx_url, |
| 144 test_file("jebgalgnebhfojomionfpkfelancnnkf.crx")); | 157 test_file("jebgalgnebhfojomionfpkfelancnnkf.crx")); |
| 145 | 158 |
| (...skipping 143 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 289 RunThreads(); | 302 RunThreads(); |
| 290 EXPECT_EQ(0, interceptor.GetHitCount()); | 303 EXPECT_EQ(0, interceptor.GetHitCount()); |
| 291 EXPECT_NE(0, error_); | 304 EXPECT_NE(0, error_); |
| 292 EXPECT_EQ(kExpectedContext, crx_context_); | 305 EXPECT_EQ(kExpectedContext, crx_context_); |
| 293 | 306 |
| 294 EXPECT_EQ(1, num_calls_); | 307 EXPECT_EQ(1, num_calls_); |
| 295 } | 308 } |
| 296 | 309 |
| 297 } // namespace component_updater | 310 } // namespace component_updater |
| 298 | 311 |
| OLD | NEW |