| 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 579 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 590 &response, | 590 &response, |
| 591 &post_data)); | 591 &post_data)); |
| 592 // convert post_data to string | 592 // convert post_data to string |
| 593 string post_str(&post_data[0], post_data.size()); | 593 string post_str(&post_data[0], post_data.size()); |
| 594 EXPECT_NE(post_str.find(" <o:ping active=\"0\"></o:ping>\n" | 594 EXPECT_NE(post_str.find(" <o:ping active=\"0\"></o:ping>\n" |
| 595 " <o:updatecheck></o:updatecheck>\n"), | 595 " <o:updatecheck></o:updatecheck>\n"), |
| 596 string::npos); | 596 string::npos); |
| 597 EXPECT_EQ(post_str.find("o:event"), string::npos); | 597 EXPECT_EQ(post_str.find("o:event"), string::npos); |
| 598 } | 598 } |
| 599 | 599 |
| 600 TEST(OmahaRequestActionTest, FormatSuccessEventOutputTest) { |
| 601 vector<char> post_data; |
| 602 OmahaRequestParams params("machine_id", |
| 603 "user_id", |
| 604 OmahaRequestParams::kOsPlatform, |
| 605 OmahaRequestParams::kOsVersion, |
| 606 "service_pack", |
| 607 "x86-generic", |
| 608 OmahaRequestParams::kAppId, |
| 609 "0.1.0.0", |
| 610 "en-US", |
| 611 "unittest_track", |
| 612 false, // delta okay |
| 613 "http://url"); |
| 614 TestEvent(params, |
| 615 new OmahaEvent(OmahaEvent::kTypeUpdateDownloadStarted), |
| 616 "invalid xml>", |
| 617 &post_data); |
| 618 // convert post_data to string |
| 619 string post_str(&post_data[0], post_data.size()); |
| 620 string expected_event = StringPrintf( |
| 621 " <o:event eventtype=\"%d\" eventresult=\"%d\"></o:event>\n", |
| 622 OmahaEvent::kTypeUpdateDownloadStarted, |
| 623 OmahaEvent::kResultSuccess); |
| 624 EXPECT_NE(post_str.find(expected_event), string::npos); |
| 625 EXPECT_EQ(post_str.find("o:updatecheck"), string::npos); |
| 626 } |
| 627 |
| 628 TEST(OmahaRequestActionTest, FormatErrorEventOutputTest) { |
| 629 vector<char> post_data; |
| 630 OmahaRequestParams params("machine_id", |
| 631 "user_id", |
| 632 OmahaRequestParams::kOsPlatform, |
| 633 OmahaRequestParams::kOsVersion, |
| 634 "service_pack", |
| 635 "x86-generic", |
| 636 OmahaRequestParams::kAppId, |
| 637 "0.1.0.0", |
| 638 "en-US", |
| 639 "unittest_track", |
| 640 false, // delta okay |
| 641 "http://url"); |
| 642 TestEvent(params, |
| 643 new OmahaEvent(OmahaEvent::kTypeDownloadComplete, |
| 644 OmahaEvent::kResultError, |
| 645 kActionCodeError), |
| 646 "invalid xml>", |
| 647 &post_data); |
| 648 // convert post_data to string |
| 649 string post_str(&post_data[0], post_data.size()); |
| 650 string expected_event = StringPrintf( |
| 651 " <o:event eventtype=\"%d\" eventresult=\"%d\" " |
| 652 "errorcode=\"%d\"></o:event>\n", |
| 653 OmahaEvent::kTypeDownloadComplete, |
| 654 OmahaEvent::kResultError, |
| 655 kActionCodeError); |
| 656 EXPECT_NE(post_str.find(expected_event), string::npos); |
| 657 EXPECT_EQ(post_str.find("o:updatecheck"), string::npos); |
| 658 } |
| 659 |
| 600 TEST(OmahaRequestActionTest, FormatEventOutputTest) { | 660 TEST(OmahaRequestActionTest, FormatEventOutputTest) { |
| 601 vector<char> post_data; | 661 vector<char> post_data; |
| 602 OmahaRequestParams params("machine_id", | 662 OmahaRequestParams params("machine_id", |
| 603 "user_id", | 663 "user_id", |
| 604 OmahaRequestParams::kOsPlatform, | 664 OmahaRequestParams::kOsPlatform, |
| 605 OmahaRequestParams::kOsVersion, | 665 OmahaRequestParams::kOsVersion, |
| 606 "service_pack", | 666 "service_pack", |
| 607 "x86-generic", | 667 "x86-generic", |
| 608 OmahaRequestParams::kAppId, | 668 OmahaRequestParams::kAppId, |
| 609 "0.1.0.0", | 669 "0.1.0.0", |
| 610 "en-US", | 670 "en-US", |
| 611 "unittest_track", | 671 "unittest_track", |
| 612 false, // delta okay | 672 false, // delta okay |
| 613 "http://url"); | 673 "http://url"); |
| 614 TestEvent(params, | 674 TestEvent(params, |
| 615 new OmahaEvent(OmahaEvent::kTypeDownloadComplete, | 675 new OmahaEvent(OmahaEvent::kTypeDownloadComplete, |
| 616 OmahaEvent::kResultError, | 676 OmahaEvent::kResultError, |
| 617 5), | 677 kActionCodeError), |
| 618 "invalid xml>", | 678 "invalid xml>", |
| 619 &post_data); | 679 &post_data); |
| 620 // convert post_data to string | 680 // convert post_data to string |
| 621 string post_str(&post_data[0], post_data.size()); | 681 string post_str(&post_data[0], post_data.size()); |
| 622 string expected_event = StringPrintf( | 682 string expected_event = StringPrintf( |
| 623 " <o:event eventtype=\"%d\" eventresult=\"%d\" " | 683 " <o:event eventtype=\"%d\" eventresult=\"%d\" " |
| 624 "errorcode=\"%d\"></o:event>\n", | 684 "errorcode=\"%d\"></o:event>\n", |
| 625 OmahaEvent::kTypeDownloadComplete, | 685 OmahaEvent::kTypeDownloadComplete, |
| 626 OmahaEvent::kResultError, | 686 OmahaEvent::kResultError, |
| 627 5); | 687 kActionCodeError); |
| 628 EXPECT_NE(post_str.find(expected_event), string::npos); | 688 EXPECT_NE(post_str.find(expected_event), string::npos); |
| 629 EXPECT_EQ(post_str.find("o:updatecheck"), string::npos); | 689 EXPECT_EQ(post_str.find("o:updatecheck"), string::npos); |
| 630 } | 690 } |
| 631 | 691 |
| 632 TEST(OmahaRequestActionTest, IsEventTest) { | 692 TEST(OmahaRequestActionTest, IsEventTest) { |
| 633 string http_response("doesn't matter"); | 693 string http_response("doesn't matter"); |
| 634 OmahaRequestParams params("machine_id", | 694 OmahaRequestParams params("machine_id", |
| 635 "user_id", | 695 "user_id", |
| 636 OmahaRequestParams::kOsPlatform, | 696 OmahaRequestParams::kOsPlatform, |
| 637 OmahaRequestParams::kOsVersion, | 697 OmahaRequestParams::kOsVersion, |
| 638 "service_pack", | 698 "service_pack", |
| 639 "x86-generic", | 699 "x86-generic", |
| 640 OmahaRequestParams::kAppId, | 700 OmahaRequestParams::kAppId, |
| 641 "0.1.0.0", | 701 "0.1.0.0", |
| 642 "en-US", | 702 "en-US", |
| 643 "unittest_track", | 703 "unittest_track", |
| 644 false, // delta okay | 704 false, // delta okay |
| 645 "http://url"); | 705 "http://url"); |
| 646 | 706 |
| 647 OmahaRequestAction update_check_action( | 707 OmahaRequestAction update_check_action( |
| 648 params, | 708 params, |
| 649 NULL, | 709 NULL, |
| 650 new MockHttpFetcher(http_response.data(), | 710 new MockHttpFetcher(http_response.data(), |
| 651 http_response.size())); | 711 http_response.size())); |
| 652 EXPECT_FALSE(update_check_action.IsEvent()); | 712 EXPECT_FALSE(update_check_action.IsEvent()); |
| 653 | 713 |
| 654 OmahaRequestAction event_action( | 714 OmahaRequestAction event_action( |
| 655 params, | 715 params, |
| 656 new OmahaEvent(OmahaEvent::kTypeInstallComplete, | 716 new OmahaEvent(OmahaEvent::kTypeUpdateComplete), |
| 657 OmahaEvent::kResultError, | |
| 658 0), | |
| 659 new MockHttpFetcher(http_response.data(), | 717 new MockHttpFetcher(http_response.data(), |
| 660 http_response.size())); | 718 http_response.size())); |
| 661 EXPECT_TRUE(event_action.IsEvent()); | 719 EXPECT_TRUE(event_action.IsEvent()); |
| 662 } | 720 } |
| 663 | 721 |
| 664 TEST(OmahaRequestActionTest, FormatDeltaOkayOutputTest) { | 722 TEST(OmahaRequestActionTest, FormatDeltaOkayOutputTest) { |
| 665 for (int i = 0; i < 2; i++) { | 723 for (int i = 0; i < 2; i++) { |
| 666 bool delta_okay = i == 1; | 724 bool delta_okay = i == 1; |
| 667 const char* delta_okay_str = delta_okay ? "true" : "false"; | 725 const char* delta_okay_str = delta_okay ? "true" : "false"; |
| 668 vector<char> post_data; | 726 vector<char> post_data; |
| (...skipping 15 matching lines...) Expand all Loading... |
| 684 NULL, | 742 NULL, |
| 685 &post_data)); | 743 &post_data)); |
| 686 // convert post_data to string | 744 // convert post_data to string |
| 687 string post_str(&post_data[0], post_data.size()); | 745 string post_str(&post_data[0], post_data.size()); |
| 688 EXPECT_NE(post_str.find(StringPrintf(" delta_okay=\"%s\"", delta_okay_str)), | 746 EXPECT_NE(post_str.find(StringPrintf(" delta_okay=\"%s\"", delta_okay_str)), |
| 689 string::npos) | 747 string::npos) |
| 690 << "i = " << i; | 748 << "i = " << i; |
| 691 } | 749 } |
| 692 } | 750 } |
| 693 | 751 |
| 752 TEST(OmahaRequestActionTest, OmahaEventTest) { |
| 753 OmahaEvent default_event; |
| 754 EXPECT_EQ(OmahaEvent::kTypeUnknown, default_event.type); |
| 755 EXPECT_EQ(OmahaEvent::kResultError, default_event.result); |
| 756 EXPECT_EQ(kActionCodeError, default_event.error_code); |
| 757 |
| 758 OmahaEvent success_event(OmahaEvent::kTypeUpdateDownloadStarted); |
| 759 EXPECT_EQ(OmahaEvent::kTypeUpdateDownloadStarted, success_event.type); |
| 760 EXPECT_EQ(OmahaEvent::kResultSuccess, success_event.result); |
| 761 EXPECT_EQ(kActionCodeSuccess, success_event.error_code); |
| 762 |
| 763 OmahaEvent error_event(OmahaEvent::kTypeUpdateDownloadFinished, |
| 764 OmahaEvent::kResultError, |
| 765 kActionCodeError); |
| 766 EXPECT_EQ(OmahaEvent::kTypeUpdateDownloadFinished, error_event.type); |
| 767 EXPECT_EQ(OmahaEvent::kResultError, error_event.result); |
| 768 EXPECT_EQ(kActionCodeError, error_event.error_code); |
| 769 } |
| 770 |
| 694 } // namespace chromeos_update_engine | 771 } // namespace chromeos_update_engine |
| OLD | NEW |