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