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