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

Side by Side Diff: omaha_request_action_unittest.cc

Issue 6836025: Add support to update_engine to poke Omaha after an update has been applied (Closed) Base URL: http://git.chromium.org/git/update_engine.git@master
Patch Set: Change to use <ping> element with active=1 Created 9 years, 8 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 | Annotate | Revision Log
OLDNEW
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 542 matching lines...) Expand 10 before | Expand all | Expand 10 after
553 EXPECT_CALL(prefs, SetString(kPrefsPreviousVersion, _)).Times(0); 553 EXPECT_CALL(prefs, SetString(kPrefsPreviousVersion, _)).Times(0);
554 ASSERT_FALSE(TestUpdateCheck(&prefs, 554 ASSERT_FALSE(TestUpdateCheck(&prefs,
555 kDefaultTestParams, 555 kDefaultTestParams,
556 "invalid xml>", 556 "invalid xml>",
557 -1, 557 -1,
558 kActionCodeOmahaRequestXMLParseError, 558 kActionCodeOmahaRequestXMLParseError,
559 NULL, // response 559 NULL, // response
560 &post_data)); 560 &post_data));
561 // convert post_data to string 561 // convert post_data to string
562 string post_str(&post_data[0], post_data.size()); 562 string post_str(&post_data[0], post_data.size());
563 EXPECT_NE(post_str.find(" <o:ping a=\"-1\" r=\"-1\"></o:ping>\n" 563 EXPECT_NE(post_str.find(
564 " <o:updatecheck></o:updatecheck>\n"), 564 " <o:ping active=\"1\" a=\"-1\" r=\"-1\"></o:ping>\n"
565 " <o:updatecheck></o:updatecheck>\n"),
565 string::npos); 566 string::npos);
566 EXPECT_NE(post_str.find("hardware_class=\"OEM MODEL 09235 7471\""), 567 EXPECT_NE(post_str.find("hardware_class=\"OEM MODEL 09235 7471\""),
567 string::npos); 568 string::npos);
568 EXPECT_EQ(post_str.find("o:event"), string::npos); 569 EXPECT_EQ(post_str.find("o:event"), string::npos);
569 } 570 }
570 571
571 TEST(OmahaRequestActionTest, FormatUpdateCheckPrevVersionOutputTest) { 572 TEST(OmahaRequestActionTest, FormatUpdateCheckPrevVersionOutputTest) {
572 vector<char> post_data; 573 vector<char> post_data;
573 NiceMock<PrefsMock> prefs; 574 NiceMock<PrefsMock> prefs;
574 EXPECT_CALL(prefs, GetString(kPrefsPreviousVersion, _)) 575 EXPECT_CALL(prefs, GetString(kPrefsPreviousVersion, _))
575 .WillOnce(DoAll(SetArgumentPointee<1>(string("1.2>3.4")), Return(true))); 576 .WillOnce(DoAll(SetArgumentPointee<1>(string("1.2>3.4")), Return(true)));
576 EXPECT_CALL(prefs, SetString(kPrefsPreviousVersion, "")) 577 EXPECT_CALL(prefs, SetString(kPrefsPreviousVersion, ""))
577 .WillOnce(Return(true)); 578 .WillOnce(Return(true));
578 ASSERT_FALSE(TestUpdateCheck(&prefs, 579 ASSERT_FALSE(TestUpdateCheck(&prefs,
579 kDefaultTestParams, 580 kDefaultTestParams,
580 "invalid xml>", 581 "invalid xml>",
581 -1, 582 -1,
582 kActionCodeOmahaRequestXMLParseError, 583 kActionCodeOmahaRequestXMLParseError,
583 NULL, // response 584 NULL, // response
584 &post_data)); 585 &post_data));
585 // convert post_data to string 586 // convert post_data to string
586 string post_str(&post_data[0], post_data.size()); 587 string post_str(&post_data[0], post_data.size());
587 EXPECT_NE(post_str.find(" <o:ping a=\"-1\" r=\"-1\"></o:ping>\n" 588 EXPECT_NE(post_str.find(
588 " <o:updatecheck></o:updatecheck>\n"), 589 " <o:ping active=\"1\" a=\"-1\" r=\"-1\"></o:ping>\n"
590 " <o:updatecheck></o:updatecheck>\n"),
589 string::npos); 591 string::npos);
590 EXPECT_NE(post_str.find("hardware_class=\"OEM MODEL 09235 7471\""), 592 EXPECT_NE(post_str.find("hardware_class=\"OEM MODEL 09235 7471\""),
591 string::npos); 593 string::npos);
592 string prev_version_event = StringPrintf( 594 string prev_version_event = StringPrintf(
593 " <o:event eventtype=\"%d\" eventresult=\"%d\" " 595 " <o:event eventtype=\"%d\" eventresult=\"%d\" "
594 "previousversion=\"1.2&gt;3.4\"></o:event>\n", 596 "previousversion=\"1.2&gt;3.4\"></o:event>\n",
595 OmahaEvent::kTypeUpdateComplete, 597 OmahaEvent::kTypeUpdateComplete,
596 OmahaEvent::kResultSuccessReboot); 598 OmahaEvent::kResultSuccessReboot);
597 EXPECT_NE(post_str.find(prev_version_event), string::npos); 599 EXPECT_NE(post_str.find(prev_version_event), string::npos);
598 } 600 }
(...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after
720 vector<char> post_data; 722 vector<char> post_data;
721 ASSERT_TRUE( 723 ASSERT_TRUE(
722 TestUpdateCheck(&prefs, 724 TestUpdateCheck(&prefs,
723 kDefaultTestParams, 725 kDefaultTestParams,
724 GetNoUpdateResponse(OmahaRequestParams::kAppId), 726 GetNoUpdateResponse(OmahaRequestParams::kAppId),
725 -1, 727 -1,
726 kActionCodeSuccess, 728 kActionCodeSuccess,
727 NULL, 729 NULL,
728 &post_data)); 730 &post_data));
729 string post_str(&post_data[0], post_data.size()); 731 string post_str(&post_data[0], post_data.size());
730 EXPECT_NE(post_str.find("<o:ping a=\"6\" r=\"5\"></o:ping>"), string::npos); 732 EXPECT_NE(post_str.find("<o:ping active=\"1\" a=\"6\" r=\"5\"></o:ping>"),
733 string::npos);
731 } 734 }
732 735
733 TEST(OmahaRequestActionTest, ActivePingTest) { 736 TEST(OmahaRequestActionTest, ActivePingTest) {
734 NiceMock<PrefsMock> prefs; 737 NiceMock<PrefsMock> prefs;
735 int64_t three_days_ago = 738 int64_t three_days_ago =
736 (Time::Now() - TimeDelta::FromHours(3 * 24 + 12)).ToInternalValue(); 739 (Time::Now() - TimeDelta::FromHours(3 * 24 + 12)).ToInternalValue();
737 int64_t now = Time::Now().ToInternalValue(); 740 int64_t now = Time::Now().ToInternalValue();
738 EXPECT_CALL(prefs, GetInt64(kPrefsLastActivePingDay, _)) 741 EXPECT_CALL(prefs, GetInt64(kPrefsLastActivePingDay, _))
739 .WillOnce(DoAll(SetArgumentPointee<1>(three_days_ago), Return(true))); 742 .WillOnce(DoAll(SetArgumentPointee<1>(three_days_ago), Return(true)));
740 EXPECT_CALL(prefs, GetInt64(kPrefsLastRollCallPingDay, _)) 743 EXPECT_CALL(prefs, GetInt64(kPrefsLastRollCallPingDay, _))
741 .WillOnce(DoAll(SetArgumentPointee<1>(now), Return(true))); 744 .WillOnce(DoAll(SetArgumentPointee<1>(now), Return(true)));
742 vector<char> post_data; 745 vector<char> post_data;
743 ASSERT_TRUE( 746 ASSERT_TRUE(
744 TestUpdateCheck(&prefs, 747 TestUpdateCheck(&prefs,
745 kDefaultTestParams, 748 kDefaultTestParams,
746 GetNoUpdateResponse(OmahaRequestParams::kAppId), 749 GetNoUpdateResponse(OmahaRequestParams::kAppId),
747 -1, 750 -1,
748 kActionCodeSuccess, 751 kActionCodeSuccess,
749 NULL, 752 NULL,
750 &post_data)); 753 &post_data));
751 string post_str(&post_data[0], post_data.size()); 754 string post_str(&post_data[0], post_data.size());
752 EXPECT_NE(post_str.find("<o:ping a=\"3\"></o:ping>"), string::npos); 755 EXPECT_NE(post_str.find("<o:ping active=\"1\" a=\"3\"></o:ping>"),
756 string::npos);
753 } 757 }
754 758
755 TEST(OmahaRequestActionTest, RollCallPingTest) { 759 TEST(OmahaRequestActionTest, RollCallPingTest) {
756 NiceMock<PrefsMock> prefs; 760 NiceMock<PrefsMock> prefs;
757 int64_t four_days_ago = 761 int64_t four_days_ago =
758 (Time::Now() - TimeDelta::FromHours(4 * 24)).ToInternalValue(); 762 (Time::Now() - TimeDelta::FromHours(4 * 24)).ToInternalValue();
759 int64_t now = Time::Now().ToInternalValue(); 763 int64_t now = Time::Now().ToInternalValue();
760 EXPECT_CALL(prefs, GetInt64(kPrefsLastActivePingDay, _)) 764 EXPECT_CALL(prefs, GetInt64(kPrefsLastActivePingDay, _))
761 .WillOnce(DoAll(SetArgumentPointee<1>(now), Return(true))); 765 .WillOnce(DoAll(SetArgumentPointee<1>(now), Return(true)));
762 EXPECT_CALL(prefs, GetInt64(kPrefsLastRollCallPingDay, _)) 766 EXPECT_CALL(prefs, GetInt64(kPrefsLastRollCallPingDay, _))
763 .WillOnce(DoAll(SetArgumentPointee<1>(four_days_ago), Return(true))); 767 .WillOnce(DoAll(SetArgumentPointee<1>(four_days_ago), Return(true)));
764 vector<char> post_data; 768 vector<char> post_data;
765 ASSERT_TRUE( 769 ASSERT_TRUE(
766 TestUpdateCheck(&prefs, 770 TestUpdateCheck(&prefs,
767 kDefaultTestParams, 771 kDefaultTestParams,
768 GetNoUpdateResponse(OmahaRequestParams::kAppId), 772 GetNoUpdateResponse(OmahaRequestParams::kAppId),
769 -1, 773 -1,
770 kActionCodeSuccess, 774 kActionCodeSuccess,
771 NULL, 775 NULL,
772 &post_data)); 776 &post_data));
773 string post_str(&post_data[0], post_data.size()); 777 string post_str(&post_data[0], post_data.size());
774 EXPECT_NE(post_str.find("<o:ping r=\"4\"></o:ping>\n"), string::npos); 778 EXPECT_NE(post_str.find("<o:ping active=\"1\" r=\"4\"></o:ping>\n"),
779 string::npos);
775 } 780 }
776 781
777 TEST(OmahaRequestActionTest, NoPingTest) { 782 TEST(OmahaRequestActionTest, NoPingTest) {
778 NiceMock<PrefsMock> prefs; 783 NiceMock<PrefsMock> prefs;
779 int64_t one_hour_ago = 784 int64_t one_hour_ago =
780 (Time::Now() - TimeDelta::FromHours(1)).ToInternalValue(); 785 (Time::Now() - TimeDelta::FromHours(1)).ToInternalValue();
781 EXPECT_CALL(prefs, GetInt64(kPrefsLastActivePingDay, _)) 786 EXPECT_CALL(prefs, GetInt64(kPrefsLastActivePingDay, _))
782 .WillOnce(DoAll(SetArgumentPointee<1>(one_hour_ago), Return(true))); 787 .WillOnce(DoAll(SetArgumentPointee<1>(one_hour_ago), Return(true)));
783 EXPECT_CALL(prefs, GetInt64(kPrefsLastRollCallPingDay, _)) 788 EXPECT_CALL(prefs, GetInt64(kPrefsLastRollCallPingDay, _))
784 .WillOnce(DoAll(SetArgumentPointee<1>(one_hour_ago), Return(true))); 789 .WillOnce(DoAll(SetArgumentPointee<1>(one_hour_ago), Return(true)));
(...skipping 144 matching lines...) Expand 10 before | Expand all | Expand 10 after
929 "", 934 "",
930 1500, 935 1500,
931 static_cast<ActionExitCode>( 936 static_cast<ActionExitCode>(
932 kActionCodeOmahaRequestHTTPResponseBase + 999), 937 kActionCodeOmahaRequestHTTPResponseBase + 999),
933 &response, 938 &response,
934 NULL)); 939 NULL));
935 EXPECT_FALSE(response.update_exists); 940 EXPECT_FALSE(response.update_exists);
936 } 941 }
937 942
938 } // namespace chromeos_update_engine 943 } // namespace chromeos_update_engine
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698