Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(383)

Side by Side Diff: components/update_client/update_checker_unittest.cc

Issue 2873533002: Prepare to abstract PersistedData by making it part of the configurator.
Patch Set: Really fix a compile error in iOS component configurator this time. Created 3 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 "components/update_client/update_checker.h" 5 #include "components/update_client/update_checker.h"
6 6
7 #include <memory> 7 #include <memory>
8 #include <utility> 8 #include <utility>
9 9
10 #include "base/bind.h" 10 #include "base/bind.h"
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
62 62
63 protected: 63 protected:
64 void Quit(); 64 void Quit();
65 void RunThreads(); 65 void RunThreads();
66 void RunThreadsUntilIdle(); 66 void RunThreadsUntilIdle();
67 67
68 std::unique_ptr<Component> MakeComponent() const; 68 std::unique_ptr<Component> MakeComponent() const;
69 69
70 scoped_refptr<TestConfigurator> config_; 70 scoped_refptr<TestConfigurator> config_;
71 std::unique_ptr<TestingPrefServiceSimple> pref_; 71 std::unique_ptr<TestingPrefServiceSimple> pref_;
72 std::unique_ptr<PersistedData> metadata_;
73 72
74 std::unique_ptr<UpdateChecker> update_checker_; 73 std::unique_ptr<UpdateChecker> update_checker_;
75 74
76 std::unique_ptr<InterceptorFactory> interceptor_factory_; 75 std::unique_ptr<InterceptorFactory> interceptor_factory_;
77 URLRequestPostInterceptor* post_interceptor_ = 76 URLRequestPostInterceptor* post_interceptor_ =
78 nullptr; // Owned by the factory. 77 nullptr; // Owned by the factory.
79 78
80 int error_ = 0; 79 int error_ = 0;
81 int retry_after_sec_ = 0; 80 int retry_after_sec_ = 0;
82 81
83 std::unique_ptr<UpdateContext> update_context_; 82 std::unique_ptr<UpdateContext> update_context_;
84 83
85 private: 84 private:
86 std::unique_ptr<UpdateContext> MakeFakeUpdateContext() const; 85 std::unique_ptr<UpdateContext> MakeFakeUpdateContext() const;
87 86
88 base::MessageLoopForIO loop_; 87 base::MessageLoopForIO loop_;
89 base::test::ScopedTaskScheduler scoped_task_scheduler_; 88 base::test::ScopedTaskScheduler scoped_task_scheduler_;
90 base::Closure quit_closure_; 89 base::Closure quit_closure_;
91 90
92 DISALLOW_COPY_AND_ASSIGN(UpdateCheckerTest); 91 DISALLOW_COPY_AND_ASSIGN(UpdateCheckerTest);
93 }; 92 };
94 93
95 UpdateCheckerTest::UpdateCheckerTest() : scoped_task_scheduler_(&loop_) {} 94 UpdateCheckerTest::UpdateCheckerTest() : scoped_task_scheduler_(&loop_) {}
96 95
97 UpdateCheckerTest::~UpdateCheckerTest() { 96 UpdateCheckerTest::~UpdateCheckerTest() {
98 } 97 }
99 98
100 void UpdateCheckerTest::SetUp() { 99 void UpdateCheckerTest::SetUp() {
100 pref_ = base::MakeUnique<TestingPrefServiceSimple>();
101 config_ = base::MakeShared<TestConfigurator>( 101 config_ = base::MakeShared<TestConfigurator>(
102 base::ThreadTaskRunnerHandle::Get(), base::ThreadTaskRunnerHandle::Get()); 102 base::ThreadTaskRunnerHandle::Get(), base::ThreadTaskRunnerHandle::Get());
103 pref_ = base::MakeUnique<TestingPrefServiceSimple>(); 103 config_->SetPrefService(pref_.get());
104 PersistedData::RegisterPrefs(pref_->registry()); 104 PersistedData::RegisterPrefs(pref_->registry());
105 metadata_ = base::MakeUnique<PersistedData>(pref_.get());
106 interceptor_factory_ = 105 interceptor_factory_ =
107 base::MakeUnique<InterceptorFactory>(base::ThreadTaskRunnerHandle::Get()); 106 base::MakeUnique<InterceptorFactory>(base::ThreadTaskRunnerHandle::Get());
108 post_interceptor_ = interceptor_factory_->CreateInterceptor(); 107 post_interceptor_ = interceptor_factory_->CreateInterceptor();
109 EXPECT_TRUE(post_interceptor_); 108 EXPECT_TRUE(post_interceptor_);
110 109
111 update_checker_ = nullptr; 110 update_checker_ = nullptr;
112 111
113 error_ = 0; 112 error_ = 0;
114 retry_after_sec_ = 0; 113 retry_after_sec_ = 0;
115 update_context_ = MakeFakeUpdateContext(); 114 update_context_ = MakeFakeUpdateContext();
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after
175 component->state_ = base::MakeUnique<Component::StateNew>(component.get()); 174 component->state_ = base::MakeUnique<Component::StateNew>(component.get());
176 component->crx_component_ = crx_component; 175 component->crx_component_ = crx_component;
177 176
178 return component; 177 return component;
179 } 178 }
180 179
181 TEST_F(UpdateCheckerTest, UpdateCheckSuccess) { 180 TEST_F(UpdateCheckerTest, UpdateCheckSuccess) {
182 EXPECT_TRUE(post_interceptor_->ExpectRequest( 181 EXPECT_TRUE(post_interceptor_->ExpectRequest(
183 new PartialMatch("updatecheck"), test_file("updatecheck_reply_1.xml"))); 182 new PartialMatch("updatecheck"), test_file("updatecheck_reply_1.xml")));
184 183
185 update_checker_ = UpdateChecker::Create(config_, metadata_.get()); 184 update_checker_ = UpdateChecker::Create(config_);
186 185
187 IdToComponentPtrMap components; 186 IdToComponentPtrMap components;
188 components[kUpdateItemId] = MakeComponent(); 187 components[kUpdateItemId] = MakeComponent();
189 188
190 auto& component = components[kUpdateItemId]; 189 auto& component = components[kUpdateItemId];
191 component->crx_component_.installer_attributes["ap"] = "some_ap"; 190 component->crx_component_.installer_attributes["ap"] = "some_ap";
192 191
193 update_checker_->CheckForUpdates( 192 update_checker_->CheckForUpdates(
194 std::vector<std::string>{kUpdateItemId}, components, "extra=\"params\"", 193 std::vector<std::string>{kUpdateItemId}, components, "extra=\"params\"",
195 true, 194 true,
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
243 EXPECT_NE(string::npos, request.find(" name=\"Omaha\" ")); 242 EXPECT_NE(string::npos, request.find(" name=\"Omaha\" "));
244 #endif // GOOGLE_CHROME_BUILD 243 #endif // GOOGLE_CHROME_BUILD
245 #endif // OS_WINDOWS 244 #endif // OS_WINDOWS
246 } 245 }
247 246
248 // Tests that an invalid "ap" is not serialized. 247 // Tests that an invalid "ap" is not serialized.
249 TEST_F(UpdateCheckerTest, UpdateCheckInvalidAp) { 248 TEST_F(UpdateCheckerTest, UpdateCheckInvalidAp) {
250 EXPECT_TRUE(post_interceptor_->ExpectRequest( 249 EXPECT_TRUE(post_interceptor_->ExpectRequest(
251 new PartialMatch("updatecheck"), test_file("updatecheck_reply_1.xml"))); 250 new PartialMatch("updatecheck"), test_file("updatecheck_reply_1.xml")));
252 251
253 update_checker_ = UpdateChecker::Create(config_, metadata_.get()); 252 update_checker_ = UpdateChecker::Create(config_);
254 253
255 IdToComponentPtrMap components; 254 IdToComponentPtrMap components;
256 components[kUpdateItemId] = MakeComponent(); 255 components[kUpdateItemId] = MakeComponent();
257 256
258 // Make "ap" too long. 257 // Make "ap" too long.
259 auto& component = components[kUpdateItemId]; 258 auto& component = components[kUpdateItemId];
260 component->crx_component_.installer_attributes["ap"] = std::string(257, 'a'); 259 component->crx_component_.installer_attributes["ap"] = std::string(257, 'a');
261 260
262 update_checker_->CheckForUpdates( 261 update_checker_->CheckForUpdates(
263 std::vector<std::string>{kUpdateItemId}, components, "", true, 262 std::vector<std::string>{kUpdateItemId}, components, "", true,
264 base::Bind(&UpdateCheckerTest::UpdateCheckComplete, 263 base::Bind(&UpdateCheckerTest::UpdateCheckComplete,
265 base::Unretained(this))); 264 base::Unretained(this)));
266 265
267 RunThreads(); 266 RunThreads();
268 267
269 EXPECT_NE(string::npos, post_interceptor_->GetRequests()[0].find( 268 EXPECT_NE(string::npos, post_interceptor_->GetRequests()[0].find(
270 std::string("app appid=\"") + kUpdateItemId + 269 std::string("app appid=\"") + kUpdateItemId +
271 "\" version=\"0.9\" " 270 "\" version=\"0.9\" "
272 "brand=\"TEST\"><updatecheck/><ping rd=\"-2\" ")); 271 "brand=\"TEST\"><updatecheck/><ping rd=\"-2\" "));
273 EXPECT_NE(string::npos, 272 EXPECT_NE(string::npos,
274 post_interceptor_->GetRequests()[0].find( 273 post_interceptor_->GetRequests()[0].find(
275 "<packages><package fp=\"fp1\"/></packages></app>")); 274 "<packages><package fp=\"fp1\"/></packages></app>"));
276 } 275 }
277 276
278 TEST_F(UpdateCheckerTest, UpdateCheckSuccessNoBrand) { 277 TEST_F(UpdateCheckerTest, UpdateCheckSuccessNoBrand) {
279 EXPECT_TRUE(post_interceptor_->ExpectRequest( 278 EXPECT_TRUE(post_interceptor_->ExpectRequest(
280 new PartialMatch("updatecheck"), test_file("updatecheck_reply_1.xml"))); 279 new PartialMatch("updatecheck"), test_file("updatecheck_reply_1.xml")));
281 280
282 config_->SetBrand("TOOLONG"); // Sets an invalid brand code. 281 config_->SetBrand("TOOLONG"); // Sets an invalid brand code.
283 update_checker_ = UpdateChecker::Create(config_, metadata_.get()); 282 update_checker_ = UpdateChecker::Create(config_);
284 283
285 IdToComponentPtrMap components; 284 IdToComponentPtrMap components;
286 components[kUpdateItemId] = MakeComponent(); 285 components[kUpdateItemId] = MakeComponent();
287 286
288 update_checker_->CheckForUpdates( 287 update_checker_->CheckForUpdates(
289 std::vector<std::string>{kUpdateItemId}, components, "", true, 288 std::vector<std::string>{kUpdateItemId}, components, "", true,
290 base::Bind(&UpdateCheckerTest::UpdateCheckComplete, 289 base::Bind(&UpdateCheckerTest::UpdateCheckComplete,
291 base::Unretained(this))); 290 base::Unretained(this)));
292 291
293 RunThreads(); 292 RunThreads();
294 293
295 EXPECT_NE(string::npos, post_interceptor_->GetRequests()[0].find( 294 EXPECT_NE(string::npos, post_interceptor_->GetRequests()[0].find(
296 std::string("<app appid=\"") + kUpdateItemId + 295 std::string("<app appid=\"") + kUpdateItemId +
297 "\" version=\"0.9\">" 296 "\" version=\"0.9\">"
298 "<updatecheck/><ping rd=\"-2\" ")); 297 "<updatecheck/><ping rd=\"-2\" "));
299 EXPECT_NE(string::npos, 298 EXPECT_NE(string::npos,
300 post_interceptor_->GetRequests()[0].find( 299 post_interceptor_->GetRequests()[0].find(
301 "<packages><package fp=\"fp1\"/></packages></app>")); 300 "<packages><package fp=\"fp1\"/></packages></app>"));
302 } 301 }
303 302
304 // Simulates a 403 server response error. 303 // Simulates a 403 server response error.
305 TEST_F(UpdateCheckerTest, UpdateCheckError) { 304 TEST_F(UpdateCheckerTest, UpdateCheckError) {
306 EXPECT_TRUE( 305 EXPECT_TRUE(
307 post_interceptor_->ExpectRequest(new PartialMatch("updatecheck"), 403)); 306 post_interceptor_->ExpectRequest(new PartialMatch("updatecheck"), 403));
308 307
309 update_checker_ = UpdateChecker::Create(config_, metadata_.get()); 308 update_checker_ = UpdateChecker::Create(config_);
310 309
311 IdToComponentPtrMap components; 310 IdToComponentPtrMap components;
312 components[kUpdateItemId] = MakeComponent(); 311 components[kUpdateItemId] = MakeComponent();
313 312
314 auto& component = components[kUpdateItemId]; 313 auto& component = components[kUpdateItemId];
315 314
316 update_checker_->CheckForUpdates( 315 update_checker_->CheckForUpdates(
317 std::vector<std::string>{kUpdateItemId}, components, "", true, 316 std::vector<std::string>{kUpdateItemId}, components, "", true,
318 base::Bind(&UpdateCheckerTest::UpdateCheckComplete, 317 base::Bind(&UpdateCheckerTest::UpdateCheckComplete,
319 base::Unretained(this))); 318 base::Unretained(this)));
320 RunThreads(); 319 RunThreads();
321 320
322 EXPECT_EQ(1, post_interceptor_->GetHitCount()) 321 EXPECT_EQ(1, post_interceptor_->GetHitCount())
323 << post_interceptor_->GetRequestsAsString(); 322 << post_interceptor_->GetRequestsAsString();
324 EXPECT_EQ(1, post_interceptor_->GetCount()) 323 EXPECT_EQ(1, post_interceptor_->GetCount())
325 << post_interceptor_->GetRequestsAsString(); 324 << post_interceptor_->GetRequestsAsString();
326 325
327 EXPECT_EQ(403, error_); 326 EXPECT_EQ(403, error_);
328 EXPECT_FALSE(component->next_version_.IsValid()); 327 EXPECT_FALSE(component->next_version_.IsValid());
329 } 328 }
330 329
331 TEST_F(UpdateCheckerTest, UpdateCheckDownloadPreference) { 330 TEST_F(UpdateCheckerTest, UpdateCheckDownloadPreference) {
332 EXPECT_TRUE(post_interceptor_->ExpectRequest( 331 EXPECT_TRUE(post_interceptor_->ExpectRequest(
333 new PartialMatch("updatecheck"), test_file("updatecheck_reply_1.xml"))); 332 new PartialMatch("updatecheck"), test_file("updatecheck_reply_1.xml")));
334 333
335 config_->SetDownloadPreference(string("cacheable")); 334 config_->SetDownloadPreference(string("cacheable"));
336 335
337 update_checker_ = UpdateChecker::Create(config_, metadata_.get()); 336 update_checker_ = UpdateChecker::Create(config_);
338 337
339 IdToComponentPtrMap components; 338 IdToComponentPtrMap components;
340 components[kUpdateItemId] = MakeComponent(); 339 components[kUpdateItemId] = MakeComponent();
341 340
342 update_checker_->CheckForUpdates( 341 update_checker_->CheckForUpdates(
343 std::vector<std::string>{kUpdateItemId}, components, "extra=\"params\"", 342 std::vector<std::string>{kUpdateItemId}, components, "extra=\"params\"",
344 true, 343 true,
345 base::Bind(&UpdateCheckerTest::UpdateCheckComplete, 344 base::Bind(&UpdateCheckerTest::UpdateCheckComplete,
346 base::Unretained(this))); 345 base::Unretained(this)));
347 346
348 RunThreads(); 347 RunThreads();
349 348
350 // The request must contain dlpref="cacheable". 349 // The request must contain dlpref="cacheable".
351 EXPECT_NE(string::npos, 350 EXPECT_NE(string::npos,
352 post_interceptor_->GetRequests()[0].find(" dlpref=\"cacheable\"")); 351 post_interceptor_->GetRequests()[0].find(" dlpref=\"cacheable\""));
353 } 352 }
354 353
355 // This test is checking that an update check signed with CUP fails, since there 354 // This test is checking that an update check signed with CUP fails, since there
356 // is currently no entity that can respond with a valid signed response. 355 // is currently no entity that can respond with a valid signed response.
357 // A proper CUP test requires network mocks, which are not available now. 356 // A proper CUP test requires network mocks, which are not available now.
358 TEST_F(UpdateCheckerTest, UpdateCheckCupError) { 357 TEST_F(UpdateCheckerTest, UpdateCheckCupError) {
359 EXPECT_TRUE(post_interceptor_->ExpectRequest( 358 EXPECT_TRUE(post_interceptor_->ExpectRequest(
360 new PartialMatch("updatecheck"), test_file("updatecheck_reply_1.xml"))); 359 new PartialMatch("updatecheck"), test_file("updatecheck_reply_1.xml")));
361 360
362 config_->SetEnabledCupSigning(true); 361 config_->SetEnabledCupSigning(true);
363 update_checker_ = UpdateChecker::Create(config_, metadata_.get()); 362 update_checker_ = UpdateChecker::Create(config_);
364 363
365 IdToComponentPtrMap components; 364 IdToComponentPtrMap components;
366 components[kUpdateItemId] = MakeComponent(); 365 components[kUpdateItemId] = MakeComponent();
367 366
368 const auto& component = components[kUpdateItemId]; 367 const auto& component = components[kUpdateItemId];
369 368
370 update_checker_->CheckForUpdates( 369 update_checker_->CheckForUpdates(
371 std::vector<std::string>{kUpdateItemId}, components, "", true, 370 std::vector<std::string>{kUpdateItemId}, components, "", true,
372 base::Bind(&UpdateCheckerTest::UpdateCheckComplete, 371 base::Bind(&UpdateCheckerTest::UpdateCheckComplete,
373 base::Unretained(this))); 372 base::Unretained(this)));
(...skipping 17 matching lines...) Expand all
391 // Expect an error since the response is not trusted. 390 // Expect an error since the response is not trusted.
392 EXPECT_EQ(-10000, error_); 391 EXPECT_EQ(-10000, error_);
393 EXPECT_FALSE(component->next_version_.IsValid()); 392 EXPECT_FALSE(component->next_version_.IsValid());
394 } 393 }
395 394
396 // Tests that the UpdateCheckers will not make an update check for a 395 // Tests that the UpdateCheckers will not make an update check for a
397 // component that requires encryption when the update check URL is unsecure. 396 // component that requires encryption when the update check URL is unsecure.
398 TEST_F(UpdateCheckerTest, UpdateCheckRequiresEncryptionError) { 397 TEST_F(UpdateCheckerTest, UpdateCheckRequiresEncryptionError) {
399 config_->SetUpdateCheckUrl(GURL("http:\\foo\bar")); 398 config_->SetUpdateCheckUrl(GURL("http:\\foo\bar"));
400 399
401 update_checker_ = UpdateChecker::Create(config_, metadata_.get()); 400 update_checker_ = UpdateChecker::Create(config_);
402 401
403 IdToComponentPtrMap components; 402 IdToComponentPtrMap components;
404 components[kUpdateItemId] = MakeComponent(); 403 components[kUpdateItemId] = MakeComponent();
405 404
406 auto& component = components[kUpdateItemId]; 405 auto& component = components[kUpdateItemId];
407 component->crx_component_.requires_network_encryption = true; 406 component->crx_component_.requires_network_encryption = true;
408 407
409 update_checker_->CheckForUpdates( 408 update_checker_->CheckForUpdates(
410 std::vector<std::string>{kUpdateItemId}, components, "", true, 409 std::vector<std::string>{kUpdateItemId}, components, "", true,
411 base::Bind(&UpdateCheckerTest::UpdateCheckComplete, 410 base::Bind(&UpdateCheckerTest::UpdateCheckComplete,
412 base::Unretained(this))); 411 base::Unretained(this)));
413 RunThreads(); 412 RunThreads();
414 413
415 EXPECT_EQ(-1, error_); 414 EXPECT_EQ(-1, error_);
416 EXPECT_FALSE(component->next_version_.IsValid()); 415 EXPECT_FALSE(component->next_version_.IsValid());
417 } 416 }
418 417
419 // Tests that the PersistedData will get correctly update and reserialize 418 // Tests that the PersistedData will get correctly update and reserialize
420 // the elapsed_days value. 419 // the elapsed_days value.
421 TEST_F(UpdateCheckerTest, UpdateCheckDateLastRollCall) { 420 TEST_F(UpdateCheckerTest, UpdateCheckDateLastRollCall) {
422 EXPECT_TRUE(post_interceptor_->ExpectRequest( 421 EXPECT_TRUE(post_interceptor_->ExpectRequest(
423 new PartialMatch("updatecheck"), test_file("updatecheck_reply_4.xml"))); 422 new PartialMatch("updatecheck"), test_file("updatecheck_reply_4.xml")));
424 EXPECT_TRUE(post_interceptor_->ExpectRequest( 423 EXPECT_TRUE(post_interceptor_->ExpectRequest(
425 new PartialMatch("updatecheck"), test_file("updatecheck_reply_4.xml"))); 424 new PartialMatch("updatecheck"), test_file("updatecheck_reply_4.xml")));
426 425
427 update_checker_ = UpdateChecker::Create(config_, metadata_.get()); 426 update_checker_ = UpdateChecker::Create(config_);
428 427
429 IdToComponentPtrMap components; 428 IdToComponentPtrMap components;
430 components[kUpdateItemId] = MakeComponent(); 429 components[kUpdateItemId] = MakeComponent();
431 430
432 // Do two update-checks. 431 // Do two update-checks.
433 update_checker_->CheckForUpdates( 432 update_checker_->CheckForUpdates(
434 std::vector<std::string>{kUpdateItemId}, components, "extra=\"params\"", 433 std::vector<std::string>{kUpdateItemId}, components, "extra=\"params\"",
435 true, 434 true,
436 base::Bind(&UpdateCheckerTest::UpdateCheckComplete, 435 base::Bind(&UpdateCheckerTest::UpdateCheckComplete,
437 base::Unretained(this))); 436 base::Unretained(this)));
438 RunThreads(); 437 RunThreads();
439 438
440 update_checker_ = UpdateChecker::Create(config_, metadata_.get()); 439 update_checker_ = UpdateChecker::Create(config_);
441 update_checker_->CheckForUpdates( 440 update_checker_->CheckForUpdates(
442 std::vector<std::string>{kUpdateItemId}, components, "extra=\"params\"", 441 std::vector<std::string>{kUpdateItemId}, components, "extra=\"params\"",
443 true, 442 true,
444 base::Bind(&UpdateCheckerTest::UpdateCheckComplete, 443 base::Bind(&UpdateCheckerTest::UpdateCheckComplete,
445 base::Unretained(this))); 444 base::Unretained(this)));
446 RunThreads(); 445 RunThreads();
447 446
448 EXPECT_EQ(2, post_interceptor_->GetHitCount()) 447 EXPECT_EQ(2, post_interceptor_->GetHitCount())
449 << post_interceptor_->GetRequestsAsString(); 448 << post_interceptor_->GetRequestsAsString();
450 ASSERT_EQ(2, post_interceptor_->GetCount()) 449 ASSERT_EQ(2, post_interceptor_->GetCount())
451 << post_interceptor_->GetRequestsAsString(); 450 << post_interceptor_->GetRequestsAsString();
452 EXPECT_NE(string::npos, post_interceptor_->GetRequests()[0].find( 451 EXPECT_NE(string::npos, post_interceptor_->GetRequests()[0].find(
453 "<ping rd=\"-2\" ping_freshness=")); 452 "<ping rd=\"-2\" ping_freshness="));
454 EXPECT_NE(string::npos, post_interceptor_->GetRequests()[1].find( 453 EXPECT_NE(string::npos, post_interceptor_->GetRequests()[1].find(
455 "<ping rd=\"3383\" ping_freshness=")); 454 "<ping rd=\"3383\" ping_freshness="));
456 } 455 }
457 456
458 TEST_F(UpdateCheckerTest, UpdateCheckUpdateDisabled) { 457 TEST_F(UpdateCheckerTest, UpdateCheckUpdateDisabled) {
459 EXPECT_TRUE(post_interceptor_->ExpectRequest( 458 EXPECT_TRUE(post_interceptor_->ExpectRequest(
460 new PartialMatch("updatecheck"), test_file("updatecheck_reply_1.xml"))); 459 new PartialMatch("updatecheck"), test_file("updatecheck_reply_1.xml")));
461 460
462 config_->SetBrand(""); 461 config_->SetBrand("");
463 update_checker_ = UpdateChecker::Create(config_, metadata_.get()); 462 update_checker_ = UpdateChecker::Create(config_);
464 463
465 IdToComponentPtrMap components; 464 IdToComponentPtrMap components;
466 components[kUpdateItemId] = MakeComponent(); 465 components[kUpdateItemId] = MakeComponent();
467 466
468 auto& component = components[kUpdateItemId]; 467 auto& component = components[kUpdateItemId];
469 468
470 // Tests the scenario where: 469 // Tests the scenario where:
471 // * the component does not support group policies. 470 // * the component does not support group policies.
472 // * the component updates are disabled. 471 // * the component updates are disabled.
473 // Expects the group policy to be ignored and the update check to not 472 // Expects the group policy to be ignored and the update check to not
(...skipping 10 matching lines...) Expand all
484 std::string("<app appid=\"") + kUpdateItemId + 483 std::string("<app appid=\"") + kUpdateItemId +
485 "\" version=\"0.9\">" 484 "\" version=\"0.9\">"
486 "<updatecheck/>")); 485 "<updatecheck/>"));
487 486
488 // Tests the scenario where: 487 // Tests the scenario where:
489 // * the component supports group policies. 488 // * the component supports group policies.
490 // * the component updates are disabled. 489 // * the component updates are disabled.
491 // Expects the update check to include the "updatedisabled" attribute. 490 // Expects the update check to include the "updatedisabled" attribute.
492 component->crx_component_.supports_group_policy_enable_component_updates = 491 component->crx_component_.supports_group_policy_enable_component_updates =
493 true; 492 true;
494 update_checker_ = UpdateChecker::Create(config_, metadata_.get()); 493 update_checker_ = UpdateChecker::Create(config_);
495 update_checker_->CheckForUpdates( 494 update_checker_->CheckForUpdates(
496 std::vector<std::string>{kUpdateItemId}, components, "", false, 495 std::vector<std::string>{kUpdateItemId}, components, "", false,
497 base::Bind(&UpdateCheckerTest::UpdateCheckComplete, 496 base::Bind(&UpdateCheckerTest::UpdateCheckComplete,
498 base::Unretained(this))); 497 base::Unretained(this)));
499 RunThreads(); 498 RunThreads();
500 EXPECT_NE(string::npos, post_interceptor_->GetRequests()[1].find( 499 EXPECT_NE(string::npos, post_interceptor_->GetRequests()[1].find(
501 std::string("<app appid=\"") + kUpdateItemId + 500 std::string("<app appid=\"") + kUpdateItemId +
502 "\" version=\"0.9\">" 501 "\" version=\"0.9\">"
503 "<updatecheck updatedisabled=\"true\"/>")); 502 "<updatecheck updatedisabled=\"true\"/>"));
504 503
505 // Tests the scenario where: 504 // Tests the scenario where:
506 // * the component does not support group policies. 505 // * the component does not support group policies.
507 // * the component updates are enabled. 506 // * the component updates are enabled.
508 // Expects the update check to not include the "updatedisabled" attribute. 507 // Expects the update check to not include the "updatedisabled" attribute.
509 component->crx_component_.supports_group_policy_enable_component_updates = 508 component->crx_component_.supports_group_policy_enable_component_updates =
510 false; 509 false;
511 update_checker_ = UpdateChecker::Create(config_, metadata_.get()); 510 update_checker_ = UpdateChecker::Create(config_);
512 update_checker_->CheckForUpdates( 511 update_checker_->CheckForUpdates(
513 std::vector<std::string>{kUpdateItemId}, components, "", true, 512 std::vector<std::string>{kUpdateItemId}, components, "", true,
514 base::Bind(&UpdateCheckerTest::UpdateCheckComplete, 513 base::Bind(&UpdateCheckerTest::UpdateCheckComplete,
515 base::Unretained(this))); 514 base::Unretained(this)));
516 RunThreads(); 515 RunThreads();
517 EXPECT_NE(string::npos, post_interceptor_->GetRequests()[2].find( 516 EXPECT_NE(string::npos, post_interceptor_->GetRequests()[2].find(
518 std::string("<app appid=\"") + kUpdateItemId + 517 std::string("<app appid=\"") + kUpdateItemId +
519 "\" version=\"0.9\">" 518 "\" version=\"0.9\">"
520 "<updatecheck/>")); 519 "<updatecheck/>"));
521 520
522 // Tests the scenario where: 521 // Tests the scenario where:
523 // * the component supports group policies. 522 // * the component supports group policies.
524 // * the component updates are enabled. 523 // * the component updates are enabled.
525 // Expects the update check to not include the "updatedisabled" attribute. 524 // Expects the update check to not include the "updatedisabled" attribute.
526 component->crx_component_.supports_group_policy_enable_component_updates = 525 component->crx_component_.supports_group_policy_enable_component_updates =
527 true; 526 true;
528 update_checker_ = UpdateChecker::Create(config_, metadata_.get()); 527 update_checker_ = UpdateChecker::Create(config_);
529 update_checker_->CheckForUpdates( 528 update_checker_->CheckForUpdates(
530 std::vector<std::string>{kUpdateItemId}, components, "", true, 529 std::vector<std::string>{kUpdateItemId}, components, "", true,
531 base::Bind(&UpdateCheckerTest::UpdateCheckComplete, 530 base::Bind(&UpdateCheckerTest::UpdateCheckComplete,
532 base::Unretained(this))); 531 base::Unretained(this)));
533 RunThreads(); 532 RunThreads();
534 EXPECT_NE(string::npos, post_interceptor_->GetRequests()[3].find( 533 EXPECT_NE(string::npos, post_interceptor_->GetRequests()[3].find(
535 std::string("<app appid=\"") + kUpdateItemId + 534 std::string("<app appid=\"") + kUpdateItemId +
536 "\" version=\"0.9\">" 535 "\" version=\"0.9\">"
537 "<updatecheck/>")); 536 "<updatecheck/>"));
538 } 537 }
539 538
540 TEST_F(UpdateCheckerTest, NoUpdateActionRun) { 539 TEST_F(UpdateCheckerTest, NoUpdateActionRun) {
541 EXPECT_TRUE(post_interceptor_->ExpectRequest( 540 EXPECT_TRUE(post_interceptor_->ExpectRequest(
542 new PartialMatch("updatecheck"), 541 new PartialMatch("updatecheck"),
543 test_file("updatecheck_reply_noupdate.xml"))); 542 test_file("updatecheck_reply_noupdate.xml")));
544 543
545 update_checker_ = UpdateChecker::Create(config_, metadata_.get()); 544 update_checker_ = UpdateChecker::Create(config_);
546 545
547 IdToComponentPtrMap components; 546 IdToComponentPtrMap components;
548 components[kUpdateItemId] = MakeComponent(); 547 components[kUpdateItemId] = MakeComponent();
549 548
550 auto& component = components[kUpdateItemId]; 549 auto& component = components[kUpdateItemId];
551 550
552 update_checker_->CheckForUpdates( 551 update_checker_->CheckForUpdates(
553 std::vector<std::string>{kUpdateItemId}, components, "", true, 552 std::vector<std::string>{kUpdateItemId}, components, "", true,
554 base::Bind(&UpdateCheckerTest::UpdateCheckComplete, 553 base::Bind(&UpdateCheckerTest::UpdateCheckComplete,
555 base::Unretained(this))); 554 base::Unretained(this)));
556 RunThreads(); 555 RunThreads();
557 556
558 EXPECT_EQ(1, post_interceptor_->GetHitCount()) 557 EXPECT_EQ(1, post_interceptor_->GetHitCount())
559 << post_interceptor_->GetRequestsAsString(); 558 << post_interceptor_->GetRequestsAsString();
560 ASSERT_EQ(1, post_interceptor_->GetCount()) 559 ASSERT_EQ(1, post_interceptor_->GetCount())
561 << post_interceptor_->GetRequestsAsString(); 560 << post_interceptor_->GetRequestsAsString();
562 561
563 EXPECT_EQ(0, error_); 562 EXPECT_EQ(0, error_);
564 EXPECT_STREQ("this", component->action_run_.c_str()); 563 EXPECT_STREQ("this", component->action_run_.c_str());
565 } 564 }
566 565
567 } // namespace update_client 566 } // namespace update_client
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698