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 "iremote_object_mocker.h"
18 #include <gtest/gtest.h>
19 #include <message_option.h>
20 #include <message_parcel.h>
21 #include "mock_message_parcel.h"
22 #include "window_manager_hilog.h"
23
24 using namespace testing;
25 using namespace testing::ext;
26 using namespace std;
27 namespace OHOS::Accessibility {
28 class AccessibilityElementInfo;
29 }
30 namespace OHOS {
31 namespace Rosen {
32 namespace {
33 constexpr HiviewDFX::HiLogLabel LABEL = {LOG_CORE, HILOG_DOMAIN_WINDOW, "WindowEventChannelProxyMockTest"};
34 }
35 class WindowEventChannelProxyMockTest : public testing::Test {
36 public:
37 static void SetUpTestCase();
38 static void TearDownTestCase();
39 void SetUp() override;
40 void TearDown() override;
41 sptr<IRemoteObject> iRemoteObjectMocker = sptr<IRemoteObjectMocker>::MakeSptr();
42 sptr<WindowEventChannelProxy> windowEventChannelProxy_ =
43 sptr<WindowEventChannelProxy>::MakeSptr(iRemoteObjectMocker);
44 };
45
SetUpTestCase()46 void WindowEventChannelProxyMockTest::SetUpTestCase()
47 {
48 }
49
TearDownTestCase()50 void WindowEventChannelProxyMockTest::TearDownTestCase()
51 {
52 }
53
SetUp()54 void WindowEventChannelProxyMockTest::SetUp()
55 {
56 }
57
TearDown()58 void WindowEventChannelProxyMockTest::TearDown()
59 {
60 }
61
62 namespace {
63 /**
64 * @tc.name: TransferAccessibilityHoverEvent
65 * @tc.desc: test function : TransferAccessibilityHoverEvent
66 * @tc.type: FUNC
67 */
68 HWTEST_F(WindowEventChannelProxyMockTest, TransferAccessibilityHoverEvent, Function | SmallTest | Level1)
69 {
70 WLOGI("TransferAccessibilityHoverEvent begin");
71 MockMessageParcel::SetWriteInterfaceTokenErrorFlag(true);
72 float pointX = 0.0f;
73 float pointY = 0.0f;
74 int32_t sourceType = 0;
75 int32_t eventType = 0;
76 int64_t timeMs = 0;
77 WSError res = windowEventChannelProxy_->TransferAccessibilityHoverEvent(
78 pointX, pointY, sourceType, eventType, timeMs);
79 ASSERT_EQ(WSError::WS_ERROR_IPC_FAILED, res);
80 MockMessageParcel::ClearAllErrorFlag();
81 WLOGI("TransferAccessibilityHoverEvent end");
82 }
83
84 /**
85 * @tc.name: TransferAccessibilityHoverEvent1
86 * @tc.desc: test function : TransferAccessibilityHoverEvent1
87 * @tc.type: FUNC
88 */
89 HWTEST_F(WindowEventChannelProxyMockTest, TransferAccessibilityHoverEvent1, Function | SmallTest | Level1)
90 {
91 WLOGI("TransferAccessibilityHoverEvent1 begin");
92 float pointX = -1.0f;
93 float pointY = 0.0f;
94 int32_t sourceType = 0;
95 int32_t eventType = 0;
96 int64_t timeMs = 0;
97 WSError res = windowEventChannelProxy_->TransferAccessibilityHoverEvent(
98 pointX, pointY, sourceType, eventType, timeMs);
99 ASSERT_EQ(WSError::WS_ERROR_IPC_FAILED, res);
100 MockMessageParcel::ClearAllErrorFlag();
101 WLOGI("TransferAccessibilityHoverEvent1 end");
102 }
103
104 /**
105 * @tc.name: TransferAccessibilityHoverEvent2
106 * @tc.desc: test function : TransferAccessibilityHoverEvent2
107 * @tc.type: FUNC
108 */
109 HWTEST_F(WindowEventChannelProxyMockTest, TransferAccessibilityHoverEvent2, Function | SmallTest | Level1)
110 {
111 WLOGI("TransferAccessibilityHoverEvent2 begin");
112 float pointX = 0.0f;
113 float pointY = -1.0f;
114 int32_t sourceType = 0;
115 int32_t eventType = 0;
116 int64_t timeMs = 0;
117 WSError res = windowEventChannelProxy_->TransferAccessibilityHoverEvent(
118 pointX, pointY, sourceType, eventType, timeMs);
119 ASSERT_EQ(WSError::WS_ERROR_IPC_FAILED, res);
120 MockMessageParcel::ClearAllErrorFlag();
121 WLOGI("TransferAccessibilityHoverEvent2 end");
122 }
123
124 /**
125 * @tc.name: TransferAccessibilityHoverEvent3
126 * @tc.desc: test function : TransferAccessibilityHoverEvent3
127 * @tc.type: FUNC
128 */
129 HWTEST_F(WindowEventChannelProxyMockTest, TransferAccessibilityHoverEvent3, Function | SmallTest | Level1)
130 {
131 WLOGI("TransferAccessibilityHoverEvent3 begin");
132 float pointX = 0.0f;
133 float pointY = 0.0f;
134 int32_t sourceType = -1;
135 int32_t eventType = 0;
136 int64_t timeMs = 0;
137 WSError res = windowEventChannelProxy_->TransferAccessibilityHoverEvent(
138 pointX, pointY, sourceType, eventType, timeMs);
139 ASSERT_EQ(WSError::WS_ERROR_IPC_FAILED, res);
140 MockMessageParcel::ClearAllErrorFlag();
141 WLOGI("TransferAccessibilityHoverEvent3 end");
142 }
143
144 /**
145 * @tc.name: TransferAccessibilityHoverEvent4
146 * @tc.desc: test function : TransferAccessibilityHoverEvent4
147 * @tc.type: FUNC
148 */
149 HWTEST_F(WindowEventChannelProxyMockTest, TransferAccessibilityHoverEvent4, Function | SmallTest | Level1)
150 {
151 WLOGI("TransferAccessibilityHoverEvent4 begin");
152 float pointX = 0.0f;
153 float pointY = 0.0f;
154 int32_t sourceType = 0;
155 int32_t eventType = -1;
156 int64_t timeMs = 0;
157 WSError res = windowEventChannelProxy_->TransferAccessibilityHoverEvent(
158 pointX, pointY, sourceType, eventType, timeMs);
159 ASSERT_EQ(WSError::WS_ERROR_IPC_FAILED, res);
160 MockMessageParcel::ClearAllErrorFlag();
161 WLOGI("TransferAccessibilityHoverEvent4 end");
162 }
163
164 /**
165 * @tc.name: TransferAccessibilityHoverEvent5
166 * @tc.desc: test function : TransferAccessibilityHoverEvent5
167 * @tc.type: FUNC
168 */
169 HWTEST_F(WindowEventChannelProxyMockTest, TransferAccessibilityHoverEvent5, Function | SmallTest | Level1)
170 {
171 WLOGI("TransferAccessibilityHoverEvent5 begin");
172 float pointX = 0.0f;
173 float pointY = 0.0f;
174 int32_t sourceType = 0;
175 int32_t eventType = 0;
176 int64_t timeMs = -1;
177 WSError res = windowEventChannelProxy_->TransferAccessibilityHoverEvent(
178 pointX, pointY, sourceType, eventType, timeMs);
179 ASSERT_EQ(WSError::WS_ERROR_IPC_FAILED, res);
180 MockMessageParcel::ClearAllErrorFlag();
181 WLOGI("TransferAccessibilityHoverEvent5 end");
182 }
183
184 /**
185 * @tc.name: TransferAccessibilityChildTreeRegister
186 * @tc.desc: test function : TransferAccessibilityChildTreeRegister
187 * @tc.type: FUNC
188 */
189 HWTEST_F(WindowEventChannelProxyMockTest, TransferAccessibilityChildTreeRegister, Function | SmallTest | Level1)
190 {
191 WLOGI("TransferAccessibilityChildTreeRegister begin");
192 MockMessageParcel::SetWriteInterfaceTokenErrorFlag(true);
193 uint32_t windowId = 0;
194 int32_t treeId = 0;
195 int64_t accessibilityId = 0;
196 WSError res = windowEventChannelProxy_->TransferAccessibilityChildTreeRegister(windowId, treeId, accessibilityId);
197 ASSERT_EQ(WSError::WS_ERROR_IPC_FAILED, res);
198 MockMessageParcel::ClearAllErrorFlag();
199 WLOGI("TransferAccessibilityChildTreeRegister end");
200 }
201
202 /**
203 * @tc.name: TransferAccessibilityChildTreeRegister
204 * @tc.desc: test function : TransferAccessibilityChildTreeRegister
205 * @tc.type: FUNC
206 */
207 HWTEST_F(WindowEventChannelProxyMockTest, TransferAccessibilityChildTreeRegister1, Function | SmallTest | Level1)
208 {
209 WLOGI("TransferAccessibilityChildTreeRegister1 begin");
210 uint32_t windowId = 0;
211 int32_t treeId = -1;
212 int64_t accessibilityId = 0;
213 WSError res = windowEventChannelProxy_->TransferAccessibilityChildTreeRegister(windowId, treeId, accessibilityId);
214 ASSERT_EQ(WSError::WS_ERROR_IPC_FAILED, res);
215 WLOGI("TransferAccessibilityChildTreeRegister1 end");
216 }
217
218 /**
219 * @tc.name: TransferAccessibilityChildTreeRegister
220 * @tc.desc: test function : TransferAccessibilityChildTreeRegister
221 * @tc.type: FUNC
222 */
223 HWTEST_F(WindowEventChannelProxyMockTest, TransferAccessibilityChildTreeRegister2, Function | SmallTest | Level1)
224 {
225 WLOGI("TransferAccessibilityChildTreeRegister2 begin");
226 uint32_t windowId = 0;
227 int32_t treeId = 0;
228 int64_t accessibilityId = -1;
229 WSError res = windowEventChannelProxy_->TransferAccessibilityChildTreeRegister(windowId, treeId, accessibilityId);
230 ASSERT_EQ(WSError::WS_ERROR_IPC_FAILED, res);
231 WLOGI("TransferAccessibilityChildTreeRegister2 end");
232 }
233
234 /**
235 * @tc.name: TransferAccessibilityChildTreeRegister
236 * @tc.desc: test function : TransferAccessibilityChildTreeRegister
237 * @tc.type: FUNC
238 */
239 HWTEST_F(WindowEventChannelProxyMockTest, TransferAccessibilityChildTreeRegister3, Function | SmallTest | Level1)
240 {
241 WLOGI("TransferAccessibilityChildTreeRegister3 begin");
242 MockMessageParcel::SetWriteUint32ErrorFlag(true);
243 uint32_t windowId = 0;
244 int32_t treeId = 0;
245 int64_t accessibilityId = 0;
246 WSError res = windowEventChannelProxy_->TransferAccessibilityChildTreeRegister(windowId, treeId, accessibilityId);
247 ASSERT_EQ(WSError::WS_ERROR_IPC_FAILED, res);
248 MockMessageParcel::ClearAllErrorFlag();
249 WLOGI("TransferAccessibilityChildTreeRegister3 end");
250 }
251
252 /**
253 * @tc.name: TransferAccessibilityChildTreeUnregister
254 * @tc.desc: test function : TransferAccessibilityChildTreeUnregister
255 * @tc.type: FUNC
256 */
257 HWTEST_F(WindowEventChannelProxyMockTest, TransferAccessibilityChildTreeUnregister, Function | SmallTest | Level1)
258 {
259 WLOGI("TransferAccessibilityChildTreeUnregister begin");
260 MockMessageParcel::SetWriteInterfaceTokenErrorFlag(true);
261 WSError res = windowEventChannelProxy_->TransferAccessibilityChildTreeUnregister();
262 ASSERT_EQ(WSError::WS_ERROR_IPC_FAILED, res);
263 MockMessageParcel::ClearAllErrorFlag();
264 WLOGI("TransferAccessibilityChildTreeUnregister end");
265 }
266
267 /**
268 * @tc.name: TransferAccessibilityChildTreeUnregister
269 * @tc.desc: test function : TransferAccessibilityChildTreeUnregister
270 * @tc.type: FUNC
271 */
272 HWTEST_F(WindowEventChannelProxyMockTest, TransferAccessibilityChildTreeUnregister1, Function | SmallTest | Level1)
273 {
274 WLOGI("TransferAccessibilityChildTreeUnregister1 begin");
275 WSError res = windowEventChannelProxy_->TransferAccessibilityChildTreeUnregister();
276 ASSERT_EQ(WSError::WS_OK, res);
277 WLOGI("TransferAccessibilityChildTreeUnregister1 end");
278 }
279
280 /**
281 * @tc.name: TransferAccessibilityDumpChildInfo
282 * @tc.desc: test function : TransferAccessibilityDumpChildInfo
283 * @tc.type: FUNC
284 */
285 HWTEST_F(WindowEventChannelProxyMockTest, TransferAccessibilityDumpChildInfo, Function | SmallTest | Level1)
286 {
287 WLOGI("TransferAccessibilityDumpChildInfo begin");
288 std::vector<std::string> params;
289 std::vector<std::string> info;
290 MockMessageParcel::SetWriteInterfaceTokenErrorFlag(true);
291 WSError res = windowEventChannelProxy_->TransferAccessibilityDumpChildInfo(params, info);
292 ASSERT_EQ(WSError::WS_ERROR_IPC_FAILED, res);
293 MockMessageParcel::ClearAllErrorFlag();
294 WLOGI("TransferAccessibilityDumpChildInfo end");
295 }
296
297 /**
298 * @tc.name: TransferAccessibilityDumpChildInfo
299 * @tc.desc: test function : TransferAccessibilityDumpChildInfo
300 * @tc.type: FUNC
301 */
302 HWTEST_F(WindowEventChannelProxyMockTest, TransferAccessibilityDumpChildInfo1, Function | SmallTest | Level1)
303 {
304 WLOGI("TransferAccessibilityDumpChildInfo1 begin");
305 std::vector<std::string> params;
306 std::vector<std::string> info;
307 WSError res = windowEventChannelProxy_->TransferAccessibilityDumpChildInfo(params, info);
308 ASSERT_EQ(WSError::WS_OK, res);
309 WLOGI("TransferAccessibilityDumpChildInfo1 end");
310 }
311
312 /**
313 * @tc.name: TransferAccessibilityDumpChildInfo
314 * @tc.desc: test function : TransferAccessibilityDumpChildInfo
315 * @tc.type: FUNC
316 */
317 HWTEST_F(WindowEventChannelProxyMockTest, TransferAccessibilityDumpChildInfo2, Function | SmallTest | Level1)
318 {
319 WLOGI("TransferAccessibilityDumpChildInfo2 begin");
320 std::vector<std::string> params;
321 params.push_back("test");
322 std::vector<std::string> info;
323 WSError res = windowEventChannelProxy_->TransferAccessibilityDumpChildInfo(params, info);
324 ASSERT_EQ(WSError::WS_ERROR_IPC_FAILED, res);
325 WLOGI("TransferAccessibilityDumpChildInfo2 end");
326 }
327 }
328 }
329 }