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 | 6a5b322 | 2010-07-13 14:55:28 -0700 | [diff] [blame] | 16 | |
Alex Deymo | 8427b4a | 2014-11-05 14:00:32 -0800 | [diff] [blame] | 17 | #include "update_engine/omaha_request_action.h" |
| 18 | |
Ben Chan | 9abb763 | 2014-08-07 00:10:53 -0700 | [diff] [blame] | 19 | #include <stdint.h> |
| 20 | |
Ben Chan | ab5a0af | 2017-10-12 14:57:50 -0700 | [diff] [blame] | 21 | #include <memory> |
Darin Petkov | 6a5b322 | 2010-07-13 14:55:28 -0700 | [diff] [blame] | 22 | #include <string> |
| 23 | #include <vector> |
Darin Petkov | 0dc8e9a | 2010-07-14 14:51:57 -0700 | [diff] [blame] | 24 | |
Alex Deymo | 60ca1a7 | 2015-06-18 18:19:15 -0700 | [diff] [blame] | 25 | #include <base/bind.h> |
Alex Deymo | 110e030 | 2015-10-19 20:35:21 -0700 | [diff] [blame] | 26 | #include <base/files/file_util.h> |
Sen Jiang | 297e583 | 2016-03-17 14:45:51 -0700 | [diff] [blame] | 27 | #include <base/files/scoped_temp_dir.h> |
Ben Chan | 5c02c13 | 2017-06-27 07:10:36 -0700 | [diff] [blame] | 28 | #include <base/memory/ptr_util.h> |
Alex Deymo | 8e18f93 | 2015-03-27 16:16:59 -0700 | [diff] [blame] | 29 | #include <base/strings/string_number_conversions.h> |
Alex Vakulenko | 75039d7 | 2014-03-25 12:36:28 -0700 | [diff] [blame] | 30 | #include <base/strings/string_util.h> |
| 31 | #include <base/strings/stringprintf.h> |
| 32 | #include <base/time/time.h> |
Alex Vakulenko | 3f39d5c | 2015-10-13 09:27:13 -0700 | [diff] [blame] | 33 | #include <brillo/bind_lambda.h> |
| 34 | #include <brillo/message_loops/fake_message_loop.h> |
| 35 | #include <brillo/message_loops/message_loop.h> |
| 36 | #include <brillo/message_loops/message_loop_utils.h> |
Alex Deymo | e1e3afe | 2014-10-30 13:02:49 -0700 | [diff] [blame] | 37 | #include <gtest/gtest.h> |
Jay Srinivasan | d29695d | 2013-04-08 15:08:05 -0700 | [diff] [blame] | 38 | |
Alex Deymo | 39910dc | 2015-11-09 17:04:30 -0800 | [diff] [blame] | 39 | #include "update_engine/common/action_pipe.h" |
| 40 | #include "update_engine/common/constants.h" |
| 41 | #include "update_engine/common/fake_prefs.h" |
| 42 | #include "update_engine/common/hash_calculator.h" |
| 43 | #include "update_engine/common/mock_http_fetcher.h" |
| 44 | #include "update_engine/common/platform_constants.h" |
| 45 | #include "update_engine/common/prefs.h" |
| 46 | #include "update_engine/common/test_utils.h" |
Alex Deymo | c1c17b4 | 2015-11-23 03:53:15 -0300 | [diff] [blame] | 47 | #include "update_engine/fake_system_state.h" |
Tianjie Xu | 282aa1f | 2017-09-05 13:42:45 -0700 | [diff] [blame] | 48 | #include "update_engine/metrics_reporter_interface.h" |
Chris Sosa | 77f79e8 | 2014-06-02 18:16:24 -0700 | [diff] [blame] | 49 | #include "update_engine/mock_connection_manager.h" |
Gilad Arnold | 74b5f55 | 2014-10-07 08:17:16 -0700 | [diff] [blame] | 50 | #include "update_engine/mock_payload_state.h" |
Darin Petkov | a4a8a8c | 2010-07-15 22:21:12 -0700 | [diff] [blame] | 51 | #include "update_engine/omaha_request_params.h" |
Darin Petkov | 6a5b322 | 2010-07-13 14:55:28 -0700 | [diff] [blame] | 52 | |
Darin Petkov | 1cbd78f | 2010-07-29 12:38:34 -0700 | [diff] [blame] | 53 | using base::Time; |
| 54 | using base::TimeDelta; |
Darin Petkov | 6a5b322 | 2010-07-13 14:55:28 -0700 | [diff] [blame] | 55 | using std::string; |
| 56 | using std::vector; |
Darin Petkov | 1cbd78f | 2010-07-29 12:38:34 -0700 | [diff] [blame] | 57 | using testing::AllOf; |
Alex Deymo | f329b93 | 2014-10-30 01:37:48 -0700 | [diff] [blame] | 58 | using testing::AnyNumber; |
Jay Srinivasan | 34b5d86 | 2012-07-23 11:43:22 -0700 | [diff] [blame] | 59 | using testing::DoAll; |
Darin Petkov | 1cbd78f | 2010-07-29 12:38:34 -0700 | [diff] [blame] | 60 | using testing::Ge; |
| 61 | using testing::Le; |
Darin Petkov | 9c096d6 | 2010-11-17 14:49:04 -0800 | [diff] [blame] | 62 | using testing::NiceMock; |
Darin Petkov | 1cbd78f | 2010-07-29 12:38:34 -0700 | [diff] [blame] | 63 | using testing::Return; |
Gilad Arnold | 74b5f55 | 2014-10-07 08:17:16 -0700 | [diff] [blame] | 64 | using testing::ReturnPointee; |
| 65 | using testing::SaveArg; |
Ben Chan | 672c1f5 | 2017-10-23 15:41:39 -0700 | [diff] [blame] | 66 | using testing::SetArgPointee; |
Alex Deymo | f329b93 | 2014-10-30 01:37:48 -0700 | [diff] [blame] | 67 | using testing::_; |
Darin Petkov | 6a5b322 | 2010-07-13 14:55:28 -0700 | [diff] [blame] | 68 | |
Alex Deymo | 8e18f93 | 2015-03-27 16:16:59 -0700 | [diff] [blame] | 69 | namespace { |
| 70 | |
Alex Deymo | 8561665 | 2015-10-15 18:48:31 -0700 | [diff] [blame] | 71 | const char kTestAppId[] = "test-app-id"; |
Aaron Wood | 7dcdedf | 2017-09-06 17:17:41 -0700 | [diff] [blame] | 72 | const char kTestAppId2[] = "test-app2-id"; |
Alex Deymo | 8561665 | 2015-10-15 18:48:31 -0700 | [diff] [blame] | 73 | |
Alex Deymo | 8e18f93 | 2015-03-27 16:16:59 -0700 | [diff] [blame] | 74 | // This is a helper struct to allow unit tests build an update response with the |
| 75 | // values they care about. |
| 76 | struct FakeUpdateResponse { |
| 77 | string GetNoUpdateResponse() const { |
| 78 | string entity_str; |
| 79 | if (include_entity) |
| 80 | entity_str = "<!DOCTYPE response [<!ENTITY CrOS \"ChromeOS\">]>"; |
Sen Jiang | 8125968 | 2017-03-30 15:11:30 -0700 | [diff] [blame] | 81 | return "<?xml version=\"1.0\" encoding=\"UTF-8\"?>" + entity_str + |
| 82 | "<response protocol=\"3.0\">" |
| 83 | "<daystart elapsed_seconds=\"100\"/>" |
| 84 | "<app appid=\"" + |
| 85 | app_id + "\" " + |
| 86 | (include_cohorts |
| 87 | ? "cohort=\"" + cohort + "\" cohorthint=\"" + cohorthint + |
| 88 | "\" cohortname=\"" + cohortname + "\" " |
| 89 | : "") + |
| 90 | " status=\"ok\">" |
| 91 | "<ping status=\"ok\"/>" |
| 92 | "<updatecheck status=\"noupdate\"/></app>" + |
| 93 | (multi_app_no_update |
Aaron Wood | 7dcdedf | 2017-09-06 17:17:41 -0700 | [diff] [blame] | 94 | ? "<app appid=\"" + app_id2 + |
| 95 | "\"><updatecheck status=\"noupdate\"/></app>" |
Sen Jiang | 8125968 | 2017-03-30 15:11:30 -0700 | [diff] [blame] | 96 | : "") + |
| 97 | "</response>"; |
Alex Deymo | 8e18f93 | 2015-03-27 16:16:59 -0700 | [diff] [blame] | 98 | } |
| 99 | |
| 100 | string GetUpdateResponse() const { |
Sen Jiang | 2703ef4 | 2017-03-16 13:36:21 -0700 | [diff] [blame] | 101 | return "<?xml version=\"1.0\" encoding=\"UTF-8\"?><response " |
| 102 | "protocol=\"3.0\">" |
| 103 | "<daystart elapsed_seconds=\"100\"" + |
| 104 | (elapsed_days.empty() ? "" |
| 105 | : (" elapsed_days=\"" + elapsed_days + "\"")) + |
| 106 | "/>" |
| 107 | "<app appid=\"" + |
| 108 | app_id + "\" " + |
| 109 | (include_cohorts |
| 110 | ? "cohort=\"" + cohort + "\" cohorthint=\"" + cohorthint + |
| 111 | "\" cohortname=\"" + cohortname + "\" " |
| 112 | : "") + |
| 113 | " status=\"ok\">" |
| 114 | "<ping status=\"ok\"/><updatecheck status=\"ok\">" |
| 115 | "<urls><url codebase=\"" + |
| 116 | codebase + |
| 117 | "\"/></urls>" |
| 118 | "<manifest version=\"" + |
| 119 | version + |
| 120 | "\">" |
| 121 | "<packages><package hash=\"not-used\" name=\"" + |
| 122 | filename + "\" size=\"" + base::Int64ToString(size) + |
Sen Jiang | 0affc2c | 2017-02-10 15:55:05 -0800 | [diff] [blame] | 123 | "\" hash_sha256=\"" + hash + "\"/>" + |
| 124 | (multi_package ? "<package name=\"package2\" size=\"222\" " |
| 125 | "hash_sha256=\"hash2\"/>" |
| 126 | : "") + |
| 127 | "</packages>" |
Sen Jiang | 8125968 | 2017-03-30 15:11:30 -0700 | [diff] [blame] | 128 | "<actions><action event=\"postinstall\" MetadataSize=\"11" + |
| 129 | (multi_package ? ":22" : "") + "\" ChromeOSVersion=\"" + version + |
| 130 | "\" MoreInfo=\"" + more_info_url + "\" Prompt=\"" + prompt + |
Sen Jiang | 2703ef4 | 2017-03-16 13:36:21 -0700 | [diff] [blame] | 131 | "\" " |
| 132 | "IsDelta=\"true\" " |
Sen Jiang | cdd5206 | 2017-05-18 15:33:10 -0700 | [diff] [blame] | 133 | "IsDeltaPayload=\"true" + |
| 134 | (multi_package ? ":false" : "") + |
| 135 | "\" " |
Sen Jiang | 2703ef4 | 2017-03-16 13:36:21 -0700 | [diff] [blame] | 136 | "MaxDaysToScatter=\"" + |
| 137 | max_days_to_scatter + |
| 138 | "\" " |
| 139 | "sha256=\"not-used\" " |
| 140 | "needsadmin=\"" + |
| 141 | needsadmin + "\" " + |
| 142 | (deadline.empty() ? "" : ("deadline=\"" + deadline + "\" ")) + |
| 143 | (disable_p2p_for_downloading ? "DisableP2PForDownloading=\"true\" " |
| 144 | : "") + |
| 145 | (disable_p2p_for_sharing ? "DisableP2PForSharing=\"true\" " : "") + |
Sen Jiang | 8125968 | 2017-03-30 15:11:30 -0700 | [diff] [blame] | 146 | "/></actions></manifest></updatecheck></app>" + |
| 147 | (multi_app |
Sen Jiang | b1e063a | 2017-09-15 17:44:31 -0700 | [diff] [blame] | 148 | ? "<app appid=\"" + app_id2 + "\"" + |
| 149 | (include_cohorts ? " cohort=\"cohort2\"" : "") + |
| 150 | "><updatecheck status=\"ok\"><urls><url codebase=\"" + |
Aaron Wood | 7dcdedf | 2017-09-06 17:17:41 -0700 | [diff] [blame] | 151 | codebase2 + "\"/></urls><manifest version=\"" + version2 + |
| 152 | "\"><packages>" |
Sen Jiang | 8125968 | 2017-03-30 15:11:30 -0700 | [diff] [blame] | 153 | "<package name=\"package3\" size=\"333\" " |
| 154 | "hash_sha256=\"hash3\"/></packages>" |
Sen Jiang | 00adf7b | 2017-06-26 15:57:29 -0700 | [diff] [blame] | 155 | "<actions><action event=\"postinstall\" " + |
| 156 | (multi_app_self_update |
| 157 | ? "noupdate=\"true\" IsDeltaPayload=\"true\" " |
| 158 | : "IsDeltaPayload=\"false\" ") + |
| 159 | "MetadataSize=\"33\"/></actions>" |
Sen Jiang | 8125968 | 2017-03-30 15:11:30 -0700 | [diff] [blame] | 160 | "</manifest></updatecheck></app>" |
| 161 | : "") + |
| 162 | (multi_app_no_update |
| 163 | ? "<app><updatecheck status=\"noupdate\"/></app>" |
| 164 | : "") + |
| 165 | "</response>"; |
Alex Deymo | 8e18f93 | 2015-03-27 16:16:59 -0700 | [diff] [blame] | 166 | } |
| 167 | |
| 168 | // Return the payload URL, which is split in two fields in the XML response. |
| 169 | string GetPayloadUrl() { |
| 170 | return codebase + filename; |
| 171 | } |
| 172 | |
Alex Deymo | 8561665 | 2015-10-15 18:48:31 -0700 | [diff] [blame] | 173 | string app_id = kTestAppId; |
Aaron Wood | 7dcdedf | 2017-09-06 17:17:41 -0700 | [diff] [blame] | 174 | string app_id2 = kTestAppId2; |
Alex Deymo | 8e18f93 | 2015-03-27 16:16:59 -0700 | [diff] [blame] | 175 | string version = "1.2.3.4"; |
Aaron Wood | 7dcdedf | 2017-09-06 17:17:41 -0700 | [diff] [blame] | 176 | string version2 = "2.3.4.5"; |
Alex Deymo | 8e18f93 | 2015-03-27 16:16:59 -0700 | [diff] [blame] | 177 | string more_info_url = "http://more/info"; |
| 178 | string prompt = "true"; |
| 179 | string codebase = "http://code/base/"; |
Sen Jiang | 8125968 | 2017-03-30 15:11:30 -0700 | [diff] [blame] | 180 | string codebase2 = "http://code/base/2/"; |
Alex Deymo | 8e18f93 | 2015-03-27 16:16:59 -0700 | [diff] [blame] | 181 | string filename = "file.signed"; |
Sen Jiang | 2703ef4 | 2017-03-16 13:36:21 -0700 | [diff] [blame] | 182 | string hash = "4841534831323334"; |
Alex Deymo | 8e18f93 | 2015-03-27 16:16:59 -0700 | [diff] [blame] | 183 | string needsadmin = "false"; |
Sen Jiang | 0affc2c | 2017-02-10 15:55:05 -0800 | [diff] [blame] | 184 | uint64_t size = 123; |
Alex Deymo | 8e18f93 | 2015-03-27 16:16:59 -0700 | [diff] [blame] | 185 | string deadline = ""; |
| 186 | string max_days_to_scatter = "7"; |
| 187 | string elapsed_days = "42"; |
| 188 | |
| 189 | // P2P setting defaults to allowed. |
| 190 | bool disable_p2p_for_downloading = false; |
| 191 | bool disable_p2p_for_sharing = false; |
| 192 | |
| 193 | // Omaha cohorts settings. |
| 194 | bool include_cohorts = false; |
| 195 | string cohort = ""; |
| 196 | string cohorthint = ""; |
| 197 | string cohortname = ""; |
| 198 | |
| 199 | // Whether to include the CrOS <!ENTITY> in the XML response. |
| 200 | bool include_entity = false; |
Sen Jiang | 0affc2c | 2017-02-10 15:55:05 -0800 | [diff] [blame] | 201 | |
Sen Jiang | 8125968 | 2017-03-30 15:11:30 -0700 | [diff] [blame] | 202 | // Whether to include more than one app. |
| 203 | bool multi_app = false; |
Sen Jiang | 00adf7b | 2017-06-26 15:57:29 -0700 | [diff] [blame] | 204 | // Whether to include an app with noupdate="true". |
| 205 | bool multi_app_self_update = false; |
| 206 | // Whether to include an additional app with status="noupdate". |
Sen Jiang | 8125968 | 2017-03-30 15:11:30 -0700 | [diff] [blame] | 207 | bool multi_app_no_update = false; |
| 208 | // Whether to include more than one package in an app. |
Sen Jiang | 0affc2c | 2017-02-10 15:55:05 -0800 | [diff] [blame] | 209 | bool multi_package = false; |
Alex Deymo | 8e18f93 | 2015-03-27 16:16:59 -0700 | [diff] [blame] | 210 | }; |
| 211 | |
| 212 | } // namespace |
| 213 | |
Darin Petkov | 6a5b322 | 2010-07-13 14:55:28 -0700 | [diff] [blame] | 214 | namespace chromeos_update_engine { |
| 215 | |
Alex Deymo | e1e3afe | 2014-10-30 13:02:49 -0700 | [diff] [blame] | 216 | class OmahaRequestActionTest : public ::testing::Test { |
| 217 | protected: |
Alex Deymo | 610277e | 2014-11-11 21:18:11 -0800 | [diff] [blame] | 218 | void SetUp() override { |
Marton Hunyady | 2abda31 | 2018-04-24 18:21:49 +0200 | [diff] [blame^] | 219 | request_params_.set_os_sp("service_pack"); |
| 220 | request_params_.set_os_board("x86-generic"); |
| 221 | request_params_.set_app_id(kTestAppId); |
| 222 | request_params_.set_app_version("0.1.0.0"); |
| 223 | request_params_.set_app_lang("en-US"); |
| 224 | request_params_.set_current_channel("unittest"); |
| 225 | request_params_.set_target_channel("unittest"); |
| 226 | request_params_.set_hwid("OEM MODEL 09235 7471"); |
| 227 | request_params_.set_fw_version("ChromeOSFirmware.1.0"); |
| 228 | request_params_.set_ec_version("0X0A1"); |
| 229 | request_params_.set_delta_okay(true); |
| 230 | request_params_.set_interactive(false); |
| 231 | request_params_.set_update_url("http://url"); |
| 232 | request_params_.set_target_version_prefix(""); |
| 233 | request_params_.set_is_powerwash_allowed(false); |
| 234 | |
Alex Deymo | e1e3afe | 2014-10-30 13:02:49 -0700 | [diff] [blame] | 235 | fake_system_state_.set_request_params(&request_params_); |
| 236 | fake_system_state_.set_prefs(&fake_prefs_); |
| 237 | } |
| 238 | |
| 239 | // Returns true iff an output response was obtained from the |
Alex Deymo | 8427b4a | 2014-11-05 14:00:32 -0800 | [diff] [blame] | 240 | // OmahaRequestAction. |prefs| may be null, in which case a local MockPrefs |
Alex Deymo | e1e3afe | 2014-10-30 13:02:49 -0700 | [diff] [blame] | 241 | // is used. |payload_state| may be null, in which case a local mock is used. |
| 242 | // |p2p_manager| may be null, in which case a local mock is used. |
| 243 | // |connection_manager| may be null, in which case a local mock is used. |
| 244 | // out_response may be null. If |fail_http_response_code| is non-negative, |
| 245 | // the transfer will fail with that code. |ping_only| is passed through to the |
| 246 | // OmahaRequestAction constructor. out_post_data may be null; if non-null, the |
| 247 | // post-data received by the mock HttpFetcher is returned. |
| 248 | // |
| 249 | // The |expected_check_result|, |expected_check_reaction| and |
| 250 | // |expected_error_code| parameters are for checking expectations |
| 251 | // about reporting UpdateEngine.Check.{Result,Reaction,DownloadError} |
| 252 | // UMA statistics. Use the appropriate ::kUnset value to specify that |
| 253 | // the given metric should not be reported. |
Marton Hunyady | 2abda31 | 2018-04-24 18:21:49 +0200 | [diff] [blame^] | 254 | bool TestUpdateCheck(const string& http_response, |
Alex Deymo | e1e3afe | 2014-10-30 13:02:49 -0700 | [diff] [blame] | 255 | int fail_http_response_code, |
| 256 | bool ping_only, |
| 257 | ErrorCode expected_code, |
| 258 | metrics::CheckResult expected_check_result, |
| 259 | metrics::CheckReaction expected_check_reaction, |
| 260 | metrics::DownloadErrorCode expected_download_error_code, |
| 261 | OmahaResponse* out_response, |
Alex Vakulenko | 3f39d5c | 2015-10-13 09:27:13 -0700 | [diff] [blame] | 262 | brillo::Blob* out_post_data); |
Alex Deymo | e1e3afe | 2014-10-30 13:02:49 -0700 | [diff] [blame] | 263 | |
Alex Vakulenko | f68bbbc | 2015-02-09 12:53:18 -0800 | [diff] [blame] | 264 | // Runs and checks a ping test. |ping_only| indicates whether it should send |
Alex Deymo | e1e3afe | 2014-10-30 13:02:49 -0700 | [diff] [blame] | 265 | // only a ping or also an updatecheck. |
| 266 | void PingTest(bool ping_only); |
| 267 | |
| 268 | // InstallDate test helper function. |
Alex Deymo | f329b93 | 2014-10-30 01:37:48 -0700 | [diff] [blame] | 269 | bool InstallDateParseHelper(const string &elapsed_days, |
Alex Deymo | e1e3afe | 2014-10-30 13:02:49 -0700 | [diff] [blame] | 270 | OmahaResponse *response); |
| 271 | |
| 272 | // P2P test helper function. |
| 273 | void P2PTest( |
| 274 | bool initial_allow_p2p_for_downloading, |
| 275 | bool initial_allow_p2p_for_sharing, |
| 276 | bool omaha_disable_p2p_for_downloading, |
| 277 | bool omaha_disable_p2p_for_sharing, |
| 278 | bool payload_state_allow_p2p_attempt, |
| 279 | bool expect_p2p_client_lookup, |
| 280 | const string& p2p_client_result_url, |
| 281 | bool expected_allow_p2p_for_downloading, |
| 282 | bool expected_allow_p2p_for_sharing, |
| 283 | const string& expected_p2p_url); |
| 284 | |
| 285 | FakeSystemState fake_system_state_; |
Alex Deymo | 8e18f93 | 2015-03-27 16:16:59 -0700 | [diff] [blame] | 286 | FakeUpdateResponse fake_update_response_; |
Marton Hunyady | 2abda31 | 2018-04-24 18:21:49 +0200 | [diff] [blame^] | 287 | // Used by all tests. |
| 288 | OmahaRequestParams request_params_{&fake_system_state_}; |
Alex Deymo | e1e3afe | 2014-10-30 13:02:49 -0700 | [diff] [blame] | 289 | |
| 290 | FakePrefs fake_prefs_; |
| 291 | }; |
Darin Petkov | 6a5b322 | 2010-07-13 14:55:28 -0700 | [diff] [blame] | 292 | |
| 293 | namespace { |
Darin Petkov | 6a5b322 | 2010-07-13 14:55:28 -0700 | [diff] [blame] | 294 | class OmahaRequestActionTestProcessorDelegate : public ActionProcessorDelegate { |
| 295 | public: |
| 296 | OmahaRequestActionTestProcessorDelegate() |
Alex Deymo | 60ca1a7 | 2015-06-18 18:19:15 -0700 | [diff] [blame] | 297 | : expected_code_(ErrorCode::kSuccess) {} |
Alex Deymo | 610277e | 2014-11-11 21:18:11 -0800 | [diff] [blame] | 298 | ~OmahaRequestActionTestProcessorDelegate() override { |
Darin Petkov | 6a5b322 | 2010-07-13 14:55:28 -0700 | [diff] [blame] | 299 | } |
Yunlian Jiang | 35866ed | 2015-01-29 13:09:20 -0800 | [diff] [blame] | 300 | void ProcessingDone(const ActionProcessor* processor, |
| 301 | ErrorCode code) override { |
Alex Vakulenko | 3f39d5c | 2015-10-13 09:27:13 -0700 | [diff] [blame] | 302 | brillo::MessageLoop::current()->BreakLoop(); |
Darin Petkov | 6a5b322 | 2010-07-13 14:55:28 -0700 | [diff] [blame] | 303 | } |
| 304 | |
Yunlian Jiang | 35866ed | 2015-01-29 13:09:20 -0800 | [diff] [blame] | 305 | void ActionCompleted(ActionProcessor* processor, |
| 306 | AbstractAction* action, |
| 307 | ErrorCode code) override { |
Darin Petkov | 6a5b322 | 2010-07-13 14:55:28 -0700 | [diff] [blame] | 308 | // make sure actions always succeed |
| 309 | if (action->Type() == OmahaRequestAction::StaticType()) |
Darin Petkov | c1a8b42 | 2010-07-19 11:34:49 -0700 | [diff] [blame] | 310 | EXPECT_EQ(expected_code_, code); |
Darin Petkov | 6a5b322 | 2010-07-13 14:55:28 -0700 | [diff] [blame] | 311 | else |
Gilad Arnold | d1c4d2d | 2014-06-05 14:07:53 -0700 | [diff] [blame] | 312 | EXPECT_EQ(ErrorCode::kSuccess, code); |
Darin Petkov | 6a5b322 | 2010-07-13 14:55:28 -0700 | [diff] [blame] | 313 | } |
David Zeuthen | a99981f | 2013-04-29 13:42:47 -0700 | [diff] [blame] | 314 | ErrorCode expected_code_; |
Darin Petkov | 6a5b322 | 2010-07-13 14:55:28 -0700 | [diff] [blame] | 315 | }; |
Alex Vakulenko | d2779df | 2014-06-16 13:19:00 -0700 | [diff] [blame] | 316 | } // namespace |
Darin Petkov | 6a5b322 | 2010-07-13 14:55:28 -0700 | [diff] [blame] | 317 | |
| 318 | class OutputObjectCollectorAction; |
| 319 | |
| 320 | template<> |
| 321 | class ActionTraits<OutputObjectCollectorAction> { |
| 322 | public: |
| 323 | // Does not take an object for input |
| 324 | typedef OmahaResponse InputObjectType; |
| 325 | // On success, puts the output path on output |
| 326 | typedef NoneType OutputObjectType; |
| 327 | }; |
| 328 | |
| 329 | class OutputObjectCollectorAction : public Action<OutputObjectCollectorAction> { |
| 330 | public: |
| 331 | OutputObjectCollectorAction() : has_input_object_(false) {} |
| 332 | void PerformAction() { |
| 333 | // copy input object |
| 334 | has_input_object_ = HasInputObject(); |
| 335 | if (has_input_object_) |
| 336 | omaha_response_ = GetInputObject(); |
Gilad Arnold | d1c4d2d | 2014-06-05 14:07:53 -0700 | [diff] [blame] | 337 | processor_->ActionComplete(this, ErrorCode::kSuccess); |
Darin Petkov | 6a5b322 | 2010-07-13 14:55:28 -0700 | [diff] [blame] | 338 | } |
| 339 | // Should never be called |
| 340 | void TerminateProcessing() { |
| 341 | CHECK(false); |
| 342 | } |
| 343 | // Debugging/logging |
Alex Deymo | f329b93 | 2014-10-30 01:37:48 -0700 | [diff] [blame] | 344 | static string StaticType() { |
Darin Petkov | 6a5b322 | 2010-07-13 14:55:28 -0700 | [diff] [blame] | 345 | return "OutputObjectCollectorAction"; |
| 346 | } |
Alex Deymo | f329b93 | 2014-10-30 01:37:48 -0700 | [diff] [blame] | 347 | string Type() const { return StaticType(); } |
Alex Vakulenko | 0057daa | 2016-01-23 16:22:50 -0800 | [diff] [blame] | 348 | using InputObjectType = |
| 349 | ActionTraits<OutputObjectCollectorAction>::InputObjectType; |
| 350 | using OutputObjectType = |
| 351 | ActionTraits<OutputObjectCollectorAction>::OutputObjectType; |
Darin Petkov | 6a5b322 | 2010-07-13 14:55:28 -0700 | [diff] [blame] | 352 | bool has_input_object_; |
| 353 | OmahaResponse omaha_response_; |
| 354 | }; |
| 355 | |
Alex Deymo | e1e3afe | 2014-10-30 13:02:49 -0700 | [diff] [blame] | 356 | bool OmahaRequestActionTest::TestUpdateCheck( |
Alex Deymo | e1e3afe | 2014-10-30 13:02:49 -0700 | [diff] [blame] | 357 | const string& http_response, |
| 358 | int fail_http_response_code, |
| 359 | bool ping_only, |
| 360 | ErrorCode expected_code, |
| 361 | metrics::CheckResult expected_check_result, |
| 362 | metrics::CheckReaction expected_check_reaction, |
| 363 | metrics::DownloadErrorCode expected_download_error_code, |
| 364 | OmahaResponse* out_response, |
Alex Vakulenko | 3f39d5c | 2015-10-13 09:27:13 -0700 | [diff] [blame] | 365 | brillo::Blob* out_post_data) { |
| 366 | brillo::FakeMessageLoop loop(nullptr); |
Alex Deymo | 60ca1a7 | 2015-06-18 18:19:15 -0700 | [diff] [blame] | 367 | loop.SetAsCurrent(); |
Darin Petkov | 0dc8e9a | 2010-07-14 14:51:57 -0700 | [diff] [blame] | 368 | MockHttpFetcher* fetcher = new MockHttpFetcher(http_response.data(), |
Andrew de los Reyes | 4516810 | 2010-11-22 11:13:50 -0800 | [diff] [blame] | 369 | http_response.size(), |
Alex Vakulenko | 88b591f | 2014-08-28 16:48:57 -0700 | [diff] [blame] | 370 | nullptr); |
Darin Petkov | edc522e | 2010-11-05 09:35:17 -0700 | [diff] [blame] | 371 | if (fail_http_response_code >= 0) { |
| 372 | fetcher->FailTransfer(fail_http_response_code); |
| 373 | } |
Marton Hunyady | 2abda31 | 2018-04-24 18:21:49 +0200 | [diff] [blame^] | 374 | // This ensures the tests didn't forget to update fake_system_state_ if they |
| 375 | // are not using the default request_params_. |
| 376 | EXPECT_EQ(&request_params_, fake_system_state_.request_params()); |
| 377 | |
Alex Deymo | e1e3afe | 2014-10-30 13:02:49 -0700 | [diff] [blame] | 378 | OmahaRequestAction action(&fake_system_state_, |
Alex Vakulenko | 88b591f | 2014-08-28 16:48:57 -0700 | [diff] [blame] | 379 | nullptr, |
Ben Chan | 5c02c13 | 2017-06-27 07:10:36 -0700 | [diff] [blame] | 380 | base::WrapUnique(fetcher), |
Darin Petkov | 265f290 | 2011-05-09 15:17:40 -0700 | [diff] [blame] | 381 | ping_only); |
Darin Petkov | 6a5b322 | 2010-07-13 14:55:28 -0700 | [diff] [blame] | 382 | OmahaRequestActionTestProcessorDelegate delegate; |
Darin Petkov | c1a8b42 | 2010-07-19 11:34:49 -0700 | [diff] [blame] | 383 | delegate.expected_code_ = expected_code; |
Darin Petkov | a4a8a8c | 2010-07-15 22:21:12 -0700 | [diff] [blame] | 384 | |
Darin Petkov | 6a5b322 | 2010-07-13 14:55:28 -0700 | [diff] [blame] | 385 | ActionProcessor processor; |
Darin Petkov | 6a5b322 | 2010-07-13 14:55:28 -0700 | [diff] [blame] | 386 | processor.set_delegate(&delegate); |
Darin Petkov | 6a5b322 | 2010-07-13 14:55:28 -0700 | [diff] [blame] | 387 | processor.EnqueueAction(&action); |
| 388 | |
| 389 | OutputObjectCollectorAction collector_action; |
Darin Petkov | 6a5b322 | 2010-07-13 14:55:28 -0700 | [diff] [blame] | 390 | BondActions(&action, &collector_action); |
| 391 | processor.EnqueueAction(&collector_action); |
| 392 | |
Tianjie Xu | 282aa1f | 2017-09-05 13:42:45 -0700 | [diff] [blame] | 393 | EXPECT_CALL(*fake_system_state_.mock_metrics_reporter(), |
| 394 | ReportUpdateCheckMetrics(_, _, _, _)) |
David Zeuthen | 33bae49 | 2014-02-25 16:16:18 -0800 | [diff] [blame] | 395 | .Times(AnyNumber()); |
Tianjie Xu | 282aa1f | 2017-09-05 13:42:45 -0700 | [diff] [blame] | 396 | |
| 397 | EXPECT_CALL(*fake_system_state_.mock_metrics_reporter(), |
| 398 | ReportUpdateCheckMetrics(_, |
| 399 | expected_check_result, |
| 400 | expected_check_reaction, |
| 401 | expected_download_error_code)) |
| 402 | .Times(ping_only ? 0 : 1); |
David Zeuthen | 33bae49 | 2014-02-25 16:16:18 -0800 | [diff] [blame] | 403 | |
Luis Hector Chavez | f1cf348 | 2016-07-19 14:29:19 -0700 | [diff] [blame] | 404 | loop.PostTask(base::Bind( |
| 405 | [](ActionProcessor* processor) { processor->StartProcessing(); }, |
| 406 | base::Unretained(&processor))); |
Alex Deymo | 60ca1a7 | 2015-06-18 18:19:15 -0700 | [diff] [blame] | 407 | loop.Run(); |
Alex Deymo | 60ca1a7 | 2015-06-18 18:19:15 -0700 | [diff] [blame] | 408 | EXPECT_FALSE(loop.PendingTasks()); |
Darin Petkov | 6a5b322 | 2010-07-13 14:55:28 -0700 | [diff] [blame] | 409 | if (collector_action.has_input_object_ && out_response) |
| 410 | *out_response = collector_action.omaha_response_; |
| 411 | if (out_post_data) |
| 412 | *out_post_data = fetcher->post_data(); |
| 413 | return collector_action.has_input_object_; |
| 414 | } |
| 415 | |
Darin Petkov | 0dc8e9a | 2010-07-14 14:51:57 -0700 | [diff] [blame] | 416 | // Tests Event requests -- they should always succeed. |out_post_data| |
| 417 | // may be null; if non-null, the post-data received by the mock |
| 418 | // HttpFetcher is returned. |
Marton Hunyady | 2abda31 | 2018-04-24 18:21:49 +0200 | [diff] [blame^] | 419 | void TestEvent(OmahaEvent* event, |
Darin Petkov | 0dc8e9a | 2010-07-14 14:51:57 -0700 | [diff] [blame] | 420 | const string& http_response, |
Alex Vakulenko | 3f39d5c | 2015-10-13 09:27:13 -0700 | [diff] [blame] | 421 | brillo::Blob* out_post_data) { |
| 422 | brillo::FakeMessageLoop loop(nullptr); |
Alex Deymo | 60ca1a7 | 2015-06-18 18:19:15 -0700 | [diff] [blame] | 423 | loop.SetAsCurrent(); |
Darin Petkov | 0dc8e9a | 2010-07-14 14:51:57 -0700 | [diff] [blame] | 424 | MockHttpFetcher* fetcher = new MockHttpFetcher(http_response.data(), |
Andrew de los Reyes | 4516810 | 2010-11-22 11:13:50 -0800 | [diff] [blame] | 425 | http_response.size(), |
Alex Vakulenko | 88b591f | 2014-08-28 16:48:57 -0700 | [diff] [blame] | 426 | nullptr); |
Gilad Arnold | 5bb4c90 | 2014-04-10 12:32:13 -0700 | [diff] [blame] | 427 | FakeSystemState fake_system_state; |
Alex Deymo | c1c17b4 | 2015-11-23 03:53:15 -0300 | [diff] [blame] | 428 | OmahaRequestAction action(&fake_system_state, |
| 429 | event, |
Ben Chan | 5c02c13 | 2017-06-27 07:10:36 -0700 | [diff] [blame] | 430 | base::WrapUnique(fetcher), |
Alex Deymo | c1c17b4 | 2015-11-23 03:53:15 -0300 | [diff] [blame] | 431 | false); |
Darin Petkov | 0dc8e9a | 2010-07-14 14:51:57 -0700 | [diff] [blame] | 432 | OmahaRequestActionTestProcessorDelegate delegate; |
Darin Petkov | 0dc8e9a | 2010-07-14 14:51:57 -0700 | [diff] [blame] | 433 | ActionProcessor processor; |
Darin Petkov | 0dc8e9a | 2010-07-14 14:51:57 -0700 | [diff] [blame] | 434 | processor.set_delegate(&delegate); |
Darin Petkov | 0dc8e9a | 2010-07-14 14:51:57 -0700 | [diff] [blame] | 435 | processor.EnqueueAction(&action); |
| 436 | |
Luis Hector Chavez | f1cf348 | 2016-07-19 14:29:19 -0700 | [diff] [blame] | 437 | loop.PostTask(base::Bind( |
| 438 | [](ActionProcessor* processor) { processor->StartProcessing(); }, |
| 439 | base::Unretained(&processor))); |
Alex Deymo | 60ca1a7 | 2015-06-18 18:19:15 -0700 | [diff] [blame] | 440 | loop.Run(); |
Alex Deymo | 72a2567 | 2016-03-23 15:44:39 -0700 | [diff] [blame] | 441 | EXPECT_FALSE(loop.PendingTasks()); |
Alex Deymo | 60ca1a7 | 2015-06-18 18:19:15 -0700 | [diff] [blame] | 442 | |
Darin Petkov | 0dc8e9a | 2010-07-14 14:51:57 -0700 | [diff] [blame] | 443 | if (out_post_data) |
| 444 | *out_post_data = fetcher->post_data(); |
| 445 | } |
| 446 | |
Alex Deymo | e1e3afe | 2014-10-30 13:02:49 -0700 | [diff] [blame] | 447 | TEST_F(OmahaRequestActionTest, RejectEntities) { |
David Zeuthen | f3e2801 | 2014-08-26 18:23:52 -0400 | [diff] [blame] | 448 | OmahaResponse response; |
Alex Deymo | 8e18f93 | 2015-03-27 16:16:59 -0700 | [diff] [blame] | 449 | fake_update_response_.include_entity = true; |
Marton Hunyady | 2abda31 | 2018-04-24 18:21:49 +0200 | [diff] [blame^] | 450 | ASSERT_FALSE(TestUpdateCheck(fake_update_response_.GetNoUpdateResponse(), |
| 451 | -1, |
| 452 | false, // ping_only |
| 453 | ErrorCode::kOmahaRequestXMLHasEntityDecl, |
| 454 | metrics::CheckResult::kParsingError, |
| 455 | metrics::CheckReaction::kUnset, |
| 456 | metrics::DownloadErrorCode::kUnset, |
| 457 | &response, |
| 458 | nullptr)); |
David Zeuthen | f3e2801 | 2014-08-26 18:23:52 -0400 | [diff] [blame] | 459 | EXPECT_FALSE(response.update_exists); |
| 460 | } |
| 461 | |
Alex Deymo | e1e3afe | 2014-10-30 13:02:49 -0700 | [diff] [blame] | 462 | TEST_F(OmahaRequestActionTest, NoUpdateTest) { |
Darin Petkov | 6a5b322 | 2010-07-13 14:55:28 -0700 | [diff] [blame] | 463 | OmahaResponse response; |
Marton Hunyady | 2abda31 | 2018-04-24 18:21:49 +0200 | [diff] [blame^] | 464 | ASSERT_TRUE(TestUpdateCheck(fake_update_response_.GetNoUpdateResponse(), |
| 465 | -1, |
| 466 | false, // ping_only |
| 467 | ErrorCode::kSuccess, |
| 468 | metrics::CheckResult::kNoUpdateAvailable, |
| 469 | metrics::CheckReaction::kUnset, |
| 470 | metrics::DownloadErrorCode::kUnset, |
| 471 | &response, |
| 472 | nullptr)); |
Darin Petkov | 6a5b322 | 2010-07-13 14:55:28 -0700 | [diff] [blame] | 473 | EXPECT_FALSE(response.update_exists); |
| 474 | } |
| 475 | |
Sen Jiang | 8125968 | 2017-03-30 15:11:30 -0700 | [diff] [blame] | 476 | TEST_F(OmahaRequestActionTest, MultiAppNoUpdateTest) { |
| 477 | OmahaResponse response; |
| 478 | fake_update_response_.multi_app_no_update = true; |
Marton Hunyady | 2abda31 | 2018-04-24 18:21:49 +0200 | [diff] [blame^] | 479 | ASSERT_TRUE(TestUpdateCheck(fake_update_response_.GetNoUpdateResponse(), |
Sen Jiang | 8125968 | 2017-03-30 15:11:30 -0700 | [diff] [blame] | 480 | -1, |
| 481 | false, // ping_only |
| 482 | ErrorCode::kSuccess, |
| 483 | metrics::CheckResult::kNoUpdateAvailable, |
| 484 | metrics::CheckReaction::kUnset, |
| 485 | metrics::DownloadErrorCode::kUnset, |
| 486 | &response, |
| 487 | nullptr)); |
| 488 | EXPECT_FALSE(response.update_exists); |
| 489 | } |
| 490 | |
Sen Jiang | 00adf7b | 2017-06-26 15:57:29 -0700 | [diff] [blame] | 491 | TEST_F(OmahaRequestActionTest, MultiAppNoPartialUpdateTest) { |
| 492 | OmahaResponse response; |
| 493 | fake_update_response_.multi_app_no_update = true; |
Marton Hunyady | 2abda31 | 2018-04-24 18:21:49 +0200 | [diff] [blame^] | 494 | ASSERT_TRUE(TestUpdateCheck(fake_update_response_.GetUpdateResponse(), |
Sen Jiang | 00adf7b | 2017-06-26 15:57:29 -0700 | [diff] [blame] | 495 | -1, |
| 496 | false, // ping_only |
| 497 | ErrorCode::kSuccess, |
| 498 | metrics::CheckResult::kNoUpdateAvailable, |
| 499 | metrics::CheckReaction::kUnset, |
| 500 | metrics::DownloadErrorCode::kUnset, |
| 501 | &response, |
| 502 | nullptr)); |
| 503 | EXPECT_FALSE(response.update_exists); |
| 504 | } |
| 505 | |
| 506 | TEST_F(OmahaRequestActionTest, NoSelfUpdateTest) { |
| 507 | OmahaResponse response; |
| 508 | ASSERT_TRUE(TestUpdateCheck( |
Sen Jiang | 00adf7b | 2017-06-26 15:57:29 -0700 | [diff] [blame] | 509 | "<response><app><updatecheck status=\"ok\"><manifest><actions><action " |
| 510 | "event=\"postinstall\" noupdate=\"true\"/></actions>" |
| 511 | "</manifest></updatecheck></app></response>", |
| 512 | -1, |
| 513 | false, // ping_only |
| 514 | ErrorCode::kSuccess, |
| 515 | metrics::CheckResult::kNoUpdateAvailable, |
| 516 | metrics::CheckReaction::kUnset, |
| 517 | metrics::DownloadErrorCode::kUnset, |
| 518 | &response, |
| 519 | nullptr)); |
| 520 | EXPECT_FALSE(response.update_exists); |
| 521 | } |
| 522 | |
Alex Deymo | 8e18f93 | 2015-03-27 16:16:59 -0700 | [diff] [blame] | 523 | // Test that all the values in the response are parsed in a normal update |
| 524 | // response. |
Alex Deymo | e1e3afe | 2014-10-30 13:02:49 -0700 | [diff] [blame] | 525 | TEST_F(OmahaRequestActionTest, ValidUpdateTest) { |
Darin Petkov | 6a5b322 | 2010-07-13 14:55:28 -0700 | [diff] [blame] | 526 | OmahaResponse response; |
Alex Deymo | 8e18f93 | 2015-03-27 16:16:59 -0700 | [diff] [blame] | 527 | fake_update_response_.deadline = "20101020"; |
Marton Hunyady | 2abda31 | 2018-04-24 18:21:49 +0200 | [diff] [blame^] | 528 | ASSERT_TRUE(TestUpdateCheck(fake_update_response_.GetUpdateResponse(), |
| 529 | -1, |
| 530 | false, // ping_only |
| 531 | ErrorCode::kSuccess, |
| 532 | metrics::CheckResult::kUpdateAvailable, |
| 533 | metrics::CheckReaction::kUpdating, |
| 534 | metrics::DownloadErrorCode::kUnset, |
| 535 | &response, |
| 536 | nullptr)); |
Darin Petkov | 6a5b322 | 2010-07-13 14:55:28 -0700 | [diff] [blame] | 537 | EXPECT_TRUE(response.update_exists); |
Alex Deymo | 8e18f93 | 2015-03-27 16:16:59 -0700 | [diff] [blame] | 538 | EXPECT_EQ(fake_update_response_.version, response.version); |
Aaron Wood | 7dcdedf | 2017-09-06 17:17:41 -0700 | [diff] [blame] | 539 | EXPECT_EQ("", response.system_version); |
Sen Jiang | 0affc2c | 2017-02-10 15:55:05 -0800 | [diff] [blame] | 540 | EXPECT_EQ(fake_update_response_.GetPayloadUrl(), |
| 541 | response.packages[0].payload_urls[0]); |
Alex Deymo | 8e18f93 | 2015-03-27 16:16:59 -0700 | [diff] [blame] | 542 | EXPECT_EQ(fake_update_response_.more_info_url, response.more_info_url); |
Sen Jiang | 0affc2c | 2017-02-10 15:55:05 -0800 | [diff] [blame] | 543 | EXPECT_EQ(fake_update_response_.hash, response.packages[0].hash); |
| 544 | EXPECT_EQ(fake_update_response_.size, response.packages[0].size); |
Sen Jiang | cdd5206 | 2017-05-18 15:33:10 -0700 | [diff] [blame] | 545 | EXPECT_EQ(true, response.packages[0].is_delta); |
Alex Deymo | 8e18f93 | 2015-03-27 16:16:59 -0700 | [diff] [blame] | 546 | EXPECT_EQ(fake_update_response_.prompt == "true", response.prompt); |
| 547 | EXPECT_EQ(fake_update_response_.deadline, response.deadline); |
Aaron Wood | 7dcdedf | 2017-09-06 17:17:41 -0700 | [diff] [blame] | 548 | // Omaha cohort attributes are not set in the response, so they should not be |
Alex Deymo | 8e18f93 | 2015-03-27 16:16:59 -0700 | [diff] [blame] | 549 | // persisted. |
| 550 | EXPECT_FALSE(fake_prefs_.Exists(kPrefsOmahaCohort)); |
| 551 | EXPECT_FALSE(fake_prefs_.Exists(kPrefsOmahaCohortHint)); |
| 552 | EXPECT_FALSE(fake_prefs_.Exists(kPrefsOmahaCohortName)); |
Darin Petkov | 6a5b322 | 2010-07-13 14:55:28 -0700 | [diff] [blame] | 553 | } |
| 554 | |
Sen Jiang | 0affc2c | 2017-02-10 15:55:05 -0800 | [diff] [blame] | 555 | TEST_F(OmahaRequestActionTest, MultiPackageUpdateTest) { |
| 556 | OmahaResponse response; |
| 557 | fake_update_response_.multi_package = true; |
Marton Hunyady | 2abda31 | 2018-04-24 18:21:49 +0200 | [diff] [blame^] | 558 | ASSERT_TRUE(TestUpdateCheck(fake_update_response_.GetUpdateResponse(), |
Sen Jiang | 0affc2c | 2017-02-10 15:55:05 -0800 | [diff] [blame] | 559 | -1, |
| 560 | false, // ping_only |
| 561 | ErrorCode::kSuccess, |
| 562 | metrics::CheckResult::kUpdateAvailable, |
| 563 | metrics::CheckReaction::kUpdating, |
| 564 | metrics::DownloadErrorCode::kUnset, |
| 565 | &response, |
| 566 | nullptr)); |
| 567 | EXPECT_TRUE(response.update_exists); |
| 568 | EXPECT_EQ(fake_update_response_.version, response.version); |
| 569 | EXPECT_EQ(fake_update_response_.GetPayloadUrl(), |
| 570 | response.packages[0].payload_urls[0]); |
| 571 | EXPECT_EQ(fake_update_response_.codebase + "package2", |
| 572 | response.packages[1].payload_urls[0]); |
| 573 | EXPECT_EQ(fake_update_response_.hash, response.packages[0].hash); |
| 574 | EXPECT_EQ(fake_update_response_.size, response.packages[0].size); |
Sen Jiang | cdd5206 | 2017-05-18 15:33:10 -0700 | [diff] [blame] | 575 | EXPECT_EQ(true, response.packages[0].is_delta); |
Sen Jiang | 8125968 | 2017-03-30 15:11:30 -0700 | [diff] [blame] | 576 | EXPECT_EQ(11u, response.packages[0].metadata_size); |
Sen Jiang | 0affc2c | 2017-02-10 15:55:05 -0800 | [diff] [blame] | 577 | ASSERT_EQ(2u, response.packages.size()); |
Sen Jiang | 8125968 | 2017-03-30 15:11:30 -0700 | [diff] [blame] | 578 | EXPECT_EQ(string("hash2"), response.packages[1].hash); |
Sen Jiang | 0affc2c | 2017-02-10 15:55:05 -0800 | [diff] [blame] | 579 | EXPECT_EQ(222u, response.packages[1].size); |
Sen Jiang | 8125968 | 2017-03-30 15:11:30 -0700 | [diff] [blame] | 580 | EXPECT_EQ(22u, response.packages[1].metadata_size); |
Sen Jiang | cdd5206 | 2017-05-18 15:33:10 -0700 | [diff] [blame] | 581 | EXPECT_EQ(false, response.packages[1].is_delta); |
Sen Jiang | 8125968 | 2017-03-30 15:11:30 -0700 | [diff] [blame] | 582 | } |
| 583 | |
| 584 | TEST_F(OmahaRequestActionTest, MultiAppUpdateTest) { |
| 585 | OmahaResponse response; |
| 586 | fake_update_response_.multi_app = true; |
Marton Hunyady | 2abda31 | 2018-04-24 18:21:49 +0200 | [diff] [blame^] | 587 | ASSERT_TRUE(TestUpdateCheck(fake_update_response_.GetUpdateResponse(), |
Sen Jiang | 8125968 | 2017-03-30 15:11:30 -0700 | [diff] [blame] | 588 | -1, |
| 589 | false, // ping_only |
| 590 | ErrorCode::kSuccess, |
| 591 | metrics::CheckResult::kUpdateAvailable, |
| 592 | metrics::CheckReaction::kUpdating, |
| 593 | metrics::DownloadErrorCode::kUnset, |
| 594 | &response, |
| 595 | nullptr)); |
| 596 | EXPECT_TRUE(response.update_exists); |
| 597 | EXPECT_EQ(fake_update_response_.version, response.version); |
| 598 | EXPECT_EQ(fake_update_response_.GetPayloadUrl(), |
| 599 | response.packages[0].payload_urls[0]); |
| 600 | EXPECT_EQ(fake_update_response_.codebase2 + "package3", |
| 601 | response.packages[1].payload_urls[0]); |
| 602 | EXPECT_EQ(fake_update_response_.hash, response.packages[0].hash); |
| 603 | EXPECT_EQ(fake_update_response_.size, response.packages[0].size); |
| 604 | EXPECT_EQ(11u, response.packages[0].metadata_size); |
Sen Jiang | cdd5206 | 2017-05-18 15:33:10 -0700 | [diff] [blame] | 605 | EXPECT_EQ(true, response.packages[0].is_delta); |
Sen Jiang | 8125968 | 2017-03-30 15:11:30 -0700 | [diff] [blame] | 606 | ASSERT_EQ(2u, response.packages.size()); |
| 607 | EXPECT_EQ(string("hash3"), response.packages[1].hash); |
| 608 | EXPECT_EQ(333u, response.packages[1].size); |
| 609 | EXPECT_EQ(33u, response.packages[1].metadata_size); |
Sen Jiang | cdd5206 | 2017-05-18 15:33:10 -0700 | [diff] [blame] | 610 | EXPECT_EQ(false, response.packages[1].is_delta); |
Sen Jiang | 8125968 | 2017-03-30 15:11:30 -0700 | [diff] [blame] | 611 | } |
| 612 | |
Aaron Wood | 7dcdedf | 2017-09-06 17:17:41 -0700 | [diff] [blame] | 613 | TEST_F(OmahaRequestActionTest, MultiAppAndSystemUpdateTest) { |
| 614 | OmahaResponse response; |
| 615 | fake_update_response_.multi_app = true; |
| 616 | // trigger the lining up of the app and system versions |
| 617 | request_params_.set_system_app_id(fake_update_response_.app_id2); |
| 618 | |
Marton Hunyady | 2abda31 | 2018-04-24 18:21:49 +0200 | [diff] [blame^] | 619 | ASSERT_TRUE(TestUpdateCheck(fake_update_response_.GetUpdateResponse(), |
Aaron Wood | 7dcdedf | 2017-09-06 17:17:41 -0700 | [diff] [blame] | 620 | -1, |
| 621 | false, // ping_only |
| 622 | ErrorCode::kSuccess, |
| 623 | metrics::CheckResult::kUpdateAvailable, |
| 624 | metrics::CheckReaction::kUpdating, |
| 625 | metrics::DownloadErrorCode::kUnset, |
| 626 | &response, |
| 627 | nullptr)); |
| 628 | EXPECT_TRUE(response.update_exists); |
| 629 | EXPECT_EQ(fake_update_response_.version, response.version); |
| 630 | EXPECT_EQ(fake_update_response_.version2, response.system_version); |
| 631 | EXPECT_EQ(fake_update_response_.GetPayloadUrl(), |
| 632 | response.packages[0].payload_urls[0]); |
| 633 | EXPECT_EQ(fake_update_response_.codebase2 + "package3", |
| 634 | response.packages[1].payload_urls[0]); |
| 635 | EXPECT_EQ(fake_update_response_.hash, response.packages[0].hash); |
| 636 | EXPECT_EQ(fake_update_response_.size, response.packages[0].size); |
| 637 | EXPECT_EQ(11u, response.packages[0].metadata_size); |
| 638 | EXPECT_EQ(true, response.packages[0].is_delta); |
| 639 | ASSERT_EQ(2u, response.packages.size()); |
| 640 | EXPECT_EQ(string("hash3"), response.packages[1].hash); |
| 641 | EXPECT_EQ(333u, response.packages[1].size); |
| 642 | EXPECT_EQ(33u, response.packages[1].metadata_size); |
| 643 | EXPECT_EQ(false, response.packages[1].is_delta); |
| 644 | } |
| 645 | |
Sen Jiang | 8125968 | 2017-03-30 15:11:30 -0700 | [diff] [blame] | 646 | TEST_F(OmahaRequestActionTest, MultiAppPartialUpdateTest) { |
| 647 | OmahaResponse response; |
Sen Jiang | 00adf7b | 2017-06-26 15:57:29 -0700 | [diff] [blame] | 648 | fake_update_response_.multi_app = true; |
| 649 | fake_update_response_.multi_app_self_update = true; |
Marton Hunyady | 2abda31 | 2018-04-24 18:21:49 +0200 | [diff] [blame^] | 650 | ASSERT_TRUE(TestUpdateCheck(fake_update_response_.GetUpdateResponse(), |
Sen Jiang | 8125968 | 2017-03-30 15:11:30 -0700 | [diff] [blame] | 651 | -1, |
| 652 | false, // ping_only |
| 653 | ErrorCode::kSuccess, |
| 654 | metrics::CheckResult::kUpdateAvailable, |
| 655 | metrics::CheckReaction::kUpdating, |
| 656 | metrics::DownloadErrorCode::kUnset, |
| 657 | &response, |
| 658 | nullptr)); |
| 659 | EXPECT_TRUE(response.update_exists); |
| 660 | EXPECT_EQ(fake_update_response_.version, response.version); |
Aaron Wood | 7dcdedf | 2017-09-06 17:17:41 -0700 | [diff] [blame] | 661 | EXPECT_EQ("", response.system_version); |
Sen Jiang | 8125968 | 2017-03-30 15:11:30 -0700 | [diff] [blame] | 662 | EXPECT_EQ(fake_update_response_.GetPayloadUrl(), |
| 663 | response.packages[0].payload_urls[0]); |
| 664 | EXPECT_EQ(fake_update_response_.hash, response.packages[0].hash); |
| 665 | EXPECT_EQ(fake_update_response_.size, response.packages[0].size); |
| 666 | EXPECT_EQ(11u, response.packages[0].metadata_size); |
Sen Jiang | 00adf7b | 2017-06-26 15:57:29 -0700 | [diff] [blame] | 667 | ASSERT_EQ(2u, response.packages.size()); |
| 668 | EXPECT_EQ(string("hash3"), response.packages[1].hash); |
| 669 | EXPECT_EQ(333u, response.packages[1].size); |
| 670 | EXPECT_EQ(33u, response.packages[1].metadata_size); |
| 671 | EXPECT_EQ(true, response.packages[1].is_delta); |
Sen Jiang | 8125968 | 2017-03-30 15:11:30 -0700 | [diff] [blame] | 672 | } |
| 673 | |
| 674 | TEST_F(OmahaRequestActionTest, MultiAppMultiPackageUpdateTest) { |
| 675 | OmahaResponse response; |
| 676 | fake_update_response_.multi_app = true; |
| 677 | fake_update_response_.multi_package = true; |
Marton Hunyady | 2abda31 | 2018-04-24 18:21:49 +0200 | [diff] [blame^] | 678 | ASSERT_TRUE(TestUpdateCheck(fake_update_response_.GetUpdateResponse(), |
Sen Jiang | 8125968 | 2017-03-30 15:11:30 -0700 | [diff] [blame] | 679 | -1, |
| 680 | false, // ping_only |
| 681 | ErrorCode::kSuccess, |
| 682 | metrics::CheckResult::kUpdateAvailable, |
| 683 | metrics::CheckReaction::kUpdating, |
| 684 | metrics::DownloadErrorCode::kUnset, |
| 685 | &response, |
| 686 | nullptr)); |
| 687 | EXPECT_TRUE(response.update_exists); |
| 688 | EXPECT_EQ(fake_update_response_.version, response.version); |
Aaron Wood | 7dcdedf | 2017-09-06 17:17:41 -0700 | [diff] [blame] | 689 | EXPECT_EQ("", response.system_version); |
Sen Jiang | 8125968 | 2017-03-30 15:11:30 -0700 | [diff] [blame] | 690 | EXPECT_EQ(fake_update_response_.GetPayloadUrl(), |
| 691 | response.packages[0].payload_urls[0]); |
| 692 | EXPECT_EQ(fake_update_response_.codebase + "package2", |
| 693 | response.packages[1].payload_urls[0]); |
| 694 | EXPECT_EQ(fake_update_response_.codebase2 + "package3", |
| 695 | response.packages[2].payload_urls[0]); |
| 696 | EXPECT_EQ(fake_update_response_.hash, response.packages[0].hash); |
| 697 | EXPECT_EQ(fake_update_response_.size, response.packages[0].size); |
| 698 | EXPECT_EQ(11u, response.packages[0].metadata_size); |
Sen Jiang | cdd5206 | 2017-05-18 15:33:10 -0700 | [diff] [blame] | 699 | EXPECT_EQ(true, response.packages[0].is_delta); |
Sen Jiang | 8125968 | 2017-03-30 15:11:30 -0700 | [diff] [blame] | 700 | ASSERT_EQ(3u, response.packages.size()); |
| 701 | EXPECT_EQ(string("hash2"), response.packages[1].hash); |
| 702 | EXPECT_EQ(222u, response.packages[1].size); |
| 703 | EXPECT_EQ(22u, response.packages[1].metadata_size); |
Sen Jiang | cdd5206 | 2017-05-18 15:33:10 -0700 | [diff] [blame] | 704 | EXPECT_EQ(false, response.packages[1].is_delta); |
Sen Jiang | 8125968 | 2017-03-30 15:11:30 -0700 | [diff] [blame] | 705 | EXPECT_EQ(string("hash3"), response.packages[2].hash); |
| 706 | EXPECT_EQ(333u, response.packages[2].size); |
| 707 | EXPECT_EQ(33u, response.packages[2].metadata_size); |
Sen Jiang | cdd5206 | 2017-05-18 15:33:10 -0700 | [diff] [blame] | 708 | EXPECT_EQ(false, response.packages[2].is_delta); |
Sen Jiang | 0affc2c | 2017-02-10 15:55:05 -0800 | [diff] [blame] | 709 | } |
| 710 | |
Alex Deymo | 14ad88e | 2016-06-29 12:30:14 -0700 | [diff] [blame] | 711 | TEST_F(OmahaRequestActionTest, ExtraHeadersSentTest) { |
| 712 | const string http_response = "<?xml invalid response"; |
| 713 | request_params_.set_interactive(true); |
| 714 | |
| 715 | brillo::FakeMessageLoop loop(nullptr); |
| 716 | loop.SetAsCurrent(); |
| 717 | |
| 718 | MockHttpFetcher* fetcher = |
| 719 | new MockHttpFetcher(http_response.data(), http_response.size(), nullptr); |
Ben Chan | 5c02c13 | 2017-06-27 07:10:36 -0700 | [diff] [blame] | 720 | OmahaRequestAction action(&fake_system_state_, nullptr, |
| 721 | base::WrapUnique(fetcher), false); |
Alex Deymo | 14ad88e | 2016-06-29 12:30:14 -0700 | [diff] [blame] | 722 | ActionProcessor processor; |
| 723 | processor.EnqueueAction(&action); |
| 724 | |
Luis Hector Chavez | f1cf348 | 2016-07-19 14:29:19 -0700 | [diff] [blame] | 725 | loop.PostTask(base::Bind( |
| 726 | [](ActionProcessor* processor) { processor->StartProcessing(); }, |
| 727 | base::Unretained(&processor))); |
Alex Deymo | 14ad88e | 2016-06-29 12:30:14 -0700 | [diff] [blame] | 728 | loop.Run(); |
| 729 | EXPECT_FALSE(loop.PendingTasks()); |
| 730 | |
| 731 | // Check that the headers were set in the fetcher during the action. Note that |
| 732 | // we set this request as "interactive". |
Sen Jiang | 42fa45e | 2018-03-12 11:02:14 -0700 | [diff] [blame] | 733 | EXPECT_EQ("fg", fetcher->GetHeader("X-Goog-Update-Interactivity")); |
| 734 | EXPECT_EQ(kTestAppId, fetcher->GetHeader("X-Goog-Update-AppId")); |
| 735 | EXPECT_NE("", fetcher->GetHeader("X-Goog-Update-Updater")); |
Alex Deymo | 14ad88e | 2016-06-29 12:30:14 -0700 | [diff] [blame] | 736 | } |
| 737 | |
Alex Deymo | e1e3afe | 2014-10-30 13:02:49 -0700 | [diff] [blame] | 738 | TEST_F(OmahaRequestActionTest, ValidUpdateBlockedByConnection) { |
Chris Sosa | 77f79e8 | 2014-06-02 18:16:24 -0700 | [diff] [blame] | 739 | OmahaResponse response; |
| 740 | // Set up a connection manager that doesn't allow a valid update over |
| 741 | // the current ethernet connection. |
Alex Deymo | f6ee016 | 2015-07-31 12:35:22 -0700 | [diff] [blame] | 742 | MockConnectionManager mock_cm; |
Alex Deymo | e1e3afe | 2014-10-30 13:02:49 -0700 | [diff] [blame] | 743 | fake_system_state_.set_connection_manager(&mock_cm); |
| 744 | |
Alex Deymo | 3053450 | 2015-07-20 15:06:33 -0700 | [diff] [blame] | 745 | EXPECT_CALL(mock_cm, GetConnectionProperties(_, _)) |
| 746 | .WillRepeatedly( |
Ben Chan | 672c1f5 | 2017-10-23 15:41:39 -0700 | [diff] [blame] | 747 | DoAll(SetArgPointee<0>(ConnectionType::kEthernet), |
| 748 | SetArgPointee<1>(ConnectionTethering::kUnknown), |
Alex Deymo | 3053450 | 2015-07-20 15:06:33 -0700 | [diff] [blame] | 749 | Return(true))); |
Sen Jiang | 255e22b | 2016-05-20 16:15:29 -0700 | [diff] [blame] | 750 | EXPECT_CALL(mock_cm, IsUpdateAllowedOver(ConnectionType::kEthernet, _)) |
| 751 | .WillRepeatedly(Return(false)); |
Chris Sosa | 77f79e8 | 2014-06-02 18:16:24 -0700 | [diff] [blame] | 752 | |
Marton Hunyady | 2abda31 | 2018-04-24 18:21:49 +0200 | [diff] [blame^] | 753 | ASSERT_FALSE(TestUpdateCheck(fake_update_response_.GetUpdateResponse(), |
| 754 | -1, |
| 755 | false, // ping_only |
| 756 | ErrorCode::kOmahaUpdateIgnoredPerPolicy, |
| 757 | metrics::CheckResult::kUpdateAvailable, |
| 758 | metrics::CheckReaction::kIgnored, |
| 759 | metrics::DownloadErrorCode::kUnset, |
| 760 | &response, |
| 761 | nullptr)); |
Chris Sosa | 77f79e8 | 2014-06-02 18:16:24 -0700 | [diff] [blame] | 762 | EXPECT_FALSE(response.update_exists); |
| 763 | } |
| 764 | |
Weidong Guo | 421ff33 | 2017-04-17 10:08:38 -0700 | [diff] [blame] | 765 | TEST_F(OmahaRequestActionTest, ValidUpdateOverCellularAllowedByDevicePolicy) { |
| 766 | // This test tests that update over cellular is allowed as device policy |
| 767 | // says yes. |
| 768 | OmahaResponse response; |
| 769 | MockConnectionManager mock_cm; |
| 770 | |
| 771 | fake_system_state_.set_connection_manager(&mock_cm); |
| 772 | |
| 773 | EXPECT_CALL(mock_cm, GetConnectionProperties(_, _)) |
| 774 | .WillRepeatedly(DoAll(SetArgPointee<0>(ConnectionType::kCellular), |
| 775 | SetArgPointee<1>(ConnectionTethering::kUnknown), |
| 776 | Return(true))); |
| 777 | EXPECT_CALL(mock_cm, IsAllowedConnectionTypesForUpdateSet()) |
| 778 | .WillRepeatedly(Return(true)); |
| 779 | EXPECT_CALL(mock_cm, IsUpdateAllowedOver(ConnectionType::kCellular, _)) |
| 780 | .WillRepeatedly(Return(true)); |
| 781 | |
Marton Hunyady | 2abda31 | 2018-04-24 18:21:49 +0200 | [diff] [blame^] | 782 | ASSERT_TRUE(TestUpdateCheck(fake_update_response_.GetUpdateResponse(), |
Weidong Guo | 421ff33 | 2017-04-17 10:08:38 -0700 | [diff] [blame] | 783 | -1, |
| 784 | false, // ping_only |
| 785 | ErrorCode::kSuccess, |
| 786 | metrics::CheckResult::kUpdateAvailable, |
| 787 | metrics::CheckReaction::kUpdating, |
| 788 | metrics::DownloadErrorCode::kUnset, |
| 789 | &response, |
| 790 | nullptr)); |
| 791 | EXPECT_TRUE(response.update_exists); |
| 792 | } |
| 793 | |
| 794 | TEST_F(OmahaRequestActionTest, ValidUpdateOverCellularBlockedByDevicePolicy) { |
| 795 | // This test tests that update over cellular is blocked as device policy |
| 796 | // says no. |
| 797 | OmahaResponse response; |
| 798 | MockConnectionManager mock_cm; |
| 799 | |
| 800 | fake_system_state_.set_connection_manager(&mock_cm); |
| 801 | |
| 802 | EXPECT_CALL(mock_cm, GetConnectionProperties(_, _)) |
| 803 | .WillRepeatedly(DoAll(SetArgPointee<0>(ConnectionType::kCellular), |
| 804 | SetArgPointee<1>(ConnectionTethering::kUnknown), |
| 805 | Return(true))); |
| 806 | EXPECT_CALL(mock_cm, IsAllowedConnectionTypesForUpdateSet()) |
| 807 | .WillRepeatedly(Return(true)); |
| 808 | EXPECT_CALL(mock_cm, IsUpdateAllowedOver(ConnectionType::kCellular, _)) |
| 809 | .WillRepeatedly(Return(false)); |
| 810 | |
Marton Hunyady | 2abda31 | 2018-04-24 18:21:49 +0200 | [diff] [blame^] | 811 | ASSERT_FALSE(TestUpdateCheck(fake_update_response_.GetUpdateResponse(), |
Weidong Guo | 421ff33 | 2017-04-17 10:08:38 -0700 | [diff] [blame] | 812 | -1, |
| 813 | false, // ping_only |
| 814 | ErrorCode::kOmahaUpdateIgnoredPerPolicy, |
| 815 | metrics::CheckResult::kUpdateAvailable, |
| 816 | metrics::CheckReaction::kIgnored, |
| 817 | metrics::DownloadErrorCode::kUnset, |
| 818 | &response, |
| 819 | nullptr)); |
| 820 | EXPECT_FALSE(response.update_exists); |
| 821 | } |
| 822 | |
| 823 | TEST_F(OmahaRequestActionTest, |
| 824 | ValidUpdateOverCellularAllowedByUserPermissionTrue) { |
| 825 | // This test tests that, when device policy is not set, update over cellular |
| 826 | // is allowed as permission for update over cellular is set to true. |
| 827 | OmahaResponse response; |
| 828 | MockConnectionManager mock_cm; |
| 829 | |
| 830 | fake_prefs_.SetBoolean(kPrefsUpdateOverCellularPermission, true); |
| 831 | fake_system_state_.set_connection_manager(&mock_cm); |
| 832 | |
| 833 | EXPECT_CALL(mock_cm, GetConnectionProperties(_, _)) |
| 834 | .WillRepeatedly(DoAll(SetArgPointee<0>(ConnectionType::kCellular), |
| 835 | SetArgPointee<1>(ConnectionTethering::kUnknown), |
| 836 | Return(true))); |
| 837 | EXPECT_CALL(mock_cm, IsAllowedConnectionTypesForUpdateSet()) |
| 838 | .WillRepeatedly(Return(false)); |
| 839 | EXPECT_CALL(mock_cm, IsUpdateAllowedOver(ConnectionType::kCellular, _)) |
| 840 | .WillRepeatedly(Return(true)); |
| 841 | |
Marton Hunyady | 2abda31 | 2018-04-24 18:21:49 +0200 | [diff] [blame^] | 842 | ASSERT_TRUE(TestUpdateCheck(fake_update_response_.GetUpdateResponse(), |
Weidong Guo | 421ff33 | 2017-04-17 10:08:38 -0700 | [diff] [blame] | 843 | -1, |
| 844 | false, // ping_only |
| 845 | ErrorCode::kSuccess, |
| 846 | metrics::CheckResult::kUpdateAvailable, |
| 847 | metrics::CheckReaction::kUpdating, |
| 848 | metrics::DownloadErrorCode::kUnset, |
| 849 | &response, |
| 850 | nullptr)); |
| 851 | EXPECT_TRUE(response.update_exists); |
| 852 | } |
| 853 | |
| 854 | TEST_F(OmahaRequestActionTest, |
| 855 | ValidUpdateOverCellularBlockedByUpdateTargetNotMatch) { |
| 856 | // This test tests that, when device policy is not set and permission for |
| 857 | // update over cellular is set to false or does not exist, update over |
| 858 | // cellular is blocked as update target does not match the omaha response. |
| 859 | OmahaResponse response; |
| 860 | MockConnectionManager mock_cm; |
| 861 | // A version different from the version in omaha response. |
| 862 | string diff_version = "99.99.99"; |
| 863 | // A size different from the size in omaha response. |
| 864 | int64_t diff_size = 999; |
| 865 | |
| 866 | fake_prefs_.SetString(kPrefsUpdateOverCellularTargetVersion, diff_version); |
| 867 | fake_prefs_.SetInt64(kPrefsUpdateOverCellularTargetSize, diff_size); |
| 868 | // This test tests cellular (3G) being the only connection type being allowed. |
| 869 | fake_system_state_.set_connection_manager(&mock_cm); |
| 870 | |
| 871 | EXPECT_CALL(mock_cm, GetConnectionProperties(_, _)) |
| 872 | .WillRepeatedly(DoAll(SetArgPointee<0>(ConnectionType::kCellular), |
| 873 | SetArgPointee<1>(ConnectionTethering::kUnknown), |
| 874 | Return(true))); |
| 875 | EXPECT_CALL(mock_cm, IsAllowedConnectionTypesForUpdateSet()) |
| 876 | .WillRepeatedly(Return(false)); |
| 877 | EXPECT_CALL(mock_cm, IsUpdateAllowedOver(ConnectionType::kCellular, _)) |
| 878 | .WillRepeatedly(Return(true)); |
| 879 | |
Marton Hunyady | 2abda31 | 2018-04-24 18:21:49 +0200 | [diff] [blame^] | 880 | ASSERT_FALSE(TestUpdateCheck(fake_update_response_.GetUpdateResponse(), |
Weidong Guo | 421ff33 | 2017-04-17 10:08:38 -0700 | [diff] [blame] | 881 | -1, |
| 882 | false, // ping_only |
| 883 | ErrorCode::kOmahaUpdateIgnoredOverCellular, |
| 884 | metrics::CheckResult::kUpdateAvailable, |
| 885 | metrics::CheckReaction::kIgnored, |
| 886 | metrics::DownloadErrorCode::kUnset, |
| 887 | &response, |
| 888 | nullptr)); |
| 889 | EXPECT_FALSE(response.update_exists); |
| 890 | } |
| 891 | |
| 892 | TEST_F(OmahaRequestActionTest, |
| 893 | ValidUpdateOverCellularAllowedByUpdateTargetMatch) { |
| 894 | // This test tests that, when device policy is not set and permission for |
| 895 | // update over cellular is set to false or does not exist, update over |
| 896 | // cellular is allowed as update target matches the omaha response. |
| 897 | OmahaResponse response; |
| 898 | MockConnectionManager mock_cm; |
| 899 | // A version same as the version in omaha response. |
| 900 | string new_version = fake_update_response_.version; |
| 901 | // A size same as the size in omaha response. |
| 902 | int64_t new_size = fake_update_response_.size; |
| 903 | |
| 904 | fake_prefs_.SetString(kPrefsUpdateOverCellularTargetVersion, new_version); |
| 905 | fake_prefs_.SetInt64(kPrefsUpdateOverCellularTargetSize, new_size); |
| 906 | fake_system_state_.set_connection_manager(&mock_cm); |
| 907 | |
| 908 | EXPECT_CALL(mock_cm, GetConnectionProperties(_, _)) |
| 909 | .WillRepeatedly(DoAll(SetArgPointee<0>(ConnectionType::kCellular), |
| 910 | SetArgPointee<1>(ConnectionTethering::kUnknown), |
| 911 | Return(true))); |
| 912 | EXPECT_CALL(mock_cm, IsAllowedConnectionTypesForUpdateSet()) |
| 913 | .WillRepeatedly(Return(false)); |
| 914 | EXPECT_CALL(mock_cm, IsUpdateAllowedOver(ConnectionType::kCellular, _)) |
| 915 | .WillRepeatedly(Return(true)); |
| 916 | |
Marton Hunyady | 2abda31 | 2018-04-24 18:21:49 +0200 | [diff] [blame^] | 917 | ASSERT_TRUE(TestUpdateCheck(fake_update_response_.GetUpdateResponse(), |
Weidong Guo | 421ff33 | 2017-04-17 10:08:38 -0700 | [diff] [blame] | 918 | -1, |
| 919 | false, // ping_only |
| 920 | ErrorCode::kSuccess, |
| 921 | metrics::CheckResult::kUpdateAvailable, |
| 922 | metrics::CheckReaction::kUpdating, |
| 923 | metrics::DownloadErrorCode::kUnset, |
| 924 | &response, |
| 925 | nullptr)); |
| 926 | EXPECT_TRUE(response.update_exists); |
| 927 | } |
| 928 | |
Alex Deymo | e1e3afe | 2014-10-30 13:02:49 -0700 | [diff] [blame] | 929 | TEST_F(OmahaRequestActionTest, ValidUpdateBlockedByRollback) { |
Chris Sosa | 77f79e8 | 2014-06-02 18:16:24 -0700 | [diff] [blame] | 930 | string rollback_version = "1234.0.0"; |
| 931 | OmahaResponse response; |
| 932 | |
| 933 | MockPayloadState mock_payload_state; |
Alex Deymo | e1e3afe | 2014-10-30 13:02:49 -0700 | [diff] [blame] | 934 | fake_system_state_.set_payload_state(&mock_payload_state); |
| 935 | |
Chris Sosa | 77f79e8 | 2014-06-02 18:16:24 -0700 | [diff] [blame] | 936 | EXPECT_CALL(mock_payload_state, GetRollbackVersion()) |
| 937 | .WillRepeatedly(Return(rollback_version)); |
| 938 | |
Alex Deymo | 8e18f93 | 2015-03-27 16:16:59 -0700 | [diff] [blame] | 939 | fake_update_response_.version = rollback_version; |
Marton Hunyady | 2abda31 | 2018-04-24 18:21:49 +0200 | [diff] [blame^] | 940 | ASSERT_FALSE(TestUpdateCheck(fake_update_response_.GetUpdateResponse(), |
| 941 | -1, |
| 942 | false, // ping_only |
| 943 | ErrorCode::kOmahaUpdateIgnoredPerPolicy, |
| 944 | metrics::CheckResult::kUpdateAvailable, |
| 945 | metrics::CheckReaction::kIgnored, |
| 946 | metrics::DownloadErrorCode::kUnset, |
| 947 | &response, |
| 948 | nullptr)); |
Chris Sosa | 77f79e8 | 2014-06-02 18:16:24 -0700 | [diff] [blame] | 949 | EXPECT_FALSE(response.update_exists); |
| 950 | } |
| 951 | |
Kevin Cernekee | 2494e28 | 2016-03-29 18:03:53 -0700 | [diff] [blame] | 952 | // Verify that update checks called during OOBE will only try to download |
| 953 | // an update if the response includes a non-empty deadline field. |
| 954 | TEST_F(OmahaRequestActionTest, SkipNonCriticalUpdatesBeforeOOBE) { |
| 955 | OmahaResponse response; |
| 956 | |
Sen Jiang | 8cd4234 | 2018-01-31 12:06:59 -0800 | [diff] [blame] | 957 | // TODO(senj): set better default value for metrics::checkresult in |
Tianjie Xu | 282aa1f | 2017-09-05 13:42:45 -0700 | [diff] [blame] | 958 | // OmahaRequestAction::ActionCompleted. |
Kevin Cernekee | 2494e28 | 2016-03-29 18:03:53 -0700 | [diff] [blame] | 959 | fake_system_state_.fake_hardware()->UnsetIsOOBEComplete(); |
Marton Hunyady | 2abda31 | 2018-04-24 18:21:49 +0200 | [diff] [blame^] | 960 | ASSERT_FALSE(TestUpdateCheck(fake_update_response_.GetUpdateResponse(), |
Tianjie Xu | 282aa1f | 2017-09-05 13:42:45 -0700 | [diff] [blame] | 961 | -1, |
| 962 | false, // ping_only |
| 963 | ErrorCode::kNonCriticalUpdateInOOBE, |
| 964 | metrics::CheckResult::kParsingError, |
| 965 | metrics::CheckReaction::kUnset, |
| 966 | metrics::DownloadErrorCode::kUnset, |
| 967 | &response, |
| 968 | nullptr)); |
Kevin Cernekee | 2494e28 | 2016-03-29 18:03:53 -0700 | [diff] [blame] | 969 | EXPECT_FALSE(response.update_exists); |
| 970 | |
Alex Deymo | 46a9aae | 2016-05-04 20:20:11 -0700 | [diff] [blame] | 971 | // The IsOOBEComplete() value is ignored when the OOBE flow is not enabled. |
| 972 | fake_system_state_.fake_hardware()->SetIsOOBEEnabled(false); |
Marton Hunyady | 2abda31 | 2018-04-24 18:21:49 +0200 | [diff] [blame^] | 973 | ASSERT_TRUE(TestUpdateCheck(fake_update_response_.GetUpdateResponse(), |
Alex Deymo | 46a9aae | 2016-05-04 20:20:11 -0700 | [diff] [blame] | 974 | -1, |
| 975 | false, // ping_only |
| 976 | ErrorCode::kSuccess, |
| 977 | metrics::CheckResult::kUpdateAvailable, |
| 978 | metrics::CheckReaction::kUpdating, |
| 979 | metrics::DownloadErrorCode::kUnset, |
| 980 | &response, |
| 981 | nullptr)); |
| 982 | EXPECT_TRUE(response.update_exists); |
| 983 | fake_system_state_.fake_hardware()->SetIsOOBEEnabled(true); |
| 984 | |
| 985 | // The payload is applied when a deadline was set in the response. |
Kevin Cernekee | 2494e28 | 2016-03-29 18:03:53 -0700 | [diff] [blame] | 986 | fake_update_response_.deadline = "20101020"; |
Marton Hunyady | 2abda31 | 2018-04-24 18:21:49 +0200 | [diff] [blame^] | 987 | ASSERT_TRUE(TestUpdateCheck(fake_update_response_.GetUpdateResponse(), |
| 988 | -1, |
| 989 | false, // ping_only |
| 990 | ErrorCode::kSuccess, |
| 991 | metrics::CheckResult::kUpdateAvailable, |
| 992 | metrics::CheckReaction::kUpdating, |
| 993 | metrics::DownloadErrorCode::kUnset, |
| 994 | &response, |
| 995 | nullptr)); |
Kevin Cernekee | 2494e28 | 2016-03-29 18:03:53 -0700 | [diff] [blame] | 996 | EXPECT_TRUE(response.update_exists); |
| 997 | } |
| 998 | |
Alex Deymo | e1e3afe | 2014-10-30 13:02:49 -0700 | [diff] [blame] | 999 | TEST_F(OmahaRequestActionTest, WallClockBasedWaitAloneCausesScattering) { |
Jay Srinivasan | 480ddfa | 2012-06-01 19:15:26 -0700 | [diff] [blame] | 1000 | OmahaResponse response; |
Marton Hunyady | 2abda31 | 2018-04-24 18:21:49 +0200 | [diff] [blame^] | 1001 | request_params_.set_wall_clock_based_wait_enabled(true); |
| 1002 | request_params_.set_update_check_count_wait_enabled(false); |
| 1003 | request_params_.set_waiting_period(TimeDelta::FromDays(2)); |
Jay Srinivasan | 480ddfa | 2012-06-01 19:15:26 -0700 | [diff] [blame] | 1004 | |
Marton Hunyady | 2abda31 | 2018-04-24 18:21:49 +0200 | [diff] [blame^] | 1005 | ASSERT_FALSE(TestUpdateCheck(fake_update_response_.GetUpdateResponse(), |
| 1006 | -1, |
| 1007 | false, // ping_only |
| 1008 | ErrorCode::kOmahaUpdateDeferredPerPolicy, |
| 1009 | metrics::CheckResult::kUpdateAvailable, |
| 1010 | metrics::CheckReaction::kDeferring, |
| 1011 | metrics::DownloadErrorCode::kUnset, |
| 1012 | &response, |
| 1013 | nullptr)); |
Jay Srinivasan | 480ddfa | 2012-06-01 19:15:26 -0700 | [diff] [blame] | 1014 | EXPECT_FALSE(response.update_exists); |
Chris Sosa | 968d057 | 2013-08-23 14:46:02 -0700 | [diff] [blame] | 1015 | |
| 1016 | // Verify if we are interactive check we don't defer. |
Marton Hunyady | 2abda31 | 2018-04-24 18:21:49 +0200 | [diff] [blame^] | 1017 | request_params_.set_interactive(true); |
| 1018 | ASSERT_TRUE(TestUpdateCheck(fake_update_response_.GetUpdateResponse(), |
| 1019 | -1, |
| 1020 | false, // ping_only |
| 1021 | ErrorCode::kSuccess, |
| 1022 | metrics::CheckResult::kUpdateAvailable, |
| 1023 | metrics::CheckReaction::kUpdating, |
| 1024 | metrics::DownloadErrorCode::kUnset, |
| 1025 | &response, |
| 1026 | nullptr)); |
Chris Sosa | 968d057 | 2013-08-23 14:46:02 -0700 | [diff] [blame] | 1027 | EXPECT_TRUE(response.update_exists); |
Jay Srinivasan | 480ddfa | 2012-06-01 19:15:26 -0700 | [diff] [blame] | 1028 | } |
| 1029 | |
Alex Deymo | e1e3afe | 2014-10-30 13:02:49 -0700 | [diff] [blame] | 1030 | TEST_F(OmahaRequestActionTest, NoWallClockBasedWaitCausesNoScattering) { |
Jay Srinivasan | 480ddfa | 2012-06-01 19:15:26 -0700 | [diff] [blame] | 1031 | OmahaResponse response; |
Marton Hunyady | 2abda31 | 2018-04-24 18:21:49 +0200 | [diff] [blame^] | 1032 | request_params_.set_wall_clock_based_wait_enabled(false); |
| 1033 | request_params_.set_waiting_period(TimeDelta::FromDays(2)); |
| 1034 | request_params_.set_update_check_count_wait_enabled(true); |
| 1035 | request_params_.set_min_update_checks_needed(1); |
| 1036 | request_params_.set_max_update_checks_allowed(8); |
Jay Srinivasan | 480ddfa | 2012-06-01 19:15:26 -0700 | [diff] [blame] | 1037 | |
Marton Hunyady | 2abda31 | 2018-04-24 18:21:49 +0200 | [diff] [blame^] | 1038 | ASSERT_TRUE(TestUpdateCheck(fake_update_response_.GetUpdateResponse(), |
| 1039 | -1, |
| 1040 | false, // ping_only |
| 1041 | ErrorCode::kSuccess, |
| 1042 | metrics::CheckResult::kUpdateAvailable, |
| 1043 | metrics::CheckReaction::kUpdating, |
| 1044 | metrics::DownloadErrorCode::kUnset, |
| 1045 | &response, |
| 1046 | nullptr)); |
Jay Srinivasan | 480ddfa | 2012-06-01 19:15:26 -0700 | [diff] [blame] | 1047 | EXPECT_TRUE(response.update_exists); |
| 1048 | } |
| 1049 | |
Alex Deymo | e1e3afe | 2014-10-30 13:02:49 -0700 | [diff] [blame] | 1050 | TEST_F(OmahaRequestActionTest, ZeroMaxDaysToScatterCausesNoScattering) { |
Jay Srinivasan | 480ddfa | 2012-06-01 19:15:26 -0700 | [diff] [blame] | 1051 | OmahaResponse response; |
Marton Hunyady | 2abda31 | 2018-04-24 18:21:49 +0200 | [diff] [blame^] | 1052 | request_params_.set_wall_clock_based_wait_enabled(true); |
| 1053 | request_params_.set_waiting_period(TimeDelta::FromDays(2)); |
| 1054 | request_params_.set_update_check_count_wait_enabled(true); |
| 1055 | request_params_.set_min_update_checks_needed(1); |
| 1056 | request_params_.set_max_update_checks_allowed(8); |
Jay Srinivasan | 480ddfa | 2012-06-01 19:15:26 -0700 | [diff] [blame] | 1057 | |
Alex Deymo | 8e18f93 | 2015-03-27 16:16:59 -0700 | [diff] [blame] | 1058 | fake_update_response_.max_days_to_scatter = "0"; |
Marton Hunyady | 2abda31 | 2018-04-24 18:21:49 +0200 | [diff] [blame^] | 1059 | ASSERT_TRUE(TestUpdateCheck(fake_update_response_.GetUpdateResponse(), |
| 1060 | -1, |
| 1061 | false, // ping_only |
| 1062 | ErrorCode::kSuccess, |
| 1063 | metrics::CheckResult::kUpdateAvailable, |
| 1064 | metrics::CheckReaction::kUpdating, |
| 1065 | metrics::DownloadErrorCode::kUnset, |
| 1066 | &response, |
| 1067 | nullptr)); |
Jay Srinivasan | 480ddfa | 2012-06-01 19:15:26 -0700 | [diff] [blame] | 1068 | EXPECT_TRUE(response.update_exists); |
| 1069 | } |
| 1070 | |
| 1071 | |
Alex Deymo | e1e3afe | 2014-10-30 13:02:49 -0700 | [diff] [blame] | 1072 | TEST_F(OmahaRequestActionTest, ZeroUpdateCheckCountCausesNoScattering) { |
Jay Srinivasan | 480ddfa | 2012-06-01 19:15:26 -0700 | [diff] [blame] | 1073 | OmahaResponse response; |
Marton Hunyady | 2abda31 | 2018-04-24 18:21:49 +0200 | [diff] [blame^] | 1074 | request_params_.set_wall_clock_based_wait_enabled(true); |
| 1075 | request_params_.set_waiting_period(TimeDelta()); |
| 1076 | request_params_.set_update_check_count_wait_enabled(true); |
| 1077 | request_params_.set_min_update_checks_needed(0); |
| 1078 | request_params_.set_max_update_checks_allowed(0); |
Jay Srinivasan | 480ddfa | 2012-06-01 19:15:26 -0700 | [diff] [blame] | 1079 | |
Jay Srinivasan | 480ddfa | 2012-06-01 19:15:26 -0700 | [diff] [blame] | 1080 | ASSERT_TRUE(TestUpdateCheck( |
Alex Deymo | 8e18f93 | 2015-03-27 16:16:59 -0700 | [diff] [blame] | 1081 | fake_update_response_.GetUpdateResponse(), |
Jay Srinivasan | 480ddfa | 2012-06-01 19:15:26 -0700 | [diff] [blame] | 1082 | -1, |
| 1083 | false, // ping_only |
Gilad Arnold | d1c4d2d | 2014-06-05 14:07:53 -0700 | [diff] [blame] | 1084 | ErrorCode::kSuccess, |
David Zeuthen | 33bae49 | 2014-02-25 16:16:18 -0800 | [diff] [blame] | 1085 | metrics::CheckResult::kUpdateAvailable, |
| 1086 | metrics::CheckReaction::kUpdating, |
| 1087 | metrics::DownloadErrorCode::kUnset, |
Jay Srinivasan | 480ddfa | 2012-06-01 19:15:26 -0700 | [diff] [blame] | 1088 | &response, |
Alex Vakulenko | 88b591f | 2014-08-28 16:48:57 -0700 | [diff] [blame] | 1089 | nullptr)); |
Jay Srinivasan | 480ddfa | 2012-06-01 19:15:26 -0700 | [diff] [blame] | 1090 | |
Ben Chan | 9abb763 | 2014-08-07 00:10:53 -0700 | [diff] [blame] | 1091 | int64_t count; |
Alex Deymo | e1e3afe | 2014-10-30 13:02:49 -0700 | [diff] [blame] | 1092 | ASSERT_TRUE(fake_prefs_.GetInt64(kPrefsUpdateCheckCount, &count)); |
Alex Vakulenko | d2779df | 2014-06-16 13:19:00 -0700 | [diff] [blame] | 1093 | ASSERT_EQ(count, 0); |
Jay Srinivasan | 480ddfa | 2012-06-01 19:15:26 -0700 | [diff] [blame] | 1094 | EXPECT_TRUE(response.update_exists); |
| 1095 | } |
| 1096 | |
Alex Deymo | e1e3afe | 2014-10-30 13:02:49 -0700 | [diff] [blame] | 1097 | TEST_F(OmahaRequestActionTest, NonZeroUpdateCheckCountCausesScattering) { |
Jay Srinivasan | 480ddfa | 2012-06-01 19:15:26 -0700 | [diff] [blame] | 1098 | OmahaResponse response; |
Marton Hunyady | 2abda31 | 2018-04-24 18:21:49 +0200 | [diff] [blame^] | 1099 | request_params_.set_wall_clock_based_wait_enabled(true); |
| 1100 | request_params_.set_waiting_period(TimeDelta()); |
| 1101 | request_params_.set_update_check_count_wait_enabled(true); |
| 1102 | request_params_.set_min_update_checks_needed(1); |
| 1103 | request_params_.set_max_update_checks_allowed(8); |
Jay Srinivasan | 480ddfa | 2012-06-01 19:15:26 -0700 | [diff] [blame] | 1104 | |
Jay Srinivasan | 480ddfa | 2012-06-01 19:15:26 -0700 | [diff] [blame] | 1105 | ASSERT_FALSE(TestUpdateCheck( |
Alex Deymo | 8e18f93 | 2015-03-27 16:16:59 -0700 | [diff] [blame] | 1106 | fake_update_response_.GetUpdateResponse(), |
Jay Srinivasan | 480ddfa | 2012-06-01 19:15:26 -0700 | [diff] [blame] | 1107 | -1, |
| 1108 | false, // ping_only |
Gilad Arnold | d1c4d2d | 2014-06-05 14:07:53 -0700 | [diff] [blame] | 1109 | ErrorCode::kOmahaUpdateDeferredPerPolicy, |
David Zeuthen | 33bae49 | 2014-02-25 16:16:18 -0800 | [diff] [blame] | 1110 | metrics::CheckResult::kUpdateAvailable, |
| 1111 | metrics::CheckReaction::kDeferring, |
| 1112 | metrics::DownloadErrorCode::kUnset, |
Jay Srinivasan | 480ddfa | 2012-06-01 19:15:26 -0700 | [diff] [blame] | 1113 | &response, |
Alex Vakulenko | 88b591f | 2014-08-28 16:48:57 -0700 | [diff] [blame] | 1114 | nullptr)); |
Jay Srinivasan | 480ddfa | 2012-06-01 19:15:26 -0700 | [diff] [blame] | 1115 | |
Ben Chan | 9abb763 | 2014-08-07 00:10:53 -0700 | [diff] [blame] | 1116 | int64_t count; |
Alex Deymo | e1e3afe | 2014-10-30 13:02:49 -0700 | [diff] [blame] | 1117 | ASSERT_TRUE(fake_prefs_.GetInt64(kPrefsUpdateCheckCount, &count)); |
Alex Vakulenko | d2779df | 2014-06-16 13:19:00 -0700 | [diff] [blame] | 1118 | ASSERT_GT(count, 0); |
Jay Srinivasan | 480ddfa | 2012-06-01 19:15:26 -0700 | [diff] [blame] | 1119 | EXPECT_FALSE(response.update_exists); |
Chris Sosa | 968d057 | 2013-08-23 14:46:02 -0700 | [diff] [blame] | 1120 | |
| 1121 | // Verify if we are interactive check we don't defer. |
Marton Hunyady | 2abda31 | 2018-04-24 18:21:49 +0200 | [diff] [blame^] | 1122 | request_params_.set_interactive(true); |
| 1123 | ASSERT_TRUE(TestUpdateCheck(fake_update_response_.GetUpdateResponse(), |
| 1124 | -1, |
| 1125 | false, // ping_only |
| 1126 | ErrorCode::kSuccess, |
| 1127 | metrics::CheckResult::kUpdateAvailable, |
| 1128 | metrics::CheckReaction::kUpdating, |
| 1129 | metrics::DownloadErrorCode::kUnset, |
| 1130 | &response, |
| 1131 | nullptr)); |
Chris Sosa | 968d057 | 2013-08-23 14:46:02 -0700 | [diff] [blame] | 1132 | EXPECT_TRUE(response.update_exists); |
Jay Srinivasan | 480ddfa | 2012-06-01 19:15:26 -0700 | [diff] [blame] | 1133 | } |
| 1134 | |
Alex Deymo | e1e3afe | 2014-10-30 13:02:49 -0700 | [diff] [blame] | 1135 | TEST_F(OmahaRequestActionTest, ExistingUpdateCheckCountCausesScattering) { |
Jay Srinivasan | 480ddfa | 2012-06-01 19:15:26 -0700 | [diff] [blame] | 1136 | OmahaResponse response; |
Marton Hunyady | 2abda31 | 2018-04-24 18:21:49 +0200 | [diff] [blame^] | 1137 | request_params_.set_wall_clock_based_wait_enabled(true); |
| 1138 | request_params_.set_waiting_period(TimeDelta()); |
| 1139 | request_params_.set_update_check_count_wait_enabled(true); |
| 1140 | request_params_.set_min_update_checks_needed(1); |
| 1141 | request_params_.set_max_update_checks_allowed(8); |
Jay Srinivasan | 480ddfa | 2012-06-01 19:15:26 -0700 | [diff] [blame] | 1142 | |
Alex Deymo | e1e3afe | 2014-10-30 13:02:49 -0700 | [diff] [blame] | 1143 | ASSERT_TRUE(fake_prefs_.SetInt64(kPrefsUpdateCheckCount, 5)); |
Jay Srinivasan | 480ddfa | 2012-06-01 19:15:26 -0700 | [diff] [blame] | 1144 | |
| 1145 | ASSERT_FALSE(TestUpdateCheck( |
Alex Deymo | 8e18f93 | 2015-03-27 16:16:59 -0700 | [diff] [blame] | 1146 | fake_update_response_.GetUpdateResponse(), |
Jay Srinivasan | 480ddfa | 2012-06-01 19:15:26 -0700 | [diff] [blame] | 1147 | -1, |
| 1148 | false, // ping_only |
Gilad Arnold | d1c4d2d | 2014-06-05 14:07:53 -0700 | [diff] [blame] | 1149 | ErrorCode::kOmahaUpdateDeferredPerPolicy, |
David Zeuthen | 33bae49 | 2014-02-25 16:16:18 -0800 | [diff] [blame] | 1150 | metrics::CheckResult::kUpdateAvailable, |
| 1151 | metrics::CheckReaction::kDeferring, |
| 1152 | metrics::DownloadErrorCode::kUnset, |
Jay Srinivasan | 480ddfa | 2012-06-01 19:15:26 -0700 | [diff] [blame] | 1153 | &response, |
Alex Vakulenko | 88b591f | 2014-08-28 16:48:57 -0700 | [diff] [blame] | 1154 | nullptr)); |
Jay Srinivasan | 480ddfa | 2012-06-01 19:15:26 -0700 | [diff] [blame] | 1155 | |
Ben Chan | 9abb763 | 2014-08-07 00:10:53 -0700 | [diff] [blame] | 1156 | int64_t count; |
Alex Deymo | e1e3afe | 2014-10-30 13:02:49 -0700 | [diff] [blame] | 1157 | ASSERT_TRUE(fake_prefs_.GetInt64(kPrefsUpdateCheckCount, &count)); |
Jay Srinivasan | 480ddfa | 2012-06-01 19:15:26 -0700 | [diff] [blame] | 1158 | // count remains the same, as the decrementing happens in update_attempter |
| 1159 | // which this test doesn't exercise. |
Alex Vakulenko | d2779df | 2014-06-16 13:19:00 -0700 | [diff] [blame] | 1160 | ASSERT_EQ(count, 5); |
Jay Srinivasan | 480ddfa | 2012-06-01 19:15:26 -0700 | [diff] [blame] | 1161 | EXPECT_FALSE(response.update_exists); |
Chris Sosa | 968d057 | 2013-08-23 14:46:02 -0700 | [diff] [blame] | 1162 | |
| 1163 | // Verify if we are interactive check we don't defer. |
Marton Hunyady | 2abda31 | 2018-04-24 18:21:49 +0200 | [diff] [blame^] | 1164 | request_params_.set_interactive(true); |
| 1165 | ASSERT_TRUE(TestUpdateCheck(fake_update_response_.GetUpdateResponse(), |
| 1166 | -1, |
| 1167 | false, // ping_only |
| 1168 | ErrorCode::kSuccess, |
| 1169 | metrics::CheckResult::kUpdateAvailable, |
| 1170 | metrics::CheckReaction::kUpdating, |
| 1171 | metrics::DownloadErrorCode::kUnset, |
| 1172 | &response, |
| 1173 | nullptr)); |
Chris Sosa | 968d057 | 2013-08-23 14:46:02 -0700 | [diff] [blame] | 1174 | EXPECT_TRUE(response.update_exists); |
Jay Srinivasan | 480ddfa | 2012-06-01 19:15:26 -0700 | [diff] [blame] | 1175 | } |
Jay Srinivasan | 0a70874 | 2012-03-20 11:26:12 -0700 | [diff] [blame] | 1176 | |
Alex Deymo | 8e18f93 | 2015-03-27 16:16:59 -0700 | [diff] [blame] | 1177 | TEST_F(OmahaRequestActionTest, CohortsArePersisted) { |
| 1178 | OmahaResponse response; |
Alex Deymo | 8e18f93 | 2015-03-27 16:16:59 -0700 | [diff] [blame] | 1179 | fake_update_response_.include_cohorts = true; |
| 1180 | fake_update_response_.cohort = "s/154454/8479665"; |
| 1181 | fake_update_response_.cohorthint = "please-put-me-on-beta"; |
| 1182 | fake_update_response_.cohortname = "stable"; |
| 1183 | |
Marton Hunyady | 2abda31 | 2018-04-24 18:21:49 +0200 | [diff] [blame^] | 1184 | ASSERT_TRUE(TestUpdateCheck(fake_update_response_.GetUpdateResponse(), |
Alex Deymo | 8e18f93 | 2015-03-27 16:16:59 -0700 | [diff] [blame] | 1185 | -1, |
| 1186 | false, // ping_only |
| 1187 | ErrorCode::kSuccess, |
| 1188 | metrics::CheckResult::kUpdateAvailable, |
| 1189 | metrics::CheckReaction::kUpdating, |
| 1190 | metrics::DownloadErrorCode::kUnset, |
| 1191 | &response, |
| 1192 | nullptr)); |
| 1193 | |
| 1194 | string value; |
| 1195 | EXPECT_TRUE(fake_prefs_.GetString(kPrefsOmahaCohort, &value)); |
| 1196 | EXPECT_EQ(fake_update_response_.cohort, value); |
| 1197 | |
| 1198 | EXPECT_TRUE(fake_prefs_.GetString(kPrefsOmahaCohortHint, &value)); |
| 1199 | EXPECT_EQ(fake_update_response_.cohorthint, value); |
| 1200 | |
| 1201 | EXPECT_TRUE(fake_prefs_.GetString(kPrefsOmahaCohortName, &value)); |
| 1202 | EXPECT_EQ(fake_update_response_.cohortname, value); |
| 1203 | } |
| 1204 | |
| 1205 | TEST_F(OmahaRequestActionTest, CohortsAreUpdated) { |
| 1206 | OmahaResponse response; |
Alex Deymo | 8e18f93 | 2015-03-27 16:16:59 -0700 | [diff] [blame] | 1207 | EXPECT_TRUE(fake_prefs_.SetString(kPrefsOmahaCohort, "old_value")); |
| 1208 | EXPECT_TRUE(fake_prefs_.SetString(kPrefsOmahaCohortHint, "old_hint")); |
| 1209 | EXPECT_TRUE(fake_prefs_.SetString(kPrefsOmahaCohortName, "old_name")); |
| 1210 | fake_update_response_.include_cohorts = true; |
| 1211 | fake_update_response_.cohort = "s/154454/8479665"; |
| 1212 | fake_update_response_.cohorthint = "please-put-me-on-beta"; |
| 1213 | fake_update_response_.cohortname = ""; |
| 1214 | |
Marton Hunyady | 2abda31 | 2018-04-24 18:21:49 +0200 | [diff] [blame^] | 1215 | ASSERT_TRUE(TestUpdateCheck(fake_update_response_.GetUpdateResponse(), |
Alex Deymo | 8e18f93 | 2015-03-27 16:16:59 -0700 | [diff] [blame] | 1216 | -1, |
| 1217 | false, // ping_only |
| 1218 | ErrorCode::kSuccess, |
| 1219 | metrics::CheckResult::kUpdateAvailable, |
| 1220 | metrics::CheckReaction::kUpdating, |
| 1221 | metrics::DownloadErrorCode::kUnset, |
| 1222 | &response, |
| 1223 | nullptr)); |
| 1224 | |
| 1225 | string value; |
| 1226 | EXPECT_TRUE(fake_prefs_.GetString(kPrefsOmahaCohort, &value)); |
| 1227 | EXPECT_EQ(fake_update_response_.cohort, value); |
| 1228 | |
| 1229 | EXPECT_TRUE(fake_prefs_.GetString(kPrefsOmahaCohortHint, &value)); |
| 1230 | EXPECT_EQ(fake_update_response_.cohorthint, value); |
| 1231 | |
| 1232 | EXPECT_FALSE(fake_prefs_.GetString(kPrefsOmahaCohortName, &value)); |
| 1233 | } |
| 1234 | |
| 1235 | TEST_F(OmahaRequestActionTest, CohortsAreNotModifiedWhenMissing) { |
| 1236 | OmahaResponse response; |
Alex Deymo | 8e18f93 | 2015-03-27 16:16:59 -0700 | [diff] [blame] | 1237 | EXPECT_TRUE(fake_prefs_.SetString(kPrefsOmahaCohort, "old_value")); |
| 1238 | |
Marton Hunyady | 2abda31 | 2018-04-24 18:21:49 +0200 | [diff] [blame^] | 1239 | ASSERT_TRUE(TestUpdateCheck(fake_update_response_.GetUpdateResponse(), |
Alex Deymo | 8e18f93 | 2015-03-27 16:16:59 -0700 | [diff] [blame] | 1240 | -1, |
| 1241 | false, // ping_only |
| 1242 | ErrorCode::kSuccess, |
| 1243 | metrics::CheckResult::kUpdateAvailable, |
| 1244 | metrics::CheckReaction::kUpdating, |
| 1245 | metrics::DownloadErrorCode::kUnset, |
| 1246 | &response, |
| 1247 | nullptr)); |
| 1248 | |
| 1249 | string value; |
| 1250 | EXPECT_TRUE(fake_prefs_.GetString(kPrefsOmahaCohort, &value)); |
| 1251 | EXPECT_EQ("old_value", value); |
| 1252 | |
| 1253 | EXPECT_FALSE(fake_prefs_.GetString(kPrefsOmahaCohortHint, &value)); |
| 1254 | EXPECT_FALSE(fake_prefs_.GetString(kPrefsOmahaCohortName, &value)); |
| 1255 | } |
| 1256 | |
Alex Deymo | 00d79ac | 2015-06-29 15:41:49 -0700 | [diff] [blame] | 1257 | TEST_F(OmahaRequestActionTest, CohortsArePersistedWhenNoUpdate) { |
| 1258 | OmahaResponse response; |
Alex Deymo | 00d79ac | 2015-06-29 15:41:49 -0700 | [diff] [blame] | 1259 | fake_update_response_.include_cohorts = true; |
| 1260 | fake_update_response_.cohort = "s/154454/8479665"; |
| 1261 | fake_update_response_.cohorthint = "please-put-me-on-beta"; |
| 1262 | fake_update_response_.cohortname = "stable"; |
| 1263 | |
Marton Hunyady | 2abda31 | 2018-04-24 18:21:49 +0200 | [diff] [blame^] | 1264 | ASSERT_TRUE(TestUpdateCheck(fake_update_response_.GetNoUpdateResponse(), |
Alex Deymo | 00d79ac | 2015-06-29 15:41:49 -0700 | [diff] [blame] | 1265 | -1, |
| 1266 | false, // ping_only |
| 1267 | ErrorCode::kSuccess, |
| 1268 | metrics::CheckResult::kNoUpdateAvailable, |
| 1269 | metrics::CheckReaction::kUnset, |
| 1270 | metrics::DownloadErrorCode::kUnset, |
| 1271 | &response, |
| 1272 | nullptr)); |
| 1273 | |
| 1274 | string value; |
| 1275 | EXPECT_TRUE(fake_prefs_.GetString(kPrefsOmahaCohort, &value)); |
| 1276 | EXPECT_EQ(fake_update_response_.cohort, value); |
| 1277 | |
| 1278 | EXPECT_TRUE(fake_prefs_.GetString(kPrefsOmahaCohortHint, &value)); |
| 1279 | EXPECT_EQ(fake_update_response_.cohorthint, value); |
| 1280 | |
| 1281 | EXPECT_TRUE(fake_prefs_.GetString(kPrefsOmahaCohortName, &value)); |
| 1282 | EXPECT_EQ(fake_update_response_.cohortname, value); |
| 1283 | } |
| 1284 | |
Sen Jiang | b1e063a | 2017-09-15 17:44:31 -0700 | [diff] [blame] | 1285 | TEST_F(OmahaRequestActionTest, MultiAppCohortTest) { |
| 1286 | OmahaResponse response; |
Sen Jiang | b1e063a | 2017-09-15 17:44:31 -0700 | [diff] [blame] | 1287 | fake_update_response_.multi_app = true; |
| 1288 | fake_update_response_.include_cohorts = true; |
| 1289 | fake_update_response_.cohort = "s/154454/8479665"; |
| 1290 | fake_update_response_.cohorthint = "please-put-me-on-beta"; |
| 1291 | fake_update_response_.cohortname = "stable"; |
| 1292 | |
Marton Hunyady | 2abda31 | 2018-04-24 18:21:49 +0200 | [diff] [blame^] | 1293 | ASSERT_TRUE(TestUpdateCheck(fake_update_response_.GetUpdateResponse(), |
Sen Jiang | b1e063a | 2017-09-15 17:44:31 -0700 | [diff] [blame] | 1294 | -1, |
| 1295 | false, // ping_only |
| 1296 | ErrorCode::kSuccess, |
| 1297 | metrics::CheckResult::kUpdateAvailable, |
| 1298 | metrics::CheckReaction::kUpdating, |
| 1299 | metrics::DownloadErrorCode::kUnset, |
| 1300 | &response, |
| 1301 | nullptr)); |
| 1302 | |
| 1303 | string value; |
| 1304 | EXPECT_TRUE(fake_prefs_.GetString(kPrefsOmahaCohort, &value)); |
| 1305 | EXPECT_EQ(fake_update_response_.cohort, value); |
| 1306 | |
| 1307 | EXPECT_TRUE(fake_prefs_.GetString(kPrefsOmahaCohortHint, &value)); |
| 1308 | EXPECT_EQ(fake_update_response_.cohorthint, value); |
| 1309 | |
| 1310 | EXPECT_TRUE(fake_prefs_.GetString(kPrefsOmahaCohortName, &value)); |
| 1311 | EXPECT_EQ(fake_update_response_.cohortname, value); |
| 1312 | } |
| 1313 | |
Alex Deymo | e1e3afe | 2014-10-30 13:02:49 -0700 | [diff] [blame] | 1314 | TEST_F(OmahaRequestActionTest, NoOutputPipeTest) { |
Alex Deymo | 8e18f93 | 2015-03-27 16:16:59 -0700 | [diff] [blame] | 1315 | const string http_response(fake_update_response_.GetNoUpdateResponse()); |
Darin Petkov | 6a5b322 | 2010-07-13 14:55:28 -0700 | [diff] [blame] | 1316 | |
Alex Vakulenko | 3f39d5c | 2015-10-13 09:27:13 -0700 | [diff] [blame] | 1317 | brillo::FakeMessageLoop loop(nullptr); |
Alex Deymo | 60ca1a7 | 2015-06-18 18:19:15 -0700 | [diff] [blame] | 1318 | loop.SetAsCurrent(); |
Darin Petkov | 6a5b322 | 2010-07-13 14:55:28 -0700 | [diff] [blame] | 1319 | |
Ben Chan | 5c02c13 | 2017-06-27 07:10:36 -0700 | [diff] [blame] | 1320 | OmahaRequestAction action( |
| 1321 | &fake_system_state_, |
| 1322 | nullptr, |
Ben Chan | ab5a0af | 2017-10-12 14:57:50 -0700 | [diff] [blame] | 1323 | std::make_unique<MockHttpFetcher>(http_response.data(), |
Ben Chan | 5c02c13 | 2017-06-27 07:10:36 -0700 | [diff] [blame] | 1324 | http_response.size(), |
| 1325 | nullptr), |
| 1326 | false); |
Darin Petkov | 6a5b322 | 2010-07-13 14:55:28 -0700 | [diff] [blame] | 1327 | OmahaRequestActionTestProcessorDelegate delegate; |
Darin Petkov | 6a5b322 | 2010-07-13 14:55:28 -0700 | [diff] [blame] | 1328 | ActionProcessor processor; |
| 1329 | processor.set_delegate(&delegate); |
Darin Petkov | 6a5b322 | 2010-07-13 14:55:28 -0700 | [diff] [blame] | 1330 | processor.EnqueueAction(&action); |
Darin Petkov | 6a5b322 | 2010-07-13 14:55:28 -0700 | [diff] [blame] | 1331 | |
Luis Hector Chavez | f1cf348 | 2016-07-19 14:29:19 -0700 | [diff] [blame] | 1332 | loop.PostTask(base::Bind( |
| 1333 | [](ActionProcessor* processor) { processor->StartProcessing(); }, |
| 1334 | base::Unretained(&processor))); |
Alex Deymo | 60ca1a7 | 2015-06-18 18:19:15 -0700 | [diff] [blame] | 1335 | loop.Run(); |
| 1336 | EXPECT_FALSE(loop.PendingTasks()); |
Darin Petkov | 6a5b322 | 2010-07-13 14:55:28 -0700 | [diff] [blame] | 1337 | EXPECT_FALSE(processor.IsRunning()); |
| 1338 | } |
| 1339 | |
Alex Deymo | e1e3afe | 2014-10-30 13:02:49 -0700 | [diff] [blame] | 1340 | TEST_F(OmahaRequestActionTest, InvalidXmlTest) { |
Darin Petkov | 6a5b322 | 2010-07-13 14:55:28 -0700 | [diff] [blame] | 1341 | OmahaResponse response; |
Marton Hunyady | 2abda31 | 2018-04-24 18:21:49 +0200 | [diff] [blame^] | 1342 | ASSERT_FALSE(TestUpdateCheck("invalid xml>", |
| 1343 | -1, |
| 1344 | false, // ping_only |
| 1345 | ErrorCode::kOmahaRequestXMLParseError, |
| 1346 | metrics::CheckResult::kParsingError, |
| 1347 | metrics::CheckReaction::kUnset, |
| 1348 | metrics::DownloadErrorCode::kUnset, |
| 1349 | &response, |
| 1350 | nullptr)); |
Darin Petkov | edc522e | 2010-11-05 09:35:17 -0700 | [diff] [blame] | 1351 | EXPECT_FALSE(response.update_exists); |
| 1352 | } |
| 1353 | |
Alex Deymo | e1e3afe | 2014-10-30 13:02:49 -0700 | [diff] [blame] | 1354 | TEST_F(OmahaRequestActionTest, EmptyResponseTest) { |
Darin Petkov | edc522e | 2010-11-05 09:35:17 -0700 | [diff] [blame] | 1355 | OmahaResponse response; |
Marton Hunyady | 2abda31 | 2018-04-24 18:21:49 +0200 | [diff] [blame^] | 1356 | ASSERT_FALSE(TestUpdateCheck("", |
| 1357 | -1, |
| 1358 | false, // ping_only |
| 1359 | ErrorCode::kOmahaRequestEmptyResponseError, |
| 1360 | metrics::CheckResult::kParsingError, |
| 1361 | metrics::CheckReaction::kUnset, |
| 1362 | metrics::DownloadErrorCode::kUnset, |
| 1363 | &response, |
| 1364 | nullptr)); |
Darin Petkov | 6a5b322 | 2010-07-13 14:55:28 -0700 | [diff] [blame] | 1365 | EXPECT_FALSE(response.update_exists); |
| 1366 | } |
| 1367 | |
Alex Deymo | e1e3afe | 2014-10-30 13:02:49 -0700 | [diff] [blame] | 1368 | TEST_F(OmahaRequestActionTest, MissingStatusTest) { |
Darin Petkov | 6a5b322 | 2010-07-13 14:55:28 -0700 | [diff] [blame] | 1369 | OmahaResponse response; |
Darin Petkov | 0dc8e9a | 2010-07-14 14:51:57 -0700 | [diff] [blame] | 1370 | ASSERT_FALSE(TestUpdateCheck( |
Jay Srinivasan | 23b92a5 | 2012-10-27 02:00:21 -0700 | [diff] [blame] | 1371 | "<?xml version=\"1.0\" encoding=\"UTF-8\"?><response protocol=\"3.0\">" |
| 1372 | "<daystart elapsed_seconds=\"100\"/>" |
| 1373 | "<app appid=\"foo\" status=\"ok\">" |
| 1374 | "<ping status=\"ok\"/>" |
| 1375 | "<updatecheck/></app></response>", |
Darin Petkov | edc522e | 2010-11-05 09:35:17 -0700 | [diff] [blame] | 1376 | -1, |
Darin Petkov | 265f290 | 2011-05-09 15:17:40 -0700 | [diff] [blame] | 1377 | false, // ping_only |
Gilad Arnold | d1c4d2d | 2014-06-05 14:07:53 -0700 | [diff] [blame] | 1378 | ErrorCode::kOmahaResponseInvalid, |
David Zeuthen | 33bae49 | 2014-02-25 16:16:18 -0800 | [diff] [blame] | 1379 | metrics::CheckResult::kParsingError, |
| 1380 | metrics::CheckReaction::kUnset, |
| 1381 | metrics::DownloadErrorCode::kUnset, |
Darin Petkov | 6a5b322 | 2010-07-13 14:55:28 -0700 | [diff] [blame] | 1382 | &response, |
Alex Vakulenko | 88b591f | 2014-08-28 16:48:57 -0700 | [diff] [blame] | 1383 | nullptr)); |
Darin Petkov | 6a5b322 | 2010-07-13 14:55:28 -0700 | [diff] [blame] | 1384 | EXPECT_FALSE(response.update_exists); |
| 1385 | } |
| 1386 | |
Alex Deymo | e1e3afe | 2014-10-30 13:02:49 -0700 | [diff] [blame] | 1387 | TEST_F(OmahaRequestActionTest, InvalidStatusTest) { |
Darin Petkov | 6a5b322 | 2010-07-13 14:55:28 -0700 | [diff] [blame] | 1388 | OmahaResponse response; |
Darin Petkov | 0dc8e9a | 2010-07-14 14:51:57 -0700 | [diff] [blame] | 1389 | ASSERT_FALSE(TestUpdateCheck( |
Jay Srinivasan | 23b92a5 | 2012-10-27 02:00:21 -0700 | [diff] [blame] | 1390 | "<?xml version=\"1.0\" encoding=\"UTF-8\"?><response protocol=\"3.0\">" |
| 1391 | "<daystart elapsed_seconds=\"100\"/>" |
| 1392 | "<app appid=\"foo\" status=\"ok\">" |
| 1393 | "<ping status=\"ok\"/>" |
| 1394 | "<updatecheck status=\"InvalidStatusTest\"/></app></response>", |
Darin Petkov | edc522e | 2010-11-05 09:35:17 -0700 | [diff] [blame] | 1395 | -1, |
Darin Petkov | 265f290 | 2011-05-09 15:17:40 -0700 | [diff] [blame] | 1396 | false, // ping_only |
Gilad Arnold | d1c4d2d | 2014-06-05 14:07:53 -0700 | [diff] [blame] | 1397 | ErrorCode::kOmahaResponseInvalid, |
David Zeuthen | 33bae49 | 2014-02-25 16:16:18 -0800 | [diff] [blame] | 1398 | metrics::CheckResult::kParsingError, |
| 1399 | metrics::CheckReaction::kUnset, |
| 1400 | metrics::DownloadErrorCode::kUnset, |
Darin Petkov | 6a5b322 | 2010-07-13 14:55:28 -0700 | [diff] [blame] | 1401 | &response, |
Alex Vakulenko | 88b591f | 2014-08-28 16:48:57 -0700 | [diff] [blame] | 1402 | nullptr)); |
Darin Petkov | 6a5b322 | 2010-07-13 14:55:28 -0700 | [diff] [blame] | 1403 | EXPECT_FALSE(response.update_exists); |
| 1404 | } |
| 1405 | |
Alex Deymo | e1e3afe | 2014-10-30 13:02:49 -0700 | [diff] [blame] | 1406 | TEST_F(OmahaRequestActionTest, MissingNodesetTest) { |
Darin Petkov | 6a5b322 | 2010-07-13 14:55:28 -0700 | [diff] [blame] | 1407 | OmahaResponse response; |
Darin Petkov | 0dc8e9a | 2010-07-14 14:51:57 -0700 | [diff] [blame] | 1408 | ASSERT_FALSE(TestUpdateCheck( |
Jay Srinivasan | 23b92a5 | 2012-10-27 02:00:21 -0700 | [diff] [blame] | 1409 | "<?xml version=\"1.0\" encoding=\"UTF-8\"?><response protocol=\"3.0\">" |
| 1410 | "<daystart elapsed_seconds=\"100\"/>" |
| 1411 | "<app appid=\"foo\" status=\"ok\">" |
| 1412 | "<ping status=\"ok\"/>" |
| 1413 | "</app></response>", |
Darin Petkov | edc522e | 2010-11-05 09:35:17 -0700 | [diff] [blame] | 1414 | -1, |
Darin Petkov | 265f290 | 2011-05-09 15:17:40 -0700 | [diff] [blame] | 1415 | false, // ping_only |
Gilad Arnold | d1c4d2d | 2014-06-05 14:07:53 -0700 | [diff] [blame] | 1416 | ErrorCode::kOmahaResponseInvalid, |
David Zeuthen | 33bae49 | 2014-02-25 16:16:18 -0800 | [diff] [blame] | 1417 | metrics::CheckResult::kParsingError, |
| 1418 | metrics::CheckReaction::kUnset, |
| 1419 | metrics::DownloadErrorCode::kUnset, |
Darin Petkov | 6a5b322 | 2010-07-13 14:55:28 -0700 | [diff] [blame] | 1420 | &response, |
Alex Vakulenko | 88b591f | 2014-08-28 16:48:57 -0700 | [diff] [blame] | 1421 | nullptr)); |
Darin Petkov | 6a5b322 | 2010-07-13 14:55:28 -0700 | [diff] [blame] | 1422 | EXPECT_FALSE(response.update_exists); |
| 1423 | } |
| 1424 | |
Alex Deymo | e1e3afe | 2014-10-30 13:02:49 -0700 | [diff] [blame] | 1425 | TEST_F(OmahaRequestActionTest, MissingFieldTest) { |
Jay Srinivasan | 23b92a5 | 2012-10-27 02:00:21 -0700 | [diff] [blame] | 1426 | string input_response = |
| 1427 | "<?xml version=\"1.0\" encoding=\"UTF-8\"?><response protocol=\"3.0\">" |
| 1428 | "<daystart elapsed_seconds=\"100\"/>" |
Aaron Wood | 7dcdedf | 2017-09-06 17:17:41 -0700 | [diff] [blame] | 1429 | // the appid needs to match that in the request params |
| 1430 | "<app appid=\"" + |
| 1431 | fake_update_response_.app_id + |
| 1432 | "\" status=\"ok\">" |
Jay Srinivasan | 23b92a5 | 2012-10-27 02:00:21 -0700 | [diff] [blame] | 1433 | "<updatecheck status=\"ok\">" |
| 1434 | "<urls><url codebase=\"http://missing/field/test/\"/></urls>" |
Chris Sosa | 3b74843 | 2013-06-20 16:42:59 -0700 | [diff] [blame] | 1435 | "<manifest version=\"10.2.3.4\">" |
Jay Srinivasan | 23b92a5 | 2012-10-27 02:00:21 -0700 | [diff] [blame] | 1436 | "<packages><package hash=\"not-used\" name=\"f\" " |
Sen Jiang | 2703ef4 | 2017-03-16 13:36:21 -0700 | [diff] [blame] | 1437 | "size=\"587\" hash_sha256=\"lkq34j5345\"/></packages>" |
Jay Srinivasan | 23b92a5 | 2012-10-27 02:00:21 -0700 | [diff] [blame] | 1438 | "<actions><action event=\"postinstall\" " |
Jay Srinivasan | 23b92a5 | 2012-10-27 02:00:21 -0700 | [diff] [blame] | 1439 | "ChromeOSVersion=\"10.2.3.4\" " |
| 1440 | "Prompt=\"false\" " |
| 1441 | "IsDelta=\"true\" " |
Jay Srinivasan | d671e97 | 2013-01-11 17:17:19 -0800 | [diff] [blame] | 1442 | "IsDeltaPayload=\"false\" " |
Sen Jiang | 2703ef4 | 2017-03-16 13:36:21 -0700 | [diff] [blame] | 1443 | "sha256=\"not-used\" " |
Jay Srinivasan | 23b92a5 | 2012-10-27 02:00:21 -0700 | [diff] [blame] | 1444 | "needsadmin=\"true\" " |
| 1445 | "/></actions></manifest></updatecheck></app></response>"; |
| 1446 | LOG(INFO) << "Input Response = " << input_response; |
| 1447 | |
Darin Petkov | 6a5b322 | 2010-07-13 14:55:28 -0700 | [diff] [blame] | 1448 | OmahaResponse response; |
Marton Hunyady | 2abda31 | 2018-04-24 18:21:49 +0200 | [diff] [blame^] | 1449 | ASSERT_TRUE(TestUpdateCheck(input_response, |
Darin Petkov | edc522e | 2010-11-05 09:35:17 -0700 | [diff] [blame] | 1450 | -1, |
Darin Petkov | 265f290 | 2011-05-09 15:17:40 -0700 | [diff] [blame] | 1451 | false, // ping_only |
Gilad Arnold | d1c4d2d | 2014-06-05 14:07:53 -0700 | [diff] [blame] | 1452 | ErrorCode::kSuccess, |
David Zeuthen | 33bae49 | 2014-02-25 16:16:18 -0800 | [diff] [blame] | 1453 | metrics::CheckResult::kUpdateAvailable, |
| 1454 | metrics::CheckReaction::kUpdating, |
| 1455 | metrics::DownloadErrorCode::kUnset, |
Darin Petkov | 0dc8e9a | 2010-07-14 14:51:57 -0700 | [diff] [blame] | 1456 | &response, |
Alex Vakulenko | 88b591f | 2014-08-28 16:48:57 -0700 | [diff] [blame] | 1457 | nullptr)); |
Darin Petkov | 6a5b322 | 2010-07-13 14:55:28 -0700 | [diff] [blame] | 1458 | EXPECT_TRUE(response.update_exists); |
Chris Sosa | 3b74843 | 2013-06-20 16:42:59 -0700 | [diff] [blame] | 1459 | EXPECT_EQ("10.2.3.4", response.version); |
Sen Jiang | 0affc2c | 2017-02-10 15:55:05 -0800 | [diff] [blame] | 1460 | EXPECT_EQ("http://missing/field/test/f", |
| 1461 | response.packages[0].payload_urls[0]); |
Darin Petkov | 6a5b322 | 2010-07-13 14:55:28 -0700 | [diff] [blame] | 1462 | EXPECT_EQ("", response.more_info_url); |
Sen Jiang | 0affc2c | 2017-02-10 15:55:05 -0800 | [diff] [blame] | 1463 | EXPECT_EQ("lkq34j5345", response.packages[0].hash); |
| 1464 | EXPECT_EQ(587u, response.packages[0].size); |
Darin Petkov | 6a5b322 | 2010-07-13 14:55:28 -0700 | [diff] [blame] | 1465 | EXPECT_FALSE(response.prompt); |
Darin Petkov | 6c11864 | 2010-10-21 12:06:30 -0700 | [diff] [blame] | 1466 | EXPECT_TRUE(response.deadline.empty()); |
Darin Petkov | 6a5b322 | 2010-07-13 14:55:28 -0700 | [diff] [blame] | 1467 | } |
| 1468 | |
| 1469 | namespace { |
| 1470 | class TerminateEarlyTestProcessorDelegate : public ActionProcessorDelegate { |
| 1471 | public: |
| 1472 | void ProcessingStopped(const ActionProcessor* processor) { |
Alex Vakulenko | 3f39d5c | 2015-10-13 09:27:13 -0700 | [diff] [blame] | 1473 | brillo::MessageLoop::current()->BreakLoop(); |
Darin Petkov | 6a5b322 | 2010-07-13 14:55:28 -0700 | [diff] [blame] | 1474 | } |
Darin Petkov | 6a5b322 | 2010-07-13 14:55:28 -0700 | [diff] [blame] | 1475 | }; |
| 1476 | |
Alex Deymo | 60ca1a7 | 2015-06-18 18:19:15 -0700 | [diff] [blame] | 1477 | void TerminateTransferTestStarter(ActionProcessor* processor) { |
Darin Petkov | 6a5b322 | 2010-07-13 14:55:28 -0700 | [diff] [blame] | 1478 | processor->StartProcessing(); |
| 1479 | CHECK(processor->IsRunning()); |
| 1480 | processor->StopProcessing(); |
Darin Petkov | 6a5b322 | 2010-07-13 14:55:28 -0700 | [diff] [blame] | 1481 | } |
Alex Vakulenko | d2779df | 2014-06-16 13:19:00 -0700 | [diff] [blame] | 1482 | } // namespace |
Darin Petkov | 6a5b322 | 2010-07-13 14:55:28 -0700 | [diff] [blame] | 1483 | |
Alex Deymo | e1e3afe | 2014-10-30 13:02:49 -0700 | [diff] [blame] | 1484 | TEST_F(OmahaRequestActionTest, TerminateTransferTest) { |
Alex Vakulenko | 3f39d5c | 2015-10-13 09:27:13 -0700 | [diff] [blame] | 1485 | brillo::FakeMessageLoop loop(nullptr); |
Alex Deymo | 60ca1a7 | 2015-06-18 18:19:15 -0700 | [diff] [blame] | 1486 | loop.SetAsCurrent(); |
Darin Petkov | 6a5b322 | 2010-07-13 14:55:28 -0700 | [diff] [blame] | 1487 | |
Alex Deymo | 60ca1a7 | 2015-06-18 18:19:15 -0700 | [diff] [blame] | 1488 | string http_response("doesn't matter"); |
Ben Chan | 5c02c13 | 2017-06-27 07:10:36 -0700 | [diff] [blame] | 1489 | OmahaRequestAction action( |
| 1490 | &fake_system_state_, |
| 1491 | nullptr, |
Ben Chan | ab5a0af | 2017-10-12 14:57:50 -0700 | [diff] [blame] | 1492 | std::make_unique<MockHttpFetcher>(http_response.data(), |
Ben Chan | 5c02c13 | 2017-06-27 07:10:36 -0700 | [diff] [blame] | 1493 | http_response.size(), |
| 1494 | nullptr), |
| 1495 | false); |
Darin Petkov | 6a5b322 | 2010-07-13 14:55:28 -0700 | [diff] [blame] | 1496 | TerminateEarlyTestProcessorDelegate delegate; |
Darin Petkov | 6a5b322 | 2010-07-13 14:55:28 -0700 | [diff] [blame] | 1497 | ActionProcessor processor; |
| 1498 | processor.set_delegate(&delegate); |
Darin Petkov | 6a5b322 | 2010-07-13 14:55:28 -0700 | [diff] [blame] | 1499 | processor.EnqueueAction(&action); |
Darin Petkov | 6a5b322 | 2010-07-13 14:55:28 -0700 | [diff] [blame] | 1500 | |
Alex Deymo | 60ca1a7 | 2015-06-18 18:19:15 -0700 | [diff] [blame] | 1501 | loop.PostTask(base::Bind(&TerminateTransferTestStarter, &processor)); |
| 1502 | loop.Run(); |
| 1503 | EXPECT_FALSE(loop.PendingTasks()); |
Darin Petkov | 6a5b322 | 2010-07-13 14:55:28 -0700 | [diff] [blame] | 1504 | } |
| 1505 | |
Alex Deymo | e1e3afe | 2014-10-30 13:02:49 -0700 | [diff] [blame] | 1506 | TEST_F(OmahaRequestActionTest, XmlEncodeTest) { |
Alex Deymo | b0d74eb | 2015-03-30 17:59:17 -0700 | [diff] [blame] | 1507 | string output; |
| 1508 | EXPECT_TRUE(XmlEncode("ab", &output)); |
| 1509 | EXPECT_EQ("ab", output); |
| 1510 | EXPECT_TRUE(XmlEncode("a<b", &output)); |
| 1511 | EXPECT_EQ("a<b", output); |
Alex Deymo | cc45785 | 2015-06-18 18:35:50 -0700 | [diff] [blame] | 1512 | EXPECT_TRUE(XmlEncode("<&>\"\'\\", &output)); |
| 1513 | EXPECT_EQ("<&>"'\\", output); |
Alex Deymo | b0d74eb | 2015-03-30 17:59:17 -0700 | [diff] [blame] | 1514 | EXPECT_TRUE(XmlEncode("<&>", &output)); |
| 1515 | EXPECT_EQ("&lt;&amp;&gt;", output); |
Alex Deymo | cc45785 | 2015-06-18 18:35:50 -0700 | [diff] [blame] | 1516 | // Check that unterminated UTF-8 strings are handled properly. |
Alex Deymo | b0d74eb | 2015-03-30 17:59:17 -0700 | [diff] [blame] | 1517 | EXPECT_FALSE(XmlEncode("\xc2", &output)); |
| 1518 | // Fail with invalid ASCII-7 chars. |
| 1519 | EXPECT_FALSE(XmlEncode("This is an 'n' with a tilde: \xc3\xb1", &output)); |
| 1520 | } |
Darin Petkov | 6a5b322 | 2010-07-13 14:55:28 -0700 | [diff] [blame] | 1521 | |
Alex Deymo | b0d74eb | 2015-03-30 17:59:17 -0700 | [diff] [blame] | 1522 | TEST_F(OmahaRequestActionTest, XmlEncodeWithDefaultTest) { |
| 1523 | EXPECT_EQ("<&>", XmlEncodeWithDefault("<&>", "something else")); |
| 1524 | EXPECT_EQ("<not escaped>", XmlEncodeWithDefault("\xc2", "<not escaped>")); |
| 1525 | } |
| 1526 | |
| 1527 | TEST_F(OmahaRequestActionTest, XmlEncodeIsUsedForParams) { |
Alex Vakulenko | 3f39d5c | 2015-10-13 09:27:13 -0700 | [diff] [blame] | 1528 | brillo::Blob post_data; |
Darin Petkov | 6a5b322 | 2010-07-13 14:55:28 -0700 | [diff] [blame] | 1529 | |
| 1530 | // Make sure XML Encode is being called on the params |
Marton Hunyady | 2abda31 | 2018-04-24 18:21:49 +0200 | [diff] [blame^] | 1531 | request_params_.set_os_sp("testtheservice_pack>"); |
| 1532 | request_params_.set_os_board("x86 generic<id"); |
| 1533 | request_params_.set_current_channel("unittest_track<"); |
| 1534 | request_params_.set_target_channel("unittest_track<"); |
| 1535 | request_params_.set_hwid("<OEM MODEL>"); |
Alex Deymo | 8e18f93 | 2015-03-27 16:16:59 -0700 | [diff] [blame] | 1536 | fake_prefs_.SetString(kPrefsOmahaCohort, "evil\nstring"); |
| 1537 | fake_prefs_.SetString(kPrefsOmahaCohortHint, "evil&string\\"); |
| 1538 | fake_prefs_.SetString(kPrefsOmahaCohortName, |
Alex Vakulenko | 0103c36 | 2016-01-20 07:56:15 -0800 | [diff] [blame] | 1539 | base::JoinString( |
| 1540 | vector<string>(100, "My spoon is too big."), " ")); |
Darin Petkov | 6a5b322 | 2010-07-13 14:55:28 -0700 | [diff] [blame] | 1541 | OmahaResponse response; |
Marton Hunyady | 2abda31 | 2018-04-24 18:21:49 +0200 | [diff] [blame^] | 1542 | ASSERT_FALSE(TestUpdateCheck("invalid xml>", |
| 1543 | -1, |
| 1544 | false, // ping_only |
| 1545 | ErrorCode::kOmahaRequestXMLParseError, |
| 1546 | metrics::CheckResult::kParsingError, |
| 1547 | metrics::CheckReaction::kUnset, |
| 1548 | metrics::DownloadErrorCode::kUnset, |
| 1549 | &response, |
| 1550 | &post_data)); |
Darin Petkov | 6a5b322 | 2010-07-13 14:55:28 -0700 | [diff] [blame] | 1551 | // convert post_data to string |
Alex Vakulenko | f68bbbc | 2015-02-09 12:53:18 -0800 | [diff] [blame] | 1552 | string post_str(post_data.begin(), post_data.end()); |
Alex Deymo | 8e18f93 | 2015-03-27 16:16:59 -0700 | [diff] [blame] | 1553 | EXPECT_NE(string::npos, post_str.find("testtheservice_pack>")); |
| 1554 | EXPECT_EQ(string::npos, post_str.find("testtheservice_pack>")); |
| 1555 | EXPECT_NE(string::npos, post_str.find("x86 generic<id")); |
| 1556 | EXPECT_EQ(string::npos, post_str.find("x86 generic<id")); |
| 1557 | EXPECT_NE(string::npos, post_str.find("unittest_track&lt;")); |
| 1558 | EXPECT_EQ(string::npos, post_str.find("unittest_track<")); |
| 1559 | EXPECT_NE(string::npos, post_str.find("<OEM MODEL>")); |
| 1560 | EXPECT_EQ(string::npos, post_str.find("<OEM MODEL>")); |
| 1561 | EXPECT_NE(string::npos, post_str.find("cohort=\"evil\nstring\"")); |
| 1562 | EXPECT_EQ(string::npos, post_str.find("cohorthint=\"evil&string\\\"")); |
| 1563 | EXPECT_NE(string::npos, post_str.find("cohorthint=\"evil&string\\\"")); |
| 1564 | // Values from Prefs that are too big are removed from the XML instead of |
| 1565 | // encoded. |
| 1566 | EXPECT_EQ(string::npos, post_str.find("cohortname=")); |
Darin Petkov | 6a5b322 | 2010-07-13 14:55:28 -0700 | [diff] [blame] | 1567 | } |
| 1568 | |
Alex Deymo | e1e3afe | 2014-10-30 13:02:49 -0700 | [diff] [blame] | 1569 | TEST_F(OmahaRequestActionTest, XmlDecodeTest) { |
Darin Petkov | 6a5b322 | 2010-07-13 14:55:28 -0700 | [diff] [blame] | 1570 | OmahaResponse response; |
Alex Deymo | 8e18f93 | 2015-03-27 16:16:59 -0700 | [diff] [blame] | 1571 | fake_update_response_.deadline = "<20110101"; |
| 1572 | fake_update_response_.more_info_url = "testthe<url"; |
| 1573 | fake_update_response_.codebase = "testthe&codebase/"; |
Marton Hunyady | 2abda31 | 2018-04-24 18:21:49 +0200 | [diff] [blame^] | 1574 | ASSERT_TRUE(TestUpdateCheck(fake_update_response_.GetUpdateResponse(), |
| 1575 | -1, |
| 1576 | false, // ping_only |
| 1577 | ErrorCode::kSuccess, |
| 1578 | metrics::CheckResult::kUpdateAvailable, |
| 1579 | metrics::CheckReaction::kUpdating, |
| 1580 | metrics::DownloadErrorCode::kUnset, |
| 1581 | &response, |
| 1582 | nullptr)); |
Darin Petkov | 6a5b322 | 2010-07-13 14:55:28 -0700 | [diff] [blame] | 1583 | |
Sen Jiang | 0affc2c | 2017-02-10 15:55:05 -0800 | [diff] [blame] | 1584 | EXPECT_EQ("testthe<url", response.more_info_url); |
| 1585 | EXPECT_EQ("testthe&codebase/file.signed", |
| 1586 | response.packages[0].payload_urls[0]); |
| 1587 | EXPECT_EQ("<20110101", response.deadline); |
Darin Petkov | 6a5b322 | 2010-07-13 14:55:28 -0700 | [diff] [blame] | 1588 | } |
| 1589 | |
Alex Deymo | e1e3afe | 2014-10-30 13:02:49 -0700 | [diff] [blame] | 1590 | TEST_F(OmahaRequestActionTest, ParseIntTest) { |
Darin Petkov | 6a5b322 | 2010-07-13 14:55:28 -0700 | [diff] [blame] | 1591 | OmahaResponse response; |
Alex Deymo | 8e18f93 | 2015-03-27 16:16:59 -0700 | [diff] [blame] | 1592 | // overflows int32_t: |
Sen Jiang | 0affc2c | 2017-02-10 15:55:05 -0800 | [diff] [blame] | 1593 | fake_update_response_.size = 123123123123123ull; |
Marton Hunyady | 2abda31 | 2018-04-24 18:21:49 +0200 | [diff] [blame^] | 1594 | ASSERT_TRUE(TestUpdateCheck(fake_update_response_.GetUpdateResponse(), |
| 1595 | -1, |
| 1596 | false, // ping_only |
| 1597 | ErrorCode::kSuccess, |
| 1598 | metrics::CheckResult::kUpdateAvailable, |
| 1599 | metrics::CheckReaction::kUpdating, |
| 1600 | metrics::DownloadErrorCode::kUnset, |
| 1601 | &response, |
| 1602 | nullptr)); |
Darin Petkov | 6a5b322 | 2010-07-13 14:55:28 -0700 | [diff] [blame] | 1603 | |
Sen Jiang | 0affc2c | 2017-02-10 15:55:05 -0800 | [diff] [blame] | 1604 | EXPECT_EQ(fake_update_response_.size, response.packages[0].size); |
Darin Petkov | 6a5b322 | 2010-07-13 14:55:28 -0700 | [diff] [blame] | 1605 | } |
| 1606 | |
Alex Deymo | e1e3afe | 2014-10-30 13:02:49 -0700 | [diff] [blame] | 1607 | TEST_F(OmahaRequestActionTest, FormatUpdateCheckOutputTest) { |
Alex Vakulenko | 3f39d5c | 2015-10-13 09:27:13 -0700 | [diff] [blame] | 1608 | brillo::Blob post_data; |
Alex Deymo | 8427b4a | 2014-11-05 14:00:32 -0800 | [diff] [blame] | 1609 | NiceMock<MockPrefs> prefs; |
Alex Deymo | e1e3afe | 2014-10-30 13:02:49 -0700 | [diff] [blame] | 1610 | fake_system_state_.set_prefs(&prefs); |
| 1611 | |
Darin Petkov | 95508da | 2011-01-05 12:42:29 -0800 | [diff] [blame] | 1612 | EXPECT_CALL(prefs, GetString(kPrefsPreviousVersion, _)) |
Ben Chan | 672c1f5 | 2017-10-23 15:41:39 -0700 | [diff] [blame] | 1613 | .WillOnce(DoAll(SetArgPointee<1>(string("")), Return(true))); |
Alex Deymo | efb9d83 | 2015-11-02 18:39:02 -0800 | [diff] [blame] | 1614 | // An existing but empty previous version means that we didn't reboot to a new |
| 1615 | // update, therefore, no need to update the previous version. |
| 1616 | EXPECT_CALL(prefs, SetString(kPrefsPreviousVersion, _)).Times(0); |
Marton Hunyady | 2abda31 | 2018-04-24 18:21:49 +0200 | [diff] [blame^] | 1617 | ASSERT_FALSE(TestUpdateCheck("invalid xml>", |
Darin Petkov | edc522e | 2010-11-05 09:35:17 -0700 | [diff] [blame] | 1618 | -1, |
Darin Petkov | 265f290 | 2011-05-09 15:17:40 -0700 | [diff] [blame] | 1619 | false, // ping_only |
Gilad Arnold | d1c4d2d | 2014-06-05 14:07:53 -0700 | [diff] [blame] | 1620 | ErrorCode::kOmahaRequestXMLParseError, |
David Zeuthen | 33bae49 | 2014-02-25 16:16:18 -0800 | [diff] [blame] | 1621 | metrics::CheckResult::kParsingError, |
| 1622 | metrics::CheckReaction::kUnset, |
| 1623 | metrics::DownloadErrorCode::kUnset, |
Alex Vakulenko | 88b591f | 2014-08-28 16:48:57 -0700 | [diff] [blame] | 1624 | nullptr, // response |
Darin Petkov | 0dc8e9a | 2010-07-14 14:51:57 -0700 | [diff] [blame] | 1625 | &post_data)); |
| 1626 | // convert post_data to string |
Alex Vakulenko | f68bbbc | 2015-02-09 12:53:18 -0800 | [diff] [blame] | 1627 | string post_str(post_data.begin(), post_data.end()); |
Thieu Le | 116fda3 | 2011-04-19 11:01:54 -0700 | [diff] [blame] | 1628 | EXPECT_NE(post_str.find( |
Jay Srinivasan | 23b92a5 | 2012-10-27 02:00:21 -0700 | [diff] [blame] | 1629 | " <ping active=\"1\" a=\"-1\" r=\"-1\"></ping>\n" |
Jay Srinivasan | ae4697c | 2013-03-18 17:08:08 -0700 | [diff] [blame] | 1630 | " <updatecheck targetversionprefix=\"\"></updatecheck>\n"), |
Jay Srinivasan | 0a70874 | 2012-03-20 11:26:12 -0700 | [diff] [blame] | 1631 | string::npos); |
Darin Petkov | fbb4009 | 2010-07-29 17:05:50 -0700 | [diff] [blame] | 1632 | EXPECT_NE(post_str.find("hardware_class=\"OEM MODEL 09235 7471\""), |
| 1633 | string::npos); |
Chris Sosa | c197248 | 2013-04-30 22:31:10 -0700 | [diff] [blame] | 1634 | EXPECT_NE(post_str.find("fw_version=\"ChromeOSFirmware.1.0\""), |
| 1635 | string::npos); |
| 1636 | EXPECT_NE(post_str.find("ec_version=\"0X0A1\""), |
| 1637 | string::npos); |
Alex Deymo | efb9d83 | 2015-11-02 18:39:02 -0800 | [diff] [blame] | 1638 | // No <event> tag should be sent if we didn't reboot to an update. |
| 1639 | EXPECT_EQ(post_str.find("<event"), string::npos); |
Darin Petkov | 0dc8e9a | 2010-07-14 14:51:57 -0700 | [diff] [blame] | 1640 | } |
| 1641 | |
Jay Srinivasan | 0a70874 | 2012-03-20 11:26:12 -0700 | [diff] [blame] | 1642 | |
Alex Deymo | e1e3afe | 2014-10-30 13:02:49 -0700 | [diff] [blame] | 1643 | TEST_F(OmahaRequestActionTest, FormatSuccessEventOutputTest) { |
Alex Vakulenko | 3f39d5c | 2015-10-13 09:27:13 -0700 | [diff] [blame] | 1644 | brillo::Blob post_data; |
Marton Hunyady | 2abda31 | 2018-04-24 18:21:49 +0200 | [diff] [blame^] | 1645 | TestEvent(new OmahaEvent(OmahaEvent::kTypeUpdateDownloadStarted), |
Darin Petkov | e17f86b | 2010-07-20 09:12:01 -0700 | [diff] [blame] | 1646 | "invalid xml>", |
| 1647 | &post_data); |
| 1648 | // convert post_data to string |
Alex Vakulenko | f68bbbc | 2015-02-09 12:53:18 -0800 | [diff] [blame] | 1649 | string post_str(post_data.begin(), post_data.end()); |
Alex Vakulenko | 75039d7 | 2014-03-25 12:36:28 -0700 | [diff] [blame] | 1650 | string expected_event = base::StringPrintf( |
Jay Srinivasan | 23b92a5 | 2012-10-27 02:00:21 -0700 | [diff] [blame] | 1651 | " <event eventtype=\"%d\" eventresult=\"%d\"></event>\n", |
Darin Petkov | e17f86b | 2010-07-20 09:12:01 -0700 | [diff] [blame] | 1652 | OmahaEvent::kTypeUpdateDownloadStarted, |
| 1653 | OmahaEvent::kResultSuccess); |
| 1654 | EXPECT_NE(post_str.find(expected_event), string::npos); |
Jay Srinivasan | 23b92a5 | 2012-10-27 02:00:21 -0700 | [diff] [blame] | 1655 | EXPECT_EQ(post_str.find("ping"), string::npos); |
| 1656 | EXPECT_EQ(post_str.find("updatecheck"), string::npos); |
Darin Petkov | e17f86b | 2010-07-20 09:12:01 -0700 | [diff] [blame] | 1657 | } |
| 1658 | |
Alex Deymo | e1e3afe | 2014-10-30 13:02:49 -0700 | [diff] [blame] | 1659 | TEST_F(OmahaRequestActionTest, FormatErrorEventOutputTest) { |
Alex Vakulenko | 3f39d5c | 2015-10-13 09:27:13 -0700 | [diff] [blame] | 1660 | brillo::Blob post_data; |
Marton Hunyady | 2abda31 | 2018-04-24 18:21:49 +0200 | [diff] [blame^] | 1661 | TestEvent(new OmahaEvent(OmahaEvent::kTypeDownloadComplete, |
Darin Petkov | e17f86b | 2010-07-20 09:12:01 -0700 | [diff] [blame] | 1662 | OmahaEvent::kResultError, |
Gilad Arnold | d1c4d2d | 2014-06-05 14:07:53 -0700 | [diff] [blame] | 1663 | ErrorCode::kError), |
Darin Petkov | e17f86b | 2010-07-20 09:12:01 -0700 | [diff] [blame] | 1664 | "invalid xml>", |
| 1665 | &post_data); |
| 1666 | // convert post_data to string |
Alex Vakulenko | f68bbbc | 2015-02-09 12:53:18 -0800 | [diff] [blame] | 1667 | string post_str(post_data.begin(), post_data.end()); |
Alex Vakulenko | 75039d7 | 2014-03-25 12:36:28 -0700 | [diff] [blame] | 1668 | string expected_event = base::StringPrintf( |
Jay Srinivasan | 23b92a5 | 2012-10-27 02:00:21 -0700 | [diff] [blame] | 1669 | " <event eventtype=\"%d\" eventresult=\"%d\" " |
| 1670 | "errorcode=\"%d\"></event>\n", |
Darin Petkov | e17f86b | 2010-07-20 09:12:01 -0700 | [diff] [blame] | 1671 | OmahaEvent::kTypeDownloadComplete, |
| 1672 | OmahaEvent::kResultError, |
Gilad Arnold | d1c4d2d | 2014-06-05 14:07:53 -0700 | [diff] [blame] | 1673 | static_cast<int>(ErrorCode::kError)); |
Darin Petkov | 0dc8e9a | 2010-07-14 14:51:57 -0700 | [diff] [blame] | 1674 | EXPECT_NE(post_str.find(expected_event), string::npos); |
Jay Srinivasan | 23b92a5 | 2012-10-27 02:00:21 -0700 | [diff] [blame] | 1675 | EXPECT_EQ(post_str.find("updatecheck"), string::npos); |
Darin Petkov | 0dc8e9a | 2010-07-14 14:51:57 -0700 | [diff] [blame] | 1676 | } |
| 1677 | |
Alex Deymo | e1e3afe | 2014-10-30 13:02:49 -0700 | [diff] [blame] | 1678 | TEST_F(OmahaRequestActionTest, IsEventTest) { |
Darin Petkov | 0dc8e9a | 2010-07-14 14:51:57 -0700 | [diff] [blame] | 1679 | string http_response("doesn't matter"); |
Darin Petkov | 0dc8e9a | 2010-07-14 14:51:57 -0700 | [diff] [blame] | 1680 | OmahaRequestAction update_check_action( |
Alex Deymo | e1e3afe | 2014-10-30 13:02:49 -0700 | [diff] [blame] | 1681 | &fake_system_state_, |
Alex Vakulenko | 88b591f | 2014-08-28 16:48:57 -0700 | [diff] [blame] | 1682 | nullptr, |
Ben Chan | ab5a0af | 2017-10-12 14:57:50 -0700 | [diff] [blame] | 1683 | std::make_unique<MockHttpFetcher>(http_response.data(), |
Ben Chan | 5c02c13 | 2017-06-27 07:10:36 -0700 | [diff] [blame] | 1684 | http_response.size(), |
| 1685 | nullptr), |
Thieu Le | 116fda3 | 2011-04-19 11:01:54 -0700 | [diff] [blame] | 1686 | false); |
Darin Petkov | 0dc8e9a | 2010-07-14 14:51:57 -0700 | [diff] [blame] | 1687 | EXPECT_FALSE(update_check_action.IsEvent()); |
| 1688 | |
| 1689 | OmahaRequestAction event_action( |
Alex Deymo | e1e3afe | 2014-10-30 13:02:49 -0700 | [diff] [blame] | 1690 | &fake_system_state_, |
Darin Petkov | e17f86b | 2010-07-20 09:12:01 -0700 | [diff] [blame] | 1691 | new OmahaEvent(OmahaEvent::kTypeUpdateComplete), |
Ben Chan | ab5a0af | 2017-10-12 14:57:50 -0700 | [diff] [blame] | 1692 | std::make_unique<MockHttpFetcher>(http_response.data(), |
Ben Chan | 5c02c13 | 2017-06-27 07:10:36 -0700 | [diff] [blame] | 1693 | http_response.size(), |
| 1694 | nullptr), |
Thieu Le | 116fda3 | 2011-04-19 11:01:54 -0700 | [diff] [blame] | 1695 | false); |
Darin Petkov | 0dc8e9a | 2010-07-14 14:51:57 -0700 | [diff] [blame] | 1696 | EXPECT_TRUE(event_action.IsEvent()); |
| 1697 | } |
| 1698 | |
Alex Deymo | e1e3afe | 2014-10-30 13:02:49 -0700 | [diff] [blame] | 1699 | TEST_F(OmahaRequestActionTest, FormatDeltaOkayOutputTest) { |
Andrew de los Reyes | 3f0303a | 2010-07-15 22:35:35 -0700 | [diff] [blame] | 1700 | for (int i = 0; i < 2; i++) { |
| 1701 | bool delta_okay = i == 1; |
| 1702 | const char* delta_okay_str = delta_okay ? "true" : "false"; |
Alex Vakulenko | 3f39d5c | 2015-10-13 09:27:13 -0700 | [diff] [blame] | 1703 | brillo::Blob post_data; |
Marton Hunyady | 2abda31 | 2018-04-24 18:21:49 +0200 | [diff] [blame^] | 1704 | |
| 1705 | request_params_.set_delta_okay(delta_okay); |
| 1706 | |
| 1707 | ASSERT_FALSE(TestUpdateCheck("invalid xml>", |
Darin Petkov | edc522e | 2010-11-05 09:35:17 -0700 | [diff] [blame] | 1708 | -1, |
Darin Petkov | 265f290 | 2011-05-09 15:17:40 -0700 | [diff] [blame] | 1709 | false, // ping_only |
Gilad Arnold | d1c4d2d | 2014-06-05 14:07:53 -0700 | [diff] [blame] | 1710 | ErrorCode::kOmahaRequestXMLParseError, |
David Zeuthen | 33bae49 | 2014-02-25 16:16:18 -0800 | [diff] [blame] | 1711 | metrics::CheckResult::kParsingError, |
| 1712 | metrics::CheckReaction::kUnset, |
| 1713 | metrics::DownloadErrorCode::kUnset, |
Alex Vakulenko | 88b591f | 2014-08-28 16:48:57 -0700 | [diff] [blame] | 1714 | nullptr, |
Andrew de los Reyes | 3f0303a | 2010-07-15 22:35:35 -0700 | [diff] [blame] | 1715 | &post_data)); |
| 1716 | // convert post_data to string |
Alex Vakulenko | f68bbbc | 2015-02-09 12:53:18 -0800 | [diff] [blame] | 1717 | string post_str(post_data.begin(), post_data.end()); |
Alex Vakulenko | 75039d7 | 2014-03-25 12:36:28 -0700 | [diff] [blame] | 1718 | EXPECT_NE(post_str.find(base::StringPrintf(" delta_okay=\"%s\"", |
| 1719 | delta_okay_str)), |
Andrew de los Reyes | 3f0303a | 2010-07-15 22:35:35 -0700 | [diff] [blame] | 1720 | string::npos) |
| 1721 | << "i = " << i; |
| 1722 | } |
| 1723 | } |
| 1724 | |
Alex Deymo | e1e3afe | 2014-10-30 13:02:49 -0700 | [diff] [blame] | 1725 | TEST_F(OmahaRequestActionTest, FormatInteractiveOutputTest) { |
Gilad Arnold | bbdd490 | 2013-01-10 16:06:30 -0800 | [diff] [blame] | 1726 | for (int i = 0; i < 2; i++) { |
| 1727 | bool interactive = i == 1; |
Gilad Arnold | 8a659d8 | 2013-01-24 11:26:00 -0800 | [diff] [blame] | 1728 | const char* interactive_str = interactive ? "ondemandupdate" : "scheduler"; |
Alex Vakulenko | 3f39d5c | 2015-10-13 09:27:13 -0700 | [diff] [blame] | 1729 | brillo::Blob post_data; |
Gilad Arnold | 5bb4c90 | 2014-04-10 12:32:13 -0700 | [diff] [blame] | 1730 | FakeSystemState fake_system_state; |
Marton Hunyady | 2abda31 | 2018-04-24 18:21:49 +0200 | [diff] [blame^] | 1731 | |
| 1732 | request_params_.set_interactive(interactive); |
| 1733 | |
| 1734 | ASSERT_FALSE(TestUpdateCheck("invalid xml>", |
Gilad Arnold | bbdd490 | 2013-01-10 16:06:30 -0800 | [diff] [blame] | 1735 | -1, |
| 1736 | false, // ping_only |
Gilad Arnold | d1c4d2d | 2014-06-05 14:07:53 -0700 | [diff] [blame] | 1737 | ErrorCode::kOmahaRequestXMLParseError, |
David Zeuthen | 33bae49 | 2014-02-25 16:16:18 -0800 | [diff] [blame] | 1738 | metrics::CheckResult::kParsingError, |
| 1739 | metrics::CheckReaction::kUnset, |
| 1740 | metrics::DownloadErrorCode::kUnset, |
Alex Vakulenko | 88b591f | 2014-08-28 16:48:57 -0700 | [diff] [blame] | 1741 | nullptr, |
Gilad Arnold | bbdd490 | 2013-01-10 16:06:30 -0800 | [diff] [blame] | 1742 | &post_data)); |
| 1743 | // convert post_data to string |
Alex Vakulenko | f68bbbc | 2015-02-09 12:53:18 -0800 | [diff] [blame] | 1744 | string post_str(post_data.begin(), post_data.end()); |
Alex Vakulenko | 75039d7 | 2014-03-25 12:36:28 -0700 | [diff] [blame] | 1745 | EXPECT_NE(post_str.find(base::StringPrintf("installsource=\"%s\"", |
| 1746 | interactive_str)), |
Gilad Arnold | bbdd490 | 2013-01-10 16:06:30 -0800 | [diff] [blame] | 1747 | string::npos) |
| 1748 | << "i = " << i; |
| 1749 | } |
| 1750 | } |
| 1751 | |
Alex Deymo | e1e3afe | 2014-10-30 13:02:49 -0700 | [diff] [blame] | 1752 | TEST_F(OmahaRequestActionTest, OmahaEventTest) { |
Darin Petkov | e17f86b | 2010-07-20 09:12:01 -0700 | [diff] [blame] | 1753 | OmahaEvent default_event; |
| 1754 | EXPECT_EQ(OmahaEvent::kTypeUnknown, default_event.type); |
| 1755 | EXPECT_EQ(OmahaEvent::kResultError, default_event.result); |
Gilad Arnold | d1c4d2d | 2014-06-05 14:07:53 -0700 | [diff] [blame] | 1756 | EXPECT_EQ(ErrorCode::kError, default_event.error_code); |
Darin Petkov | e17f86b | 2010-07-20 09:12:01 -0700 | [diff] [blame] | 1757 | |
| 1758 | OmahaEvent success_event(OmahaEvent::kTypeUpdateDownloadStarted); |
| 1759 | EXPECT_EQ(OmahaEvent::kTypeUpdateDownloadStarted, success_event.type); |
| 1760 | EXPECT_EQ(OmahaEvent::kResultSuccess, success_event.result); |
Gilad Arnold | d1c4d2d | 2014-06-05 14:07:53 -0700 | [diff] [blame] | 1761 | EXPECT_EQ(ErrorCode::kSuccess, success_event.error_code); |
Darin Petkov | e17f86b | 2010-07-20 09:12:01 -0700 | [diff] [blame] | 1762 | |
| 1763 | OmahaEvent error_event(OmahaEvent::kTypeUpdateDownloadFinished, |
| 1764 | OmahaEvent::kResultError, |
Gilad Arnold | d1c4d2d | 2014-06-05 14:07:53 -0700 | [diff] [blame] | 1765 | ErrorCode::kError); |
Darin Petkov | e17f86b | 2010-07-20 09:12:01 -0700 | [diff] [blame] | 1766 | EXPECT_EQ(OmahaEvent::kTypeUpdateDownloadFinished, error_event.type); |
| 1767 | EXPECT_EQ(OmahaEvent::kResultError, error_event.result); |
Gilad Arnold | d1c4d2d | 2014-06-05 14:07:53 -0700 | [diff] [blame] | 1768 | EXPECT_EQ(ErrorCode::kError, error_event.error_code); |
Darin Petkov | e17f86b | 2010-07-20 09:12:01 -0700 | [diff] [blame] | 1769 | } |
| 1770 | |
Alex Deymo | e1e3afe | 2014-10-30 13:02:49 -0700 | [diff] [blame] | 1771 | void OmahaRequestActionTest::PingTest(bool ping_only) { |
Alex Deymo | 8427b4a | 2014-11-05 14:00:32 -0800 | [diff] [blame] | 1772 | NiceMock<MockPrefs> prefs; |
Alex Deymo | e1e3afe | 2014-10-30 13:02:49 -0700 | [diff] [blame] | 1773 | fake_system_state_.set_prefs(&prefs); |
| 1774 | EXPECT_CALL(prefs, GetInt64(kPrefsMetricsCheckLastReportingTime, _)) |
| 1775 | .Times(AnyNumber()); |
| 1776 | EXPECT_CALL(prefs, SetInt64(_, _)).Times(AnyNumber()); |
| 1777 | // Add a few hours to the day difference to test no rounding, etc. |
| 1778 | int64_t five_days_ago = |
| 1779 | (Time::Now() - TimeDelta::FromHours(5 * 24 + 13)).ToInternalValue(); |
| 1780 | int64_t six_days_ago = |
| 1781 | (Time::Now() - TimeDelta::FromHours(6 * 24 + 11)).ToInternalValue(); |
| 1782 | EXPECT_CALL(prefs, GetInt64(kPrefsInstallDateDays, _)) |
Ben Chan | 672c1f5 | 2017-10-23 15:41:39 -0700 | [diff] [blame] | 1783 | .WillOnce(DoAll(SetArgPointee<1>(0), Return(true))); |
Alex Deymo | e1e3afe | 2014-10-30 13:02:49 -0700 | [diff] [blame] | 1784 | EXPECT_CALL(prefs, GetInt64(kPrefsLastActivePingDay, _)) |
Ben Chan | 672c1f5 | 2017-10-23 15:41:39 -0700 | [diff] [blame] | 1785 | .WillOnce(DoAll(SetArgPointee<1>(six_days_ago), Return(true))); |
Alex Deymo | e1e3afe | 2014-10-30 13:02:49 -0700 | [diff] [blame] | 1786 | EXPECT_CALL(prefs, GetInt64(kPrefsLastRollCallPingDay, _)) |
Ben Chan | 672c1f5 | 2017-10-23 15:41:39 -0700 | [diff] [blame] | 1787 | .WillOnce(DoAll(SetArgPointee<1>(five_days_ago), Return(true))); |
Alex Vakulenko | 3f39d5c | 2015-10-13 09:27:13 -0700 | [diff] [blame] | 1788 | brillo::Blob post_data; |
Marton Hunyady | 2abda31 | 2018-04-24 18:21:49 +0200 | [diff] [blame^] | 1789 | ASSERT_TRUE(TestUpdateCheck(fake_update_response_.GetNoUpdateResponse(), |
Tianjie Xu | 282aa1f | 2017-09-05 13:42:45 -0700 | [diff] [blame] | 1790 | -1, |
| 1791 | ping_only, |
| 1792 | ErrorCode::kSuccess, |
| 1793 | metrics::CheckResult::kNoUpdateAvailable, |
| 1794 | metrics::CheckReaction::kUnset, |
| 1795 | metrics::DownloadErrorCode::kUnset, |
| 1796 | nullptr, |
| 1797 | &post_data)); |
Alex Vakulenko | f68bbbc | 2015-02-09 12:53:18 -0800 | [diff] [blame] | 1798 | string post_str(post_data.begin(), post_data.end()); |
Alex Deymo | e1e3afe | 2014-10-30 13:02:49 -0700 | [diff] [blame] | 1799 | EXPECT_NE(post_str.find("<ping active=\"1\" a=\"6\" r=\"5\"></ping>"), |
| 1800 | string::npos); |
| 1801 | if (ping_only) { |
| 1802 | EXPECT_EQ(post_str.find("updatecheck"), string::npos); |
| 1803 | EXPECT_EQ(post_str.find("previousversion"), string::npos); |
| 1804 | } else { |
| 1805 | EXPECT_NE(post_str.find("updatecheck"), string::npos); |
| 1806 | EXPECT_NE(post_str.find("previousversion"), string::npos); |
Darin Petkov | 265f290 | 2011-05-09 15:17:40 -0700 | [diff] [blame] | 1807 | } |
Darin Petkov | 1cbd78f | 2010-07-29 12:38:34 -0700 | [diff] [blame] | 1808 | } |
| 1809 | |
Alex Deymo | e1e3afe | 2014-10-30 13:02:49 -0700 | [diff] [blame] | 1810 | TEST_F(OmahaRequestActionTest, PingTestSendOnlyAPing) { |
| 1811 | PingTest(true /* ping_only */); |
| 1812 | } |
| 1813 | |
| 1814 | TEST_F(OmahaRequestActionTest, PingTestSendAlsoAnUpdateCheck) { |
| 1815 | PingTest(false /* ping_only */); |
| 1816 | } |
| 1817 | |
| 1818 | TEST_F(OmahaRequestActionTest, ActivePingTest) { |
Alex Deymo | 8427b4a | 2014-11-05 14:00:32 -0800 | [diff] [blame] | 1819 | NiceMock<MockPrefs> prefs; |
Alex Deymo | e1e3afe | 2014-10-30 13:02:49 -0700 | [diff] [blame] | 1820 | fake_system_state_.set_prefs(&prefs); |
David Zeuthen | 33bae49 | 2014-02-25 16:16:18 -0800 | [diff] [blame] | 1821 | EXPECT_CALL(prefs, GetInt64(kPrefsMetricsCheckLastReportingTime, _)) |
| 1822 | .Times(AnyNumber()); |
| 1823 | EXPECT_CALL(prefs, SetInt64(_, _)).Times(AnyNumber()); |
Darin Petkov | 1cbd78f | 2010-07-29 12:38:34 -0700 | [diff] [blame] | 1824 | int64_t three_days_ago = |
| 1825 | (Time::Now() - TimeDelta::FromHours(3 * 24 + 12)).ToInternalValue(); |
| 1826 | int64_t now = Time::Now().ToInternalValue(); |
David Zeuthen | 639aa36 | 2014-02-03 16:23:44 -0800 | [diff] [blame] | 1827 | EXPECT_CALL(prefs, GetInt64(kPrefsInstallDateDays, _)) |
Ben Chan | 672c1f5 | 2017-10-23 15:41:39 -0700 | [diff] [blame] | 1828 | .WillOnce(DoAll(SetArgPointee<1>(0), Return(true))); |
Darin Petkov | 1cbd78f | 2010-07-29 12:38:34 -0700 | [diff] [blame] | 1829 | EXPECT_CALL(prefs, GetInt64(kPrefsLastActivePingDay, _)) |
Ben Chan | 672c1f5 | 2017-10-23 15:41:39 -0700 | [diff] [blame] | 1830 | .WillOnce(DoAll(SetArgPointee<1>(three_days_ago), Return(true))); |
Darin Petkov | 1cbd78f | 2010-07-29 12:38:34 -0700 | [diff] [blame] | 1831 | EXPECT_CALL(prefs, GetInt64(kPrefsLastRollCallPingDay, _)) |
Ben Chan | 672c1f5 | 2017-10-23 15:41:39 -0700 | [diff] [blame] | 1832 | .WillOnce(DoAll(SetArgPointee<1>(now), Return(true))); |
Alex Vakulenko | 3f39d5c | 2015-10-13 09:27:13 -0700 | [diff] [blame] | 1833 | brillo::Blob post_data; |
Marton Hunyady | 2abda31 | 2018-04-24 18:21:49 +0200 | [diff] [blame^] | 1834 | ASSERT_TRUE(TestUpdateCheck(fake_update_response_.GetNoUpdateResponse(), |
| 1835 | -1, |
| 1836 | false, // ping_only |
| 1837 | ErrorCode::kSuccess, |
| 1838 | metrics::CheckResult::kNoUpdateAvailable, |
| 1839 | metrics::CheckReaction::kUnset, |
| 1840 | metrics::DownloadErrorCode::kUnset, |
| 1841 | nullptr, |
| 1842 | &post_data)); |
Alex Vakulenko | f68bbbc | 2015-02-09 12:53:18 -0800 | [diff] [blame] | 1843 | string post_str(post_data.begin(), post_data.end()); |
Jay Srinivasan | 23b92a5 | 2012-10-27 02:00:21 -0700 | [diff] [blame] | 1844 | EXPECT_NE(post_str.find("<ping active=\"1\" a=\"3\"></ping>"), |
Thieu Le | 116fda3 | 2011-04-19 11:01:54 -0700 | [diff] [blame] | 1845 | string::npos); |
Darin Petkov | 1cbd78f | 2010-07-29 12:38:34 -0700 | [diff] [blame] | 1846 | } |
| 1847 | |
Alex Deymo | e1e3afe | 2014-10-30 13:02:49 -0700 | [diff] [blame] | 1848 | TEST_F(OmahaRequestActionTest, RollCallPingTest) { |
Alex Deymo | 8427b4a | 2014-11-05 14:00:32 -0800 | [diff] [blame] | 1849 | NiceMock<MockPrefs> prefs; |
Alex Deymo | e1e3afe | 2014-10-30 13:02:49 -0700 | [diff] [blame] | 1850 | fake_system_state_.set_prefs(&prefs); |
David Zeuthen | 33bae49 | 2014-02-25 16:16:18 -0800 | [diff] [blame] | 1851 | EXPECT_CALL(prefs, GetInt64(kPrefsMetricsCheckLastReportingTime, _)) |
| 1852 | .Times(AnyNumber()); |
| 1853 | EXPECT_CALL(prefs, SetInt64(_, _)).Times(AnyNumber()); |
Darin Petkov | 1cbd78f | 2010-07-29 12:38:34 -0700 | [diff] [blame] | 1854 | int64_t four_days_ago = |
| 1855 | (Time::Now() - TimeDelta::FromHours(4 * 24)).ToInternalValue(); |
| 1856 | int64_t now = Time::Now().ToInternalValue(); |
David Zeuthen | 639aa36 | 2014-02-03 16:23:44 -0800 | [diff] [blame] | 1857 | EXPECT_CALL(prefs, GetInt64(kPrefsInstallDateDays, _)) |
Ben Chan | 672c1f5 | 2017-10-23 15:41:39 -0700 | [diff] [blame] | 1858 | .WillOnce(DoAll(SetArgPointee<1>(0), Return(true))); |
Darin Petkov | 1cbd78f | 2010-07-29 12:38:34 -0700 | [diff] [blame] | 1859 | EXPECT_CALL(prefs, GetInt64(kPrefsLastActivePingDay, _)) |
Ben Chan | 672c1f5 | 2017-10-23 15:41:39 -0700 | [diff] [blame] | 1860 | .WillOnce(DoAll(SetArgPointee<1>(now), Return(true))); |
Darin Petkov | 1cbd78f | 2010-07-29 12:38:34 -0700 | [diff] [blame] | 1861 | EXPECT_CALL(prefs, GetInt64(kPrefsLastRollCallPingDay, _)) |
Ben Chan | 672c1f5 | 2017-10-23 15:41:39 -0700 | [diff] [blame] | 1862 | .WillOnce(DoAll(SetArgPointee<1>(four_days_ago), Return(true))); |
Alex Vakulenko | 3f39d5c | 2015-10-13 09:27:13 -0700 | [diff] [blame] | 1863 | brillo::Blob post_data; |
Marton Hunyady | 2abda31 | 2018-04-24 18:21:49 +0200 | [diff] [blame^] | 1864 | ASSERT_TRUE(TestUpdateCheck(fake_update_response_.GetNoUpdateResponse(), |
| 1865 | -1, |
| 1866 | false, // ping_only |
| 1867 | ErrorCode::kSuccess, |
| 1868 | metrics::CheckResult::kNoUpdateAvailable, |
| 1869 | metrics::CheckReaction::kUnset, |
| 1870 | metrics::DownloadErrorCode::kUnset, |
| 1871 | nullptr, |
| 1872 | &post_data)); |
Alex Vakulenko | f68bbbc | 2015-02-09 12:53:18 -0800 | [diff] [blame] | 1873 | string post_str(post_data.begin(), post_data.end()); |
Jay Srinivasan | 23b92a5 | 2012-10-27 02:00:21 -0700 | [diff] [blame] | 1874 | EXPECT_NE(post_str.find("<ping active=\"1\" r=\"4\"></ping>\n"), |
Thieu Le | 116fda3 | 2011-04-19 11:01:54 -0700 | [diff] [blame] | 1875 | string::npos); |
Darin Petkov | 1cbd78f | 2010-07-29 12:38:34 -0700 | [diff] [blame] | 1876 | } |
| 1877 | |
Alex Deymo | e1e3afe | 2014-10-30 13:02:49 -0700 | [diff] [blame] | 1878 | TEST_F(OmahaRequestActionTest, NoPingTest) { |
Alex Deymo | 8427b4a | 2014-11-05 14:00:32 -0800 | [diff] [blame] | 1879 | NiceMock<MockPrefs> prefs; |
Alex Deymo | e1e3afe | 2014-10-30 13:02:49 -0700 | [diff] [blame] | 1880 | fake_system_state_.set_prefs(&prefs); |
David Zeuthen | 33bae49 | 2014-02-25 16:16:18 -0800 | [diff] [blame] | 1881 | EXPECT_CALL(prefs, GetInt64(kPrefsMetricsCheckLastReportingTime, _)) |
| 1882 | .Times(AnyNumber()); |
| 1883 | EXPECT_CALL(prefs, SetInt64(_, _)).Times(AnyNumber()); |
Darin Petkov | 1cbd78f | 2010-07-29 12:38:34 -0700 | [diff] [blame] | 1884 | int64_t one_hour_ago = |
| 1885 | (Time::Now() - TimeDelta::FromHours(1)).ToInternalValue(); |
David Zeuthen | 639aa36 | 2014-02-03 16:23:44 -0800 | [diff] [blame] | 1886 | EXPECT_CALL(prefs, GetInt64(kPrefsInstallDateDays, _)) |
Ben Chan | 672c1f5 | 2017-10-23 15:41:39 -0700 | [diff] [blame] | 1887 | .WillOnce(DoAll(SetArgPointee<1>(0), Return(true))); |
Darin Petkov | 1cbd78f | 2010-07-29 12:38:34 -0700 | [diff] [blame] | 1888 | EXPECT_CALL(prefs, GetInt64(kPrefsLastActivePingDay, _)) |
Ben Chan | 672c1f5 | 2017-10-23 15:41:39 -0700 | [diff] [blame] | 1889 | .WillOnce(DoAll(SetArgPointee<1>(one_hour_ago), Return(true))); |
Darin Petkov | 1cbd78f | 2010-07-29 12:38:34 -0700 | [diff] [blame] | 1890 | EXPECT_CALL(prefs, GetInt64(kPrefsLastRollCallPingDay, _)) |
Ben Chan | 672c1f5 | 2017-10-23 15:41:39 -0700 | [diff] [blame] | 1891 | .WillOnce(DoAll(SetArgPointee<1>(one_hour_ago), Return(true))); |
Alex Deymo | ebbe7ef | 2014-10-30 13:02:49 -0700 | [diff] [blame] | 1892 | // LastActivePingDay and PrefsLastRollCallPingDay are set even if we didn't |
| 1893 | // send a ping. |
| 1894 | EXPECT_CALL(prefs, SetInt64(kPrefsLastActivePingDay, _)) |
| 1895 | .WillOnce(Return(true)); |
| 1896 | EXPECT_CALL(prefs, SetInt64(kPrefsLastRollCallPingDay, _)) |
| 1897 | .WillOnce(Return(true)); |
Alex Vakulenko | 3f39d5c | 2015-10-13 09:27:13 -0700 | [diff] [blame] | 1898 | brillo::Blob post_data; |
Marton Hunyady | 2abda31 | 2018-04-24 18:21:49 +0200 | [diff] [blame^] | 1899 | ASSERT_TRUE(TestUpdateCheck(fake_update_response_.GetNoUpdateResponse(), |
| 1900 | -1, |
| 1901 | false, // ping_only |
| 1902 | ErrorCode::kSuccess, |
| 1903 | metrics::CheckResult::kNoUpdateAvailable, |
| 1904 | metrics::CheckReaction::kUnset, |
| 1905 | metrics::DownloadErrorCode::kUnset, |
| 1906 | nullptr, |
| 1907 | &post_data)); |
Alex Vakulenko | f68bbbc | 2015-02-09 12:53:18 -0800 | [diff] [blame] | 1908 | string post_str(post_data.begin(), post_data.end()); |
Jay Srinivasan | 23b92a5 | 2012-10-27 02:00:21 -0700 | [diff] [blame] | 1909 | EXPECT_EQ(post_str.find("ping"), string::npos); |
Darin Petkov | 1cbd78f | 2010-07-29 12:38:34 -0700 | [diff] [blame] | 1910 | } |
| 1911 | |
Alex Deymo | e1e3afe | 2014-10-30 13:02:49 -0700 | [diff] [blame] | 1912 | TEST_F(OmahaRequestActionTest, IgnoreEmptyPingTest) { |
Thieu Le | b44e9e8 | 2011-06-06 14:34:04 -0700 | [diff] [blame] | 1913 | // This test ensures that we ignore empty ping only requests. |
Alex Deymo | 8427b4a | 2014-11-05 14:00:32 -0800 | [diff] [blame] | 1914 | NiceMock<MockPrefs> prefs; |
Alex Deymo | e1e3afe | 2014-10-30 13:02:49 -0700 | [diff] [blame] | 1915 | fake_system_state_.set_prefs(&prefs); |
Thieu Le | b44e9e8 | 2011-06-06 14:34:04 -0700 | [diff] [blame] | 1916 | int64_t now = Time::Now().ToInternalValue(); |
| 1917 | EXPECT_CALL(prefs, GetInt64(kPrefsLastActivePingDay, _)) |
Ben Chan | 672c1f5 | 2017-10-23 15:41:39 -0700 | [diff] [blame] | 1918 | .WillOnce(DoAll(SetArgPointee<1>(now), Return(true))); |
Thieu Le | b44e9e8 | 2011-06-06 14:34:04 -0700 | [diff] [blame] | 1919 | EXPECT_CALL(prefs, GetInt64(kPrefsLastRollCallPingDay, _)) |
Ben Chan | 672c1f5 | 2017-10-23 15:41:39 -0700 | [diff] [blame] | 1920 | .WillOnce(DoAll(SetArgPointee<1>(now), Return(true))); |
Thieu Le | b44e9e8 | 2011-06-06 14:34:04 -0700 | [diff] [blame] | 1921 | EXPECT_CALL(prefs, SetInt64(kPrefsLastActivePingDay, _)).Times(0); |
| 1922 | EXPECT_CALL(prefs, SetInt64(kPrefsLastRollCallPingDay, _)).Times(0); |
Alex Vakulenko | 3f39d5c | 2015-10-13 09:27:13 -0700 | [diff] [blame] | 1923 | brillo::Blob post_data; |
Marton Hunyady | 2abda31 | 2018-04-24 18:21:49 +0200 | [diff] [blame^] | 1924 | EXPECT_TRUE(TestUpdateCheck(fake_update_response_.GetNoUpdateResponse(), |
| 1925 | -1, |
| 1926 | true, // ping_only |
| 1927 | ErrorCode::kSuccess, |
| 1928 | metrics::CheckResult::kUnset, |
| 1929 | metrics::CheckReaction::kUnset, |
| 1930 | metrics::DownloadErrorCode::kUnset, |
| 1931 | nullptr, |
| 1932 | &post_data)); |
Alex Deymo | 80f70ff | 2016-02-10 16:08:11 -0800 | [diff] [blame] | 1933 | EXPECT_EQ(0U, post_data.size()); |
Thieu Le | b44e9e8 | 2011-06-06 14:34:04 -0700 | [diff] [blame] | 1934 | } |
| 1935 | |
Alex Deymo | e1e3afe | 2014-10-30 13:02:49 -0700 | [diff] [blame] | 1936 | TEST_F(OmahaRequestActionTest, BackInTimePingTest) { |
Alex Deymo | 8427b4a | 2014-11-05 14:00:32 -0800 | [diff] [blame] | 1937 | NiceMock<MockPrefs> prefs; |
Alex Deymo | e1e3afe | 2014-10-30 13:02:49 -0700 | [diff] [blame] | 1938 | fake_system_state_.set_prefs(&prefs); |
David Zeuthen | 33bae49 | 2014-02-25 16:16:18 -0800 | [diff] [blame] | 1939 | EXPECT_CALL(prefs, GetInt64(kPrefsMetricsCheckLastReportingTime, _)) |
| 1940 | .Times(AnyNumber()); |
| 1941 | EXPECT_CALL(prefs, SetInt64(_, _)).Times(AnyNumber()); |
Darin Petkov | 1cbd78f | 2010-07-29 12:38:34 -0700 | [diff] [blame] | 1942 | int64_t future = |
| 1943 | (Time::Now() + TimeDelta::FromHours(3 * 24 + 4)).ToInternalValue(); |
David Zeuthen | 639aa36 | 2014-02-03 16:23:44 -0800 | [diff] [blame] | 1944 | EXPECT_CALL(prefs, GetInt64(kPrefsInstallDateDays, _)) |
Ben Chan | 672c1f5 | 2017-10-23 15:41:39 -0700 | [diff] [blame] | 1945 | .WillOnce(DoAll(SetArgPointee<1>(0), Return(true))); |
Darin Petkov | 1cbd78f | 2010-07-29 12:38:34 -0700 | [diff] [blame] | 1946 | EXPECT_CALL(prefs, GetInt64(kPrefsLastActivePingDay, _)) |
Ben Chan | 672c1f5 | 2017-10-23 15:41:39 -0700 | [diff] [blame] | 1947 | .WillOnce(DoAll(SetArgPointee<1>(future), Return(true))); |
Darin Petkov | 1cbd78f | 2010-07-29 12:38:34 -0700 | [diff] [blame] | 1948 | EXPECT_CALL(prefs, GetInt64(kPrefsLastRollCallPingDay, _)) |
Ben Chan | 672c1f5 | 2017-10-23 15:41:39 -0700 | [diff] [blame] | 1949 | .WillOnce(DoAll(SetArgPointee<1>(future), Return(true))); |
Darin Petkov | 1cbd78f | 2010-07-29 12:38:34 -0700 | [diff] [blame] | 1950 | EXPECT_CALL(prefs, SetInt64(kPrefsLastActivePingDay, _)) |
| 1951 | .WillOnce(Return(true)); |
| 1952 | EXPECT_CALL(prefs, SetInt64(kPrefsLastRollCallPingDay, _)) |
| 1953 | .WillOnce(Return(true)); |
Alex Vakulenko | 3f39d5c | 2015-10-13 09:27:13 -0700 | [diff] [blame] | 1954 | brillo::Blob post_data; |
Darin Petkov | 1cbd78f | 2010-07-29 12:38:34 -0700 | [diff] [blame] | 1955 | ASSERT_TRUE( |
Marton Hunyady | 2abda31 | 2018-04-24 18:21:49 +0200 | [diff] [blame^] | 1956 | TestUpdateCheck("<?xml version=\"1.0\" encoding=\"UTF-8\"?><response " |
Jay Srinivasan | 23b92a5 | 2012-10-27 02:00:21 -0700 | [diff] [blame] | 1957 | "protocol=\"3.0\"><daystart elapsed_seconds=\"100\"/>" |
Darin Petkov | 1cbd78f | 2010-07-29 12:38:34 -0700 | [diff] [blame] | 1958 | "<app appid=\"foo\" status=\"ok\"><ping status=\"ok\"/>" |
Jay Srinivasan | 23b92a5 | 2012-10-27 02:00:21 -0700 | [diff] [blame] | 1959 | "<updatecheck status=\"noupdate\"/></app></response>", |
Darin Petkov | edc522e | 2010-11-05 09:35:17 -0700 | [diff] [blame] | 1960 | -1, |
Darin Petkov | 265f290 | 2011-05-09 15:17:40 -0700 | [diff] [blame] | 1961 | false, // ping_only |
Gilad Arnold | d1c4d2d | 2014-06-05 14:07:53 -0700 | [diff] [blame] | 1962 | ErrorCode::kSuccess, |
David Zeuthen | 33bae49 | 2014-02-25 16:16:18 -0800 | [diff] [blame] | 1963 | metrics::CheckResult::kNoUpdateAvailable, |
| 1964 | metrics::CheckReaction::kUnset, |
| 1965 | metrics::DownloadErrorCode::kUnset, |
Alex Vakulenko | 88b591f | 2014-08-28 16:48:57 -0700 | [diff] [blame] | 1966 | nullptr, |
Darin Petkov | 1cbd78f | 2010-07-29 12:38:34 -0700 | [diff] [blame] | 1967 | &post_data)); |
Alex Vakulenko | f68bbbc | 2015-02-09 12:53:18 -0800 | [diff] [blame] | 1968 | string post_str(post_data.begin(), post_data.end()); |
Jay Srinivasan | 23b92a5 | 2012-10-27 02:00:21 -0700 | [diff] [blame] | 1969 | EXPECT_EQ(post_str.find("ping"), string::npos); |
Darin Petkov | 1cbd78f | 2010-07-29 12:38:34 -0700 | [diff] [blame] | 1970 | } |
| 1971 | |
Alex Deymo | e1e3afe | 2014-10-30 13:02:49 -0700 | [diff] [blame] | 1972 | TEST_F(OmahaRequestActionTest, LastPingDayUpdateTest) { |
Darin Petkov | 1cbd78f | 2010-07-29 12:38:34 -0700 | [diff] [blame] | 1973 | // This test checks that the action updates the last ping day to now |
Darin Petkov | 84c763c | 2010-07-29 16:27:58 -0700 | [diff] [blame] | 1974 | // minus 200 seconds with a slack of 5 seconds. Therefore, the test |
Darin Petkov | 1cbd78f | 2010-07-29 12:38:34 -0700 | [diff] [blame] | 1975 | // may fail if it runs for longer than 5 seconds. It shouldn't run |
| 1976 | // that long though. |
| 1977 | int64_t midnight = |
| 1978 | (Time::Now() - TimeDelta::FromSeconds(200)).ToInternalValue(); |
| 1979 | int64_t midnight_slack = |
| 1980 | (Time::Now() - TimeDelta::FromSeconds(195)).ToInternalValue(); |
Alex Deymo | 8427b4a | 2014-11-05 14:00:32 -0800 | [diff] [blame] | 1981 | NiceMock<MockPrefs> prefs; |
Alex Deymo | e1e3afe | 2014-10-30 13:02:49 -0700 | [diff] [blame] | 1982 | fake_system_state_.set_prefs(&prefs); |
David Zeuthen | 33bae49 | 2014-02-25 16:16:18 -0800 | [diff] [blame] | 1983 | EXPECT_CALL(prefs, GetInt64(_, _)).Times(AnyNumber()); |
| 1984 | EXPECT_CALL(prefs, SetInt64(_, _)).Times(AnyNumber()); |
Darin Petkov | 1cbd78f | 2010-07-29 12:38:34 -0700 | [diff] [blame] | 1985 | EXPECT_CALL(prefs, SetInt64(kPrefsLastActivePingDay, |
| 1986 | AllOf(Ge(midnight), Le(midnight_slack)))) |
| 1987 | .WillOnce(Return(true)); |
| 1988 | EXPECT_CALL(prefs, SetInt64(kPrefsLastRollCallPingDay, |
| 1989 | AllOf(Ge(midnight), Le(midnight_slack)))) |
| 1990 | .WillOnce(Return(true)); |
| 1991 | ASSERT_TRUE( |
Marton Hunyady | 2abda31 | 2018-04-24 18:21:49 +0200 | [diff] [blame^] | 1992 | TestUpdateCheck("<?xml version=\"1.0\" encoding=\"UTF-8\"?><response " |
Jay Srinivasan | 23b92a5 | 2012-10-27 02:00:21 -0700 | [diff] [blame] | 1993 | "protocol=\"3.0\"><daystart elapsed_seconds=\"200\"/>" |
Darin Petkov | 1cbd78f | 2010-07-29 12:38:34 -0700 | [diff] [blame] | 1994 | "<app appid=\"foo\" status=\"ok\"><ping status=\"ok\"/>" |
Jay Srinivasan | 23b92a5 | 2012-10-27 02:00:21 -0700 | [diff] [blame] | 1995 | "<updatecheck status=\"noupdate\"/></app></response>", |
Darin Petkov | edc522e | 2010-11-05 09:35:17 -0700 | [diff] [blame] | 1996 | -1, |
Darin Petkov | 265f290 | 2011-05-09 15:17:40 -0700 | [diff] [blame] | 1997 | false, // ping_only |
Gilad Arnold | d1c4d2d | 2014-06-05 14:07:53 -0700 | [diff] [blame] | 1998 | ErrorCode::kSuccess, |
David Zeuthen | 33bae49 | 2014-02-25 16:16:18 -0800 | [diff] [blame] | 1999 | metrics::CheckResult::kNoUpdateAvailable, |
| 2000 | metrics::CheckReaction::kUnset, |
| 2001 | metrics::DownloadErrorCode::kUnset, |
Alex Vakulenko | 88b591f | 2014-08-28 16:48:57 -0700 | [diff] [blame] | 2002 | nullptr, |
| 2003 | nullptr)); |
Darin Petkov | 1cbd78f | 2010-07-29 12:38:34 -0700 | [diff] [blame] | 2004 | } |
| 2005 | |
Alex Deymo | e1e3afe | 2014-10-30 13:02:49 -0700 | [diff] [blame] | 2006 | TEST_F(OmahaRequestActionTest, NoElapsedSecondsTest) { |
Alex Deymo | 8427b4a | 2014-11-05 14:00:32 -0800 | [diff] [blame] | 2007 | NiceMock<MockPrefs> prefs; |
Alex Deymo | e1e3afe | 2014-10-30 13:02:49 -0700 | [diff] [blame] | 2008 | fake_system_state_.set_prefs(&prefs); |
David Zeuthen | 33bae49 | 2014-02-25 16:16:18 -0800 | [diff] [blame] | 2009 | EXPECT_CALL(prefs, GetInt64(_, _)).Times(AnyNumber()); |
| 2010 | EXPECT_CALL(prefs, SetInt64(_, _)).Times(AnyNumber()); |
Darin Petkov | 1cbd78f | 2010-07-29 12:38:34 -0700 | [diff] [blame] | 2011 | EXPECT_CALL(prefs, SetInt64(kPrefsLastActivePingDay, _)).Times(0); |
| 2012 | EXPECT_CALL(prefs, SetInt64(kPrefsLastRollCallPingDay, _)).Times(0); |
| 2013 | ASSERT_TRUE( |
Marton Hunyady | 2abda31 | 2018-04-24 18:21:49 +0200 | [diff] [blame^] | 2014 | TestUpdateCheck("<?xml version=\"1.0\" encoding=\"UTF-8\"?><response " |
Jay Srinivasan | 23b92a5 | 2012-10-27 02:00:21 -0700 | [diff] [blame] | 2015 | "protocol=\"3.0\"><daystart blah=\"200\"/>" |
Darin Petkov | 1cbd78f | 2010-07-29 12:38:34 -0700 | [diff] [blame] | 2016 | "<app appid=\"foo\" status=\"ok\"><ping status=\"ok\"/>" |
Jay Srinivasan | 23b92a5 | 2012-10-27 02:00:21 -0700 | [diff] [blame] | 2017 | "<updatecheck status=\"noupdate\"/></app></response>", |
Darin Petkov | edc522e | 2010-11-05 09:35:17 -0700 | [diff] [blame] | 2018 | -1, |
Darin Petkov | 265f290 | 2011-05-09 15:17:40 -0700 | [diff] [blame] | 2019 | false, // ping_only |
Gilad Arnold | d1c4d2d | 2014-06-05 14:07:53 -0700 | [diff] [blame] | 2020 | ErrorCode::kSuccess, |
David Zeuthen | 33bae49 | 2014-02-25 16:16:18 -0800 | [diff] [blame] | 2021 | metrics::CheckResult::kNoUpdateAvailable, |
| 2022 | metrics::CheckReaction::kUnset, |
| 2023 | metrics::DownloadErrorCode::kUnset, |
Alex Vakulenko | 88b591f | 2014-08-28 16:48:57 -0700 | [diff] [blame] | 2024 | nullptr, |
| 2025 | nullptr)); |
Darin Petkov | 1cbd78f | 2010-07-29 12:38:34 -0700 | [diff] [blame] | 2026 | } |
| 2027 | |
Alex Deymo | e1e3afe | 2014-10-30 13:02:49 -0700 | [diff] [blame] | 2028 | TEST_F(OmahaRequestActionTest, BadElapsedSecondsTest) { |
Alex Deymo | 8427b4a | 2014-11-05 14:00:32 -0800 | [diff] [blame] | 2029 | NiceMock<MockPrefs> prefs; |
Alex Deymo | e1e3afe | 2014-10-30 13:02:49 -0700 | [diff] [blame] | 2030 | fake_system_state_.set_prefs(&prefs); |
David Zeuthen | 33bae49 | 2014-02-25 16:16:18 -0800 | [diff] [blame] | 2031 | EXPECT_CALL(prefs, GetInt64(_, _)).Times(AnyNumber()); |
| 2032 | EXPECT_CALL(prefs, SetInt64(_, _)).Times(AnyNumber()); |
Darin Petkov | 1cbd78f | 2010-07-29 12:38:34 -0700 | [diff] [blame] | 2033 | EXPECT_CALL(prefs, SetInt64(kPrefsLastActivePingDay, _)).Times(0); |
| 2034 | EXPECT_CALL(prefs, SetInt64(kPrefsLastRollCallPingDay, _)).Times(0); |
| 2035 | ASSERT_TRUE( |
Marton Hunyady | 2abda31 | 2018-04-24 18:21:49 +0200 | [diff] [blame^] | 2036 | TestUpdateCheck("<?xml version=\"1.0\" encoding=\"UTF-8\"?><response " |
Jay Srinivasan | 23b92a5 | 2012-10-27 02:00:21 -0700 | [diff] [blame] | 2037 | "protocol=\"3.0\"><daystart elapsed_seconds=\"x\"/>" |
Darin Petkov | 1cbd78f | 2010-07-29 12:38:34 -0700 | [diff] [blame] | 2038 | "<app appid=\"foo\" status=\"ok\"><ping status=\"ok\"/>" |
Jay Srinivasan | 23b92a5 | 2012-10-27 02:00:21 -0700 | [diff] [blame] | 2039 | "<updatecheck status=\"noupdate\"/></app></response>", |
Darin Petkov | edc522e | 2010-11-05 09:35:17 -0700 | [diff] [blame] | 2040 | -1, |
Darin Petkov | 265f290 | 2011-05-09 15:17:40 -0700 | [diff] [blame] | 2041 | false, // ping_only |
Gilad Arnold | d1c4d2d | 2014-06-05 14:07:53 -0700 | [diff] [blame] | 2042 | ErrorCode::kSuccess, |
David Zeuthen | 33bae49 | 2014-02-25 16:16:18 -0800 | [diff] [blame] | 2043 | metrics::CheckResult::kNoUpdateAvailable, |
| 2044 | metrics::CheckReaction::kUnset, |
| 2045 | metrics::DownloadErrorCode::kUnset, |
Alex Vakulenko | 88b591f | 2014-08-28 16:48:57 -0700 | [diff] [blame] | 2046 | nullptr, |
| 2047 | nullptr)); |
Darin Petkov | 1cbd78f | 2010-07-29 12:38:34 -0700 | [diff] [blame] | 2048 | } |
| 2049 | |
Alex Deymo | b3fa53b | 2016-04-18 19:57:58 -0700 | [diff] [blame] | 2050 | TEST_F(OmahaRequestActionTest, ParseUpdateCheckAttributesTest) { |
| 2051 | // Test that the "eol" flags is only parsed from the "_eol" attribute and not |
| 2052 | // the "eol" attribute. |
| 2053 | ASSERT_TRUE( |
Marton Hunyady | 2abda31 | 2018-04-24 18:21:49 +0200 | [diff] [blame^] | 2054 | TestUpdateCheck("<?xml version=\"1.0\" encoding=\"UTF-8\"?><response " |
Alex Deymo | b3fa53b | 2016-04-18 19:57:58 -0700 | [diff] [blame] | 2055 | "protocol=\"3.0\"><app appid=\"foo\" status=\"ok\">" |
| 2056 | "<ping status=\"ok\"/><updatecheck status=\"noupdate\" " |
| 2057 | "_eol=\"security-only\" eol=\"eol\" _foo=\"bar\"/>" |
| 2058 | "</app></response>", |
| 2059 | -1, |
| 2060 | false, // ping_only |
| 2061 | ErrorCode::kSuccess, |
| 2062 | metrics::CheckResult::kNoUpdateAvailable, |
| 2063 | metrics::CheckReaction::kUnset, |
| 2064 | metrics::DownloadErrorCode::kUnset, |
| 2065 | nullptr, |
| 2066 | nullptr)); |
| 2067 | string eol_pref; |
| 2068 | EXPECT_TRUE( |
| 2069 | fake_system_state_.prefs()->GetString(kPrefsOmahaEolStatus, &eol_pref)); |
| 2070 | // Note that the eol="eol" attribute should be ignored and the _eol should be |
| 2071 | // used instead. |
| 2072 | EXPECT_EQ("security-only", eol_pref); |
| 2073 | } |
| 2074 | |
Alex Deymo | e1e3afe | 2014-10-30 13:02:49 -0700 | [diff] [blame] | 2075 | TEST_F(OmahaRequestActionTest, NoUniqueIDTest) { |
Alex Vakulenko | 3f39d5c | 2015-10-13 09:27:13 -0700 | [diff] [blame] | 2076 | brillo::Blob post_data; |
Marton Hunyady | 2abda31 | 2018-04-24 18:21:49 +0200 | [diff] [blame^] | 2077 | ASSERT_FALSE(TestUpdateCheck("invalid xml>", |
Darin Petkov | edc522e | 2010-11-05 09:35:17 -0700 | [diff] [blame] | 2078 | -1, |
Darin Petkov | 265f290 | 2011-05-09 15:17:40 -0700 | [diff] [blame] | 2079 | false, // ping_only |
Gilad Arnold | d1c4d2d | 2014-06-05 14:07:53 -0700 | [diff] [blame] | 2080 | ErrorCode::kOmahaRequestXMLParseError, |
David Zeuthen | 33bae49 | 2014-02-25 16:16:18 -0800 | [diff] [blame] | 2081 | metrics::CheckResult::kParsingError, |
| 2082 | metrics::CheckReaction::kUnset, |
| 2083 | metrics::DownloadErrorCode::kUnset, |
Alex Vakulenko | 88b591f | 2014-08-28 16:48:57 -0700 | [diff] [blame] | 2084 | nullptr, // response |
Darin Petkov | 84c763c | 2010-07-29 16:27:58 -0700 | [diff] [blame] | 2085 | &post_data)); |
| 2086 | // convert post_data to string |
Alex Vakulenko | f68bbbc | 2015-02-09 12:53:18 -0800 | [diff] [blame] | 2087 | string post_str(post_data.begin(), post_data.end()); |
Darin Petkov | 84c763c | 2010-07-29 16:27:58 -0700 | [diff] [blame] | 2088 | EXPECT_EQ(post_str.find("machineid="), string::npos); |
| 2089 | EXPECT_EQ(post_str.find("userid="), string::npos); |
| 2090 | } |
| 2091 | |
Alex Deymo | e1e3afe | 2014-10-30 13:02:49 -0700 | [diff] [blame] | 2092 | TEST_F(OmahaRequestActionTest, NetworkFailureTest) { |
Darin Petkov | edc522e | 2010-11-05 09:35:17 -0700 | [diff] [blame] | 2093 | OmahaResponse response; |
Gilad Arnold | d1c4d2d | 2014-06-05 14:07:53 -0700 | [diff] [blame] | 2094 | const int http_error_code = |
| 2095 | static_cast<int>(ErrorCode::kOmahaRequestHTTPResponseBase) + 501; |
Marton Hunyady | 2abda31 | 2018-04-24 18:21:49 +0200 | [diff] [blame^] | 2096 | ASSERT_FALSE(TestUpdateCheck("", |
| 2097 | 501, |
| 2098 | false, // ping_only |
| 2099 | static_cast<ErrorCode>(http_error_code), |
| 2100 | metrics::CheckResult::kDownloadError, |
| 2101 | metrics::CheckReaction::kUnset, |
| 2102 | static_cast<metrics::DownloadErrorCode>(501), |
| 2103 | &response, |
| 2104 | nullptr)); |
Darin Petkov | edc522e | 2010-11-05 09:35:17 -0700 | [diff] [blame] | 2105 | EXPECT_FALSE(response.update_exists); |
| 2106 | } |
| 2107 | |
Alex Deymo | e1e3afe | 2014-10-30 13:02:49 -0700 | [diff] [blame] | 2108 | TEST_F(OmahaRequestActionTest, NetworkFailureBadHTTPCodeTest) { |
Darin Petkov | edc522e | 2010-11-05 09:35:17 -0700 | [diff] [blame] | 2109 | OmahaResponse response; |
Gilad Arnold | d1c4d2d | 2014-06-05 14:07:53 -0700 | [diff] [blame] | 2110 | const int http_error_code = |
| 2111 | static_cast<int>(ErrorCode::kOmahaRequestHTTPResponseBase) + 999; |
Marton Hunyady | 2abda31 | 2018-04-24 18:21:49 +0200 | [diff] [blame^] | 2112 | ASSERT_FALSE(TestUpdateCheck("", |
| 2113 | 1500, |
| 2114 | false, // ping_only |
| 2115 | static_cast<ErrorCode>(http_error_code), |
| 2116 | metrics::CheckResult::kDownloadError, |
| 2117 | metrics::CheckReaction::kUnset, |
| 2118 | metrics::DownloadErrorCode::kHttpStatusOther, |
| 2119 | &response, |
| 2120 | nullptr)); |
Darin Petkov | edc522e | 2010-11-05 09:35:17 -0700 | [diff] [blame] | 2121 | EXPECT_FALSE(response.update_exists); |
| 2122 | } |
| 2123 | |
Alex Deymo | e1e3afe | 2014-10-30 13:02:49 -0700 | [diff] [blame] | 2124 | TEST_F(OmahaRequestActionTest, TestUpdateFirstSeenAtGetsPersistedFirstTime) { |
Jay Srinivasan | 34b5d86 | 2012-07-23 11:43:22 -0700 | [diff] [blame] | 2125 | OmahaResponse response; |
Marton Hunyady | 2abda31 | 2018-04-24 18:21:49 +0200 | [diff] [blame^] | 2126 | request_params_.set_wall_clock_based_wait_enabled(true); |
| 2127 | request_params_.set_waiting_period(TimeDelta().FromDays(1)); |
| 2128 | request_params_.set_update_check_count_wait_enabled(false); |
Jay Srinivasan | 34b5d86 | 2012-07-23 11:43:22 -0700 | [diff] [blame] | 2129 | |
Sen Jiang | 7c1171e | 2016-06-23 11:35:40 -0700 | [diff] [blame] | 2130 | Time arbitrary_date; |
Amin Hassani | 71818c8 | 2018-03-06 13:25:40 -0800 | [diff] [blame] | 2131 | Time::FromString("6/4/1989", &arbitrary_date); |
Sen Jiang | 7c1171e | 2016-06-23 11:35:40 -0700 | [diff] [blame] | 2132 | fake_system_state_.fake_clock()->SetWallclockTime(arbitrary_date); |
Marton Hunyady | 2abda31 | 2018-04-24 18:21:49 +0200 | [diff] [blame^] | 2133 | ASSERT_FALSE(TestUpdateCheck(fake_update_response_.GetUpdateResponse(), |
Sen Jiang | 7c1171e | 2016-06-23 11:35:40 -0700 | [diff] [blame] | 2134 | -1, |
| 2135 | false, // ping_only |
| 2136 | ErrorCode::kOmahaUpdateDeferredPerPolicy, |
| 2137 | metrics::CheckResult::kUpdateAvailable, |
| 2138 | metrics::CheckReaction::kDeferring, |
| 2139 | metrics::DownloadErrorCode::kUnset, |
| 2140 | &response, |
| 2141 | nullptr)); |
Jay Srinivasan | 34b5d86 | 2012-07-23 11:43:22 -0700 | [diff] [blame] | 2142 | |
Ben Chan | 9abb763 | 2014-08-07 00:10:53 -0700 | [diff] [blame] | 2143 | int64_t timestamp = 0; |
Alex Deymo | e1e3afe | 2014-10-30 13:02:49 -0700 | [diff] [blame] | 2144 | ASSERT_TRUE(fake_prefs_.GetInt64(kPrefsUpdateFirstSeenAt, ×tamp)); |
Sen Jiang | 7c1171e | 2016-06-23 11:35:40 -0700 | [diff] [blame] | 2145 | EXPECT_EQ(arbitrary_date.ToInternalValue(), timestamp); |
Jay Srinivasan | 34b5d86 | 2012-07-23 11:43:22 -0700 | [diff] [blame] | 2146 | EXPECT_FALSE(response.update_exists); |
Chris Sosa | 968d057 | 2013-08-23 14:46:02 -0700 | [diff] [blame] | 2147 | |
| 2148 | // Verify if we are interactive check we don't defer. |
Marton Hunyady | 2abda31 | 2018-04-24 18:21:49 +0200 | [diff] [blame^] | 2149 | request_params_.set_interactive(true); |
| 2150 | ASSERT_TRUE(TestUpdateCheck(fake_update_response_.GetUpdateResponse(), |
Sen Jiang | 7c1171e | 2016-06-23 11:35:40 -0700 | [diff] [blame] | 2151 | -1, |
| 2152 | false, // ping_only |
| 2153 | ErrorCode::kSuccess, |
| 2154 | metrics::CheckResult::kUpdateAvailable, |
| 2155 | metrics::CheckReaction::kUpdating, |
| 2156 | metrics::DownloadErrorCode::kUnset, |
| 2157 | &response, |
| 2158 | nullptr)); |
Chris Sosa | 968d057 | 2013-08-23 14:46:02 -0700 | [diff] [blame] | 2159 | EXPECT_TRUE(response.update_exists); |
Jay Srinivasan | 34b5d86 | 2012-07-23 11:43:22 -0700 | [diff] [blame] | 2160 | } |
| 2161 | |
Alex Deymo | e1e3afe | 2014-10-30 13:02:49 -0700 | [diff] [blame] | 2162 | TEST_F(OmahaRequestActionTest, TestUpdateFirstSeenAtGetsUsedIfAlreadyPresent) { |
Jay Srinivasan | 34b5d86 | 2012-07-23 11:43:22 -0700 | [diff] [blame] | 2163 | OmahaResponse response; |
Marton Hunyady | 2abda31 | 2018-04-24 18:21:49 +0200 | [diff] [blame^] | 2164 | request_params_.set_wall_clock_based_wait_enabled(true); |
| 2165 | request_params_.set_waiting_period(TimeDelta().FromDays(1)); |
| 2166 | request_params_.set_update_check_count_wait_enabled(false); |
Jay Srinivasan | 34b5d86 | 2012-07-23 11:43:22 -0700 | [diff] [blame] | 2167 | |
Sen Jiang | 7c1171e | 2016-06-23 11:35:40 -0700 | [diff] [blame] | 2168 | Time t1, t2; |
Amin Hassani | 71818c8 | 2018-03-06 13:25:40 -0800 | [diff] [blame] | 2169 | Time::FromString("1/1/2012", &t1); |
| 2170 | Time::FromString("1/3/2012", &t2); |
Sen Jiang | 7c1171e | 2016-06-23 11:35:40 -0700 | [diff] [blame] | 2171 | ASSERT_TRUE( |
| 2172 | fake_prefs_.SetInt64(kPrefsUpdateFirstSeenAt, t1.ToInternalValue())); |
| 2173 | fake_system_state_.fake_clock()->SetWallclockTime(t2); |
Marton Hunyady | 2abda31 | 2018-04-24 18:21:49 +0200 | [diff] [blame^] | 2174 | ASSERT_TRUE(TestUpdateCheck(fake_update_response_.GetUpdateResponse(), |
Sen Jiang | 7c1171e | 2016-06-23 11:35:40 -0700 | [diff] [blame] | 2175 | -1, |
| 2176 | false, // ping_only |
| 2177 | ErrorCode::kSuccess, |
| 2178 | metrics::CheckResult::kUpdateAvailable, |
| 2179 | metrics::CheckReaction::kUpdating, |
| 2180 | metrics::DownloadErrorCode::kUnset, |
| 2181 | &response, |
| 2182 | nullptr)); |
Jay Srinivasan | 34b5d86 | 2012-07-23 11:43:22 -0700 | [diff] [blame] | 2183 | |
| 2184 | EXPECT_TRUE(response.update_exists); |
| 2185 | |
| 2186 | // Make sure the timestamp t1 is unchanged showing that it was reused. |
Ben Chan | 9abb763 | 2014-08-07 00:10:53 -0700 | [diff] [blame] | 2187 | int64_t timestamp = 0; |
Alex Deymo | e1e3afe | 2014-10-30 13:02:49 -0700 | [diff] [blame] | 2188 | ASSERT_TRUE(fake_prefs_.GetInt64(kPrefsUpdateFirstSeenAt, ×tamp)); |
Jay Srinivasan | 34b5d86 | 2012-07-23 11:43:22 -0700 | [diff] [blame] | 2189 | ASSERT_TRUE(timestamp == t1.ToInternalValue()); |
| 2190 | } |
| 2191 | |
Alex Deymo | e1e3afe | 2014-10-30 13:02:49 -0700 | [diff] [blame] | 2192 | TEST_F(OmahaRequestActionTest, TestChangingToMoreStableChannel) { |
Gilad Arnold | eff87cc | 2013-07-22 18:32:09 -0700 | [diff] [blame] | 2193 | // Create a uniquely named test directory. |
Sen Jiang | 297e583 | 2016-03-17 14:45:51 -0700 | [diff] [blame] | 2194 | base::ScopedTempDir tempdir; |
| 2195 | ASSERT_TRUE(tempdir.CreateUniqueTempDir()); |
Gilad Arnold | eff87cc | 2013-07-22 18:32:09 -0700 | [diff] [blame] | 2196 | |
Alex Vakulenko | 3f39d5c | 2015-10-13 09:27:13 -0700 | [diff] [blame] | 2197 | brillo::Blob post_data; |
Marton Hunyady | 2abda31 | 2018-04-24 18:21:49 +0200 | [diff] [blame^] | 2198 | request_params_.set_root(tempdir.GetPath().value()); |
| 2199 | request_params_.set_app_id("{22222222-2222-2222-2222-222222222222}"); |
| 2200 | request_params_.set_app_version("1.2.3.4"); |
| 2201 | request_params_.set_product_components("o.bundle=1"); |
| 2202 | request_params_.set_current_channel("canary-channel"); |
| 2203 | EXPECT_TRUE( |
| 2204 | request_params_.SetTargetChannel("stable-channel", true, nullptr)); |
| 2205 | request_params_.UpdateDownloadChannel(); |
| 2206 | EXPECT_TRUE(request_params_.ShouldPowerwash()); |
| 2207 | ASSERT_FALSE(TestUpdateCheck("invalid xml>", |
Jay Srinivasan | ae4697c | 2013-03-18 17:08:08 -0700 | [diff] [blame] | 2208 | -1, |
| 2209 | false, // ping_only |
Gilad Arnold | d1c4d2d | 2014-06-05 14:07:53 -0700 | [diff] [blame] | 2210 | ErrorCode::kOmahaRequestXMLParseError, |
David Zeuthen | 33bae49 | 2014-02-25 16:16:18 -0800 | [diff] [blame] | 2211 | metrics::CheckResult::kParsingError, |
| 2212 | metrics::CheckReaction::kUnset, |
| 2213 | metrics::DownloadErrorCode::kUnset, |
Alex Vakulenko | 88b591f | 2014-08-28 16:48:57 -0700 | [diff] [blame] | 2214 | nullptr, // response |
Jay Srinivasan | ae4697c | 2013-03-18 17:08:08 -0700 | [diff] [blame] | 2215 | &post_data)); |
| 2216 | // convert post_data to string |
Alex Vakulenko | f68bbbc | 2015-02-09 12:53:18 -0800 | [diff] [blame] | 2217 | string post_str(post_data.begin(), post_data.end()); |
Jay Srinivasan | ae4697c | 2013-03-18 17:08:08 -0700 | [diff] [blame] | 2218 | EXPECT_NE(string::npos, post_str.find( |
| 2219 | "appid=\"{22222222-2222-2222-2222-222222222222}\" " |
| 2220 | "version=\"0.0.0.0\" from_version=\"1.2.3.4\" " |
| 2221 | "track=\"stable-channel\" from_track=\"canary-channel\" ")); |
Sen Jiang | 8cd4234 | 2018-01-31 12:06:59 -0800 | [diff] [blame] | 2222 | EXPECT_EQ(string::npos, post_str.find("o.bundle")); |
Jay Srinivasan | ae4697c | 2013-03-18 17:08:08 -0700 | [diff] [blame] | 2223 | } |
| 2224 | |
Alex Deymo | e1e3afe | 2014-10-30 13:02:49 -0700 | [diff] [blame] | 2225 | TEST_F(OmahaRequestActionTest, TestChangingToLessStableChannel) { |
Gilad Arnold | eff87cc | 2013-07-22 18:32:09 -0700 | [diff] [blame] | 2226 | // Create a uniquely named test directory. |
Sen Jiang | 297e583 | 2016-03-17 14:45:51 -0700 | [diff] [blame] | 2227 | base::ScopedTempDir tempdir; |
| 2228 | ASSERT_TRUE(tempdir.CreateUniqueTempDir()); |
Gilad Arnold | eff87cc | 2013-07-22 18:32:09 -0700 | [diff] [blame] | 2229 | |
Alex Vakulenko | 3f39d5c | 2015-10-13 09:27:13 -0700 | [diff] [blame] | 2230 | brillo::Blob post_data; |
Marton Hunyady | 2abda31 | 2018-04-24 18:21:49 +0200 | [diff] [blame^] | 2231 | request_params_.set_root(tempdir.GetPath().value()); |
| 2232 | request_params_.set_app_id("{11111111-1111-1111-1111-111111111111}"); |
| 2233 | request_params_.set_app_version("5.6.7.8"); |
| 2234 | request_params_.set_product_components("o.bundle=1"); |
| 2235 | request_params_.set_current_channel("stable-channel"); |
| 2236 | EXPECT_TRUE( |
| 2237 | request_params_.SetTargetChannel("canary-channel", false, nullptr)); |
| 2238 | request_params_.UpdateDownloadChannel(); |
| 2239 | EXPECT_FALSE(request_params_.ShouldPowerwash()); |
| 2240 | ASSERT_FALSE(TestUpdateCheck("invalid xml>", |
Jay Srinivasan | ae4697c | 2013-03-18 17:08:08 -0700 | [diff] [blame] | 2241 | -1, |
| 2242 | false, // ping_only |
Gilad Arnold | d1c4d2d | 2014-06-05 14:07:53 -0700 | [diff] [blame] | 2243 | ErrorCode::kOmahaRequestXMLParseError, |
David Zeuthen | 33bae49 | 2014-02-25 16:16:18 -0800 | [diff] [blame] | 2244 | metrics::CheckResult::kParsingError, |
| 2245 | metrics::CheckReaction::kUnset, |
| 2246 | metrics::DownloadErrorCode::kUnset, |
Alex Vakulenko | 88b591f | 2014-08-28 16:48:57 -0700 | [diff] [blame] | 2247 | nullptr, // response |
Jay Srinivasan | ae4697c | 2013-03-18 17:08:08 -0700 | [diff] [blame] | 2248 | &post_data)); |
| 2249 | // convert post_data to string |
Alex Vakulenko | f68bbbc | 2015-02-09 12:53:18 -0800 | [diff] [blame] | 2250 | string post_str(post_data.begin(), post_data.end()); |
Jay Srinivasan | ae4697c | 2013-03-18 17:08:08 -0700 | [diff] [blame] | 2251 | EXPECT_NE(string::npos, post_str.find( |
| 2252 | "appid=\"{11111111-1111-1111-1111-111111111111}\" " |
| 2253 | "version=\"5.6.7.8\" " |
| 2254 | "track=\"canary-channel\" from_track=\"stable-channel\"")); |
Alex Vakulenko | d2779df | 2014-06-16 13:19:00 -0700 | [diff] [blame] | 2255 | EXPECT_EQ(string::npos, post_str.find("from_version")); |
Sen Jiang | 8cd4234 | 2018-01-31 12:06:59 -0800 | [diff] [blame] | 2256 | EXPECT_NE(string::npos, post_str.find("o.bundle.version=\"1\"")); |
Jay Srinivasan | ae4697c | 2013-03-18 17:08:08 -0700 | [diff] [blame] | 2257 | } |
| 2258 | |
Alex Deymo | ebbe7ef | 2014-10-30 13:02:49 -0700 | [diff] [blame] | 2259 | // Checks that the initial ping with a=-1 r=-1 is not send when the device |
| 2260 | // was powerwashed. |
| 2261 | TEST_F(OmahaRequestActionTest, PingWhenPowerwashed) { |
| 2262 | fake_prefs_.SetString(kPrefsPreviousVersion, ""); |
| 2263 | |
| 2264 | // Flag that the device was powerwashed in the past. |
| 2265 | fake_system_state_.fake_hardware()->SetPowerwashCount(1); |
| 2266 | |
Alex Vakulenko | 3f39d5c | 2015-10-13 09:27:13 -0700 | [diff] [blame] | 2267 | brillo::Blob post_data; |
Marton Hunyady | 2abda31 | 2018-04-24 18:21:49 +0200 | [diff] [blame^] | 2268 | ASSERT_TRUE(TestUpdateCheck(fake_update_response_.GetNoUpdateResponse(), |
| 2269 | -1, |
| 2270 | false, // ping_only |
| 2271 | ErrorCode::kSuccess, |
| 2272 | metrics::CheckResult::kNoUpdateAvailable, |
| 2273 | metrics::CheckReaction::kUnset, |
| 2274 | metrics::DownloadErrorCode::kUnset, |
| 2275 | nullptr, |
| 2276 | &post_data)); |
Alex Deymo | ebbe7ef | 2014-10-30 13:02:49 -0700 | [diff] [blame] | 2277 | // We shouldn't send a ping in this case since powerwash > 0. |
Alex Vakulenko | f68bbbc | 2015-02-09 12:53:18 -0800 | [diff] [blame] | 2278 | string post_str(post_data.begin(), post_data.end()); |
Alex Deymo | ebbe7ef | 2014-10-30 13:02:49 -0700 | [diff] [blame] | 2279 | EXPECT_EQ(string::npos, post_str.find("<ping")); |
| 2280 | } |
| 2281 | |
Amin Hassani | 1677e81 | 2017-06-21 13:36:36 -0700 | [diff] [blame] | 2282 | // Checks that the initial ping with a=-1 r=-1 is not send when the device |
| 2283 | // first_active_omaha_ping_sent is set. |
| 2284 | TEST_F(OmahaRequestActionTest, PingWhenFirstActiveOmahaPingIsSent) { |
| 2285 | fake_prefs_.SetString(kPrefsPreviousVersion, ""); |
| 2286 | |
| 2287 | // Flag that the device was not powerwashed in the past. |
| 2288 | fake_system_state_.fake_hardware()->SetPowerwashCount(0); |
| 2289 | |
| 2290 | // Flag that the device has sent first active ping in the past. |
| 2291 | fake_system_state_.fake_hardware()->SetFirstActiveOmahaPingSent(); |
| 2292 | |
| 2293 | brillo::Blob post_data; |
Marton Hunyady | 2abda31 | 2018-04-24 18:21:49 +0200 | [diff] [blame^] | 2294 | ASSERT_TRUE(TestUpdateCheck(fake_update_response_.GetNoUpdateResponse(), |
| 2295 | -1, |
| 2296 | false, // ping_only |
| 2297 | ErrorCode::kSuccess, |
| 2298 | metrics::CheckResult::kNoUpdateAvailable, |
| 2299 | metrics::CheckReaction::kUnset, |
| 2300 | metrics::DownloadErrorCode::kUnset, |
| 2301 | nullptr, |
| 2302 | &post_data)); |
Amin Hassani | 1677e81 | 2017-06-21 13:36:36 -0700 | [diff] [blame] | 2303 | // We shouldn't send a ping in this case since |
| 2304 | // first_active_omaha_ping_sent=true |
| 2305 | string post_str(post_data.begin(), post_data.end()); |
| 2306 | EXPECT_EQ(string::npos, post_str.find("<ping")); |
| 2307 | } |
| 2308 | |
Alex Deymo | 9fded1e | 2015-11-05 12:31:19 -0800 | [diff] [blame] | 2309 | // Checks that the event 54 is sent on a reboot to a new update. |
| 2310 | TEST_F(OmahaRequestActionTest, RebootAfterUpdateEvent) { |
| 2311 | // Flag that the device was updated in a previous boot. |
| 2312 | fake_prefs_.SetString(kPrefsPreviousVersion, "1.2.3.4"); |
| 2313 | |
| 2314 | brillo::Blob post_data; |
Marton Hunyady | 2abda31 | 2018-04-24 18:21:49 +0200 | [diff] [blame^] | 2315 | ASSERT_TRUE(TestUpdateCheck(fake_update_response_.GetNoUpdateResponse(), |
| 2316 | -1, |
| 2317 | false, // ping_only |
| 2318 | ErrorCode::kSuccess, |
| 2319 | metrics::CheckResult::kNoUpdateAvailable, |
| 2320 | metrics::CheckReaction::kUnset, |
| 2321 | metrics::DownloadErrorCode::kUnset, |
| 2322 | nullptr, |
| 2323 | &post_data)); |
Alex Deymo | 9fded1e | 2015-11-05 12:31:19 -0800 | [diff] [blame] | 2324 | string post_str(post_data.begin(), post_data.end()); |
| 2325 | |
| 2326 | // An event 54 is included and has the right version. |
| 2327 | EXPECT_NE(string::npos, |
| 2328 | post_str.find(base::StringPrintf( |
| 2329 | "<event eventtype=\"%d\"", |
| 2330 | OmahaEvent::kTypeRebootedAfterUpdate))); |
| 2331 | EXPECT_NE(string::npos, |
| 2332 | post_str.find("previousversion=\"1.2.3.4\"></event>")); |
| 2333 | |
| 2334 | // The previous version flag should have been removed. |
| 2335 | EXPECT_TRUE(fake_prefs_.Exists(kPrefsPreviousVersion)); |
| 2336 | string prev_version; |
| 2337 | EXPECT_TRUE(fake_prefs_.GetString(kPrefsPreviousVersion, &prev_version)); |
| 2338 | EXPECT_TRUE(prev_version.empty()); |
| 2339 | } |
| 2340 | |
Alex Deymo | e1e3afe | 2014-10-30 13:02:49 -0700 | [diff] [blame] | 2341 | void OmahaRequestActionTest::P2PTest( |
| 2342 | bool initial_allow_p2p_for_downloading, |
| 2343 | bool initial_allow_p2p_for_sharing, |
| 2344 | bool omaha_disable_p2p_for_downloading, |
| 2345 | bool omaha_disable_p2p_for_sharing, |
| 2346 | bool payload_state_allow_p2p_attempt, |
| 2347 | bool expect_p2p_client_lookup, |
| 2348 | const string& p2p_client_result_url, |
| 2349 | bool expected_allow_p2p_for_downloading, |
| 2350 | bool expected_allow_p2p_for_sharing, |
| 2351 | const string& expected_p2p_url) { |
David Zeuthen | 8f191b2 | 2013-08-06 12:27:50 -0700 | [diff] [blame] | 2352 | OmahaResponse response; |
Gilad Arnold | 74b5f55 | 2014-10-07 08:17:16 -0700 | [diff] [blame] | 2353 | bool actual_allow_p2p_for_downloading = initial_allow_p2p_for_downloading; |
| 2354 | bool actual_allow_p2p_for_sharing = initial_allow_p2p_for_sharing; |
| 2355 | string actual_p2p_url; |
David Zeuthen | 8f191b2 | 2013-08-06 12:27:50 -0700 | [diff] [blame] | 2356 | |
| 2357 | MockPayloadState mock_payload_state; |
Alex Deymo | e1e3afe | 2014-10-30 13:02:49 -0700 | [diff] [blame] | 2358 | fake_system_state_.set_payload_state(&mock_payload_state); |
David Zeuthen | 8f191b2 | 2013-08-06 12:27:50 -0700 | [diff] [blame] | 2359 | EXPECT_CALL(mock_payload_state, P2PAttemptAllowed()) |
| 2360 | .WillRepeatedly(Return(payload_state_allow_p2p_attempt)); |
Gilad Arnold | 74b5f55 | 2014-10-07 08:17:16 -0700 | [diff] [blame] | 2361 | EXPECT_CALL(mock_payload_state, GetUsingP2PForDownloading()) |
| 2362 | .WillRepeatedly(ReturnPointee(&actual_allow_p2p_for_downloading)); |
| 2363 | EXPECT_CALL(mock_payload_state, GetUsingP2PForSharing()) |
| 2364 | .WillRepeatedly(ReturnPointee(&actual_allow_p2p_for_sharing)); |
| 2365 | EXPECT_CALL(mock_payload_state, SetUsingP2PForDownloading(_)) |
| 2366 | .WillRepeatedly(SaveArg<0>(&actual_allow_p2p_for_downloading)); |
| 2367 | EXPECT_CALL(mock_payload_state, SetUsingP2PForSharing(_)) |
| 2368 | .WillRepeatedly(SaveArg<0>(&actual_allow_p2p_for_sharing)); |
| 2369 | EXPECT_CALL(mock_payload_state, SetP2PUrl(_)) |
| 2370 | .WillRepeatedly(SaveArg<0>(&actual_p2p_url)); |
| 2371 | |
David Zeuthen | 8f191b2 | 2013-08-06 12:27:50 -0700 | [diff] [blame] | 2372 | MockP2PManager mock_p2p_manager; |
Alex Deymo | e1e3afe | 2014-10-30 13:02:49 -0700 | [diff] [blame] | 2373 | fake_system_state_.set_p2p_manager(&mock_p2p_manager); |
David Zeuthen | 8f191b2 | 2013-08-06 12:27:50 -0700 | [diff] [blame] | 2374 | mock_p2p_manager.fake().SetLookupUrlForFileResult(p2p_client_result_url); |
| 2375 | |
David Zeuthen | 4cc5ed2 | 2014-01-15 12:35:03 -0800 | [diff] [blame] | 2376 | TimeDelta timeout = TimeDelta::FromSeconds(kMaxP2PNetworkWaitTimeSeconds); |
| 2377 | EXPECT_CALL(mock_p2p_manager, LookupUrlForFile(_, _, timeout, _)) |
David Zeuthen | 8f191b2 | 2013-08-06 12:27:50 -0700 | [diff] [blame] | 2378 | .Times(expect_p2p_client_lookup ? 1 : 0); |
| 2379 | |
Alex Deymo | 8e18f93 | 2015-03-27 16:16:59 -0700 | [diff] [blame] | 2380 | fake_update_response_.disable_p2p_for_downloading = |
| 2381 | omaha_disable_p2p_for_downloading; |
| 2382 | fake_update_response_.disable_p2p_for_sharing = omaha_disable_p2p_for_sharing; |
Marton Hunyady | 2abda31 | 2018-04-24 18:21:49 +0200 | [diff] [blame^] | 2383 | ASSERT_TRUE(TestUpdateCheck(fake_update_response_.GetUpdateResponse(), |
| 2384 | -1, |
| 2385 | false, // ping_only |
| 2386 | ErrorCode::kSuccess, |
| 2387 | metrics::CheckResult::kUpdateAvailable, |
| 2388 | metrics::CheckReaction::kUpdating, |
| 2389 | metrics::DownloadErrorCode::kUnset, |
| 2390 | &response, |
| 2391 | nullptr)); |
David Zeuthen | 8f191b2 | 2013-08-06 12:27:50 -0700 | [diff] [blame] | 2392 | EXPECT_TRUE(response.update_exists); |
| 2393 | |
Gilad Arnold | 74b5f55 | 2014-10-07 08:17:16 -0700 | [diff] [blame] | 2394 | EXPECT_EQ(omaha_disable_p2p_for_downloading, |
| 2395 | response.disable_p2p_for_downloading); |
| 2396 | EXPECT_EQ(omaha_disable_p2p_for_sharing, |
| 2397 | response.disable_p2p_for_sharing); |
David Zeuthen | 8f191b2 | 2013-08-06 12:27:50 -0700 | [diff] [blame] | 2398 | |
Gilad Arnold | 74b5f55 | 2014-10-07 08:17:16 -0700 | [diff] [blame] | 2399 | EXPECT_EQ(expected_allow_p2p_for_downloading, |
| 2400 | actual_allow_p2p_for_downloading); |
| 2401 | EXPECT_EQ(expected_allow_p2p_for_sharing, actual_allow_p2p_for_sharing); |
| 2402 | EXPECT_EQ(expected_p2p_url, actual_p2p_url); |
David Zeuthen | 8f191b2 | 2013-08-06 12:27:50 -0700 | [diff] [blame] | 2403 | } |
| 2404 | |
Alex Deymo | e1e3afe | 2014-10-30 13:02:49 -0700 | [diff] [blame] | 2405 | TEST_F(OmahaRequestActionTest, P2PWithPeer) { |
Alex Vakulenko | d2779df | 2014-06-16 13:19:00 -0700 | [diff] [blame] | 2406 | P2PTest(true, // initial_allow_p2p_for_downloading |
| 2407 | true, // initial_allow_p2p_for_sharing |
| 2408 | false, // omaha_disable_p2p_for_downloading |
| 2409 | false, // omaha_disable_p2p_for_sharing |
| 2410 | true, // payload_state_allow_p2p_attempt |
| 2411 | true, // expect_p2p_client_lookup |
| 2412 | "http://1.3.5.7/p2p", // p2p_client_result_url |
| 2413 | true, // expected_allow_p2p_for_downloading |
| 2414 | true, // expected_allow_p2p_for_sharing |
| 2415 | "http://1.3.5.7/p2p"); // expected_p2p_url |
David Zeuthen | 8f191b2 | 2013-08-06 12:27:50 -0700 | [diff] [blame] | 2416 | } |
| 2417 | |
Alex Deymo | e1e3afe | 2014-10-30 13:02:49 -0700 | [diff] [blame] | 2418 | TEST_F(OmahaRequestActionTest, P2PWithoutPeer) { |
Alex Vakulenko | d2779df | 2014-06-16 13:19:00 -0700 | [diff] [blame] | 2419 | P2PTest(true, // initial_allow_p2p_for_downloading |
| 2420 | true, // initial_allow_p2p_for_sharing |
| 2421 | false, // omaha_disable_p2p_for_downloading |
| 2422 | false, // omaha_disable_p2p_for_sharing |
| 2423 | true, // payload_state_allow_p2p_attempt |
| 2424 | true, // expect_p2p_client_lookup |
| 2425 | "", // p2p_client_result_url |
| 2426 | false, // expected_allow_p2p_for_downloading |
| 2427 | true, // expected_allow_p2p_for_sharing |
| 2428 | ""); // expected_p2p_url |
David Zeuthen | 8f191b2 | 2013-08-06 12:27:50 -0700 | [diff] [blame] | 2429 | } |
| 2430 | |
Alex Deymo | e1e3afe | 2014-10-30 13:02:49 -0700 | [diff] [blame] | 2431 | TEST_F(OmahaRequestActionTest, P2PDownloadNotAllowed) { |
Alex Vakulenko | d2779df | 2014-06-16 13:19:00 -0700 | [diff] [blame] | 2432 | P2PTest(false, // initial_allow_p2p_for_downloading |
| 2433 | true, // initial_allow_p2p_for_sharing |
| 2434 | false, // omaha_disable_p2p_for_downloading |
| 2435 | false, // omaha_disable_p2p_for_sharing |
| 2436 | true, // payload_state_allow_p2p_attempt |
| 2437 | false, // expect_p2p_client_lookup |
| 2438 | "unset", // p2p_client_result_url |
| 2439 | false, // expected_allow_p2p_for_downloading |
| 2440 | true, // expected_allow_p2p_for_sharing |
| 2441 | ""); // expected_p2p_url |
David Zeuthen | 8f191b2 | 2013-08-06 12:27:50 -0700 | [diff] [blame] | 2442 | } |
| 2443 | |
Alex Deymo | e1e3afe | 2014-10-30 13:02:49 -0700 | [diff] [blame] | 2444 | TEST_F(OmahaRequestActionTest, P2PWithPeerDownloadDisabledByOmaha) { |
Alex Vakulenko | d2779df | 2014-06-16 13:19:00 -0700 | [diff] [blame] | 2445 | P2PTest(true, // initial_allow_p2p_for_downloading |
| 2446 | true, // initial_allow_p2p_for_sharing |
| 2447 | true, // omaha_disable_p2p_for_downloading |
| 2448 | false, // omaha_disable_p2p_for_sharing |
| 2449 | true, // payload_state_allow_p2p_attempt |
| 2450 | false, // expect_p2p_client_lookup |
| 2451 | "unset", // p2p_client_result_url |
| 2452 | false, // expected_allow_p2p_for_downloading |
| 2453 | true, // expected_allow_p2p_for_sharing |
| 2454 | ""); // expected_p2p_url |
David Zeuthen | 8f191b2 | 2013-08-06 12:27:50 -0700 | [diff] [blame] | 2455 | } |
| 2456 | |
Alex Deymo | e1e3afe | 2014-10-30 13:02:49 -0700 | [diff] [blame] | 2457 | TEST_F(OmahaRequestActionTest, P2PWithPeerSharingDisabledByOmaha) { |
Alex Vakulenko | d2779df | 2014-06-16 13:19:00 -0700 | [diff] [blame] | 2458 | P2PTest(true, // initial_allow_p2p_for_downloading |
| 2459 | true, // initial_allow_p2p_for_sharing |
| 2460 | false, // omaha_disable_p2p_for_downloading |
| 2461 | true, // omaha_disable_p2p_for_sharing |
| 2462 | true, // payload_state_allow_p2p_attempt |
| 2463 | true, // expect_p2p_client_lookup |
| 2464 | "http://1.3.5.7/p2p", // p2p_client_result_url |
| 2465 | true, // expected_allow_p2p_for_downloading |
| 2466 | false, // expected_allow_p2p_for_sharing |
| 2467 | "http://1.3.5.7/p2p"); // expected_p2p_url |
David Zeuthen | 8f191b2 | 2013-08-06 12:27:50 -0700 | [diff] [blame] | 2468 | } |
| 2469 | |
Alex Deymo | e1e3afe | 2014-10-30 13:02:49 -0700 | [diff] [blame] | 2470 | TEST_F(OmahaRequestActionTest, P2PWithPeerBothDisabledByOmaha) { |
Alex Vakulenko | d2779df | 2014-06-16 13:19:00 -0700 | [diff] [blame] | 2471 | P2PTest(true, // initial_allow_p2p_for_downloading |
| 2472 | true, // initial_allow_p2p_for_sharing |
| 2473 | true, // omaha_disable_p2p_for_downloading |
| 2474 | true, // omaha_disable_p2p_for_sharing |
| 2475 | true, // payload_state_allow_p2p_attempt |
| 2476 | false, // expect_p2p_client_lookup |
| 2477 | "unset", // p2p_client_result_url |
| 2478 | false, // expected_allow_p2p_for_downloading |
| 2479 | false, // expected_allow_p2p_for_sharing |
| 2480 | ""); // expected_p2p_url |
David Zeuthen | 8f191b2 | 2013-08-06 12:27:50 -0700 | [diff] [blame] | 2481 | } |
| 2482 | |
Alex Deymo | f329b93 | 2014-10-30 01:37:48 -0700 | [diff] [blame] | 2483 | bool OmahaRequestActionTest::InstallDateParseHelper(const string &elapsed_days, |
| 2484 | OmahaResponse *response) { |
Alex Deymo | 8e18f93 | 2015-03-27 16:16:59 -0700 | [diff] [blame] | 2485 | fake_update_response_.elapsed_days = elapsed_days; |
Marton Hunyady | 2abda31 | 2018-04-24 18:21:49 +0200 | [diff] [blame^] | 2486 | return TestUpdateCheck(fake_update_response_.GetUpdateResponse(), |
| 2487 | -1, |
| 2488 | false, // ping_only |
| 2489 | ErrorCode::kSuccess, |
| 2490 | metrics::CheckResult::kUpdateAvailable, |
| 2491 | metrics::CheckReaction::kUpdating, |
| 2492 | metrics::DownloadErrorCode::kUnset, |
| 2493 | response, |
| 2494 | nullptr); |
David Zeuthen | 639aa36 | 2014-02-03 16:23:44 -0800 | [diff] [blame] | 2495 | } |
| 2496 | |
Alex Deymo | e1e3afe | 2014-10-30 13:02:49 -0700 | [diff] [blame] | 2497 | TEST_F(OmahaRequestActionTest, ParseInstallDateFromResponse) { |
David Zeuthen | 639aa36 | 2014-02-03 16:23:44 -0800 | [diff] [blame] | 2498 | OmahaResponse response; |
David Zeuthen | 639aa36 | 2014-02-03 16:23:44 -0800 | [diff] [blame] | 2499 | |
Kevin Cernekee | 2494e28 | 2016-03-29 18:03:53 -0700 | [diff] [blame] | 2500 | // Simulate a successful update check that happens during OOBE. The |
| 2501 | // deadline in the response is needed to force the update attempt to |
| 2502 | // occur; responses without a deadline seen during OOBE will normally |
| 2503 | // return ErrorCode::kNonCriticalUpdateInOOBE. |
| 2504 | fake_system_state_.fake_hardware()->UnsetIsOOBEComplete(); |
| 2505 | fake_update_response_.deadline = "20101020"; |
| 2506 | |
David Zeuthen | 639aa36 | 2014-02-03 16:23:44 -0800 | [diff] [blame] | 2507 | // Check that we parse elapsed_days in the Omaha Response correctly. |
| 2508 | // and that the kPrefsInstallDateDays value is written to. |
Alex Deymo | e1e3afe | 2014-10-30 13:02:49 -0700 | [diff] [blame] | 2509 | EXPECT_FALSE(fake_prefs_.Exists(kPrefsInstallDateDays)); |
| 2510 | EXPECT_TRUE(InstallDateParseHelper("42", &response)); |
David Zeuthen | 639aa36 | 2014-02-03 16:23:44 -0800 | [diff] [blame] | 2511 | EXPECT_TRUE(response.update_exists); |
| 2512 | EXPECT_EQ(42, response.install_date_days); |
Alex Deymo | e1e3afe | 2014-10-30 13:02:49 -0700 | [diff] [blame] | 2513 | EXPECT_TRUE(fake_prefs_.Exists(kPrefsInstallDateDays)); |
David Zeuthen | 639aa36 | 2014-02-03 16:23:44 -0800 | [diff] [blame] | 2514 | int64_t prefs_days; |
Alex Deymo | e1e3afe | 2014-10-30 13:02:49 -0700 | [diff] [blame] | 2515 | EXPECT_TRUE(fake_prefs_.GetInt64(kPrefsInstallDateDays, &prefs_days)); |
David Zeuthen | 639aa36 | 2014-02-03 16:23:44 -0800 | [diff] [blame] | 2516 | EXPECT_EQ(prefs_days, 42); |
| 2517 | |
| 2518 | // If there already is a value set, we shouldn't do anything. |
Alex Deymo | e1e3afe | 2014-10-30 13:02:49 -0700 | [diff] [blame] | 2519 | EXPECT_TRUE(InstallDateParseHelper("7", &response)); |
David Zeuthen | 639aa36 | 2014-02-03 16:23:44 -0800 | [diff] [blame] | 2520 | EXPECT_TRUE(response.update_exists); |
| 2521 | EXPECT_EQ(7, response.install_date_days); |
Alex Deymo | e1e3afe | 2014-10-30 13:02:49 -0700 | [diff] [blame] | 2522 | EXPECT_TRUE(fake_prefs_.GetInt64(kPrefsInstallDateDays, &prefs_days)); |
David Zeuthen | 639aa36 | 2014-02-03 16:23:44 -0800 | [diff] [blame] | 2523 | EXPECT_EQ(prefs_days, 42); |
| 2524 | |
| 2525 | // Note that elapsed_days is not necessarily divisible by 7 so check |
| 2526 | // that we round down correctly when populating kPrefsInstallDateDays. |
Alex Deymo | e1e3afe | 2014-10-30 13:02:49 -0700 | [diff] [blame] | 2527 | EXPECT_TRUE(fake_prefs_.Delete(kPrefsInstallDateDays)); |
| 2528 | EXPECT_TRUE(InstallDateParseHelper("23", &response)); |
David Zeuthen | 639aa36 | 2014-02-03 16:23:44 -0800 | [diff] [blame] | 2529 | EXPECT_TRUE(response.update_exists); |
| 2530 | EXPECT_EQ(23, response.install_date_days); |
Alex Deymo | e1e3afe | 2014-10-30 13:02:49 -0700 | [diff] [blame] | 2531 | EXPECT_TRUE(fake_prefs_.GetInt64(kPrefsInstallDateDays, &prefs_days)); |
David Zeuthen | 639aa36 | 2014-02-03 16:23:44 -0800 | [diff] [blame] | 2532 | EXPECT_EQ(prefs_days, 21); |
| 2533 | |
| 2534 | // Check that we correctly handle elapsed_days not being included in |
| 2535 | // the Omaha Response. |
Alex Deymo | e1e3afe | 2014-10-30 13:02:49 -0700 | [diff] [blame] | 2536 | EXPECT_TRUE(InstallDateParseHelper("", &response)); |
David Zeuthen | 639aa36 | 2014-02-03 16:23:44 -0800 | [diff] [blame] | 2537 | EXPECT_TRUE(response.update_exists); |
| 2538 | EXPECT_EQ(-1, response.install_date_days); |
David Zeuthen | 639aa36 | 2014-02-03 16:23:44 -0800 | [diff] [blame] | 2539 | } |
| 2540 | |
Alex Deymo | e1e3afe | 2014-10-30 13:02:49 -0700 | [diff] [blame] | 2541 | // If there is no prefs and OOBE is not complete, we should not |
| 2542 | // report anything to Omaha. |
| 2543 | TEST_F(OmahaRequestActionTest, GetInstallDateWhenNoPrefsNorOOBE) { |
Kevin Cernekee | 2494e28 | 2016-03-29 18:03:53 -0700 | [diff] [blame] | 2544 | fake_system_state_.fake_hardware()->UnsetIsOOBEComplete(); |
Alex Deymo | e1e3afe | 2014-10-30 13:02:49 -0700 | [diff] [blame] | 2545 | EXPECT_EQ(OmahaRequestAction::GetInstallDate(&fake_system_state_), -1); |
| 2546 | EXPECT_FALSE(fake_prefs_.Exists(kPrefsInstallDateDays)); |
| 2547 | } |
David Zeuthen | 639aa36 | 2014-02-03 16:23:44 -0800 | [diff] [blame] | 2548 | |
Alex Deymo | e1e3afe | 2014-10-30 13:02:49 -0700 | [diff] [blame] | 2549 | // If OOBE is complete and happened on a valid date (e.g. after Jan |
| 2550 | // 1 2007 0:00 PST), that date should be used and written to |
| 2551 | // prefs. However, first try with an invalid date and check we do |
| 2552 | // nothing. |
| 2553 | TEST_F(OmahaRequestActionTest, GetInstallDateWhenOOBECompletedWithInvalidDate) { |
| 2554 | Time oobe_date = Time::FromTimeT(42); // Dec 31, 1969 16:00:42 PST. |
| 2555 | fake_system_state_.fake_hardware()->SetIsOOBEComplete(oobe_date); |
| 2556 | EXPECT_EQ(OmahaRequestAction::GetInstallDate(&fake_system_state_), -1); |
| 2557 | EXPECT_FALSE(fake_prefs_.Exists(kPrefsInstallDateDays)); |
| 2558 | } |
David Zeuthen | 639aa36 | 2014-02-03 16:23:44 -0800 | [diff] [blame] | 2559 | |
Alex Deymo | e1e3afe | 2014-10-30 13:02:49 -0700 | [diff] [blame] | 2560 | // Then check with a valid date. The date Jan 20, 2007 0:00 PST |
| 2561 | // should yield an InstallDate of 14. |
| 2562 | TEST_F(OmahaRequestActionTest, GetInstallDateWhenOOBECompletedWithValidDate) { |
| 2563 | Time oobe_date = Time::FromTimeT(1169280000); // Jan 20, 2007 0:00 PST. |
| 2564 | fake_system_state_.fake_hardware()->SetIsOOBEComplete(oobe_date); |
| 2565 | EXPECT_EQ(OmahaRequestAction::GetInstallDate(&fake_system_state_), 14); |
| 2566 | EXPECT_TRUE(fake_prefs_.Exists(kPrefsInstallDateDays)); |
David Zeuthen | 639aa36 | 2014-02-03 16:23:44 -0800 | [diff] [blame] | 2567 | |
Alex Deymo | e1e3afe | 2014-10-30 13:02:49 -0700 | [diff] [blame] | 2568 | int64_t prefs_days; |
| 2569 | EXPECT_TRUE(fake_prefs_.GetInt64(kPrefsInstallDateDays, &prefs_days)); |
| 2570 | EXPECT_EQ(prefs_days, 14); |
| 2571 | } |
David Zeuthen | 639aa36 | 2014-02-03 16:23:44 -0800 | [diff] [blame] | 2572 | |
Alex Deymo | e1e3afe | 2014-10-30 13:02:49 -0700 | [diff] [blame] | 2573 | // Now that we have a valid date in prefs, check that we keep using |
| 2574 | // that even if OOBE date reports something else. The date Jan 30, |
| 2575 | // 2007 0:00 PST should yield an InstallDate of 28... but since |
| 2576 | // there's a prefs file, we should still get 14. |
| 2577 | TEST_F(OmahaRequestActionTest, GetInstallDateWhenOOBECompletedDateChanges) { |
| 2578 | // Set a valid date in the prefs first. |
| 2579 | EXPECT_TRUE(fake_prefs_.SetInt64(kPrefsInstallDateDays, 14)); |
David Zeuthen | 639aa36 | 2014-02-03 16:23:44 -0800 | [diff] [blame] | 2580 | |
Alex Deymo | e1e3afe | 2014-10-30 13:02:49 -0700 | [diff] [blame] | 2581 | Time oobe_date = Time::FromTimeT(1170144000); // Jan 30, 2007 0:00 PST. |
| 2582 | fake_system_state_.fake_hardware()->SetIsOOBEComplete(oobe_date); |
| 2583 | EXPECT_EQ(OmahaRequestAction::GetInstallDate(&fake_system_state_), 14); |
David Zeuthen | 639aa36 | 2014-02-03 16:23:44 -0800 | [diff] [blame] | 2584 | |
Alex Deymo | e1e3afe | 2014-10-30 13:02:49 -0700 | [diff] [blame] | 2585 | int64_t prefs_days; |
| 2586 | EXPECT_TRUE(fake_prefs_.GetInt64(kPrefsInstallDateDays, &prefs_days)); |
| 2587 | EXPECT_EQ(prefs_days, 14); |
David Zeuthen | 639aa36 | 2014-02-03 16:23:44 -0800 | [diff] [blame] | 2588 | |
Alex Deymo | e1e3afe | 2014-10-30 13:02:49 -0700 | [diff] [blame] | 2589 | // If we delete the prefs file, we should get 28 days. |
| 2590 | EXPECT_TRUE(fake_prefs_.Delete(kPrefsInstallDateDays)); |
| 2591 | EXPECT_EQ(OmahaRequestAction::GetInstallDate(&fake_system_state_), 28); |
| 2592 | EXPECT_TRUE(fake_prefs_.GetInt64(kPrefsInstallDateDays, &prefs_days)); |
| 2593 | EXPECT_EQ(prefs_days, 28); |
David Zeuthen | 639aa36 | 2014-02-03 16:23:44 -0800 | [diff] [blame] | 2594 | } |
| 2595 | |
Darin Petkov | 6a5b322 | 2010-07-13 14:55:28 -0700 | [diff] [blame] | 2596 | } // namespace chromeos_update_engine |