| OLD | NEW |
| 1 // Copyright (c) 2010 The Chromium OS Authors. All rights reserved. | 1 // Copyright (c) 2010 The Chromium OS 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 <string> | 5 #include <string> |
| 6 #include <vector> | 6 #include <vector> |
| 7 | 7 |
| 8 #include <glib.h> | 8 #include <glib.h> |
| 9 | 9 |
| 10 #include "base/string_util.h" | 10 #include "base/string_util.h" |
| (...skipping 503 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 514 -1, | 514 -1, |
| 515 kActionCodeSuccess, | 515 kActionCodeSuccess, |
| 516 &response, | 516 &response, |
| 517 NULL)); | 517 NULL)); |
| 518 | 518 |
| 519 EXPECT_EQ(response.size, 123123123123123ll); | 519 EXPECT_EQ(response.size, 123123123123123ll); |
| 520 } | 520 } |
| 521 | 521 |
| 522 TEST(OmahaRequestActionTest, FormatUpdateCheckOutputTest) { | 522 TEST(OmahaRequestActionTest, FormatUpdateCheckOutputTest) { |
| 523 vector<char> post_data; | 523 vector<char> post_data; |
| 524 ASSERT_FALSE(TestUpdateCheck(NULL, // prefs | 524 NiceMock<PrefsMock> prefs; |
| 525 EXPECT_CALL(prefs, GetString(kPrefsPreviousVersion, _)) |
| 526 .WillOnce(DoAll(SetArgumentPointee<1>(string("")), Return(true))); |
| 527 EXPECT_CALL(prefs, SetString(kPrefsPreviousVersion, _)).Times(0); |
| 528 ASSERT_FALSE(TestUpdateCheck(&prefs, |
| 525 kDefaultTestParams, | 529 kDefaultTestParams, |
| 526 "invalid xml>", | 530 "invalid xml>", |
| 527 -1, | 531 -1, |
| 528 kActionCodeOmahaRequestXMLParseError, | 532 kActionCodeOmahaRequestXMLParseError, |
| 529 NULL, // response | 533 NULL, // response |
| 530 &post_data)); | 534 &post_data)); |
| 531 // convert post_data to string | 535 // convert post_data to string |
| 532 string post_str(&post_data[0], post_data.size()); | 536 string post_str(&post_data[0], post_data.size()); |
| 533 EXPECT_NE(post_str.find(" <o:ping a=\"-1\" r=\"-1\"></o:ping>\n" | 537 EXPECT_NE(post_str.find(" <o:ping a=\"-1\" r=\"-1\"></o:ping>\n" |
| 534 " <o:updatecheck></o:updatecheck>\n"), | 538 " <o:updatecheck></o:updatecheck>\n"), |
| 535 string::npos); | 539 string::npos); |
| 536 EXPECT_NE(post_str.find("hardware_class=\"OEM MODEL 09235 7471\""), | 540 EXPECT_NE(post_str.find("hardware_class=\"OEM MODEL 09235 7471\""), |
| 537 string::npos); | 541 string::npos); |
| 538 EXPECT_EQ(post_str.find("o:event"), string::npos); | 542 EXPECT_EQ(post_str.find("o:event"), string::npos); |
| 539 } | 543 } |
| 540 | 544 |
| 545 TEST(OmahaRequestActionTest, FormatUpdateCheckPrevVersionOutputTest) { |
| 546 vector<char> post_data; |
| 547 NiceMock<PrefsMock> prefs; |
| 548 EXPECT_CALL(prefs, GetString(kPrefsPreviousVersion, _)) |
| 549 .WillOnce(DoAll(SetArgumentPointee<1>(string("1.2.3.4")), Return(true))); |
| 550 EXPECT_CALL(prefs, SetString(kPrefsPreviousVersion, "")) |
| 551 .WillOnce(Return(true)); |
| 552 ASSERT_FALSE(TestUpdateCheck(&prefs, |
| 553 kDefaultTestParams, |
| 554 "invalid xml>", |
| 555 -1, |
| 556 kActionCodeOmahaRequestXMLParseError, |
| 557 NULL, // response |
| 558 &post_data)); |
| 559 // convert post_data to string |
| 560 string post_str(&post_data[0], post_data.size()); |
| 561 EXPECT_NE(post_str.find(" <o:ping a=\"-1\" r=\"-1\"></o:ping>\n" |
| 562 " <o:updatecheck></o:updatecheck>\n"), |
| 563 string::npos); |
| 564 EXPECT_NE(post_str.find("hardware_class=\"OEM MODEL 09235 7471\""), |
| 565 string::npos); |
| 566 string prev_version_event = StringPrintf( |
| 567 " <o:event eventtype=\"%d\" eventresult=\"%d\" " |
| 568 "previousversion=\"1.2.3.4\"></o:event>\n", |
| 569 OmahaEvent::kTypeUpdateComplete, |
| 570 OmahaEvent::kResultSuccessReboot); |
| 571 EXPECT_NE(post_str.find(prev_version_event), string::npos); |
| 572 } |
| 573 |
| 541 TEST(OmahaRequestActionTest, FormatSuccessEventOutputTest) { | 574 TEST(OmahaRequestActionTest, FormatSuccessEventOutputTest) { |
| 542 vector<char> post_data; | 575 vector<char> post_data; |
| 543 TestEvent(kDefaultTestParams, | 576 TestEvent(kDefaultTestParams, |
| 544 new OmahaEvent(OmahaEvent::kTypeUpdateDownloadStarted), | 577 new OmahaEvent(OmahaEvent::kTypeUpdateDownloadStarted), |
| 545 "invalid xml>", | 578 "invalid xml>", |
| 546 &post_data); | 579 &post_data); |
| 547 // convert post_data to string | 580 // convert post_data to string |
| 548 string post_str(&post_data[0], post_data.size()); | 581 string post_str(&post_data[0], post_data.size()); |
| 549 string expected_event = StringPrintf( | 582 string expected_event = StringPrintf( |
| 550 " <o:event eventtype=\"%d\" eventresult=\"%d\"></o:event>\n", | 583 " <o:event eventtype=\"%d\" eventresult=\"%d\"></o:event>\n", |
| (...skipping 339 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 890 "", | 923 "", |
| 891 1500, | 924 1500, |
| 892 static_cast<ActionExitCode>( | 925 static_cast<ActionExitCode>( |
| 893 kActionCodeOmahaRequestHTTPResponseBase + 999), | 926 kActionCodeOmahaRequestHTTPResponseBase + 999), |
| 894 &response, | 927 &response, |
| 895 NULL)); | 928 NULL)); |
| 896 EXPECT_FALSE(response.update_exists); | 929 EXPECT_FALSE(response.update_exists); |
| 897 } | 930 } |
| 898 | 931 |
| 899 } // namespace chromeos_update_engine | 932 } // namespace chromeos_update_engine |
| OLD | NEW |