| 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 "base/bind.h" | 5 #include "base/bind.h" |
| 6 #include "base/bind_helpers.h" | 6 #include "base/bind_helpers.h" |
| 7 #include "base/files/file_util.h" | 7 #include "base/files/file_util.h" |
| 8 #include "base/macros.h" | 8 #include "base/macros.h" |
| 9 #include "base/memory/ref_counted.h" | 9 #include "base/memory/ref_counted.h" |
| 10 #include "base/memory/scoped_ptr.h" | 10 #include "base/memory/scoped_ptr.h" |
| (...skipping 29 matching lines...) Expand all Loading... |
| 40 | 40 |
| 41 class UpdateCheckerTest : public testing::Test { | 41 class UpdateCheckerTest : public testing::Test { |
| 42 public: | 42 public: |
| 43 UpdateCheckerTest(); | 43 UpdateCheckerTest(); |
| 44 ~UpdateCheckerTest() override; | 44 ~UpdateCheckerTest() override; |
| 45 | 45 |
| 46 // Overrides from testing::Test. | 46 // Overrides from testing::Test. |
| 47 void SetUp() override; | 47 void SetUp() override; |
| 48 void TearDown() override; | 48 void TearDown() override; |
| 49 | 49 |
| 50 void UpdateCheckComplete(int error, const UpdateResponse::Results& results); | 50 void UpdateCheckComplete(int error, |
| 51 const UpdateResponse::Results& results, |
| 52 int retry_after_sec); |
| 51 | 53 |
| 52 protected: | 54 protected: |
| 53 void Quit(); | 55 void Quit(); |
| 54 void RunThreads(); | 56 void RunThreads(); |
| 55 void RunThreadsUntilIdle(); | 57 void RunThreadsUntilIdle(); |
| 56 | 58 |
| 57 CrxUpdateItem BuildCrxUpdateItem(); | 59 CrxUpdateItem BuildCrxUpdateItem(); |
| 58 | 60 |
| 59 scoped_refptr<TestConfigurator> config_; | 61 scoped_refptr<TestConfigurator> config_; |
| 60 | 62 |
| (...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 122 base::RunLoop().RunUntilIdle(); | 124 base::RunLoop().RunUntilIdle(); |
| 123 } | 125 } |
| 124 | 126 |
| 125 void UpdateCheckerTest::Quit() { | 127 void UpdateCheckerTest::Quit() { |
| 126 if (!quit_closure_.is_null()) | 128 if (!quit_closure_.is_null()) |
| 127 quit_closure_.Run(); | 129 quit_closure_.Run(); |
| 128 } | 130 } |
| 129 | 131 |
| 130 void UpdateCheckerTest::UpdateCheckComplete( | 132 void UpdateCheckerTest::UpdateCheckComplete( |
| 131 int error, | 133 int error, |
| 132 const UpdateResponse::Results& results) { | 134 const UpdateResponse::Results& results, |
| 135 int retry_after_sec) { |
| 133 error_ = error; | 136 error_ = error; |
| 134 results_ = results; | 137 results_ = results; |
| 135 Quit(); | 138 Quit(); |
| 136 } | 139 } |
| 137 | 140 |
| 138 CrxUpdateItem UpdateCheckerTest::BuildCrxUpdateItem() { | 141 CrxUpdateItem UpdateCheckerTest::BuildCrxUpdateItem() { |
| 139 CrxComponent crx_component; | 142 CrxComponent crx_component; |
| 140 crx_component.name = "test_jebg"; | 143 crx_component.name = "test_jebg"; |
| 141 crx_component.pk_hash.assign(jebg_hash, jebg_hash + arraysize(jebg_hash)); | 144 crx_component.pk_hash.assign(jebg_hash, jebg_hash + arraysize(jebg_hash)); |
| 142 crx_component.installer = NULL; | 145 crx_component.installer = NULL; |
| (...skipping 158 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 301 post_interceptor_->GetRequests()[0].find( | 304 post_interceptor_->GetRequests()[0].find( |
| 302 "app appid=\"jebgalgnebhfojomionfpkfelancnnkf\" version=\"0.9\" " | 305 "app appid=\"jebgalgnebhfojomionfpkfelancnnkf\" version=\"0.9\" " |
| 303 "brand=\"TEST\"><updatecheck />" | 306 "brand=\"TEST\"><updatecheck />" |
| 304 "<packages><package fp=\"fp1\"/></packages></app>")); | 307 "<packages><package fp=\"fp1\"/></packages></app>")); |
| 305 | 308 |
| 306 // Expect an error since the response is not trusted. | 309 // Expect an error since the response is not trusted. |
| 307 EXPECT_EQ(-10000, error_); | 310 EXPECT_EQ(-10000, error_); |
| 308 EXPECT_EQ(0ul, results_.list.size()); | 311 EXPECT_EQ(0ul, results_.list.size()); |
| 309 } | 312 } |
| 310 | 313 |
| 314 // Tests that the UpdateCheckers will not make an update check for a |
| 315 // component that requires encryption when the update check URL is unsecure. |
| 316 TEST_F(UpdateCheckerTest, UpdateCheckRequiresEncryptionError) { |
| 317 config_->SetUpdateCheckUrl(GURL("http:\\foo\bar")); |
| 318 |
| 319 update_checker_ = UpdateChecker::Create(config_); |
| 320 |
| 321 CrxUpdateItem item(BuildCrxUpdateItem()); |
| 322 item.component.requires_network_encryption = true; |
| 323 std::vector<CrxUpdateItem*> items_to_check; |
| 324 items_to_check.push_back(&item); |
| 325 |
| 326 update_checker_->CheckForUpdates( |
| 327 items_to_check, "", base::Bind(&UpdateCheckerTest::UpdateCheckComplete, |
| 328 base::Unretained(this))); |
| 329 RunThreads(); |
| 330 |
| 331 EXPECT_EQ(-1, error_); |
| 332 EXPECT_EQ(0u, results_.list.size()); |
| 333 } |
| 334 |
| 311 } // namespace update_client | 335 } // namespace update_client |
| OLD | NEW |