123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187 |
- #include "update_engine/common_service.h"
- #include <gtest/gtest.h>
- #include <string>
- #include <vector>
- #include <brillo/errors/error.h>
- #include <policy/libpolicy.h>
- #include <policy/mock_device_policy.h>
- #include "update_engine/common/fake_prefs.h"
- #include "update_engine/fake_system_state.h"
- #include "update_engine/omaha_utils.h"
- using std::string;
- using std::vector;
- using testing::_;
- using testing::Return;
- using testing::SetArgPointee;
- using update_engine::UpdateAttemptFlags;
- namespace chromeos_update_engine {
- class UpdateEngineServiceTest : public ::testing::Test {
- protected:
- UpdateEngineServiceTest()
- : mock_update_attempter_(fake_system_state_.mock_update_attempter()),
- common_service_(&fake_system_state_) {}
- void SetUp() override { fake_system_state_.set_device_policy(nullptr); }
-
- FakeSystemState fake_system_state_;
- policy::MockDevicePolicy mock_device_policy_;
-
- MockUpdateAttempter* mock_update_attempter_;
- brillo::ErrorPtr error_;
- UpdateEngineService common_service_;
- };
- TEST_F(UpdateEngineServiceTest, AttemptUpdate) {
- EXPECT_CALL(
- *mock_update_attempter_,
- CheckForUpdate("app_ver", "url", UpdateAttemptFlags::kFlagNonInteractive))
- .WillOnce(Return(true));
-
- bool result = false;
- EXPECT_TRUE(
- common_service_.AttemptUpdate(&error_,
- "app_ver",
- "url",
- UpdateAttemptFlags::kFlagNonInteractive,
- &result));
- EXPECT_EQ(nullptr, error_);
- EXPECT_TRUE(result);
- }
- TEST_F(UpdateEngineServiceTest, AttemptUpdateReturnsFalse) {
- EXPECT_CALL(*mock_update_attempter_,
- CheckForUpdate("app_ver", "url", UpdateAttemptFlags::kNone))
- .WillOnce(Return(false));
- bool result = true;
- EXPECT_TRUE(common_service_.AttemptUpdate(
- &error_, "app_ver", "url", UpdateAttemptFlags::kNone, &result));
- EXPECT_EQ(nullptr, error_);
- EXPECT_FALSE(result);
- }
- TEST_F(UpdateEngineServiceTest, AttemptInstall) {
- EXPECT_CALL(*mock_update_attempter_, CheckForInstall(_, _))
- .WillOnce(Return(true));
- EXPECT_TRUE(common_service_.AttemptInstall(&error_, "", {}));
- EXPECT_EQ(nullptr, error_);
- }
- TEST_F(UpdateEngineServiceTest, AttemptInstallReturnsFalse) {
- EXPECT_CALL(*mock_update_attempter_, CheckForInstall(_, _))
- .WillOnce(Return(false));
- EXPECT_FALSE(common_service_.AttemptInstall(&error_, "", {}));
- }
- TEST_F(UpdateEngineServiceTest, SetChannelWithNoPolicy) {
- EXPECT_CALL(*mock_update_attempter_, RefreshDevicePolicy());
-
- EXPECT_CALL(*fake_system_state_.mock_request_params(),
- SetTargetChannel("stable-channel", true, _))
- .WillOnce(Return(true));
- EXPECT_TRUE(common_service_.SetChannel(&error_, "stable-channel", true));
- ASSERT_EQ(nullptr, error_);
- }
- TEST_F(UpdateEngineServiceTest, SetChannelWithDelegatedPolicy) {
- policy::MockDevicePolicy mock_device_policy;
- fake_system_state_.set_device_policy(&mock_device_policy);
- EXPECT_CALL(mock_device_policy, GetReleaseChannelDelegated(_))
- .WillOnce(DoAll(SetArgPointee<0>(true), Return(true)));
- EXPECT_CALL(*fake_system_state_.mock_request_params(),
- SetTargetChannel("beta-channel", true, _))
- .WillOnce(Return(true));
- EXPECT_TRUE(common_service_.SetChannel(&error_, "beta-channel", true));
- ASSERT_EQ(nullptr, error_);
- }
- TEST_F(UpdateEngineServiceTest, SetChannelWithInvalidChannel) {
- EXPECT_CALL(*mock_update_attempter_, RefreshDevicePolicy());
- EXPECT_CALL(*fake_system_state_.mock_request_params(),
- SetTargetChannel("foo-channel", true, _))
- .WillOnce(Return(false));
- EXPECT_FALSE(common_service_.SetChannel(&error_, "foo-channel", true));
- ASSERT_NE(nullptr, error_);
- EXPECT_TRUE(error_->HasError(UpdateEngineService::kErrorDomain,
- UpdateEngineService::kErrorFailed));
- }
- TEST_F(UpdateEngineServiceTest, GetChannel) {
- fake_system_state_.mock_request_params()->set_current_channel("current");
- fake_system_state_.mock_request_params()->set_target_channel("target");
- string channel;
- EXPECT_TRUE(common_service_.GetChannel(
- &error_, true , &channel));
- EXPECT_EQ(nullptr, error_);
- EXPECT_EQ("current", channel);
- EXPECT_TRUE(common_service_.GetChannel(
- &error_, false , &channel));
- EXPECT_EQ(nullptr, error_);
- EXPECT_EQ("target", channel);
- }
- TEST_F(UpdateEngineServiceTest, ResetStatusSucceeds) {
- EXPECT_CALL(*mock_update_attempter_, ResetStatus()).WillOnce(Return(true));
- EXPECT_TRUE(common_service_.ResetStatus(&error_));
- EXPECT_EQ(nullptr, error_);
- }
- TEST_F(UpdateEngineServiceTest, ResetStatusFails) {
- EXPECT_CALL(*mock_update_attempter_, ResetStatus()).WillOnce(Return(false));
- EXPECT_FALSE(common_service_.ResetStatus(&error_));
- ASSERT_NE(nullptr, error_);
- EXPECT_TRUE(error_->HasError(UpdateEngineService::kErrorDomain,
- UpdateEngineService::kErrorFailed));
- }
- TEST_F(UpdateEngineServiceTest, GetEolStatusTest) {
- FakePrefs fake_prefs;
- fake_system_state_.set_prefs(&fake_prefs);
-
- int32_t eol_status = static_cast<int32_t>(EolStatus::kEol);
- EXPECT_TRUE(common_service_.GetEolStatus(&error_, &eol_status));
- EXPECT_EQ(nullptr, error_);
- EXPECT_EQ(EolStatus::kSupported, static_cast<EolStatus>(eol_status));
- fake_prefs.SetString(kPrefsOmahaEolStatus, "security-only");
- EXPECT_TRUE(common_service_.GetEolStatus(&error_, &eol_status));
- EXPECT_EQ(nullptr, error_);
- EXPECT_EQ(EolStatus::kSecurityOnly, static_cast<EolStatus>(eol_status));
- }
- }
|