!1398 增加自定义动画属性的UT/ST,旋转动画关联issue

Merge pull request !1398 from chenhaiying/m3
This commit is contained in:
openharmony_ci 2022-08-23 06:14:37 +00:00 committed by Gitee
commit 51ab2b9993
No known key found for this signature in database
GPG Key ID: 173E9B9CA92EEF8F
6 changed files with 304 additions and 8 deletions

View File

@ -739,6 +739,7 @@ HWTEST_F(ScreenManagerTest, ScreenManager15, Function | MediumTest | Level2)
* @tc.name: ScreenManager16
* @tc.desc: Screen orientation.
* @tc.type: FUNC
* @tc.require: issueI5NDLK
*/
HWTEST_F(ScreenManagerTest, ScreenManager16, Function | MediumTest | Level2)
{

View File

@ -20,6 +20,7 @@ group("systemtest") {
testonly = true
deps = [
":wms_window_animation_transition_test",
":wms_window_app_floating_window_test",
":wms_window_dialogwindow_test",
":wms_window_drag_test",
@ -219,6 +220,14 @@ ohos_systemtest("wms_window_app_floating_window_test") {
deps = [ ":wms_systemtest_common" ]
}
ohos_systemtest("wms_window_animation_transition_test") {
module_out_path = module_out_path
sources = [ "window_animation_transition_test.cpp" ]
deps = [ ":wms_systemtest_common" ]
}
## Build wms_systemtest_common.a {{{
config("wms_systemtest_common_public_config") {
include_dirs = [

View File

@ -0,0 +1,173 @@
/*
* Copyright (c) 2022 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
// gtest
#include <gtest/gtest.h>
#include "window.h"
#include "window_test_utils.h"
using namespace testing;
using namespace testing::ext;
namespace OHOS {
namespace Rosen {
namespace {
constexpr HiviewDFX::HiLogLabel LABEL = {LOG_CORE, HILOG_DOMAIN_WINDOW, "WindowAnimationTest"};
}
using Utils = WindowTestUtils;
class TestAnimationTransitionController : public IAnimationTransitionController {
public:
explicit TestAnimationTransitionController(sptr<Window> window) : window_(window) {}
void AnimationForShown() override;
void AnimationForHidden() override;
private:
sptr<Window> window_ = nullptr;
};
class WindowAnimationTransitionTest : public testing::Test {
public:
static void SetUpTestCase();
static void TearDownTestCase();
virtual void SetUp() override;
virtual void TearDown() override;
sptr<TestAnimationTransitionController> testAnimationTransitionListener_;
Utils::TestWindowInfo windowInfo_;
Transform trans_;
Transform defaultTrans_;
};
void TestAnimationTransitionController::AnimationForShown()
{
WLOGFI("TestAnimationTransitionController AnimationForShown");
Transform trans;
window_->SetTransform(trans);
}
void TestAnimationTransitionController::AnimationForHidden()
{
WLOGFI("TestAnimationTransitionController AnimationForHidden");
Transform trans;
trans.pivotX_ = 1.0f;
trans.pivotY_ = 0.6f;
window_->SetTransform(trans);
}
void WindowAnimationTransitionTest::SetUpTestCase()
{
}
void WindowAnimationTransitionTest::TearDownTestCase()
{
}
void WindowAnimationTransitionTest::SetUp()
{
windowInfo_ = {
.name = "TestWindow",
.rect = {0, 0, 100, 200},
.type = WindowType::WINDOW_TYPE_FLOAT,
.mode = WindowMode::WINDOW_MODE_FLOATING,
.needAvoid = false,
.parentLimit = false,
.parentName = "",
};
trans_.pivotX_ = 1.0f;
trans_.pivotY_ = 0.6f;
}
void WindowAnimationTransitionTest::TearDown()
{
}
namespace {
/**
* @tc.name: AnimationTransitionTest01
* @tc.desc: Register AnimationController and hide with custom animation
* @tc.type: FUNC
* @tc.require: issueI5NDLK
*/
HWTEST_F(WindowAnimationTransitionTest, AnimationTransitionTest01, Function | MediumTest | Level3)
{
const sptr<Window>& window = Utils::CreateTestWindow(windowInfo_);
ASSERT_NE(nullptr, window);
sptr<TestAnimationTransitionController> testAnimationTransitionListener =
new TestAnimationTransitionController(window);
window->RegisterAnimationTransitionController(testAnimationTransitionListener);
ASSERT_EQ(WMError::WM_OK, window->Show());
usleep(500000); // 500000us = 0.5s
ASSERT_EQ(WMError::WM_OK, window->Hide(0, true));
usleep(500000); // 500000us = 0.5s
ASSERT_TRUE(trans_ == window->GetTransform());
ASSERT_EQ(WMError::WM_OK, window->Destroy());
}
/**
* @tc.name: AnimationTransitionTest02
* @tc.desc: Register AnimationController and show without animation
* @tc.type: FUNC
* @tc.require: issueI5NDLK
*/
HWTEST_F(WindowAnimationTransitionTest, AnimationTransitionTest02, Function | MediumTest | Level3)
{
const sptr<Window>& window = Utils::CreateTestWindow(windowInfo_);
ASSERT_NE(nullptr, window);
sptr<TestAnimationTransitionController> testAnimationTransitionListener =
new TestAnimationTransitionController(window);
window->RegisterAnimationTransitionController(testAnimationTransitionListener);
ASSERT_EQ(WMError::WM_OK, window->Show());
usleep(500000); // 500000us = 0.5s
ASSERT_TRUE(defaultTrans_ == window->GetTransform());
ASSERT_EQ(WMError::WM_OK, window->Destroy());
}
/**
* @tc.name: AnimationTransitionTest03
* @tc.desc: hide with default animation without register animationController
* @tc.type: FUNC
* @tc.require: issueI5NDLK
*/
HWTEST_F(WindowAnimationTransitionTest, AnimationTransitionTest03, Function | MediumTest | Level3)
{
const sptr<Window>& window = Utils::CreateTestWindow(windowInfo_);
ASSERT_NE(nullptr, window);
ASSERT_EQ(WMError::WM_OK, window->Hide(0, true));
usleep(500000); // 500000us = 0.5s
ASSERT_TRUE(defaultTrans_ == window->GetTransform());
ASSERT_EQ(WMError::WM_OK, window->Destroy());
}
/**
* @tc.name: AnimationTransitionTest04
* @tc.desc: hide without custom animation and register animationController
* @tc.type: FUNC
* @tc.require: issueI5NDLK
*/
HWTEST_F(WindowAnimationTransitionTest, AnimationTransitionTest04, Function | MediumTest | Level3)
{
const sptr<Window>& window = Utils::CreateTestWindow(windowInfo_);
ASSERT_NE(nullptr, window);
sptr<TestAnimationTransitionController> testAnimationTransitionListener =
new TestAnimationTransitionController(window);
window->RegisterAnimationTransitionController(testAnimationTransitionListener);
ASSERT_EQ(WMError::WM_OK, window->Show());
usleep(500000); // 500000us = 0.5s
ASSERT_EQ(WMError::WM_OK, window->Hide());
ASSERT_TRUE(defaultTrans_ == window->GetTransform());
ASSERT_EQ(WMError::WM_OK, window->Destroy());
}
}
} // namespace Rosen
} // namespace OHOS

View File

@ -429,7 +429,7 @@ private:
std::vector<sptr<IOccupiedAreaChangeListener>> occupiedAreaChangeListeners_;
sptr<IDialogDeathRecipientListener> dialogDeathRecipientListener_;
std::shared_ptr<IInputEventConsumer> inputEventConsumer_;
sptr<IAnimationTransitionController> animationTranistionController_;
sptr<IAnimationTransitionController> animationTransitionController_;
NotifyNativeWinDestroyFunc notifyNativefunc_;
std::shared_ptr<RSSurfaceNode> surfaceNode_;
std::string name_;

View File

@ -391,8 +391,14 @@ void WindowImpl::SetTransform(const Transform& trans)
if (!IsWindowValid()) {
return;
}
Transform oriTrans = property_->GetTransform();
property_->SetTransform(trans);
UpdateProperty(PropertyChangeAction::ACTION_UPDATE_TRANSFORM_PROPERTY);
WMError ret = UpdateProperty(PropertyChangeAction::ACTION_UPDATE_TRANSFORM_PROPERTY);
if (ret != WMError::WM_OK) {
WLOGFE("SetTransform errCode:%{public}d winId:%{public}u",
static_cast<int32_t>(ret), property_->GetWindowId());
property_->SetTransform(oriTrans); // reset to ori transform when update failed
}
}
const Transform& WindowImpl::GetTransform() const
@ -1272,7 +1278,7 @@ WMError WindowImpl::Hide(uint32_t reason, bool withAnimation)
NotifyAfterBackground();
uint32_t animationFlag = property_->GetAnimationFlag();
if (animationFlag == static_cast<uint32_t>(WindowAnimation::CUSTOM)) {
animationTranistionController_->AnimationForHidden();
animationTransitionController_->AnimationForHidden();
}
ResetMoveOrDragState();
return ret;
@ -1870,9 +1876,9 @@ void WindowImpl::RegisterAnimationTransitionController(const sptr<IAnimationTran
WLOGFE("listener is nullptr");
return;
}
animationTranistionController_ = listener;
animationTransitionController_ = listener;
wptr<WindowProperty> propertyToken(property_);
wptr<IAnimationTransitionController> animationTransitionControllerToken(animationTranistionController_);
wptr<IAnimationTransitionController> animationTransitionControllerToken(animationTransitionController_);
if (uiContent_) {
uiContent_->SetNextFrameLayoutCallback([propertyToken, animationTransitionControllerToken]() {
auto property = propertyToken.promote();
@ -1882,7 +1888,7 @@ void WindowImpl::RegisterAnimationTransitionController(const sptr<IAnimationTran
}
uint32_t animationFlag = property->GetAnimationFlag();
if (animationFlag == static_cast<uint32_t>(WindowAnimation::CUSTOM)) {
// CustomAnimation is enabled when animationTranistionController_ exists
// CustomAnimation is enabled when animationTransitionController_ exists
animationTransitionController->AnimationForShown();
}
});
@ -2350,10 +2356,10 @@ void WindowImpl::AdjustWindowAnimationFlag(bool withAnimation)
// use custom animation when transitionController exists; else use default animation
WindowType winType = property_->GetWindowType();
bool isAppWindow = WindowHelper::IsAppWindow(winType);
if (withAnimation && !isAppWindow && animationTranistionController_) {
if (withAnimation && !isAppWindow && animationTransitionController_) {
// use custom animation
property_->SetAnimationFlag(static_cast<uint32_t>(WindowAnimation::CUSTOM));
} else if (isAppWindow || (withAnimation && !animationTranistionController_)) {
} else if (isAppWindow || (withAnimation && !animationTransitionController_)) {
// use default animation
property_->SetAnimationFlag(static_cast<uint32_t>(WindowAnimation::DEFAULT));
} else if (winType == WindowType::WINDOW_TYPE_INPUT_METHOD_FLOAT) {

View File

@ -1317,6 +1317,113 @@ HWTEST_F(WindowImplTest, SetTouchHotAreas01, Function | SmallTest | Level3)
EXPECT_CALL(m->Mock(), DestroyWindow(_)).Times(1).WillOnce(Return(WMError::WM_OK));
ASSERT_EQ(WMError::WM_OK, window->Destroy());
}
/**
* @tc.name: SetTransform01
* @tc.desc: set transform
* @tc.type: FUNC
* @tc.require: issueI5NDLK
*/
HWTEST_F(WindowImplTest, SetTransform01, Function | SmallTest | Level3)
{
std::unique_ptr<Mocker> m = std::make_unique<Mocker>();
sptr<WindowOption> option = new WindowOption();
option->SetWindowName("SetTransform01");
sptr<WindowImpl> window = new WindowImpl(option);
EXPECT_CALL(m->Mock(), CreateWindow(_, _, _, _, _)).Times(1).WillOnce(Return(WMError::WM_OK));
ASSERT_EQ(WMError::WM_OK, window->Create(""));
window->DisableAppWindowDecor();
EXPECT_CALL(m->Mock(), AddWindow(_)).Times(1).WillOnce(Return(WMError::WM_OK));
ASSERT_EQ(WMError::WM_OK, window->Show());
EXPECT_CALL(m->Mock(), UpdateProperty(_, _)).Times(1).WillOnce(Return(WMError::WM_ERROR_SAMGR));
Transform trans_;
window->SetTransform(trans_);
ASSERT_TRUE(trans_ == window->GetTransform());
EXPECT_CALL(m->Mock(), DestroyWindow(_)).Times(1).WillOnce(Return(WMError::WM_OK));
ASSERT_EQ(WMError::WM_OK, window->Destroy());
}
/**
* @tc.name: SetTransform02
* @tc.desc: set transform and getTransform
* @tc.type: FUNC
* @tc.require: issueI5NDLK
*/
HWTEST_F(WindowImplTest, SetTransform02, Function | SmallTest | Level3)
{
std::unique_ptr<Mocker> m = std::make_unique<Mocker>();
sptr<WindowOption> option = new WindowOption();
option->SetWindowName("SetTransform01");
sptr<WindowImpl> window = new WindowImpl(option);
EXPECT_CALL(m->Mock(), CreateWindow(_, _, _, _, _)).Times(1).WillOnce(Return(WMError::WM_OK));
ASSERT_EQ(WMError::WM_OK, window->Create(""));
window->DisableAppWindowDecor();
EXPECT_CALL(m->Mock(), AddWindow(_)).Times(1).WillOnce(Return(WMError::WM_OK));
ASSERT_EQ(WMError::WM_OK, window->Show());
EXPECT_CALL(m->Mock(), UpdateProperty(_, _)).Times(1).WillOnce(Return(WMError::WM_ERROR_SAMGR));
Transform trans_;
trans_.pivotX_ = 1.0f;
trans_.pivotY_ = 0.6f;
window->SetTransform(trans_);
ASSERT_TRUE(trans_ != window->GetTransform());
EXPECT_CALL(m->Mock(), DestroyWindow(_)).Times(1).WillOnce(Return(WMError::WM_OK));
ASSERT_EQ(WMError::WM_OK, window->Destroy());
}
/**
* @tc.name: SetTransform03
* @tc.desc: set transform and getTransform
* @tc.type: FUNC
* @tc.require: issueI5NDLK
*/
HWTEST_F(WindowImplTest, SetTransform03, Function | SmallTest | Level3)
{
std::unique_ptr<Mocker> m = std::make_unique<Mocker>();
sptr<WindowOption> option = new WindowOption();
option->SetWindowName("SetTransform01");
sptr<WindowImpl> window = new WindowImpl(option);
EXPECT_CALL(m->Mock(), CreateWindow(_, _, _, _, _)).Times(1).WillOnce(Return(WMError::WM_OK));
ASSERT_EQ(WMError::WM_OK, window->Create(""));
window->DisableAppWindowDecor();
EXPECT_CALL(m->Mock(), AddWindow(_)).Times(1).WillOnce(Return(WMError::WM_OK));
ASSERT_EQ(WMError::WM_OK, window->Show());
EXPECT_CALL(m->Mock(), UpdateProperty(_, _)).Times(1).WillOnce(Return(WMError::WM_OK));
Transform trans_;
trans_.pivotX_ = 1.0f;
trans_.pivotY_ = 0.6f;
window->SetTransform(trans_);
ASSERT_TRUE(trans_ == window->GetTransform());
EXPECT_CALL(m->Mock(), DestroyWindow(_)).Times(1).WillOnce(Return(WMError::WM_OK));
ASSERT_EQ(WMError::WM_OK, window->Destroy());
}
/**
* @tc.name: SetTransform04
* @tc.desc: set transform and getTransform
* @tc.type: FUNC
* @tc.require: issueI5NDLK
*/
HWTEST_F(WindowImplTest, SetTransform04, Function | SmallTest | Level3)
{
std::unique_ptr<Mocker> m = std::make_unique<Mocker>();
sptr<WindowOption> option = new WindowOption();
option->SetWindowName("SetTransform01");
sptr<WindowImpl> window = new WindowImpl(option);
EXPECT_CALL(m->Mock(), CreateWindow(_, _, _, _, _)).Times(1).WillOnce(Return(WMError::WM_OK));
ASSERT_EQ(WMError::WM_OK, window->Create(""));
window->DisableAppWindowDecor();
EXPECT_CALL(m->Mock(), AddWindow(_)).Times(1).WillOnce(Return(WMError::WM_OK));
ASSERT_EQ(WMError::WM_OK, window->Show());
EXPECT_CALL(m->Mock(), UpdateProperty(_, _)).Times(1).WillOnce(Return(WMError::WM_OK));
Transform trans_;
trans_.pivotX_ = 1.0f;
trans_.pivotY_ = 0.6f;
Transform defaultTrans_;
window->SetTransform(trans_);
ASSERT_TRUE(defaultTrans_ != window->GetTransform());
EXPECT_CALL(m->Mock(), DestroyWindow(_)).Times(1).WillOnce(Return(WMError::WM_OK));
ASSERT_EQ(WMError::WM_OK, window->Destroy());
}
}
} // namespace Rosen
} // namespace OHOS