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