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