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