| 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 25 matching lines...) Expand all Loading... |
| 36 namespace { | 36 namespace { |
| 37 const OmahaRequestParams kDefaultTestParams( | 37 const OmahaRequestParams kDefaultTestParams( |
| 38 OmahaRequestParams::kOsPlatform, | 38 OmahaRequestParams::kOsPlatform, |
| 39 OmahaRequestParams::kOsVersion, | 39 OmahaRequestParams::kOsVersion, |
| 40 "service_pack", | 40 "service_pack", |
| 41 "x86-generic", | 41 "x86-generic", |
| 42 OmahaRequestParams::kAppId, | 42 OmahaRequestParams::kAppId, |
| 43 "0.1.0.0", | 43 "0.1.0.0", |
| 44 "en-US", | 44 "en-US", |
| 45 "unittest", | 45 "unittest", |
| 46 "OEM MODEL 09235 7471", |
| 46 false, // delta okay | 47 false, // delta okay |
| 47 "http://url"); | 48 "http://url"); |
| 48 | 49 |
| 49 string GetNoUpdateResponse(const string& app_id) { | 50 string GetNoUpdateResponse(const string& app_id) { |
| 50 return string( | 51 return string( |
| 51 "<?xml version=\"1.0\" encoding=\"UTF-8\"?><gupdate " | 52 "<?xml version=\"1.0\" encoding=\"UTF-8\"?><gupdate " |
| 52 "xmlns=\"http://www.google.com/update2/response\" protocol=\"2.0\"><app " | 53 "xmlns=\"http://www.google.com/update2/response\" protocol=\"2.0\"><app " |
| 53 "appid=\"") + app_id + "\" status=\"ok\"><ping " | 54 "appid=\"") + app_id + "\" status=\"ok\"><ping " |
| 54 "status=\"ok\"/><updatecheck status=\"noupdate\"/></app></gupdate>"; | 55 "status=\"ok\"/><updatecheck status=\"noupdate\"/></app></gupdate>"; |
| 55 } | 56 } |
| (...skipping 349 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 405 | 406 |
| 406 // Make sure XML Encode is being called on the params | 407 // Make sure XML Encode is being called on the params |
| 407 OmahaRequestParams params(OmahaRequestParams::kOsPlatform, | 408 OmahaRequestParams params(OmahaRequestParams::kOsPlatform, |
| 408 OmahaRequestParams::kOsVersion, | 409 OmahaRequestParams::kOsVersion, |
| 409 "testtheservice_pack>", | 410 "testtheservice_pack>", |
| 410 "x86 generic<id", | 411 "x86 generic<id", |
| 411 OmahaRequestParams::kAppId, | 412 OmahaRequestParams::kAppId, |
| 412 "0.1.0.0", | 413 "0.1.0.0", |
| 413 "en-US", | 414 "en-US", |
| 414 "unittest_track<", | 415 "unittest_track<", |
| 416 "<OEM MODEL>", |
| 415 false, // delta okay | 417 false, // delta okay |
| 416 "http://url"); | 418 "http://url"); |
| 417 OmahaResponse response; | 419 OmahaResponse response; |
| 418 ASSERT_FALSE( | 420 ASSERT_FALSE( |
| 419 TestUpdateCheck(NULL, // prefs | 421 TestUpdateCheck(NULL, // prefs |
| 420 params, | 422 params, |
| 421 "invalid xml>", | 423 "invalid xml>", |
| 422 kActionCodeError, | 424 kActionCodeError, |
| 423 &response, | 425 &response, |
| 424 &post_data)); | 426 &post_data)); |
| 425 // convert post_data to string | 427 // convert post_data to string |
| 426 string post_str(&post_data[0], post_data.size()); | 428 string post_str(&post_data[0], post_data.size()); |
| 427 EXPECT_NE(post_str.find("testtheservice_pack>"), string::npos); | 429 EXPECT_NE(post_str.find("testtheservice_pack>"), string::npos); |
| 428 EXPECT_EQ(post_str.find("testtheservice_pack>"), string::npos); | 430 EXPECT_EQ(post_str.find("testtheservice_pack>"), string::npos); |
| 429 EXPECT_NE(post_str.find("x86 generic<id"), string::npos); | 431 EXPECT_NE(post_str.find("x86 generic<id"), string::npos); |
| 430 EXPECT_EQ(post_str.find("x86 generic<id"), string::npos); | 432 EXPECT_EQ(post_str.find("x86 generic<id"), string::npos); |
| 431 EXPECT_NE(post_str.find("unittest_track&lt;"), string::npos); | 433 EXPECT_NE(post_str.find("unittest_track&lt;"), string::npos); |
| 432 EXPECT_EQ(post_str.find("unittest_track<"), string::npos); | 434 EXPECT_EQ(post_str.find("unittest_track<"), string::npos); |
| 435 EXPECT_NE(post_str.find("<OEM MODEL>"), string::npos); |
| 436 EXPECT_EQ(post_str.find("<OEM MODEL>"), string::npos); |
| 433 } | 437 } |
| 434 | 438 |
| 435 TEST(OmahaRequestActionTest, XmlDecodeTest) { | 439 TEST(OmahaRequestActionTest, XmlDecodeTest) { |
| 436 OmahaResponse response; | 440 OmahaResponse response; |
| 437 ASSERT_TRUE( | 441 ASSERT_TRUE( |
| 438 TestUpdateCheck(NULL, // prefs | 442 TestUpdateCheck(NULL, // prefs |
| 439 kDefaultTestParams, | 443 kDefaultTestParams, |
| 440 GetUpdateResponse(OmahaRequestParams::kAppId, | 444 GetUpdateResponse(OmahaRequestParams::kAppId, |
| 441 "1.2.3.4", // version | 445 "1.2.3.4", // version |
| 442 "testthe<url", // more info | 446 "testthe<url", // more info |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 480 kDefaultTestParams, | 484 kDefaultTestParams, |
| 481 "invalid xml>", | 485 "invalid xml>", |
| 482 kActionCodeError, | 486 kActionCodeError, |
| 483 NULL, // response | 487 NULL, // response |
| 484 &post_data)); | 488 &post_data)); |
| 485 // convert post_data to string | 489 // convert post_data to string |
| 486 string post_str(&post_data[0], post_data.size()); | 490 string post_str(&post_data[0], post_data.size()); |
| 487 EXPECT_NE(post_str.find(" <o:ping a=\"-1\" r=\"-1\"></o:ping>\n" | 491 EXPECT_NE(post_str.find(" <o:ping a=\"-1\" r=\"-1\"></o:ping>\n" |
| 488 " <o:updatecheck></o:updatecheck>\n"), | 492 " <o:updatecheck></o:updatecheck>\n"), |
| 489 string::npos); | 493 string::npos); |
| 494 EXPECT_NE(post_str.find("hardware_class=\"OEM MODEL 09235 7471\""), |
| 495 string::npos); |
| 490 EXPECT_EQ(post_str.find("o:event"), string::npos); | 496 EXPECT_EQ(post_str.find("o:event"), string::npos); |
| 491 } | 497 } |
| 492 | 498 |
| 493 TEST(OmahaRequestActionTest, FormatSuccessEventOutputTest) { | 499 TEST(OmahaRequestActionTest, FormatSuccessEventOutputTest) { |
| 494 vector<char> post_data; | 500 vector<char> post_data; |
| 495 TestEvent(kDefaultTestParams, | 501 TestEvent(kDefaultTestParams, |
| 496 new OmahaEvent(OmahaEvent::kTypeUpdateDownloadStarted), | 502 new OmahaEvent(OmahaEvent::kTypeUpdateDownloadStarted), |
| 497 "invalid xml>", | 503 "invalid xml>", |
| 498 &post_data); | 504 &post_data); |
| 499 // convert post_data to string | 505 // convert post_data to string |
| (...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 573 const char* delta_okay_str = delta_okay ? "true" : "false"; | 579 const char* delta_okay_str = delta_okay ? "true" : "false"; |
| 574 vector<char> post_data; | 580 vector<char> post_data; |
| 575 OmahaRequestParams params(OmahaRequestParams::kOsPlatform, | 581 OmahaRequestParams params(OmahaRequestParams::kOsPlatform, |
| 576 OmahaRequestParams::kOsVersion, | 582 OmahaRequestParams::kOsVersion, |
| 577 "service_pack", | 583 "service_pack", |
| 578 "x86-generic", | 584 "x86-generic", |
| 579 OmahaRequestParams::kAppId, | 585 OmahaRequestParams::kAppId, |
| 580 "0.1.0.0", | 586 "0.1.0.0", |
| 581 "en-US", | 587 "en-US", |
| 582 "unittest_track", | 588 "unittest_track", |
| 589 "OEM MODEL REV 1234", |
| 583 delta_okay, | 590 delta_okay, |
| 584 "http://url"); | 591 "http://url"); |
| 585 ASSERT_FALSE(TestUpdateCheck(NULL, // prefs | 592 ASSERT_FALSE(TestUpdateCheck(NULL, // prefs |
| 586 params, | 593 params, |
| 587 "invalid xml>", | 594 "invalid xml>", |
| 588 kActionCodeError, | 595 kActionCodeError, |
| 589 NULL, | 596 NULL, |
| 590 &post_data)); | 597 &post_data)); |
| 591 // convert post_data to string | 598 // convert post_data to string |
| 592 string post_str(&post_data[0], post_data.size()); | 599 string post_str(&post_data[0], post_data.size()); |
| (...skipping 208 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 801 kActionCodeError, | 808 kActionCodeError, |
| 802 NULL, // response | 809 NULL, // response |
| 803 &post_data)); | 810 &post_data)); |
| 804 // convert post_data to string | 811 // convert post_data to string |
| 805 string post_str(&post_data[0], post_data.size()); | 812 string post_str(&post_data[0], post_data.size()); |
| 806 EXPECT_EQ(post_str.find("machineid="), string::npos); | 813 EXPECT_EQ(post_str.find("machineid="), string::npos); |
| 807 EXPECT_EQ(post_str.find("userid="), string::npos); | 814 EXPECT_EQ(post_str.find("userid="), string::npos); |
| 808 } | 815 } |
| 809 | 816 |
| 810 } // namespace chromeos_update_engine | 817 } // namespace chromeos_update_engine |
| OLD | NEW |