Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(483)

Side by Side Diff: omaha_request_action_unittest.cc

Issue 4432002: AU: Separate error codes for different OmahaRequestAction failures. (Closed) Base URL: ssh://git@gitrw.chromium.org:9222/update_engine.git@master
Patch Set: Created 10 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « omaha_request_action.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 127 matching lines...) Expand 10 before | Expand all | Expand 10 after
138 // Debugging/logging 138 // Debugging/logging
139 static std::string StaticType() { 139 static std::string StaticType() {
140 return "OutputObjectCollectorAction"; 140 return "OutputObjectCollectorAction";
141 } 141 }
142 std::string Type() const { return StaticType(); } 142 std::string Type() const { return StaticType(); }
143 bool has_input_object_; 143 bool has_input_object_;
144 OmahaResponse omaha_response_; 144 OmahaResponse omaha_response_;
145 }; 145 };
146 146
147 // Returns true iff an output response was obtained from the 147 // Returns true iff an output response was obtained from the
148 // OmahaRequestAction. |prefs| may be NULL, in which case a local 148 // OmahaRequestAction. |prefs| may be NULL, in which case a local PrefsMock is
149 // PrefsMock is used. out_response may be NULL. out_post_data may be 149 // used. out_response may be NULL. If |fail_http_response_code| is
150 // null; if non-null, the post-data received by the mock HttpFetcher 150 // non-negative, the transfer will fail with that code. out_post_data may be
151 // is returned. 151 // null; if non-null, the post-data received by the mock HttpFetcher is
152 // returned.
152 bool TestUpdateCheck(PrefsInterface* prefs, 153 bool TestUpdateCheck(PrefsInterface* prefs,
153 const OmahaRequestParams& params, 154 const OmahaRequestParams& params,
154 const string& http_response, 155 const string& http_response,
156 int fail_http_response_code,
155 ActionExitCode expected_code, 157 ActionExitCode expected_code,
156 OmahaResponse* out_response, 158 OmahaResponse* out_response,
157 vector<char>* out_post_data) { 159 vector<char>* out_post_data) {
158 GMainLoop* loop = g_main_loop_new(g_main_context_default(), FALSE); 160 GMainLoop* loop = g_main_loop_new(g_main_context_default(), FALSE);
159 MockHttpFetcher* fetcher = new MockHttpFetcher(http_response.data(), 161 MockHttpFetcher* fetcher = new MockHttpFetcher(http_response.data(),
160 http_response.size()); 162 http_response.size());
163 if (fail_http_response_code >= 0) {
164 fetcher->FailTransfer(fail_http_response_code);
165 }
161 PrefsMock local_prefs; 166 PrefsMock local_prefs;
162 OmahaRequestAction action(prefs ? prefs : &local_prefs, 167 OmahaRequestAction action(prefs ? prefs : &local_prefs,
163 params, 168 params,
164 NULL, 169 NULL,
165 fetcher); 170 fetcher);
166 OmahaRequestActionTestProcessorDelegate delegate; 171 OmahaRequestActionTestProcessorDelegate delegate;
167 delegate.loop_ = loop; 172 delegate.loop_ = loop;
168 delegate.expected_code_ = expected_code; 173 delegate.expected_code_ = expected_code;
169 174
170 ActionProcessor processor; 175 ActionProcessor processor;
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
209 if (out_post_data) 214 if (out_post_data)
210 *out_post_data = fetcher->post_data(); 215 *out_post_data = fetcher->post_data();
211 } 216 }
212 217
213 TEST(OmahaRequestActionTest, NoUpdateTest) { 218 TEST(OmahaRequestActionTest, NoUpdateTest) {
214 OmahaResponse response; 219 OmahaResponse response;
215 ASSERT_TRUE( 220 ASSERT_TRUE(
216 TestUpdateCheck(NULL, // prefs 221 TestUpdateCheck(NULL, // prefs
217 kDefaultTestParams, 222 kDefaultTestParams,
218 GetNoUpdateResponse(OmahaRequestParams::kAppId), 223 GetNoUpdateResponse(OmahaRequestParams::kAppId),
224 -1,
219 kActionCodeSuccess, 225 kActionCodeSuccess,
220 &response, 226 &response,
221 NULL)); 227 NULL));
222 EXPECT_FALSE(response.update_exists); 228 EXPECT_FALSE(response.update_exists);
223 } 229 }
224 230
225 TEST(OmahaRequestActionTest, ValidUpdateTest) { 231 TEST(OmahaRequestActionTest, ValidUpdateTest) {
226 OmahaResponse response; 232 OmahaResponse response;
227 ASSERT_TRUE( 233 ASSERT_TRUE(
228 TestUpdateCheck(NULL, // prefs 234 TestUpdateCheck(NULL, // prefs
229 kDefaultTestParams, 235 kDefaultTestParams,
230 GetUpdateResponse(OmahaRequestParams::kAppId, 236 GetUpdateResponse(OmahaRequestParams::kAppId,
231 "1.2.3.4", // version 237 "1.2.3.4", // version
232 "http://more/info", 238 "http://more/info",
233 "true", // prompt 239 "true", // prompt
234 "http://code/base", // dl url 240 "http://code/base", // dl url
235 "HASH1234=", // checksum 241 "HASH1234=", // checksum
236 "false", // needs admin 242 "false", // needs admin
237 "123", // size 243 "123", // size
238 "20101020"), // deadline 244 "20101020"), // deadline
245 -1,
239 kActionCodeSuccess, 246 kActionCodeSuccess,
240 &response, 247 &response,
241 NULL)); 248 NULL));
242 EXPECT_TRUE(response.update_exists); 249 EXPECT_TRUE(response.update_exists);
243 EXPECT_EQ("1.2.3.4", response.display_version); 250 EXPECT_EQ("1.2.3.4", response.display_version);
244 EXPECT_EQ("http://code/base", response.codebase); 251 EXPECT_EQ("http://code/base", response.codebase);
245 EXPECT_EQ("http://more/info", response.more_info_url); 252 EXPECT_EQ("http://more/info", response.more_info_url);
246 EXPECT_TRUE(response.is_delta); 253 EXPECT_TRUE(response.is_delta);
247 EXPECT_EQ("HASH1234=", response.hash); 254 EXPECT_EQ("HASH1234=", response.hash);
248 EXPECT_EQ(123, response.size); 255 EXPECT_EQ(123, response.size);
(...skipping 22 matching lines...) Expand all
271 g_main_loop_unref(loop); 278 g_main_loop_unref(loop);
272 EXPECT_FALSE(processor.IsRunning()); 279 EXPECT_FALSE(processor.IsRunning());
273 } 280 }
274 281
275 TEST(OmahaRequestActionTest, InvalidXmlTest) { 282 TEST(OmahaRequestActionTest, InvalidXmlTest) {
276 OmahaResponse response; 283 OmahaResponse response;
277 ASSERT_FALSE( 284 ASSERT_FALSE(
278 TestUpdateCheck(NULL, // prefs 285 TestUpdateCheck(NULL, // prefs
279 kDefaultTestParams, 286 kDefaultTestParams,
280 "invalid xml>", 287 "invalid xml>",
281 kActionCodeError, 288 -1,
289 kActionCodeOmahaRequestXMLParseError,
282 &response, 290 &response,
283 NULL)); 291 NULL));
284 EXPECT_FALSE(response.update_exists); 292 EXPECT_FALSE(response.update_exists);
293 }
294
295 TEST(OmahaRequestActionTest, EmptyResponseTest) {
296 OmahaResponse response;
297 ASSERT_FALSE(
298 TestUpdateCheck(NULL, // prefs
299 kDefaultTestParams,
300 "",
301 -1,
302 kActionCodeOmahaRequestEmptyResponseError,
303 &response,
304 NULL));
305 EXPECT_FALSE(response.update_exists);
285 } 306 }
286 307
287 TEST(OmahaRequestActionTest, MissingStatusTest) { 308 TEST(OmahaRequestActionTest, MissingStatusTest) {
288 OmahaResponse response; 309 OmahaResponse response;
289 ASSERT_FALSE(TestUpdateCheck( 310 ASSERT_FALSE(TestUpdateCheck(
290 NULL, // prefs 311 NULL, // prefs
291 kDefaultTestParams, 312 kDefaultTestParams,
292 "<?xml version=\"1.0\" encoding=\"UTF-8\"?><gupdate " 313 "<?xml version=\"1.0\" encoding=\"UTF-8\"?><gupdate "
293 "xmlns=\"http://www.google.com/update2/response\" protocol=\"2.0\"><app " 314 "xmlns=\"http://www.google.com/update2/response\" protocol=\"2.0\"><app "
294 "appid=\"foo\" status=\"ok\"><ping " 315 "appid=\"foo\" status=\"ok\"><ping "
295 "status=\"ok\"/><updatecheck/></app></gupdate>", 316 "status=\"ok\"/><updatecheck/></app></gupdate>",
296 kActionCodeError, 317 -1,
318 kActionCodeOmahaRequestNoUpdateCheckStatus,
297 &response, 319 &response,
298 NULL)); 320 NULL));
299 EXPECT_FALSE(response.update_exists); 321 EXPECT_FALSE(response.update_exists);
300 } 322 }
301 323
302 TEST(OmahaRequestActionTest, InvalidStatusTest) { 324 TEST(OmahaRequestActionTest, InvalidStatusTest) {
303 OmahaResponse response; 325 OmahaResponse response;
304 ASSERT_FALSE(TestUpdateCheck( 326 ASSERT_FALSE(TestUpdateCheck(
305 NULL, // prefs 327 NULL, // prefs
306 kDefaultTestParams, 328 kDefaultTestParams,
307 "<?xml version=\"1.0\" encoding=\"UTF-8\"?><gupdate " 329 "<?xml version=\"1.0\" encoding=\"UTF-8\"?><gupdate "
308 "xmlns=\"http://www.google.com/update2/response\" protocol=\"2.0\"><app " 330 "xmlns=\"http://www.google.com/update2/response\" protocol=\"2.0\"><app "
309 "appid=\"foo\" status=\"ok\"><ping " 331 "appid=\"foo\" status=\"ok\"><ping "
310 "status=\"ok\"/><updatecheck status=\"foo\"/></app></gupdate>", 332 "status=\"ok\"/><updatecheck status=\"foo\"/></app></gupdate>",
311 kActionCodeError, 333 -1,
334 kActionCodeOmahaRequestBadUpdateCheckStatus,
312 &response, 335 &response,
313 NULL)); 336 NULL));
314 EXPECT_FALSE(response.update_exists); 337 EXPECT_FALSE(response.update_exists);
315 } 338 }
316 339
317 TEST(OmahaRequestActionTest, MissingNodesetTest) { 340 TEST(OmahaRequestActionTest, MissingNodesetTest) {
318 OmahaResponse response; 341 OmahaResponse response;
319 ASSERT_FALSE(TestUpdateCheck( 342 ASSERT_FALSE(TestUpdateCheck(
320 NULL, // prefs 343 NULL, // prefs
321 kDefaultTestParams, 344 kDefaultTestParams,
322 "<?xml version=\"1.0\" encoding=\"UTF-8\"?><gupdate " 345 "<?xml version=\"1.0\" encoding=\"UTF-8\"?><gupdate "
323 "xmlns=\"http://www.google.com/update2/response\" protocol=\"2.0\"><app " 346 "xmlns=\"http://www.google.com/update2/response\" protocol=\"2.0\"><app "
324 "appid=\"foo\" status=\"ok\"><ping " 347 "appid=\"foo\" status=\"ok\"><ping "
325 "status=\"ok\"/></app></gupdate>", 348 "status=\"ok\"/></app></gupdate>",
326 kActionCodeError, 349 -1,
350 kActionCodeOmahaRequestNoUpdateCheckNode,
327 &response, 351 &response,
328 NULL)); 352 NULL));
329 EXPECT_FALSE(response.update_exists); 353 EXPECT_FALSE(response.update_exists);
330 } 354 }
331 355
332 TEST(OmahaRequestActionTest, MissingFieldTest) { 356 TEST(OmahaRequestActionTest, MissingFieldTest) {
333 OmahaResponse response; 357 OmahaResponse response;
334 ASSERT_TRUE(TestUpdateCheck(NULL, // prefs 358 ASSERT_TRUE(TestUpdateCheck(NULL, // prefs
335 kDefaultTestParams, 359 kDefaultTestParams,
336 string("<?xml version=\"1.0\" " 360 string("<?xml version=\"1.0\" "
337 "encoding=\"UTF-8\"?><gupdate " 361 "encoding=\"UTF-8\"?><gupdate "
338 "xmlns=\"http://www.google.com/" 362 "xmlns=\"http://www.google.com/"
339 "update2/response\" " 363 "update2/response\" "
340 "protocol=\"2.0\"><app appid=\"") + 364 "protocol=\"2.0\"><app appid=\"") +
341 OmahaRequestParams::kAppId 365 OmahaRequestParams::kAppId
342 + "\" status=\"ok\"><ping " 366 + "\" status=\"ok\"><ping "
343 "status=\"ok\"/><updatecheck " 367 "status=\"ok\"/><updatecheck "
344 "DisplayVersion=\"1.2.3.4\" " 368 "DisplayVersion=\"1.2.3.4\" "
345 "Prompt=\"false\" " 369 "Prompt=\"false\" "
346 "codebase=\"http://code/base\" hash=\"foo\" " 370 "codebase=\"http://code/base\" hash=\"foo\" "
347 "sha256=\"HASH1234=\" needsadmin=\"true\" " 371 "sha256=\"HASH1234=\" needsadmin=\"true\" "
348 "size=\"123\" " 372 "size=\"123\" "
349 "status=\"ok\"/></app></gupdate>", 373 "status=\"ok\"/></app></gupdate>",
374 -1,
350 kActionCodeSuccess, 375 kActionCodeSuccess,
351 &response, 376 &response,
352 NULL)); 377 NULL));
353 EXPECT_TRUE(response.update_exists); 378 EXPECT_TRUE(response.update_exists);
354 EXPECT_EQ("1.2.3.4", response.display_version); 379 EXPECT_EQ("1.2.3.4", response.display_version);
355 EXPECT_EQ("http://code/base", response.codebase); 380 EXPECT_EQ("http://code/base", response.codebase);
356 EXPECT_EQ("", response.more_info_url); 381 EXPECT_EQ("", response.more_info_url);
357 EXPECT_FALSE(response.is_delta); 382 EXPECT_FALSE(response.is_delta);
358 EXPECT_EQ("HASH1234=", response.hash); 383 EXPECT_EQ("HASH1234=", response.hash);
359 EXPECT_EQ(123, response.size); 384 EXPECT_EQ(123, response.size);
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after
419 "en-US", 444 "en-US",
420 "unittest_track&lt;", 445 "unittest_track&lt;",
421 "<OEM MODEL>", 446 "<OEM MODEL>",
422 false, // delta okay 447 false, // delta okay
423 "http://url"); 448 "http://url");
424 OmahaResponse response; 449 OmahaResponse response;
425 ASSERT_FALSE( 450 ASSERT_FALSE(
426 TestUpdateCheck(NULL, // prefs 451 TestUpdateCheck(NULL, // prefs
427 params, 452 params,
428 "invalid xml>", 453 "invalid xml>",
429 kActionCodeError, 454 -1,
455 kActionCodeOmahaRequestXMLParseError,
430 &response, 456 &response,
431 &post_data)); 457 &post_data));
432 // convert post_data to string 458 // convert post_data to string
433 string post_str(&post_data[0], post_data.size()); 459 string post_str(&post_data[0], post_data.size());
434 EXPECT_NE(post_str.find("testtheservice_pack&gt;"), string::npos); 460 EXPECT_NE(post_str.find("testtheservice_pack&gt;"), string::npos);
435 EXPECT_EQ(post_str.find("testtheservice_pack>"), string::npos); 461 EXPECT_EQ(post_str.find("testtheservice_pack>"), string::npos);
436 EXPECT_NE(post_str.find("x86 generic&lt;id"), string::npos); 462 EXPECT_NE(post_str.find("x86 generic&lt;id"), string::npos);
437 EXPECT_EQ(post_str.find("x86 generic<id"), string::npos); 463 EXPECT_EQ(post_str.find("x86 generic<id"), string::npos);
438 EXPECT_NE(post_str.find("unittest_track&amp;lt;"), string::npos); 464 EXPECT_NE(post_str.find("unittest_track&amp;lt;"), string::npos);
439 EXPECT_EQ(post_str.find("unittest_track&lt;"), string::npos); 465 EXPECT_EQ(post_str.find("unittest_track&lt;"), string::npos);
440 EXPECT_NE(post_str.find("&lt;OEM MODEL&gt;"), string::npos); 466 EXPECT_NE(post_str.find("&lt;OEM MODEL&gt;"), string::npos);
441 EXPECT_EQ(post_str.find("<OEM MODEL>"), string::npos); 467 EXPECT_EQ(post_str.find("<OEM MODEL>"), string::npos);
442 } 468 }
443 469
444 TEST(OmahaRequestActionTest, XmlDecodeTest) { 470 TEST(OmahaRequestActionTest, XmlDecodeTest) {
445 OmahaResponse response; 471 OmahaResponse response;
446 ASSERT_TRUE( 472 ASSERT_TRUE(
447 TestUpdateCheck(NULL, // prefs 473 TestUpdateCheck(NULL, // prefs
448 kDefaultTestParams, 474 kDefaultTestParams,
449 GetUpdateResponse(OmahaRequestParams::kAppId, 475 GetUpdateResponse(OmahaRequestParams::kAppId,
450 "1.2.3.4", // version 476 "1.2.3.4", // version
451 "testthe&lt;url", // more info 477 "testthe&lt;url", // more info
452 "true", // prompt 478 "true", // prompt
453 "testthe&amp;codebase", // dl url 479 "testthe&amp;codebase", // dl url
454 "HASH1234=", // checksum 480 "HASH1234=", // checksum
455 "false", // needs admin 481 "false", // needs admin
456 "123", // size 482 "123", // size
457 "&lt;20110101"), // deadline 483 "&lt;20110101"), // deadline
484 -1,
458 kActionCodeSuccess, 485 kActionCodeSuccess,
459 &response, 486 &response,
460 NULL)); 487 NULL));
461 488
462 EXPECT_EQ(response.more_info_url, "testthe<url"); 489 EXPECT_EQ(response.more_info_url, "testthe<url");
463 EXPECT_EQ(response.codebase, "testthe&codebase"); 490 EXPECT_EQ(response.codebase, "testthe&codebase");
464 EXPECT_EQ(response.deadline, "<20110101"); 491 EXPECT_EQ(response.deadline, "<20110101");
465 } 492 }
466 493
467 TEST(OmahaRequestActionTest, ParseIntTest) { 494 TEST(OmahaRequestActionTest, ParseIntTest) {
468 OmahaResponse response; 495 OmahaResponse response;
469 ASSERT_TRUE( 496 ASSERT_TRUE(
470 TestUpdateCheck(NULL, // prefs 497 TestUpdateCheck(NULL, // prefs
471 kDefaultTestParams, 498 kDefaultTestParams,
472 GetUpdateResponse(OmahaRequestParams::kAppId, 499 GetUpdateResponse(OmahaRequestParams::kAppId,
473 "1.2.3.4", // version 500 "1.2.3.4", // version
474 "theurl", // more info 501 "theurl", // more info
475 "true", // prompt 502 "true", // prompt
476 "thecodebase", // dl url 503 "thecodebase", // dl url
477 "HASH1234=", // checksum 504 "HASH1234=", // checksum
478 "false", // needs admin 505 "false", // needs admin
479 // overflows int32: 506 // overflows int32:
480 "123123123123123", // size 507 "123123123123123", // size
481 "deadline"), 508 "deadline"),
509 -1,
482 kActionCodeSuccess, 510 kActionCodeSuccess,
483 &response, 511 &response,
484 NULL)); 512 NULL));
485 513
486 EXPECT_EQ(response.size, 123123123123123ll); 514 EXPECT_EQ(response.size, 123123123123123ll);
487 } 515 }
488 516
489 TEST(OmahaRequestActionTest, FormatUpdateCheckOutputTest) { 517 TEST(OmahaRequestActionTest, FormatUpdateCheckOutputTest) {
490 vector<char> post_data; 518 vector<char> post_data;
491 ASSERT_FALSE(TestUpdateCheck(NULL, // prefs 519 ASSERT_FALSE(TestUpdateCheck(NULL, // prefs
492 kDefaultTestParams, 520 kDefaultTestParams,
493 "invalid xml>", 521 "invalid xml>",
494 kActionCodeError, 522 -1,
523 kActionCodeOmahaRequestXMLParseError,
495 NULL, // response 524 NULL, // response
496 &post_data)); 525 &post_data));
497 // convert post_data to string 526 // convert post_data to string
498 string post_str(&post_data[0], post_data.size()); 527 string post_str(&post_data[0], post_data.size());
499 EXPECT_NE(post_str.find(" <o:ping a=\"-1\" r=\"-1\"></o:ping>\n" 528 EXPECT_NE(post_str.find(" <o:ping a=\"-1\" r=\"-1\"></o:ping>\n"
500 " <o:updatecheck></o:updatecheck>\n"), 529 " <o:updatecheck></o:updatecheck>\n"),
501 string::npos); 530 string::npos);
502 EXPECT_NE(post_str.find("hardware_class=\"OEM MODEL 09235 7471\""), 531 EXPECT_NE(post_str.find("hardware_class=\"OEM MODEL 09235 7471\""),
503 string::npos); 532 string::npos);
504 EXPECT_EQ(post_str.find("o:event"), string::npos); 533 EXPECT_EQ(post_str.find("o:event"), string::npos);
(...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after
593 OmahaRequestParams::kAppId, 622 OmahaRequestParams::kAppId,
594 "0.1.0.0", 623 "0.1.0.0",
595 "en-US", 624 "en-US",
596 "unittest_track", 625 "unittest_track",
597 "OEM MODEL REV 1234", 626 "OEM MODEL REV 1234",
598 delta_okay, 627 delta_okay,
599 "http://url"); 628 "http://url");
600 ASSERT_FALSE(TestUpdateCheck(NULL, // prefs 629 ASSERT_FALSE(TestUpdateCheck(NULL, // prefs
601 params, 630 params,
602 "invalid xml>", 631 "invalid xml>",
603 kActionCodeError, 632 -1,
633 kActionCodeOmahaRequestXMLParseError,
604 NULL, 634 NULL,
605 &post_data)); 635 &post_data));
606 // convert post_data to string 636 // convert post_data to string
607 string post_str(&post_data[0], post_data.size()); 637 string post_str(&post_data[0], post_data.size());
608 EXPECT_NE(post_str.find(StringPrintf(" delta_okay=\"%s\"", delta_okay_str)), 638 EXPECT_NE(post_str.find(StringPrintf(" delta_okay=\"%s\"", delta_okay_str)),
609 string::npos) 639 string::npos)
610 << "i = " << i; 640 << "i = " << i;
611 } 641 }
612 } 642 }
613 643
(...skipping 25 matching lines...) Expand all
639 (Time::Now() - TimeDelta::FromHours(6 * 24 + 11)).ToInternalValue(); 669 (Time::Now() - TimeDelta::FromHours(6 * 24 + 11)).ToInternalValue();
640 EXPECT_CALL(prefs, GetInt64(kPrefsLastActivePingDay, _)) 670 EXPECT_CALL(prefs, GetInt64(kPrefsLastActivePingDay, _))
641 .WillOnce(DoAll(SetArgumentPointee<1>(six_days_ago), Return(true))); 671 .WillOnce(DoAll(SetArgumentPointee<1>(six_days_ago), Return(true)));
642 EXPECT_CALL(prefs, GetInt64(kPrefsLastRollCallPingDay, _)) 672 EXPECT_CALL(prefs, GetInt64(kPrefsLastRollCallPingDay, _))
643 .WillOnce(DoAll(SetArgumentPointee<1>(five_days_ago), Return(true))); 673 .WillOnce(DoAll(SetArgumentPointee<1>(five_days_ago), Return(true)));
644 vector<char> post_data; 674 vector<char> post_data;
645 ASSERT_TRUE( 675 ASSERT_TRUE(
646 TestUpdateCheck(&prefs, 676 TestUpdateCheck(&prefs,
647 kDefaultTestParams, 677 kDefaultTestParams,
648 GetNoUpdateResponse(OmahaRequestParams::kAppId), 678 GetNoUpdateResponse(OmahaRequestParams::kAppId),
679 -1,
649 kActionCodeSuccess, 680 kActionCodeSuccess,
650 NULL, 681 NULL,
651 &post_data)); 682 &post_data));
652 string post_str(&post_data[0], post_data.size()); 683 string post_str(&post_data[0], post_data.size());
653 EXPECT_NE(post_str.find("<o:ping a=\"6\" r=\"5\"></o:ping>"), string::npos); 684 EXPECT_NE(post_str.find("<o:ping a=\"6\" r=\"5\"></o:ping>"), string::npos);
654 } 685 }
655 686
656 TEST(OmahaRequestActionTest, ActivePingTest) { 687 TEST(OmahaRequestActionTest, ActivePingTest) {
657 PrefsMock prefs; 688 PrefsMock prefs;
658 int64_t three_days_ago = 689 int64_t three_days_ago =
659 (Time::Now() - TimeDelta::FromHours(3 * 24 + 12)).ToInternalValue(); 690 (Time::Now() - TimeDelta::FromHours(3 * 24 + 12)).ToInternalValue();
660 int64_t now = Time::Now().ToInternalValue(); 691 int64_t now = Time::Now().ToInternalValue();
661 EXPECT_CALL(prefs, GetInt64(kPrefsLastActivePingDay, _)) 692 EXPECT_CALL(prefs, GetInt64(kPrefsLastActivePingDay, _))
662 .WillOnce(DoAll(SetArgumentPointee<1>(three_days_ago), Return(true))); 693 .WillOnce(DoAll(SetArgumentPointee<1>(three_days_ago), Return(true)));
663 EXPECT_CALL(prefs, GetInt64(kPrefsLastRollCallPingDay, _)) 694 EXPECT_CALL(prefs, GetInt64(kPrefsLastRollCallPingDay, _))
664 .WillOnce(DoAll(SetArgumentPointee<1>(now), Return(true))); 695 .WillOnce(DoAll(SetArgumentPointee<1>(now), Return(true)));
665 vector<char> post_data; 696 vector<char> post_data;
666 ASSERT_TRUE( 697 ASSERT_TRUE(
667 TestUpdateCheck(&prefs, 698 TestUpdateCheck(&prefs,
668 kDefaultTestParams, 699 kDefaultTestParams,
669 GetNoUpdateResponse(OmahaRequestParams::kAppId), 700 GetNoUpdateResponse(OmahaRequestParams::kAppId),
701 -1,
670 kActionCodeSuccess, 702 kActionCodeSuccess,
671 NULL, 703 NULL,
672 &post_data)); 704 &post_data));
673 string post_str(&post_data[0], post_data.size()); 705 string post_str(&post_data[0], post_data.size());
674 EXPECT_NE(post_str.find("<o:ping a=\"3\"></o:ping>"), string::npos); 706 EXPECT_NE(post_str.find("<o:ping a=\"3\"></o:ping>"), string::npos);
675 } 707 }
676 708
677 TEST(OmahaRequestActionTest, RollCallPingTest) { 709 TEST(OmahaRequestActionTest, RollCallPingTest) {
678 PrefsMock prefs; 710 PrefsMock prefs;
679 int64_t four_days_ago = 711 int64_t four_days_ago =
680 (Time::Now() - TimeDelta::FromHours(4 * 24)).ToInternalValue(); 712 (Time::Now() - TimeDelta::FromHours(4 * 24)).ToInternalValue();
681 int64_t now = Time::Now().ToInternalValue(); 713 int64_t now = Time::Now().ToInternalValue();
682 EXPECT_CALL(prefs, GetInt64(kPrefsLastActivePingDay, _)) 714 EXPECT_CALL(prefs, GetInt64(kPrefsLastActivePingDay, _))
683 .WillOnce(DoAll(SetArgumentPointee<1>(now), Return(true))); 715 .WillOnce(DoAll(SetArgumentPointee<1>(now), Return(true)));
684 EXPECT_CALL(prefs, GetInt64(kPrefsLastRollCallPingDay, _)) 716 EXPECT_CALL(prefs, GetInt64(kPrefsLastRollCallPingDay, _))
685 .WillOnce(DoAll(SetArgumentPointee<1>(four_days_ago), Return(true))); 717 .WillOnce(DoAll(SetArgumentPointee<1>(four_days_ago), Return(true)));
686 vector<char> post_data; 718 vector<char> post_data;
687 ASSERT_TRUE( 719 ASSERT_TRUE(
688 TestUpdateCheck(&prefs, 720 TestUpdateCheck(&prefs,
689 kDefaultTestParams, 721 kDefaultTestParams,
690 GetNoUpdateResponse(OmahaRequestParams::kAppId), 722 GetNoUpdateResponse(OmahaRequestParams::kAppId),
723 -1,
691 kActionCodeSuccess, 724 kActionCodeSuccess,
692 NULL, 725 NULL,
693 &post_data)); 726 &post_data));
694 string post_str(&post_data[0], post_data.size()); 727 string post_str(&post_data[0], post_data.size());
695 EXPECT_NE(post_str.find("<o:ping r=\"4\"></o:ping>\n"), string::npos); 728 EXPECT_NE(post_str.find("<o:ping r=\"4\"></o:ping>\n"), string::npos);
696 } 729 }
697 730
698 TEST(OmahaRequestActionTest, NoPingTest) { 731 TEST(OmahaRequestActionTest, NoPingTest) {
699 PrefsMock prefs; 732 PrefsMock prefs;
700 int64_t one_hour_ago = 733 int64_t one_hour_ago =
701 (Time::Now() - TimeDelta::FromHours(1)).ToInternalValue(); 734 (Time::Now() - TimeDelta::FromHours(1)).ToInternalValue();
702 EXPECT_CALL(prefs, GetInt64(kPrefsLastActivePingDay, _)) 735 EXPECT_CALL(prefs, GetInt64(kPrefsLastActivePingDay, _))
703 .WillOnce(DoAll(SetArgumentPointee<1>(one_hour_ago), Return(true))); 736 .WillOnce(DoAll(SetArgumentPointee<1>(one_hour_ago), Return(true)));
704 EXPECT_CALL(prefs, GetInt64(kPrefsLastRollCallPingDay, _)) 737 EXPECT_CALL(prefs, GetInt64(kPrefsLastRollCallPingDay, _))
705 .WillOnce(DoAll(SetArgumentPointee<1>(one_hour_ago), Return(true))); 738 .WillOnce(DoAll(SetArgumentPointee<1>(one_hour_ago), Return(true)));
706 EXPECT_CALL(prefs, SetInt64(kPrefsLastActivePingDay, _)).Times(0); 739 EXPECT_CALL(prefs, SetInt64(kPrefsLastActivePingDay, _)).Times(0);
707 EXPECT_CALL(prefs, SetInt64(kPrefsLastRollCallPingDay, _)).Times(0); 740 EXPECT_CALL(prefs, SetInt64(kPrefsLastRollCallPingDay, _)).Times(0);
708 vector<char> post_data; 741 vector<char> post_data;
709 ASSERT_TRUE( 742 ASSERT_TRUE(
710 TestUpdateCheck(&prefs, 743 TestUpdateCheck(&prefs,
711 kDefaultTestParams, 744 kDefaultTestParams,
712 GetNoUpdateResponse(OmahaRequestParams::kAppId), 745 GetNoUpdateResponse(OmahaRequestParams::kAppId),
746 -1,
713 kActionCodeSuccess, 747 kActionCodeSuccess,
714 NULL, 748 NULL,
715 &post_data)); 749 &post_data));
716 string post_str(&post_data[0], post_data.size()); 750 string post_str(&post_data[0], post_data.size());
717 EXPECT_EQ(post_str.find("o:ping"), string::npos); 751 EXPECT_EQ(post_str.find("o:ping"), string::npos);
718 } 752 }
719 753
720 TEST(OmahaRequestActionTest, BackInTimePingTest) { 754 TEST(OmahaRequestActionTest, BackInTimePingTest) {
721 PrefsMock prefs; 755 PrefsMock prefs;
722 int64_t future = 756 int64_t future =
723 (Time::Now() + TimeDelta::FromHours(3 * 24 + 4)).ToInternalValue(); 757 (Time::Now() + TimeDelta::FromHours(3 * 24 + 4)).ToInternalValue();
724 EXPECT_CALL(prefs, GetInt64(kPrefsLastActivePingDay, _)) 758 EXPECT_CALL(prefs, GetInt64(kPrefsLastActivePingDay, _))
725 .WillOnce(DoAll(SetArgumentPointee<1>(future), Return(true))); 759 .WillOnce(DoAll(SetArgumentPointee<1>(future), Return(true)));
726 EXPECT_CALL(prefs, GetInt64(kPrefsLastRollCallPingDay, _)) 760 EXPECT_CALL(prefs, GetInt64(kPrefsLastRollCallPingDay, _))
727 .WillOnce(DoAll(SetArgumentPointee<1>(future), Return(true))); 761 .WillOnce(DoAll(SetArgumentPointee<1>(future), Return(true)));
728 EXPECT_CALL(prefs, SetInt64(kPrefsLastActivePingDay, _)) 762 EXPECT_CALL(prefs, SetInt64(kPrefsLastActivePingDay, _))
729 .WillOnce(Return(true)); 763 .WillOnce(Return(true));
730 EXPECT_CALL(prefs, SetInt64(kPrefsLastRollCallPingDay, _)) 764 EXPECT_CALL(prefs, SetInt64(kPrefsLastRollCallPingDay, _))
731 .WillOnce(Return(true)); 765 .WillOnce(Return(true));
732 vector<char> post_data; 766 vector<char> post_data;
733 ASSERT_TRUE( 767 ASSERT_TRUE(
734 TestUpdateCheck(&prefs, 768 TestUpdateCheck(&prefs,
735 kDefaultTestParams, 769 kDefaultTestParams,
736 "<?xml version=\"1.0\" encoding=\"UTF-8\"?><gupdate " 770 "<?xml version=\"1.0\" encoding=\"UTF-8\"?><gupdate "
737 "xmlns=\"http://www.google.com/update2/response\" " 771 "xmlns=\"http://www.google.com/update2/response\" "
738 "protocol=\"2.0\"><daystart elapsed_seconds=\"100\"/>" 772 "protocol=\"2.0\"><daystart elapsed_seconds=\"100\"/>"
739 "<app appid=\"foo\" status=\"ok\"><ping status=\"ok\"/>" 773 "<app appid=\"foo\" status=\"ok\"><ping status=\"ok\"/>"
740 "<updatecheck status=\"noupdate\"/></app></gupdate>", 774 "<updatecheck status=\"noupdate\"/></app></gupdate>",
775 -1,
741 kActionCodeSuccess, 776 kActionCodeSuccess,
742 NULL, 777 NULL,
743 &post_data)); 778 &post_data));
744 string post_str(&post_data[0], post_data.size()); 779 string post_str(&post_data[0], post_data.size());
745 EXPECT_EQ(post_str.find("o:ping"), string::npos); 780 EXPECT_EQ(post_str.find("o:ping"), string::npos);
746 } 781 }
747 782
748 TEST(OmahaRequestActionTest, LastPingDayUpdateTest) { 783 TEST(OmahaRequestActionTest, LastPingDayUpdateTest) {
749 // This test checks that the action updates the last ping day to now 784 // This test checks that the action updates the last ping day to now
750 // minus 200 seconds with a slack of 5 seconds. Therefore, the test 785 // minus 200 seconds with a slack of 5 seconds. Therefore, the test
(...skipping 11 matching lines...) Expand all
762 AllOf(Ge(midnight), Le(midnight_slack)))) 797 AllOf(Ge(midnight), Le(midnight_slack))))
763 .WillOnce(Return(true)); 798 .WillOnce(Return(true));
764 ASSERT_TRUE( 799 ASSERT_TRUE(
765 TestUpdateCheck(&prefs, 800 TestUpdateCheck(&prefs,
766 kDefaultTestParams, 801 kDefaultTestParams,
767 "<?xml version=\"1.0\" encoding=\"UTF-8\"?><gupdate " 802 "<?xml version=\"1.0\" encoding=\"UTF-8\"?><gupdate "
768 "xmlns=\"http://www.google.com/update2/response\" " 803 "xmlns=\"http://www.google.com/update2/response\" "
769 "protocol=\"2.0\"><daystart elapsed_seconds=\"200\"/>" 804 "protocol=\"2.0\"><daystart elapsed_seconds=\"200\"/>"
770 "<app appid=\"foo\" status=\"ok\"><ping status=\"ok\"/>" 805 "<app appid=\"foo\" status=\"ok\"><ping status=\"ok\"/>"
771 "<updatecheck status=\"noupdate\"/></app></gupdate>", 806 "<updatecheck status=\"noupdate\"/></app></gupdate>",
807 -1,
772 kActionCodeSuccess, 808 kActionCodeSuccess,
773 NULL, 809 NULL,
774 NULL)); 810 NULL));
775 } 811 }
776 812
777 TEST(OmahaRequestActionTest, NoElapsedSecondsTest) { 813 TEST(OmahaRequestActionTest, NoElapsedSecondsTest) {
778 PrefsMock prefs; 814 PrefsMock prefs;
779 EXPECT_CALL(prefs, SetInt64(kPrefsLastActivePingDay, _)).Times(0); 815 EXPECT_CALL(prefs, SetInt64(kPrefsLastActivePingDay, _)).Times(0);
780 EXPECT_CALL(prefs, SetInt64(kPrefsLastRollCallPingDay, _)).Times(0); 816 EXPECT_CALL(prefs, SetInt64(kPrefsLastRollCallPingDay, _)).Times(0);
781 ASSERT_TRUE( 817 ASSERT_TRUE(
782 TestUpdateCheck(&prefs, 818 TestUpdateCheck(&prefs,
783 kDefaultTestParams, 819 kDefaultTestParams,
784 "<?xml version=\"1.0\" encoding=\"UTF-8\"?><gupdate " 820 "<?xml version=\"1.0\" encoding=\"UTF-8\"?><gupdate "
785 "xmlns=\"http://www.google.com/update2/response\" " 821 "xmlns=\"http://www.google.com/update2/response\" "
786 "protocol=\"2.0\"><daystart blah=\"200\"/>" 822 "protocol=\"2.0\"><daystart blah=\"200\"/>"
787 "<app appid=\"foo\" status=\"ok\"><ping status=\"ok\"/>" 823 "<app appid=\"foo\" status=\"ok\"><ping status=\"ok\"/>"
788 "<updatecheck status=\"noupdate\"/></app></gupdate>", 824 "<updatecheck status=\"noupdate\"/></app></gupdate>",
825 -1,
789 kActionCodeSuccess, 826 kActionCodeSuccess,
790 NULL, 827 NULL,
791 NULL)); 828 NULL));
792 } 829 }
793 830
794 TEST(OmahaRequestActionTest, BadElapsedSecondsTest) { 831 TEST(OmahaRequestActionTest, BadElapsedSecondsTest) {
795 PrefsMock prefs; 832 PrefsMock prefs;
796 EXPECT_CALL(prefs, SetInt64(kPrefsLastActivePingDay, _)).Times(0); 833 EXPECT_CALL(prefs, SetInt64(kPrefsLastActivePingDay, _)).Times(0);
797 EXPECT_CALL(prefs, SetInt64(kPrefsLastRollCallPingDay, _)).Times(0); 834 EXPECT_CALL(prefs, SetInt64(kPrefsLastRollCallPingDay, _)).Times(0);
798 ASSERT_TRUE( 835 ASSERT_TRUE(
799 TestUpdateCheck(&prefs, 836 TestUpdateCheck(&prefs,
800 kDefaultTestParams, 837 kDefaultTestParams,
801 "<?xml version=\"1.0\" encoding=\"UTF-8\"?><gupdate " 838 "<?xml version=\"1.0\" encoding=\"UTF-8\"?><gupdate "
802 "xmlns=\"http://www.google.com/update2/response\" " 839 "xmlns=\"http://www.google.com/update2/response\" "
803 "protocol=\"2.0\"><daystart elapsed_seconds=\"x\"/>" 840 "protocol=\"2.0\"><daystart elapsed_seconds=\"x\"/>"
804 "<app appid=\"foo\" status=\"ok\"><ping status=\"ok\"/>" 841 "<app appid=\"foo\" status=\"ok\"><ping status=\"ok\"/>"
805 "<updatecheck status=\"noupdate\"/></app></gupdate>", 842 "<updatecheck status=\"noupdate\"/></app></gupdate>",
843 -1,
806 kActionCodeSuccess, 844 kActionCodeSuccess,
807 NULL, 845 NULL,
808 NULL)); 846 NULL));
809 } 847 }
810 848
811 TEST(OmahaRequestActionTest, NoUniqueIDTest) { 849 TEST(OmahaRequestActionTest, NoUniqueIDTest) {
812 vector<char> post_data; 850 vector<char> post_data;
813 ASSERT_FALSE(TestUpdateCheck(NULL, // prefs 851 ASSERT_FALSE(TestUpdateCheck(NULL, // prefs
814 kDefaultTestParams, 852 kDefaultTestParams,
815 "invalid xml>", 853 "invalid xml>",
816 kActionCodeError, 854 -1,
855 kActionCodeOmahaRequestXMLParseError,
817 NULL, // response 856 NULL, // response
818 &post_data)); 857 &post_data));
819 // convert post_data to string 858 // convert post_data to string
820 string post_str(&post_data[0], post_data.size()); 859 string post_str(&post_data[0], post_data.size());
821 EXPECT_EQ(post_str.find("machineid="), string::npos); 860 EXPECT_EQ(post_str.find("machineid="), string::npos);
822 EXPECT_EQ(post_str.find("userid="), string::npos); 861 EXPECT_EQ(post_str.find("userid="), string::npos);
823 } 862 }
824 863
864 TEST(OmahaRequestActionTest, NetworkFailureTest) {
865 OmahaResponse response;
866 ASSERT_FALSE(
867 TestUpdateCheck(NULL, // prefs
868 kDefaultTestParams,
869 "",
870 501,
871 static_cast<ActionExitCode>(
872 kActionCodeOmahaRequestHTTPResponseBase + 501),
873 &response,
874 NULL));
875 EXPECT_FALSE(response.update_exists);
876 }
877
878 TEST(OmahaRequestActionTest, NetworkFailureBadHTTPCodeTest) {
879 OmahaResponse response;
880 ASSERT_FALSE(
881 TestUpdateCheck(NULL, // prefs
882 kDefaultTestParams,
883 "",
884 1500,
885 static_cast<ActionExitCode>(
886 kActionCodeOmahaRequestHTTPResponseBase + 999),
887 &response,
888 NULL));
889 EXPECT_FALSE(response.update_exists);
890 }
891
825 } // namespace chromeos_update_engine 892 } // namespace chromeos_update_engine
OLDNEW
« no previous file with comments | « omaha_request_action.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698