| 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/basictypes.h" | 5 #include "base/basictypes.h" |
| 6 #include "base/compiler_specific.h" | 6 #include "base/compiler_specific.h" |
| 7 #include "base/file_util.h" | 7 #include "base/file_util.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 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 48 const std::string& error_message, | 48 const std::string& error_message, |
| 49 const UpdateResponse::Results& results); | 49 const UpdateResponse::Results& results); |
| 50 | 50 |
| 51 net::URLRequestContextGetter* context() { return context_.get(); } | 51 net::URLRequestContextGetter* context() { return context_.get(); } |
| 52 | 52 |
| 53 protected: | 53 protected: |
| 54 void Quit(); | 54 void Quit(); |
| 55 void RunThreads(); | 55 void RunThreads(); |
| 56 void RunThreadsUntilIdle(); | 56 void RunThreadsUntilIdle(); |
| 57 | 57 |
| 58 CrxUpdateItem BuildCrxUpdateItem(); | 58 scoped_ptr<CrxUpdateItem> BuildCrxUpdateItem(); |
| 59 | 59 |
| 60 scoped_ptr<UpdateChecker> update_checker_; | 60 scoped_ptr<UpdateChecker> update_checker_; |
| 61 | 61 |
| 62 scoped_ptr<InterceptorFactory> interceptor_factory_; | 62 scoped_ptr<InterceptorFactory> interceptor_factory_; |
| 63 URLRequestPostInterceptor* post_interceptor_; // Owned by the factory. | 63 URLRequestPostInterceptor* post_interceptor_; // Owned by the factory. |
| 64 | 64 |
| 65 int error_; | 65 int error_; |
| 66 std::string error_message_; | 66 std::string error_message_; |
| 67 UpdateResponse::Results results_; | 67 UpdateResponse::Results results_; |
| 68 | 68 |
| (...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 135 void UpdateCheckerTest::UpdateCheckComplete( | 135 void UpdateCheckerTest::UpdateCheckComplete( |
| 136 int error, | 136 int error, |
| 137 const std::string& error_message, | 137 const std::string& error_message, |
| 138 const UpdateResponse::Results& results) { | 138 const UpdateResponse::Results& results) { |
| 139 error_ = error; | 139 error_ = error; |
| 140 error_message_ = error_message; | 140 error_message_ = error_message; |
| 141 results_ = results; | 141 results_ = results; |
| 142 Quit(); | 142 Quit(); |
| 143 } | 143 } |
| 144 | 144 |
| 145 CrxUpdateItem UpdateCheckerTest::BuildCrxUpdateItem() { | 145 scoped_ptr<CrxUpdateItem> UpdateCheckerTest::BuildCrxUpdateItem() { |
| 146 CrxComponent crx_component; | 146 CrxComponent crx_component; |
| 147 crx_component.name = "test_jebg"; | 147 crx_component.name = "test_jebg"; |
| 148 crx_component.pk_hash.assign(jebg_hash, jebg_hash + arraysize(jebg_hash)); | 148 crx_component.pk_hash.assign(jebg_hash, jebg_hash + arraysize(jebg_hash)); |
| 149 crx_component.installer = NULL; | 149 crx_component.installer = NULL; |
| 150 crx_component.version = base::Version("0.9"); | 150 crx_component.version = base::Version("0.9"); |
| 151 crx_component.fingerprint = "fp1"; | 151 crx_component.fingerprint = "fp1"; |
| 152 | 152 |
| 153 CrxUpdateItem crx_update_item; | 153 scoped_ptr<CrxUpdateItem> crx_update_item(new CrxUpdateItem()); |
| 154 crx_update_item.status = CrxUpdateItem::kNew; | 154 crx_update_item->status = CrxUpdateItem::kNew; |
| 155 crx_update_item.id = "jebgalgnebhfojomionfpkfelancnnkf"; | 155 crx_update_item->id = "jebgalgnebhfojomionfpkfelancnnkf"; |
| 156 crx_update_item.component = crx_component; | 156 crx_update_item->component = crx_component; |
| 157 | 157 |
| 158 return crx_update_item; | 158 return crx_update_item.Pass(); |
| 159 } | 159 } |
| 160 | 160 |
| 161 TEST_F(UpdateCheckerTest, UpdateCheckSuccess) { | 161 TEST_F(UpdateCheckerTest, UpdateCheckSuccess) { |
| 162 EXPECT_TRUE(post_interceptor_->ExpectRequest( | 162 EXPECT_TRUE(post_interceptor_->ExpectRequest( |
| 163 new PartialMatch("updatecheck"), test_file("updatecheck_reply_1.xml"))); | 163 new PartialMatch("updatecheck"), test_file("updatecheck_reply_1.xml"))); |
| 164 | 164 |
| 165 update_checker_ = | 165 update_checker_ = |
| 166 UpdateChecker::Create(GURL("https://localhost2/update2"), | 166 UpdateChecker::Create(GURL("https://localhost2/update2"), |
| 167 context(), | 167 context(), |
| 168 base::Bind(&UpdateCheckerTest::UpdateCheckComplete, | 168 base::Bind(&UpdateCheckerTest::UpdateCheckComplete, |
| 169 base::Unretained(this))).Pass(); | 169 base::Unretained(this))).Pass(); |
| 170 | 170 |
| 171 CrxUpdateItem item(BuildCrxUpdateItem()); | 171 scoped_ptr<CrxUpdateItem> item(BuildCrxUpdateItem()); |
| 172 std::vector<CrxUpdateItem*> items_to_check; | 172 std::vector<CrxUpdateItem*> items_to_check; |
| 173 items_to_check.push_back(&item); | 173 items_to_check.push_back(item.get()); |
| 174 | 174 |
| 175 update_checker_->CheckForUpdates(items_to_check, "extra=\"params\""); | 175 update_checker_->CheckForUpdates(items_to_check, "extra=\"params\""); |
| 176 | 176 |
| 177 RunThreads(); | 177 RunThreads(); |
| 178 | 178 |
| 179 EXPECT_EQ(1, post_interceptor_->GetHitCount()) | 179 EXPECT_EQ(1, post_interceptor_->GetHitCount()) |
| 180 << post_interceptor_->GetRequestsAsString(); | 180 << post_interceptor_->GetRequestsAsString(); |
| 181 EXPECT_EQ(1, post_interceptor_->GetCount()) | 181 EXPECT_EQ(1, post_interceptor_->GetCount()) |
| 182 << post_interceptor_->GetRequestsAsString(); | 182 << post_interceptor_->GetRequestsAsString(); |
| 183 | 183 |
| (...skipping 27 matching lines...) Expand all Loading... |
| 211 scoped_ptr<PartialMatch> request_matcher(new PartialMatch("updatecheck")); | 211 scoped_ptr<PartialMatch> request_matcher(new PartialMatch("updatecheck")); |
| 212 EXPECT_FALSE(post_interceptor_->ExpectRequest(request_matcher.get(), | 212 EXPECT_FALSE(post_interceptor_->ExpectRequest(request_matcher.get(), |
| 213 test_file("no such file"))); | 213 test_file("no such file"))); |
| 214 | 214 |
| 215 update_checker_ = | 215 update_checker_ = |
| 216 UpdateChecker::Create(GURL("https://localhost2/update2"), | 216 UpdateChecker::Create(GURL("https://localhost2/update2"), |
| 217 context(), | 217 context(), |
| 218 base::Bind(&UpdateCheckerTest::UpdateCheckComplete, | 218 base::Bind(&UpdateCheckerTest::UpdateCheckComplete, |
| 219 base::Unretained(this))).Pass(); | 219 base::Unretained(this))).Pass(); |
| 220 | 220 |
| 221 CrxUpdateItem item(BuildCrxUpdateItem()); | 221 scoped_ptr<CrxUpdateItem> item(BuildCrxUpdateItem()); |
| 222 std::vector<CrxUpdateItem*> items_to_check; | 222 std::vector<CrxUpdateItem*> items_to_check; |
| 223 items_to_check.push_back(&item); | 223 items_to_check.push_back(item.get()); |
| 224 | 224 |
| 225 update_checker_->CheckForUpdates(items_to_check, ""); | 225 update_checker_->CheckForUpdates(items_to_check, ""); |
| 226 | 226 |
| 227 RunThreads(); | 227 RunThreads(); |
| 228 | 228 |
| 229 EXPECT_EQ(0, post_interceptor_->GetHitCount()) | 229 EXPECT_EQ(0, post_interceptor_->GetHitCount()) |
| 230 << post_interceptor_->GetRequestsAsString(); | 230 << post_interceptor_->GetRequestsAsString(); |
| 231 EXPECT_EQ(1, post_interceptor_->GetCount()) | 231 EXPECT_EQ(1, post_interceptor_->GetCount()) |
| 232 << post_interceptor_->GetRequestsAsString(); | 232 << post_interceptor_->GetRequestsAsString(); |
| 233 | 233 |
| 234 EXPECT_NE(0, error_); | 234 EXPECT_NE(0, error_); |
| 235 EXPECT_STREQ("network error", error_message_.c_str()); | 235 EXPECT_STREQ("network error", error_message_.c_str()); |
| 236 EXPECT_EQ(0ul, results_.list.size()); | 236 EXPECT_EQ(0ul, results_.list.size()); |
| 237 } | 237 } |
| 238 | 238 |
| 239 } // namespace component_updater | 239 } // namespace component_updater |
| OLD | NEW |