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