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