OLD | NEW |
1 // Copyright (c) 2010 The Chromium OS Authors. All rights reserved. | 1 // Copyright (c) 2010 The Chromium OS Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include <string> | 5 #include <string> |
6 #include <vector> | 6 #include <vector> |
7 | 7 |
8 #include <glib.h> | 8 #include <glib.h> |
9 | 9 |
10 #include "base/string_util.h" | 10 #include "base/string_util.h" |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
49 "IsDelta=\"true\" " | 49 "IsDelta=\"true\" " |
50 "codebase=\"" + codebase + "\" " | 50 "codebase=\"" + codebase + "\" " |
51 "hash=\"" + hash + "\" needsadmin=\"" + needsadmin + "\" " | 51 "hash=\"" + hash + "\" needsadmin=\"" + needsadmin + "\" " |
52 "size=\"" + size + "\" status=\"ok\"/></app></gupdate>"; | 52 "size=\"" + size + "\" status=\"ok\"/></app></gupdate>"; |
53 } | 53 } |
54 | 54 |
55 class OmahaRequestActionTestProcessorDelegate : public ActionProcessorDelegate { | 55 class OmahaRequestActionTestProcessorDelegate : public ActionProcessorDelegate { |
56 public: | 56 public: |
57 OmahaRequestActionTestProcessorDelegate() | 57 OmahaRequestActionTestProcessorDelegate() |
58 : loop_(NULL), | 58 : loop_(NULL), |
59 expected_success_(true) {} | 59 expected_code_(kActionCodeSuccess) {} |
60 virtual ~OmahaRequestActionTestProcessorDelegate() { | 60 virtual ~OmahaRequestActionTestProcessorDelegate() { |
61 } | 61 } |
62 virtual void ProcessingDone(const ActionProcessor* processor, bool success) { | 62 virtual void ProcessingDone(const ActionProcessor* processor, |
| 63 ActionExitCode code) { |
63 ASSERT_TRUE(loop_); | 64 ASSERT_TRUE(loop_); |
64 g_main_loop_quit(loop_); | 65 g_main_loop_quit(loop_); |
65 } | 66 } |
66 | 67 |
67 virtual void ActionCompleted(ActionProcessor* processor, | 68 virtual void ActionCompleted(ActionProcessor* processor, |
68 AbstractAction* action, | 69 AbstractAction* action, |
69 bool success) { | 70 ActionExitCode code) { |
70 // make sure actions always succeed | 71 // make sure actions always succeed |
71 if (action->Type() == OmahaRequestAction::StaticType()) | 72 if (action->Type() == OmahaRequestAction::StaticType()) |
72 EXPECT_EQ(expected_success_, success); | 73 EXPECT_EQ(expected_code_, code); |
73 else | 74 else |
74 EXPECT_TRUE(success); | 75 EXPECT_EQ(kActionCodeSuccess, code); |
75 } | 76 } |
76 GMainLoop *loop_; | 77 GMainLoop *loop_; |
77 bool expected_success_; | 78 ActionExitCode expected_code_; |
78 }; | 79 }; |
79 | 80 |
80 gboolean StartProcessorInRunLoop(gpointer data) { | 81 gboolean StartProcessorInRunLoop(gpointer data) { |
81 ActionProcessor *processor = reinterpret_cast<ActionProcessor*>(data); | 82 ActionProcessor *processor = reinterpret_cast<ActionProcessor*>(data); |
82 processor->StartProcessing(); | 83 processor->StartProcessing(); |
83 return FALSE; | 84 return FALSE; |
84 } | 85 } |
85 | 86 |
86 } // namespace {} | 87 } // namespace {} |
87 | 88 |
88 class OutputObjectCollectorAction; | 89 class OutputObjectCollectorAction; |
89 | 90 |
90 template<> | 91 template<> |
91 class ActionTraits<OutputObjectCollectorAction> { | 92 class ActionTraits<OutputObjectCollectorAction> { |
92 public: | 93 public: |
93 // Does not take an object for input | 94 // Does not take an object for input |
94 typedef OmahaResponse InputObjectType; | 95 typedef OmahaResponse InputObjectType; |
95 // On success, puts the output path on output | 96 // On success, puts the output path on output |
96 typedef NoneType OutputObjectType; | 97 typedef NoneType OutputObjectType; |
97 }; | 98 }; |
98 | 99 |
99 class OutputObjectCollectorAction : public Action<OutputObjectCollectorAction> { | 100 class OutputObjectCollectorAction : public Action<OutputObjectCollectorAction> { |
100 public: | 101 public: |
101 OutputObjectCollectorAction() : has_input_object_(false) {} | 102 OutputObjectCollectorAction() : has_input_object_(false) {} |
102 void PerformAction() { | 103 void PerformAction() { |
103 // copy input object | 104 // copy input object |
104 has_input_object_ = HasInputObject(); | 105 has_input_object_ = HasInputObject(); |
105 if (has_input_object_) | 106 if (has_input_object_) |
106 omaha_response_ = GetInputObject(); | 107 omaha_response_ = GetInputObject(); |
107 processor_->ActionComplete(this, true); | 108 processor_->ActionComplete(this, kActionCodeSuccess); |
108 } | 109 } |
109 // Should never be called | 110 // Should never be called |
110 void TerminateProcessing() { | 111 void TerminateProcessing() { |
111 CHECK(false); | 112 CHECK(false); |
112 } | 113 } |
113 // Debugging/logging | 114 // Debugging/logging |
114 static std::string StaticType() { | 115 static std::string StaticType() { |
115 return "OutputObjectCollectorAction"; | 116 return "OutputObjectCollectorAction"; |
116 } | 117 } |
117 std::string Type() const { return StaticType(); } | 118 std::string Type() const { return StaticType(); } |
118 bool has_input_object_; | 119 bool has_input_object_; |
119 OmahaResponse omaha_response_; | 120 OmahaResponse omaha_response_; |
120 }; | 121 }; |
121 | 122 |
122 // returns true iff an output response was obtained from the | 123 // returns true iff an output response was obtained from the |
123 // OmahaRequestAction. out_response may be NULL. | 124 // OmahaRequestAction. out_response may be NULL. |
124 // out_post_data may be null; if non-null, the post-data received by the | 125 // out_post_data may be null; if non-null, the post-data received by the |
125 // mock HttpFetcher is returned. | 126 // mock HttpFetcher is returned. |
126 bool TestUpdateCheck(const OmahaRequestParams& params, | 127 bool TestUpdateCheck(const OmahaRequestParams& params, |
127 const string& http_response, | 128 const string& http_response, |
128 bool expected_success, | 129 ActionExitCode expected_code, |
129 OmahaResponse* out_response, | 130 OmahaResponse* out_response, |
130 vector<char>* out_post_data) { | 131 vector<char>* out_post_data) { |
131 GMainLoop* loop = g_main_loop_new(g_main_context_default(), FALSE); | 132 GMainLoop* loop = g_main_loop_new(g_main_context_default(), FALSE); |
132 MockHttpFetcher* fetcher = new MockHttpFetcher(http_response.data(), | 133 MockHttpFetcher* fetcher = new MockHttpFetcher(http_response.data(), |
133 http_response.size()); | 134 http_response.size()); |
134 OmahaRequestAction action(params, NULL, fetcher); | 135 OmahaRequestAction action(params, NULL, fetcher); |
135 OmahaRequestActionTestProcessorDelegate delegate; | 136 OmahaRequestActionTestProcessorDelegate delegate; |
136 delegate.loop_ = loop; | 137 delegate.loop_ = loop; |
137 delegate.expected_success_ = expected_success; | 138 delegate.expected_code_ = expected_code; |
138 | 139 |
139 ActionProcessor processor; | 140 ActionProcessor processor; |
140 processor.set_delegate(&delegate); | 141 processor.set_delegate(&delegate); |
141 processor.EnqueueAction(&action); | 142 processor.EnqueueAction(&action); |
142 | 143 |
143 OutputObjectCollectorAction collector_action; | 144 OutputObjectCollectorAction collector_action; |
144 BondActions(&action, &collector_action); | 145 BondActions(&action, &collector_action); |
145 processor.EnqueueAction(&collector_action); | 146 processor.EnqueueAction(&collector_action); |
146 | 147 |
147 g_timeout_add(0, &StartProcessorInRunLoop, &processor); | 148 g_timeout_add(0, &StartProcessorInRunLoop, &processor); |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
188 OmahaRequestParams::kAppId, | 189 OmahaRequestParams::kAppId, |
189 "0.1.0.0", | 190 "0.1.0.0", |
190 "en-US", | 191 "en-US", |
191 "unittest", | 192 "unittest", |
192 false, // delta okay | 193 false, // delta okay |
193 ""); // url | 194 ""); // url |
194 OmahaResponse response; | 195 OmahaResponse response; |
195 ASSERT_TRUE( | 196 ASSERT_TRUE( |
196 TestUpdateCheck(params, | 197 TestUpdateCheck(params, |
197 GetNoUpdateResponse(OmahaRequestParams::kAppId), | 198 GetNoUpdateResponse(OmahaRequestParams::kAppId), |
198 true, | 199 kActionCodeSuccess, |
199 &response, | 200 &response, |
200 NULL)); | 201 NULL)); |
201 EXPECT_FALSE(response.update_exists); | 202 EXPECT_FALSE(response.update_exists); |
202 } | 203 } |
203 | 204 |
204 TEST(OmahaRequestActionTest, ValidUpdateTest) { | 205 TEST(OmahaRequestActionTest, ValidUpdateTest) { |
205 OmahaRequestParams params("machine_id", | 206 OmahaRequestParams params("machine_id", |
206 "user_id", | 207 "user_id", |
207 OmahaRequestParams::kOsPlatform, | 208 OmahaRequestParams::kOsPlatform, |
208 OmahaRequestParams::kOsVersion, | 209 OmahaRequestParams::kOsVersion, |
209 "service_pack", | 210 "service_pack", |
210 "arm-generic", | 211 "arm-generic", |
211 OmahaRequestParams::kAppId, | 212 OmahaRequestParams::kAppId, |
212 "0.1.0.0", | 213 "0.1.0.0", |
213 "en-US", | 214 "en-US", |
214 "unittest_track", | 215 "unittest_track", |
215 false, // delta okay | 216 false, // delta okay |
216 ""); // url | 217 ""); // url |
217 OmahaResponse response; | 218 OmahaResponse response; |
218 ASSERT_TRUE( | 219 ASSERT_TRUE( |
219 TestUpdateCheck(params, | 220 TestUpdateCheck(params, |
220 GetUpdateResponse(OmahaRequestParams::kAppId, | 221 GetUpdateResponse(OmahaRequestParams::kAppId, |
221 "1.2.3.4", // version | 222 "1.2.3.4", // version |
222 "http://more/info", | 223 "http://more/info", |
223 "true", // prompt | 224 "true", // prompt |
224 "http://code/base", // dl url | 225 "http://code/base", // dl url |
225 "HASH1234=", // checksum | 226 "HASH1234=", // checksum |
226 "false", // needs admin | 227 "false", // needs admin |
227 "123"), // size | 228 "123"), // size |
228 true, | 229 kActionCodeSuccess, |
229 &response, | 230 &response, |
230 NULL)); | 231 NULL)); |
231 EXPECT_TRUE(response.update_exists); | 232 EXPECT_TRUE(response.update_exists); |
232 EXPECT_EQ("1.2.3.4", response.display_version); | 233 EXPECT_EQ("1.2.3.4", response.display_version); |
233 EXPECT_EQ("http://code/base", response.codebase); | 234 EXPECT_EQ("http://code/base", response.codebase); |
234 EXPECT_EQ("http://more/info", response.more_info_url); | 235 EXPECT_EQ("http://more/info", response.more_info_url); |
235 EXPECT_TRUE(response.is_delta); | 236 EXPECT_TRUE(response.is_delta); |
236 EXPECT_EQ("HASH1234=", response.hash); | 237 EXPECT_EQ("HASH1234=", response.hash); |
237 EXPECT_EQ(123, response.size); | 238 EXPECT_EQ(123, response.size); |
238 EXPECT_FALSE(response.needs_admin); | 239 EXPECT_FALSE(response.needs_admin); |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
281 OmahaRequestParams::kAppId, | 282 OmahaRequestParams::kAppId, |
282 "0.1.0.0", | 283 "0.1.0.0", |
283 "en-US", | 284 "en-US", |
284 "unittest_track", | 285 "unittest_track", |
285 false, // delta okay | 286 false, // delta okay |
286 "http://url"); | 287 "http://url"); |
287 OmahaResponse response; | 288 OmahaResponse response; |
288 ASSERT_FALSE( | 289 ASSERT_FALSE( |
289 TestUpdateCheck(params, | 290 TestUpdateCheck(params, |
290 "invalid xml>", | 291 "invalid xml>", |
291 false, | 292 kActionCodeError, |
292 &response, | 293 &response, |
293 NULL)); | 294 NULL)); |
294 EXPECT_FALSE(response.update_exists); | 295 EXPECT_FALSE(response.update_exists); |
295 } | 296 } |
296 | 297 |
297 TEST(OmahaRequestActionTest, MissingStatusTest) { | 298 TEST(OmahaRequestActionTest, MissingStatusTest) { |
298 OmahaRequestParams params("machine_id", | 299 OmahaRequestParams params("machine_id", |
299 "user_id", | 300 "user_id", |
300 OmahaRequestParams::kOsPlatform, | 301 OmahaRequestParams::kOsPlatform, |
301 OmahaRequestParams::kOsVersion, | 302 OmahaRequestParams::kOsVersion, |
302 "service_pack", | 303 "service_pack", |
303 "x86-generic", | 304 "x86-generic", |
304 OmahaRequestParams::kAppId, | 305 OmahaRequestParams::kAppId, |
305 "0.1.0.0", | 306 "0.1.0.0", |
306 "en-US", | 307 "en-US", |
307 "unittest_track", | 308 "unittest_track", |
308 false, // delta okay | 309 false, // delta okay |
309 "http://url"); | 310 "http://url"); |
310 OmahaResponse response; | 311 OmahaResponse response; |
311 ASSERT_FALSE(TestUpdateCheck( | 312 ASSERT_FALSE(TestUpdateCheck( |
312 params, | 313 params, |
313 "<?xml version=\"1.0\" encoding=\"UTF-8\"?><gupdate " | 314 "<?xml version=\"1.0\" encoding=\"UTF-8\"?><gupdate " |
314 "xmlns=\"http://www.google.com/update2/response\" protocol=\"2.0\"><app " | 315 "xmlns=\"http://www.google.com/update2/response\" protocol=\"2.0\"><app " |
315 "appid=\"foo\" status=\"ok\"><ping " | 316 "appid=\"foo\" status=\"ok\"><ping " |
316 "status=\"ok\"/><updatecheck/></app></gupdate>", | 317 "status=\"ok\"/><updatecheck/></app></gupdate>", |
317 false, | 318 kActionCodeError, |
318 &response, | 319 &response, |
319 NULL)); | 320 NULL)); |
320 EXPECT_FALSE(response.update_exists); | 321 EXPECT_FALSE(response.update_exists); |
321 } | 322 } |
322 | 323 |
323 TEST(OmahaRequestActionTest, InvalidStatusTest) { | 324 TEST(OmahaRequestActionTest, InvalidStatusTest) { |
324 OmahaRequestParams params("machine_id", | 325 OmahaRequestParams params("machine_id", |
325 "user_id", | 326 "user_id", |
326 OmahaRequestParams::kOsPlatform, | 327 OmahaRequestParams::kOsPlatform, |
327 OmahaRequestParams::kOsVersion, | 328 OmahaRequestParams::kOsVersion, |
328 "service_pack", | 329 "service_pack", |
329 "x86-generic", | 330 "x86-generic", |
330 OmahaRequestParams::kAppId, | 331 OmahaRequestParams::kAppId, |
331 "0.1.0.0", | 332 "0.1.0.0", |
332 "en-US", | 333 "en-US", |
333 "unittest_track", | 334 "unittest_track", |
334 false, // delta okay | 335 false, // delta okay |
335 "http://url"); | 336 "http://url"); |
336 OmahaResponse response; | 337 OmahaResponse response; |
337 ASSERT_FALSE(TestUpdateCheck( | 338 ASSERT_FALSE(TestUpdateCheck( |
338 params, | 339 params, |
339 "<?xml version=\"1.0\" encoding=\"UTF-8\"?><gupdate " | 340 "<?xml version=\"1.0\" encoding=\"UTF-8\"?><gupdate " |
340 "xmlns=\"http://www.google.com/update2/response\" protocol=\"2.0\"><app " | 341 "xmlns=\"http://www.google.com/update2/response\" protocol=\"2.0\"><app " |
341 "appid=\"foo\" status=\"ok\"><ping " | 342 "appid=\"foo\" status=\"ok\"><ping " |
342 "status=\"ok\"/><updatecheck status=\"foo\"/></app></gupdate>", | 343 "status=\"ok\"/><updatecheck status=\"foo\"/></app></gupdate>", |
343 false, | 344 kActionCodeError, |
344 &response, | 345 &response, |
345 NULL)); | 346 NULL)); |
346 EXPECT_FALSE(response.update_exists); | 347 EXPECT_FALSE(response.update_exists); |
347 } | 348 } |
348 | 349 |
349 TEST(OmahaRequestActionTest, MissingNodesetTest) { | 350 TEST(OmahaRequestActionTest, MissingNodesetTest) { |
350 OmahaRequestParams params("machine_id", | 351 OmahaRequestParams params("machine_id", |
351 "user_id", | 352 "user_id", |
352 OmahaRequestParams::kOsPlatform, | 353 OmahaRequestParams::kOsPlatform, |
353 OmahaRequestParams::kOsVersion, | 354 OmahaRequestParams::kOsVersion, |
354 "service_pack", | 355 "service_pack", |
355 "x86-generic", | 356 "x86-generic", |
356 OmahaRequestParams::kAppId, | 357 OmahaRequestParams::kAppId, |
357 "0.1.0.0", | 358 "0.1.0.0", |
358 "en-US", | 359 "en-US", |
359 "unittest_track", | 360 "unittest_track", |
360 false, // delta okay | 361 false, // delta okay |
361 "http://url"); | 362 "http://url"); |
362 OmahaResponse response; | 363 OmahaResponse response; |
363 ASSERT_FALSE(TestUpdateCheck( | 364 ASSERT_FALSE(TestUpdateCheck( |
364 params, | 365 params, |
365 "<?xml version=\"1.0\" encoding=\"UTF-8\"?><gupdate " | 366 "<?xml version=\"1.0\" encoding=\"UTF-8\"?><gupdate " |
366 "xmlns=\"http://www.google.com/update2/response\" protocol=\"2.0\"><app " | 367 "xmlns=\"http://www.google.com/update2/response\" protocol=\"2.0\"><app " |
367 "appid=\"foo\" status=\"ok\"><ping " | 368 "appid=\"foo\" status=\"ok\"><ping " |
368 "status=\"ok\"/></app></gupdate>", | 369 "status=\"ok\"/></app></gupdate>", |
369 false, | 370 kActionCodeError, |
370 &response, | 371 &response, |
371 NULL)); | 372 NULL)); |
372 EXPECT_FALSE(response.update_exists); | 373 EXPECT_FALSE(response.update_exists); |
373 } | 374 } |
374 | 375 |
375 TEST(OmahaRequestActionTest, MissingFieldTest) { | 376 TEST(OmahaRequestActionTest, MissingFieldTest) { |
376 OmahaRequestParams params("machine_id", | 377 OmahaRequestParams params("machine_id", |
377 "user_id", | 378 "user_id", |
378 OmahaRequestParams::kOsPlatform, | 379 OmahaRequestParams::kOsPlatform, |
379 OmahaRequestParams::kOsVersion, | 380 OmahaRequestParams::kOsVersion, |
(...skipping 14 matching lines...) Expand all Loading... |
394 "protocol=\"2.0\"><app appid=\"") + | 395 "protocol=\"2.0\"><app appid=\"") + |
395 OmahaRequestParams::kAppId | 396 OmahaRequestParams::kAppId |
396 + "\" status=\"ok\"><ping " | 397 + "\" status=\"ok\"><ping " |
397 "status=\"ok\"/><updatecheck " | 398 "status=\"ok\"/><updatecheck " |
398 "DisplayVersion=\"1.2.3.4\" " | 399 "DisplayVersion=\"1.2.3.4\" " |
399 "Prompt=\"false\" " | 400 "Prompt=\"false\" " |
400 "codebase=\"http://code/base\" " | 401 "codebase=\"http://code/base\" " |
401 "hash=\"HASH1234=\" needsadmin=\"true\" " | 402 "hash=\"HASH1234=\" needsadmin=\"true\" " |
402 "size=\"123\" " | 403 "size=\"123\" " |
403 "status=\"ok\"/></app></gupdate>", | 404 "status=\"ok\"/></app></gupdate>", |
404 true, | 405 kActionCodeSuccess, |
405 &response, | 406 &response, |
406 NULL)); | 407 NULL)); |
407 EXPECT_TRUE(response.update_exists); | 408 EXPECT_TRUE(response.update_exists); |
408 EXPECT_EQ("1.2.3.4", response.display_version); | 409 EXPECT_EQ("1.2.3.4", response.display_version); |
409 EXPECT_EQ("http://code/base", response.codebase); | 410 EXPECT_EQ("http://code/base", response.codebase); |
410 EXPECT_EQ("", response.more_info_url); | 411 EXPECT_EQ("", response.more_info_url); |
411 EXPECT_FALSE(response.is_delta); | 412 EXPECT_FALSE(response.is_delta); |
412 EXPECT_EQ("HASH1234=", response.hash); | 413 EXPECT_EQ("HASH1234=", response.hash); |
413 EXPECT_EQ(123, response.size); | 414 EXPECT_EQ(123, response.size); |
414 EXPECT_TRUE(response.needs_admin); | 415 EXPECT_TRUE(response.needs_admin); |
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
483 OmahaRequestParams::kAppId, | 484 OmahaRequestParams::kAppId, |
484 "0.1.0.0", | 485 "0.1.0.0", |
485 "en-US", | 486 "en-US", |
486 "unittest_track", | 487 "unittest_track", |
487 false, // delta okay | 488 false, // delta okay |
488 "http://url"); | 489 "http://url"); |
489 OmahaResponse response; | 490 OmahaResponse response; |
490 ASSERT_FALSE( | 491 ASSERT_FALSE( |
491 TestUpdateCheck(params, | 492 TestUpdateCheck(params, |
492 "invalid xml>", | 493 "invalid xml>", |
493 false, | 494 kActionCodeError, |
494 &response, | 495 &response, |
495 &post_data)); | 496 &post_data)); |
496 // convert post_data to string | 497 // convert post_data to string |
497 string post_str(&post_data[0], post_data.size()); | 498 string post_str(&post_data[0], post_data.size()); |
498 EXPECT_NE(post_str.find("testthemachine<id"), string::npos); | 499 EXPECT_NE(post_str.find("testthemachine<id"), string::npos); |
499 EXPECT_EQ(post_str.find("testthemachine<id"), string::npos); | 500 EXPECT_EQ(post_str.find("testthemachine<id"), string::npos); |
500 EXPECT_NE(post_str.find("testtheuser_id&lt;"), string::npos); | 501 EXPECT_NE(post_str.find("testtheuser_id&lt;"), string::npos); |
501 EXPECT_EQ(post_str.find("testtheuser_id<"), string::npos); | 502 EXPECT_EQ(post_str.find("testtheuser_id<"), string::npos); |
502 EXPECT_NE(post_str.find("testtheservice_pack>"), string::npos); | 503 EXPECT_NE(post_str.find("testtheservice_pack>"), string::npos); |
503 EXPECT_EQ(post_str.find("testtheservice_pack>"), string::npos); | 504 EXPECT_EQ(post_str.find("testtheservice_pack>"), string::npos); |
(...skipping 17 matching lines...) Expand all Loading... |
521 ASSERT_TRUE( | 522 ASSERT_TRUE( |
522 TestUpdateCheck(params, | 523 TestUpdateCheck(params, |
523 GetUpdateResponse(OmahaRequestParams::kAppId, | 524 GetUpdateResponse(OmahaRequestParams::kAppId, |
524 "1.2.3.4", // version | 525 "1.2.3.4", // version |
525 "testthe<url", // more info | 526 "testthe<url", // more info |
526 "true", // prompt | 527 "true", // prompt |
527 "testthe&codebase", // dl url | 528 "testthe&codebase", // dl url |
528 "HASH1234=", // checksum | 529 "HASH1234=", // checksum |
529 "false", // needs admin | 530 "false", // needs admin |
530 "123"), // size | 531 "123"), // size |
531 true, | 532 kActionCodeSuccess, |
532 &response, | 533 &response, |
533 NULL)); | 534 NULL)); |
534 | 535 |
535 EXPECT_EQ(response.more_info_url, "testthe<url"); | 536 EXPECT_EQ(response.more_info_url, "testthe<url"); |
536 EXPECT_EQ(response.codebase, "testthe&codebase"); | 537 EXPECT_EQ(response.codebase, "testthe&codebase"); |
537 } | 538 } |
538 | 539 |
539 TEST(OmahaRequestActionTest, ParseIntTest) { | 540 TEST(OmahaRequestActionTest, ParseIntTest) { |
540 OmahaRequestParams params("machine_id", | 541 OmahaRequestParams params("machine_id", |
541 "user_id", | 542 "user_id", |
(...skipping 12 matching lines...) Expand all Loading... |
554 TestUpdateCheck(params, | 555 TestUpdateCheck(params, |
555 GetUpdateResponse(OmahaRequestParams::kAppId, | 556 GetUpdateResponse(OmahaRequestParams::kAppId, |
556 "1.2.3.4", // version | 557 "1.2.3.4", // version |
557 "theurl", // more info | 558 "theurl", // more info |
558 "true", // prompt | 559 "true", // prompt |
559 "thecodebase", // dl url | 560 "thecodebase", // dl url |
560 "HASH1234=", // checksum | 561 "HASH1234=", // checksum |
561 "false", // needs admin | 562 "false", // needs admin |
562 // overflows int32: | 563 // overflows int32: |
563 "123123123123123"), // size | 564 "123123123123123"), // size |
564 true, | 565 kActionCodeSuccess, |
565 &response, | 566 &response, |
566 NULL)); | 567 NULL)); |
567 | 568 |
568 EXPECT_EQ(response.size, 123123123123123ll); | 569 EXPECT_EQ(response.size, 123123123123123ll); |
569 } | 570 } |
570 | 571 |
571 TEST(OmahaRequestActionTest, FormatUpdateCheckOutputTest) { | 572 TEST(OmahaRequestActionTest, FormatUpdateCheckOutputTest) { |
572 vector<char> post_data; | 573 vector<char> post_data; |
573 OmahaRequestParams params("machine_id", | 574 OmahaRequestParams params("machine_id", |
574 "user_id", | 575 "user_id", |
575 OmahaRequestParams::kOsPlatform, | 576 OmahaRequestParams::kOsPlatform, |
576 OmahaRequestParams::kOsVersion, | 577 OmahaRequestParams::kOsVersion, |
577 "service_pack", | 578 "service_pack", |
578 "x86-generic", | 579 "x86-generic", |
579 OmahaRequestParams::kAppId, | 580 OmahaRequestParams::kAppId, |
580 "0.1.0.0", | 581 "0.1.0.0", |
581 "en-US", | 582 "en-US", |
582 "unittest_track", | 583 "unittest_track", |
583 false, // delta okay | 584 false, // delta okay |
584 "http://url"); | 585 "http://url"); |
585 OmahaResponse response; | 586 OmahaResponse response; |
586 ASSERT_FALSE(TestUpdateCheck(params, | 587 ASSERT_FALSE(TestUpdateCheck(params, |
587 "invalid xml>", | 588 "invalid xml>", |
588 false, | 589 kActionCodeError, |
589 &response, | 590 &response, |
590 &post_data)); | 591 &post_data)); |
591 // convert post_data to string | 592 // convert post_data to string |
592 string post_str(&post_data[0], post_data.size()); | 593 string post_str(&post_data[0], post_data.size()); |
593 EXPECT_NE(post_str.find(" <o:ping active=\"0\"></o:ping>\n" | 594 EXPECT_NE(post_str.find(" <o:ping active=\"0\"></o:ping>\n" |
594 " <o:updatecheck></o:updatecheck>\n"), | 595 " <o:updatecheck></o:updatecheck>\n"), |
595 string::npos); | 596 string::npos); |
596 EXPECT_EQ(post_str.find("o:event"), string::npos); | 597 EXPECT_EQ(post_str.find("o:event"), string::npos); |
597 } | 598 } |
598 | 599 |
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
672 "service_pack", | 673 "service_pack", |
673 "x86-generic", | 674 "x86-generic", |
674 OmahaRequestParams::kAppId, | 675 OmahaRequestParams::kAppId, |
675 "0.1.0.0", | 676 "0.1.0.0", |
676 "en-US", | 677 "en-US", |
677 "unittest_track", | 678 "unittest_track", |
678 delta_okay, | 679 delta_okay, |
679 "http://url"); | 680 "http://url"); |
680 ASSERT_FALSE(TestUpdateCheck(params, | 681 ASSERT_FALSE(TestUpdateCheck(params, |
681 "invalid xml>", | 682 "invalid xml>", |
682 false, | 683 kActionCodeError, |
683 NULL, | 684 NULL, |
684 &post_data)); | 685 &post_data)); |
685 // convert post_data to string | 686 // convert post_data to string |
686 string post_str(&post_data[0], post_data.size()); | 687 string post_str(&post_data[0], post_data.size()); |
687 EXPECT_NE(post_str.find(StringPrintf(" delta_okay=\"%s\"", delta_okay_str)), | 688 EXPECT_NE(post_str.find(StringPrintf(" delta_okay=\"%s\"", delta_okay_str)), |
688 string::npos) | 689 string::npos) |
689 << "i = " << i; | 690 << "i = " << i; |
690 } | 691 } |
691 } | 692 } |
692 | 693 |
693 } // namespace chromeos_update_engine | 694 } // namespace chromeos_update_engine |
OLD | NEW |