• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 //
2 // Copyright (C) 2014 The Android Open Source Project
3 //
4 // Licensed under the Apache License, Version 2.0 (the "License");
5 // you may not use this file except in compliance with the License.
6 // You may obtain a copy of the License at
7 //
8 //      http://www.apache.org/licenses/LICENSE-2.0
9 //
10 // Unless required by applicable law or agreed to in writing, software
11 // distributed under the License is distributed on an "AS IS" BASIS,
12 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 // See the License for the specific language governing permissions and
14 // limitations under the License.
15 //
16 
17 #include "update_engine/update_manager/real_system_provider.h"
18 
19 #include <memory>
20 
21 #include <base/time/time.h>
22 #include <brillo/make_unique_ptr.h>
23 #include <gmock/gmock.h>
24 #include <gtest/gtest.h>
25 
26 #include "update_engine/common/fake_boot_control.h"
27 #include "update_engine/common/fake_hardware.h"
28 #include "update_engine/update_manager/umtest_utils.h"
29 #if USE_LIBCROS
30 #include "libcros/dbus-proxies.h"
31 #include "libcros/dbus-proxy-mocks.h"
32 #include "update_engine/libcros_proxy.h"
33 
34 using org::chromium::LibCrosServiceInterfaceProxyMock;
35 #endif  // USE_LIBCROS
36 using std::unique_ptr;
37 using testing::_;
38 using testing::DoAll;
39 using testing::Return;
40 using testing::SetArgPointee;
41 
42 #if USE_LIBCROS
43 namespace {
44 const char kRequiredPlatformVersion[] ="1234.0.0";
45 }  // namespace
46 #endif  // USE_LIBCROS
47 
48 namespace chromeos_update_manager {
49 
50 class UmRealSystemProviderTest : public ::testing::Test {
51  protected:
SetUp()52   void SetUp() override {
53 #if USE_LIBCROS
54     service_interface_mock_ = new LibCrosServiceInterfaceProxyMock();
55     libcros_proxy_.reset(new chromeos_update_engine::LibCrosProxy(
56         brillo::make_unique_ptr(service_interface_mock_),
57         unique_ptr<
58             org::chromium::
59                 UpdateEngineLibcrosProxyResolvedInterfaceProxyInterface>()));
60     ON_CALL(*service_interface_mock_,
61             GetKioskAppRequiredPlatformVersion(_, _, _))
62         .WillByDefault(
63             DoAll(SetArgPointee<0>(kRequiredPlatformVersion), Return(true)));
64 
65     provider_.reset(new RealSystemProvider(
66         &fake_hardware_, &fake_boot_control_, libcros_proxy_.get()));
67 #else
68     provider_.reset(
69         new RealSystemProvider(&fake_hardware_, &fake_boot_control_, nullptr));
70 #endif  // USE_LIBCROS
71     EXPECT_TRUE(provider_->Init());
72   }
73 
74   chromeos_update_engine::FakeHardware fake_hardware_;
75   chromeos_update_engine::FakeBootControl fake_boot_control_;
76   unique_ptr<RealSystemProvider> provider_;
77 
78 #if USE_LIBCROS
79   // Local pointers to the mocks. The instances are owned by the
80   // |libcros_proxy_|.
81   LibCrosServiceInterfaceProxyMock* service_interface_mock_;
82 
83   unique_ptr<chromeos_update_engine::LibCrosProxy> libcros_proxy_;
84 #endif  // USE_LIBCROS
85 };
86 
TEST_F(UmRealSystemProviderTest,InitTest)87 TEST_F(UmRealSystemProviderTest, InitTest) {
88   EXPECT_NE(nullptr, provider_->var_is_normal_boot_mode());
89   EXPECT_NE(nullptr, provider_->var_is_official_build());
90   EXPECT_NE(nullptr, provider_->var_is_oobe_complete());
91   EXPECT_NE(nullptr, provider_->var_kiosk_required_platform_version());
92 }
93 
TEST_F(UmRealSystemProviderTest,IsOOBECompleteTrue)94 TEST_F(UmRealSystemProviderTest, IsOOBECompleteTrue) {
95   fake_hardware_.SetIsOOBEComplete(base::Time());
96   UmTestUtils::ExpectVariableHasValue(true, provider_->var_is_oobe_complete());
97 }
98 
TEST_F(UmRealSystemProviderTest,IsOOBECompleteFalse)99 TEST_F(UmRealSystemProviderTest, IsOOBECompleteFalse) {
100   fake_hardware_.UnsetIsOOBEComplete();
101   UmTestUtils::ExpectVariableHasValue(false, provider_->var_is_oobe_complete());
102 }
103 
104 #if USE_LIBCROS
TEST_F(UmRealSystemProviderTest,KioskRequiredPlatformVersion)105 TEST_F(UmRealSystemProviderTest, KioskRequiredPlatformVersion) {
106   UmTestUtils::ExpectVariableHasValue(
107       std::string(kRequiredPlatformVersion),
108       provider_->var_kiosk_required_platform_version());
109 }
110 
TEST_F(UmRealSystemProviderTest,KioskRequiredPlatformVersionFailure)111 TEST_F(UmRealSystemProviderTest, KioskRequiredPlatformVersionFailure) {
112   EXPECT_CALL(*service_interface_mock_,
113               GetKioskAppRequiredPlatformVersion(_, _, _))
114       .WillOnce(Return(false));
115 
116   UmTestUtils::ExpectVariableNotSet(
117       provider_->var_kiosk_required_platform_version());
118 }
119 
TEST_F(UmRealSystemProviderTest,KioskRequiredPlatformVersionRecoveryFromFailure)120 TEST_F(UmRealSystemProviderTest,
121        KioskRequiredPlatformVersionRecoveryFromFailure) {
122   EXPECT_CALL(*service_interface_mock_,
123               GetKioskAppRequiredPlatformVersion(_, _, _))
124       .WillOnce(Return(false));
125   UmTestUtils::ExpectVariableNotSet(
126       provider_->var_kiosk_required_platform_version());
127   testing::Mock::VerifyAndClearExpectations(service_interface_mock_);
128 
129   EXPECT_CALL(*service_interface_mock_,
130               GetKioskAppRequiredPlatformVersion(_, _, _))
131       .WillOnce(
132           DoAll(SetArgPointee<0>(kRequiredPlatformVersion), Return(true)));
133   UmTestUtils::ExpectVariableHasValue(
134       std::string(kRequiredPlatformVersion),
135       provider_->var_kiosk_required_platform_version());
136 }
137 #else
TEST_F(UmRealSystemProviderTest,KioskRequiredPlatformVersion)138 TEST_F(UmRealSystemProviderTest, KioskRequiredPlatformVersion) {
139   UmTestUtils::ExpectVariableHasValue(
140       std::string(), provider_->var_kiosk_required_platform_version());
141 }
142 #endif
143 
144 }  // namespace chromeos_update_manager
145