• 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 "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,
__anonac644c860202(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,
__anonac644c860302(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  * @tc.name: SetDisplayState
92  * @tc.desc: SetDisplayState func
93  * @tc.type: FUNC
94  */
95 HWTEST_F(SessionDisplayPowerControllerTest, SetDisplayState, Function | SmallTest | Level1)
96 {
97     DisplayState state = DisplayState::UNKNOWN;
98     SessionDisplayPowerController controller([](DisplayId id, sptr<DisplayInfo> info, const std::map<DisplayId,
__anonac644c860402(DisplayId id, sptr<DisplayInfo> info, const std::map<DisplayId, sptr<DisplayInfo>>& infos, DisplayStateChangeType type) 99         sptr<DisplayInfo>>& infos, DisplayStateChangeType type) {
100         EXPECT_TRUE(true);
101     });
102     bool result = controller.SetDisplayState(state);
103     EXPECT_FALSE(result);
104     state = DisplayState::ON;
105     result = controller.SetDisplayState(state);
106     EXPECT_TRUE(result);
107     state = DisplayState::OFF;
108     result = controller.SetDisplayState(state);
109     EXPECT_TRUE(result);
110 }
111 
112 /**
113  * @tc.name: SuspendBegin
114  * @tc.desc: SuspendBegin func
115  * @tc.type: FUNC
116  */
117 HWTEST_F(SessionDisplayPowerControllerTest, SuspendBegin, Function | SmallTest | Level1)
118 {
119     PowerStateChangeReason reason = PowerStateChangeReason::POWER_BUTTON;
120     SessionDisplayPowerController controller([](DisplayId id, sptr<DisplayInfo> info, const std::map<DisplayId,
__anonac644c860502(DisplayId id, sptr<DisplayInfo> info, const std::map<DisplayId, sptr<DisplayInfo>>& infos, DisplayStateChangeType type) 121         sptr<DisplayInfo>>& infos, DisplayStateChangeType type) {
122         EXPECT_TRUE(true);
123     });
124     EXPECT_TRUE(controller.SuspendBegin(reason));
125 }
126 
127 /**
128  * @tc.name: WaitScreenOffNotify
129  * @tc.desc: WaitScreenOffNotify func
130  * @tc.type: FUNC
131  */
132 HWTEST_F(SessionDisplayPowerControllerTest, WaitScreenOffNotify, Function | SmallTest | Level1)
133 {
134     DisplayState state = DisplayState::ON_SUSPEND;
135     ScreenSessionManager::GetInstance().sessionDisplayPowerController_->WaitScreenOffNotify(state);
136     EXPECT_NE(state, DisplayState::UNKNOWN);
137 }
138 
139 }
140 } // namespace Rosen
141 } // namespace OHOS
142 
143