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