• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2023 Huawei Device Co., Ltd.
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at
6  *
7  *     http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14  */
15 
16 #include <gtest/gtest.h>
17 #include "interfaces/include/ws_common.h"
18 #include "session_manager/include/scene_session_manager.h"
19 #include "session_info.h"
20 #include "session/host/include/scene_session.h"
21 #include "window_manager_agent.h"
22 #include "session_manager.h"
23 #include "session_display_power_controller.h"
24 #include "zidl/window_manager_agent_interface.h"
25 #include "screen_session_manager/include/screen_session_manager.h"
26 
27 using namespace testing;
28 using namespace testing::ext;
29 
30 namespace OHOS {
31 namespace Rosen {
32 class SessionDisplayPowerControllerTest : public testing::Test {
33 public:
34     static void SetUpTestCase();
35     static void TearDownTestCase();
36     void SetUp() override;
37     void TearDown() override;
38 };
39 
SetUpTestCase()40 void SessionDisplayPowerControllerTest::SetUpTestCase()
41 {
42 }
43 
TearDownTestCase()44 void SessionDisplayPowerControllerTest::TearDownTestCase()
45 {
46 }
47 
SetUp()48 void SessionDisplayPowerControllerTest::SetUp()
49 {
50 }
51 
TearDown()52 void SessionDisplayPowerControllerTest::TearDown()
53 {
54 }
55 
56 namespace {
57 
58 /**
59  * @tc.name: NotifyDisplayEvent
60  * @tc.desc: NotifyDisplayEvent_Unlock func
61  * @tc.type: FUNC
62  */
63 HWTEST_F(SessionDisplayPowerControllerTest, NotifyDisplayEvent_Unlock, Function | SmallTest | Level1)
64 {
65     DisplayEvent event = DisplayEvent::UNLOCK;
66     SessionDisplayPowerController controller([](DisplayId id, sptr<DisplayInfo> info, const std::map<DisplayId,
__anon08c07c440202(DisplayId id, sptr<DisplayInfo> info, const std::map<DisplayId, sptr<DisplayInfo>>& infos, DisplayStateChangeType type) 67         sptr<DisplayInfo>>& infos, DisplayStateChangeType type) {
68         EXPECT_EQ(id, DISPLAY_ID_INVALID);
69         EXPECT_EQ(info, nullptr);
70         EXPECT_TRUE(infos.empty());
71         EXPECT_EQ(type, DisplayStateChangeType::BEFORE_UNLOCK);
72     });
73     controller.NotifyDisplayEvent(event);
74 }
75 
76 /**
77  * @tc.name: NotifyDisplayEvent
78  * @tc.desc: NotifyDisplayEvent_KeyguardDrawn func
79  * @tc.type: FUNC
80  */
81     HWTEST_F(SessionDisplayPowerControllerTest, NotifyDisplayEvent_KeyguardDrawn, Function | SmallTest | Level1)
82     {
83         DisplayEvent event = DisplayEvent::KEYGUARD_DRAWN;
84         SessionDisplayPowerController controller([](DisplayId id, sptr<DisplayInfo> info, const std::map<DisplayId,
__anon08c07c440302(DisplayId id, sptr<DisplayInfo> info, const std::map<DisplayId, sptr<DisplayInfo>>& infos, DisplayStateChangeType type) 85         sptr<DisplayInfo>>& infos, DisplayStateChangeType type) {
86         EXPECT_TRUE(true);
87     });
88     controller.NotifyDisplayEvent(event);
89 }
90 
91 /**
92  * @tc.name: SetDisplayState
93  * @tc.desc: SetDisplayState func
94  * @tc.type: FUNC
95  */
96 HWTEST_F(SessionDisplayPowerControllerTest, SetDisplayState, Function | SmallTest | Level1)
97 {
98     DisplayState state = DisplayState::UNKNOWN;
99     SessionDisplayPowerController controller([](DisplayId id, sptr<DisplayInfo> info, const std::map<DisplayId,
__anon08c07c440402(DisplayId id, sptr<DisplayInfo> info, const std::map<DisplayId, sptr<DisplayInfo>>& infos, DisplayStateChangeType type) 100         sptr<DisplayInfo>>& infos, DisplayStateChangeType type) {
101         EXPECT_TRUE(true);
102     });
103     bool result = controller.SetDisplayState(state);
104     EXPECT_FALSE(result);
105     state = DisplayState::ON;
106     result = controller.SetDisplayState(state);
107     EXPECT_TRUE(result);
108     state = DisplayState::OFF;
109     result = controller.SetDisplayState(state);
110     EXPECT_TRUE(result);
111     state = DisplayState::DOZE;
112     result = controller.SetDisplayState(state);
113     EXPECT_TRUE(result);
114     state = DisplayState::DOZE_SUSPEND;
115     result = controller.SetDisplayState(state);
116     EXPECT_TRUE(result);
117 }
118 
119 /**
120  * @tc.name: HandleSetDisplayStateOff
121  * @tc.desc: HandleSetDisplayStateOff func
122  * @tc.type: FUNC
123  */
124 HWTEST_F(SessionDisplayPowerControllerTest, HandleSetDisplayStateOff, Function | SmallTest | Level1)
125 {
126     DisplayState state = DisplayState::UNKNOWN;
127     SessionDisplayPowerController controller([](DisplayId id, sptr<DisplayInfo> info, const std::map<DisplayId,
__anon08c07c440502(DisplayId id, sptr<DisplayInfo> info, const std::map<DisplayId, sptr<DisplayInfo>>& infos, DisplayStateChangeType type) 128         sptr<DisplayInfo>>& infos, DisplayStateChangeType type) {
129         EXPECT_TRUE(true);
130     });
131     state = DisplayState::OFF;
132     bool result = controller.HandleSetDisplayStateOff(state);
133     EXPECT_FALSE(result);
134     controller.needCancelNotify_ = true;
135     result = controller.HandleSetDisplayStateOff(state);
136     EXPECT_TRUE(result);
137     controller.needCancelNotify_ = false;
138     controller.canceledSuspend_ = true;
139     result = controller.HandleSetDisplayStateOff(state);
140     EXPECT_TRUE(result);
141     controller.isSuspendBegin_ = true;
142     controller.canceledSuspend_ = false;
143     result = controller.HandleSetDisplayStateOff(state);
144     EXPECT_FALSE(result);
145 }
146 
147 /**
148  * @tc.name: SuspendBegin
149  * @tc.desc: SuspendBegin func
150  * @tc.type: FUNC
151  */
152 HWTEST_F(SessionDisplayPowerControllerTest, SuspendBegin, Function | SmallTest | Level1)
153 {
154     PowerStateChangeReason reason = PowerStateChangeReason::POWER_BUTTON;
155     SessionDisplayPowerController controller([](DisplayId id, sptr<DisplayInfo> info, const std::map<DisplayId,
__anon08c07c440602(DisplayId id, sptr<DisplayInfo> info, const std::map<DisplayId, sptr<DisplayInfo>>& infos, DisplayStateChangeType type) 156         sptr<DisplayInfo>>& infos, DisplayStateChangeType type) {
157         EXPECT_TRUE(true);
158     });
159     EXPECT_TRUE(controller.SuspendBegin(reason));
160 }
161 
162 /**
163  * @tc.name: WaitScreenOffNotify
164  * @tc.desc: WaitScreenOffNotify func
165  * @tc.type: FUNC
166  */
167 HWTEST_F(SessionDisplayPowerControllerTest, WaitScreenOffNotify, Function | SmallTest | Level1)
168 {
169     DisplayState state = DisplayState::ON_SUSPEND;
170     ScreenSessionManager::GetInstance().sessionDisplayPowerController_->WaitScreenOffNotify(state);
171     EXPECT_NE(state, DisplayState::UNKNOWN);
172 }
173 
174 }
175 } // namespace Rosen
176 } // namespace OHOS
177 
178