• 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 // gtest
17 #include <gtest/gtest.h>
18 #include "window.h"
19 #include "wm_common.h"
20 #include "window_test_utils.h"
21 using namespace testing;
22 using namespace testing::ext;
23 
24 namespace OHOS {
25 namespace Rosen {
26 namespace {
27     constexpr HiviewDFX::HiLogLabel LABEL = {LOG_CORE, HILOG_DOMAIN_WINDOW, "WindowAnimationTest"};
28 }
29 
30 using Utils = WindowTestUtils;
31 
32 class TestAnimationTransitionController : public IAnimationTransitionController {
33 public:
TestAnimationTransitionController(sptr<Window> window)34     explicit TestAnimationTransitionController(sptr<Window> window) : window_(window) {}
35     void AnimationForShown() override;
36     void AnimationForHidden() override;
37 private:
38     sptr<Window> window_ = nullptr;
39 };
40 
41 class WindowAnimationTransitionTest : public testing::Test {
42 public:
43     static void SetUpTestCase();
44     static void TearDownTestCase();
45     virtual void SetUp() override;
46     virtual void TearDown() override;
47     sptr<TestAnimationTransitionController> testAnimationTransitionListener_;
48     Utils::TestWindowInfo windowInfo_;
49     Transform trans_;
50     Transform defaultTrans_;
51 };
52 
AnimationForShown()53 void TestAnimationTransitionController::AnimationForShown()
54 {
55     WLOGFI("TestAnimationTransitionController AnimationForShown");
56     Transform trans;
57     window_->SetTransform(trans);
58 }
59 
AnimationForHidden()60 void TestAnimationTransitionController::AnimationForHidden()
61 {
62     WLOGFI("TestAnimationTransitionController AnimationForHidden");
63     Transform trans;
64     trans.pivotX_ = 1.0f;
65     trans.pivotY_ = 0.6f;
66     window_->SetTransform(trans);
67 }
68 
SetUpTestCase()69 void WindowAnimationTransitionTest::SetUpTestCase()
70 {
71 }
72 
TearDownTestCase()73 void WindowAnimationTransitionTest::TearDownTestCase()
74 {
75 }
76 
SetUp()77 void WindowAnimationTransitionTest::SetUp()
78 {
79     windowInfo_ = {
80             .name = "AnimationTestWindow",
81             .rect = {0, 0, 200, 200},
82             .type = WindowType::WINDOW_TYPE_FLOAT,
83             .mode = WindowMode::WINDOW_MODE_FLOATING,
84             .needAvoid = false,
85             .parentLimit = false,
86             .parentId = INVALID_WINDOW_ID,
87     };
88     trans_.pivotX_ = 1.0f;
89     trans_.pivotY_ = 0.6f;
90 }
91 
TearDown()92 void WindowAnimationTransitionTest::TearDown()
93 {
94 }
95 
96 namespace {
97 /**
98  * @tc.name: AnimationTransitionTest01
99  * @tc.desc: Register AnimationController and hide with custom animation
100  * @tc.type: FUNC
101  * @tc.require: issueI5NDLK
102  */
103 HWTEST_F(WindowAnimationTransitionTest, AnimationTransitionTest01, Function | MediumTest | Level3)
104 {
105     const sptr<Window>& window = Utils::CreateTestWindow(windowInfo_);
106     ASSERT_NE(nullptr, window);
107     sptr<TestAnimationTransitionController> testAnimationTransitionListener =
108         new TestAnimationTransitionController(window);
109     window->RegisterAnimationTransitionController(testAnimationTransitionListener);
110     ASSERT_EQ(WMError::WM_OK, window->Show());
111     usleep(500000); // 500000us = 0.5s
112     ASSERT_EQ(WMError::WM_OK, window->Hide(0, true));
113     usleep(500000); // 500000us = 0.5s
114     ASSERT_TRUE(trans_ == window->GetTransform());
115     ASSERT_EQ(WMError::WM_OK, window->Destroy());
116 }
117 
118 /**
119  * @tc.name: AnimationTransitionTest02
120  * @tc.desc: Register AnimationController and show without animation
121  * @tc.type: FUNC
122  * @tc.require: issueI5NDLK
123  */
124 HWTEST_F(WindowAnimationTransitionTest, AnimationTransitionTest02, Function | MediumTest | Level3)
125 {
126     const sptr<Window>& window = Utils::CreateTestWindow(windowInfo_);
127     ASSERT_NE(nullptr, window);
128     sptr<TestAnimationTransitionController> testAnimationTransitionListener =
129         new TestAnimationTransitionController(window);
130     window->RegisterAnimationTransitionController(testAnimationTransitionListener);
131     ASSERT_EQ(WMError::WM_OK, window->Show());
132     usleep(500000); // 500000us = 0.5s
133     ASSERT_TRUE(defaultTrans_ == window->GetTransform());
134     ASSERT_EQ(WMError::WM_OK, window->Destroy());
135 }
136 
137 /**
138  * @tc.name: AnimationTransitionTest03
139  * @tc.desc: hide with default animation without register animationController
140  * @tc.type: FUNC
141  * @tc.require: issueI5NDLK
142  */
143 HWTEST_F(WindowAnimationTransitionTest, AnimationTransitionTest03, Function | MediumTest | Level3)
144 {
145     const sptr<Window>& window = Utils::CreateTestWindow(windowInfo_);
146     ASSERT_NE(nullptr, window);
147     ASSERT_EQ(WMError::WM_OK, window->Hide(0, true));
148     usleep(500000); // 500000us = 0.5s
149     ASSERT_TRUE(defaultTrans_ == window->GetTransform());
150     ASSERT_EQ(WMError::WM_OK, window->Destroy());
151 }
152 
153 /**
154  * @tc.name: AnimationTransitionTest04
155  * @tc.desc: hide without custom animation and register animationController
156  * @tc.type: FUNC
157  * @tc.require: issueI5NDLK
158  */
159 HWTEST_F(WindowAnimationTransitionTest, AnimationTransitionTest04, Function | MediumTest | Level3)
160 {
161     const sptr<Window>& window = Utils::CreateTestWindow(windowInfo_);
162     ASSERT_NE(nullptr, window);
163     sptr<TestAnimationTransitionController> testAnimationTransitionListener =
164         new TestAnimationTransitionController(window);
165     window->RegisterAnimationTransitionController(testAnimationTransitionListener);
166     ASSERT_EQ(WMError::WM_OK, window->Show());
167     usleep(500000); // 500000us = 0.5s
168     ASSERT_EQ(WMError::WM_OK, window->Hide());
169     ASSERT_TRUE(defaultTrans_ == window->GetTransform());
170     ASSERT_EQ(WMError::WM_OK, window->Destroy());
171 }
172 }
173 } // namespace Rosen
174 } // namespace OHOS
175