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