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