Darin Petkov | a4a8a8c | 2010-07-15 22:21:12 -0700 | [diff] [blame] | 1 | // Copyright (c) 2010 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" |
| 11 | #include "gtest/gtest.h" |
Darin Petkov | 6a5b322 | 2010-07-13 14:55:28 -0700 | [diff] [blame] | 12 | #include "update_engine/action_pipe.h" |
| 13 | #include "update_engine/mock_http_fetcher.h" |
| 14 | #include "update_engine/omaha_hash_calculator.h" |
| 15 | #include "update_engine/omaha_request_action.h" |
Darin Petkov | a4a8a8c | 2010-07-15 22:21:12 -0700 | [diff] [blame] | 16 | #include "update_engine/omaha_request_params.h" |
Darin Petkov | 6a5b322 | 2010-07-13 14:55:28 -0700 | [diff] [blame] | 17 | #include "update_engine/test_utils.h" |
| 18 | |
| 19 | using std::string; |
| 20 | using std::vector; |
| 21 | |
| 22 | namespace chromeos_update_engine { |
| 23 | |
| 24 | class OmahaRequestActionTest : public ::testing::Test { }; |
| 25 | |
| 26 | namespace { |
| 27 | string GetNoUpdateResponse(const string& app_id) { |
| 28 | return string( |
| 29 | "<?xml version=\"1.0\" encoding=\"UTF-8\"?><gupdate " |
| 30 | "xmlns=\"http://www.google.com/update2/response\" protocol=\"2.0\"><app " |
| 31 | "appid=\"") + app_id + "\" status=\"ok\"><ping " |
| 32 | "status=\"ok\"/><updatecheck status=\"noupdate\"/></app></gupdate>"; |
| 33 | } |
| 34 | |
| 35 | string GetUpdateResponse(const string& app_id, |
| 36 | const string& display_version, |
| 37 | const string& more_info_url, |
| 38 | const string& prompt, |
| 39 | const string& codebase, |
| 40 | const string& hash, |
| 41 | const string& needsadmin, |
| 42 | const string& size) { |
| 43 | return string("<?xml version=\"1.0\" encoding=\"UTF-8\"?><gupdate " |
| 44 | "xmlns=\"http://www.google.com/update2/response\" " |
| 45 | "protocol=\"2.0\"><app " |
| 46 | "appid=\"") + app_id + "\" status=\"ok\"><ping " |
| 47 | "status=\"ok\"/><updatecheck DisplayVersion=\"" + display_version + "\" " |
| 48 | "MoreInfo=\"" + more_info_url + "\" Prompt=\"" + prompt + "\" " |
Andrew de los Reyes | 3270f74 | 2010-07-15 22:28:14 -0700 | [diff] [blame] | 49 | "IsDelta=\"true\" " |
Darin Petkov | 6a5b322 | 2010-07-13 14:55:28 -0700 | [diff] [blame] | 50 | "codebase=\"" + codebase + "\" " |
| 51 | "hash=\"" + hash + "\" needsadmin=\"" + needsadmin + "\" " |
| 52 | "size=\"" + size + "\" status=\"ok\"/></app></gupdate>"; |
| 53 | } |
| 54 | |
| 55 | class OmahaRequestActionTestProcessorDelegate : public ActionProcessorDelegate { |
| 56 | public: |
| 57 | OmahaRequestActionTestProcessorDelegate() |
| 58 | : loop_(NULL), |
Darin Petkov | c1a8b42 | 2010-07-19 11:34:49 -0700 | [diff] [blame] | 59 | expected_code_(kActionCodeSuccess) {} |
Darin Petkov | 6a5b322 | 2010-07-13 14:55:28 -0700 | [diff] [blame] | 60 | virtual ~OmahaRequestActionTestProcessorDelegate() { |
| 61 | } |
Darin Petkov | c1a8b42 | 2010-07-19 11:34:49 -0700 | [diff] [blame] | 62 | virtual void ProcessingDone(const ActionProcessor* processor, |
| 63 | ActionExitCode code) { |
Darin Petkov | 6a5b322 | 2010-07-13 14:55:28 -0700 | [diff] [blame] | 64 | ASSERT_TRUE(loop_); |
| 65 | g_main_loop_quit(loop_); |
| 66 | } |
| 67 | |
| 68 | virtual void ActionCompleted(ActionProcessor* processor, |
| 69 | AbstractAction* action, |
Darin Petkov | c1a8b42 | 2010-07-19 11:34:49 -0700 | [diff] [blame] | 70 | ActionExitCode code) { |
Darin Petkov | 6a5b322 | 2010-07-13 14:55:28 -0700 | [diff] [blame] | 71 | // make sure actions always succeed |
| 72 | if (action->Type() == OmahaRequestAction::StaticType()) |
Darin Petkov | c1a8b42 | 2010-07-19 11:34:49 -0700 | [diff] [blame] | 73 | EXPECT_EQ(expected_code_, code); |
Darin Petkov | 6a5b322 | 2010-07-13 14:55:28 -0700 | [diff] [blame] | 74 | else |
Darin Petkov | c1a8b42 | 2010-07-19 11:34:49 -0700 | [diff] [blame] | 75 | EXPECT_EQ(kActionCodeSuccess, code); |
Darin Petkov | 6a5b322 | 2010-07-13 14:55:28 -0700 | [diff] [blame] | 76 | } |
| 77 | GMainLoop *loop_; |
Darin Petkov | c1a8b42 | 2010-07-19 11:34:49 -0700 | [diff] [blame] | 78 | ActionExitCode expected_code_; |
Darin Petkov | 6a5b322 | 2010-07-13 14:55:28 -0700 | [diff] [blame] | 79 | }; |
| 80 | |
| 81 | gboolean StartProcessorInRunLoop(gpointer data) { |
| 82 | ActionProcessor *processor = reinterpret_cast<ActionProcessor*>(data); |
| 83 | processor->StartProcessing(); |
| 84 | return FALSE; |
| 85 | } |
| 86 | |
| 87 | } // namespace {} |
| 88 | |
| 89 | class OutputObjectCollectorAction; |
| 90 | |
| 91 | template<> |
| 92 | class ActionTraits<OutputObjectCollectorAction> { |
| 93 | public: |
| 94 | // Does not take an object for input |
| 95 | typedef OmahaResponse InputObjectType; |
| 96 | // On success, puts the output path on output |
| 97 | typedef NoneType OutputObjectType; |
| 98 | }; |
| 99 | |
| 100 | class OutputObjectCollectorAction : public Action<OutputObjectCollectorAction> { |
| 101 | public: |
| 102 | OutputObjectCollectorAction() : has_input_object_(false) {} |
| 103 | void PerformAction() { |
| 104 | // copy input object |
| 105 | has_input_object_ = HasInputObject(); |
| 106 | if (has_input_object_) |
| 107 | omaha_response_ = GetInputObject(); |
Darin Petkov | c1a8b42 | 2010-07-19 11:34:49 -0700 | [diff] [blame] | 108 | processor_->ActionComplete(this, kActionCodeSuccess); |
Darin Petkov | 6a5b322 | 2010-07-13 14:55:28 -0700 | [diff] [blame] | 109 | } |
| 110 | // Should never be called |
| 111 | void TerminateProcessing() { |
| 112 | CHECK(false); |
| 113 | } |
| 114 | // Debugging/logging |
| 115 | static std::string StaticType() { |
| 116 | return "OutputObjectCollectorAction"; |
| 117 | } |
| 118 | std::string Type() const { return StaticType(); } |
| 119 | bool has_input_object_; |
| 120 | OmahaResponse omaha_response_; |
| 121 | }; |
| 122 | |
| 123 | // returns true iff an output response was obtained from the |
| 124 | // OmahaRequestAction. out_response may be NULL. |
| 125 | // out_post_data may be null; if non-null, the post-data received by the |
| 126 | // mock HttpFetcher is returned. |
Darin Petkov | 0dc8e9a | 2010-07-14 14:51:57 -0700 | [diff] [blame] | 127 | bool TestUpdateCheck(const OmahaRequestParams& params, |
| 128 | const string& http_response, |
Darin Petkov | c1a8b42 | 2010-07-19 11:34:49 -0700 | [diff] [blame] | 129 | ActionExitCode expected_code, |
Darin Petkov | 0dc8e9a | 2010-07-14 14:51:57 -0700 | [diff] [blame] | 130 | OmahaResponse* out_response, |
| 131 | vector<char>* out_post_data) { |
| 132 | GMainLoop* loop = g_main_loop_new(g_main_context_default(), FALSE); |
| 133 | MockHttpFetcher* fetcher = new MockHttpFetcher(http_response.data(), |
Darin Petkov | 6a5b322 | 2010-07-13 14:55:28 -0700 | [diff] [blame] | 134 | http_response.size()); |
Darin Petkov | a4a8a8c | 2010-07-15 22:21:12 -0700 | [diff] [blame] | 135 | OmahaRequestAction action(params, NULL, fetcher); |
Darin Petkov | 6a5b322 | 2010-07-13 14:55:28 -0700 | [diff] [blame] | 136 | OmahaRequestActionTestProcessorDelegate delegate; |
| 137 | delegate.loop_ = loop; |
Darin Petkov | c1a8b42 | 2010-07-19 11:34:49 -0700 | [diff] [blame] | 138 | delegate.expected_code_ = expected_code; |
Darin Petkov | a4a8a8c | 2010-07-15 22:21:12 -0700 | [diff] [blame] | 139 | |
Darin Petkov | 6a5b322 | 2010-07-13 14:55:28 -0700 | [diff] [blame] | 140 | ActionProcessor processor; |
Darin Petkov | 6a5b322 | 2010-07-13 14:55:28 -0700 | [diff] [blame] | 141 | processor.set_delegate(&delegate); |
Darin Petkov | 6a5b322 | 2010-07-13 14:55:28 -0700 | [diff] [blame] | 142 | processor.EnqueueAction(&action); |
| 143 | |
| 144 | OutputObjectCollectorAction collector_action; |
Darin Petkov | 6a5b322 | 2010-07-13 14:55:28 -0700 | [diff] [blame] | 145 | BondActions(&action, &collector_action); |
| 146 | processor.EnqueueAction(&collector_action); |
| 147 | |
| 148 | g_timeout_add(0, &StartProcessorInRunLoop, &processor); |
| 149 | g_main_loop_run(loop); |
| 150 | g_main_loop_unref(loop); |
| 151 | if (collector_action.has_input_object_ && out_response) |
| 152 | *out_response = collector_action.omaha_response_; |
| 153 | if (out_post_data) |
| 154 | *out_post_data = fetcher->post_data(); |
| 155 | return collector_action.has_input_object_; |
| 156 | } |
| 157 | |
Darin Petkov | 0dc8e9a | 2010-07-14 14:51:57 -0700 | [diff] [blame] | 158 | // Tests Event requests -- they should always succeed. |out_post_data| |
| 159 | // may be null; if non-null, the post-data received by the mock |
| 160 | // HttpFetcher is returned. |
| 161 | void TestEvent(const OmahaRequestParams& params, |
| 162 | OmahaEvent* event, |
| 163 | const string& http_response, |
| 164 | vector<char>* out_post_data) { |
| 165 | GMainLoop* loop = g_main_loop_new(g_main_context_default(), FALSE); |
| 166 | MockHttpFetcher* fetcher = new MockHttpFetcher(http_response.data(), |
| 167 | http_response.size()); |
Darin Petkov | a4a8a8c | 2010-07-15 22:21:12 -0700 | [diff] [blame] | 168 | OmahaRequestAction action(params, event, fetcher); |
Darin Petkov | 0dc8e9a | 2010-07-14 14:51:57 -0700 | [diff] [blame] | 169 | OmahaRequestActionTestProcessorDelegate delegate; |
| 170 | delegate.loop_ = loop; |
| 171 | ActionProcessor processor; |
Darin Petkov | 0dc8e9a | 2010-07-14 14:51:57 -0700 | [diff] [blame] | 172 | processor.set_delegate(&delegate); |
Darin Petkov | 0dc8e9a | 2010-07-14 14:51:57 -0700 | [diff] [blame] | 173 | processor.EnqueueAction(&action); |
| 174 | |
Darin Petkov | 0dc8e9a | 2010-07-14 14:51:57 -0700 | [diff] [blame] | 175 | g_timeout_add(0, &StartProcessorInRunLoop, &processor); |
| 176 | g_main_loop_run(loop); |
| 177 | g_main_loop_unref(loop); |
| 178 | if (out_post_data) |
| 179 | *out_post_data = fetcher->post_data(); |
| 180 | } |
| 181 | |
Darin Petkov | 6a5b322 | 2010-07-13 14:55:28 -0700 | [diff] [blame] | 182 | TEST(OmahaRequestActionTest, NoUpdateTest) { |
| 183 | OmahaRequestParams params("", // machine_id |
| 184 | "", // user_id |
| 185 | OmahaRequestParams::kOsPlatform, |
| 186 | OmahaRequestParams::kOsVersion, |
| 187 | "", // os_sp |
| 188 | "x86-generic", |
| 189 | OmahaRequestParams::kAppId, |
| 190 | "0.1.0.0", |
| 191 | "en-US", |
| 192 | "unittest", |
Andrew de los Reyes | 3f0303a | 2010-07-15 22:35:35 -0700 | [diff] [blame] | 193 | false, // delta okay |
Darin Petkov | 6a5b322 | 2010-07-13 14:55:28 -0700 | [diff] [blame] | 194 | ""); // url |
| 195 | OmahaResponse response; |
| 196 | ASSERT_TRUE( |
Darin Petkov | 0dc8e9a | 2010-07-14 14:51:57 -0700 | [diff] [blame] | 197 | TestUpdateCheck(params, |
| 198 | GetNoUpdateResponse(OmahaRequestParams::kAppId), |
Darin Petkov | c1a8b42 | 2010-07-19 11:34:49 -0700 | [diff] [blame] | 199 | kActionCodeSuccess, |
Darin Petkov | 0dc8e9a | 2010-07-14 14:51:57 -0700 | [diff] [blame] | 200 | &response, |
| 201 | NULL)); |
Darin Petkov | 6a5b322 | 2010-07-13 14:55:28 -0700 | [diff] [blame] | 202 | EXPECT_FALSE(response.update_exists); |
| 203 | } |
| 204 | |
| 205 | TEST(OmahaRequestActionTest, ValidUpdateTest) { |
| 206 | OmahaRequestParams params("machine_id", |
| 207 | "user_id", |
| 208 | OmahaRequestParams::kOsPlatform, |
| 209 | OmahaRequestParams::kOsVersion, |
| 210 | "service_pack", |
| 211 | "arm-generic", |
| 212 | OmahaRequestParams::kAppId, |
| 213 | "0.1.0.0", |
| 214 | "en-US", |
| 215 | "unittest_track", |
Andrew de los Reyes | 3f0303a | 2010-07-15 22:35:35 -0700 | [diff] [blame] | 216 | false, // delta okay |
Darin Petkov | 6a5b322 | 2010-07-13 14:55:28 -0700 | [diff] [blame] | 217 | ""); // url |
| 218 | OmahaResponse response; |
| 219 | ASSERT_TRUE( |
Darin Petkov | 0dc8e9a | 2010-07-14 14:51:57 -0700 | [diff] [blame] | 220 | TestUpdateCheck(params, |
| 221 | GetUpdateResponse(OmahaRequestParams::kAppId, |
| 222 | "1.2.3.4", // version |
| 223 | "http://more/info", |
| 224 | "true", // prompt |
| 225 | "http://code/base", // dl url |
| 226 | "HASH1234=", // checksum |
| 227 | "false", // needs admin |
| 228 | "123"), // size |
Darin Petkov | c1a8b42 | 2010-07-19 11:34:49 -0700 | [diff] [blame] | 229 | kActionCodeSuccess, |
Darin Petkov | 0dc8e9a | 2010-07-14 14:51:57 -0700 | [diff] [blame] | 230 | &response, |
| 231 | NULL)); |
Darin Petkov | 6a5b322 | 2010-07-13 14:55:28 -0700 | [diff] [blame] | 232 | EXPECT_TRUE(response.update_exists); |
| 233 | EXPECT_EQ("1.2.3.4", response.display_version); |
| 234 | EXPECT_EQ("http://code/base", response.codebase); |
| 235 | EXPECT_EQ("http://more/info", response.more_info_url); |
Andrew de los Reyes | 3270f74 | 2010-07-15 22:28:14 -0700 | [diff] [blame] | 236 | EXPECT_TRUE(response.is_delta); |
Darin Petkov | 6a5b322 | 2010-07-13 14:55:28 -0700 | [diff] [blame] | 237 | EXPECT_EQ("HASH1234=", response.hash); |
| 238 | EXPECT_EQ(123, response.size); |
| 239 | EXPECT_FALSE(response.needs_admin); |
| 240 | EXPECT_TRUE(response.prompt); |
| 241 | } |
| 242 | |
| 243 | TEST(OmahaRequestActionTest, NoOutputPipeTest) { |
| 244 | OmahaRequestParams params("", // machine_id |
| 245 | "", // usr_id |
| 246 | OmahaRequestParams::kOsPlatform, |
| 247 | OmahaRequestParams::kOsVersion, |
| 248 | "", // os_sp |
| 249 | "", // os_board |
| 250 | OmahaRequestParams::kAppId, |
| 251 | "0.1.0.0", |
| 252 | "en-US", |
| 253 | "unittest", |
Andrew de los Reyes | 3f0303a | 2010-07-15 22:35:35 -0700 | [diff] [blame] | 254 | false, // delta okay |
Darin Petkov | 6a5b322 | 2010-07-13 14:55:28 -0700 | [diff] [blame] | 255 | ""); // url |
| 256 | const string http_response(GetNoUpdateResponse(OmahaRequestParams::kAppId)); |
| 257 | |
| 258 | GMainLoop *loop = g_main_loop_new(g_main_context_default(), FALSE); |
| 259 | |
Darin Petkov | a4a8a8c | 2010-07-15 22:21:12 -0700 | [diff] [blame] | 260 | OmahaRequestAction action(params, NULL, |
Darin Petkov | 0dc8e9a | 2010-07-14 14:51:57 -0700 | [diff] [blame] | 261 | new MockHttpFetcher(http_response.data(), |
Darin Petkov | 6a5b322 | 2010-07-13 14:55:28 -0700 | [diff] [blame] | 262 | http_response.size())); |
| 263 | OmahaRequestActionTestProcessorDelegate delegate; |
| 264 | delegate.loop_ = loop; |
| 265 | ActionProcessor processor; |
| 266 | processor.set_delegate(&delegate); |
Darin Petkov | 6a5b322 | 2010-07-13 14:55:28 -0700 | [diff] [blame] | 267 | processor.EnqueueAction(&action); |
Darin Petkov | 6a5b322 | 2010-07-13 14:55:28 -0700 | [diff] [blame] | 268 | |
| 269 | g_timeout_add(0, &StartProcessorInRunLoop, &processor); |
| 270 | g_main_loop_run(loop); |
| 271 | g_main_loop_unref(loop); |
| 272 | EXPECT_FALSE(processor.IsRunning()); |
| 273 | } |
| 274 | |
| 275 | TEST(OmahaRequestActionTest, InvalidXmlTest) { |
| 276 | OmahaRequestParams params("machine_id", |
| 277 | "user_id", |
| 278 | OmahaRequestParams::kOsPlatform, |
| 279 | OmahaRequestParams::kOsVersion, |
| 280 | "service_pack", |
| 281 | "x86-generic", |
| 282 | OmahaRequestParams::kAppId, |
| 283 | "0.1.0.0", |
| 284 | "en-US", |
| 285 | "unittest_track", |
Andrew de los Reyes | 3f0303a | 2010-07-15 22:35:35 -0700 | [diff] [blame] | 286 | false, // delta okay |
Darin Petkov | 6a5b322 | 2010-07-13 14:55:28 -0700 | [diff] [blame] | 287 | "http://url"); |
| 288 | OmahaResponse response; |
| 289 | ASSERT_FALSE( |
Darin Petkov | 0dc8e9a | 2010-07-14 14:51:57 -0700 | [diff] [blame] | 290 | TestUpdateCheck(params, |
| 291 | "invalid xml>", |
Darin Petkov | c1a8b42 | 2010-07-19 11:34:49 -0700 | [diff] [blame] | 292 | kActionCodeError, |
Darin Petkov | 0dc8e9a | 2010-07-14 14:51:57 -0700 | [diff] [blame] | 293 | &response, |
| 294 | NULL)); |
Darin Petkov | 6a5b322 | 2010-07-13 14:55:28 -0700 | [diff] [blame] | 295 | EXPECT_FALSE(response.update_exists); |
| 296 | } |
| 297 | |
| 298 | TEST(OmahaRequestActionTest, MissingStatusTest) { |
| 299 | OmahaRequestParams params("machine_id", |
| 300 | "user_id", |
| 301 | OmahaRequestParams::kOsPlatform, |
| 302 | OmahaRequestParams::kOsVersion, |
| 303 | "service_pack", |
| 304 | "x86-generic", |
| 305 | OmahaRequestParams::kAppId, |
| 306 | "0.1.0.0", |
| 307 | "en-US", |
| 308 | "unittest_track", |
Andrew de los Reyes | 3f0303a | 2010-07-15 22:35:35 -0700 | [diff] [blame] | 309 | false, // delta okay |
Darin Petkov | 6a5b322 | 2010-07-13 14:55:28 -0700 | [diff] [blame] | 310 | "http://url"); |
| 311 | OmahaResponse response; |
Darin Petkov | 0dc8e9a | 2010-07-14 14:51:57 -0700 | [diff] [blame] | 312 | ASSERT_FALSE(TestUpdateCheck( |
Darin Petkov | 6a5b322 | 2010-07-13 14:55:28 -0700 | [diff] [blame] | 313 | params, |
| 314 | "<?xml version=\"1.0\" encoding=\"UTF-8\"?><gupdate " |
| 315 | "xmlns=\"http://www.google.com/update2/response\" protocol=\"2.0\"><app " |
| 316 | "appid=\"foo\" status=\"ok\"><ping " |
| 317 | "status=\"ok\"/><updatecheck/></app></gupdate>", |
Darin Petkov | c1a8b42 | 2010-07-19 11:34:49 -0700 | [diff] [blame] | 318 | kActionCodeError, |
Darin Petkov | 6a5b322 | 2010-07-13 14:55:28 -0700 | [diff] [blame] | 319 | &response, |
| 320 | NULL)); |
| 321 | EXPECT_FALSE(response.update_exists); |
| 322 | } |
| 323 | |
| 324 | TEST(OmahaRequestActionTest, InvalidStatusTest) { |
| 325 | OmahaRequestParams params("machine_id", |
| 326 | "user_id", |
| 327 | OmahaRequestParams::kOsPlatform, |
| 328 | OmahaRequestParams::kOsVersion, |
| 329 | "service_pack", |
| 330 | "x86-generic", |
| 331 | OmahaRequestParams::kAppId, |
| 332 | "0.1.0.0", |
| 333 | "en-US", |
| 334 | "unittest_track", |
Andrew de los Reyes | 3f0303a | 2010-07-15 22:35:35 -0700 | [diff] [blame] | 335 | false, // delta okay |
Darin Petkov | 6a5b322 | 2010-07-13 14:55:28 -0700 | [diff] [blame] | 336 | "http://url"); |
| 337 | OmahaResponse response; |
Darin Petkov | 0dc8e9a | 2010-07-14 14:51:57 -0700 | [diff] [blame] | 338 | ASSERT_FALSE(TestUpdateCheck( |
Darin Petkov | 6a5b322 | 2010-07-13 14:55:28 -0700 | [diff] [blame] | 339 | params, |
| 340 | "<?xml version=\"1.0\" encoding=\"UTF-8\"?><gupdate " |
| 341 | "xmlns=\"http://www.google.com/update2/response\" protocol=\"2.0\"><app " |
| 342 | "appid=\"foo\" status=\"ok\"><ping " |
| 343 | "status=\"ok\"/><updatecheck status=\"foo\"/></app></gupdate>", |
Darin Petkov | c1a8b42 | 2010-07-19 11:34:49 -0700 | [diff] [blame] | 344 | kActionCodeError, |
Darin Petkov | 6a5b322 | 2010-07-13 14:55:28 -0700 | [diff] [blame] | 345 | &response, |
| 346 | NULL)); |
| 347 | EXPECT_FALSE(response.update_exists); |
| 348 | } |
| 349 | |
| 350 | TEST(OmahaRequestActionTest, MissingNodesetTest) { |
| 351 | OmahaRequestParams params("machine_id", |
| 352 | "user_id", |
| 353 | OmahaRequestParams::kOsPlatform, |
| 354 | OmahaRequestParams::kOsVersion, |
| 355 | "service_pack", |
| 356 | "x86-generic", |
| 357 | OmahaRequestParams::kAppId, |
| 358 | "0.1.0.0", |
| 359 | "en-US", |
| 360 | "unittest_track", |
Andrew de los Reyes | 3f0303a | 2010-07-15 22:35:35 -0700 | [diff] [blame] | 361 | false, // delta okay |
Darin Petkov | 6a5b322 | 2010-07-13 14:55:28 -0700 | [diff] [blame] | 362 | "http://url"); |
| 363 | OmahaResponse response; |
Darin Petkov | 0dc8e9a | 2010-07-14 14:51:57 -0700 | [diff] [blame] | 364 | ASSERT_FALSE(TestUpdateCheck( |
Darin Petkov | 6a5b322 | 2010-07-13 14:55:28 -0700 | [diff] [blame] | 365 | params, |
| 366 | "<?xml version=\"1.0\" encoding=\"UTF-8\"?><gupdate " |
| 367 | "xmlns=\"http://www.google.com/update2/response\" protocol=\"2.0\"><app " |
| 368 | "appid=\"foo\" status=\"ok\"><ping " |
| 369 | "status=\"ok\"/></app></gupdate>", |
Darin Petkov | c1a8b42 | 2010-07-19 11:34:49 -0700 | [diff] [blame] | 370 | kActionCodeError, |
Darin Petkov | 6a5b322 | 2010-07-13 14:55:28 -0700 | [diff] [blame] | 371 | &response, |
| 372 | NULL)); |
| 373 | EXPECT_FALSE(response.update_exists); |
| 374 | } |
| 375 | |
| 376 | TEST(OmahaRequestActionTest, MissingFieldTest) { |
| 377 | OmahaRequestParams params("machine_id", |
| 378 | "user_id", |
| 379 | OmahaRequestParams::kOsPlatform, |
| 380 | OmahaRequestParams::kOsVersion, |
| 381 | "service_pack", |
| 382 | "x86-generic", |
| 383 | OmahaRequestParams::kAppId, |
| 384 | "0.1.0.0", |
| 385 | "en-US", |
| 386 | "unittest_track", |
Andrew de los Reyes | 3f0303a | 2010-07-15 22:35:35 -0700 | [diff] [blame] | 387 | false, // delta okay |
Darin Petkov | 6a5b322 | 2010-07-13 14:55:28 -0700 | [diff] [blame] | 388 | "http://url"); |
| 389 | OmahaResponse response; |
Darin Petkov | 0dc8e9a | 2010-07-14 14:51:57 -0700 | [diff] [blame] | 390 | ASSERT_TRUE(TestUpdateCheck(params, |
| 391 | string("<?xml version=\"1.0\" " |
| 392 | "encoding=\"UTF-8\"?><gupdate " |
| 393 | "xmlns=\"http://www.google.com/" |
| 394 | "update2/response\" " |
| 395 | "protocol=\"2.0\"><app appid=\"") + |
| 396 | OmahaRequestParams::kAppId |
| 397 | + "\" status=\"ok\"><ping " |
| 398 | "status=\"ok\"/><updatecheck " |
| 399 | "DisplayVersion=\"1.2.3.4\" " |
| 400 | "Prompt=\"false\" " |
| 401 | "codebase=\"http://code/base\" " |
| 402 | "hash=\"HASH1234=\" needsadmin=\"true\" " |
| 403 | "size=\"123\" " |
| 404 | "status=\"ok\"/></app></gupdate>", |
Darin Petkov | c1a8b42 | 2010-07-19 11:34:49 -0700 | [diff] [blame] | 405 | kActionCodeSuccess, |
Darin Petkov | 0dc8e9a | 2010-07-14 14:51:57 -0700 | [diff] [blame] | 406 | &response, |
| 407 | NULL)); |
Darin Petkov | 6a5b322 | 2010-07-13 14:55:28 -0700 | [diff] [blame] | 408 | EXPECT_TRUE(response.update_exists); |
| 409 | EXPECT_EQ("1.2.3.4", response.display_version); |
| 410 | EXPECT_EQ("http://code/base", response.codebase); |
| 411 | EXPECT_EQ("", response.more_info_url); |
Andrew de los Reyes | 3270f74 | 2010-07-15 22:28:14 -0700 | [diff] [blame] | 412 | EXPECT_FALSE(response.is_delta); |
Darin Petkov | 6a5b322 | 2010-07-13 14:55:28 -0700 | [diff] [blame] | 413 | EXPECT_EQ("HASH1234=", response.hash); |
| 414 | EXPECT_EQ(123, response.size); |
| 415 | EXPECT_TRUE(response.needs_admin); |
| 416 | EXPECT_FALSE(response.prompt); |
| 417 | } |
| 418 | |
| 419 | namespace { |
| 420 | class TerminateEarlyTestProcessorDelegate : public ActionProcessorDelegate { |
| 421 | public: |
| 422 | void ProcessingStopped(const ActionProcessor* processor) { |
| 423 | ASSERT_TRUE(loop_); |
| 424 | g_main_loop_quit(loop_); |
| 425 | } |
| 426 | GMainLoop *loop_; |
| 427 | }; |
| 428 | |
| 429 | gboolean TerminateTransferTestStarter(gpointer data) { |
| 430 | ActionProcessor *processor = reinterpret_cast<ActionProcessor*>(data); |
| 431 | processor->StartProcessing(); |
| 432 | CHECK(processor->IsRunning()); |
| 433 | processor->StopProcessing(); |
| 434 | return FALSE; |
| 435 | } |
| 436 | } // namespace {} |
| 437 | |
| 438 | TEST(OmahaRequestActionTest, TerminateTransferTest) { |
| 439 | OmahaRequestParams params("", // machine_id |
| 440 | "", // usr_id |
| 441 | OmahaRequestParams::kOsPlatform, |
| 442 | OmahaRequestParams::kOsVersion, |
| 443 | "", // os_sp |
| 444 | "", // os_board |
| 445 | OmahaRequestParams::kAppId, |
| 446 | "0.1.0.0", |
| 447 | "en-US", |
| 448 | "unittest", |
Andrew de los Reyes | 3f0303a | 2010-07-15 22:35:35 -0700 | [diff] [blame] | 449 | false, // delta okay |
Darin Petkov | 6a5b322 | 2010-07-13 14:55:28 -0700 | [diff] [blame] | 450 | "http://url"); |
| 451 | string http_response("doesn't matter"); |
| 452 | GMainLoop *loop = g_main_loop_new(g_main_context_default(), FALSE); |
| 453 | |
Darin Petkov | a4a8a8c | 2010-07-15 22:21:12 -0700 | [diff] [blame] | 454 | OmahaRequestAction action(params, NULL, |
Darin Petkov | 0dc8e9a | 2010-07-14 14:51:57 -0700 | [diff] [blame] | 455 | new MockHttpFetcher(http_response.data(), |
Darin Petkov | 6a5b322 | 2010-07-13 14:55:28 -0700 | [diff] [blame] | 456 | http_response.size())); |
| 457 | TerminateEarlyTestProcessorDelegate delegate; |
| 458 | delegate.loop_ = loop; |
| 459 | ActionProcessor processor; |
| 460 | processor.set_delegate(&delegate); |
Darin Petkov | 6a5b322 | 2010-07-13 14:55:28 -0700 | [diff] [blame] | 461 | processor.EnqueueAction(&action); |
Darin Petkov | 6a5b322 | 2010-07-13 14:55:28 -0700 | [diff] [blame] | 462 | |
| 463 | g_timeout_add(0, &TerminateTransferTestStarter, &processor); |
| 464 | g_main_loop_run(loop); |
| 465 | g_main_loop_unref(loop); |
| 466 | } |
| 467 | |
| 468 | TEST(OmahaRequestActionTest, XmlEncodeTest) { |
| 469 | EXPECT_EQ("ab", XmlEncode("ab")); |
| 470 | EXPECT_EQ("a<b", XmlEncode("a<b")); |
| 471 | EXPECT_EQ("foo-Ω", XmlEncode("foo-\xce\xa9")); |
| 472 | EXPECT_EQ("<&>", XmlEncode("<&>")); |
| 473 | EXPECT_EQ("&lt;&amp;&gt;", XmlEncode("<&>")); |
| 474 | |
| 475 | vector<char> post_data; |
| 476 | |
| 477 | // Make sure XML Encode is being called on the params |
| 478 | OmahaRequestParams params("testthemachine<id", |
| 479 | "testtheuser_id<", |
| 480 | OmahaRequestParams::kOsPlatform, |
| 481 | OmahaRequestParams::kOsVersion, |
| 482 | "testtheservice_pack>", |
| 483 | "x86 generic", |
| 484 | OmahaRequestParams::kAppId, |
| 485 | "0.1.0.0", |
| 486 | "en-US", |
| 487 | "unittest_track", |
Andrew de los Reyes | 3f0303a | 2010-07-15 22:35:35 -0700 | [diff] [blame] | 488 | false, // delta okay |
Darin Petkov | 6a5b322 | 2010-07-13 14:55:28 -0700 | [diff] [blame] | 489 | "http://url"); |
| 490 | OmahaResponse response; |
| 491 | ASSERT_FALSE( |
Darin Petkov | 0dc8e9a | 2010-07-14 14:51:57 -0700 | [diff] [blame] | 492 | TestUpdateCheck(params, |
| 493 | "invalid xml>", |
Darin Petkov | c1a8b42 | 2010-07-19 11:34:49 -0700 | [diff] [blame] | 494 | kActionCodeError, |
Darin Petkov | 0dc8e9a | 2010-07-14 14:51:57 -0700 | [diff] [blame] | 495 | &response, |
| 496 | &post_data)); |
Darin Petkov | 6a5b322 | 2010-07-13 14:55:28 -0700 | [diff] [blame] | 497 | // convert post_data to string |
| 498 | string post_str(&post_data[0], post_data.size()); |
| 499 | EXPECT_NE(post_str.find("testthemachine<id"), string::npos); |
| 500 | EXPECT_EQ(post_str.find("testthemachine<id"), string::npos); |
| 501 | EXPECT_NE(post_str.find("testtheuser_id&lt;"), string::npos); |
| 502 | EXPECT_EQ(post_str.find("testtheuser_id<"), string::npos); |
| 503 | EXPECT_NE(post_str.find("testtheservice_pack>"), string::npos); |
| 504 | EXPECT_EQ(post_str.find("testtheservice_pack>"), string::npos); |
| 505 | EXPECT_NE(post_str.find("x86 generic"), string::npos); |
| 506 | } |
| 507 | |
| 508 | TEST(OmahaRequestActionTest, XmlDecodeTest) { |
| 509 | OmahaRequestParams params("machine_id", |
| 510 | "user_id", |
| 511 | OmahaRequestParams::kOsPlatform, |
| 512 | OmahaRequestParams::kOsVersion, |
| 513 | "service_pack", |
| 514 | "x86-generic", |
| 515 | OmahaRequestParams::kAppId, |
| 516 | "0.1.0.0", |
| 517 | "en-US", |
| 518 | "unittest_track", |
Andrew de los Reyes | 3f0303a | 2010-07-15 22:35:35 -0700 | [diff] [blame] | 519 | false, // delta okay |
Darin Petkov | 6a5b322 | 2010-07-13 14:55:28 -0700 | [diff] [blame] | 520 | "http://url"); |
| 521 | OmahaResponse response; |
| 522 | ASSERT_TRUE( |
Darin Petkov | 0dc8e9a | 2010-07-14 14:51:57 -0700 | [diff] [blame] | 523 | TestUpdateCheck(params, |
| 524 | GetUpdateResponse(OmahaRequestParams::kAppId, |
| 525 | "1.2.3.4", // version |
| 526 | "testthe<url", // more info |
| 527 | "true", // prompt |
| 528 | "testthe&codebase", // dl url |
| 529 | "HASH1234=", // checksum |
| 530 | "false", // needs admin |
| 531 | "123"), // size |
Darin Petkov | c1a8b42 | 2010-07-19 11:34:49 -0700 | [diff] [blame] | 532 | kActionCodeSuccess, |
Darin Petkov | 0dc8e9a | 2010-07-14 14:51:57 -0700 | [diff] [blame] | 533 | &response, |
| 534 | NULL)); |
Darin Petkov | 6a5b322 | 2010-07-13 14:55:28 -0700 | [diff] [blame] | 535 | |
| 536 | EXPECT_EQ(response.more_info_url, "testthe<url"); |
Darin Petkov | 0dc8e9a | 2010-07-14 14:51:57 -0700 | [diff] [blame] | 537 | EXPECT_EQ(response.codebase, "testthe&codebase"); |
Darin Petkov | 6a5b322 | 2010-07-13 14:55:28 -0700 | [diff] [blame] | 538 | } |
| 539 | |
| 540 | TEST(OmahaRequestActionTest, ParseIntTest) { |
| 541 | OmahaRequestParams params("machine_id", |
| 542 | "user_id", |
| 543 | OmahaRequestParams::kOsPlatform, |
| 544 | OmahaRequestParams::kOsVersion, |
| 545 | "service_pack", |
| 546 | "the_board", |
| 547 | OmahaRequestParams::kAppId, |
| 548 | "0.1.0.0", |
| 549 | "en-US", |
| 550 | "unittest_track", |
Andrew de los Reyes | 3f0303a | 2010-07-15 22:35:35 -0700 | [diff] [blame] | 551 | false, // delta okay |
Darin Petkov | 6a5b322 | 2010-07-13 14:55:28 -0700 | [diff] [blame] | 552 | "http://url"); |
| 553 | OmahaResponse response; |
| 554 | ASSERT_TRUE( |
Darin Petkov | 0dc8e9a | 2010-07-14 14:51:57 -0700 | [diff] [blame] | 555 | TestUpdateCheck(params, |
| 556 | GetUpdateResponse(OmahaRequestParams::kAppId, |
| 557 | "1.2.3.4", // version |
| 558 | "theurl", // more info |
| 559 | "true", // prompt |
| 560 | "thecodebase", // dl url |
| 561 | "HASH1234=", // checksum |
| 562 | "false", // needs admin |
| 563 | // overflows int32: |
| 564 | "123123123123123"), // size |
Darin Petkov | c1a8b42 | 2010-07-19 11:34:49 -0700 | [diff] [blame] | 565 | kActionCodeSuccess, |
Darin Petkov | 0dc8e9a | 2010-07-14 14:51:57 -0700 | [diff] [blame] | 566 | &response, |
| 567 | NULL)); |
Darin Petkov | 6a5b322 | 2010-07-13 14:55:28 -0700 | [diff] [blame] | 568 | |
| 569 | EXPECT_EQ(response.size, 123123123123123ll); |
| 570 | } |
| 571 | |
Darin Petkov | 0dc8e9a | 2010-07-14 14:51:57 -0700 | [diff] [blame] | 572 | TEST(OmahaRequestActionTest, FormatUpdateCheckOutputTest) { |
| 573 | vector<char> post_data; |
| 574 | OmahaRequestParams params("machine_id", |
| 575 | "user_id", |
| 576 | OmahaRequestParams::kOsPlatform, |
| 577 | OmahaRequestParams::kOsVersion, |
| 578 | "service_pack", |
| 579 | "x86-generic", |
| 580 | OmahaRequestParams::kAppId, |
| 581 | "0.1.0.0", |
| 582 | "en-US", |
| 583 | "unittest_track", |
Andrew de los Reyes | 3f0303a | 2010-07-15 22:35:35 -0700 | [diff] [blame] | 584 | false, // delta okay |
Darin Petkov | 0dc8e9a | 2010-07-14 14:51:57 -0700 | [diff] [blame] | 585 | "http://url"); |
| 586 | OmahaResponse response; |
| 587 | ASSERT_FALSE(TestUpdateCheck(params, |
| 588 | "invalid xml>", |
Darin Petkov | c1a8b42 | 2010-07-19 11:34:49 -0700 | [diff] [blame] | 589 | kActionCodeError, |
Darin Petkov | 0dc8e9a | 2010-07-14 14:51:57 -0700 | [diff] [blame] | 590 | &response, |
| 591 | &post_data)); |
| 592 | // convert post_data to string |
| 593 | string post_str(&post_data[0], post_data.size()); |
| 594 | EXPECT_NE(post_str.find(" <o:ping active=\"0\"></o:ping>\n" |
| 595 | " <o:updatecheck></o:updatecheck>\n"), |
| 596 | string::npos); |
| 597 | EXPECT_EQ(post_str.find("o:event"), string::npos); |
| 598 | } |
| 599 | |
Darin Petkov | e17f86b | 2010-07-20 09:12:01 -0700 | [diff] [blame] | 600 | TEST(OmahaRequestActionTest, FormatSuccessEventOutputTest) { |
| 601 | vector<char> post_data; |
| 602 | OmahaRequestParams params("machine_id", |
| 603 | "user_id", |
| 604 | OmahaRequestParams::kOsPlatform, |
| 605 | OmahaRequestParams::kOsVersion, |
| 606 | "service_pack", |
| 607 | "x86-generic", |
| 608 | OmahaRequestParams::kAppId, |
| 609 | "0.1.0.0", |
| 610 | "en-US", |
| 611 | "unittest_track", |
| 612 | false, // delta okay |
| 613 | "http://url"); |
| 614 | TestEvent(params, |
| 615 | new OmahaEvent(OmahaEvent::kTypeUpdateDownloadStarted), |
| 616 | "invalid xml>", |
| 617 | &post_data); |
| 618 | // convert post_data to string |
| 619 | string post_str(&post_data[0], post_data.size()); |
| 620 | string expected_event = StringPrintf( |
| 621 | " <o:event eventtype=\"%d\" eventresult=\"%d\"></o:event>\n", |
| 622 | OmahaEvent::kTypeUpdateDownloadStarted, |
| 623 | OmahaEvent::kResultSuccess); |
| 624 | EXPECT_NE(post_str.find(expected_event), string::npos); |
| 625 | EXPECT_EQ(post_str.find("o:updatecheck"), string::npos); |
| 626 | } |
| 627 | |
| 628 | TEST(OmahaRequestActionTest, FormatErrorEventOutputTest) { |
| 629 | vector<char> post_data; |
| 630 | OmahaRequestParams params("machine_id", |
| 631 | "user_id", |
| 632 | OmahaRequestParams::kOsPlatform, |
| 633 | OmahaRequestParams::kOsVersion, |
| 634 | "service_pack", |
| 635 | "x86-generic", |
| 636 | OmahaRequestParams::kAppId, |
| 637 | "0.1.0.0", |
| 638 | "en-US", |
| 639 | "unittest_track", |
| 640 | false, // delta okay |
| 641 | "http://url"); |
| 642 | TestEvent(params, |
| 643 | new OmahaEvent(OmahaEvent::kTypeDownloadComplete, |
| 644 | OmahaEvent::kResultError, |
| 645 | kActionCodeError), |
| 646 | "invalid xml>", |
| 647 | &post_data); |
| 648 | // convert post_data to string |
| 649 | string post_str(&post_data[0], post_data.size()); |
| 650 | string expected_event = StringPrintf( |
| 651 | " <o:event eventtype=\"%d\" eventresult=\"%d\" " |
| 652 | "errorcode=\"%d\"></o:event>\n", |
| 653 | OmahaEvent::kTypeDownloadComplete, |
| 654 | OmahaEvent::kResultError, |
| 655 | kActionCodeError); |
| 656 | EXPECT_NE(post_str.find(expected_event), string::npos); |
| 657 | EXPECT_EQ(post_str.find("o:updatecheck"), string::npos); |
| 658 | } |
| 659 | |
Darin Petkov | 0dc8e9a | 2010-07-14 14:51:57 -0700 | [diff] [blame] | 660 | TEST(OmahaRequestActionTest, FormatEventOutputTest) { |
| 661 | vector<char> post_data; |
| 662 | OmahaRequestParams params("machine_id", |
| 663 | "user_id", |
| 664 | OmahaRequestParams::kOsPlatform, |
| 665 | OmahaRequestParams::kOsVersion, |
| 666 | "service_pack", |
| 667 | "x86-generic", |
| 668 | OmahaRequestParams::kAppId, |
| 669 | "0.1.0.0", |
| 670 | "en-US", |
| 671 | "unittest_track", |
Andrew de los Reyes | 3f0303a | 2010-07-15 22:35:35 -0700 | [diff] [blame] | 672 | false, // delta okay |
Darin Petkov | 0dc8e9a | 2010-07-14 14:51:57 -0700 | [diff] [blame] | 673 | "http://url"); |
| 674 | TestEvent(params, |
| 675 | new OmahaEvent(OmahaEvent::kTypeDownloadComplete, |
| 676 | OmahaEvent::kResultError, |
Darin Petkov | e17f86b | 2010-07-20 09:12:01 -0700 | [diff] [blame] | 677 | kActionCodeError), |
Darin Petkov | 0dc8e9a | 2010-07-14 14:51:57 -0700 | [diff] [blame] | 678 | "invalid xml>", |
| 679 | &post_data); |
| 680 | // convert post_data to string |
| 681 | string post_str(&post_data[0], post_data.size()); |
| 682 | string expected_event = StringPrintf( |
| 683 | " <o:event eventtype=\"%d\" eventresult=\"%d\" " |
| 684 | "errorcode=\"%d\"></o:event>\n", |
| 685 | OmahaEvent::kTypeDownloadComplete, |
| 686 | OmahaEvent::kResultError, |
Darin Petkov | e17f86b | 2010-07-20 09:12:01 -0700 | [diff] [blame] | 687 | kActionCodeError); |
Darin Petkov | 0dc8e9a | 2010-07-14 14:51:57 -0700 | [diff] [blame] | 688 | EXPECT_NE(post_str.find(expected_event), string::npos); |
| 689 | EXPECT_EQ(post_str.find("o:updatecheck"), string::npos); |
| 690 | } |
| 691 | |
| 692 | TEST(OmahaRequestActionTest, IsEventTest) { |
| 693 | string http_response("doesn't matter"); |
Darin Petkov | a4a8a8c | 2010-07-15 22:21:12 -0700 | [diff] [blame] | 694 | OmahaRequestParams params("machine_id", |
| 695 | "user_id", |
| 696 | OmahaRequestParams::kOsPlatform, |
| 697 | OmahaRequestParams::kOsVersion, |
| 698 | "service_pack", |
| 699 | "x86-generic", |
| 700 | OmahaRequestParams::kAppId, |
| 701 | "0.1.0.0", |
| 702 | "en-US", |
| 703 | "unittest_track", |
Andrew de los Reyes | 3f0303a | 2010-07-15 22:35:35 -0700 | [diff] [blame] | 704 | false, // delta okay |
Darin Petkov | a4a8a8c | 2010-07-15 22:21:12 -0700 | [diff] [blame] | 705 | "http://url"); |
Darin Petkov | 0dc8e9a | 2010-07-14 14:51:57 -0700 | [diff] [blame] | 706 | |
| 707 | OmahaRequestAction update_check_action( |
Darin Petkov | a4a8a8c | 2010-07-15 22:21:12 -0700 | [diff] [blame] | 708 | params, |
Darin Petkov | 0dc8e9a | 2010-07-14 14:51:57 -0700 | [diff] [blame] | 709 | NULL, |
| 710 | new MockHttpFetcher(http_response.data(), |
| 711 | http_response.size())); |
| 712 | EXPECT_FALSE(update_check_action.IsEvent()); |
| 713 | |
| 714 | OmahaRequestAction event_action( |
Darin Petkov | a4a8a8c | 2010-07-15 22:21:12 -0700 | [diff] [blame] | 715 | params, |
Darin Petkov | e17f86b | 2010-07-20 09:12:01 -0700 | [diff] [blame] | 716 | new OmahaEvent(OmahaEvent::kTypeUpdateComplete), |
Darin Petkov | 0dc8e9a | 2010-07-14 14:51:57 -0700 | [diff] [blame] | 717 | new MockHttpFetcher(http_response.data(), |
| 718 | http_response.size())); |
| 719 | EXPECT_TRUE(event_action.IsEvent()); |
| 720 | } |
| 721 | |
Andrew de los Reyes | 3f0303a | 2010-07-15 22:35:35 -0700 | [diff] [blame] | 722 | TEST(OmahaRequestActionTest, FormatDeltaOkayOutputTest) { |
| 723 | for (int i = 0; i < 2; i++) { |
| 724 | bool delta_okay = i == 1; |
| 725 | const char* delta_okay_str = delta_okay ? "true" : "false"; |
| 726 | vector<char> post_data; |
| 727 | OmahaRequestParams params("machine_id", |
| 728 | "user_id", |
| 729 | OmahaRequestParams::kOsPlatform, |
| 730 | OmahaRequestParams::kOsVersion, |
| 731 | "service_pack", |
| 732 | "x86-generic", |
| 733 | OmahaRequestParams::kAppId, |
| 734 | "0.1.0.0", |
| 735 | "en-US", |
| 736 | "unittest_track", |
| 737 | delta_okay, |
| 738 | "http://url"); |
| 739 | ASSERT_FALSE(TestUpdateCheck(params, |
| 740 | "invalid xml>", |
Darin Petkov | c1a8b42 | 2010-07-19 11:34:49 -0700 | [diff] [blame] | 741 | kActionCodeError, |
Andrew de los Reyes | 3f0303a | 2010-07-15 22:35:35 -0700 | [diff] [blame] | 742 | NULL, |
| 743 | &post_data)); |
| 744 | // convert post_data to string |
| 745 | string post_str(&post_data[0], post_data.size()); |
| 746 | EXPECT_NE(post_str.find(StringPrintf(" delta_okay=\"%s\"", delta_okay_str)), |
| 747 | string::npos) |
| 748 | << "i = " << i; |
| 749 | } |
| 750 | } |
| 751 | |
Darin Petkov | e17f86b | 2010-07-20 09:12:01 -0700 | [diff] [blame] | 752 | TEST(OmahaRequestActionTest, OmahaEventTest) { |
| 753 | OmahaEvent default_event; |
| 754 | EXPECT_EQ(OmahaEvent::kTypeUnknown, default_event.type); |
| 755 | EXPECT_EQ(OmahaEvent::kResultError, default_event.result); |
| 756 | EXPECT_EQ(kActionCodeError, default_event.error_code); |
| 757 | |
| 758 | OmahaEvent success_event(OmahaEvent::kTypeUpdateDownloadStarted); |
| 759 | EXPECT_EQ(OmahaEvent::kTypeUpdateDownloadStarted, success_event.type); |
| 760 | EXPECT_EQ(OmahaEvent::kResultSuccess, success_event.result); |
| 761 | EXPECT_EQ(kActionCodeSuccess, success_event.error_code); |
| 762 | |
| 763 | OmahaEvent error_event(OmahaEvent::kTypeUpdateDownloadFinished, |
| 764 | OmahaEvent::kResultError, |
| 765 | kActionCodeError); |
| 766 | EXPECT_EQ(OmahaEvent::kTypeUpdateDownloadFinished, error_event.type); |
| 767 | EXPECT_EQ(OmahaEvent::kResultError, error_event.result); |
| 768 | EXPECT_EQ(kActionCodeError, error_event.error_code); |
| 769 | } |
| 770 | |
Darin Petkov | 6a5b322 | 2010-07-13 14:55:28 -0700 | [diff] [blame] | 771 | } // namespace chromeos_update_engine |