• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 
18 #include "rs_window_animation_proxy.h"
19 #include "rs_window_animation_finished_callback.h"
20 #include "rs_window_animation_target.h"
21 #include "ui/rs_surface_node.h"
22 
23 using namespace testing;
24 using namespace testing::ext;
25 
26 namespace OHOS {
27 namespace Rosen {
28 class MockIRemoteObject : public IRemoteObject {
29 public:
MockIRemoteObject()30     MockIRemoteObject() : IRemoteObject {u"MockIRemoteObject"}
31     {
32     }
33 
~MockIRemoteObject()34     ~MockIRemoteObject()
35     {
36     }
37 
GetObjectRefCount()38     int32_t GetObjectRefCount()
39     {
40         return 0;
41     }
42 
SendRequest(uint32_t code,MessageParcel & data,MessageParcel & reply,MessageOption & option)43     int SendRequest(uint32_t code, MessageParcel &data, MessageParcel &reply, MessageOption &option)
44     {
45         return sendRequestResult_;
46     }
47 
IsProxyObject() const48     bool IsProxyObject() const
49     {
50         return true;
51     }
52 
CheckObjectLegality() const53     bool CheckObjectLegality() const
54     {
55         return true;
56     }
57 
AddDeathRecipient(const sptr<DeathRecipient> & recipient)58     bool AddDeathRecipient(const sptr<DeathRecipient> &recipient)
59     {
60         return true;
61     }
62 
RemoveDeathRecipient(const sptr<DeathRecipient> & recipient)63     bool RemoveDeathRecipient(const sptr<DeathRecipient> &recipient)
64     {
65         return true;
66     }
67 
AsInterface()68     sptr<IRemoteBroker> AsInterface()
69     {
70         return nullptr;
71     }
72 
Dump(int fd,const std::vector<std::u16string> & args)73     int Dump(int fd, const std::vector<std::u16string> &args)
74     {
75         return 0;
76     }
77 
78     int sendRequestResult_ = 0;
79     int count_ = 0;
80 };
81 
82 class RSWindowAnimationProxyTest : public testing::Test {
83 public:
84     static void SetUpTestCase();
85     static void TearDownTestCase();
86     void SetUp() override;
87     void TearDown() override;
88 
89     sptr<RSWindowAnimationProxy> proxy_;
90     sptr<RSWindowAnimationProxy> proxyNull_;
91     static std::shared_ptr<RSSurfaceNode> animationSurfaceNode;
92     sptr<RSWindowAnimationTarget> windowAnimationTarget_;
93 };
94 std::shared_ptr<RSSurfaceNode> RSWindowAnimationProxyTest::animationSurfaceNode = nullptr;
95 
SetUpTestCase()96 void RSWindowAnimationProxyTest::SetUpTestCase()
97 {
98     RSSurfaceNodeConfig config;
99     animationSurfaceNode = RSSurfaceNode::Create(config, true);
100 }
101 
TearDownTestCase()102 void RSWindowAnimationProxyTest::TearDownTestCase() {}
103 
SetUp()104 void RSWindowAnimationProxyTest::SetUp()
105 {
106     sptr<MockIRemoteObject> remoteMocker = new MockIRemoteObject();
107     proxy_ = new RSWindowAnimationProxy(remoteMocker);
108     proxyNull_ = new RSWindowAnimationProxy(nullptr);
109     windowAnimationTarget_ = new RSWindowAnimationTarget();
110     windowAnimationTarget_->bundleName_ = "";
111     windowAnimationTarget_->abilityName_ = "";
112     windowAnimationTarget_->windowBounds_ = RRect();
113     windowAnimationTarget_->surfaceNode_ = animationSurfaceNode;
114     windowAnimationTarget_->windowId_ = 0;
115     windowAnimationTarget_->displayId_ = 0;
116     windowAnimationTarget_->missionId_ = 0;
117 }
118 
TearDown()119 void RSWindowAnimationProxyTest::TearDown() {}
120 
121 /**
122  * @tc.name: OnStartApp001
123  * @tc.desc: Verify the OnStartApp
124  * @tc.type:FUNC
125  */
126 HWTEST_F(RSWindowAnimationProxyTest, OnStartApp001, TestSize.Level1)
127 {
128     GTEST_LOG_(INFO) << "RSWindowAnimationStubTest OnStartApp001 start";
129     ASSERT_TRUE(proxy_ != nullptr);
130     sptr<RSWindowAnimationFinishedCallback> finishedCallback = new RSWindowAnimationFinishedCallback(nullptr);
131 
132     proxyNull_->OnStartApp(StartingAppType::FROM_LAUNCHER, nullptr, finishedCallback);
133     proxyNull_->OnStartApp(StartingAppType::FROM_LAUNCHER, windowAnimationTarget_, finishedCallback);
134 
135     proxy_->OnStartApp(StartingAppType::FROM_LAUNCHER, nullptr, finishedCallback);
136     proxy_->OnStartApp(StartingAppType::FROM_LAUNCHER, windowAnimationTarget_, finishedCallback);
137     ASSERT_TRUE(proxy_ != nullptr);
138     GTEST_LOG_(INFO) << "RSWindowAnimationStubTest OnStartApp001 end";
139 }
140 
141 /**
142  * @tc.name: OnAppTransition001
143  * @tc.desc: Verify the OnAppTransition
144  * @tc.type:FUNC
145  */
146 HWTEST_F(RSWindowAnimationProxyTest, OnAppTransition001, TestSize.Level1)
147 {
148     GTEST_LOG_(INFO) << "RSWindowAnimationStubTest OnAppTransition001 start";
149     ASSERT_TRUE(proxy_ != nullptr);
150     sptr<RSWindowAnimationFinishedCallback> finishedCallback = new RSWindowAnimationFinishedCallback(nullptr);
151 
152     proxyNull_->OnAppTransition(nullptr, nullptr, finishedCallback);
153     proxyNull_->OnAppTransition(windowAnimationTarget_, nullptr, finishedCallback);
154     proxyNull_->OnAppTransition(windowAnimationTarget_, windowAnimationTarget_, finishedCallback);
155 
156     proxy_->OnAppTransition(nullptr, nullptr, finishedCallback);
157     proxy_->OnAppTransition(windowAnimationTarget_, nullptr, finishedCallback);
158     proxy_->OnAppTransition(windowAnimationTarget_, windowAnimationTarget_, finishedCallback);
159     GTEST_LOG_(INFO) << "RSWindowAnimationStubTest OnAppTransition001 end";
160 }
161 
162 /**
163  * @tc.name: OnAppBackTransition001
164  * @tc.desc: Verify the OnAppBackTransition
165  * @tc.type:FUNC
166  */
167 HWTEST_F(RSWindowAnimationProxyTest, OnAppBackTransition001, TestSize.Level1)
168 {
169     GTEST_LOG_(INFO) << "RSWindowAnimationStubTest OnAppBackTransition001 start";
170     ASSERT_TRUE(proxy_ != nullptr);
171     sptr<RSWindowAnimationFinishedCallback> finishedCallback = new RSWindowAnimationFinishedCallback(nullptr);
172 
173     proxyNull_->OnAppBackTransition(nullptr, nullptr, finishedCallback);
174     proxyNull_->OnAppBackTransition(windowAnimationTarget_, nullptr, finishedCallback);
175     proxyNull_->OnAppBackTransition(windowAnimationTarget_, windowAnimationTarget_, finishedCallback);
176 
177     proxy_->OnAppBackTransition(nullptr, nullptr, finishedCallback);
178     proxy_->OnAppBackTransition(windowAnimationTarget_, nullptr, finishedCallback);
179     proxy_->OnAppBackTransition(windowAnimationTarget_, windowAnimationTarget_, finishedCallback);
180     GTEST_LOG_(INFO) << "RSWindowAnimationStubTest OnAppBackTransition001 end";
181 }
182 
183 /**
184  * @tc.name: OnMinimizeWindow001
185  * @tc.desc: Verify the OnMinimizeWindow
186  * @tc.type:FUNC
187  */
188 HWTEST_F(RSWindowAnimationProxyTest, OnMinimizeWindow001, TestSize.Level1)
189 {
190     GTEST_LOG_(INFO) << "RSWindowAnimationStubTest OnMinimizeWindow001 start";
191     ASSERT_TRUE(proxy_ != nullptr);
192     sptr<RSWindowAnimationFinishedCallback> finishedCallback = new RSWindowAnimationFinishedCallback(nullptr);
193 
194     proxyNull_->OnMinimizeWindow(nullptr, finishedCallback);
195     proxyNull_->OnMinimizeWindow(windowAnimationTarget_, finishedCallback);
196 
197     proxy_->OnMinimizeWindow(nullptr, finishedCallback);
198     proxy_->OnMinimizeWindow(windowAnimationTarget_, finishedCallback);
199     GTEST_LOG_(INFO) << "RSWindowAnimationStubTest OnMinimizeWindow001 end";
200 }
201 
202 /**
203  * @tc.name: OnMinimizeAllWindow001
204  * @tc.desc: Verify the OnMinimizeAllWindow
205  * @tc.type:FUNC
206  */
207 HWTEST_F(RSWindowAnimationProxyTest, OnMinimizeAllWindow001, TestSize.Level1)
208 {
209     GTEST_LOG_(INFO) << "RSWindowAnimationStubTest OnMinimizeAllWindow001 start";
210     ASSERT_TRUE(proxy_ != nullptr);
211     std::vector<sptr<RSWindowAnimationTarget>> minimizingWindowsTarget1;
212     std::vector<sptr<RSWindowAnimationTarget>> minimizingWindowsTarget2;
213     minimizingWindowsTarget2.push_back(windowAnimationTarget_);
214     sptr<RSWindowAnimationFinishedCallback> finishedCallback = new RSWindowAnimationFinishedCallback(nullptr);
215 
216     proxyNull_->OnMinimizeAllWindow(minimizingWindowsTarget1, nullptr);
217     proxyNull_->OnMinimizeAllWindow(minimizingWindowsTarget1, finishedCallback);
218     proxyNull_->OnMinimizeAllWindow(minimizingWindowsTarget2, finishedCallback);
219 
220     proxy_->OnMinimizeAllWindow(minimizingWindowsTarget1, nullptr);
221     proxy_->OnMinimizeAllWindow(minimizingWindowsTarget1, finishedCallback);
222     proxy_->OnMinimizeAllWindow(minimizingWindowsTarget2, finishedCallback);
223     GTEST_LOG_(INFO) << "RSWindowAnimationStubTest OnMinimizeAllWindow001 end";
224 }
225 
226 /**
227  * @tc.name: OnCloseWindow001
228  * @tc.desc: Verify the OnCloseWindow
229  * @tc.type:FUNC
230  */
231 HWTEST_F(RSWindowAnimationProxyTest, OnCloseWindow001, TestSize.Level1)
232 {
233     GTEST_LOG_(INFO) << "RSWindowAnimationStubTest OnCloseWindow001 start";
234     ASSERT_TRUE(proxy_ != nullptr);
235     sptr<RSWindowAnimationFinishedCallback> finishedCallback = new RSWindowAnimationFinishedCallback(nullptr);
236 
237     proxyNull_->OnCloseWindow(nullptr, finishedCallback);
238     proxyNull_->OnCloseWindow(windowAnimationTarget_, finishedCallback);
239 
240     proxy_->OnCloseWindow(nullptr, finishedCallback);
241     proxy_->OnCloseWindow(windowAnimationTarget_, finishedCallback);
242     GTEST_LOG_(INFO) << "RSWindowAnimationStubTest OnCloseWindow001 end";
243 }
244 
245 /**
246  * @tc.name: OnScreenUnlock001
247  * @tc.desc: Verify the OnScreenUnlock
248  * @tc.type:FUNC
249  */
250 HWTEST_F(RSWindowAnimationProxyTest, OnScreenUnlock001, TestSize.Level1)
251 {
252     GTEST_LOG_(INFO) << "RSWindowAnimationStubTest OnScreenUnlock001 start";
253     ASSERT_TRUE(proxy_ != nullptr);
254     sptr<RSWindowAnimationFinishedCallback> finishedCallback = new RSWindowAnimationFinishedCallback(nullptr);
255 
256     proxyNull_->OnScreenUnlock(finishedCallback);
257 
258     proxy_->OnScreenUnlock(finishedCallback);
259     GTEST_LOG_(INFO) << "RSWindowAnimationStubTest OnScreenUnlock001 end";
260 }
261 
262 
263 /**
264  * @tc.name: OnWindowAnimationTargetsUpdate001
265  * @tc.desc: Verify the OnWindowAnimationTargetsUpdate
266  * @tc.type:FUNC
267  */
268 HWTEST_F(RSWindowAnimationProxyTest, OnWindowAnimationTargetsUpdate001, TestSize.Level1)
269 {
270     GTEST_LOG_(INFO) << "RSWindowAnimationStubTest OnWindowAnimationTargetsUpdate001 start";
271     ASSERT_TRUE(proxy_ != nullptr);
272     std::vector<sptr<RSWindowAnimationTarget>> floatingWindowTargets1;
273     for (int i = 0; i < 500; i++) {
274         floatingWindowTargets1.push_back(windowAnimationTarget_);
275     }
276     std::vector<sptr<RSWindowAnimationTarget>> floatingWindowTargets2;
277     floatingWindowTargets2.push_back(windowAnimationTarget_);
278 
279     proxyNull_->OnWindowAnimationTargetsUpdate(windowAnimationTarget_, floatingWindowTargets1);
280     proxyNull_->OnWindowAnimationTargetsUpdate(nullptr, floatingWindowTargets2);
281     proxyNull_->OnWindowAnimationTargetsUpdate(windowAnimationTarget_, floatingWindowTargets2);
282 
283     proxy_->OnWindowAnimationTargetsUpdate(windowAnimationTarget_, floatingWindowTargets1);
284     proxy_->OnWindowAnimationTargetsUpdate(nullptr, floatingWindowTargets2);
285     proxy_->OnWindowAnimationTargetsUpdate(windowAnimationTarget_, floatingWindowTargets2);
286     GTEST_LOG_(INFO) << "RSWindowAnimationStubTest OnWindowAnimationTargetsUpdate001 end";
287 }
288 
289 /**
290  * @tc.name: OnWallpaperUpdate001
291  * @tc.desc: Verify the OnWallpaperUpdate
292  * @tc.type:FUNC
293  */
294 HWTEST_F(RSWindowAnimationProxyTest, OnWallpaperUpdate001, TestSize.Level1)
295 {
296     GTEST_LOG_(INFO) << "RSWindowAnimationStubTest OnWallpaperUpdate001 start";
297     ASSERT_TRUE(proxy_ != nullptr);
298 
299     proxyNull_->OnWallpaperUpdate(nullptr);
300     proxyNull_->OnWallpaperUpdate(windowAnimationTarget_);
301 
302     proxy_->OnWallpaperUpdate(nullptr);
303     proxy_->OnWallpaperUpdate(windowAnimationTarget_);
304     GTEST_LOG_(INFO) << "RSWindowAnimationStubTest OnWallpaperUpdate001 end";
305 }
306 
307 } // namespace Rosen
308 } // namespace OHOS