add_raisetotop_tdd

Signed-off-by: zhangkai <zhangkai324@huawei.com>
Change-Id: I733c0c936ab39c2db770e468f238e43eeaa8212e
This commit is contained in:
zhangkai 2023-01-30 10:16:09 +08:00
parent 627dd949d6
commit 5baee2e8c4
5 changed files with 315 additions and 0 deletions

View File

@ -36,6 +36,7 @@ group("systemtest") {
":wms_window_move_drag_test",
":wms_window_multi_ability_test",
":wms_window_occupied_area_change_test",
":wms_window_raisetoapptop_test",
":wms_window_rotation_test",
":wms_window_split_immersive_test",
":wms_window_split_test",
@ -190,6 +191,14 @@ ohos_systemtest("wms_window_drag_test") {
deps = [ ":wms_systemtest_common" ]
}
ohos_systemtest("wms_window_raisetoapptop_test") {
module_out_path = module_out_path
sources = [ "window_raisetoapptop_test.cpp" ]
deps = [ ":wms_systemtest_common" ]
}
ohos_systemtest("wms_window_rotation_test") {
module_out_path = module_out_path

View File

@ -0,0 +1,227 @@
/*
* Copyright (c) 2023 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_test_utils.h"
#include "window_impl.h"
#include "wm_common.h"
using namespace testing;
using namespace testing::ext;
namespace OHOS {
namespace Rosen {
using Utils = WindowTestUtils;
class WindowRaiseToAppTopTest : public testing::Test {
public:
static void SetUpTestCase();
static void TearDownTestCase();
void SetUp() override;
void TearDown() override;
std::vector<sptr<Window>> activeWindows_;
Utils::TestWindowInfo fullInfo_;
private:
static constexpr uint32_t TEST_SLEEP_S = 1;
};
void WindowRaiseToAppTopTest::SetUpTestCase()
{
}
void WindowRaiseToAppTopTest::TearDownTestCase()
{
}
void WindowRaiseToAppTopTest::SetUp()
{
fullInfo_ = {
.name = "",
.rect = Utils::customAppRect_,
.type = WindowType::WINDOW_TYPE_APP_MAIN_WINDOW,
.parentId = INVALID_WINDOW_ID,
};
activeWindows_.clear();
}
void WindowRaiseToAppTopTest::TearDown()
{
while (!activeWindows_.empty()) {
ASSERT_EQ(WMError::WM_OK, activeWindows_.back()->Destroy());
activeWindows_.pop_back();
}
}
namespace {
/**
* @tc.name: WindowRaiseToAppTopTest1
* @tc.desc: to raise to app top, normal
* @tc.type: FUNC
*/
HWTEST_F(WindowRaiseToAppTopTest, NormalRaise1, Function | MediumTest | Level3)
{
fullInfo_.name = "mainWindow.1";
sptr<Window> mainWindow = Utils::CreateTestWindow(fullInfo_);
ASSERT_NE(nullptr, mainWindow);
activeWindows_.push_back(mainWindow);
ASSERT_EQ(WMError::WM_OK, mainWindow->Show());
sleep(TEST_SLEEP_S);
fullInfo_.name = "subWindow.1";
fullInfo_.type = WindowType::WINDOW_TYPE_APP_SUB_WINDOW;
fullInfo_.parentId = mainWindow->GetWindowId();
sptr<Window> subWindow1 = Utils::CreateTestWindow(fullInfo_);
ASSERT_NE(nullptr, subWindow1);
activeWindows_.push_back(subWindow1);
ASSERT_EQ(WMError::WM_OK, subWindow1->Show());
sleep(TEST_SLEEP_S);
fullInfo_.name = "subWindow.2";
fullInfo_.type = WindowType::WINDOW_TYPE_APP_SUB_WINDOW;
fullInfo_.parentId = mainWindow->GetWindowId();
sptr<Window> subWindow2 = Utils::CreateTestWindow(fullInfo_);
ASSERT_NE(nullptr, subWindow2);
activeWindows_.push_back(subWindow2);
ASSERT_EQ(WMError::WM_OK, subWindow2->Show());
sleep(TEST_SLEEP_S);
auto result1 = mainWindow->RaiseToAppTop();
ASSERT_EQ(WmErrorCode::WM_ERROR_INVALID_PARENT, result1);
auto result2 = subWindow1->RaiseToAppTop();
ASSERT_EQ(WmErrorCode::WM_OK, result2);
}
/**
* @tc.name: WindowRaiseToAppTopTest2
* @tc.desc: to raise to app top, with dialog
* @tc.type: FUNC
*/
HWTEST_F(WindowRaiseToAppTopTest, RaiseWithDialog1, Function | MediumTest | Level3)
{
fullInfo_.name = "mainWindow.1";
sptr<Window> mainWindow = Utils::CreateTestWindow(fullInfo_);
ASSERT_NE(nullptr, mainWindow);
activeWindows_.push_back(mainWindow);
ASSERT_EQ(WMError::WM_OK, mainWindow->Show());
sleep(TEST_SLEEP_S);
fullInfo_.name = "subWindow.1";
fullInfo_.type = WindowType::WINDOW_TYPE_APP_SUB_WINDOW;
fullInfo_.parentId = mainWindow->GetWindowId();
sptr<Window> subWindow1 = Utils::CreateTestWindow(fullInfo_);
ASSERT_NE(nullptr, subWindow1);
activeWindows_.push_back(subWindow1);
ASSERT_EQ(WMError::WM_OK, subWindow1->Show());
sleep(TEST_SLEEP_S);
fullInfo_.name = "subWindow.2";
fullInfo_.type = WindowType::WINDOW_TYPE_APP_SUB_WINDOW;
fullInfo_.parentId = mainWindow->GetWindowId();
sptr<Window> subWindow2 = Utils::CreateTestWindow(fullInfo_);
ASSERT_NE(nullptr, subWindow2);
activeWindows_.push_back(subWindow2);
ASSERT_EQ(WMError::WM_OK, subWindow2->Show());
sleep(TEST_SLEEP_S);
fullInfo_.name = "dialog.2";
fullInfo_.type = WindowType::WINDOW_TYPE_DIALOG;
fullInfo_.parentId = INVALID_WINDOW_ID;
sptr<Window> dialog = Utils::CreateTestWindow(fullInfo_);
ASSERT_NE(nullptr, dialog);
activeWindows_.push_back(dialog);
ASSERT_EQ(WMError::WM_OK, dialog->Show());
sleep(TEST_SLEEP_S);
auto result = subWindow1->RaiseToAppTop();
ASSERT_EQ(WmErrorCode::WM_OK, result);
}
/**
* @tc.name: WindowRaiseToAppTopTest3
* @tc.desc: to raise to app top, in hide
* @tc.type: FUNC
*/
HWTEST_F(WindowRaiseToAppTopTest, RaiseWhenHide, Function | MediumTest | Level3)
{
fullInfo_.name = "mainWindow.1";
sptr<Window> mainWindow = Utils::CreateTestWindow(fullInfo_);
ASSERT_NE(nullptr, mainWindow);
activeWindows_.push_back(mainWindow);
ASSERT_EQ(WMError::WM_OK, mainWindow->Show());
sleep(TEST_SLEEP_S);
fullInfo_.name = "subWindow.1";
fullInfo_.type = WindowType::WINDOW_TYPE_APP_SUB_WINDOW;
fullInfo_.parentId = mainWindow->GetWindowId();
sptr<Window> subWindow1 = Utils::CreateTestWindow(fullInfo_);
ASSERT_NE(nullptr, subWindow1);
activeWindows_.push_back(subWindow1);
ASSERT_EQ(WMError::WM_OK, subWindow1->Show());
sleep(TEST_SLEEP_S);
fullInfo_.name = "subWindow.2";
fullInfo_.type = WindowType::WINDOW_TYPE_APP_SUB_WINDOW;
fullInfo_.parentId = mainWindow->GetWindowId();
sptr<Window> subWindow2 = Utils::CreateTestWindow(fullInfo_);
ASSERT_NE(nullptr, subWindow2);
activeWindows_.push_back(subWindow2);
ASSERT_EQ(WMError::WM_OK, subWindow2->Show());
sleep(TEST_SLEEP_S);
ASSERT_EQ(WMError::WM_OK, mainWindow->Hide());
sleep(TEST_SLEEP_S);
auto result = subWindow1->RaiseToAppTop();
ASSERT_EQ(WmErrorCode::WM_OK, result);
ASSERT_EQ(WMError::WM_OK, subWindow1->Hide());
sleep(TEST_SLEEP_S);
result = subWindow1->RaiseToAppTop();
ASSERT_EQ(WmErrorCode::WM_ERROR_STATE_ABNORMALLY, result);
}
/**
* @tc.name: WindowRaiseToAppTopTest3
* @tc.desc: to raise to app top, not app subwindow
* @tc.type: FUNC
*/
HWTEST_F(WindowRaiseToAppTopTest, NotAppSubWindow, Function | MediumTest | Level3)
{
fullInfo_.name = "mainWindow.1";
fullInfo_.type = WindowType::WINDOW_TYPE_FLOAT;
sptr<Window> mainWindow = Utils::CreateTestWindow(fullInfo_);
ASSERT_NE(nullptr, mainWindow);
activeWindows_.push_back(mainWindow);
ASSERT_EQ(WMError::WM_OK, mainWindow->Show());
sleep(TEST_SLEEP_S);
fullInfo_.name = "subWindow.1";
fullInfo_.type = WindowType::WINDOW_TYPE_SYSTEM_SUB_WINDOW;
fullInfo_.parentId = mainWindow->GetWindowId();
sptr<Window> subWindow1 = Utils::CreateTestWindow(fullInfo_);
ASSERT_NE(nullptr, subWindow1);
activeWindows_.push_back(subWindow1);
ASSERT_EQ(WMError::WM_OK, subWindow1->Show());
sleep(TEST_SLEEP_S);
auto result = subWindow1->RaiseToAppTop();
ASSERT_EQ(WmErrorCode::WM_ERROR_INVALID_CALLING, result);
}
}
} // namespace Rosen
} // namespace OHOS

View File

@ -3115,6 +3115,34 @@ HWTEST_F(WindowImplTest, UpdateWindowStateWhenShow, Function | SmallTest | Level
EXPECT_CALL(m->Mock(), DestroyWindow(_)).Times(1).WillOnce(Return(WMError::WM_OK));
ASSERT_EQ(WMError::WM_OK, mainWindow->Destroy());
}
/*
* @tc.name: RaiseToAppTop
* @tc.desc: RaiseToAppTop test
* @tc.type: FUNC
*/
HWTEST_F(WindowImplTest, RaiseToAppTop, Function | SmallTest | Level3)
{
sptr<WindowOption> option = new WindowOption();
option->parentId_ = INVALID_WINDOW_ID;
sptr<WindowImpl> window = new WindowImpl(option);
ASSERT_EQ(WmErrorCode::WM_ERROR_INVALID_PARENT, window->RaiseToAppTop());
window->property_->parentId_ = 100000;
window->property_->SetWindowType(WindowType::WINDOW_TYPE_APP_MAIN_WINDOW);
ASSERT_EQ(WmErrorCode::WM_ERROR_INVALID_CALLING, window->RaiseToAppTop());
window->property_->SetWindowType(WindowType::WINDOW_TYPE_APP_SUB_WINDOW);
window->state_ = WindowState::STATE_HIDDEN;
ASSERT_EQ(WmErrorCode::WM_ERROR_STATE_ABNORMALLY, window->RaiseToAppTop());
window->state_ = WindowState::STATE_SHOWN;
EXPECT_CALL(m->Mock(), RaiseToAppTop(_)).Times(1).WillOnce(Return(WmErrorCode::WM_OK));
ASSERT_EQ(WmErrorCode::WM_OK, window->RaiseToAppTop());
EXPECT_CALL(m->Mock(), DestroyWindow(_)).Times(1).WillOnce(Return(WMError::WM_OK));
ASSERT_EQ(WMError::WM_OK, window->Destroy());
}
}
} // namespace Rosen
} // namespace OHOS

View File

@ -14,6 +14,8 @@
*/
#include <gtest/gtest.h>
#include <map>
#include "display_manager.h"
#include "iremote_object_mocker.h"
#include "mock_rs_iwindow_animation_controller.h"
#include "remote_animation.h"
@ -513,6 +515,36 @@ HWTEST_F(WindowControllerTest, BindDialogTarget, Function | SmallTest | Level3)
ASSERT_EQ(WMError::WM_OK, windowController_->BindDialogTarget(id, abilityTokenMocker));
windowRoot_->windowNodeMap_.clear();
}
/**
* @tc.name: RaiseToAppTop
* @tc.desc: check app subwindow raise to top
* @tc.type: FUNC
*/
HWTEST_F(WindowControllerTest, RaiseToAppTop, Function | SmallTest | Level3)
{
windowRoot_->windowNodeMap_.clear();
sptr<WindowNode> windowNode = new (std::nothrow)WindowNode();
windowNode->property_->windowId_ = 100;
windowNode->SetDisplayId(DISPLAY_ID_INVALID);
uint32_t windowId = windowNode->GetWindowId();
ASSERT_EQ(WmErrorCode::WM_ERROR_STATE_ABNORMALLY, windowController_->RaiseToAppTop(windowId));
windowRoot_->windowNodeMap_.insert(std::make_pair(windowNode->GetWindowId(), windowNode));
ASSERT_EQ(WmErrorCode::WM_ERROR_INVALID_PARENT, windowController_->RaiseToAppTop(windowId));
sptr<WindowNode> parentWindow = new (std::nothrow)WindowNode();
parentWindow->property_->windowId_ = 90;
parentWindow->SetDisplayId(DISPLAY_ID_INVALID);
windowRoot_->windowNodeMap_.insert(std::make_pair(parentWindow->GetWindowId(), parentWindow));
windowNode->parent_ = parentWindow;
ASSERT_EQ(WmErrorCode::WM_ERROR_STAGE_ABNORMALLY, windowController_->RaiseToAppTop(windowId));
windowRoot_->windowNodeMap_.clear();
}
}
}
}

View File

@ -495,6 +495,25 @@ HWTEST_F(WindowManagerStubTest, OnRemoteRequest20, Function | SmallTest | Level2
EXPECT_EQ(res, 0);
}
/**
* @tc.name: OnRemoteRequest20
* @tc.desc: test TRANS_ID_RAISE_WINDOW_Z_ORDER success
* @tc.type: FUNC
*/
HWTEST_F(WindowManagerStubTest, OnRemoteRequest21, Function | SmallTest | Level2)
{
MessageParcel data;
MessageParcel reply;
MessageOption option;
data.WriteInterfaceToken(WindowManagerStub::GetDescriptor());
data.WriteUint32(100);
uint32_t code = static_cast<uint32_t>(IWindowManager::WindowManagerMessage::TRANS_ID_RAISE_WINDOW_Z_ORDER);
int res = stub_->OnRemoteRequest(code, data, reply, option);
EXPECT_EQ(res, 0);
}
}
}
}