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