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