• 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 
33 using org::chromium::LibCrosServiceInterfaceProxyMock;
34 #endif  // USE_LIBCROS
35 using std::unique_ptr;
36 using testing::_;
37 using testing::DoAll;
38 using testing::Return;
39 using testing::SetArgPointee;
40 
41 #if USE_LIBCROS
42 namespace {
43 const char kRequiredPlatformVersion[] ="1234.0.0";
44 }  // namespace
45 #endif  // USE_LIBCROS
46 
47 namespace chromeos_update_manager {
48 
49 class UmRealSystemProviderTest : public ::testing::Test {
50  protected:
SetUp()51   void SetUp() override {
52 #if USE_LIBCROS
53     libcros_proxy_mock_.reset(new LibCrosServiceInterfaceProxyMock());
54     ON_CALL(*libcros_proxy_mock_,
55             GetKioskAppRequiredPlatformVersion(_, _, _))
56         .WillByDefault(
57             DoAll(SetArgPointee<0>(kRequiredPlatformVersion), Return(true)));
58 
59     provider_.reset(new RealSystemProvider(
60         &fake_hardware_, &fake_boot_control_, libcros_proxy_mock_.get()));
61 #else
62     provider_.reset(
63         new RealSystemProvider(&fake_hardware_, &fake_boot_control_, nullptr));
64 #endif  // USE_LIBCROS
65     EXPECT_TRUE(provider_->Init());
66   }
67 
68   chromeos_update_engine::FakeHardware fake_hardware_;
69   chromeos_update_engine::FakeBootControl fake_boot_control_;
70   unique_ptr<RealSystemProvider> provider_;
71 
72 #if USE_LIBCROS
73   unique_ptr<LibCrosServiceInterfaceProxyMock> libcros_proxy_mock_;
74 #endif  // USE_LIBCROS
75 };
76 
TEST_F(UmRealSystemProviderTest,InitTest)77 TEST_F(UmRealSystemProviderTest, InitTest) {
78   EXPECT_NE(nullptr, provider_->var_is_normal_boot_mode());
79   EXPECT_NE(nullptr, provider_->var_is_official_build());
80   EXPECT_NE(nullptr, provider_->var_is_oobe_complete());
81   EXPECT_NE(nullptr, provider_->var_kiosk_required_platform_version());
82 }
83 
TEST_F(UmRealSystemProviderTest,IsOOBECompleteTrue)84 TEST_F(UmRealSystemProviderTest, IsOOBECompleteTrue) {
85   fake_hardware_.SetIsOOBEComplete(base::Time());
86   UmTestUtils::ExpectVariableHasValue(true, provider_->var_is_oobe_complete());
87 }
88 
TEST_F(UmRealSystemProviderTest,IsOOBECompleteFalse)89 TEST_F(UmRealSystemProviderTest, IsOOBECompleteFalse) {
90   fake_hardware_.UnsetIsOOBEComplete();
91   UmTestUtils::ExpectVariableHasValue(false, provider_->var_is_oobe_complete());
92 }
93 
94 #if USE_LIBCROS
TEST_F(UmRealSystemProviderTest,KioskRequiredPlatformVersion)95 TEST_F(UmRealSystemProviderTest, KioskRequiredPlatformVersion) {
96   UmTestUtils::ExpectVariableHasValue(
97       std::string(kRequiredPlatformVersion),
98       provider_->var_kiosk_required_platform_version());
99 }
100 
TEST_F(UmRealSystemProviderTest,KioskRequiredPlatformVersionFailure)101 TEST_F(UmRealSystemProviderTest, KioskRequiredPlatformVersionFailure) {
102   EXPECT_CALL(*libcros_proxy_mock_,
103               GetKioskAppRequiredPlatformVersion(_, _, _))
104       .WillOnce(Return(false));
105 
106   UmTestUtils::ExpectVariableNotSet(
107       provider_->var_kiosk_required_platform_version());
108 }
109 
TEST_F(UmRealSystemProviderTest,KioskRequiredPlatformVersionRecoveryFromFailure)110 TEST_F(UmRealSystemProviderTest,
111        KioskRequiredPlatformVersionRecoveryFromFailure) {
112   EXPECT_CALL(*libcros_proxy_mock_,
113               GetKioskAppRequiredPlatformVersion(_, _, _))
114       .WillOnce(Return(false));
115   UmTestUtils::ExpectVariableNotSet(
116       provider_->var_kiosk_required_platform_version());
117   testing::Mock::VerifyAndClearExpectations(libcros_proxy_mock_.get());
118 
119   EXPECT_CALL(*libcros_proxy_mock_,
120               GetKioskAppRequiredPlatformVersion(_, _, _))
121       .WillOnce(
122           DoAll(SetArgPointee<0>(kRequiredPlatformVersion), Return(true)));
123   UmTestUtils::ExpectVariableHasValue(
124       std::string(kRequiredPlatformVersion),
125       provider_->var_kiosk_required_platform_version());
126 }
127 #else
TEST_F(UmRealSystemProviderTest,KioskRequiredPlatformVersion)128 TEST_F(UmRealSystemProviderTest, KioskRequiredPlatformVersion) {
129   UmTestUtils::ExpectVariableHasValue(
130       std::string(), provider_->var_kiosk_required_platform_version());
131 }
132 #endif
133 
134 }  // namespace chromeos_update_manager
135