| 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 17 matching lines...) Expand all Loading... |
| 28 using testing::Le; | 28 using testing::Le; |
| 29 using testing::Return; | 29 using testing::Return; |
| 30 using testing::SetArgumentPointee; | 30 using testing::SetArgumentPointee; |
| 31 | 31 |
| 32 namespace chromeos_update_engine { | 32 namespace chromeos_update_engine { |
| 33 | 33 |
| 34 class OmahaRequestActionTest : public ::testing::Test { }; | 34 class OmahaRequestActionTest : public ::testing::Test { }; |
| 35 | 35 |
| 36 namespace { | 36 namespace { |
| 37 const OmahaRequestParams kDefaultTestParams( | 37 const OmahaRequestParams kDefaultTestParams( |
| 38 "machine_id", | |
| 39 "user_id", | |
| 40 OmahaRequestParams::kOsPlatform, | 38 OmahaRequestParams::kOsPlatform, |
| 41 OmahaRequestParams::kOsVersion, | 39 OmahaRequestParams::kOsVersion, |
| 42 "service_pack", | 40 "service_pack", |
| 43 "x86-generic", | 41 "x86-generic", |
| 44 OmahaRequestParams::kAppId, | 42 OmahaRequestParams::kAppId, |
| 45 "0.1.0.0", | 43 "0.1.0.0", |
| 46 "en-US", | 44 "en-US", |
| 47 "unittest", | 45 "unittest", |
| 48 false, // delta okay | 46 false, // delta okay |
| 49 "http://url"); | 47 "http://url"); |
| (...skipping 349 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 399 TEST(OmahaRequestActionTest, XmlEncodeTest) { | 397 TEST(OmahaRequestActionTest, XmlEncodeTest) { |
| 400 EXPECT_EQ("ab", XmlEncode("ab")); | 398 EXPECT_EQ("ab", XmlEncode("ab")); |
| 401 EXPECT_EQ("a<b", XmlEncode("a<b")); | 399 EXPECT_EQ("a<b", XmlEncode("a<b")); |
| 402 EXPECT_EQ("foo-Ω", XmlEncode("foo-\xce\xa9")); | 400 EXPECT_EQ("foo-Ω", XmlEncode("foo-\xce\xa9")); |
| 403 EXPECT_EQ("<&>", XmlEncode("<&>")); | 401 EXPECT_EQ("<&>", XmlEncode("<&>")); |
| 404 EXPECT_EQ("&lt;&amp;&gt;", XmlEncode("<&>")); | 402 EXPECT_EQ("&lt;&amp;&gt;", XmlEncode("<&>")); |
| 405 | 403 |
| 406 vector<char> post_data; | 404 vector<char> post_data; |
| 407 | 405 |
| 408 // Make sure XML Encode is being called on the params | 406 // Make sure XML Encode is being called on the params |
| 409 OmahaRequestParams params("testthemachine<id", | 407 OmahaRequestParams params(OmahaRequestParams::kOsPlatform, |
| 410 "testtheuser_id<", | |
| 411 OmahaRequestParams::kOsPlatform, | |
| 412 OmahaRequestParams::kOsVersion, | 408 OmahaRequestParams::kOsVersion, |
| 413 "testtheservice_pack>", | 409 "testtheservice_pack>", |
| 414 "x86 generic<id", | 410 "x86 generic<id", |
| 415 OmahaRequestParams::kAppId, | 411 OmahaRequestParams::kAppId, |
| 416 "0.1.0.0", | 412 "0.1.0.0", |
| 417 "en-US", | 413 "en-US", |
| 418 "unittest_track<", | 414 "unittest_track<", |
| 419 false, // delta okay | 415 false, // delta okay |
| 420 "http://url"); | 416 "http://url"); |
| 421 OmahaResponse response; | 417 OmahaResponse response; |
| (...skipping 147 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 569 new MockHttpFetcher(http_response.data(), | 565 new MockHttpFetcher(http_response.data(), |
| 570 http_response.size())); | 566 http_response.size())); |
| 571 EXPECT_TRUE(event_action.IsEvent()); | 567 EXPECT_TRUE(event_action.IsEvent()); |
| 572 } | 568 } |
| 573 | 569 |
| 574 TEST(OmahaRequestActionTest, FormatDeltaOkayOutputTest) { | 570 TEST(OmahaRequestActionTest, FormatDeltaOkayOutputTest) { |
| 575 for (int i = 0; i < 2; i++) { | 571 for (int i = 0; i < 2; i++) { |
| 576 bool delta_okay = i == 1; | 572 bool delta_okay = i == 1; |
| 577 const char* delta_okay_str = delta_okay ? "true" : "false"; | 573 const char* delta_okay_str = delta_okay ? "true" : "false"; |
| 578 vector<char> post_data; | 574 vector<char> post_data; |
| 579 OmahaRequestParams params("machine_id", | 575 OmahaRequestParams params(OmahaRequestParams::kOsPlatform, |
| 580 "user_id", | |
| 581 OmahaRequestParams::kOsPlatform, | |
| 582 OmahaRequestParams::kOsVersion, | 576 OmahaRequestParams::kOsVersion, |
| 583 "service_pack", | 577 "service_pack", |
| 584 "x86-generic", | 578 "x86-generic", |
| 585 OmahaRequestParams::kAppId, | 579 OmahaRequestParams::kAppId, |
| 586 "0.1.0.0", | 580 "0.1.0.0", |
| 587 "en-US", | 581 "en-US", |
| 588 "unittest_track", | 582 "unittest_track", |
| 589 delta_okay, | 583 delta_okay, |
| 590 "http://url"); | 584 "http://url"); |
| 591 ASSERT_FALSE(TestUpdateCheck(NULL, // prefs | 585 ASSERT_FALSE(TestUpdateCheck(NULL, // prefs |
| (...skipping 139 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 731 "<updatecheck status=\"noupdate\"/></app></gupdate>", | 725 "<updatecheck status=\"noupdate\"/></app></gupdate>", |
| 732 kActionCodeSuccess, | 726 kActionCodeSuccess, |
| 733 NULL, | 727 NULL, |
| 734 &post_data)); | 728 &post_data)); |
| 735 string post_str(&post_data[0], post_data.size()); | 729 string post_str(&post_data[0], post_data.size()); |
| 736 EXPECT_EQ(post_str.find("o:ping"), string::npos); | 730 EXPECT_EQ(post_str.find("o:ping"), string::npos); |
| 737 } | 731 } |
| 738 | 732 |
| 739 TEST(OmahaRequestActionTest, LastPingDayUpdateTest) { | 733 TEST(OmahaRequestActionTest, LastPingDayUpdateTest) { |
| 740 // This test checks that the action updates the last ping day to now | 734 // This test checks that the action updates the last ping day to now |
| 741 // minus 200 seconds with a slack for 5 seconds. Therefore, the test | 735 // minus 200 seconds with a slack of 5 seconds. Therefore, the test |
| 742 // may fail if it runs for longer than 5 seconds. It shouldn't run | 736 // may fail if it runs for longer than 5 seconds. It shouldn't run |
| 743 // that long though. | 737 // that long though. |
| 744 int64_t midnight = | 738 int64_t midnight = |
| 745 (Time::Now() - TimeDelta::FromSeconds(200)).ToInternalValue(); | 739 (Time::Now() - TimeDelta::FromSeconds(200)).ToInternalValue(); |
| 746 int64_t midnight_slack = | 740 int64_t midnight_slack = |
| 747 (Time::Now() - TimeDelta::FromSeconds(195)).ToInternalValue(); | 741 (Time::Now() - TimeDelta::FromSeconds(195)).ToInternalValue(); |
| 748 PrefsMock prefs; | 742 PrefsMock prefs; |
| 749 EXPECT_CALL(prefs, SetInt64(kPrefsLastActivePingDay, | 743 EXPECT_CALL(prefs, SetInt64(kPrefsLastActivePingDay, |
| 750 AllOf(Ge(midnight), Le(midnight_slack)))) | 744 AllOf(Ge(midnight), Le(midnight_slack)))) |
| 751 .WillOnce(Return(true)); | 745 .WillOnce(Return(true)); |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 792 "<?xml version=\"1.0\" encoding=\"UTF-8\"?><gupdate " | 786 "<?xml version=\"1.0\" encoding=\"UTF-8\"?><gupdate " |
| 793 "xmlns=\"http://www.google.com/update2/response\" " | 787 "xmlns=\"http://www.google.com/update2/response\" " |
| 794 "protocol=\"2.0\"><daystart elapsed_seconds=\"x\"/>" | 788 "protocol=\"2.0\"><daystart elapsed_seconds=\"x\"/>" |
| 795 "<app appid=\"foo\" status=\"ok\"><ping status=\"ok\"/>" | 789 "<app appid=\"foo\" status=\"ok\"><ping status=\"ok\"/>" |
| 796 "<updatecheck status=\"noupdate\"/></app></gupdate>", | 790 "<updatecheck status=\"noupdate\"/></app></gupdate>", |
| 797 kActionCodeSuccess, | 791 kActionCodeSuccess, |
| 798 NULL, | 792 NULL, |
| 799 NULL)); | 793 NULL)); |
| 800 } | 794 } |
| 801 | 795 |
| 796 TEST(OmahaRequestActionTest, NoUniqueIDTest) { |
| 797 vector<char> post_data; |
| 798 ASSERT_FALSE(TestUpdateCheck(NULL, // prefs |
| 799 kDefaultTestParams, |
| 800 "invalid xml>", |
| 801 kActionCodeError, |
| 802 NULL, // response |
| 803 &post_data)); |
| 804 // convert post_data to string |
| 805 string post_str(&post_data[0], post_data.size()); |
| 806 EXPECT_EQ(post_str.find("machineid="), string::npos); |
| 807 EXPECT_EQ(post_str.find("userid="), string::npos); |
| 808 } |
| 809 |
| 802 } // namespace chromeos_update_engine | 810 } // namespace chromeos_update_engine |
| OLD | NEW |