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