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