1 /*
2 * Copyright (c) 2022 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 <gtest/gtest.h>
17 #include "window_extension_proxy.h"
18 #include "window_extension_client_proxy.h"
19 #include "window_extension_stub.h"
20 #include "window_extension_stub_impl.h"
21 #include "window_extension_client_interface.h"
22 #include "window_extension_client_stub_impl.h"
23 #include "mock_message_parcel.h"
24 #include "iremote_object_mocker.h"
25
26 using namespace testing;
27 using namespace testing::ext;
28
29 namespace OHOS {
30 namespace Rosen {
31 class WindowExtensionProxyTest : public testing::Test {
32 public:
33 static void SetUpTestCase();
34 static void TearDownTestCase();
35 void SetUp() override;
36 void TearDown() override;
37 sptr<WindowExtensionStub> mockWindowExtensionStub_;
38 sptr<WindowExtensionProxy> windowExtensionProxy_;
39 sptr<IRemoteObject> impl_;
40 sptr<WindowExtensionClientProxy> windowExtensionClientProxy_;
41 };
42
SetUpTestCase()43 void WindowExtensionProxyTest::SetUpTestCase()
44 {
45 }
46
TearDownTestCase()47 void WindowExtensionProxyTest::TearDownTestCase()
48 {
49 }
50
SetUp()51 void WindowExtensionProxyTest::SetUp()
52 {
53 mockWindowExtensionStub_ = new WindowExtensionStubImpl("name");
54 windowExtensionProxy_ = new WindowExtensionProxy(mockWindowExtensionStub_);
55 impl_ = new IRemoteObjectMocker();
56 ASSERT_NE(nullptr, impl_);
57 windowExtensionClientProxy_ = new WindowExtensionClientProxy(impl_);
58 }
59
TearDown()60 void WindowExtensionProxyTest::TearDown()
61 {
62 MockMessageParcel::ClearAllErrorFlag();
63 }
64
65 namespace {
66
67 /**
68 * @tc.name: OnWindowReady
69 * @tc.desc: test success
70 * @tc.type: FUNC
71 */
72 HWTEST_F(WindowExtensionProxyTest, OnWindowReady, Function | SmallTest | Level2)
73 {
74 ASSERT_NE(nullptr, windowExtensionClientProxy_);
75 MockMessageParcel::SetWriteInterfaceTokenErrorFlag(true);
76 windowExtensionClientProxy_->OnWindowReady(nullptr);
77
78 MockMessageParcel::SetWriteInterfaceTokenErrorFlag(false);
79 windowExtensionClientProxy_->OnWindowReady(nullptr);
80
81 struct RSSurfaceNodeConfig config;
82 auto surfaceNode = RSSurfaceNode::Create(config);
83 windowExtensionClientProxy_->OnWindowReady(surfaceNode);
84 }
85
86 /**
87 * @tc.name: OnBackPress
88 * @tc.desc: test success
89 * @tc.type: FUNC
90 */
91 HWTEST_F(WindowExtensionProxyTest, OnBackPress, Function | SmallTest | Level2)
92 {
93 ASSERT_NE(nullptr, windowExtensionClientProxy_);
94 MockMessageParcel::SetWriteInterfaceTokenErrorFlag(true);
95 windowExtensionClientProxy_->OnBackPress();
96 MockMessageParcel::SetWriteInterfaceTokenErrorFlag(false);
97 windowExtensionClientProxy_->OnBackPress();
98 }
99
100 /**
101 * @tc.name: OnKeyEvent
102 * @tc.desc: test success
103 * @tc.type: FUNC
104 */
105 HWTEST_F(WindowExtensionProxyTest, OnKeyEvent, Function | SmallTest | Level2)
106 {
107 ASSERT_NE(nullptr, windowExtensionClientProxy_);
108 std::shared_ptr<MMI::KeyEvent> keyEvent = MMI::KeyEvent::Create();
109 ASSERT_NE(nullptr, keyEvent);
110 MockMessageParcel::SetWriteInterfaceTokenErrorFlag(true);
111 windowExtensionClientProxy_->OnKeyEvent(keyEvent);
112
113 MockMessageParcel::SetWriteInterfaceTokenErrorFlag(false);
114 windowExtensionClientProxy_->OnKeyEvent(keyEvent);
115 }
116
117 /**
118 * @tc.name: OnPointerEvent
119 * @tc.desc: test success
120 * @tc.type: FUNC
121 */
122 HWTEST_F(WindowExtensionProxyTest, OnPointerEvent, Function | SmallTest | Level2)
123 {
124 ASSERT_NE(nullptr, windowExtensionClientProxy_);
125 std::shared_ptr<MMI::PointerEvent> pointerEvent = MMI::PointerEvent::Create();
126 ASSERT_NE(nullptr, pointerEvent);
127 MockMessageParcel::SetWriteInterfaceTokenErrorFlag(true);
128 windowExtensionClientProxy_->OnPointerEvent(pointerEvent);
129
130 MockMessageParcel::SetWriteInterfaceTokenErrorFlag(false);
131 windowExtensionClientProxy_->OnPointerEvent(pointerEvent);
132 }
133
134 /**
135 * @tc.name: OnRemoteRequest
136 * @tc.desc: test success
137 * @tc.type: FUNC
138 */
139 HWTEST_F(WindowExtensionProxyTest, OnRemoteRequest, Function | SmallTest | Level2)
140 {
141 uint32_t code = 1000;
142 MessageParcel data = {};
143 MessageParcel reply = {};
144 MessageOption option = {MessageOption::TF_SYNC};
145 ASSERT_NE(-1, mockWindowExtensionStub_->OnRemoteRequest(code, data, reply, option));
146 }
147 }
148 }
149 }