Chromium Code Reviews| 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 <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" |
| (...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 57 EXPECT_FALSE(attempter_.is_full_update_); | 57 EXPECT_FALSE(attempter_.is_full_update_); |
| 58 processor_ = new ActionProcessorMock(); | 58 processor_ = new ActionProcessorMock(); |
| 59 attempter_.processor_.reset(processor_); // Transfers ownership. | 59 attempter_.processor_.reset(processor_); // Transfers ownership. |
| 60 attempter_.prefs_ = &prefs_; | 60 attempter_.prefs_ = &prefs_; |
| 61 } | 61 } |
| 62 | 62 |
| 63 void UpdateTestStart(); | 63 void UpdateTestStart(); |
| 64 void UpdateTestVerify(); | 64 void UpdateTestVerify(); |
| 65 static gboolean StaticUpdateTestStart(gpointer data); | 65 static gboolean StaticUpdateTestStart(gpointer data); |
| 66 static gboolean StaticUpdateTestVerify(gpointer data); | 66 static gboolean StaticUpdateTestVerify(gpointer data); |
| 67 void PingOmahaTestStart(); | |
| 68 void PingOmahaTestDone(); | |
| 69 static gboolean StaticPingOmahaTestStart(gpointer data); | |
| 70 static gboolean StaticPingOmahaTestDone(gpointer data); | |
| 67 | 71 |
| 68 MockDbusGlib dbus_; | 72 MockDbusGlib dbus_; |
| 69 UpdateAttempterUnderTest attempter_; | 73 UpdateAttempterUnderTest attempter_; |
| 70 ActionProcessorMock* processor_; | 74 ActionProcessorMock* processor_; |
| 71 NiceMock<PrefsMock> prefs_; | 75 NiceMock<PrefsMock> prefs_; |
| 72 GMainLoop* loop_; | 76 GMainLoop* loop_; |
| 73 }; | 77 }; |
| 74 | 78 |
| 75 TEST_F(UpdateAttempterTest, ActionCompletedDownloadTest) { | 79 TEST_F(UpdateAttempterTest, ActionCompletedDownloadTest) { |
| 76 scoped_ptr<MockHttpFetcher> fetcher(new MockHttpFetcher("", 0, NULL)); | 80 scoped_ptr<MockHttpFetcher> fetcher(new MockHttpFetcher("", 0, NULL)); |
| (...skipping 13 matching lines...) Expand all Loading... | |
| 90 EXPECT_CALL(prefs_, GetInt64(kPrefsDeltaUpdateFailures, _)) | 94 EXPECT_CALL(prefs_, GetInt64(kPrefsDeltaUpdateFailures, _)) |
| 91 .WillOnce(Return(false)); | 95 .WillOnce(Return(false)); |
| 92 attempter_.ActionCompleted(NULL, &action, kActionCodeError); | 96 attempter_.ActionCompleted(NULL, &action, kActionCodeError); |
| 93 ASSERT_TRUE(attempter_.error_event_.get() != NULL); | 97 ASSERT_TRUE(attempter_.error_event_.get() != NULL); |
| 94 } | 98 } |
| 95 | 99 |
| 96 TEST_F(UpdateAttempterTest, ActionCompletedOmahaRequestTest) { | 100 TEST_F(UpdateAttempterTest, ActionCompletedOmahaRequestTest) { |
| 97 scoped_ptr<MockHttpFetcher> fetcher(new MockHttpFetcher("", 0, NULL)); | 101 scoped_ptr<MockHttpFetcher> fetcher(new MockHttpFetcher("", 0, NULL)); |
| 98 fetcher->FailTransfer(500); // Sets the HTTP response code. | 102 fetcher->FailTransfer(500); // Sets the HTTP response code. |
| 99 OmahaRequestParams params; | 103 OmahaRequestParams params; |
| 100 OmahaRequestAction action(&prefs_, params, NULL, fetcher.release()); | 104 OmahaRequestAction action(&prefs_, params, NULL, fetcher.release(), false); |
| 101 ObjectCollectorAction<OmahaResponse> collector_action; | 105 ObjectCollectorAction<OmahaResponse> collector_action; |
| 102 BondActions(&action, &collector_action); | 106 BondActions(&action, &collector_action); |
| 103 OmahaResponse response; | 107 OmahaResponse response; |
| 104 response.poll_interval = 234; | 108 response.poll_interval = 234; |
| 105 action.SetOutputObject(response); | 109 action.SetOutputObject(response); |
| 106 UpdateCheckScheduler scheduler(&attempter_); | 110 UpdateCheckScheduler scheduler(&attempter_); |
| 107 attempter_.set_update_check_scheduler(&scheduler); | 111 attempter_.set_update_check_scheduler(&scheduler); |
| 108 EXPECT_CALL(prefs_, GetInt64(kPrefsDeltaUpdateFailures, _)).Times(0); | 112 EXPECT_CALL(prefs_, GetInt64(kPrefsDeltaUpdateFailures, _)).Times(0); |
| 109 attempter_.ActionCompleted(NULL, &action, kActionCodeSuccess); | 113 attempter_.ActionCompleted(NULL, &action, kActionCodeSuccess); |
| 110 EXPECT_EQ(500, attempter_.http_response_code()); | 114 EXPECT_EQ(500, attempter_.http_response_code()); |
| (...skipping 12 matching lines...) Expand all Loading... | |
| 123 EXPECT_TRUE(file_util::Delete(kMarker, false)); | 127 EXPECT_TRUE(file_util::Delete(kMarker, false)); |
| 124 } | 128 } |
| 125 | 129 |
| 126 TEST_F(UpdateAttempterTest, GetErrorCodeForActionTest) { | 130 TEST_F(UpdateAttempterTest, GetErrorCodeForActionTest) { |
| 127 extern ActionExitCode GetErrorCodeForAction(AbstractAction* action, | 131 extern ActionExitCode GetErrorCodeForAction(AbstractAction* action, |
| 128 ActionExitCode code); | 132 ActionExitCode code); |
| 129 EXPECT_EQ(kActionCodeSuccess, | 133 EXPECT_EQ(kActionCodeSuccess, |
| 130 GetErrorCodeForAction(NULL, kActionCodeSuccess)); | 134 GetErrorCodeForAction(NULL, kActionCodeSuccess)); |
| 131 | 135 |
| 132 OmahaRequestParams params; | 136 OmahaRequestParams params; |
| 133 OmahaRequestAction omaha_request_action(NULL, params, NULL, NULL); | 137 OmahaRequestAction omaha_request_action(NULL, params, NULL, NULL, false); |
| 134 EXPECT_EQ(kActionCodeOmahaRequestError, | 138 EXPECT_EQ(kActionCodeOmahaRequestError, |
| 135 GetErrorCodeForAction(&omaha_request_action, kActionCodeError)); | 139 GetErrorCodeForAction(&omaha_request_action, kActionCodeError)); |
| 136 OmahaResponseHandlerAction omaha_response_handler_action(&prefs_); | 140 OmahaResponseHandlerAction omaha_response_handler_action(&prefs_); |
| 137 EXPECT_EQ(kActionCodeOmahaResponseHandlerError, | 141 EXPECT_EQ(kActionCodeOmahaResponseHandlerError, |
| 138 GetErrorCodeForAction(&omaha_response_handler_action, | 142 GetErrorCodeForAction(&omaha_response_handler_action, |
| 139 kActionCodeError)); | 143 kActionCodeError)); |
| 140 FilesystemCopierAction filesystem_copier_action(false, false); | 144 FilesystemCopierAction filesystem_copier_action(false, false); |
| 141 EXPECT_EQ(kActionCodeFilesystemCopierError, | 145 EXPECT_EQ(kActionCodeFilesystemCopierError, |
| 142 GetErrorCodeForAction(&filesystem_copier_action, kActionCodeError)); | 146 GetErrorCodeForAction(&filesystem_copier_action, kActionCodeError)); |
| 143 PostinstallRunnerAction postinstall_runner_action; | 147 PostinstallRunnerAction postinstall_runner_action; |
| (...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 236 gboolean UpdateAttempterTest::StaticUpdateTestStart(gpointer data) { | 240 gboolean UpdateAttempterTest::StaticUpdateTestStart(gpointer data) { |
| 237 reinterpret_cast<UpdateAttempterTest*>(data)->UpdateTestStart(); | 241 reinterpret_cast<UpdateAttempterTest*>(data)->UpdateTestStart(); |
| 238 return FALSE; | 242 return FALSE; |
| 239 } | 243 } |
| 240 | 244 |
| 241 gboolean UpdateAttempterTest::StaticUpdateTestVerify(gpointer data) { | 245 gboolean UpdateAttempterTest::StaticUpdateTestVerify(gpointer data) { |
| 242 reinterpret_cast<UpdateAttempterTest*>(data)->UpdateTestVerify(); | 246 reinterpret_cast<UpdateAttempterTest*>(data)->UpdateTestVerify(); |
| 243 return FALSE; | 247 return FALSE; |
| 244 } | 248 } |
| 245 | 249 |
| 250 gboolean UpdateAttempterTest::StaticPingOmahaTestStart(gpointer data) { | |
| 251 reinterpret_cast<UpdateAttempterTest*>(data)->PingOmahaTestStart(); | |
| 252 return FALSE; | |
| 253 } | |
| 254 | |
| 255 gboolean UpdateAttempterTest::StaticPingOmahaTestDone(gpointer data) { | |
| 256 reinterpret_cast<UpdateAttempterTest*>(data)->PingOmahaTestDone(); | |
| 257 return FALSE; | |
| 258 } | |
| 259 | |
| 246 namespace { | 260 namespace { |
| 247 const string kActionTypes[] = { | 261 const string kActionTypes[] = { |
| 248 OmahaRequestAction::StaticType(), | 262 OmahaRequestAction::StaticType(), |
| 249 OmahaResponseHandlerAction::StaticType(), | 263 OmahaResponseHandlerAction::StaticType(), |
| 250 FilesystemCopierAction::StaticType(), | 264 FilesystemCopierAction::StaticType(), |
| 251 FilesystemCopierAction::StaticType(), | 265 FilesystemCopierAction::StaticType(), |
| 252 OmahaRequestAction::StaticType(), | 266 OmahaRequestAction::StaticType(), |
| 253 DownloadAction::StaticType(), | 267 DownloadAction::StaticType(), |
| 254 OmahaRequestAction::StaticType(), | 268 OmahaRequestAction::StaticType(), |
| 255 OmahaRequestAction::StaticType(), | 269 OmahaRequestAction::StaticType(), |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 292 } | 306 } |
| 293 | 307 |
| 294 TEST_F(UpdateAttempterTest, UpdateTest) { | 308 TEST_F(UpdateAttempterTest, UpdateTest) { |
| 295 loop_ = g_main_loop_new(g_main_context_default(), FALSE); | 309 loop_ = g_main_loop_new(g_main_context_default(), FALSE); |
| 296 g_idle_add(&StaticUpdateTestStart, this); | 310 g_idle_add(&StaticUpdateTestStart, this); |
| 297 g_main_loop_run(loop_); | 311 g_main_loop_run(loop_); |
| 298 g_main_loop_unref(loop_); | 312 g_main_loop_unref(loop_); |
| 299 loop_ = NULL; | 313 loop_ = NULL; |
| 300 } | 314 } |
| 301 | 315 |
| 316 void UpdateAttempterTest::PingOmahaTestStart() { | |
| 317 EXPECT_CALL(*processor_, | |
| 318 EnqueueAction(Property(&AbstractAction::Type, | |
| 319 OmahaRequestAction::StaticType()))) | |
| 320 .Times(1); | |
| 321 EXPECT_CALL(*processor_, StartProcessing()).Times(1); | |
| 322 attempter_.PingOmaha(); | |
| 323 g_idle_add(&StaticPingOmahaTestDone, this); | |
| 324 } | |
| 325 | |
| 326 void UpdateAttempterTest::PingOmahaTestDone() { | |
| 327 g_main_loop_quit(loop_); | |
|
adlr
2011/04/18 18:05:28
this still may run before the action completes. Ca
thieule
2011/04/18 21:40:15
It looks like the processor is a mock so it doesn'
| |
| 328 } | |
| 329 | |
| 330 TEST_F(UpdateAttempterTest, PingOmahaTest) { | |
| 331 UpdateCheckScheduler scheduler(&attempter_); | |
| 332 scheduler.enabled_ = true; | |
| 333 EXPECT_EQ(false, scheduler.scheduled_); | |
| 334 attempter_.set_update_check_scheduler(&scheduler); | |
| 335 loop_ = g_main_loop_new(g_main_context_default(), FALSE); | |
| 336 g_idle_add(&StaticPingOmahaTestStart, this); | |
| 337 g_main_loop_run(loop_); | |
| 338 g_main_loop_unref(loop_); | |
| 339 loop_ = NULL; | |
| 340 EXPECT_EQ(UPDATE_STATUS_UPDATED_NEED_REBOOT, attempter_.status()); | |
| 341 EXPECT_EQ(true, scheduler.scheduled_); | |
| 342 } | |
| 343 | |
| 302 } // namespace chromeos_update_engine | 344 } // namespace chromeos_update_engine |
| OLD | NEW |