Jay Srinivasan | 480ddfa | 2012-06-01 19:15:26 -0700 | [diff] [blame] | 1 | // Copyright (c) 2012 The Chromium OS Authors. All rights reserved. |
Darin Petkov | f42cc1c | 2010-09-01 09:03:02 -0700 | [diff] [blame] | 2 | // 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 Dubroy | 7fbbe8a | 2011-08-01 17:28:22 +0200 | [diff] [blame] | 7 | #include <policy/libpolicy.h> |
| 8 | #include <policy/mock_device_policy.h> |
Darin Petkov | f42cc1c | 2010-09-01 09:03:02 -0700 | [diff] [blame] | 9 | |
| 10 | #include "update_engine/action_mock.h" |
| 11 | #include "update_engine/action_processor_mock.h" |
| 12 | #include "update_engine/filesystem_copier_action.h" |
Chris Sosa | 76a29ae | 2013-07-11 17:59:24 -0700 | [diff] [blame] | 13 | #include "update_engine/install_plan.h" |
Andrew de los Reyes | 4516810 | 2010-11-22 11:13:50 -0800 | [diff] [blame] | 14 | #include "update_engine/mock_dbus_interface.h" |
Darin Petkov | 1b00310 | 2010-11-30 10:18:36 -0800 | [diff] [blame] | 15 | #include "update_engine/mock_http_fetcher.h" |
Jay Srinivasan | 6f6ea00 | 2012-12-14 11:26:28 -0800 | [diff] [blame] | 16 | #include "update_engine/mock_payload_state.h" |
Jay Srinivasan | 08fce04 | 2012-06-07 16:31:01 -0700 | [diff] [blame] | 17 | #include "update_engine/mock_system_state.h" |
Darin Petkov | f42cc1c | 2010-09-01 09:03:02 -0700 | [diff] [blame] | 18 | #include "update_engine/postinstall_runner_action.h" |
Jay Srinivasan | 480ddfa | 2012-06-01 19:15:26 -0700 | [diff] [blame] | 19 | #include "update_engine/prefs.h" |
Darin Petkov | 3627577 | 2010-10-01 11:40:57 -0700 | [diff] [blame] | 20 | #include "update_engine/prefs_mock.h" |
Darin Petkov | 1b00310 | 2010-11-30 10:18:36 -0800 | [diff] [blame] | 21 | #include "update_engine/test_utils.h" |
Darin Petkov | f42cc1c | 2010-09-01 09:03:02 -0700 | [diff] [blame] | 22 | #include "update_engine/update_attempter.h" |
Darin Petkov | 1b00310 | 2010-11-30 10:18:36 -0800 | [diff] [blame] | 23 | #include "update_engine/update_check_scheduler.h" |
Darin Petkov | f42cc1c | 2010-09-01 09:03:02 -0700 | [diff] [blame] | 24 | |
| 25 | using std::string; |
Darin Petkov | 3627577 | 2010-10-01 11:40:57 -0700 | [diff] [blame] | 26 | using testing::_; |
| 27 | using testing::DoAll; |
Darin Petkov | f42cc1c | 2010-09-01 09:03:02 -0700 | [diff] [blame] | 28 | using testing::InSequence; |
Darin Petkov | 2dd0109 | 2010-10-08 15:43:05 -0700 | [diff] [blame] | 29 | using testing::Ne; |
Darin Petkov | 9c096d6 | 2010-11-17 14:49:04 -0800 | [diff] [blame] | 30 | using testing::NiceMock; |
Darin Petkov | f42cc1c | 2010-09-01 09:03:02 -0700 | [diff] [blame] | 31 | using testing::Property; |
| 32 | using testing::Return; |
Darin Petkov | 3627577 | 2010-10-01 11:40:57 -0700 | [diff] [blame] | 33 | using testing::SetArgumentPointee; |
Darin Petkov | f42cc1c | 2010-09-01 09:03:02 -0700 | [diff] [blame] | 34 | |
| 35 | namespace chromeos_update_engine { |
| 36 | |
| 37 | // Test a subclass rather than the main class directly so that we can mock out |
Darin Petkov | cd1666f | 2010-09-23 09:53:44 -0700 | [diff] [blame] | 38 | // methods within the class. There're explicit unit tests for the mocked out |
Darin Petkov | f42cc1c | 2010-09-01 09:03:02 -0700 | [diff] [blame] | 39 | // methods. |
| 40 | class UpdateAttempterUnderTest : public UpdateAttempter { |
| 41 | public: |
Jay Srinivasan | 6f6ea00 | 2012-12-14 11:26:28 -0800 | [diff] [blame] | 42 | explicit UpdateAttempterUnderTest(MockSystemState* mock_system_state, |
| 43 | MockDbusGlib* dbus) |
Gilad Arnold | bf7919b | 2013-01-08 13:07:37 -0800 | [diff] [blame] | 44 | : UpdateAttempter(mock_system_state, dbus) {} |
Darin Petkov | f42cc1c | 2010-09-01 09:03:02 -0700 | [diff] [blame] | 45 | }; |
| 46 | |
| 47 | class UpdateAttempterTest : public ::testing::Test { |
| 48 | protected: |
Jay Srinivasan | 4348879 | 2012-06-19 00:25:31 -0700 | [diff] [blame] | 49 | UpdateAttempterTest() |
Jay Srinivasan | 6f6ea00 | 2012-12-14 11:26:28 -0800 | [diff] [blame] | 50 | : attempter_(&mock_system_state_, &dbus_), |
Jay Srinivasan | 4348879 | 2012-06-19 00:25:31 -0700 | [diff] [blame] | 51 | mock_connection_manager(&mock_system_state_), |
| 52 | loop_(NULL) { |
Jay Srinivasan | 6f6ea00 | 2012-12-14 11:26:28 -0800 | [diff] [blame] | 53 | mock_system_state_.set_connection_manager(&mock_connection_manager); |
Jay Srinivasan | 4348879 | 2012-06-19 00:25:31 -0700 | [diff] [blame] | 54 | } |
Darin Petkov | f42cc1c | 2010-09-01 09:03:02 -0700 | [diff] [blame] | 55 | virtual void SetUp() { |
| 56 | EXPECT_EQ(NULL, attempter_.dbus_service_); |
Jay Srinivasan | 6f6ea00 | 2012-12-14 11:26:28 -0800 | [diff] [blame] | 57 | EXPECT_TRUE(attempter_.system_state_ != NULL); |
Darin Petkov | f42cc1c | 2010-09-01 09:03:02 -0700 | [diff] [blame] | 58 | EXPECT_EQ(NULL, attempter_.update_check_scheduler_); |
| 59 | EXPECT_EQ(0, attempter_.http_response_code_); |
Chris Sosa | 4f8ee27 | 2012-11-30 13:01:54 -0800 | [diff] [blame] | 60 | EXPECT_EQ(utils::kCpuSharesNormal, attempter_.shares_); |
| 61 | EXPECT_EQ(NULL, attempter_.manage_shares_source_); |
Darin Petkov | f42cc1c | 2010-09-01 09:03:02 -0700 | [diff] [blame] | 62 | EXPECT_FALSE(attempter_.download_active_); |
| 63 | EXPECT_EQ(UPDATE_STATUS_IDLE, attempter_.status_); |
| 64 | EXPECT_EQ(0.0, attempter_.download_progress_); |
| 65 | EXPECT_EQ(0, attempter_.last_checked_time_); |
| 66 | EXPECT_EQ("0.0.0.0", attempter_.new_version_); |
Jay Srinivasan | 51dcf26 | 2012-09-13 17:24:32 -0700 | [diff] [blame] | 67 | EXPECT_EQ(0, attempter_.new_payload_size_); |
Jay Srinivasan | 55f50c2 | 2013-01-10 19:24:35 -0800 | [diff] [blame] | 68 | processor_ = new NiceMock<ActionProcessorMock>(); |
Darin Petkov | f42cc1c | 2010-09-01 09:03:02 -0700 | [diff] [blame] | 69 | attempter_.processor_.reset(processor_); // Transfers ownership. |
Jay Srinivasan | 6f6ea00 | 2012-12-14 11:26:28 -0800 | [diff] [blame] | 70 | prefs_ = mock_system_state_.mock_prefs(); |
Darin Petkov | f42cc1c | 2010-09-01 09:03:02 -0700 | [diff] [blame] | 71 | } |
| 72 | |
Patrick Dubroy | 7fbbe8a | 2011-08-01 17:28:22 +0200 | [diff] [blame] | 73 | void QuitMainLoop(); |
| 74 | static gboolean StaticQuitMainLoop(gpointer data); |
| 75 | |
Darin Petkov | e6ef2f8 | 2011-03-07 17:31:11 -0800 | [diff] [blame] | 76 | void UpdateTestStart(); |
| 77 | void UpdateTestVerify(); |
Chris Sosa | 28e479c | 2013-07-12 11:39:53 -0700 | [diff] [blame] | 78 | void RollbackTestStart(bool enterprise_rollback, bool stable_channel); |
Chris Sosa | 76a29ae | 2013-07-11 17:59:24 -0700 | [diff] [blame] | 79 | void RollbackTestVerify(); |
Darin Petkov | e6ef2f8 | 2011-03-07 17:31:11 -0800 | [diff] [blame] | 80 | static gboolean StaticUpdateTestStart(gpointer data); |
| 81 | static gboolean StaticUpdateTestVerify(gpointer data); |
Chris Sosa | 76a29ae | 2013-07-11 17:59:24 -0700 | [diff] [blame] | 82 | static gboolean StaticRollbackTestStart(gpointer data); |
| 83 | static gboolean StaticEnterpriseRollbackTestStart(gpointer data); |
Chris Sosa | 28e479c | 2013-07-12 11:39:53 -0700 | [diff] [blame] | 84 | static gboolean StaticStableChannelRollbackTestStart(gpointer data); |
Chris Sosa | 76a29ae | 2013-07-11 17:59:24 -0700 | [diff] [blame] | 85 | static gboolean StaticRollbackTestVerify(gpointer data); |
Patrick Dubroy | 7fbbe8a | 2011-08-01 17:28:22 +0200 | [diff] [blame] | 86 | |
Thieu Le | 116fda3 | 2011-04-19 11:01:54 -0700 | [diff] [blame] | 87 | void PingOmahaTestStart(); |
Thieu Le | 116fda3 | 2011-04-19 11:01:54 -0700 | [diff] [blame] | 88 | static gboolean StaticPingOmahaTestStart(gpointer data); |
Patrick Dubroy | 7fbbe8a | 2011-08-01 17:28:22 +0200 | [diff] [blame] | 89 | |
Jay Srinivasan | ae4697c | 2013-03-18 17:08:08 -0700 | [diff] [blame] | 90 | void ReadChannelFromPolicyTestStart(); |
| 91 | static gboolean StaticReadChannelFromPolicyTestStart(gpointer data); |
Darin Petkov | e6ef2f8 | 2011-03-07 17:31:11 -0800 | [diff] [blame] | 92 | |
Jay Srinivasan | 0a70874 | 2012-03-20 11:26:12 -0700 | [diff] [blame] | 93 | void ReadUpdateDisabledFromPolicyTestStart(); |
| 94 | static gboolean StaticReadUpdateDisabledFromPolicyTestStart(gpointer data); |
| 95 | |
| 96 | void ReadTargetVersionPrefixFromPolicyTestStart(); |
| 97 | static gboolean StaticReadTargetVersionPrefixFromPolicyTestStart( |
| 98 | gpointer data); |
| 99 | |
Jay Srinivasan | 480ddfa | 2012-06-01 19:15:26 -0700 | [diff] [blame] | 100 | void ReadScatterFactorFromPolicyTestStart(); |
| 101 | static gboolean StaticReadScatterFactorFromPolicyTestStart( |
| 102 | gpointer data); |
| 103 | |
| 104 | void DecrementUpdateCheckCountTestStart(); |
| 105 | static gboolean StaticDecrementUpdateCheckCountTestStart( |
| 106 | gpointer data); |
| 107 | |
Jay Srinivasan | 08fce04 | 2012-06-07 16:31:01 -0700 | [diff] [blame] | 108 | void NoScatteringDoneDuringManualUpdateTestStart(); |
| 109 | static gboolean StaticNoScatteringDoneDuringManualUpdateTestStart( |
| 110 | gpointer data); |
| 111 | |
Jay Srinivasan | 55f50c2 | 2013-01-10 19:24:35 -0800 | [diff] [blame] | 112 | NiceMock<MockSystemState> mock_system_state_; |
| 113 | NiceMock<MockDbusGlib> dbus_; |
Darin Petkov | f42cc1c | 2010-09-01 09:03:02 -0700 | [diff] [blame] | 114 | UpdateAttempterUnderTest attempter_; |
Jay Srinivasan | 55f50c2 | 2013-01-10 19:24:35 -0800 | [diff] [blame] | 115 | NiceMock<ActionProcessorMock>* processor_; |
Jay Srinivasan | 6f6ea00 | 2012-12-14 11:26:28 -0800 | [diff] [blame] | 116 | NiceMock<PrefsMock>* prefs_; // shortcut to mock_system_state_->mock_prefs() |
Jay Srinivasan | 55f50c2 | 2013-01-10 19:24:35 -0800 | [diff] [blame] | 117 | NiceMock<MockConnectionManager> mock_connection_manager; |
Darin Petkov | e6ef2f8 | 2011-03-07 17:31:11 -0800 | [diff] [blame] | 118 | GMainLoop* loop_; |
Darin Petkov | f42cc1c | 2010-09-01 09:03:02 -0700 | [diff] [blame] | 119 | }; |
| 120 | |
Darin Petkov | 1b00310 | 2010-11-30 10:18:36 -0800 | [diff] [blame] | 121 | TEST_F(UpdateAttempterTest, ActionCompletedDownloadTest) { |
| 122 | scoped_ptr<MockHttpFetcher> fetcher(new MockHttpFetcher("", 0, NULL)); |
| 123 | fetcher->FailTransfer(503); // Sets the HTTP response code. |
Jay Srinivasan | 6f6ea00 | 2012-12-14 11:26:28 -0800 | [diff] [blame] | 124 | DownloadAction action(prefs_, NULL, fetcher.release()); |
| 125 | EXPECT_CALL(*prefs_, GetInt64(kPrefsDeltaUpdateFailures, _)).Times(0); |
David Zeuthen | a99981f | 2013-04-29 13:42:47 -0700 | [diff] [blame] | 126 | attempter_.ActionCompleted(NULL, &action, kErrorCodeSuccess); |
Darin Petkov | 1b00310 | 2010-11-30 10:18:36 -0800 | [diff] [blame] | 127 | EXPECT_EQ(503, attempter_.http_response_code()); |
| 128 | EXPECT_EQ(UPDATE_STATUS_FINALIZING, attempter_.status()); |
| 129 | ASSERT_TRUE(attempter_.error_event_.get() == NULL); |
| 130 | } |
| 131 | |
| 132 | TEST_F(UpdateAttempterTest, ActionCompletedErrorTest) { |
| 133 | ActionMock action; |
| 134 | EXPECT_CALL(action, Type()).WillRepeatedly(Return("ActionMock")); |
| 135 | attempter_.status_ = UPDATE_STATUS_DOWNLOADING; |
Jay Srinivasan | 6f6ea00 | 2012-12-14 11:26:28 -0800 | [diff] [blame] | 136 | EXPECT_CALL(*prefs_, GetInt64(kPrefsDeltaUpdateFailures, _)) |
Darin Petkov | 1b00310 | 2010-11-30 10:18:36 -0800 | [diff] [blame] | 137 | .WillOnce(Return(false)); |
David Zeuthen | a99981f | 2013-04-29 13:42:47 -0700 | [diff] [blame] | 138 | attempter_.ActionCompleted(NULL, &action, kErrorCodeError); |
Darin Petkov | 1b00310 | 2010-11-30 10:18:36 -0800 | [diff] [blame] | 139 | ASSERT_TRUE(attempter_.error_event_.get() != NULL); |
| 140 | } |
| 141 | |
| 142 | TEST_F(UpdateAttempterTest, ActionCompletedOmahaRequestTest) { |
| 143 | scoped_ptr<MockHttpFetcher> fetcher(new MockHttpFetcher("", 0, NULL)); |
| 144 | fetcher->FailTransfer(500); // Sets the HTTP response code. |
Jay Srinivasan | ae4697c | 2013-03-18 17:08:08 -0700 | [diff] [blame] | 145 | OmahaRequestAction action(&mock_system_state_, NULL, |
Jay Srinivasan | 6f6ea00 | 2012-12-14 11:26:28 -0800 | [diff] [blame] | 146 | fetcher.release(), false); |
Darin Petkov | 1b00310 | 2010-11-30 10:18:36 -0800 | [diff] [blame] | 147 | ObjectCollectorAction<OmahaResponse> collector_action; |
| 148 | BondActions(&action, &collector_action); |
| 149 | OmahaResponse response; |
| 150 | response.poll_interval = 234; |
| 151 | action.SetOutputObject(response); |
Gilad Arnold | bf7919b | 2013-01-08 13:07:37 -0800 | [diff] [blame] | 152 | UpdateCheckScheduler scheduler(&attempter_, &mock_system_state_); |
Darin Petkov | 1b00310 | 2010-11-30 10:18:36 -0800 | [diff] [blame] | 153 | attempter_.set_update_check_scheduler(&scheduler); |
Jay Srinivasan | 6f6ea00 | 2012-12-14 11:26:28 -0800 | [diff] [blame] | 154 | EXPECT_CALL(*prefs_, GetInt64(kPrefsDeltaUpdateFailures, _)).Times(0); |
David Zeuthen | a99981f | 2013-04-29 13:42:47 -0700 | [diff] [blame] | 155 | attempter_.ActionCompleted(NULL, &action, kErrorCodeSuccess); |
Darin Petkov | 1b00310 | 2010-11-30 10:18:36 -0800 | [diff] [blame] | 156 | EXPECT_EQ(500, attempter_.http_response_code()); |
| 157 | EXPECT_EQ(UPDATE_STATUS_IDLE, attempter_.status()); |
| 158 | EXPECT_EQ(234, scheduler.poll_interval()); |
| 159 | ASSERT_TRUE(attempter_.error_event_.get() == NULL); |
| 160 | } |
| 161 | |
Darin Petkov | cd1666f | 2010-09-23 09:53:44 -0700 | [diff] [blame] | 162 | TEST_F(UpdateAttempterTest, RunAsRootConstructWithUpdatedMarkerTest) { |
Darin Petkov | f42cc1c | 2010-09-01 09:03:02 -0700 | [diff] [blame] | 163 | extern const char* kUpdateCompletedMarker; |
| 164 | const FilePath kMarker(kUpdateCompletedMarker); |
| 165 | EXPECT_EQ(0, file_util::WriteFile(kMarker, "", 0)); |
Jay Srinivasan | 6f6ea00 | 2012-12-14 11:26:28 -0800 | [diff] [blame] | 166 | UpdateAttempterUnderTest attempter(&mock_system_state_, &dbus_); |
Darin Petkov | f42cc1c | 2010-09-01 09:03:02 -0700 | [diff] [blame] | 167 | EXPECT_EQ(UPDATE_STATUS_UPDATED_NEED_REBOOT, attempter.status()); |
| 168 | EXPECT_TRUE(file_util::Delete(kMarker, false)); |
| 169 | } |
| 170 | |
| 171 | TEST_F(UpdateAttempterTest, GetErrorCodeForActionTest) { |
David Zeuthen | a99981f | 2013-04-29 13:42:47 -0700 | [diff] [blame] | 172 | extern ErrorCode GetErrorCodeForAction(AbstractAction* action, |
| 173 | ErrorCode code); |
| 174 | EXPECT_EQ(kErrorCodeSuccess, |
| 175 | GetErrorCodeForAction(NULL, kErrorCodeSuccess)); |
Darin Petkov | f42cc1c | 2010-09-01 09:03:02 -0700 | [diff] [blame] | 176 | |
Jay Srinivasan | 6f6ea00 | 2012-12-14 11:26:28 -0800 | [diff] [blame] | 177 | MockSystemState mock_system_state; |
Jay Srinivasan | ae4697c | 2013-03-18 17:08:08 -0700 | [diff] [blame] | 178 | OmahaRequestAction omaha_request_action(&mock_system_state, NULL, |
Jay Srinivasan | 6f6ea00 | 2012-12-14 11:26:28 -0800 | [diff] [blame] | 179 | NULL, false); |
David Zeuthen | a99981f | 2013-04-29 13:42:47 -0700 | [diff] [blame] | 180 | EXPECT_EQ(kErrorCodeOmahaRequestError, |
| 181 | GetErrorCodeForAction(&omaha_request_action, kErrorCodeError)); |
Jay Srinivasan | 6f6ea00 | 2012-12-14 11:26:28 -0800 | [diff] [blame] | 182 | OmahaResponseHandlerAction omaha_response_handler_action(&mock_system_state_); |
David Zeuthen | a99981f | 2013-04-29 13:42:47 -0700 | [diff] [blame] | 183 | EXPECT_EQ(kErrorCodeOmahaResponseHandlerError, |
Darin Petkov | f42cc1c | 2010-09-01 09:03:02 -0700 | [diff] [blame] | 184 | GetErrorCodeForAction(&omaha_response_handler_action, |
David Zeuthen | a99981f | 2013-04-29 13:42:47 -0700 | [diff] [blame] | 185 | kErrorCodeError)); |
Alex Deymo | 4243291 | 2013-07-12 20:21:15 -0700 | [diff] [blame^] | 186 | FilesystemCopierAction filesystem_copier_action( |
| 187 | &mock_system_state_, false, false); |
David Zeuthen | a99981f | 2013-04-29 13:42:47 -0700 | [diff] [blame] | 188 | EXPECT_EQ(kErrorCodeFilesystemCopierError, |
| 189 | GetErrorCodeForAction(&filesystem_copier_action, kErrorCodeError)); |
Darin Petkov | 6d5dbf6 | 2010-11-08 16:09:55 -0800 | [diff] [blame] | 190 | PostinstallRunnerAction postinstall_runner_action; |
David Zeuthen | a99981f | 2013-04-29 13:42:47 -0700 | [diff] [blame] | 191 | EXPECT_EQ(kErrorCodePostinstallRunnerError, |
Darin Petkov | f42cc1c | 2010-09-01 09:03:02 -0700 | [diff] [blame] | 192 | GetErrorCodeForAction(&postinstall_runner_action, |
David Zeuthen | a99981f | 2013-04-29 13:42:47 -0700 | [diff] [blame] | 193 | kErrorCodeError)); |
Darin Petkov | f42cc1c | 2010-09-01 09:03:02 -0700 | [diff] [blame] | 194 | ActionMock action_mock; |
| 195 | EXPECT_CALL(action_mock, Type()).Times(1).WillOnce(Return("ActionMock")); |
David Zeuthen | a99981f | 2013-04-29 13:42:47 -0700 | [diff] [blame] | 196 | EXPECT_EQ(kErrorCodeError, |
| 197 | GetErrorCodeForAction(&action_mock, kErrorCodeError)); |
Darin Petkov | f42cc1c | 2010-09-01 09:03:02 -0700 | [diff] [blame] | 198 | } |
| 199 | |
Darin Petkov | 3627577 | 2010-10-01 11:40:57 -0700 | [diff] [blame] | 200 | TEST_F(UpdateAttempterTest, DisableDeltaUpdateIfNeededTest) { |
Jay Srinivasan | ae4697c | 2013-03-18 17:08:08 -0700 | [diff] [blame] | 201 | attempter_.omaha_request_params_->set_delta_okay(true); |
Jay Srinivasan | 6f6ea00 | 2012-12-14 11:26:28 -0800 | [diff] [blame] | 202 | EXPECT_CALL(*prefs_, GetInt64(kPrefsDeltaUpdateFailures, _)) |
Darin Petkov | 3627577 | 2010-10-01 11:40:57 -0700 | [diff] [blame] | 203 | .WillOnce(Return(false)); |
| 204 | attempter_.DisableDeltaUpdateIfNeeded(); |
Jay Srinivasan | ae4697c | 2013-03-18 17:08:08 -0700 | [diff] [blame] | 205 | EXPECT_TRUE(attempter_.omaha_request_params_->delta_okay()); |
Jay Srinivasan | 6f6ea00 | 2012-12-14 11:26:28 -0800 | [diff] [blame] | 206 | EXPECT_CALL(*prefs_, GetInt64(kPrefsDeltaUpdateFailures, _)) |
Darin Petkov | 3627577 | 2010-10-01 11:40:57 -0700 | [diff] [blame] | 207 | .WillOnce(DoAll( |
| 208 | SetArgumentPointee<1>(UpdateAttempter::kMaxDeltaUpdateFailures - 1), |
| 209 | Return(true))); |
| 210 | attempter_.DisableDeltaUpdateIfNeeded(); |
Jay Srinivasan | ae4697c | 2013-03-18 17:08:08 -0700 | [diff] [blame] | 211 | EXPECT_TRUE(attempter_.omaha_request_params_->delta_okay()); |
Jay Srinivasan | 6f6ea00 | 2012-12-14 11:26:28 -0800 | [diff] [blame] | 212 | EXPECT_CALL(*prefs_, GetInt64(kPrefsDeltaUpdateFailures, _)) |
Darin Petkov | 3627577 | 2010-10-01 11:40:57 -0700 | [diff] [blame] | 213 | .WillOnce(DoAll( |
| 214 | SetArgumentPointee<1>(UpdateAttempter::kMaxDeltaUpdateFailures), |
| 215 | Return(true))); |
| 216 | attempter_.DisableDeltaUpdateIfNeeded(); |
Jay Srinivasan | ae4697c | 2013-03-18 17:08:08 -0700 | [diff] [blame] | 217 | EXPECT_FALSE(attempter_.omaha_request_params_->delta_okay()); |
Jay Srinivasan | 6f6ea00 | 2012-12-14 11:26:28 -0800 | [diff] [blame] | 218 | EXPECT_CALL(*prefs_, GetInt64(_, _)).Times(0); |
Darin Petkov | 3627577 | 2010-10-01 11:40:57 -0700 | [diff] [blame] | 219 | attempter_.DisableDeltaUpdateIfNeeded(); |
Jay Srinivasan | ae4697c | 2013-03-18 17:08:08 -0700 | [diff] [blame] | 220 | EXPECT_FALSE(attempter_.omaha_request_params_->delta_okay()); |
Darin Petkov | 3627577 | 2010-10-01 11:40:57 -0700 | [diff] [blame] | 221 | } |
| 222 | |
| 223 | TEST_F(UpdateAttempterTest, MarkDeltaUpdateFailureTest) { |
Jay Srinivasan | 6f6ea00 | 2012-12-14 11:26:28 -0800 | [diff] [blame] | 224 | EXPECT_CALL(*prefs_, GetInt64(kPrefsDeltaUpdateFailures, _)) |
Darin Petkov | 3627577 | 2010-10-01 11:40:57 -0700 | [diff] [blame] | 225 | .WillOnce(Return(false)) |
| 226 | .WillOnce(DoAll(SetArgumentPointee<1>(-1), Return(true))) |
| 227 | .WillOnce(DoAll(SetArgumentPointee<1>(1), Return(true))) |
| 228 | .WillOnce(DoAll( |
| 229 | SetArgumentPointee<1>(UpdateAttempter::kMaxDeltaUpdateFailures), |
| 230 | Return(true))); |
Jay Srinivasan | 6f6ea00 | 2012-12-14 11:26:28 -0800 | [diff] [blame] | 231 | EXPECT_CALL(*prefs_, SetInt64(Ne(kPrefsDeltaUpdateFailures), _)) |
Darin Petkov | 2dd0109 | 2010-10-08 15:43:05 -0700 | [diff] [blame] | 232 | .WillRepeatedly(Return(true)); |
Jay Srinivasan | 6f6ea00 | 2012-12-14 11:26:28 -0800 | [diff] [blame] | 233 | EXPECT_CALL(*prefs_, SetInt64(kPrefsDeltaUpdateFailures, 1)).Times(2); |
| 234 | EXPECT_CALL(*prefs_, SetInt64(kPrefsDeltaUpdateFailures, 2)).Times(1); |
| 235 | EXPECT_CALL(*prefs_, SetInt64(kPrefsDeltaUpdateFailures, |
Darin Petkov | 3627577 | 2010-10-01 11:40:57 -0700 | [diff] [blame] | 236 | UpdateAttempter::kMaxDeltaUpdateFailures + 1)) |
| 237 | .Times(1); |
| 238 | for (int i = 0; i < 4; i ++) |
| 239 | attempter_.MarkDeltaUpdateFailure(); |
| 240 | } |
| 241 | |
Darin Petkov | 1b00310 | 2010-11-30 10:18:36 -0800 | [diff] [blame] | 242 | TEST_F(UpdateAttempterTest, ScheduleErrorEventActionNoEventTest) { |
| 243 | EXPECT_CALL(*processor_, EnqueueAction(_)).Times(0); |
| 244 | EXPECT_CALL(*processor_, StartProcessing()).Times(0); |
Jay Srinivasan | 6f6ea00 | 2012-12-14 11:26:28 -0800 | [diff] [blame] | 245 | EXPECT_CALL(*mock_system_state_.mock_payload_state(), UpdateFailed(_)) |
| 246 | .Times(0); |
| 247 | OmahaResponse response; |
Jay Srinivasan | 53173b9 | 2013-05-17 17:13:01 -0700 | [diff] [blame] | 248 | string url1 = "http://url1"; |
| 249 | response.payload_urls.push_back(url1); |
Jay Srinivasan | 6f6ea00 | 2012-12-14 11:26:28 -0800 | [diff] [blame] | 250 | response.payload_urls.push_back("https://url"); |
Jay Srinivasan | 53173b9 | 2013-05-17 17:13:01 -0700 | [diff] [blame] | 251 | EXPECT_CALL(*(mock_system_state_.mock_payload_state()), GetCurrentUrl()) |
| 252 | .WillRepeatedly(Return(url1)); |
Jay Srinivasan | 6f6ea00 | 2012-12-14 11:26:28 -0800 | [diff] [blame] | 253 | mock_system_state_.mock_payload_state()->SetResponse(response); |
Darin Petkov | 1b00310 | 2010-11-30 10:18:36 -0800 | [diff] [blame] | 254 | attempter_.ScheduleErrorEventAction(); |
Jay Srinivasan | 53173b9 | 2013-05-17 17:13:01 -0700 | [diff] [blame] | 255 | EXPECT_EQ(url1, mock_system_state_.mock_payload_state()->GetCurrentUrl()); |
Darin Petkov | 1b00310 | 2010-11-30 10:18:36 -0800 | [diff] [blame] | 256 | } |
| 257 | |
| 258 | TEST_F(UpdateAttempterTest, ScheduleErrorEventActionTest) { |
| 259 | EXPECT_CALL(*processor_, |
| 260 | EnqueueAction(Property(&AbstractAction::Type, |
| 261 | OmahaRequestAction::StaticType()))) |
| 262 | .Times(1); |
| 263 | EXPECT_CALL(*processor_, StartProcessing()).Times(1); |
David Zeuthen | a99981f | 2013-04-29 13:42:47 -0700 | [diff] [blame] | 264 | ErrorCode err = kErrorCodeError; |
Jay Srinivasan | 2b5a0f0 | 2012-12-19 17:25:56 -0800 | [diff] [blame] | 265 | EXPECT_CALL(*mock_system_state_.mock_payload_state(), UpdateFailed(err)); |
Darin Petkov | 1b00310 | 2010-11-30 10:18:36 -0800 | [diff] [blame] | 266 | attempter_.error_event_.reset(new OmahaEvent(OmahaEvent::kTypeUpdateComplete, |
| 267 | OmahaEvent::kResultError, |
Jay Srinivasan | 6f6ea00 | 2012-12-14 11:26:28 -0800 | [diff] [blame] | 268 | err)); |
Darin Petkov | 1b00310 | 2010-11-30 10:18:36 -0800 | [diff] [blame] | 269 | attempter_.ScheduleErrorEventAction(); |
| 270 | EXPECT_EQ(UPDATE_STATUS_REPORTING_ERROR_EVENT, attempter_.status()); |
| 271 | } |
| 272 | |
Darin Petkov | f42cc1c | 2010-09-01 09:03:02 -0700 | [diff] [blame] | 273 | TEST_F(UpdateAttempterTest, UpdateStatusToStringTest) { |
| 274 | extern const char* UpdateStatusToString(UpdateStatus); |
| 275 | EXPECT_STREQ("UPDATE_STATUS_IDLE", UpdateStatusToString(UPDATE_STATUS_IDLE)); |
| 276 | EXPECT_STREQ("UPDATE_STATUS_CHECKING_FOR_UPDATE", |
| 277 | UpdateStatusToString(UPDATE_STATUS_CHECKING_FOR_UPDATE)); |
| 278 | EXPECT_STREQ("UPDATE_STATUS_UPDATE_AVAILABLE", |
| 279 | UpdateStatusToString(UPDATE_STATUS_UPDATE_AVAILABLE)); |
| 280 | EXPECT_STREQ("UPDATE_STATUS_DOWNLOADING", |
| 281 | UpdateStatusToString(UPDATE_STATUS_DOWNLOADING)); |
| 282 | EXPECT_STREQ("UPDATE_STATUS_VERIFYING", |
| 283 | UpdateStatusToString(UPDATE_STATUS_VERIFYING)); |
| 284 | EXPECT_STREQ("UPDATE_STATUS_FINALIZING", |
| 285 | UpdateStatusToString(UPDATE_STATUS_FINALIZING)); |
| 286 | EXPECT_STREQ("UPDATE_STATUS_UPDATED_NEED_REBOOT", |
| 287 | UpdateStatusToString(UPDATE_STATUS_UPDATED_NEED_REBOOT)); |
| 288 | EXPECT_STREQ("UPDATE_STATUS_REPORTING_ERROR_EVENT", |
| 289 | UpdateStatusToString(UPDATE_STATUS_REPORTING_ERROR_EVENT)); |
| 290 | EXPECT_STREQ("unknown status", |
| 291 | UpdateStatusToString(static_cast<UpdateStatus>(-1))); |
| 292 | } |
| 293 | |
Patrick Dubroy | 7fbbe8a | 2011-08-01 17:28:22 +0200 | [diff] [blame] | 294 | void UpdateAttempterTest::QuitMainLoop() { |
| 295 | g_main_loop_quit(loop_); |
| 296 | } |
| 297 | |
| 298 | gboolean UpdateAttempterTest::StaticQuitMainLoop(gpointer data) { |
| 299 | reinterpret_cast<UpdateAttempterTest*>(data)->QuitMainLoop(); |
| 300 | return FALSE; |
| 301 | } |
| 302 | |
Darin Petkov | e6ef2f8 | 2011-03-07 17:31:11 -0800 | [diff] [blame] | 303 | gboolean UpdateAttempterTest::StaticUpdateTestStart(gpointer data) { |
| 304 | reinterpret_cast<UpdateAttempterTest*>(data)->UpdateTestStart(); |
| 305 | return FALSE; |
| 306 | } |
| 307 | |
| 308 | gboolean UpdateAttempterTest::StaticUpdateTestVerify(gpointer data) { |
| 309 | reinterpret_cast<UpdateAttempterTest*>(data)->UpdateTestVerify(); |
| 310 | return FALSE; |
| 311 | } |
| 312 | |
Chris Sosa | 76a29ae | 2013-07-11 17:59:24 -0700 | [diff] [blame] | 313 | gboolean UpdateAttempterTest::StaticRollbackTestStart(gpointer data) { |
Chris Sosa | 28e479c | 2013-07-12 11:39:53 -0700 | [diff] [blame] | 314 | reinterpret_cast<UpdateAttempterTest*>(data)->RollbackTestStart(false, false); |
Chris Sosa | 76a29ae | 2013-07-11 17:59:24 -0700 | [diff] [blame] | 315 | return FALSE; |
| 316 | } |
| 317 | |
| 318 | gboolean UpdateAttempterTest::StaticEnterpriseRollbackTestStart(gpointer data) { |
Chris Sosa | 28e479c | 2013-07-12 11:39:53 -0700 | [diff] [blame] | 319 | reinterpret_cast<UpdateAttempterTest*>(data)->RollbackTestStart(true, false); |
| 320 | return FALSE; |
| 321 | } |
| 322 | |
| 323 | gboolean UpdateAttempterTest::StaticStableChannelRollbackTestStart( |
| 324 | gpointer data) { |
| 325 | reinterpret_cast<UpdateAttempterTest*>(data)->RollbackTestStart( |
| 326 | false, true); |
Chris Sosa | 76a29ae | 2013-07-11 17:59:24 -0700 | [diff] [blame] | 327 | return FALSE; |
| 328 | } |
| 329 | |
| 330 | gboolean UpdateAttempterTest::StaticRollbackTestVerify(gpointer data) { |
| 331 | reinterpret_cast<UpdateAttempterTest*>(data)->RollbackTestVerify(); |
| 332 | return FALSE; |
| 333 | } |
| 334 | |
Thieu Le | 116fda3 | 2011-04-19 11:01:54 -0700 | [diff] [blame] | 335 | gboolean UpdateAttempterTest::StaticPingOmahaTestStart(gpointer data) { |
| 336 | reinterpret_cast<UpdateAttempterTest*>(data)->PingOmahaTestStart(); |
| 337 | return FALSE; |
| 338 | } |
| 339 | |
Jay Srinivasan | ae4697c | 2013-03-18 17:08:08 -0700 | [diff] [blame] | 340 | gboolean UpdateAttempterTest::StaticReadChannelFromPolicyTestStart( |
Patrick Dubroy | 7fbbe8a | 2011-08-01 17:28:22 +0200 | [diff] [blame] | 341 | gpointer data) { |
Jay Srinivasan | ae4697c | 2013-03-18 17:08:08 -0700 | [diff] [blame] | 342 | UpdateAttempterTest* ua_test = reinterpret_cast<UpdateAttempterTest*>(data); |
| 343 | ua_test->ReadChannelFromPolicyTestStart(); |
Thieu Le | 116fda3 | 2011-04-19 11:01:54 -0700 | [diff] [blame] | 344 | return FALSE; |
| 345 | } |
| 346 | |
Jay Srinivasan | 0a70874 | 2012-03-20 11:26:12 -0700 | [diff] [blame] | 347 | gboolean UpdateAttempterTest::StaticReadUpdateDisabledFromPolicyTestStart( |
| 348 | gpointer data) { |
| 349 | UpdateAttempterTest* ua_test = reinterpret_cast<UpdateAttempterTest*>(data); |
| 350 | ua_test->ReadUpdateDisabledFromPolicyTestStart(); |
| 351 | return FALSE; |
| 352 | } |
| 353 | |
| 354 | gboolean UpdateAttempterTest::StaticReadTargetVersionPrefixFromPolicyTestStart( |
| 355 | gpointer data) { |
| 356 | UpdateAttempterTest* ua_test = reinterpret_cast<UpdateAttempterTest*>(data); |
| 357 | ua_test->ReadTargetVersionPrefixFromPolicyTestStart(); |
| 358 | return FALSE; |
| 359 | } |
| 360 | |
Jay Srinivasan | 480ddfa | 2012-06-01 19:15:26 -0700 | [diff] [blame] | 361 | gboolean UpdateAttempterTest::StaticReadScatterFactorFromPolicyTestStart( |
| 362 | gpointer data) { |
| 363 | UpdateAttempterTest* ua_test = reinterpret_cast<UpdateAttempterTest*>(data); |
| 364 | ua_test->ReadScatterFactorFromPolicyTestStart(); |
| 365 | return FALSE; |
| 366 | } |
| 367 | |
| 368 | gboolean UpdateAttempterTest::StaticDecrementUpdateCheckCountTestStart( |
| 369 | gpointer data) { |
| 370 | UpdateAttempterTest* ua_test = reinterpret_cast<UpdateAttempterTest*>(data); |
| 371 | ua_test->DecrementUpdateCheckCountTestStart(); |
| 372 | return FALSE; |
| 373 | } |
| 374 | |
Jay Srinivasan | 08fce04 | 2012-06-07 16:31:01 -0700 | [diff] [blame] | 375 | gboolean UpdateAttempterTest::StaticNoScatteringDoneDuringManualUpdateTestStart( |
| 376 | gpointer data) { |
| 377 | UpdateAttempterTest* ua_test = reinterpret_cast<UpdateAttempterTest*>(data); |
| 378 | ua_test->NoScatteringDoneDuringManualUpdateTestStart(); |
| 379 | return FALSE; |
| 380 | } |
| 381 | |
Darin Petkov | e6ef2f8 | 2011-03-07 17:31:11 -0800 | [diff] [blame] | 382 | namespace { |
Chris Sosa | 76a29ae | 2013-07-11 17:59:24 -0700 | [diff] [blame] | 383 | // Actions that will be built as part of an update check. |
| 384 | const string kUpdateActionTypes[] = { |
Darin Petkov | e6ef2f8 | 2011-03-07 17:31:11 -0800 | [diff] [blame] | 385 | OmahaRequestAction::StaticType(), |
| 386 | OmahaResponseHandlerAction::StaticType(), |
| 387 | FilesystemCopierAction::StaticType(), |
| 388 | FilesystemCopierAction::StaticType(), |
| 389 | OmahaRequestAction::StaticType(), |
| 390 | DownloadAction::StaticType(), |
| 391 | OmahaRequestAction::StaticType(), |
| 392 | FilesystemCopierAction::StaticType(), |
| 393 | FilesystemCopierAction::StaticType(), |
| 394 | PostinstallRunnerAction::StaticType(), |
| 395 | OmahaRequestAction::StaticType() |
| 396 | }; |
Chris Sosa | 76a29ae | 2013-07-11 17:59:24 -0700 | [diff] [blame] | 397 | |
| 398 | // Actions that will be built as part of a user-initiated rollback. |
| 399 | const string kRollbackActionTypes[] = { |
| 400 | InstallPlanAction::StaticType(), |
| 401 | PostinstallRunnerAction::StaticType(), |
| 402 | }; |
| 403 | |
Darin Petkov | e6ef2f8 | 2011-03-07 17:31:11 -0800 | [diff] [blame] | 404 | } // namespace {} |
| 405 | |
| 406 | void UpdateAttempterTest::UpdateTestStart() { |
Darin Petkov | f42cc1c | 2010-09-01 09:03:02 -0700 | [diff] [blame] | 407 | attempter_.set_http_response_code(200); |
| 408 | InSequence s; |
Chris Sosa | 76a29ae | 2013-07-11 17:59:24 -0700 | [diff] [blame] | 409 | for (size_t i = 0; i < arraysize(kUpdateActionTypes); ++i) { |
Darin Petkov | f42cc1c | 2010-09-01 09:03:02 -0700 | [diff] [blame] | 410 | EXPECT_CALL(*processor_, |
| 411 | EnqueueAction(Property(&AbstractAction::Type, |
Chris Sosa | 76a29ae | 2013-07-11 17:59:24 -0700 | [diff] [blame] | 412 | kUpdateActionTypes[i]))).Times(1); |
Darin Petkov | f42cc1c | 2010-09-01 09:03:02 -0700 | [diff] [blame] | 413 | } |
| 414 | EXPECT_CALL(*processor_, StartProcessing()).Times(1); |
| 415 | |
Gilad Arnold | b92f0df | 2013-01-10 16:32:45 -0800 | [diff] [blame] | 416 | attempter_.Update("", "", false, false, false); |
Darin Petkov | e6ef2f8 | 2011-03-07 17:31:11 -0800 | [diff] [blame] | 417 | g_idle_add(&StaticUpdateTestVerify, this); |
| 418 | } |
Darin Petkov | f42cc1c | 2010-09-01 09:03:02 -0700 | [diff] [blame] | 419 | |
Darin Petkov | e6ef2f8 | 2011-03-07 17:31:11 -0800 | [diff] [blame] | 420 | void UpdateAttempterTest::UpdateTestVerify() { |
Darin Petkov | f42cc1c | 2010-09-01 09:03:02 -0700 | [diff] [blame] | 421 | EXPECT_EQ(0, attempter_.http_response_code()); |
| 422 | EXPECT_EQ(&attempter_, processor_->delegate()); |
Chris Sosa | 76a29ae | 2013-07-11 17:59:24 -0700 | [diff] [blame] | 423 | EXPECT_EQ(arraysize(kUpdateActionTypes), attempter_.actions_.size()); |
| 424 | for (size_t i = 0; i < arraysize(kUpdateActionTypes); ++i) { |
| 425 | EXPECT_EQ(kUpdateActionTypes[i], attempter_.actions_[i]->Type()); |
Darin Petkov | f42cc1c | 2010-09-01 09:03:02 -0700 | [diff] [blame] | 426 | } |
| 427 | EXPECT_EQ(attempter_.response_handler_action_.get(), |
| 428 | attempter_.actions_[1].get()); |
| 429 | DownloadAction* download_action = |
| 430 | dynamic_cast<DownloadAction*>(attempter_.actions_[5].get()); |
| 431 | ASSERT_TRUE(download_action != NULL); |
| 432 | EXPECT_EQ(&attempter_, download_action->delegate()); |
| 433 | EXPECT_EQ(UPDATE_STATUS_CHECKING_FOR_UPDATE, attempter_.status()); |
Darin Petkov | e6ef2f8 | 2011-03-07 17:31:11 -0800 | [diff] [blame] | 434 | g_main_loop_quit(loop_); |
| 435 | } |
| 436 | |
Chris Sosa | 28e479c | 2013-07-12 11:39:53 -0700 | [diff] [blame] | 437 | void UpdateAttempterTest::RollbackTestStart( |
| 438 | bool enterprise_rollback, bool stable_channel) { |
Chris Sosa | 76a29ae | 2013-07-11 17:59:24 -0700 | [diff] [blame] | 439 | // Create a device policy so that we can change settings. |
| 440 | policy::MockDevicePolicy* device_policy = new policy::MockDevicePolicy(); |
| 441 | attempter_.policy_provider_.reset(new policy::PolicyProvider(device_policy)); |
| 442 | |
| 443 | EXPECT_CALL(*device_policy, LoadPolicy()).WillRepeatedly(Return(true)); |
| 444 | EXPECT_CALL(mock_system_state_, device_policy()).WillRepeatedly( |
| 445 | Return(device_policy)); |
| 446 | |
| 447 | string install_path = "/dev/sda3"; |
Chris Sosa | 28e479c | 2013-07-12 11:39:53 -0700 | [diff] [blame] | 448 | bool is_rollback_allowed = false; |
Chris Sosa | 76a29ae | 2013-07-11 17:59:24 -0700 | [diff] [blame] | 449 | |
Chris Sosa | 28e479c | 2013-07-12 11:39:53 -0700 | [diff] [blame] | 450 | // We only allow rollback on devices that are neither enterprise enrolled or |
| 451 | // not on the stable channel. |
| 452 | if (!(enterprise_rollback || stable_channel)) { |
| 453 | is_rollback_allowed = true; |
| 454 | } |
| 455 | |
| 456 | // Set up the policy for the test given our args. |
| 457 | if (stable_channel) { |
| 458 | attempter_.omaha_request_params_->set_current_channel( |
| 459 | string("stable-channel")); |
| 460 | } else if (enterprise_rollback) { |
| 461 | // We return an empty owner as this is an enterprise. |
| 462 | EXPECT_CALL(*device_policy, GetOwner(_)).WillOnce( |
| 463 | DoAll(SetArgumentPointee<0>(std::string("")), |
| 464 | Return(true))); |
| 465 | } else { |
| 466 | // We return a fake owner as this is an owned consumer device. |
Chris Sosa | 76a29ae | 2013-07-11 17:59:24 -0700 | [diff] [blame] | 467 | EXPECT_CALL(*device_policy, GetOwner(_)).WillOnce( |
| 468 | DoAll(SetArgumentPointee<0>(std::string("fake.mail@fake.com")), |
| 469 | Return(true))); |
Chris Sosa | 28e479c | 2013-07-12 11:39:53 -0700 | [diff] [blame] | 470 | } |
Chris Sosa | 76a29ae | 2013-07-11 17:59:24 -0700 | [diff] [blame] | 471 | |
Chris Sosa | 28e479c | 2013-07-12 11:39:53 -0700 | [diff] [blame] | 472 | if (is_rollback_allowed) { |
Chris Sosa | 76a29ae | 2013-07-11 17:59:24 -0700 | [diff] [blame] | 473 | InSequence s; |
| 474 | for (size_t i = 0; i < arraysize(kRollbackActionTypes); ++i) { |
| 475 | EXPECT_CALL(*processor_, |
| 476 | EnqueueAction(Property(&AbstractAction::Type, |
| 477 | kRollbackActionTypes[i]))).Times(1); |
| 478 | } |
| 479 | EXPECT_CALL(*processor_, StartProcessing()).Times(1); |
| 480 | |
| 481 | EXPECT_TRUE(attempter_.Rollback(true, &install_path)); |
| 482 | g_idle_add(&StaticRollbackTestVerify, this); |
| 483 | } else { |
Chris Sosa | 76a29ae | 2013-07-11 17:59:24 -0700 | [diff] [blame] | 484 | EXPECT_FALSE(attempter_.Rollback(true, &install_path)); |
| 485 | g_main_loop_quit(loop_); |
| 486 | } |
| 487 | } |
| 488 | |
| 489 | void UpdateAttempterTest::RollbackTestVerify() { |
| 490 | // Verifies the actions that were enqueued. |
| 491 | EXPECT_EQ(&attempter_, processor_->delegate()); |
| 492 | EXPECT_EQ(arraysize(kRollbackActionTypes), attempter_.actions_.size()); |
| 493 | for (size_t i = 0; i < arraysize(kRollbackActionTypes); ++i) { |
| 494 | EXPECT_EQ(kRollbackActionTypes[i], attempter_.actions_[i]->Type()); |
| 495 | } |
| 496 | EXPECT_EQ(UPDATE_STATUS_ATTEMPTING_ROLLBACK, attempter_.status()); |
| 497 | InstallPlanAction* install_plan_action = |
| 498 | dynamic_cast<InstallPlanAction*>(attempter_.actions_[0].get()); |
| 499 | InstallPlan* install_plan = install_plan_action->install_plan(); |
| 500 | EXPECT_EQ(install_plan->install_path, string("/dev/sda3")); |
| 501 | EXPECT_EQ(install_plan->kernel_install_path, string("/dev/sda2")); |
| 502 | EXPECT_EQ(install_plan->powerwash_required, true); |
| 503 | g_main_loop_quit(loop_); |
| 504 | } |
| 505 | |
Darin Petkov | e6ef2f8 | 2011-03-07 17:31:11 -0800 | [diff] [blame] | 506 | TEST_F(UpdateAttempterTest, UpdateTest) { |
| 507 | loop_ = g_main_loop_new(g_main_context_default(), FALSE); |
| 508 | g_idle_add(&StaticUpdateTestStart, this); |
| 509 | g_main_loop_run(loop_); |
| 510 | g_main_loop_unref(loop_); |
| 511 | loop_ = NULL; |
Darin Petkov | f42cc1c | 2010-09-01 09:03:02 -0700 | [diff] [blame] | 512 | } |
| 513 | |
Chris Sosa | 76a29ae | 2013-07-11 17:59:24 -0700 | [diff] [blame] | 514 | TEST_F(UpdateAttempterTest, RollbackTest) { |
| 515 | loop_ = g_main_loop_new(g_main_context_default(), FALSE); |
| 516 | g_idle_add(&StaticRollbackTestStart, this); |
| 517 | g_main_loop_run(loop_); |
| 518 | g_main_loop_unref(loop_); |
| 519 | loop_ = NULL; |
| 520 | } |
| 521 | |
Chris Sosa | 28e479c | 2013-07-12 11:39:53 -0700 | [diff] [blame] | 522 | TEST_F(UpdateAttempterTest, StableChannelRollbackTest) { |
| 523 | loop_ = g_main_loop_new(g_main_context_default(), FALSE); |
| 524 | g_idle_add(&StaticStableChannelRollbackTestStart, this); |
| 525 | g_main_loop_run(loop_); |
| 526 | g_main_loop_unref(loop_); |
| 527 | loop_ = NULL; |
| 528 | } |
| 529 | |
Chris Sosa | 76a29ae | 2013-07-11 17:59:24 -0700 | [diff] [blame] | 530 | TEST_F(UpdateAttempterTest, EnterpriseRollbackTest) { |
| 531 | loop_ = g_main_loop_new(g_main_context_default(), FALSE); |
| 532 | g_idle_add(&StaticEnterpriseRollbackTestStart, this); |
| 533 | g_main_loop_run(loop_); |
| 534 | g_main_loop_unref(loop_); |
| 535 | loop_ = NULL; |
| 536 | } |
| 537 | |
Thieu Le | 116fda3 | 2011-04-19 11:01:54 -0700 | [diff] [blame] | 538 | void UpdateAttempterTest::PingOmahaTestStart() { |
| 539 | EXPECT_CALL(*processor_, |
| 540 | EnqueueAction(Property(&AbstractAction::Type, |
| 541 | OmahaRequestAction::StaticType()))) |
| 542 | .Times(1); |
| 543 | EXPECT_CALL(*processor_, StartProcessing()).Times(1); |
| 544 | attempter_.PingOmaha(); |
Patrick Dubroy | 7fbbe8a | 2011-08-01 17:28:22 +0200 | [diff] [blame] | 545 | g_idle_add(&StaticQuitMainLoop, this); |
Thieu Le | 116fda3 | 2011-04-19 11:01:54 -0700 | [diff] [blame] | 546 | } |
| 547 | |
| 548 | TEST_F(UpdateAttempterTest, PingOmahaTest) { |
Gilad Arnold | bf7919b | 2013-01-08 13:07:37 -0800 | [diff] [blame] | 549 | UpdateCheckScheduler scheduler(&attempter_, &mock_system_state_); |
Thieu Le | 116fda3 | 2011-04-19 11:01:54 -0700 | [diff] [blame] | 550 | scheduler.enabled_ = true; |
Andrew de los Reyes | e05fc28 | 2011-06-02 09:50:08 -0700 | [diff] [blame] | 551 | EXPECT_FALSE(scheduler.scheduled_); |
Thieu Le | 116fda3 | 2011-04-19 11:01:54 -0700 | [diff] [blame] | 552 | attempter_.set_update_check_scheduler(&scheduler); |
| 553 | loop_ = g_main_loop_new(g_main_context_default(), FALSE); |
| 554 | g_idle_add(&StaticPingOmahaTestStart, this); |
| 555 | g_main_loop_run(loop_); |
| 556 | g_main_loop_unref(loop_); |
| 557 | loop_ = NULL; |
| 558 | EXPECT_EQ(UPDATE_STATUS_UPDATED_NEED_REBOOT, attempter_.status()); |
| 559 | EXPECT_EQ(true, scheduler.scheduled_); |
| 560 | } |
| 561 | |
Darin Petkov | 18c7bce | 2011-06-16 14:07:00 -0700 | [diff] [blame] | 562 | TEST_F(UpdateAttempterTest, CreatePendingErrorEventTest) { |
| 563 | ActionMock action; |
David Zeuthen | a99981f | 2013-04-29 13:42:47 -0700 | [diff] [blame] | 564 | const ErrorCode kCode = kErrorCodeDownloadTransferError; |
Darin Petkov | 18c7bce | 2011-06-16 14:07:00 -0700 | [diff] [blame] | 565 | attempter_.CreatePendingErrorEvent(&action, kCode); |
| 566 | ASSERT_TRUE(attempter_.error_event_.get() != NULL); |
| 567 | EXPECT_EQ(OmahaEvent::kTypeUpdateComplete, attempter_.error_event_->type); |
| 568 | EXPECT_EQ(OmahaEvent::kResultError, attempter_.error_event_->result); |
David Zeuthen | a99981f | 2013-04-29 13:42:47 -0700 | [diff] [blame] | 569 | EXPECT_EQ(kCode | kErrorCodeTestOmahaUrlFlag, |
Jay Srinivasan | 55f50c2 | 2013-01-10 19:24:35 -0800 | [diff] [blame] | 570 | attempter_.error_event_->error_code); |
Darin Petkov | 18c7bce | 2011-06-16 14:07:00 -0700 | [diff] [blame] | 571 | } |
| 572 | |
| 573 | TEST_F(UpdateAttempterTest, CreatePendingErrorEventResumedTest) { |
| 574 | OmahaResponseHandlerAction *response_action = |
Jay Srinivasan | 6f6ea00 | 2012-12-14 11:26:28 -0800 | [diff] [blame] | 575 | new OmahaResponseHandlerAction(&mock_system_state_); |
Darin Petkov | 18c7bce | 2011-06-16 14:07:00 -0700 | [diff] [blame] | 576 | response_action->install_plan_.is_resume = true; |
| 577 | attempter_.response_handler_action_.reset(response_action); |
| 578 | ActionMock action; |
David Zeuthen | a99981f | 2013-04-29 13:42:47 -0700 | [diff] [blame] | 579 | const ErrorCode kCode = kErrorCodeInstallDeviceOpenError; |
Darin Petkov | 18c7bce | 2011-06-16 14:07:00 -0700 | [diff] [blame] | 580 | attempter_.CreatePendingErrorEvent(&action, kCode); |
| 581 | ASSERT_TRUE(attempter_.error_event_.get() != NULL); |
| 582 | EXPECT_EQ(OmahaEvent::kTypeUpdateComplete, attempter_.error_event_->type); |
| 583 | EXPECT_EQ(OmahaEvent::kResultError, attempter_.error_event_->result); |
David Zeuthen | a99981f | 2013-04-29 13:42:47 -0700 | [diff] [blame] | 584 | EXPECT_EQ(kCode | kErrorCodeResumedFlag | kErrorCodeTestOmahaUrlFlag, |
Darin Petkov | 18c7bce | 2011-06-16 14:07:00 -0700 | [diff] [blame] | 585 | attempter_.error_event_->error_code); |
| 586 | } |
| 587 | |
Jay Srinivasan | ae4697c | 2013-03-18 17:08:08 -0700 | [diff] [blame] | 588 | TEST_F(UpdateAttempterTest, ReadChannelFromPolicy) { |
Patrick Dubroy | 7fbbe8a | 2011-08-01 17:28:22 +0200 | [diff] [blame] | 589 | loop_ = g_main_loop_new(g_main_context_default(), FALSE); |
Jay Srinivasan | ae4697c | 2013-03-18 17:08:08 -0700 | [diff] [blame] | 590 | g_idle_add(&StaticReadChannelFromPolicyTestStart, this); |
Patrick Dubroy | 7fbbe8a | 2011-08-01 17:28:22 +0200 | [diff] [blame] | 591 | g_main_loop_run(loop_); |
| 592 | g_main_loop_unref(loop_); |
| 593 | loop_ = NULL; |
| 594 | } |
| 595 | |
Jay Srinivasan | ae4697c | 2013-03-18 17:08:08 -0700 | [diff] [blame] | 596 | void UpdateAttempterTest::ReadChannelFromPolicyTestStart() { |
| 597 | // Tests that the update channel (aka release channel) is properly fetched |
Patrick Dubroy | 7fbbe8a | 2011-08-01 17:28:22 +0200 | [diff] [blame] | 598 | // from the device policy. |
| 599 | |
| 600 | policy::MockDevicePolicy* device_policy = new policy::MockDevicePolicy(); |
| 601 | attempter_.policy_provider_.reset(new policy::PolicyProvider(device_policy)); |
| 602 | |
| 603 | EXPECT_CALL(*device_policy, LoadPolicy()).WillRepeatedly(Return(true)); |
Jay Srinivasan | ae4697c | 2013-03-18 17:08:08 -0700 | [diff] [blame] | 604 | EXPECT_CALL(mock_system_state_, device_policy()).WillRepeatedly( |
| 605 | Return(device_policy)); |
Patrick Dubroy | 7fbbe8a | 2011-08-01 17:28:22 +0200 | [diff] [blame] | 606 | |
Jay Srinivasan | ae4697c | 2013-03-18 17:08:08 -0700 | [diff] [blame] | 607 | EXPECT_CALL(*device_policy, GetReleaseChannelDelegated(_)).WillRepeatedly( |
| 608 | DoAll(SetArgumentPointee<0>(bool(false)), |
| 609 | Return(true))); |
Patrick Dubroy | 7fbbe8a | 2011-08-01 17:28:22 +0200 | [diff] [blame] | 610 | |
Jay Srinivasan | ae4697c | 2013-03-18 17:08:08 -0700 | [diff] [blame] | 611 | EXPECT_CALL(*device_policy, GetReleaseChannel(_)).WillRepeatedly( |
| 612 | DoAll(SetArgumentPointee<0>(std::string("beta-channel")), |
| 613 | Return(true))); |
| 614 | |
| 615 | attempter_.omaha_request_params_->set_root("./UpdateAttempterTest"); |
Gilad Arnold | b92f0df | 2013-01-10 16:32:45 -0800 | [diff] [blame] | 616 | attempter_.Update("", "", false, false, false); |
Jay Srinivasan | ae4697c | 2013-03-18 17:08:08 -0700 | [diff] [blame] | 617 | EXPECT_EQ("beta-channel", |
| 618 | attempter_.omaha_request_params_->target_channel()); |
Patrick Dubroy | 7fbbe8a | 2011-08-01 17:28:22 +0200 | [diff] [blame] | 619 | |
| 620 | g_idle_add(&StaticQuitMainLoop, this); |
| 621 | } |
| 622 | |
Jay Srinivasan | 0a70874 | 2012-03-20 11:26:12 -0700 | [diff] [blame] | 623 | TEST_F(UpdateAttempterTest, ReadUpdateDisabledFromPolicy) { |
| 624 | loop_ = g_main_loop_new(g_main_context_default(), FALSE); |
| 625 | g_idle_add(&StaticReadUpdateDisabledFromPolicyTestStart, this); |
| 626 | g_main_loop_run(loop_); |
| 627 | g_main_loop_unref(loop_); |
| 628 | loop_ = NULL; |
| 629 | } |
| 630 | |
| 631 | void UpdateAttempterTest::ReadUpdateDisabledFromPolicyTestStart() { |
| 632 | // Tests that the update_disbled flag is properly fetched |
| 633 | // from the device policy. |
| 634 | |
| 635 | policy::MockDevicePolicy* device_policy = new policy::MockDevicePolicy(); |
| 636 | attempter_.policy_provider_.reset(new policy::PolicyProvider(device_policy)); |
| 637 | |
| 638 | EXPECT_CALL(*device_policy, LoadPolicy()).WillRepeatedly(Return(true)); |
Jay Srinivasan | ae4697c | 2013-03-18 17:08:08 -0700 | [diff] [blame] | 639 | EXPECT_CALL(mock_system_state_, device_policy()).WillRepeatedly( |
| 640 | Return(device_policy)); |
Jay Srinivasan | 0a70874 | 2012-03-20 11:26:12 -0700 | [diff] [blame] | 641 | |
| 642 | EXPECT_CALL(*device_policy, GetUpdateDisabled(_)) |
| 643 | .WillRepeatedly(DoAll( |
| 644 | SetArgumentPointee<0>(true), |
| 645 | Return(true))); |
| 646 | |
Gilad Arnold | b92f0df | 2013-01-10 16:32:45 -0800 | [diff] [blame] | 647 | attempter_.Update("", "", false, false, false); |
Jay Srinivasan | ae4697c | 2013-03-18 17:08:08 -0700 | [diff] [blame] | 648 | EXPECT_TRUE(attempter_.omaha_request_params_->update_disabled()); |
Jay Srinivasan | 0a70874 | 2012-03-20 11:26:12 -0700 | [diff] [blame] | 649 | |
| 650 | g_idle_add(&StaticQuitMainLoop, this); |
| 651 | } |
| 652 | |
| 653 | TEST_F(UpdateAttempterTest, ReadTargetVersionPrefixFromPolicy) { |
| 654 | loop_ = g_main_loop_new(g_main_context_default(), FALSE); |
| 655 | g_idle_add(&StaticReadTargetVersionPrefixFromPolicyTestStart, this); |
| 656 | g_main_loop_run(loop_); |
| 657 | g_main_loop_unref(loop_); |
| 658 | loop_ = NULL; |
| 659 | } |
| 660 | |
| 661 | void UpdateAttempterTest::ReadTargetVersionPrefixFromPolicyTestStart() { |
| 662 | // Tests that the target_version_prefix value is properly fetched |
| 663 | // from the device policy. |
| 664 | |
| 665 | const std::string target_version_prefix = "1412."; |
| 666 | |
| 667 | policy::MockDevicePolicy* device_policy = new policy::MockDevicePolicy(); |
| 668 | attempter_.policy_provider_.reset(new policy::PolicyProvider(device_policy)); |
| 669 | |
| 670 | EXPECT_CALL(*device_policy, LoadPolicy()).WillRepeatedly(Return(true)); |
Jay Srinivasan | ae4697c | 2013-03-18 17:08:08 -0700 | [diff] [blame] | 671 | EXPECT_CALL(mock_system_state_, device_policy()).WillRepeatedly( |
| 672 | Return(device_policy)); |
Jay Srinivasan | 0a70874 | 2012-03-20 11:26:12 -0700 | [diff] [blame] | 673 | |
| 674 | EXPECT_CALL(*device_policy, GetTargetVersionPrefix(_)) |
| 675 | .WillRepeatedly(DoAll( |
| 676 | SetArgumentPointee<0>(target_version_prefix), |
| 677 | Return(true))); |
| 678 | |
Gilad Arnold | b92f0df | 2013-01-10 16:32:45 -0800 | [diff] [blame] | 679 | attempter_.Update("", "", false, false, false); |
Jay Srinivasan | 0a70874 | 2012-03-20 11:26:12 -0700 | [diff] [blame] | 680 | EXPECT_EQ(target_version_prefix.c_str(), |
Jay Srinivasan | ae4697c | 2013-03-18 17:08:08 -0700 | [diff] [blame] | 681 | attempter_.omaha_request_params_->target_version_prefix()); |
Jay Srinivasan | 0a70874 | 2012-03-20 11:26:12 -0700 | [diff] [blame] | 682 | |
| 683 | g_idle_add(&StaticQuitMainLoop, this); |
| 684 | } |
| 685 | |
| 686 | |
Jay Srinivasan | 480ddfa | 2012-06-01 19:15:26 -0700 | [diff] [blame] | 687 | TEST_F(UpdateAttempterTest, ReadScatterFactorFromPolicy) { |
| 688 | loop_ = g_main_loop_new(g_main_context_default(), FALSE); |
| 689 | g_idle_add(&StaticReadScatterFactorFromPolicyTestStart, this); |
| 690 | g_main_loop_run(loop_); |
| 691 | g_main_loop_unref(loop_); |
| 692 | loop_ = NULL; |
| 693 | } |
| 694 | |
| 695 | // Tests that the scatter_factor_in_seconds value is properly fetched |
| 696 | // from the device policy. |
| 697 | void UpdateAttempterTest::ReadScatterFactorFromPolicyTestStart() { |
| 698 | int64 scatter_factor_in_seconds = 36000; |
| 699 | |
| 700 | policy::MockDevicePolicy* device_policy = new policy::MockDevicePolicy(); |
| 701 | attempter_.policy_provider_.reset(new policy::PolicyProvider(device_policy)); |
| 702 | |
| 703 | EXPECT_CALL(*device_policy, LoadPolicy()).WillRepeatedly(Return(true)); |
Jay Srinivasan | 6f6ea00 | 2012-12-14 11:26:28 -0800 | [diff] [blame] | 704 | EXPECT_CALL(mock_system_state_, device_policy()).WillRepeatedly( |
Jay Srinivasan | 21be075 | 2012-07-25 15:44:56 -0700 | [diff] [blame] | 705 | Return(device_policy)); |
Jay Srinivasan | 480ddfa | 2012-06-01 19:15:26 -0700 | [diff] [blame] | 706 | |
| 707 | EXPECT_CALL(*device_policy, GetScatterFactorInSeconds(_)) |
| 708 | .WillRepeatedly(DoAll( |
| 709 | SetArgumentPointee<0>(scatter_factor_in_seconds), |
| 710 | Return(true))); |
| 711 | |
Gilad Arnold | b92f0df | 2013-01-10 16:32:45 -0800 | [diff] [blame] | 712 | attempter_.Update("", "", false, false, false); |
Jay Srinivasan | 480ddfa | 2012-06-01 19:15:26 -0700 | [diff] [blame] | 713 | EXPECT_EQ(scatter_factor_in_seconds, attempter_.scatter_factor_.InSeconds()); |
| 714 | |
| 715 | g_idle_add(&StaticQuitMainLoop, this); |
| 716 | } |
| 717 | |
| 718 | TEST_F(UpdateAttempterTest, DecrementUpdateCheckCountTest) { |
| 719 | loop_ = g_main_loop_new(g_main_context_default(), FALSE); |
| 720 | g_idle_add(&StaticDecrementUpdateCheckCountTestStart, this); |
| 721 | g_main_loop_run(loop_); |
| 722 | g_main_loop_unref(loop_); |
| 723 | loop_ = NULL; |
| 724 | } |
| 725 | |
| 726 | void UpdateAttempterTest::DecrementUpdateCheckCountTestStart() { |
| 727 | // Tests that the scatter_factor_in_seconds value is properly fetched |
| 728 | // from the device policy and is decremented if value > 0. |
| 729 | int64 initial_value = 5; |
| 730 | Prefs prefs; |
| 731 | attempter_.prefs_ = &prefs; |
| 732 | |
Jay Srinivasan | 08fce04 | 2012-06-07 16:31:01 -0700 | [diff] [blame] | 733 | EXPECT_CALL(mock_system_state_, |
| 734 | IsOOBEComplete()).WillRepeatedly(Return(true)); |
| 735 | |
Jay Srinivasan | 480ddfa | 2012-06-01 19:15:26 -0700 | [diff] [blame] | 736 | string prefs_dir; |
| 737 | EXPECT_TRUE(utils::MakeTempDirectory("/tmp/ue_ut_prefs.XXXXXX", |
| 738 | &prefs_dir)); |
| 739 | ScopedDirRemover temp_dir_remover(prefs_dir); |
| 740 | |
| 741 | LOG_IF(ERROR, !prefs.Init(FilePath(prefs_dir))) |
| 742 | << "Failed to initialize preferences."; |
| 743 | EXPECT_TRUE(prefs.SetInt64(kPrefsUpdateCheckCount, initial_value)); |
| 744 | |
| 745 | int64 scatter_factor_in_seconds = 10; |
| 746 | |
| 747 | policy::MockDevicePolicy* device_policy = new policy::MockDevicePolicy(); |
| 748 | attempter_.policy_provider_.reset(new policy::PolicyProvider(device_policy)); |
| 749 | |
| 750 | EXPECT_CALL(*device_policy, LoadPolicy()).WillRepeatedly(Return(true)); |
Jay Srinivasan | 6f6ea00 | 2012-12-14 11:26:28 -0800 | [diff] [blame] | 751 | EXPECT_CALL(mock_system_state_, device_policy()).WillRepeatedly( |
Jay Srinivasan | 21be075 | 2012-07-25 15:44:56 -0700 | [diff] [blame] | 752 | Return(device_policy)); |
Jay Srinivasan | 480ddfa | 2012-06-01 19:15:26 -0700 | [diff] [blame] | 753 | |
| 754 | EXPECT_CALL(*device_policy, GetScatterFactorInSeconds(_)) |
| 755 | .WillRepeatedly(DoAll( |
| 756 | SetArgumentPointee<0>(scatter_factor_in_seconds), |
| 757 | Return(true))); |
| 758 | |
Gilad Arnold | b92f0df | 2013-01-10 16:32:45 -0800 | [diff] [blame] | 759 | attempter_.Update("", "", false, false, false); |
Jay Srinivasan | 480ddfa | 2012-06-01 19:15:26 -0700 | [diff] [blame] | 760 | EXPECT_EQ(scatter_factor_in_seconds, attempter_.scatter_factor_.InSeconds()); |
| 761 | |
| 762 | // Make sure the file still exists. |
| 763 | EXPECT_TRUE(prefs.Exists(kPrefsUpdateCheckCount)); |
| 764 | |
| 765 | int64 new_value; |
| 766 | EXPECT_TRUE(prefs.GetInt64(kPrefsUpdateCheckCount, &new_value)); |
| 767 | EXPECT_EQ(initial_value - 1, new_value); |
| 768 | |
Jay Srinivasan | ae4697c | 2013-03-18 17:08:08 -0700 | [diff] [blame] | 769 | EXPECT_TRUE( |
| 770 | attempter_.omaha_request_params_->update_check_count_wait_enabled()); |
Jay Srinivasan | 480ddfa | 2012-06-01 19:15:26 -0700 | [diff] [blame] | 771 | |
| 772 | // However, if the count is already 0, it's not decremented. Test that. |
| 773 | initial_value = 0; |
| 774 | EXPECT_TRUE(prefs.SetInt64(kPrefsUpdateCheckCount, initial_value)); |
Gilad Arnold | b92f0df | 2013-01-10 16:32:45 -0800 | [diff] [blame] | 775 | attempter_.Update("", "", false, false, false); |
Jay Srinivasan | 480ddfa | 2012-06-01 19:15:26 -0700 | [diff] [blame] | 776 | EXPECT_TRUE(prefs.Exists(kPrefsUpdateCheckCount)); |
| 777 | EXPECT_TRUE(prefs.GetInt64(kPrefsUpdateCheckCount, &new_value)); |
| 778 | EXPECT_EQ(initial_value, new_value); |
| 779 | |
| 780 | g_idle_add(&StaticQuitMainLoop, this); |
| 781 | } |
| 782 | |
Jay Srinivasan | 08fce04 | 2012-06-07 16:31:01 -0700 | [diff] [blame] | 783 | TEST_F(UpdateAttempterTest, NoScatteringDoneDuringManualUpdateTestStart) { |
| 784 | loop_ = g_main_loop_new(g_main_context_default(), FALSE); |
| 785 | g_idle_add(&StaticNoScatteringDoneDuringManualUpdateTestStart, this); |
| 786 | g_main_loop_run(loop_); |
| 787 | g_main_loop_unref(loop_); |
| 788 | loop_ = NULL; |
| 789 | } |
| 790 | |
| 791 | void UpdateAttempterTest::NoScatteringDoneDuringManualUpdateTestStart() { |
| 792 | // Tests that no scattering logic is enabled if the update check |
| 793 | // is manually done (as opposed to a scheduled update check) |
| 794 | int64 initial_value = 8; |
| 795 | Prefs prefs; |
| 796 | attempter_.prefs_ = &prefs; |
| 797 | |
| 798 | EXPECT_CALL(mock_system_state_, |
| 799 | IsOOBEComplete()).WillRepeatedly(Return(true)); |
| 800 | |
| 801 | string prefs_dir; |
| 802 | EXPECT_TRUE(utils::MakeTempDirectory("/tmp/ue_ut_prefs.XXXXXX", |
| 803 | &prefs_dir)); |
| 804 | ScopedDirRemover temp_dir_remover(prefs_dir); |
| 805 | |
| 806 | LOG_IF(ERROR, !prefs.Init(FilePath(prefs_dir))) |
| 807 | << "Failed to initialize preferences."; |
Jay Srinivasan | 21be075 | 2012-07-25 15:44:56 -0700 | [diff] [blame] | 808 | EXPECT_TRUE(prefs.SetInt64(kPrefsWallClockWaitPeriod, initial_value)); |
Jay Srinivasan | 08fce04 | 2012-06-07 16:31:01 -0700 | [diff] [blame] | 809 | EXPECT_TRUE(prefs.SetInt64(kPrefsUpdateCheckCount, initial_value)); |
| 810 | |
| 811 | // make sure scatter_factor is non-zero as scattering is disabled |
| 812 | // otherwise. |
| 813 | int64 scatter_factor_in_seconds = 50; |
| 814 | |
| 815 | policy::MockDevicePolicy* device_policy = new policy::MockDevicePolicy(); |
| 816 | attempter_.policy_provider_.reset(new policy::PolicyProvider(device_policy)); |
| 817 | |
| 818 | EXPECT_CALL(*device_policy, LoadPolicy()).WillRepeatedly(Return(true)); |
Jay Srinivasan | 6f6ea00 | 2012-12-14 11:26:28 -0800 | [diff] [blame] | 819 | EXPECT_CALL(mock_system_state_, device_policy()).WillRepeatedly( |
Jay Srinivasan | 21be075 | 2012-07-25 15:44:56 -0700 | [diff] [blame] | 820 | Return(device_policy)); |
Jay Srinivasan | 08fce04 | 2012-06-07 16:31:01 -0700 | [diff] [blame] | 821 | |
| 822 | EXPECT_CALL(*device_policy, GetScatterFactorInSeconds(_)) |
| 823 | .WillRepeatedly(DoAll( |
| 824 | SetArgumentPointee<0>(scatter_factor_in_seconds), |
| 825 | Return(true))); |
| 826 | |
Gilad Arnold | b92f0df | 2013-01-10 16:32:45 -0800 | [diff] [blame] | 827 | // Trigger an interactive check so we can test that scattering is disabled. |
| 828 | attempter_.Update("", "", false, true, false); |
Jay Srinivasan | 08fce04 | 2012-06-07 16:31:01 -0700 | [diff] [blame] | 829 | EXPECT_EQ(scatter_factor_in_seconds, attempter_.scatter_factor_.InSeconds()); |
| 830 | |
| 831 | // Make sure scattering is disabled for manual (i.e. user initiated) update |
Jay Srinivasan | 21be075 | 2012-07-25 15:44:56 -0700 | [diff] [blame] | 832 | // checks and all artifacts are removed. |
Jay Srinivasan | ae4697c | 2013-03-18 17:08:08 -0700 | [diff] [blame] | 833 | EXPECT_FALSE( |
| 834 | attempter_.omaha_request_params_->wall_clock_based_wait_enabled()); |
Jay Srinivasan | 08fce04 | 2012-06-07 16:31:01 -0700 | [diff] [blame] | 835 | EXPECT_FALSE(prefs.Exists(kPrefsWallClockWaitPeriod)); |
Jay Srinivasan | ae4697c | 2013-03-18 17:08:08 -0700 | [diff] [blame] | 836 | EXPECT_EQ(0, attempter_.omaha_request_params_->waiting_period().InSeconds()); |
| 837 | EXPECT_FALSE( |
| 838 | attempter_.omaha_request_params_->update_check_count_wait_enabled()); |
Jay Srinivasan | 08fce04 | 2012-06-07 16:31:01 -0700 | [diff] [blame] | 839 | EXPECT_FALSE(prefs.Exists(kPrefsUpdateCheckCount)); |
| 840 | |
| 841 | g_idle_add(&StaticQuitMainLoop, this); |
| 842 | } |
| 843 | |
Darin Petkov | f42cc1c | 2010-09-01 09:03:02 -0700 | [diff] [blame] | 844 | } // namespace chromeos_update_engine |