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