1 /*
2 * Copyright (c) 2022-2022 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 "common_test_utils.h"
18 #include "iremote_object_mocker.h"
19 #include "mock_RSIWindowAnimationController.h"
20 #include "window_manager_service.h"
21
22 #include <thread>
23
24 #include <ability_manager_client.h>
25 #include <cinttypes>
26 #include <chrono>
27 #include <hisysevent.h>
28 #include <hitrace_meter.h>
29 #include <ipc_skeleton.h>
30 #include <parameters.h>
31 #include <rs_iwindow_animation_controller.h>
32 #include <system_ability_definition.h>
33 #include <sstream>
34 #include "xcollie/watchdog.h"
35
36 #include "color_parser.h"
37 #include "display_manager_service_inner.h"
38 #include "dm_common.h"
39 #include "drag_controller.h"
40 #include "minimize_app.h"
41 #include "permission.h"
42 #include "remote_animation.h"
43 #include "singleton_container.h"
44 #include "ui/rs_ui_director.h"
45 #include "window_helper.h"
46 #include "window_inner_manager.h"
47 #include "window_manager_agent_controller.h"
48 #include "window_manager_hilog.h"
49 #include "wm_common.h"
50 #include "wm_math.h"
51
52
53 using namespace testing;
54 using namespace testing::ext;
55 namespace OHOS {
56 namespace Rosen {
57 class WindowManagerServiceTest : public testing::Test {
58 public:
59 static void SetUpTestCase();
60 static void TearDownTestCase();
61 void SetUp() override;
62 void TearDown() override;
63
64 void SetAceessTokenPermission(const std::string processName);
65 sptr<WindowManagerService> wms = new WindowManagerService();
66 };
67
SetUpTestCase()68 void WindowManagerServiceTest::SetUpTestCase()
69 {
70 }
71
TearDownTestCase()72 void WindowManagerServiceTest::TearDownTestCase()
73 {
74 }
75
SetUp()76 void WindowManagerServiceTest::SetUp()
77 {
78 CommonTestUtils::SetAceessTokenPermission("WindowManagerServiceTest");
79 }
80
TearDown()81 void WindowManagerServiceTest::TearDown()
82 {
83 }
84
85 namespace {
86 /**
87 * @tc.name: OnAddSystemAbility
88 * @tc.desc: OnAddSystemAbility test
89 * @tc.type: FUNC
90 */
91 HWTEST_F(WindowManagerServiceTest, OnAddSystemAbility01, Function | SmallTest | Level2)
92 {
93 std::string str = "OnAddSystemAbility";
94 wms->OnAddSystemAbility(0, str);
95 ASSERT_EQ(nullptr, wms->windowCommonEvent_->subscriber_);
96 }
97 /**
98 * @tc.name: WindowVisibilityChangeCallback
99 * @tc.desc: WindowVisibilityChangeCallback test
100 * @tc.type: FUNC
101 */
102 HWTEST_F(WindowManagerServiceTest, WindowVisibilityChangeCallback01, Function | SmallTest | Level2)
103 {
104 std::shared_ptr<RSOcclusionData> occlusionData = nullptr;
105 wms->WindowVisibilityChangeCallback(occlusionData);
106 ASSERT_EQ(nullptr, occlusionData);
107 }
108 /**
109 * @tc.name: InitWithAbilityManagerServiceAdded
110 * @tc.desc: Init with ability manager service added.
111 * @tc.type: FUNC
112 */
113 HWTEST_F(WindowManagerServiceTest, InitWithAbilityManagerServiceAdded01, Function | SmallTest | Level2)
114 {
115 wms->wmsHandler_ = new WindowManagerServiceHandler;
116 wms->InitWithAbilityManagerServiceAdded();
117 ASSERT_NE(nullptr, wms->wmsHandler_);
118 }
119 /**
120 * @tc.name: Dump
121 * @tc.desc: Dump info
122 * @tc.type: FUNC
123 */
124 HWTEST_F(WindowManagerServiceTest, Dump01, Function | SmallTest | Level2)
125 {
126 wms->windowDumper_ = nullptr;
127 std::vector<std::u16string> args;
128 ASSERT_EQ(static_cast<int>(WMError::WM_ERROR_INVALID_PARAM), wms->Dump(-1, args));
129 ASSERT_EQ(static_cast<int>(WMError::WM_OK), wms->Dump(0, args));
130 }
131 /**
132 * @tc.name: NotifyWindowTransition
133 * @tc.desc: NotifyWindowTransition test
134 * @tc.type: FUNC
135 */
136 HWTEST_F(WindowManagerServiceTest, NotifyWindowTransition01, Function | SmallTest | Level2)
137 {
138 sptr<WindowTransitionInfo> fromInfo = nullptr;
139 sptr<WindowTransitionInfo> toInfo = nullptr;
140 ASSERT_EQ(WMError::WM_OK, wms->NotifyWindowTransition(fromInfo, toInfo, false));
141 ASSERT_EQ(WMError::WM_ERROR_NO_REMOTE_ANIMATION, wms->NotifyWindowTransition(fromInfo, toInfo, true));
142 }
143 /**
144 * @tc.name: StartingWindow
145 * @tc.desc: StartingWindow test
146 * @tc.type: FUNC
147 */
148 HWTEST_F(WindowManagerServiceTest, StartingWindow01, Function | SmallTest | Level2)
149 {
150 wms->startingOpen_ = false;
151 wms->StartingWindow(nullptr, nullptr, false, 0);
152 ASSERT_EQ(false, wms->startingOpen_);
153 wms->CancelStartingWindow(nullptr);
154 wms->startingOpen_ = true;
155 wms->StartingWindow(nullptr, nullptr, false, 0);
156 ASSERT_EQ(true, wms->startingOpen_);
157 wms->CancelStartingWindow(nullptr);
158 }
159 /**
160 * @tc.name: CreateWindow
161 * @tc.desc: CreateWindow test
162 * @tc.type: FUNC
163 */
164 HWTEST_F(WindowManagerServiceTest, CreateWindow01, Function | SmallTest | Level2)
165 {
166 sptr<IWindow> window = nullptr;
167 uint32_t id = 2;
168 std::shared_ptr<RSSurfaceNode> RS_node = nullptr;
169 sptr<WindowProperty> property = new WindowProperty();
170 property->SetWindowType(WindowType::WINDOW_TYPE_WALLPAPER);
171 ASSERT_EQ(WMError::WM_ERROR_NULLPTR, wms->CreateWindow(window, property, RS_node, id, nullptr));
172 wms->DestroyWindow(id, true);
173 }
174 /**
175 * @tc.name: AddWindow
176 * @tc.desc: AddWindow test
177 * @tc.type: FUNC
178 */
179 HWTEST_F(WindowManagerServiceTest, AddWindow01, Function | SmallTest | Level2)
180 {
181 sptr<WindowProperty> property = nullptr;
182 ASSERT_EQ(WMError::WM_ERROR_NULLPTR, wms->AddWindow(property));
183 }
184 /**
185 * @tc.name: RegisterWindowManagerAgent
186 * @tc.desc: RegisterWindowManagerAgent test
187 * @tc.type: FUNC
188 */
189 HWTEST_F(WindowManagerServiceTest, RegisterWindowManagerAgent01, Function | SmallTest | Level2)
190 {
191 sptr<IWindowManagerAgent> windowManagerAgent = nullptr;
192 WindowManagerAgentType type = WindowManagerAgentType::WINDOW_MANAGER_AGENT_TYPE_CAMERA_FLOAT;
193 ASSERT_EQ(false, wms->RegisterWindowManagerAgent(type, windowManagerAgent));
194 ASSERT_EQ(false, wms->UnregisterWindowManagerAgent(type, windowManagerAgent));
195 }
196 /**
197 * @tc.name: SetWindowAnimationController
198 * @tc.desc: SetWindowAnimationController test
199 * @tc.type: FUNC
200 */
201 HWTEST_F(WindowManagerServiceTest, SetWindowAnimationController01, Function | SmallTest | Level2)
202 {
203 sptr<RSIWindowAnimationController> controller = nullptr;
204 ASSERT_EQ(WMError::WM_ERROR_NULLPTR, wms->SetWindowAnimationController(controller));
205 controller = new RSIWindowAnimationControllerMocker;
206 ASSERT_EQ(WMError::WM_OK, wms->SetWindowAnimationController(controller));
207 }
208 /**
209 * @tc.name: OnWindowEvent
210 * @tc.desc: OnWindowEvent test
211 * @tc.type: FUNC
212 */
213 HWTEST_F(WindowManagerServiceTest, OnWindowEvent01, Function | SmallTest | Level2)
214 {
215 sptr<IRemoteObject> remoteObject = new IRemoteObjectMocker;
216 wms->OnWindowEvent(static_cast<Event>(1), remoteObject);
217 wms->OnWindowEvent(Event::REMOTE_DIED, remoteObject);
218 ASSERT_EQ(INVALID_WINDOW_ID, wms->windowRoot_->GetWindowIdByObject(remoteObject));
219 }
220 /**
221 * @tc.name: UpdateProperty
222 * @tc.desc: UpdateProperty test
223 * @tc.type: FUNC
224 */
225 HWTEST_F(WindowManagerServiceTest, UpdateProperty01, Function | SmallTest | Level2)
226 {
227 sptr<WindowProperty> windowProperty = nullptr;
228 ASSERT_EQ(WMError::WM_ERROR_NULLPTR, wms->UpdateProperty(windowProperty,
229 PropertyChangeAction::ACTION_UPDATE_ANIMATION_FLAG, true));
230 }
231 /**
232 * @tc.name: GetModeChangeHotZones
233 * @tc.desc: GetModeChangeHotZones test
234 * @tc.type: FUNC
235 */
236 HWTEST_F(WindowManagerServiceTest, GetModeChangeHotZones01, Function | SmallTest | Level2)
237 {
238 ModeChangeHotZonesConfig config = {false, 0, 0, 0};
239 DisplayId displayId = 0;
240 ModeChangeHotZones hotZone;
241 wms->hotZonesConfig_ = config;
242 ASSERT_EQ(WMError::WM_DO_NOTHING, wms->GetModeChangeHotZones(displayId, hotZone));
243 config.isModeChangeHotZoneConfigured_ = true;
244 wms->hotZonesConfig_ = config;
245 ASSERT_EQ(WMError::WM_ERROR_NULLPTR, wms->GetModeChangeHotZones(displayId, hotZone));
246 }
247 /**
248 * @tc.name: UpdateAvoidAreaListener
249 * @tc.desc: UpdateAvoidAreaListener test
250 * @tc.type: FUNC
251 */
252 HWTEST_F(WindowManagerServiceTest, UpdateAvoidAreaListener01, Function | SmallTest | Level2)
253 {
254 sptr<WindowProperty> property = new WindowProperty();
255 sptr<WindowNode> node = new WindowNode(property);
256 wms->windowRoot_->windowNodeMap_.insert(std::make_pair(0, node));
257 ASSERT_EQ(WMError::WM_DO_NOTHING, wms->UpdateAvoidAreaListener(0, true));
258 }
259 /**
260 * @tc.name: BindDialogTarget
261 * @tc.desc: BindDialogTarget test
262 * @tc.type: FUNC
263 */
264 HWTEST_F(WindowManagerServiceTest, BindDialogTarget01, Function | SmallTest | Level2)
265 {
266 sptr<IRemoteObject> targetToken = new IRemoteObjectMocker();
267 uint32_t id = 0;
268 ASSERT_EQ(WMError::WM_ERROR_NULLPTR, wms->BindDialogTarget(id, targetToken));
269 }
270 }
271 }
272 }
273