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