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 | |
| 5 | #include <string> |
| 6 | #include <vector> |
Darin Petkov | 0dc8e9a | 2010-07-14 14:51:57 -0700 | [diff] [blame] | 7 | |
Darin Petkov | 6a5b322 | 2010-07-13 14:55:28 -0700 | [diff] [blame] | 8 | #include <glib.h> |
Darin Petkov | 0dc8e9a | 2010-07-14 14:51:57 -0700 | [diff] [blame] | 9 | |
Alex Vakulenko | 75039d7 | 2014-03-25 12:36:28 -0700 | [diff] [blame] | 10 | #include <base/strings/string_util.h> |
| 11 | #include <base/strings/stringprintf.h> |
| 12 | #include <base/time/time.h> |
Chris Sosa | 77f79e8 | 2014-06-02 18:16:24 -0700 | [diff] [blame] | 13 | #include <chromeos/dbus/service_constants.h> |
Darin Petkov | 0dc8e9a | 2010-07-14 14:51:57 -0700 | [diff] [blame] | 14 | #include "gtest/gtest.h" |
Jay Srinivasan | d29695d | 2013-04-08 15:08:05 -0700 | [diff] [blame] | 15 | |
Darin Petkov | 6a5b322 | 2010-07-13 14:55:28 -0700 | [diff] [blame] | 16 | #include "update_engine/action_pipe.h" |
Jay Srinivasan | d29695d | 2013-04-08 15:08:05 -0700 | [diff] [blame] | 17 | #include "update_engine/constants.h" |
Chris Sosa | 77f79e8 | 2014-06-02 18:16:24 -0700 | [diff] [blame] | 18 | #include "update_engine/mock_connection_manager.h" |
Darin Petkov | 6a5b322 | 2010-07-13 14:55:28 -0700 | [diff] [blame] | 19 | #include "update_engine/mock_http_fetcher.h" |
| 20 | #include "update_engine/omaha_hash_calculator.h" |
| 21 | #include "update_engine/omaha_request_action.h" |
Darin Petkov | a4a8a8c | 2010-07-15 22:21:12 -0700 | [diff] [blame] | 22 | #include "update_engine/omaha_request_params.h" |
Jay Srinivasan | 480ddfa | 2012-06-01 19:15:26 -0700 | [diff] [blame] | 23 | #include "update_engine/prefs.h" |
Darin Petkov | 6a5b322 | 2010-07-13 14:55:28 -0700 | [diff] [blame] | 24 | #include "update_engine/test_utils.h" |
Jay Srinivasan | 480ddfa | 2012-06-01 19:15:26 -0700 | [diff] [blame] | 25 | #include "update_engine/utils.h" |
Darin Petkov | 6a5b322 | 2010-07-13 14:55:28 -0700 | [diff] [blame] | 26 | |
Darin Petkov | 1cbd78f | 2010-07-29 12:38:34 -0700 | [diff] [blame] | 27 | using base::Time; |
| 28 | using base::TimeDelta; |
Darin Petkov | 6a5b322 | 2010-07-13 14:55:28 -0700 | [diff] [blame] | 29 | using std::string; |
| 30 | using std::vector; |
Darin Petkov | 1cbd78f | 2010-07-29 12:38:34 -0700 | [diff] [blame] | 31 | using testing::_; |
| 32 | using testing::AllOf; |
Jay Srinivasan | 34b5d86 | 2012-07-23 11:43:22 -0700 | [diff] [blame] | 33 | using testing::DoAll; |
Darin Petkov | 1cbd78f | 2010-07-29 12:38:34 -0700 | [diff] [blame] | 34 | using testing::Ge; |
| 35 | using testing::Le; |
Darin Petkov | 9c096d6 | 2010-11-17 14:49:04 -0800 | [diff] [blame] | 36 | using testing::NiceMock; |
Darin Petkov | 1cbd78f | 2010-07-29 12:38:34 -0700 | [diff] [blame] | 37 | using testing::Return; |
| 38 | using testing::SetArgumentPointee; |
David Zeuthen | 33bae49 | 2014-02-25 16:16:18 -0800 | [diff] [blame] | 39 | using testing::AnyNumber; |
Darin Petkov | 6a5b322 | 2010-07-13 14:55:28 -0700 | [diff] [blame] | 40 | |
| 41 | namespace chromeos_update_engine { |
| 42 | |
Jay Srinivasan | ae4697c | 2013-03-18 17:08:08 -0700 | [diff] [blame] | 43 | class OmahaRequestActionTest : public ::testing::Test {}; |
Darin Petkov | 6a5b322 | 2010-07-13 14:55:28 -0700 | [diff] [blame] | 44 | |
| 45 | namespace { |
Jay Srinivasan | 480ddfa | 2012-06-01 19:15:26 -0700 | [diff] [blame] | 46 | |
Gilad Arnold | 5bb4c90 | 2014-04-10 12:32:13 -0700 | [diff] [blame] | 47 | FakeSystemState fake_system_state; |
Jay Srinivasan | 480ddfa | 2012-06-01 19:15:26 -0700 | [diff] [blame] | 48 | OmahaRequestParams kDefaultTestParams( |
Gilad Arnold | 5bb4c90 | 2014-04-10 12:32:13 -0700 | [diff] [blame] | 49 | &fake_system_state, |
Darin Petkov | 1cbd78f | 2010-07-29 12:38:34 -0700 | [diff] [blame] | 50 | OmahaRequestParams::kOsPlatform, |
| 51 | OmahaRequestParams::kOsVersion, |
| 52 | "service_pack", |
| 53 | "x86-generic", |
| 54 | OmahaRequestParams::kAppId, |
| 55 | "0.1.0.0", |
| 56 | "en-US", |
| 57 | "unittest", |
Darin Petkov | fbb4009 | 2010-07-29 17:05:50 -0700 | [diff] [blame] | 58 | "OEM MODEL 09235 7471", |
Chris Sosa | c197248 | 2013-04-30 22:31:10 -0700 | [diff] [blame] | 59 | "ChromeOSFirmware.1.0", |
| 60 | "0X0A1", |
Darin Petkov | 1cbd78f | 2010-07-29 12:38:34 -0700 | [diff] [blame] | 61 | false, // delta okay |
Gilad Arnold | bbdd490 | 2013-01-10 16:06:30 -0800 | [diff] [blame] | 62 | false, // interactive |
Jay Srinivasan | 0a70874 | 2012-03-20 11:26:12 -0700 | [diff] [blame] | 63 | "http://url", |
David Zeuthen | 8f191b2 | 2013-08-06 12:27:50 -0700 | [diff] [blame] | 64 | false, // update_disabled |
| 65 | "", // target_version_prefix |
| 66 | false, // use_p2p_for_downloading |
| 67 | false); // use_p2p_for_sharing |
Darin Petkov | 1cbd78f | 2010-07-29 12:38:34 -0700 | [diff] [blame] | 68 | |
Darin Petkov | 6a5b322 | 2010-07-13 14:55:28 -0700 | [diff] [blame] | 69 | string GetNoUpdateResponse(const string& app_id) { |
| 70 | return string( |
Jay Srinivasan | 23b92a5 | 2012-10-27 02:00:21 -0700 | [diff] [blame] | 71 | "<?xml version=\"1.0\" encoding=\"UTF-8\"?><response protocol=\"3.0\">" |
| 72 | "<daystart elapsed_seconds=\"100\"/>" |
| 73 | "<app appid=\"") + app_id + "\" status=\"ok\"><ping " |
| 74 | "status=\"ok\"/><updatecheck status=\"noupdate\"/></app></response>"; |
Darin Petkov | 6a5b322 | 2010-07-13 14:55:28 -0700 | [diff] [blame] | 75 | } |
| 76 | |
Jay Srinivasan | 480ddfa | 2012-06-01 19:15:26 -0700 | [diff] [blame] | 77 | string GetUpdateResponse2(const string& app_id, |
Chris Sosa | 3b74843 | 2013-06-20 16:42:59 -0700 | [diff] [blame] | 78 | const string& version, |
Jay Srinivasan | 480ddfa | 2012-06-01 19:15:26 -0700 | [diff] [blame] | 79 | const string& more_info_url, |
| 80 | const string& prompt, |
| 81 | const string& codebase, |
Jay Srinivasan | 23b92a5 | 2012-10-27 02:00:21 -0700 | [diff] [blame] | 82 | const string& filename, |
Jay Srinivasan | 480ddfa | 2012-06-01 19:15:26 -0700 | [diff] [blame] | 83 | const string& hash, |
| 84 | const string& needsadmin, |
| 85 | const string& size, |
| 86 | const string& deadline, |
David Zeuthen | 8f191b2 | 2013-08-06 12:27:50 -0700 | [diff] [blame] | 87 | const string& max_days_to_scatter, |
David Zeuthen | 639aa36 | 2014-02-03 16:23:44 -0800 | [diff] [blame] | 88 | const string& elapsed_days, |
David Zeuthen | 8f191b2 | 2013-08-06 12:27:50 -0700 | [diff] [blame] | 89 | bool disable_p2p_for_downloading, |
| 90 | bool disable_p2p_for_sharing) { |
Jay Srinivasan | 23b92a5 | 2012-10-27 02:00:21 -0700 | [diff] [blame] | 91 | string response = |
| 92 | "<?xml version=\"1.0\" encoding=\"UTF-8\"?><response " |
| 93 | "protocol=\"3.0\">" |
David Zeuthen | 639aa36 | 2014-02-03 16:23:44 -0800 | [diff] [blame] | 94 | "<daystart elapsed_seconds=\"100\"" + |
| 95 | (elapsed_days.empty() ? "" : (" elapsed_days=\"" + elapsed_days + "\"")) + |
| 96 | "/>" |
Jay Srinivasan | 23b92a5 | 2012-10-27 02:00:21 -0700 | [diff] [blame] | 97 | "<app appid=\"" + app_id + "\" status=\"ok\">" |
| 98 | "<ping status=\"ok\"/><updatecheck status=\"ok\">" |
| 99 | "<urls><url codebase=\"" + codebase + "\"/></urls>" |
Chris Sosa | 3b74843 | 2013-06-20 16:42:59 -0700 | [diff] [blame] | 100 | "<manifest version=\"" + version + "\">" |
Jay Srinivasan | 23b92a5 | 2012-10-27 02:00:21 -0700 | [diff] [blame] | 101 | "<packages><package hash=\"not-used\" name=\"" + filename + "\" " |
| 102 | "size=\"" + size + "\"/></packages>" |
| 103 | "<actions><action event=\"postinstall\" " |
Chris Sosa | 3b74843 | 2013-06-20 16:42:59 -0700 | [diff] [blame] | 104 | "ChromeOSVersion=\"" + version + "\" " |
Jay Srinivasan | 480ddfa | 2012-06-01 19:15:26 -0700 | [diff] [blame] | 105 | "MoreInfo=\"" + more_info_url + "\" Prompt=\"" + prompt + "\" " |
| 106 | "IsDelta=\"true\" " |
Jay Srinivasan | d671e97 | 2013-01-11 17:17:19 -0800 | [diff] [blame] | 107 | "IsDeltaPayload=\"true\" " |
Jay Srinivasan | 480ddfa | 2012-06-01 19:15:26 -0700 | [diff] [blame] | 108 | "MaxDaysToScatter=\"" + max_days_to_scatter + "\" " |
Jay Srinivasan | 480ddfa | 2012-06-01 19:15:26 -0700 | [diff] [blame] | 109 | "sha256=\"" + hash + "\" " |
Jay Srinivasan | 23b92a5 | 2012-10-27 02:00:21 -0700 | [diff] [blame] | 110 | "needsadmin=\"" + needsadmin + "\" " + |
Jay Srinivasan | 480ddfa | 2012-06-01 19:15:26 -0700 | [diff] [blame] | 111 | (deadline.empty() ? "" : ("deadline=\"" + deadline + "\" ")) + |
David Zeuthen | 8f191b2 | 2013-08-06 12:27:50 -0700 | [diff] [blame] | 112 | (disable_p2p_for_downloading ? |
| 113 | "DisableP2PForDownloading=\"true\" " : "") + |
| 114 | (disable_p2p_for_sharing ? "DisableP2PForSharing=\"true\" " : "") + |
Jay Srinivasan | 23b92a5 | 2012-10-27 02:00:21 -0700 | [diff] [blame] | 115 | "/></actions></manifest></updatecheck></app></response>"; |
| 116 | LOG(INFO) << "Response = " << response; |
| 117 | return response; |
Jay Srinivasan | 480ddfa | 2012-06-01 19:15:26 -0700 | [diff] [blame] | 118 | } |
| 119 | |
Darin Petkov | 6a5b322 | 2010-07-13 14:55:28 -0700 | [diff] [blame] | 120 | string GetUpdateResponse(const string& app_id, |
Chris Sosa | 3b74843 | 2013-06-20 16:42:59 -0700 | [diff] [blame] | 121 | const string& version, |
Darin Petkov | 6a5b322 | 2010-07-13 14:55:28 -0700 | [diff] [blame] | 122 | const string& more_info_url, |
| 123 | const string& prompt, |
| 124 | const string& codebase, |
Jay Srinivasan | 23b92a5 | 2012-10-27 02:00:21 -0700 | [diff] [blame] | 125 | const string& filename, |
Darin Petkov | 6a5b322 | 2010-07-13 14:55:28 -0700 | [diff] [blame] | 126 | const string& hash, |
| 127 | const string& needsadmin, |
Darin Petkov | 6c11864 | 2010-10-21 12:06:30 -0700 | [diff] [blame] | 128 | const string& size, |
| 129 | const string& deadline) { |
Jay Srinivasan | 480ddfa | 2012-06-01 19:15:26 -0700 | [diff] [blame] | 130 | return GetUpdateResponse2(app_id, |
Chris Sosa | 3b74843 | 2013-06-20 16:42:59 -0700 | [diff] [blame] | 131 | version, |
Jay Srinivasan | 480ddfa | 2012-06-01 19:15:26 -0700 | [diff] [blame] | 132 | more_info_url, |
| 133 | prompt, |
| 134 | codebase, |
Jay Srinivasan | 23b92a5 | 2012-10-27 02:00:21 -0700 | [diff] [blame] | 135 | filename, |
Jay Srinivasan | 480ddfa | 2012-06-01 19:15:26 -0700 | [diff] [blame] | 136 | hash, |
| 137 | needsadmin, |
| 138 | size, |
| 139 | deadline, |
David Zeuthen | 8f191b2 | 2013-08-06 12:27:50 -0700 | [diff] [blame] | 140 | "7", |
David Zeuthen | 639aa36 | 2014-02-03 16:23:44 -0800 | [diff] [blame] | 141 | "42", // elapsed_days |
David Zeuthen | 8f191b2 | 2013-08-06 12:27:50 -0700 | [diff] [blame] | 142 | false, // disable_p2p_for_downloading |
| 143 | false); // disable_p2p_for sharing |
Darin Petkov | 6a5b322 | 2010-07-13 14:55:28 -0700 | [diff] [blame] | 144 | } |
| 145 | |
| 146 | class OmahaRequestActionTestProcessorDelegate : public ActionProcessorDelegate { |
| 147 | public: |
| 148 | OmahaRequestActionTestProcessorDelegate() |
| 149 | : loop_(NULL), |
Gilad Arnold | d1c4d2d | 2014-06-05 14:07:53 -0700 | [diff] [blame^] | 150 | expected_code_(ErrorCode::kSuccess) {} |
Darin Petkov | 6a5b322 | 2010-07-13 14:55:28 -0700 | [diff] [blame] | 151 | virtual ~OmahaRequestActionTestProcessorDelegate() { |
| 152 | } |
Darin Petkov | c1a8b42 | 2010-07-19 11:34:49 -0700 | [diff] [blame] | 153 | virtual void ProcessingDone(const ActionProcessor* processor, |
David Zeuthen | a99981f | 2013-04-29 13:42:47 -0700 | [diff] [blame] | 154 | ErrorCode code) { |
Darin Petkov | 6a5b322 | 2010-07-13 14:55:28 -0700 | [diff] [blame] | 155 | ASSERT_TRUE(loop_); |
| 156 | g_main_loop_quit(loop_); |
| 157 | } |
| 158 | |
| 159 | virtual void ActionCompleted(ActionProcessor* processor, |
| 160 | AbstractAction* action, |
David Zeuthen | a99981f | 2013-04-29 13:42:47 -0700 | [diff] [blame] | 161 | ErrorCode code) { |
Darin Petkov | 6a5b322 | 2010-07-13 14:55:28 -0700 | [diff] [blame] | 162 | // make sure actions always succeed |
| 163 | if (action->Type() == OmahaRequestAction::StaticType()) |
Darin Petkov | c1a8b42 | 2010-07-19 11:34:49 -0700 | [diff] [blame] | 164 | EXPECT_EQ(expected_code_, code); |
Darin Petkov | 6a5b322 | 2010-07-13 14:55:28 -0700 | [diff] [blame] | 165 | else |
Gilad Arnold | d1c4d2d | 2014-06-05 14:07:53 -0700 | [diff] [blame^] | 166 | EXPECT_EQ(ErrorCode::kSuccess, code); |
Darin Petkov | 6a5b322 | 2010-07-13 14:55:28 -0700 | [diff] [blame] | 167 | } |
| 168 | GMainLoop *loop_; |
David Zeuthen | a99981f | 2013-04-29 13:42:47 -0700 | [diff] [blame] | 169 | ErrorCode expected_code_; |
Darin Petkov | 6a5b322 | 2010-07-13 14:55:28 -0700 | [diff] [blame] | 170 | }; |
| 171 | |
| 172 | gboolean StartProcessorInRunLoop(gpointer data) { |
| 173 | ActionProcessor *processor = reinterpret_cast<ActionProcessor*>(data); |
| 174 | processor->StartProcessing(); |
| 175 | return FALSE; |
| 176 | } |
Darin Petkov | 6a5b322 | 2010-07-13 14:55:28 -0700 | [diff] [blame] | 177 | } // namespace {} |
| 178 | |
| 179 | class OutputObjectCollectorAction; |
| 180 | |
| 181 | template<> |
| 182 | class ActionTraits<OutputObjectCollectorAction> { |
| 183 | public: |
| 184 | // Does not take an object for input |
| 185 | typedef OmahaResponse InputObjectType; |
| 186 | // On success, puts the output path on output |
| 187 | typedef NoneType OutputObjectType; |
| 188 | }; |
| 189 | |
| 190 | class OutputObjectCollectorAction : public Action<OutputObjectCollectorAction> { |
| 191 | public: |
| 192 | OutputObjectCollectorAction() : has_input_object_(false) {} |
| 193 | void PerformAction() { |
| 194 | // copy input object |
| 195 | has_input_object_ = HasInputObject(); |
| 196 | if (has_input_object_) |
| 197 | omaha_response_ = GetInputObject(); |
Gilad Arnold | d1c4d2d | 2014-06-05 14:07:53 -0700 | [diff] [blame^] | 198 | processor_->ActionComplete(this, ErrorCode::kSuccess); |
Darin Petkov | 6a5b322 | 2010-07-13 14:55:28 -0700 | [diff] [blame] | 199 | } |
| 200 | // Should never be called |
| 201 | void TerminateProcessing() { |
| 202 | CHECK(false); |
| 203 | } |
| 204 | // Debugging/logging |
| 205 | static std::string StaticType() { |
| 206 | return "OutputObjectCollectorAction"; |
| 207 | } |
| 208 | std::string Type() const { return StaticType(); } |
| 209 | bool has_input_object_; |
| 210 | OmahaResponse omaha_response_; |
| 211 | }; |
| 212 | |
Darin Petkov | 1cbd78f | 2010-07-29 12:38:34 -0700 | [diff] [blame] | 213 | // Returns true iff an output response was obtained from the |
Darin Petkov | edc522e | 2010-11-05 09:35:17 -0700 | [diff] [blame] | 214 | // OmahaRequestAction. |prefs| may be NULL, in which case a local PrefsMock is |
David Zeuthen | 8f191b2 | 2013-08-06 12:27:50 -0700 | [diff] [blame] | 215 | // used. |payload_state| may be NULL, in which case a local mock is used. |
| 216 | // |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] | 217 | // |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] | 218 | // 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] | 219 | // the transfer will fail with that code. |ping_only| is passed through to the |
| 220 | // OmahaRequestAction constructor. out_post_data may be null; if non-null, the |
| 221 | // post-data received by the mock HttpFetcher is returned. |
David Zeuthen | 33bae49 | 2014-02-25 16:16:18 -0800 | [diff] [blame] | 222 | // |
| 223 | // The |expected_check_result|, |expected_check_reaction| and |
| 224 | // |expected_error_code| parameters are for checking expectations |
| 225 | // about reporting UpdateEngine.Check.{Result,Reaction,DownloadError} |
| 226 | // UMA statistics. Use the appropriate ::kUnset value to specify that |
| 227 | // the given metric should not be reported. |
Darin Petkov | 1cbd78f | 2010-07-29 12:38:34 -0700 | [diff] [blame] | 228 | bool TestUpdateCheck(PrefsInterface* prefs, |
David Zeuthen | 8f191b2 | 2013-08-06 12:27:50 -0700 | [diff] [blame] | 229 | PayloadStateInterface *payload_state, |
| 230 | P2PManager *p2p_manager, |
Chris Sosa | 77f79e8 | 2014-06-02 18:16:24 -0700 | [diff] [blame] | 231 | ConnectionManager *connection_manager, |
David Zeuthen | 8f191b2 | 2013-08-06 12:27:50 -0700 | [diff] [blame] | 232 | OmahaRequestParams& params, |
Darin Petkov | 0dc8e9a | 2010-07-14 14:51:57 -0700 | [diff] [blame] | 233 | const string& http_response, |
Darin Petkov | edc522e | 2010-11-05 09:35:17 -0700 | [diff] [blame] | 234 | int fail_http_response_code, |
Darin Petkov | 265f290 | 2011-05-09 15:17:40 -0700 | [diff] [blame] | 235 | bool ping_only, |
David Zeuthen | a99981f | 2013-04-29 13:42:47 -0700 | [diff] [blame] | 236 | ErrorCode expected_code, |
David Zeuthen | 33bae49 | 2014-02-25 16:16:18 -0800 | [diff] [blame] | 237 | metrics::CheckResult expected_check_result, |
| 238 | metrics::CheckReaction expected_check_reaction, |
| 239 | metrics::DownloadErrorCode expected_download_error_code, |
Darin Petkov | 0dc8e9a | 2010-07-14 14:51:57 -0700 | [diff] [blame] | 240 | OmahaResponse* out_response, |
| 241 | vector<char>* out_post_data) { |
| 242 | GMainLoop* loop = g_main_loop_new(g_main_context_default(), FALSE); |
| 243 | MockHttpFetcher* fetcher = new MockHttpFetcher(http_response.data(), |
Andrew de los Reyes | 4516810 | 2010-11-22 11:13:50 -0800 | [diff] [blame] | 244 | http_response.size(), |
| 245 | NULL); |
Darin Petkov | edc522e | 2010-11-05 09:35:17 -0700 | [diff] [blame] | 246 | if (fail_http_response_code >= 0) { |
| 247 | fetcher->FailTransfer(fail_http_response_code); |
| 248 | } |
Gilad Arnold | 5bb4c90 | 2014-04-10 12:32:13 -0700 | [diff] [blame] | 249 | FakeSystemState fake_system_state; |
Jay Srinivasan | 6f6ea00 | 2012-12-14 11:26:28 -0800 | [diff] [blame] | 250 | if (prefs) |
Gilad Arnold | 5bb4c90 | 2014-04-10 12:32:13 -0700 | [diff] [blame] | 251 | fake_system_state.set_prefs(prefs); |
David Zeuthen | 8f191b2 | 2013-08-06 12:27:50 -0700 | [diff] [blame] | 252 | if (payload_state) |
Gilad Arnold | 5bb4c90 | 2014-04-10 12:32:13 -0700 | [diff] [blame] | 253 | fake_system_state.set_payload_state(payload_state); |
David Zeuthen | 8f191b2 | 2013-08-06 12:27:50 -0700 | [diff] [blame] | 254 | if (p2p_manager) |
Gilad Arnold | 5bb4c90 | 2014-04-10 12:32:13 -0700 | [diff] [blame] | 255 | fake_system_state.set_p2p_manager(p2p_manager); |
Chris Sosa | 77f79e8 | 2014-06-02 18:16:24 -0700 | [diff] [blame] | 256 | if (connection_manager) |
| 257 | fake_system_state.set_connection_manager(connection_manager); |
Gilad Arnold | 5bb4c90 | 2014-04-10 12:32:13 -0700 | [diff] [blame] | 258 | fake_system_state.set_request_params(¶ms); |
| 259 | OmahaRequestAction action(&fake_system_state, |
Darin Petkov | 1cbd78f | 2010-07-29 12:38:34 -0700 | [diff] [blame] | 260 | NULL, |
Thieu Le | 116fda3 | 2011-04-19 11:01:54 -0700 | [diff] [blame] | 261 | fetcher, |
Darin Petkov | 265f290 | 2011-05-09 15:17:40 -0700 | [diff] [blame] | 262 | ping_only); |
Darin Petkov | 6a5b322 | 2010-07-13 14:55:28 -0700 | [diff] [blame] | 263 | OmahaRequestActionTestProcessorDelegate delegate; |
| 264 | delegate.loop_ = loop; |
Darin Petkov | c1a8b42 | 2010-07-19 11:34:49 -0700 | [diff] [blame] | 265 | delegate.expected_code_ = expected_code; |
Darin Petkov | a4a8a8c | 2010-07-15 22:21:12 -0700 | [diff] [blame] | 266 | |
Darin Petkov | 6a5b322 | 2010-07-13 14:55:28 -0700 | [diff] [blame] | 267 | ActionProcessor processor; |
Darin Petkov | 6a5b322 | 2010-07-13 14:55:28 -0700 | [diff] [blame] | 268 | processor.set_delegate(&delegate); |
Darin Petkov | 6a5b322 | 2010-07-13 14:55:28 -0700 | [diff] [blame] | 269 | processor.EnqueueAction(&action); |
| 270 | |
| 271 | OutputObjectCollectorAction collector_action; |
Darin Petkov | 6a5b322 | 2010-07-13 14:55:28 -0700 | [diff] [blame] | 272 | BondActions(&action, &collector_action); |
| 273 | processor.EnqueueAction(&collector_action); |
| 274 | |
Gilad Arnold | 5bb4c90 | 2014-04-10 12:32:13 -0700 | [diff] [blame] | 275 | EXPECT_CALL(*fake_system_state.mock_metrics_lib(), SendEnumToUMA(_, _, _)) |
David Zeuthen | 33bae49 | 2014-02-25 16:16:18 -0800 | [diff] [blame] | 276 | .Times(AnyNumber()); |
Gilad Arnold | 5bb4c90 | 2014-04-10 12:32:13 -0700 | [diff] [blame] | 277 | EXPECT_CALL(*fake_system_state.mock_metrics_lib(), |
David Zeuthen | 33bae49 | 2014-02-25 16:16:18 -0800 | [diff] [blame] | 278 | SendEnumToUMA(metrics::kMetricCheckResult, |
| 279 | static_cast<int>(expected_check_result), |
| 280 | static_cast<int>(metrics::CheckResult::kNumConstants) - 1)) |
| 281 | .Times(expected_check_result == metrics::CheckResult::kUnset ? 0 : 1); |
Gilad Arnold | 5bb4c90 | 2014-04-10 12:32:13 -0700 | [diff] [blame] | 282 | EXPECT_CALL(*fake_system_state.mock_metrics_lib(), |
David Zeuthen | 33bae49 | 2014-02-25 16:16:18 -0800 | [diff] [blame] | 283 | SendEnumToUMA(metrics::kMetricCheckReaction, |
| 284 | static_cast<int>(expected_check_reaction), |
| 285 | static_cast<int>(metrics::CheckReaction::kNumConstants) - 1)) |
| 286 | .Times(expected_check_reaction == metrics::CheckReaction::kUnset ? 0 : 1); |
Gilad Arnold | 5bb4c90 | 2014-04-10 12:32:13 -0700 | [diff] [blame] | 287 | EXPECT_CALL(*fake_system_state.mock_metrics_lib(), |
David Zeuthen | c0dd021 | 2014-04-04 14:49:49 -0700 | [diff] [blame] | 288 | SendSparseToUMA(metrics::kMetricCheckDownloadErrorCode, |
| 289 | static_cast<int>(expected_download_error_code))) |
David Zeuthen | 33bae49 | 2014-02-25 16:16:18 -0800 | [diff] [blame] | 290 | .Times(expected_download_error_code == metrics::DownloadErrorCode::kUnset |
| 291 | ? 0 : 1); |
| 292 | |
Darin Petkov | 6a5b322 | 2010-07-13 14:55:28 -0700 | [diff] [blame] | 293 | g_timeout_add(0, &StartProcessorInRunLoop, &processor); |
| 294 | g_main_loop_run(loop); |
| 295 | g_main_loop_unref(loop); |
| 296 | if (collector_action.has_input_object_ && out_response) |
| 297 | *out_response = collector_action.omaha_response_; |
| 298 | if (out_post_data) |
| 299 | *out_post_data = fetcher->post_data(); |
| 300 | return collector_action.has_input_object_; |
| 301 | } |
| 302 | |
Darin Petkov | 0dc8e9a | 2010-07-14 14:51:57 -0700 | [diff] [blame] | 303 | // Tests Event requests -- they should always succeed. |out_post_data| |
| 304 | // may be null; if non-null, the post-data received by the mock |
| 305 | // HttpFetcher is returned. |
Jay Srinivasan | 480ddfa | 2012-06-01 19:15:26 -0700 | [diff] [blame] | 306 | void TestEvent(OmahaRequestParams params, |
Darin Petkov | 0dc8e9a | 2010-07-14 14:51:57 -0700 | [diff] [blame] | 307 | OmahaEvent* event, |
| 308 | const string& http_response, |
| 309 | vector<char>* out_post_data) { |
| 310 | GMainLoop* loop = g_main_loop_new(g_main_context_default(), FALSE); |
| 311 | MockHttpFetcher* fetcher = new MockHttpFetcher(http_response.data(), |
Andrew de los Reyes | 4516810 | 2010-11-22 11:13:50 -0800 | [diff] [blame] | 312 | http_response.size(), |
| 313 | NULL); |
Gilad Arnold | 5bb4c90 | 2014-04-10 12:32:13 -0700 | [diff] [blame] | 314 | FakeSystemState fake_system_state; |
| 315 | fake_system_state.set_request_params(¶ms); |
| 316 | OmahaRequestAction action(&fake_system_state, event, fetcher, false); |
Darin Petkov | 0dc8e9a | 2010-07-14 14:51:57 -0700 | [diff] [blame] | 317 | OmahaRequestActionTestProcessorDelegate delegate; |
| 318 | delegate.loop_ = loop; |
| 319 | ActionProcessor processor; |
Darin Petkov | 0dc8e9a | 2010-07-14 14:51:57 -0700 | [diff] [blame] | 320 | processor.set_delegate(&delegate); |
Darin Petkov | 0dc8e9a | 2010-07-14 14:51:57 -0700 | [diff] [blame] | 321 | processor.EnqueueAction(&action); |
| 322 | |
Darin Petkov | 0dc8e9a | 2010-07-14 14:51:57 -0700 | [diff] [blame] | 323 | g_timeout_add(0, &StartProcessorInRunLoop, &processor); |
| 324 | g_main_loop_run(loop); |
| 325 | g_main_loop_unref(loop); |
| 326 | if (out_post_data) |
| 327 | *out_post_data = fetcher->post_data(); |
| 328 | } |
| 329 | |
Darin Petkov | 6a5b322 | 2010-07-13 14:55:28 -0700 | [diff] [blame] | 330 | TEST(OmahaRequestActionTest, NoUpdateTest) { |
Darin Petkov | 6a5b322 | 2010-07-13 14:55:28 -0700 | [diff] [blame] | 331 | OmahaResponse response; |
| 332 | ASSERT_TRUE( |
Darin Petkov | 1cbd78f | 2010-07-29 12:38:34 -0700 | [diff] [blame] | 333 | TestUpdateCheck(NULL, // prefs |
David Zeuthen | 8f191b2 | 2013-08-06 12:27:50 -0700 | [diff] [blame] | 334 | NULL, // payload_state |
| 335 | NULL, // p2p_manager |
Chris Sosa | 77f79e8 | 2014-06-02 18:16:24 -0700 | [diff] [blame] | 336 | NULL, // connection_manager |
Darin Petkov | 1cbd78f | 2010-07-29 12:38:34 -0700 | [diff] [blame] | 337 | kDefaultTestParams, |
Darin Petkov | 0dc8e9a | 2010-07-14 14:51:57 -0700 | [diff] [blame] | 338 | GetNoUpdateResponse(OmahaRequestParams::kAppId), |
Darin Petkov | edc522e | 2010-11-05 09:35:17 -0700 | [diff] [blame] | 339 | -1, |
Darin Petkov | 265f290 | 2011-05-09 15:17:40 -0700 | [diff] [blame] | 340 | false, // ping_only |
Gilad Arnold | d1c4d2d | 2014-06-05 14:07:53 -0700 | [diff] [blame^] | 341 | ErrorCode::kSuccess, |
David Zeuthen | 33bae49 | 2014-02-25 16:16:18 -0800 | [diff] [blame] | 342 | metrics::CheckResult::kNoUpdateAvailable, |
| 343 | metrics::CheckReaction::kUnset, |
| 344 | metrics::DownloadErrorCode::kUnset, |
Darin Petkov | 0dc8e9a | 2010-07-14 14:51:57 -0700 | [diff] [blame] | 345 | &response, |
| 346 | NULL)); |
Darin Petkov | 6a5b322 | 2010-07-13 14:55:28 -0700 | [diff] [blame] | 347 | EXPECT_FALSE(response.update_exists); |
| 348 | } |
| 349 | |
| 350 | TEST(OmahaRequestActionTest, ValidUpdateTest) { |
Darin Petkov | 6a5b322 | 2010-07-13 14:55:28 -0700 | [diff] [blame] | 351 | OmahaResponse response; |
| 352 | ASSERT_TRUE( |
Darin Petkov | 1cbd78f | 2010-07-29 12:38:34 -0700 | [diff] [blame] | 353 | TestUpdateCheck(NULL, // prefs |
David Zeuthen | 8f191b2 | 2013-08-06 12:27:50 -0700 | [diff] [blame] | 354 | NULL, // payload_state |
| 355 | NULL, // p2p_manager |
Chris Sosa | 77f79e8 | 2014-06-02 18:16:24 -0700 | [diff] [blame] | 356 | NULL, // connection_manager |
Darin Petkov | 1cbd78f | 2010-07-29 12:38:34 -0700 | [diff] [blame] | 357 | kDefaultTestParams, |
Darin Petkov | 0dc8e9a | 2010-07-14 14:51:57 -0700 | [diff] [blame] | 358 | GetUpdateResponse(OmahaRequestParams::kAppId, |
| 359 | "1.2.3.4", // version |
| 360 | "http://more/info", |
| 361 | "true", // prompt |
Jay Srinivasan | 23b92a5 | 2012-10-27 02:00:21 -0700 | [diff] [blame] | 362 | "http://code/base/", // dl url |
| 363 | "file.signed", // file name |
Darin Petkov | 0dc8e9a | 2010-07-14 14:51:57 -0700 | [diff] [blame] | 364 | "HASH1234=", // checksum |
| 365 | "false", // needs admin |
Darin Petkov | 6c11864 | 2010-10-21 12:06:30 -0700 | [diff] [blame] | 366 | "123", // size |
| 367 | "20101020"), // deadline |
Darin Petkov | edc522e | 2010-11-05 09:35:17 -0700 | [diff] [blame] | 368 | -1, |
Darin Petkov | 265f290 | 2011-05-09 15:17:40 -0700 | [diff] [blame] | 369 | false, // ping_only |
Gilad Arnold | d1c4d2d | 2014-06-05 14:07:53 -0700 | [diff] [blame^] | 370 | ErrorCode::kSuccess, |
David Zeuthen | 33bae49 | 2014-02-25 16:16:18 -0800 | [diff] [blame] | 371 | metrics::CheckResult::kUpdateAvailable, |
| 372 | metrics::CheckReaction::kUpdating, |
| 373 | metrics::DownloadErrorCode::kUnset, |
Darin Petkov | 0dc8e9a | 2010-07-14 14:51:57 -0700 | [diff] [blame] | 374 | &response, |
| 375 | NULL)); |
Darin Petkov | 6a5b322 | 2010-07-13 14:55:28 -0700 | [diff] [blame] | 376 | EXPECT_TRUE(response.update_exists); |
Jay Srinivasan | 34b5d86 | 2012-07-23 11:43:22 -0700 | [diff] [blame] | 377 | EXPECT_TRUE(response.update_exists); |
Chris Sosa | 3b74843 | 2013-06-20 16:42:59 -0700 | [diff] [blame] | 378 | EXPECT_EQ("1.2.3.4", response.version); |
Jay Srinivasan | 6f6ea00 | 2012-12-14 11:26:28 -0800 | [diff] [blame] | 379 | EXPECT_EQ("http://code/base/file.signed", response.payload_urls[0]); |
Darin Petkov | 6a5b322 | 2010-07-13 14:55:28 -0700 | [diff] [blame] | 380 | EXPECT_EQ("http://more/info", response.more_info_url); |
| 381 | EXPECT_EQ("HASH1234=", response.hash); |
| 382 | EXPECT_EQ(123, response.size); |
Darin Petkov | 6a5b322 | 2010-07-13 14:55:28 -0700 | [diff] [blame] | 383 | EXPECT_TRUE(response.prompt); |
Darin Petkov | 6c11864 | 2010-10-21 12:06:30 -0700 | [diff] [blame] | 384 | EXPECT_EQ("20101020", response.deadline); |
Darin Petkov | 6a5b322 | 2010-07-13 14:55:28 -0700 | [diff] [blame] | 385 | } |
| 386 | |
Jay Srinivasan | 0a70874 | 2012-03-20 11:26:12 -0700 | [diff] [blame] | 387 | TEST(OmahaRequestActionTest, ValidUpdateBlockedByPolicyTest) { |
| 388 | OmahaResponse response; |
| 389 | OmahaRequestParams params = kDefaultTestParams; |
Jay Srinivasan | ae4697c | 2013-03-18 17:08:08 -0700 | [diff] [blame] | 390 | params.set_update_disabled(true); |
Jay Srinivasan | 0a70874 | 2012-03-20 11:26:12 -0700 | [diff] [blame] | 391 | ASSERT_FALSE( |
| 392 | TestUpdateCheck(NULL, // prefs |
David Zeuthen | 8f191b2 | 2013-08-06 12:27:50 -0700 | [diff] [blame] | 393 | NULL, // payload_state |
| 394 | NULL, // p2p_manager |
Chris Sosa | 77f79e8 | 2014-06-02 18:16:24 -0700 | [diff] [blame] | 395 | NULL, // connection_manager |
Jay Srinivasan | 0a70874 | 2012-03-20 11:26:12 -0700 | [diff] [blame] | 396 | params, |
| 397 | GetUpdateResponse(OmahaRequestParams::kAppId, |
| 398 | "1.2.3.4", // version |
| 399 | "http://more/info", |
| 400 | "true", // prompt |
Jay Srinivasan | 23b92a5 | 2012-10-27 02:00:21 -0700 | [diff] [blame] | 401 | "http://code/base/", // dl url |
| 402 | "file.signed", // file name |
Jay Srinivasan | 0a70874 | 2012-03-20 11:26:12 -0700 | [diff] [blame] | 403 | "HASH1234=", // checksum |
| 404 | "false", // needs admin |
| 405 | "123", // size |
Jay Srinivasan | 480ddfa | 2012-06-01 19:15:26 -0700 | [diff] [blame] | 406 | ""), // deadline |
Jay Srinivasan | 0a70874 | 2012-03-20 11:26:12 -0700 | [diff] [blame] | 407 | -1, |
| 408 | false, // ping_only |
Gilad Arnold | d1c4d2d | 2014-06-05 14:07:53 -0700 | [diff] [blame^] | 409 | ErrorCode::kOmahaUpdateIgnoredPerPolicy, |
David Zeuthen | 33bae49 | 2014-02-25 16:16:18 -0800 | [diff] [blame] | 410 | metrics::CheckResult::kUpdateAvailable, |
| 411 | metrics::CheckReaction::kIgnored, |
| 412 | metrics::DownloadErrorCode::kUnset, |
Jay Srinivasan | 0a70874 | 2012-03-20 11:26:12 -0700 | [diff] [blame] | 413 | &response, |
| 414 | NULL)); |
| 415 | EXPECT_FALSE(response.update_exists); |
| 416 | } |
| 417 | |
Chris Sosa | 77f79e8 | 2014-06-02 18:16:24 -0700 | [diff] [blame] | 418 | TEST(OmahaRequestActionTest, ValidUpdateBlockedByConnection) { |
| 419 | OmahaResponse response; |
| 420 | // Set up a connection manager that doesn't allow a valid update over |
| 421 | // the current ethernet connection. |
| 422 | MockConnectionManager mock_cm(NULL); |
| 423 | EXPECT_CALL(mock_cm, GetConnectionProperties(_,_,_)) |
| 424 | .WillRepeatedly(DoAll(SetArgumentPointee<1>(kNetEthernet), |
| 425 | SetArgumentPointee<2>(NetworkTethering::kUnknown), |
| 426 | Return(true))); |
| 427 | EXPECT_CALL(mock_cm, IsUpdateAllowedOver(kNetEthernet, _)) |
| 428 | .WillRepeatedly(Return(false)); |
| 429 | EXPECT_CALL(mock_cm, StringForConnectionType(kNetEthernet)) |
| 430 | .WillRepeatedly(Return(shill::kTypeEthernet)); |
| 431 | |
| 432 | ASSERT_FALSE( |
| 433 | TestUpdateCheck(NULL, // prefs |
| 434 | NULL, // payload_state |
| 435 | NULL, // p2p_manager |
| 436 | &mock_cm, // connection_manager |
| 437 | kDefaultTestParams, |
| 438 | GetUpdateResponse(OmahaRequestParams::kAppId, |
| 439 | "1.2.3.4", // version |
| 440 | "http://more/info", |
| 441 | "true", // prompt |
| 442 | "http://code/base/", // dl url |
| 443 | "file.signed", // file name |
| 444 | "HASH1234=", // checksum |
| 445 | "false", // needs admin |
| 446 | "123", // size |
| 447 | ""), // deadline |
| 448 | -1, |
| 449 | false, // ping_only |
Gilad Arnold | d1c4d2d | 2014-06-05 14:07:53 -0700 | [diff] [blame^] | 450 | ErrorCode::kOmahaUpdateIgnoredPerPolicy, |
Chris Sosa | 77f79e8 | 2014-06-02 18:16:24 -0700 | [diff] [blame] | 451 | metrics::CheckResult::kUpdateAvailable, |
| 452 | metrics::CheckReaction::kIgnored, |
| 453 | metrics::DownloadErrorCode::kUnset, |
| 454 | &response, |
| 455 | NULL)); |
| 456 | EXPECT_FALSE(response.update_exists); |
| 457 | } |
| 458 | |
| 459 | TEST(OmahaRequestActionTest, ValidUpdateBlockedByRollback) { |
| 460 | string rollback_version = "1234.0.0"; |
| 461 | OmahaResponse response; |
| 462 | |
| 463 | MockPayloadState mock_payload_state; |
| 464 | EXPECT_CALL(mock_payload_state, GetRollbackVersion()) |
| 465 | .WillRepeatedly(Return(rollback_version)); |
| 466 | |
| 467 | ASSERT_FALSE( |
| 468 | TestUpdateCheck(NULL, // prefs |
| 469 | &mock_payload_state, // payload_state |
| 470 | NULL, // p2p_manager |
| 471 | NULL, // connection_manager |
| 472 | kDefaultTestParams, |
| 473 | GetUpdateResponse(OmahaRequestParams::kAppId, |
| 474 | rollback_version, // version |
| 475 | "http://more/info", |
| 476 | "true", // prompt |
| 477 | "http://code/base/", // dl url |
| 478 | "file.signed", // file name |
| 479 | "HASH1234=", // checksum |
| 480 | "false", // needs admin |
| 481 | "123", // size |
| 482 | ""), // deadline |
| 483 | -1, |
| 484 | false, // ping_only |
Gilad Arnold | d1c4d2d | 2014-06-05 14:07:53 -0700 | [diff] [blame^] | 485 | ErrorCode::kOmahaUpdateIgnoredPerPolicy, |
Chris Sosa | 77f79e8 | 2014-06-02 18:16:24 -0700 | [diff] [blame] | 486 | metrics::CheckResult::kUpdateAvailable, |
| 487 | metrics::CheckReaction::kIgnored, |
| 488 | metrics::DownloadErrorCode::kUnset, |
| 489 | &response, |
| 490 | NULL)); |
| 491 | EXPECT_FALSE(response.update_exists); |
| 492 | } |
| 493 | |
Jay Srinivasan | 0a70874 | 2012-03-20 11:26:12 -0700 | [diff] [blame] | 494 | TEST(OmahaRequestActionTest, NoUpdatesSentWhenBlockedByPolicyTest) { |
| 495 | OmahaResponse response; |
| 496 | OmahaRequestParams params = kDefaultTestParams; |
Jay Srinivasan | ae4697c | 2013-03-18 17:08:08 -0700 | [diff] [blame] | 497 | params.set_update_disabled(true); |
Jay Srinivasan | 0a70874 | 2012-03-20 11:26:12 -0700 | [diff] [blame] | 498 | ASSERT_TRUE( |
| 499 | TestUpdateCheck(NULL, // prefs |
David Zeuthen | 8f191b2 | 2013-08-06 12:27:50 -0700 | [diff] [blame] | 500 | NULL, // payload_state |
| 501 | NULL, // p2p_manager |
Chris Sosa | 77f79e8 | 2014-06-02 18:16:24 -0700 | [diff] [blame] | 502 | NULL, // connection_manager |
Jay Srinivasan | 0a70874 | 2012-03-20 11:26:12 -0700 | [diff] [blame] | 503 | params, |
| 504 | GetNoUpdateResponse(OmahaRequestParams::kAppId), |
| 505 | -1, |
| 506 | false, // ping_only |
Gilad Arnold | d1c4d2d | 2014-06-05 14:07:53 -0700 | [diff] [blame^] | 507 | ErrorCode::kSuccess, |
David Zeuthen | 33bae49 | 2014-02-25 16:16:18 -0800 | [diff] [blame] | 508 | metrics::CheckResult::kNoUpdateAvailable, |
| 509 | metrics::CheckReaction::kUnset, |
| 510 | metrics::DownloadErrorCode::kUnset, |
Jay Srinivasan | 0a70874 | 2012-03-20 11:26:12 -0700 | [diff] [blame] | 511 | &response, |
| 512 | NULL)); |
| 513 | EXPECT_FALSE(response.update_exists); |
| 514 | } |
| 515 | |
Jay Srinivasan | 480ddfa | 2012-06-01 19:15:26 -0700 | [diff] [blame] | 516 | TEST(OmahaRequestActionTest, WallClockBasedWaitAloneCausesScattering) { |
| 517 | OmahaResponse response; |
| 518 | OmahaRequestParams params = kDefaultTestParams; |
Jay Srinivasan | ae4697c | 2013-03-18 17:08:08 -0700 | [diff] [blame] | 519 | params.set_wall_clock_based_wait_enabled(true); |
| 520 | params.set_update_check_count_wait_enabled(false); |
| 521 | params.set_waiting_period(TimeDelta::FromDays(2)); |
Jay Srinivasan | 480ddfa | 2012-06-01 19:15:26 -0700 | [diff] [blame] | 522 | |
| 523 | string prefs_dir; |
Gilad Arnold | a6742b3 | 2014-01-11 00:18:34 -0800 | [diff] [blame] | 524 | EXPECT_TRUE(utils::MakeTempDirectory("ue_ut_prefs.XXXXXX", |
Jay Srinivasan | 480ddfa | 2012-06-01 19:15:26 -0700 | [diff] [blame] | 525 | &prefs_dir)); |
| 526 | ScopedDirRemover temp_dir_remover(prefs_dir); |
| 527 | |
| 528 | Prefs prefs; |
Alex Vakulenko | 75039d7 | 2014-03-25 12:36:28 -0700 | [diff] [blame] | 529 | LOG_IF(ERROR, !prefs.Init(base::FilePath(prefs_dir))) |
Jay Srinivasan | 480ddfa | 2012-06-01 19:15:26 -0700 | [diff] [blame] | 530 | << "Failed to initialize preferences."; |
| 531 | |
| 532 | ASSERT_FALSE( |
| 533 | TestUpdateCheck(&prefs, // prefs |
David Zeuthen | 8f191b2 | 2013-08-06 12:27:50 -0700 | [diff] [blame] | 534 | NULL, // payload_state |
| 535 | NULL, // p2p_manager |
Chris Sosa | 77f79e8 | 2014-06-02 18:16:24 -0700 | [diff] [blame] | 536 | NULL, // connection_manager |
Jay Srinivasan | 480ddfa | 2012-06-01 19:15:26 -0700 | [diff] [blame] | 537 | params, |
| 538 | GetUpdateResponse2(OmahaRequestParams::kAppId, |
| 539 | "1.2.3.4", // version |
| 540 | "http://more/info", |
| 541 | "true", // prompt |
Jay Srinivasan | 23b92a5 | 2012-10-27 02:00:21 -0700 | [diff] [blame] | 542 | "http://code/base/", // dl url |
| 543 | "file.signed", // file name |
Jay Srinivasan | 480ddfa | 2012-06-01 19:15:26 -0700 | [diff] [blame] | 544 | "HASH1234=", // checksum |
| 545 | "false", // needs admin |
| 546 | "123", // size |
| 547 | "", // deadline |
David Zeuthen | 8f191b2 | 2013-08-06 12:27:50 -0700 | [diff] [blame] | 548 | "7", // max days to scatter |
David Zeuthen | 639aa36 | 2014-02-03 16:23:44 -0800 | [diff] [blame] | 549 | "42", // elapsed_days |
David Zeuthen | 8f191b2 | 2013-08-06 12:27:50 -0700 | [diff] [blame] | 550 | false, // disable_p2p_for_downloading |
| 551 | false), // disable_p2p_for sharing |
Jay Srinivasan | 480ddfa | 2012-06-01 19:15:26 -0700 | [diff] [blame] | 552 | -1, |
| 553 | false, // ping_only |
Gilad Arnold | d1c4d2d | 2014-06-05 14:07:53 -0700 | [diff] [blame^] | 554 | ErrorCode::kOmahaUpdateDeferredPerPolicy, |
David Zeuthen | 33bae49 | 2014-02-25 16:16:18 -0800 | [diff] [blame] | 555 | metrics::CheckResult::kUpdateAvailable, |
| 556 | metrics::CheckReaction::kDeferring, |
| 557 | metrics::DownloadErrorCode::kUnset, |
Jay Srinivasan | 480ddfa | 2012-06-01 19:15:26 -0700 | [diff] [blame] | 558 | &response, |
| 559 | NULL)); |
| 560 | EXPECT_FALSE(response.update_exists); |
Chris Sosa | 968d057 | 2013-08-23 14:46:02 -0700 | [diff] [blame] | 561 | |
| 562 | // Verify if we are interactive check we don't defer. |
| 563 | params.set_interactive(true); |
| 564 | ASSERT_TRUE( |
| 565 | TestUpdateCheck(&prefs, // prefs |
David Zeuthen | 8f191b2 | 2013-08-06 12:27:50 -0700 | [diff] [blame] | 566 | NULL, // payload_state |
| 567 | NULL, // p2p_manager |
Chris Sosa | 77f79e8 | 2014-06-02 18:16:24 -0700 | [diff] [blame] | 568 | NULL, // connection_manager |
Chris Sosa | 968d057 | 2013-08-23 14:46:02 -0700 | [diff] [blame] | 569 | params, |
| 570 | GetUpdateResponse2(OmahaRequestParams::kAppId, |
| 571 | "1.2.3.4", // version |
| 572 | "http://more/info", |
| 573 | "true", // prompt |
| 574 | "http://code/base/", // dl url |
| 575 | "file.signed", // file name |
| 576 | "HASH1234=", // checksum |
| 577 | "false", // needs admin |
| 578 | "123", // size |
| 579 | "", // deadline |
David Zeuthen | 8f191b2 | 2013-08-06 12:27:50 -0700 | [diff] [blame] | 580 | "7", // max days to scatter |
David Zeuthen | 639aa36 | 2014-02-03 16:23:44 -0800 | [diff] [blame] | 581 | "42", // elapsed_days |
David Zeuthen | 8f191b2 | 2013-08-06 12:27:50 -0700 | [diff] [blame] | 582 | false, // disable_p2p_for_downloading |
| 583 | false), // disable_p2p_for sharing |
Chris Sosa | 968d057 | 2013-08-23 14:46:02 -0700 | [diff] [blame] | 584 | -1, |
| 585 | false, // ping_only |
Gilad Arnold | d1c4d2d | 2014-06-05 14:07:53 -0700 | [diff] [blame^] | 586 | ErrorCode::kSuccess, |
David Zeuthen | 33bae49 | 2014-02-25 16:16:18 -0800 | [diff] [blame] | 587 | metrics::CheckResult::kUpdateAvailable, |
| 588 | metrics::CheckReaction::kUpdating, |
| 589 | metrics::DownloadErrorCode::kUnset, |
Chris Sosa | 968d057 | 2013-08-23 14:46:02 -0700 | [diff] [blame] | 590 | &response, |
| 591 | NULL)); |
| 592 | EXPECT_TRUE(response.update_exists); |
Jay Srinivasan | 480ddfa | 2012-06-01 19:15:26 -0700 | [diff] [blame] | 593 | } |
| 594 | |
| 595 | TEST(OmahaRequestActionTest, NoWallClockBasedWaitCausesNoScattering) { |
| 596 | OmahaResponse response; |
| 597 | OmahaRequestParams params = kDefaultTestParams; |
Jay Srinivasan | ae4697c | 2013-03-18 17:08:08 -0700 | [diff] [blame] | 598 | params.set_wall_clock_based_wait_enabled(false); |
| 599 | params.set_waiting_period(TimeDelta::FromDays(2)); |
Jay Srinivasan | 480ddfa | 2012-06-01 19:15:26 -0700 | [diff] [blame] | 600 | |
Jay Srinivasan | ae4697c | 2013-03-18 17:08:08 -0700 | [diff] [blame] | 601 | params.set_update_check_count_wait_enabled(true); |
| 602 | params.set_min_update_checks_needed(1); |
| 603 | params.set_max_update_checks_allowed(8); |
Jay Srinivasan | 480ddfa | 2012-06-01 19:15:26 -0700 | [diff] [blame] | 604 | |
| 605 | string prefs_dir; |
Gilad Arnold | a6742b3 | 2014-01-11 00:18:34 -0800 | [diff] [blame] | 606 | EXPECT_TRUE(utils::MakeTempDirectory("ue_ut_prefs.XXXXXX", |
Jay Srinivasan | 480ddfa | 2012-06-01 19:15:26 -0700 | [diff] [blame] | 607 | &prefs_dir)); |
| 608 | ScopedDirRemover temp_dir_remover(prefs_dir); |
| 609 | |
| 610 | Prefs prefs; |
Alex Vakulenko | 75039d7 | 2014-03-25 12:36:28 -0700 | [diff] [blame] | 611 | LOG_IF(ERROR, !prefs.Init(base::FilePath(prefs_dir))) |
Jay Srinivasan | 480ddfa | 2012-06-01 19:15:26 -0700 | [diff] [blame] | 612 | << "Failed to initialize preferences."; |
| 613 | |
| 614 | ASSERT_TRUE( |
| 615 | TestUpdateCheck(&prefs, // prefs |
David Zeuthen | 8f191b2 | 2013-08-06 12:27:50 -0700 | [diff] [blame] | 616 | NULL, // payload_state |
| 617 | NULL, // p2p_manager |
Chris Sosa | 77f79e8 | 2014-06-02 18:16:24 -0700 | [diff] [blame] | 618 | NULL, // connection_manager |
Jay Srinivasan | 480ddfa | 2012-06-01 19:15:26 -0700 | [diff] [blame] | 619 | params, |
| 620 | GetUpdateResponse2(OmahaRequestParams::kAppId, |
| 621 | "1.2.3.4", // version |
| 622 | "http://more/info", |
| 623 | "true", // prompt |
Jay Srinivasan | 23b92a5 | 2012-10-27 02:00:21 -0700 | [diff] [blame] | 624 | "http://code/base/", // dl url |
| 625 | "file.signed", // file name |
Jay Srinivasan | 480ddfa | 2012-06-01 19:15:26 -0700 | [diff] [blame] | 626 | "HASH1234=", // checksum |
| 627 | "false", // needs admin |
| 628 | "123", // size |
| 629 | "", // deadline |
David Zeuthen | 8f191b2 | 2013-08-06 12:27:50 -0700 | [diff] [blame] | 630 | "7", // max days to scatter |
David Zeuthen | 639aa36 | 2014-02-03 16:23:44 -0800 | [diff] [blame] | 631 | "42", // elapsed_days |
David Zeuthen | 8f191b2 | 2013-08-06 12:27:50 -0700 | [diff] [blame] | 632 | false, // disable_p2p_for_downloading |
| 633 | false), // disable_p2p_for sharing |
Jay Srinivasan | 480ddfa | 2012-06-01 19:15:26 -0700 | [diff] [blame] | 634 | -1, |
| 635 | false, // ping_only |
Gilad Arnold | d1c4d2d | 2014-06-05 14:07:53 -0700 | [diff] [blame^] | 636 | ErrorCode::kSuccess, |
David Zeuthen | 33bae49 | 2014-02-25 16:16:18 -0800 | [diff] [blame] | 637 | metrics::CheckResult::kUpdateAvailable, |
| 638 | metrics::CheckReaction::kUpdating, |
| 639 | metrics::DownloadErrorCode::kUnset, |
Jay Srinivasan | 480ddfa | 2012-06-01 19:15:26 -0700 | [diff] [blame] | 640 | &response, |
| 641 | NULL)); |
| 642 | EXPECT_TRUE(response.update_exists); |
| 643 | } |
| 644 | |
| 645 | TEST(OmahaRequestActionTest, ZeroMaxDaysToScatterCausesNoScattering) { |
| 646 | OmahaResponse response; |
| 647 | OmahaRequestParams params = kDefaultTestParams; |
Jay Srinivasan | ae4697c | 2013-03-18 17:08:08 -0700 | [diff] [blame] | 648 | params.set_wall_clock_based_wait_enabled(true); |
| 649 | params.set_waiting_period(TimeDelta::FromDays(2)); |
Jay Srinivasan | 480ddfa | 2012-06-01 19:15:26 -0700 | [diff] [blame] | 650 | |
Jay Srinivasan | ae4697c | 2013-03-18 17:08:08 -0700 | [diff] [blame] | 651 | params.set_update_check_count_wait_enabled(true); |
| 652 | params.set_min_update_checks_needed(1); |
| 653 | params.set_max_update_checks_allowed(8); |
Jay Srinivasan | 480ddfa | 2012-06-01 19:15:26 -0700 | [diff] [blame] | 654 | |
| 655 | string prefs_dir; |
Gilad Arnold | a6742b3 | 2014-01-11 00:18:34 -0800 | [diff] [blame] | 656 | EXPECT_TRUE(utils::MakeTempDirectory("ue_ut_prefs.XXXXXX", |
Jay Srinivasan | 480ddfa | 2012-06-01 19:15:26 -0700 | [diff] [blame] | 657 | &prefs_dir)); |
| 658 | ScopedDirRemover temp_dir_remover(prefs_dir); |
| 659 | |
| 660 | Prefs prefs; |
Alex Vakulenko | 75039d7 | 2014-03-25 12:36:28 -0700 | [diff] [blame] | 661 | LOG_IF(ERROR, !prefs.Init(base::FilePath(prefs_dir))) |
Jay Srinivasan | 480ddfa | 2012-06-01 19:15:26 -0700 | [diff] [blame] | 662 | << "Failed to initialize preferences."; |
| 663 | |
| 664 | ASSERT_TRUE( |
| 665 | TestUpdateCheck(&prefs, // prefs |
David Zeuthen | 8f191b2 | 2013-08-06 12:27:50 -0700 | [diff] [blame] | 666 | NULL, // payload_state |
| 667 | NULL, // p2p_manager |
Chris Sosa | 77f79e8 | 2014-06-02 18:16:24 -0700 | [diff] [blame] | 668 | NULL, // connection_manager |
Jay Srinivasan | 480ddfa | 2012-06-01 19:15:26 -0700 | [diff] [blame] | 669 | params, |
| 670 | GetUpdateResponse2(OmahaRequestParams::kAppId, |
| 671 | "1.2.3.4", // version |
| 672 | "http://more/info", |
| 673 | "true", // prompt |
Jay Srinivasan | 23b92a5 | 2012-10-27 02:00:21 -0700 | [diff] [blame] | 674 | "http://code/base/", // dl url |
| 675 | "file.signed", // file name |
Jay Srinivasan | 480ddfa | 2012-06-01 19:15:26 -0700 | [diff] [blame] | 676 | "HASH1234=", // checksum |
| 677 | "false", // needs admin |
| 678 | "123", // size |
| 679 | "", // deadline |
David Zeuthen | 8f191b2 | 2013-08-06 12:27:50 -0700 | [diff] [blame] | 680 | "0", // max days to scatter |
David Zeuthen | 639aa36 | 2014-02-03 16:23:44 -0800 | [diff] [blame] | 681 | "42", // elapsed_days |
David Zeuthen | 8f191b2 | 2013-08-06 12:27:50 -0700 | [diff] [blame] | 682 | false, // disable_p2p_for_downloading |
| 683 | false), // disable_p2p_for sharing |
Jay Srinivasan | 480ddfa | 2012-06-01 19:15:26 -0700 | [diff] [blame] | 684 | -1, |
| 685 | false, // ping_only |
Gilad Arnold | d1c4d2d | 2014-06-05 14:07:53 -0700 | [diff] [blame^] | 686 | ErrorCode::kSuccess, |
David Zeuthen | 33bae49 | 2014-02-25 16:16:18 -0800 | [diff] [blame] | 687 | metrics::CheckResult::kUpdateAvailable, |
| 688 | metrics::CheckReaction::kUpdating, |
| 689 | metrics::DownloadErrorCode::kUnset, |
Jay Srinivasan | 480ddfa | 2012-06-01 19:15:26 -0700 | [diff] [blame] | 690 | &response, |
| 691 | NULL)); |
| 692 | EXPECT_TRUE(response.update_exists); |
| 693 | } |
| 694 | |
| 695 | |
| 696 | TEST(OmahaRequestActionTest, ZeroUpdateCheckCountCausesNoScattering) { |
| 697 | OmahaResponse response; |
| 698 | OmahaRequestParams params = kDefaultTestParams; |
Jay Srinivasan | ae4697c | 2013-03-18 17:08:08 -0700 | [diff] [blame] | 699 | params.set_wall_clock_based_wait_enabled(true); |
| 700 | params.set_waiting_period(TimeDelta()); |
Jay Srinivasan | 480ddfa | 2012-06-01 19:15:26 -0700 | [diff] [blame] | 701 | |
Jay Srinivasan | ae4697c | 2013-03-18 17:08:08 -0700 | [diff] [blame] | 702 | params.set_update_check_count_wait_enabled(true); |
| 703 | params.set_min_update_checks_needed(0); |
| 704 | params.set_max_update_checks_allowed(0); |
Jay Srinivasan | 480ddfa | 2012-06-01 19:15:26 -0700 | [diff] [blame] | 705 | |
| 706 | string prefs_dir; |
Gilad Arnold | a6742b3 | 2014-01-11 00:18:34 -0800 | [diff] [blame] | 707 | EXPECT_TRUE(utils::MakeTempDirectory("ue_ut_prefs.XXXXXX", |
Jay Srinivasan | 480ddfa | 2012-06-01 19:15:26 -0700 | [diff] [blame] | 708 | &prefs_dir)); |
| 709 | ScopedDirRemover temp_dir_remover(prefs_dir); |
| 710 | |
| 711 | Prefs prefs; |
Alex Vakulenko | 75039d7 | 2014-03-25 12:36:28 -0700 | [diff] [blame] | 712 | LOG_IF(ERROR, !prefs.Init(base::FilePath(prefs_dir))) |
Jay Srinivasan | 480ddfa | 2012-06-01 19:15:26 -0700 | [diff] [blame] | 713 | << "Failed to initialize preferences."; |
| 714 | |
| 715 | ASSERT_TRUE(TestUpdateCheck( |
| 716 | &prefs, // prefs |
David Zeuthen | 8f191b2 | 2013-08-06 12:27:50 -0700 | [diff] [blame] | 717 | NULL, // payload_state |
| 718 | NULL, // p2p_manager |
Chris Sosa | 77f79e8 | 2014-06-02 18:16:24 -0700 | [diff] [blame] | 719 | NULL, // connection_manager |
Jay Srinivasan | 480ddfa | 2012-06-01 19:15:26 -0700 | [diff] [blame] | 720 | params, |
| 721 | GetUpdateResponse2(OmahaRequestParams::kAppId, |
| 722 | "1.2.3.4", // version |
| 723 | "http://more/info", |
| 724 | "true", // prompt |
Jay Srinivasan | 23b92a5 | 2012-10-27 02:00:21 -0700 | [diff] [blame] | 725 | "http://code/base/", // dl url |
| 726 | "file.signed", // file name |
Jay Srinivasan | 480ddfa | 2012-06-01 19:15:26 -0700 | [diff] [blame] | 727 | "HASH1234=", // checksum |
| 728 | "false", // needs admin |
| 729 | "123", // size |
| 730 | "", // deadline |
David Zeuthen | 8f191b2 | 2013-08-06 12:27:50 -0700 | [diff] [blame] | 731 | "7", // max days to scatter |
David Zeuthen | 639aa36 | 2014-02-03 16:23:44 -0800 | [diff] [blame] | 732 | "42", // elapsed_days |
David Zeuthen | 8f191b2 | 2013-08-06 12:27:50 -0700 | [diff] [blame] | 733 | false, // disable_p2p_for_downloading |
| 734 | false), // disable_p2p_for sharing |
Jay Srinivasan | 480ddfa | 2012-06-01 19:15:26 -0700 | [diff] [blame] | 735 | -1, |
| 736 | false, // ping_only |
Gilad Arnold | d1c4d2d | 2014-06-05 14:07:53 -0700 | [diff] [blame^] | 737 | ErrorCode::kSuccess, |
David Zeuthen | 33bae49 | 2014-02-25 16:16:18 -0800 | [diff] [blame] | 738 | metrics::CheckResult::kUpdateAvailable, |
| 739 | metrics::CheckReaction::kUpdating, |
| 740 | metrics::DownloadErrorCode::kUnset, |
Jay Srinivasan | 480ddfa | 2012-06-01 19:15:26 -0700 | [diff] [blame] | 741 | &response, |
| 742 | NULL)); |
| 743 | |
| 744 | int64 count; |
| 745 | ASSERT_TRUE(prefs.GetInt64(kPrefsUpdateCheckCount, &count)); |
| 746 | ASSERT_TRUE(count == 0); |
| 747 | EXPECT_TRUE(response.update_exists); |
| 748 | } |
| 749 | |
| 750 | TEST(OmahaRequestActionTest, NonZeroUpdateCheckCountCausesScattering) { |
| 751 | OmahaResponse response; |
| 752 | OmahaRequestParams params = kDefaultTestParams; |
Jay Srinivasan | ae4697c | 2013-03-18 17:08:08 -0700 | [diff] [blame] | 753 | params.set_wall_clock_based_wait_enabled(true); |
| 754 | params.set_waiting_period(TimeDelta()); |
Jay Srinivasan | 480ddfa | 2012-06-01 19:15:26 -0700 | [diff] [blame] | 755 | |
Jay Srinivasan | ae4697c | 2013-03-18 17:08:08 -0700 | [diff] [blame] | 756 | params.set_update_check_count_wait_enabled(true); |
| 757 | params.set_min_update_checks_needed(1); |
| 758 | params.set_max_update_checks_allowed(8); |
Jay Srinivasan | 480ddfa | 2012-06-01 19:15:26 -0700 | [diff] [blame] | 759 | |
| 760 | string prefs_dir; |
Gilad Arnold | a6742b3 | 2014-01-11 00:18:34 -0800 | [diff] [blame] | 761 | EXPECT_TRUE(utils::MakeTempDirectory("ue_ut_prefs.XXXXXX", |
Jay Srinivasan | 480ddfa | 2012-06-01 19:15:26 -0700 | [diff] [blame] | 762 | &prefs_dir)); |
| 763 | ScopedDirRemover temp_dir_remover(prefs_dir); |
| 764 | |
| 765 | Prefs prefs; |
Alex Vakulenko | 75039d7 | 2014-03-25 12:36:28 -0700 | [diff] [blame] | 766 | LOG_IF(ERROR, !prefs.Init(base::FilePath(prefs_dir))) |
Jay Srinivasan | 480ddfa | 2012-06-01 19:15:26 -0700 | [diff] [blame] | 767 | << "Failed to initialize preferences."; |
| 768 | |
| 769 | ASSERT_FALSE(TestUpdateCheck( |
| 770 | &prefs, // prefs |
David Zeuthen | 8f191b2 | 2013-08-06 12:27:50 -0700 | [diff] [blame] | 771 | NULL, // payload_state |
| 772 | NULL, // p2p_manager |
Chris Sosa | 77f79e8 | 2014-06-02 18:16:24 -0700 | [diff] [blame] | 773 | NULL, // connection_manager |
Jay Srinivasan | 480ddfa | 2012-06-01 19:15:26 -0700 | [diff] [blame] | 774 | params, |
| 775 | GetUpdateResponse2(OmahaRequestParams::kAppId, |
| 776 | "1.2.3.4", // version |
| 777 | "http://more/info", |
| 778 | "true", // prompt |
Jay Srinivasan | 23b92a5 | 2012-10-27 02:00:21 -0700 | [diff] [blame] | 779 | "http://code/base/", // dl url |
| 780 | "file.signed", // file name |
Jay Srinivasan | 480ddfa | 2012-06-01 19:15:26 -0700 | [diff] [blame] | 781 | "HASH1234=", // checksum |
| 782 | "false", // needs admin |
| 783 | "123", // size |
| 784 | "", // deadline |
David Zeuthen | 8f191b2 | 2013-08-06 12:27:50 -0700 | [diff] [blame] | 785 | "7", // max days to scatter |
David Zeuthen | 639aa36 | 2014-02-03 16:23:44 -0800 | [diff] [blame] | 786 | "42", // elapsed_days |
David Zeuthen | 8f191b2 | 2013-08-06 12:27:50 -0700 | [diff] [blame] | 787 | false, // disable_p2p_for_downloading |
| 788 | false), // disable_p2p_for sharing |
Jay Srinivasan | 480ddfa | 2012-06-01 19:15:26 -0700 | [diff] [blame] | 789 | -1, |
| 790 | false, // ping_only |
Gilad Arnold | d1c4d2d | 2014-06-05 14:07:53 -0700 | [diff] [blame^] | 791 | ErrorCode::kOmahaUpdateDeferredPerPolicy, |
David Zeuthen | 33bae49 | 2014-02-25 16:16:18 -0800 | [diff] [blame] | 792 | metrics::CheckResult::kUpdateAvailable, |
| 793 | metrics::CheckReaction::kDeferring, |
| 794 | metrics::DownloadErrorCode::kUnset, |
Jay Srinivasan | 480ddfa | 2012-06-01 19:15:26 -0700 | [diff] [blame] | 795 | &response, |
| 796 | NULL)); |
| 797 | |
| 798 | int64 count; |
| 799 | ASSERT_TRUE(prefs.GetInt64(kPrefsUpdateCheckCount, &count)); |
| 800 | ASSERT_TRUE(count > 0); |
| 801 | EXPECT_FALSE(response.update_exists); |
Chris Sosa | 968d057 | 2013-08-23 14:46:02 -0700 | [diff] [blame] | 802 | |
| 803 | // Verify if we are interactive check we don't defer. |
| 804 | params.set_interactive(true); |
| 805 | ASSERT_TRUE( |
| 806 | TestUpdateCheck(&prefs, // prefs |
David Zeuthen | 8f191b2 | 2013-08-06 12:27:50 -0700 | [diff] [blame] | 807 | NULL, // payload_state |
| 808 | NULL, // p2p_manager |
Chris Sosa | 77f79e8 | 2014-06-02 18:16:24 -0700 | [diff] [blame] | 809 | NULL, // connection_manager |
Chris Sosa | 968d057 | 2013-08-23 14:46:02 -0700 | [diff] [blame] | 810 | params, |
| 811 | GetUpdateResponse2(OmahaRequestParams::kAppId, |
| 812 | "1.2.3.4", // version |
| 813 | "http://more/info", |
| 814 | "true", // prompt |
| 815 | "http://code/base/", // dl url |
| 816 | "file.signed", // file name |
| 817 | "HASH1234=", // checksum |
| 818 | "false", // needs admin |
| 819 | "123", // size |
| 820 | "", // deadline |
David Zeuthen | 8f191b2 | 2013-08-06 12:27:50 -0700 | [diff] [blame] | 821 | "7", // max days to scatter |
David Zeuthen | 639aa36 | 2014-02-03 16:23:44 -0800 | [diff] [blame] | 822 | "42", // elapsed_days |
David Zeuthen | 8f191b2 | 2013-08-06 12:27:50 -0700 | [diff] [blame] | 823 | false, // disable_p2p_for_downloading |
| 824 | false), // disable_p2p_for sharing |
Chris Sosa | 968d057 | 2013-08-23 14:46:02 -0700 | [diff] [blame] | 825 | -1, |
| 826 | false, // ping_only |
Gilad Arnold | d1c4d2d | 2014-06-05 14:07:53 -0700 | [diff] [blame^] | 827 | ErrorCode::kSuccess, |
David Zeuthen | 33bae49 | 2014-02-25 16:16:18 -0800 | [diff] [blame] | 828 | metrics::CheckResult::kUpdateAvailable, |
| 829 | metrics::CheckReaction::kUpdating, |
| 830 | metrics::DownloadErrorCode::kUnset, |
Chris Sosa | 968d057 | 2013-08-23 14:46:02 -0700 | [diff] [blame] | 831 | &response, |
| 832 | NULL)); |
| 833 | EXPECT_TRUE(response.update_exists); |
Jay Srinivasan | 480ddfa | 2012-06-01 19:15:26 -0700 | [diff] [blame] | 834 | } |
| 835 | |
| 836 | TEST(OmahaRequestActionTest, ExistingUpdateCheckCountCausesScattering) { |
| 837 | OmahaResponse response; |
| 838 | OmahaRequestParams params = kDefaultTestParams; |
Jay Srinivasan | ae4697c | 2013-03-18 17:08:08 -0700 | [diff] [blame] | 839 | params.set_wall_clock_based_wait_enabled(true); |
| 840 | params.set_waiting_period(TimeDelta()); |
Jay Srinivasan | 480ddfa | 2012-06-01 19:15:26 -0700 | [diff] [blame] | 841 | |
Jay Srinivasan | ae4697c | 2013-03-18 17:08:08 -0700 | [diff] [blame] | 842 | params.set_update_check_count_wait_enabled(true); |
| 843 | params.set_min_update_checks_needed(1); |
| 844 | params.set_max_update_checks_allowed(8); |
Jay Srinivasan | 480ddfa | 2012-06-01 19:15:26 -0700 | [diff] [blame] | 845 | |
| 846 | string prefs_dir; |
Gilad Arnold | a6742b3 | 2014-01-11 00:18:34 -0800 | [diff] [blame] | 847 | EXPECT_TRUE(utils::MakeTempDirectory("ue_ut_prefs.XXXXXX", |
Jay Srinivasan | 480ddfa | 2012-06-01 19:15:26 -0700 | [diff] [blame] | 848 | &prefs_dir)); |
| 849 | ScopedDirRemover temp_dir_remover(prefs_dir); |
| 850 | |
| 851 | Prefs prefs; |
Alex Vakulenko | 75039d7 | 2014-03-25 12:36:28 -0700 | [diff] [blame] | 852 | LOG_IF(ERROR, !prefs.Init(base::FilePath(prefs_dir))) |
Jay Srinivasan | 480ddfa | 2012-06-01 19:15:26 -0700 | [diff] [blame] | 853 | << "Failed to initialize preferences."; |
| 854 | |
| 855 | ASSERT_TRUE(prefs.SetInt64(kPrefsUpdateCheckCount, 5)); |
| 856 | |
| 857 | ASSERT_FALSE(TestUpdateCheck( |
| 858 | &prefs, // prefs |
David Zeuthen | 8f191b2 | 2013-08-06 12:27:50 -0700 | [diff] [blame] | 859 | NULL, // payload_state |
| 860 | NULL, // p2p_manager |
Chris Sosa | 77f79e8 | 2014-06-02 18:16:24 -0700 | [diff] [blame] | 861 | NULL, // connection_manager |
Jay Srinivasan | 480ddfa | 2012-06-01 19:15:26 -0700 | [diff] [blame] | 862 | params, |
| 863 | GetUpdateResponse2(OmahaRequestParams::kAppId, |
| 864 | "1.2.3.4", // version |
| 865 | "http://more/info", |
| 866 | "true", // prompt |
Jay Srinivasan | 23b92a5 | 2012-10-27 02:00:21 -0700 | [diff] [blame] | 867 | "http://code/base/", // dl url |
| 868 | "file.signed", // file name |
Jay Srinivasan | 480ddfa | 2012-06-01 19:15:26 -0700 | [diff] [blame] | 869 | "HASH1234=", // checksum |
| 870 | "false", // needs admin |
| 871 | "123", // size |
| 872 | "", // deadline |
David Zeuthen | 8f191b2 | 2013-08-06 12:27:50 -0700 | [diff] [blame] | 873 | "7", // max days to scatter |
David Zeuthen | 639aa36 | 2014-02-03 16:23:44 -0800 | [diff] [blame] | 874 | "42", // elapsed_days |
David Zeuthen | 8f191b2 | 2013-08-06 12:27:50 -0700 | [diff] [blame] | 875 | false, // disable_p2p_for_downloading |
| 876 | false), // disable_p2p_for sharing |
Jay Srinivasan | 480ddfa | 2012-06-01 19:15:26 -0700 | [diff] [blame] | 877 | -1, |
| 878 | false, // ping_only |
Gilad Arnold | d1c4d2d | 2014-06-05 14:07:53 -0700 | [diff] [blame^] | 879 | ErrorCode::kOmahaUpdateDeferredPerPolicy, |
David Zeuthen | 33bae49 | 2014-02-25 16:16:18 -0800 | [diff] [blame] | 880 | metrics::CheckResult::kUpdateAvailable, |
| 881 | metrics::CheckReaction::kDeferring, |
| 882 | metrics::DownloadErrorCode::kUnset, |
Jay Srinivasan | 480ddfa | 2012-06-01 19:15:26 -0700 | [diff] [blame] | 883 | &response, |
| 884 | NULL)); |
| 885 | |
| 886 | int64 count; |
| 887 | ASSERT_TRUE(prefs.GetInt64(kPrefsUpdateCheckCount, &count)); |
| 888 | // count remains the same, as the decrementing happens in update_attempter |
| 889 | // which this test doesn't exercise. |
| 890 | ASSERT_TRUE(count == 5); |
| 891 | EXPECT_FALSE(response.update_exists); |
Chris Sosa | 968d057 | 2013-08-23 14:46:02 -0700 | [diff] [blame] | 892 | |
| 893 | // Verify if we are interactive check we don't defer. |
| 894 | params.set_interactive(true); |
| 895 | ASSERT_TRUE( |
| 896 | TestUpdateCheck(&prefs, // prefs |
David Zeuthen | 8f191b2 | 2013-08-06 12:27:50 -0700 | [diff] [blame] | 897 | NULL, // payload_state |
| 898 | NULL, // p2p_manager |
Chris Sosa | 77f79e8 | 2014-06-02 18:16:24 -0700 | [diff] [blame] | 899 | NULL, // connection_manager |
Chris Sosa | 968d057 | 2013-08-23 14:46:02 -0700 | [diff] [blame] | 900 | params, |
| 901 | GetUpdateResponse2(OmahaRequestParams::kAppId, |
| 902 | "1.2.3.4", // version |
| 903 | "http://more/info", |
| 904 | "true", // prompt |
| 905 | "http://code/base/", // dl url |
| 906 | "file.signed", // file name |
| 907 | "HASH1234=", // checksum |
| 908 | "false", // needs admin |
| 909 | "123", // size |
| 910 | "", // deadline |
David Zeuthen | 8f191b2 | 2013-08-06 12:27:50 -0700 | [diff] [blame] | 911 | "7", // max days to scatter |
David Zeuthen | 639aa36 | 2014-02-03 16:23:44 -0800 | [diff] [blame] | 912 | "42", // elapsed_days |
David Zeuthen | 8f191b2 | 2013-08-06 12:27:50 -0700 | [diff] [blame] | 913 | false, // disable_p2p_for_downloading |
| 914 | false), // disable_p2p_for sharing |
Chris Sosa | 968d057 | 2013-08-23 14:46:02 -0700 | [diff] [blame] | 915 | -1, |
| 916 | false, // ping_only |
Gilad Arnold | d1c4d2d | 2014-06-05 14:07:53 -0700 | [diff] [blame^] | 917 | ErrorCode::kSuccess, |
David Zeuthen | 33bae49 | 2014-02-25 16:16:18 -0800 | [diff] [blame] | 918 | metrics::CheckResult::kUpdateAvailable, |
| 919 | metrics::CheckReaction::kUpdating, |
| 920 | metrics::DownloadErrorCode::kUnset, |
Chris Sosa | 968d057 | 2013-08-23 14:46:02 -0700 | [diff] [blame] | 921 | &response, |
| 922 | NULL)); |
| 923 | EXPECT_TRUE(response.update_exists); |
Jay Srinivasan | 480ddfa | 2012-06-01 19:15:26 -0700 | [diff] [blame] | 924 | } |
Jay Srinivasan | 0a70874 | 2012-03-20 11:26:12 -0700 | [diff] [blame] | 925 | |
Darin Petkov | 6a5b322 | 2010-07-13 14:55:28 -0700 | [diff] [blame] | 926 | TEST(OmahaRequestActionTest, NoOutputPipeTest) { |
Darin Petkov | 6a5b322 | 2010-07-13 14:55:28 -0700 | [diff] [blame] | 927 | const string http_response(GetNoUpdateResponse(OmahaRequestParams::kAppId)); |
| 928 | |
| 929 | GMainLoop *loop = g_main_loop_new(g_main_context_default(), FALSE); |
| 930 | |
Gilad Arnold | 5bb4c90 | 2014-04-10 12:32:13 -0700 | [diff] [blame] | 931 | FakeSystemState fake_system_state; |
Jay Srinivasan | 480ddfa | 2012-06-01 19:15:26 -0700 | [diff] [blame] | 932 | OmahaRequestParams params = kDefaultTestParams; |
Gilad Arnold | 5bb4c90 | 2014-04-10 12:32:13 -0700 | [diff] [blame] | 933 | fake_system_state.set_request_params(¶ms); |
| 934 | OmahaRequestAction action(&fake_system_state, NULL, |
Darin Petkov | 0dc8e9a | 2010-07-14 14:51:57 -0700 | [diff] [blame] | 935 | new MockHttpFetcher(http_response.data(), |
Andrew de los Reyes | 4516810 | 2010-11-22 11:13:50 -0800 | [diff] [blame] | 936 | http_response.size(), |
Thieu Le | 116fda3 | 2011-04-19 11:01:54 -0700 | [diff] [blame] | 937 | NULL), |
| 938 | false); |
Darin Petkov | 6a5b322 | 2010-07-13 14:55:28 -0700 | [diff] [blame] | 939 | OmahaRequestActionTestProcessorDelegate delegate; |
| 940 | delegate.loop_ = loop; |
| 941 | ActionProcessor processor; |
| 942 | processor.set_delegate(&delegate); |
Darin Petkov | 6a5b322 | 2010-07-13 14:55:28 -0700 | [diff] [blame] | 943 | processor.EnqueueAction(&action); |
Darin Petkov | 6a5b322 | 2010-07-13 14:55:28 -0700 | [diff] [blame] | 944 | |
| 945 | g_timeout_add(0, &StartProcessorInRunLoop, &processor); |
| 946 | g_main_loop_run(loop); |
| 947 | g_main_loop_unref(loop); |
| 948 | EXPECT_FALSE(processor.IsRunning()); |
| 949 | } |
| 950 | |
| 951 | TEST(OmahaRequestActionTest, InvalidXmlTest) { |
Darin Petkov | 6a5b322 | 2010-07-13 14:55:28 -0700 | [diff] [blame] | 952 | OmahaResponse response; |
| 953 | ASSERT_FALSE( |
Darin Petkov | 1cbd78f | 2010-07-29 12:38:34 -0700 | [diff] [blame] | 954 | TestUpdateCheck(NULL, // prefs |
David Zeuthen | 8f191b2 | 2013-08-06 12:27:50 -0700 | [diff] [blame] | 955 | NULL, // payload_state |
| 956 | NULL, // p2p_manager |
Chris Sosa | 77f79e8 | 2014-06-02 18:16:24 -0700 | [diff] [blame] | 957 | NULL, // connection_manager |
Darin Petkov | 1cbd78f | 2010-07-29 12:38:34 -0700 | [diff] [blame] | 958 | kDefaultTestParams, |
Darin Petkov | 0dc8e9a | 2010-07-14 14:51:57 -0700 | [diff] [blame] | 959 | "invalid xml>", |
Darin Petkov | edc522e | 2010-11-05 09:35:17 -0700 | [diff] [blame] | 960 | -1, |
Darin Petkov | 265f290 | 2011-05-09 15:17:40 -0700 | [diff] [blame] | 961 | false, // ping_only |
Gilad Arnold | d1c4d2d | 2014-06-05 14:07:53 -0700 | [diff] [blame^] | 962 | ErrorCode::kOmahaRequestXMLParseError, |
David Zeuthen | 33bae49 | 2014-02-25 16:16:18 -0800 | [diff] [blame] | 963 | metrics::CheckResult::kParsingError, |
| 964 | metrics::CheckReaction::kUnset, |
| 965 | metrics::DownloadErrorCode::kUnset, |
Darin Petkov | edc522e | 2010-11-05 09:35:17 -0700 | [diff] [blame] | 966 | &response, |
| 967 | NULL)); |
| 968 | EXPECT_FALSE(response.update_exists); |
| 969 | } |
| 970 | |
| 971 | TEST(OmahaRequestActionTest, EmptyResponseTest) { |
| 972 | OmahaResponse response; |
| 973 | ASSERT_FALSE( |
| 974 | TestUpdateCheck(NULL, // prefs |
David Zeuthen | 8f191b2 | 2013-08-06 12:27:50 -0700 | [diff] [blame] | 975 | NULL, // payload_state |
| 976 | NULL, // p2p_manager |
Chris Sosa | 77f79e8 | 2014-06-02 18:16:24 -0700 | [diff] [blame] | 977 | NULL, // connection_manager |
Darin Petkov | edc522e | 2010-11-05 09:35:17 -0700 | [diff] [blame] | 978 | kDefaultTestParams, |
| 979 | "", |
| 980 | -1, |
Darin Petkov | 265f290 | 2011-05-09 15:17:40 -0700 | [diff] [blame] | 981 | false, // ping_only |
Gilad Arnold | d1c4d2d | 2014-06-05 14:07:53 -0700 | [diff] [blame^] | 982 | ErrorCode::kOmahaRequestEmptyResponseError, |
David Zeuthen | 33bae49 | 2014-02-25 16:16:18 -0800 | [diff] [blame] | 983 | metrics::CheckResult::kParsingError, |
| 984 | metrics::CheckReaction::kUnset, |
| 985 | metrics::DownloadErrorCode::kUnset, |
Darin Petkov | 0dc8e9a | 2010-07-14 14:51:57 -0700 | [diff] [blame] | 986 | &response, |
| 987 | NULL)); |
Darin Petkov | 6a5b322 | 2010-07-13 14:55:28 -0700 | [diff] [blame] | 988 | EXPECT_FALSE(response.update_exists); |
| 989 | } |
| 990 | |
| 991 | TEST(OmahaRequestActionTest, MissingStatusTest) { |
Darin Petkov | 6a5b322 | 2010-07-13 14:55:28 -0700 | [diff] [blame] | 992 | OmahaResponse response; |
Darin Petkov | 0dc8e9a | 2010-07-14 14:51:57 -0700 | [diff] [blame] | 993 | ASSERT_FALSE(TestUpdateCheck( |
Darin Petkov | 1cbd78f | 2010-07-29 12:38:34 -0700 | [diff] [blame] | 994 | NULL, // prefs |
David Zeuthen | 8f191b2 | 2013-08-06 12:27:50 -0700 | [diff] [blame] | 995 | NULL, // payload_state |
| 996 | NULL, // p2p_manager |
Chris Sosa | 77f79e8 | 2014-06-02 18:16:24 -0700 | [diff] [blame] | 997 | NULL, // connection_manager |
Darin Petkov | 1cbd78f | 2010-07-29 12:38:34 -0700 | [diff] [blame] | 998 | kDefaultTestParams, |
Jay Srinivasan | 23b92a5 | 2012-10-27 02:00:21 -0700 | [diff] [blame] | 999 | "<?xml version=\"1.0\" encoding=\"UTF-8\"?><response protocol=\"3.0\">" |
| 1000 | "<daystart elapsed_seconds=\"100\"/>" |
| 1001 | "<app appid=\"foo\" status=\"ok\">" |
| 1002 | "<ping status=\"ok\"/>" |
| 1003 | "<updatecheck/></app></response>", |
Darin Petkov | edc522e | 2010-11-05 09:35:17 -0700 | [diff] [blame] | 1004 | -1, |
Darin Petkov | 265f290 | 2011-05-09 15:17:40 -0700 | [diff] [blame] | 1005 | false, // ping_only |
Gilad Arnold | d1c4d2d | 2014-06-05 14:07:53 -0700 | [diff] [blame^] | 1006 | ErrorCode::kOmahaResponseInvalid, |
David Zeuthen | 33bae49 | 2014-02-25 16:16:18 -0800 | [diff] [blame] | 1007 | metrics::CheckResult::kParsingError, |
| 1008 | metrics::CheckReaction::kUnset, |
| 1009 | metrics::DownloadErrorCode::kUnset, |
Darin Petkov | 6a5b322 | 2010-07-13 14:55:28 -0700 | [diff] [blame] | 1010 | &response, |
| 1011 | NULL)); |
| 1012 | EXPECT_FALSE(response.update_exists); |
| 1013 | } |
| 1014 | |
| 1015 | TEST(OmahaRequestActionTest, InvalidStatusTest) { |
Darin Petkov | 6a5b322 | 2010-07-13 14:55:28 -0700 | [diff] [blame] | 1016 | OmahaResponse response; |
Darin Petkov | 0dc8e9a | 2010-07-14 14:51:57 -0700 | [diff] [blame] | 1017 | ASSERT_FALSE(TestUpdateCheck( |
Darin Petkov | 1cbd78f | 2010-07-29 12:38:34 -0700 | [diff] [blame] | 1018 | NULL, // prefs |
David Zeuthen | 8f191b2 | 2013-08-06 12:27:50 -0700 | [diff] [blame] | 1019 | NULL, // payload_state |
| 1020 | NULL, // p2p_manager |
Chris Sosa | 77f79e8 | 2014-06-02 18:16:24 -0700 | [diff] [blame] | 1021 | NULL, // connection_manager |
Darin Petkov | 1cbd78f | 2010-07-29 12:38:34 -0700 | [diff] [blame] | 1022 | kDefaultTestParams, |
Jay Srinivasan | 23b92a5 | 2012-10-27 02:00:21 -0700 | [diff] [blame] | 1023 | "<?xml version=\"1.0\" encoding=\"UTF-8\"?><response protocol=\"3.0\">" |
| 1024 | "<daystart elapsed_seconds=\"100\"/>" |
| 1025 | "<app appid=\"foo\" status=\"ok\">" |
| 1026 | "<ping status=\"ok\"/>" |
| 1027 | "<updatecheck status=\"InvalidStatusTest\"/></app></response>", |
Darin Petkov | edc522e | 2010-11-05 09:35:17 -0700 | [diff] [blame] | 1028 | -1, |
Darin Petkov | 265f290 | 2011-05-09 15:17:40 -0700 | [diff] [blame] | 1029 | false, // ping_only |
Gilad Arnold | d1c4d2d | 2014-06-05 14:07:53 -0700 | [diff] [blame^] | 1030 | ErrorCode::kOmahaResponseInvalid, |
David Zeuthen | 33bae49 | 2014-02-25 16:16:18 -0800 | [diff] [blame] | 1031 | metrics::CheckResult::kParsingError, |
| 1032 | metrics::CheckReaction::kUnset, |
| 1033 | metrics::DownloadErrorCode::kUnset, |
Darin Petkov | 6a5b322 | 2010-07-13 14:55:28 -0700 | [diff] [blame] | 1034 | &response, |
| 1035 | NULL)); |
| 1036 | EXPECT_FALSE(response.update_exists); |
| 1037 | } |
| 1038 | |
| 1039 | TEST(OmahaRequestActionTest, MissingNodesetTest) { |
Darin Petkov | 6a5b322 | 2010-07-13 14:55:28 -0700 | [diff] [blame] | 1040 | OmahaResponse response; |
Darin Petkov | 0dc8e9a | 2010-07-14 14:51:57 -0700 | [diff] [blame] | 1041 | ASSERT_FALSE(TestUpdateCheck( |
Darin Petkov | 1cbd78f | 2010-07-29 12:38:34 -0700 | [diff] [blame] | 1042 | NULL, // prefs |
David Zeuthen | 8f191b2 | 2013-08-06 12:27:50 -0700 | [diff] [blame] | 1043 | NULL, // payload_state |
| 1044 | NULL, // p2p_manager |
Chris Sosa | 77f79e8 | 2014-06-02 18:16:24 -0700 | [diff] [blame] | 1045 | NULL, // connection_manager |
Darin Petkov | 1cbd78f | 2010-07-29 12:38:34 -0700 | [diff] [blame] | 1046 | kDefaultTestParams, |
Jay Srinivasan | 23b92a5 | 2012-10-27 02:00:21 -0700 | [diff] [blame] | 1047 | "<?xml version=\"1.0\" encoding=\"UTF-8\"?><response protocol=\"3.0\">" |
| 1048 | "<daystart elapsed_seconds=\"100\"/>" |
| 1049 | "<app appid=\"foo\" status=\"ok\">" |
| 1050 | "<ping status=\"ok\"/>" |
| 1051 | "</app></response>", |
Darin Petkov | edc522e | 2010-11-05 09:35:17 -0700 | [diff] [blame] | 1052 | -1, |
Darin Petkov | 265f290 | 2011-05-09 15:17:40 -0700 | [diff] [blame] | 1053 | false, // ping_only |
Gilad Arnold | d1c4d2d | 2014-06-05 14:07:53 -0700 | [diff] [blame^] | 1054 | ErrorCode::kOmahaResponseInvalid, |
David Zeuthen | 33bae49 | 2014-02-25 16:16:18 -0800 | [diff] [blame] | 1055 | metrics::CheckResult::kParsingError, |
| 1056 | metrics::CheckReaction::kUnset, |
| 1057 | metrics::DownloadErrorCode::kUnset, |
Darin Petkov | 6a5b322 | 2010-07-13 14:55:28 -0700 | [diff] [blame] | 1058 | &response, |
| 1059 | NULL)); |
| 1060 | EXPECT_FALSE(response.update_exists); |
| 1061 | } |
| 1062 | |
| 1063 | TEST(OmahaRequestActionTest, MissingFieldTest) { |
Jay Srinivasan | 23b92a5 | 2012-10-27 02:00:21 -0700 | [diff] [blame] | 1064 | string input_response = |
| 1065 | "<?xml version=\"1.0\" encoding=\"UTF-8\"?><response protocol=\"3.0\">" |
| 1066 | "<daystart elapsed_seconds=\"100\"/>" |
| 1067 | "<app appid=\"xyz\" status=\"ok\">" |
| 1068 | "<updatecheck status=\"ok\">" |
| 1069 | "<urls><url codebase=\"http://missing/field/test/\"/></urls>" |
Chris Sosa | 3b74843 | 2013-06-20 16:42:59 -0700 | [diff] [blame] | 1070 | "<manifest version=\"10.2.3.4\">" |
Jay Srinivasan | 23b92a5 | 2012-10-27 02:00:21 -0700 | [diff] [blame] | 1071 | "<packages><package hash=\"not-used\" name=\"f\" " |
| 1072 | "size=\"587\"/></packages>" |
| 1073 | "<actions><action event=\"postinstall\" " |
Jay Srinivasan | 23b92a5 | 2012-10-27 02:00:21 -0700 | [diff] [blame] | 1074 | "ChromeOSVersion=\"10.2.3.4\" " |
| 1075 | "Prompt=\"false\" " |
| 1076 | "IsDelta=\"true\" " |
Jay Srinivasan | d671e97 | 2013-01-11 17:17:19 -0800 | [diff] [blame] | 1077 | "IsDeltaPayload=\"false\" " |
Jay Srinivasan | 23b92a5 | 2012-10-27 02:00:21 -0700 | [diff] [blame] | 1078 | "sha256=\"lkq34j5345\" " |
| 1079 | "needsadmin=\"true\" " |
| 1080 | "/></actions></manifest></updatecheck></app></response>"; |
| 1081 | LOG(INFO) << "Input Response = " << input_response; |
| 1082 | |
Darin Petkov | 6a5b322 | 2010-07-13 14:55:28 -0700 | [diff] [blame] | 1083 | OmahaResponse response; |
Darin Petkov | 1cbd78f | 2010-07-29 12:38:34 -0700 | [diff] [blame] | 1084 | ASSERT_TRUE(TestUpdateCheck(NULL, // prefs |
David Zeuthen | 8f191b2 | 2013-08-06 12:27:50 -0700 | [diff] [blame] | 1085 | NULL, // payload_state |
| 1086 | NULL, // p2p_manager |
Chris Sosa | 77f79e8 | 2014-06-02 18:16:24 -0700 | [diff] [blame] | 1087 | NULL, // connection_manager |
Darin Petkov | 1cbd78f | 2010-07-29 12:38:34 -0700 | [diff] [blame] | 1088 | kDefaultTestParams, |
Jay Srinivasan | 23b92a5 | 2012-10-27 02:00:21 -0700 | [diff] [blame] | 1089 | input_response, |
Darin Petkov | edc522e | 2010-11-05 09:35:17 -0700 | [diff] [blame] | 1090 | -1, |
Darin Petkov | 265f290 | 2011-05-09 15:17:40 -0700 | [diff] [blame] | 1091 | false, // ping_only |
Gilad Arnold | d1c4d2d | 2014-06-05 14:07:53 -0700 | [diff] [blame^] | 1092 | ErrorCode::kSuccess, |
David Zeuthen | 33bae49 | 2014-02-25 16:16:18 -0800 | [diff] [blame] | 1093 | metrics::CheckResult::kUpdateAvailable, |
| 1094 | metrics::CheckReaction::kUpdating, |
| 1095 | metrics::DownloadErrorCode::kUnset, |
Darin Petkov | 0dc8e9a | 2010-07-14 14:51:57 -0700 | [diff] [blame] | 1096 | &response, |
| 1097 | NULL)); |
Darin Petkov | 6a5b322 | 2010-07-13 14:55:28 -0700 | [diff] [blame] | 1098 | EXPECT_TRUE(response.update_exists); |
Chris Sosa | 3b74843 | 2013-06-20 16:42:59 -0700 | [diff] [blame] | 1099 | EXPECT_EQ("10.2.3.4", response.version); |
Jay Srinivasan | 6f6ea00 | 2012-12-14 11:26:28 -0800 | [diff] [blame] | 1100 | EXPECT_EQ("http://missing/field/test/f", response.payload_urls[0]); |
Darin Petkov | 6a5b322 | 2010-07-13 14:55:28 -0700 | [diff] [blame] | 1101 | EXPECT_EQ("", response.more_info_url); |
Jay Srinivasan | 23b92a5 | 2012-10-27 02:00:21 -0700 | [diff] [blame] | 1102 | EXPECT_EQ("lkq34j5345", response.hash); |
| 1103 | EXPECT_EQ(587, response.size); |
Darin Petkov | 6a5b322 | 2010-07-13 14:55:28 -0700 | [diff] [blame] | 1104 | EXPECT_FALSE(response.prompt); |
Darin Petkov | 6c11864 | 2010-10-21 12:06:30 -0700 | [diff] [blame] | 1105 | EXPECT_TRUE(response.deadline.empty()); |
Darin Petkov | 6a5b322 | 2010-07-13 14:55:28 -0700 | [diff] [blame] | 1106 | } |
| 1107 | |
| 1108 | namespace { |
| 1109 | class TerminateEarlyTestProcessorDelegate : public ActionProcessorDelegate { |
| 1110 | public: |
| 1111 | void ProcessingStopped(const ActionProcessor* processor) { |
| 1112 | ASSERT_TRUE(loop_); |
| 1113 | g_main_loop_quit(loop_); |
| 1114 | } |
| 1115 | GMainLoop *loop_; |
| 1116 | }; |
| 1117 | |
| 1118 | gboolean TerminateTransferTestStarter(gpointer data) { |
| 1119 | ActionProcessor *processor = reinterpret_cast<ActionProcessor*>(data); |
| 1120 | processor->StartProcessing(); |
| 1121 | CHECK(processor->IsRunning()); |
| 1122 | processor->StopProcessing(); |
| 1123 | return FALSE; |
| 1124 | } |
| 1125 | } // namespace {} |
| 1126 | |
| 1127 | TEST(OmahaRequestActionTest, TerminateTransferTest) { |
Darin Petkov | 6a5b322 | 2010-07-13 14:55:28 -0700 | [diff] [blame] | 1128 | string http_response("doesn't matter"); |
| 1129 | GMainLoop *loop = g_main_loop_new(g_main_context_default(), FALSE); |
| 1130 | |
Gilad Arnold | 5bb4c90 | 2014-04-10 12:32:13 -0700 | [diff] [blame] | 1131 | FakeSystemState fake_system_state; |
Jay Srinivasan | 480ddfa | 2012-06-01 19:15:26 -0700 | [diff] [blame] | 1132 | OmahaRequestParams params = kDefaultTestParams; |
Gilad Arnold | 5bb4c90 | 2014-04-10 12:32:13 -0700 | [diff] [blame] | 1133 | fake_system_state.set_request_params(¶ms); |
| 1134 | OmahaRequestAction action(&fake_system_state, NULL, |
Darin Petkov | 0dc8e9a | 2010-07-14 14:51:57 -0700 | [diff] [blame] | 1135 | new MockHttpFetcher(http_response.data(), |
Andrew de los Reyes | 4516810 | 2010-11-22 11:13:50 -0800 | [diff] [blame] | 1136 | http_response.size(), |
Thieu Le | 116fda3 | 2011-04-19 11:01:54 -0700 | [diff] [blame] | 1137 | NULL), |
| 1138 | false); |
Darin Petkov | 6a5b322 | 2010-07-13 14:55:28 -0700 | [diff] [blame] | 1139 | TerminateEarlyTestProcessorDelegate delegate; |
| 1140 | delegate.loop_ = loop; |
| 1141 | ActionProcessor processor; |
| 1142 | processor.set_delegate(&delegate); |
Darin Petkov | 6a5b322 | 2010-07-13 14:55:28 -0700 | [diff] [blame] | 1143 | processor.EnqueueAction(&action); |
Darin Petkov | 6a5b322 | 2010-07-13 14:55:28 -0700 | [diff] [blame] | 1144 | |
| 1145 | g_timeout_add(0, &TerminateTransferTestStarter, &processor); |
| 1146 | g_main_loop_run(loop); |
| 1147 | g_main_loop_unref(loop); |
| 1148 | } |
| 1149 | |
| 1150 | TEST(OmahaRequestActionTest, XmlEncodeTest) { |
| 1151 | EXPECT_EQ("ab", XmlEncode("ab")); |
| 1152 | EXPECT_EQ("a<b", XmlEncode("a<b")); |
| 1153 | EXPECT_EQ("foo-Ω", XmlEncode("foo-\xce\xa9")); |
| 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", |
Andrew de los Reyes | 3f0303a | 2010-07-15 22:35:35 -0700 | [diff] [blame] | 1173 | false, // delta okay |
Gilad Arnold | bbdd490 | 2013-01-10 16:06:30 -0800 | [diff] [blame] | 1174 | false, // interactive |
Jay Srinivasan | 0a70874 | 2012-03-20 11:26:12 -0700 | [diff] [blame] | 1175 | "http://url", |
David Zeuthen | 8f191b2 | 2013-08-06 12:27:50 -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 |
Darin Petkov | 1cbd78f | 2010-07-29 12:38:34 -0700 | [diff] [blame] | 1186 | params, |
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 |
Darin Petkov | 1cbd78f | 2010-07-29 12:38:34 -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 |
| 1221 | "file.signed", // file name |
Darin Petkov | 0dc8e9a | 2010-07-14 14:51:57 -0700 | [diff] [blame] | 1222 | "HASH1234=", // checksum |
| 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 |
Darin Petkov | 1cbd78f | 2010-07-29 12:38:34 -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 |
| 1253 | "file.signed", // file name |
Darin Petkov | 0dc8e9a | 2010-07-14 14:51:57 -0700 | [diff] [blame] | 1254 | "HASH1234=", // checksum |
| 1255 | "false", // needs admin |
| 1256 | // overflows int32: |
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 |
Darin Petkov | 1cbd78f | 2010-07-29 12:38:34 -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 |
Jay Srinivasan | 0a70874 | 2012-03-20 11:26:12 -0700 | [diff] [blame] | 1318 | params, |
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 |
| 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 |
Darin Petkov | 1cbd78f | 2010-07-29 12:38:34 -0700 | [diff] [blame] | 1434 | params, |
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 |
| 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 |
Gilad Arnold | bbdd490 | 2013-01-10 16:06:30 -0800 | [diff] [blame] | 1482 | params, |
| 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 |
Darin Petkov | 265f290 | 2011-05-09 15:17:40 -0700 | [diff] [blame] | 1543 | kDefaultTestParams, |
| 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 |
Darin Petkov | 1cbd78f | 2010-07-29 12:38:34 -0700 | [diff] [blame] | 1586 | kDefaultTestParams, |
| 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 |
Darin Petkov | 1cbd78f | 2010-07-29 12:38:34 -0700 | [diff] [blame] | 1621 | kDefaultTestParams, |
| 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 |
Darin Petkov | 1cbd78f | 2010-07-29 12:38:34 -0700 | [diff] [blame] | 1657 | kDefaultTestParams, |
| 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 |
Thieu Le | b44e9e8 | 2011-06-06 14:34:04 -0700 | [diff] [blame] | 1687 | kDefaultTestParams, |
| 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 |
Darin Petkov | 1cbd78f | 2010-07-29 12:38:34 -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 |
Darin Petkov | 1cbd78f | 2010-07-29 12:38:34 -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 |
Darin Petkov | 1cbd78f | 2010-07-29 12:38:34 -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 |
Darin Petkov | 1cbd78f | 2010-07-29 12:38:34 -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 |
Darin Petkov | 84c763c | 2010-07-29 16:27:58 -0700 | [diff] [blame] | 1836 | kDefaultTestParams, |
| 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 |
Darin Petkov | edc522e | 2010-11-05 09:35:17 -0700 | [diff] [blame] | 1861 | kDefaultTestParams, |
| 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 |
Darin Petkov | edc522e | 2010-11-05 09:35:17 -0700 | [diff] [blame] | 1883 | kDefaultTestParams, |
| 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 |
Jay Srinivasan | 34b5d86 | 2012-07-23 11:43:22 -0700 | [diff] [blame] | 1917 | params, |
| 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 |
| 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 |
David Zeuthen | 8f191b2 | 2013-08-06 12:27:50 -0700 | [diff] [blame] | 1928 | "7", // max days to scatter |
David Zeuthen | 639aa36 | 2014-02-03 16:23:44 -0800 | [diff] [blame] | 1929 | "42", // elapsed_days |
David Zeuthen | 8f191b2 | 2013-08-06 12:27:50 -0700 | [diff] [blame] | 1930 | false, // disable_p2p_for_downloading |
| 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 | |
| 1941 | int64 timestamp = 0; |
| 1942 | ASSERT_TRUE(prefs.GetInt64(kPrefsUpdateFirstSeenAt, ×tamp)); |
| 1943 | ASSERT_TRUE(timestamp > 0); |
| 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 |
Chris Sosa | 968d057 | 2013-08-23 14:46:02 -0700 | [diff] [blame] | 1953 | params, |
| 1954 | GetUpdateResponse2(OmahaRequestParams::kAppId, |
| 1955 | "1.2.3.4", // version |
| 1956 | "http://more/info", |
| 1957 | "true", // prompt |
| 1958 | "http://code/base/", // dl url |
| 1959 | "file.signed", // file name |
| 1960 | "HASH1234=", // checksum |
| 1961 | "false", // needs admin |
| 1962 | "123", // size |
| 1963 | "", // deadline |
David Zeuthen | 8f191b2 | 2013-08-06 12:27:50 -0700 | [diff] [blame] | 1964 | "7", // max days to scatter |
David Zeuthen | 639aa36 | 2014-02-03 16:23:44 -0800 | [diff] [blame] | 1965 | "42", // elapsed_days |
David Zeuthen | 8f191b2 | 2013-08-06 12:27:50 -0700 | [diff] [blame] | 1966 | false, // disable_p2p_for_downloading |
| 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 |
Jay Srinivasan | 34b5d86 | 2012-07-23 11:43:22 -0700 | [diff] [blame] | 2005 | params, |
| 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 |
| 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 |
David Zeuthen | 8f191b2 | 2013-08-06 12:27:50 -0700 | [diff] [blame] | 2016 | "7", // max days to scatter |
David Zeuthen | 639aa36 | 2014-02-03 16:23:44 -0800 | [diff] [blame] | 2017 | "42", // elapsed_days |
David Zeuthen | 8f191b2 | 2013-08-06 12:27:50 -0700 | [diff] [blame] | 2018 | false, // disable_p2p_for_downloading |
| 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. |
| 2032 | int64 timestamp = 0; |
| 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 |
Jay Srinivasan | ae4697c | 2013-03-18 17:08:08 -0700 | [diff] [blame] | 2069 | params, |
| 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 |
Jay Srinivasan | ae4697c | 2013-03-18 17:08:08 -0700 | [diff] [blame] | 2120 | params, |
| 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\"")); |
| 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 |
David Zeuthen | 8f191b2 | 2013-08-06 12:27:50 -0700 | [diff] [blame] | 2171 | request_params, |
| 2172 | GetUpdateResponse2(OmahaRequestParams::kAppId, |
| 2173 | "1.2.3.4", // version |
| 2174 | "http://more/info", |
| 2175 | "true", // prompt |
| 2176 | "http://code/base/", // dl url |
| 2177 | "file.signed", // file name |
| 2178 | "HASH1234=", // checksum |
| 2179 | "false", // needs admin |
| 2180 | "123", // size |
| 2181 | "", // deadline |
| 2182 | "7", // max days to scatter |
David Zeuthen | 639aa36 | 2014-02-03 16:23:44 -0800 | [diff] [blame] | 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) { |
| 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 |
| 2221 | } |
| 2222 | |
| 2223 | TEST(OmahaRequestActionTest, P2PWithoutPeer) { |
| 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 |
| 2234 | } |
| 2235 | |
| 2236 | TEST(OmahaRequestActionTest, P2PDownloadNotAllowed) { |
| 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 |
| 2247 | } |
| 2248 | |
| 2249 | TEST(OmahaRequestActionTest, P2PWithPeerDownloadDisabledByOmaha) { |
| 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 |
| 2260 | } |
| 2261 | |
| 2262 | TEST(OmahaRequestActionTest, P2PWithPeerSharingDisabledByOmaha) { |
| 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 |
| 2273 | } |
| 2274 | |
| 2275 | TEST(OmahaRequestActionTest, P2PWithPeerBothDisabledByOmaha) { |
| 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 |
| 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 |
David Zeuthen | 639aa36 | 2014-02-03 16:23:44 -0800 | [diff] [blame] | 2296 | kDefaultTestParams, |
| 2297 | GetUpdateResponse2(OmahaRequestParams::kAppId, |
| 2298 | "1.2.3.4", // version |
| 2299 | "http://more/info", |
| 2300 | "true", // prompt |
| 2301 | "http://code/base/", // dl url |
| 2302 | "file.signed", // file name |
| 2303 | "HASH1234=", // checksum |
| 2304 | "false", // needs admin |
| 2305 | "123", // size |
| 2306 | "", // deadline |
| 2307 | "7", // max days to scatter |
| 2308 | elapsed_days, |
| 2309 | false, // disable_p2p_for_downloading |
| 2310 | false), // disable_p2p_for sharing |
| 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 | |
| 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 | |
| 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 | |
| 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 |