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