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