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

Side by Side Diff: omaha_request_action_unittest.cc

Issue 5141004: AU: Use NiceMock<PrefsMock to suppress uninteresting call warnings. (Closed) Base URL: ssh://git@gitrw.chromium.org:9222/update_engine.git@master
Patch Set: Created 10 years, 1 month 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
« no previous file with comments | « no previous file | omaha_response_handler_action_unittest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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"
11 #include "base/time.h" 11 #include "base/time.h"
12 #include "gtest/gtest.h" 12 #include "gtest/gtest.h"
13 #include "update_engine/action_pipe.h" 13 #include "update_engine/action_pipe.h"
14 #include "update_engine/mock_http_fetcher.h" 14 #include "update_engine/mock_http_fetcher.h"
15 #include "update_engine/omaha_hash_calculator.h" 15 #include "update_engine/omaha_hash_calculator.h"
16 #include "update_engine/omaha_request_action.h" 16 #include "update_engine/omaha_request_action.h"
17 #include "update_engine/omaha_request_params.h" 17 #include "update_engine/omaha_request_params.h"
18 #include "update_engine/prefs_mock.h" 18 #include "update_engine/prefs_mock.h"
19 #include "update_engine/test_utils.h" 19 #include "update_engine/test_utils.h"
20 20
21 using base::Time; 21 using base::Time;
22 using base::TimeDelta; 22 using base::TimeDelta;
23 using std::string; 23 using std::string;
24 using std::vector; 24 using std::vector;
25 using testing::_; 25 using testing::_;
26 using testing::AllOf; 26 using testing::AllOf;
27 using testing::Ge; 27 using testing::Ge;
28 using testing::Le; 28 using testing::Le;
29 using testing::NiceMock;
29 using testing::Return; 30 using testing::Return;
30 using testing::SetArgumentPointee; 31 using testing::SetArgumentPointee;
31 32
32 namespace chromeos_update_engine { 33 namespace chromeos_update_engine {
33 34
34 class OmahaRequestActionTest : public ::testing::Test { }; 35 class OmahaRequestActionTest : public ::testing::Test { };
35 36
36 namespace { 37 namespace {
37 const OmahaRequestParams kDefaultTestParams( 38 const OmahaRequestParams kDefaultTestParams(
38 OmahaRequestParams::kOsPlatform, 39 OmahaRequestParams::kOsPlatform,
(...skipping 117 matching lines...) Expand 10 before | Expand all | Expand 10 after
156 int fail_http_response_code, 157 int fail_http_response_code,
157 ActionExitCode expected_code, 158 ActionExitCode expected_code,
158 OmahaResponse* out_response, 159 OmahaResponse* out_response,
159 vector<char>* out_post_data) { 160 vector<char>* out_post_data) {
160 GMainLoop* loop = g_main_loop_new(g_main_context_default(), FALSE); 161 GMainLoop* loop = g_main_loop_new(g_main_context_default(), FALSE);
161 MockHttpFetcher* fetcher = new MockHttpFetcher(http_response.data(), 162 MockHttpFetcher* fetcher = new MockHttpFetcher(http_response.data(),
162 http_response.size()); 163 http_response.size());
163 if (fail_http_response_code >= 0) { 164 if (fail_http_response_code >= 0) {
164 fetcher->FailTransfer(fail_http_response_code); 165 fetcher->FailTransfer(fail_http_response_code);
165 } 166 }
166 PrefsMock local_prefs; 167 NiceMock<PrefsMock> local_prefs;
167 OmahaRequestAction action(prefs ? prefs : &local_prefs, 168 OmahaRequestAction action(prefs ? prefs : &local_prefs,
168 params, 169 params,
169 NULL, 170 NULL,
170 fetcher); 171 fetcher);
171 OmahaRequestActionTestProcessorDelegate delegate; 172 OmahaRequestActionTestProcessorDelegate delegate;
172 delegate.loop_ = loop; 173 delegate.loop_ = loop;
173 delegate.expected_code_ = expected_code; 174 delegate.expected_code_ = expected_code;
174 175
175 ActionProcessor processor; 176 ActionProcessor processor;
176 processor.set_delegate(&delegate); 177 processor.set_delegate(&delegate);
(...skipping 16 matching lines...) Expand all
193 // Tests Event requests -- they should always succeed. |out_post_data| 194 // Tests Event requests -- they should always succeed. |out_post_data|
194 // may be null; if non-null, the post-data received by the mock 195 // may be null; if non-null, the post-data received by the mock
195 // HttpFetcher is returned. 196 // HttpFetcher is returned.
196 void TestEvent(const OmahaRequestParams& params, 197 void TestEvent(const OmahaRequestParams& params,
197 OmahaEvent* event, 198 OmahaEvent* event,
198 const string& http_response, 199 const string& http_response,
199 vector<char>* out_post_data) { 200 vector<char>* out_post_data) {
200 GMainLoop* loop = g_main_loop_new(g_main_context_default(), FALSE); 201 GMainLoop* loop = g_main_loop_new(g_main_context_default(), FALSE);
201 MockHttpFetcher* fetcher = new MockHttpFetcher(http_response.data(), 202 MockHttpFetcher* fetcher = new MockHttpFetcher(http_response.data(),
202 http_response.size()); 203 http_response.size());
203 PrefsMock prefs; 204 NiceMock<PrefsMock> prefs;
204 OmahaRequestAction action(&prefs, params, event, fetcher); 205 OmahaRequestAction action(&prefs, params, event, fetcher);
205 OmahaRequestActionTestProcessorDelegate delegate; 206 OmahaRequestActionTestProcessorDelegate delegate;
206 delegate.loop_ = loop; 207 delegate.loop_ = loop;
207 ActionProcessor processor; 208 ActionProcessor processor;
208 processor.set_delegate(&delegate); 209 processor.set_delegate(&delegate);
209 processor.EnqueueAction(&action); 210 processor.EnqueueAction(&action);
210 211
211 g_timeout_add(0, &StartProcessorInRunLoop, &processor); 212 g_timeout_add(0, &StartProcessorInRunLoop, &processor);
212 g_main_loop_run(loop); 213 g_main_loop_run(loop);
213 g_main_loop_unref(loop); 214 g_main_loop_unref(loop);
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
256 EXPECT_FALSE(response.needs_admin); 257 EXPECT_FALSE(response.needs_admin);
257 EXPECT_TRUE(response.prompt); 258 EXPECT_TRUE(response.prompt);
258 EXPECT_EQ("20101020", response.deadline); 259 EXPECT_EQ("20101020", response.deadline);
259 } 260 }
260 261
261 TEST(OmahaRequestActionTest, NoOutputPipeTest) { 262 TEST(OmahaRequestActionTest, NoOutputPipeTest) {
262 const string http_response(GetNoUpdateResponse(OmahaRequestParams::kAppId)); 263 const string http_response(GetNoUpdateResponse(OmahaRequestParams::kAppId));
263 264
264 GMainLoop *loop = g_main_loop_new(g_main_context_default(), FALSE); 265 GMainLoop *loop = g_main_loop_new(g_main_context_default(), FALSE);
265 266
266 PrefsMock prefs; 267 NiceMock<PrefsMock> prefs;
267 OmahaRequestAction action(&prefs, kDefaultTestParams, NULL, 268 OmahaRequestAction action(&prefs, kDefaultTestParams, NULL,
268 new MockHttpFetcher(http_response.data(), 269 new MockHttpFetcher(http_response.data(),
269 http_response.size())); 270 http_response.size()));
270 OmahaRequestActionTestProcessorDelegate delegate; 271 OmahaRequestActionTestProcessorDelegate delegate;
271 delegate.loop_ = loop; 272 delegate.loop_ = loop;
272 ActionProcessor processor; 273 ActionProcessor processor;
273 processor.set_delegate(&delegate); 274 processor.set_delegate(&delegate);
274 processor.EnqueueAction(&action); 275 processor.EnqueueAction(&action);
275 276
276 g_timeout_add(0, &StartProcessorInRunLoop, &processor); 277 g_timeout_add(0, &StartProcessorInRunLoop, &processor);
(...skipping 126 matching lines...) Expand 10 before | Expand all | Expand 10 after
403 CHECK(processor->IsRunning()); 404 CHECK(processor->IsRunning());
404 processor->StopProcessing(); 405 processor->StopProcessing();
405 return FALSE; 406 return FALSE;
406 } 407 }
407 } // namespace {} 408 } // namespace {}
408 409
409 TEST(OmahaRequestActionTest, TerminateTransferTest) { 410 TEST(OmahaRequestActionTest, TerminateTransferTest) {
410 string http_response("doesn't matter"); 411 string http_response("doesn't matter");
411 GMainLoop *loop = g_main_loop_new(g_main_context_default(), FALSE); 412 GMainLoop *loop = g_main_loop_new(g_main_context_default(), FALSE);
412 413
413 PrefsMock prefs; 414 NiceMock<PrefsMock> prefs;
414 OmahaRequestAction action(&prefs, kDefaultTestParams, NULL, 415 OmahaRequestAction action(&prefs, kDefaultTestParams, NULL,
415 new MockHttpFetcher(http_response.data(), 416 new MockHttpFetcher(http_response.data(),
416 http_response.size())); 417 http_response.size()));
417 TerminateEarlyTestProcessorDelegate delegate; 418 TerminateEarlyTestProcessorDelegate delegate;
418 delegate.loop_ = loop; 419 delegate.loop_ = loop;
419 ActionProcessor processor; 420 ActionProcessor processor;
420 processor.set_delegate(&delegate); 421 processor.set_delegate(&delegate);
421 processor.EnqueueAction(&action); 422 processor.EnqueueAction(&action);
422 423
423 g_timeout_add(0, &TerminateTransferTestStarter, &processor); 424 g_timeout_add(0, &TerminateTransferTestStarter, &processor);
(...skipping 161 matching lines...) Expand 10 before | Expand all | Expand 10 after
585 "errorcode=\"%d\"></o:event>\n", 586 "errorcode=\"%d\"></o:event>\n",
586 OmahaEvent::kTypeDownloadComplete, 587 OmahaEvent::kTypeDownloadComplete,
587 OmahaEvent::kResultError, 588 OmahaEvent::kResultError,
588 kActionCodeError); 589 kActionCodeError);
589 EXPECT_NE(post_str.find(expected_event), string::npos); 590 EXPECT_NE(post_str.find(expected_event), string::npos);
590 EXPECT_EQ(post_str.find("o:updatecheck"), string::npos); 591 EXPECT_EQ(post_str.find("o:updatecheck"), string::npos);
591 } 592 }
592 593
593 TEST(OmahaRequestActionTest, IsEventTest) { 594 TEST(OmahaRequestActionTest, IsEventTest) {
594 string http_response("doesn't matter"); 595 string http_response("doesn't matter");
595 PrefsMock prefs; 596 NiceMock<PrefsMock> prefs;
596 OmahaRequestAction update_check_action( 597 OmahaRequestAction update_check_action(
597 &prefs, 598 &prefs,
598 kDefaultTestParams, 599 kDefaultTestParams,
599 NULL, 600 NULL,
600 new MockHttpFetcher(http_response.data(), 601 new MockHttpFetcher(http_response.data(),
601 http_response.size())); 602 http_response.size()));
602 EXPECT_FALSE(update_check_action.IsEvent()); 603 EXPECT_FALSE(update_check_action.IsEvent());
603 604
604 OmahaRequestAction event_action( 605 OmahaRequestAction event_action(
605 &prefs, 606 &prefs,
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
654 655
655 OmahaEvent error_event(OmahaEvent::kTypeUpdateDownloadFinished, 656 OmahaEvent error_event(OmahaEvent::kTypeUpdateDownloadFinished,
656 OmahaEvent::kResultError, 657 OmahaEvent::kResultError,
657 kActionCodeError); 658 kActionCodeError);
658 EXPECT_EQ(OmahaEvent::kTypeUpdateDownloadFinished, error_event.type); 659 EXPECT_EQ(OmahaEvent::kTypeUpdateDownloadFinished, error_event.type);
659 EXPECT_EQ(OmahaEvent::kResultError, error_event.result); 660 EXPECT_EQ(OmahaEvent::kResultError, error_event.result);
660 EXPECT_EQ(kActionCodeError, error_event.error_code); 661 EXPECT_EQ(kActionCodeError, error_event.error_code);
661 } 662 }
662 663
663 TEST(OmahaRequestActionTest, PingTest) { 664 TEST(OmahaRequestActionTest, PingTest) {
664 PrefsMock prefs; 665 NiceMock<PrefsMock> prefs;
665 // Add a few hours to the day difference to test no rounding, etc. 666 // Add a few hours to the day difference to test no rounding, etc.
666 int64_t five_days_ago = 667 int64_t five_days_ago =
667 (Time::Now() - TimeDelta::FromHours(5 * 24 + 13)).ToInternalValue(); 668 (Time::Now() - TimeDelta::FromHours(5 * 24 + 13)).ToInternalValue();
668 int64_t six_days_ago = 669 int64_t six_days_ago =
669 (Time::Now() - TimeDelta::FromHours(6 * 24 + 11)).ToInternalValue(); 670 (Time::Now() - TimeDelta::FromHours(6 * 24 + 11)).ToInternalValue();
670 EXPECT_CALL(prefs, GetInt64(kPrefsLastActivePingDay, _)) 671 EXPECT_CALL(prefs, GetInt64(kPrefsLastActivePingDay, _))
671 .WillOnce(DoAll(SetArgumentPointee<1>(six_days_ago), Return(true))); 672 .WillOnce(DoAll(SetArgumentPointee<1>(six_days_ago), Return(true)));
672 EXPECT_CALL(prefs, GetInt64(kPrefsLastRollCallPingDay, _)) 673 EXPECT_CALL(prefs, GetInt64(kPrefsLastRollCallPingDay, _))
673 .WillOnce(DoAll(SetArgumentPointee<1>(five_days_ago), Return(true))); 674 .WillOnce(DoAll(SetArgumentPointee<1>(five_days_ago), Return(true)));
674 vector<char> post_data; 675 vector<char> post_data;
675 ASSERT_TRUE( 676 ASSERT_TRUE(
676 TestUpdateCheck(&prefs, 677 TestUpdateCheck(&prefs,
677 kDefaultTestParams, 678 kDefaultTestParams,
678 GetNoUpdateResponse(OmahaRequestParams::kAppId), 679 GetNoUpdateResponse(OmahaRequestParams::kAppId),
679 -1, 680 -1,
680 kActionCodeSuccess, 681 kActionCodeSuccess,
681 NULL, 682 NULL,
682 &post_data)); 683 &post_data));
683 string post_str(&post_data[0], post_data.size()); 684 string post_str(&post_data[0], post_data.size());
684 EXPECT_NE(post_str.find("<o:ping a=\"6\" r=\"5\"></o:ping>"), string::npos); 685 EXPECT_NE(post_str.find("<o:ping a=\"6\" r=\"5\"></o:ping>"), string::npos);
685 } 686 }
686 687
687 TEST(OmahaRequestActionTest, ActivePingTest) { 688 TEST(OmahaRequestActionTest, ActivePingTest) {
688 PrefsMock prefs; 689 NiceMock<PrefsMock> prefs;
689 int64_t three_days_ago = 690 int64_t three_days_ago =
690 (Time::Now() - TimeDelta::FromHours(3 * 24 + 12)).ToInternalValue(); 691 (Time::Now() - TimeDelta::FromHours(3 * 24 + 12)).ToInternalValue();
691 int64_t now = Time::Now().ToInternalValue(); 692 int64_t now = Time::Now().ToInternalValue();
692 EXPECT_CALL(prefs, GetInt64(kPrefsLastActivePingDay, _)) 693 EXPECT_CALL(prefs, GetInt64(kPrefsLastActivePingDay, _))
693 .WillOnce(DoAll(SetArgumentPointee<1>(three_days_ago), Return(true))); 694 .WillOnce(DoAll(SetArgumentPointee<1>(three_days_ago), Return(true)));
694 EXPECT_CALL(prefs, GetInt64(kPrefsLastRollCallPingDay, _)) 695 EXPECT_CALL(prefs, GetInt64(kPrefsLastRollCallPingDay, _))
695 .WillOnce(DoAll(SetArgumentPointee<1>(now), Return(true))); 696 .WillOnce(DoAll(SetArgumentPointee<1>(now), Return(true)));
696 vector<char> post_data; 697 vector<char> post_data;
697 ASSERT_TRUE( 698 ASSERT_TRUE(
698 TestUpdateCheck(&prefs, 699 TestUpdateCheck(&prefs,
699 kDefaultTestParams, 700 kDefaultTestParams,
700 GetNoUpdateResponse(OmahaRequestParams::kAppId), 701 GetNoUpdateResponse(OmahaRequestParams::kAppId),
701 -1, 702 -1,
702 kActionCodeSuccess, 703 kActionCodeSuccess,
703 NULL, 704 NULL,
704 &post_data)); 705 &post_data));
705 string post_str(&post_data[0], post_data.size()); 706 string post_str(&post_data[0], post_data.size());
706 EXPECT_NE(post_str.find("<o:ping a=\"3\"></o:ping>"), string::npos); 707 EXPECT_NE(post_str.find("<o:ping a=\"3\"></o:ping>"), string::npos);
707 } 708 }
708 709
709 TEST(OmahaRequestActionTest, RollCallPingTest) { 710 TEST(OmahaRequestActionTest, RollCallPingTest) {
710 PrefsMock prefs; 711 NiceMock<PrefsMock> prefs;
711 int64_t four_days_ago = 712 int64_t four_days_ago =
712 (Time::Now() - TimeDelta::FromHours(4 * 24)).ToInternalValue(); 713 (Time::Now() - TimeDelta::FromHours(4 * 24)).ToInternalValue();
713 int64_t now = Time::Now().ToInternalValue(); 714 int64_t now = Time::Now().ToInternalValue();
714 EXPECT_CALL(prefs, GetInt64(kPrefsLastActivePingDay, _)) 715 EXPECT_CALL(prefs, GetInt64(kPrefsLastActivePingDay, _))
715 .WillOnce(DoAll(SetArgumentPointee<1>(now), Return(true))); 716 .WillOnce(DoAll(SetArgumentPointee<1>(now), Return(true)));
716 EXPECT_CALL(prefs, GetInt64(kPrefsLastRollCallPingDay, _)) 717 EXPECT_CALL(prefs, GetInt64(kPrefsLastRollCallPingDay, _))
717 .WillOnce(DoAll(SetArgumentPointee<1>(four_days_ago), Return(true))); 718 .WillOnce(DoAll(SetArgumentPointee<1>(four_days_ago), Return(true)));
718 vector<char> post_data; 719 vector<char> post_data;
719 ASSERT_TRUE( 720 ASSERT_TRUE(
720 TestUpdateCheck(&prefs, 721 TestUpdateCheck(&prefs,
721 kDefaultTestParams, 722 kDefaultTestParams,
722 GetNoUpdateResponse(OmahaRequestParams::kAppId), 723 GetNoUpdateResponse(OmahaRequestParams::kAppId),
723 -1, 724 -1,
724 kActionCodeSuccess, 725 kActionCodeSuccess,
725 NULL, 726 NULL,
726 &post_data)); 727 &post_data));
727 string post_str(&post_data[0], post_data.size()); 728 string post_str(&post_data[0], post_data.size());
728 EXPECT_NE(post_str.find("<o:ping r=\"4\"></o:ping>\n"), string::npos); 729 EXPECT_NE(post_str.find("<o:ping r=\"4\"></o:ping>\n"), string::npos);
729 } 730 }
730 731
731 TEST(OmahaRequestActionTest, NoPingTest) { 732 TEST(OmahaRequestActionTest, NoPingTest) {
732 PrefsMock prefs; 733 NiceMock<PrefsMock> prefs;
733 int64_t one_hour_ago = 734 int64_t one_hour_ago =
734 (Time::Now() - TimeDelta::FromHours(1)).ToInternalValue(); 735 (Time::Now() - TimeDelta::FromHours(1)).ToInternalValue();
735 EXPECT_CALL(prefs, GetInt64(kPrefsLastActivePingDay, _)) 736 EXPECT_CALL(prefs, GetInt64(kPrefsLastActivePingDay, _))
736 .WillOnce(DoAll(SetArgumentPointee<1>(one_hour_ago), Return(true))); 737 .WillOnce(DoAll(SetArgumentPointee<1>(one_hour_ago), Return(true)));
737 EXPECT_CALL(prefs, GetInt64(kPrefsLastRollCallPingDay, _)) 738 EXPECT_CALL(prefs, GetInt64(kPrefsLastRollCallPingDay, _))
738 .WillOnce(DoAll(SetArgumentPointee<1>(one_hour_ago), Return(true))); 739 .WillOnce(DoAll(SetArgumentPointee<1>(one_hour_ago), Return(true)));
739 EXPECT_CALL(prefs, SetInt64(kPrefsLastActivePingDay, _)).Times(0); 740 EXPECT_CALL(prefs, SetInt64(kPrefsLastActivePingDay, _)).Times(0);
740 EXPECT_CALL(prefs, SetInt64(kPrefsLastRollCallPingDay, _)).Times(0); 741 EXPECT_CALL(prefs, SetInt64(kPrefsLastRollCallPingDay, _)).Times(0);
741 vector<char> post_data; 742 vector<char> post_data;
742 ASSERT_TRUE( 743 ASSERT_TRUE(
743 TestUpdateCheck(&prefs, 744 TestUpdateCheck(&prefs,
744 kDefaultTestParams, 745 kDefaultTestParams,
745 GetNoUpdateResponse(OmahaRequestParams::kAppId), 746 GetNoUpdateResponse(OmahaRequestParams::kAppId),
746 -1, 747 -1,
747 kActionCodeSuccess, 748 kActionCodeSuccess,
748 NULL, 749 NULL,
749 &post_data)); 750 &post_data));
750 string post_str(&post_data[0], post_data.size()); 751 string post_str(&post_data[0], post_data.size());
751 EXPECT_EQ(post_str.find("o:ping"), string::npos); 752 EXPECT_EQ(post_str.find("o:ping"), string::npos);
752 } 753 }
753 754
754 TEST(OmahaRequestActionTest, BackInTimePingTest) { 755 TEST(OmahaRequestActionTest, BackInTimePingTest) {
755 PrefsMock prefs; 756 NiceMock<PrefsMock> prefs;
756 int64_t future = 757 int64_t future =
757 (Time::Now() + TimeDelta::FromHours(3 * 24 + 4)).ToInternalValue(); 758 (Time::Now() + TimeDelta::FromHours(3 * 24 + 4)).ToInternalValue();
758 EXPECT_CALL(prefs, GetInt64(kPrefsLastActivePingDay, _)) 759 EXPECT_CALL(prefs, GetInt64(kPrefsLastActivePingDay, _))
759 .WillOnce(DoAll(SetArgumentPointee<1>(future), Return(true))); 760 .WillOnce(DoAll(SetArgumentPointee<1>(future), Return(true)));
760 EXPECT_CALL(prefs, GetInt64(kPrefsLastRollCallPingDay, _)) 761 EXPECT_CALL(prefs, GetInt64(kPrefsLastRollCallPingDay, _))
761 .WillOnce(DoAll(SetArgumentPointee<1>(future), Return(true))); 762 .WillOnce(DoAll(SetArgumentPointee<1>(future), Return(true)));
762 EXPECT_CALL(prefs, SetInt64(kPrefsLastActivePingDay, _)) 763 EXPECT_CALL(prefs, SetInt64(kPrefsLastActivePingDay, _))
763 .WillOnce(Return(true)); 764 .WillOnce(Return(true));
764 EXPECT_CALL(prefs, SetInt64(kPrefsLastRollCallPingDay, _)) 765 EXPECT_CALL(prefs, SetInt64(kPrefsLastRollCallPingDay, _))
765 .WillOnce(Return(true)); 766 .WillOnce(Return(true));
(...skipping 16 matching lines...) Expand all
782 783
783 TEST(OmahaRequestActionTest, LastPingDayUpdateTest) { 784 TEST(OmahaRequestActionTest, LastPingDayUpdateTest) {
784 // This test checks that the action updates the last ping day to now 785 // This test checks that the action updates the last ping day to now
785 // minus 200 seconds with a slack of 5 seconds. Therefore, the test 786 // minus 200 seconds with a slack of 5 seconds. Therefore, the test
786 // may fail if it runs for longer than 5 seconds. It shouldn't run 787 // may fail if it runs for longer than 5 seconds. It shouldn't run
787 // that long though. 788 // that long though.
788 int64_t midnight = 789 int64_t midnight =
789 (Time::Now() - TimeDelta::FromSeconds(200)).ToInternalValue(); 790 (Time::Now() - TimeDelta::FromSeconds(200)).ToInternalValue();
790 int64_t midnight_slack = 791 int64_t midnight_slack =
791 (Time::Now() - TimeDelta::FromSeconds(195)).ToInternalValue(); 792 (Time::Now() - TimeDelta::FromSeconds(195)).ToInternalValue();
792 PrefsMock prefs; 793 NiceMock<PrefsMock> prefs;
793 EXPECT_CALL(prefs, SetInt64(kPrefsLastActivePingDay, 794 EXPECT_CALL(prefs, SetInt64(kPrefsLastActivePingDay,
794 AllOf(Ge(midnight), Le(midnight_slack)))) 795 AllOf(Ge(midnight), Le(midnight_slack))))
795 .WillOnce(Return(true)); 796 .WillOnce(Return(true));
796 EXPECT_CALL(prefs, SetInt64(kPrefsLastRollCallPingDay, 797 EXPECT_CALL(prefs, SetInt64(kPrefsLastRollCallPingDay,
797 AllOf(Ge(midnight), Le(midnight_slack)))) 798 AllOf(Ge(midnight), Le(midnight_slack))))
798 .WillOnce(Return(true)); 799 .WillOnce(Return(true));
799 ASSERT_TRUE( 800 ASSERT_TRUE(
800 TestUpdateCheck(&prefs, 801 TestUpdateCheck(&prefs,
801 kDefaultTestParams, 802 kDefaultTestParams,
802 "<?xml version=\"1.0\" encoding=\"UTF-8\"?><gupdate " 803 "<?xml version=\"1.0\" encoding=\"UTF-8\"?><gupdate "
803 "xmlns=\"http://www.google.com/update2/response\" " 804 "xmlns=\"http://www.google.com/update2/response\" "
804 "protocol=\"2.0\"><daystart elapsed_seconds=\"200\"/>" 805 "protocol=\"2.0\"><daystart elapsed_seconds=\"200\"/>"
805 "<app appid=\"foo\" status=\"ok\"><ping status=\"ok\"/>" 806 "<app appid=\"foo\" status=\"ok\"><ping status=\"ok\"/>"
806 "<updatecheck status=\"noupdate\"/></app></gupdate>", 807 "<updatecheck status=\"noupdate\"/></app></gupdate>",
807 -1, 808 -1,
808 kActionCodeSuccess, 809 kActionCodeSuccess,
809 NULL, 810 NULL,
810 NULL)); 811 NULL));
811 } 812 }
812 813
813 TEST(OmahaRequestActionTest, NoElapsedSecondsTest) { 814 TEST(OmahaRequestActionTest, NoElapsedSecondsTest) {
814 PrefsMock prefs; 815 NiceMock<PrefsMock> prefs;
815 EXPECT_CALL(prefs, SetInt64(kPrefsLastActivePingDay, _)).Times(0); 816 EXPECT_CALL(prefs, SetInt64(kPrefsLastActivePingDay, _)).Times(0);
816 EXPECT_CALL(prefs, SetInt64(kPrefsLastRollCallPingDay, _)).Times(0); 817 EXPECT_CALL(prefs, SetInt64(kPrefsLastRollCallPingDay, _)).Times(0);
817 ASSERT_TRUE( 818 ASSERT_TRUE(
818 TestUpdateCheck(&prefs, 819 TestUpdateCheck(&prefs,
819 kDefaultTestParams, 820 kDefaultTestParams,
820 "<?xml version=\"1.0\" encoding=\"UTF-8\"?><gupdate " 821 "<?xml version=\"1.0\" encoding=\"UTF-8\"?><gupdate "
821 "xmlns=\"http://www.google.com/update2/response\" " 822 "xmlns=\"http://www.google.com/update2/response\" "
822 "protocol=\"2.0\"><daystart blah=\"200\"/>" 823 "protocol=\"2.0\"><daystart blah=\"200\"/>"
823 "<app appid=\"foo\" status=\"ok\"><ping status=\"ok\"/>" 824 "<app appid=\"foo\" status=\"ok\"><ping status=\"ok\"/>"
824 "<updatecheck status=\"noupdate\"/></app></gupdate>", 825 "<updatecheck status=\"noupdate\"/></app></gupdate>",
825 -1, 826 -1,
826 kActionCodeSuccess, 827 kActionCodeSuccess,
827 NULL, 828 NULL,
828 NULL)); 829 NULL));
829 } 830 }
830 831
831 TEST(OmahaRequestActionTest, BadElapsedSecondsTest) { 832 TEST(OmahaRequestActionTest, BadElapsedSecondsTest) {
832 PrefsMock prefs; 833 NiceMock<PrefsMock> prefs;
833 EXPECT_CALL(prefs, SetInt64(kPrefsLastActivePingDay, _)).Times(0); 834 EXPECT_CALL(prefs, SetInt64(kPrefsLastActivePingDay, _)).Times(0);
834 EXPECT_CALL(prefs, SetInt64(kPrefsLastRollCallPingDay, _)).Times(0); 835 EXPECT_CALL(prefs, SetInt64(kPrefsLastRollCallPingDay, _)).Times(0);
835 ASSERT_TRUE( 836 ASSERT_TRUE(
836 TestUpdateCheck(&prefs, 837 TestUpdateCheck(&prefs,
837 kDefaultTestParams, 838 kDefaultTestParams,
838 "<?xml version=\"1.0\" encoding=\"UTF-8\"?><gupdate " 839 "<?xml version=\"1.0\" encoding=\"UTF-8\"?><gupdate "
839 "xmlns=\"http://www.google.com/update2/response\" " 840 "xmlns=\"http://www.google.com/update2/response\" "
840 "protocol=\"2.0\"><daystart elapsed_seconds=\"x\"/>" 841 "protocol=\"2.0\"><daystart elapsed_seconds=\"x\"/>"
841 "<app appid=\"foo\" status=\"ok\"><ping status=\"ok\"/>" 842 "<app appid=\"foo\" status=\"ok\"><ping status=\"ok\"/>"
842 "<updatecheck status=\"noupdate\"/></app></gupdate>", 843 "<updatecheck status=\"noupdate\"/></app></gupdate>",
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
883 "", 884 "",
884 1500, 885 1500,
885 static_cast<ActionExitCode>( 886 static_cast<ActionExitCode>(
886 kActionCodeOmahaRequestHTTPResponseBase + 999), 887 kActionCodeOmahaRequestHTTPResponseBase + 999),
887 &response, 888 &response,
888 NULL)); 889 NULL));
889 EXPECT_FALSE(response.update_exists); 890 EXPECT_FALSE(response.update_exists);
890 } 891 }
891 892
892 } // namespace chromeos_update_engine 893 } // namespace chromeos_update_engine
OLDNEW
« no previous file with comments | « no previous file | omaha_response_handler_action_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698