Alex Deymo | aea4c1c | 2015-08-19 20:24:43 -0700 | [diff] [blame] | 1 | // |
| 2 | // Copyright (C) 2012 The Android Open Source Project |
| 3 | // |
| 4 | // Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | // you may not use this file except in compliance with the License. |
| 6 | // You may obtain a copy of the License at |
| 7 | // |
| 8 | // http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | // |
| 10 | // Unless required by applicable law or agreed to in writing, software |
| 11 | // distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | // See the License for the specific language governing permissions and |
| 14 | // limitations under the License. |
| 15 | // |
Darin Petkov | f42cc1c | 2010-09-01 09:03:02 -0700 | [diff] [blame] | 16 | |
Amin Hassani | ec7bc11 | 2020-10-29 16:47:58 -0700 | [diff] [blame] | 17 | #include "update_engine/cros/update_attempter.h" |
Alex Deymo | 2c0db7b | 2014-11-04 12:23:39 -0800 | [diff] [blame] | 18 | |
Ben Chan | 9abb763 | 2014-08-07 00:10:53 -0700 | [diff] [blame] | 19 | #include <stdint.h> |
| 20 | |
Jae Hoon Kim | 051627a | 2019-09-03 12:56:32 -0700 | [diff] [blame] | 21 | #include <limits> |
Jae Hoon Kim | 7fdfbf1 | 2020-04-10 18:15:50 -0700 | [diff] [blame] | 22 | #include <map> |
Ben Chan | 02f7c1d | 2014-10-18 15:18:02 -0700 | [diff] [blame] | 23 | #include <memory> |
Jae Hoon Kim | 7fdfbf1 | 2020-04-10 18:15:50 -0700 | [diff] [blame] | 24 | #include <string> |
Jae Hoon Kim | edb6550 | 2019-06-14 11:52:17 -0700 | [diff] [blame] | 25 | #include <unordered_set> |
Ben Chan | 02f7c1d | 2014-10-18 15:18:02 -0700 | [diff] [blame] | 26 | |
Ben Chan | 06c76a4 | 2014-09-05 08:21:06 -0700 | [diff] [blame] | 27 | #include <base/files/file_util.h> |
Miriam Polzer | aff7200 | 2020-08-27 08:20:39 +0200 | [diff] [blame] | 28 | #include <base/files/scoped_temp_dir.h> |
Qijiang Fan | b0b6cc2 | 2020-10-15 21:54:11 +0900 | [diff] [blame] | 29 | #include <base/task/single_thread_task_executor.h> |
Alex Vakulenko | 3f39d5c | 2015-10-13 09:27:13 -0700 | [diff] [blame] | 30 | #include <brillo/message_loops/base_message_loop.h> |
| 31 | #include <brillo/message_loops/message_loop.h> |
| 32 | #include <brillo/message_loops/message_loop_utils.h> |
Darin Petkov | f42cc1c | 2010-09-01 09:03:02 -0700 | [diff] [blame] | 33 | #include <gtest/gtest.h> |
Patrick Dubroy | 7fbbe8a | 2011-08-01 17:28:22 +0200 | [diff] [blame] | 34 | #include <policy/libpolicy.h> |
| 35 | #include <policy/mock_device_policy.h> |
Marton Hunyady | e58bddb | 2018-04-10 20:27:26 +0200 | [diff] [blame] | 36 | #include <policy/mock_libpolicy.h> |
Darin Petkov | f42cc1c | 2010-09-01 09:03:02 -0700 | [diff] [blame] | 37 | |
Jae Hoon Kim | 0ae8fe1 | 2019-06-26 14:32:50 -0700 | [diff] [blame] | 38 | #include "update_engine/common/constants.h" |
Xiaochu Liu | 8ba486f | 2018-11-06 11:14:10 -0800 | [diff] [blame] | 39 | #include "update_engine/common/dlcservice_interface.h" |
Alex Deymo | 39910dc | 2015-11-09 17:04:30 -0800 | [diff] [blame] | 40 | #include "update_engine/common/fake_clock.h" |
| 41 | #include "update_engine/common/fake_prefs.h" |
Alex Deymo | 14fd1ec | 2016-02-24 22:03:57 -0800 | [diff] [blame] | 42 | #include "update_engine/common/mock_action.h" |
| 43 | #include "update_engine/common/mock_action_processor.h" |
Alex Deymo | 39910dc | 2015-11-09 17:04:30 -0800 | [diff] [blame] | 44 | #include "update_engine/common/mock_http_fetcher.h" |
| 45 | #include "update_engine/common/mock_prefs.h" |
Amin Hassani | ec7bc11 | 2020-10-29 16:47:58 -0700 | [diff] [blame] | 46 | #include "update_engine/common/mock_service_observer.h" |
Alex Deymo | 39910dc | 2015-11-09 17:04:30 -0800 | [diff] [blame] | 47 | #include "update_engine/common/platform_constants.h" |
| 48 | #include "update_engine/common/prefs.h" |
| 49 | #include "update_engine/common/test_utils.h" |
| 50 | #include "update_engine/common/utils.h" |
Amin Hassani | ec7bc11 | 2020-10-29 16:47:58 -0700 | [diff] [blame] | 51 | #include "update_engine/cros/fake_system_state.h" |
| 52 | #include "update_engine/cros/mock_p2p_manager.h" |
| 53 | #include "update_engine/cros/mock_payload_state.h" |
| 54 | #include "update_engine/cros/omaha_utils.h" |
Jae Hoon Kim | 0ae8fe1 | 2019-06-26 14:32:50 -0700 | [diff] [blame] | 55 | #include "update_engine/libcurl_http_fetcher.h" |
Alex Deymo | 39910dc | 2015-11-09 17:04:30 -0800 | [diff] [blame] | 56 | #include "update_engine/payload_consumer/filesystem_verifier_action.h" |
| 57 | #include "update_engine/payload_consumer/install_plan.h" |
| 58 | #include "update_engine/payload_consumer/payload_constants.h" |
| 59 | #include "update_engine/payload_consumer/postinstall_runner_action.h" |
Amin Hassani | 0882a51 | 2018-04-05 16:25:44 -0700 | [diff] [blame] | 60 | #include "update_engine/update_boot_flags_action.h" |
Jae Hoon Kim | 504c3cb | 2019-07-02 11:17:24 -0700 | [diff] [blame] | 61 | #include "update_engine/update_manager/mock_update_manager.h" |
Darin Petkov | f42cc1c | 2010-09-01 09:03:02 -0700 | [diff] [blame] | 62 | |
David Zeuthen | 985b112 | 2013-10-09 12:13:15 -0700 | [diff] [blame] | 63 | using base::Time; |
| 64 | using base::TimeDelta; |
Aaron Wood | bf5a252 | 2017-10-04 10:58:36 -0700 | [diff] [blame] | 65 | using chromeos_update_manager::EvalStatus; |
Jae Hoon Kim | 504c3cb | 2019-07-02 11:17:24 -0700 | [diff] [blame] | 66 | using chromeos_update_manager::MockUpdateManager; |
Adolfo Victoria | 497044c | 2018-07-18 07:51:42 -0700 | [diff] [blame] | 67 | using chromeos_update_manager::StagingSchedule; |
Aaron Wood | bf5a252 | 2017-10-04 10:58:36 -0700 | [diff] [blame] | 68 | using chromeos_update_manager::UpdateCheckParams; |
Adolfo Victoria | 497044c | 2018-07-18 07:51:42 -0700 | [diff] [blame] | 69 | using policy::DevicePolicy; |
Jae Hoon Kim | 7fdfbf1 | 2020-04-10 18:15:50 -0700 | [diff] [blame] | 70 | using std::map; |
Darin Petkov | f42cc1c | 2010-09-01 09:03:02 -0700 | [diff] [blame] | 71 | using std::string; |
Ben Chan | 02f7c1d | 2014-10-18 15:18:02 -0700 | [diff] [blame] | 72 | using std::unique_ptr; |
Jae Hoon Kim | edb6550 | 2019-06-14 11:52:17 -0700 | [diff] [blame] | 73 | using std::unordered_set; |
Xiaochu Liu | 88d9038 | 2018-08-29 16:09:11 -0700 | [diff] [blame] | 74 | using std::vector; |
Aaron Wood | bf5a252 | 2017-10-04 10:58:36 -0700 | [diff] [blame] | 75 | using testing::_; |
Andrew | 065d78d | 2020-04-07 15:43:07 -0700 | [diff] [blame] | 76 | using testing::Contains; |
Darin Petkov | 3627577 | 2010-10-01 11:40:57 -0700 | [diff] [blame] | 77 | using testing::DoAll; |
Jae Hoon Kim | 7fdfbf1 | 2020-04-10 18:15:50 -0700 | [diff] [blame] | 78 | using testing::ElementsAre; |
Aaron Wood | 7f92e2b | 2017-08-28 14:51:21 -0700 | [diff] [blame] | 79 | using testing::Field; |
Darin Petkov | f42cc1c | 2010-09-01 09:03:02 -0700 | [diff] [blame] | 80 | using testing::InSequence; |
Jae Hoon Kim | edb6550 | 2019-06-14 11:52:17 -0700 | [diff] [blame] | 81 | using testing::Invoke; |
Darin Petkov | 2dd0109 | 2010-10-08 15:43:05 -0700 | [diff] [blame] | 82 | using testing::Ne; |
Darin Petkov | 9c096d6 | 2010-11-17 14:49:04 -0800 | [diff] [blame] | 83 | using testing::NiceMock; |
Amin Hassani | d3f4bea | 2018-04-30 14:52:40 -0700 | [diff] [blame] | 84 | using testing::Pointee; |
Darin Petkov | f42cc1c | 2010-09-01 09:03:02 -0700 | [diff] [blame] | 85 | using testing::Property; |
| 86 | using testing::Return; |
Gilad Arnold | 74b5f55 | 2014-10-07 08:17:16 -0700 | [diff] [blame] | 87 | using testing::ReturnPointee; |
Marton Hunyady | e58bddb | 2018-04-10 20:27:26 +0200 | [diff] [blame] | 88 | using testing::ReturnRef; |
Alex Deymo | 2c0db7b | 2014-11-04 12:23:39 -0800 | [diff] [blame] | 89 | using testing::SaveArg; |
Ben Chan | 672c1f5 | 2017-10-23 15:41:39 -0700 | [diff] [blame] | 90 | using testing::SetArgPointee; |
Aaron Wood | bf5a252 | 2017-10-04 10:58:36 -0700 | [diff] [blame] | 91 | using update_engine::UpdateAttemptFlags; |
Aaron Wood | 7f92e2b | 2017-08-28 14:51:21 -0700 | [diff] [blame] | 92 | using update_engine::UpdateEngineStatus; |
Christopher Wiley | 6b6cc1b | 2015-10-05 17:50:07 -0700 | [diff] [blame] | 93 | using update_engine::UpdateStatus; |
Darin Petkov | f42cc1c | 2010-09-01 09:03:02 -0700 | [diff] [blame] | 94 | |
| 95 | namespace chromeos_update_engine { |
| 96 | |
Xiaochu Liu | 8ba486f | 2018-11-06 11:14:10 -0800 | [diff] [blame] | 97 | namespace { |
| 98 | |
Jae Hoon Kim | c437ea5 | 2019-07-11 11:20:38 -0700 | [diff] [blame] | 99 | const UpdateStatus kNonIdleUpdateStatuses[] = { |
| 100 | UpdateStatus::CHECKING_FOR_UPDATE, |
| 101 | UpdateStatus::UPDATE_AVAILABLE, |
| 102 | UpdateStatus::DOWNLOADING, |
| 103 | UpdateStatus::VERIFYING, |
| 104 | UpdateStatus::FINALIZING, |
| 105 | UpdateStatus::UPDATED_NEED_REBOOT, |
| 106 | UpdateStatus::REPORTING_ERROR_EVENT, |
| 107 | UpdateStatus::ATTEMPTING_ROLLBACK, |
| 108 | UpdateStatus::DISABLED, |
| 109 | UpdateStatus::NEED_PERMISSION_TO_UPDATE, |
| 110 | }; |
| 111 | |
Jae Hoon Kim | 51ea9ae | 2019-07-03 16:56:30 -0700 | [diff] [blame] | 112 | struct CheckForUpdateTestParams { |
| 113 | // Setups + Inputs: |
| 114 | UpdateStatus status = UpdateStatus::IDLE; |
| 115 | string app_version = "fake_app_version"; |
| 116 | string omaha_url = "fake_omaha_url"; |
| 117 | UpdateAttemptFlags flags = UpdateAttemptFlags::kNone; |
| 118 | bool is_official_build = true; |
| 119 | bool are_dev_features_enabled = false; |
| 120 | |
| 121 | // Expects: |
| 122 | string expected_forced_app_version = ""; |
| 123 | string expected_forced_omaha_url = ""; |
Jae Hoon Kim | 2b73ac2 | 2019-07-02 11:17:24 -0700 | [diff] [blame] | 124 | bool should_schedule_updates_be_called = true; |
Jae Hoon Kim | 51ea9ae | 2019-07-03 16:56:30 -0700 | [diff] [blame] | 125 | bool expected_result = true; |
| 126 | }; |
| 127 | |
Jae Hoon Kim | 75daa38 | 2019-07-02 11:17:24 -0700 | [diff] [blame] | 128 | struct OnUpdateScheduledTestParams { |
| 129 | // Setups + Inputs: |
| 130 | UpdateCheckParams params = {}; |
| 131 | EvalStatus status = EvalStatus::kFailed; |
| 132 | // Expects: |
| 133 | UpdateStatus exit_status = UpdateStatus::IDLE; |
| 134 | bool should_schedule_updates_be_called = false; |
| 135 | bool should_update_be_called = false; |
| 136 | }; |
| 137 | |
Jae Hoon Kim | ed3fcc0 | 2019-07-11 14:35:38 -0700 | [diff] [blame] | 138 | struct ProcessingDoneTestParams { |
| 139 | // Setups + Inputs: |
| 140 | bool is_install = false; |
| 141 | UpdateStatus status = UpdateStatus::CHECKING_FOR_UPDATE; |
| 142 | ActionProcessor* processor = nullptr; |
| 143 | ErrorCode code = ErrorCode::kSuccess; |
Jae Hoon Kim | 7fdfbf1 | 2020-04-10 18:15:50 -0700 | [diff] [blame] | 144 | map<string, OmahaRequestParams::AppParams> dlc_apps_params; |
Jae Hoon Kim | ed3fcc0 | 2019-07-11 14:35:38 -0700 | [diff] [blame] | 145 | |
| 146 | // Expects: |
| 147 | const bool kExpectedIsInstall = false; |
| 148 | bool should_schedule_updates_be_called = true; |
| 149 | UpdateStatus expected_exit_status = UpdateStatus::IDLE; |
Jae Hoon Kim | 7fdfbf1 | 2020-04-10 18:15:50 -0700 | [diff] [blame] | 150 | bool should_install_completed_be_called = false; |
| 151 | bool should_update_completed_be_called = false; |
| 152 | vector<string> args_to_install_completed; |
| 153 | vector<string> args_to_update_completed; |
Jae Hoon Kim | ed3fcc0 | 2019-07-11 14:35:38 -0700 | [diff] [blame] | 154 | }; |
| 155 | |
Xiaochu Liu | 8ba486f | 2018-11-06 11:14:10 -0800 | [diff] [blame] | 156 | class MockDlcService : public DlcServiceInterface { |
| 157 | public: |
Amin Hassani | 2b68e6b | 2020-04-17 10:49:12 -0700 | [diff] [blame] | 158 | MOCK_METHOD1(GetDlcsToUpdate, bool(vector<string>*)); |
Jae Hoon Kim | 7fdfbf1 | 2020-04-10 18:15:50 -0700 | [diff] [blame] | 159 | MOCK_METHOD1(InstallCompleted, bool(const vector<string>&)); |
| 160 | MOCK_METHOD1(UpdateCompleted, bool(const vector<string>&)); |
Xiaochu Liu | 8ba486f | 2018-11-06 11:14:10 -0800 | [diff] [blame] | 161 | }; |
| 162 | |
| 163 | } // namespace |
| 164 | |
Marton Hunyady | a030268 | 2018-05-16 18:52:13 +0200 | [diff] [blame] | 165 | const char kRollbackVersion[] = "10575.39.2"; |
| 166 | |
Darin Petkov | f42cc1c | 2010-09-01 09:03:02 -0700 | [diff] [blame] | 167 | // 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] | 168 | // 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] | 169 | // methods. |
| 170 | class UpdateAttempterUnderTest : public UpdateAttempter { |
| 171 | public: |
Amin Hassani | 538bd59 | 2020-11-04 20:46:08 -0800 | [diff] [blame] | 172 | UpdateAttempterUnderTest() : UpdateAttempter(nullptr) {} |
Gilad Arnold | ec7f916 | 2014-07-15 13:24:46 -0700 | [diff] [blame] | 173 | |
Amin Hassani | e815363 | 2020-10-27 15:11:28 -0700 | [diff] [blame] | 174 | void Update(const UpdateCheckParams& params) override { |
Jae Hoon Kim | 75daa38 | 2019-07-02 11:17:24 -0700 | [diff] [blame] | 175 | update_called_ = true; |
| 176 | if (do_update_) { |
Amin Hassani | e815363 | 2020-10-27 15:11:28 -0700 | [diff] [blame] | 177 | UpdateAttempter::Update(params); |
Jae Hoon Kim | 75daa38 | 2019-07-02 11:17:24 -0700 | [diff] [blame] | 178 | return; |
| 179 | } |
| 180 | LOG(INFO) << "[TEST] Update() disabled."; |
| 181 | status_ = UpdateStatus::CHECKING_FOR_UPDATE; |
| 182 | } |
| 183 | |
| 184 | void DisableUpdate() { do_update_ = false; } |
| 185 | |
| 186 | bool WasUpdateCalled() const { return update_called_; } |
| 187 | |
Gilad Arnold | ec7f916 | 2014-07-15 13:24:46 -0700 | [diff] [blame] | 188 | // Wrap the update scheduling method, allowing us to opt out of scheduled |
| 189 | // updates for testing purposes. |
Xiaochu Liu | 88d9038 | 2018-08-29 16:09:11 -0700 | [diff] [blame] | 190 | bool ScheduleUpdates() override { |
Gilad Arnold | ec7f916 | 2014-07-15 13:24:46 -0700 | [diff] [blame] | 191 | schedule_updates_called_ = true; |
Jae Hoon Kim | 75daa38 | 2019-07-02 11:17:24 -0700 | [diff] [blame] | 192 | if (do_schedule_updates_) |
| 193 | return UpdateAttempter::ScheduleUpdates(); |
| 194 | LOG(INFO) << "[TEST] Update scheduling disabled."; |
| 195 | waiting_for_scheduled_check_ = true; |
Xiaochu Liu | 88d9038 | 2018-08-29 16:09:11 -0700 | [diff] [blame] | 196 | return true; |
Gilad Arnold | ec7f916 | 2014-07-15 13:24:46 -0700 | [diff] [blame] | 197 | } |
Jae Hoon Kim | edb6550 | 2019-06-14 11:52:17 -0700 | [diff] [blame] | 198 | |
Gilad Arnold | ec7f916 | 2014-07-15 13:24:46 -0700 | [diff] [blame] | 199 | void DisableScheduleUpdates() { do_schedule_updates_ = false; } |
| 200 | |
Jae Hoon Kim | edb6550 | 2019-06-14 11:52:17 -0700 | [diff] [blame] | 201 | // Indicates whether |ScheduleUpdates()| was called. |
Jae Hoon Kim | 75daa38 | 2019-07-02 11:17:24 -0700 | [diff] [blame] | 202 | bool WasScheduleUpdatesCalled() const { return schedule_updates_called_; } |
Gilad Arnold | ec7f916 | 2014-07-15 13:24:46 -0700 | [diff] [blame] | 203 | |
Jae Hoon Kim | 51ea9ae | 2019-07-03 16:56:30 -0700 | [diff] [blame] | 204 | // Need to expose following private members of |UpdateAttempter| for tests. |
| 205 | const string& forced_app_version() const { return forced_app_version_; } |
Alex Deymo | 60ca1a7 | 2015-06-18 18:19:15 -0700 | [diff] [blame] | 206 | const string& forced_omaha_url() const { return forced_omaha_url_; } |
David Pursell | 02c1864 | 2014-11-06 11:26:11 -0800 | [diff] [blame] | 207 | |
Jae Hoon Kim | 75daa38 | 2019-07-02 11:17:24 -0700 | [diff] [blame] | 208 | // Need to expose |waiting_for_scheduled_check_| for testing. |
| 209 | void SetWaitingForScheduledCheck(bool waiting) { |
| 210 | waiting_for_scheduled_check_ = waiting; |
| 211 | } |
| 212 | |
Gilad Arnold | ec7f916 | 2014-07-15 13:24:46 -0700 | [diff] [blame] | 213 | private: |
Jae Hoon Kim | 75daa38 | 2019-07-02 11:17:24 -0700 | [diff] [blame] | 214 | // Used for overrides of |Update()|. |
| 215 | bool update_called_ = false; |
| 216 | bool do_update_ = true; |
| 217 | |
| 218 | // Used for overrides of |ScheduleUpdates()|. |
Gilad Arnold | ec7f916 | 2014-07-15 13:24:46 -0700 | [diff] [blame] | 219 | bool schedule_updates_called_ = false; |
| 220 | bool do_schedule_updates_ = true; |
Darin Petkov | f42cc1c | 2010-09-01 09:03:02 -0700 | [diff] [blame] | 221 | }; |
| 222 | |
| 223 | class UpdateAttempterTest : public ::testing::Test { |
| 224 | protected: |
Amin Hassani | 538bd59 | 2020-11-04 20:46:08 -0800 | [diff] [blame] | 225 | void SetUp() override { |
Gilad Arnold | 1f84723 | 2014-04-07 12:07:49 -0700 | [diff] [blame] | 226 | // Override system state members. |
Amin Hassani | 538bd59 | 2020-11-04 20:46:08 -0800 | [diff] [blame] | 227 | FakeSystemState::CreateInstance(); |
| 228 | FakeSystemState::Get()->set_connection_manager(&mock_connection_manager); |
| 229 | FakeSystemState::Get()->set_update_attempter(&attempter_); |
| 230 | FakeSystemState::Get()->set_dlcservice(&mock_dlcservice_); |
| 231 | FakeSystemState::Get()->set_update_manager(&mock_update_manager_); |
Alex Deymo | 60ca1a7 | 2015-06-18 18:19:15 -0700 | [diff] [blame] | 232 | loop_.SetAsCurrent(); |
Gilad Arnold | 1f84723 | 2014-04-07 12:07:49 -0700 | [diff] [blame] | 233 | |
Amin Hassani | 538bd59 | 2020-11-04 20:46:08 -0800 | [diff] [blame] | 234 | certificate_checker_.reset(new CertificateChecker( |
| 235 | FakeSystemState::Get()->mock_prefs(), &openssl_wrapper_)); |
| 236 | certificate_checker_->Init(); |
Alex Deymo | 33e91e7 | 2015-12-01 18:26:08 -0300 | [diff] [blame] | 237 | |
Xiaochu Liu | 8ba486f | 2018-11-06 11:14:10 -0800 | [diff] [blame] | 238 | attempter_.set_forced_update_pending_callback( |
| 239 | new base::Callback<void(bool, bool)>(base::Bind([](bool, bool) {}))); |
Sen Jiang | e67bb5b | 2016-06-20 15:53:56 -0700 | [diff] [blame] | 240 | // Finish initializing the attempter. |
Gilad Arnold | 1f84723 | 2014-04-07 12:07:49 -0700 | [diff] [blame] | 241 | attempter_.Init(); |
Gilad Arnold | eff87cc | 2013-07-22 18:32:09 -0700 | [diff] [blame] | 242 | |
Darin Petkov | f42cc1c | 2010-09-01 09:03:02 -0700 | [diff] [blame] | 243 | EXPECT_EQ(0, attempter_.http_response_code_); |
Christopher Wiley | 6b6cc1b | 2015-10-05 17:50:07 -0700 | [diff] [blame] | 244 | EXPECT_EQ(UpdateStatus::IDLE, attempter_.status_); |
Darin Petkov | f42cc1c | 2010-09-01 09:03:02 -0700 | [diff] [blame] | 245 | EXPECT_EQ(0.0, attempter_.download_progress_); |
| 246 | EXPECT_EQ(0, attempter_.last_checked_time_); |
| 247 | EXPECT_EQ("0.0.0.0", attempter_.new_version_); |
Aaron Wood | 7f92e2b | 2017-08-28 14:51:21 -0700 | [diff] [blame] | 248 | EXPECT_EQ(0ULL, attempter_.new_payload_size_); |
Alex Deymo | 8427b4a | 2014-11-05 14:00:32 -0800 | [diff] [blame] | 249 | processor_ = new NiceMock<MockActionProcessor>(); |
Darin Petkov | f42cc1c | 2010-09-01 09:03:02 -0700 | [diff] [blame] | 250 | attempter_.processor_.reset(processor_); // Transfers ownership. |
Amin Hassani | 538bd59 | 2020-11-04 20:46:08 -0800 | [diff] [blame] | 251 | prefs_ = FakeSystemState::Get()->mock_prefs(); |
Gilad Arnold | 74b5f55 | 2014-10-07 08:17:16 -0700 | [diff] [blame] | 252 | |
Jae Hoon Kim | edb6550 | 2019-06-14 11:52:17 -0700 | [diff] [blame] | 253 | // Setup store/load semantics of P2P properties via the mock |PayloadState|. |
Gilad Arnold | 74b5f55 | 2014-10-07 08:17:16 -0700 | [diff] [blame] | 254 | actual_using_p2p_for_downloading_ = false; |
Amin Hassani | 538bd59 | 2020-11-04 20:46:08 -0800 | [diff] [blame] | 255 | EXPECT_CALL(*FakeSystemState::Get()->mock_payload_state(), |
Gilad Arnold | 74b5f55 | 2014-10-07 08:17:16 -0700 | [diff] [blame] | 256 | SetUsingP2PForDownloading(_)) |
| 257 | .WillRepeatedly(SaveArg<0>(&actual_using_p2p_for_downloading_)); |
Amin Hassani | 538bd59 | 2020-11-04 20:46:08 -0800 | [diff] [blame] | 258 | EXPECT_CALL(*FakeSystemState::Get()->mock_payload_state(), |
Gilad Arnold | 74b5f55 | 2014-10-07 08:17:16 -0700 | [diff] [blame] | 259 | GetUsingP2PForDownloading()) |
| 260 | .WillRepeatedly(ReturnPointee(&actual_using_p2p_for_downloading_)); |
| 261 | actual_using_p2p_for_sharing_ = false; |
Amin Hassani | 538bd59 | 2020-11-04 20:46:08 -0800 | [diff] [blame] | 262 | EXPECT_CALL(*FakeSystemState::Get()->mock_payload_state(), |
Gilad Arnold | 74b5f55 | 2014-10-07 08:17:16 -0700 | [diff] [blame] | 263 | SetUsingP2PForSharing(_)) |
| 264 | .WillRepeatedly(SaveArg<0>(&actual_using_p2p_for_sharing_)); |
Amin Hassani | 538bd59 | 2020-11-04 20:46:08 -0800 | [diff] [blame] | 265 | EXPECT_CALL(*FakeSystemState::Get()->mock_payload_state(), |
Gilad Arnold | 74b5f55 | 2014-10-07 08:17:16 -0700 | [diff] [blame] | 266 | GetUsingP2PForDownloading()) |
| 267 | .WillRepeatedly(ReturnPointee(&actual_using_p2p_for_sharing_)); |
Darin Petkov | f42cc1c | 2010-09-01 09:03:02 -0700 | [diff] [blame] | 268 | } |
| 269 | |
Alex Deymo | 60ca1a7 | 2015-06-18 18:19:15 -0700 | [diff] [blame] | 270 | public: |
| 271 | void ScheduleQuitMainLoop(); |
Patrick Dubroy | 7fbbe8a | 2011-08-01 17:28:22 +0200 | [diff] [blame] | 272 | |
Alex Deymo | 60ca1a7 | 2015-06-18 18:19:15 -0700 | [diff] [blame] | 273 | // Callbacks to run the different tests from the main loop. |
Darin Petkov | e6ef2f8 | 2011-03-07 17:31:11 -0800 | [diff] [blame] | 274 | void UpdateTestStart(); |
| 275 | void UpdateTestVerify(); |
Alex Deymo | 60ca1a7 | 2015-06-18 18:19:15 -0700 | [diff] [blame] | 276 | void RollbackTestStart(bool enterprise_rollback, bool valid_slot); |
Chris Sosa | 76a29ae | 2013-07-11 17:59:24 -0700 | [diff] [blame] | 277 | void RollbackTestVerify(); |
Thieu Le | 116fda3 | 2011-04-19 11:01:54 -0700 | [diff] [blame] | 278 | void PingOmahaTestStart(); |
Jay Srinivasan | 480ddfa | 2012-06-01 19:15:26 -0700 | [diff] [blame] | 279 | void ReadScatterFactorFromPolicyTestStart(); |
Jay Srinivasan | 480ddfa | 2012-06-01 19:15:26 -0700 | [diff] [blame] | 280 | void DecrementUpdateCheckCountTestStart(); |
Jay Srinivasan | 08fce04 | 2012-06-07 16:31:01 -0700 | [diff] [blame] | 281 | void NoScatteringDoneDuringManualUpdateTestStart(); |
David Zeuthen | 8f191b2 | 2013-08-06 12:27:50 -0700 | [diff] [blame] | 282 | void P2PNotEnabledStart(); |
David Zeuthen | 8f191b2 | 2013-08-06 12:27:50 -0700 | [diff] [blame] | 283 | void P2PEnabledStart(); |
David Zeuthen | 8f191b2 | 2013-08-06 12:27:50 -0700 | [diff] [blame] | 284 | void P2PEnabledInteractiveStart(); |
David Zeuthen | 8f191b2 | 2013-08-06 12:27:50 -0700 | [diff] [blame] | 285 | void P2PEnabledStartingFailsStart(); |
David Zeuthen | 8f191b2 | 2013-08-06 12:27:50 -0700 | [diff] [blame] | 286 | void P2PEnabledHousekeepingFailsStart(); |
Jae Hoon Kim | edb6550 | 2019-06-14 11:52:17 -0700 | [diff] [blame] | 287 | void SessionIdTestChange(); |
| 288 | void SessionIdTestEnforceEmptyStrPingOmaha(); |
| 289 | void SessionIdTestConsistencyInUpdateFlow(); |
Jae Hoon Kim | 0ae8fe1 | 2019-06-26 14:32:50 -0700 | [diff] [blame] | 290 | void SessionIdTestInDownloadAction(); |
Amr Aboelkher | 21ac996 | 2019-05-15 14:50:05 +0200 | [diff] [blame] | 291 | void UpdateToQuickFixBuildStart(bool set_token); |
Marton Hunyady | e58bddb | 2018-04-10 20:27:26 +0200 | [diff] [blame] | 292 | void ResetRollbackHappenedStart(bool is_consumer, |
| 293 | bool is_policy_available, |
| 294 | bool expected_reset); |
Adolfo Victoria | 497044c | 2018-07-18 07:51:42 -0700 | [diff] [blame] | 295 | // Staging related callbacks. |
| 296 | void SetUpStagingTest(const StagingSchedule& schedule, FakePrefs* prefs); |
| 297 | void CheckStagingOff(); |
| 298 | void StagingSetsPrefsAndTurnsOffScatteringStart(); |
| 299 | void StagingOffIfInteractiveStart(); |
| 300 | void StagingOffIfOobeStart(); |
David Zeuthen | 8f191b2 | 2013-08-06 12:27:50 -0700 | [diff] [blame] | 301 | |
Gilad Arnold | 74b5f55 | 2014-10-07 08:17:16 -0700 | [diff] [blame] | 302 | bool actual_using_p2p_for_downloading() { |
| 303 | return actual_using_p2p_for_downloading_; |
| 304 | } |
Amin Hassani | 7cc8bb0 | 2019-01-14 16:29:47 -0800 | [diff] [blame] | 305 | bool actual_using_p2p_for_sharing() { return actual_using_p2p_for_sharing_; } |
Gilad Arnold | 74b5f55 | 2014-10-07 08:17:16 -0700 | [diff] [blame] | 306 | |
Jae Hoon Kim | 51ea9ae | 2019-07-03 16:56:30 -0700 | [diff] [blame] | 307 | // |CheckForUpdate()| related member functions. |
| 308 | void TestCheckForUpdate(); |
| 309 | |
Jae Hoon Kim | 75daa38 | 2019-07-02 11:17:24 -0700 | [diff] [blame] | 310 | // |OnUpdateScheduled()| related member functions. |
| 311 | void TestOnUpdateScheduled(); |
| 312 | |
Jae Hoon Kim | ed3fcc0 | 2019-07-11 14:35:38 -0700 | [diff] [blame] | 313 | // |ProcessingDone()| related member functions. |
| 314 | void TestProcessingDone(); |
| 315 | |
Qijiang Fan | b0b6cc2 | 2020-10-15 21:54:11 +0900 | [diff] [blame] | 316 | base::SingleThreadTaskExecutor base_loop_{base::MessagePumpType::IO}; |
| 317 | brillo::BaseMessageLoop loop_{base_loop_.task_runner()}; |
Alex Deymo | 60ca1a7 | 2015-06-18 18:19:15 -0700 | [diff] [blame] | 318 | |
Amin Hassani | 538bd59 | 2020-11-04 20:46:08 -0800 | [diff] [blame] | 319 | UpdateAttempterUnderTest attempter_; |
Alex Deymo | 33e91e7 | 2015-12-01 18:26:08 -0300 | [diff] [blame] | 320 | OpenSSLWrapper openssl_wrapper_; |
Amin Hassani | 538bd59 | 2020-11-04 20:46:08 -0800 | [diff] [blame] | 321 | std::unique_ptr<CertificateChecker> certificate_checker_; |
Xiaochu Liu | 8ba486f | 2018-11-06 11:14:10 -0800 | [diff] [blame] | 322 | MockDlcService mock_dlcservice_; |
Jae Hoon Kim | 504c3cb | 2019-07-02 11:17:24 -0700 | [diff] [blame] | 323 | MockUpdateManager mock_update_manager_; |
Alex Deymo | 3053450 | 2015-07-20 15:06:33 -0700 | [diff] [blame] | 324 | |
Alex Deymo | 8427b4a | 2014-11-05 14:00:32 -0800 | [diff] [blame] | 325 | NiceMock<MockActionProcessor>* processor_; |
Amin Hassani | 538bd59 | 2020-11-04 20:46:08 -0800 | [diff] [blame] | 326 | NiceMock<MockPrefs>* prefs_; |
Jay Srinivasan | 55f50c2 | 2013-01-10 19:24:35 -0800 | [diff] [blame] | 327 | NiceMock<MockConnectionManager> mock_connection_manager; |
Gilad Arnold | eff87cc | 2013-07-22 18:32:09 -0700 | [diff] [blame] | 328 | |
Jae Hoon Kim | 51ea9ae | 2019-07-03 16:56:30 -0700 | [diff] [blame] | 329 | // |CheckForUpdate()| test params. |
| 330 | CheckForUpdateTestParams cfu_params_; |
| 331 | |
Jae Hoon Kim | 75daa38 | 2019-07-02 11:17:24 -0700 | [diff] [blame] | 332 | // |OnUpdateScheduled()| test params. |
| 333 | OnUpdateScheduledTestParams ous_params_; |
| 334 | |
Jae Hoon Kim | ed3fcc0 | 2019-07-11 14:35:38 -0700 | [diff] [blame] | 335 | // |ProcessingDone()| test params. |
| 336 | ProcessingDoneTestParams pd_params_; |
| 337 | |
Gilad Arnold | 74b5f55 | 2014-10-07 08:17:16 -0700 | [diff] [blame] | 338 | bool actual_using_p2p_for_downloading_; |
| 339 | bool actual_using_p2p_for_sharing_; |
Darin Petkov | f42cc1c | 2010-09-01 09:03:02 -0700 | [diff] [blame] | 340 | }; |
| 341 | |
Jae Hoon Kim | 51ea9ae | 2019-07-03 16:56:30 -0700 | [diff] [blame] | 342 | void UpdateAttempterTest::TestCheckForUpdate() { |
| 343 | // Setup |
| 344 | attempter_.status_ = cfu_params_.status; |
Amin Hassani | 538bd59 | 2020-11-04 20:46:08 -0800 | [diff] [blame] | 345 | FakeSystemState::Get()->fake_hardware()->SetIsOfficialBuild( |
Jae Hoon Kim | 51ea9ae | 2019-07-03 16:56:30 -0700 | [diff] [blame] | 346 | cfu_params_.is_official_build); |
Amin Hassani | 538bd59 | 2020-11-04 20:46:08 -0800 | [diff] [blame] | 347 | FakeSystemState::Get()->fake_hardware()->SetAreDevFeaturesEnabled( |
Jae Hoon Kim | 51ea9ae | 2019-07-03 16:56:30 -0700 | [diff] [blame] | 348 | cfu_params_.are_dev_features_enabled); |
| 349 | |
| 350 | // Invocation |
| 351 | EXPECT_EQ( |
| 352 | cfu_params_.expected_result, |
| 353 | attempter_.CheckForUpdate( |
| 354 | cfu_params_.app_version, cfu_params_.omaha_url, cfu_params_.flags)); |
| 355 | |
| 356 | // Verify |
| 357 | EXPECT_EQ(cfu_params_.expected_forced_app_version, |
| 358 | attempter_.forced_app_version()); |
| 359 | EXPECT_EQ(cfu_params_.expected_forced_omaha_url, |
| 360 | attempter_.forced_omaha_url()); |
Jae Hoon Kim | 2b73ac2 | 2019-07-02 11:17:24 -0700 | [diff] [blame] | 361 | EXPECT_EQ(cfu_params_.should_schedule_updates_be_called, |
| 362 | attempter_.WasScheduleUpdatesCalled()); |
Jae Hoon Kim | 51ea9ae | 2019-07-03 16:56:30 -0700 | [diff] [blame] | 363 | } |
| 364 | |
Jae Hoon Kim | ed3fcc0 | 2019-07-11 14:35:38 -0700 | [diff] [blame] | 365 | void UpdateAttempterTest::TestProcessingDone() { |
| 366 | // Setup |
| 367 | attempter_.DisableScheduleUpdates(); |
| 368 | attempter_.is_install_ = pd_params_.is_install; |
| 369 | attempter_.status_ = pd_params_.status; |
Jae Hoon Kim | 7fdfbf1 | 2020-04-10 18:15:50 -0700 | [diff] [blame] | 370 | attempter_.omaha_request_params_->set_dlc_apps_params( |
| 371 | pd_params_.dlc_apps_params); |
| 372 | |
| 373 | // Expects |
| 374 | if (pd_params_.should_install_completed_be_called) |
| 375 | EXPECT_CALL(mock_dlcservice_, |
| 376 | InstallCompleted(pd_params_.args_to_install_completed)) |
| 377 | .WillOnce(Return(true)); |
| 378 | else |
| 379 | EXPECT_CALL(mock_dlcservice_, InstallCompleted(_)).Times(0); |
| 380 | if (pd_params_.should_update_completed_be_called) |
| 381 | EXPECT_CALL(mock_dlcservice_, |
| 382 | UpdateCompleted(pd_params_.args_to_update_completed)) |
| 383 | .WillOnce(Return(true)); |
| 384 | else |
| 385 | EXPECT_CALL(mock_dlcservice_, UpdateCompleted(_)).Times(0); |
Jae Hoon Kim | ed3fcc0 | 2019-07-11 14:35:38 -0700 | [diff] [blame] | 386 | |
| 387 | // Invocation |
| 388 | attempter_.ProcessingDone(pd_params_.processor, pd_params_.code); |
| 389 | |
| 390 | // Verify |
| 391 | EXPECT_EQ(pd_params_.kExpectedIsInstall, attempter_.is_install_); |
| 392 | EXPECT_EQ(pd_params_.should_schedule_updates_be_called, |
| 393 | attempter_.WasScheduleUpdatesCalled()); |
| 394 | EXPECT_EQ(pd_params_.expected_exit_status, attempter_.status_); |
| 395 | } |
| 396 | |
Alex Deymo | 60ca1a7 | 2015-06-18 18:19:15 -0700 | [diff] [blame] | 397 | void UpdateAttempterTest::ScheduleQuitMainLoop() { |
Luis Hector Chavez | f1cf348 | 2016-07-19 14:29:19 -0700 | [diff] [blame] | 398 | loop_.PostTask( |
| 399 | FROM_HERE, |
| 400 | base::Bind([](brillo::BaseMessageLoop* loop) { loop->BreakLoop(); }, |
| 401 | base::Unretained(&loop_))); |
Alex Deymo | 60ca1a7 | 2015-06-18 18:19:15 -0700 | [diff] [blame] | 402 | } |
| 403 | |
Jae Hoon Kim | edb6550 | 2019-06-14 11:52:17 -0700 | [diff] [blame] | 404 | void UpdateAttempterTest::SessionIdTestChange() { |
| 405 | EXPECT_NE(UpdateStatus::UPDATED_NEED_REBOOT, attempter_.status()); |
| 406 | const auto old_session_id = attempter_.session_id_; |
Amin Hassani | e815363 | 2020-10-27 15:11:28 -0700 | [diff] [blame] | 407 | attempter_.Update({}); |
Jae Hoon Kim | edb6550 | 2019-06-14 11:52:17 -0700 | [diff] [blame] | 408 | EXPECT_NE(old_session_id, attempter_.session_id_); |
| 409 | ScheduleQuitMainLoop(); |
| 410 | } |
| 411 | |
| 412 | TEST_F(UpdateAttempterTest, SessionIdTestChange) { |
| 413 | loop_.PostTask(FROM_HERE, |
| 414 | base::Bind(&UpdateAttempterTest::SessionIdTestChange, |
| 415 | base::Unretained(this))); |
| 416 | loop_.Run(); |
| 417 | } |
| 418 | |
| 419 | void UpdateAttempterTest::SessionIdTestEnforceEmptyStrPingOmaha() { |
| 420 | // The |session_id_| should not be changed and should remain as an empty |
| 421 | // string when |status_| is |UPDATED_NEED_REBOOT| (only for consistency) |
| 422 | // and |PingOmaha()| is called. |
| 423 | attempter_.DisableScheduleUpdates(); |
| 424 | attempter_.status_ = UpdateStatus::UPDATED_NEED_REBOOT; |
| 425 | const auto old_session_id = attempter_.session_id_; |
| 426 | auto CheckIfEmptySessionId = [](AbstractAction* aa) { |
| 427 | if (aa->Type() == OmahaRequestAction::StaticType()) { |
| 428 | EXPECT_TRUE(static_cast<OmahaRequestAction*>(aa)->session_id_.empty()); |
| 429 | } |
| 430 | }; |
| 431 | EXPECT_CALL(*processor_, EnqueueAction(Pointee(_))) |
| 432 | .WillRepeatedly(Invoke(CheckIfEmptySessionId)); |
| 433 | EXPECT_CALL(*processor_, StartProcessing()); |
| 434 | attempter_.PingOmaha(); |
| 435 | EXPECT_EQ(old_session_id, attempter_.session_id_); |
| 436 | EXPECT_EQ(UpdateStatus::UPDATED_NEED_REBOOT, attempter_.status_); |
| 437 | ScheduleQuitMainLoop(); |
| 438 | } |
| 439 | |
| 440 | TEST_F(UpdateAttempterTest, SessionIdTestEnforceEmptyStrPingOmaha) { |
| 441 | loop_.PostTask( |
| 442 | FROM_HERE, |
| 443 | base::Bind(&UpdateAttempterTest::SessionIdTestEnforceEmptyStrPingOmaha, |
| 444 | base::Unretained(this))); |
| 445 | loop_.Run(); |
| 446 | } |
| 447 | |
| 448 | void UpdateAttempterTest::SessionIdTestConsistencyInUpdateFlow() { |
| 449 | // All session IDs passed into |OmahaRequestActions| should be enforced to |
| 450 | // have the same value in |BuildUpdateActions()|. |
| 451 | unordered_set<string> session_ids; |
| 452 | // Gather all the session IDs being passed to |OmahaRequestActions|. |
| 453 | auto CheckSessionId = [&session_ids](AbstractAction* aa) { |
| 454 | if (aa->Type() == OmahaRequestAction::StaticType()) |
| 455 | session_ids.insert(static_cast<OmahaRequestAction*>(aa)->session_id_); |
| 456 | }; |
| 457 | EXPECT_CALL(*processor_, EnqueueAction(Pointee(_))) |
| 458 | .WillRepeatedly(Invoke(CheckSessionId)); |
| 459 | attempter_.BuildUpdateActions(false); |
| 460 | // Validate that all the session IDs are the same. |
| 461 | EXPECT_EQ(1, session_ids.size()); |
| 462 | ScheduleQuitMainLoop(); |
| 463 | } |
| 464 | |
| 465 | TEST_F(UpdateAttempterTest, SessionIdTestConsistencyInUpdateFlow) { |
| 466 | loop_.PostTask( |
| 467 | FROM_HERE, |
| 468 | base::Bind(&UpdateAttempterTest::SessionIdTestConsistencyInUpdateFlow, |
| 469 | base::Unretained(this))); |
| 470 | loop_.Run(); |
| 471 | } |
| 472 | |
Jae Hoon Kim | 0ae8fe1 | 2019-06-26 14:32:50 -0700 | [diff] [blame] | 473 | void UpdateAttempterTest::SessionIdTestInDownloadAction() { |
| 474 | // The session ID passed into |DownloadAction|'s |LibcurlHttpFetcher| should |
| 475 | // be enforced to be included in the HTTP header as X-Goog-Update-SessionId. |
| 476 | string header_value; |
| 477 | auto CheckSessionIdInDownloadAction = [&header_value](AbstractAction* aa) { |
| 478 | if (aa->Type() == DownloadAction::StaticType()) { |
| 479 | DownloadAction* da = static_cast<DownloadAction*>(aa); |
| 480 | EXPECT_TRUE(da->http_fetcher()->GetHeader(kXGoogleUpdateSessionId, |
| 481 | &header_value)); |
| 482 | } |
| 483 | }; |
| 484 | EXPECT_CALL(*processor_, EnqueueAction(Pointee(_))) |
| 485 | .WillRepeatedly(Invoke(CheckSessionIdInDownloadAction)); |
| 486 | attempter_.BuildUpdateActions(false); |
| 487 | // Validate that X-Goog-Update_SessionId is set correctly in HTTP Header. |
| 488 | EXPECT_EQ(attempter_.session_id_, header_value); |
| 489 | ScheduleQuitMainLoop(); |
| 490 | } |
| 491 | |
| 492 | TEST_F(UpdateAttempterTest, SessionIdTestInDownloadAction) { |
| 493 | loop_.PostTask(FROM_HERE, |
| 494 | base::Bind(&UpdateAttempterTest::SessionIdTestInDownloadAction, |
| 495 | base::Unretained(this))); |
| 496 | loop_.Run(); |
| 497 | } |
| 498 | |
Darin Petkov | 1b00310 | 2010-11-30 10:18:36 -0800 | [diff] [blame] | 499 | TEST_F(UpdateAttempterTest, ActionCompletedDownloadTest) { |
Ben Chan | 02f7c1d | 2014-10-18 15:18:02 -0700 | [diff] [blame] | 500 | unique_ptr<MockHttpFetcher> fetcher(new MockHttpFetcher("", 0, nullptr)); |
Darin Petkov | 1b00310 | 2010-11-30 10:18:36 -0800 | [diff] [blame] | 501 | fetcher->FailTransfer(503); // Sets the HTTP response code. |
Amin Hassani | 7ecda26 | 2017-07-11 17:10:50 -0700 | [diff] [blame] | 502 | DownloadAction action(prefs_, |
| 503 | nullptr, |
| 504 | nullptr, |
Amin Hassani | 7ecda26 | 2017-07-11 17:10:50 -0700 | [diff] [blame] | 505 | fetcher.release(), |
Amin Hassani | ed37d68 | 2018-04-06 13:22:00 -0700 | [diff] [blame] | 506 | false /* interactive */); |
Jay Srinivasan | 6f6ea00 | 2012-12-14 11:26:28 -0800 | [diff] [blame] | 507 | EXPECT_CALL(*prefs_, GetInt64(kPrefsDeltaUpdateFailures, _)).Times(0); |
Alex Vakulenko | 88b591f | 2014-08-28 16:48:57 -0700 | [diff] [blame] | 508 | attempter_.ActionCompleted(nullptr, &action, ErrorCode::kSuccess); |
Christopher Wiley | 6b6cc1b | 2015-10-05 17:50:07 -0700 | [diff] [blame] | 509 | EXPECT_EQ(UpdateStatus::FINALIZING, attempter_.status()); |
Aaron Wood | 9321f50 | 2017-09-07 11:18:54 -0700 | [diff] [blame] | 510 | EXPECT_EQ(0.0, attempter_.download_progress_); |
Alex Vakulenko | 88b591f | 2014-08-28 16:48:57 -0700 | [diff] [blame] | 511 | ASSERT_EQ(nullptr, attempter_.error_event_.get()); |
Darin Petkov | 1b00310 | 2010-11-30 10:18:36 -0800 | [diff] [blame] | 512 | } |
| 513 | |
| 514 | TEST_F(UpdateAttempterTest, ActionCompletedErrorTest) { |
Alex Deymo | 8427b4a | 2014-11-05 14:00:32 -0800 | [diff] [blame] | 515 | MockAction action; |
| 516 | EXPECT_CALL(action, Type()).WillRepeatedly(Return("MockAction")); |
Christopher Wiley | 6b6cc1b | 2015-10-05 17:50:07 -0700 | [diff] [blame] | 517 | attempter_.status_ = UpdateStatus::DOWNLOADING; |
Jay Srinivasan | 6f6ea00 | 2012-12-14 11:26:28 -0800 | [diff] [blame] | 518 | EXPECT_CALL(*prefs_, GetInt64(kPrefsDeltaUpdateFailures, _)) |
Darin Petkov | 1b00310 | 2010-11-30 10:18:36 -0800 | [diff] [blame] | 519 | .WillOnce(Return(false)); |
Alex Vakulenko | 88b591f | 2014-08-28 16:48:57 -0700 | [diff] [blame] | 520 | attempter_.ActionCompleted(nullptr, &action, ErrorCode::kError); |
| 521 | ASSERT_NE(nullptr, attempter_.error_event_.get()); |
Darin Petkov | 1b00310 | 2010-11-30 10:18:36 -0800 | [diff] [blame] | 522 | } |
| 523 | |
Aaron Wood | 9321f50 | 2017-09-07 11:18:54 -0700 | [diff] [blame] | 524 | TEST_F(UpdateAttempterTest, DownloadProgressAccumulationTest) { |
| 525 | // Simple test case, where all the values match (nothing was skipped) |
| 526 | uint64_t bytes_progressed_1 = 1024 * 1024; // 1MB |
| 527 | uint64_t bytes_progressed_2 = 1024 * 1024; // 1MB |
| 528 | uint64_t bytes_received_1 = bytes_progressed_1; |
| 529 | uint64_t bytes_received_2 = bytes_received_1 + bytes_progressed_2; |
| 530 | uint64_t bytes_total = 20 * 1024 * 1024; // 20MB |
| 531 | |
| 532 | double progress_1 = |
| 533 | static_cast<double>(bytes_received_1) / static_cast<double>(bytes_total); |
| 534 | double progress_2 = |
| 535 | static_cast<double>(bytes_received_2) / static_cast<double>(bytes_total); |
| 536 | |
| 537 | EXPECT_EQ(0.0, attempter_.download_progress_); |
| 538 | // This is set via inspecting the InstallPlan payloads when the |
Jae Hoon Kim | edb6550 | 2019-06-14 11:52:17 -0700 | [diff] [blame] | 539 | // |OmahaResponseAction| is completed. |
Aaron Wood | 9321f50 | 2017-09-07 11:18:54 -0700 | [diff] [blame] | 540 | attempter_.new_payload_size_ = bytes_total; |
| 541 | NiceMock<MockServiceObserver> observer; |
| 542 | EXPECT_CALL(observer, |
Aaron Wood | 7f92e2b | 2017-08-28 14:51:21 -0700 | [diff] [blame] | 543 | SendStatusUpdate(AllOf( |
| 544 | Field(&UpdateEngineStatus::progress, progress_1), |
| 545 | Field(&UpdateEngineStatus::status, UpdateStatus::DOWNLOADING), |
| 546 | Field(&UpdateEngineStatus::new_size_bytes, bytes_total)))); |
Aaron Wood | 9321f50 | 2017-09-07 11:18:54 -0700 | [diff] [blame] | 547 | EXPECT_CALL(observer, |
Aaron Wood | 7f92e2b | 2017-08-28 14:51:21 -0700 | [diff] [blame] | 548 | SendStatusUpdate(AllOf( |
| 549 | Field(&UpdateEngineStatus::progress, progress_2), |
| 550 | Field(&UpdateEngineStatus::status, UpdateStatus::DOWNLOADING), |
| 551 | Field(&UpdateEngineStatus::new_size_bytes, bytes_total)))); |
Aaron Wood | 9321f50 | 2017-09-07 11:18:54 -0700 | [diff] [blame] | 552 | attempter_.AddObserver(&observer); |
| 553 | attempter_.BytesReceived(bytes_progressed_1, bytes_received_1, bytes_total); |
| 554 | EXPECT_EQ(progress_1, attempter_.download_progress_); |
| 555 | // This iteration validates that a later set of updates to the variables are |
| 556 | // properly handled (so that |getStatus()| will return the same progress info |
| 557 | // as the callback is receiving. |
| 558 | attempter_.BytesReceived(bytes_progressed_2, bytes_received_2, bytes_total); |
| 559 | EXPECT_EQ(progress_2, attempter_.download_progress_); |
| 560 | } |
| 561 | |
| 562 | TEST_F(UpdateAttempterTest, ChangeToDownloadingOnReceivedBytesTest) { |
Jae Hoon Kim | edb6550 | 2019-06-14 11:52:17 -0700 | [diff] [blame] | 563 | // The transition into |UpdateStatus::DOWNLOADING| happens when the |
Aaron Wood | 9321f50 | 2017-09-07 11:18:54 -0700 | [diff] [blame] | 564 | // first bytes are received. |
| 565 | uint64_t bytes_progressed = 1024 * 1024; // 1MB |
| 566 | uint64_t bytes_received = 2 * 1024 * 1024; // 2MB |
| 567 | uint64_t bytes_total = 20 * 1024 * 1024; // 300MB |
| 568 | attempter_.status_ = UpdateStatus::CHECKING_FOR_UPDATE; |
| 569 | // This is set via inspecting the InstallPlan payloads when the |
Jae Hoon Kim | edb6550 | 2019-06-14 11:52:17 -0700 | [diff] [blame] | 570 | // |OmahaResponseAction| is completed. |
Aaron Wood | 9321f50 | 2017-09-07 11:18:54 -0700 | [diff] [blame] | 571 | attempter_.new_payload_size_ = bytes_total; |
| 572 | EXPECT_EQ(0.0, attempter_.download_progress_); |
| 573 | NiceMock<MockServiceObserver> observer; |
Aaron Wood | 7f92e2b | 2017-08-28 14:51:21 -0700 | [diff] [blame] | 574 | EXPECT_CALL(observer, |
| 575 | SendStatusUpdate(AllOf( |
| 576 | Field(&UpdateEngineStatus::status, UpdateStatus::DOWNLOADING), |
| 577 | Field(&UpdateEngineStatus::new_size_bytes, bytes_total)))); |
Aaron Wood | 9321f50 | 2017-09-07 11:18:54 -0700 | [diff] [blame] | 578 | attempter_.AddObserver(&observer); |
| 579 | attempter_.BytesReceived(bytes_progressed, bytes_received, bytes_total); |
| 580 | EXPECT_EQ(UpdateStatus::DOWNLOADING, attempter_.status_); |
| 581 | } |
| 582 | |
| 583 | TEST_F(UpdateAttempterTest, BroadcastCompleteDownloadTest) { |
| 584 | // There is a special case to ensure that at 100% downloaded, |
Jae Hoon Kim | edb6550 | 2019-06-14 11:52:17 -0700 | [diff] [blame] | 585 | // |download_progress_| is updated and broadcastest. |
Aaron Wood | 9321f50 | 2017-09-07 11:18:54 -0700 | [diff] [blame] | 586 | uint64_t bytes_progressed = 0; // ignored |
| 587 | uint64_t bytes_received = 5 * 1024 * 1024; // ignored |
| 588 | uint64_t bytes_total = 5 * 1024 * 1024; // 300MB |
| 589 | attempter_.status_ = UpdateStatus::DOWNLOADING; |
| 590 | attempter_.new_payload_size_ = bytes_total; |
| 591 | EXPECT_EQ(0.0, attempter_.download_progress_); |
| 592 | NiceMock<MockServiceObserver> observer; |
Aaron Wood | 7f92e2b | 2017-08-28 14:51:21 -0700 | [diff] [blame] | 593 | EXPECT_CALL(observer, |
| 594 | SendStatusUpdate(AllOf( |
| 595 | Field(&UpdateEngineStatus::progress, 1.0), |
| 596 | Field(&UpdateEngineStatus::status, UpdateStatus::DOWNLOADING), |
| 597 | Field(&UpdateEngineStatus::new_size_bytes, bytes_total)))); |
Aaron Wood | 9321f50 | 2017-09-07 11:18:54 -0700 | [diff] [blame] | 598 | attempter_.AddObserver(&observer); |
| 599 | attempter_.BytesReceived(bytes_progressed, bytes_received, bytes_total); |
| 600 | EXPECT_EQ(1.0, attempter_.download_progress_); |
| 601 | } |
| 602 | |
Darin Petkov | 1b00310 | 2010-11-30 10:18:36 -0800 | [diff] [blame] | 603 | TEST_F(UpdateAttempterTest, ActionCompletedOmahaRequestTest) { |
Ben Chan | 02f7c1d | 2014-10-18 15:18:02 -0700 | [diff] [blame] | 604 | unique_ptr<MockHttpFetcher> fetcher(new MockHttpFetcher("", 0, nullptr)); |
Darin Petkov | 1b00310 | 2010-11-30 10:18:36 -0800 | [diff] [blame] | 605 | fetcher->FailTransfer(500); // Sets the HTTP response code. |
Amin Hassani | 538bd59 | 2020-11-04 20:46:08 -0800 | [diff] [blame] | 606 | OmahaRequestAction action(nullptr, std::move(fetcher), false, ""); |
Darin Petkov | 1b00310 | 2010-11-30 10:18:36 -0800 | [diff] [blame] | 607 | ObjectCollectorAction<OmahaResponse> collector_action; |
| 608 | BondActions(&action, &collector_action); |
| 609 | OmahaResponse response; |
| 610 | response.poll_interval = 234; |
| 611 | action.SetOutputObject(response); |
Jay Srinivasan | 6f6ea00 | 2012-12-14 11:26:28 -0800 | [diff] [blame] | 612 | EXPECT_CALL(*prefs_, GetInt64(kPrefsDeltaUpdateFailures, _)).Times(0); |
Alex Vakulenko | 88b591f | 2014-08-28 16:48:57 -0700 | [diff] [blame] | 613 | attempter_.ActionCompleted(nullptr, &action, ErrorCode::kSuccess); |
Darin Petkov | 1b00310 | 2010-11-30 10:18:36 -0800 | [diff] [blame] | 614 | EXPECT_EQ(500, attempter_.http_response_code()); |
Christopher Wiley | 6b6cc1b | 2015-10-05 17:50:07 -0700 | [diff] [blame] | 615 | EXPECT_EQ(UpdateStatus::IDLE, attempter_.status()); |
Alex Deymo | 80f70ff | 2016-02-10 16:08:11 -0800 | [diff] [blame] | 616 | EXPECT_EQ(234U, attempter_.server_dictated_poll_interval_); |
Alex Vakulenko | 88b591f | 2014-08-28 16:48:57 -0700 | [diff] [blame] | 617 | ASSERT_TRUE(attempter_.error_event_.get() == nullptr); |
Darin Petkov | 1b00310 | 2010-11-30 10:18:36 -0800 | [diff] [blame] | 618 | } |
| 619 | |
Alex Deymo | 3053450 | 2015-07-20 15:06:33 -0700 | [diff] [blame] | 620 | TEST_F(UpdateAttempterTest, ConstructWithUpdatedMarkerTest) { |
Alex Deymo | 906191f | 2015-10-12 12:22:44 -0700 | [diff] [blame] | 621 | FakePrefs fake_prefs; |
| 622 | string boot_id; |
| 623 | EXPECT_TRUE(utils::GetBootId(&boot_id)); |
| 624 | fake_prefs.SetString(kPrefsUpdateCompletedOnBootId, boot_id); |
Amin Hassani | 538bd59 | 2020-11-04 20:46:08 -0800 | [diff] [blame] | 625 | FakeSystemState::Get()->set_prefs(&fake_prefs); |
Sen Jiang | aeeb2e0 | 2016-06-09 15:00:16 -0700 | [diff] [blame] | 626 | attempter_.Init(); |
| 627 | EXPECT_EQ(UpdateStatus::UPDATED_NEED_REBOOT, attempter_.status()); |
Darin Petkov | f42cc1c | 2010-09-01 09:03:02 -0700 | [diff] [blame] | 628 | } |
| 629 | |
| 630 | TEST_F(UpdateAttempterTest, GetErrorCodeForActionTest) { |
Gilad Arnold | d1c4d2d | 2014-06-05 14:07:53 -0700 | [diff] [blame] | 631 | EXPECT_EQ(ErrorCode::kSuccess, |
Alex Vakulenko | 88b591f | 2014-08-28 16:48:57 -0700 | [diff] [blame] | 632 | GetErrorCodeForAction(nullptr, ErrorCode::kSuccess)); |
Darin Petkov | f42cc1c | 2010-09-01 09:03:02 -0700 | [diff] [blame] | 633 | |
Amin Hassani | 538bd59 | 2020-11-04 20:46:08 -0800 | [diff] [blame] | 634 | OmahaRequestAction omaha_request_action(nullptr, nullptr, false, ""); |
Gilad Arnold | d1c4d2d | 2014-06-05 14:07:53 -0700 | [diff] [blame] | 635 | EXPECT_EQ(ErrorCode::kOmahaRequestError, |
| 636 | GetErrorCodeForAction(&omaha_request_action, ErrorCode::kError)); |
Amin Hassani | 538bd59 | 2020-11-04 20:46:08 -0800 | [diff] [blame] | 637 | OmahaResponseHandlerAction omaha_response_handler_action; |
Amin Hassani | 7cc8bb0 | 2019-01-14 16:29:47 -0800 | [diff] [blame] | 638 | EXPECT_EQ( |
| 639 | ErrorCode::kOmahaResponseHandlerError, |
| 640 | GetErrorCodeForAction(&omaha_response_handler_action, ErrorCode::kError)); |
Tianjie | 24f9609 | 2020-06-30 12:26:25 -0700 | [diff] [blame] | 641 | DynamicPartitionControlStub dynamic_control_stub; |
| 642 | FilesystemVerifierAction filesystem_verifier_action(&dynamic_control_stub); |
Amin Hassani | 7cc8bb0 | 2019-01-14 16:29:47 -0800 | [diff] [blame] | 643 | EXPECT_EQ( |
| 644 | ErrorCode::kFilesystemVerifierError, |
| 645 | GetErrorCodeForAction(&filesystem_verifier_action, ErrorCode::kError)); |
Alex Deymo | b15a0b8 | 2015-11-25 20:30:40 -0300 | [diff] [blame] | 646 | PostinstallRunnerAction postinstall_runner_action( |
Amin Hassani | 538bd59 | 2020-11-04 20:46:08 -0800 | [diff] [blame] | 647 | FakeSystemState::Get()->fake_boot_control(), |
| 648 | FakeSystemState::Get()->fake_hardware()); |
Amin Hassani | 7cc8bb0 | 2019-01-14 16:29:47 -0800 | [diff] [blame] | 649 | EXPECT_EQ( |
| 650 | ErrorCode::kPostinstallRunnerError, |
| 651 | GetErrorCodeForAction(&postinstall_runner_action, ErrorCode::kError)); |
Alex Deymo | 8427b4a | 2014-11-05 14:00:32 -0800 | [diff] [blame] | 652 | MockAction action_mock; |
| 653 | EXPECT_CALL(action_mock, Type()).WillOnce(Return("MockAction")); |
Gilad Arnold | d1c4d2d | 2014-06-05 14:07:53 -0700 | [diff] [blame] | 654 | EXPECT_EQ(ErrorCode::kError, |
| 655 | GetErrorCodeForAction(&action_mock, ErrorCode::kError)); |
Darin Petkov | f42cc1c | 2010-09-01 09:03:02 -0700 | [diff] [blame] | 656 | } |
| 657 | |
Darin Petkov | 3627577 | 2010-10-01 11:40:57 -0700 | [diff] [blame] | 658 | TEST_F(UpdateAttempterTest, DisableDeltaUpdateIfNeededTest) { |
Jay Srinivasan | ae4697c | 2013-03-18 17:08:08 -0700 | [diff] [blame] | 659 | attempter_.omaha_request_params_->set_delta_okay(true); |
Jay Srinivasan | 6f6ea00 | 2012-12-14 11:26:28 -0800 | [diff] [blame] | 660 | EXPECT_CALL(*prefs_, GetInt64(kPrefsDeltaUpdateFailures, _)) |
Darin Petkov | 3627577 | 2010-10-01 11:40:57 -0700 | [diff] [blame] | 661 | .WillOnce(Return(false)); |
| 662 | attempter_.DisableDeltaUpdateIfNeeded(); |
Jay Srinivasan | ae4697c | 2013-03-18 17:08:08 -0700 | [diff] [blame] | 663 | EXPECT_TRUE(attempter_.omaha_request_params_->delta_okay()); |
Jay Srinivasan | 6f6ea00 | 2012-12-14 11:26:28 -0800 | [diff] [blame] | 664 | EXPECT_CALL(*prefs_, GetInt64(kPrefsDeltaUpdateFailures, _)) |
Amin Hassani | 7cc8bb0 | 2019-01-14 16:29:47 -0800 | [diff] [blame] | 665 | .WillOnce( |
| 666 | DoAll(SetArgPointee<1>(UpdateAttempter::kMaxDeltaUpdateFailures - 1), |
| 667 | Return(true))); |
Darin Petkov | 3627577 | 2010-10-01 11:40:57 -0700 | [diff] [blame] | 668 | attempter_.DisableDeltaUpdateIfNeeded(); |
Jay Srinivasan | ae4697c | 2013-03-18 17:08:08 -0700 | [diff] [blame] | 669 | EXPECT_TRUE(attempter_.omaha_request_params_->delta_okay()); |
Jay Srinivasan | 6f6ea00 | 2012-12-14 11:26:28 -0800 | [diff] [blame] | 670 | EXPECT_CALL(*prefs_, GetInt64(kPrefsDeltaUpdateFailures, _)) |
Amin Hassani | 7cc8bb0 | 2019-01-14 16:29:47 -0800 | [diff] [blame] | 671 | .WillOnce( |
| 672 | DoAll(SetArgPointee<1>(UpdateAttempter::kMaxDeltaUpdateFailures), |
| 673 | Return(true))); |
Darin Petkov | 3627577 | 2010-10-01 11:40:57 -0700 | [diff] [blame] | 674 | attempter_.DisableDeltaUpdateIfNeeded(); |
Jay Srinivasan | ae4697c | 2013-03-18 17:08:08 -0700 | [diff] [blame] | 675 | EXPECT_FALSE(attempter_.omaha_request_params_->delta_okay()); |
Jay Srinivasan | 6f6ea00 | 2012-12-14 11:26:28 -0800 | [diff] [blame] | 676 | EXPECT_CALL(*prefs_, GetInt64(_, _)).Times(0); |
Darin Petkov | 3627577 | 2010-10-01 11:40:57 -0700 | [diff] [blame] | 677 | attempter_.DisableDeltaUpdateIfNeeded(); |
Jay Srinivasan | ae4697c | 2013-03-18 17:08:08 -0700 | [diff] [blame] | 678 | EXPECT_FALSE(attempter_.omaha_request_params_->delta_okay()); |
Darin Petkov | 3627577 | 2010-10-01 11:40:57 -0700 | [diff] [blame] | 679 | } |
| 680 | |
| 681 | TEST_F(UpdateAttempterTest, MarkDeltaUpdateFailureTest) { |
Jay Srinivasan | 6f6ea00 | 2012-12-14 11:26:28 -0800 | [diff] [blame] | 682 | EXPECT_CALL(*prefs_, GetInt64(kPrefsDeltaUpdateFailures, _)) |
Darin Petkov | 3627577 | 2010-10-01 11:40:57 -0700 | [diff] [blame] | 683 | .WillOnce(Return(false)) |
Ben Chan | 672c1f5 | 2017-10-23 15:41:39 -0700 | [diff] [blame] | 684 | .WillOnce(DoAll(SetArgPointee<1>(-1), Return(true))) |
| 685 | .WillOnce(DoAll(SetArgPointee<1>(1), Return(true))) |
Amin Hassani | 7cc8bb0 | 2019-01-14 16:29:47 -0800 | [diff] [blame] | 686 | .WillOnce( |
| 687 | DoAll(SetArgPointee<1>(UpdateAttempter::kMaxDeltaUpdateFailures), |
| 688 | Return(true))); |
Jay Srinivasan | 6f6ea00 | 2012-12-14 11:26:28 -0800 | [diff] [blame] | 689 | EXPECT_CALL(*prefs_, SetInt64(Ne(kPrefsDeltaUpdateFailures), _)) |
Darin Petkov | 2dd0109 | 2010-10-08 15:43:05 -0700 | [diff] [blame] | 690 | .WillRepeatedly(Return(true)); |
Jay Srinivasan | 6f6ea00 | 2012-12-14 11:26:28 -0800 | [diff] [blame] | 691 | EXPECT_CALL(*prefs_, SetInt64(kPrefsDeltaUpdateFailures, 1)).Times(2); |
Gilad Arnold | 74b5f55 | 2014-10-07 08:17:16 -0700 | [diff] [blame] | 692 | EXPECT_CALL(*prefs_, SetInt64(kPrefsDeltaUpdateFailures, 2)); |
Amin Hassani | 7cc8bb0 | 2019-01-14 16:29:47 -0800 | [diff] [blame] | 693 | EXPECT_CALL(*prefs_, |
| 694 | SetInt64(kPrefsDeltaUpdateFailures, |
| 695 | UpdateAttempter::kMaxDeltaUpdateFailures + 1)); |
| 696 | for (int i = 0; i < 4; i++) |
Darin Petkov | 3627577 | 2010-10-01 11:40:57 -0700 | [diff] [blame] | 697 | attempter_.MarkDeltaUpdateFailure(); |
| 698 | } |
| 699 | |
Darin Petkov | 1b00310 | 2010-11-30 10:18:36 -0800 | [diff] [blame] | 700 | TEST_F(UpdateAttempterTest, ScheduleErrorEventActionNoEventTest) { |
| 701 | EXPECT_CALL(*processor_, EnqueueAction(_)).Times(0); |
| 702 | EXPECT_CALL(*processor_, StartProcessing()).Times(0); |
Amin Hassani | 538bd59 | 2020-11-04 20:46:08 -0800 | [diff] [blame] | 703 | EXPECT_CALL(*FakeSystemState::Get()->mock_payload_state(), UpdateFailed(_)) |
Jay Srinivasan | 6f6ea00 | 2012-12-14 11:26:28 -0800 | [diff] [blame] | 704 | .Times(0); |
| 705 | OmahaResponse response; |
Jay Srinivasan | 53173b9 | 2013-05-17 17:13:01 -0700 | [diff] [blame] | 706 | string url1 = "http://url1"; |
Sen Jiang | 0affc2c | 2017-02-10 15:55:05 -0800 | [diff] [blame] | 707 | response.packages.push_back({.payload_urls = {url1, "https://url"}}); |
Amin Hassani | 538bd59 | 2020-11-04 20:46:08 -0800 | [diff] [blame] | 708 | EXPECT_CALL(*(FakeSystemState::Get()->mock_payload_state()), GetCurrentUrl()) |
Jay Srinivasan | 53173b9 | 2013-05-17 17:13:01 -0700 | [diff] [blame] | 709 | .WillRepeatedly(Return(url1)); |
Amin Hassani | 538bd59 | 2020-11-04 20:46:08 -0800 | [diff] [blame] | 710 | FakeSystemState::Get()->mock_payload_state()->SetResponse(response); |
Darin Petkov | 1b00310 | 2010-11-30 10:18:36 -0800 | [diff] [blame] | 711 | attempter_.ScheduleErrorEventAction(); |
Amin Hassani | 538bd59 | 2020-11-04 20:46:08 -0800 | [diff] [blame] | 712 | EXPECT_EQ(url1, |
| 713 | FakeSystemState::Get()->mock_payload_state()->GetCurrentUrl()); |
Darin Petkov | 1b00310 | 2010-11-30 10:18:36 -0800 | [diff] [blame] | 714 | } |
| 715 | |
| 716 | TEST_F(UpdateAttempterTest, ScheduleErrorEventActionTest) { |
| 717 | EXPECT_CALL(*processor_, |
Amin Hassani | d3f4bea | 2018-04-30 14:52:40 -0700 | [diff] [blame] | 718 | EnqueueAction(Pointee(Property( |
| 719 | &AbstractAction::Type, OmahaRequestAction::StaticType())))); |
Gilad Arnold | 74b5f55 | 2014-10-07 08:17:16 -0700 | [diff] [blame] | 720 | EXPECT_CALL(*processor_, StartProcessing()); |
Gilad Arnold | d1c4d2d | 2014-06-05 14:07:53 -0700 | [diff] [blame] | 721 | ErrorCode err = ErrorCode::kError; |
Amin Hassani | 538bd59 | 2020-11-04 20:46:08 -0800 | [diff] [blame] | 722 | EXPECT_CALL(*FakeSystemState::Get()->mock_payload_state(), UpdateFailed(err)); |
Amin Hassani | 7cc8bb0 | 2019-01-14 16:29:47 -0800 | [diff] [blame] | 723 | attempter_.error_event_.reset(new OmahaEvent( |
| 724 | OmahaEvent::kTypeUpdateComplete, OmahaEvent::kResultError, err)); |
Darin Petkov | 1b00310 | 2010-11-30 10:18:36 -0800 | [diff] [blame] | 725 | attempter_.ScheduleErrorEventAction(); |
Christopher Wiley | 6b6cc1b | 2015-10-05 17:50:07 -0700 | [diff] [blame] | 726 | EXPECT_EQ(UpdateStatus::REPORTING_ERROR_EVENT, attempter_.status()); |
Darin Petkov | 1b00310 | 2010-11-30 10:18:36 -0800 | [diff] [blame] | 727 | } |
| 728 | |
Darin Petkov | e6ef2f8 | 2011-03-07 17:31:11 -0800 | [diff] [blame] | 729 | namespace { |
Chris Sosa | 76a29ae | 2013-07-11 17:59:24 -0700 | [diff] [blame] | 730 | // Actions that will be built as part of an update check. |
Askar Aitzhan | 570ca87 | 2019-04-24 11:16:12 +0200 | [diff] [blame] | 731 | vector<string> GetUpdateActionTypes() { |
| 732 | return {OmahaRequestAction::StaticType(), |
| 733 | OmahaResponseHandlerAction::StaticType(), |
| 734 | UpdateBootFlagsAction::StaticType(), |
| 735 | OmahaRequestAction::StaticType(), |
| 736 | DownloadAction::StaticType(), |
| 737 | OmahaRequestAction::StaticType(), |
| 738 | FilesystemVerifierAction::StaticType(), |
| 739 | PostinstallRunnerAction::StaticType(), |
| 740 | OmahaRequestAction::StaticType()}; |
| 741 | } |
Chris Sosa | 76a29ae | 2013-07-11 17:59:24 -0700 | [diff] [blame] | 742 | |
| 743 | // Actions that will be built as part of a user-initiated rollback. |
Askar Aitzhan | 570ca87 | 2019-04-24 11:16:12 +0200 | [diff] [blame] | 744 | vector<string> GetRollbackActionTypes() { |
| 745 | return {InstallPlanAction::StaticType(), |
| 746 | PostinstallRunnerAction::StaticType()}; |
| 747 | } |
Chris Sosa | 76a29ae | 2013-07-11 17:59:24 -0700 | [diff] [blame] | 748 | |
Adolfo Victoria | 497044c | 2018-07-18 07:51:42 -0700 | [diff] [blame] | 749 | const StagingSchedule kValidStagingSchedule = { |
| 750 | {4, 10}, {10, 40}, {19, 70}, {26, 100}}; |
| 751 | |
Alex Vakulenko | d2779df | 2014-06-16 13:19:00 -0700 | [diff] [blame] | 752 | } // namespace |
Darin Petkov | e6ef2f8 | 2011-03-07 17:31:11 -0800 | [diff] [blame] | 753 | |
| 754 | void UpdateAttempterTest::UpdateTestStart() { |
Darin Petkov | f42cc1c | 2010-09-01 09:03:02 -0700 | [diff] [blame] | 755 | attempter_.set_http_response_code(200); |
Alex Deymo | 749ecf1 | 2014-10-21 20:06:57 -0700 | [diff] [blame] | 756 | |
Jae Hoon Kim | edb6550 | 2019-06-14 11:52:17 -0700 | [diff] [blame] | 757 | // Expect that the device policy is loaded by the |UpdateAttempter| at some |
| 758 | // point by calling |RefreshDevicePolicy()|. |
Igor | 9fd76b6 | 2017-12-11 15:24:18 +0100 | [diff] [blame] | 759 | auto device_policy = std::make_unique<policy::MockDevicePolicy>(); |
Alex Deymo | 749ecf1 | 2014-10-21 20:06:57 -0700 | [diff] [blame] | 760 | EXPECT_CALL(*device_policy, LoadPolicy()) |
Amin Hassani | 7cc8bb0 | 2019-01-14 16:29:47 -0800 | [diff] [blame] | 761 | .Times(testing::AtLeast(1)) |
| 762 | .WillRepeatedly(Return(true)); |
Igor | 9fd76b6 | 2017-12-11 15:24:18 +0100 | [diff] [blame] | 763 | attempter_.policy_provider_.reset( |
| 764 | new policy::PolicyProvider(std::move(device_policy))); |
Alex Deymo | 749ecf1 | 2014-10-21 20:06:57 -0700 | [diff] [blame] | 765 | |
| 766 | { |
| 767 | InSequence s; |
Askar Aitzhan | 570ca87 | 2019-04-24 11:16:12 +0200 | [diff] [blame] | 768 | for (const auto& update_action_type : GetUpdateActionTypes()) { |
Alex Deymo | 749ecf1 | 2014-10-21 20:06:57 -0700 | [diff] [blame] | 769 | EXPECT_CALL(*processor_, |
Amin Hassani | d3f4bea | 2018-04-30 14:52:40 -0700 | [diff] [blame] | 770 | EnqueueAction(Pointee( |
Askar Aitzhan | 570ca87 | 2019-04-24 11:16:12 +0200 | [diff] [blame] | 771 | Property(&AbstractAction::Type, update_action_type)))); |
Alex Deymo | 749ecf1 | 2014-10-21 20:06:57 -0700 | [diff] [blame] | 772 | } |
Gilad Arnold | 74b5f55 | 2014-10-07 08:17:16 -0700 | [diff] [blame] | 773 | EXPECT_CALL(*processor_, StartProcessing()); |
Darin Petkov | f42cc1c | 2010-09-01 09:03:02 -0700 | [diff] [blame] | 774 | } |
Darin Petkov | f42cc1c | 2010-09-01 09:03:02 -0700 | [diff] [blame] | 775 | |
Amin Hassani | e815363 | 2020-10-27 15:11:28 -0700 | [diff] [blame] | 776 | attempter_.Update({}); |
Alex Deymo | 60ca1a7 | 2015-06-18 18:19:15 -0700 | [diff] [blame] | 777 | loop_.PostTask(FROM_HERE, |
| 778 | base::Bind(&UpdateAttempterTest::UpdateTestVerify, |
| 779 | base::Unretained(this))); |
Darin Petkov | e6ef2f8 | 2011-03-07 17:31:11 -0800 | [diff] [blame] | 780 | } |
Darin Petkov | f42cc1c | 2010-09-01 09:03:02 -0700 | [diff] [blame] | 781 | |
Darin Petkov | e6ef2f8 | 2011-03-07 17:31:11 -0800 | [diff] [blame] | 782 | void UpdateAttempterTest::UpdateTestVerify() { |
Darin Petkov | f42cc1c | 2010-09-01 09:03:02 -0700 | [diff] [blame] | 783 | EXPECT_EQ(0, attempter_.http_response_code()); |
| 784 | EXPECT_EQ(&attempter_, processor_->delegate()); |
Christopher Wiley | 6b6cc1b | 2015-10-05 17:50:07 -0700 | [diff] [blame] | 785 | EXPECT_EQ(UpdateStatus::CHECKING_FOR_UPDATE, attempter_.status()); |
Alex Deymo | 60ca1a7 | 2015-06-18 18:19:15 -0700 | [diff] [blame] | 786 | loop_.BreakLoop(); |
Darin Petkov | e6ef2f8 | 2011-03-07 17:31:11 -0800 | [diff] [blame] | 787 | } |
| 788 | |
Amin Hassani | 7cc8bb0 | 2019-01-14 16:29:47 -0800 | [diff] [blame] | 789 | void UpdateAttempterTest::RollbackTestStart(bool enterprise_rollback, |
| 790 | bool valid_slot) { |
Chris Sosa | 76a29ae | 2013-07-11 17:59:24 -0700 | [diff] [blame] | 791 | // Create a device policy so that we can change settings. |
Igor | 9fd76b6 | 2017-12-11 15:24:18 +0100 | [diff] [blame] | 792 | auto device_policy = std::make_unique<policy::MockDevicePolicy>(); |
Chris Sosa | 76a29ae | 2013-07-11 17:59:24 -0700 | [diff] [blame] | 793 | EXPECT_CALL(*device_policy, LoadPolicy()).WillRepeatedly(Return(true)); |
Amin Hassani | 538bd59 | 2020-11-04 20:46:08 -0800 | [diff] [blame] | 794 | FakeSystemState::Get()->set_device_policy(device_policy.get()); |
Igor | 9fd76b6 | 2017-12-11 15:24:18 +0100 | [diff] [blame] | 795 | if (enterprise_rollback) { |
| 796 | // We return an empty owner as this is an enterprise. |
Amin Hassani | 7cc8bb0 | 2019-01-14 16:29:47 -0800 | [diff] [blame] | 797 | EXPECT_CALL(*device_policy, GetOwner(_)) |
| 798 | .WillRepeatedly(DoAll(SetArgPointee<0>(string("")), Return(true))); |
Igor | 9fd76b6 | 2017-12-11 15:24:18 +0100 | [diff] [blame] | 799 | } else { |
| 800 | // We return a fake owner as this is an owned consumer device. |
Amin Hassani | 7cc8bb0 | 2019-01-14 16:29:47 -0800 | [diff] [blame] | 801 | EXPECT_CALL(*device_policy, GetOwner(_)) |
| 802 | .WillRepeatedly(DoAll(SetArgPointee<0>(string("fake.mail@fake.com")), |
| 803 | Return(true))); |
Igor | 9fd76b6 | 2017-12-11 15:24:18 +0100 | [diff] [blame] | 804 | } |
| 805 | |
| 806 | attempter_.policy_provider_.reset( |
| 807 | new policy::PolicyProvider(std::move(device_policy))); |
Chris Sosa | 76a29ae | 2013-07-11 17:59:24 -0700 | [diff] [blame] | 808 | |
Alex Deymo | 763e7db | 2015-08-27 21:08:08 -0700 | [diff] [blame] | 809 | if (valid_slot) { |
| 810 | BootControlInterface::Slot rollback_slot = 1; |
| 811 | LOG(INFO) << "Test Mark Bootable: " |
| 812 | << BootControlInterface::SlotName(rollback_slot); |
Amin Hassani | 538bd59 | 2020-11-04 20:46:08 -0800 | [diff] [blame] | 813 | FakeSystemState::Get()->fake_boot_control()->SetSlotBootable(rollback_slot, |
| 814 | true); |
Don Garrett | 6646b44 | 2013-11-13 15:29:11 -0800 | [diff] [blame] | 815 | } |
| 816 | |
Chris Sosa | 28e479c | 2013-07-12 11:39:53 -0700 | [diff] [blame] | 817 | bool is_rollback_allowed = false; |
Chris Sosa | 76a29ae | 2013-07-11 17:59:24 -0700 | [diff] [blame] | 818 | |
Chris Sosa | d38b113 | 2014-03-25 10:43:59 -0700 | [diff] [blame] | 819 | // We only allow rollback on devices that are not enterprise enrolled and |
| 820 | // which have a valid slot to rollback to. |
| 821 | if (!enterprise_rollback && valid_slot) { |
Amin Hassani | 7cc8bb0 | 2019-01-14 16:29:47 -0800 | [diff] [blame] | 822 | is_rollback_allowed = true; |
Chris Sosa | 28e479c | 2013-07-12 11:39:53 -0700 | [diff] [blame] | 823 | } |
| 824 | |
Chris Sosa | 28e479c | 2013-07-12 11:39:53 -0700 | [diff] [blame] | 825 | if (is_rollback_allowed) { |
Chris Sosa | 76a29ae | 2013-07-11 17:59:24 -0700 | [diff] [blame] | 826 | InSequence s; |
Askar Aitzhan | 570ca87 | 2019-04-24 11:16:12 +0200 | [diff] [blame] | 827 | for (const auto& rollback_action_type : GetRollbackActionTypes()) { |
Chris Sosa | 76a29ae | 2013-07-11 17:59:24 -0700 | [diff] [blame] | 828 | EXPECT_CALL(*processor_, |
Askar Aitzhan | 570ca87 | 2019-04-24 11:16:12 +0200 | [diff] [blame] | 829 | EnqueueAction(Pointee( |
| 830 | Property(&AbstractAction::Type, rollback_action_type)))); |
Chris Sosa | 76a29ae | 2013-07-11 17:59:24 -0700 | [diff] [blame] | 831 | } |
Gilad Arnold | 74b5f55 | 2014-10-07 08:17:16 -0700 | [diff] [blame] | 832 | EXPECT_CALL(*processor_, StartProcessing()); |
Chris Sosa | 76a29ae | 2013-07-11 17:59:24 -0700 | [diff] [blame] | 833 | |
Chris Sosa | 44b9b7e | 2014-04-02 13:53:46 -0700 | [diff] [blame] | 834 | EXPECT_TRUE(attempter_.Rollback(true)); |
Alex Deymo | 60ca1a7 | 2015-06-18 18:19:15 -0700 | [diff] [blame] | 835 | loop_.PostTask(FROM_HERE, |
| 836 | base::Bind(&UpdateAttempterTest::RollbackTestVerify, |
| 837 | base::Unretained(this))); |
Chris Sosa | 76a29ae | 2013-07-11 17:59:24 -0700 | [diff] [blame] | 838 | } else { |
Chris Sosa | 44b9b7e | 2014-04-02 13:53:46 -0700 | [diff] [blame] | 839 | EXPECT_FALSE(attempter_.Rollback(true)); |
Alex Deymo | 60ca1a7 | 2015-06-18 18:19:15 -0700 | [diff] [blame] | 840 | loop_.BreakLoop(); |
Chris Sosa | 76a29ae | 2013-07-11 17:59:24 -0700 | [diff] [blame] | 841 | } |
| 842 | } |
| 843 | |
| 844 | void UpdateAttempterTest::RollbackTestVerify() { |
| 845 | // Verifies the actions that were enqueued. |
| 846 | EXPECT_EQ(&attempter_, processor_->delegate()); |
Christopher Wiley | 6b6cc1b | 2015-10-05 17:50:07 -0700 | [diff] [blame] | 847 | EXPECT_EQ(UpdateStatus::ATTEMPTING_ROLLBACK, attempter_.status()); |
Amin Hassani | d3f4bea | 2018-04-30 14:52:40 -0700 | [diff] [blame] | 848 | EXPECT_EQ(0U, attempter_.install_plan_->partitions.size()); |
| 849 | EXPECT_EQ(attempter_.install_plan_->powerwash_required, true); |
Alex Deymo | 60ca1a7 | 2015-06-18 18:19:15 -0700 | [diff] [blame] | 850 | loop_.BreakLoop(); |
Chris Sosa | 76a29ae | 2013-07-11 17:59:24 -0700 | [diff] [blame] | 851 | } |
| 852 | |
Darin Petkov | e6ef2f8 | 2011-03-07 17:31:11 -0800 | [diff] [blame] | 853 | TEST_F(UpdateAttempterTest, UpdateTest) { |
Alex Deymo | 461b259 | 2015-07-24 20:10:52 -0700 | [diff] [blame] | 854 | UpdateTestStart(); |
Alex Deymo | 60ca1a7 | 2015-06-18 18:19:15 -0700 | [diff] [blame] | 855 | loop_.Run(); |
Darin Petkov | f42cc1c | 2010-09-01 09:03:02 -0700 | [diff] [blame] | 856 | } |
| 857 | |
Chris Sosa | 76a29ae | 2013-07-11 17:59:24 -0700 | [diff] [blame] | 858 | TEST_F(UpdateAttempterTest, RollbackTest) { |
Alex Deymo | 60ca1a7 | 2015-06-18 18:19:15 -0700 | [diff] [blame] | 859 | loop_.PostTask(FROM_HERE, |
| 860 | base::Bind(&UpdateAttempterTest::RollbackTestStart, |
| 861 | base::Unretained(this), |
Amin Hassani | 7cc8bb0 | 2019-01-14 16:29:47 -0800 | [diff] [blame] | 862 | false, |
| 863 | true)); |
Alex Deymo | 60ca1a7 | 2015-06-18 18:19:15 -0700 | [diff] [blame] | 864 | loop_.Run(); |
Chris Sosa | 76a29ae | 2013-07-11 17:59:24 -0700 | [diff] [blame] | 865 | } |
| 866 | |
Don Garrett | 6646b44 | 2013-11-13 15:29:11 -0800 | [diff] [blame] | 867 | TEST_F(UpdateAttempterTest, InvalidSlotRollbackTest) { |
Alex Deymo | 60ca1a7 | 2015-06-18 18:19:15 -0700 | [diff] [blame] | 868 | loop_.PostTask(FROM_HERE, |
| 869 | base::Bind(&UpdateAttempterTest::RollbackTestStart, |
| 870 | base::Unretained(this), |
Amin Hassani | 7cc8bb0 | 2019-01-14 16:29:47 -0800 | [diff] [blame] | 871 | false, |
| 872 | false)); |
Alex Deymo | 60ca1a7 | 2015-06-18 18:19:15 -0700 | [diff] [blame] | 873 | loop_.Run(); |
Don Garrett | 6646b44 | 2013-11-13 15:29:11 -0800 | [diff] [blame] | 874 | } |
| 875 | |
Chris Sosa | 76a29ae | 2013-07-11 17:59:24 -0700 | [diff] [blame] | 876 | TEST_F(UpdateAttempterTest, EnterpriseRollbackTest) { |
Alex Deymo | 60ca1a7 | 2015-06-18 18:19:15 -0700 | [diff] [blame] | 877 | loop_.PostTask(FROM_HERE, |
| 878 | base::Bind(&UpdateAttempterTest::RollbackTestStart, |
| 879 | base::Unretained(this), |
Amin Hassani | 7cc8bb0 | 2019-01-14 16:29:47 -0800 | [diff] [blame] | 880 | true, |
| 881 | true)); |
Alex Deymo | 60ca1a7 | 2015-06-18 18:19:15 -0700 | [diff] [blame] | 882 | loop_.Run(); |
Chris Sosa | 76a29ae | 2013-07-11 17:59:24 -0700 | [diff] [blame] | 883 | } |
| 884 | |
Thieu Le | 116fda3 | 2011-04-19 11:01:54 -0700 | [diff] [blame] | 885 | void UpdateAttempterTest::PingOmahaTestStart() { |
| 886 | EXPECT_CALL(*processor_, |
Amin Hassani | d3f4bea | 2018-04-30 14:52:40 -0700 | [diff] [blame] | 887 | EnqueueAction(Pointee(Property( |
| 888 | &AbstractAction::Type, OmahaRequestAction::StaticType())))); |
Gilad Arnold | 74b5f55 | 2014-10-07 08:17:16 -0700 | [diff] [blame] | 889 | EXPECT_CALL(*processor_, StartProcessing()); |
Thieu Le | 116fda3 | 2011-04-19 11:01:54 -0700 | [diff] [blame] | 890 | attempter_.PingOmaha(); |
Alex Deymo | 60ca1a7 | 2015-06-18 18:19:15 -0700 | [diff] [blame] | 891 | ScheduleQuitMainLoop(); |
Thieu Le | 116fda3 | 2011-04-19 11:01:54 -0700 | [diff] [blame] | 892 | } |
| 893 | |
| 894 | TEST_F(UpdateAttempterTest, PingOmahaTest) { |
Gilad Arnold | ec7f916 | 2014-07-15 13:24:46 -0700 | [diff] [blame] | 895 | EXPECT_FALSE(attempter_.waiting_for_scheduled_check_); |
Jae Hoon Kim | 75daa38 | 2019-07-02 11:17:24 -0700 | [diff] [blame] | 896 | EXPECT_FALSE(attempter_.WasScheduleUpdatesCalled()); |
Jae Hoon Kim | edb6550 | 2019-06-14 11:52:17 -0700 | [diff] [blame] | 897 | // Disable scheduling of subsequnet checks; we're using the |DefaultPolicy| in |
Gilad Arnold | ec7f916 | 2014-07-15 13:24:46 -0700 | [diff] [blame] | 898 | // testing, which is more permissive than we want to handle here. |
| 899 | attempter_.DisableScheduleUpdates(); |
Alex Deymo | 60ca1a7 | 2015-06-18 18:19:15 -0700 | [diff] [blame] | 900 | loop_.PostTask(FROM_HERE, |
| 901 | base::Bind(&UpdateAttempterTest::PingOmahaTestStart, |
| 902 | base::Unretained(this))); |
Alex Vakulenko | 3f39d5c | 2015-10-13 09:27:13 -0700 | [diff] [blame] | 903 | brillo::MessageLoopRunMaxIterations(&loop_, 100); |
Christopher Wiley | 6b6cc1b | 2015-10-05 17:50:07 -0700 | [diff] [blame] | 904 | EXPECT_EQ(UpdateStatus::UPDATED_NEED_REBOOT, attempter_.status()); |
Jae Hoon Kim | 75daa38 | 2019-07-02 11:17:24 -0700 | [diff] [blame] | 905 | EXPECT_TRUE(attempter_.WasScheduleUpdatesCalled()); |
Thieu Le | 116fda3 | 2011-04-19 11:01:54 -0700 | [diff] [blame] | 906 | } |
| 907 | |
Darin Petkov | 18c7bce | 2011-06-16 14:07:00 -0700 | [diff] [blame] | 908 | TEST_F(UpdateAttempterTest, CreatePendingErrorEventTest) { |
Alex Deymo | 8427b4a | 2014-11-05 14:00:32 -0800 | [diff] [blame] | 909 | MockAction action; |
Gilad Arnold | d1c4d2d | 2014-06-05 14:07:53 -0700 | [diff] [blame] | 910 | const ErrorCode kCode = ErrorCode::kDownloadTransferError; |
Darin Petkov | 18c7bce | 2011-06-16 14:07:00 -0700 | [diff] [blame] | 911 | attempter_.CreatePendingErrorEvent(&action, kCode); |
Alex Vakulenko | 88b591f | 2014-08-28 16:48:57 -0700 | [diff] [blame] | 912 | ASSERT_NE(nullptr, attempter_.error_event_.get()); |
Darin Petkov | 18c7bce | 2011-06-16 14:07:00 -0700 | [diff] [blame] | 913 | EXPECT_EQ(OmahaEvent::kTypeUpdateComplete, attempter_.error_event_->type); |
| 914 | EXPECT_EQ(OmahaEvent::kResultError, attempter_.error_event_->result); |
Gilad Arnold | d1c4d2d | 2014-06-05 14:07:53 -0700 | [diff] [blame] | 915 | EXPECT_EQ( |
| 916 | static_cast<ErrorCode>(static_cast<int>(kCode) | |
| 917 | static_cast<int>(ErrorCode::kTestOmahaUrlFlag)), |
| 918 | attempter_.error_event_->error_code); |
Darin Petkov | 18c7bce | 2011-06-16 14:07:00 -0700 | [diff] [blame] | 919 | } |
| 920 | |
| 921 | TEST_F(UpdateAttempterTest, CreatePendingErrorEventResumedTest) { |
Amin Hassani | d3f4bea | 2018-04-30 14:52:40 -0700 | [diff] [blame] | 922 | attempter_.install_plan_.reset(new InstallPlan); |
| 923 | attempter_.install_plan_->is_resume = true; |
Alex Deymo | 8427b4a | 2014-11-05 14:00:32 -0800 | [diff] [blame] | 924 | MockAction action; |
Gilad Arnold | d1c4d2d | 2014-06-05 14:07:53 -0700 | [diff] [blame] | 925 | const ErrorCode kCode = ErrorCode::kInstallDeviceOpenError; |
Darin Petkov | 18c7bce | 2011-06-16 14:07:00 -0700 | [diff] [blame] | 926 | attempter_.CreatePendingErrorEvent(&action, kCode); |
Alex Vakulenko | 88b591f | 2014-08-28 16:48:57 -0700 | [diff] [blame] | 927 | ASSERT_NE(nullptr, attempter_.error_event_.get()); |
Darin Petkov | 18c7bce | 2011-06-16 14:07:00 -0700 | [diff] [blame] | 928 | EXPECT_EQ(OmahaEvent::kTypeUpdateComplete, attempter_.error_event_->type); |
| 929 | EXPECT_EQ(OmahaEvent::kResultError, attempter_.error_event_->result); |
Gilad Arnold | d1c4d2d | 2014-06-05 14:07:53 -0700 | [diff] [blame] | 930 | EXPECT_EQ( |
Amin Hassani | 7cc8bb0 | 2019-01-14 16:29:47 -0800 | [diff] [blame] | 931 | static_cast<ErrorCode>(static_cast<int>(kCode) | |
| 932 | static_cast<int>(ErrorCode::kResumedFlag) | |
| 933 | static_cast<int>(ErrorCode::kTestOmahaUrlFlag)), |
Gilad Arnold | d1c4d2d | 2014-06-05 14:07:53 -0700 | [diff] [blame] | 934 | attempter_.error_event_->error_code); |
Darin Petkov | 18c7bce | 2011-06-16 14:07:00 -0700 | [diff] [blame] | 935 | } |
| 936 | |
David Zeuthen | 8f191b2 | 2013-08-06 12:27:50 -0700 | [diff] [blame] | 937 | TEST_F(UpdateAttempterTest, P2PNotStartedAtStartupWhenNotEnabled) { |
| 938 | MockP2PManager mock_p2p_manager; |
Amin Hassani | 538bd59 | 2020-11-04 20:46:08 -0800 | [diff] [blame] | 939 | FakeSystemState::Get()->set_p2p_manager(&mock_p2p_manager); |
David Zeuthen | 8f191b2 | 2013-08-06 12:27:50 -0700 | [diff] [blame] | 940 | mock_p2p_manager.fake().SetP2PEnabled(false); |
| 941 | EXPECT_CALL(mock_p2p_manager, EnsureP2PRunning()).Times(0); |
| 942 | attempter_.UpdateEngineStarted(); |
| 943 | } |
| 944 | |
| 945 | TEST_F(UpdateAttempterTest, P2PNotStartedAtStartupWhenEnabledButNotSharing) { |
| 946 | MockP2PManager mock_p2p_manager; |
Amin Hassani | 538bd59 | 2020-11-04 20:46:08 -0800 | [diff] [blame] | 947 | FakeSystemState::Get()->set_p2p_manager(&mock_p2p_manager); |
David Zeuthen | 8f191b2 | 2013-08-06 12:27:50 -0700 | [diff] [blame] | 948 | mock_p2p_manager.fake().SetP2PEnabled(true); |
| 949 | EXPECT_CALL(mock_p2p_manager, EnsureP2PRunning()).Times(0); |
| 950 | attempter_.UpdateEngineStarted(); |
| 951 | } |
| 952 | |
| 953 | TEST_F(UpdateAttempterTest, P2PStartedAtStartupWhenEnabledAndSharing) { |
| 954 | MockP2PManager mock_p2p_manager; |
Amin Hassani | 538bd59 | 2020-11-04 20:46:08 -0800 | [diff] [blame] | 955 | FakeSystemState::Get()->set_p2p_manager(&mock_p2p_manager); |
David Zeuthen | 8f191b2 | 2013-08-06 12:27:50 -0700 | [diff] [blame] | 956 | mock_p2p_manager.fake().SetP2PEnabled(true); |
| 957 | mock_p2p_manager.fake().SetCountSharedFilesResult(1); |
Gilad Arnold | 74b5f55 | 2014-10-07 08:17:16 -0700 | [diff] [blame] | 958 | EXPECT_CALL(mock_p2p_manager, EnsureP2PRunning()); |
David Zeuthen | 8f191b2 | 2013-08-06 12:27:50 -0700 | [diff] [blame] | 959 | attempter_.UpdateEngineStarted(); |
| 960 | } |
| 961 | |
| 962 | TEST_F(UpdateAttempterTest, P2PNotEnabled) { |
Alex Deymo | 60ca1a7 | 2015-06-18 18:19:15 -0700 | [diff] [blame] | 963 | loop_.PostTask(FROM_HERE, |
| 964 | base::Bind(&UpdateAttempterTest::P2PNotEnabledStart, |
| 965 | base::Unretained(this))); |
| 966 | loop_.Run(); |
David Zeuthen | 8f191b2 | 2013-08-06 12:27:50 -0700 | [diff] [blame] | 967 | } |
Alex Deymo | 60ca1a7 | 2015-06-18 18:19:15 -0700 | [diff] [blame] | 968 | |
David Zeuthen | 8f191b2 | 2013-08-06 12:27:50 -0700 | [diff] [blame] | 969 | void UpdateAttempterTest::P2PNotEnabledStart() { |
| 970 | // If P2P is not enabled, check that we do not attempt housekeeping |
Jae Hoon Kim | edb6550 | 2019-06-14 11:52:17 -0700 | [diff] [blame] | 971 | // and do not convey that P2P is to be used. |
David Zeuthen | 8f191b2 | 2013-08-06 12:27:50 -0700 | [diff] [blame] | 972 | MockP2PManager mock_p2p_manager; |
Amin Hassani | 538bd59 | 2020-11-04 20:46:08 -0800 | [diff] [blame] | 973 | FakeSystemState::Get()->set_p2p_manager(&mock_p2p_manager); |
David Zeuthen | 8f191b2 | 2013-08-06 12:27:50 -0700 | [diff] [blame] | 974 | mock_p2p_manager.fake().SetP2PEnabled(false); |
| 975 | EXPECT_CALL(mock_p2p_manager, PerformHousekeeping()).Times(0); |
Amin Hassani | e815363 | 2020-10-27 15:11:28 -0700 | [diff] [blame] | 976 | attempter_.Update({}); |
Alex Deymo | 60ca1a7 | 2015-06-18 18:19:15 -0700 | [diff] [blame] | 977 | EXPECT_FALSE(actual_using_p2p_for_downloading_); |
Gilad Arnold | 74b5f55 | 2014-10-07 08:17:16 -0700 | [diff] [blame] | 978 | EXPECT_FALSE(actual_using_p2p_for_sharing()); |
Alex Deymo | 60ca1a7 | 2015-06-18 18:19:15 -0700 | [diff] [blame] | 979 | ScheduleQuitMainLoop(); |
David Zeuthen | 8f191b2 | 2013-08-06 12:27:50 -0700 | [diff] [blame] | 980 | } |
| 981 | |
| 982 | TEST_F(UpdateAttempterTest, P2PEnabledStartingFails) { |
Alex Deymo | 60ca1a7 | 2015-06-18 18:19:15 -0700 | [diff] [blame] | 983 | loop_.PostTask(FROM_HERE, |
| 984 | base::Bind(&UpdateAttempterTest::P2PEnabledStartingFailsStart, |
| 985 | base::Unretained(this))); |
| 986 | loop_.Run(); |
David Zeuthen | 8f191b2 | 2013-08-06 12:27:50 -0700 | [diff] [blame] | 987 | } |
Alex Deymo | 60ca1a7 | 2015-06-18 18:19:15 -0700 | [diff] [blame] | 988 | |
David Zeuthen | 8f191b2 | 2013-08-06 12:27:50 -0700 | [diff] [blame] | 989 | void UpdateAttempterTest::P2PEnabledStartingFailsStart() { |
Jae Hoon Kim | edb6550 | 2019-06-14 11:52:17 -0700 | [diff] [blame] | 990 | // If P2P is enabled, but starting it fails ensure we don't do |
| 991 | // any housekeeping and do not convey that P2P should be used. |
David Zeuthen | 8f191b2 | 2013-08-06 12:27:50 -0700 | [diff] [blame] | 992 | MockP2PManager mock_p2p_manager; |
Amin Hassani | 538bd59 | 2020-11-04 20:46:08 -0800 | [diff] [blame] | 993 | FakeSystemState::Get()->set_p2p_manager(&mock_p2p_manager); |
David Zeuthen | 8f191b2 | 2013-08-06 12:27:50 -0700 | [diff] [blame] | 994 | mock_p2p_manager.fake().SetP2PEnabled(true); |
| 995 | mock_p2p_manager.fake().SetEnsureP2PRunningResult(false); |
| 996 | mock_p2p_manager.fake().SetPerformHousekeepingResult(false); |
| 997 | EXPECT_CALL(mock_p2p_manager, PerformHousekeeping()).Times(0); |
Amin Hassani | e815363 | 2020-10-27 15:11:28 -0700 | [diff] [blame] | 998 | attempter_.Update({}); |
Gilad Arnold | 74b5f55 | 2014-10-07 08:17:16 -0700 | [diff] [blame] | 999 | EXPECT_FALSE(actual_using_p2p_for_downloading()); |
| 1000 | EXPECT_FALSE(actual_using_p2p_for_sharing()); |
Alex Deymo | 60ca1a7 | 2015-06-18 18:19:15 -0700 | [diff] [blame] | 1001 | ScheduleQuitMainLoop(); |
David Zeuthen | 8f191b2 | 2013-08-06 12:27:50 -0700 | [diff] [blame] | 1002 | } |
| 1003 | |
| 1004 | TEST_F(UpdateAttempterTest, P2PEnabledHousekeepingFails) { |
Alex Deymo | 60ca1a7 | 2015-06-18 18:19:15 -0700 | [diff] [blame] | 1005 | loop_.PostTask( |
| 1006 | FROM_HERE, |
| 1007 | base::Bind(&UpdateAttempterTest::P2PEnabledHousekeepingFailsStart, |
| 1008 | base::Unretained(this))); |
| 1009 | loop_.Run(); |
David Zeuthen | 8f191b2 | 2013-08-06 12:27:50 -0700 | [diff] [blame] | 1010 | } |
Alex Deymo | 60ca1a7 | 2015-06-18 18:19:15 -0700 | [diff] [blame] | 1011 | |
David Zeuthen | 8f191b2 | 2013-08-06 12:27:50 -0700 | [diff] [blame] | 1012 | void UpdateAttempterTest::P2PEnabledHousekeepingFailsStart() { |
Jae Hoon Kim | edb6550 | 2019-06-14 11:52:17 -0700 | [diff] [blame] | 1013 | // If P2P is enabled, starting it works but housekeeping fails, ensure |
| 1014 | // we do not convey P2P is to be used. |
David Zeuthen | 8f191b2 | 2013-08-06 12:27:50 -0700 | [diff] [blame] | 1015 | MockP2PManager mock_p2p_manager; |
Amin Hassani | 538bd59 | 2020-11-04 20:46:08 -0800 | [diff] [blame] | 1016 | FakeSystemState::Get()->set_p2p_manager(&mock_p2p_manager); |
David Zeuthen | 8f191b2 | 2013-08-06 12:27:50 -0700 | [diff] [blame] | 1017 | mock_p2p_manager.fake().SetP2PEnabled(true); |
| 1018 | mock_p2p_manager.fake().SetEnsureP2PRunningResult(true); |
| 1019 | mock_p2p_manager.fake().SetPerformHousekeepingResult(false); |
Gilad Arnold | 74b5f55 | 2014-10-07 08:17:16 -0700 | [diff] [blame] | 1020 | EXPECT_CALL(mock_p2p_manager, PerformHousekeeping()); |
Amin Hassani | e815363 | 2020-10-27 15:11:28 -0700 | [diff] [blame] | 1021 | attempter_.Update({}); |
Gilad Arnold | 74b5f55 | 2014-10-07 08:17:16 -0700 | [diff] [blame] | 1022 | EXPECT_FALSE(actual_using_p2p_for_downloading()); |
| 1023 | EXPECT_FALSE(actual_using_p2p_for_sharing()); |
Alex Deymo | 60ca1a7 | 2015-06-18 18:19:15 -0700 | [diff] [blame] | 1024 | ScheduleQuitMainLoop(); |
David Zeuthen | 8f191b2 | 2013-08-06 12:27:50 -0700 | [diff] [blame] | 1025 | } |
| 1026 | |
| 1027 | TEST_F(UpdateAttempterTest, P2PEnabled) { |
Alex Deymo | 60ca1a7 | 2015-06-18 18:19:15 -0700 | [diff] [blame] | 1028 | loop_.PostTask(FROM_HERE, |
| 1029 | base::Bind(&UpdateAttempterTest::P2PEnabledStart, |
| 1030 | base::Unretained(this))); |
| 1031 | loop_.Run(); |
David Zeuthen | 8f191b2 | 2013-08-06 12:27:50 -0700 | [diff] [blame] | 1032 | } |
Alex Deymo | 60ca1a7 | 2015-06-18 18:19:15 -0700 | [diff] [blame] | 1033 | |
David Zeuthen | 8f191b2 | 2013-08-06 12:27:50 -0700 | [diff] [blame] | 1034 | void UpdateAttempterTest::P2PEnabledStart() { |
| 1035 | MockP2PManager mock_p2p_manager; |
Amin Hassani | 538bd59 | 2020-11-04 20:46:08 -0800 | [diff] [blame] | 1036 | FakeSystemState::Get()->set_p2p_manager(&mock_p2p_manager); |
David Zeuthen | 8f191b2 | 2013-08-06 12:27:50 -0700 | [diff] [blame] | 1037 | // If P2P is enabled and starting it works, check that we performed |
Jae Hoon Kim | edb6550 | 2019-06-14 11:52:17 -0700 | [diff] [blame] | 1038 | // housekeeping and that we convey P2P should be used. |
David Zeuthen | 8f191b2 | 2013-08-06 12:27:50 -0700 | [diff] [blame] | 1039 | mock_p2p_manager.fake().SetP2PEnabled(true); |
| 1040 | mock_p2p_manager.fake().SetEnsureP2PRunningResult(true); |
| 1041 | mock_p2p_manager.fake().SetPerformHousekeepingResult(true); |
Gilad Arnold | 74b5f55 | 2014-10-07 08:17:16 -0700 | [diff] [blame] | 1042 | EXPECT_CALL(mock_p2p_manager, PerformHousekeeping()); |
Amin Hassani | e815363 | 2020-10-27 15:11:28 -0700 | [diff] [blame] | 1043 | attempter_.Update({}); |
Gilad Arnold | 74b5f55 | 2014-10-07 08:17:16 -0700 | [diff] [blame] | 1044 | EXPECT_TRUE(actual_using_p2p_for_downloading()); |
| 1045 | EXPECT_TRUE(actual_using_p2p_for_sharing()); |
Alex Deymo | 60ca1a7 | 2015-06-18 18:19:15 -0700 | [diff] [blame] | 1046 | ScheduleQuitMainLoop(); |
David Zeuthen | 8f191b2 | 2013-08-06 12:27:50 -0700 | [diff] [blame] | 1047 | } |
| 1048 | |
| 1049 | TEST_F(UpdateAttempterTest, P2PEnabledInteractive) { |
Alex Deymo | 60ca1a7 | 2015-06-18 18:19:15 -0700 | [diff] [blame] | 1050 | loop_.PostTask(FROM_HERE, |
| 1051 | base::Bind(&UpdateAttempterTest::P2PEnabledInteractiveStart, |
| 1052 | base::Unretained(this))); |
| 1053 | loop_.Run(); |
David Zeuthen | 8f191b2 | 2013-08-06 12:27:50 -0700 | [diff] [blame] | 1054 | } |
Alex Deymo | 60ca1a7 | 2015-06-18 18:19:15 -0700 | [diff] [blame] | 1055 | |
David Zeuthen | 8f191b2 | 2013-08-06 12:27:50 -0700 | [diff] [blame] | 1056 | void UpdateAttempterTest::P2PEnabledInteractiveStart() { |
| 1057 | MockP2PManager mock_p2p_manager; |
Amin Hassani | 538bd59 | 2020-11-04 20:46:08 -0800 | [diff] [blame] | 1058 | FakeSystemState::Get()->set_p2p_manager(&mock_p2p_manager); |
David Zeuthen | 8f191b2 | 2013-08-06 12:27:50 -0700 | [diff] [blame] | 1059 | // For an interactive check, if P2P is enabled and starting it |
| 1060 | // works, check that we performed housekeeping and that we convey |
Jae Hoon Kim | edb6550 | 2019-06-14 11:52:17 -0700 | [diff] [blame] | 1061 | // P2P should be used for sharing but NOT for downloading. |
David Zeuthen | 8f191b2 | 2013-08-06 12:27:50 -0700 | [diff] [blame] | 1062 | mock_p2p_manager.fake().SetP2PEnabled(true); |
| 1063 | mock_p2p_manager.fake().SetEnsureP2PRunningResult(true); |
| 1064 | mock_p2p_manager.fake().SetPerformHousekeepingResult(true); |
Gilad Arnold | 74b5f55 | 2014-10-07 08:17:16 -0700 | [diff] [blame] | 1065 | EXPECT_CALL(mock_p2p_manager, PerformHousekeeping()); |
Amin Hassani | e815363 | 2020-10-27 15:11:28 -0700 | [diff] [blame] | 1066 | attempter_.Update({.interactive = true}); |
Gilad Arnold | 74b5f55 | 2014-10-07 08:17:16 -0700 | [diff] [blame] | 1067 | EXPECT_FALSE(actual_using_p2p_for_downloading()); |
| 1068 | EXPECT_TRUE(actual_using_p2p_for_sharing()); |
Alex Deymo | 60ca1a7 | 2015-06-18 18:19:15 -0700 | [diff] [blame] | 1069 | ScheduleQuitMainLoop(); |
David Zeuthen | 8f191b2 | 2013-08-06 12:27:50 -0700 | [diff] [blame] | 1070 | } |
| 1071 | |
Jay Srinivasan | 480ddfa | 2012-06-01 19:15:26 -0700 | [diff] [blame] | 1072 | TEST_F(UpdateAttempterTest, ReadScatterFactorFromPolicy) { |
Alex Deymo | 60ca1a7 | 2015-06-18 18:19:15 -0700 | [diff] [blame] | 1073 | loop_.PostTask( |
| 1074 | FROM_HERE, |
| 1075 | base::Bind(&UpdateAttempterTest::ReadScatterFactorFromPolicyTestStart, |
| 1076 | base::Unretained(this))); |
| 1077 | loop_.Run(); |
Jay Srinivasan | 480ddfa | 2012-06-01 19:15:26 -0700 | [diff] [blame] | 1078 | } |
| 1079 | |
| 1080 | // Tests that the scatter_factor_in_seconds value is properly fetched |
| 1081 | // from the device policy. |
| 1082 | void UpdateAttempterTest::ReadScatterFactorFromPolicyTestStart() { |
Ben Chan | 9abb763 | 2014-08-07 00:10:53 -0700 | [diff] [blame] | 1083 | int64_t scatter_factor_in_seconds = 36000; |
Jay Srinivasan | 480ddfa | 2012-06-01 19:15:26 -0700 | [diff] [blame] | 1084 | |
Igor | 9fd76b6 | 2017-12-11 15:24:18 +0100 | [diff] [blame] | 1085 | auto device_policy = std::make_unique<policy::MockDevicePolicy>(); |
Jay Srinivasan | 480ddfa | 2012-06-01 19:15:26 -0700 | [diff] [blame] | 1086 | EXPECT_CALL(*device_policy, LoadPolicy()).WillRepeatedly(Return(true)); |
Amin Hassani | 538bd59 | 2020-11-04 20:46:08 -0800 | [diff] [blame] | 1087 | FakeSystemState::Get()->set_device_policy(device_policy.get()); |
Jay Srinivasan | 480ddfa | 2012-06-01 19:15:26 -0700 | [diff] [blame] | 1088 | |
| 1089 | EXPECT_CALL(*device_policy, GetScatterFactorInSeconds(_)) |
Amin Hassani | 7cc8bb0 | 2019-01-14 16:29:47 -0800 | [diff] [blame] | 1090 | .WillRepeatedly( |
| 1091 | DoAll(SetArgPointee<0>(scatter_factor_in_seconds), Return(true))); |
Jay Srinivasan | 480ddfa | 2012-06-01 19:15:26 -0700 | [diff] [blame] | 1092 | |
Igor | 9fd76b6 | 2017-12-11 15:24:18 +0100 | [diff] [blame] | 1093 | attempter_.policy_provider_.reset( |
| 1094 | new policy::PolicyProvider(std::move(device_policy))); |
| 1095 | |
Amin Hassani | e815363 | 2020-10-27 15:11:28 -0700 | [diff] [blame] | 1096 | attempter_.Update({}); |
Jay Srinivasan | 480ddfa | 2012-06-01 19:15:26 -0700 | [diff] [blame] | 1097 | EXPECT_EQ(scatter_factor_in_seconds, attempter_.scatter_factor_.InSeconds()); |
| 1098 | |
Alex Deymo | 60ca1a7 | 2015-06-18 18:19:15 -0700 | [diff] [blame] | 1099 | ScheduleQuitMainLoop(); |
Jay Srinivasan | 480ddfa | 2012-06-01 19:15:26 -0700 | [diff] [blame] | 1100 | } |
| 1101 | |
| 1102 | TEST_F(UpdateAttempterTest, DecrementUpdateCheckCountTest) { |
Alex Deymo | 60ca1a7 | 2015-06-18 18:19:15 -0700 | [diff] [blame] | 1103 | loop_.PostTask( |
| 1104 | FROM_HERE, |
| 1105 | base::Bind(&UpdateAttempterTest::DecrementUpdateCheckCountTestStart, |
| 1106 | base::Unretained(this))); |
| 1107 | loop_.Run(); |
Jay Srinivasan | 480ddfa | 2012-06-01 19:15:26 -0700 | [diff] [blame] | 1108 | } |
| 1109 | |
| 1110 | void UpdateAttempterTest::DecrementUpdateCheckCountTestStart() { |
| 1111 | // Tests that the scatter_factor_in_seconds value is properly fetched |
| 1112 | // from the device policy and is decremented if value > 0. |
Ben Chan | 9abb763 | 2014-08-07 00:10:53 -0700 | [diff] [blame] | 1113 | int64_t initial_value = 5; |
Alex Deymo | 2c0db7b | 2014-11-04 12:23:39 -0800 | [diff] [blame] | 1114 | FakePrefs fake_prefs; |
| 1115 | attempter_.prefs_ = &fake_prefs; |
Jay Srinivasan | 480ddfa | 2012-06-01 19:15:26 -0700 | [diff] [blame] | 1116 | |
Amin Hassani | 538bd59 | 2020-11-04 20:46:08 -0800 | [diff] [blame] | 1117 | FakeSystemState::Get()->fake_hardware()->SetIsOOBEComplete(Time::UnixEpoch()); |
Jay Srinivasan | 08fce04 | 2012-06-07 16:31:01 -0700 | [diff] [blame] | 1118 | |
Alex Deymo | 2c0db7b | 2014-11-04 12:23:39 -0800 | [diff] [blame] | 1119 | EXPECT_TRUE(fake_prefs.SetInt64(kPrefsUpdateCheckCount, initial_value)); |
Jay Srinivasan | 480ddfa | 2012-06-01 19:15:26 -0700 | [diff] [blame] | 1120 | |
Ben Chan | 9abb763 | 2014-08-07 00:10:53 -0700 | [diff] [blame] | 1121 | int64_t scatter_factor_in_seconds = 10; |
Jay Srinivasan | 480ddfa | 2012-06-01 19:15:26 -0700 | [diff] [blame] | 1122 | |
Igor | 9fd76b6 | 2017-12-11 15:24:18 +0100 | [diff] [blame] | 1123 | auto device_policy = std::make_unique<policy::MockDevicePolicy>(); |
Jay Srinivasan | 480ddfa | 2012-06-01 19:15:26 -0700 | [diff] [blame] | 1124 | EXPECT_CALL(*device_policy, LoadPolicy()).WillRepeatedly(Return(true)); |
Amin Hassani | 538bd59 | 2020-11-04 20:46:08 -0800 | [diff] [blame] | 1125 | FakeSystemState::Get()->set_device_policy(device_policy.get()); |
Jay Srinivasan | 480ddfa | 2012-06-01 19:15:26 -0700 | [diff] [blame] | 1126 | |
| 1127 | EXPECT_CALL(*device_policy, GetScatterFactorInSeconds(_)) |
Amin Hassani | 7cc8bb0 | 2019-01-14 16:29:47 -0800 | [diff] [blame] | 1128 | .WillRepeatedly( |
| 1129 | DoAll(SetArgPointee<0>(scatter_factor_in_seconds), Return(true))); |
Jay Srinivasan | 480ddfa | 2012-06-01 19:15:26 -0700 | [diff] [blame] | 1130 | |
Igor | 9fd76b6 | 2017-12-11 15:24:18 +0100 | [diff] [blame] | 1131 | attempter_.policy_provider_.reset( |
| 1132 | new policy::PolicyProvider(std::move(device_policy))); |
| 1133 | |
Amin Hassani | e815363 | 2020-10-27 15:11:28 -0700 | [diff] [blame] | 1134 | attempter_.Update({}); |
Jay Srinivasan | 480ddfa | 2012-06-01 19:15:26 -0700 | [diff] [blame] | 1135 | EXPECT_EQ(scatter_factor_in_seconds, attempter_.scatter_factor_.InSeconds()); |
| 1136 | |
| 1137 | // Make sure the file still exists. |
Alex Deymo | 2c0db7b | 2014-11-04 12:23:39 -0800 | [diff] [blame] | 1138 | EXPECT_TRUE(fake_prefs.Exists(kPrefsUpdateCheckCount)); |
Jay Srinivasan | 480ddfa | 2012-06-01 19:15:26 -0700 | [diff] [blame] | 1139 | |
Ben Chan | 9abb763 | 2014-08-07 00:10:53 -0700 | [diff] [blame] | 1140 | int64_t new_value; |
Alex Deymo | 2c0db7b | 2014-11-04 12:23:39 -0800 | [diff] [blame] | 1141 | EXPECT_TRUE(fake_prefs.GetInt64(kPrefsUpdateCheckCount, &new_value)); |
Jay Srinivasan | 480ddfa | 2012-06-01 19:15:26 -0700 | [diff] [blame] | 1142 | EXPECT_EQ(initial_value - 1, new_value); |
| 1143 | |
Jay Srinivasan | ae4697c | 2013-03-18 17:08:08 -0700 | [diff] [blame] | 1144 | EXPECT_TRUE( |
| 1145 | attempter_.omaha_request_params_->update_check_count_wait_enabled()); |
Jay Srinivasan | 480ddfa | 2012-06-01 19:15:26 -0700 | [diff] [blame] | 1146 | |
| 1147 | // However, if the count is already 0, it's not decremented. Test that. |
| 1148 | initial_value = 0; |
Alex Deymo | 2c0db7b | 2014-11-04 12:23:39 -0800 | [diff] [blame] | 1149 | EXPECT_TRUE(fake_prefs.SetInt64(kPrefsUpdateCheckCount, initial_value)); |
Amin Hassani | e815363 | 2020-10-27 15:11:28 -0700 | [diff] [blame] | 1150 | attempter_.Update({}); |
Alex Deymo | 2c0db7b | 2014-11-04 12:23:39 -0800 | [diff] [blame] | 1151 | EXPECT_TRUE(fake_prefs.Exists(kPrefsUpdateCheckCount)); |
| 1152 | EXPECT_TRUE(fake_prefs.GetInt64(kPrefsUpdateCheckCount, &new_value)); |
Jay Srinivasan | 480ddfa | 2012-06-01 19:15:26 -0700 | [diff] [blame] | 1153 | EXPECT_EQ(initial_value, new_value); |
| 1154 | |
Alex Deymo | 60ca1a7 | 2015-06-18 18:19:15 -0700 | [diff] [blame] | 1155 | ScheduleQuitMainLoop(); |
Jay Srinivasan | 480ddfa | 2012-06-01 19:15:26 -0700 | [diff] [blame] | 1156 | } |
| 1157 | |
Jay Srinivasan | 08fce04 | 2012-06-07 16:31:01 -0700 | [diff] [blame] | 1158 | TEST_F(UpdateAttempterTest, NoScatteringDoneDuringManualUpdateTestStart) { |
Amin Hassani | 7cc8bb0 | 2019-01-14 16:29:47 -0800 | [diff] [blame] | 1159 | loop_.PostTask( |
| 1160 | FROM_HERE, |
| 1161 | base::Bind( |
| 1162 | &UpdateAttempterTest::NoScatteringDoneDuringManualUpdateTestStart, |
| 1163 | base::Unretained(this))); |
Alex Deymo | 60ca1a7 | 2015-06-18 18:19:15 -0700 | [diff] [blame] | 1164 | loop_.Run(); |
Jay Srinivasan | 08fce04 | 2012-06-07 16:31:01 -0700 | [diff] [blame] | 1165 | } |
| 1166 | |
| 1167 | void UpdateAttempterTest::NoScatteringDoneDuringManualUpdateTestStart() { |
| 1168 | // Tests that no scattering logic is enabled if the update check |
| 1169 | // is manually done (as opposed to a scheduled update check) |
Ben Chan | 9abb763 | 2014-08-07 00:10:53 -0700 | [diff] [blame] | 1170 | int64_t initial_value = 8; |
Alex Deymo | 2c0db7b | 2014-11-04 12:23:39 -0800 | [diff] [blame] | 1171 | FakePrefs fake_prefs; |
| 1172 | attempter_.prefs_ = &fake_prefs; |
Jay Srinivasan | 08fce04 | 2012-06-07 16:31:01 -0700 | [diff] [blame] | 1173 | |
Amin Hassani | 538bd59 | 2020-11-04 20:46:08 -0800 | [diff] [blame] | 1174 | FakeSystemState::Get()->fake_hardware()->SetIsOOBEComplete(Time::UnixEpoch()); |
| 1175 | FakeSystemState::Get()->set_prefs(&fake_prefs); |
Jay Srinivasan | 08fce04 | 2012-06-07 16:31:01 -0700 | [diff] [blame] | 1176 | |
Adolfo Victoria | d3a1e35 | 2018-07-16 11:40:47 -0700 | [diff] [blame] | 1177 | EXPECT_TRUE( |
| 1178 | fake_prefs.SetInt64(kPrefsWallClockScatteringWaitPeriod, initial_value)); |
Alex Deymo | 2c0db7b | 2014-11-04 12:23:39 -0800 | [diff] [blame] | 1179 | EXPECT_TRUE(fake_prefs.SetInt64(kPrefsUpdateCheckCount, initial_value)); |
Jay Srinivasan | 08fce04 | 2012-06-07 16:31:01 -0700 | [diff] [blame] | 1180 | |
| 1181 | // make sure scatter_factor is non-zero as scattering is disabled |
| 1182 | // otherwise. |
Ben Chan | 9abb763 | 2014-08-07 00:10:53 -0700 | [diff] [blame] | 1183 | int64_t scatter_factor_in_seconds = 50; |
Jay Srinivasan | 08fce04 | 2012-06-07 16:31:01 -0700 | [diff] [blame] | 1184 | |
Igor | 9fd76b6 | 2017-12-11 15:24:18 +0100 | [diff] [blame] | 1185 | auto device_policy = std::make_unique<policy::MockDevicePolicy>(); |
Jay Srinivasan | 08fce04 | 2012-06-07 16:31:01 -0700 | [diff] [blame] | 1186 | EXPECT_CALL(*device_policy, LoadPolicy()).WillRepeatedly(Return(true)); |
Amin Hassani | 538bd59 | 2020-11-04 20:46:08 -0800 | [diff] [blame] | 1187 | FakeSystemState::Get()->set_device_policy(device_policy.get()); |
Jay Srinivasan | 08fce04 | 2012-06-07 16:31:01 -0700 | [diff] [blame] | 1188 | |
| 1189 | EXPECT_CALL(*device_policy, GetScatterFactorInSeconds(_)) |
Amin Hassani | 7cc8bb0 | 2019-01-14 16:29:47 -0800 | [diff] [blame] | 1190 | .WillRepeatedly( |
| 1191 | DoAll(SetArgPointee<0>(scatter_factor_in_seconds), Return(true))); |
Jay Srinivasan | 08fce04 | 2012-06-07 16:31:01 -0700 | [diff] [blame] | 1192 | |
Igor | 9fd76b6 | 2017-12-11 15:24:18 +0100 | [diff] [blame] | 1193 | attempter_.policy_provider_.reset( |
| 1194 | new policy::PolicyProvider(std::move(device_policy))); |
| 1195 | |
Gilad Arnold | b92f0df | 2013-01-10 16:32:45 -0800 | [diff] [blame] | 1196 | // Trigger an interactive check so we can test that scattering is disabled. |
Amin Hassani | e815363 | 2020-10-27 15:11:28 -0700 | [diff] [blame] | 1197 | attempter_.Update({.interactive = true}); |
Jay Srinivasan | 08fce04 | 2012-06-07 16:31:01 -0700 | [diff] [blame] | 1198 | EXPECT_EQ(scatter_factor_in_seconds, attempter_.scatter_factor_.InSeconds()); |
| 1199 | |
| 1200 | // Make sure scattering is disabled for manual (i.e. user initiated) update |
Jay Srinivasan | 21be075 | 2012-07-25 15:44:56 -0700 | [diff] [blame] | 1201 | // checks and all artifacts are removed. |
Jay Srinivasan | ae4697c | 2013-03-18 17:08:08 -0700 | [diff] [blame] | 1202 | EXPECT_FALSE( |
| 1203 | attempter_.omaha_request_params_->wall_clock_based_wait_enabled()); |
Adolfo Victoria | d3a1e35 | 2018-07-16 11:40:47 -0700 | [diff] [blame] | 1204 | EXPECT_FALSE(fake_prefs.Exists(kPrefsWallClockScatteringWaitPeriod)); |
Jay Srinivasan | ae4697c | 2013-03-18 17:08:08 -0700 | [diff] [blame] | 1205 | EXPECT_EQ(0, attempter_.omaha_request_params_->waiting_period().InSeconds()); |
| 1206 | EXPECT_FALSE( |
| 1207 | attempter_.omaha_request_params_->update_check_count_wait_enabled()); |
Alex Deymo | 2c0db7b | 2014-11-04 12:23:39 -0800 | [diff] [blame] | 1208 | EXPECT_FALSE(fake_prefs.Exists(kPrefsUpdateCheckCount)); |
Jay Srinivasan | 08fce04 | 2012-06-07 16:31:01 -0700 | [diff] [blame] | 1209 | |
Alex Deymo | 60ca1a7 | 2015-06-18 18:19:15 -0700 | [diff] [blame] | 1210 | ScheduleQuitMainLoop(); |
Jay Srinivasan | 08fce04 | 2012-06-07 16:31:01 -0700 | [diff] [blame] | 1211 | } |
| 1212 | |
Adolfo Victoria | 497044c | 2018-07-18 07:51:42 -0700 | [diff] [blame] | 1213 | void UpdateAttempterTest::SetUpStagingTest(const StagingSchedule& schedule, |
| 1214 | FakePrefs* prefs) { |
| 1215 | attempter_.prefs_ = prefs; |
Amin Hassani | 538bd59 | 2020-11-04 20:46:08 -0800 | [diff] [blame] | 1216 | FakeSystemState::Get()->set_prefs(prefs); |
Adolfo Victoria | 497044c | 2018-07-18 07:51:42 -0700 | [diff] [blame] | 1217 | |
| 1218 | int64_t initial_value = 8; |
| 1219 | EXPECT_TRUE( |
| 1220 | prefs->SetInt64(kPrefsWallClockScatteringWaitPeriod, initial_value)); |
| 1221 | EXPECT_TRUE(prefs->SetInt64(kPrefsUpdateCheckCount, initial_value)); |
| 1222 | attempter_.scatter_factor_ = TimeDelta::FromSeconds(20); |
| 1223 | |
| 1224 | auto device_policy = std::make_unique<policy::MockDevicePolicy>(); |
| 1225 | EXPECT_CALL(*device_policy, LoadPolicy()).WillRepeatedly(Return(true)); |
Amin Hassani | 538bd59 | 2020-11-04 20:46:08 -0800 | [diff] [blame] | 1226 | FakeSystemState::Get()->set_device_policy(device_policy.get()); |
Adolfo Victoria | 497044c | 2018-07-18 07:51:42 -0700 | [diff] [blame] | 1227 | EXPECT_CALL(*device_policy, GetDeviceUpdateStagingSchedule(_)) |
| 1228 | .WillRepeatedly(DoAll(SetArgPointee<0>(schedule), Return(true))); |
| 1229 | |
| 1230 | attempter_.policy_provider_.reset( |
| 1231 | new policy::PolicyProvider(std::move(device_policy))); |
| 1232 | } |
| 1233 | |
| 1234 | TEST_F(UpdateAttempterTest, StagingSetsPrefsAndTurnsOffScattering) { |
| 1235 | loop_.PostTask( |
| 1236 | FROM_HERE, |
| 1237 | base::Bind( |
| 1238 | &UpdateAttempterTest::StagingSetsPrefsAndTurnsOffScatteringStart, |
| 1239 | base::Unretained(this))); |
| 1240 | loop_.Run(); |
| 1241 | } |
| 1242 | |
| 1243 | void UpdateAttempterTest::StagingSetsPrefsAndTurnsOffScatteringStart() { |
| 1244 | // Tests that staging sets its prefs properly and turns off scattering. |
Amin Hassani | 538bd59 | 2020-11-04 20:46:08 -0800 | [diff] [blame] | 1245 | FakeSystemState::Get()->fake_hardware()->SetIsOOBEComplete(Time::UnixEpoch()); |
Adolfo Victoria | 497044c | 2018-07-18 07:51:42 -0700 | [diff] [blame] | 1246 | FakePrefs fake_prefs; |
| 1247 | SetUpStagingTest(kValidStagingSchedule, &fake_prefs); |
| 1248 | |
Amin Hassani | e815363 | 2020-10-27 15:11:28 -0700 | [diff] [blame] | 1249 | attempter_.Update({}); |
Adolfo Victoria | 497044c | 2018-07-18 07:51:42 -0700 | [diff] [blame] | 1250 | // Check that prefs have the correct values. |
| 1251 | int64_t update_count; |
| 1252 | EXPECT_TRUE(fake_prefs.GetInt64(kPrefsUpdateCheckCount, &update_count)); |
| 1253 | int64_t waiting_time_days; |
| 1254 | EXPECT_TRUE(fake_prefs.GetInt64(kPrefsWallClockStagingWaitPeriod, |
| 1255 | &waiting_time_days)); |
| 1256 | EXPECT_GT(waiting_time_days, 0); |
| 1257 | // Update count should have been decremented. |
| 1258 | EXPECT_EQ(7, update_count); |
| 1259 | // Check that Omaha parameters were updated correctly. |
| 1260 | EXPECT_TRUE( |
| 1261 | attempter_.omaha_request_params_->update_check_count_wait_enabled()); |
| 1262 | EXPECT_TRUE( |
| 1263 | attempter_.omaha_request_params_->wall_clock_based_wait_enabled()); |
| 1264 | EXPECT_EQ(waiting_time_days, |
| 1265 | attempter_.omaha_request_params_->waiting_period().InDays()); |
| 1266 | // Check class variables. |
| 1267 | EXPECT_EQ(waiting_time_days, attempter_.staging_wait_time_.InDays()); |
| 1268 | EXPECT_EQ(kValidStagingSchedule, attempter_.staging_schedule_); |
| 1269 | // Check that scattering is turned off |
| 1270 | EXPECT_EQ(0, attempter_.scatter_factor_.InSeconds()); |
| 1271 | EXPECT_FALSE(fake_prefs.Exists(kPrefsWallClockScatteringWaitPeriod)); |
| 1272 | |
| 1273 | ScheduleQuitMainLoop(); |
| 1274 | } |
| 1275 | |
| 1276 | void UpdateAttempterTest::CheckStagingOff() { |
| 1277 | // Check that all prefs were removed. |
| 1278 | EXPECT_FALSE(attempter_.prefs_->Exists(kPrefsUpdateCheckCount)); |
| 1279 | EXPECT_FALSE(attempter_.prefs_->Exists(kPrefsWallClockScatteringWaitPeriod)); |
| 1280 | EXPECT_FALSE(attempter_.prefs_->Exists(kPrefsWallClockStagingWaitPeriod)); |
| 1281 | // Check that the Omaha parameters have the correct value. |
| 1282 | EXPECT_EQ(0, attempter_.omaha_request_params_->waiting_period().InDays()); |
| 1283 | EXPECT_EQ(attempter_.omaha_request_params_->waiting_period(), |
| 1284 | attempter_.staging_wait_time_); |
| 1285 | EXPECT_FALSE( |
| 1286 | attempter_.omaha_request_params_->update_check_count_wait_enabled()); |
| 1287 | EXPECT_FALSE( |
| 1288 | attempter_.omaha_request_params_->wall_clock_based_wait_enabled()); |
| 1289 | // Check that scattering is turned off too. |
| 1290 | EXPECT_EQ(0, attempter_.scatter_factor_.InSeconds()); |
| 1291 | } |
| 1292 | |
| 1293 | TEST_F(UpdateAttempterTest, StagingOffIfInteractive) { |
| 1294 | loop_.PostTask(FROM_HERE, |
| 1295 | base::Bind(&UpdateAttempterTest::StagingOffIfInteractiveStart, |
| 1296 | base::Unretained(this))); |
| 1297 | loop_.Run(); |
| 1298 | } |
| 1299 | |
| 1300 | void UpdateAttempterTest::StagingOffIfInteractiveStart() { |
| 1301 | // Tests that staging is turned off when an interactive update is requested. |
Amin Hassani | 538bd59 | 2020-11-04 20:46:08 -0800 | [diff] [blame] | 1302 | FakeSystemState::Get()->fake_hardware()->SetIsOOBEComplete(Time::UnixEpoch()); |
Adolfo Victoria | 497044c | 2018-07-18 07:51:42 -0700 | [diff] [blame] | 1303 | FakePrefs fake_prefs; |
| 1304 | SetUpStagingTest(kValidStagingSchedule, &fake_prefs); |
| 1305 | |
Amin Hassani | e815363 | 2020-10-27 15:11:28 -0700 | [diff] [blame] | 1306 | attempter_.Update({.interactive = true}); |
Adolfo Victoria | 497044c | 2018-07-18 07:51:42 -0700 | [diff] [blame] | 1307 | CheckStagingOff(); |
| 1308 | |
| 1309 | ScheduleQuitMainLoop(); |
| 1310 | } |
| 1311 | |
| 1312 | TEST_F(UpdateAttempterTest, StagingOffIfOobe) { |
| 1313 | loop_.PostTask(FROM_HERE, |
| 1314 | base::Bind(&UpdateAttempterTest::StagingOffIfOobeStart, |
| 1315 | base::Unretained(this))); |
| 1316 | loop_.Run(); |
| 1317 | } |
| 1318 | |
| 1319 | void UpdateAttempterTest::StagingOffIfOobeStart() { |
| 1320 | // Tests that staging is turned off if OOBE hasn't been completed. |
Amin Hassani | 538bd59 | 2020-11-04 20:46:08 -0800 | [diff] [blame] | 1321 | FakeSystemState::Get()->fake_hardware()->SetIsOOBEEnabled(true); |
| 1322 | FakeSystemState::Get()->fake_hardware()->UnsetIsOOBEComplete(); |
Adolfo Victoria | 497044c | 2018-07-18 07:51:42 -0700 | [diff] [blame] | 1323 | FakePrefs fake_prefs; |
| 1324 | SetUpStagingTest(kValidStagingSchedule, &fake_prefs); |
| 1325 | |
Amin Hassani | e815363 | 2020-10-27 15:11:28 -0700 | [diff] [blame] | 1326 | attempter_.Update({.interactive = true}); |
Adolfo Victoria | 497044c | 2018-07-18 07:51:42 -0700 | [diff] [blame] | 1327 | CheckStagingOff(); |
| 1328 | |
| 1329 | ScheduleQuitMainLoop(); |
| 1330 | } |
| 1331 | |
David Zeuthen | 985b112 | 2013-10-09 12:13:15 -0700 | [diff] [blame] | 1332 | // Checks that we only report daily metrics at most every 24 hours. |
| 1333 | TEST_F(UpdateAttempterTest, ReportDailyMetrics) { |
| 1334 | FakeClock fake_clock; |
Alex Deymo | 2c0db7b | 2014-11-04 12:23:39 -0800 | [diff] [blame] | 1335 | FakePrefs fake_prefs; |
David Zeuthen | 985b112 | 2013-10-09 12:13:15 -0700 | [diff] [blame] | 1336 | |
Amin Hassani | 538bd59 | 2020-11-04 20:46:08 -0800 | [diff] [blame] | 1337 | FakeSystemState::Get()->set_clock(&fake_clock); |
| 1338 | FakeSystemState::Get()->set_prefs(&fake_prefs); |
David Zeuthen | 985b112 | 2013-10-09 12:13:15 -0700 | [diff] [blame] | 1339 | |
| 1340 | Time epoch = Time::FromInternalValue(0); |
| 1341 | fake_clock.SetWallclockTime(epoch); |
| 1342 | |
| 1343 | // If there is no kPrefsDailyMetricsLastReportedAt state variable, |
| 1344 | // we should report. |
| 1345 | EXPECT_TRUE(attempter_.CheckAndReportDailyMetrics()); |
| 1346 | // We should not report again if no time has passed. |
| 1347 | EXPECT_FALSE(attempter_.CheckAndReportDailyMetrics()); |
| 1348 | |
| 1349 | // We should not report if only 10 hours has passed. |
| 1350 | fake_clock.SetWallclockTime(epoch + TimeDelta::FromHours(10)); |
| 1351 | EXPECT_FALSE(attempter_.CheckAndReportDailyMetrics()); |
| 1352 | |
| 1353 | // We should not report if only 24 hours - 1 sec has passed. |
| 1354 | fake_clock.SetWallclockTime(epoch + TimeDelta::FromHours(24) - |
| 1355 | TimeDelta::FromSeconds(1)); |
| 1356 | EXPECT_FALSE(attempter_.CheckAndReportDailyMetrics()); |
| 1357 | |
| 1358 | // We should report if 24 hours has passed. |
| 1359 | fake_clock.SetWallclockTime(epoch + TimeDelta::FromHours(24)); |
| 1360 | EXPECT_TRUE(attempter_.CheckAndReportDailyMetrics()); |
| 1361 | |
| 1362 | // But then we should not report again.. |
| 1363 | EXPECT_FALSE(attempter_.CheckAndReportDailyMetrics()); |
| 1364 | |
| 1365 | // .. until another 24 hours has passed |
| 1366 | fake_clock.SetWallclockTime(epoch + TimeDelta::FromHours(47)); |
| 1367 | EXPECT_FALSE(attempter_.CheckAndReportDailyMetrics()); |
| 1368 | fake_clock.SetWallclockTime(epoch + TimeDelta::FromHours(48)); |
| 1369 | EXPECT_TRUE(attempter_.CheckAndReportDailyMetrics()); |
| 1370 | EXPECT_FALSE(attempter_.CheckAndReportDailyMetrics()); |
| 1371 | |
| 1372 | // .. and another 24 hours |
| 1373 | fake_clock.SetWallclockTime(epoch + TimeDelta::FromHours(71)); |
| 1374 | EXPECT_FALSE(attempter_.CheckAndReportDailyMetrics()); |
| 1375 | fake_clock.SetWallclockTime(epoch + TimeDelta::FromHours(72)); |
| 1376 | EXPECT_TRUE(attempter_.CheckAndReportDailyMetrics()); |
| 1377 | EXPECT_FALSE(attempter_.CheckAndReportDailyMetrics()); |
| 1378 | |
| 1379 | // If the span between time of reporting and present time is |
| 1380 | // negative, we report. This is in order to reset the timestamp and |
| 1381 | // avoid an edge condition whereby a distant point in the future is |
| 1382 | // in the state variable resulting in us never ever reporting again. |
| 1383 | fake_clock.SetWallclockTime(epoch + TimeDelta::FromHours(71)); |
| 1384 | EXPECT_TRUE(attempter_.CheckAndReportDailyMetrics()); |
| 1385 | EXPECT_FALSE(attempter_.CheckAndReportDailyMetrics()); |
| 1386 | |
| 1387 | // In this case we should not update until the clock reads 71 + 24 = 95. |
| 1388 | // Check that. |
| 1389 | fake_clock.SetWallclockTime(epoch + TimeDelta::FromHours(94)); |
| 1390 | EXPECT_FALSE(attempter_.CheckAndReportDailyMetrics()); |
| 1391 | fake_clock.SetWallclockTime(epoch + TimeDelta::FromHours(95)); |
| 1392 | EXPECT_TRUE(attempter_.CheckAndReportDailyMetrics()); |
| 1393 | EXPECT_FALSE(attempter_.CheckAndReportDailyMetrics()); |
David Zeuthen | 985b112 | 2013-10-09 12:13:15 -0700 | [diff] [blame] | 1394 | } |
| 1395 | |
David Zeuthen | 3c55abd | 2013-10-14 12:48:03 -0700 | [diff] [blame] | 1396 | TEST_F(UpdateAttempterTest, BootTimeInUpdateMarkerFile) { |
David Zeuthen | 3c55abd | 2013-10-14 12:48:03 -0700 | [diff] [blame] | 1397 | FakeClock fake_clock; |
| 1398 | fake_clock.SetBootTime(Time::FromTimeT(42)); |
Amin Hassani | 538bd59 | 2020-11-04 20:46:08 -0800 | [diff] [blame] | 1399 | FakeSystemState::Get()->set_clock(&fake_clock); |
Alex Deymo | 906191f | 2015-10-12 12:22:44 -0700 | [diff] [blame] | 1400 | FakePrefs fake_prefs; |
Amin Hassani | 538bd59 | 2020-11-04 20:46:08 -0800 | [diff] [blame] | 1401 | FakeSystemState::Get()->set_prefs(&fake_prefs); |
Sen Jiang | aeeb2e0 | 2016-06-09 15:00:16 -0700 | [diff] [blame] | 1402 | attempter_.Init(); |
David Zeuthen | 3c55abd | 2013-10-14 12:48:03 -0700 | [diff] [blame] | 1403 | |
| 1404 | Time boot_time; |
Sen Jiang | aeeb2e0 | 2016-06-09 15:00:16 -0700 | [diff] [blame] | 1405 | EXPECT_FALSE(attempter_.GetBootTimeAtUpdate(&boot_time)); |
David Zeuthen | 3c55abd | 2013-10-14 12:48:03 -0700 | [diff] [blame] | 1406 | |
Sen Jiang | aeeb2e0 | 2016-06-09 15:00:16 -0700 | [diff] [blame] | 1407 | attempter_.WriteUpdateCompletedMarker(); |
David Zeuthen | 3c55abd | 2013-10-14 12:48:03 -0700 | [diff] [blame] | 1408 | |
Sen Jiang | aeeb2e0 | 2016-06-09 15:00:16 -0700 | [diff] [blame] | 1409 | EXPECT_TRUE(attempter_.GetBootTimeAtUpdate(&boot_time)); |
David Zeuthen | 3c55abd | 2013-10-14 12:48:03 -0700 | [diff] [blame] | 1410 | EXPECT_EQ(boot_time.ToTimeT(), 42); |
| 1411 | } |
| 1412 | |
David Pursell | 02c1864 | 2014-11-06 11:26:11 -0800 | [diff] [blame] | 1413 | TEST_F(UpdateAttempterTest, AnyUpdateSourceAllowedUnofficial) { |
Amin Hassani | 538bd59 | 2020-11-04 20:46:08 -0800 | [diff] [blame] | 1414 | FakeSystemState::Get()->fake_hardware()->SetIsOfficialBuild(false); |
David Pursell | 02c1864 | 2014-11-06 11:26:11 -0800 | [diff] [blame] | 1415 | EXPECT_TRUE(attempter_.IsAnyUpdateSourceAllowed()); |
| 1416 | } |
| 1417 | |
| 1418 | TEST_F(UpdateAttempterTest, AnyUpdateSourceAllowedOfficialDevmode) { |
Amin Hassani | 538bd59 | 2020-11-04 20:46:08 -0800 | [diff] [blame] | 1419 | FakeSystemState::Get()->fake_hardware()->SetIsOfficialBuild(true); |
| 1420 | FakeSystemState::Get()->fake_hardware()->SetAreDevFeaturesEnabled(true); |
David Pursell | 02c1864 | 2014-11-06 11:26:11 -0800 | [diff] [blame] | 1421 | EXPECT_TRUE(attempter_.IsAnyUpdateSourceAllowed()); |
| 1422 | } |
| 1423 | |
| 1424 | TEST_F(UpdateAttempterTest, AnyUpdateSourceDisallowedOfficialNormal) { |
Amin Hassani | 538bd59 | 2020-11-04 20:46:08 -0800 | [diff] [blame] | 1425 | FakeSystemState::Get()->fake_hardware()->SetIsOfficialBuild(true); |
| 1426 | FakeSystemState::Get()->fake_hardware()->SetAreDevFeaturesEnabled(false); |
David Pursell | 02c1864 | 2014-11-06 11:26:11 -0800 | [diff] [blame] | 1427 | EXPECT_FALSE(attempter_.IsAnyUpdateSourceAllowed()); |
| 1428 | } |
| 1429 | |
Jae Hoon Kim | c437ea5 | 2019-07-11 11:20:38 -0700 | [diff] [blame] | 1430 | // TODO(kimjae): Follow testing pattern with params for |CheckForInstall()|. |
| 1431 | // When adding, remove older tests related to |CheckForInstall()|. |
| 1432 | TEST_F(UpdateAttempterTest, CheckForInstallNotIdleFails) { |
| 1433 | for (const auto status : kNonIdleUpdateStatuses) { |
| 1434 | // GIVEN a non-idle status. |
| 1435 | attempter_.status_ = status; |
Xiaochu Liu | 8ba486f | 2018-11-06 11:14:10 -0800 | [diff] [blame] | 1436 | |
Jae Hoon Kim | c437ea5 | 2019-07-11 11:20:38 -0700 | [diff] [blame] | 1437 | EXPECT_FALSE(attempter_.CheckForInstall({}, "")); |
| 1438 | } |
Xiaochu Liu | 8ba486f | 2018-11-06 11:14:10 -0800 | [diff] [blame] | 1439 | } |
| 1440 | |
Jae Hoon Kim | c437ea5 | 2019-07-11 11:20:38 -0700 | [diff] [blame] | 1441 | TEST_F(UpdateAttempterTest, CheckForUpdateNotIdleFails) { |
| 1442 | for (const auto status : kNonIdleUpdateStatuses) { |
| 1443 | // GIVEN a non-idle status. |
| 1444 | cfu_params_.status = status; |
Jae Hoon Kim | 51ea9ae | 2019-07-03 16:56:30 -0700 | [diff] [blame] | 1445 | |
Jae Hoon Kim | c437ea5 | 2019-07-11 11:20:38 -0700 | [diff] [blame] | 1446 | // THEN |ScheduleUpdates()| should not be called. |
| 1447 | cfu_params_.should_schedule_updates_be_called = false; |
| 1448 | // THEN result should indicate failure. |
| 1449 | cfu_params_.expected_result = false; |
Jae Hoon Kim | 51ea9ae | 2019-07-03 16:56:30 -0700 | [diff] [blame] | 1450 | |
Jae Hoon Kim | c437ea5 | 2019-07-11 11:20:38 -0700 | [diff] [blame] | 1451 | TestCheckForUpdate(); |
| 1452 | } |
Jae Hoon Kim | 51ea9ae | 2019-07-03 16:56:30 -0700 | [diff] [blame] | 1453 | } |
| 1454 | |
| 1455 | TEST_F(UpdateAttempterTest, CheckForUpdateOfficalBuildClearsSource) { |
| 1456 | // GIVEN a official build. |
| 1457 | |
| 1458 | // THEN we except forced app version + forced omaha url to be cleared. |
| 1459 | |
| 1460 | TestCheckForUpdate(); |
| 1461 | } |
| 1462 | |
| 1463 | TEST_F(UpdateAttempterTest, CheckForUpdateUnofficialBuildChangesSource) { |
Jae Hoon Kim | c437ea5 | 2019-07-11 11:20:38 -0700 | [diff] [blame] | 1464 | // GIVEN a nonofficial build with dev features enabled. |
Jae Hoon Kim | 51ea9ae | 2019-07-03 16:56:30 -0700 | [diff] [blame] | 1465 | cfu_params_.is_official_build = false; |
| 1466 | cfu_params_.are_dev_features_enabled = true; |
| 1467 | |
| 1468 | // THEN the forced app version + forced omaha url changes based on input. |
| 1469 | cfu_params_.expected_forced_app_version = cfu_params_.app_version; |
| 1470 | cfu_params_.expected_forced_omaha_url = cfu_params_.omaha_url; |
| 1471 | |
| 1472 | TestCheckForUpdate(); |
| 1473 | } |
| 1474 | |
| 1475 | TEST_F(UpdateAttempterTest, CheckForUpdateOfficialBuildScheduledAUTest) { |
| 1476 | // GIVEN a scheduled autest omaha url. |
| 1477 | cfu_params_.omaha_url = "autest-scheduled"; |
| 1478 | |
| 1479 | // THEN forced app version is cleared. |
| 1480 | // THEN forced omaha url changes to default constant. |
| 1481 | cfu_params_.expected_forced_omaha_url = constants::kOmahaDefaultAUTestURL; |
| 1482 | |
| 1483 | TestCheckForUpdate(); |
| 1484 | } |
| 1485 | |
| 1486 | TEST_F(UpdateAttempterTest, CheckForUpdateUnofficialBuildScheduledAUTest) { |
| 1487 | // GIVEN a scheduled autest omaha url. |
| 1488 | cfu_params_.omaha_url = "autest-scheduled"; |
Jae Hoon Kim | c437ea5 | 2019-07-11 11:20:38 -0700 | [diff] [blame] | 1489 | // GIVEN a nonofficial build with dev features enabled. |
Jae Hoon Kim | 51ea9ae | 2019-07-03 16:56:30 -0700 | [diff] [blame] | 1490 | cfu_params_.is_official_build = false; |
| 1491 | cfu_params_.are_dev_features_enabled = true; |
| 1492 | |
| 1493 | // THEN forced app version changes based on input. |
| 1494 | cfu_params_.expected_forced_app_version = cfu_params_.app_version; |
| 1495 | // THEN forced omaha url changes to default constant. |
| 1496 | cfu_params_.expected_forced_omaha_url = constants::kOmahaDefaultAUTestURL; |
| 1497 | |
| 1498 | TestCheckForUpdate(); |
| 1499 | } |
| 1500 | |
| 1501 | TEST_F(UpdateAttempterTest, CheckForUpdateOfficialBuildAUTest) { |
| 1502 | // GIVEN a autest omaha url. |
| 1503 | cfu_params_.omaha_url = "autest"; |
| 1504 | |
| 1505 | // THEN forced app version is cleared. |
| 1506 | // THEN forced omaha url changes to default constant. |
| 1507 | cfu_params_.expected_forced_omaha_url = constants::kOmahaDefaultAUTestURL; |
| 1508 | |
| 1509 | TestCheckForUpdate(); |
| 1510 | } |
| 1511 | |
| 1512 | TEST_F(UpdateAttempterTest, CheckForUpdateUnofficialBuildAUTest) { |
| 1513 | // GIVEN a autest omha url. |
| 1514 | cfu_params_.omaha_url = "autest"; |
Jae Hoon Kim | c437ea5 | 2019-07-11 11:20:38 -0700 | [diff] [blame] | 1515 | // GIVEN a nonofficial build with dev features enabled. |
Jae Hoon Kim | 51ea9ae | 2019-07-03 16:56:30 -0700 | [diff] [blame] | 1516 | cfu_params_.is_official_build = false; |
| 1517 | cfu_params_.are_dev_features_enabled = true; |
| 1518 | |
| 1519 | // THEN forced app version changes based on input. |
| 1520 | cfu_params_.expected_forced_app_version = cfu_params_.app_version; |
| 1521 | // THEN forced omaha url changes to default constant. |
| 1522 | cfu_params_.expected_forced_omaha_url = constants::kOmahaDefaultAUTestURL; |
| 1523 | |
| 1524 | TestCheckForUpdate(); |
| 1525 | } |
| 1526 | |
| 1527 | TEST_F(UpdateAttempterTest, |
| 1528 | CheckForUpdateNonInteractiveOfficialBuildScheduledAUTest) { |
| 1529 | // GIVEN a scheduled autest omaha url. |
| 1530 | cfu_params_.omaha_url = "autest-scheduled"; |
Jae Hoon Kim | c437ea5 | 2019-07-11 11:20:38 -0700 | [diff] [blame] | 1531 | // GIVEN a noninteractive update. |
Jae Hoon Kim | 51ea9ae | 2019-07-03 16:56:30 -0700 | [diff] [blame] | 1532 | cfu_params_.flags = UpdateAttemptFlags::kFlagNonInteractive; |
| 1533 | |
| 1534 | // THEN forced app version is cleared. |
| 1535 | // THEN forced omaha url changes to default constant. |
| 1536 | cfu_params_.expected_forced_omaha_url = constants::kOmahaDefaultAUTestURL; |
| 1537 | |
| 1538 | TestCheckForUpdate(); |
| 1539 | } |
| 1540 | |
| 1541 | TEST_F(UpdateAttempterTest, |
| 1542 | CheckForUpdateNonInteractiveUnofficialBuildScheduledAUTest) { |
| 1543 | // GIVEN a scheduled autest omaha url. |
| 1544 | cfu_params_.omaha_url = "autest-scheduled"; |
Jae Hoon Kim | c437ea5 | 2019-07-11 11:20:38 -0700 | [diff] [blame] | 1545 | // GIVEN a noninteractive update. |
Jae Hoon Kim | 51ea9ae | 2019-07-03 16:56:30 -0700 | [diff] [blame] | 1546 | cfu_params_.flags = UpdateAttemptFlags::kFlagNonInteractive; |
Jae Hoon Kim | c437ea5 | 2019-07-11 11:20:38 -0700 | [diff] [blame] | 1547 | // GIVEN a nonofficial build with dev features enabled. |
Jae Hoon Kim | 51ea9ae | 2019-07-03 16:56:30 -0700 | [diff] [blame] | 1548 | cfu_params_.is_official_build = false; |
| 1549 | cfu_params_.are_dev_features_enabled = true; |
| 1550 | |
| 1551 | // THEN forced app version changes based on input. |
| 1552 | cfu_params_.expected_forced_app_version = cfu_params_.app_version; |
| 1553 | // THEN forced omaha url changes to default constant. |
| 1554 | cfu_params_.expected_forced_omaha_url = constants::kOmahaDefaultAUTestURL; |
| 1555 | |
| 1556 | TestCheckForUpdate(); |
| 1557 | } |
| 1558 | |
| 1559 | TEST_F(UpdateAttempterTest, CheckForUpdateNonInteractiveOfficialBuildAUTest) { |
| 1560 | // GIVEN a autest omaha url. |
| 1561 | cfu_params_.omaha_url = "autest"; |
Jae Hoon Kim | c437ea5 | 2019-07-11 11:20:38 -0700 | [diff] [blame] | 1562 | // GIVEN a noninteractive update. |
Jae Hoon Kim | 51ea9ae | 2019-07-03 16:56:30 -0700 | [diff] [blame] | 1563 | cfu_params_.flags = UpdateAttemptFlags::kFlagNonInteractive; |
| 1564 | |
| 1565 | // THEN forced app version is cleared. |
| 1566 | // THEN forced omaha url changes to default constant. |
| 1567 | cfu_params_.expected_forced_omaha_url = constants::kOmahaDefaultAUTestURL; |
| 1568 | |
| 1569 | TestCheckForUpdate(); |
| 1570 | } |
| 1571 | |
| 1572 | TEST_F(UpdateAttempterTest, CheckForUpdateNonInteractiveUnofficialBuildAUTest) { |
| 1573 | // GIVEN a autest omaha url. |
| 1574 | cfu_params_.omaha_url = "autest"; |
Jae Hoon Kim | c437ea5 | 2019-07-11 11:20:38 -0700 | [diff] [blame] | 1575 | // GIVEN a noninteractive update. |
Jae Hoon Kim | 51ea9ae | 2019-07-03 16:56:30 -0700 | [diff] [blame] | 1576 | cfu_params_.flags = UpdateAttemptFlags::kFlagNonInteractive; |
Jae Hoon Kim | c437ea5 | 2019-07-11 11:20:38 -0700 | [diff] [blame] | 1577 | // GIVEN a nonofficial build with dev features enabled. |
Jae Hoon Kim | 51ea9ae | 2019-07-03 16:56:30 -0700 | [diff] [blame] | 1578 | cfu_params_.is_official_build = false; |
| 1579 | cfu_params_.are_dev_features_enabled = true; |
| 1580 | |
| 1581 | // THEN forced app version changes based on input. |
| 1582 | cfu_params_.expected_forced_app_version = cfu_params_.app_version; |
| 1583 | // THEN forced omaha url changes to default constant. |
| 1584 | cfu_params_.expected_forced_omaha_url = constants::kOmahaDefaultAUTestURL; |
| 1585 | |
| 1586 | TestCheckForUpdate(); |
David Pursell | 02c1864 | 2014-11-06 11:26:11 -0800 | [diff] [blame] | 1587 | } |
| 1588 | |
Jae Hoon Kim | 2b73ac2 | 2019-07-02 11:17:24 -0700 | [diff] [blame] | 1589 | TEST_F(UpdateAttempterTest, CheckForUpdateMissingForcedCallback1) { |
| 1590 | // GIVEN a official build. |
| 1591 | // GIVEN forced callback is not set. |
| 1592 | attempter_.set_forced_update_pending_callback(nullptr); |
| 1593 | |
| 1594 | // THEN we except forced app version + forced omaha url to be cleared. |
| 1595 | // THEN |ScheduleUpdates()| should not be called. |
| 1596 | cfu_params_.should_schedule_updates_be_called = false; |
| 1597 | |
| 1598 | TestCheckForUpdate(); |
| 1599 | } |
| 1600 | |
| 1601 | TEST_F(UpdateAttempterTest, CheckForUpdateMissingForcedCallback2) { |
Jae Hoon Kim | c437ea5 | 2019-07-11 11:20:38 -0700 | [diff] [blame] | 1602 | // GIVEN a nonofficial build with dev features enabled. |
Jae Hoon Kim | 2b73ac2 | 2019-07-02 11:17:24 -0700 | [diff] [blame] | 1603 | cfu_params_.is_official_build = false; |
| 1604 | cfu_params_.are_dev_features_enabled = true; |
| 1605 | // GIVEN forced callback is not set. |
| 1606 | attempter_.set_forced_update_pending_callback(nullptr); |
| 1607 | |
| 1608 | // THEN the forced app version + forced omaha url changes based on input. |
| 1609 | cfu_params_.expected_forced_app_version = cfu_params_.app_version; |
| 1610 | cfu_params_.expected_forced_omaha_url = cfu_params_.omaha_url; |
| 1611 | // THEN |ScheduleUpdates()| should not be called. |
| 1612 | cfu_params_.should_schedule_updates_be_called = false; |
| 1613 | |
| 1614 | TestCheckForUpdate(); |
| 1615 | } |
| 1616 | |
Xiaochu Liu | 88d9038 | 2018-08-29 16:09:11 -0700 | [diff] [blame] | 1617 | TEST_F(UpdateAttempterTest, CheckForInstallTest) { |
Amin Hassani | 538bd59 | 2020-11-04 20:46:08 -0800 | [diff] [blame] | 1618 | FakeSystemState::Get()->fake_hardware()->SetIsOfficialBuild(true); |
| 1619 | FakeSystemState::Get()->fake_hardware()->SetAreDevFeaturesEnabled(false); |
Xiaochu Liu | 88d9038 | 2018-08-29 16:09:11 -0700 | [diff] [blame] | 1620 | attempter_.CheckForInstall({}, "autest"); |
| 1621 | EXPECT_EQ(constants::kOmahaDefaultAUTestURL, attempter_.forced_omaha_url()); |
| 1622 | |
| 1623 | attempter_.CheckForInstall({}, "autest-scheduled"); |
| 1624 | EXPECT_EQ(constants::kOmahaDefaultAUTestURL, attempter_.forced_omaha_url()); |
| 1625 | |
| 1626 | attempter_.CheckForInstall({}, "http://omaha.phishing"); |
| 1627 | EXPECT_EQ("", attempter_.forced_omaha_url()); |
| 1628 | } |
| 1629 | |
Colin Howes | ac170d9 | 2018-11-20 16:29:28 -0800 | [diff] [blame] | 1630 | TEST_F(UpdateAttempterTest, InstallSetsStatusIdle) { |
| 1631 | attempter_.CheckForInstall({}, "http://foo.bar"); |
| 1632 | attempter_.status_ = UpdateStatus::DOWNLOADING; |
| 1633 | EXPECT_TRUE(attempter_.is_install_); |
| 1634 | attempter_.ProcessingDone(nullptr, ErrorCode::kSuccess); |
| 1635 | UpdateEngineStatus status; |
| 1636 | attempter_.GetStatus(&status); |
| 1637 | // Should set status to idle after an install operation. |
| 1638 | EXPECT_EQ(UpdateStatus::IDLE, status.status); |
| 1639 | } |
| 1640 | |
Colin Howes | 978c108 | 2018-12-03 11:46:12 -0800 | [diff] [blame] | 1641 | TEST_F(UpdateAttempterTest, RollbackAfterInstall) { |
| 1642 | attempter_.is_install_ = true; |
| 1643 | attempter_.Rollback(false); |
| 1644 | EXPECT_FALSE(attempter_.is_install_); |
| 1645 | } |
| 1646 | |
| 1647 | TEST_F(UpdateAttempterTest, UpdateAfterInstall) { |
| 1648 | attempter_.is_install_ = true; |
| 1649 | attempter_.CheckForUpdate("", "", UpdateAttemptFlags::kNone); |
| 1650 | EXPECT_FALSE(attempter_.is_install_); |
| 1651 | } |
| 1652 | |
Xiyuan Xia | c0e8f9a | 2017-02-22 13:19:35 -0800 | [diff] [blame] | 1653 | TEST_F(UpdateAttempterTest, TargetVersionPrefixSetAndReset) { |
Amin Hassani | e815363 | 2020-10-27 15:11:28 -0700 | [diff] [blame] | 1654 | UpdateCheckParams params; |
| 1655 | attempter_.CalculateUpdateParams({.target_version_prefix = "1234"}); |
Xiyuan Xia | c0e8f9a | 2017-02-22 13:19:35 -0800 | [diff] [blame] | 1656 | EXPECT_EQ("1234", |
Amin Hassani | 538bd59 | 2020-11-04 20:46:08 -0800 | [diff] [blame] | 1657 | FakeSystemState::Get()->request_params()->target_version_prefix()); |
Xiyuan Xia | c0e8f9a | 2017-02-22 13:19:35 -0800 | [diff] [blame] | 1658 | |
Amin Hassani | e815363 | 2020-10-27 15:11:28 -0700 | [diff] [blame] | 1659 | attempter_.CalculateUpdateParams({}); |
Amin Hassani | 538bd59 | 2020-11-04 20:46:08 -0800 | [diff] [blame] | 1660 | EXPECT_TRUE(FakeSystemState::Get() |
| 1661 | ->request_params() |
| 1662 | ->target_version_prefix() |
| 1663 | .empty()); |
Xiyuan Xia | c0e8f9a | 2017-02-22 13:19:35 -0800 | [diff] [blame] | 1664 | } |
| 1665 | |
Amin Hassani | 37b6723 | 2020-08-13 09:29:48 -0700 | [diff] [blame] | 1666 | TEST_F(UpdateAttempterTest, TargetChannelHintSetAndReset) { |
Amin Hassani | e815363 | 2020-10-27 15:11:28 -0700 | [diff] [blame] | 1667 | attempter_.CalculateUpdateParams({.lts_tag = "hint"}); |
Amin Hassani | 538bd59 | 2020-11-04 20:46:08 -0800 | [diff] [blame] | 1668 | EXPECT_EQ("hint", FakeSystemState::Get()->request_params()->lts_tag()); |
Amin Hassani | 37b6723 | 2020-08-13 09:29:48 -0700 | [diff] [blame] | 1669 | |
Amin Hassani | e815363 | 2020-10-27 15:11:28 -0700 | [diff] [blame] | 1670 | attempter_.CalculateUpdateParams({}); |
Amin Hassani | 538bd59 | 2020-11-04 20:46:08 -0800 | [diff] [blame] | 1671 | EXPECT_TRUE(FakeSystemState::Get()->request_params()->lts_tag().empty()); |
Amin Hassani | 37b6723 | 2020-08-13 09:29:48 -0700 | [diff] [blame] | 1672 | } |
| 1673 | |
Marton Hunyady | ba51c3f | 2018-04-25 15:18:10 +0200 | [diff] [blame] | 1674 | TEST_F(UpdateAttempterTest, RollbackAllowedSetAndReset) { |
Amin Hassani | e815363 | 2020-10-27 15:11:28 -0700 | [diff] [blame] | 1675 | attempter_.CalculateUpdateParams({ |
| 1676 | .target_version_prefix = "1234", |
| 1677 | .rollback_allowed = true, |
| 1678 | .rollback_allowed_milestones = 4, |
| 1679 | }); |
Amin Hassani | 538bd59 | 2020-11-04 20:46:08 -0800 | [diff] [blame] | 1680 | EXPECT_TRUE(FakeSystemState::Get()->request_params()->rollback_allowed()); |
| 1681 | EXPECT_EQ( |
| 1682 | 4, |
| 1683 | FakeSystemState::Get()->request_params()->rollback_allowed_milestones()); |
Marton Hunyady | ba51c3f | 2018-04-25 15:18:10 +0200 | [diff] [blame] | 1684 | |
Amin Hassani | e815363 | 2020-10-27 15:11:28 -0700 | [diff] [blame] | 1685 | attempter_.CalculateUpdateParams({ |
| 1686 | .target_version_prefix = "1234", |
| 1687 | .rollback_allowed_milestones = 4, |
| 1688 | }); |
Amin Hassani | 538bd59 | 2020-11-04 20:46:08 -0800 | [diff] [blame] | 1689 | EXPECT_FALSE(FakeSystemState::Get()->request_params()->rollback_allowed()); |
| 1690 | EXPECT_EQ( |
| 1691 | 4, |
| 1692 | FakeSystemState::Get()->request_params()->rollback_allowed_milestones()); |
Marton Hunyady | ba51c3f | 2018-04-25 15:18:10 +0200 | [diff] [blame] | 1693 | } |
| 1694 | |
Miriam Polzer | aff7200 | 2020-08-27 08:20:39 +0200 | [diff] [blame] | 1695 | TEST_F(UpdateAttempterTest, ChannelDowngradeNoRollback) { |
| 1696 | base::ScopedTempDir tempdir; |
| 1697 | ASSERT_TRUE(tempdir.CreateUniqueTempDir()); |
Amin Hassani | 538bd59 | 2020-11-04 20:46:08 -0800 | [diff] [blame] | 1698 | FakeSystemState::Get()->request_params()->set_root(tempdir.GetPath().value()); |
Amin Hassani | e815363 | 2020-10-27 15:11:28 -0700 | [diff] [blame] | 1699 | attempter_.CalculateUpdateParams({ |
| 1700 | .target_channel = "stable-channel", |
| 1701 | }); |
Amin Hassani | 538bd59 | 2020-11-04 20:46:08 -0800 | [diff] [blame] | 1702 | EXPECT_FALSE( |
| 1703 | FakeSystemState::Get()->request_params()->is_powerwash_allowed()); |
Miriam Polzer | aff7200 | 2020-08-27 08:20:39 +0200 | [diff] [blame] | 1704 | } |
| 1705 | |
| 1706 | TEST_F(UpdateAttempterTest, ChannelDowngradeRollback) { |
| 1707 | base::ScopedTempDir tempdir; |
| 1708 | ASSERT_TRUE(tempdir.CreateUniqueTempDir()); |
Amin Hassani | 538bd59 | 2020-11-04 20:46:08 -0800 | [diff] [blame] | 1709 | FakeSystemState::Get()->request_params()->set_root(tempdir.GetPath().value()); |
Amin Hassani | e815363 | 2020-10-27 15:11:28 -0700 | [diff] [blame] | 1710 | attempter_.CalculateUpdateParams({ |
| 1711 | .rollback_on_channel_downgrade = true, |
| 1712 | .target_channel = "stable-channel", |
| 1713 | }); |
Amin Hassani | 538bd59 | 2020-11-04 20:46:08 -0800 | [diff] [blame] | 1714 | EXPECT_TRUE(FakeSystemState::Get()->request_params()->is_powerwash_allowed()); |
Miriam Polzer | aff7200 | 2020-08-27 08:20:39 +0200 | [diff] [blame] | 1715 | } |
| 1716 | |
Aaron Wood | 23bd339 | 2017-10-06 14:48:25 -0700 | [diff] [blame] | 1717 | TEST_F(UpdateAttempterTest, UpdateDeferredByPolicyTest) { |
| 1718 | // Construct an OmahaResponseHandlerAction that has processed an InstallPlan, |
| 1719 | // but the update is being deferred by the Policy. |
Amin Hassani | 538bd59 | 2020-11-04 20:46:08 -0800 | [diff] [blame] | 1720 | OmahaResponseHandlerAction response_action; |
Amin Hassani | 68512d4 | 2018-07-31 23:52:33 -0700 | [diff] [blame] | 1721 | response_action.install_plan_.version = "a.b.c.d"; |
Amin Hassani | 68512d4 | 2018-07-31 23:52:33 -0700 | [diff] [blame] | 1722 | response_action.install_plan_.payloads.push_back( |
Aaron Wood | 23bd339 | 2017-10-06 14:48:25 -0700 | [diff] [blame] | 1723 | {.size = 1234ULL, .type = InstallPayloadType::kFull}); |
Aaron Wood | 23bd339 | 2017-10-06 14:48:25 -0700 | [diff] [blame] | 1724 | // Inform the UpdateAttempter that the OmahaResponseHandlerAction has |
| 1725 | // completed, with the deferred-update error code. |
| 1726 | attempter_.ActionCompleted( |
Amin Hassani | 68512d4 | 2018-07-31 23:52:33 -0700 | [diff] [blame] | 1727 | nullptr, &response_action, ErrorCode::kOmahaUpdateDeferredPerPolicy); |
Aaron Wood | 23bd339 | 2017-10-06 14:48:25 -0700 | [diff] [blame] | 1728 | { |
| 1729 | UpdateEngineStatus status; |
| 1730 | attempter_.GetStatus(&status); |
| 1731 | EXPECT_EQ(UpdateStatus::UPDATE_AVAILABLE, status.status); |
Amin Hassani | d3f4bea | 2018-04-30 14:52:40 -0700 | [diff] [blame] | 1732 | EXPECT_TRUE(attempter_.install_plan_); |
| 1733 | EXPECT_EQ(attempter_.install_plan_->version, status.new_version); |
Amin Hassani | d3f4bea | 2018-04-30 14:52:40 -0700 | [diff] [blame] | 1734 | EXPECT_EQ(attempter_.install_plan_->payloads[0].size, |
Aaron Wood | 23bd339 | 2017-10-06 14:48:25 -0700 | [diff] [blame] | 1735 | status.new_size_bytes); |
| 1736 | } |
| 1737 | // An "error" event should have been created to tell Omaha that the update is |
| 1738 | // being deferred. |
| 1739 | EXPECT_TRUE(nullptr != attempter_.error_event_); |
| 1740 | EXPECT_EQ(OmahaEvent::kTypeUpdateComplete, attempter_.error_event_->type); |
| 1741 | EXPECT_EQ(OmahaEvent::kResultUpdateDeferred, attempter_.error_event_->result); |
| 1742 | ErrorCode expected_code = static_cast<ErrorCode>( |
| 1743 | static_cast<int>(ErrorCode::kOmahaUpdateDeferredPerPolicy) | |
| 1744 | static_cast<int>(ErrorCode::kTestOmahaUrlFlag)); |
| 1745 | EXPECT_EQ(expected_code, attempter_.error_event_->error_code); |
| 1746 | // End the processing |
| 1747 | attempter_.ProcessingDone(nullptr, ErrorCode::kOmahaUpdateDeferredPerPolicy); |
| 1748 | // Validate the state of the attempter. |
| 1749 | { |
| 1750 | UpdateEngineStatus status; |
| 1751 | attempter_.GetStatus(&status); |
| 1752 | EXPECT_EQ(UpdateStatus::REPORTING_ERROR_EVENT, status.status); |
Amin Hassani | 68512d4 | 2018-07-31 23:52:33 -0700 | [diff] [blame] | 1753 | EXPECT_EQ(response_action.install_plan_.version, status.new_version); |
Amin Hassani | 68512d4 | 2018-07-31 23:52:33 -0700 | [diff] [blame] | 1754 | EXPECT_EQ(response_action.install_plan_.payloads[0].size, |
Aaron Wood | 23bd339 | 2017-10-06 14:48:25 -0700 | [diff] [blame] | 1755 | status.new_size_bytes); |
| 1756 | } |
| 1757 | } |
| 1758 | |
| 1759 | TEST_F(UpdateAttempterTest, UpdateIsNotRunningWhenUpdateAvailable) { |
Jae Hoon Kim | 75daa38 | 2019-07-02 11:17:24 -0700 | [diff] [blame] | 1760 | // Default construction for |waiting_for_scheduled_check_| is false. |
Jae Hoon Kim | ba2fdce | 2019-07-11 13:18:58 -0700 | [diff] [blame] | 1761 | EXPECT_FALSE(attempter_.IsBusyOrUpdateScheduled()); |
Aaron Wood | 23bd339 | 2017-10-06 14:48:25 -0700 | [diff] [blame] | 1762 | // Verify in-progress update with UPDATE_AVAILABLE is running |
| 1763 | attempter_.status_ = UpdateStatus::UPDATE_AVAILABLE; |
Jae Hoon Kim | ba2fdce | 2019-07-11 13:18:58 -0700 | [diff] [blame] | 1764 | EXPECT_TRUE(attempter_.IsBusyOrUpdateScheduled()); |
Aaron Wood | 23bd339 | 2017-10-06 14:48:25 -0700 | [diff] [blame] | 1765 | } |
| 1766 | |
Aaron Wood | bf5a252 | 2017-10-04 10:58:36 -0700 | [diff] [blame] | 1767 | TEST_F(UpdateAttempterTest, UpdateAttemptFlagsCachedAtUpdateStart) { |
| 1768 | attempter_.SetUpdateAttemptFlags(UpdateAttemptFlags::kFlagRestrictDownload); |
| 1769 | |
| 1770 | UpdateCheckParams params = {.updates_enabled = true}; |
| 1771 | attempter_.OnUpdateScheduled(EvalStatus::kSucceeded, params); |
| 1772 | |
| 1773 | EXPECT_EQ(UpdateAttemptFlags::kFlagRestrictDownload, |
| 1774 | attempter_.GetCurrentUpdateAttemptFlags()); |
| 1775 | } |
| 1776 | |
Marton Hunyady | ba51c3f | 2018-04-25 15:18:10 +0200 | [diff] [blame] | 1777 | TEST_F(UpdateAttempterTest, RollbackNotAllowed) { |
| 1778 | UpdateCheckParams params = {.updates_enabled = true, |
| 1779 | .rollback_allowed = false}; |
| 1780 | attempter_.OnUpdateScheduled(EvalStatus::kSucceeded, params); |
Amin Hassani | 538bd59 | 2020-11-04 20:46:08 -0800 | [diff] [blame] | 1781 | EXPECT_FALSE(FakeSystemState::Get()->request_params()->rollback_allowed()); |
Marton Hunyady | ba51c3f | 2018-04-25 15:18:10 +0200 | [diff] [blame] | 1782 | } |
| 1783 | |
| 1784 | TEST_F(UpdateAttempterTest, RollbackAllowed) { |
| 1785 | UpdateCheckParams params = {.updates_enabled = true, |
| 1786 | .rollback_allowed = true}; |
| 1787 | attempter_.OnUpdateScheduled(EvalStatus::kSucceeded, params); |
Amin Hassani | 538bd59 | 2020-11-04 20:46:08 -0800 | [diff] [blame] | 1788 | EXPECT_TRUE(FakeSystemState::Get()->request_params()->rollback_allowed()); |
Marton Hunyady | ba51c3f | 2018-04-25 15:18:10 +0200 | [diff] [blame] | 1789 | } |
| 1790 | |
Aaron Wood | 081c023 | 2017-10-19 17:14:58 -0700 | [diff] [blame] | 1791 | TEST_F(UpdateAttempterTest, InteractiveUpdateUsesPassedRestrictions) { |
| 1792 | attempter_.SetUpdateAttemptFlags(UpdateAttemptFlags::kFlagRestrictDownload); |
| 1793 | |
| 1794 | attempter_.CheckForUpdate("", "", UpdateAttemptFlags::kNone); |
| 1795 | EXPECT_EQ(UpdateAttemptFlags::kNone, |
| 1796 | attempter_.GetCurrentUpdateAttemptFlags()); |
| 1797 | } |
| 1798 | |
| 1799 | TEST_F(UpdateAttempterTest, NonInteractiveUpdateUsesSetRestrictions) { |
| 1800 | attempter_.SetUpdateAttemptFlags(UpdateAttemptFlags::kNone); |
| 1801 | |
| 1802 | // This tests that when CheckForUpdate() is called with the non-interactive |
| 1803 | // flag set, that it doesn't change the current UpdateAttemptFlags. |
| 1804 | attempter_.CheckForUpdate("", |
| 1805 | "", |
| 1806 | UpdateAttemptFlags::kFlagNonInteractive | |
| 1807 | UpdateAttemptFlags::kFlagRestrictDownload); |
| 1808 | EXPECT_EQ(UpdateAttemptFlags::kNone, |
| 1809 | attempter_.GetCurrentUpdateAttemptFlags()); |
| 1810 | } |
| 1811 | |
Marton Hunyady | e58bddb | 2018-04-10 20:27:26 +0200 | [diff] [blame] | 1812 | void UpdateAttempterTest::ResetRollbackHappenedStart(bool is_consumer, |
| 1813 | bool is_policy_loaded, |
| 1814 | bool expected_reset) { |
Amin Hassani | 538bd59 | 2020-11-04 20:46:08 -0800 | [diff] [blame] | 1815 | EXPECT_CALL(*FakeSystemState::Get()->mock_payload_state(), |
| 1816 | GetRollbackHappened()) |
Marton Hunyady | e58bddb | 2018-04-10 20:27:26 +0200 | [diff] [blame] | 1817 | .WillRepeatedly(Return(true)); |
| 1818 | auto mock_policy_provider = |
| 1819 | std::make_unique<NiceMock<policy::MockPolicyProvider>>(); |
| 1820 | EXPECT_CALL(*mock_policy_provider, IsConsumerDevice()) |
| 1821 | .WillRepeatedly(Return(is_consumer)); |
| 1822 | EXPECT_CALL(*mock_policy_provider, device_policy_is_loaded()) |
| 1823 | .WillRepeatedly(Return(is_policy_loaded)); |
| 1824 | const policy::MockDevicePolicy device_policy; |
| 1825 | EXPECT_CALL(*mock_policy_provider, GetDevicePolicy()) |
| 1826 | .WillRepeatedly(ReturnRef(device_policy)); |
Amin Hassani | 538bd59 | 2020-11-04 20:46:08 -0800 | [diff] [blame] | 1827 | EXPECT_CALL(*FakeSystemState::Get()->mock_payload_state(), |
Marton Hunyady | e58bddb | 2018-04-10 20:27:26 +0200 | [diff] [blame] | 1828 | SetRollbackHappened(false)) |
| 1829 | .Times(expected_reset ? 1 : 0); |
| 1830 | attempter_.policy_provider_ = std::move(mock_policy_provider); |
Amin Hassani | e815363 | 2020-10-27 15:11:28 -0700 | [diff] [blame] | 1831 | attempter_.Update({}); |
Marton Hunyady | e58bddb | 2018-04-10 20:27:26 +0200 | [diff] [blame] | 1832 | ScheduleQuitMainLoop(); |
| 1833 | } |
| 1834 | |
| 1835 | TEST_F(UpdateAttempterTest, ResetRollbackHappenedOobe) { |
| 1836 | loop_.PostTask(FROM_HERE, |
| 1837 | base::Bind(&UpdateAttempterTest::ResetRollbackHappenedStart, |
| 1838 | base::Unretained(this), |
| 1839 | /*is_consumer=*/false, |
| 1840 | /*is_policy_loaded=*/false, |
| 1841 | /*expected_reset=*/false)); |
| 1842 | loop_.Run(); |
| 1843 | } |
| 1844 | |
| 1845 | TEST_F(UpdateAttempterTest, ResetRollbackHappenedConsumer) { |
| 1846 | loop_.PostTask(FROM_HERE, |
| 1847 | base::Bind(&UpdateAttempterTest::ResetRollbackHappenedStart, |
| 1848 | base::Unretained(this), |
| 1849 | /*is_consumer=*/true, |
| 1850 | /*is_policy_loaded=*/false, |
| 1851 | /*expected_reset=*/true)); |
| 1852 | loop_.Run(); |
| 1853 | } |
| 1854 | |
| 1855 | TEST_F(UpdateAttempterTest, ResetRollbackHappenedEnterprise) { |
| 1856 | loop_.PostTask(FROM_HERE, |
| 1857 | base::Bind(&UpdateAttempterTest::ResetRollbackHappenedStart, |
| 1858 | base::Unretained(this), |
| 1859 | /*is_consumer=*/false, |
| 1860 | /*is_policy_loaded=*/true, |
| 1861 | /*expected_reset=*/true)); |
| 1862 | loop_.Run(); |
| 1863 | } |
| 1864 | |
Marton Hunyady | 199152d | 2018-05-07 19:08:48 +0200 | [diff] [blame] | 1865 | TEST_F(UpdateAttempterTest, SetRollbackHappenedRollback) { |
Amin Hassani | d3f4bea | 2018-04-30 14:52:40 -0700 | [diff] [blame] | 1866 | attempter_.install_plan_.reset(new InstallPlan); |
| 1867 | attempter_.install_plan_->is_rollback = true; |
Marton Hunyady | 199152d | 2018-05-07 19:08:48 +0200 | [diff] [blame] | 1868 | |
Amin Hassani | 538bd59 | 2020-11-04 20:46:08 -0800 | [diff] [blame] | 1869 | EXPECT_CALL(*FakeSystemState::Get()->mock_payload_state(), |
Marton Hunyady | 199152d | 2018-05-07 19:08:48 +0200 | [diff] [blame] | 1870 | SetRollbackHappened(true)) |
| 1871 | .Times(1); |
| 1872 | attempter_.ProcessingDone(nullptr, ErrorCode::kSuccess); |
| 1873 | } |
| 1874 | |
| 1875 | TEST_F(UpdateAttempterTest, SetRollbackHappenedNotRollback) { |
Amin Hassani | d3f4bea | 2018-04-30 14:52:40 -0700 | [diff] [blame] | 1876 | attempter_.install_plan_.reset(new InstallPlan); |
| 1877 | attempter_.install_plan_->is_rollback = false; |
Marton Hunyady | 199152d | 2018-05-07 19:08:48 +0200 | [diff] [blame] | 1878 | |
Amin Hassani | 538bd59 | 2020-11-04 20:46:08 -0800 | [diff] [blame] | 1879 | EXPECT_CALL(*FakeSystemState::Get()->mock_payload_state(), |
Marton Hunyady | 199152d | 2018-05-07 19:08:48 +0200 | [diff] [blame] | 1880 | SetRollbackHappened(true)) |
| 1881 | .Times(0); |
| 1882 | attempter_.ProcessingDone(nullptr, ErrorCode::kSuccess); |
| 1883 | } |
| 1884 | |
Marton Hunyady | a030268 | 2018-05-16 18:52:13 +0200 | [diff] [blame] | 1885 | TEST_F(UpdateAttempterTest, RollbackMetricsRollbackSuccess) { |
Amin Hassani | d3f4bea | 2018-04-30 14:52:40 -0700 | [diff] [blame] | 1886 | attempter_.install_plan_.reset(new InstallPlan); |
| 1887 | attempter_.install_plan_->is_rollback = true; |
| 1888 | attempter_.install_plan_->version = kRollbackVersion; |
Marton Hunyady | a030268 | 2018-05-16 18:52:13 +0200 | [diff] [blame] | 1889 | |
Amin Hassani | 538bd59 | 2020-11-04 20:46:08 -0800 | [diff] [blame] | 1890 | EXPECT_CALL(*FakeSystemState::Get()->mock_metrics_reporter(), |
Marton Hunyady | a030268 | 2018-05-16 18:52:13 +0200 | [diff] [blame] | 1891 | ReportEnterpriseRollbackMetrics(true, kRollbackVersion)) |
| 1892 | .Times(1); |
| 1893 | attempter_.ProcessingDone(nullptr, ErrorCode::kSuccess); |
| 1894 | } |
| 1895 | |
| 1896 | TEST_F(UpdateAttempterTest, RollbackMetricsNotRollbackSuccess) { |
Amin Hassani | d3f4bea | 2018-04-30 14:52:40 -0700 | [diff] [blame] | 1897 | attempter_.install_plan_.reset(new InstallPlan); |
| 1898 | attempter_.install_plan_->is_rollback = false; |
| 1899 | attempter_.install_plan_->version = kRollbackVersion; |
Marton Hunyady | a030268 | 2018-05-16 18:52:13 +0200 | [diff] [blame] | 1900 | |
Amin Hassani | 538bd59 | 2020-11-04 20:46:08 -0800 | [diff] [blame] | 1901 | EXPECT_CALL(*FakeSystemState::Get()->mock_metrics_reporter(), |
Marton Hunyady | a030268 | 2018-05-16 18:52:13 +0200 | [diff] [blame] | 1902 | ReportEnterpriseRollbackMetrics(_, _)) |
| 1903 | .Times(0); |
| 1904 | attempter_.ProcessingDone(nullptr, ErrorCode::kSuccess); |
| 1905 | } |
| 1906 | |
| 1907 | TEST_F(UpdateAttempterTest, RollbackMetricsRollbackFailure) { |
Amin Hassani | d3f4bea | 2018-04-30 14:52:40 -0700 | [diff] [blame] | 1908 | attempter_.install_plan_.reset(new InstallPlan); |
| 1909 | attempter_.install_plan_->is_rollback = true; |
| 1910 | attempter_.install_plan_->version = kRollbackVersion; |
Marton Hunyady | a030268 | 2018-05-16 18:52:13 +0200 | [diff] [blame] | 1911 | |
Amin Hassani | 538bd59 | 2020-11-04 20:46:08 -0800 | [diff] [blame] | 1912 | EXPECT_CALL(*FakeSystemState::Get()->mock_metrics_reporter(), |
Marton Hunyady | a030268 | 2018-05-16 18:52:13 +0200 | [diff] [blame] | 1913 | ReportEnterpriseRollbackMetrics(false, kRollbackVersion)) |
| 1914 | .Times(1); |
| 1915 | MockAction action; |
| 1916 | attempter_.CreatePendingErrorEvent(&action, ErrorCode::kRollbackNotPossible); |
| 1917 | attempter_.ProcessingDone(nullptr, ErrorCode::kRollbackNotPossible); |
| 1918 | } |
| 1919 | |
| 1920 | TEST_F(UpdateAttempterTest, RollbackMetricsNotRollbackFailure) { |
Amin Hassani | d3f4bea | 2018-04-30 14:52:40 -0700 | [diff] [blame] | 1921 | attempter_.install_plan_.reset(new InstallPlan); |
| 1922 | attempter_.install_plan_->is_rollback = false; |
| 1923 | attempter_.install_plan_->version = kRollbackVersion; |
Marton Hunyady | a030268 | 2018-05-16 18:52:13 +0200 | [diff] [blame] | 1924 | |
Amin Hassani | 538bd59 | 2020-11-04 20:46:08 -0800 | [diff] [blame] | 1925 | EXPECT_CALL(*FakeSystemState::Get()->mock_metrics_reporter(), |
Marton Hunyady | a030268 | 2018-05-16 18:52:13 +0200 | [diff] [blame] | 1926 | ReportEnterpriseRollbackMetrics(_, _)) |
| 1927 | .Times(0); |
| 1928 | MockAction action; |
| 1929 | attempter_.CreatePendingErrorEvent(&action, ErrorCode::kRollbackNotPossible); |
| 1930 | attempter_.ProcessingDone(nullptr, ErrorCode::kRollbackNotPossible); |
| 1931 | } |
| 1932 | |
May Lippert | 60aa3ca | 2018-08-15 16:55:29 -0700 | [diff] [blame] | 1933 | TEST_F(UpdateAttempterTest, TimeToUpdateAppliedMetricFailure) { |
Amin Hassani | 538bd59 | 2020-11-04 20:46:08 -0800 | [diff] [blame] | 1934 | EXPECT_CALL(*FakeSystemState::Get()->mock_metrics_reporter(), |
May Lippert | 60aa3ca | 2018-08-15 16:55:29 -0700 | [diff] [blame] | 1935 | ReportEnterpriseUpdateSeenToDownloadDays(_, _)) |
| 1936 | .Times(0); |
| 1937 | attempter_.ProcessingDone(nullptr, ErrorCode::kOmahaUpdateDeferredPerPolicy); |
| 1938 | } |
| 1939 | |
| 1940 | TEST_F(UpdateAttempterTest, TimeToUpdateAppliedOnNonEnterprise) { |
| 1941 | auto device_policy = std::make_unique<policy::MockDevicePolicy>(); |
Amin Hassani | 538bd59 | 2020-11-04 20:46:08 -0800 | [diff] [blame] | 1942 | FakeSystemState::Get()->set_device_policy(device_policy.get()); |
May Lippert | 60aa3ca | 2018-08-15 16:55:29 -0700 | [diff] [blame] | 1943 | // Make device policy return that this is not enterprise enrolled |
| 1944 | EXPECT_CALL(*device_policy, IsEnterpriseEnrolled()).WillOnce(Return(false)); |
| 1945 | |
| 1946 | // Ensure that the metric is not recorded. |
Amin Hassani | 538bd59 | 2020-11-04 20:46:08 -0800 | [diff] [blame] | 1947 | EXPECT_CALL(*FakeSystemState::Get()->mock_metrics_reporter(), |
May Lippert | 60aa3ca | 2018-08-15 16:55:29 -0700 | [diff] [blame] | 1948 | ReportEnterpriseUpdateSeenToDownloadDays(_, _)) |
| 1949 | .Times(0); |
| 1950 | attempter_.ProcessingDone(nullptr, ErrorCode::kSuccess); |
| 1951 | } |
| 1952 | |
| 1953 | TEST_F(UpdateAttempterTest, |
| 1954 | TimeToUpdateAppliedWithTimeRestrictionMetricSuccess) { |
| 1955 | constexpr int kDaysToUpdate = 15; |
| 1956 | auto device_policy = std::make_unique<policy::MockDevicePolicy>(); |
Amin Hassani | 538bd59 | 2020-11-04 20:46:08 -0800 | [diff] [blame] | 1957 | FakeSystemState::Get()->set_device_policy(device_policy.get()); |
May Lippert | 60aa3ca | 2018-08-15 16:55:29 -0700 | [diff] [blame] | 1958 | // Make device policy return that this is enterprise enrolled |
| 1959 | EXPECT_CALL(*device_policy, IsEnterpriseEnrolled()).WillOnce(Return(true)); |
| 1960 | // Pretend that there's a time restriction policy in place |
| 1961 | EXPECT_CALL(*device_policy, GetDisallowedTimeIntervals(_)) |
| 1962 | .WillOnce(Return(true)); |
| 1963 | |
| 1964 | FakePrefs fake_prefs; |
| 1965 | Time update_first_seen_at = Time::Now(); |
| 1966 | fake_prefs.SetInt64(kPrefsUpdateFirstSeenAt, |
| 1967 | update_first_seen_at.ToInternalValue()); |
| 1968 | |
| 1969 | FakeClock fake_clock; |
| 1970 | Time update_finished_at = |
| 1971 | update_first_seen_at + TimeDelta::FromDays(kDaysToUpdate); |
| 1972 | fake_clock.SetWallclockTime(update_finished_at); |
| 1973 | |
Amin Hassani | 538bd59 | 2020-11-04 20:46:08 -0800 | [diff] [blame] | 1974 | FakeSystemState::Get()->set_clock(&fake_clock); |
| 1975 | FakeSystemState::Get()->set_prefs(&fake_prefs); |
May Lippert | 60aa3ca | 2018-08-15 16:55:29 -0700 | [diff] [blame] | 1976 | |
Amin Hassani | 538bd59 | 2020-11-04 20:46:08 -0800 | [diff] [blame] | 1977 | EXPECT_CALL(*FakeSystemState::Get()->mock_metrics_reporter(), |
May Lippert | 60aa3ca | 2018-08-15 16:55:29 -0700 | [diff] [blame] | 1978 | ReportEnterpriseUpdateSeenToDownloadDays(true, kDaysToUpdate)) |
| 1979 | .Times(1); |
| 1980 | attempter_.ProcessingDone(nullptr, ErrorCode::kSuccess); |
| 1981 | } |
| 1982 | |
| 1983 | TEST_F(UpdateAttempterTest, |
| 1984 | TimeToUpdateAppliedWithoutTimeRestrictionMetricSuccess) { |
| 1985 | constexpr int kDaysToUpdate = 15; |
| 1986 | auto device_policy = std::make_unique<policy::MockDevicePolicy>(); |
Amin Hassani | 538bd59 | 2020-11-04 20:46:08 -0800 | [diff] [blame] | 1987 | FakeSystemState::Get()->set_device_policy(device_policy.get()); |
May Lippert | 60aa3ca | 2018-08-15 16:55:29 -0700 | [diff] [blame] | 1988 | // Make device policy return that this is enterprise enrolled |
| 1989 | EXPECT_CALL(*device_policy, IsEnterpriseEnrolled()).WillOnce(Return(true)); |
| 1990 | // Pretend that there's no time restriction policy in place |
| 1991 | EXPECT_CALL(*device_policy, GetDisallowedTimeIntervals(_)) |
| 1992 | .WillOnce(Return(false)); |
| 1993 | |
| 1994 | FakePrefs fake_prefs; |
| 1995 | Time update_first_seen_at = Time::Now(); |
| 1996 | fake_prefs.SetInt64(kPrefsUpdateFirstSeenAt, |
| 1997 | update_first_seen_at.ToInternalValue()); |
| 1998 | |
| 1999 | FakeClock fake_clock; |
| 2000 | Time update_finished_at = |
| 2001 | update_first_seen_at + TimeDelta::FromDays(kDaysToUpdate); |
| 2002 | fake_clock.SetWallclockTime(update_finished_at); |
| 2003 | |
Amin Hassani | 538bd59 | 2020-11-04 20:46:08 -0800 | [diff] [blame] | 2004 | FakeSystemState::Get()->set_clock(&fake_clock); |
| 2005 | FakeSystemState::Get()->set_prefs(&fake_prefs); |
May Lippert | 60aa3ca | 2018-08-15 16:55:29 -0700 | [diff] [blame] | 2006 | |
Amin Hassani | 538bd59 | 2020-11-04 20:46:08 -0800 | [diff] [blame] | 2007 | EXPECT_CALL(*FakeSystemState::Get()->mock_metrics_reporter(), |
May Lippert | 60aa3ca | 2018-08-15 16:55:29 -0700 | [diff] [blame] | 2008 | ReportEnterpriseUpdateSeenToDownloadDays(false, kDaysToUpdate)) |
| 2009 | .Times(1); |
| 2010 | attempter_.ProcessingDone(nullptr, ErrorCode::kSuccess); |
| 2011 | } |
| 2012 | |
Jae Hoon Kim | ed3fcc0 | 2019-07-11 14:35:38 -0700 | [diff] [blame] | 2013 | TEST_F(UpdateAttempterTest, ProcessingDoneUpdated) { |
| 2014 | // GIVEN an update finished. |
| 2015 | |
Jae Hoon Kim | 7fdfbf1 | 2020-04-10 18:15:50 -0700 | [diff] [blame] | 2016 | // THEN update_engine should call update completion. |
| 2017 | pd_params_.should_update_completed_be_called = true; |
| 2018 | // THEN need reboot since update applied. |
| 2019 | pd_params_.expected_exit_status = UpdateStatus::UPDATED_NEED_REBOOT; |
| 2020 | // THEN install indication should be false. |
| 2021 | |
| 2022 | TestProcessingDone(); |
| 2023 | } |
| 2024 | |
| 2025 | TEST_F(UpdateAttempterTest, ProcessingDoneUpdatedDlcFilter) { |
| 2026 | // GIVEN an update finished. |
| 2027 | // GIVEN DLC |AppParams| list. |
| 2028 | auto dlc_1 = "dlc_1", dlc_2 = "dlc_2"; |
| 2029 | pd_params_.dlc_apps_params = {{dlc_1, {.name = dlc_1, .updated = false}}, |
| 2030 | {dlc_2, {.name = dlc_2}}}; |
| 2031 | |
| 2032 | // THEN update_engine should call update completion. |
| 2033 | pd_params_.should_update_completed_be_called = true; |
| 2034 | pd_params_.args_to_update_completed = {dlc_2}; |
Jae Hoon Kim | ed3fcc0 | 2019-07-11 14:35:38 -0700 | [diff] [blame] | 2035 | // THEN need reboot since update applied. |
| 2036 | pd_params_.expected_exit_status = UpdateStatus::UPDATED_NEED_REBOOT; |
| 2037 | // THEN install indication should be false. |
| 2038 | |
| 2039 | TestProcessingDone(); |
| 2040 | } |
| 2041 | |
| 2042 | TEST_F(UpdateAttempterTest, ProcessingDoneInstalled) { |
| 2043 | // GIVEN an install finished. |
| 2044 | pd_params_.is_install = true; |
| 2045 | |
Jae Hoon Kim | 7fdfbf1 | 2020-04-10 18:15:50 -0700 | [diff] [blame] | 2046 | // THEN update_engine should call install completion. |
| 2047 | pd_params_.should_install_completed_be_called = true; |
| 2048 | // THEN go idle. |
| 2049 | // THEN install indication should be false. |
| 2050 | |
| 2051 | TestProcessingDone(); |
| 2052 | } |
| 2053 | |
| 2054 | TEST_F(UpdateAttempterTest, ProcessingDoneInstalledDlcFilter) { |
| 2055 | // GIVEN an install finished. |
| 2056 | pd_params_.is_install = true; |
| 2057 | // GIVEN DLC |AppParams| list. |
| 2058 | auto dlc_1 = "dlc_1", dlc_2 = "dlc_2"; |
| 2059 | pd_params_.dlc_apps_params = {{dlc_1, {.name = dlc_1, .updated = false}}, |
| 2060 | {dlc_2, {.name = dlc_2}}}; |
| 2061 | |
| 2062 | // THEN update_engine should call install completion. |
| 2063 | pd_params_.should_install_completed_be_called = true; |
| 2064 | pd_params_.args_to_install_completed = {dlc_2}; |
Jae Hoon Kim | ed3fcc0 | 2019-07-11 14:35:38 -0700 | [diff] [blame] | 2065 | // THEN go idle. |
| 2066 | // THEN install indication should be false. |
| 2067 | |
| 2068 | TestProcessingDone(); |
| 2069 | } |
| 2070 | |
| 2071 | TEST_F(UpdateAttempterTest, ProcessingDoneInstallReportingError) { |
| 2072 | // GIVEN an install finished. |
| 2073 | pd_params_.is_install = true; |
| 2074 | // GIVEN a reporting error occurred. |
| 2075 | pd_params_.status = UpdateStatus::REPORTING_ERROR_EVENT; |
| 2076 | |
Jae Hoon Kim | 7fdfbf1 | 2020-04-10 18:15:50 -0700 | [diff] [blame] | 2077 | // THEN update_engine should not call install completion. |
Jae Hoon Kim | ed3fcc0 | 2019-07-11 14:35:38 -0700 | [diff] [blame] | 2078 | // THEN go idle. |
| 2079 | // THEN install indication should be false. |
| 2080 | |
| 2081 | TestProcessingDone(); |
| 2082 | } |
| 2083 | |
| 2084 | TEST_F(UpdateAttempterTest, ProcessingDoneNoUpdate) { |
| 2085 | // GIVEN an update finished. |
| 2086 | // GIVEN an action error occured. |
| 2087 | pd_params_.code = ErrorCode::kNoUpdate; |
| 2088 | |
Jae Hoon Kim | 7fdfbf1 | 2020-04-10 18:15:50 -0700 | [diff] [blame] | 2089 | // THEN update_engine should not call update completion. |
Jae Hoon Kim | ed3fcc0 | 2019-07-11 14:35:38 -0700 | [diff] [blame] | 2090 | // THEN go idle. |
| 2091 | // THEN install indication should be false. |
| 2092 | |
| 2093 | TestProcessingDone(); |
| 2094 | } |
| 2095 | |
| 2096 | TEST_F(UpdateAttempterTest, ProcessingDoneNoInstall) { |
| 2097 | // GIVEN an install finished. |
| 2098 | pd_params_.is_install = true; |
| 2099 | // GIVEN an action error occured. |
| 2100 | pd_params_.code = ErrorCode::kNoUpdate; |
| 2101 | |
Jae Hoon Kim | 7fdfbf1 | 2020-04-10 18:15:50 -0700 | [diff] [blame] | 2102 | // THEN update_engine should not call install completion. |
Jae Hoon Kim | ed3fcc0 | 2019-07-11 14:35:38 -0700 | [diff] [blame] | 2103 | // THEN go idle. |
| 2104 | // THEN install indication should be false. |
| 2105 | |
| 2106 | TestProcessingDone(); |
| 2107 | } |
| 2108 | |
| 2109 | TEST_F(UpdateAttempterTest, ProcessingDoneUpdateError) { |
| 2110 | // GIVEN an update finished. |
| 2111 | // GIVEN an action error occured. |
| 2112 | pd_params_.code = ErrorCode::kError; |
| 2113 | // GIVEN an event error is set. |
| 2114 | attempter_.error_event_.reset(new OmahaEvent(OmahaEvent::kTypeUpdateComplete, |
| 2115 | OmahaEvent::kResultError, |
| 2116 | ErrorCode::kError)); |
| 2117 | |
| 2118 | // THEN indicate a error event. |
| 2119 | pd_params_.expected_exit_status = UpdateStatus::REPORTING_ERROR_EVENT; |
| 2120 | // THEN install indication should be false. |
| 2121 | |
Jae Hoon Kim | 7fdfbf1 | 2020-04-10 18:15:50 -0700 | [diff] [blame] | 2122 | // THEN update_engine should not call update completion. |
Jae Hoon Kim | ed3fcc0 | 2019-07-11 14:35:38 -0700 | [diff] [blame] | 2123 | // THEN expect critical actions of |ScheduleErrorEventAction()|. |
| 2124 | EXPECT_CALL(*processor_, EnqueueAction(Pointee(_))).Times(1); |
| 2125 | EXPECT_CALL(*processor_, StartProcessing()).Times(1); |
| 2126 | // THEN |ScheduleUpdates()| will be called next |ProcessingDone()| so skip. |
| 2127 | pd_params_.should_schedule_updates_be_called = false; |
| 2128 | |
| 2129 | TestProcessingDone(); |
| 2130 | } |
| 2131 | |
| 2132 | TEST_F(UpdateAttempterTest, ProcessingDoneInstallError) { |
| 2133 | // GIVEN an install finished. |
| 2134 | pd_params_.is_install = true; |
| 2135 | // GIVEN an action error occured. |
| 2136 | pd_params_.code = ErrorCode::kError; |
| 2137 | // GIVEN an event error is set. |
| 2138 | attempter_.error_event_.reset(new OmahaEvent(OmahaEvent::kTypeUpdateComplete, |
| 2139 | OmahaEvent::kResultError, |
| 2140 | ErrorCode::kError)); |
| 2141 | |
| 2142 | // THEN indicate a error event. |
| 2143 | pd_params_.expected_exit_status = UpdateStatus::REPORTING_ERROR_EVENT; |
| 2144 | // THEN install indication should be false. |
| 2145 | |
Jae Hoon Kim | 7fdfbf1 | 2020-04-10 18:15:50 -0700 | [diff] [blame] | 2146 | // THEN update_engine should not call install completion. |
Jae Hoon Kim | ed3fcc0 | 2019-07-11 14:35:38 -0700 | [diff] [blame] | 2147 | // THEN expect critical actions of |ScheduleErrorEventAction()|. |
| 2148 | EXPECT_CALL(*processor_, EnqueueAction(Pointee(_))).Times(1); |
| 2149 | EXPECT_CALL(*processor_, StartProcessing()).Times(1); |
| 2150 | // THEN |ScheduleUpdates()| will be called next |ProcessingDone()| so skip. |
| 2151 | pd_params_.should_schedule_updates_be_called = false; |
| 2152 | |
| 2153 | TestProcessingDone(); |
| 2154 | } |
| 2155 | |
Amr Aboelkher | 21ac996 | 2019-05-15 14:50:05 +0200 | [diff] [blame] | 2156 | void UpdateAttempterTest::UpdateToQuickFixBuildStart(bool set_token) { |
| 2157 | // Tests that checks if |device_quick_fix_build_token| arrives when |
| 2158 | // policy is set and the device is enterprise enrolled based on |set_token|. |
| 2159 | string token = set_token ? "some_token" : ""; |
Askar Aitzhan | 570ca87 | 2019-04-24 11:16:12 +0200 | [diff] [blame] | 2160 | auto device_policy = std::make_unique<policy::MockDevicePolicy>(); |
Amin Hassani | 538bd59 | 2020-11-04 20:46:08 -0800 | [diff] [blame] | 2161 | FakeSystemState::Get()->set_device_policy(device_policy.get()); |
Askar Aitzhan | 570ca87 | 2019-04-24 11:16:12 +0200 | [diff] [blame] | 2162 | EXPECT_CALL(*device_policy, LoadPolicy()).WillRepeatedly(Return(true)); |
Amr Aboelkher | 21ac996 | 2019-05-15 14:50:05 +0200 | [diff] [blame] | 2163 | |
| 2164 | if (set_token) |
| 2165 | EXPECT_CALL(*device_policy, GetDeviceQuickFixBuildToken(_)) |
| 2166 | .WillOnce(DoAll(SetArgPointee<0>(token), Return(true))); |
| 2167 | else |
| 2168 | EXPECT_CALL(*device_policy, GetDeviceQuickFixBuildToken(_)) |
| 2169 | .WillOnce(Return(false)); |
Askar Aitzhan | 570ca87 | 2019-04-24 11:16:12 +0200 | [diff] [blame] | 2170 | attempter_.policy_provider_.reset( |
| 2171 | new policy::PolicyProvider(std::move(device_policy))); |
Amin Hassani | e815363 | 2020-10-27 15:11:28 -0700 | [diff] [blame] | 2172 | attempter_.Update({}); |
Askar Aitzhan | 570ca87 | 2019-04-24 11:16:12 +0200 | [diff] [blame] | 2173 | |
Amr Aboelkher | 21ac996 | 2019-05-15 14:50:05 +0200 | [diff] [blame] | 2174 | EXPECT_EQ(token, attempter_.omaha_request_params_->autoupdate_token()); |
Askar Aitzhan | 570ca87 | 2019-04-24 11:16:12 +0200 | [diff] [blame] | 2175 | ScheduleQuitMainLoop(); |
| 2176 | } |
| 2177 | |
Amr Aboelkher | 21ac996 | 2019-05-15 14:50:05 +0200 | [diff] [blame] | 2178 | TEST_F(UpdateAttempterTest, |
| 2179 | QuickFixTokenWhenDeviceIsEnterpriseEnrolledAndPolicyIsSet) { |
Askar Aitzhan | 570ca87 | 2019-04-24 11:16:12 +0200 | [diff] [blame] | 2180 | loop_.PostTask(FROM_HERE, |
| 2181 | base::Bind(&UpdateAttempterTest::UpdateToQuickFixBuildStart, |
Amr Aboelkher | 21ac996 | 2019-05-15 14:50:05 +0200 | [diff] [blame] | 2182 | base::Unretained(this), |
| 2183 | /*set_token=*/true)); |
| 2184 | loop_.Run(); |
| 2185 | } |
| 2186 | |
| 2187 | TEST_F(UpdateAttempterTest, EmptyQuickFixToken) { |
| 2188 | loop_.PostTask(FROM_HERE, |
| 2189 | base::Bind(&UpdateAttempterTest::UpdateToQuickFixBuildStart, |
| 2190 | base::Unretained(this), |
| 2191 | /*set_token=*/false)); |
Askar Aitzhan | 570ca87 | 2019-04-24 11:16:12 +0200 | [diff] [blame] | 2192 | loop_.Run(); |
| 2193 | } |
| 2194 | |
Jae Hoon Kim | 75daa38 | 2019-07-02 11:17:24 -0700 | [diff] [blame] | 2195 | TEST_F(UpdateAttempterTest, ScheduleUpdateSpamHandlerTest) { |
| 2196 | EXPECT_CALL(mock_update_manager_, AsyncPolicyRequestUpdateCheckAllowed(_, _)) |
| 2197 | .Times(1); |
| 2198 | EXPECT_TRUE(attempter_.ScheduleUpdates()); |
| 2199 | // Now there is an update scheduled which means that all subsequent |
| 2200 | // |ScheduleUpdates()| should fail. |
| 2201 | EXPECT_FALSE(attempter_.ScheduleUpdates()); |
| 2202 | EXPECT_FALSE(attempter_.ScheduleUpdates()); |
| 2203 | EXPECT_FALSE(attempter_.ScheduleUpdates()); |
| 2204 | } |
| 2205 | |
| 2206 | // Critical tests to always make sure that an update is scheduled. The following |
| 2207 | // unittest(s) try and cover the correctness in synergy between |
| 2208 | // |UpdateAttempter| and |UpdateManager|. Also it is good to remember the |
| 2209 | // actions that happen in the flow when |UpdateAttempter| get callbacked on |
| 2210 | // |OnUpdateScheduled()| -> (various cases which leads to) -> |ProcessingDone()| |
| 2211 | void UpdateAttempterTest::TestOnUpdateScheduled() { |
| 2212 | // Setup |
| 2213 | attempter_.SetWaitingForScheduledCheck(true); |
| 2214 | attempter_.DisableUpdate(); |
| 2215 | attempter_.DisableScheduleUpdates(); |
| 2216 | |
| 2217 | // Invocation |
| 2218 | attempter_.OnUpdateScheduled(ous_params_.status, ous_params_.params); |
| 2219 | |
| 2220 | // Verify |
| 2221 | EXPECT_EQ(ous_params_.exit_status, attempter_.status()); |
| 2222 | EXPECT_EQ(ous_params_.should_schedule_updates_be_called, |
| 2223 | attempter_.WasScheduleUpdatesCalled()); |
| 2224 | EXPECT_EQ(ous_params_.should_update_be_called, attempter_.WasUpdateCalled()); |
| 2225 | } |
| 2226 | |
| 2227 | TEST_F(UpdateAttempterTest, OnUpdatesScheduledFailed) { |
| 2228 | // GIVEN failed status. |
| 2229 | |
| 2230 | // THEN update should be scheduled. |
| 2231 | ous_params_.should_schedule_updates_be_called = true; |
| 2232 | |
| 2233 | TestOnUpdateScheduled(); |
| 2234 | } |
| 2235 | |
| 2236 | TEST_F(UpdateAttempterTest, OnUpdatesScheduledAskMeAgainLater) { |
| 2237 | // GIVEN ask me again later status. |
| 2238 | ous_params_.status = EvalStatus::kAskMeAgainLater; |
| 2239 | |
| 2240 | // THEN update should be scheduled. |
| 2241 | ous_params_.should_schedule_updates_be_called = true; |
| 2242 | |
| 2243 | TestOnUpdateScheduled(); |
| 2244 | } |
| 2245 | |
| 2246 | TEST_F(UpdateAttempterTest, OnUpdatesScheduledContinue) { |
| 2247 | // GIVEN continue status. |
| 2248 | ous_params_.status = EvalStatus::kContinue; |
| 2249 | |
| 2250 | // THEN update should be scheduled. |
| 2251 | ous_params_.should_schedule_updates_be_called = true; |
| 2252 | |
| 2253 | TestOnUpdateScheduled(); |
| 2254 | } |
| 2255 | |
| 2256 | TEST_F(UpdateAttempterTest, OnUpdatesScheduledSucceededButUpdateDisabledFails) { |
| 2257 | // GIVEN updates disabled. |
| 2258 | ous_params_.params = {.updates_enabled = false}; |
| 2259 | // GIVEN succeeded status. |
| 2260 | ous_params_.status = EvalStatus::kSucceeded; |
| 2261 | |
| 2262 | // THEN update should not be scheduled. |
| 2263 | |
| 2264 | TestOnUpdateScheduled(); |
| 2265 | } |
| 2266 | |
| 2267 | TEST_F(UpdateAttempterTest, OnUpdatesScheduledSucceeded) { |
| 2268 | // GIVEN updates enabled. |
| 2269 | ous_params_.params = {.updates_enabled = true}; |
| 2270 | // GIVEN succeeded status. |
| 2271 | ous_params_.status = EvalStatus::kSucceeded; |
| 2272 | |
| 2273 | // THEN update should be called indicating status change. |
| 2274 | ous_params_.exit_status = UpdateStatus::CHECKING_FOR_UPDATE; |
| 2275 | ous_params_.should_update_be_called = true; |
| 2276 | |
| 2277 | TestOnUpdateScheduled(); |
| 2278 | } |
| 2279 | |
Amin Hassani | 9be122e | 2019-08-29 09:20:12 -0700 | [diff] [blame] | 2280 | TEST_F(UpdateAttempterTest, IsEnterpriseRollbackInGetStatusDefault) { |
| 2281 | UpdateEngineStatus status; |
| 2282 | attempter_.GetStatus(&status); |
| 2283 | EXPECT_FALSE(status.is_enterprise_rollback); |
| 2284 | } |
| 2285 | |
| 2286 | TEST_F(UpdateAttempterTest, IsEnterpriseRollbackInGetStatusFalse) { |
| 2287 | attempter_.install_plan_.reset(new InstallPlan); |
| 2288 | attempter_.install_plan_->is_rollback = false; |
| 2289 | |
| 2290 | UpdateEngineStatus status; |
| 2291 | attempter_.GetStatus(&status); |
| 2292 | EXPECT_FALSE(status.is_enterprise_rollback); |
| 2293 | } |
| 2294 | |
| 2295 | TEST_F(UpdateAttempterTest, IsEnterpriseRollbackInGetStatusTrue) { |
| 2296 | attempter_.install_plan_.reset(new InstallPlan); |
| 2297 | attempter_.install_plan_->is_rollback = true; |
| 2298 | |
| 2299 | UpdateEngineStatus status; |
| 2300 | attempter_.GetStatus(&status); |
| 2301 | EXPECT_TRUE(status.is_enterprise_rollback); |
| 2302 | } |
| 2303 | |
Miriam Polzer | 0cf1acb | 2020-04-29 17:39:51 +0200 | [diff] [blame] | 2304 | TEST_F(UpdateAttempterTest, PowerwashInGetStatusDefault) { |
| 2305 | UpdateEngineStatus status; |
| 2306 | attempter_.GetStatus(&status); |
| 2307 | EXPECT_FALSE(status.will_powerwash_after_reboot); |
| 2308 | } |
| 2309 | |
| 2310 | TEST_F(UpdateAttempterTest, PowerwashInGetStatusTrueBecausePowerwashRequired) { |
| 2311 | attempter_.install_plan_.reset(new InstallPlan); |
| 2312 | attempter_.install_plan_->powerwash_required = true; |
| 2313 | |
| 2314 | UpdateEngineStatus status; |
| 2315 | attempter_.GetStatus(&status); |
| 2316 | EXPECT_TRUE(status.will_powerwash_after_reboot); |
| 2317 | } |
| 2318 | |
| 2319 | TEST_F(UpdateAttempterTest, PowerwashInGetStatusTrueBecauseRollback) { |
| 2320 | attempter_.install_plan_.reset(new InstallPlan); |
| 2321 | attempter_.install_plan_->is_rollback = true; |
| 2322 | |
| 2323 | UpdateEngineStatus status; |
| 2324 | attempter_.GetStatus(&status); |
| 2325 | EXPECT_TRUE(status.will_powerwash_after_reboot); |
| 2326 | } |
| 2327 | |
Jae Hoon Kim | 051627a | 2019-09-03 12:56:32 -0700 | [diff] [blame] | 2328 | TEST_F(UpdateAttempterTest, FutureEolTest) { |
| 2329 | EolDate eol_date = std::numeric_limits<int64_t>::max(); |
Jae Hoon Kim | 2dfd35d | 2020-06-02 10:53:13 -0700 | [diff] [blame] | 2330 | EXPECT_CALL(*prefs_, Exists(kPrefsOmahaEolDate)).WillOnce(Return(true)); |
Jae Hoon Kim | 051627a | 2019-09-03 12:56:32 -0700 | [diff] [blame] | 2331 | EXPECT_CALL(*prefs_, GetString(kPrefsOmahaEolDate, _)) |
| 2332 | .WillOnce( |
| 2333 | DoAll(SetArgPointee<1>(EolDateToString(eol_date)), Return(true))); |
| 2334 | |
| 2335 | UpdateEngineStatus status; |
| 2336 | attempter_.GetStatus(&status); |
| 2337 | EXPECT_EQ(eol_date, status.eol_date); |
| 2338 | } |
| 2339 | |
| 2340 | TEST_F(UpdateAttempterTest, PastEolTest) { |
| 2341 | EolDate eol_date = 1; |
Jae Hoon Kim | 2dfd35d | 2020-06-02 10:53:13 -0700 | [diff] [blame] | 2342 | EXPECT_CALL(*prefs_, Exists(kPrefsOmahaEolDate)).WillOnce(Return(true)); |
Jae Hoon Kim | 051627a | 2019-09-03 12:56:32 -0700 | [diff] [blame] | 2343 | EXPECT_CALL(*prefs_, GetString(kPrefsOmahaEolDate, _)) |
| 2344 | .WillOnce( |
| 2345 | DoAll(SetArgPointee<1>(EolDateToString(eol_date)), Return(true))); |
| 2346 | |
| 2347 | UpdateEngineStatus status; |
| 2348 | attempter_.GetStatus(&status); |
| 2349 | EXPECT_EQ(eol_date, status.eol_date); |
| 2350 | } |
| 2351 | |
| 2352 | TEST_F(UpdateAttempterTest, FailedEolTest) { |
Jae Hoon Kim | 2dfd35d | 2020-06-02 10:53:13 -0700 | [diff] [blame] | 2353 | EXPECT_CALL(*prefs_, Exists(kPrefsOmahaEolDate)).WillOnce(Return(true)); |
Jae Hoon Kim | 051627a | 2019-09-03 12:56:32 -0700 | [diff] [blame] | 2354 | EXPECT_CALL(*prefs_, GetString(kPrefsOmahaEolDate, _)) |
| 2355 | .WillOnce(Return(false)); |
| 2356 | |
| 2357 | UpdateEngineStatus status; |
| 2358 | attempter_.GetStatus(&status); |
Jae Hoon Kim | 2dfd35d | 2020-06-02 10:53:13 -0700 | [diff] [blame] | 2359 | EXPECT_EQ(kEolDateInvalid, status.eol_date); |
| 2360 | } |
| 2361 | |
| 2362 | TEST_F(UpdateAttempterTest, MissingEolTest) { |
| 2363 | EXPECT_CALL(*prefs_, Exists(kPrefsOmahaEolDate)).WillOnce(Return(false)); |
| 2364 | |
| 2365 | UpdateEngineStatus status; |
| 2366 | attempter_.GetStatus(&status); |
| 2367 | EXPECT_EQ(kEolDateInvalid, status.eol_date); |
Jae Hoon Kim | 051627a | 2019-09-03 12:56:32 -0700 | [diff] [blame] | 2368 | } |
| 2369 | |
Andrew | e045aef | 2020-01-08 16:29:22 -0800 | [diff] [blame] | 2370 | TEST_F(UpdateAttempterTest, CalculateDlcParamsInstallTest) { |
Andrew | e045aef | 2020-01-08 16:29:22 -0800 | [diff] [blame] | 2371 | string dlc_id = "dlc0"; |
Andrew | 065d78d | 2020-04-07 15:43:07 -0700 | [diff] [blame] | 2372 | FakePrefs fake_prefs; |
Amin Hassani | 538bd59 | 2020-11-04 20:46:08 -0800 | [diff] [blame] | 2373 | FakeSystemState::Get()->set_prefs(&fake_prefs); |
Andrew | e045aef | 2020-01-08 16:29:22 -0800 | [diff] [blame] | 2374 | attempter_.is_install_ = true; |
Amin Hassani | 2b68e6b | 2020-04-17 10:49:12 -0700 | [diff] [blame] | 2375 | attempter_.dlc_ids_ = {dlc_id}; |
Andrew | e045aef | 2020-01-08 16:29:22 -0800 | [diff] [blame] | 2376 | attempter_.CalculateDlcParams(); |
| 2377 | |
Amin Hassani | 538bd59 | 2020-11-04 20:46:08 -0800 | [diff] [blame] | 2378 | OmahaRequestParams* params = FakeSystemState::Get()->request_params(); |
Andrew | e045aef | 2020-01-08 16:29:22 -0800 | [diff] [blame] | 2379 | EXPECT_EQ(1, params->dlc_apps_params().count(params->GetDlcAppId(dlc_id))); |
| 2380 | OmahaRequestParams::AppParams dlc_app_params = |
| 2381 | params->dlc_apps_params().at(params->GetDlcAppId(dlc_id)); |
| 2382 | EXPECT_STREQ(dlc_id.c_str(), dlc_app_params.name.c_str()); |
| 2383 | EXPECT_EQ(false, dlc_app_params.send_ping); |
| 2384 | // When the DLC gets installed, a ping is not sent, therefore we don't store |
| 2385 | // the values sent by Omaha. |
Andrew | 065d78d | 2020-04-07 15:43:07 -0700 | [diff] [blame] | 2386 | auto last_active_key = PrefsInterface::CreateSubKey( |
Jae Hoon Kim | c1f3692 | 2020-05-11 18:20:18 -0700 | [diff] [blame] | 2387 | {kDlcPrefsSubDir, dlc_id, kPrefsPingLastActive}); |
Amin Hassani | 538bd59 | 2020-11-04 20:46:08 -0800 | [diff] [blame] | 2388 | EXPECT_FALSE(FakeSystemState::Get()->prefs()->Exists(last_active_key)); |
Andrew | 065d78d | 2020-04-07 15:43:07 -0700 | [diff] [blame] | 2389 | auto last_rollcall_key = PrefsInterface::CreateSubKey( |
Jae Hoon Kim | c1f3692 | 2020-05-11 18:20:18 -0700 | [diff] [blame] | 2390 | {kDlcPrefsSubDir, dlc_id, kPrefsPingLastRollcall}); |
Amin Hassani | 538bd59 | 2020-11-04 20:46:08 -0800 | [diff] [blame] | 2391 | EXPECT_FALSE(FakeSystemState::Get()->prefs()->Exists(last_rollcall_key)); |
Andrew | e045aef | 2020-01-08 16:29:22 -0800 | [diff] [blame] | 2392 | } |
| 2393 | |
| 2394 | TEST_F(UpdateAttempterTest, CalculateDlcParamsNoPrefFilesTest) { |
Andrew | e045aef | 2020-01-08 16:29:22 -0800 | [diff] [blame] | 2395 | string dlc_id = "dlc0"; |
Andrew | 065d78d | 2020-04-07 15:43:07 -0700 | [diff] [blame] | 2396 | FakePrefs fake_prefs; |
Amin Hassani | 538bd59 | 2020-11-04 20:46:08 -0800 | [diff] [blame] | 2397 | FakeSystemState::Get()->set_prefs(&fake_prefs); |
Amin Hassani | 2b68e6b | 2020-04-17 10:49:12 -0700 | [diff] [blame] | 2398 | EXPECT_CALL(mock_dlcservice_, GetDlcsToUpdate(_)) |
Andrew | e045aef | 2020-01-08 16:29:22 -0800 | [diff] [blame] | 2399 | .WillOnce( |
| 2400 | DoAll(SetArgPointee<0>(std::vector<string>({dlc_id})), Return(true))); |
| 2401 | |
| 2402 | attempter_.is_install_ = false; |
| 2403 | attempter_.CalculateDlcParams(); |
| 2404 | |
Amin Hassani | 538bd59 | 2020-11-04 20:46:08 -0800 | [diff] [blame] | 2405 | OmahaRequestParams* params = FakeSystemState::Get()->request_params(); |
Andrew | e045aef | 2020-01-08 16:29:22 -0800 | [diff] [blame] | 2406 | EXPECT_EQ(1, params->dlc_apps_params().count(params->GetDlcAppId(dlc_id))); |
| 2407 | OmahaRequestParams::AppParams dlc_app_params = |
| 2408 | params->dlc_apps_params().at(params->GetDlcAppId(dlc_id)); |
| 2409 | EXPECT_STREQ(dlc_id.c_str(), dlc_app_params.name.c_str()); |
| 2410 | |
| 2411 | EXPECT_EQ(true, dlc_app_params.send_ping); |
| 2412 | EXPECT_EQ(0, dlc_app_params.ping_active); |
| 2413 | EXPECT_EQ(-1, dlc_app_params.ping_date_last_active); |
| 2414 | EXPECT_EQ(-1, dlc_app_params.ping_date_last_rollcall); |
| 2415 | } |
| 2416 | |
| 2417 | TEST_F(UpdateAttempterTest, CalculateDlcParamsNonParseableValuesTest) { |
Andrew | e045aef | 2020-01-08 16:29:22 -0800 | [diff] [blame] | 2418 | string dlc_id = "dlc0"; |
Andrew | 065d78d | 2020-04-07 15:43:07 -0700 | [diff] [blame] | 2419 | MemoryPrefs prefs; |
Amin Hassani | 538bd59 | 2020-11-04 20:46:08 -0800 | [diff] [blame] | 2420 | FakeSystemState::Get()->set_prefs(&prefs); |
Amin Hassani | 2b68e6b | 2020-04-17 10:49:12 -0700 | [diff] [blame] | 2421 | EXPECT_CALL(mock_dlcservice_, GetDlcsToUpdate(_)) |
Andrew | e045aef | 2020-01-08 16:29:22 -0800 | [diff] [blame] | 2422 | .WillOnce( |
| 2423 | DoAll(SetArgPointee<0>(std::vector<string>({dlc_id})), Return(true))); |
| 2424 | |
| 2425 | // Write non numeric values in the metadata files. |
Andrew | 065d78d | 2020-04-07 15:43:07 -0700 | [diff] [blame] | 2426 | auto active_key = |
Jae Hoon Kim | c1f3692 | 2020-05-11 18:20:18 -0700 | [diff] [blame] | 2427 | PrefsInterface::CreateSubKey({kDlcPrefsSubDir, dlc_id, kPrefsPingActive}); |
Andrew | 065d78d | 2020-04-07 15:43:07 -0700 | [diff] [blame] | 2428 | auto last_active_key = PrefsInterface::CreateSubKey( |
Jae Hoon Kim | c1f3692 | 2020-05-11 18:20:18 -0700 | [diff] [blame] | 2429 | {kDlcPrefsSubDir, dlc_id, kPrefsPingLastActive}); |
Andrew | 065d78d | 2020-04-07 15:43:07 -0700 | [diff] [blame] | 2430 | auto last_rollcall_key = PrefsInterface::CreateSubKey( |
Jae Hoon Kim | c1f3692 | 2020-05-11 18:20:18 -0700 | [diff] [blame] | 2431 | {kDlcPrefsSubDir, dlc_id, kPrefsPingLastRollcall}); |
Amin Hassani | 538bd59 | 2020-11-04 20:46:08 -0800 | [diff] [blame] | 2432 | FakeSystemState::Get()->prefs()->SetString(active_key, "z2yz"); |
| 2433 | FakeSystemState::Get()->prefs()->SetString(last_active_key, "z2yz"); |
| 2434 | FakeSystemState::Get()->prefs()->SetString(last_rollcall_key, "z2yz"); |
Andrew | e045aef | 2020-01-08 16:29:22 -0800 | [diff] [blame] | 2435 | attempter_.is_install_ = false; |
| 2436 | attempter_.CalculateDlcParams(); |
| 2437 | |
Amin Hassani | 538bd59 | 2020-11-04 20:46:08 -0800 | [diff] [blame] | 2438 | OmahaRequestParams* params = FakeSystemState::Get()->request_params(); |
Andrew | e045aef | 2020-01-08 16:29:22 -0800 | [diff] [blame] | 2439 | EXPECT_EQ(1, params->dlc_apps_params().count(params->GetDlcAppId(dlc_id))); |
| 2440 | OmahaRequestParams::AppParams dlc_app_params = |
| 2441 | params->dlc_apps_params().at(params->GetDlcAppId(dlc_id)); |
| 2442 | EXPECT_STREQ(dlc_id.c_str(), dlc_app_params.name.c_str()); |
| 2443 | |
| 2444 | EXPECT_EQ(true, dlc_app_params.send_ping); |
| 2445 | EXPECT_EQ(0, dlc_app_params.ping_active); |
| 2446 | EXPECT_EQ(-2, dlc_app_params.ping_date_last_active); |
| 2447 | EXPECT_EQ(-2, dlc_app_params.ping_date_last_rollcall); |
| 2448 | } |
| 2449 | |
| 2450 | TEST_F(UpdateAttempterTest, CalculateDlcParamsValidValuesTest) { |
Andrew | e045aef | 2020-01-08 16:29:22 -0800 | [diff] [blame] | 2451 | string dlc_id = "dlc0"; |
Andrew | 065d78d | 2020-04-07 15:43:07 -0700 | [diff] [blame] | 2452 | MemoryPrefs fake_prefs; |
Amin Hassani | 538bd59 | 2020-11-04 20:46:08 -0800 | [diff] [blame] | 2453 | FakeSystemState::Get()->set_prefs(&fake_prefs); |
Amin Hassani | 2b68e6b | 2020-04-17 10:49:12 -0700 | [diff] [blame] | 2454 | EXPECT_CALL(mock_dlcservice_, GetDlcsToUpdate(_)) |
Andrew | e045aef | 2020-01-08 16:29:22 -0800 | [diff] [blame] | 2455 | .WillOnce( |
| 2456 | DoAll(SetArgPointee<0>(std::vector<string>({dlc_id})), Return(true))); |
| 2457 | |
| 2458 | // Write numeric values in the metadata files. |
Andrew | 065d78d | 2020-04-07 15:43:07 -0700 | [diff] [blame] | 2459 | auto active_key = |
Jae Hoon Kim | c1f3692 | 2020-05-11 18:20:18 -0700 | [diff] [blame] | 2460 | PrefsInterface::CreateSubKey({kDlcPrefsSubDir, dlc_id, kPrefsPingActive}); |
Andrew | 065d78d | 2020-04-07 15:43:07 -0700 | [diff] [blame] | 2461 | auto last_active_key = PrefsInterface::CreateSubKey( |
Jae Hoon Kim | c1f3692 | 2020-05-11 18:20:18 -0700 | [diff] [blame] | 2462 | {kDlcPrefsSubDir, dlc_id, kPrefsPingLastActive}); |
Andrew | 065d78d | 2020-04-07 15:43:07 -0700 | [diff] [blame] | 2463 | auto last_rollcall_key = PrefsInterface::CreateSubKey( |
Jae Hoon Kim | c1f3692 | 2020-05-11 18:20:18 -0700 | [diff] [blame] | 2464 | {kDlcPrefsSubDir, dlc_id, kPrefsPingLastRollcall}); |
Andrew | 065d78d | 2020-04-07 15:43:07 -0700 | [diff] [blame] | 2465 | |
Amin Hassani | 538bd59 | 2020-11-04 20:46:08 -0800 | [diff] [blame] | 2466 | FakeSystemState::Get()->prefs()->SetInt64(active_key, 1); |
| 2467 | FakeSystemState::Get()->prefs()->SetInt64(last_active_key, 78); |
| 2468 | FakeSystemState::Get()->prefs()->SetInt64(last_rollcall_key, 99); |
Andrew | e045aef | 2020-01-08 16:29:22 -0800 | [diff] [blame] | 2469 | attempter_.is_install_ = false; |
| 2470 | attempter_.CalculateDlcParams(); |
| 2471 | |
Amin Hassani | 538bd59 | 2020-11-04 20:46:08 -0800 | [diff] [blame] | 2472 | OmahaRequestParams* params = FakeSystemState::Get()->request_params(); |
Andrew | e045aef | 2020-01-08 16:29:22 -0800 | [diff] [blame] | 2473 | EXPECT_EQ(1, params->dlc_apps_params().count(params->GetDlcAppId(dlc_id))); |
| 2474 | OmahaRequestParams::AppParams dlc_app_params = |
| 2475 | params->dlc_apps_params().at(params->GetDlcAppId(dlc_id)); |
| 2476 | EXPECT_STREQ(dlc_id.c_str(), dlc_app_params.name.c_str()); |
| 2477 | |
| 2478 | EXPECT_EQ(true, dlc_app_params.send_ping); |
| 2479 | EXPECT_EQ(1, dlc_app_params.ping_active); |
| 2480 | EXPECT_EQ(78, dlc_app_params.ping_date_last_active); |
| 2481 | EXPECT_EQ(99, dlc_app_params.ping_date_last_rollcall); |
| 2482 | } |
Andrew | a8d7df3 | 2020-03-15 20:10:01 -0700 | [diff] [blame] | 2483 | |
| 2484 | TEST_F(UpdateAttempterTest, CalculateDlcParamsRemoveStaleMetadata) { |
Andrew | a8d7df3 | 2020-03-15 20:10:01 -0700 | [diff] [blame] | 2485 | string dlc_id = "dlc0"; |
Andrew | 065d78d | 2020-04-07 15:43:07 -0700 | [diff] [blame] | 2486 | FakePrefs fake_prefs; |
Amin Hassani | 538bd59 | 2020-11-04 20:46:08 -0800 | [diff] [blame] | 2487 | FakeSystemState::Get()->set_prefs(&fake_prefs); |
Andrew | 065d78d | 2020-04-07 15:43:07 -0700 | [diff] [blame] | 2488 | auto active_key = |
Jae Hoon Kim | c1f3692 | 2020-05-11 18:20:18 -0700 | [diff] [blame] | 2489 | PrefsInterface::CreateSubKey({kDlcPrefsSubDir, dlc_id, kPrefsPingActive}); |
Andrew | 065d78d | 2020-04-07 15:43:07 -0700 | [diff] [blame] | 2490 | auto last_active_key = PrefsInterface::CreateSubKey( |
Jae Hoon Kim | c1f3692 | 2020-05-11 18:20:18 -0700 | [diff] [blame] | 2491 | {kDlcPrefsSubDir, dlc_id, kPrefsPingLastActive}); |
Andrew | 065d78d | 2020-04-07 15:43:07 -0700 | [diff] [blame] | 2492 | auto last_rollcall_key = PrefsInterface::CreateSubKey( |
Jae Hoon Kim | c1f3692 | 2020-05-11 18:20:18 -0700 | [diff] [blame] | 2493 | {kDlcPrefsSubDir, dlc_id, kPrefsPingLastRollcall}); |
Amin Hassani | 538bd59 | 2020-11-04 20:46:08 -0800 | [diff] [blame] | 2494 | FakeSystemState::Get()->prefs()->SetInt64(active_key, kPingInactiveValue); |
| 2495 | FakeSystemState::Get()->prefs()->SetInt64(last_active_key, 0); |
| 2496 | FakeSystemState::Get()->prefs()->SetInt64(last_rollcall_key, 0); |
| 2497 | EXPECT_TRUE(FakeSystemState::Get()->prefs()->Exists(active_key)); |
| 2498 | EXPECT_TRUE(FakeSystemState::Get()->prefs()->Exists(last_active_key)); |
| 2499 | EXPECT_TRUE(FakeSystemState::Get()->prefs()->Exists(last_rollcall_key)); |
Andrew | a8d7df3 | 2020-03-15 20:10:01 -0700 | [diff] [blame] | 2500 | |
Andrew | 065d78d | 2020-04-07 15:43:07 -0700 | [diff] [blame] | 2501 | attempter_.dlc_ids_ = {dlc_id}; |
| 2502 | attempter_.is_install_ = true; |
Andrew | a8d7df3 | 2020-03-15 20:10:01 -0700 | [diff] [blame] | 2503 | attempter_.CalculateDlcParams(); |
| 2504 | |
Amin Hassani | 538bd59 | 2020-11-04 20:46:08 -0800 | [diff] [blame] | 2505 | EXPECT_FALSE(FakeSystemState::Get()->prefs()->Exists(last_active_key)); |
| 2506 | EXPECT_FALSE(FakeSystemState::Get()->prefs()->Exists(last_rollcall_key)); |
Andrew | 065d78d | 2020-04-07 15:43:07 -0700 | [diff] [blame] | 2507 | // Active key is set on install. |
Amin Hassani | 538bd59 | 2020-11-04 20:46:08 -0800 | [diff] [blame] | 2508 | EXPECT_TRUE(FakeSystemState::Get()->prefs()->Exists(active_key)); |
Andrew | 065d78d | 2020-04-07 15:43:07 -0700 | [diff] [blame] | 2509 | int64_t temp_int; |
Amin Hassani | 538bd59 | 2020-11-04 20:46:08 -0800 | [diff] [blame] | 2510 | EXPECT_TRUE(FakeSystemState::Get()->prefs()->GetInt64(active_key, &temp_int)); |
Andrew | 065d78d | 2020-04-07 15:43:07 -0700 | [diff] [blame] | 2511 | EXPECT_EQ(temp_int, kPingActiveValue); |
Andrew | a8d7df3 | 2020-03-15 20:10:01 -0700 | [diff] [blame] | 2512 | } |
| 2513 | |
| 2514 | TEST_F(UpdateAttempterTest, SetDlcActiveValue) { |
Andrew | a8d7df3 | 2020-03-15 20:10:01 -0700 | [diff] [blame] | 2515 | string dlc_id = "dlc0"; |
Andrew | 065d78d | 2020-04-07 15:43:07 -0700 | [diff] [blame] | 2516 | FakePrefs fake_prefs; |
Amin Hassani | 538bd59 | 2020-11-04 20:46:08 -0800 | [diff] [blame] | 2517 | FakeSystemState::Get()->set_prefs(&fake_prefs); |
Andrew | a8d7df3 | 2020-03-15 20:10:01 -0700 | [diff] [blame] | 2518 | attempter_.SetDlcActiveValue(true, dlc_id); |
Andrew | a8d7df3 | 2020-03-15 20:10:01 -0700 | [diff] [blame] | 2519 | int64_t temp_int; |
Andrew | 065d78d | 2020-04-07 15:43:07 -0700 | [diff] [blame] | 2520 | auto active_key = |
Jae Hoon Kim | c1f3692 | 2020-05-11 18:20:18 -0700 | [diff] [blame] | 2521 | PrefsInterface::CreateSubKey({kDlcPrefsSubDir, dlc_id, kPrefsPingActive}); |
Amin Hassani | 538bd59 | 2020-11-04 20:46:08 -0800 | [diff] [blame] | 2522 | EXPECT_TRUE(FakeSystemState::Get()->prefs()->Exists(active_key)); |
| 2523 | EXPECT_TRUE(FakeSystemState::Get()->prefs()->GetInt64(active_key, &temp_int)); |
Andrew | a8d7df3 | 2020-03-15 20:10:01 -0700 | [diff] [blame] | 2524 | EXPECT_EQ(temp_int, kPingActiveValue); |
| 2525 | } |
| 2526 | |
| 2527 | TEST_F(UpdateAttempterTest, SetDlcInactive) { |
Andrew | a8d7df3 | 2020-03-15 20:10:01 -0700 | [diff] [blame] | 2528 | string dlc_id = "dlc0"; |
Andrew | 065d78d | 2020-04-07 15:43:07 -0700 | [diff] [blame] | 2529 | MemoryPrefs fake_prefs; |
Amin Hassani | 538bd59 | 2020-11-04 20:46:08 -0800 | [diff] [blame] | 2530 | FakeSystemState::Get()->set_prefs(&fake_prefs); |
Andrew | 065d78d | 2020-04-07 15:43:07 -0700 | [diff] [blame] | 2531 | auto sub_keys = { |
| 2532 | kPrefsPingActive, kPrefsPingLastActive, kPrefsPingLastRollcall}; |
| 2533 | for (auto& sub_key : sub_keys) { |
Jae Hoon Kim | c1f3692 | 2020-05-11 18:20:18 -0700 | [diff] [blame] | 2534 | auto key = PrefsInterface::CreateSubKey({kDlcPrefsSubDir, dlc_id, sub_key}); |
Amin Hassani | 538bd59 | 2020-11-04 20:46:08 -0800 | [diff] [blame] | 2535 | FakeSystemState::Get()->prefs()->SetInt64(key, 1); |
| 2536 | EXPECT_TRUE(FakeSystemState::Get()->prefs()->Exists(key)); |
Andrew | 065d78d | 2020-04-07 15:43:07 -0700 | [diff] [blame] | 2537 | } |
Andrew | a8d7df3 | 2020-03-15 20:10:01 -0700 | [diff] [blame] | 2538 | attempter_.SetDlcActiveValue(false, dlc_id); |
Andrew | 065d78d | 2020-04-07 15:43:07 -0700 | [diff] [blame] | 2539 | for (auto& sub_key : sub_keys) { |
Jae Hoon Kim | c1f3692 | 2020-05-11 18:20:18 -0700 | [diff] [blame] | 2540 | auto key = PrefsInterface::CreateSubKey({kDlcPrefsSubDir, dlc_id, sub_key}); |
Amin Hassani | 538bd59 | 2020-11-04 20:46:08 -0800 | [diff] [blame] | 2541 | EXPECT_FALSE(FakeSystemState::Get()->prefs()->Exists(key)); |
Andrew | 065d78d | 2020-04-07 15:43:07 -0700 | [diff] [blame] | 2542 | } |
Andrew | a8d7df3 | 2020-03-15 20:10:01 -0700 | [diff] [blame] | 2543 | } |
| 2544 | |
Jae Hoon Kim | 7fdfbf1 | 2020-04-10 18:15:50 -0700 | [diff] [blame] | 2545 | TEST_F(UpdateAttempterTest, GetSuccessfulDlcIds) { |
| 2546 | auto dlc_1 = "1", dlc_2 = "2", dlc_3 = "3"; |
| 2547 | attempter_.omaha_request_params_->set_dlc_apps_params( |
| 2548 | {{dlc_1, {.name = dlc_1, .updated = false}}, |
| 2549 | {dlc_2, {.name = dlc_2}}, |
| 2550 | {dlc_3, {.name = dlc_3, .updated = false}}}); |
| 2551 | EXPECT_THAT(attempter_.GetSuccessfulDlcIds(), ElementsAre(dlc_2)); |
| 2552 | } |
| 2553 | |
Darin Petkov | f42cc1c | 2010-09-01 09:03:02 -0700 | [diff] [blame] | 2554 | } // namespace chromeos_update_engine |