blob: 673471cb8c834c65a9282157488246c5aab32644 [file] [log] [blame]
Darin Petkov18c7bce2011-06-16 14:07:00 -07001// Copyright (c) 2011 The Chromium OS Authors. All rights reserved.
Darin Petkovf42cc1c2010-09-01 09:03:02 -07002// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
5#include <base/file_util.h>
6#include <gtest/gtest.h>
Patrick Dubroy7fbbe8a2011-08-01 17:28:22 +02007#include <policy/libpolicy.h>
8#include <policy/mock_device_policy.h>
Darin Petkovf42cc1c2010-09-01 09:03:02 -07009
10#include "update_engine/action_mock.h"
11#include "update_engine/action_processor_mock.h"
12#include "update_engine/filesystem_copier_action.h"
Andrew de los Reyes45168102010-11-22 11:13:50 -080013#include "update_engine/mock_dbus_interface.h"
Darin Petkov1b003102010-11-30 10:18:36 -080014#include "update_engine/mock_http_fetcher.h"
Darin Petkovf42cc1c2010-09-01 09:03:02 -070015#include "update_engine/postinstall_runner_action.h"
Darin Petkov36275772010-10-01 11:40:57 -070016#include "update_engine/prefs_mock.h"
Darin Petkov1b003102010-11-30 10:18:36 -080017#include "update_engine/test_utils.h"
Darin Petkovf42cc1c2010-09-01 09:03:02 -070018#include "update_engine/update_attempter.h"
Darin Petkov1b003102010-11-30 10:18:36 -080019#include "update_engine/update_check_scheduler.h"
Darin Petkovf42cc1c2010-09-01 09:03:02 -070020
21using std::string;
Darin Petkov36275772010-10-01 11:40:57 -070022using testing::_;
23using testing::DoAll;
Darin Petkovf42cc1c2010-09-01 09:03:02 -070024using testing::InSequence;
Darin Petkov2dd01092010-10-08 15:43:05 -070025using testing::Ne;
Darin Petkov9c096d62010-11-17 14:49:04 -080026using testing::NiceMock;
Darin Petkovf42cc1c2010-09-01 09:03:02 -070027using testing::Property;
28using testing::Return;
Darin Petkov36275772010-10-01 11:40:57 -070029using testing::SetArgumentPointee;
Darin Petkovf42cc1c2010-09-01 09:03:02 -070030
31namespace chromeos_update_engine {
32
33// Test a subclass rather than the main class directly so that we can mock out
Darin Petkovcd1666f2010-09-23 09:53:44 -070034// methods within the class. There're explicit unit tests for the mocked out
Darin Petkovf42cc1c2010-09-01 09:03:02 -070035// methods.
36class UpdateAttempterUnderTest : public UpdateAttempter {
37 public:
Andrew de los Reyes000d8952011-03-02 15:21:14 -080038 explicit UpdateAttempterUnderTest(MockDbusGlib* dbus)
39 : UpdateAttempter(NULL, NULL, dbus) {}
Darin Petkovf42cc1c2010-09-01 09:03:02 -070040};
41
42class UpdateAttempterTest : public ::testing::Test {
43 protected:
Darin Petkove6ef2f82011-03-07 17:31:11 -080044 UpdateAttempterTest() : attempter_(&dbus_), loop_(NULL) {}
Darin Petkovf42cc1c2010-09-01 09:03:02 -070045 virtual void SetUp() {
46 EXPECT_EQ(NULL, attempter_.dbus_service_);
47 EXPECT_EQ(NULL, attempter_.prefs_);
48 EXPECT_EQ(NULL, attempter_.metrics_lib_);
49 EXPECT_EQ(NULL, attempter_.update_check_scheduler_);
50 EXPECT_EQ(0, attempter_.http_response_code_);
51 EXPECT_EQ(utils::kProcessPriorityNormal, attempter_.priority_);
52 EXPECT_EQ(NULL, attempter_.manage_priority_source_);
53 EXPECT_FALSE(attempter_.download_active_);
54 EXPECT_EQ(UPDATE_STATUS_IDLE, attempter_.status_);
55 EXPECT_EQ(0.0, attempter_.download_progress_);
56 EXPECT_EQ(0, attempter_.last_checked_time_);
57 EXPECT_EQ("0.0.0.0", attempter_.new_version_);
58 EXPECT_EQ(0, attempter_.new_size_);
Darin Petkov36275772010-10-01 11:40:57 -070059 EXPECT_FALSE(attempter_.is_full_update_);
Darin Petkovf42cc1c2010-09-01 09:03:02 -070060 processor_ = new ActionProcessorMock();
61 attempter_.processor_.reset(processor_); // Transfers ownership.
Darin Petkov36275772010-10-01 11:40:57 -070062 attempter_.prefs_ = &prefs_;
Darin Petkovf42cc1c2010-09-01 09:03:02 -070063 }
64
Patrick Dubroy7fbbe8a2011-08-01 17:28:22 +020065 void QuitMainLoop();
66 static gboolean StaticQuitMainLoop(gpointer data);
67
Darin Petkove6ef2f82011-03-07 17:31:11 -080068 void UpdateTestStart();
69 void UpdateTestVerify();
70 static gboolean StaticUpdateTestStart(gpointer data);
71 static gboolean StaticUpdateTestVerify(gpointer data);
Patrick Dubroy7fbbe8a2011-08-01 17:28:22 +020072
Thieu Le116fda32011-04-19 11:01:54 -070073 void PingOmahaTestStart();
Thieu Le116fda32011-04-19 11:01:54 -070074 static gboolean StaticPingOmahaTestStart(gpointer data);
Patrick Dubroy7fbbe8a2011-08-01 17:28:22 +020075
76 void ReadTrackFromPolicyTestStart();
77 static gboolean StaticReadTrackFromPolicyTestStart(gpointer data);
Darin Petkove6ef2f82011-03-07 17:31:11 -080078
Andrew de los Reyes000d8952011-03-02 15:21:14 -080079 MockDbusGlib dbus_;
Darin Petkovf42cc1c2010-09-01 09:03:02 -070080 UpdateAttempterUnderTest attempter_;
81 ActionProcessorMock* processor_;
Darin Petkov9c096d62010-11-17 14:49:04 -080082 NiceMock<PrefsMock> prefs_;
Darin Petkove6ef2f82011-03-07 17:31:11 -080083 GMainLoop* loop_;
Darin Petkovf42cc1c2010-09-01 09:03:02 -070084};
85
Darin Petkov1b003102010-11-30 10:18:36 -080086TEST_F(UpdateAttempterTest, ActionCompletedDownloadTest) {
87 scoped_ptr<MockHttpFetcher> fetcher(new MockHttpFetcher("", 0, NULL));
88 fetcher->FailTransfer(503); // Sets the HTTP response code.
89 DownloadAction action(&prefs_, fetcher.release());
90 EXPECT_CALL(prefs_, GetInt64(kPrefsDeltaUpdateFailures, _)).Times(0);
91 attempter_.ActionCompleted(NULL, &action, kActionCodeSuccess);
92 EXPECT_EQ(503, attempter_.http_response_code());
93 EXPECT_EQ(UPDATE_STATUS_FINALIZING, attempter_.status());
94 ASSERT_TRUE(attempter_.error_event_.get() == NULL);
95}
96
97TEST_F(UpdateAttempterTest, ActionCompletedErrorTest) {
98 ActionMock action;
99 EXPECT_CALL(action, Type()).WillRepeatedly(Return("ActionMock"));
100 attempter_.status_ = UPDATE_STATUS_DOWNLOADING;
101 EXPECT_CALL(prefs_, GetInt64(kPrefsDeltaUpdateFailures, _))
102 .WillOnce(Return(false));
103 attempter_.ActionCompleted(NULL, &action, kActionCodeError);
104 ASSERT_TRUE(attempter_.error_event_.get() != NULL);
105}
106
107TEST_F(UpdateAttempterTest, ActionCompletedOmahaRequestTest) {
108 scoped_ptr<MockHttpFetcher> fetcher(new MockHttpFetcher("", 0, NULL));
109 fetcher->FailTransfer(500); // Sets the HTTP response code.
110 OmahaRequestParams params;
Thieu Le116fda32011-04-19 11:01:54 -0700111 OmahaRequestAction action(&prefs_, params, NULL, fetcher.release(), false);
Darin Petkov1b003102010-11-30 10:18:36 -0800112 ObjectCollectorAction<OmahaResponse> collector_action;
113 BondActions(&action, &collector_action);
114 OmahaResponse response;
115 response.poll_interval = 234;
116 action.SetOutputObject(response);
117 UpdateCheckScheduler scheduler(&attempter_);
118 attempter_.set_update_check_scheduler(&scheduler);
119 EXPECT_CALL(prefs_, GetInt64(kPrefsDeltaUpdateFailures, _)).Times(0);
120 attempter_.ActionCompleted(NULL, &action, kActionCodeSuccess);
121 EXPECT_EQ(500, attempter_.http_response_code());
122 EXPECT_EQ(UPDATE_STATUS_IDLE, attempter_.status());
123 EXPECT_EQ(234, scheduler.poll_interval());
124 ASSERT_TRUE(attempter_.error_event_.get() == NULL);
125}
126
Darin Petkovcd1666f2010-09-23 09:53:44 -0700127TEST_F(UpdateAttempterTest, RunAsRootConstructWithUpdatedMarkerTest) {
Darin Petkovf42cc1c2010-09-01 09:03:02 -0700128 extern const char* kUpdateCompletedMarker;
129 const FilePath kMarker(kUpdateCompletedMarker);
130 EXPECT_EQ(0, file_util::WriteFile(kMarker, "", 0));
Andrew de los Reyes000d8952011-03-02 15:21:14 -0800131 MockDbusGlib dbus;
132 UpdateAttempterUnderTest attempter(&dbus);
Darin Petkovf42cc1c2010-09-01 09:03:02 -0700133 EXPECT_EQ(UPDATE_STATUS_UPDATED_NEED_REBOOT, attempter.status());
134 EXPECT_TRUE(file_util::Delete(kMarker, false));
135}
136
137TEST_F(UpdateAttempterTest, GetErrorCodeForActionTest) {
138 extern ActionExitCode GetErrorCodeForAction(AbstractAction* action,
139 ActionExitCode code);
140 EXPECT_EQ(kActionCodeSuccess,
141 GetErrorCodeForAction(NULL, kActionCodeSuccess));
142
143 OmahaRequestParams params;
Thieu Le116fda32011-04-19 11:01:54 -0700144 OmahaRequestAction omaha_request_action(NULL, params, NULL, NULL, false);
Darin Petkovf42cc1c2010-09-01 09:03:02 -0700145 EXPECT_EQ(kActionCodeOmahaRequestError,
146 GetErrorCodeForAction(&omaha_request_action, kActionCodeError));
Darin Petkov73058b42010-10-06 16:32:19 -0700147 OmahaResponseHandlerAction omaha_response_handler_action(&prefs_);
Darin Petkovf42cc1c2010-09-01 09:03:02 -0700148 EXPECT_EQ(kActionCodeOmahaResponseHandlerError,
149 GetErrorCodeForAction(&omaha_response_handler_action,
150 kActionCodeError));
Darin Petkov3aefa862010-12-07 14:45:00 -0800151 FilesystemCopierAction filesystem_copier_action(false, false);
Darin Petkovf42cc1c2010-09-01 09:03:02 -0700152 EXPECT_EQ(kActionCodeFilesystemCopierError,
153 GetErrorCodeForAction(&filesystem_copier_action, kActionCodeError));
Darin Petkov6d5dbf62010-11-08 16:09:55 -0800154 PostinstallRunnerAction postinstall_runner_action;
Darin Petkovf42cc1c2010-09-01 09:03:02 -0700155 EXPECT_EQ(kActionCodePostinstallRunnerError,
156 GetErrorCodeForAction(&postinstall_runner_action,
157 kActionCodeError));
Darin Petkovf42cc1c2010-09-01 09:03:02 -0700158 ActionMock action_mock;
159 EXPECT_CALL(action_mock, Type()).Times(1).WillOnce(Return("ActionMock"));
160 EXPECT_EQ(kActionCodeError,
161 GetErrorCodeForAction(&action_mock, kActionCodeError));
162}
163
Darin Petkov36275772010-10-01 11:40:57 -0700164TEST_F(UpdateAttempterTest, DisableDeltaUpdateIfNeededTest) {
165 attempter_.omaha_request_params_.delta_okay = true;
166 EXPECT_CALL(prefs_, GetInt64(kPrefsDeltaUpdateFailures, _))
167 .WillOnce(Return(false));
168 attempter_.DisableDeltaUpdateIfNeeded();
169 EXPECT_TRUE(attempter_.omaha_request_params_.delta_okay);
170 EXPECT_CALL(prefs_, GetInt64(kPrefsDeltaUpdateFailures, _))
171 .WillOnce(DoAll(
172 SetArgumentPointee<1>(UpdateAttempter::kMaxDeltaUpdateFailures - 1),
173 Return(true)));
174 attempter_.DisableDeltaUpdateIfNeeded();
175 EXPECT_TRUE(attempter_.omaha_request_params_.delta_okay);
176 EXPECT_CALL(prefs_, GetInt64(kPrefsDeltaUpdateFailures, _))
177 .WillOnce(DoAll(
178 SetArgumentPointee<1>(UpdateAttempter::kMaxDeltaUpdateFailures),
179 Return(true)));
180 attempter_.DisableDeltaUpdateIfNeeded();
181 EXPECT_FALSE(attempter_.omaha_request_params_.delta_okay);
182 EXPECT_CALL(prefs_, GetInt64(_, _)).Times(0);
183 attempter_.DisableDeltaUpdateIfNeeded();
184 EXPECT_FALSE(attempter_.omaha_request_params_.delta_okay);
185}
186
187TEST_F(UpdateAttempterTest, MarkDeltaUpdateFailureTest) {
188 attempter_.is_full_update_ = false;
189 EXPECT_CALL(prefs_, GetInt64(kPrefsDeltaUpdateFailures, _))
190 .WillOnce(Return(false))
191 .WillOnce(DoAll(SetArgumentPointee<1>(-1), Return(true)))
192 .WillOnce(DoAll(SetArgumentPointee<1>(1), Return(true)))
193 .WillOnce(DoAll(
194 SetArgumentPointee<1>(UpdateAttempter::kMaxDeltaUpdateFailures),
195 Return(true)));
Darin Petkov2dd01092010-10-08 15:43:05 -0700196 EXPECT_CALL(prefs_, SetInt64(Ne(kPrefsDeltaUpdateFailures), _))
197 .WillRepeatedly(Return(true));
Darin Petkov36275772010-10-01 11:40:57 -0700198 EXPECT_CALL(prefs_, SetInt64(kPrefsDeltaUpdateFailures, 1)).Times(2);
199 EXPECT_CALL(prefs_, SetInt64(kPrefsDeltaUpdateFailures, 2)).Times(1);
200 EXPECT_CALL(prefs_, SetInt64(kPrefsDeltaUpdateFailures,
201 UpdateAttempter::kMaxDeltaUpdateFailures + 1))
202 .Times(1);
203 for (int i = 0; i < 4; i ++)
204 attempter_.MarkDeltaUpdateFailure();
205}
206
Darin Petkov1b003102010-11-30 10:18:36 -0800207TEST_F(UpdateAttempterTest, ScheduleErrorEventActionNoEventTest) {
208 EXPECT_CALL(*processor_, EnqueueAction(_)).Times(0);
209 EXPECT_CALL(*processor_, StartProcessing()).Times(0);
210 attempter_.ScheduleErrorEventAction();
211}
212
213TEST_F(UpdateAttempterTest, ScheduleErrorEventActionTest) {
214 EXPECT_CALL(*processor_,
215 EnqueueAction(Property(&AbstractAction::Type,
216 OmahaRequestAction::StaticType())))
217 .Times(1);
218 EXPECT_CALL(*processor_, StartProcessing()).Times(1);
219 attempter_.error_event_.reset(new OmahaEvent(OmahaEvent::kTypeUpdateComplete,
220 OmahaEvent::kResultError,
221 kActionCodeError));
222 attempter_.ScheduleErrorEventAction();
223 EXPECT_EQ(UPDATE_STATUS_REPORTING_ERROR_EVENT, attempter_.status());
224}
225
Darin Petkovf42cc1c2010-09-01 09:03:02 -0700226TEST_F(UpdateAttempterTest, UpdateStatusToStringTest) {
227 extern const char* UpdateStatusToString(UpdateStatus);
228 EXPECT_STREQ("UPDATE_STATUS_IDLE", UpdateStatusToString(UPDATE_STATUS_IDLE));
229 EXPECT_STREQ("UPDATE_STATUS_CHECKING_FOR_UPDATE",
230 UpdateStatusToString(UPDATE_STATUS_CHECKING_FOR_UPDATE));
231 EXPECT_STREQ("UPDATE_STATUS_UPDATE_AVAILABLE",
232 UpdateStatusToString(UPDATE_STATUS_UPDATE_AVAILABLE));
233 EXPECT_STREQ("UPDATE_STATUS_DOWNLOADING",
234 UpdateStatusToString(UPDATE_STATUS_DOWNLOADING));
235 EXPECT_STREQ("UPDATE_STATUS_VERIFYING",
236 UpdateStatusToString(UPDATE_STATUS_VERIFYING));
237 EXPECT_STREQ("UPDATE_STATUS_FINALIZING",
238 UpdateStatusToString(UPDATE_STATUS_FINALIZING));
239 EXPECT_STREQ("UPDATE_STATUS_UPDATED_NEED_REBOOT",
240 UpdateStatusToString(UPDATE_STATUS_UPDATED_NEED_REBOOT));
241 EXPECT_STREQ("UPDATE_STATUS_REPORTING_ERROR_EVENT",
242 UpdateStatusToString(UPDATE_STATUS_REPORTING_ERROR_EVENT));
243 EXPECT_STREQ("unknown status",
244 UpdateStatusToString(static_cast<UpdateStatus>(-1)));
245}
246
Patrick Dubroy7fbbe8a2011-08-01 17:28:22 +0200247void UpdateAttempterTest::QuitMainLoop() {
248 g_main_loop_quit(loop_);
249}
250
251gboolean UpdateAttempterTest::StaticQuitMainLoop(gpointer data) {
252 reinterpret_cast<UpdateAttempterTest*>(data)->QuitMainLoop();
253 return FALSE;
254}
255
Darin Petkove6ef2f82011-03-07 17:31:11 -0800256gboolean UpdateAttempterTest::StaticUpdateTestStart(gpointer data) {
257 reinterpret_cast<UpdateAttempterTest*>(data)->UpdateTestStart();
258 return FALSE;
259}
260
261gboolean UpdateAttempterTest::StaticUpdateTestVerify(gpointer data) {
262 reinterpret_cast<UpdateAttempterTest*>(data)->UpdateTestVerify();
263 return FALSE;
264}
265
Thieu Le116fda32011-04-19 11:01:54 -0700266gboolean UpdateAttempterTest::StaticPingOmahaTestStart(gpointer data) {
267 reinterpret_cast<UpdateAttempterTest*>(data)->PingOmahaTestStart();
268 return FALSE;
269}
270
Patrick Dubroy7fbbe8a2011-08-01 17:28:22 +0200271gboolean UpdateAttempterTest::StaticReadTrackFromPolicyTestStart(
272 gpointer data) {
273 reinterpret_cast<UpdateAttempterTest*>(data)->ReadTrackFromPolicyTestStart();
Thieu Le116fda32011-04-19 11:01:54 -0700274 return FALSE;
275}
276
Darin Petkove6ef2f82011-03-07 17:31:11 -0800277namespace {
278const string kActionTypes[] = {
279 OmahaRequestAction::StaticType(),
280 OmahaResponseHandlerAction::StaticType(),
281 FilesystemCopierAction::StaticType(),
282 FilesystemCopierAction::StaticType(),
283 OmahaRequestAction::StaticType(),
284 DownloadAction::StaticType(),
285 OmahaRequestAction::StaticType(),
Andrew de los Reyes21816e12011-04-07 14:18:56 -0700286 OmahaRequestAction::StaticType(),
Darin Petkove6ef2f82011-03-07 17:31:11 -0800287 FilesystemCopierAction::StaticType(),
288 FilesystemCopierAction::StaticType(),
289 PostinstallRunnerAction::StaticType(),
290 OmahaRequestAction::StaticType()
291};
292} // namespace {}
293
294void UpdateAttempterTest::UpdateTestStart() {
Darin Petkovf42cc1c2010-09-01 09:03:02 -0700295 attempter_.set_http_response_code(200);
296 InSequence s;
Darin Petkovf42cc1c2010-09-01 09:03:02 -0700297 for (size_t i = 0; i < arraysize(kActionTypes); ++i) {
298 EXPECT_CALL(*processor_,
299 EnqueueAction(Property(&AbstractAction::Type,
300 kActionTypes[i]))).Times(1);
301 }
302 EXPECT_CALL(*processor_, StartProcessing()).Times(1);
303
Andrew de los Reyesfb2f4612011-06-09 18:21:49 -0700304 attempter_.Update("", "", false, false);
Darin Petkove6ef2f82011-03-07 17:31:11 -0800305 g_idle_add(&StaticUpdateTestVerify, this);
306}
Darin Petkovf42cc1c2010-09-01 09:03:02 -0700307
Darin Petkove6ef2f82011-03-07 17:31:11 -0800308void UpdateAttempterTest::UpdateTestVerify() {
Darin Petkovf42cc1c2010-09-01 09:03:02 -0700309 EXPECT_EQ(0, attempter_.http_response_code());
310 EXPECT_EQ(&attempter_, processor_->delegate());
311 EXPECT_EQ(arraysize(kActionTypes), attempter_.actions_.size());
312 for (size_t i = 0; i < arraysize(kActionTypes); ++i) {
313 EXPECT_EQ(kActionTypes[i], attempter_.actions_[i]->Type());
314 }
315 EXPECT_EQ(attempter_.response_handler_action_.get(),
316 attempter_.actions_[1].get());
317 DownloadAction* download_action =
318 dynamic_cast<DownloadAction*>(attempter_.actions_[5].get());
319 ASSERT_TRUE(download_action != NULL);
320 EXPECT_EQ(&attempter_, download_action->delegate());
321 EXPECT_EQ(UPDATE_STATUS_CHECKING_FOR_UPDATE, attempter_.status());
Darin Petkove6ef2f82011-03-07 17:31:11 -0800322 g_main_loop_quit(loop_);
323}
324
325TEST_F(UpdateAttempterTest, UpdateTest) {
326 loop_ = g_main_loop_new(g_main_context_default(), FALSE);
327 g_idle_add(&StaticUpdateTestStart, this);
328 g_main_loop_run(loop_);
329 g_main_loop_unref(loop_);
330 loop_ = NULL;
Darin Petkovf42cc1c2010-09-01 09:03:02 -0700331}
332
Thieu Le116fda32011-04-19 11:01:54 -0700333void UpdateAttempterTest::PingOmahaTestStart() {
334 EXPECT_CALL(*processor_,
335 EnqueueAction(Property(&AbstractAction::Type,
336 OmahaRequestAction::StaticType())))
337 .Times(1);
338 EXPECT_CALL(*processor_, StartProcessing()).Times(1);
339 attempter_.PingOmaha();
Patrick Dubroy7fbbe8a2011-08-01 17:28:22 +0200340 g_idle_add(&StaticQuitMainLoop, this);
Thieu Le116fda32011-04-19 11:01:54 -0700341}
342
343TEST_F(UpdateAttempterTest, PingOmahaTest) {
344 UpdateCheckScheduler scheduler(&attempter_);
345 scheduler.enabled_ = true;
Andrew de los Reyese05fc282011-06-02 09:50:08 -0700346 EXPECT_FALSE(scheduler.scheduled_);
Thieu Le116fda32011-04-19 11:01:54 -0700347 attempter_.set_update_check_scheduler(&scheduler);
348 loop_ = g_main_loop_new(g_main_context_default(), FALSE);
349 g_idle_add(&StaticPingOmahaTestStart, this);
350 g_main_loop_run(loop_);
351 g_main_loop_unref(loop_);
352 loop_ = NULL;
353 EXPECT_EQ(UPDATE_STATUS_UPDATED_NEED_REBOOT, attempter_.status());
354 EXPECT_EQ(true, scheduler.scheduled_);
355}
356
Darin Petkov18c7bce2011-06-16 14:07:00 -0700357TEST_F(UpdateAttempterTest, CreatePendingErrorEventTest) {
358 ActionMock action;
359 const ActionExitCode kCode = kActionCodeDownloadTransferError;
360 attempter_.CreatePendingErrorEvent(&action, kCode);
361 ASSERT_TRUE(attempter_.error_event_.get() != NULL);
362 EXPECT_EQ(OmahaEvent::kTypeUpdateComplete, attempter_.error_event_->type);
363 EXPECT_EQ(OmahaEvent::kResultError, attempter_.error_event_->result);
364 EXPECT_EQ(kCode, attempter_.error_event_->error_code);
365}
366
367TEST_F(UpdateAttempterTest, CreatePendingErrorEventResumedTest) {
368 OmahaResponseHandlerAction *response_action =
369 new OmahaResponseHandlerAction(&prefs_);
370 response_action->install_plan_.is_resume = true;
371 attempter_.response_handler_action_.reset(response_action);
372 ActionMock action;
373 const ActionExitCode kCode = kActionCodeInstallDeviceOpenError;
374 attempter_.CreatePendingErrorEvent(&action, kCode);
375 ASSERT_TRUE(attempter_.error_event_.get() != NULL);
376 EXPECT_EQ(OmahaEvent::kTypeUpdateComplete, attempter_.error_event_->type);
377 EXPECT_EQ(OmahaEvent::kResultError, attempter_.error_event_->result);
378 EXPECT_EQ(kCode | kActionCodeResumedFlag,
379 attempter_.error_event_->error_code);
380}
381
Patrick Dubroy7fbbe8a2011-08-01 17:28:22 +0200382TEST_F(UpdateAttempterTest, ReadTrackFromPolicy) {
383 loop_ = g_main_loop_new(g_main_context_default(), FALSE);
384 g_idle_add(&StaticReadTrackFromPolicyTestStart, this);
385 g_main_loop_run(loop_);
386 g_main_loop_unref(loop_);
387 loop_ = NULL;
388}
389
390void UpdateAttempterTest::ReadTrackFromPolicyTestStart() {
391 // Tests that the update track (aka release channel) is properly fetched
392 // from the device policy.
393
394 policy::MockDevicePolicy* device_policy = new policy::MockDevicePolicy();
395 attempter_.policy_provider_.reset(new policy::PolicyProvider(device_policy));
396
397 EXPECT_CALL(*device_policy, LoadPolicy()).WillRepeatedly(Return(true));
398
399 EXPECT_CALL(*device_policy, GetReleaseChannel(_))
400 .WillRepeatedly(DoAll(
401 SetArgumentPointee<0>(std::string("canary-channel")),
402 Return(true)));
403
404 attempter_.Update("", "", false, false);
405 EXPECT_EQ("canary-channel", attempter_.omaha_request_params_.app_track);
406
407 g_idle_add(&StaticQuitMainLoop, this);
408}
409
Darin Petkovf42cc1c2010-09-01 09:03:02 -0700410} // namespace chromeos_update_engine