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