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

Side by Side Diff: update_attempter_unittest.cc

Issue 5301002: AU: More UpdateAttempter unit tests. (Closed) Base URL: ssh://git@gitrw.chromium.org:9222/update_engine.git@master
Patch Set: Created 10 years 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 | « update_attempter.h ('k') | update_check_scheduler.h » ('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 <base/file_util.h> 5 #include <base/file_util.h>
6 #include <gtest/gtest.h> 6 #include <gtest/gtest.h>
7 7
8 #include "update_engine/action_mock.h" 8 #include "update_engine/action_mock.h"
9 #include "update_engine/action_processor_mock.h" 9 #include "update_engine/action_processor_mock.h"
10 #include "update_engine/filesystem_copier_action.h" 10 #include "update_engine/filesystem_copier_action.h"
11 #include "update_engine/mock_dbus_interface.h" 11 #include "update_engine/mock_dbus_interface.h"
12 #include "update_engine/mock_http_fetcher.h"
12 #include "update_engine/postinstall_runner_action.h" 13 #include "update_engine/postinstall_runner_action.h"
13 #include "update_engine/prefs_mock.h" 14 #include "update_engine/prefs_mock.h"
15 #include "update_engine/test_utils.h"
14 #include "update_engine/update_attempter.h" 16 #include "update_engine/update_attempter.h"
17 #include "update_engine/update_check_scheduler.h"
15 18
16 using std::string; 19 using std::string;
17 using testing::_; 20 using testing::_;
18 using testing::DoAll; 21 using testing::DoAll;
19 using testing::InSequence; 22 using testing::InSequence;
20 using testing::Ne; 23 using testing::Ne;
21 using testing::NiceMock; 24 using testing::NiceMock;
22 using testing::Property; 25 using testing::Property;
23 using testing::Return; 26 using testing::Return;
24 using testing::SetArgumentPointee; 27 using testing::SetArgumentPointee;
(...skipping 30 matching lines...) Expand all
55 processor_ = new ActionProcessorMock(); 58 processor_ = new ActionProcessorMock();
56 attempter_.processor_.reset(processor_); // Transfers ownership. 59 attempter_.processor_.reset(processor_); // Transfers ownership.
57 attempter_.prefs_ = &prefs_; 60 attempter_.prefs_ = &prefs_;
58 } 61 }
59 62
60 UpdateAttempterUnderTest attempter_; 63 UpdateAttempterUnderTest attempter_;
61 ActionProcessorMock* processor_; 64 ActionProcessorMock* processor_;
62 NiceMock<PrefsMock> prefs_; 65 NiceMock<PrefsMock> prefs_;
63 }; 66 };
64 67
68 TEST_F(UpdateAttempterTest, ActionCompletedDownloadTest) {
69 scoped_ptr<MockHttpFetcher> fetcher(new MockHttpFetcher("", 0, NULL));
70 fetcher->FailTransfer(503); // Sets the HTTP response code.
71 DownloadAction action(&prefs_, fetcher.release());
72 EXPECT_CALL(prefs_, GetInt64(kPrefsDeltaUpdateFailures, _)).Times(0);
73 attempter_.ActionCompleted(NULL, &action, kActionCodeSuccess);
74 EXPECT_EQ(503, attempter_.http_response_code());
75 EXPECT_EQ(UPDATE_STATUS_FINALIZING, attempter_.status());
76 ASSERT_TRUE(attempter_.error_event_.get() == NULL);
77 }
78
79 TEST_F(UpdateAttempterTest, ActionCompletedErrorTest) {
80 ActionMock action;
81 EXPECT_CALL(action, Type()).WillRepeatedly(Return("ActionMock"));
82 attempter_.status_ = UPDATE_STATUS_DOWNLOADING;
83 EXPECT_CALL(prefs_, GetInt64(kPrefsDeltaUpdateFailures, _))
84 .WillOnce(Return(false));
85 attempter_.ActionCompleted(NULL, &action, kActionCodeError);
86 ASSERT_TRUE(attempter_.error_event_.get() != NULL);
87 }
88
89 TEST_F(UpdateAttempterTest, ActionCompletedOmahaRequestTest) {
90 scoped_ptr<MockHttpFetcher> fetcher(new MockHttpFetcher("", 0, NULL));
91 fetcher->FailTransfer(500); // Sets the HTTP response code.
92 OmahaRequestParams params;
93 OmahaRequestAction action(&prefs_, params, NULL, fetcher.release());
94 ObjectCollectorAction<OmahaResponse> collector_action;
95 BondActions(&action, &collector_action);
96 OmahaResponse response;
97 response.poll_interval = 234;
98 action.SetOutputObject(response);
99 UpdateCheckScheduler scheduler(&attempter_);
100 attempter_.set_update_check_scheduler(&scheduler);
101 EXPECT_CALL(prefs_, GetInt64(kPrefsDeltaUpdateFailures, _)).Times(0);
102 attempter_.ActionCompleted(NULL, &action, kActionCodeSuccess);
103 EXPECT_EQ(500, attempter_.http_response_code());
104 EXPECT_EQ(UPDATE_STATUS_IDLE, attempter_.status());
105 EXPECT_EQ(234, scheduler.poll_interval());
106 ASSERT_TRUE(attempter_.error_event_.get() == NULL);
107 }
108
65 TEST_F(UpdateAttempterTest, RunAsRootConstructWithUpdatedMarkerTest) { 109 TEST_F(UpdateAttempterTest, RunAsRootConstructWithUpdatedMarkerTest) {
66 extern const char* kUpdateCompletedMarker; 110 extern const char* kUpdateCompletedMarker;
67 const FilePath kMarker(kUpdateCompletedMarker); 111 const FilePath kMarker(kUpdateCompletedMarker);
68 EXPECT_EQ(0, file_util::WriteFile(kMarker, "", 0)); 112 EXPECT_EQ(0, file_util::WriteFile(kMarker, "", 0));
69 UpdateAttempterUnderTest attempter; 113 UpdateAttempterUnderTest attempter;
70 EXPECT_EQ(UPDATE_STATUS_UPDATED_NEED_REBOOT, attempter.status()); 114 EXPECT_EQ(UPDATE_STATUS_UPDATED_NEED_REBOOT, attempter.status());
71 EXPECT_TRUE(file_util::Delete(kMarker, false)); 115 EXPECT_TRUE(file_util::Delete(kMarker, false));
72 } 116 }
73 117
74 TEST_F(UpdateAttempterTest, GetErrorCodeForActionTest) { 118 TEST_F(UpdateAttempterTest, GetErrorCodeForActionTest) {
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after
134 .WillRepeatedly(Return(true)); 178 .WillRepeatedly(Return(true));
135 EXPECT_CALL(prefs_, SetInt64(kPrefsDeltaUpdateFailures, 1)).Times(2); 179 EXPECT_CALL(prefs_, SetInt64(kPrefsDeltaUpdateFailures, 1)).Times(2);
136 EXPECT_CALL(prefs_, SetInt64(kPrefsDeltaUpdateFailures, 2)).Times(1); 180 EXPECT_CALL(prefs_, SetInt64(kPrefsDeltaUpdateFailures, 2)).Times(1);
137 EXPECT_CALL(prefs_, SetInt64(kPrefsDeltaUpdateFailures, 181 EXPECT_CALL(prefs_, SetInt64(kPrefsDeltaUpdateFailures,
138 UpdateAttempter::kMaxDeltaUpdateFailures + 1)) 182 UpdateAttempter::kMaxDeltaUpdateFailures + 1))
139 .Times(1); 183 .Times(1);
140 for (int i = 0; i < 4; i ++) 184 for (int i = 0; i < 4; i ++)
141 attempter_.MarkDeltaUpdateFailure(); 185 attempter_.MarkDeltaUpdateFailure();
142 } 186 }
143 187
188 TEST_F(UpdateAttempterTest, ScheduleErrorEventActionNoEventTest) {
189 EXPECT_CALL(*processor_, EnqueueAction(_)).Times(0);
190 EXPECT_CALL(*processor_, StartProcessing()).Times(0);
191 attempter_.ScheduleErrorEventAction();
192 }
193
194 TEST_F(UpdateAttempterTest, ScheduleErrorEventActionTest) {
195 EXPECT_CALL(*processor_,
196 EnqueueAction(Property(&AbstractAction::Type,
197 OmahaRequestAction::StaticType())))
198 .Times(1);
199 EXPECT_CALL(*processor_, StartProcessing()).Times(1);
200 attempter_.error_event_.reset(new OmahaEvent(OmahaEvent::kTypeUpdateComplete,
201 OmahaEvent::kResultError,
202 kActionCodeError));
203 attempter_.ScheduleErrorEventAction();
204 EXPECT_EQ(UPDATE_STATUS_REPORTING_ERROR_EVENT, attempter_.status());
205 }
206
144 TEST_F(UpdateAttempterTest, UpdateStatusToStringTest) { 207 TEST_F(UpdateAttempterTest, UpdateStatusToStringTest) {
145 extern const char* UpdateStatusToString(UpdateStatus); 208 extern const char* UpdateStatusToString(UpdateStatus);
146 EXPECT_STREQ("UPDATE_STATUS_IDLE", UpdateStatusToString(UPDATE_STATUS_IDLE)); 209 EXPECT_STREQ("UPDATE_STATUS_IDLE", UpdateStatusToString(UPDATE_STATUS_IDLE));
147 EXPECT_STREQ("UPDATE_STATUS_CHECKING_FOR_UPDATE", 210 EXPECT_STREQ("UPDATE_STATUS_CHECKING_FOR_UPDATE",
148 UpdateStatusToString(UPDATE_STATUS_CHECKING_FOR_UPDATE)); 211 UpdateStatusToString(UPDATE_STATUS_CHECKING_FOR_UPDATE));
149 EXPECT_STREQ("UPDATE_STATUS_UPDATE_AVAILABLE", 212 EXPECT_STREQ("UPDATE_STATUS_UPDATE_AVAILABLE",
150 UpdateStatusToString(UPDATE_STATUS_UPDATE_AVAILABLE)); 213 UpdateStatusToString(UPDATE_STATUS_UPDATE_AVAILABLE));
151 EXPECT_STREQ("UPDATE_STATUS_DOWNLOADING", 214 EXPECT_STREQ("UPDATE_STATUS_DOWNLOADING",
152 UpdateStatusToString(UPDATE_STATUS_DOWNLOADING)); 215 UpdateStatusToString(UPDATE_STATUS_DOWNLOADING));
153 EXPECT_STREQ("UPDATE_STATUS_VERIFYING", 216 EXPECT_STREQ("UPDATE_STATUS_VERIFYING",
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
194 EXPECT_EQ(attempter_.response_handler_action_.get(), 257 EXPECT_EQ(attempter_.response_handler_action_.get(),
195 attempter_.actions_[1].get()); 258 attempter_.actions_[1].get());
196 DownloadAction* download_action = 259 DownloadAction* download_action =
197 dynamic_cast<DownloadAction*>(attempter_.actions_[5].get()); 260 dynamic_cast<DownloadAction*>(attempter_.actions_[5].get());
198 ASSERT_TRUE(download_action != NULL); 261 ASSERT_TRUE(download_action != NULL);
199 EXPECT_EQ(&attempter_, download_action->delegate()); 262 EXPECT_EQ(&attempter_, download_action->delegate());
200 EXPECT_EQ(UPDATE_STATUS_CHECKING_FOR_UPDATE, attempter_.status()); 263 EXPECT_EQ(UPDATE_STATUS_CHECKING_FOR_UPDATE, attempter_.status());
201 } 264 }
202 265
203 } // namespace chromeos_update_engine 266 } // namespace chromeos_update_engine
OLDNEW
« no previous file with comments | « update_attempter.h ('k') | update_check_scheduler.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698