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_proxy.h"
17 #include "session/container/include/zidl/window_event_ipc_interface_code.h"
18 #include "iremote_object_mocker.h"
19 #include <gtest/gtest.h>
20 #include <axis_event.h>
21 #include <ipc_types.h>
22 #include <key_event.h>
23 #include <message_option.h>
24 #include <message_parcel.h>
25 #include <pointer_event.h>
26 #include "window_manager_hilog.h"
27 
28 using namespace testing;
29 using namespace testing::ext;
30 using namespace std;
31 namespace OHOS::Accessibility {
32 class AccessibilityElementInfo;
33 }
34 namespace OHOS {
35 namespace Rosen {
36 class WindowEventChannelProxyTest : public testing::Test {
37 public:
38     static void SetUpTestCase();
39     static void TearDownTestCase();
40     void SetUp() override;
41     void TearDown() override;
42     sptr<IRemoteObject> iRemoteObjectMocker = new (std::nothrow) IRemoteObjectMocker();
43     sptr<WindowEventChannelProxy> windowEventChannelProxy_ = new WindowEventChannelProxy(iRemoteObjectMocker);
44 };
45 
SetUpTestCase()46 void WindowEventChannelProxyTest::SetUpTestCase()
47 {
48 }
49 
TearDownTestCase()50 void WindowEventChannelProxyTest::TearDownTestCase()
51 {
52 }
53 
SetUp()54 void WindowEventChannelProxyTest::SetUp()
55 {
56 }
57 
TearDown()58 void WindowEventChannelProxyTest::TearDown()
59 {
60 }
61 
62 namespace {
63 /**
64  * @tc.name: TransferKeyEvent
65  * @tc.desc: test function : TransferKeyEvent
66  * @tc.type: FUNC
67  */
68 HWTEST_F(WindowEventChannelProxyTest, TransferKeyEvent, Function | SmallTest | Level1)
69 {
70     std::shared_ptr<MMI::KeyEvent> keyEvent = MMI::KeyEvent::Create();
71     MMI::KeyEvent::KeyItem item = {};
72     item.SetPressed(true);
73     keyEvent->AddKeyItem(item);
74     keyEvent->SetKeyCode(1);
75     ASSERT_TRUE((windowEventChannelProxy_ != nullptr));
76     WSError res = windowEventChannelProxy_->TransferKeyEvent(keyEvent);
77     ASSERT_EQ(WSError::WS_OK, res);
78 }
79 
80 /**
81  * @tc.name: TransferPointerEvent
82  * @tc.desc: test function : TransferPointerEvent
83  * @tc.type: FUNC
84  */
85 HWTEST_F(WindowEventChannelProxyTest, TransferPointerEvent, Function | SmallTest | Level1)
86 {
87     std::shared_ptr<MMI::PointerEvent> pointerEvent = MMI::PointerEvent::Create();
88     pointerEvent->SetPointerAction(MMI::PointerEvent::POINTER_ACTION_DOWN);
89     pointerEvent->SetPointerId(0);
90     pointerEvent->SetSourceType(MMI::PointerEvent::SOURCE_TYPE_MOUSE);
91     ASSERT_TRUE((windowEventChannelProxy_ != nullptr));
92     WSError res = windowEventChannelProxy_->TransferPointerEvent(pointerEvent);
93     ASSERT_EQ(WSError::WS_OK, res);
94 }
95 
96 /**
97  * @tc.name: TransferKeyEventForConsumed
98  * @tc.desc: test function : TransferKeyEventForConsumed
99  * @tc.type: FUNC
100  */
101 HWTEST_F(WindowEventChannelProxyTest, TransferKeyEventForConsumed, Function | SmallTest | Level1)
102 {
103     std::shared_ptr<MMI::KeyEvent> keyEvent = MMI::KeyEvent::Create();
104     MMI::KeyEvent::KeyItem item = {};
105     item.SetPressed(true);
106     keyEvent->AddKeyItem(item);
107     keyEvent->SetKeyCode(1);
108     bool isConsumed = false;
109     WSError res = windowEventChannelProxy_->TransferKeyEventForConsumed(keyEvent, isConsumed);
110     ASSERT_EQ(WSError::WS_OK, res);
111 }
112 
113 /**
114  * @tc.name: TransferKeyEventForConsumedAsync
115  * @tc.desc: test function : TransferKeyEventForConsumedAsync
116  * @tc.type: FUNC
117  */
118 HWTEST_F(WindowEventChannelProxyTest, TransferKeyEventForConsumedAsync, Function | SmallTest | Level1)
119 {
120     auto keyEvent = MMI::KeyEvent::Create();
121     ASSERT_NE(keyEvent, nullptr);
122     bool isPreImeEvent = false;
123     sptr<IRemoteObject> iRemoteObjectMocker = new (std::nothrow) IRemoteObjectMocker();
124     WSError res = windowEventChannelProxy_->TransferKeyEventForConsumedAsync(keyEvent, isPreImeEvent,
125         iRemoteObjectMocker);
126     ASSERT_EQ(WSError::WS_OK, res);
127 }
128 
129 /**
130  * @tc.name: TransferFocusActiveEvent
131  * @tc.desc: test function : TransferFocusActiveEvent
132  * @tc.type: FUNC
133  */
134 HWTEST_F(WindowEventChannelProxyTest, TransferFocusActiveEvent, Function | SmallTest | Level1)
135 {
136     bool isFocusActive = false;
137     WSError res = windowEventChannelProxy_->TransferFocusActiveEvent(isFocusActive);
138     ASSERT_EQ(WSError::WS_OK, res);
139     isFocusActive = true;
140     res = windowEventChannelProxy_->TransferFocusActiveEvent(isFocusActive);
141     ASSERT_EQ(WSError::WS_OK, res);
142 }
143 
144 /**
145  * @tc.name: TransferFocusState
146  * @tc.desc: test function : TransferFocusState
147  * @tc.type: FUNC
148  */
149 HWTEST_F(WindowEventChannelProxyTest, TransferFocusState, Function | SmallTest | Level1)
150 {
151     bool focusState = false;
152     WSError res = windowEventChannelProxy_->TransferFocusActiveEvent(focusState);
153     ASSERT_EQ(WSError::WS_OK, res);
154     focusState = true;
155     res = windowEventChannelProxy_->TransferFocusState(focusState);
156     ASSERT_EQ(WSError::WS_OK, res);
157 }
158 
159 /**
160  * @tc.name: TransferAccessibilityHoverEvent
161  * @tc.desc: test function : TransferAccessibilityHoverEvent
162  * @tc.type: FUNC
163  */
164 HWTEST_F(WindowEventChannelProxyTest, TransferAccessibilityHoverEvent, Function | SmallTest | Level1)
165 {
166     float pointX = 0.0f;
167     float pointY = 0.0f;
168     int32_t sourceType = 0;
169     int32_t eventType = 0;
170     int64_t timeMs = 0;
171     WSError res = windowEventChannelProxy_->TransferAccessibilityHoverEvent(
172         pointX, pointY, sourceType, eventType, timeMs);
173     ASSERT_EQ(WSError::WS_OK, res);
174 }
175 
176 /**
177  * @tc.name: TransferAccessibilityChildTreeRegister
178  * @tc.desc: test function : TransferAccessibilityChildTreeRegister
179  * @tc.type: FUNC
180  */
181 HWTEST_F(WindowEventChannelProxyTest, TransferAccessibilityChildTreeRegister, Function | SmallTest | Level1)
182 {
183     uint32_t windowId = 0;
184     int32_t treeId = 0;
185     int64_t accessibilityId = 0;
186 
187     WSError res = windowEventChannelProxy_->TransferAccessibilityChildTreeRegister(windowId, treeId, accessibilityId);
188     ASSERT_EQ(WSError::WS_OK, res);
189 }
190 
191 /**
192  * @tc.name: TransferAccessibilityChildTreeUnregister
193  * @tc.desc: test function : TransferAccessibilityChildTreeUnregister
194  * @tc.type: FUNC
195  */
196 HWTEST_F(WindowEventChannelProxyTest, TransferAccessibilityChildTreeUnregister, Function | SmallTest | Level1)
197 {
198     WSError res = windowEventChannelProxy_->TransferAccessibilityChildTreeUnregister();
199     ASSERT_EQ(WSError::WS_OK, res);
200 }
201 
202 /**
203  * @tc.name: TransferAccessibilityDumpChildInfo
204  * @tc.desc: test function : TransferAccessibilityDumpChildInfo
205  * @tc.type: FUNC
206  */
207 HWTEST_F(WindowEventChannelProxyTest, TransferAccessibilityDumpChildInfo, Function | SmallTest | Level1)
208 {
209     std::vector<std::string> params;
210     std::vector<std::string> info;
211 
212     WSError res = windowEventChannelProxy_->TransferAccessibilityDumpChildInfo(params, info);
213     ASSERT_EQ(WSError::WS_OK, res);
214 }
215 }
216 }
217 }