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 | |
| 10 | #include "base/string_util.h" |
Mike Frysinger | 8155d08 | 2012-04-06 15:23:18 -0400 | [diff] [blame] | 11 | #include <base/stringprintf.h> |
Darin Petkov | 1cbd78f | 2010-07-29 12:38:34 -0700 | [diff] [blame] | 12 | #include "base/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; |
Darin Petkov | 6a5b322 | 2010-07-13 14:55:28 -0700 | [diff] [blame] | 37 | |
| 38 | namespace chromeos_update_engine { |
| 39 | |
Jay Srinivasan | ae4697c | 2013-03-18 17:08:08 -0700 | [diff] [blame] | 40 | class OmahaRequestActionTest : public ::testing::Test {}; |
Darin Petkov | 6a5b322 | 2010-07-13 14:55:28 -0700 | [diff] [blame] | 41 | |
| 42 | namespace { |
Jay Srinivasan | 480ddfa | 2012-06-01 19:15:26 -0700 | [diff] [blame] | 43 | |
Jay Srinivasan | ae4697c | 2013-03-18 17:08:08 -0700 | [diff] [blame] | 44 | MockSystemState mock_system_state; |
Jay Srinivasan | 480ddfa | 2012-06-01 19:15:26 -0700 | [diff] [blame] | 45 | OmahaRequestParams kDefaultTestParams( |
Jay Srinivasan | ae4697c | 2013-03-18 17:08:08 -0700 | [diff] [blame] | 46 | &mock_system_state, |
Darin Petkov | 1cbd78f | 2010-07-29 12:38:34 -0700 | [diff] [blame] | 47 | OmahaRequestParams::kOsPlatform, |
| 48 | OmahaRequestParams::kOsVersion, |
| 49 | "service_pack", |
| 50 | "x86-generic", |
| 51 | OmahaRequestParams::kAppId, |
| 52 | "0.1.0.0", |
| 53 | "en-US", |
| 54 | "unittest", |
Darin Petkov | fbb4009 | 2010-07-29 17:05:50 -0700 | [diff] [blame] | 55 | "OEM MODEL 09235 7471", |
Darin Petkov | 1cbd78f | 2010-07-29 12:38:34 -0700 | [diff] [blame] | 56 | false, // delta okay |
Gilad Arnold | bbdd490 | 2013-01-10 16:06:30 -0800 | [diff] [blame] | 57 | false, // interactive |
Jay Srinivasan | 0a70874 | 2012-03-20 11:26:12 -0700 | [diff] [blame] | 58 | "http://url", |
| 59 | false, // update_disabled |
Jay Srinivasan | 480ddfa | 2012-06-01 19:15:26 -0700 | [diff] [blame] | 60 | ""); // target_version_prefix); |
Darin Petkov | 1cbd78f | 2010-07-29 12:38:34 -0700 | [diff] [blame] | 61 | |
Darin Petkov | 6a5b322 | 2010-07-13 14:55:28 -0700 | [diff] [blame] | 62 | string GetNoUpdateResponse(const string& app_id) { |
| 63 | return string( |
Jay Srinivasan | 23b92a5 | 2012-10-27 02:00:21 -0700 | [diff] [blame] | 64 | "<?xml version=\"1.0\" encoding=\"UTF-8\"?><response protocol=\"3.0\">" |
| 65 | "<daystart elapsed_seconds=\"100\"/>" |
| 66 | "<app appid=\"") + app_id + "\" status=\"ok\"><ping " |
| 67 | "status=\"ok\"/><updatecheck status=\"noupdate\"/></app></response>"; |
Darin Petkov | 6a5b322 | 2010-07-13 14:55:28 -0700 | [diff] [blame] | 68 | } |
| 69 | |
Jay Srinivasan | 480ddfa | 2012-06-01 19:15:26 -0700 | [diff] [blame] | 70 | string GetUpdateResponse2(const string& app_id, |
| 71 | const string& display_version, |
| 72 | const string& more_info_url, |
| 73 | const string& prompt, |
| 74 | const string& codebase, |
Jay Srinivasan | 23b92a5 | 2012-10-27 02:00:21 -0700 | [diff] [blame] | 75 | const string& filename, |
Jay Srinivasan | 480ddfa | 2012-06-01 19:15:26 -0700 | [diff] [blame] | 76 | const string& hash, |
| 77 | const string& needsadmin, |
| 78 | const string& size, |
| 79 | const string& deadline, |
Jay Srinivasan | 480ddfa | 2012-06-01 19:15:26 -0700 | [diff] [blame] | 80 | const string& max_days_to_scatter) { |
Jay Srinivasan | 23b92a5 | 2012-10-27 02:00:21 -0700 | [diff] [blame] | 81 | string response = |
| 82 | "<?xml version=\"1.0\" encoding=\"UTF-8\"?><response " |
| 83 | "protocol=\"3.0\">" |
| 84 | "<daystart elapsed_seconds=\"100\"/>" |
| 85 | "<app appid=\"" + app_id + "\" status=\"ok\">" |
| 86 | "<ping status=\"ok\"/><updatecheck status=\"ok\">" |
| 87 | "<urls><url codebase=\"" + codebase + "\"/></urls>" |
| 88 | "<manifest version=\"" + display_version + "\">" |
| 89 | "<packages><package hash=\"not-used\" name=\"" + filename + "\" " |
| 90 | "size=\"" + size + "\"/></packages>" |
| 91 | "<actions><action event=\"postinstall\" " |
| 92 | "DisplayVersion=\"" + display_version + "\" " |
Jay Srinivasan | 480ddfa | 2012-06-01 19:15:26 -0700 | [diff] [blame] | 93 | "ChromeOSVersion=\"" + display_version + "\" " |
| 94 | "MoreInfo=\"" + more_info_url + "\" Prompt=\"" + prompt + "\" " |
| 95 | "IsDelta=\"true\" " |
Jay Srinivasan | d671e97 | 2013-01-11 17:17:19 -0800 | [diff] [blame] | 96 | "IsDeltaPayload=\"true\" " |
Jay Srinivasan | 480ddfa | 2012-06-01 19:15:26 -0700 | [diff] [blame] | 97 | "MaxDaysToScatter=\"" + max_days_to_scatter + "\" " |
Jay Srinivasan | 480ddfa | 2012-06-01 19:15:26 -0700 | [diff] [blame] | 98 | "sha256=\"" + hash + "\" " |
Jay Srinivasan | 23b92a5 | 2012-10-27 02:00:21 -0700 | [diff] [blame] | 99 | "needsadmin=\"" + needsadmin + "\" " + |
Jay Srinivasan | 480ddfa | 2012-06-01 19:15:26 -0700 | [diff] [blame] | 100 | (deadline.empty() ? "" : ("deadline=\"" + deadline + "\" ")) + |
Jay Srinivasan | 23b92a5 | 2012-10-27 02:00:21 -0700 | [diff] [blame] | 101 | "/></actions></manifest></updatecheck></app></response>"; |
| 102 | LOG(INFO) << "Response = " << response; |
| 103 | return response; |
Jay Srinivasan | 480ddfa | 2012-06-01 19:15:26 -0700 | [diff] [blame] | 104 | } |
| 105 | |
Darin Petkov | 6a5b322 | 2010-07-13 14:55:28 -0700 | [diff] [blame] | 106 | string GetUpdateResponse(const string& app_id, |
| 107 | const string& display_version, |
| 108 | const string& more_info_url, |
| 109 | const string& prompt, |
| 110 | const string& codebase, |
Jay Srinivasan | 23b92a5 | 2012-10-27 02:00:21 -0700 | [diff] [blame] | 111 | const string& filename, |
Darin Petkov | 6a5b322 | 2010-07-13 14:55:28 -0700 | [diff] [blame] | 112 | const string& hash, |
| 113 | const string& needsadmin, |
Darin Petkov | 6c11864 | 2010-10-21 12:06:30 -0700 | [diff] [blame] | 114 | const string& size, |
| 115 | const string& deadline) { |
Jay Srinivasan | 480ddfa | 2012-06-01 19:15:26 -0700 | [diff] [blame] | 116 | return GetUpdateResponse2(app_id, |
| 117 | display_version, |
| 118 | more_info_url, |
| 119 | prompt, |
| 120 | codebase, |
Jay Srinivasan | 23b92a5 | 2012-10-27 02:00:21 -0700 | [diff] [blame] | 121 | filename, |
Jay Srinivasan | 480ddfa | 2012-06-01 19:15:26 -0700 | [diff] [blame] | 122 | hash, |
| 123 | needsadmin, |
| 124 | size, |
| 125 | deadline, |
Jay Srinivasan | 480ddfa | 2012-06-01 19:15:26 -0700 | [diff] [blame] | 126 | "7"); |
Darin Petkov | 6a5b322 | 2010-07-13 14:55:28 -0700 | [diff] [blame] | 127 | } |
| 128 | |
| 129 | class OmahaRequestActionTestProcessorDelegate : public ActionProcessorDelegate { |
| 130 | public: |
| 131 | OmahaRequestActionTestProcessorDelegate() |
| 132 | : loop_(NULL), |
Darin Petkov | c1a8b42 | 2010-07-19 11:34:49 -0700 | [diff] [blame] | 133 | expected_code_(kActionCodeSuccess) {} |
Darin Petkov | 6a5b322 | 2010-07-13 14:55:28 -0700 | [diff] [blame] | 134 | virtual ~OmahaRequestActionTestProcessorDelegate() { |
| 135 | } |
Darin Petkov | c1a8b42 | 2010-07-19 11:34:49 -0700 | [diff] [blame] | 136 | virtual void ProcessingDone(const ActionProcessor* processor, |
| 137 | ActionExitCode code) { |
Darin Petkov | 6a5b322 | 2010-07-13 14:55:28 -0700 | [diff] [blame] | 138 | ASSERT_TRUE(loop_); |
| 139 | g_main_loop_quit(loop_); |
| 140 | } |
| 141 | |
| 142 | virtual void ActionCompleted(ActionProcessor* processor, |
| 143 | AbstractAction* action, |
Darin Petkov | c1a8b42 | 2010-07-19 11:34:49 -0700 | [diff] [blame] | 144 | ActionExitCode code) { |
Darin Petkov | 6a5b322 | 2010-07-13 14:55:28 -0700 | [diff] [blame] | 145 | // make sure actions always succeed |
| 146 | if (action->Type() == OmahaRequestAction::StaticType()) |
Darin Petkov | c1a8b42 | 2010-07-19 11:34:49 -0700 | [diff] [blame] | 147 | EXPECT_EQ(expected_code_, code); |
Darin Petkov | 6a5b322 | 2010-07-13 14:55:28 -0700 | [diff] [blame] | 148 | else |
Darin Petkov | c1a8b42 | 2010-07-19 11:34:49 -0700 | [diff] [blame] | 149 | EXPECT_EQ(kActionCodeSuccess, code); |
Darin Petkov | 6a5b322 | 2010-07-13 14:55:28 -0700 | [diff] [blame] | 150 | } |
| 151 | GMainLoop *loop_; |
Darin Petkov | c1a8b42 | 2010-07-19 11:34:49 -0700 | [diff] [blame] | 152 | ActionExitCode expected_code_; |
Darin Petkov | 6a5b322 | 2010-07-13 14:55:28 -0700 | [diff] [blame] | 153 | }; |
| 154 | |
| 155 | gboolean StartProcessorInRunLoop(gpointer data) { |
| 156 | ActionProcessor *processor = reinterpret_cast<ActionProcessor*>(data); |
| 157 | processor->StartProcessing(); |
| 158 | return FALSE; |
| 159 | } |
Darin Petkov | 6a5b322 | 2010-07-13 14:55:28 -0700 | [diff] [blame] | 160 | } // namespace {} |
| 161 | |
| 162 | class OutputObjectCollectorAction; |
| 163 | |
| 164 | template<> |
| 165 | class ActionTraits<OutputObjectCollectorAction> { |
| 166 | public: |
| 167 | // Does not take an object for input |
| 168 | typedef OmahaResponse InputObjectType; |
| 169 | // On success, puts the output path on output |
| 170 | typedef NoneType OutputObjectType; |
| 171 | }; |
| 172 | |
| 173 | class OutputObjectCollectorAction : public Action<OutputObjectCollectorAction> { |
| 174 | public: |
| 175 | OutputObjectCollectorAction() : has_input_object_(false) {} |
| 176 | void PerformAction() { |
| 177 | // copy input object |
| 178 | has_input_object_ = HasInputObject(); |
| 179 | if (has_input_object_) |
| 180 | omaha_response_ = GetInputObject(); |
Darin Petkov | c1a8b42 | 2010-07-19 11:34:49 -0700 | [diff] [blame] | 181 | processor_->ActionComplete(this, kActionCodeSuccess); |
Darin Petkov | 6a5b322 | 2010-07-13 14:55:28 -0700 | [diff] [blame] | 182 | } |
| 183 | // Should never be called |
| 184 | void TerminateProcessing() { |
| 185 | CHECK(false); |
| 186 | } |
| 187 | // Debugging/logging |
| 188 | static std::string StaticType() { |
| 189 | return "OutputObjectCollectorAction"; |
| 190 | } |
| 191 | std::string Type() const { return StaticType(); } |
| 192 | bool has_input_object_; |
| 193 | OmahaResponse omaha_response_; |
| 194 | }; |
| 195 | |
Darin Petkov | 1cbd78f | 2010-07-29 12:38:34 -0700 | [diff] [blame] | 196 | // Returns true iff an output response was obtained from the |
Darin Petkov | edc522e | 2010-11-05 09:35:17 -0700 | [diff] [blame] | 197 | // OmahaRequestAction. |prefs| may be NULL, in which case a local PrefsMock is |
Darin Petkov | 265f290 | 2011-05-09 15:17:40 -0700 | [diff] [blame] | 198 | // used. out_response may be NULL. If |fail_http_response_code| is non-negative, |
| 199 | // the transfer will fail with that code. |ping_only| is passed through to the |
| 200 | // OmahaRequestAction constructor. out_post_data may be null; if non-null, the |
| 201 | // post-data received by the mock HttpFetcher is returned. |
Darin Petkov | 1cbd78f | 2010-07-29 12:38:34 -0700 | [diff] [blame] | 202 | bool TestUpdateCheck(PrefsInterface* prefs, |
Jay Srinivasan | 480ddfa | 2012-06-01 19:15:26 -0700 | [diff] [blame] | 203 | OmahaRequestParams params, |
Darin Petkov | 0dc8e9a | 2010-07-14 14:51:57 -0700 | [diff] [blame] | 204 | const string& http_response, |
Darin Petkov | edc522e | 2010-11-05 09:35:17 -0700 | [diff] [blame] | 205 | int fail_http_response_code, |
Darin Petkov | 265f290 | 2011-05-09 15:17:40 -0700 | [diff] [blame] | 206 | bool ping_only, |
Darin Petkov | c1a8b42 | 2010-07-19 11:34:49 -0700 | [diff] [blame] | 207 | ActionExitCode expected_code, |
Darin Petkov | 0dc8e9a | 2010-07-14 14:51:57 -0700 | [diff] [blame] | 208 | OmahaResponse* out_response, |
| 209 | vector<char>* out_post_data) { |
| 210 | GMainLoop* loop = g_main_loop_new(g_main_context_default(), FALSE); |
| 211 | MockHttpFetcher* fetcher = new MockHttpFetcher(http_response.data(), |
Andrew de los Reyes | 4516810 | 2010-11-22 11:13:50 -0800 | [diff] [blame] | 212 | http_response.size(), |
| 213 | NULL); |
Darin Petkov | edc522e | 2010-11-05 09:35:17 -0700 | [diff] [blame] | 214 | if (fail_http_response_code >= 0) { |
| 215 | fetcher->FailTransfer(fail_http_response_code); |
| 216 | } |
Jay Srinivasan | 6f6ea00 | 2012-12-14 11:26:28 -0800 | [diff] [blame] | 217 | MockSystemState mock_system_state; |
| 218 | if (prefs) |
| 219 | mock_system_state.set_prefs(prefs); |
Jay Srinivasan | ae4697c | 2013-03-18 17:08:08 -0700 | [diff] [blame] | 220 | mock_system_state.set_request_params(¶ms); |
Jay Srinivasan | 6f6ea00 | 2012-12-14 11:26:28 -0800 | [diff] [blame] | 221 | OmahaRequestAction action(&mock_system_state, |
Darin Petkov | 1cbd78f | 2010-07-29 12:38:34 -0700 | [diff] [blame] | 222 | NULL, |
Thieu Le | 116fda3 | 2011-04-19 11:01:54 -0700 | [diff] [blame] | 223 | fetcher, |
Darin Petkov | 265f290 | 2011-05-09 15:17:40 -0700 | [diff] [blame] | 224 | ping_only); |
Darin Petkov | 6a5b322 | 2010-07-13 14:55:28 -0700 | [diff] [blame] | 225 | OmahaRequestActionTestProcessorDelegate delegate; |
| 226 | delegate.loop_ = loop; |
Darin Petkov | c1a8b42 | 2010-07-19 11:34:49 -0700 | [diff] [blame] | 227 | delegate.expected_code_ = expected_code; |
Darin Petkov | a4a8a8c | 2010-07-15 22:21:12 -0700 | [diff] [blame] | 228 | |
Darin Petkov | 6a5b322 | 2010-07-13 14:55:28 -0700 | [diff] [blame] | 229 | ActionProcessor processor; |
Darin Petkov | 6a5b322 | 2010-07-13 14:55:28 -0700 | [diff] [blame] | 230 | processor.set_delegate(&delegate); |
Darin Petkov | 6a5b322 | 2010-07-13 14:55:28 -0700 | [diff] [blame] | 231 | processor.EnqueueAction(&action); |
| 232 | |
| 233 | OutputObjectCollectorAction collector_action; |
Darin Petkov | 6a5b322 | 2010-07-13 14:55:28 -0700 | [diff] [blame] | 234 | BondActions(&action, &collector_action); |
| 235 | processor.EnqueueAction(&collector_action); |
| 236 | |
| 237 | g_timeout_add(0, &StartProcessorInRunLoop, &processor); |
| 238 | g_main_loop_run(loop); |
| 239 | g_main_loop_unref(loop); |
| 240 | if (collector_action.has_input_object_ && out_response) |
| 241 | *out_response = collector_action.omaha_response_; |
| 242 | if (out_post_data) |
| 243 | *out_post_data = fetcher->post_data(); |
| 244 | return collector_action.has_input_object_; |
| 245 | } |
| 246 | |
Darin Petkov | 0dc8e9a | 2010-07-14 14:51:57 -0700 | [diff] [blame] | 247 | // Tests Event requests -- they should always succeed. |out_post_data| |
| 248 | // may be null; if non-null, the post-data received by the mock |
| 249 | // HttpFetcher is returned. |
Jay Srinivasan | 480ddfa | 2012-06-01 19:15:26 -0700 | [diff] [blame] | 250 | void TestEvent(OmahaRequestParams params, |
Darin Petkov | 0dc8e9a | 2010-07-14 14:51:57 -0700 | [diff] [blame] | 251 | OmahaEvent* event, |
| 252 | const string& http_response, |
| 253 | vector<char>* out_post_data) { |
| 254 | GMainLoop* loop = g_main_loop_new(g_main_context_default(), FALSE); |
| 255 | MockHttpFetcher* fetcher = new MockHttpFetcher(http_response.data(), |
Andrew de los Reyes | 4516810 | 2010-11-22 11:13:50 -0800 | [diff] [blame] | 256 | http_response.size(), |
| 257 | NULL); |
Jay Srinivasan | 6f6ea00 | 2012-12-14 11:26:28 -0800 | [diff] [blame] | 258 | MockSystemState mock_system_state; |
Jay Srinivasan | ae4697c | 2013-03-18 17:08:08 -0700 | [diff] [blame] | 259 | mock_system_state.set_request_params(¶ms); |
| 260 | OmahaRequestAction action(&mock_system_state, event, fetcher, false); |
Darin Petkov | 0dc8e9a | 2010-07-14 14:51:57 -0700 | [diff] [blame] | 261 | OmahaRequestActionTestProcessorDelegate delegate; |
| 262 | delegate.loop_ = loop; |
| 263 | ActionProcessor processor; |
Darin Petkov | 0dc8e9a | 2010-07-14 14:51:57 -0700 | [diff] [blame] | 264 | processor.set_delegate(&delegate); |
Darin Petkov | 0dc8e9a | 2010-07-14 14:51:57 -0700 | [diff] [blame] | 265 | processor.EnqueueAction(&action); |
| 266 | |
Darin Petkov | 0dc8e9a | 2010-07-14 14:51:57 -0700 | [diff] [blame] | 267 | g_timeout_add(0, &StartProcessorInRunLoop, &processor); |
| 268 | g_main_loop_run(loop); |
| 269 | g_main_loop_unref(loop); |
| 270 | if (out_post_data) |
| 271 | *out_post_data = fetcher->post_data(); |
| 272 | } |
| 273 | |
Darin Petkov | 6a5b322 | 2010-07-13 14:55:28 -0700 | [diff] [blame] | 274 | TEST(OmahaRequestActionTest, NoUpdateTest) { |
Darin Petkov | 6a5b322 | 2010-07-13 14:55:28 -0700 | [diff] [blame] | 275 | OmahaResponse response; |
| 276 | ASSERT_TRUE( |
Darin Petkov | 1cbd78f | 2010-07-29 12:38:34 -0700 | [diff] [blame] | 277 | TestUpdateCheck(NULL, // prefs |
| 278 | kDefaultTestParams, |
Darin Petkov | 0dc8e9a | 2010-07-14 14:51:57 -0700 | [diff] [blame] | 279 | GetNoUpdateResponse(OmahaRequestParams::kAppId), |
Darin Petkov | edc522e | 2010-11-05 09:35:17 -0700 | [diff] [blame] | 280 | -1, |
Darin Petkov | 265f290 | 2011-05-09 15:17:40 -0700 | [diff] [blame] | 281 | false, // ping_only |
Darin Petkov | c1a8b42 | 2010-07-19 11:34:49 -0700 | [diff] [blame] | 282 | kActionCodeSuccess, |
Darin Petkov | 0dc8e9a | 2010-07-14 14:51:57 -0700 | [diff] [blame] | 283 | &response, |
| 284 | NULL)); |
Darin Petkov | 6a5b322 | 2010-07-13 14:55:28 -0700 | [diff] [blame] | 285 | EXPECT_FALSE(response.update_exists); |
| 286 | } |
| 287 | |
| 288 | TEST(OmahaRequestActionTest, ValidUpdateTest) { |
Darin Petkov | 6a5b322 | 2010-07-13 14:55:28 -0700 | [diff] [blame] | 289 | OmahaResponse response; |
| 290 | ASSERT_TRUE( |
Darin Petkov | 1cbd78f | 2010-07-29 12:38:34 -0700 | [diff] [blame] | 291 | TestUpdateCheck(NULL, // prefs |
| 292 | kDefaultTestParams, |
Darin Petkov | 0dc8e9a | 2010-07-14 14:51:57 -0700 | [diff] [blame] | 293 | GetUpdateResponse(OmahaRequestParams::kAppId, |
| 294 | "1.2.3.4", // version |
| 295 | "http://more/info", |
| 296 | "true", // prompt |
Jay Srinivasan | 23b92a5 | 2012-10-27 02:00:21 -0700 | [diff] [blame] | 297 | "http://code/base/", // dl url |
| 298 | "file.signed", // file name |
Darin Petkov | 0dc8e9a | 2010-07-14 14:51:57 -0700 | [diff] [blame] | 299 | "HASH1234=", // checksum |
| 300 | "false", // needs admin |
Darin Petkov | 6c11864 | 2010-10-21 12:06:30 -0700 | [diff] [blame] | 301 | "123", // size |
| 302 | "20101020"), // deadline |
Darin Petkov | edc522e | 2010-11-05 09:35:17 -0700 | [diff] [blame] | 303 | -1, |
Darin Petkov | 265f290 | 2011-05-09 15:17:40 -0700 | [diff] [blame] | 304 | false, // ping_only |
Darin Petkov | c1a8b42 | 2010-07-19 11:34:49 -0700 | [diff] [blame] | 305 | kActionCodeSuccess, |
Darin Petkov | 0dc8e9a | 2010-07-14 14:51:57 -0700 | [diff] [blame] | 306 | &response, |
| 307 | NULL)); |
Darin Petkov | 6a5b322 | 2010-07-13 14:55:28 -0700 | [diff] [blame] | 308 | EXPECT_TRUE(response.update_exists); |
Jay Srinivasan | 34b5d86 | 2012-07-23 11:43:22 -0700 | [diff] [blame] | 309 | EXPECT_TRUE(response.update_exists); |
Darin Petkov | 6a5b322 | 2010-07-13 14:55:28 -0700 | [diff] [blame] | 310 | EXPECT_EQ("1.2.3.4", response.display_version); |
Jay Srinivasan | 6f6ea00 | 2012-12-14 11:26:28 -0800 | [diff] [blame] | 311 | EXPECT_EQ("http://code/base/file.signed", response.payload_urls[0]); |
Darin Petkov | 6a5b322 | 2010-07-13 14:55:28 -0700 | [diff] [blame] | 312 | EXPECT_EQ("http://more/info", response.more_info_url); |
| 313 | EXPECT_EQ("HASH1234=", response.hash); |
| 314 | EXPECT_EQ(123, response.size); |
Darin Petkov | 6a5b322 | 2010-07-13 14:55:28 -0700 | [diff] [blame] | 315 | EXPECT_TRUE(response.prompt); |
Darin Petkov | 6c11864 | 2010-10-21 12:06:30 -0700 | [diff] [blame] | 316 | EXPECT_EQ("20101020", response.deadline); |
Darin Petkov | 6a5b322 | 2010-07-13 14:55:28 -0700 | [diff] [blame] | 317 | } |
| 318 | |
Jay Srinivasan | 0a70874 | 2012-03-20 11:26:12 -0700 | [diff] [blame] | 319 | TEST(OmahaRequestActionTest, ValidUpdateBlockedByPolicyTest) { |
| 320 | OmahaResponse response; |
| 321 | OmahaRequestParams params = kDefaultTestParams; |
Jay Srinivasan | ae4697c | 2013-03-18 17:08:08 -0700 | [diff] [blame] | 322 | params.set_update_disabled(true); |
Jay Srinivasan | 0a70874 | 2012-03-20 11:26:12 -0700 | [diff] [blame] | 323 | ASSERT_FALSE( |
| 324 | TestUpdateCheck(NULL, // prefs |
| 325 | params, |
| 326 | GetUpdateResponse(OmahaRequestParams::kAppId, |
| 327 | "1.2.3.4", // version |
| 328 | "http://more/info", |
| 329 | "true", // prompt |
Jay Srinivasan | 23b92a5 | 2012-10-27 02:00:21 -0700 | [diff] [blame] | 330 | "http://code/base/", // dl url |
| 331 | "file.signed", // file name |
Jay Srinivasan | 0a70874 | 2012-03-20 11:26:12 -0700 | [diff] [blame] | 332 | "HASH1234=", // checksum |
| 333 | "false", // needs admin |
| 334 | "123", // size |
Jay Srinivasan | 480ddfa | 2012-06-01 19:15:26 -0700 | [diff] [blame] | 335 | ""), // deadline |
Jay Srinivasan | 0a70874 | 2012-03-20 11:26:12 -0700 | [diff] [blame] | 336 | -1, |
| 337 | false, // ping_only |
| 338 | kActionCodeOmahaUpdateIgnoredPerPolicy, |
| 339 | &response, |
| 340 | NULL)); |
| 341 | EXPECT_FALSE(response.update_exists); |
| 342 | } |
| 343 | |
Jay Srinivasan | 0a70874 | 2012-03-20 11:26:12 -0700 | [diff] [blame] | 344 | TEST(OmahaRequestActionTest, NoUpdatesSentWhenBlockedByPolicyTest) { |
| 345 | OmahaResponse response; |
| 346 | OmahaRequestParams params = kDefaultTestParams; |
Jay Srinivasan | ae4697c | 2013-03-18 17:08:08 -0700 | [diff] [blame] | 347 | params.set_update_disabled(true); |
Jay Srinivasan | 0a70874 | 2012-03-20 11:26:12 -0700 | [diff] [blame] | 348 | ASSERT_TRUE( |
| 349 | TestUpdateCheck(NULL, // prefs |
| 350 | params, |
| 351 | GetNoUpdateResponse(OmahaRequestParams::kAppId), |
| 352 | -1, |
| 353 | false, // ping_only |
| 354 | kActionCodeSuccess, |
| 355 | &response, |
| 356 | NULL)); |
| 357 | EXPECT_FALSE(response.update_exists); |
| 358 | } |
| 359 | |
Jay Srinivasan | 480ddfa | 2012-06-01 19:15:26 -0700 | [diff] [blame] | 360 | TEST(OmahaRequestActionTest, WallClockBasedWaitAloneCausesScattering) { |
| 361 | OmahaResponse response; |
| 362 | OmahaRequestParams params = kDefaultTestParams; |
Jay Srinivasan | ae4697c | 2013-03-18 17:08:08 -0700 | [diff] [blame] | 363 | params.set_wall_clock_based_wait_enabled(true); |
| 364 | params.set_update_check_count_wait_enabled(false); |
| 365 | params.set_waiting_period(TimeDelta::FromDays(2)); |
Jay Srinivasan | 480ddfa | 2012-06-01 19:15:26 -0700 | [diff] [blame] | 366 | |
| 367 | string prefs_dir; |
| 368 | EXPECT_TRUE(utils::MakeTempDirectory("/tmp/ue_ut_prefs.XXXXXX", |
| 369 | &prefs_dir)); |
| 370 | ScopedDirRemover temp_dir_remover(prefs_dir); |
| 371 | |
| 372 | Prefs prefs; |
| 373 | LOG_IF(ERROR, !prefs.Init(FilePath(prefs_dir))) |
| 374 | << "Failed to initialize preferences."; |
| 375 | |
| 376 | ASSERT_FALSE( |
| 377 | TestUpdateCheck(&prefs, // prefs |
| 378 | params, |
| 379 | GetUpdateResponse2(OmahaRequestParams::kAppId, |
| 380 | "1.2.3.4", // version |
| 381 | "http://more/info", |
| 382 | "true", // prompt |
Jay Srinivasan | 23b92a5 | 2012-10-27 02:00:21 -0700 | [diff] [blame] | 383 | "http://code/base/", // dl url |
| 384 | "file.signed", // file name |
Jay Srinivasan | 480ddfa | 2012-06-01 19:15:26 -0700 | [diff] [blame] | 385 | "HASH1234=", // checksum |
| 386 | "false", // needs admin |
| 387 | "123", // size |
| 388 | "", // deadline |
Jay Srinivasan | 480ddfa | 2012-06-01 19:15:26 -0700 | [diff] [blame] | 389 | "7"), // max days to scatter |
| 390 | -1, |
| 391 | false, // ping_only |
| 392 | kActionCodeOmahaUpdateDeferredPerPolicy, |
| 393 | &response, |
| 394 | NULL)); |
| 395 | EXPECT_FALSE(response.update_exists); |
| 396 | } |
| 397 | |
| 398 | TEST(OmahaRequestActionTest, NoWallClockBasedWaitCausesNoScattering) { |
| 399 | OmahaResponse response; |
| 400 | OmahaRequestParams params = kDefaultTestParams; |
Jay Srinivasan | ae4697c | 2013-03-18 17:08:08 -0700 | [diff] [blame] | 401 | params.set_wall_clock_based_wait_enabled(false); |
| 402 | params.set_waiting_period(TimeDelta::FromDays(2)); |
Jay Srinivasan | 480ddfa | 2012-06-01 19:15:26 -0700 | [diff] [blame] | 403 | |
Jay Srinivasan | ae4697c | 2013-03-18 17:08:08 -0700 | [diff] [blame] | 404 | params.set_update_check_count_wait_enabled(true); |
| 405 | params.set_min_update_checks_needed(1); |
| 406 | params.set_max_update_checks_allowed(8); |
Jay Srinivasan | 480ddfa | 2012-06-01 19:15:26 -0700 | [diff] [blame] | 407 | |
| 408 | string prefs_dir; |
| 409 | EXPECT_TRUE(utils::MakeTempDirectory("/tmp/ue_ut_prefs.XXXXXX", |
| 410 | &prefs_dir)); |
| 411 | ScopedDirRemover temp_dir_remover(prefs_dir); |
| 412 | |
| 413 | Prefs prefs; |
| 414 | LOG_IF(ERROR, !prefs.Init(FilePath(prefs_dir))) |
| 415 | << "Failed to initialize preferences."; |
| 416 | |
| 417 | ASSERT_TRUE( |
| 418 | TestUpdateCheck(&prefs, // prefs |
| 419 | params, |
| 420 | GetUpdateResponse2(OmahaRequestParams::kAppId, |
| 421 | "1.2.3.4", // version |
| 422 | "http://more/info", |
| 423 | "true", // prompt |
Jay Srinivasan | 23b92a5 | 2012-10-27 02:00:21 -0700 | [diff] [blame] | 424 | "http://code/base/", // dl url |
| 425 | "file.signed", // file name |
Jay Srinivasan | 480ddfa | 2012-06-01 19:15:26 -0700 | [diff] [blame] | 426 | "HASH1234=", // checksum |
| 427 | "false", // needs admin |
| 428 | "123", // size |
| 429 | "", // deadline |
Jay Srinivasan | 480ddfa | 2012-06-01 19:15:26 -0700 | [diff] [blame] | 430 | "7"), // max days to scatter |
| 431 | -1, |
| 432 | false, // ping_only |
| 433 | kActionCodeSuccess, |
| 434 | &response, |
| 435 | NULL)); |
| 436 | EXPECT_TRUE(response.update_exists); |
| 437 | } |
| 438 | |
| 439 | TEST(OmahaRequestActionTest, ZeroMaxDaysToScatterCausesNoScattering) { |
| 440 | OmahaResponse response; |
| 441 | OmahaRequestParams params = kDefaultTestParams; |
Jay Srinivasan | ae4697c | 2013-03-18 17:08:08 -0700 | [diff] [blame] | 442 | params.set_wall_clock_based_wait_enabled(true); |
| 443 | params.set_waiting_period(TimeDelta::FromDays(2)); |
Jay Srinivasan | 480ddfa | 2012-06-01 19:15:26 -0700 | [diff] [blame] | 444 | |
Jay Srinivasan | ae4697c | 2013-03-18 17:08:08 -0700 | [diff] [blame] | 445 | params.set_update_check_count_wait_enabled(true); |
| 446 | params.set_min_update_checks_needed(1); |
| 447 | params.set_max_update_checks_allowed(8); |
Jay Srinivasan | 480ddfa | 2012-06-01 19:15:26 -0700 | [diff] [blame] | 448 | |
| 449 | string prefs_dir; |
| 450 | EXPECT_TRUE(utils::MakeTempDirectory("/tmp/ue_ut_prefs.XXXXXX", |
| 451 | &prefs_dir)); |
| 452 | ScopedDirRemover temp_dir_remover(prefs_dir); |
| 453 | |
| 454 | Prefs prefs; |
| 455 | LOG_IF(ERROR, !prefs.Init(FilePath(prefs_dir))) |
| 456 | << "Failed to initialize preferences."; |
| 457 | |
| 458 | ASSERT_TRUE( |
| 459 | TestUpdateCheck(&prefs, // prefs |
| 460 | params, |
| 461 | GetUpdateResponse2(OmahaRequestParams::kAppId, |
| 462 | "1.2.3.4", // version |
| 463 | "http://more/info", |
| 464 | "true", // prompt |
Jay Srinivasan | 23b92a5 | 2012-10-27 02:00:21 -0700 | [diff] [blame] | 465 | "http://code/base/", // dl url |
| 466 | "file.signed", // file name |
Jay Srinivasan | 480ddfa | 2012-06-01 19:15:26 -0700 | [diff] [blame] | 467 | "HASH1234=", // checksum |
| 468 | "false", // needs admin |
| 469 | "123", // size |
| 470 | "", // deadline |
Jay Srinivasan | 480ddfa | 2012-06-01 19:15:26 -0700 | [diff] [blame] | 471 | "0"), // max days to scatter |
| 472 | -1, |
| 473 | false, // ping_only |
| 474 | kActionCodeSuccess, |
| 475 | &response, |
| 476 | NULL)); |
| 477 | EXPECT_TRUE(response.update_exists); |
| 478 | } |
| 479 | |
| 480 | |
| 481 | TEST(OmahaRequestActionTest, ZeroUpdateCheckCountCausesNoScattering) { |
| 482 | OmahaResponse response; |
| 483 | OmahaRequestParams params = kDefaultTestParams; |
Jay Srinivasan | ae4697c | 2013-03-18 17:08:08 -0700 | [diff] [blame] | 484 | params.set_wall_clock_based_wait_enabled(true); |
| 485 | params.set_waiting_period(TimeDelta()); |
Jay Srinivasan | 480ddfa | 2012-06-01 19:15:26 -0700 | [diff] [blame] | 486 | |
Jay Srinivasan | ae4697c | 2013-03-18 17:08:08 -0700 | [diff] [blame] | 487 | params.set_update_check_count_wait_enabled(true); |
| 488 | params.set_min_update_checks_needed(0); |
| 489 | params.set_max_update_checks_allowed(0); |
Jay Srinivasan | 480ddfa | 2012-06-01 19:15:26 -0700 | [diff] [blame] | 490 | |
| 491 | string prefs_dir; |
| 492 | EXPECT_TRUE(utils::MakeTempDirectory("/tmp/ue_ut_prefs.XXXXXX", |
| 493 | &prefs_dir)); |
| 494 | ScopedDirRemover temp_dir_remover(prefs_dir); |
| 495 | |
| 496 | Prefs prefs; |
| 497 | LOG_IF(ERROR, !prefs.Init(FilePath(prefs_dir))) |
| 498 | << "Failed to initialize preferences."; |
| 499 | |
| 500 | ASSERT_TRUE(TestUpdateCheck( |
| 501 | &prefs, // prefs |
| 502 | params, |
| 503 | GetUpdateResponse2(OmahaRequestParams::kAppId, |
| 504 | "1.2.3.4", // version |
| 505 | "http://more/info", |
| 506 | "true", // prompt |
Jay Srinivasan | 23b92a5 | 2012-10-27 02:00:21 -0700 | [diff] [blame] | 507 | "http://code/base/", // dl url |
| 508 | "file.signed", // file name |
Jay Srinivasan | 480ddfa | 2012-06-01 19:15:26 -0700 | [diff] [blame] | 509 | "HASH1234=", // checksum |
| 510 | "false", // needs admin |
| 511 | "123", // size |
| 512 | "", // deadline |
Jay Srinivasan | 480ddfa | 2012-06-01 19:15:26 -0700 | [diff] [blame] | 513 | "7"), // max days to scatter |
| 514 | -1, |
| 515 | false, // ping_only |
| 516 | kActionCodeSuccess, |
| 517 | &response, |
| 518 | NULL)); |
| 519 | |
| 520 | int64 count; |
| 521 | ASSERT_TRUE(prefs.GetInt64(kPrefsUpdateCheckCount, &count)); |
| 522 | ASSERT_TRUE(count == 0); |
| 523 | EXPECT_TRUE(response.update_exists); |
| 524 | } |
| 525 | |
| 526 | TEST(OmahaRequestActionTest, NonZeroUpdateCheckCountCausesScattering) { |
| 527 | OmahaResponse response; |
| 528 | OmahaRequestParams params = kDefaultTestParams; |
Jay Srinivasan | ae4697c | 2013-03-18 17:08:08 -0700 | [diff] [blame] | 529 | params.set_wall_clock_based_wait_enabled(true); |
| 530 | params.set_waiting_period(TimeDelta()); |
Jay Srinivasan | 480ddfa | 2012-06-01 19:15:26 -0700 | [diff] [blame] | 531 | |
Jay Srinivasan | ae4697c | 2013-03-18 17:08:08 -0700 | [diff] [blame] | 532 | params.set_update_check_count_wait_enabled(true); |
| 533 | params.set_min_update_checks_needed(1); |
| 534 | params.set_max_update_checks_allowed(8); |
Jay Srinivasan | 480ddfa | 2012-06-01 19:15:26 -0700 | [diff] [blame] | 535 | |
| 536 | string prefs_dir; |
| 537 | EXPECT_TRUE(utils::MakeTempDirectory("/tmp/ue_ut_prefs.XXXXXX", |
| 538 | &prefs_dir)); |
| 539 | ScopedDirRemover temp_dir_remover(prefs_dir); |
| 540 | |
| 541 | Prefs prefs; |
| 542 | LOG_IF(ERROR, !prefs.Init(FilePath(prefs_dir))) |
| 543 | << "Failed to initialize preferences."; |
| 544 | |
| 545 | ASSERT_FALSE(TestUpdateCheck( |
| 546 | &prefs, // prefs |
| 547 | params, |
| 548 | GetUpdateResponse2(OmahaRequestParams::kAppId, |
| 549 | "1.2.3.4", // version |
| 550 | "http://more/info", |
| 551 | "true", // prompt |
Jay Srinivasan | 23b92a5 | 2012-10-27 02:00:21 -0700 | [diff] [blame] | 552 | "http://code/base/", // dl url |
| 553 | "file.signed", // file name |
Jay Srinivasan | 480ddfa | 2012-06-01 19:15:26 -0700 | [diff] [blame] | 554 | "HASH1234=", // checksum |
| 555 | "false", // needs admin |
| 556 | "123", // size |
| 557 | "", // deadline |
Jay Srinivasan | 480ddfa | 2012-06-01 19:15:26 -0700 | [diff] [blame] | 558 | "7"), // max days to scatter |
| 559 | -1, |
| 560 | false, // ping_only |
| 561 | kActionCodeOmahaUpdateDeferredPerPolicy, |
| 562 | &response, |
| 563 | NULL)); |
| 564 | |
| 565 | int64 count; |
| 566 | ASSERT_TRUE(prefs.GetInt64(kPrefsUpdateCheckCount, &count)); |
| 567 | ASSERT_TRUE(count > 0); |
| 568 | EXPECT_FALSE(response.update_exists); |
| 569 | } |
| 570 | |
| 571 | TEST(OmahaRequestActionTest, ExistingUpdateCheckCountCausesScattering) { |
| 572 | OmahaResponse response; |
| 573 | OmahaRequestParams params = kDefaultTestParams; |
Jay Srinivasan | ae4697c | 2013-03-18 17:08:08 -0700 | [diff] [blame] | 574 | params.set_wall_clock_based_wait_enabled(true); |
| 575 | params.set_waiting_period(TimeDelta()); |
Jay Srinivasan | 480ddfa | 2012-06-01 19:15:26 -0700 | [diff] [blame] | 576 | |
Jay Srinivasan | ae4697c | 2013-03-18 17:08:08 -0700 | [diff] [blame] | 577 | params.set_update_check_count_wait_enabled(true); |
| 578 | params.set_min_update_checks_needed(1); |
| 579 | params.set_max_update_checks_allowed(8); |
Jay Srinivasan | 480ddfa | 2012-06-01 19:15:26 -0700 | [diff] [blame] | 580 | |
| 581 | string prefs_dir; |
| 582 | EXPECT_TRUE(utils::MakeTempDirectory("/tmp/ue_ut_prefs.XXXXXX", |
| 583 | &prefs_dir)); |
| 584 | ScopedDirRemover temp_dir_remover(prefs_dir); |
| 585 | |
| 586 | Prefs prefs; |
| 587 | LOG_IF(ERROR, !prefs.Init(FilePath(prefs_dir))) |
| 588 | << "Failed to initialize preferences."; |
| 589 | |
| 590 | ASSERT_TRUE(prefs.SetInt64(kPrefsUpdateCheckCount, 5)); |
| 591 | |
| 592 | ASSERT_FALSE(TestUpdateCheck( |
| 593 | &prefs, // prefs |
| 594 | params, |
| 595 | GetUpdateResponse2(OmahaRequestParams::kAppId, |
| 596 | "1.2.3.4", // version |
| 597 | "http://more/info", |
| 598 | "true", // prompt |
Jay Srinivasan | 23b92a5 | 2012-10-27 02:00:21 -0700 | [diff] [blame] | 599 | "http://code/base/", // dl url |
| 600 | "file.signed", // file name |
Jay Srinivasan | 480ddfa | 2012-06-01 19:15:26 -0700 | [diff] [blame] | 601 | "HASH1234=", // checksum |
| 602 | "false", // needs admin |
| 603 | "123", // size |
| 604 | "", // deadline |
Jay Srinivasan | 480ddfa | 2012-06-01 19:15:26 -0700 | [diff] [blame] | 605 | "7"), // max days to scatter |
| 606 | -1, |
| 607 | false, // ping_only |
| 608 | kActionCodeOmahaUpdateDeferredPerPolicy, |
| 609 | &response, |
| 610 | NULL)); |
| 611 | |
| 612 | int64 count; |
| 613 | ASSERT_TRUE(prefs.GetInt64(kPrefsUpdateCheckCount, &count)); |
| 614 | // count remains the same, as the decrementing happens in update_attempter |
| 615 | // which this test doesn't exercise. |
| 616 | ASSERT_TRUE(count == 5); |
| 617 | EXPECT_FALSE(response.update_exists); |
| 618 | } |
Jay Srinivasan | 0a70874 | 2012-03-20 11:26:12 -0700 | [diff] [blame] | 619 | |
Darin Petkov | 6a5b322 | 2010-07-13 14:55:28 -0700 | [diff] [blame] | 620 | TEST(OmahaRequestActionTest, NoOutputPipeTest) { |
Darin Petkov | 6a5b322 | 2010-07-13 14:55:28 -0700 | [diff] [blame] | 621 | const string http_response(GetNoUpdateResponse(OmahaRequestParams::kAppId)); |
| 622 | |
| 623 | GMainLoop *loop = g_main_loop_new(g_main_context_default(), FALSE); |
| 624 | |
Jay Srinivasan | 6f6ea00 | 2012-12-14 11:26:28 -0800 | [diff] [blame] | 625 | MockSystemState mock_system_state; |
Jay Srinivasan | 480ddfa | 2012-06-01 19:15:26 -0700 | [diff] [blame] | 626 | OmahaRequestParams params = kDefaultTestParams; |
Jay Srinivasan | ae4697c | 2013-03-18 17:08:08 -0700 | [diff] [blame] | 627 | mock_system_state.set_request_params(¶ms); |
| 628 | OmahaRequestAction action(&mock_system_state, NULL, |
Darin Petkov | 0dc8e9a | 2010-07-14 14:51:57 -0700 | [diff] [blame] | 629 | new MockHttpFetcher(http_response.data(), |
Andrew de los Reyes | 4516810 | 2010-11-22 11:13:50 -0800 | [diff] [blame] | 630 | http_response.size(), |
Thieu Le | 116fda3 | 2011-04-19 11:01:54 -0700 | [diff] [blame] | 631 | NULL), |
| 632 | false); |
Darin Petkov | 6a5b322 | 2010-07-13 14:55:28 -0700 | [diff] [blame] | 633 | OmahaRequestActionTestProcessorDelegate delegate; |
| 634 | delegate.loop_ = loop; |
| 635 | ActionProcessor processor; |
| 636 | processor.set_delegate(&delegate); |
Darin Petkov | 6a5b322 | 2010-07-13 14:55:28 -0700 | [diff] [blame] | 637 | processor.EnqueueAction(&action); |
Darin Petkov | 6a5b322 | 2010-07-13 14:55:28 -0700 | [diff] [blame] | 638 | |
| 639 | g_timeout_add(0, &StartProcessorInRunLoop, &processor); |
| 640 | g_main_loop_run(loop); |
| 641 | g_main_loop_unref(loop); |
| 642 | EXPECT_FALSE(processor.IsRunning()); |
| 643 | } |
| 644 | |
| 645 | TEST(OmahaRequestActionTest, InvalidXmlTest) { |
Darin Petkov | 6a5b322 | 2010-07-13 14:55:28 -0700 | [diff] [blame] | 646 | OmahaResponse response; |
| 647 | ASSERT_FALSE( |
Darin Petkov | 1cbd78f | 2010-07-29 12:38:34 -0700 | [diff] [blame] | 648 | TestUpdateCheck(NULL, // prefs |
| 649 | kDefaultTestParams, |
Darin Petkov | 0dc8e9a | 2010-07-14 14:51:57 -0700 | [diff] [blame] | 650 | "invalid xml>", |
Darin Petkov | edc522e | 2010-11-05 09:35:17 -0700 | [diff] [blame] | 651 | -1, |
Darin Petkov | 265f290 | 2011-05-09 15:17:40 -0700 | [diff] [blame] | 652 | false, // ping_only |
Darin Petkov | edc522e | 2010-11-05 09:35:17 -0700 | [diff] [blame] | 653 | kActionCodeOmahaRequestXMLParseError, |
| 654 | &response, |
| 655 | NULL)); |
| 656 | EXPECT_FALSE(response.update_exists); |
| 657 | } |
| 658 | |
| 659 | TEST(OmahaRequestActionTest, EmptyResponseTest) { |
| 660 | OmahaResponse response; |
| 661 | ASSERT_FALSE( |
| 662 | TestUpdateCheck(NULL, // prefs |
| 663 | kDefaultTestParams, |
| 664 | "", |
| 665 | -1, |
Darin Petkov | 265f290 | 2011-05-09 15:17:40 -0700 | [diff] [blame] | 666 | false, // ping_only |
Darin Petkov | edc522e | 2010-11-05 09:35:17 -0700 | [diff] [blame] | 667 | kActionCodeOmahaRequestEmptyResponseError, |
Darin Petkov | 0dc8e9a | 2010-07-14 14:51:57 -0700 | [diff] [blame] | 668 | &response, |
| 669 | NULL)); |
Darin Petkov | 6a5b322 | 2010-07-13 14:55:28 -0700 | [diff] [blame] | 670 | EXPECT_FALSE(response.update_exists); |
| 671 | } |
| 672 | |
| 673 | TEST(OmahaRequestActionTest, MissingStatusTest) { |
Darin Petkov | 6a5b322 | 2010-07-13 14:55:28 -0700 | [diff] [blame] | 674 | OmahaResponse response; |
Darin Petkov | 0dc8e9a | 2010-07-14 14:51:57 -0700 | [diff] [blame] | 675 | ASSERT_FALSE(TestUpdateCheck( |
Darin Petkov | 1cbd78f | 2010-07-29 12:38:34 -0700 | [diff] [blame] | 676 | NULL, // prefs |
| 677 | kDefaultTestParams, |
Jay Srinivasan | 23b92a5 | 2012-10-27 02:00:21 -0700 | [diff] [blame] | 678 | "<?xml version=\"1.0\" encoding=\"UTF-8\"?><response protocol=\"3.0\">" |
| 679 | "<daystart elapsed_seconds=\"100\"/>" |
| 680 | "<app appid=\"foo\" status=\"ok\">" |
| 681 | "<ping status=\"ok\"/>" |
| 682 | "<updatecheck/></app></response>", |
Darin Petkov | edc522e | 2010-11-05 09:35:17 -0700 | [diff] [blame] | 683 | -1, |
Darin Petkov | 265f290 | 2011-05-09 15:17:40 -0700 | [diff] [blame] | 684 | false, // ping_only |
Jay Srinivasan | 23b92a5 | 2012-10-27 02:00:21 -0700 | [diff] [blame] | 685 | kActionCodeOmahaResponseInvalid, |
Darin Petkov | 6a5b322 | 2010-07-13 14:55:28 -0700 | [diff] [blame] | 686 | &response, |
| 687 | NULL)); |
| 688 | EXPECT_FALSE(response.update_exists); |
| 689 | } |
| 690 | |
| 691 | TEST(OmahaRequestActionTest, InvalidStatusTest) { |
Darin Petkov | 6a5b322 | 2010-07-13 14:55:28 -0700 | [diff] [blame] | 692 | OmahaResponse response; |
Darin Petkov | 0dc8e9a | 2010-07-14 14:51:57 -0700 | [diff] [blame] | 693 | ASSERT_FALSE(TestUpdateCheck( |
Darin Petkov | 1cbd78f | 2010-07-29 12:38:34 -0700 | [diff] [blame] | 694 | NULL, // prefs |
| 695 | kDefaultTestParams, |
Jay Srinivasan | 23b92a5 | 2012-10-27 02:00:21 -0700 | [diff] [blame] | 696 | "<?xml version=\"1.0\" encoding=\"UTF-8\"?><response protocol=\"3.0\">" |
| 697 | "<daystart elapsed_seconds=\"100\"/>" |
| 698 | "<app appid=\"foo\" status=\"ok\">" |
| 699 | "<ping status=\"ok\"/>" |
| 700 | "<updatecheck status=\"InvalidStatusTest\"/></app></response>", |
Darin Petkov | edc522e | 2010-11-05 09:35:17 -0700 | [diff] [blame] | 701 | -1, |
Darin Petkov | 265f290 | 2011-05-09 15:17:40 -0700 | [diff] [blame] | 702 | false, // ping_only |
Jay Srinivasan | 23b92a5 | 2012-10-27 02:00:21 -0700 | [diff] [blame] | 703 | kActionCodeOmahaResponseInvalid, |
Darin Petkov | 6a5b322 | 2010-07-13 14:55:28 -0700 | [diff] [blame] | 704 | &response, |
| 705 | NULL)); |
| 706 | EXPECT_FALSE(response.update_exists); |
| 707 | } |
| 708 | |
| 709 | TEST(OmahaRequestActionTest, MissingNodesetTest) { |
Darin Petkov | 6a5b322 | 2010-07-13 14:55:28 -0700 | [diff] [blame] | 710 | OmahaResponse response; |
Darin Petkov | 0dc8e9a | 2010-07-14 14:51:57 -0700 | [diff] [blame] | 711 | ASSERT_FALSE(TestUpdateCheck( |
Darin Petkov | 1cbd78f | 2010-07-29 12:38:34 -0700 | [diff] [blame] | 712 | NULL, // prefs |
| 713 | kDefaultTestParams, |
Jay Srinivasan | 23b92a5 | 2012-10-27 02:00:21 -0700 | [diff] [blame] | 714 | "<?xml version=\"1.0\" encoding=\"UTF-8\"?><response protocol=\"3.0\">" |
| 715 | "<daystart elapsed_seconds=\"100\"/>" |
| 716 | "<app appid=\"foo\" status=\"ok\">" |
| 717 | "<ping status=\"ok\"/>" |
| 718 | "</app></response>", |
Darin Petkov | edc522e | 2010-11-05 09:35:17 -0700 | [diff] [blame] | 719 | -1, |
Darin Petkov | 265f290 | 2011-05-09 15:17:40 -0700 | [diff] [blame] | 720 | false, // ping_only |
Jay Srinivasan | 23b92a5 | 2012-10-27 02:00:21 -0700 | [diff] [blame] | 721 | kActionCodeOmahaResponseInvalid, |
Darin Petkov | 6a5b322 | 2010-07-13 14:55:28 -0700 | [diff] [blame] | 722 | &response, |
| 723 | NULL)); |
| 724 | EXPECT_FALSE(response.update_exists); |
| 725 | } |
| 726 | |
| 727 | TEST(OmahaRequestActionTest, MissingFieldTest) { |
Jay Srinivasan | 23b92a5 | 2012-10-27 02:00:21 -0700 | [diff] [blame] | 728 | string input_response = |
| 729 | "<?xml version=\"1.0\" encoding=\"UTF-8\"?><response protocol=\"3.0\">" |
| 730 | "<daystart elapsed_seconds=\"100\"/>" |
| 731 | "<app appid=\"xyz\" status=\"ok\">" |
| 732 | "<updatecheck status=\"ok\">" |
| 733 | "<urls><url codebase=\"http://missing/field/test/\"/></urls>" |
| 734 | "<manifest version=\"1.0.0.0\">" |
| 735 | "<packages><package hash=\"not-used\" name=\"f\" " |
| 736 | "size=\"587\"/></packages>" |
| 737 | "<actions><action event=\"postinstall\" " |
| 738 | "DisplayVersion=\"10.2.3.4\" " |
| 739 | "ChromeOSVersion=\"10.2.3.4\" " |
| 740 | "Prompt=\"false\" " |
| 741 | "IsDelta=\"true\" " |
Jay Srinivasan | d671e97 | 2013-01-11 17:17:19 -0800 | [diff] [blame] | 742 | "IsDeltaPayload=\"false\" " |
Jay Srinivasan | 23b92a5 | 2012-10-27 02:00:21 -0700 | [diff] [blame] | 743 | "sha256=\"lkq34j5345\" " |
| 744 | "needsadmin=\"true\" " |
| 745 | "/></actions></manifest></updatecheck></app></response>"; |
| 746 | LOG(INFO) << "Input Response = " << input_response; |
| 747 | |
Darin Petkov | 6a5b322 | 2010-07-13 14:55:28 -0700 | [diff] [blame] | 748 | OmahaResponse response; |
Darin Petkov | 1cbd78f | 2010-07-29 12:38:34 -0700 | [diff] [blame] | 749 | ASSERT_TRUE(TestUpdateCheck(NULL, // prefs |
| 750 | kDefaultTestParams, |
Jay Srinivasan | 23b92a5 | 2012-10-27 02:00:21 -0700 | [diff] [blame] | 751 | input_response, |
Darin Petkov | edc522e | 2010-11-05 09:35:17 -0700 | [diff] [blame] | 752 | -1, |
Darin Petkov | 265f290 | 2011-05-09 15:17:40 -0700 | [diff] [blame] | 753 | false, // ping_only |
Darin Petkov | c1a8b42 | 2010-07-19 11:34:49 -0700 | [diff] [blame] | 754 | kActionCodeSuccess, |
Darin Petkov | 0dc8e9a | 2010-07-14 14:51:57 -0700 | [diff] [blame] | 755 | &response, |
| 756 | NULL)); |
Darin Petkov | 6a5b322 | 2010-07-13 14:55:28 -0700 | [diff] [blame] | 757 | EXPECT_TRUE(response.update_exists); |
Jay Srinivasan | 23b92a5 | 2012-10-27 02:00:21 -0700 | [diff] [blame] | 758 | EXPECT_EQ("10.2.3.4", response.display_version); |
Jay Srinivasan | 6f6ea00 | 2012-12-14 11:26:28 -0800 | [diff] [blame] | 759 | EXPECT_EQ("http://missing/field/test/f", response.payload_urls[0]); |
Darin Petkov | 6a5b322 | 2010-07-13 14:55:28 -0700 | [diff] [blame] | 760 | EXPECT_EQ("", response.more_info_url); |
Jay Srinivasan | 23b92a5 | 2012-10-27 02:00:21 -0700 | [diff] [blame] | 761 | EXPECT_EQ("lkq34j5345", response.hash); |
| 762 | EXPECT_EQ(587, response.size); |
Darin Petkov | 6a5b322 | 2010-07-13 14:55:28 -0700 | [diff] [blame] | 763 | EXPECT_FALSE(response.prompt); |
Darin Petkov | 6c11864 | 2010-10-21 12:06:30 -0700 | [diff] [blame] | 764 | EXPECT_TRUE(response.deadline.empty()); |
Darin Petkov | 6a5b322 | 2010-07-13 14:55:28 -0700 | [diff] [blame] | 765 | } |
| 766 | |
| 767 | namespace { |
| 768 | class TerminateEarlyTestProcessorDelegate : public ActionProcessorDelegate { |
| 769 | public: |
| 770 | void ProcessingStopped(const ActionProcessor* processor) { |
| 771 | ASSERT_TRUE(loop_); |
| 772 | g_main_loop_quit(loop_); |
| 773 | } |
| 774 | GMainLoop *loop_; |
| 775 | }; |
| 776 | |
| 777 | gboolean TerminateTransferTestStarter(gpointer data) { |
| 778 | ActionProcessor *processor = reinterpret_cast<ActionProcessor*>(data); |
| 779 | processor->StartProcessing(); |
| 780 | CHECK(processor->IsRunning()); |
| 781 | processor->StopProcessing(); |
| 782 | return FALSE; |
| 783 | } |
| 784 | } // namespace {} |
| 785 | |
| 786 | TEST(OmahaRequestActionTest, TerminateTransferTest) { |
Darin Petkov | 6a5b322 | 2010-07-13 14:55:28 -0700 | [diff] [blame] | 787 | string http_response("doesn't matter"); |
| 788 | GMainLoop *loop = g_main_loop_new(g_main_context_default(), FALSE); |
| 789 | |
Jay Srinivasan | 6f6ea00 | 2012-12-14 11:26:28 -0800 | [diff] [blame] | 790 | MockSystemState mock_system_state; |
Jay Srinivasan | 480ddfa | 2012-06-01 19:15:26 -0700 | [diff] [blame] | 791 | OmahaRequestParams params = kDefaultTestParams; |
Jay Srinivasan | ae4697c | 2013-03-18 17:08:08 -0700 | [diff] [blame] | 792 | mock_system_state.set_request_params(¶ms); |
| 793 | OmahaRequestAction action(&mock_system_state, NULL, |
Darin Petkov | 0dc8e9a | 2010-07-14 14:51:57 -0700 | [diff] [blame] | 794 | new MockHttpFetcher(http_response.data(), |
Andrew de los Reyes | 4516810 | 2010-11-22 11:13:50 -0800 | [diff] [blame] | 795 | http_response.size(), |
Thieu Le | 116fda3 | 2011-04-19 11:01:54 -0700 | [diff] [blame] | 796 | NULL), |
| 797 | false); |
Darin Petkov | 6a5b322 | 2010-07-13 14:55:28 -0700 | [diff] [blame] | 798 | TerminateEarlyTestProcessorDelegate delegate; |
| 799 | delegate.loop_ = loop; |
| 800 | ActionProcessor processor; |
| 801 | processor.set_delegate(&delegate); |
Darin Petkov | 6a5b322 | 2010-07-13 14:55:28 -0700 | [diff] [blame] | 802 | processor.EnqueueAction(&action); |
Darin Petkov | 6a5b322 | 2010-07-13 14:55:28 -0700 | [diff] [blame] | 803 | |
| 804 | g_timeout_add(0, &TerminateTransferTestStarter, &processor); |
| 805 | g_main_loop_run(loop); |
| 806 | g_main_loop_unref(loop); |
| 807 | } |
| 808 | |
| 809 | TEST(OmahaRequestActionTest, XmlEncodeTest) { |
| 810 | EXPECT_EQ("ab", XmlEncode("ab")); |
| 811 | EXPECT_EQ("a<b", XmlEncode("a<b")); |
| 812 | EXPECT_EQ("foo-Ω", XmlEncode("foo-\xce\xa9")); |
| 813 | EXPECT_EQ("<&>", XmlEncode("<&>")); |
| 814 | EXPECT_EQ("&lt;&amp;&gt;", XmlEncode("<&>")); |
| 815 | |
| 816 | vector<char> post_data; |
| 817 | |
| 818 | // Make sure XML Encode is being called on the params |
Jay Srinivasan | ae4697c | 2013-03-18 17:08:08 -0700 | [diff] [blame] | 819 | MockSystemState mock_system_state; |
| 820 | OmahaRequestParams params(&mock_system_state, |
| 821 | OmahaRequestParams::kOsPlatform, |
Darin Petkov | 6a5b322 | 2010-07-13 14:55:28 -0700 | [diff] [blame] | 822 | OmahaRequestParams::kOsVersion, |
| 823 | "testtheservice_pack>", |
Darin Petkov | 1cbd78f | 2010-07-29 12:38:34 -0700 | [diff] [blame] | 824 | "x86 generic<id", |
Darin Petkov | 6a5b322 | 2010-07-13 14:55:28 -0700 | [diff] [blame] | 825 | OmahaRequestParams::kAppId, |
| 826 | "0.1.0.0", |
| 827 | "en-US", |
Darin Petkov | 1cbd78f | 2010-07-29 12:38:34 -0700 | [diff] [blame] | 828 | "unittest_track<", |
Darin Petkov | fbb4009 | 2010-07-29 17:05:50 -0700 | [diff] [blame] | 829 | "<OEM MODEL>", |
Andrew de los Reyes | 3f0303a | 2010-07-15 22:35:35 -0700 | [diff] [blame] | 830 | false, // delta okay |
Gilad Arnold | bbdd490 | 2013-01-10 16:06:30 -0800 | [diff] [blame] | 831 | false, // interactive |
Jay Srinivasan | 0a70874 | 2012-03-20 11:26:12 -0700 | [diff] [blame] | 832 | "http://url", |
| 833 | false, // update_disabled |
Jay Srinivasan | 480ddfa | 2012-06-01 19:15:26 -0700 | [diff] [blame] | 834 | ""); // target_version_prefix |
Darin Petkov | 6a5b322 | 2010-07-13 14:55:28 -0700 | [diff] [blame] | 835 | OmahaResponse response; |
| 836 | ASSERT_FALSE( |
Darin Petkov | 1cbd78f | 2010-07-29 12:38:34 -0700 | [diff] [blame] | 837 | TestUpdateCheck(NULL, // prefs |
| 838 | params, |
Darin Petkov | 0dc8e9a | 2010-07-14 14:51:57 -0700 | [diff] [blame] | 839 | "invalid xml>", |
Darin Petkov | edc522e | 2010-11-05 09:35:17 -0700 | [diff] [blame] | 840 | -1, |
Darin Petkov | 265f290 | 2011-05-09 15:17:40 -0700 | [diff] [blame] | 841 | false, // ping_only |
Darin Petkov | edc522e | 2010-11-05 09:35:17 -0700 | [diff] [blame] | 842 | kActionCodeOmahaRequestXMLParseError, |
Darin Petkov | 0dc8e9a | 2010-07-14 14:51:57 -0700 | [diff] [blame] | 843 | &response, |
| 844 | &post_data)); |
Darin Petkov | 6a5b322 | 2010-07-13 14:55:28 -0700 | [diff] [blame] | 845 | // convert post_data to string |
| 846 | string post_str(&post_data[0], post_data.size()); |
Darin Petkov | 6a5b322 | 2010-07-13 14:55:28 -0700 | [diff] [blame] | 847 | EXPECT_NE(post_str.find("testtheservice_pack>"), string::npos); |
| 848 | EXPECT_EQ(post_str.find("testtheservice_pack>"), string::npos); |
Darin Petkov | 1cbd78f | 2010-07-29 12:38:34 -0700 | [diff] [blame] | 849 | EXPECT_NE(post_str.find("x86 generic<id"), string::npos); |
| 850 | EXPECT_EQ(post_str.find("x86 generic<id"), string::npos); |
| 851 | EXPECT_NE(post_str.find("unittest_track&lt;"), string::npos); |
| 852 | EXPECT_EQ(post_str.find("unittest_track<"), string::npos); |
Darin Petkov | fbb4009 | 2010-07-29 17:05:50 -0700 | [diff] [blame] | 853 | EXPECT_NE(post_str.find("<OEM MODEL>"), string::npos); |
| 854 | EXPECT_EQ(post_str.find("<OEM MODEL>"), string::npos); |
Darin Petkov | 6a5b322 | 2010-07-13 14:55:28 -0700 | [diff] [blame] | 855 | } |
| 856 | |
| 857 | TEST(OmahaRequestActionTest, XmlDecodeTest) { |
Darin Petkov | 6a5b322 | 2010-07-13 14:55:28 -0700 | [diff] [blame] | 858 | OmahaResponse response; |
| 859 | ASSERT_TRUE( |
Darin Petkov | 1cbd78f | 2010-07-29 12:38:34 -0700 | [diff] [blame] | 860 | TestUpdateCheck(NULL, // prefs |
| 861 | kDefaultTestParams, |
Darin Petkov | 0dc8e9a | 2010-07-14 14:51:57 -0700 | [diff] [blame] | 862 | GetUpdateResponse(OmahaRequestParams::kAppId, |
| 863 | "1.2.3.4", // version |
| 864 | "testthe<url", // more info |
| 865 | "true", // prompt |
Jay Srinivasan | 23b92a5 | 2012-10-27 02:00:21 -0700 | [diff] [blame] | 866 | "testthe&codebase/", // dl url |
| 867 | "file.signed", // file name |
Darin Petkov | 0dc8e9a | 2010-07-14 14:51:57 -0700 | [diff] [blame] | 868 | "HASH1234=", // checksum |
| 869 | "false", // needs admin |
Darin Petkov | 6c11864 | 2010-10-21 12:06:30 -0700 | [diff] [blame] | 870 | "123", // size |
| 871 | "<20110101"), // deadline |
Darin Petkov | edc522e | 2010-11-05 09:35:17 -0700 | [diff] [blame] | 872 | -1, |
Darin Petkov | 265f290 | 2011-05-09 15:17:40 -0700 | [diff] [blame] | 873 | false, // ping_only |
Darin Petkov | c1a8b42 | 2010-07-19 11:34:49 -0700 | [diff] [blame] | 874 | kActionCodeSuccess, |
Darin Petkov | 0dc8e9a | 2010-07-14 14:51:57 -0700 | [diff] [blame] | 875 | &response, |
| 876 | NULL)); |
Darin Petkov | 6a5b322 | 2010-07-13 14:55:28 -0700 | [diff] [blame] | 877 | |
| 878 | EXPECT_EQ(response.more_info_url, "testthe<url"); |
Jay Srinivasan | 6f6ea00 | 2012-12-14 11:26:28 -0800 | [diff] [blame] | 879 | EXPECT_EQ(response.payload_urls[0], "testthe&codebase/file.signed"); |
Darin Petkov | 6c11864 | 2010-10-21 12:06:30 -0700 | [diff] [blame] | 880 | EXPECT_EQ(response.deadline, "<20110101"); |
Darin Petkov | 6a5b322 | 2010-07-13 14:55:28 -0700 | [diff] [blame] | 881 | } |
| 882 | |
| 883 | TEST(OmahaRequestActionTest, ParseIntTest) { |
Darin Petkov | 6a5b322 | 2010-07-13 14:55:28 -0700 | [diff] [blame] | 884 | OmahaResponse response; |
| 885 | ASSERT_TRUE( |
Darin Petkov | 1cbd78f | 2010-07-29 12:38:34 -0700 | [diff] [blame] | 886 | TestUpdateCheck(NULL, // prefs |
| 887 | kDefaultTestParams, |
Darin Petkov | 0dc8e9a | 2010-07-14 14:51:57 -0700 | [diff] [blame] | 888 | GetUpdateResponse(OmahaRequestParams::kAppId, |
| 889 | "1.2.3.4", // version |
| 890 | "theurl", // more info |
| 891 | "true", // prompt |
Jay Srinivasan | 23b92a5 | 2012-10-27 02:00:21 -0700 | [diff] [blame] | 892 | "thecodebase/", // dl url |
| 893 | "file.signed", // file name |
Darin Petkov | 0dc8e9a | 2010-07-14 14:51:57 -0700 | [diff] [blame] | 894 | "HASH1234=", // checksum |
| 895 | "false", // needs admin |
| 896 | // overflows int32: |
Darin Petkov | 6c11864 | 2010-10-21 12:06:30 -0700 | [diff] [blame] | 897 | "123123123123123", // size |
| 898 | "deadline"), |
Darin Petkov | edc522e | 2010-11-05 09:35:17 -0700 | [diff] [blame] | 899 | -1, |
Darin Petkov | 265f290 | 2011-05-09 15:17:40 -0700 | [diff] [blame] | 900 | false, // ping_only |
Darin Petkov | c1a8b42 | 2010-07-19 11:34:49 -0700 | [diff] [blame] | 901 | kActionCodeSuccess, |
Darin Petkov | 0dc8e9a | 2010-07-14 14:51:57 -0700 | [diff] [blame] | 902 | &response, |
| 903 | NULL)); |
Darin Petkov | 6a5b322 | 2010-07-13 14:55:28 -0700 | [diff] [blame] | 904 | |
| 905 | EXPECT_EQ(response.size, 123123123123123ll); |
| 906 | } |
| 907 | |
Darin Petkov | 0dc8e9a | 2010-07-14 14:51:57 -0700 | [diff] [blame] | 908 | TEST(OmahaRequestActionTest, FormatUpdateCheckOutputTest) { |
| 909 | vector<char> post_data; |
Darin Petkov | 95508da | 2011-01-05 12:42:29 -0800 | [diff] [blame] | 910 | NiceMock<PrefsMock> prefs; |
| 911 | EXPECT_CALL(prefs, GetString(kPrefsPreviousVersion, _)) |
| 912 | .WillOnce(DoAll(SetArgumentPointee<1>(string("")), Return(true))); |
Jay Srinivasan | ae4697c | 2013-03-18 17:08:08 -0700 | [diff] [blame] | 913 | EXPECT_CALL(prefs, SetString(kPrefsPreviousVersion, _)).Times(1); |
Darin Petkov | 95508da | 2011-01-05 12:42:29 -0800 | [diff] [blame] | 914 | ASSERT_FALSE(TestUpdateCheck(&prefs, |
Darin Petkov | 1cbd78f | 2010-07-29 12:38:34 -0700 | [diff] [blame] | 915 | kDefaultTestParams, |
Darin Petkov | 0dc8e9a | 2010-07-14 14:51:57 -0700 | [diff] [blame] | 916 | "invalid xml>", |
Darin Petkov | edc522e | 2010-11-05 09:35:17 -0700 | [diff] [blame] | 917 | -1, |
Darin Petkov | 265f290 | 2011-05-09 15:17:40 -0700 | [diff] [blame] | 918 | false, // ping_only |
Darin Petkov | edc522e | 2010-11-05 09:35:17 -0700 | [diff] [blame] | 919 | kActionCodeOmahaRequestXMLParseError, |
Darin Petkov | 1cbd78f | 2010-07-29 12:38:34 -0700 | [diff] [blame] | 920 | NULL, // response |
Darin Petkov | 0dc8e9a | 2010-07-14 14:51:57 -0700 | [diff] [blame] | 921 | &post_data)); |
| 922 | // convert post_data to string |
| 923 | string post_str(&post_data[0], post_data.size()); |
Thieu Le | 116fda3 | 2011-04-19 11:01:54 -0700 | [diff] [blame] | 924 | EXPECT_NE(post_str.find( |
Jay Srinivasan | 23b92a5 | 2012-10-27 02:00:21 -0700 | [diff] [blame] | 925 | " <ping active=\"1\" a=\"-1\" r=\"-1\"></ping>\n" |
Jay Srinivasan | ae4697c | 2013-03-18 17:08:08 -0700 | [diff] [blame] | 926 | " <updatecheck targetversionprefix=\"\"></updatecheck>\n"), |
Jay Srinivasan | 0a70874 | 2012-03-20 11:26:12 -0700 | [diff] [blame] | 927 | string::npos); |
Darin Petkov | fbb4009 | 2010-07-29 17:05:50 -0700 | [diff] [blame] | 928 | EXPECT_NE(post_str.find("hardware_class=\"OEM MODEL 09235 7471\""), |
| 929 | string::npos); |
Darin Petkov | 0dc8e9a | 2010-07-14 14:51:57 -0700 | [diff] [blame] | 930 | } |
| 931 | |
Jay Srinivasan | 0a70874 | 2012-03-20 11:26:12 -0700 | [diff] [blame] | 932 | |
Jay Srinivasan | ae4697c | 2013-03-18 17:08:08 -0700 | [diff] [blame] | 933 | TEST(OmahaRequestActionTest, FormatUpdateDisabledOutputTest) { |
Darin Petkov | 95508da | 2011-01-05 12:42:29 -0800 | [diff] [blame] | 934 | vector<char> post_data; |
| 935 | NiceMock<PrefsMock> prefs; |
| 936 | EXPECT_CALL(prefs, GetString(kPrefsPreviousVersion, _)) |
Jay Srinivasan | 0a70874 | 2012-03-20 11:26:12 -0700 | [diff] [blame] | 937 | .WillOnce(DoAll(SetArgumentPointee<1>(string("")), Return(true))); |
Jay Srinivasan | ae4697c | 2013-03-18 17:08:08 -0700 | [diff] [blame] | 938 | EXPECT_CALL(prefs, SetString(kPrefsPreviousVersion, _)).Times(1); |
Jay Srinivasan | 0a70874 | 2012-03-20 11:26:12 -0700 | [diff] [blame] | 939 | OmahaRequestParams params = kDefaultTestParams; |
Jay Srinivasan | ae4697c | 2013-03-18 17:08:08 -0700 | [diff] [blame] | 940 | params.set_update_disabled(true); |
Darin Petkov | 95508da | 2011-01-05 12:42:29 -0800 | [diff] [blame] | 941 | ASSERT_FALSE(TestUpdateCheck(&prefs, |
Jay Srinivasan | 0a70874 | 2012-03-20 11:26:12 -0700 | [diff] [blame] | 942 | params, |
Darin Petkov | 95508da | 2011-01-05 12:42:29 -0800 | [diff] [blame] | 943 | "invalid xml>", |
| 944 | -1, |
Darin Petkov | 265f290 | 2011-05-09 15:17:40 -0700 | [diff] [blame] | 945 | false, // ping_only |
Darin Petkov | 95508da | 2011-01-05 12:42:29 -0800 | [diff] [blame] | 946 | kActionCodeOmahaRequestXMLParseError, |
| 947 | NULL, // response |
| 948 | &post_data)); |
| 949 | // convert post_data to string |
| 950 | string post_str(&post_data[0], post_data.size()); |
Thieu Le | 116fda3 | 2011-04-19 11:01:54 -0700 | [diff] [blame] | 951 | EXPECT_NE(post_str.find( |
Jay Srinivasan | 23b92a5 | 2012-10-27 02:00:21 -0700 | [diff] [blame] | 952 | " <ping active=\"1\" a=\"-1\" r=\"-1\"></ping>\n" |
Jay Srinivasan | ae4697c | 2013-03-18 17:08:08 -0700 | [diff] [blame] | 953 | " <updatecheck targetversionprefix=\"\"></updatecheck>\n"), |
Jay Srinivasan | 0a70874 | 2012-03-20 11:26:12 -0700 | [diff] [blame] | 954 | string::npos); |
Darin Petkov | 95508da | 2011-01-05 12:42:29 -0800 | [diff] [blame] | 955 | EXPECT_NE(post_str.find("hardware_class=\"OEM MODEL 09235 7471\""), |
| 956 | string::npos); |
Darin Petkov | 95508da | 2011-01-05 12:42:29 -0800 | [diff] [blame] | 957 | } |
| 958 | |
Darin Petkov | e17f86b | 2010-07-20 09:12:01 -0700 | [diff] [blame] | 959 | TEST(OmahaRequestActionTest, FormatSuccessEventOutputTest) { |
| 960 | vector<char> post_data; |
Darin Petkov | 1cbd78f | 2010-07-29 12:38:34 -0700 | [diff] [blame] | 961 | TestEvent(kDefaultTestParams, |
Darin Petkov | e17f86b | 2010-07-20 09:12:01 -0700 | [diff] [blame] | 962 | new OmahaEvent(OmahaEvent::kTypeUpdateDownloadStarted), |
| 963 | "invalid xml>", |
| 964 | &post_data); |
| 965 | // convert post_data to string |
| 966 | string post_str(&post_data[0], post_data.size()); |
| 967 | string expected_event = StringPrintf( |
Jay Srinivasan | 23b92a5 | 2012-10-27 02:00:21 -0700 | [diff] [blame] | 968 | " <event eventtype=\"%d\" eventresult=\"%d\"></event>\n", |
Darin Petkov | e17f86b | 2010-07-20 09:12:01 -0700 | [diff] [blame] | 969 | OmahaEvent::kTypeUpdateDownloadStarted, |
| 970 | OmahaEvent::kResultSuccess); |
| 971 | EXPECT_NE(post_str.find(expected_event), string::npos); |
Jay Srinivasan | 23b92a5 | 2012-10-27 02:00:21 -0700 | [diff] [blame] | 972 | EXPECT_EQ(post_str.find("ping"), string::npos); |
| 973 | EXPECT_EQ(post_str.find("updatecheck"), string::npos); |
Darin Petkov | e17f86b | 2010-07-20 09:12:01 -0700 | [diff] [blame] | 974 | } |
| 975 | |
| 976 | TEST(OmahaRequestActionTest, FormatErrorEventOutputTest) { |
| 977 | vector<char> post_data; |
Darin Petkov | 1cbd78f | 2010-07-29 12:38:34 -0700 | [diff] [blame] | 978 | TestEvent(kDefaultTestParams, |
Darin Petkov | e17f86b | 2010-07-20 09:12:01 -0700 | [diff] [blame] | 979 | new OmahaEvent(OmahaEvent::kTypeDownloadComplete, |
| 980 | OmahaEvent::kResultError, |
| 981 | kActionCodeError), |
| 982 | "invalid xml>", |
| 983 | &post_data); |
| 984 | // convert post_data to string |
| 985 | string post_str(&post_data[0], post_data.size()); |
| 986 | string expected_event = StringPrintf( |
Jay Srinivasan | 23b92a5 | 2012-10-27 02:00:21 -0700 | [diff] [blame] | 987 | " <event eventtype=\"%d\" eventresult=\"%d\" " |
| 988 | "errorcode=\"%d\"></event>\n", |
Darin Petkov | e17f86b | 2010-07-20 09:12:01 -0700 | [diff] [blame] | 989 | OmahaEvent::kTypeDownloadComplete, |
| 990 | OmahaEvent::kResultError, |
Darin Petkov | 44d98d9 | 2011-03-21 16:08:11 -0700 | [diff] [blame] | 991 | kActionCodeError); |
Darin Petkov | 0dc8e9a | 2010-07-14 14:51:57 -0700 | [diff] [blame] | 992 | EXPECT_NE(post_str.find(expected_event), string::npos); |
Jay Srinivasan | 23b92a5 | 2012-10-27 02:00:21 -0700 | [diff] [blame] | 993 | EXPECT_EQ(post_str.find("updatecheck"), string::npos); |
Darin Petkov | 0dc8e9a | 2010-07-14 14:51:57 -0700 | [diff] [blame] | 994 | } |
| 995 | |
| 996 | TEST(OmahaRequestActionTest, IsEventTest) { |
| 997 | string http_response("doesn't matter"); |
Jay Srinivasan | 6f6ea00 | 2012-12-14 11:26:28 -0800 | [diff] [blame] | 998 | MockSystemState mock_system_state; |
Jay Srinivasan | 480ddfa | 2012-06-01 19:15:26 -0700 | [diff] [blame] | 999 | OmahaRequestParams params = kDefaultTestParams; |
Jay Srinivasan | ae4697c | 2013-03-18 17:08:08 -0700 | [diff] [blame] | 1000 | mock_system_state.set_request_params(¶ms); |
Darin Petkov | 0dc8e9a | 2010-07-14 14:51:57 -0700 | [diff] [blame] | 1001 | OmahaRequestAction update_check_action( |
Jay Srinivasan | 6f6ea00 | 2012-12-14 11:26:28 -0800 | [diff] [blame] | 1002 | &mock_system_state, |
Darin Petkov | 0dc8e9a | 2010-07-14 14:51:57 -0700 | [diff] [blame] | 1003 | NULL, |
| 1004 | new MockHttpFetcher(http_response.data(), |
Andrew de los Reyes | 4516810 | 2010-11-22 11:13:50 -0800 | [diff] [blame] | 1005 | http_response.size(), |
Thieu Le | 116fda3 | 2011-04-19 11:01:54 -0700 | [diff] [blame] | 1006 | NULL), |
| 1007 | false); |
Darin Petkov | 0dc8e9a | 2010-07-14 14:51:57 -0700 | [diff] [blame] | 1008 | EXPECT_FALSE(update_check_action.IsEvent()); |
| 1009 | |
Jay Srinivasan | 480ddfa | 2012-06-01 19:15:26 -0700 | [diff] [blame] | 1010 | params = kDefaultTestParams; |
Jay Srinivasan | ae4697c | 2013-03-18 17:08:08 -0700 | [diff] [blame] | 1011 | mock_system_state.set_request_params(¶ms); |
Darin Petkov | 0dc8e9a | 2010-07-14 14:51:57 -0700 | [diff] [blame] | 1012 | OmahaRequestAction event_action( |
Jay Srinivasan | 6f6ea00 | 2012-12-14 11:26:28 -0800 | [diff] [blame] | 1013 | &mock_system_state, |
Darin Petkov | e17f86b | 2010-07-20 09:12:01 -0700 | [diff] [blame] | 1014 | new OmahaEvent(OmahaEvent::kTypeUpdateComplete), |
Darin Petkov | 0dc8e9a | 2010-07-14 14:51:57 -0700 | [diff] [blame] | 1015 | new MockHttpFetcher(http_response.data(), |
Andrew de los Reyes | 4516810 | 2010-11-22 11:13:50 -0800 | [diff] [blame] | 1016 | http_response.size(), |
Thieu Le | 116fda3 | 2011-04-19 11:01:54 -0700 | [diff] [blame] | 1017 | NULL), |
| 1018 | false); |
Darin Petkov | 0dc8e9a | 2010-07-14 14:51:57 -0700 | [diff] [blame] | 1019 | EXPECT_TRUE(event_action.IsEvent()); |
| 1020 | } |
| 1021 | |
Andrew de los Reyes | 3f0303a | 2010-07-15 22:35:35 -0700 | [diff] [blame] | 1022 | TEST(OmahaRequestActionTest, FormatDeltaOkayOutputTest) { |
| 1023 | for (int i = 0; i < 2; i++) { |
| 1024 | bool delta_okay = i == 1; |
| 1025 | const char* delta_okay_str = delta_okay ? "true" : "false"; |
| 1026 | vector<char> post_data; |
Jay Srinivasan | ae4697c | 2013-03-18 17:08:08 -0700 | [diff] [blame] | 1027 | MockSystemState mock_system_state; |
| 1028 | OmahaRequestParams params(&mock_system_state, |
| 1029 | OmahaRequestParams::kOsPlatform, |
Andrew de los Reyes | 3f0303a | 2010-07-15 22:35:35 -0700 | [diff] [blame] | 1030 | OmahaRequestParams::kOsVersion, |
| 1031 | "service_pack", |
| 1032 | "x86-generic", |
| 1033 | OmahaRequestParams::kAppId, |
| 1034 | "0.1.0.0", |
| 1035 | "en-US", |
| 1036 | "unittest_track", |
Darin Petkov | fbb4009 | 2010-07-29 17:05:50 -0700 | [diff] [blame] | 1037 | "OEM MODEL REV 1234", |
Andrew de los Reyes | 3f0303a | 2010-07-15 22:35:35 -0700 | [diff] [blame] | 1038 | delta_okay, |
Gilad Arnold | bbdd490 | 2013-01-10 16:06:30 -0800 | [diff] [blame] | 1039 | false, // interactive |
Jay Srinivasan | 0a70874 | 2012-03-20 11:26:12 -0700 | [diff] [blame] | 1040 | "http://url", |
| 1041 | false, // update_disabled |
| 1042 | ""); // target_version_prefix |
Darin Petkov | 1cbd78f | 2010-07-29 12:38:34 -0700 | [diff] [blame] | 1043 | ASSERT_FALSE(TestUpdateCheck(NULL, // prefs |
| 1044 | params, |
Andrew de los Reyes | 3f0303a | 2010-07-15 22:35:35 -0700 | [diff] [blame] | 1045 | "invalid xml>", |
Darin Petkov | edc522e | 2010-11-05 09:35:17 -0700 | [diff] [blame] | 1046 | -1, |
Darin Petkov | 265f290 | 2011-05-09 15:17:40 -0700 | [diff] [blame] | 1047 | false, // ping_only |
Darin Petkov | edc522e | 2010-11-05 09:35:17 -0700 | [diff] [blame] | 1048 | kActionCodeOmahaRequestXMLParseError, |
Andrew de los Reyes | 3f0303a | 2010-07-15 22:35:35 -0700 | [diff] [blame] | 1049 | NULL, |
| 1050 | &post_data)); |
| 1051 | // convert post_data to string |
| 1052 | string post_str(&post_data[0], post_data.size()); |
| 1053 | EXPECT_NE(post_str.find(StringPrintf(" delta_okay=\"%s\"", delta_okay_str)), |
| 1054 | string::npos) |
| 1055 | << "i = " << i; |
| 1056 | } |
| 1057 | } |
| 1058 | |
Gilad Arnold | bbdd490 | 2013-01-10 16:06:30 -0800 | [diff] [blame] | 1059 | TEST(OmahaRequestActionTest, FormatInteractiveOutputTest) { |
| 1060 | for (int i = 0; i < 2; i++) { |
| 1061 | bool interactive = i == 1; |
Gilad Arnold | 8a659d8 | 2013-01-24 11:26:00 -0800 | [diff] [blame] | 1062 | const char* interactive_str = interactive ? "ondemandupdate" : "scheduler"; |
Gilad Arnold | bbdd490 | 2013-01-10 16:06:30 -0800 | [diff] [blame] | 1063 | vector<char> post_data; |
Jay Srinivasan | ae4697c | 2013-03-18 17:08:08 -0700 | [diff] [blame] | 1064 | MockSystemState mock_system_state; |
| 1065 | OmahaRequestParams params(&mock_system_state, |
| 1066 | OmahaRequestParams::kOsPlatform, |
Gilad Arnold | bbdd490 | 2013-01-10 16:06:30 -0800 | [diff] [blame] | 1067 | OmahaRequestParams::kOsVersion, |
| 1068 | "service_pack", |
| 1069 | "x86-generic", |
| 1070 | OmahaRequestParams::kAppId, |
| 1071 | "0.1.0.0", |
| 1072 | "en-US", |
| 1073 | "unittest_track", |
| 1074 | "OEM MODEL REV 1234", |
| 1075 | true, // delta_okay |
| 1076 | interactive, |
| 1077 | "http://url", |
| 1078 | false, // update_disabled |
| 1079 | ""); // target_version_prefix |
| 1080 | ASSERT_FALSE(TestUpdateCheck(NULL, // prefs |
| 1081 | params, |
| 1082 | "invalid xml>", |
| 1083 | -1, |
| 1084 | false, // ping_only |
| 1085 | kActionCodeOmahaRequestXMLParseError, |
| 1086 | NULL, |
| 1087 | &post_data)); |
| 1088 | // convert post_data to string |
| 1089 | string post_str(&post_data[0], post_data.size()); |
Gilad Arnold | 8a659d8 | 2013-01-24 11:26:00 -0800 | [diff] [blame] | 1090 | EXPECT_NE(post_str.find(StringPrintf("installsource=\"%s\"", |
Gilad Arnold | bbdd490 | 2013-01-10 16:06:30 -0800 | [diff] [blame] | 1091 | interactive_str)), |
| 1092 | string::npos) |
| 1093 | << "i = " << i; |
| 1094 | } |
| 1095 | } |
| 1096 | |
Darin Petkov | e17f86b | 2010-07-20 09:12:01 -0700 | [diff] [blame] | 1097 | TEST(OmahaRequestActionTest, OmahaEventTest) { |
| 1098 | OmahaEvent default_event; |
| 1099 | EXPECT_EQ(OmahaEvent::kTypeUnknown, default_event.type); |
| 1100 | EXPECT_EQ(OmahaEvent::kResultError, default_event.result); |
| 1101 | EXPECT_EQ(kActionCodeError, default_event.error_code); |
| 1102 | |
| 1103 | OmahaEvent success_event(OmahaEvent::kTypeUpdateDownloadStarted); |
| 1104 | EXPECT_EQ(OmahaEvent::kTypeUpdateDownloadStarted, success_event.type); |
| 1105 | EXPECT_EQ(OmahaEvent::kResultSuccess, success_event.result); |
| 1106 | EXPECT_EQ(kActionCodeSuccess, success_event.error_code); |
| 1107 | |
| 1108 | OmahaEvent error_event(OmahaEvent::kTypeUpdateDownloadFinished, |
| 1109 | OmahaEvent::kResultError, |
| 1110 | kActionCodeError); |
| 1111 | EXPECT_EQ(OmahaEvent::kTypeUpdateDownloadFinished, error_event.type); |
| 1112 | EXPECT_EQ(OmahaEvent::kResultError, error_event.result); |
| 1113 | EXPECT_EQ(kActionCodeError, error_event.error_code); |
| 1114 | } |
| 1115 | |
Darin Petkov | 1cbd78f | 2010-07-29 12:38:34 -0700 | [diff] [blame] | 1116 | TEST(OmahaRequestActionTest, PingTest) { |
Darin Petkov | 265f290 | 2011-05-09 15:17:40 -0700 | [diff] [blame] | 1117 | for (int ping_only = 0; ping_only < 2; ping_only++) { |
| 1118 | NiceMock<PrefsMock> prefs; |
| 1119 | // Add a few hours to the day difference to test no rounding, etc. |
| 1120 | int64_t five_days_ago = |
| 1121 | (Time::Now() - TimeDelta::FromHours(5 * 24 + 13)).ToInternalValue(); |
| 1122 | int64_t six_days_ago = |
| 1123 | (Time::Now() - TimeDelta::FromHours(6 * 24 + 11)).ToInternalValue(); |
| 1124 | EXPECT_CALL(prefs, GetInt64(kPrefsLastActivePingDay, _)) |
| 1125 | .WillOnce(DoAll(SetArgumentPointee<1>(six_days_ago), Return(true))); |
| 1126 | EXPECT_CALL(prefs, GetInt64(kPrefsLastRollCallPingDay, _)) |
| 1127 | .WillOnce(DoAll(SetArgumentPointee<1>(five_days_ago), Return(true))); |
| 1128 | vector<char> post_data; |
| 1129 | ASSERT_TRUE( |
| 1130 | TestUpdateCheck(&prefs, |
| 1131 | kDefaultTestParams, |
| 1132 | GetNoUpdateResponse(OmahaRequestParams::kAppId), |
| 1133 | -1, |
| 1134 | ping_only, |
| 1135 | kActionCodeSuccess, |
| 1136 | NULL, |
| 1137 | &post_data)); |
| 1138 | string post_str(&post_data[0], post_data.size()); |
Jay Srinivasan | 23b92a5 | 2012-10-27 02:00:21 -0700 | [diff] [blame] | 1139 | 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] | 1140 | string::npos); |
| 1141 | if (ping_only) { |
Jay Srinivasan | 23b92a5 | 2012-10-27 02:00:21 -0700 | [diff] [blame] | 1142 | EXPECT_EQ(post_str.find("updatecheck"), string::npos); |
Darin Petkov | 265f290 | 2011-05-09 15:17:40 -0700 | [diff] [blame] | 1143 | EXPECT_EQ(post_str.find("previousversion"), string::npos); |
| 1144 | } else { |
Jay Srinivasan | 23b92a5 | 2012-10-27 02:00:21 -0700 | [diff] [blame] | 1145 | EXPECT_NE(post_str.find("updatecheck"), string::npos); |
Darin Petkov | 265f290 | 2011-05-09 15:17:40 -0700 | [diff] [blame] | 1146 | EXPECT_NE(post_str.find("previousversion"), string::npos); |
| 1147 | } |
| 1148 | } |
Darin Petkov | 1cbd78f | 2010-07-29 12:38:34 -0700 | [diff] [blame] | 1149 | } |
| 1150 | |
| 1151 | TEST(OmahaRequestActionTest, ActivePingTest) { |
Darin Petkov | 9c096d6 | 2010-11-17 14:49:04 -0800 | [diff] [blame] | 1152 | NiceMock<PrefsMock> prefs; |
Darin Petkov | 1cbd78f | 2010-07-29 12:38:34 -0700 | [diff] [blame] | 1153 | int64_t three_days_ago = |
| 1154 | (Time::Now() - TimeDelta::FromHours(3 * 24 + 12)).ToInternalValue(); |
| 1155 | int64_t now = Time::Now().ToInternalValue(); |
| 1156 | EXPECT_CALL(prefs, GetInt64(kPrefsLastActivePingDay, _)) |
| 1157 | .WillOnce(DoAll(SetArgumentPointee<1>(three_days_ago), Return(true))); |
| 1158 | EXPECT_CALL(prefs, GetInt64(kPrefsLastRollCallPingDay, _)) |
| 1159 | .WillOnce(DoAll(SetArgumentPointee<1>(now), Return(true))); |
| 1160 | vector<char> post_data; |
| 1161 | ASSERT_TRUE( |
| 1162 | TestUpdateCheck(&prefs, |
| 1163 | kDefaultTestParams, |
| 1164 | GetNoUpdateResponse(OmahaRequestParams::kAppId), |
Darin Petkov | edc522e | 2010-11-05 09:35:17 -0700 | [diff] [blame] | 1165 | -1, |
Darin Petkov | 265f290 | 2011-05-09 15:17:40 -0700 | [diff] [blame] | 1166 | false, // ping_only |
Darin Petkov | 1cbd78f | 2010-07-29 12:38:34 -0700 | [diff] [blame] | 1167 | kActionCodeSuccess, |
| 1168 | NULL, |
| 1169 | &post_data)); |
| 1170 | string post_str(&post_data[0], post_data.size()); |
Jay Srinivasan | 23b92a5 | 2012-10-27 02:00:21 -0700 | [diff] [blame] | 1171 | EXPECT_NE(post_str.find("<ping active=\"1\" a=\"3\"></ping>"), |
Thieu Le | 116fda3 | 2011-04-19 11:01:54 -0700 | [diff] [blame] | 1172 | string::npos); |
Darin Petkov | 1cbd78f | 2010-07-29 12:38:34 -0700 | [diff] [blame] | 1173 | } |
| 1174 | |
| 1175 | TEST(OmahaRequestActionTest, RollCallPingTest) { |
Darin Petkov | 9c096d6 | 2010-11-17 14:49:04 -0800 | [diff] [blame] | 1176 | NiceMock<PrefsMock> prefs; |
Darin Petkov | 1cbd78f | 2010-07-29 12:38:34 -0700 | [diff] [blame] | 1177 | int64_t four_days_ago = |
| 1178 | (Time::Now() - TimeDelta::FromHours(4 * 24)).ToInternalValue(); |
| 1179 | int64_t now = Time::Now().ToInternalValue(); |
| 1180 | EXPECT_CALL(prefs, GetInt64(kPrefsLastActivePingDay, _)) |
| 1181 | .WillOnce(DoAll(SetArgumentPointee<1>(now), Return(true))); |
| 1182 | EXPECT_CALL(prefs, GetInt64(kPrefsLastRollCallPingDay, _)) |
| 1183 | .WillOnce(DoAll(SetArgumentPointee<1>(four_days_ago), Return(true))); |
| 1184 | vector<char> post_data; |
| 1185 | ASSERT_TRUE( |
| 1186 | TestUpdateCheck(&prefs, |
| 1187 | kDefaultTestParams, |
| 1188 | GetNoUpdateResponse(OmahaRequestParams::kAppId), |
Darin Petkov | edc522e | 2010-11-05 09:35:17 -0700 | [diff] [blame] | 1189 | -1, |
Darin Petkov | 265f290 | 2011-05-09 15:17:40 -0700 | [diff] [blame] | 1190 | false, // ping_only |
Darin Petkov | 1cbd78f | 2010-07-29 12:38:34 -0700 | [diff] [blame] | 1191 | kActionCodeSuccess, |
| 1192 | NULL, |
| 1193 | &post_data)); |
| 1194 | string post_str(&post_data[0], post_data.size()); |
Jay Srinivasan | 23b92a5 | 2012-10-27 02:00:21 -0700 | [diff] [blame] | 1195 | EXPECT_NE(post_str.find("<ping active=\"1\" r=\"4\"></ping>\n"), |
Thieu Le | 116fda3 | 2011-04-19 11:01:54 -0700 | [diff] [blame] | 1196 | string::npos); |
Darin Petkov | 1cbd78f | 2010-07-29 12:38:34 -0700 | [diff] [blame] | 1197 | } |
| 1198 | |
| 1199 | TEST(OmahaRequestActionTest, NoPingTest) { |
Darin Petkov | 9c096d6 | 2010-11-17 14:49:04 -0800 | [diff] [blame] | 1200 | NiceMock<PrefsMock> prefs; |
Darin Petkov | 1cbd78f | 2010-07-29 12:38:34 -0700 | [diff] [blame] | 1201 | int64_t one_hour_ago = |
| 1202 | (Time::Now() - TimeDelta::FromHours(1)).ToInternalValue(); |
| 1203 | EXPECT_CALL(prefs, GetInt64(kPrefsLastActivePingDay, _)) |
| 1204 | .WillOnce(DoAll(SetArgumentPointee<1>(one_hour_ago), Return(true))); |
| 1205 | EXPECT_CALL(prefs, GetInt64(kPrefsLastRollCallPingDay, _)) |
| 1206 | .WillOnce(DoAll(SetArgumentPointee<1>(one_hour_ago), Return(true))); |
| 1207 | EXPECT_CALL(prefs, SetInt64(kPrefsLastActivePingDay, _)).Times(0); |
| 1208 | EXPECT_CALL(prefs, SetInt64(kPrefsLastRollCallPingDay, _)).Times(0); |
| 1209 | vector<char> post_data; |
| 1210 | ASSERT_TRUE( |
| 1211 | TestUpdateCheck(&prefs, |
| 1212 | kDefaultTestParams, |
| 1213 | GetNoUpdateResponse(OmahaRequestParams::kAppId), |
Darin Petkov | edc522e | 2010-11-05 09:35:17 -0700 | [diff] [blame] | 1214 | -1, |
Darin Petkov | 265f290 | 2011-05-09 15:17:40 -0700 | [diff] [blame] | 1215 | false, // ping_only |
Darin Petkov | 1cbd78f | 2010-07-29 12:38:34 -0700 | [diff] [blame] | 1216 | kActionCodeSuccess, |
| 1217 | NULL, |
| 1218 | &post_data)); |
| 1219 | string post_str(&post_data[0], post_data.size()); |
Jay Srinivasan | 23b92a5 | 2012-10-27 02:00:21 -0700 | [diff] [blame] | 1220 | EXPECT_EQ(post_str.find("ping"), string::npos); |
Darin Petkov | 1cbd78f | 2010-07-29 12:38:34 -0700 | [diff] [blame] | 1221 | } |
| 1222 | |
Thieu Le | b44e9e8 | 2011-06-06 14:34:04 -0700 | [diff] [blame] | 1223 | TEST(OmahaRequestActionTest, IgnoreEmptyPingTest) { |
| 1224 | // This test ensures that we ignore empty ping only requests. |
| 1225 | NiceMock<PrefsMock> prefs; |
| 1226 | int64_t now = Time::Now().ToInternalValue(); |
| 1227 | EXPECT_CALL(prefs, GetInt64(kPrefsLastActivePingDay, _)) |
| 1228 | .WillOnce(DoAll(SetArgumentPointee<1>(now), Return(true))); |
| 1229 | EXPECT_CALL(prefs, GetInt64(kPrefsLastRollCallPingDay, _)) |
| 1230 | .WillOnce(DoAll(SetArgumentPointee<1>(now), Return(true))); |
| 1231 | EXPECT_CALL(prefs, SetInt64(kPrefsLastActivePingDay, _)).Times(0); |
| 1232 | EXPECT_CALL(prefs, SetInt64(kPrefsLastRollCallPingDay, _)).Times(0); |
| 1233 | vector<char> post_data; |
| 1234 | EXPECT_TRUE( |
| 1235 | TestUpdateCheck(&prefs, |
| 1236 | kDefaultTestParams, |
| 1237 | GetNoUpdateResponse(OmahaRequestParams::kAppId), |
| 1238 | -1, |
| 1239 | true, // ping_only |
| 1240 | kActionCodeSuccess, |
| 1241 | NULL, |
| 1242 | &post_data)); |
| 1243 | EXPECT_EQ(post_data.size(), 0); |
| 1244 | } |
| 1245 | |
Darin Petkov | 1cbd78f | 2010-07-29 12:38:34 -0700 | [diff] [blame] | 1246 | TEST(OmahaRequestActionTest, BackInTimePingTest) { |
Darin Petkov | 9c096d6 | 2010-11-17 14:49:04 -0800 | [diff] [blame] | 1247 | NiceMock<PrefsMock> prefs; |
Darin Petkov | 1cbd78f | 2010-07-29 12:38:34 -0700 | [diff] [blame] | 1248 | int64_t future = |
| 1249 | (Time::Now() + TimeDelta::FromHours(3 * 24 + 4)).ToInternalValue(); |
| 1250 | EXPECT_CALL(prefs, GetInt64(kPrefsLastActivePingDay, _)) |
| 1251 | .WillOnce(DoAll(SetArgumentPointee<1>(future), Return(true))); |
| 1252 | EXPECT_CALL(prefs, GetInt64(kPrefsLastRollCallPingDay, _)) |
| 1253 | .WillOnce(DoAll(SetArgumentPointee<1>(future), Return(true))); |
| 1254 | EXPECT_CALL(prefs, SetInt64(kPrefsLastActivePingDay, _)) |
| 1255 | .WillOnce(Return(true)); |
| 1256 | EXPECT_CALL(prefs, SetInt64(kPrefsLastRollCallPingDay, _)) |
| 1257 | .WillOnce(Return(true)); |
| 1258 | vector<char> post_data; |
| 1259 | ASSERT_TRUE( |
| 1260 | TestUpdateCheck(&prefs, |
| 1261 | kDefaultTestParams, |
Jay Srinivasan | 23b92a5 | 2012-10-27 02:00:21 -0700 | [diff] [blame] | 1262 | "<?xml version=\"1.0\" encoding=\"UTF-8\"?><response " |
| 1263 | "protocol=\"3.0\"><daystart elapsed_seconds=\"100\"/>" |
Darin Petkov | 1cbd78f | 2010-07-29 12:38:34 -0700 | [diff] [blame] | 1264 | "<app appid=\"foo\" status=\"ok\"><ping status=\"ok\"/>" |
Jay Srinivasan | 23b92a5 | 2012-10-27 02:00:21 -0700 | [diff] [blame] | 1265 | "<updatecheck status=\"noupdate\"/></app></response>", |
Darin Petkov | edc522e | 2010-11-05 09:35:17 -0700 | [diff] [blame] | 1266 | -1, |
Darin Petkov | 265f290 | 2011-05-09 15:17:40 -0700 | [diff] [blame] | 1267 | false, // ping_only |
Darin Petkov | 1cbd78f | 2010-07-29 12:38:34 -0700 | [diff] [blame] | 1268 | kActionCodeSuccess, |
| 1269 | NULL, |
| 1270 | &post_data)); |
| 1271 | string post_str(&post_data[0], post_data.size()); |
Jay Srinivasan | 23b92a5 | 2012-10-27 02:00:21 -0700 | [diff] [blame] | 1272 | EXPECT_EQ(post_str.find("ping"), string::npos); |
Darin Petkov | 1cbd78f | 2010-07-29 12:38:34 -0700 | [diff] [blame] | 1273 | } |
| 1274 | |
| 1275 | TEST(OmahaRequestActionTest, LastPingDayUpdateTest) { |
| 1276 | // 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] | 1277 | // minus 200 seconds with a slack of 5 seconds. Therefore, the test |
Darin Petkov | 1cbd78f | 2010-07-29 12:38:34 -0700 | [diff] [blame] | 1278 | // may fail if it runs for longer than 5 seconds. It shouldn't run |
| 1279 | // that long though. |
| 1280 | int64_t midnight = |
| 1281 | (Time::Now() - TimeDelta::FromSeconds(200)).ToInternalValue(); |
| 1282 | int64_t midnight_slack = |
| 1283 | (Time::Now() - TimeDelta::FromSeconds(195)).ToInternalValue(); |
Darin Petkov | 9c096d6 | 2010-11-17 14:49:04 -0800 | [diff] [blame] | 1284 | NiceMock<PrefsMock> prefs; |
Darin Petkov | 1cbd78f | 2010-07-29 12:38:34 -0700 | [diff] [blame] | 1285 | EXPECT_CALL(prefs, SetInt64(kPrefsLastActivePingDay, |
| 1286 | AllOf(Ge(midnight), Le(midnight_slack)))) |
| 1287 | .WillOnce(Return(true)); |
| 1288 | EXPECT_CALL(prefs, SetInt64(kPrefsLastRollCallPingDay, |
| 1289 | AllOf(Ge(midnight), Le(midnight_slack)))) |
| 1290 | .WillOnce(Return(true)); |
| 1291 | ASSERT_TRUE( |
| 1292 | TestUpdateCheck(&prefs, |
| 1293 | kDefaultTestParams, |
Jay Srinivasan | 23b92a5 | 2012-10-27 02:00:21 -0700 | [diff] [blame] | 1294 | "<?xml version=\"1.0\" encoding=\"UTF-8\"?><response " |
| 1295 | "protocol=\"3.0\"><daystart elapsed_seconds=\"200\"/>" |
Darin Petkov | 1cbd78f | 2010-07-29 12:38:34 -0700 | [diff] [blame] | 1296 | "<app appid=\"foo\" status=\"ok\"><ping status=\"ok\"/>" |
Jay Srinivasan | 23b92a5 | 2012-10-27 02:00:21 -0700 | [diff] [blame] | 1297 | "<updatecheck status=\"noupdate\"/></app></response>", |
Darin Petkov | edc522e | 2010-11-05 09:35:17 -0700 | [diff] [blame] | 1298 | -1, |
Darin Petkov | 265f290 | 2011-05-09 15:17:40 -0700 | [diff] [blame] | 1299 | false, // ping_only |
Darin Petkov | 1cbd78f | 2010-07-29 12:38:34 -0700 | [diff] [blame] | 1300 | kActionCodeSuccess, |
| 1301 | NULL, |
| 1302 | NULL)); |
| 1303 | } |
| 1304 | |
| 1305 | TEST(OmahaRequestActionTest, NoElapsedSecondsTest) { |
Darin Petkov | 9c096d6 | 2010-11-17 14:49:04 -0800 | [diff] [blame] | 1306 | NiceMock<PrefsMock> prefs; |
Darin Petkov | 1cbd78f | 2010-07-29 12:38:34 -0700 | [diff] [blame] | 1307 | EXPECT_CALL(prefs, SetInt64(kPrefsLastActivePingDay, _)).Times(0); |
| 1308 | EXPECT_CALL(prefs, SetInt64(kPrefsLastRollCallPingDay, _)).Times(0); |
| 1309 | ASSERT_TRUE( |
| 1310 | TestUpdateCheck(&prefs, |
| 1311 | kDefaultTestParams, |
Jay Srinivasan | 23b92a5 | 2012-10-27 02:00:21 -0700 | [diff] [blame] | 1312 | "<?xml version=\"1.0\" encoding=\"UTF-8\"?><response " |
| 1313 | "protocol=\"3.0\"><daystart blah=\"200\"/>" |
Darin Petkov | 1cbd78f | 2010-07-29 12:38:34 -0700 | [diff] [blame] | 1314 | "<app appid=\"foo\" status=\"ok\"><ping status=\"ok\"/>" |
Jay Srinivasan | 23b92a5 | 2012-10-27 02:00:21 -0700 | [diff] [blame] | 1315 | "<updatecheck status=\"noupdate\"/></app></response>", |
Darin Petkov | edc522e | 2010-11-05 09:35:17 -0700 | [diff] [blame] | 1316 | -1, |
Darin Petkov | 265f290 | 2011-05-09 15:17:40 -0700 | [diff] [blame] | 1317 | false, // ping_only |
Darin Petkov | 1cbd78f | 2010-07-29 12:38:34 -0700 | [diff] [blame] | 1318 | kActionCodeSuccess, |
| 1319 | NULL, |
| 1320 | NULL)); |
| 1321 | } |
| 1322 | |
| 1323 | TEST(OmahaRequestActionTest, BadElapsedSecondsTest) { |
Darin Petkov | 9c096d6 | 2010-11-17 14:49:04 -0800 | [diff] [blame] | 1324 | NiceMock<PrefsMock> prefs; |
Darin Petkov | 1cbd78f | 2010-07-29 12:38:34 -0700 | [diff] [blame] | 1325 | EXPECT_CALL(prefs, SetInt64(kPrefsLastActivePingDay, _)).Times(0); |
| 1326 | EXPECT_CALL(prefs, SetInt64(kPrefsLastRollCallPingDay, _)).Times(0); |
| 1327 | ASSERT_TRUE( |
| 1328 | TestUpdateCheck(&prefs, |
| 1329 | kDefaultTestParams, |
Jay Srinivasan | 23b92a5 | 2012-10-27 02:00:21 -0700 | [diff] [blame] | 1330 | "<?xml version=\"1.0\" encoding=\"UTF-8\"?><response " |
| 1331 | "protocol=\"3.0\"><daystart elapsed_seconds=\"x\"/>" |
Darin Petkov | 1cbd78f | 2010-07-29 12:38:34 -0700 | [diff] [blame] | 1332 | "<app appid=\"foo\" status=\"ok\"><ping status=\"ok\"/>" |
Jay Srinivasan | 23b92a5 | 2012-10-27 02:00:21 -0700 | [diff] [blame] | 1333 | "<updatecheck status=\"noupdate\"/></app></response>", |
Darin Petkov | edc522e | 2010-11-05 09:35:17 -0700 | [diff] [blame] | 1334 | -1, |
Darin Petkov | 265f290 | 2011-05-09 15:17:40 -0700 | [diff] [blame] | 1335 | false, // ping_only |
Darin Petkov | 1cbd78f | 2010-07-29 12:38:34 -0700 | [diff] [blame] | 1336 | kActionCodeSuccess, |
| 1337 | NULL, |
| 1338 | NULL)); |
| 1339 | } |
| 1340 | |
Darin Petkov | 84c763c | 2010-07-29 16:27:58 -0700 | [diff] [blame] | 1341 | TEST(OmahaRequestActionTest, NoUniqueIDTest) { |
| 1342 | vector<char> post_data; |
| 1343 | ASSERT_FALSE(TestUpdateCheck(NULL, // prefs |
| 1344 | kDefaultTestParams, |
| 1345 | "invalid xml>", |
Darin Petkov | edc522e | 2010-11-05 09:35:17 -0700 | [diff] [blame] | 1346 | -1, |
Darin Petkov | 265f290 | 2011-05-09 15:17:40 -0700 | [diff] [blame] | 1347 | false, // ping_only |
Darin Petkov | edc522e | 2010-11-05 09:35:17 -0700 | [diff] [blame] | 1348 | kActionCodeOmahaRequestXMLParseError, |
Darin Petkov | 84c763c | 2010-07-29 16:27:58 -0700 | [diff] [blame] | 1349 | NULL, // response |
| 1350 | &post_data)); |
| 1351 | // convert post_data to string |
| 1352 | string post_str(&post_data[0], post_data.size()); |
| 1353 | EXPECT_EQ(post_str.find("machineid="), string::npos); |
| 1354 | EXPECT_EQ(post_str.find("userid="), string::npos); |
| 1355 | } |
| 1356 | |
Darin Petkov | edc522e | 2010-11-05 09:35:17 -0700 | [diff] [blame] | 1357 | TEST(OmahaRequestActionTest, NetworkFailureTest) { |
| 1358 | OmahaResponse response; |
| 1359 | ASSERT_FALSE( |
| 1360 | TestUpdateCheck(NULL, // prefs |
| 1361 | kDefaultTestParams, |
| 1362 | "", |
| 1363 | 501, |
Darin Petkov | 265f290 | 2011-05-09 15:17:40 -0700 | [diff] [blame] | 1364 | false, // ping_only |
Darin Petkov | edc522e | 2010-11-05 09:35:17 -0700 | [diff] [blame] | 1365 | static_cast<ActionExitCode>( |
| 1366 | kActionCodeOmahaRequestHTTPResponseBase + 501), |
| 1367 | &response, |
| 1368 | NULL)); |
| 1369 | EXPECT_FALSE(response.update_exists); |
| 1370 | } |
| 1371 | |
| 1372 | TEST(OmahaRequestActionTest, NetworkFailureBadHTTPCodeTest) { |
| 1373 | OmahaResponse response; |
| 1374 | ASSERT_FALSE( |
| 1375 | TestUpdateCheck(NULL, // prefs |
| 1376 | kDefaultTestParams, |
| 1377 | "", |
| 1378 | 1500, |
Darin Petkov | 265f290 | 2011-05-09 15:17:40 -0700 | [diff] [blame] | 1379 | false, // ping_only |
Darin Petkov | edc522e | 2010-11-05 09:35:17 -0700 | [diff] [blame] | 1380 | static_cast<ActionExitCode>( |
| 1381 | kActionCodeOmahaRequestHTTPResponseBase + 999), |
| 1382 | &response, |
| 1383 | NULL)); |
| 1384 | EXPECT_FALSE(response.update_exists); |
| 1385 | } |
| 1386 | |
Jay Srinivasan | 34b5d86 | 2012-07-23 11:43:22 -0700 | [diff] [blame] | 1387 | TEST(OmahaRequestActionTest, TestUpdateFirstSeenAtGetsPersistedFirstTime) { |
| 1388 | OmahaResponse response; |
| 1389 | OmahaRequestParams params = kDefaultTestParams; |
Jay Srinivasan | ae4697c | 2013-03-18 17:08:08 -0700 | [diff] [blame] | 1390 | params.set_wall_clock_based_wait_enabled(true); |
| 1391 | params.set_waiting_period(TimeDelta().FromDays(1)); |
| 1392 | params.set_update_check_count_wait_enabled(false); |
Jay Srinivasan | 34b5d86 | 2012-07-23 11:43:22 -0700 | [diff] [blame] | 1393 | |
| 1394 | string prefs_dir; |
| 1395 | EXPECT_TRUE(utils::MakeTempDirectory("/tmp/ue_ut_prefs.XXXXXX", |
| 1396 | &prefs_dir)); |
| 1397 | ScopedDirRemover temp_dir_remover(prefs_dir); |
| 1398 | |
| 1399 | Prefs prefs; |
| 1400 | LOG_IF(ERROR, !prefs.Init(FilePath(prefs_dir))) |
| 1401 | << "Failed to initialize preferences."; |
| 1402 | |
| 1403 | ASSERT_FALSE(TestUpdateCheck( |
| 1404 | &prefs, // prefs |
| 1405 | params, |
| 1406 | GetUpdateResponse2(OmahaRequestParams::kAppId, |
| 1407 | "1.2.3.4", // version |
| 1408 | "http://more/info", |
| 1409 | "true", // prompt |
Jay Srinivasan | 23b92a5 | 2012-10-27 02:00:21 -0700 | [diff] [blame] | 1410 | "http://code/base/", // dl url |
| 1411 | "file.signed", // file name |
Jay Srinivasan | 34b5d86 | 2012-07-23 11:43:22 -0700 | [diff] [blame] | 1412 | "HASH1234=", // checksum |
| 1413 | "false", // needs admin |
| 1414 | "123", // size |
| 1415 | "", // deadline |
| 1416 | "7"), // max days to scatter |
| 1417 | -1, |
| 1418 | false, // ping_only |
| 1419 | kActionCodeOmahaUpdateDeferredPerPolicy, |
| 1420 | &response, |
| 1421 | NULL)); |
| 1422 | |
| 1423 | int64 timestamp = 0; |
| 1424 | ASSERT_TRUE(prefs.GetInt64(kPrefsUpdateFirstSeenAt, ×tamp)); |
| 1425 | ASSERT_TRUE(timestamp > 0); |
| 1426 | EXPECT_FALSE(response.update_exists); |
| 1427 | } |
| 1428 | |
| 1429 | TEST(OmahaRequestActionTest, TestUpdateFirstSeenAtGetsUsedIfAlreadyPresent) { |
| 1430 | OmahaResponse response; |
| 1431 | OmahaRequestParams params = kDefaultTestParams; |
Jay Srinivasan | ae4697c | 2013-03-18 17:08:08 -0700 | [diff] [blame] | 1432 | params.set_wall_clock_based_wait_enabled(true); |
| 1433 | params.set_waiting_period(TimeDelta().FromDays(1)); |
| 1434 | params.set_update_check_count_wait_enabled(false); |
Jay Srinivasan | 34b5d86 | 2012-07-23 11:43:22 -0700 | [diff] [blame] | 1435 | |
| 1436 | string prefs_dir; |
| 1437 | EXPECT_TRUE(utils::MakeTempDirectory("/tmp/ue_ut_prefs.XXXXXX", |
| 1438 | &prefs_dir)); |
| 1439 | ScopedDirRemover temp_dir_remover(prefs_dir); |
| 1440 | |
| 1441 | Prefs prefs; |
| 1442 | LOG_IF(ERROR, !prefs.Init(FilePath(prefs_dir))) |
| 1443 | << "Failed to initialize preferences."; |
| 1444 | |
| 1445 | // Set the timestamp to a very old value such that it exceeds the |
| 1446 | // waiting period set above. |
| 1447 | Time t1; |
| 1448 | Time::FromString("1/1/2012", &t1); |
| 1449 | ASSERT_TRUE(prefs.SetInt64(kPrefsUpdateFirstSeenAt, t1.ToInternalValue())); |
| 1450 | ASSERT_TRUE(TestUpdateCheck( |
| 1451 | &prefs, // prefs |
| 1452 | params, |
| 1453 | GetUpdateResponse2(OmahaRequestParams::kAppId, |
| 1454 | "1.2.3.4", // version |
| 1455 | "http://more/info", |
| 1456 | "true", // prompt |
Jay Srinivasan | 23b92a5 | 2012-10-27 02:00:21 -0700 | [diff] [blame] | 1457 | "http://code/base/", // dl url |
| 1458 | "file.signed", // file name |
Jay Srinivasan | 34b5d86 | 2012-07-23 11:43:22 -0700 | [diff] [blame] | 1459 | "HASH1234=", // checksum |
| 1460 | "false", // needs admin |
| 1461 | "123", // size |
| 1462 | "", // deadline |
| 1463 | "7"), // max days to scatter |
| 1464 | -1, |
| 1465 | false, // ping_only |
| 1466 | kActionCodeSuccess, |
| 1467 | &response, |
| 1468 | NULL)); |
| 1469 | |
| 1470 | EXPECT_TRUE(response.update_exists); |
| 1471 | |
| 1472 | // Make sure the timestamp t1 is unchanged showing that it was reused. |
| 1473 | int64 timestamp = 0; |
| 1474 | ASSERT_TRUE(prefs.GetInt64(kPrefsUpdateFirstSeenAt, ×tamp)); |
| 1475 | ASSERT_TRUE(timestamp == t1.ToInternalValue()); |
| 1476 | } |
| 1477 | |
Jay Srinivasan | ae4697c | 2013-03-18 17:08:08 -0700 | [diff] [blame] | 1478 | TEST(OmahaRequestActionTest, TestChangingToMoreStableChannel) { |
| 1479 | const string kTestDir = "omaha_request_action-test"; |
| 1480 | ASSERT_EQ(0, System(string("mkdir -p ") + kTestDir + "/etc")); |
| 1481 | ASSERT_EQ(0, System(string("mkdir -p ") + kTestDir + |
Chris Sosa | be45bef | 2013-04-09 18:25:12 -0700 | [diff] [blame^] | 1482 | kStatefulPartition + "/etc")); |
Jay Srinivasan | ae4697c | 2013-03-18 17:08:08 -0700 | [diff] [blame] | 1483 | vector<char> post_data; |
| 1484 | NiceMock<PrefsMock> prefs; |
| 1485 | ASSERT_TRUE(WriteFileString( |
| 1486 | kTestDir + "/etc/lsb-release", |
| 1487 | "CHROMEOS_RELEASE_APPID={11111111-1111-1111-1111-111111111111}\n" |
| 1488 | "CHROMEOS_BOARD_APPID={22222222-2222-2222-2222-222222222222}\n" |
| 1489 | "CHROMEOS_RELEASE_TRACK=canary-channel\n")); |
| 1490 | ASSERT_TRUE(WriteFileString( |
Chris Sosa | be45bef | 2013-04-09 18:25:12 -0700 | [diff] [blame^] | 1491 | kTestDir + kStatefulPartition + "/etc/lsb-release", |
Jay Srinivasan | ae4697c | 2013-03-18 17:08:08 -0700 | [diff] [blame] | 1492 | "CHROMEOS_IS_POWERWASH_ALLOWED=true\n" |
| 1493 | "CHROMEOS_RELEASE_TRACK=stable-channel\n")); |
| 1494 | OmahaRequestParams params = kDefaultTestParams; |
| 1495 | params.set_root(string("./") + kTestDir); |
| 1496 | params.SetLockDown(false); |
| 1497 | params.Init("1.2.3.4", "", 0); |
| 1498 | EXPECT_EQ("canary-channel", params.current_channel()); |
| 1499 | EXPECT_EQ("stable-channel", params.target_channel()); |
| 1500 | EXPECT_TRUE(params.to_more_stable_channel()); |
| 1501 | EXPECT_TRUE(params.is_powerwash_allowed()); |
| 1502 | ASSERT_FALSE(TestUpdateCheck(&prefs, |
| 1503 | params, |
| 1504 | "invalid xml>", |
| 1505 | -1, |
| 1506 | false, // ping_only |
| 1507 | kActionCodeOmahaRequestXMLParseError, |
| 1508 | NULL, // response |
| 1509 | &post_data)); |
| 1510 | // convert post_data to string |
| 1511 | string post_str(&post_data[0], post_data.size()); |
| 1512 | EXPECT_NE(string::npos, post_str.find( |
| 1513 | "appid=\"{22222222-2222-2222-2222-222222222222}\" " |
| 1514 | "version=\"0.0.0.0\" from_version=\"1.2.3.4\" " |
| 1515 | "track=\"stable-channel\" from_track=\"canary-channel\" ")); |
| 1516 | } |
| 1517 | |
| 1518 | TEST(OmahaRequestActionTest, TestChangingToLessStableChannel) { |
| 1519 | const string kTestDir = "omaha_request_action-test"; |
| 1520 | ASSERT_EQ(0, System(string("mkdir -p ") + kTestDir + "/etc")); |
| 1521 | ASSERT_EQ(0, System(string("mkdir -p ") + kTestDir + |
Chris Sosa | be45bef | 2013-04-09 18:25:12 -0700 | [diff] [blame^] | 1522 | kStatefulPartition + "/etc")); |
Jay Srinivasan | ae4697c | 2013-03-18 17:08:08 -0700 | [diff] [blame] | 1523 | vector<char> post_data; |
| 1524 | NiceMock<PrefsMock> prefs; |
| 1525 | ASSERT_TRUE(WriteFileString( |
| 1526 | kTestDir + "/etc/lsb-release", |
| 1527 | "CHROMEOS_RELEASE_APPID={11111111-1111-1111-1111-111111111111}\n" |
| 1528 | "CHROMEOS_BOARD_APPID={22222222-2222-2222-2222-222222222222}\n" |
| 1529 | "CHROMEOS_RELEASE_TRACK=stable-channel\n")); |
| 1530 | ASSERT_TRUE(WriteFileString( |
Chris Sosa | be45bef | 2013-04-09 18:25:12 -0700 | [diff] [blame^] | 1531 | kTestDir + kStatefulPartition + "/etc/lsb-release", |
Jay Srinivasan | ae4697c | 2013-03-18 17:08:08 -0700 | [diff] [blame] | 1532 | "CHROMEOS_RELEASE_TRACK=canary-channel\n")); |
| 1533 | OmahaRequestParams params = kDefaultTestParams; |
| 1534 | params.set_root(string("./") + kTestDir); |
| 1535 | params.SetLockDown(false); |
| 1536 | params.Init("5.6.7.8", "", 0); |
| 1537 | EXPECT_EQ("stable-channel", params.current_channel()); |
| 1538 | EXPECT_EQ("canary-channel", params.target_channel()); |
| 1539 | EXPECT_FALSE(params.to_more_stable_channel()); |
| 1540 | EXPECT_FALSE(params.is_powerwash_allowed()); |
| 1541 | ASSERT_FALSE(TestUpdateCheck(&prefs, |
| 1542 | params, |
| 1543 | "invalid xml>", |
| 1544 | -1, |
| 1545 | false, // ping_only |
| 1546 | kActionCodeOmahaRequestXMLParseError, |
| 1547 | NULL, // response |
| 1548 | &post_data)); |
| 1549 | // convert post_data to string |
| 1550 | string post_str(&post_data[0], post_data.size()); |
| 1551 | EXPECT_NE(string::npos, post_str.find( |
| 1552 | "appid=\"{11111111-1111-1111-1111-111111111111}\" " |
| 1553 | "version=\"5.6.7.8\" " |
| 1554 | "track=\"canary-channel\" from_track=\"stable-channel\"")); |
| 1555 | EXPECT_EQ(string::npos, post_str.find( "from_version")); |
| 1556 | } |
| 1557 | |
Darin Petkov | 6a5b322 | 2010-07-13 14:55:28 -0700 | [diff] [blame] | 1558 | } // namespace chromeos_update_engine |