• 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 "session/container/include/zidl/window_event_channel_stub.h"
17 #include "session/container/include/zidl/session_stage_interface.h"
18 #include "session/container/include/zidl/window_event_ipc_interface_code.h"
19 #include "mock/mock_session_stage.h"
20 #include "mock/mock_window_event_channel.h"
21 #include "iremote_object_mocker.h"
22 #include <message_option.h>
23 #include <message_parcel.h>
24 #include <string>
25 #include <gtest/gtest.h>
26 #include <axis_event.h>
27 #include <ipc_types.h>
28 #include <key_event.h>
29 #include <pointer_event.h>
30 #include "session_manager/include/scene_session_manager.h"
31 #include "session_manager/include/zidl/scene_session_manager_interface.h"
32 #include "window_manager.h"
33 #include "window_manager_agent.h"
34 
35 using namespace testing;
36 using namespace testing::ext;
37 
38 namespace OHOS {
39 namespace Rosen {
40 namespace {
41 constexpr HiviewDFX::HiLogLabel LABEL = { LOG_CORE, HILOG_DOMAIN_WINDOW, "WindowEventChannelStubTest" };
42 }
43 class WindowEventChannelStubTest : public testing::Test {
44 public:
45     static void SetUpTestCase();
46     static void TearDownTestCase();
47     void SetUp() override;
48     void TearDown() override;
49 
50     sptr<ISessionStage> sessionStage = sptr<SessionStageMocker>::MakeSptr();
51     sptr<WindowEventChannelStub> windowEventChannelStub_ = sptr<WindowEventChannelMocker>::MakeSptr(sessionStage);
52 };
53 
SetUpTestCase()54 void WindowEventChannelStubTest::SetUpTestCase() {}
55 
TearDownTestCase()56 void WindowEventChannelStubTest::TearDownTestCase() {}
57 
SetUp()58 void WindowEventChannelStubTest::SetUp() {}
59 
TearDown()60 void WindowEventChannelStubTest::TearDown() {}
61 
62 namespace {
63 /**
64  * @tc.name: OnRemoteRequest
65  * @tc.desc: test function : OnRemoteRequest
66  * @tc.type: FUNC
67  */
68 HWTEST_F(WindowEventChannelStubTest, OnRemoteRequest, TestSize.Level1)
69 {
70     MessageParcel data;
71     MessageParcel reply;
72     MessageOption option;
73 
74     data.WriteInterfaceToken(WindowEventChannelStub::GetDescriptor());
75     WindowManagerAgentType type = WindowManagerAgentType::WINDOW_MANAGER_AGENT_TYPE_FOCUS;
76     data.WriteUint32(static_cast<uint32_t>(type));
77     sptr<IWindowManagerAgent> windowManagerAgent = sptr<WindowManagerAgent>::MakeSptr();
78     data.WriteRemoteObject(windowManagerAgent->AsObject());
79 
80     uint32_t code = static_cast<uint32_t>(
81         ISceneSessionManager::SceneSessionManagerMessage::TRANS_ID_UNREGISTER_WINDOW_MANAGER_AGENT);
82     ASSERT_TRUE((windowEventChannelStub_ != nullptr));
83     ASSERT_EQ(0, windowEventChannelStub_->OnRemoteRequest(code, data, reply, option));
84 }
85 
86 /**
87  * @tc.name: HandleTransferKeyEvent01
88  * @tc.desc: test function : HandleTransferKeyEvent01
89  * @tc.type: FUNC
90  */
91 HWTEST_F(WindowEventChannelStubTest, HandleTransferKeyEvent01, TestSize.Level1)
92 {
93     MessageParcel data;
94     MessageParcel reply;
95 
96     data.WriteUint32(1);
97     ASSERT_TRUE((windowEventChannelStub_ != nullptr));
98     ASSERT_EQ(5, windowEventChannelStub_->HandleTransferKeyEvent(data, reply));
99 }
100 
101 /**
102  * @tc.name: HandleTransferKeyEvent02
103  * @tc.desc: test function : HandleTransferKeyEvent02
104  * @tc.type: FUNC
105  */
106 HWTEST_F(WindowEventChannelStubTest, HandleTransferKeyEvent02, TestSize.Level1)
107 {
108     MessageParcel data;
109     MessageParcel reply;
110 
111     data.WriteUint32(0);
112     ASSERT_TRUE((windowEventChannelStub_ != nullptr));
113     ASSERT_EQ(5, windowEventChannelStub_->HandleTransferKeyEvent(data, reply));
114 }
115 
116 /**
117  * @tc.name: HandleTransferKeyEventAsync
118  * @tc.desc: test function : HandleTransferKeyEventAsync
119  * @tc.type: FUNC
120  */
121 HWTEST_F(WindowEventChannelStubTest, HandleTransferKeyEventAsync, TestSize.Level1)
122 {
123     MessageParcel data;
124     MessageParcel reply;
125 
126     data.WriteBool(true);
127     ASSERT_TRUE((windowEventChannelStub_ != nullptr));
128     ASSERT_EQ(5, windowEventChannelStub_->HandleTransferKeyEventAsync(data, reply));
129 }
130 
131 /**
132  * @tc.name: HandleTransferPointerEvent01
133  * @tc.desc: test function : HandleTransferPointerEvent01
134  * @tc.type: FUNC
135  */
136 HWTEST_F(WindowEventChannelStubTest, HandleTransferPointerEvent01, TestSize.Level1)
137 {
138     MessageParcel data;
139     MessageParcel reply;
140     ASSERT_TRUE((windowEventChannelStub_ != nullptr));
141     ASSERT_EQ(5, windowEventChannelStub_->HandleTransferPointerEvent(data, reply));
142 }
143 
144 /**
145  * @tc.name: HandleTransferPointerEvent02
146  * @tc.desc: test function : HandleTransferPointerEvent02
147  * @tc.type: FUNC
148  */
149 HWTEST_F(WindowEventChannelStubTest, HandleTransferPointerEvent02, TestSize.Level1)
150 {
151     MessageParcel data;
152     MessageParcel reply;
153 
154     data.WriteUint32(0);
155     ASSERT_TRUE((windowEventChannelStub_ != nullptr));
156     ASSERT_EQ(5, windowEventChannelStub_->HandleTransferPointerEvent(data, reply));
157 }
158 
159 /**
160  * @tc.name: HandleTransferFocusActiveEvent
161  * @tc.desc: test function : HandleTransferFocusActiveEvent
162  * @tc.type: FUNC
163  */
164 HWTEST_F(WindowEventChannelStubTest, HandleTransferFocusActiveEvent, TestSize.Level1)
165 {
166     MessageParcel data;
167     MessageParcel reply;
168 
169     data.WriteBool(false);
170     ASSERT_TRUE((windowEventChannelStub_ != nullptr));
171     ASSERT_EQ(0, windowEventChannelStub_->HandleTransferFocusActiveEvent(data, reply));
172 }
173 
174 /**
175  * @tc.name: HandleTransferFocusStateEvent
176  * @tc.desc: test function : HandleTransferFocusStateEvent
177  * @tc.type: FUNC
178  */
179 HWTEST_F(WindowEventChannelStubTest, HandleTransferFocusStateEvent, TestSize.Level1)
180 {
181     MessageParcel data;
182     MessageParcel reply;
183 
184     data.WriteBool(false);
185     ASSERT_TRUE((windowEventChannelStub_ != nullptr));
186     ASSERT_EQ(0, windowEventChannelStub_->HandleTransferFocusStateEvent(data, reply));
187 }
188 
189 /**
190  * @tc.name: HandleTransferAccessibilityHoverEvent01
191  * @tc.desc: test function : HandleTransferAccessibilityHoverEvent01
192  * @tc.type: FUNC
193  */
194 HWTEST_F(WindowEventChannelStubTest, HandleTransferAccessibilityHoverEvent01, TestSize.Level1)
195 {
196     WLOGI("HandleTransferAccessibilityHoverEvent01 begin");
197     MessageParcel data;
198     MessageParcel reply;
199 
200     data.WriteFloat(0.0f);
201     data.WriteFloat(0.0f);
202     data.WriteInt32(0);
203     data.WriteInt32(0);
204     data.WriteInt64(0);
205     ASSERT_TRUE(windowEventChannelStub_ != nullptr);
206     ASSERT_EQ(0, windowEventChannelStub_->HandleTransferAccessibilityHoverEvent(data, reply));
207     WLOGI("HandleTransferAccessibilityHoverEvent01 end");
208 }
209 
210 /**
211  * @tc.name: HandleTransferAccessibilityHoverEvent02
212  * @tc.desc: test function : HandleTransferAccessibilityHoverEvent02
213  * @tc.type: FUNC
214  */
215 HWTEST_F(WindowEventChannelStubTest, HandleTransferAccessibilityHoverEvent02, TestSize.Level1)
216 {
217     WLOGI("HandleTransferAccessibilityHoverEvent02 begin");
218     MessageParcel data;
219     MessageParcel reply;
220     ASSERT_TRUE(windowEventChannelStub_ != nullptr);
221     ASSERT_EQ(ERR_INVALID_DATA, windowEventChannelStub_->HandleTransferAccessibilityHoverEvent(data, reply));
222     WLOGI("HandleTransferAccessibilityHoverEvent02 end");
223 }
224 
225 /**
226  * @tc.name: HandleTransferAccessibilityHoverEvent03
227  * @tc.desc: test function : HandleTransferAccessibilityHoverEvent03
228  * @tc.type: FUNC
229  */
230 HWTEST_F(WindowEventChannelStubTest, HandleTransferAccessibilityHoverEvent03, TestSize.Level1)
231 {
232     WLOGI("HandleTransferAccessibilityHoverEvent03 begin");
233     MessageParcel data;
234     MessageParcel reply;
235 
236     data.WriteFloat(0.0f);
237     ASSERT_TRUE(windowEventChannelStub_ != nullptr);
238     ASSERT_EQ(ERR_INVALID_DATA, windowEventChannelStub_->HandleTransferAccessibilityHoverEvent(data, reply));
239     WLOGI("HandleTransferAccessibilityHoverEvent03 end");
240 }
241 
242 /**
243  * @tc.name: HandleTransferAccessibilityHoverEvent04
244  * @tc.desc: test function : HandleTransferAccessibilityHoverEvent04
245  * @tc.type: FUNC
246  */
247 HWTEST_F(WindowEventChannelStubTest, HandleTransferAccessibilityHoverEvent04, TestSize.Level1)
248 {
249     WLOGI("HandleTransferAccessibilityHoverEvent04 begin");
250     MessageParcel data;
251     MessageParcel reply;
252 
253     data.WriteFloat(0.0f);
254     data.WriteFloat(0.0f);
255     ASSERT_TRUE(windowEventChannelStub_ != nullptr);
256     ASSERT_EQ(ERR_INVALID_DATA, windowEventChannelStub_->HandleTransferAccessibilityHoverEvent(data, reply));
257     WLOGI("HandleTransferAccessibilityHoverEvent04 end");
258 }
259 
260 /**
261  * @tc.name: HandleTransferAccessibilityHoverEvent05
262  * @tc.desc: test function : HandleTransferAccessibilityHoverEvent05
263  * @tc.type: FUNC
264  */
265 HWTEST_F(WindowEventChannelStubTest, HandleTransferAccessibilityHoverEvent05, TestSize.Level1)
266 {
267     WLOGI("HandleTransferAccessibilityHoverEvent05 begin");
268     MessageParcel data;
269     MessageParcel reply;
270 
271     data.WriteFloat(0.0f);
272     data.WriteFloat(0.0f);
273     data.WriteInt32(0);
274     ASSERT_TRUE(windowEventChannelStub_ != nullptr);
275     ASSERT_EQ(ERR_INVALID_DATA, windowEventChannelStub_->HandleTransferAccessibilityHoverEvent(data, reply));
276     WLOGI("HandleTransferAccessibilityHoverEvent05 end");
277 }
278 
279 /**
280  * @tc.name: HandleTransferAccessibilityHoverEvent06
281  * @tc.desc: test function : HandleTransferAccessibilityHoverEvent06
282  * @tc.type: FUNC
283  */
284 HWTEST_F(WindowEventChannelStubTest, HandleTransferAccessibilityHoverEvent06, TestSize.Level1)
285 {
286     WLOGI("HandleTransferAccessibilityHoverEvent06 begin");
287     MessageParcel data;
288     MessageParcel reply;
289 
290     data.WriteFloat(0.0f);
291     data.WriteFloat(0.0f);
292     data.WriteInt32(0);
293     data.WriteInt32(0);
294     ASSERT_TRUE(windowEventChannelStub_ != nullptr);
295     ASSERT_EQ(ERR_INVALID_DATA, windowEventChannelStub_->HandleTransferAccessibilityHoverEvent(data, reply));
296     WLOGI("HandleTransferAccessibilityHoverEvent06 end");
297 }
298 
299 /**
300  * @tc.name: HandleTransferAccessibilityChildTreeRegister01
301  * @tc.desc: test function : HandleTransferAccessibilityChildTreeRegister01
302  * @tc.type: FUNC
303  */
304 HWTEST_F(WindowEventChannelStubTest, HandleTransferAccessibilityChildTreeRegister01, TestSize.Level1)
305 {
306     WLOGI("HandleTransferAccessibilityChildTreeRegister01 begin");
307     MessageParcel data;
308     MessageParcel reply;
309 
310     data.WriteUint32(0);
311     data.WriteInt32(0);
312     data.WriteInt64(0);
313     ASSERT_TRUE(windowEventChannelStub_ != nullptr);
314     ASSERT_EQ(0, windowEventChannelStub_->HandleTransferAccessibilityChildTreeRegister(data, reply));
315     WLOGI("HandleTransferAccessibilityChildTreeRegister01 end");
316 }
317 
318 /**
319  * @tc.name: HandleTransferAccessibilityChildTreeRegister02
320  * @tc.desc: test function : HandleTransferAccessibilityChildTreeRegister02
321  * @tc.type: FUNC
322  */
323 HWTEST_F(WindowEventChannelStubTest, HandleTransferAccessibilityChildTreeRegister02, TestSize.Level1)
324 {
325     WLOGI("HandleTransferAccessibilityChildTreeRegister02 begin");
326     MessageParcel data;
327     MessageParcel reply;
328 
329     ASSERT_TRUE(windowEventChannelStub_ != nullptr);
330     ASSERT_EQ(ERR_INVALID_DATA, windowEventChannelStub_->HandleTransferAccessibilityChildTreeRegister(data, reply));
331     WLOGI("HandleTransferAccessibilityChildTreeRegister02 end");
332 }
333 
334 /**
335  * @tc.name: HandleTransferAccessibilityChildTreeRegister03
336  * @tc.desc: test function : HandleTransferAccessibilityChildTreeRegister03
337  * @tc.type: FUNC
338  */
339 HWTEST_F(WindowEventChannelStubTest, HandleTransferAccessibilityChildTreeRegister03, TestSize.Level1)
340 {
341     WLOGI("HandleTransferAccessibilityChildTreeRegister03 begin");
342     MessageParcel data;
343     MessageParcel reply;
344 
345     data.WriteUint32(0);
346     ASSERT_TRUE(windowEventChannelStub_ != nullptr);
347     ASSERT_EQ(ERR_INVALID_DATA, windowEventChannelStub_->HandleTransferAccessibilityChildTreeRegister(data, reply));
348     WLOGI("HandleTransferAccessibilityChildTreeRegister03 end");
349 }
350 
351 /**
352  * @tc.name: HandleTransferAccessibilityChildTreeRegister04
353  * @tc.desc: test function : HandleTransferAccessibilityChildTreeRegister04
354  * @tc.type: FUNC
355  */
356 HWTEST_F(WindowEventChannelStubTest, HandleTransferAccessibilityChildTreeRegister04, TestSize.Level1)
357 {
358     WLOGI("HandleTransferAccessibilityChildTreeRegister04 begin");
359     MessageParcel data;
360     MessageParcel reply;
361 
362     data.WriteUint32(0);
363     data.WriteInt32(0);
364     ASSERT_TRUE(windowEventChannelStub_ != nullptr);
365     ASSERT_EQ(ERR_INVALID_DATA, windowEventChannelStub_->HandleTransferAccessibilityChildTreeRegister(data, reply));
366     WLOGI("HandleTransferAccessibilityChildTreeRegister04 end");
367 }
368 
369 /**
370  * @tc.name: HandleTransferAccessibilityChildTreeUnregister01
371  * @tc.desc: test function : HandleTransferAccessibilityChildTreeUnregister01
372  * @tc.type: FUNC
373  */
374 HWTEST_F(WindowEventChannelStubTest, HandleTransferAccessibilityChildTreeUnregister01, TestSize.Level1)
375 {
376     WLOGI("HandleTransferAccessibilityChildTreeUnregister01 begin");
377     MessageParcel data;
378     MessageParcel reply;
379     ASSERT_TRUE(windowEventChannelStub_ != nullptr);
380     ASSERT_EQ(0, windowEventChannelStub_->HandleTransferAccessibilityChildTreeUnregister(data, reply));
381     WLOGI("HandleTransferAccessibilityChildTreeUnregister01 end");
382 }
383 
384 /**
385  * @tc.name: HandleTransferAccessibilityDumpChildInfo01
386  * @tc.desc: test function : HandleTransferAccessibilityDumpChildInfo01
387  * @tc.type: FUNC
388  */
389 HWTEST_F(WindowEventChannelStubTest, HandleTransferAccessibilityDumpChildInfo01, TestSize.Level1)
390 {
391     WLOGI("HandleTransferAccessibilityDumpChildInfo01 begin");
392     MessageParcel data;
393     MessageParcel reply;
394 
395     std::vector<std::string> params;
396     data.WriteStringVector(params);
397     ASSERT_TRUE(windowEventChannelStub_ != nullptr);
398     ASSERT_EQ(0, windowEventChannelStub_->HandleTransferAccessibilityDumpChildInfo(data, reply));
399     WLOGI("HandleTransferAccessibilityDumpChildInfo01 end");
400 }
401 } // namespace
402 } // namespace Rosen
403 } // namespace OHOS