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