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