From ecc128e23faffce96a53f13e87b91856b103a342 Mon Sep 17 00:00:00 2001 From: d00347686 Date: Fri, 29 Jul 2022 03:53:28 +0000 Subject: [PATCH] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E9=9A=90=E7=A7=81=E7=AA=97?= =?UTF-8?q?=E5=8F=A3=E6=9F=A5=E8=AF=A2=E7=9A=84=E6=B5=8B=E8=AF=95=E7=94=A8?= =?UTF-8?q?=E4=BE=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: d00347686 Change-Id: I2a167949bb3c2cf4fb006970851aae92068a424e --- test/systemtest/dms/BUILD.gn | 9 + test/systemtest/dms/display_manager_test.cpp | 250 +++++++++++++++++++ 2 files changed, 259 insertions(+) create mode 100644 test/systemtest/dms/display_manager_test.cpp diff --git a/test/systemtest/dms/BUILD.gn b/test/systemtest/dms/BUILD.gn index 8296b0f5..9abb270a 100644 --- a/test/systemtest/dms/BUILD.gn +++ b/test/systemtest/dms/BUILD.gn @@ -20,6 +20,7 @@ group("systemtest") { deps = [ ":dms_display_change_test", + ":dms_display_manager_test", ":dms_display_minimal_test", ":dms_display_power_test", ":dms_screen_manager_test", @@ -35,6 +36,14 @@ ohos_systemtest("dms_display_minimal_test") { deps = [ ":dms_systemtest_common" ] } +ohos_systemtest("dms_display_manager_test") { + module_out_path = module_out_path + + sources = [ "display_manager_test.cpp" ] + + deps = [ ":dms_systemtest_common" ] +} + ohos_systemtest("dms_display_power_test") { module_out_path = module_out_path diff --git a/test/systemtest/dms/display_manager_test.cpp b/test/systemtest/dms/display_manager_test.cpp new file mode 100644 index 00000000..b70a58ab --- /dev/null +++ b/test/systemtest/dms/display_manager_test.cpp @@ -0,0 +1,250 @@ +/* + * 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. + */ +#include +#include +#include "display_test_utils.h" +#include "display.h" +#include "screen.h" +#include "surface_draw.h" +#include "wm_common.h" +#include "window.h" +#include "window_option.h" +#include "window_manager_hilog.h" + +using namespace testing; +using namespace testing::ext; + +namespace OHOS::Rosen { +namespace { + constexpr HiviewDFX::HiLogLabel LABEL = {LOG_CORE, HILOG_DOMAIN_WINDOW, "DisplayManagerTest"}; + const int WAIT_FOR_SYNC_US = 1000 * 500; // 500ms +} + +class DisplayManagerTest : public testing::Test { +public: + static void SetUpTestCase(); + static void TearDownTestCase(); + virtual void SetUp() override; + virtual void TearDown() override; + + sptr CreateWindow(std::string name, WindowMode mode, Rect rect); + bool DrawWindowColor(const sptr& window, uint32_t color, int32_t width, int32_t height); + static inline DisplayId displayId_; + static inline int32_t displayWidth_; + static inline int32_t displayHeight_; +}; + +void DisplayManagerTest::SetUpTestCase() +{ + displayId_ = DisplayManager::GetInstance().GetDefaultDisplayId(); + sptr display = DisplayManager::GetInstance().GetDefaultDisplay(); + if (display == nullptr) { + return; + } + displayWidth_ = display->GetWidth(); + displayHeight_ = display->GetHeight(); +} + +void DisplayManagerTest::TearDownTestCase() +{ +} + +void DisplayManagerTest::SetUp() +{ +} + +void DisplayManagerTest::TearDown() +{ +} + +sptr DisplayManagerTest::CreateWindow(std::string name, WindowMode mode, Rect rect) +{ + sptr option = new WindowOption(); + option->SetDisplayId(displayId_); + option->SetWindowType(WindowType::WINDOW_TYPE_APP_MAIN_WINDOW); + int32_t width = 0; + int32_t height = 0; + if (mode != WindowMode::WINDOW_MODE_FULLSCREEN) { + option->SetWindowRect(rect); + width = rect.width_; + height = rect.height_; + } else { + width = displayWidth_; + height = displayHeight_; + } + option->SetWindowMode(mode); + option->SetWindowName(name); + sptr window = Window::Create(option->GetWindowName(), option); + DrawWindowColor(window, 0x66000000, width, height); // 0x66000000 color_black + window->AddWindowFlag(WindowFlag::WINDOW_FLAG_SHOW_WHEN_LOCKED); + RSTransaction::FlushImplicitTransaction(); + window->Show(); + return window; +} + +bool DisplayManagerTest::DrawWindowColor(const sptr& window, uint32_t color, int32_t width, int32_t height) +{ + auto surfaceNode = window->GetSurfaceNode(); + if (surfaceNode == nullptr) { + WLOGFE("Failed to GetSurfaceNode!"); + return false; + } + SurfaceDraw::DrawColor(surfaceNode, width, height, color); + surfaceNode->SetAbilityBGAlpha(255); // 255 is alpha + return true; +} + +namespace { +/** + * @tc.name: HasPrivateWindow + * @tc.desc: Check whether there is a private window in the current display + * @tc.type: FUNC + */ +HWTEST_F(DisplayManagerTest, HasPrivateWindow, Function | SmallTest | Level2) +{ + sptr window = CreateWindow("test", WindowMode::WINDOW_MODE_FULLSCREEN, Rect {0, 0, 0, 0}); + window->SetPrivacyMode(true); + usleep(WAIT_FOR_SYNC_US); + bool hasPrivateWindow = false; + DisplayId id = DisplayManager::GetInstance().GetDefaultDisplayId(); + DisplayManager::GetInstance().HasPrivateWindow(id, hasPrivateWindow); + ASSERT_TRUE(hasPrivateWindow); + + window->SetPrivacyMode(false); + usleep(WAIT_FOR_SYNC_US); + DisplayManager::GetInstance().HasPrivateWindow(id, hasPrivateWindow); + ASSERT_TRUE(!hasPrivateWindow); + window->Destroy(); +} + +/** + * @tc.name: HasPrivateWindowCovered + * @tc.desc: The private window is covered + * @tc.type: FUNC + */ +HWTEST_F(DisplayManagerTest, HasPrivateWindowCovered, Function | SmallTest | Level2) +{ + sptr window1 = CreateWindow("test", WindowMode::WINDOW_MODE_FULLSCREEN, Rect {0, 0, 0, 0}); + // 20:rect.posX_, 120:rect.posY_, 360:rect.width, 480:rect.height + sptr window2 = CreateWindow("private", WindowMode::WINDOW_MODE_FLOATING, Rect {20, 120, 360, 480}); + window2->SetPrivacyMode(true); + // 10:rect.posX_, 110:rect.posY_, 400:rect.width, 500:rect.height + sptr window3 = CreateWindow("covered", WindowMode::WINDOW_MODE_FLOATING, Rect {10, 110, 400, 500}); + usleep(WAIT_FOR_SYNC_US); + bool hasPrivateWindow = false; + DisplayId id = DisplayManager::GetInstance().GetDefaultDisplayId(); + DisplayManager::GetInstance().HasPrivateWindow(id, hasPrivateWindow); + ASSERT_TRUE(!hasPrivateWindow); + window1->Destroy(); + window2->Destroy(); + window3->Destroy(); +} + +/** + * @tc.name: HasPrivateWindowCovered01 + * @tc.desc: The private window is partially covered + * @tc.type: FUNC + */ +HWTEST_F(DisplayManagerTest, HasPrivateWindowCovered01, Function | SmallTest | Level2) +{ + sptr window1 = CreateWindow("test", WindowMode::WINDOW_MODE_FULLSCREEN, Rect {0, 0, 0, 0}); + // 20:rect.posX_, 120:rect.posY_, 360:rect.width, 480:rect.height + sptr window2 = CreateWindow("private", WindowMode::WINDOW_MODE_FLOATING, Rect {20, 120, 360, 480}); + window2->SetPrivacyMode(true); + // 10:rect.posX_, 110:rect.posY_, 360:rect.width, 480:rect.height + sptr window3 = CreateWindow("covered", WindowMode::WINDOW_MODE_FLOATING, Rect {10, 110, 360, 480}); + usleep(WAIT_FOR_SYNC_US); + bool hasPrivateWindow = false; + DisplayId id = DisplayManager::GetInstance().GetDefaultDisplayId(); + DisplayManager::GetInstance().HasPrivateWindow(id, hasPrivateWindow); + ASSERT_TRUE(hasPrivateWindow); + window1->Destroy(); + window2->Destroy(); + window3->Destroy(); +} + +/** + * @tc.name: HasPrivateWindowCovered02 + * @tc.desc: The private window is covered + * @tc.type: FUNC + */ +HWTEST_F(DisplayManagerTest, HasPrivateWindowCovered02, Function | SmallTest | Level2) +{ + sptr window1 = CreateWindow("test", WindowMode::WINDOW_MODE_FULLSCREEN, Rect {0, 0, 0, 0}); + // 20:rect.posX_, 120:rect.posY_, 360:rect.width, 480:rect.height + sptr window2 = CreateWindow("private", WindowMode::WINDOW_MODE_FLOATING, Rect {20, 120, 360, 480}); + window2->SetPrivacyMode(true); + // 10:rect.posX_, 110:rect.posY_, 380:rect.width, 480:rect.height + sptr window3 = CreateWindow("covered1", WindowMode::WINDOW_MODE_FLOATING, Rect {10, 110, 380, 480}); + // 10:rect.posX_, 300:rect.posY_, 380:rect.width, 480:rect.height + sptr window4 = CreateWindow("covered2", WindowMode::WINDOW_MODE_FLOATING, Rect {10, 300, 380, 480}); + usleep(WAIT_FOR_SYNC_US); + bool hasPrivateWindow = false; + DisplayId id = DisplayManager::GetInstance().GetDefaultDisplayId(); + DisplayManager::GetInstance().HasPrivateWindow(id, hasPrivateWindow); + ASSERT_TRUE(!hasPrivateWindow); + window1->Destroy(); + window2->Destroy(); + window3->Destroy(); + window4->Destroy(); +} + +/** + * @tc.name: HasPrivateWindowCovered03 + * @tc.desc: The private window is partially covered + * @tc.type: FUNC + */ +HWTEST_F(DisplayManagerTest, HasPrivateWindowCovered03, Function | SmallTest | Level2) +{ + sptr window1 = CreateWindow("test", WindowMode::WINDOW_MODE_FULLSCREEN, Rect {0, 0, 0, 0}); + // 20:rect.posX_, 120:rect.pos_Y, rect.width_:360, rect.height_:700 + sptr window2 = CreateWindow("private", WindowMode::WINDOW_MODE_FLOATING, Rect {20, 120, 360, 700}); + window2->SetPrivacyMode(true); + // 10:rect.posX_, 110:rect.pos_Y, rect.width_:380, rect.height_:480 + sptr window3 = CreateWindow("covered1", WindowMode::WINDOW_MODE_FLOATING, Rect {10, 110, 380, 480}); + // 10:rect.posX_, 600:rect.pos_Y, rect.width_:380, rect.height_:480 + sptr window4 = CreateWindow("covered2", WindowMode::WINDOW_MODE_FLOATING, Rect {10, 600, 380, 480}); + usleep(WAIT_FOR_SYNC_US); + bool hasPrivateWindow = false; + DisplayId id = DisplayManager::GetInstance().GetDefaultDisplayId(); + DisplayManager::GetInstance().HasPrivateWindow(id, hasPrivateWindow); + ASSERT_TRUE(hasPrivateWindow); + window1->Destroy(); + window2->Destroy(); + window3->Destroy(); + window4->Destroy(); +} + +/** + * @tc.name: HasPrivateWindowSkipSnapShot + * @tc.desc: set snap shot skip + * @tc.type: FUNC + */ +HWTEST_F(DisplayManagerTest, HasPrivateWindowSkipSnapShot, Function | SmallTest | Level2) +{ + sptr window1 = CreateWindow("test", WindowMode::WINDOW_MODE_FULLSCREEN, Rect {0, 0, 0, 0}); + // 20:rect.posX_, 120:rect.posY_, 360:rect.width, 480:rect.height + sptr window2 = CreateWindow("private", WindowMode::WINDOW_MODE_FLOATING, Rect {20, 120, 360, 480}); + window2->SetSnapshotSkip(true); + usleep(WAIT_FOR_SYNC_US); + bool hasPrivateWindow = false; + DisplayId id = DisplayManager::GetInstance().GetDefaultDisplayId(); + DisplayManager::GetInstance().HasPrivateWindow(id, hasPrivateWindow); + ASSERT_TRUE(!hasPrivateWindow); + window1->Destroy(); + window2->Destroy(); +} +} +} // namespace OHOS::Rosen