1 /*
2 * Copyright (c) 2025 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 "modifier_render_thread/rs_modifiers_draw_thread.h"
20 #include "scene_board_judgement.h"
21 #include "window.h"
22 #include "window_helper.h"
23 #include "window_manager.h"
24 #include "window_test_utils.h"
25 #include "wm_common.h"
26 using namespace testing;
27 using namespace testing::ext;
28
29 namespace OHOS {
30 namespace Rosen {
31 namespace {
32 constexpr uint32_t MAX_WINDOW_ID = -1;
33 }
34
35 using Utils = WindowTestUtils;
36
37 class WindowAnimateToTest : public testing::Test {
38 public:
39 static void SetUpTestCase();
40 static void TearDownTestCase();
41 void SetUp() override;
42 void TearDown() override;
43 };
44
SetUpTestCase()45 void WindowAnimateToTest::SetUpTestCase() {}
46
TearDownTestCase()47 void WindowAnimateToTest::TearDownTestCase()
48 {
49 #ifdef RS_ENABLE_VK
50 RSModifiersDrawThread::Destroy();
51 #endif
52 }
53
SetUp()54 void WindowAnimateToTest::SetUp()
55 {
56 CommonTestUtils::GuaranteeFloatWindowPermission("wms_window_animation_transition_test");
57 }
58
TearDown()59 void WindowAnimateToTest::TearDown() {}
60
61 namespace {
62 /**
63 * @tc.name: AnimateTo
64 * @tc.desc: 测试WindowManager::AnimateTo接口的完整通路.
65 * @tc.type: FUNC
66 * @tc.require: issueI5NDLK
67 */
68 HWTEST_F(WindowAnimateToTest, AnimateTo01, TestSize.Level1)
69 {
70 WindowAnimationOption animationOption;
71 WindowAnimationProperty animationProperty;
72 if (!SceneBoardJudgement::IsSceneBoardEnabled()) {
73 ASSERT_EQ(WMError::WM_ERROR_DEVICE_NOT_SUPPORT,
74 WindowManager::GetInstance().AnimateTo(0, animationProperty, animationOption));
75 GTEST_SKIP() << "AnimateTo01 not support if IsSceneBoardEnabled() return false";
76 }
77
78 FocusChangeInfo focusInfo;
79 WindowManager::GetInstance().GetFocusWindowInfo(focusInfo);
80 sleep(1);
81 if (focusInfo.windowId_ == 0 || focusInfo.windowId_ == INVALID_WINDOW_ID) {
82 // 功能特有测试,依赖存在前台获焦窗口,所以当没有获焦窗口ID时返回DO_NOTHING;
83 ASSERT_EQ(WMError::WM_DO_NOTHING,
84 WindowManager::GetInstance().AnimateTo(focusInfo.windowId_, animationProperty, animationOption));
85 GTEST_SKIP() << "If windowId is 0 or INVALID_WINDOW_ID, break out";
86 }
87 animationOption.curve = WindowAnimationCurve::LINEAR;
88 animationOption.duration = 100; // 100ms
89 animationProperty.targetScale = 0.5f;
90 if (WindowHelper::IsSystemWindow(focusInfo.windowType_)) {
91 ASSERT_EQ(WMError::WM_DO_NOTHING,
92 WindowManager::GetInstance().AnimateTo(focusInfo.windowId_, animationProperty, animationOption));
93 } else {
94 ASSERT_EQ(WMError::WM_OK,
95 WindowManager::GetInstance().AnimateTo(focusInfo.windowId_, animationProperty, animationOption));
96 }
97 }
98
99 /**
100 * @tc.name: AnimateTo
101 * @tc.desc: test founction WindowManager::AnimateTo with windowId 0.
102 * @tc.type: FUNC
103 * @tc.require: issueI5NDLK
104 */
105 HWTEST_F(WindowAnimateToTest, AnimateTo02, TestSize.Level1)
106 {
107 WindowAnimationOption animationOption;
108 WindowAnimationProperty animationProperty;
109 if (!SceneBoardJudgement::IsSceneBoardEnabled()) {
110 GTEST_SKIP() << "AnimateTo02 not support if IsSceneBoardEnabled() return false";
111 }
112
113 animationOption.curve = WindowAnimationCurve::LINEAR;
114 animationOption.duration = 100; // 100ms
115 animationProperty.targetScale = 0.5f;
116 ASSERT_EQ(WMError::WM_DO_NOTHING,
117 WindowManager::GetInstance().AnimateTo(MAX_WINDOW_ID, animationProperty, animationOption));
118 }
119 } // namespace
120 } // namespace Rosen
121 } // namespace OHOS
122