| 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 "components/update_client/update_checker.h" | 5 #include "components/update_client/update_checker.h" |
| 6 | 6 |
| 7 #include <memory> | 7 #include <memory> |
| 8 | 8 |
| 9 #include "base/bind.h" | 9 #include "base/bind.h" |
| 10 #include "base/bind_helpers.h" | 10 #include "base/bind_helpers.h" |
| (...skipping 178 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 189 // Sanity check the request. | 189 // Sanity check the request. |
| 190 EXPECT_NE(string::npos, post_interceptor_->GetRequests()[0].find( | 190 EXPECT_NE(string::npos, post_interceptor_->GetRequests()[0].find( |
| 191 "request protocol=\"3.0\" extra=\"params\"")); | 191 "request protocol=\"3.0\" extra=\"params\"")); |
| 192 // The request must not contain any "dlpref" in the default case. | 192 // The request must not contain any "dlpref" in the default case. |
| 193 EXPECT_EQ(string::npos, | 193 EXPECT_EQ(string::npos, |
| 194 post_interceptor_->GetRequests()[0].find(" dlpref=\"")); | 194 post_interceptor_->GetRequests()[0].find(" dlpref=\"")); |
| 195 EXPECT_NE( | 195 EXPECT_NE( |
| 196 string::npos, | 196 string::npos, |
| 197 post_interceptor_->GetRequests()[0].find( | 197 post_interceptor_->GetRequests()[0].find( |
| 198 "<app appid=\"jebgalgnebhfojomionfpkfelancnnkf\" version=\"0.9\" " | 198 "<app appid=\"jebgalgnebhfojomionfpkfelancnnkf\" version=\"0.9\" " |
| 199 "brand=\"TEST\" ap=\"some_ap\"><updatecheck /><ping rd=\"-2\" ")); | 199 "brand=\"TEST\" ap=\"some_ap\"><updatecheck/><ping rd=\"-2\" ")); |
| 200 EXPECT_NE(string::npos, | 200 EXPECT_NE(string::npos, |
| 201 post_interceptor_->GetRequests()[0].find( | 201 post_interceptor_->GetRequests()[0].find( |
| 202 "<packages><package fp=\"fp1\"/></packages></app>")); | 202 "<packages><package fp=\"fp1\"/></packages></app>")); |
| 203 | 203 |
| 204 EXPECT_NE(string::npos, | 204 EXPECT_NE(string::npos, |
| 205 post_interceptor_->GetRequests()[0].find("<hw physmemory=")); | 205 post_interceptor_->GetRequests()[0].find("<hw physmemory=")); |
| 206 | 206 |
| 207 // Sanity check the arguments of the callback after parsing. | 207 // Sanity check the arguments of the callback after parsing. |
| 208 EXPECT_EQ(0, error_); | 208 EXPECT_EQ(0, error_); |
| 209 EXPECT_EQ(1ul, results_.list.size()); | 209 EXPECT_EQ(1ul, results_.list.size()); |
| (...skipping 18 matching lines...) Expand all Loading... |
| 228 update_checker_->CheckForUpdates( | 228 update_checker_->CheckForUpdates( |
| 229 items_to_check, "", base::Bind(&UpdateCheckerTest::UpdateCheckComplete, | 229 items_to_check, "", base::Bind(&UpdateCheckerTest::UpdateCheckComplete, |
| 230 base::Unretained(this))); | 230 base::Unretained(this))); |
| 231 | 231 |
| 232 RunThreads(); | 232 RunThreads(); |
| 233 | 233 |
| 234 EXPECT_NE( | 234 EXPECT_NE( |
| 235 string::npos, | 235 string::npos, |
| 236 post_interceptor_->GetRequests()[0].find( | 236 post_interceptor_->GetRequests()[0].find( |
| 237 "app appid=\"jebgalgnebhfojomionfpkfelancnnkf\" version=\"0.9\" " | 237 "app appid=\"jebgalgnebhfojomionfpkfelancnnkf\" version=\"0.9\" " |
| 238 "brand=\"TEST\"><updatecheck /><ping rd=\"-2\" ")); | 238 "brand=\"TEST\"><updatecheck/><ping rd=\"-2\" ")); |
| 239 EXPECT_NE(string::npos, | 239 EXPECT_NE(string::npos, |
| 240 post_interceptor_->GetRequests()[0].find( | 240 post_interceptor_->GetRequests()[0].find( |
| 241 "<packages><package fp=\"fp1\"/></packages></app>")); | 241 "<packages><package fp=\"fp1\"/></packages></app>")); |
| 242 } | 242 } |
| 243 | 243 |
| 244 TEST_F(UpdateCheckerTest, UpdateCheckSuccessNoBrand) { | 244 TEST_F(UpdateCheckerTest, UpdateCheckSuccessNoBrand) { |
| 245 EXPECT_TRUE(post_interceptor_->ExpectRequest( | 245 EXPECT_TRUE(post_interceptor_->ExpectRequest( |
| 246 new PartialMatch("updatecheck"), test_file("updatecheck_reply_1.xml"))); | 246 new PartialMatch("updatecheck"), test_file("updatecheck_reply_1.xml"))); |
| 247 | 247 |
| 248 config_->SetBrand("TOOLONG"); // Sets an invalid brand code. | 248 config_->SetBrand("TOOLONG"); // Sets an invalid brand code. |
| 249 update_checker_ = UpdateChecker::Create(config_, metadata_.get()); | 249 update_checker_ = UpdateChecker::Create(config_, metadata_.get()); |
| 250 | 250 |
| 251 CrxUpdateItem item(BuildCrxUpdateItem()); | 251 CrxUpdateItem item(BuildCrxUpdateItem()); |
| 252 std::vector<CrxUpdateItem*> items_to_check; | 252 std::vector<CrxUpdateItem*> items_to_check; |
| 253 items_to_check.push_back(&item); | 253 items_to_check.push_back(&item); |
| 254 | 254 |
| 255 update_checker_->CheckForUpdates( | 255 update_checker_->CheckForUpdates( |
| 256 items_to_check, "", base::Bind(&UpdateCheckerTest::UpdateCheckComplete, | 256 items_to_check, "", base::Bind(&UpdateCheckerTest::UpdateCheckComplete, |
| 257 base::Unretained(this))); | 257 base::Unretained(this))); |
| 258 | 258 |
| 259 RunThreads(); | 259 RunThreads(); |
| 260 | 260 |
| 261 EXPECT_NE( | 261 EXPECT_NE( |
| 262 string::npos, | 262 string::npos, |
| 263 post_interceptor_->GetRequests()[0].find( | 263 post_interceptor_->GetRequests()[0].find( |
| 264 "<app appid=\"jebgalgnebhfojomionfpkfelancnnkf\" version=\"0.9\">" | 264 "<app appid=\"jebgalgnebhfojomionfpkfelancnnkf\" version=\"0.9\">" |
| 265 "<updatecheck /><ping rd=\"-2\" ")); | 265 "<updatecheck/><ping rd=\"-2\" ")); |
| 266 EXPECT_NE(string::npos, | 266 EXPECT_NE(string::npos, |
| 267 post_interceptor_->GetRequests()[0].find( | 267 post_interceptor_->GetRequests()[0].find( |
| 268 "<packages><package fp=\"fp1\"/></packages></app>")); | 268 "<packages><package fp=\"fp1\"/></packages></app>")); |
| 269 } | 269 } |
| 270 | 270 |
| 271 // Simulates a 403 server response error. | 271 // Simulates a 403 server response error. |
| 272 TEST_F(UpdateCheckerTest, UpdateCheckError) { | 272 TEST_F(UpdateCheckerTest, UpdateCheckError) { |
| 273 EXPECT_TRUE( | 273 EXPECT_TRUE( |
| 274 post_interceptor_->ExpectRequest(new PartialMatch("updatecheck"), 403)); | 274 post_interceptor_->ExpectRequest(new PartialMatch("updatecheck"), 403)); |
| 275 | 275 |
| (...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 340 EXPECT_EQ(1, post_interceptor_->GetHitCount()) | 340 EXPECT_EQ(1, post_interceptor_->GetHitCount()) |
| 341 << post_interceptor_->GetRequestsAsString(); | 341 << post_interceptor_->GetRequestsAsString(); |
| 342 ASSERT_EQ(1, post_interceptor_->GetCount()) | 342 ASSERT_EQ(1, post_interceptor_->GetCount()) |
| 343 << post_interceptor_->GetRequestsAsString(); | 343 << post_interceptor_->GetRequestsAsString(); |
| 344 | 344 |
| 345 // Sanity check the request. | 345 // Sanity check the request. |
| 346 EXPECT_NE( | 346 EXPECT_NE( |
| 347 string::npos, | 347 string::npos, |
| 348 post_interceptor_->GetRequests()[0].find( | 348 post_interceptor_->GetRequests()[0].find( |
| 349 "<app appid=\"jebgalgnebhfojomionfpkfelancnnkf\" version=\"0.9\" " | 349 "<app appid=\"jebgalgnebhfojomionfpkfelancnnkf\" version=\"0.9\" " |
| 350 "brand=\"TEST\"><updatecheck /><ping rd=\"-2\" ")); | 350 "brand=\"TEST\"><updatecheck/><ping rd=\"-2\" ")); |
| 351 EXPECT_NE(string::npos, | 351 EXPECT_NE(string::npos, |
| 352 post_interceptor_->GetRequests()[0].find( | 352 post_interceptor_->GetRequests()[0].find( |
| 353 "<packages><package fp=\"fp1\"/></packages></app>")); | 353 "<packages><package fp=\"fp1\"/></packages></app>")); |
| 354 | 354 |
| 355 // Expect an error since the response is not trusted. | 355 // Expect an error since the response is not trusted. |
| 356 EXPECT_EQ(-10000, error_); | 356 EXPECT_EQ(-10000, error_); |
| 357 EXPECT_EQ(0ul, results_.list.size()); | 357 EXPECT_EQ(0ul, results_.list.size()); |
| 358 } | 358 } |
| 359 | 359 |
| 360 // Tests that the UpdateCheckers will not make an update check for a | 360 // Tests that the UpdateCheckers will not make an update check for a |
| (...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 408 EXPECT_EQ(2, post_interceptor_->GetHitCount()) | 408 EXPECT_EQ(2, post_interceptor_->GetHitCount()) |
| 409 << post_interceptor_->GetRequestsAsString(); | 409 << post_interceptor_->GetRequestsAsString(); |
| 410 ASSERT_EQ(2, post_interceptor_->GetCount()) | 410 ASSERT_EQ(2, post_interceptor_->GetCount()) |
| 411 << post_interceptor_->GetRequestsAsString(); | 411 << post_interceptor_->GetRequestsAsString(); |
| 412 EXPECT_NE(string::npos, post_interceptor_->GetRequests()[0].find( | 412 EXPECT_NE(string::npos, post_interceptor_->GetRequests()[0].find( |
| 413 "<ping rd=\"-2\" ping_freshness=")); | 413 "<ping rd=\"-2\" ping_freshness=")); |
| 414 EXPECT_NE(string::npos, post_interceptor_->GetRequests()[1].find( | 414 EXPECT_NE(string::npos, post_interceptor_->GetRequests()[1].find( |
| 415 "<ping rd=\"3383\" ping_freshness=")); | 415 "<ping rd=\"3383\" ping_freshness=")); |
| 416 } | 416 } |
| 417 | 417 |
| 418 TEST_F(UpdateCheckerTest, UpdateCheckUpdateDisabled) { |
| 419 EXPECT_TRUE(post_interceptor_->ExpectRequest( |
| 420 new PartialMatch("updatecheck"), test_file("updatecheck_reply_1.xml"))); |
| 421 |
| 422 config_->SetBrand(""); |
| 423 update_checker_ = UpdateChecker::Create(config_, metadata_.get()); |
| 424 |
| 425 CrxUpdateItem item(BuildCrxUpdateItem()); |
| 426 |
| 427 // Tests the scenario where: |
| 428 // * the component does not support group policies. |
| 429 // * the component updates are disabled. |
| 430 // Expects the group policy to be ignored and the update check to not |
| 431 // include the "updatedisabled" attribute. |
| 432 EXPECT_FALSE(item.component.supports_group_policy_enable_component_updates); |
| 433 config_->SetEnabledComponentUpdates(false); |
| 434 std::vector<CrxUpdateItem*> items_to_check; |
| 435 items_to_check.push_back(&item); |
| 436 update_checker_->CheckForUpdates( |
| 437 items_to_check, "", base::Bind(&UpdateCheckerTest::UpdateCheckComplete, |
| 438 base::Unretained(this))); |
| 439 RunThreads(); |
| 440 EXPECT_NE( |
| 441 string::npos, |
| 442 post_interceptor_->GetRequests()[0].find( |
| 443 "<app appid=\"jebgalgnebhfojomionfpkfelancnnkf\" version=\"0.9\">" |
| 444 "<updatecheck/>")); |
| 445 |
| 446 // Tests the scenario where: |
| 447 // * the component supports group policies. |
| 448 // * the component updates are disabled. |
| 449 // Expects the update check to include the "updatedisabled" attribute. |
| 450 item.component.supports_group_policy_enable_component_updates = true; |
| 451 config_->SetEnabledComponentUpdates(false); |
| 452 update_checker_ = UpdateChecker::Create(config_, metadata_.get()); |
| 453 update_checker_->CheckForUpdates( |
| 454 items_to_check, "", base::Bind(&UpdateCheckerTest::UpdateCheckComplete, |
| 455 base::Unretained(this))); |
| 456 RunThreads(); |
| 457 EXPECT_NE( |
| 458 string::npos, |
| 459 post_interceptor_->GetRequests()[1].find( |
| 460 "<app appid=\"jebgalgnebhfojomionfpkfelancnnkf\" version=\"0.9\">" |
| 461 "<updatecheck updatedisabled=\"true\"/>")); |
| 462 |
| 463 // Tests the scenario where: |
| 464 // * the component does not support group policies. |
| 465 // * the component updates are enabled. |
| 466 // Expects the update check to not include the "updatedisabled" attribute. |
| 467 item.component.supports_group_policy_enable_component_updates = false; |
| 468 config_->SetEnabledComponentUpdates(true); |
| 469 update_checker_ = UpdateChecker::Create(config_, metadata_.get()); |
| 470 update_checker_->CheckForUpdates( |
| 471 items_to_check, "", base::Bind(&UpdateCheckerTest::UpdateCheckComplete, |
| 472 base::Unretained(this))); |
| 473 RunThreads(); |
| 474 EXPECT_NE( |
| 475 string::npos, |
| 476 post_interceptor_->GetRequests()[2].find( |
| 477 "<app appid=\"jebgalgnebhfojomionfpkfelancnnkf\" version=\"0.9\">" |
| 478 "<updatecheck/>")); |
| 479 |
| 480 // Tests the scenario where: |
| 481 // * the component supports group policies. |
| 482 // * the component updates are enabled. |
| 483 // Expects the update check to not include the "updatedisabled" attribute. |
| 484 item.component.supports_group_policy_enable_component_updates = true; |
| 485 config_->SetEnabledComponentUpdates(true); |
| 486 update_checker_ = UpdateChecker::Create(config_, metadata_.get()); |
| 487 update_checker_->CheckForUpdates( |
| 488 items_to_check, "", base::Bind(&UpdateCheckerTest::UpdateCheckComplete, |
| 489 base::Unretained(this))); |
| 490 RunThreads(); |
| 491 EXPECT_NE( |
| 492 string::npos, |
| 493 post_interceptor_->GetRequests()[3].find( |
| 494 "<app appid=\"jebgalgnebhfojomionfpkfelancnnkf\" version=\"0.9\">" |
| 495 "<updatecheck/>")); |
| 496 } |
| 497 |
| 418 } // namespace update_client | 498 } // namespace update_client |
| OLD | NEW |