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 "window_manager_proxy.h"
18 #include "window_manager_stub_impl.h"
19 #include "iremote_object_mocker.h"
20 #include <rs_window_animation_target.h>
21
22 using namespace testing;
23 using namespace testing::ext;
24 namespace OHOS {
25 namespace Rosen {
26 class WindowManagerProxyTest : public testing::Test {
27 public:
28 static void SetUpTestCase();
29 static void TearDownTestCase();
30 void SetUp() override;
31 void TearDown() override;
32 sptr<WindowManagerStubImpl> mockWindowManagerStub_;
33 sptr<WindowManagerProxy> windowManagerProxy_;
34 };
35
SetUpTestCase()36 void WindowManagerProxyTest::SetUpTestCase()
37 {
38 }
39
TearDownTestCase()40 void WindowManagerProxyTest::TearDownTestCase()
41 {
42 }
43
SetUp()44 void WindowManagerProxyTest::SetUp()
45 {
46 mockWindowManagerStub_ = new WindowManagerStubImpl();
47 windowManagerProxy_ = new WindowManagerProxy(mockWindowManagerStub_);
48 }
49
TearDown()50 void WindowManagerProxyTest::TearDown()
51 {
52 }
53
54 namespace {
55 /**
56 * @tc.name: RequestFocus
57 * @tc.desc: test success
58 * @tc.type: FUNC
59 */
60 HWTEST_F(WindowManagerProxyTest, RequestFocus, Function | SmallTest | Level2)
61 {
62 uint32_t windowId = 0;
63 WMError err = windowManagerProxy_->RequestFocus(windowId);
64 ASSERT_EQ(err, WMError::WM_OK);
65 }
66
67 /**
68 * @tc.name: SetWindowAnimationController
69 * @tc.desc: test failed
70 * @tc.type: FUNC
71 */
72 HWTEST_F(WindowManagerProxyTest, SetWindowAnimationController, Function | SmallTest | Level2)
73 {
74 sptr<RSIWindowAnimationController> controller = nullptr;
75 WMError err = windowManagerProxy_->SetWindowAnimationController(controller);
76 ASSERT_EQ(err, WMError::WM_ERROR_IPC_FAILED);
77 }
78
79 /**
80 * @tc.name: SetWindowAnimationController01
81 * @tc.desc: test success
82 * @tc.type: FUNC
83 */
84 HWTEST_F(WindowManagerProxyTest, SetWindowAnimationController01, Function | SmallTest | Level2)
85 {
86 sptr<IRemoteObject> iRemoteObjectMocker = new IRemoteObjectMocker();
87 sptr<RSIWindowAnimationController> controller = iface_cast<RSIWindowAnimationController>(iRemoteObjectMocker);
88 WMError err = windowManagerProxy_->SetWindowAnimationController(controller);
89 ASSERT_EQ(err, WMError::WM_OK);
90 }
91
92 /**
93 * @tc.name: ToggleShownStateForAllAppWindows
94 * @tc.desc: test success
95 * @tc.type: FUNC
96 */
97 HWTEST_F(WindowManagerProxyTest, ToggleShownStateForAllAppWindows, Function | SmallTest | Level2)
98 {
99 WMError err = windowManagerProxy_->ToggleShownStateForAllAppWindows();
100 ASSERT_EQ(err, WMError::WM_OK);
101 }
102
103 /**
104 * @tc.name: GetTopWindowId
105 * @tc.desc: test success
106 * @tc.type: FUNC
107 */
108 HWTEST_F(WindowManagerProxyTest, GetTopWindowId, Function | SmallTest | Level2)
109 {
110 uint32_t mainWinId = 0;
111 uint32_t topWinId;
112 WMError err = windowManagerProxy_->GetTopWindowId(mainWinId, topWinId);
113 ASSERT_EQ(err, WMError::WM_OK);
114 }
115
116 /**
117 * @tc.name: NotifyWindowTransition
118 * @tc.desc: test success
119 * @tc.type: FUNC
120 */
121 HWTEST_F(WindowManagerProxyTest, NotifyWindowTransition, Function | SmallTest | Level2)
122 {
123 sptr<WindowTransitionInfo> from = new WindowTransitionInfo();
124 sptr<WindowTransitionInfo> to = new WindowTransitionInfo();
125 bool isFromClient = false;
126 WMError err = windowManagerProxy_->NotifyWindowTransition(from, to, isFromClient);
127 ASSERT_EQ(err, WMError::WM_OK);
128 }
129
130 /**
131 * @tc.name: GetModeChangeHotZones
132 * @tc.desc: test success
133 * @tc.type: FUNC
134 */
135 HWTEST_F(WindowManagerProxyTest, GetModeChangeHotZones, Function | SmallTest | Level2)
136 {
137 DisplayId displayId = 10;
138 ModeChangeHotZones hotZones;
139 WMError err = windowManagerProxy_->GetModeChangeHotZones(displayId, hotZones);
140 ASSERT_EQ(err, WMError::WM_OK);
141 }
142
143 /**
144 * @tc.name: MinimizeWindowsByLauncher
145 * @tc.desc: test success
146 * @tc.type: FUNC
147 */
148 HWTEST_F(WindowManagerProxyTest, MinimizeWindowsByLauncher, Function | SmallTest | Level2)
149 {
150 std::vector<uint32_t> windowIds;
151 bool isAnimated = false;
152 sptr<RSIWindowAnimationFinishedCallback> finishCallback;
153 windowManagerProxy_->MinimizeWindowsByLauncher(windowIds, isAnimated, finishCallback);
154 ASSERT_EQ(finishCallback, nullptr);
155 }
156
157 /**
158 * @tc.name: MinimizeWindowsByLauncher01
159 * @tc.desc: test success
160 * @tc.type: FUNC
161 */
162 HWTEST_F(WindowManagerProxyTest, MinimizeWindowsByLauncher01, Function | SmallTest | Level2)
163 {
164 std::vector<uint32_t> windowIds;
165 windowIds.push_back(0);
166 windowIds.push_back(1);
167 bool isAnimated = false;
168 sptr<RSIWindowAnimationFinishedCallback> finishCallback;
169 windowManagerProxy_->MinimizeWindowsByLauncher(windowIds, isAnimated, finishCallback);
170 ASSERT_EQ(finishCallback, nullptr);
171 }
172
173 /**
174 * @tc.name: UpdateRsTree
175 * @tc.desc: test success
176 * @tc.type: FUNC
177 */
178 HWTEST_F(WindowManagerProxyTest, UpdateRsTree, Function | SmallTest | Level2)
179 {
180 uint32_t windowId = 0;
181 bool isAdd = false;
182 WMError err = windowManagerProxy_->UpdateRsTree(windowId, isAdd);
183 ASSERT_EQ(err, WMError::WM_OK);
184 }
185
186 /**
187 * @tc.name: BindDialogTarget
188 * @tc.desc: test success
189 * @tc.type: FUNC
190 */
191 HWTEST_F(WindowManagerProxyTest, BindDialogTarget, Function | SmallTest | Level2)
192 {
193 uint32_t windowId = 0;
194 sptr<IRemoteObject> targetToken = nullptr;
195 WMError err = windowManagerProxy_->BindDialogTarget(windowId, targetToken);
196 ASSERT_EQ(err, WMError::WM_OK);
197 }
198
199 /**
200 * @tc.name: BindDialogTarget01
201 * @tc.desc: test success
202 * @tc.type: FUNC
203 */
204 HWTEST_F(WindowManagerProxyTest, BindDialogTarget01, Function | SmallTest | Level2)
205 {
206 uint32_t windowId = 0;
207 sptr<IRemoteObject> targetToken = nullptr;
208 WMError err = windowManagerProxy_->BindDialogTarget(windowId, targetToken);
209 ASSERT_EQ(err, WMError::WM_OK);
210 }
211
212 /**
213 * @tc.name: GetVisibilityWindowInfo01
214 * @tc.desc: test success
215 * @tc.type: FUNC
216 */
217 HWTEST_F(WindowManagerProxyTest, GetVisibilityWindowInfo01, Function | SmallTest | Level2)
218 {
219 std::vector<sptr<WindowVisibilityInfo>> infos;
220 WMError err = windowManagerProxy_->GetVisibilityWindowInfo(infos);
221 ASSERT_EQ(err, WMError::WM_OK);
222 }
223
224 /**
225 * @tc.name: GetWindowAnimationTargets01
226 * @tc.desc: test success
227 * @tc.type: FUNC
228 */
229 HWTEST_F(WindowManagerProxyTest, GetWindowAnimationTargets01, Function | SmallTest | Level2)
230 {
231 std::vector<uint32_t> missionIds;
232 missionIds.push_back(0);
233 missionIds.push_back(1);
234 std::vector<sptr<RSWindowAnimationTarget>> targets;
235 WMError err = windowManagerProxy_->GetWindowAnimationTargets(missionIds, targets);
236 ASSERT_EQ(err, WMError::WM_OK);
237 }
238 }
239 }
240 }
241