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