• 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 
26 using namespace testing;
27 using namespace testing::ext;
28 
29 namespace OHOS {
30 namespace Rosen {
31 class SessionDisplayPowerControllerTest : public testing::Test {
32 public:
33     static void SetUpTestCase();
34     static void TearDownTestCase();
35     void SetUp() override;
36     void TearDown() override;
37 };
38 
SetUpTestCase()39 void SessionDisplayPowerControllerTest::SetUpTestCase()
40 {
41 }
42 
TearDownTestCase()43 void SessionDisplayPowerControllerTest::TearDownTestCase()
44 {
45 }
46 
SetUp()47 void SessionDisplayPowerControllerTest::SetUp()
48 {
49 }
50 
TearDown()51 void SessionDisplayPowerControllerTest::TearDown()
52 {
53 }
54 
55 namespace {
56 
57 /**
58  * @tc.name: NotifyDisplayEvent
59  * @tc.desc: NotifyDisplayEvent_Unlock func
60  * @tc.type: FUNC
61  */
62 HWTEST_F(SessionDisplayPowerControllerTest, NotifyDisplayEvent_Unlock, Function | SmallTest | Level1)
63 {
64     DisplayEvent event = DisplayEvent::UNLOCK;
65     SessionDisplayPowerController controller([](DisplayId id, sptr<DisplayInfo> info, const std::map<DisplayId,
__anon27979a450202(DisplayId id, sptr<DisplayInfo> info, const std::map<DisplayId, sptr<DisplayInfo>>& infos, DisplayStateChangeType type) 66         sptr<DisplayInfo>>& infos, DisplayStateChangeType type) {
67         EXPECT_EQ(id, DISPLAY_ID_INVALID);
68         EXPECT_EQ(info, nullptr);
69         EXPECT_TRUE(infos.empty());
70         EXPECT_EQ(type, DisplayStateChangeType::BEFORE_UNLOCK);
71     });
72     controller.NotifyDisplayEvent(event);
73 }
74 
75 /**
76  * @tc.name: NotifyDisplayEvent
77  * @tc.desc: NotifyDisplayEvent_KeyguardDrawn func
78  * @tc.type: FUNC
79  */
80     HWTEST_F(SessionDisplayPowerControllerTest, NotifyDisplayEvent_KeyguardDrawn, Function | SmallTest | Level1)
81     {
82         DisplayEvent event = DisplayEvent::KEYGUARD_DRAWN;
83         SessionDisplayPowerController controller([](DisplayId id, sptr<DisplayInfo> info, const std::map<DisplayId,
__anon27979a450302(DisplayId id, sptr<DisplayInfo> info, const std::map<DisplayId, sptr<DisplayInfo>>& infos, DisplayStateChangeType type) 84         sptr<DisplayInfo>>& infos, DisplayStateChangeType type) {
85         EXPECT_TRUE(true);
86     });
87     controller.NotifyDisplayEvent(event);
88 }
89 /**
90  * @tc.name: SetDisplayState
91  * @tc.desc: SetDisplayState func
92  * @tc.type: FUNC
93  */
94 HWTEST_F(SessionDisplayPowerControllerTest, SetDisplayState, Function | SmallTest | Level1)
95 {
96     DisplayState state = DisplayState::UNKNOWN;
97     SessionDisplayPowerController controller([](DisplayId id, sptr<DisplayInfo> info, const std::map<DisplayId,
__anon27979a450402(DisplayId id, sptr<DisplayInfo> info, const std::map<DisplayId, sptr<DisplayInfo>>& infos, DisplayStateChangeType type) 98         sptr<DisplayInfo>>& infos, DisplayStateChangeType type) {
99         EXPECT_TRUE(true);
100     });
101     bool result = controller.SetDisplayState(state);
102     EXPECT_FALSE(result);
103     state = DisplayState::ON;
104     result = controller.SetDisplayState(state);
105     EXPECT_TRUE(result);
106     state = DisplayState::OFF;
107     result = controller.SetDisplayState(state);
108     EXPECT_TRUE(result);
109 }
110 
111 /**
112  * @tc.name: SuspendBegin
113  * @tc.desc: SuspendBegin func
114  * @tc.type: FUNC
115  */
116 HWTEST_F(SessionDisplayPowerControllerTest, SuspendBegin, Function | SmallTest | Level1)
117 {
118     PowerStateChangeReason reason = PowerStateChangeReason::POWER_BUTTON;
119     SessionDisplayPowerController controller([](DisplayId id, sptr<DisplayInfo> info, const std::map<DisplayId,
__anon27979a450502(DisplayId id, sptr<DisplayInfo> info, const std::map<DisplayId, sptr<DisplayInfo>>& infos, DisplayStateChangeType type) 120         sptr<DisplayInfo>>& infos, DisplayStateChangeType type) {
121         EXPECT_TRUE(true);
122     });
123     EXPECT_TRUE(controller.SuspendBegin(reason));
124 }
125 
126 /**
127  * @tc.name: WaitScreenOffNotify
128  * @tc.desc: WaitScreenOffNotify func
129  * @tc.type: FUNC
130  */
131 HWTEST_F(SessionDisplayPowerControllerTest, WaitScreenOffNotify, Function | SmallTest | Level1)
132 {
133     DisplayState state = DisplayState::ON_SUSPEND;
134     SessionDisplayPowerController controller([](DisplayId id, sptr<DisplayInfo> info, const std::map<DisplayId,
__anon27979a450602(DisplayId id, sptr<DisplayInfo> info, const std::map<DisplayId, sptr<DisplayInfo>>& infos, DisplayStateChangeType type) 135         sptr<DisplayInfo>>& infos, DisplayStateChangeType type) {
136         EXPECT_TRUE(true);
137     });
138     EXPECT_EQ(state, DisplayState::ON_SUSPEND);
139 }
140 
141 }
142 } // namespace Rosen
143 } // namespace OHOS
144 
145