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