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_manager_agent_stub.h"
18 #include "window_manager_agent.h"
19 #include "marshalling_helper.h"
20
21 using namespace testing;
22 using namespace testing::ext;
23 namespace OHOS {
24 namespace Rosen {
25 class WindowManagerAgentStubTest : public testing::Test {
26 public:
27 static void SetUpTestCase();
28 static void TearDownTestCase();
29 void SetUp() override;
30 void TearDown() override;
31 sptr<WindowManagerAgentStub> stub_;
32 };
33
SetUpTestCase()34 void WindowManagerAgentStubTest::SetUpTestCase()
35 {
36 }
37
TearDownTestCase()38 void WindowManagerAgentStubTest::TearDownTestCase()
39 {
40 }
41
SetUp()42 void WindowManagerAgentStubTest::SetUp()
43 {
44 stub_ = new WindowManagerAgent();
45 }
46
TearDown()47 void WindowManagerAgentStubTest::TearDown()
48 {
49 }
50
51 namespace {
52 /**
53 * @tc.name: OnRemoteRequest01
54 * @tc.desc: test InterfaceToken check failed
55 * @tc.type: FUNC
56 */
57 HWTEST_F(WindowManagerAgentStubTest, OnRemoteRequest01, Function | SmallTest | Level2)
58 {
59 MessageParcel data;
60 MessageParcel reply;
61 MessageOption option;
62
63 data.WriteInterfaceToken(u"error.GetDescriptor");
64
65 uint32_t code = static_cast<uint32_t>(IWindowManagerAgent::WindowManagerAgentMsg::TRANS_ID_UPDATE_FOCUS);
66
67 int res = stub_->OnRemoteRequest(code, data, reply, option);
68 EXPECT_EQ(res, -1);
69 }
70
71 /**
72 * @tc.name: OnRemoteRequest02
73 * @tc.desc: test TRANS_ID_UPDATE_FOCUS
74 * @tc.type: FUNC
75 */
76 HWTEST_F(WindowManagerAgentStubTest, OnRemoteRequest02, Function | SmallTest | Level2)
77 {
78 MessageParcel data;
79 MessageParcel reply;
80 MessageOption option;
81
82 data.WriteInterfaceToken(WindowManagerAgentStub::GetDescriptor());
83
84 sptr<FocusChangeInfo> focusChangeInfo = new FocusChangeInfo();
85 data.WriteParcelable(focusChangeInfo);
86 data.WriteRemoteObject(focusChangeInfo->abilityToken_);
87 data.WriteBool(false);
88
89 uint32_t code = static_cast<uint32_t>(IWindowManagerAgent::WindowManagerAgentMsg::TRANS_ID_UPDATE_FOCUS);
90
91 int res = stub_->OnRemoteRequest(code, data, reply, option);
92 EXPECT_EQ(res, 0);
93 }
94
95 /**
96 * @tc.name: OnRemoteRequest03
97 * @tc.desc: test TRANS_ID_UPDATE_FOCUS success
98 * @tc.type: FUNC
99 */
100 HWTEST_F(WindowManagerAgentStubTest, OnRemoteRequest03, Function | SmallTest | Level2)
101 {
102 MessageParcel data;
103 MessageParcel reply;
104 MessageOption option;
105
106 data.WriteInterfaceToken(WindowManagerAgentStub::GetDescriptor());
107
108 uint32_t code = static_cast<uint32_t>(IWindowManagerAgent::WindowManagerAgentMsg::TRANS_ID_UPDATE_FOCUS);
109
110 int res = stub_->OnRemoteRequest(code, data, reply, option);
111 EXPECT_EQ(res, 0);
112 }
113
114 /**
115 * @tc.name: OnRemoteRequest04
116 * @tc.desc: test TRANS_ID_UPDATE_WINDOW_STATUS success
117 * @tc.type: FUNC
118 */
119 HWTEST_F(WindowManagerAgentStubTest, OnRemoteRequest04, Function | SmallTest | Level2)
120 {
121 MessageParcel data;
122 MessageParcel reply;
123 MessageOption option;
124
125 data.WriteInterfaceToken(WindowManagerAgentStub::GetDescriptor());
126
127 sptr<AccessibilityWindowInfo> info = new AccessibilityWindowInfo();
128 std::vector<sptr<AccessibilityWindowInfo>> infos;
129 infos.emplace_back(info);
130 MarshallingHelper::MarshallingVectorParcelableObj<AccessibilityWindowInfo>(data, infos);
131
132 data.WriteUint32(static_cast<uint32_t>(WindowUpdateType::WINDOW_UPDATE_ADDED));
133
134 uint32_t code = static_cast<uint32_t>(IWindowManagerAgent::WindowManagerAgentMsg::TRANS_ID_UPDATE_WINDOW_STATUS);
135
136 int res = stub_->OnRemoteRequest(code, data, reply, option);
137 EXPECT_EQ(res, 0);
138 }
139
140 /**
141 * @tc.name: OnRemoteRequest06
142 * @tc.desc: test TRANS_ID_UPDATE_WINDOW_VISIBILITY success
143 * @tc.type: FUNC
144 */
145 HWTEST_F(WindowManagerAgentStubTest, OnRemoteRequest06, Function | SmallTest | Level2)
146 {
147 MessageParcel data;
148 MessageParcel reply;
149 MessageOption option;
150
151 data.WriteInterfaceToken(WindowManagerAgentStub::GetDescriptor());
152
153 sptr<WindowVisibilityInfo> visibilityInfo = new WindowVisibilityInfo();
154 std::vector<sptr<WindowVisibilityInfo>> visibilityInfos;
155 visibilityInfos.emplace_back(visibilityInfo);
156 data.WriteUint32(static_cast<uint32_t>(visibilityInfos.size()));
157 for (auto& info : visibilityInfos) {
158 data.WriteParcelable(info);
159 }
160
161 auto code = static_cast<uint32_t>(IWindowManagerAgent::WindowManagerAgentMsg::TRANS_ID_UPDATE_WINDOW_VISIBILITY);
162
163 int res = stub_->OnRemoteRequest(code, data, reply, option);
164 EXPECT_EQ(res, 0);
165 }
166
167 /**
168 * @tc.name: OnRemoteRequest08
169 * @tc.desc: test TRANS_ID_UPDATE_SYSTEM_BAR_PROPS success
170 * @tc.type: FUNC
171 */
172 HWTEST_F(WindowManagerAgentStubTest, OnRemoteRequest08, Function | SmallTest | Level2)
173 {
174 MessageParcel data;
175 MessageParcel reply;
176 MessageOption option;
177
178 data.WriteInterfaceToken(WindowManagerAgentStub::GetDescriptor());
179
180 data.WriteUint64(0);
181
182 SystemBarRegionTints tints;
183 MarshallingHelper::MarshallingVectorObj<SystemBarRegionTint>(data, tints,
__anonb84200350202(Parcel& parcel, const SystemBarRegionTint& tint) 184 [](Parcel& parcel, const SystemBarRegionTint& tint) {
185 return parcel.WriteUint32(static_cast<uint32_t>(tint.type_)) && parcel.WriteBool(tint.prop_.enable_) &&
186 parcel.WriteUint32(tint.prop_.backgroundColor_) && parcel.WriteUint32(tint.prop_.contentColor_) &&
187 parcel.WriteInt32(tint.region_.posX_) && parcel.WriteInt32(tint.region_.posY_) &&
188 parcel.WriteInt32(tint.region_.width_) && parcel.WriteInt32(tint.region_.height_);
189 }
190 );
191
192 uint32_t code = static_cast<uint32_t>(IWindowManagerAgent::WindowManagerAgentMsg::TRANS_ID_UPDATE_SYSTEM_BAR_PROPS);
193
194 int res = stub_->OnRemoteRequest(code, data, reply, option);
195 EXPECT_EQ(res, 0);
196 }
197
198 }
199 }
200 }
201