From 3a0ea06eaaccbbdff18066a3b577fbce39bf6f6a Mon Sep 17 00:00:00 2001 From: qianlf Date: Wed, 12 Jan 2022 10:24:33 +0800 Subject: [PATCH 1/3] add window wm tests Signed-off-by: qianlf Change-Id: Ic4809bc4348ceca21ad3c176d8c9c5f4850bdc8a --- ohos.build | 1 + wm/BUILD.gn | 5 + wm/test/BUILD.gn | 20 + wm/test/systemtest/BUILD.gn | 117 ++++++ wm/test/systemtest/window_layout_test.cpp | 229 ++++++++++ .../systemtest/window_multi_ability_test.cpp | 153 +++++++ wm/test/systemtest/window_subwindow_test.cpp | 312 ++++++++++++++ wm/test/systemtest/window_test_utils.cpp | 107 +++++ wm/test/systemtest/window_test_utils.h | 52 +++ wm/test/unittest/BUILD.gn | 150 +++++++ .../unittest/input_transfer_station_test.cpp | 87 ++++ .../unittest/input_transfer_station_test.h | 37 ++ wm/test/unittest/mock_static_call.h | 33 ++ .../test/unittest}/mock_window_adapter.h | 12 +- .../test/unittest}/singleton_mocker.h | 6 +- wm/test/unittest/window_impl_test.cpp | 392 ++++++++++++++++++ wm/test/unittest/window_impl_test.h | 39 ++ .../unittest/window_input_channel_test.cpp | 91 ++++ .../test/unittest/window_input_channel_test.h | 13 +- wm/test/unittest/window_option_test.cpp | 191 +++++++++ wm/test/unittest/window_option_test.h | 33 ++ wm/test/unittest/window_scene_test.cpp | 231 +++++++++++ wm/test/unittest/window_scene_test.h | 37 ++ wm/test/unittest/window_test.cpp | 138 ++++++ wm/test/unittest/window_test.h | 36 ++ wmtest/unittest/BUILD.gn | 85 ---- wmtest/unittest/include/test_header.h | 43 -- wmtest/unittest/src/window_impl_test.cpp | 130 ------ 28 files changed, 2507 insertions(+), 273 deletions(-) create mode 100644 wm/test/BUILD.gn create mode 100644 wm/test/systemtest/BUILD.gn create mode 100644 wm/test/systemtest/window_layout_test.cpp create mode 100644 wm/test/systemtest/window_multi_ability_test.cpp create mode 100644 wm/test/systemtest/window_subwindow_test.cpp create mode 100644 wm/test/systemtest/window_test_utils.cpp create mode 100644 wm/test/systemtest/window_test_utils.h create mode 100644 wm/test/unittest/BUILD.gn create mode 100644 wm/test/unittest/input_transfer_station_test.cpp create mode 100644 wm/test/unittest/input_transfer_station_test.h create mode 100644 wm/test/unittest/mock_static_call.h rename {wmtest/unittest/include/mock => wm/test/unittest}/mock_window_adapter.h (64%) rename {wmtest/unittest/include/mock => wm/test/unittest}/singleton_mocker.h (87%) create mode 100644 wm/test/unittest/window_impl_test.cpp create mode 100644 wm/test/unittest/window_impl_test.h create mode 100644 wm/test/unittest/window_input_channel_test.cpp rename wmtest/unittest/include/window_impl_test.h => wm/test/unittest/window_input_channel_test.h (72%) create mode 100644 wm/test/unittest/window_option_test.cpp create mode 100644 wm/test/unittest/window_option_test.h create mode 100644 wm/test/unittest/window_scene_test.cpp create mode 100644 wm/test/unittest/window_scene_test.h create mode 100644 wm/test/unittest/window_test.cpp create mode 100644 wm/test/unittest/window_test.h delete mode 100644 wmtest/unittest/BUILD.gn delete mode 100644 wmtest/unittest/include/test_header.h delete mode 100644 wmtest/unittest/src/window_impl_test.cpp diff --git a/ohos.build b/ohos.build index 0887e15a..7e7080fd 100644 --- a/ohos.build +++ b/ohos.build @@ -15,6 +15,7 @@ ], "test_list": [ + "//foundation/windowmanager/wm:test" ] } } diff --git a/wm/BUILD.gn b/wm/BUILD.gn index fa58a7a3..343ac4d5 100644 --- a/wm/BUILD.gn +++ b/wm/BUILD.gn @@ -169,3 +169,8 @@ ohos_shared_library("libwm") { part_name = "window_manager" subsystem_name = "window" } + +group("test") { + testonly = true + deps = [ "test:test" ] +} diff --git a/wm/test/BUILD.gn b/wm/test/BUILD.gn new file mode 100644 index 00000000..db162a47 --- /dev/null +++ b/wm/test/BUILD.gn @@ -0,0 +1,20 @@ +# Copyright (c) 2021 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. + +group("test") { + testonly = true + deps = [ + "systemtest:systemtest", + "unittest:unittest", + ] +} diff --git a/wm/test/systemtest/BUILD.gn b/wm/test/systemtest/BUILD.gn new file mode 100644 index 00000000..8d04cad4 --- /dev/null +++ b/wm/test/systemtest/BUILD.gn @@ -0,0 +1,117 @@ +# Copyright (c) 2021 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. + +import("//build/test.gni") + +module_out_path = "window_manager/wm" + +group("systemtest") { + testonly = true + + deps = [ + ":wm_window_layout_test", + ":wm_window_multi_ability_test", + ":wm_window_subwindow_test", + ] +} + +## SystemTest wm_window_layout_test {{{ +ohos_systemtest("wm_window_layout_test") { + module_out_path = module_out_path + + sources = [ "window_layout_test.cpp" ] + + deps = [ ":wm_systemtest_common" ] +} + +## SystemTest wm_window_layout_test }}} + +## SystemTest wm_window_multi_ability_test {{{ +ohos_systemtest("wm_window_multi_ability_test") { + module_out_path = module_out_path + + sources = [ "window_multi_ability_test.cpp" ] + + deps = [ ":wm_systemtest_common" ] +} + +## SystemTest wm_window_multi_ability_test }}} + +## SystemTest wm_window_subwindow_test {{{ +ohos_systemtest("wm_window_subwindow_test") { + module_out_path = module_out_path + + sources = [ "window_subwindow_test.cpp" ] + + deps = [ ":wm_systemtest_common" ] +} + +## SystemTest wm_window_subwindow_test }}} + +## Build wm_systemtest_common.a {{{ +config("wm_systemtest_common_public_config") { + include_dirs = [ + "//foundation/windowmanager/wm/include", + "//foundation/windowmanager/wmserver/include", + "//foundation/windowmanager/interfaces/innerkits/wm", + "//foundation/windowmanager/utils/include", + "//utils/native/base/include", + "//foundation/communication/ipc/interfaces/innerkits/ipc_core/include", + "//base/hiviewdfx/hilog/interfaces/native/innerkits/include", + "//third_party/googletest/googlemock/include", + + # for abilityContext + "//foundation/aafwk/standard/frameworks/kits/ability/ability_runtime/include", + "//foundation/appexecfwk/standard/interfaces/innerkits/appexecfwk_base/include", + "//foundation/appexecfwk/standard/kits/appkit/native/ability_runtime/context", + "//base/global/resmgr_standard/interfaces/innerkits/include", + "//third_party/node/deps/icu-small/source/common", + "//foundation/aafwk/standard/interfaces/innerkits/ability_manager/include", + "//foundation/aafwk/standard/interfaces/innerkits/want/include/ohos/aafwk/content", + "//foundation/distributedschedule/dmsfwk/services/dtbschedmgr/include", + "//foundation/aafwk/standard/interfaces/innerkits/base/include", + + # abilityContext end + ] + + cflags = [ + "-Wall", + "-Werror", + "-g3", + "-Dprivate=public", + "-Dprotected=public", + ] +} + +ohos_static_library("wm_systemtest_common") { + visibility = [ ":*" ] + testonly = true + + sources = [ "window_test_utils.cpp" ] + + public_configs = [ ":wm_systemtest_common_public_config" ] + + public_deps = [ + "//foundation/ace/ace_engine/interfaces/innerkits/ace:ace_uicontent", + "//foundation/multimodalinput/input/frameworks/proxy:libmmi-client", + "//foundation/windowmanager/wm:libwm", + "//foundation/windowmanager/wm:libwmutil", + "//foundation/windowmanager/wmserver:libwms", + "//third_party/googletest:gmock", + "//third_party/googletest:gtest_main", + "//utils/native/base:utils", + ] + + external_deps = [ "aafwk_standard:ability_context_native" ] +} +## Build wm_systemtest_common.a }}} diff --git a/wm/test/systemtest/window_layout_test.cpp b/wm/test/systemtest/window_layout_test.cpp new file mode 100644 index 00000000..d495bf05 --- /dev/null +++ b/wm/test/systemtest/window_layout_test.cpp @@ -0,0 +1,229 @@ +/* + * Copyright (c) 2021 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 +#include "window_test_utils.h" +using namespace testing; +using namespace testing::ext; + +namespace OHOS { +namespace Rosen { +using utils = WindowTestUtils; +class WindowLayoutTest : public testing::Test { +public: + static void SetUpTestCase(); + static void TearDownTestCase(); + virtual void SetUp() override; + virtual void TearDown() override; + int displayId_ = 0; + std::vector> activeWindows_; + static vector fullScreenExpecteds_; +}; + +vector WindowLayoutTest::fullScreenExpecteds_; + +void WindowLayoutTest::SetUpTestCase() +{ + auto display = DisplayManager::GetInstance().GetDisplayById(0); + if (display == nullptr) { + printf("GetDefaultDisplay: failed!\n"); + } else { + printf("GetDefaultDisplay: id %llu, w %d, h %d, fps %u\n", display->GetId(), display->GetWidth(), + display->GetHeight(), display->GetFreshRate()); + } + Rect screenRect = {0, 0, display->GetWidth(), display->GetHeight()}; + utils::InitByScreenRect(screenRect); + // calc expected rects + Rect expected = { // 0. only statusBar + 0, + utils::statusBarRect_.height_, + utils::screenRect_.width_, + utils::screenRect_.height_ - utils::statusBarRect_.height_, + }; + fullScreenExpecteds_.push_back(expected); + expected = { // 1. both statusBar and naviBar + 0, + utils::statusBarRect_.height_, + utils::screenRect_.width_, + utils::screenRect_.height_ - utils::statusBarRect_.height_ - utils::naviBarRect_.height_, + }; + fullScreenExpecteds_.push_back(expected); + expected = { // 2. only naviBar + 0, + 0, + utils::screenRect_.width_, + utils::screenRect_.height_ - utils::naviBarRect_.height_, + }; + fullScreenExpecteds_.push_back(expected); +} + +void WindowLayoutTest::TearDownTestCase() +{ +} + +void WindowLayoutTest::SetUp() +{ + activeWindows_.clear(); +} + +void WindowLayoutTest::TearDown() +{ + while (!activeWindows_.empty()) { + ASSERT_EQ(WMError::WM_OK, activeWindows_.back()->Destroy()); + activeWindows_.pop_back(); + } +} + +namespace { +/** + * @tc.name: LayoutWindow02 + * @tc.desc: One FLOATING APP Window + * @tc.type: FUNC + * @tc.require: AR000GGTVJ + */ +HWTEST_F(WindowLayoutTest, LayoutWindow02, Function | MediumTest | Level3) +{ + utils::TestWindowInfo info = { + .name = "main", + .rect = utils::defaultAppRect_, + .type = WindowType::WINDOW_TYPE_APP_MAIN_WINDOW, + .mode = WindowMode::WINDOW_MODE_FLOATING, + .needAvoid = true, + .parentLimit = false, + .parentName = "", + }; + const sptr& window = utils::CreateTestWindow(info); + activeWindows_.push_back(window); + + ASSERT_EQ(WMError::WM_OK, window->Show()); + ASSERT_TRUE(utils::RectEqualTo(window, utils::defaultAppRect_)); + ASSERT_EQ(WMError::WM_OK, window->Hide()); +} + +/** + * @tc.name: LayoutWindow04 + * @tc.desc: One FLOATING APP Window & One StatusBar Window + * @tc.type: FUNC + * @tc.require: AR000GGTVJ + */ +HWTEST_F(WindowLayoutTest, LayoutWindow04, Function | MediumTest | Level3) +{ + // app window + utils::TestWindowInfo info = { + .name = "main", + .rect = utils::defaultAppRect_, + .type = WindowType::WINDOW_TYPE_APP_MAIN_WINDOW, + .mode = WindowMode::WINDOW_MODE_FLOATING, + .needAvoid = true, + .parentLimit = false, + .parentName = "", + }; + sptr appWin = utils::CreateTestWindow(info); + activeWindows_.push_back(appWin); + + // statusBar window + sptr statBar = utils::CreateStatusBarWindow(); + activeWindows_.push_back(statBar); + + ASSERT_EQ(WMError::WM_OK, appWin->Show()); + ASSERT_TRUE(utils::RectEqualTo(appWin, utils::defaultAppRect_)); + ASSERT_EQ(WMError::WM_OK, statBar->Show()); + ASSERT_TRUE(utils::RectEqualTo(appWin, utils::defaultAppRect_)); + ASSERT_TRUE(utils::RectEqualTo(statBar, utils::statusBarRect_)); + ASSERT_EQ(WMError::WM_OK, statBar->Hide()); + ASSERT_TRUE(utils::RectEqualTo(appWin, utils::defaultAppRect_)); +} + +/** + * @tc.name: LayoutWindow06 + * @tc.desc: StatusBar Window and NaviBar & Sys Window FULLSCRENN,NOT NEEDVOID,PARENTLIMIT + * @tc.type: FUNC + * @tc.require: AR000GGTVJ + */ +HWTEST_F(WindowLayoutTest, LayoutWindow06, Function | MediumTest | Level3) +{ + // statusBar window + sptr statBar = utils::CreateStatusBarWindow(); + activeWindows_.push_back(statBar); + + // naviBar window + sptr naviBar = utils::CreateNavigationBarWindow(); + activeWindows_.push_back(naviBar); + + // sys window + utils::TestWindowInfo info = { + .name = "main", + .rect = utils::defaultAppRect_, + .type = WindowType::WINDOW_TYPE_PANEL, + .mode = WindowMode::WINDOW_MODE_FULLSCREEN, + .needAvoid = false, + .parentLimit = true, + .parentName = "", + }; + sptr sysWin = utils::CreateTestWindow(info); + activeWindows_.push_back(sysWin); + + ASSERT_EQ(WMError::WM_OK, statBar->Show()); + ASSERT_TRUE(utils::RectEqualTo(statBar, utils::statusBarRect_)); + ASSERT_EQ(WMError::WM_OK, sysWin->Show()); + ASSERT_TRUE(utils::RectEqualTo(sysWin, utils::screenRect_)); + ASSERT_EQ(WMError::WM_OK, naviBar->Show()); + ASSERT_TRUE(utils::RectEqualTo(sysWin, utils::screenRect_)); + ASSERT_EQ(WMError::WM_OK, statBar->Hide()); + ASSERT_TRUE(utils::RectEqualTo(sysWin, utils::screenRect_)); +} + +/** + * @tc.name: LayoutWindow07 + * @tc.desc: StatusBar Window and NaviBar & One Floating Sys Window + * @tc.type: FUNC + * @tc.require: AR000GGTVJ + */ +HWTEST_F(WindowLayoutTest, LayoutWindow07, Function | MediumTest | Level3) +{ + // statusBar window + sptr statBar = utils::CreateStatusBarWindow(); + activeWindows_.push_back(statBar); + + // naviBar window + sptr naviBar = utils::CreateNavigationBarWindow(); + activeWindows_.push_back(naviBar); + + // sys window + utils::TestWindowInfo info = { + .name = "main", + .rect = utils::defaultAppRect_, + .type = WindowType::WINDOW_TYPE_PANEL, + .mode = WindowMode::WINDOW_MODE_FLOATING, + .needAvoid = false, + .parentLimit = true, + .parentName = "", + }; + sptr sysWin = utils::CreateTestWindow(info); + activeWindows_.push_back(sysWin); + + ASSERT_EQ(WMError::WM_OK, statBar->Show()); + ASSERT_TRUE(utils::RectEqualTo(statBar, utils::statusBarRect_)); + ASSERT_EQ(WMError::WM_OK, sysWin->Show()); + ASSERT_TRUE(utils::RectEqualTo(sysWin, utils::defaultAppRect_)); + ASSERT_EQ(WMError::WM_OK, naviBar->Show()); + ASSERT_TRUE(utils::RectEqualTo(sysWin, utils::defaultAppRect_)); + ASSERT_EQ(WMError::WM_OK, statBar->Hide()); + ASSERT_TRUE(utils::RectEqualTo(sysWin, utils::defaultAppRect_)); +} +} +} // namespace Rosen +} // namespace OHOS diff --git a/wm/test/systemtest/window_multi_ability_test.cpp b/wm/test/systemtest/window_multi_ability_test.cpp new file mode 100644 index 00000000..3237e150 --- /dev/null +++ b/wm/test/systemtest/window_multi_ability_test.cpp @@ -0,0 +1,153 @@ +/* + * Copyright (c) 2021 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 +#include +#include "window_test_utils.h" + +using namespace testing; +using namespace testing::ext; + +namespace OHOS { +namespace Rosen { +using utils = WindowTestUtils; +class WindowMultiAbilityTest : public testing::Test { +public: + static void SetUpTestCase(); + static void TearDownTestCase(); + virtual void SetUp() override; + virtual void TearDown() override; +}; + +void WindowMultiAbilityTest::SetUpTestCase() +{ +} + +void WindowMultiAbilityTest::TearDownTestCase() +{ +} + +void WindowMultiAbilityTest::SetUp() +{ +} + +void WindowMultiAbilityTest::TearDown() +{ +} + +const int SLEEP_MS = 20; + +static void ShowHideWindowSceneCallable(int i) +{ + int sleepTimeMs = i * SLEEP_MS; + usleep(sleepTimeMs); + sptr scene = utils::CreateWindowScene(); + const int loop = 10; + int j = 0; + for (; j < loop; j++) { + usleep(sleepTimeMs); + ASSERT_EQ(WMError::WM_OK, scene->GoForeground()); + usleep(sleepTimeMs); + ASSERT_EQ(WMError::WM_OK, scene->GoBackground()); + usleep(sleepTimeMs); + } +} + +static void CreateDestroyWindowSceneCallable(int i) +{ + int sleepTimeMs = i * SLEEP_MS; + const int loop = 10; + int j = 0; + for (; j < loop; j++) { + usleep(sleepTimeMs); + sptr scene = utils::CreateWindowScene(); + usleep(sleepTimeMs); + ASSERT_EQ(WMError::WM_OK, scene->GoForeground()); + usleep(sleepTimeMs); + ASSERT_EQ(WMError::WM_OK, scene->GoBackground()); + usleep(sleepTimeMs); + scene.clear(); + usleep(sleepTimeMs); + } +} + +/** + * @tc.name: MultiAbilityWindow01 + * @tc.desc: Five scene process in one thread + * @tc.type: FUNC + * @tc.require: AR000GGTVJ + */ +HWTEST_F(WindowMultiAbilityTest, MultiAbilityWindow01, Function | MediumTest | Level2) +{ + sptr scene1 = utils::CreateWindowScene(); + sptr scene2 = utils::CreateWindowScene(); + sptr scene3 = utils::CreateWindowScene(); + sptr scene4 = utils::CreateWindowScene(); + sptr scene5 = utils::CreateWindowScene(); + + ASSERT_EQ(WMError::WM_OK, scene1->GoForeground()); + ASSERT_EQ(WMError::WM_OK, scene2->GoForeground()); + ASSERT_EQ(WMError::WM_OK, scene3->GoForeground()); + ASSERT_EQ(WMError::WM_OK, scene4->GoForeground()); + ASSERT_EQ(WMError::WM_OK, scene5->GoForeground()); + ASSERT_EQ(WMError::WM_OK, scene5->GoBackground()); + ASSERT_EQ(WMError::WM_OK, scene4->GoBackground()); + ASSERT_EQ(WMError::WM_OK, scene3->GoBackground()); + ASSERT_EQ(WMError::WM_OK, scene2->GoBackground()); + ASSERT_EQ(WMError::WM_OK, scene1->GoBackground()); +} + +/** + * @tc.name: MultiAbilityWindow02 + * @tc.desc: Five scene process show/hide in five threads + * @tc.type: FUNC + * @tc.require: AR000GGTVJ + */ +HWTEST_F(WindowMultiAbilityTest, MultiAbilityWindow02, Function | MediumTest | Level2) +{ + std::thread th1(ShowHideWindowSceneCallable, 1); + std::thread th2(ShowHideWindowSceneCallable, 2); + std::thread th3(ShowHideWindowSceneCallable, 3); + std::thread th4(ShowHideWindowSceneCallable, 4); + std::thread th5(ShowHideWindowSceneCallable, 5); + th1.join(); + th2.join(); + th3.join(); + th4.join(); + th5.join(); +} + +/** + * @tc.name: MultiAbilityWindow03 + * @tc.desc: Five scene process create/destroy in five threads + * @tc.type: FUNC + * @tc.require: AR000GGTVJ + */ +HWTEST_F(WindowMultiAbilityTest, MultiAbilityWindow03, Function | MediumTest | Level2) +{ + std::thread th1(CreateDestroyWindowSceneCallable, 1); + std::thread th2(CreateDestroyWindowSceneCallable, 2); + std::thread th3(CreateDestroyWindowSceneCallable, 3); + std::thread th4(CreateDestroyWindowSceneCallable, 4); + std::thread th5(CreateDestroyWindowSceneCallable, 5); + th1.join(); + th2.join(); + th3.join(); + th4.join(); + th5.join(); +} +} // namespace Rosen +} // namespace OHOS diff --git a/wm/test/systemtest/window_subwindow_test.cpp b/wm/test/systemtest/window_subwindow_test.cpp new file mode 100644 index 00000000..3aa5f966 --- /dev/null +++ b/wm/test/systemtest/window_subwindow_test.cpp @@ -0,0 +1,312 @@ +/* + * Copyright (c) 2021 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 + +#include "window.h" +#include "window_life_cycle_interface.h" +#include "window_option.h" +#include "window_scene.h" +#include "wm_common.h" + +using namespace testing; +using namespace testing::ext; + +namespace OHOS { +namespace Rosen { +class WindowSubWindowTest : public testing::Test { +public: + static void SetUpTestCase(); + static void TearDownTestCase(); + virtual void SetUp() override; + virtual void TearDown() override; +}; + +void WindowSubWindowTest::SetUpTestCase() +{ +} + +void WindowSubWindowTest::TearDownTestCase() +{ +} + +void WindowSubWindowTest::SetUp() +{ +} + +void WindowSubWindowTest::TearDown() +{ +} + +static sptr CreateWindowScene() +{ + sptr listener = nullptr; + std::shared_ptr abilityContext = nullptr; + + sptr scene = new WindowScene(); + scene->Init(0, abilityContext, listener); + return scene; +} + +static sptr CreateSubWindow(sptr scene, WindowType type, + WindowMode mode, struct Rect rect, uint32_t flags) +{ + sptr subOp = new WindowOption(); + subOp->SetWindowType(type); + subOp->SetWindowMode(mode); + subOp->SetWindowRect(rect); + subOp->SetWindowFlags(flags); + + static int cnt = 0; + return scene->CreateWindow("SubWindow" + std::to_string(cnt++), subOp); +} + +/** + * @tc.name: SubWindow01 + * @tc.desc: FullScreen Main Window + Floating SubWindow + * @tc.type: FUNC + * @tc.require: AR000GGTVJ + */ +HWTEST_F(WindowSubWindowTest, SubWindow01, Function | MediumTest | Level2) +{ + sptr scene = CreateWindowScene(); + + struct Rect rect = {0, 0, 100, 200}; + uint32_t flags = 0; + sptr subWindow = CreateSubWindow(scene, WindowType::WINDOW_TYPE_APP_SUB_WINDOW, + WindowMode::WINDOW_MODE_FLOATING, rect, flags); + ASSERT_NE(nullptr, subWindow); + + ASSERT_EQ(WMError::WM_OK, scene->GoForeground()); + ASSERT_EQ(WMError::WM_OK, subWindow->Show()); + + ASSERT_EQ(WMError::WM_OK, subWindow->Hide()); + ASSERT_EQ(WMError::WM_OK, scene->GoBackground()); +} + +/** + * @tc.name: SubWindow02 + * @tc.desc: FullScreen Main Window + Floating SubWindow & Parent Limit work + * @tc.type: FUNC + * @tc.require: AR000GGTVJ + */ +HWTEST_F(WindowSubWindowTest, SubWindow02, Function | MediumTest | Level2) +{ + sptr scene = CreateWindowScene(); + + struct Rect rect = {0, 0, 100, 200}; + uint32_t flags = static_cast(WindowFlag::WINDOW_FLAG_PARENT_LIMIT); + sptr subWindow = CreateSubWindow(scene, WindowType::WINDOW_TYPE_APP_SUB_WINDOW, + WindowMode::WINDOW_MODE_FLOATING, rect, flags); + ASSERT_NE(nullptr, subWindow); + + ASSERT_EQ(WMError::WM_OK, scene->GoForeground()); + ASSERT_EQ(WMError::WM_OK, subWindow->Show()); + + ASSERT_EQ(WMError::WM_OK, subWindow->Hide()); + ASSERT_EQ(WMError::WM_OK, scene->GoBackground()); +} + +/** + * @tc.name: SubWindow03 + * @tc.desc: FullScreen Main Window + Floating MediaWindow + * @tc.type: FUNC + * @tc.require: AR000GGTVJ + */ +HWTEST_F(WindowSubWindowTest, SubWindow03, Function | MediumTest | Level2) +{ + sptr scene = CreateWindowScene(); + + struct Rect rect = {0, 2000, 100, 200}; + uint32_t flags = static_cast(WindowFlag::WINDOW_FLAG_PARENT_LIMIT); + sptr subWindow = CreateSubWindow(scene, WindowType::WINDOW_TYPE_MEDIA, + WindowMode::WINDOW_MODE_FLOATING, rect, flags); + ASSERT_NE(nullptr, subWindow); + + ASSERT_EQ(WMError::WM_OK, scene->GoForeground()); + ASSERT_EQ(WMError::WM_OK, subWindow->Show()); + + ASSERT_EQ(WMError::WM_OK, subWindow->Hide()); + ASSERT_EQ(WMError::WM_OK, scene->GoBackground()); +} + +/** + * @tc.name: SubWindow04 + * @tc.desc: FullScreen Main Window + Floating MediaWindow + * @tc.type: FUNC + * @tc.require: AR000GGTVJ + */ +HWTEST_F(WindowSubWindowTest, SubWindow04, Function | MediumTest | Level2) +{ + sptr scene = CreateWindowScene(); + + struct Rect rect = {0, 2000, 3000, 2000}; + uint32_t flags = static_cast(WindowFlag::WINDOW_FLAG_PARENT_LIMIT); + sptr subWindow = CreateSubWindow(scene, WindowType::WINDOW_TYPE_MEDIA, + WindowMode::WINDOW_MODE_FLOATING, rect, flags); + ASSERT_NE(nullptr, subWindow); + + ASSERT_EQ(WMError::WM_OK, scene->GoForeground()); + ASSERT_EQ(WMError::WM_OK, subWindow->Show()); + + ASSERT_EQ(WMError::WM_OK, subWindow->Hide()); + ASSERT_EQ(WMError::WM_OK, scene->GoBackground()); +} + +/** + * @tc.name: SubWindow05 + * @tc.desc: FullScreen Main Window + Floating MediaWindow + Floating SubWindow + * @tc.type: FUNC + * @tc.require: AR000GGTVJ + */ +HWTEST_F(WindowSubWindowTest, SubWindow05, Function | MediumTest | Level3) +{ + sptr scene = CreateWindowScene(); + + struct Rect rect = {0, 0, 100, 200}; + uint32_t flags = static_cast(WindowFlag::WINDOW_FLAG_PARENT_LIMIT); + sptr subWindow = CreateSubWindow(scene, WindowType::WINDOW_TYPE_MEDIA, + WindowMode::WINDOW_MODE_FLOATING, rect, flags); + ASSERT_NE(nullptr, subWindow); + + sptr subWindow2 = CreateSubWindow(scene, WindowType::WINDOW_TYPE_APP_SUB_WINDOW, + WindowMode::WINDOW_MODE_FLOATING, rect, flags); + ASSERT_NE(nullptr, subWindow2); + + ASSERT_EQ(WMError::WM_OK, scene->GoForeground()); + ASSERT_EQ(WMError::WM_OK, subWindow->Show()); + ASSERT_EQ(WMError::WM_OK, subWindow2->Show()); + + ASSERT_EQ(WMError::WM_OK, subWindow->Hide()); + ASSERT_EQ(WMError::WM_OK, subWindow2->Hide()); + ASSERT_EQ(WMError::WM_OK, scene->GoBackground()); +} + +/** + * @tc.name: SubWindow06 + * @tc.desc: FullScreen Main Window + FullScreen SubWindow + * @tc.type: FUNC + * @tc.require: AR000GGTVJ + */ +HWTEST_F(WindowSubWindowTest, SubWindow06, Function | MediumTest | Level3) +{ + sptr scene = CreateWindowScene(); + + struct Rect rect = {0, 0, 100, 200}; + uint32_t flags = static_cast(WindowFlag::WINDOW_FLAG_PARENT_LIMIT); + sptr subWindow = CreateSubWindow(scene, WindowType::WINDOW_TYPE_APP_SUB_WINDOW, + WindowMode::WINDOW_MODE_FULLSCREEN, rect, flags); + ASSERT_NE(nullptr, subWindow); + + ASSERT_EQ(WMError::WM_OK, scene->GoForeground()); + ASSERT_EQ(WMError::WM_OK, subWindow->Show()); + + ASSERT_EQ(WMError::WM_OK, subWindow->Hide()); + ASSERT_EQ(WMError::WM_OK, scene->GoBackground()); +} + +/** + * @tc.name: SubWindow07 + * @tc.desc: FullScreen Main Window + Floating SubWindow & MainWindow Fisrt GoBackground + * @tc.type: FUNC + * @tc.require: AR000GGTVJ + */ +HWTEST_F(WindowSubWindowTest, SubWindow07, Function | MediumTest | Level4) +{ + sptr scene = CreateWindowScene(); + + struct Rect rect = {0, 0, 100, 200}; + uint32_t flags = static_cast(WindowFlag::WINDOW_FLAG_PARENT_LIMIT); + sptr subWindow = CreateSubWindow(scene, WindowType::WINDOW_TYPE_APP_SUB_WINDOW, + WindowMode::WINDOW_MODE_FLOATING, rect, flags); + ASSERT_NE(nullptr, subWindow); + + ASSERT_EQ(WMError::WM_OK, scene->GoForeground()); + ASSERT_EQ(WMError::WM_OK, subWindow->Show()); + + ASSERT_EQ(WMError::WM_OK, scene->GoBackground()); + ASSERT_EQ(WMError::WM_OK, subWindow->Hide()); +} + +/** + * @tc.name: SubWindow08 + * @tc.desc: FullScreen Main Window + Floating SubWindow & only show SubWindow + * @tc.type: FUNC + * @tc.require: AR000GGTVJ + */ +HWTEST_F(WindowSubWindowTest, SubWindow08, Function | MediumTest | Level4) +{ + sptr scene = CreateWindowScene(); + + struct Rect rect = {0, 0, 100, 200}; + uint32_t flags = static_cast(WindowFlag::WINDOW_FLAG_PARENT_LIMIT); + sptr subWindow = CreateSubWindow(scene, WindowType::WINDOW_TYPE_APP_SUB_WINDOW, + WindowMode::WINDOW_MODE_FLOATING, rect, flags); + ASSERT_NE(nullptr, subWindow); + + ASSERT_EQ(WMError::WM_ERROR_INVALID_PARAM, subWindow->Show()); +} + +/** + * @tc.name: SubWindow09 + * @tc.desc: FullScreen Main Window + Floating SubWindow & first destroy SubWindow, then destroy MainWindow + * @tc.type: FUNC + * @tc.require: AR000GGTVJ + */ +HWTEST_F(WindowSubWindowTest, SubWindow09, Function | MediumTest | Level2) +{ + sptr scene = CreateWindowScene(); + + struct Rect rect = {0, 0, 100, 200}; + uint32_t flags = static_cast(WindowFlag::WINDOW_FLAG_PARENT_LIMIT); + sptr subWindow = CreateSubWindow(scene, WindowType::WINDOW_TYPE_APP_SUB_WINDOW, + WindowMode::WINDOW_MODE_FLOATING, rect, flags); + ASSERT_NE(nullptr, subWindow); + + ASSERT_EQ(WMError::WM_OK, scene->GoForeground()); + ASSERT_EQ(WMError::WM_OK, subWindow->Show()); + + ASSERT_EQ(WMError::WM_OK, subWindow->Hide()); + ASSERT_EQ(WMError::WM_OK, scene->GoBackground()); + + ASSERT_EQ(WMError::WM_OK, subWindow->Destroy()); +} + +/** + * @tc.name: SubWindow10 + * @tc.desc: FullScreen Main Window + Floating SubWindow & first destroy MainWindow, then destroy SubWindow + * @tc.type: FUNC + * @tc.require: AR000GGTVJ + */ +HWTEST_F(WindowSubWindowTest, SubWindow10, Function | MediumTest | Level2) +{ + sptr scene = CreateWindowScene(); + + struct Rect rect = {0, 0, 100, 200}; + uint32_t flags = static_cast(WindowFlag::WINDOW_FLAG_PARENT_LIMIT); + sptr subWindow = CreateSubWindow(scene, WindowType::WINDOW_TYPE_APP_SUB_WINDOW, + WindowMode::WINDOW_MODE_FLOATING, rect, flags); + ASSERT_NE(nullptr, subWindow); + + ASSERT_EQ(WMError::WM_OK, scene->GoForeground()); + ASSERT_EQ(WMError::WM_OK, subWindow->Show()); + + sptr mainWindow = scene->GetMainWindow(); + ASSERT_EQ(WMError::WM_OK, mainWindow->Destroy()); + ASSERT_EQ(WMError::WM_ERROR_DESTROYED_OBJECT, subWindow->Destroy()); +} +} // namespace Rosen +} // namespace OHOS diff --git a/wm/test/systemtest/window_test_utils.cpp b/wm/test/systemtest/window_test_utils.cpp new file mode 100644 index 00000000..a7615147 --- /dev/null +++ b/wm/test/systemtest/window_test_utils.cpp @@ -0,0 +1,107 @@ +/* + * Copyright (c) 2021 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 "window_test_utils.h" + +namespace OHOS { +namespace Rosen { +Rect WindowTestUtils::screenRect_ = {0, 0, 0, 0}; +Rect WindowTestUtils::statusBarRect_ = {0, 0, 0, 0}; +Rect WindowTestUtils::naviBarRect_ = {0, 0, 0, 0}; +Rect WindowTestUtils::defaultAppRect_ = {0, 0, 0, 0}; + +sptr WindowTestUtils::CreateTestWindow(const TestWindowInfo& info) +{ + sptr option = new WindowOption(); + option->SetWindowRect(info.rect); + option->SetWindowType(info.type); + option->SetWindowMode(info.mode); + if (info.parentName != "") { + option->SetParentName(info.parentName); + } + if (info.needAvoid) { + option->AddWindowFlag(WindowFlag::WINDOW_FLAG_NEED_AVOID); + } else { + option->RemoveWindowFlag(WindowFlag::WINDOW_FLAG_NEED_AVOID); + } + if (info.parentLimit) { + option->AddWindowFlag(WindowFlag::WINDOW_FLAG_PARENT_LIMIT); + } else { + option->RemoveWindowFlag(WindowFlag::WINDOW_FLAG_PARENT_LIMIT); + } + sptr window = Window::Create(info.name, option); + return window; +} + +sptr WindowTestUtils::CreateStatusBarWindow() +{ + TestWindowInfo info = { + .name = "statusBar", + .rect = statusBarRect_, + .type = WindowType::WINDOW_TYPE_STATUS_BAR, + .mode = WindowMode::WINDOW_MODE_FLOATING, + .needAvoid = false, + .parentLimit = false, + .parentName = "", + }; + return CreateTestWindow(info); +} + +sptr WindowTestUtils::CreateNavigationBarWindow() +{ + TestWindowInfo info = { + .name = "naviBar", + .rect = naviBarRect_, + .type = WindowType::WINDOW_TYPE_NAVIGATION_BAR, + .mode = WindowMode::WINDOW_MODE_FLOATING, + .needAvoid = false, + .parentLimit = false, + .parentName = "", + }; + return CreateTestWindow(info); +} + +sptr WindowTestUtils::CreateWindowScene() +{ + sptr listener = nullptr; + std::shared_ptr abilityContext = nullptr; + + sptr scene = new WindowScene(); + scene->Init(0, abilityContext, listener); + return scene; +} + +void WindowTestUtils::InitByScreenRect(const Rect& screenRect) +{ + const float barRatio = 0.07; + const float appRation = 0.4; + screenRect_ = screenRect; + statusBarRect_ = {0, 0, screenRect_.width_, screenRect_.height_ * barRatio}; + naviBarRect_ = {0, screenRect_.height_ * (1 - barRatio), screenRect_.width_, screenRect_.height_ * barRatio}; + defaultAppRect_ = {0, 0, screenRect_.width_ * appRation, screenRect_.height_ * appRation}; +} + +bool WindowTestUtils::RectEqualTo(const sptr& window, const Rect& r) +{ + Rect l = window->GetRect(); + bool res = ((l.posX_ == r.posX_) && (l.posY_ == r.posY_) && (l.width_ == r.width_) && (l.height_ == r.height_)); + if (!res) { + printf("GetLayoutRect: %d %d %d %d, Expect: %d %d %d %d\n", l.posX_, l.posY_, l.width_, l.height_, + r.posX_, r.posY_, r.width_, r.height_); + } + return res; +} +} // namespace ROSEN +} // namespace OHOS diff --git a/wm/test/systemtest/window_test_utils.h b/wm/test/systemtest/window_test_utils.h new file mode 100644 index 00000000..a8998c6b --- /dev/null +++ b/wm/test/systemtest/window_test_utils.h @@ -0,0 +1,52 @@ +/* + * Copyright (c) 2021 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. + */ + +#ifndef FRAMEWORKS_WM_TEST_ST_WINDOW_TEST_UTILS_H +#define FRAMEWORKS_WM_TEST_ST_WINDOW_TEST_UTILS_H + +#include "display_manager.h" +#include "window.h" +#include "window_life_cycle_interface.h" +#include "window_option.h" +#include "window_scene.h" +#include "wm_common.h" + +namespace OHOS { +namespace Rosen { +class WindowTestUtils { +public: + struct TestWindowInfo { + std::string name; + Rect rect; + WindowType type; + WindowMode mode; + bool needAvoid; + bool parentLimit; + std::string parentName; + }; + static Rect screenRect_; + static Rect statusBarRect_; + static Rect naviBarRect_; + static Rect defaultAppRect_; + static void InitByScreenRect(const Rect& screenRect); + static sptr CreateTestWindow(const TestWindowInfo& info); + static sptr CreateStatusBarWindow(); + static sptr CreateNavigationBarWindow(); + static sptr CreateWindowScene(); + static bool RectEqualTo(const sptr& window, const Rect& r); +}; +} // namespace ROSEN +} // namespace OHOS +#endif // FRAMEWORKS_WM_TEST_ST_WINDOW_TEST_UTILS_H diff --git a/wm/test/unittest/BUILD.gn b/wm/test/unittest/BUILD.gn new file mode 100644 index 00000000..144000bc --- /dev/null +++ b/wm/test/unittest/BUILD.gn @@ -0,0 +1,150 @@ +# Copyright (c) 2021 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. + +import("//build/test.gni") +module_out_path = "window_manager/wm" + +group("unittest") { + testonly = true + + deps = [ + ":wm_input_transfer_station_test", + ":wm_window_impl_test", + ":wm_window_input_channel_test", + ":wm_window_option_test", + ":wm_window_scene_test", + ":wm_window_test", + ] +} + +## UnitTest wm_window_impl_test {{{ +ohos_unittest("wm_window_impl_test") { + module_out_path = module_out_path + + sources = [ "window_impl_test.cpp" ] + + deps = [ ":wm_unittest_common" ] +} + +## UnitTest wm_window_impl_test }}} + +## UnitTest wm_input_transfer_station_test {{{ +ohos_unittest("wm_input_transfer_station_test") { + module_out_path = module_out_path + + sources = [ "input_transfer_station_test.cpp" ] + + deps = [ ":wm_unittest_common" ] +} + +## UnitTest wm_input_transfer_station_test }}} + +## UnitTest wm_window_input_channel_test {{{ +ohos_unittest("wm_window_input_channel_test") { + module_out_path = module_out_path + + sources = [ "window_input_channel_test.cpp" ] + + deps = [ ":wm_unittest_common" ] +} + +## UnitTest wm_window_input_channel_test }}} + +## UnitTest wm_window_option_test {{{ +ohos_unittest("wm_window_option_test") { + module_out_path = module_out_path + + sources = [ "window_option_test.cpp" ] + + deps = [ ":wm_unittest_common" ] +} + +## UnitTest wm_window_option_test }}} + +## UnitTest wm_window_scene_test {{{ +ohos_unittest("wm_window_scene_test") { + module_out_path = module_out_path + + sources = [ "window_scene_test.cpp" ] + + deps = [ ":wm_unittest_common" ] +} + +## UnitTest wm_window_scene_test }}} + +## UnitTest wm_window_test {{{ +ohos_unittest("wm_window_test") { + module_out_path = module_out_path + + sources = [ "window_test.cpp" ] + + deps = [ ":wm_unittest_common" ] +} + +## UnitTest wm_window_test }}} + +## Build wm_unittest_common.a {{{ +config("wm_unittest_common_public_config") { + include_dirs = [ + "//foundation/windowmanager/wm/include", + "//foundation/windowmanager/wmserver/include", + "//foundation/windowmanager/interfaces/innerkits/wm", + "//foundation/windowmanager/utils/include", + "//utils/native/base/include", + "//foundation/communication/ipc/interfaces/innerkits/ipc_core/include", + "//base/hiviewdfx/hilog/interfaces/native/innerkits/include", + "//third_party/googletest/googlemock/include", + + # for abilityContext + "//foundation/aafwk/standard/frameworks/kits/ability/ability_runtime/include", + "//foundation/appexecfwk/standard/interfaces/innerkits/appexecfwk_base/include", + "//foundation/appexecfwk/standard/kits/appkit/native/ability_runtime/context", + "//base/global/resmgr_standard/interfaces/innerkits/include", + "//third_party/node/deps/icu-small/source/common", + "//foundation/aafwk/standard/interfaces/innerkits/ability_manager/include", + "//foundation/aafwk/standard/interfaces/innerkits/want/include/ohos/aafwk/content", + "//foundation/distributedschedule/dmsfwk/services/dtbschedmgr/include", + "//foundation/aafwk/standard/interfaces/innerkits/base/include", + + # abilityContext end + ] + + cflags = [ + "-Wall", + "-Werror", + "-g3", + "-Dprivate=public", + "-Dprotected=public", + ] +} + +ohos_static_library("wm_unittest_common") { + visibility = [ ":*" ] + testonly = true + + public_configs = [ ":wm_unittest_common_public_config" ] + + public_deps = [ + "//foundation/ace/ace_engine/interfaces/innerkits/ace:ace_uicontent", + "//foundation/multimodalinput/input/frameworks/proxy:libmmi-client", + "//foundation/windowmanager/wm:libwm", + "//foundation/windowmanager/wm:libwmutil", + "//foundation/windowmanager/wmserver:libwms", + "//third_party/googletest:gmock", + "//third_party/googletest:gtest_main", + "//utils/native/base:utils", + ] + + external_deps = [ "aafwk_standard:ability_context_native" ] +} +## Build wm_unittest_common.a }}} diff --git a/wm/test/unittest/input_transfer_station_test.cpp b/wm/test/unittest/input_transfer_station_test.cpp new file mode 100644 index 00000000..a4852e37 --- /dev/null +++ b/wm/test/unittest/input_transfer_station_test.cpp @@ -0,0 +1,87 @@ +/* + * Copyright (c) 2021 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 "input_transfer_station_test.h" +#include "mock_window_adapter.h" +#include "singleton_mocker.h" + +using namespace testing; +using namespace testing::ext; + +namespace OHOS { +namespace Rosen { +using WindowMocker = SingletonMocker; +void InputTransferStationTest::SetUpTestCase() +{ + std::unique_ptr m = std::make_unique(); + sptr option = new WindowOption(); + option->SetWindowName("inputwindow"); + window_ = new WindowImpl(option); + EXPECT_CALL(m->Mock(), CreateWindow(_, _, _, _)).Times(1).WillOnce(Return(WMError::WM_OK)); + window_->Create(""); +} + +void InputTransferStationTest::TearDownTestCase() +{ +} + +void InputTransferStationTest::SetUp() +{ +} + +void InputTransferStationTest::TearDown() +{ +} + +namespace { +/** + * @tc.name: AddInputWindow + * @tc.desc: add input window in station. + * @tc.type: FUNC + * @tc.require: AR000GGTUV + */ +HWTEST_F(InputTransferStationTest, AddInputWindow, Function | SmallTest | Level2) +{ + std::shared_ptr listener = std::make_shared(InputEventListener()); + MMI::InputManager::GetInstance()->SetWindowInputEventConsumer(listener); + InputTransferStation::GetInstance().AddInputWindow(window_); +} + +/** + * @tc.name: RemoveInputWindow + * @tc.desc: remove input window in station. + * @tc.type: FUNC + * @tc.require: AR000GGTUV + */ +HWTEST_F(InputTransferStationTest, RemoveInputWindow, Function | SmallTest | Level2) +{ + InputTransferStation::GetInstance().RemoveInputWindow(window_); +} + +/** + * @tc.name: SetInputListener + * @tc.desc: set input listener for inner window + * @tc.type: FUNC + * @tc.require: AR000GGTUV + */ +HWTEST_F(InputTransferStationTest, SetInputListener, Function | SmallTest | Level2) +{ + int32_t windowId = 1; + std::shared_ptr listener = std::make_shared(InputEventListener()); + InputTransferStation::GetInstance().SetInputListener(windowId, listener); +} +} +} // namespace Rosen +} // namespace OHOS diff --git a/wm/test/unittest/input_transfer_station_test.h b/wm/test/unittest/input_transfer_station_test.h new file mode 100644 index 00000000..3f6c7576 --- /dev/null +++ b/wm/test/unittest/input_transfer_station_test.h @@ -0,0 +1,37 @@ +/* + * Copyright (c) 2021 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. + */ + +#ifndef FRAMEWORKS_WM_TEST_UT_INPUT_TRANSFER_STATION_TEST_H +#define FRAMEWORKS_WM_TEST_UT_INPUT_TRANSFER_STATION_TEST_H + +#include +#include "input_manager.h" +#include "input_transfer_station.h" +#include "window_impl.h" + +namespace OHOS { +namespace Rosen { +class InputTransferStationTest : public testing::Test { +public: + static void SetUpTestCase(); + static void TearDownTestCase(); + virtual void SetUp() override; + virtual void TearDown() override; + static inline sptr window_; +}; +} // namespace ROSEN +} // namespace OHOS + +#endif // FRAMEWORKS_WM_TEST_UT_INPUT_TRANSFER_STATION_TEST_H \ No newline at end of file diff --git a/wm/test/unittest/mock_static_call.h b/wm/test/unittest/mock_static_call.h new file mode 100644 index 00000000..fa14ff0b --- /dev/null +++ b/wm/test/unittest/mock_static_call.h @@ -0,0 +1,33 @@ +/* + * Copyright (c) 2021 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. + */ + +#ifndef FRAMEWORKS_WM_TEST_UT_MOCK_STATIC_CALL_H +#define FRAMEWORKS_WM_TEST_UT_MOCK_STATIC_CALL_H +#include + +#include "ability_context_impl.h" +#include "static_call.h" + +namespace OHOS { +namespace Rosen { +class MockStaticCall : public StaticCall { +public: + MOCK_METHOD3(CreateWindow, sptr(const std::string& windowName, + sptr& option, std::shared_ptr abilityContext)); +}; +} +} // namespace OHOS + +#endif // FRAMEWORKS_WM_TEST_UT_MOCK_STATIC_CALL_H+ diff --git a/wmtest/unittest/include/mock/mock_window_adapter.h b/wm/test/unittest/mock_window_adapter.h similarity index 64% rename from wmtest/unittest/include/mock/mock_window_adapter.h rename to wm/test/unittest/mock_window_adapter.h index b839fe78..fc5d523c 100644 --- a/wmtest/unittest/include/mock/mock_window_adapter.h +++ b/wm/test/unittest/mock_window_adapter.h @@ -13,9 +13,8 @@ * limitations under the License. */ -#ifndef UNITTEST_MOCK_WINDOW_ADAPTER_H -#define UNITTEST_MOCK_WINDOW_ADAPTER_H - +#ifndef FRAMEWORKS_WM_TEST_UT_MOCK_WINDOW_ADAPTER_H +#define FRAMEWORKS_WM_TEST_UT_MOCK_WINDOW_ADAPTER_H #include #include "window_adapter.h" @@ -24,12 +23,15 @@ namespace OHOS { namespace Rosen { class MockWindowAdapter : public WindowAdapter { public: + MOCK_METHOD4(CreateWindow, WMError(sptr& window, sptr& windowProperty, + std::shared_ptr surfaceNode, uint32_t& windowId)); MOCK_METHOD1(AddWindow, WMError(sptr& windowProperty)); MOCK_METHOD1(RemoveWindow, WMError(uint32_t windowId)); MOCK_METHOD0(ClearWindowAdapter, void()); + MOCK_METHOD1(DestroyWindow, WMError(uint32_t windowId)); + MOCK_METHOD2(SaveAbilityToken, WMError(const sptr& abilityToken, uint32_t windowId)); }; } } // namespace OHOS - -#endif \ No newline at end of file +#endif // FRAMEWORKS_WM_TEST_UT_MOCK_WINDOW_ADAPTER_H \ No newline at end of file diff --git a/wmtest/unittest/include/mock/singleton_mocker.h b/wm/test/unittest/singleton_mocker.h similarity index 87% rename from wmtest/unittest/include/mock/singleton_mocker.h rename to wm/test/unittest/singleton_mocker.h index e593e5fb..e87b91f1 100644 --- a/wmtest/unittest/include/mock/singleton_mocker.h +++ b/wm/test/unittest/singleton_mocker.h @@ -13,8 +13,8 @@ * limitations under the License. */ -#ifndef UNITTEST_MOCK_SINGLETON_MOCKER_H -#define UNITTEST_MOCK_SINGLETON_MOCKER_H +#ifndef FRAMEWORKS_WM_TEST_UT_SINGLETON_MOCKER_H +#define FRAMEWORKS_WM_TEST_UT_SINGLETON_MOCKER_H #include "singleton_container.h" namespace OHOS { @@ -43,4 +43,4 @@ private: } // namespace Rosen } // namespace OHOS -#endif // FRAMEWORKS_WM_TEST_UNITTEST_MOCK_SINGLETON_MOCKER_H +#endif // FRAMEWORKS_WM_TEST_UT_SINGLETON_MOCKER_H diff --git a/wm/test/unittest/window_impl_test.cpp b/wm/test/unittest/window_impl_test.cpp new file mode 100644 index 00000000..cc4abc3b --- /dev/null +++ b/wm/test/unittest/window_impl_test.cpp @@ -0,0 +1,392 @@ +/* + * Copyright (c) 2021 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 "window_impl_test.h" +#include "mock_window_adapter.h" +#include "singleton_mocker.h" + +using namespace testing; +using namespace testing::ext; + +namespace OHOS { +namespace Rosen { +using Mocker = SingletonMocker; +void WindowImplTest::SetUpTestCase() +{ + option_ = new WindowOption(); + option_->SetWindowName("WindowImplTest"); + window_ = new WindowImpl(option_); + abilityContext_ = std::make_shared(); + + std::unique_ptr m = std::make_unique(); + EXPECT_CALL(m->Mock(), CreateWindow(_, _, _, _)).Times(1).WillOnce(Return(WMError::WM_OK)); + window_->Create(""); +} + +void WindowImplTest::TearDownTestCase() +{ + std::unique_ptr m = std::make_unique(); + EXPECT_CALL(m->Mock(), DestroyWindow(_)).Times(1).WillOnce(Return(WMError::WM_OK)); + window_->Destroy(); +} + +void WindowImplTest::SetUp() +{ +} + +void WindowImplTest::TearDown() +{ +} + +namespace { +/** + * @tc.name: CreateWindow01 + * @tc.desc: Create window with no parentName + * @tc.type: FUNC + * @tc.require: AR000GGTVJ + */ +HWTEST_F(WindowImplTest, CreateWindow01, Function | SmallTest | Level2) +{ + std::unique_ptr m = std::make_unique(); + + sptr option = new WindowOption(); + option->SetWindowName("CreateWindow01"); + sptr window = new WindowImpl(option); + + EXPECT_CALL(m->Mock(), CreateWindow(_, _, _, _)).Times(1).WillOnce(Return(WMError::WM_OK)); + ASSERT_EQ(WMError::WM_OK, window->Create("")); + + EXPECT_CALL(m->Mock(), DestroyWindow(_)).Times(1).WillOnce(Return(WMError::WM_OK)); + ASSERT_EQ(WMError::WM_OK, window->Destroy()); +} + +/** + * @tc.name: CreateWindow02 + * @tc.desc: Create window with no parentName and no abilityContext + * @tc.type: FUNC + * @tc.require: AR000GGTVJ + */ +HWTEST_F(WindowImplTest, CreateWindow02, Function | SmallTest | Level2) +{ + std::unique_ptr m = std::make_unique(); + + sptr option = new WindowOption(); + option->SetWindowName("CreateWindow02"); + sptr window = new WindowImpl(option); + + EXPECT_CALL(m->Mock(), CreateWindow(_, _, _, _)).Times(1).WillOnce(Return(WMError::WM_ERROR_SAMGR)); + ASSERT_EQ(WMError::WM_ERROR_SAMGR, window->Create("")); +} + +/** + * @tc.name: CreateWindow03 + * @tc.desc: Create window with illegal parentName + * @tc.type: FUNC + * @tc.require: AR000GGTVJ + */ +HWTEST_F(WindowImplTest, CreateWindow03, Function | SmallTest | Level2) +{ + sptr option = new WindowOption(); + option->SetWindowName("CreateWindow03"); + sptr window = new WindowImpl(option); + ASSERT_EQ(WMError::WM_ERROR_INVALID_PARAM, window->Create("illegal")); +} + +/** + * @tc.name: CreateWindow04 + * @tc.desc: Create window with repeated windowName + * @tc.type: FUNC + * @tc.require: AR000GGTVJ + */ +HWTEST_F(WindowImplTest, CreateWindow04, Function | SmallTest | Level2) +{ + sptr option = new WindowOption(); + option->SetWindowName("WindowImplTest"); + sptr window = new WindowImpl(option); + + ASSERT_EQ(WMError::WM_ERROR_INVALID_PARAM, window->Create("")); +} + +/** + * @tc.name: CreateWindow05 + * @tc.desc: Create window with exist parentName + * @tc.type: FUNC + * @tc.require: AR000GGTVJ + */ +HWTEST_F(WindowImplTest, CreateWindow05, Function | SmallTest | Level2) +{ + std::unique_ptr m = std::make_unique(); + + sptr option = new WindowOption(); + option->SetWindowName("CreateWindow05"); + sptr window = new WindowImpl(option); + + EXPECT_CALL(m->Mock(), CreateWindow(_, _, _, _)).Times(1).WillOnce(Return(WMError::WM_OK)); + ASSERT_EQ(WMError::WM_OK, window->Create("WindowImplTest")); + + EXPECT_CALL(m->Mock(), DestroyWindow(_)).Times(1).WillOnce(Return(WMError::WM_OK)); + ASSERT_EQ(WMError::WM_OK, window->Destroy()); +} + +/** + * @tc.name: CreateWindow06 + * @tc.desc: Create window with no default option, get and check Property + * @tc.type: FUNC + * @tc.require: AR000GGTVJ + */ +HWTEST_F(WindowImplTest, CreateWindow06, Function | SmallTest | Level2) +{ + std::unique_ptr m = std::make_unique(); + + sptr option = new WindowOption(); + option->SetWindowName("CreateWindow06"); + struct Rect rect = {1, 2, 3u, 4u}; + option->SetWindowRect(rect); + option->SetWindowType(WindowType::WINDOW_TYPE_APP_MAIN_WINDOW); + option->SetWindowMode(WindowMode::WINDOW_MODE_FULLSCREEN); + sptr window = new WindowImpl(option); + + EXPECT_CALL(m->Mock(), CreateWindow(_, _, _, _)).Times(1).WillOnce(Return(WMError::WM_OK)); + ASSERT_EQ(WMError::WM_OK, window->Create("")); + + ASSERT_EQ(1, window->GetRect().posX_); + ASSERT_EQ(2, window->GetRect().posY_); + ASSERT_EQ(3u, window->GetRect().width_); + ASSERT_EQ(4u, window->GetRect().height_); + ASSERT_EQ(WindowType::WINDOW_TYPE_APP_MAIN_WINDOW, window->GetType()); + ASSERT_EQ(WindowMode::WINDOW_MODE_FULLSCREEN, window->GetMode()); + ASSERT_EQ("CreateWindow06", window->GetWindowName()); + + EXPECT_CALL(m->Mock(), DestroyWindow(_)).Times(1).WillOnce(Return(WMError::WM_OK)); + ASSERT_EQ(WMError::WM_OK, window->Destroy()); +} + +/** + * @tc.name: CreateWindow07 + * @tc.desc: Create window with no parentName and abilityContext + * @tc.type: FUNC + * @tc.require: AR000GGTVJ + */ +HWTEST_F(WindowImplTest, CreateWindow07, Function | SmallTest | Level2) +{ + std::unique_ptr m = std::make_unique(); + + sptr option = new WindowOption(); + option->SetWindowName("CreateWindow07"); + sptr window = new WindowImpl(option); + + EXPECT_CALL(m->Mock(), SaveAbilityToken(_, _)).Times(1).WillOnce(Return(WMError::WM_OK)); + EXPECT_CALL(m->Mock(), CreateWindow(_, _, _, _)).Times(1).WillOnce(Return(WMError::WM_OK)); + ASSERT_EQ(WMError::WM_OK, window->Create("", abilityContext_)); +} + +/** + * @tc.name: CreateWindow08 + * @tc.desc: Mock SaveAbilityToken return WM_ERROR_NULLPTR, create window with no parentName and abilityContext + * @tc.type: FUNC + * @tc.require: AR000GGTVJ + */ +HWTEST_F(WindowImplTest, CreateWindow08, Function | SmallTest | Level2) +{ + std::unique_ptr m = std::make_unique(); + + sptr option = new WindowOption(); + option->SetWindowName("CreateWindow08"); + sptr window = new WindowImpl(option); + + EXPECT_CALL(m->Mock(), SaveAbilityToken(_, _)).Times(1).WillOnce(Return(WMError::WM_ERROR_NULLPTR)); + EXPECT_CALL(m->Mock(), CreateWindow(_, _, _, _)).Times(1).WillOnce(Return(WMError::WM_OK)); + ASSERT_EQ(WMError::WM_ERROR_NULLPTR, window->Create("", abilityContext_)); +} + +/** + * @tc.name: FindWindow01 + * @tc.desc: Find one exit window + * @tc.type: FUNC + * @tc.require: AR000GGTVJ + */ +HWTEST_F(WindowImplTest, FindWindow01, Function | SmallTest | Level2) +{ + ASSERT_NE(nullptr, WindowImpl::Find("WindowImplTest")); +} + +/** + * @tc.name: FindWindow02 + * @tc.desc: Add another window, find both two windows + * @tc.type: FUNC + * @tc.require: AR000GGTVJ + */ +HWTEST_F(WindowImplTest, FindWindow02, Function | SmallTest | Level2) +{ + std::unique_ptr m = std::make_unique(); + + sptr option = new WindowOption(); + option->SetWindowName("FindWindow02"); + sptr window = new WindowImpl(option); + + EXPECT_CALL(m->Mock(), CreateWindow(_, _, _, _)).Times(1).WillOnce(Return(WMError::WM_OK)); + + ASSERT_EQ(WMError::WM_OK, window->Create("")); + + ASSERT_NE(nullptr, WindowImpl::Find("WindowImplTest")); + ASSERT_NE(nullptr, WindowImpl::Find("FindWindow02")); + + EXPECT_CALL(m->Mock(), DestroyWindow(_)).Times(1).WillOnce(Return(WMError::WM_OK)); + ASSERT_EQ(WMError::WM_OK, window->Destroy()); +} + +/** + * @tc.name: FindWindow03 + * @tc.desc: Find one no exit window + * @tc.type: FUNC + * @tc.require: AR000GGTVJ + */ +HWTEST_F(WindowImplTest, FindWindow03, Function | SmallTest | Level2) +{ + ASSERT_EQ(nullptr, WindowImpl::Find("FindWindow03")); +} + +/** + * @tc.name: FindWindow04 + * @tc.desc: Find window with empty name + * @tc.type: FUNC + * @tc.require: AR000GGTVJ + */ +HWTEST_F(WindowImplTest, FindWindow04, Function | SmallTest | Level2) +{ + ASSERT_EQ(nullptr, WindowImpl::Find("")); +} + +/** + * @tc.name: FindWindow05 + * @tc.desc: Find one destroyed window + * @tc.type: FUNC + * @tc.require: AR000GGTVJ + */ +HWTEST_F(WindowImplTest, FindWindow05, Function | SmallTest | Level2) +{ + ASSERT_EQ(nullptr, WindowImpl::Find("FindWindow02")); +} + +/** + * @tc.name: SetWindowType01 + * @tc.desc: SetWindowType + * @tc.type: FUNC + * @tc.require: AR000GGTVJ + */ +HWTEST_F(WindowImplTest, SetWindowType01, Function | SmallTest | Level2) +{ + ASSERT_EQ(WMError::WM_OK, window_->SetWindowType(WindowType::WINDOW_TYPE_APP_MAIN_WINDOW)); +} + +/** + * @tc.name: SetWindowMode01 + * @tc.desc: SetWindowMode + * @tc.type: FUNC + * @tc.require: AR000GGTVJ + */ +HWTEST_F(WindowImplTest, SetWindowMode01, Function | SmallTest | Level2) +{ + ASSERT_EQ(WMError::WM_OK, window_->SetWindowMode(WindowMode::WINDOW_MODE_FULLSCREEN)); +} + +/** + * @tc.name: ShowHideWindow01 + * @tc.desc: Show and hide window with add and remove window ok + * @tc.type: FUNC + * @tc.require: AR000GGTVJ + */ +HWTEST_F(WindowImplTest, ShowHideWindow01, Function | SmallTest | Level2) +{ + std::unique_ptr m = std::make_unique(); + + EXPECT_CALL(m->Mock(), AddWindow(_)).Times(1).WillOnce(Return(WMError::WM_OK)); + ASSERT_EQ(WMError::WM_OK, window_->Show()); + EXPECT_CALL(m->Mock(), RemoveWindow(_)).Times(1).WillOnce(Return(WMError::WM_OK)); + ASSERT_EQ(WMError::WM_OK, window_->Hide()); +} + +/** + * @tc.name: ShowHideWindow02 + * @tc.desc: Show window with add window WM_ERROR_SAMGR + * @tc.type: FUNC + * @tc.require: AR000GGTVJ + */ +HWTEST_F(WindowImplTest, ShowHideWindow02, Function | SmallTest | Level2) +{ + std::unique_ptr m = std::make_unique(); + + EXPECT_CALL(m->Mock(), AddWindow(_)).Times(1).WillOnce(Return(WMError::WM_ERROR_SAMGR)); + ASSERT_EQ(WMError::WM_ERROR_SAMGR, window_->Show()); +} + +/** + * @tc.name: ShowHideWindow03 + * @tc.desc: Show window with add window WM_ERROR_IPC_FAILED + * @tc.type: FUNC + * @tc.require: AR000GGTVJ + */ +HWTEST_F(WindowImplTest, ShowHideWindow03, Function | SmallTest | Level3) +{ + std::unique_ptr m = std::make_unique(); + + EXPECT_CALL(m->Mock(), AddWindow(_)).Times(1).WillOnce(Return(WMError::WM_ERROR_IPC_FAILED)); + ASSERT_EQ(WMError::WM_ERROR_IPC_FAILED, window_->Show()); +} + +/** + * @tc.name: ShowHideWindow04 + * @tc.desc: Show window with add window OK & Hide window with remove window WM_ERROR_SAMGR + * @tc.type: FUNC + * @tc.require: AR000GGTVJ + */ +HWTEST_F(WindowImplTest, ShowHideWindow04, Function | SmallTest | Level3) +{ + std::unique_ptr m = std::make_unique(); + + EXPECT_CALL(m->Mock(), AddWindow(_)).Times(1).WillOnce(Return(WMError::WM_OK)); + ASSERT_EQ(WMError::WM_OK, window_->Show()); + EXPECT_CALL(m->Mock(), RemoveWindow(_)).Times(1).WillOnce(Return(WMError::WM_ERROR_SAMGR)); + ASSERT_EQ(WMError::WM_ERROR_SAMGR, window_->Hide()); +} + +/** + * @tc.name: ShowHideWindow05 + * @tc.desc: Hide window with remove window WM_ERROR_IPC_FAILED + * @tc.type: FUNC + * @tc.require: AR000GGTVJ + */ +HWTEST_F(WindowImplTest, ShowHideWindow05, Function | SmallTest | Level3) +{ + std::unique_ptr m = std::make_unique(); + EXPECT_CALL(m->Mock(), RemoveWindow(_)).Times(1).WillOnce(Return(WMError::WM_ERROR_IPC_FAILED)); + ASSERT_EQ(WMError::WM_ERROR_IPC_FAILED, window_->Hide()); +} + +/** + * @tc.name: ShowHideWindow06 + * @tc.desc: Hide window with remove window OK + * @tc.type: FUNC + * @tc.require: AR000GGTVJ + */ +HWTEST_F(WindowImplTest, ShowHideWindow06, Function | SmallTest | Level3) +{ + std::unique_ptr m = std::make_unique(); + EXPECT_CALL(m->Mock(), RemoveWindow(_)).Times(1).WillOnce(Return(WMError::WM_OK)); + ASSERT_EQ(WMError::WM_OK, window_->Hide()); +} +} +} // namespace Rosen +} // namespace OHOS diff --git a/wm/test/unittest/window_impl_test.h b/wm/test/unittest/window_impl_test.h new file mode 100644 index 00000000..a22bd18b --- /dev/null +++ b/wm/test/unittest/window_impl_test.h @@ -0,0 +1,39 @@ +/* + * Copyright (c) 2021 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. + */ + +#ifndef FRAMEWORKS_WM_TEST_UT_WINDOW_IMPL_TEST_H +#define FRAMEWORKS_WM_TEST_UT_WINDOW_IMPL_TEST_H + +#include +#include "ability_context_impl.h" +#include "window_impl.h" + +namespace OHOS { +namespace Rosen { +class WindowImplTest : public testing::Test { +public: + static void SetUpTestCase(); + static void TearDownTestCase(); + virtual void SetUp() override; + virtual void TearDown() override; + + static inline sptr window_ = nullptr; + static inline sptr option_ = nullptr; + static inline std::shared_ptr abilityContext_; +}; +} // namespace ROSEN +} // namespace OHOS + +#endif // FRAMEWORKS_WM_TEST_UT_WINDOW_IMPL_TEST_H \ No newline at end of file diff --git a/wm/test/unittest/window_input_channel_test.cpp b/wm/test/unittest/window_input_channel_test.cpp new file mode 100644 index 00000000..c22101e3 --- /dev/null +++ b/wm/test/unittest/window_input_channel_test.cpp @@ -0,0 +1,91 @@ +/* + * Copyright (c) 2021 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 "window_input_channel_test.h" +#include "mock_window_adapter.h" +#include "singleton_mocker.h" + +using namespace testing; +using namespace testing::ext; + +namespace OHOS { +namespace Rosen { +using WindowMocker = SingletonMocker; +void WindowInputChannelTest::SetUpTestCase() +{ + std::unique_ptr m = std::make_unique(); + sptr option = new WindowOption(); + option->SetWindowName("window"); + window_ = new WindowImpl(option); + EXPECT_CALL(m->Mock(), CreateWindow(_, _, _, _)).Times(1).WillOnce(Return(WMError::WM_OK)); + window_->Create(""); +} + +void WindowInputChannelTest::TearDownTestCase() +{ +} + +void WindowInputChannelTest::SetUp() +{ +} + +void WindowInputChannelTest::TearDown() +{ +} + +namespace { +/** + * @tc.name: HandlePointerEvent + * @tc.desc: consume pointer event when receive callback from input + * @tc.type: FUNC + * @tc.require: AR000GGTUV + */ +HWTEST_F(WindowInputChannelTest, HandlePointerEvent, Function | SmallTest | Level2) +{ + auto pointerEvent = MMI::PointerEvent::Create(); + sptr inputChannel = new WindowInputChannel(window_); + window_->ConsumePointerEvent(pointerEvent); + inputChannel->HandlePointerEvent(pointerEvent); +} + +/** + * @tc.name: HandleKeyEvent + * @tc.desc: consume key event when receive callback from input + * @tc.type: FUNC + * @tc.require: AR000GGTUV + */ +HWTEST_F(WindowInputChannelTest, HandleKeyEvent, Function | SmallTest | Level2) +{ + auto keyEvent = MMI::KeyEvent::Create(); + sptr inputChannel = new WindowInputChannel(window_); + window_->ConsumeKeyEvent(keyEvent); + inputChannel->HandleKeyEvent(keyEvent); +} + +/** + * @tc.name: SetInputListener + * @tc.desc: set input listener when create window + * @tc.type: FUNC + * @tc.require: AR000GGTUV + */ +HWTEST_F(WindowInputChannelTest, SetInputListener, Function | SmallTest | Level2) +{ + sptr inputChannel = new WindowInputChannel(window_); + std::shared_ptr listener = std::make_shared(InputEventListener()); + inputChannel->SetInputListener(listener); +} +} +} // namespace Rosen +} // namespace OHOS diff --git a/wmtest/unittest/include/window_impl_test.h b/wm/test/unittest/window_input_channel_test.h similarity index 72% rename from wmtest/unittest/include/window_impl_test.h rename to wm/test/unittest/window_input_channel_test.h index f9adbf5f..4f43ff2f 100644 --- a/wmtest/unittest/include/window_impl_test.h +++ b/wm/test/unittest/window_input_channel_test.h @@ -13,25 +13,24 @@ * limitations under the License. */ -#ifndef UNITTEST_WINDOW_IMPL_TEST_H -#define UNITTEST_WINDOW_IMPL_TEST_H +#ifndef FRAMEWORKS_WM_TEST_UT_WINDOW_INPUT_CHANNEL_TEST_H +#define FRAMEWORKS_WM_TEST_UT_WINDOW_INPUT_CHANNEL_TEST_H #include #include "window_impl.h" +#include "window_input_channel.h" namespace OHOS { namespace Rosen { -class WindowImplTest : public testing::Test { +class WindowInputChannelTest : public testing::Test { public: static void SetUpTestCase(); static void TearDownTestCase(); virtual void SetUp() override; virtual void TearDown() override; - - static inline sptr window_ = nullptr; - static inline sptr property_ = nullptr; + static inline sptr window_; }; } // namespace ROSEN } // namespace OHOS -#endif // FRAMEWORKS_WM_TEST_UNITTEST_WINDOW_IMPL_TEST_H \ No newline at end of file +#endif // FRAMEWORKS_WM_TEST_UT_WINDOW_INPUT_CHANNEL_TEST_H \ No newline at end of file diff --git a/wm/test/unittest/window_option_test.cpp b/wm/test/unittest/window_option_test.cpp new file mode 100644 index 00000000..fcf61560 --- /dev/null +++ b/wm/test/unittest/window_option_test.cpp @@ -0,0 +1,191 @@ +/* + * Copyright (c) 2021 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 "window_option_test.h" + +using namespace testing; +using namespace testing::ext; + +namespace OHOS { +namespace Rosen { +void WindowOptionTest::SetUpTestCase() +{ +} + +void WindowOptionTest::TearDownTestCase() +{ +} + +void WindowOptionTest::SetUp() +{ +} + +void WindowOptionTest::TearDown() +{ +} + +namespace { +/** + * @tc.name: WindowRect01 + * @tc.desc: SetWindowRect/GetWindowRect + * @tc.type: FUNC + * @tc.require: AR000GGTVJ + */ +HWTEST_F(WindowOptionTest, WindowRect01, Function | SmallTest | Level2) +{ + sptr option = new WindowOption(); + struct Rect rect = {1, 2, 3u, 4u}; + option->SetWindowRect(rect); + + ASSERT_EQ(1, option->GetWindowRect().posX_); + ASSERT_EQ(2, option->GetWindowRect().posY_); + ASSERT_EQ(3u, option->GetWindowRect().width_); + ASSERT_EQ(4u, option->GetWindowRect().height_); +} + +/** + * @tc.name: WindowType01 + * @tc.desc: SetWindowType/GetWindowType + * @tc.type: FUNC + * @tc.require: AR000GGTVJ + */ +HWTEST_F(WindowOptionTest, WindowType01, Function | SmallTest | Level2) +{ + sptr option = new WindowOption(); + option->SetWindowType(WindowType::WINDOW_TYPE_APP_MAIN_WINDOW); + ASSERT_EQ(WindowType::WINDOW_TYPE_APP_MAIN_WINDOW, option->GetWindowType()); +} + +/** + * @tc.name: WindowMode01 + * @tc.desc: SetWindowMode/GetWindowMode + * @tc.type: FUNC + * @tc.require: AR000GGTVJ + */ +HWTEST_F(WindowOptionTest, WindowMode01, Function | SmallTest | Level2) +{ + sptr option = new WindowOption(); + option->SetWindowMode(WindowMode::WINDOW_MODE_FULLSCREEN); + ASSERT_EQ(WindowMode::WINDOW_MODE_FULLSCREEN, option->GetWindowMode()); +} + +/** + * @tc.name: Focusable01 + * @tc.desc: SetFocusable/GetFocusable + * @tc.type: FUNC + * @tc.require: AR000GGTVJ + */ +HWTEST_F(WindowOptionTest, Focusable01, Function | SmallTest | Level2) +{ + sptr option = new WindowOption(); + option->SetFocusable(true); + ASSERT_EQ(true, option->GetFocusable()); +} + +/** + * @tc.name: Touchable01 + * @tc.desc: SetTouchable/GetTouchable + * @tc.type: FUNC + * @tc.require: AR000GGTVJ + */ +HWTEST_F(WindowOptionTest, Touchable01, Function | SmallTest | Level2) +{ + sptr option = new WindowOption(); + option->SetTouchable(true); + ASSERT_EQ(true, option->GetTouchable()); +} + +/** + * @tc.name: DisplayId01 + * @tc.desc: SetDisplayId/GetDisplayId + * @tc.type: FUNC + * @tc.require: AR000GGTVJ + */ +HWTEST_F(WindowOptionTest, DisplayId01, Function | SmallTest | Level2) +{ + sptr option = new WindowOption(); + option->SetDisplayId(1); + ASSERT_EQ(1, option->GetDisplayId()); +} + +/** + * @tc.name: ParentName01 + * @tc.desc: SetParentName/GetParentName + * @tc.type: FUNC + * @tc.require: AR000GGTVJ + */ +HWTEST_F(WindowOptionTest, ParentName01, Function | SmallTest | Level2) +{ + sptr option = new WindowOption(); + option->SetParentName("Main Window"); + ASSERT_EQ("Main Window", option->GetParentName()); +} + +/** + * @tc.name: WindowName01 + * @tc.desc: SetWindowName/GetWindowName + * @tc.type: FUNC + * @tc.require: AR000GGTVJ + */ +HWTEST_F(WindowOptionTest, WindowName01, Function | SmallTest | Level2) +{ + sptr option = new WindowOption(); + option->SetWindowName("Sub Window"); + ASSERT_EQ("Sub Window", option->GetWindowName()); +} + +/** + * @tc.name: WindowFlag01 + * @tc.desc: SetWindowFlags/GetWindowFlags + * @tc.type: FUNC + * @tc.require: AR000GGTVJ + */ +HWTEST_F(WindowOptionTest, WindowFlag01, Function | SmallTest | Level2) +{ + sptr option = new WindowOption(); + option->SetWindowFlags(1u); + ASSERT_EQ(1u, option->GetWindowFlags()); +} + +/** + * @tc.name: WindowFlag02 + * @tc.desc: AddWindowFlag/GetWindowFlags + * @tc.type: FUNC + * @tc.require: AR000GGTVJ + */ +HWTEST_F(WindowOptionTest, WindowFlag02, Function | SmallTest | Level2) +{ + sptr option = new WindowOption(); + option->AddWindowFlag(WindowFlag::WINDOW_FLAG_NEED_AVOID); + ASSERT_EQ(static_cast(WindowFlag::WINDOW_FLAG_NEED_AVOID), option->GetWindowFlags()); +} + +/** + * @tc.name: WindowFlag03 + * @tc.desc: AddWindowFlag/RemoveWindowFlag/GetWindowFlags + * @tc.type: FUNC + * @tc.require: AR000GGTVJ + */ +HWTEST_F(WindowOptionTest, WindowFlag03, Function | SmallTest | Level2) +{ + sptr option = new WindowOption(); + option->AddWindowFlag(WindowFlag::WINDOW_FLAG_NEED_AVOID); + option->AddWindowFlag(WindowFlag::WINDOW_FLAG_PARENT_LIMIT); + option->RemoveWindowFlag(WindowFlag::WINDOW_FLAG_NEED_AVOID); + ASSERT_EQ(static_cast(WindowFlag::WINDOW_FLAG_PARENT_LIMIT), option->GetWindowFlags()); +} +} +} // namespace Rosen +} // namespace OHOS diff --git a/wm/test/unittest/window_option_test.h b/wm/test/unittest/window_option_test.h new file mode 100644 index 00000000..09c7d7b1 --- /dev/null +++ b/wm/test/unittest/window_option_test.h @@ -0,0 +1,33 @@ +/* + * Copyright (c) 2021 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. + */ + +#ifndef FRAMEWORKS_WM_TEST_UT_WINDOW_OPTION_TEST_H +#define FRAMEWORKS_WM_TEST_UT_WINDOW_OPTION_TEST_H + +#include +#include "window_option.h" + +namespace OHOS { +namespace Rosen { +class WindowOptionTest : public testing::Test { +public: + static void SetUpTestCase(); + static void TearDownTestCase(); + virtual void SetUp() override; + virtual void TearDown() override; +}; +} // namespace ROSEN +} // namespace OHOS +#endif // FRAMEWORKS_WM_TEST_UT_WINDOW_OPTION_TEST_H diff --git a/wm/test/unittest/window_scene_test.cpp b/wm/test/unittest/window_scene_test.cpp new file mode 100644 index 00000000..b00ed6f9 --- /dev/null +++ b/wm/test/unittest/window_scene_test.cpp @@ -0,0 +1,231 @@ +/* + * Copyright (c) 2021 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 "window_scene_test.h" +#include "ability_context_impl.h" +#include "mock_static_call.h" +#include "singleton_mocker.h" +#include "window_impl.h" + +using namespace testing; +using namespace testing::ext; + +namespace OHOS { +namespace Rosen { +using Mocker = SingletonMocker; +void WindowSceneTest::SetUpTestCase() +{ + int displayId = 0; + sptr listener = nullptr; + scene_ = new WindowScene(); + abilityContext_ = std::make_shared(); + std::unique_ptr m = std::make_unique(); + sptr option = new WindowOption(); + EXPECT_CALL(m->Mock(), CreateWindow(_, _, _)).Times(1).WillOnce(Return(new WindowImpl(option))); + ASSERT_EQ(WMError::WM_OK, scene_->Init(displayId, abilityContext_, listener)); +} + +void WindowSceneTest::TearDownTestCase() +{ +} + +void WindowSceneTest::SetUp() +{ +} + +void WindowSceneTest::TearDown() +{ +} + +namespace { +/** + * @tc.name: Init01 + * @tc.desc: Init Scene with null abilityContext, null listener + * @tc.type: FUNC + * @tc.require: AR000GGTVJ + */ +HWTEST_F(WindowSceneTest, Init01, Function | SmallTest | Level2) +{ + std::unique_ptr m = std::make_unique(); + sptr optionTest = new WindowOption(); + EXPECT_CALL(m->Mock(), CreateWindow(_, _, _)).Times(1).WillOnce(Return(new WindowImpl(optionTest))); + int displayId = 0; + sptr listener = nullptr; + sptr scene = new WindowScene(); + std::shared_ptr abilityContext = nullptr; + ASSERT_EQ(WMError::WM_OK, scene->Init(displayId, abilityContext, listener)); +} + +/** + * @tc.name: Init02 + * @tc.desc: Mock window Create Static Method return nullptr, init Scene with null abilityContext, null listener + * @tc.type: FUNC + * @tc.require: AR000GGTVJ + */ +HWTEST_F(WindowSceneTest, Init02, Function | SmallTest | Level2) +{ + std::unique_ptr m = std::make_unique(); + sptr optionTest = new WindowOption(); + EXPECT_CALL(m->Mock(), CreateWindow(_, _, _)).Times(1).WillOnce(Return(nullptr)); + int displayId = 0; + sptr listener = nullptr; + sptr scene = new WindowScene(); + std::shared_ptr abilityContext = nullptr; + ASSERT_EQ(WMError::WM_ERROR_NULLPTR, scene->Init(displayId, abilityContext, listener)); +} + +/** + * @tc.name: Init03 + * @tc.desc: Init Scene with abilityContext, null listener + * @tc.type: FUNC + * @tc.require: AR000GGTVJ + */ +HWTEST_F(WindowSceneTest, Init03, Function | SmallTest | Level2) +{ + std::unique_ptr m = std::make_unique(); + sptr optionTest = new WindowOption(); + EXPECT_CALL(m->Mock(), CreateWindow(_, _, _)).Times(1).WillOnce(Return(new WindowImpl(optionTest))); + int displayId = 0; + sptr listener = nullptr; + sptr scene = new WindowScene(); + ASSERT_EQ(WMError::WM_OK, scene->Init(displayId, abilityContext_, listener)); +} + +/** + * @tc.name: Create01 + * @tc.desc: CreateWindow without windowName + * @tc.type: FUNC + * @tc.require: AR000GGTVJ + */ +HWTEST_F(WindowSceneTest, Create01, Function | SmallTest | Level2) +{ + sptr optionTest = new WindowOption(); + sptr scene = new WindowScene(); + ASSERT_EQ(nullptr, scene->CreateWindow("", optionTest)); +} + +/** + * @tc.name: Create02 + * @tc.desc: CreateWindow with windowName and without mainWindow + * @tc.type: FUNC + * @tc.require: AR000GGTVJ + */ +HWTEST_F(WindowSceneTest, Create02, Function | SmallTest | Level2) +{ + sptr optionTest = new WindowOption(); + sptr scene = new WindowScene(); + ASSERT_EQ(nullptr, scene->CreateWindow("WindowSceneTest02", optionTest)); +} + +/** + * @tc.name: Create03 + * @tc.desc: CreateWindow with windowName and mainWindow + * @tc.type: FUNC + * @tc.require: AR000GGTVJ + */ +HWTEST_F(WindowSceneTest, Create03, Function | SmallTest | Level2) +{ + std::unique_ptr m = std::make_unique(); + sptr optionTest = new WindowOption(); + EXPECT_CALL(m->Mock(), CreateWindow(_, _, _)).Times(1).WillOnce(Return(new WindowImpl(optionTest))); + ASSERT_NE(nullptr, scene_->CreateWindow("WindowSceneTest03", optionTest)); +} + +/** + * @tc.name: Create04 + * @tc.desc: Mock window Create Static Method return nullptr, createWindow with windowName and mainWindow + * @tc.type: FUNC + * @tc.require: AR000GGTVJ + */ +HWTEST_F(WindowSceneTest, Create04, Function | SmallTest | Level2) +{ + sptr optionTest = new WindowOption(); + std::unique_ptr m = std::make_unique(); + EXPECT_CALL(m->Mock(), CreateWindow(_, _, _)).Times(1).WillOnce(Return(nullptr)); + ASSERT_EQ(nullptr, scene_->CreateWindow("WindowSceneTest04", optionTest)); +} + +/** + * @tc.name: Create05 + * @tc.desc: createWindow with windowName and null option + * @tc.type: FUNC + * @tc.require: AR000GGTVJ + */ +HWTEST_F(WindowSceneTest, Create05, Function | SmallTest | Level2) +{ + sptr optionTest = nullptr; + ASSERT_EQ(nullptr, scene_->CreateWindow("WindowSceneTest05", optionTest)); +} + +/** + * @tc.name: GetMainWindow01 + * @tc.desc: GetMainWindow without scene init + * @tc.type: FUNC + * @tc.require: AR000GGTVJ + */ +HWTEST_F(WindowSceneTest, GetMainWindow01, Function | SmallTest | Level2) +{ + sptr scene = new WindowScene(); + ASSERT_EQ(nullptr, scene->GetMainWindow()); +} + +/** + * @tc.name: GetMainWindow02 + * @tc.desc: GetMainWindow01 with scene init success + * @tc.type: FUNC + * @tc.require: AR000GGTVJ + */ +HWTEST_F(WindowSceneTest, GetMainWindow02, Function | SmallTest | Level2) +{ + ASSERT_NE(nullptr, scene_->GetMainWindow()); +} + +/** + * @tc.name: GoForeground01 + * @tc.desc: GoForeground01 without mainWindow + * @tc.type: FUNC + * @tc.require: AR000GGTVJ + */ +HWTEST_F(WindowSceneTest, GoForeground01, Function | SmallTest | Level2) +{ + sptr scene = new WindowScene(); + ASSERT_EQ(WMError::WM_ERROR_NULLPTR, scene->GoForeground()); +} + +/** + * @tc.name: GoBackground01 + * @tc.desc: GoBackground01 without mainWindow + * @tc.type: FUNC + * @tc.require: AR000GGTVJ + */ +HWTEST_F(WindowSceneTest, GoBackground01, Function | SmallTest | Level2) +{ + sptr scene = new WindowScene(); + ASSERT_EQ(WMError::WM_ERROR_NULLPTR, scene->GoBackground()); +} + +/** + * @tc.name: RequestFocus01 + * @tc.desc: RequestFocus01 without mainWindow + * @tc.type: FUNC + * @tc.require: AR000GGTVJ + */ +HWTEST_F(WindowSceneTest, RequestFocus01, Function | SmallTest | Level2) +{ + sptr scene = new WindowScene(); + ASSERT_EQ(WMError::WM_ERROR_NULLPTR, scene->RequestFocus()); +} +} +} // namespace Rosen +} // namespace OHOS \ No newline at end of file diff --git a/wm/test/unittest/window_scene_test.h b/wm/test/unittest/window_scene_test.h new file mode 100644 index 00000000..3573507f --- /dev/null +++ b/wm/test/unittest/window_scene_test.h @@ -0,0 +1,37 @@ +/* + * Copyright (c) 2021 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. + */ + +#ifndef FRAMEWORKS_WM_TEST_UT_WINDOW_SCENE_TEST_H +#define FRAMEWORKS_WM_TEST_UT_WINDOW_SCENE_TEST_H + +#include +#include "window_scene.h" + +namespace OHOS { +namespace Rosen { +class WindowSceneTest : public testing::Test { +public: + static void SetUpTestCase(); + static void TearDownTestCase(); + virtual void SetUp() override; + virtual void TearDown() override; + + static inline sptr scene_ = nullptr; + static inline std::shared_ptr abilityContext_; +}; +} // namespace ROSEN +} // namespace OHOS + +#endif // FRAMEWORKS_WM_TEST_UT_WINDOW_SCENE_TEST_H \ No newline at end of file diff --git a/wm/test/unittest/window_test.cpp b/wm/test/unittest/window_test.cpp new file mode 100644 index 00000000..f5614b06 --- /dev/null +++ b/wm/test/unittest/window_test.cpp @@ -0,0 +1,138 @@ +/* + * Copyright (c) 2021 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 "window_test.h" +#include "mock_window_adapter.h" +#include "singleton_mocker.h" + +using namespace testing; +using namespace testing::ext; + +namespace OHOS { +namespace Rosen { +using Mocker = SingletonMocker; +void WindowTest::SetUpTestCase() +{ + abilityContext_ = std::make_shared(); +} + +void WindowTest::TearDownTestCase() +{ +} + +void WindowTest::SetUp() +{ +} + +void WindowTest::TearDown() +{ +} + +namespace { +/** + * @tc.name: Create01 + * @tc.desc: Create window with no WindowName and no abilityToken + * @tc.type: FUNC + * @tc.require: AR000GGTVJ + */ +HWTEST_F(WindowTest, Create01, Function | SmallTest | Level2) +{ + sptr option = new WindowOption(); + ASSERT_EQ(nullptr, Window::Create("", option)); +} + +/** + * @tc.name: Create02 + * @tc.desc: Create window with WindowName and no abilityToken + * @tc.type: FUNC + * @tc.require: AR000GGTVJ + */ +HWTEST_F(WindowTest, Create02, Function | SmallTest | Level2) +{ + std::unique_ptr m = std::make_unique(); + sptr option = new WindowOption(); + EXPECT_CALL(m->Mock(), CreateWindow(_, _, _, _)).Times(1).WillOnce(Return(WMError::WM_OK)); + ASSERT_NE(nullptr, Window::Create("WindowTest02", option)); +} + +/** + * @tc.name: Create03 + * @tc.desc: Mock CreateWindow return WM_ERROR_SAMGR, create window with WindowName and no abilityToken + * @tc.type: FUNC + * @tc.require: AR000GGTVJ + */ +HWTEST_F(WindowTest, Create03, Function | SmallTest | Level2) +{ + std::unique_ptr m = std::make_unique(); + sptr option = new WindowOption(); + EXPECT_CALL(m->Mock(), CreateWindow(_, _, _, _)).Times(1).WillOnce(Return(WMError::WM_ERROR_SAMGR)); + ASSERT_EQ(nullptr, Window::Create("WindowTest03", option)); +} + +/** + * @tc.name: Create04 + * @tc.desc: Create window with WindowName and abilityContext + * @tc.type: FUNC + * @tc.require: AR000GGTVJ + */ +HWTEST_F(WindowTest, Create04, Function | SmallTest | Level2) +{ + std::unique_ptr m = std::make_unique(); + sptr option = new WindowOption(); + EXPECT_CALL(m->Mock(), CreateWindow(_, _, _, _)).Times(1).WillOnce(Return(WMError::WM_OK)); + EXPECT_CALL(m->Mock(), SaveAbilityToken(_, _)).Times(1).WillOnce(Return(WMError::WM_OK)); + ASSERT_NE(nullptr, Window::Create("WindowTest04", option, abilityContext_)); +} + +/** + * @tc.name: Create06 + * @tc.desc: Create window with WindowName and no option + * @tc.type: FUNC + * @tc.require: AR000GGTVJ + */ +HWTEST_F(WindowTest, Create06, Function | SmallTest | Level2) +{ + sptr option = nullptr; + ASSERT_EQ(nullptr, Window::Create("", option)); +} + +/** + * @tc.name: Find01 + * @tc.desc: Find with no name + * @tc.type: FUNC + * @tc.require: AR000GGTVJ + */ +HWTEST_F(WindowTest, Find01, Function | SmallTest | Level2) +{ + ASSERT_EQ(nullptr, Window::Find("")); +} + +/** + * @tc.name: Find02 + * @tc.desc: Find with name + * @tc.type: FUNC + * @tc.require: AR000GGTVJ + */ +HWTEST_F(WindowTest, Find02, Function | SmallTest | Level2) +{ + std::unique_ptr m = std::make_unique(); + sptr option = new WindowOption(); + EXPECT_CALL(m->Mock(), CreateWindow(_, _, _, _)).Times(1).WillOnce(Return(WMError::WM_OK)); + ASSERT_NE(nullptr, Window::Create("WindowTest03", option)); + ASSERT_NE(nullptr, Window::Find("WindowTest03")); +} +} +} // namespace Rosen +} // namespace OHOS diff --git a/wm/test/unittest/window_test.h b/wm/test/unittest/window_test.h new file mode 100644 index 00000000..58ff5cc7 --- /dev/null +++ b/wm/test/unittest/window_test.h @@ -0,0 +1,36 @@ +/* + * Copyright (c) 2021 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. + */ + +#ifndef FRAMEWORKS_WM_TEST_UT_WINDOW_TEST_H +#define FRAMEWORKS_WM_TEST_UT_WINDOW_TEST_H + +#include +#include "ability_context_impl.h" +#include "window.h" + +namespace OHOS { +namespace Rosen { +class WindowTest : public testing::Test { +public: + static void SetUpTestCase(); + static void TearDownTestCase(); + virtual void SetUp() override; + virtual void TearDown() override; + static inline std::shared_ptr abilityContext_; +}; +} // namespace ROSEN +} // namespace OHOS + +#endif // FRAMEWORKS_WM_TEST_UT_WINDOW_TEST_H \ No newline at end of file diff --git a/wmtest/unittest/BUILD.gn b/wmtest/unittest/BUILD.gn deleted file mode 100644 index b034b699..00000000 --- a/wmtest/unittest/BUILD.gn +++ /dev/null @@ -1,85 +0,0 @@ -# Copyright (c) 2021 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. - -import("//build/test.gni") -module_out_path = "window_manager/" - -group("unittest") { - testonly = true - - deps = [ ":ut_window_impl_test" ] -} - -## UnitTest ut_window_impl_test {{{ -ohos_unittest("ut_window_impl_test") { - module_out_path = module_out_path - - sources = [ "src/window_impl_test.cpp" ] - - deps = [ ":unittest_wmtest_common" ] -} - -## UnitTest ut_window_impl_test }}} - -## Build unittest_wmtest_common.a {{{ -config("unittest_wmtest_common_public_config") { - include_dirs = [ - "//foundation/windowmanager/wm/include", - "//foundation/windowmanager/wmserver/include", - "include", - "//foundation/windowmanager/interfaces/innerkits/wm", - "//utils/native/base/include", - "//foundation/communication/ipc/interfaces/innerkits/ipc_core/include", - "//base/hiviewdfx/hilog/interfaces/native/innerkits/include", - "//foundation/windowmanager/utils/include", - "//third_party/googletest/googlemock/include", - - #RSSurface - "//foundation/graphic/standard/rosen/modules/render_service_client/core", - "//foundation/graphic/standard/rosen/modules/render_service_base/include", - "//third_party/flutter/skia", - ] - - cflags = [ - "-Wall", - "-Werror", - "-g3", - "-Dprivate=public", - "-Dprotected=public", - ] -} - -ohos_static_library("unittest_wmtest_common") { - visibility = [ ":*" ] - testonly = true - - public_configs = [ ":unittest_wmtest_common_public_config" ] - - deps = [ - "//foundation/windowmanager/wm:libwm", - "//foundation/windowmanager/wm:libwmutil", - "//foundation/windowmanager/wmserver:libwms", - "//third_party/googletest:gmock", - "//utils/native/base:utils", - - # RSSurface - "//foundation/graphic/standard/rosen/modules/render_service_base:librender_service_base", - "//foundation/graphic/standard/rosen/modules/render_service_client:librender_service_client", - ] - - external_deps = [ - "hiviewdfx_hilog_native:libhilog", - "ipc:ipc_core", - ] -} -## Build unittest_wmtest_common.a }}} diff --git a/wmtest/unittest/include/test_header.h b/wmtest/unittest/include/test_header.h deleted file mode 100644 index 31f8bfbd..00000000 --- a/wmtest/unittest/include/test_header.h +++ /dev/null @@ -1,43 +0,0 @@ -/* - * Copyright (c) 2021 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. - */ - -#ifndef UNITTEST_TEST_HEADER_H -#define UNITTEST_TEST_HEADER_H - -#include "window_manager_hilog.h" - -namespace OHOS { -namespace Rosen { -#define _WMT_CPRINTF(color, func, fmt, ...) \ - func({LOG_CORE, 0, "WM_UINTTEST"}, "\033[" #color "m" "<%{public}d>" fmt "\033[0m", __LINE__, ##__VA_ARGS__) -#define WMTLOGI(color, fmt, ...) \ - _WMT_CPRINTF(color, HiviewDFX::HiLog::Info, "%{public}s: " fmt, __func__, ##__VA_ARGS__) - -#define PART(part) WMTLOGI(33, part); if (const char *strPart = part) -#define STEP(desc) WMTLOGI(34, desc); if (const char *strDesc = desc) - -#define STEP_CONDITION(condition) strPart << ": " << strDesc << " (" << condition << ")" - -#define STEP_ASSERT_(l, r, func, opstr) ASSERT_##func(l, r) << STEP_CONDITION(#l " " opstr " " #r) - -#define STEP_ASSERT_EQ(l, r) STEP_ASSERT_(l, r, EQ, "==") -#define STEP_ASSERT_NE(l, r) STEP_ASSERT_(l, r, NE, "!=") -#define STEP_ASSERT_GE(l, r) STEP_ASSERT_(l, r, GE, ">=") -#define STEP_ASSERT_LE(l, r) STEP_ASSERT_(l, r, LE, "<=") -#define STEP_ASSERT_GT(l, r) STEP_ASSERT_(l, r, GT, ">") -#define STEP_ASSERT_LT(l, r) STEP_ASSERT_(l, r, LT, "<") -} // namespace Rosen -} // namespace OHOS -#endif // UNITTEST_TEST_HEADER_H diff --git a/wmtest/unittest/src/window_impl_test.cpp b/wmtest/unittest/src/window_impl_test.cpp deleted file mode 100644 index 3e6bd8b3..00000000 --- a/wmtest/unittest/src/window_impl_test.cpp +++ /dev/null @@ -1,130 +0,0 @@ -/* - * Copyright (c) 2021 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 "window_impl_test.h" -#include "mock/mock_window_adapter.h" -#include "mock/singleton_mocker.h" -#include "test_header.h" -#include "window_property.h" - - -namespace OHOS { -namespace Rosen { -using namespace testing; - -void WindowImplTest::SetUpTestCase() -{ - property_ = sptr(new WindowProperty()); - property_->SetWindowId(0); - window_ = sptr(new WindowImpl(property_)); -} - -void WindowImplTest::TearDownTestCase() -{ -} - -void WindowImplTest::SetUp() -{ -} - -void WindowImplTest::TearDown() -{ -} - -namespace { -/* - * Function: Show - * Type: Reliability - * Rank: Important(2) - * EnvConditions: N/A - * CaseDescription: 1. mock WindowAdapter - * 2. mock AddWindow return WM_OK - * 3. call Show to AddWindow and check return is WM_OK - * 4. call Show with isAdded_=true and check return is WM_OK - * 5. mock RemoveWindow return WM_OK - * 6. call Destroy check return is WM_OK - */ -HWTEST_F(WindowImplTest, ShowWindow01, testing::ext::TestSize.Level0) -{ - PART("CaseShow01") { -#ifdef _NEW_RENDERSERVER_ - using Mocker = SingletonMocker; - std::unique_ptr m = nullptr; - STEP("1. mock WindowAdapter") { - m = std::make_unique(); - } - - STEP("2. mock AddWindow return WM_OK") { - EXPECT_CALL(m->Mock(), AddWindow(_)).Times(1).WillOnce(Return(WMError::WM_OK)); - } - - STEP("3. call Show and check return is WM_OK") { - STEP_ASSERT_EQ(WMError::WM_OK, window_->Show()); - } - - STEP("4. mock RemoveWindow return WM_OK") { - EXPECT_CALL(m->Mock(), RemoveWindow(_)).Times(1).WillOnce(Return(WMError::WM_OK)); - } - - STEP("5. call Destroy check return is WM_OK") { - STEP_ASSERT_EQ(WMError::WM_OK, window_->Destroy()); - } -#endif - } -} - -/* - * Function: Show - * Type: Reliability - * Rank: Important(2) - * EnvConditions: N/A - * CaseDescription: 1. mock WindowAdapter - * 2. mock AddWindow return WM_ERROR_DEATH_RECIPIENT - * 3. call Show to AddWindow and check return is WM_ERROR_DEATH_RECIPIENT - * 4. call Show with isAdded_=true and check return is WM_ERROR_DEATH_RECIPIENT - * 5. mock RemoveWindow return WM_OK - * 6. call Destroy check return is WM_OK - */ -HWTEST_F(WindowImplTest, ShowWindow02, testing::ext::TestSize.Level0) -{ - PART("CaseShow02") { -#ifdef _NEW_RENDERSERVER_ - using Mocker = SingletonMocker; - std::unique_ptr m = nullptr; - STEP("1. mock WindowAdapter") { - m = std::make_unique(); - } - - STEP("2. mock AddWindow return WM_ERROR_DEATH_RECIPIENT") { - EXPECT_CALL(m->Mock(), AddWindow(_)).Times(1).WillOnce(Return(WMError::WM_ERROR_DEATH_RECIPIENT)); - } - - STEP("3. call Show and check return is WM_ERROR_DEATH_RECIPIENT") { - STEP_ASSERT_EQ(WMError::WM_ERROR_DEATH_RECIPIENT, window_->Show()); - } - - STEP("4. mock RemoveWindow return WM_OK") { - EXPECT_CALL(m->Mock(), RemoveWindow(_)).Times(1).WillOnce(Return(WMError::WM_OK)); - } - - STEP("5. call Destroy check return is WM_OK") { - STEP_ASSERT_EQ(WMError::WM_OK, window_->Destroy()); - } -#endif - } -} -} -} // namespace Rosen -} // namespace OHOS \ No newline at end of file From 4499699d774c7eb1c86b927f977c97894f82e41f Mon Sep 17 00:00:00 2001 From: fanby01 Date: Wed, 12 Jan 2022 15:25:36 +0800 Subject: [PATCH 2/3] add snapshot shell bin for display Change-Id: Ic828a0b9a101431622f119472d393e3394ad44d1 Signed-off-by: fanby01 --- bundle.json | 1 + snapshot/BUILD.gn | 45 +++++++++ snapshot/snapshot_display.cpp | 48 +++++++++ snapshot/snapshot_utils.cpp | 178 ++++++++++++++++++++++++++++++++++ snapshot/snapshot_utils.h | 53 ++++++++++ 5 files changed, 325 insertions(+) create mode 100644 snapshot/BUILD.gn create mode 100644 snapshot/snapshot_display.cpp create mode 100644 snapshot/snapshot_utils.cpp create mode 100644 snapshot/snapshot_utils.h diff --git a/bundle.json b/bundle.json index 48f8a822..60477fd2 100644 --- a/bundle.json +++ b/bundle.json @@ -24,6 +24,7 @@ "//foundation/windowmanager/wm:libwm", "//foundation/windowmanager/wmserver:libwms", "//foundation/windowmanager/wm:libwmutil", + "//foundation/windowmanager/snapshot:snapshot_display", "//foundation/windowmanager/interfaces/kits/napi:windowstage", "//foundation/windowmanager/interfaces/kits/napi:napi_packages" ], diff --git a/snapshot/BUILD.gn b/snapshot/BUILD.gn new file mode 100644 index 00000000..4b66a20e --- /dev/null +++ b/snapshot/BUILD.gn @@ -0,0 +1,45 @@ +# Copyright (c) 2021 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. + +import("//build/ohos.gni") + +## Build snapshot {{{ +config("snapshot_config") { + visibility = [ ":*" ] +} + +ohos_executable("snapshot_display") { + install_enable = false + sources = [ + "snapshot_display.cpp", + "snapshot_utils.cpp", + ] + + configs = [ ":snapshot_config" ] + + deps = [ + "//foundation/multimedia/image_standard/interfaces/innerkits:image_native", # PixelMap + "//foundation/windowmanager/dm:libdm", + "//foundation/windowmanager/wm:libwm", + "//third_party/libpng:libpng", # png + ] + + part_name = "window_manager" + subsystem_name = "window" +} + +## Build snapshot }}} + +group("test") { + testonly = true +} diff --git a/snapshot/snapshot_display.cpp b/snapshot/snapshot_display.cpp new file mode 100644 index 00000000..40a64d2d --- /dev/null +++ b/snapshot/snapshot_display.cpp @@ -0,0 +1,48 @@ +/* + * Copyright (c) 2021 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 "snapshot_utils.h" + +using namespace OHOS; +using namespace OHOS::Media; +using namespace OHOS::Rosen; + +int main(int argc, char *argv[]) +{ + CmdArgments cmdArgments; + cmdArgments.fileName = "/data/snapshot_display_1.png"; + + if (!SnapShotUtils::ProcessArgs(argc, argv, cmdArgments)) { + return 0; + } + + // get PixelMap from DisplayManager API + auto pixelMap = DisplayManager::GetInstance().GetScreenshot(cmdArgments.displayId); + bool ret = false; + if (pixelMap != nullptr) { + ret = SnapShotUtils::WriteToPngWithPixelMap(cmdArgments.fileName, *pixelMap); + } + if (!ret) { + printf("error: snapshot display %" PRIu64 ", write to %s as png failed!\n", + cmdArgments.displayId, cmdArgments.fileName.c_str()); + return -1; + } + + printf("success: snapshot display %" PRIu64 ", write to %s as png\n", + cmdArgments.displayId, cmdArgments.fileName.c_str()); + return 0; +} \ No newline at end of file diff --git a/snapshot/snapshot_utils.cpp b/snapshot/snapshot_utils.cpp new file mode 100644 index 00000000..cb6110cf --- /dev/null +++ b/snapshot/snapshot_utils.cpp @@ -0,0 +1,178 @@ +/* + * Copyright (c) 2021 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 "snapshot_utils.h" + +#include +#include +#include + +using namespace OHOS::Media; +using namespace OHOS::Rosen; + +namespace OHOS { +constexpr int BITMAP_DEPTH = 8; + +void SnapShotUtils::PrintUsage(const std::string &cmdLine) +{ + printf("usage: %s [-i displayId] [-f output_file]\n", cmdLine.c_str()); +} + +bool SnapShotUtils::CheckFileNameValid(const std::string &fileName) +{ + std::string fileDir = fileName; + auto pos = fileDir.find_last_of("/"); + if (pos != std::string::npos) { + fileDir.erase(pos + 1); + } else { + fileDir = "."; + } + char resolvedPath[PATH_MAX] = { 0 }; + char *realPath = realpath(fileDir.c_str(), resolvedPath); + if (realPath == nullptr) { + printf("error: fileName %s invalid, nullptr!\n", fileName.c_str()); + return false; + } + std::string realPathString = realPath; + if (realPathString.find("/data") != 0) { + printf("error: fileName %s invalid, %s must dump at dir: /data \n", fileName.c_str(), realPathString.c_str()); + return false; + } + return true; +} + +bool SnapShotUtils::WriteToPng(const std::string &fileName, const WriteToPngParam ¶m) +{ + if (!CheckFileNameValid(fileName)) { + return false; + } + png_structp pngStruct = png_create_write_struct(PNG_LIBPNG_VER_STRING, nullptr, nullptr, nullptr); + if (pngStruct == nullptr) { + printf("error: png_create_write_struct nullptr!\n"); + return false; + } + png_infop pngInfo = png_create_info_struct(pngStruct); + if (pngInfo == nullptr) { + printf("error: png_create_info_struct error nullptr!\n"); + png_destroy_write_struct(&pngStruct, nullptr); + return false; + } + FILE *fp = fopen(fileName.c_str(), "wb"); + if (fp == nullptr) { + printf("error: open file [%s] error, %d [%s]!\n", fileName.c_str(), errno, strerror(errno)); + png_destroy_write_struct(&pngStruct, &pngInfo); + return false; + } + png_init_io(pngStruct, fp); + + // set png header + png_set_IHDR(pngStruct, pngInfo, + param.width, param.height, + param.bitDepth, + PNG_COLOR_TYPE_RGBA, + PNG_INTERLACE_NONE, + PNG_COMPRESSION_TYPE_BASE, + PNG_FILTER_TYPE_BASE); + png_set_packing(pngStruct); // set packing info + png_write_info(pngStruct, pngInfo); // write to header + + for (uint32_t i = 0; i < param.height; i++) { + png_write_row(pngStruct, param.data + (i * param.stride)); + } + + png_write_end(pngStruct, pngInfo); + + // free + png_destroy_write_struct(&pngStruct, &pngInfo); + if (fclose(fp) != 0) { + return false; + } + return true; +} + +bool SnapShotUtils::WriteToPngWithPixelMap(const std::string &fileName, PixelMap &pixelMap) +{ + WriteToPngParam param; + param.width = pixelMap.GetWidth(); + param.height = pixelMap.GetHeight(); + param.data = pixelMap.GetPixels(); + param.stride = pixelMap.GetRowBytes(); + param.bitDepth = BITMAP_DEPTH; + return SnapShotUtils::WriteToPng(fileName, param); +} + +static bool ProcessDisplayId(DisplayId &displayId) +{ + if (displayId == DISPLAY_ID_INVALD) { + displayId = DisplayManager::GetInstance().GetDefaultDisplayId(); + } else { + bool validFlag = false; + auto displayIds = DisplayManager::GetInstance().GetAllDisplayIds(); + for (auto id: displayIds) { + if (displayId == id) { + validFlag = true; + break; + } + } + if (!validFlag) { + printf("error: displayId %" PRIu64 " invalid!\n", displayId); + printf("tips: supported displayIds:\n"); + for (auto id: displayIds) { + printf("\t%" PRIu64 "\n", id); + } + return false; + } + } + return true; +} + +bool SnapShotUtils::ProcessArgs(int argc, char * const argv[], CmdArgments &cmdArgments) +{ + int opt = 0; + const struct option longOption[] = { + { "id", required_argument, nullptr, 'i' }, + { "file", required_argument, nullptr, 'f' }, + { "help", required_argument, nullptr, 'h' }, + { nullptr, 0, nullptr, 0 } + }; + while ((opt = getopt_long(argc, argv, "i:f:h", longOption, nullptr)) != -1) { + switch (opt) { + case 'i': // display id + cmdArgments.displayId = atoll(optarg); + break; + case 'f': // output file name + cmdArgments.fileName = optarg; + break; + case 'h': // help + SnapShotUtils::PrintUsage(argv[0]); + return false; + default: + SnapShotUtils::PrintUsage(argv[0]); + return false; + } + } + + if (!ProcessDisplayId(cmdArgments.displayId)) { + return false; + } + + // check fileName + if (!SnapShotUtils::CheckFileNameValid(cmdArgments.fileName)) { + printf("error: filename %s invalid!\n", cmdArgments.fileName.c_str()); + return false; + } + return true; +} +} \ No newline at end of file diff --git a/snapshot/snapshot_utils.h b/snapshot/snapshot_utils.h new file mode 100644 index 00000000..3bd7cd97 --- /dev/null +++ b/snapshot/snapshot_utils.h @@ -0,0 +1,53 @@ +/* + * Copyright (c) 2021 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. + */ + +#ifndef SNAPSHOT_UTILS_H +#define SNAPSHOT_UTILS_H + +#include +#include +#include + +#include "display_manager.h" + +namespace OHOS { +using WriteToPngParam = struct { + uint32_t width; + uint32_t height; + uint32_t stride; + uint32_t bitDepth; + const uint8_t *data; +}; + +using CmdArgments = struct { + Rosen::DisplayId displayId = Rosen::DISPLAY_ID_INVALD; + std::string fileName; +}; + +class SnapShotUtils { +public: + SnapShotUtils() = default; + ~SnapShotUtils() = default; + + static void PrintUsage(const std::string &cmdLine); + static bool CheckFileNameValid(const std::string &fileName); + static bool WriteToPng(const std::string &fileName, const WriteToPngParam ¶m); + static bool WriteToPngWithPixelMap(const std::string &fileName, Media::PixelMap &pixelMap); + static bool ProcessArgs(int argc, char * const argv[], CmdArgments& cmdArgments); +private: +}; +} + +#endif // SNAPSHOT_UTILS_H From d5ed29450853ceb60a8b4b7859cdc8832d565913 Mon Sep 17 00:00:00 2001 From: jincanran Date: Tue, 11 Jan 2022 16:12:17 +0800 Subject: [PATCH 3/3] modify callback register impl for systemUI Change-Id: I467dcc6b27c20dc878fe5c588c1bd975885022e8 Signed-off-by: jincanran --- interfaces/innerkits/wm/window.h | 6 -- interfaces/innerkits/wm/window_manager.h | 8 +++ interfaces/innerkits/wm/wm_common.h | 14 ++-- wm/include/window_adapter.h | 6 +- wm/include/window_agent.h | 1 - wm/include/window_impl.h | 3 - wm/include/window_interface.h | 2 - wm/include/window_manager_agent.h | 1 + wm/include/window_proxy.h | 1 - .../zidl/window_manager_agent_interface.h | 7 ++ wm/include/zidl/window_manager_agent_proxy.h | 1 + wm/src/window_adapter.cpp | 10 +-- wm/src/window_agent.cpp | 9 --- wm/src/window_impl.cpp | 14 ---- wm/src/window_manager.cpp | 65 ++++++++++++++++++- wm/src/window_manager_agent.cpp | 5 ++ wm/src/window_property.cpp | 2 +- wm/src/window_proxy.cpp | 20 ------ wm/src/window_stub.cpp | 5 -- wm/src/zidl/window_manager_agent_proxy.cpp | 38 +++++++++++ wm/src/zidl/window_manager_agent_stub.cpp | 13 ++++ wmserver/include/window_controller.h | 6 +- wmserver/include/window_layout_policy.h | 2 - wmserver/include/window_manager_interface.h | 10 +-- wmserver/include/window_manager_proxy.h | 6 +- wmserver/include/window_manager_service.h | 6 +- wmserver/include/window_node_container.h | 10 ++- wmserver/include/window_root.h | 11 ++-- wmserver/src/window_controller.cpp | 10 +-- wmserver/src/window_layout_policy.cpp | 23 +------ wmserver/src/window_manager_proxy.cpp | 20 ++++-- wmserver/src/window_manager_service.cpp | 25 +++---- wmserver/src/window_manager_stub.cpp | 10 +-- wmserver/src/window_node_container.cpp | 19 +++--- wmserver/src/window_root.cpp | 46 +++++++++---- 35 files changed, 275 insertions(+), 160 deletions(-) diff --git a/interfaces/innerkits/wm/window.h b/interfaces/innerkits/wm/window.h index e20e0f7b..4ba32e0a 100644 --- a/interfaces/innerkits/wm/window.h +++ b/interfaces/innerkits/wm/window.h @@ -45,11 +45,6 @@ public: virtual void OnSizeChange(Rect rect) = 0; }; -class IWindowSystemBarChangeListener : public RefBase { -public: - virtual void OnSystemBarPropertyChange(uint32_t displayId, WindowType type, const SystemBarProperty& prop) = 0; -}; - class Window : public RefBase { public: static sptr Create(const std::string& windowName, @@ -89,7 +84,6 @@ public: virtual void RegisterLifeCycleListener(sptr& listener) = 0; virtual void RegisterWindowChangeListener(sptr& listener) = 0; - virtual void RegisterWindowSystemBarChangeListener(sptr& listener) = 0; virtual WMError SetUIContent(std::shared_ptr context, std::string& contentInfo, NativeEngine* engine, NativeValue* storage, bool isdistributed = false) = 0; virtual const std::string& GetContentInfo() = 0; diff --git a/interfaces/innerkits/wm/window_manager.h b/interfaces/innerkits/wm/window_manager.h index 8572d2fb..66538d75 100644 --- a/interfaces/innerkits/wm/window_manager.h +++ b/interfaces/innerkits/wm/window_manager.h @@ -34,12 +34,19 @@ public: WindowType windowType, int32_t displayId) = 0; }; +class ISystemBarChangedListener : public RefBase { +public: + virtual void OnSystemBarPropertyChange(uint64_t displayId, const SystemBarProps& props) = 0; +}; + class WindowManager : public RefBase { WM_DECLARE_SINGLE_INSTANCE_BASE(WindowManager); friend class WindowManagerAgent; public: void RegisterFocusChangedListener(const sptr& listener); void UnregisterFocusChangedListener(const sptr& listener); + void RegisterSystemBarChangedListener(const sptr& listener); + void UnregisterSystemBarChangedListener(const sptr& listener); private: WindowManager(); @@ -49,6 +56,7 @@ private: void UpdateFocusStatus(uint32_t windowId, const sptr& abilityToken, WindowType windowType, int32_t displayId, bool focused) const; + void UpdateSystemBarProperties(uint64_t displayId, const SystemBarProps& props) const; }; } // namespace Rosen } // namespace OHOS diff --git a/interfaces/innerkits/wm/wm_common.h b/interfaces/innerkits/wm/wm_common.h index 388086cd..f281ede7 100644 --- a/interfaces/innerkits/wm/wm_common.h +++ b/interfaces/innerkits/wm/wm_common.h @@ -93,6 +93,13 @@ enum class WindowFlag : uint32_t { WINDOW_FLAG_END = 1 << 2, }; +struct Rect { + int32_t posX_; + int32_t posY_; + uint32_t width_; + uint32_t height_; +}; + namespace { constexpr uint32_t SYSTEM_COLOR_WHITE = 0xE5FFFFFF; constexpr uint32_t SYSTEM_COLOR_BLACK = 0x66000000; @@ -111,12 +118,7 @@ struct SystemBarProperty { } }; -struct Rect { - int32_t posX_; - int32_t posY_; - uint32_t width_; - uint32_t height_; -}; +using SystemBarProps = std::vector>; } } #endif // OHOS_ROSEN_WM_COMMON_H diff --git a/wm/include/window_adapter.h b/wm/include/window_adapter.h index 836a7cae..66cc0dc8 100644 --- a/wm/include/window_adapter.h +++ b/wm/include/window_adapter.h @@ -47,8 +47,10 @@ public: virtual WMError SetWindowFlags(uint32_t windowId, uint32_t flags); virtual WMError SetSystemBarProperty(uint32_t windowId, WindowType type, const SystemBarProperty& property); - virtual void RegisterFocusChangedListener(const sptr& windowManagerAgent); - virtual void UnregisterFocusChangedListener(const sptr& windowManagerAgent); + virtual void RegisterWindowManagerAgent(WindowManagerAgentType type, + const sptr& windowManagerAgent); + virtual void UnregisterWindowManagerAgent(WindowManagerAgentType type, + const sptr& windowManagerAgent); virtual void ClearWindowAdapter(); private: diff --git a/wm/include/window_agent.h b/wm/include/window_agent.h index 60130bdb..31bd1ccd 100644 --- a/wm/include/window_agent.h +++ b/wm/include/window_agent.h @@ -30,7 +30,6 @@ public: void UpdateWindowRect(const struct Rect& rect) override; void UpdateWindowMode(WindowMode mode) override; void UpdateFocusStatus(bool focused) override; - void UpdateSystemBarProperty(const SystemBarProperty& prop) override; private: sptr window_; diff --git a/wm/include/window_impl.h b/wm/include/window_impl.h index 53e19417..8e8480bc 100644 --- a/wm/include/window_impl.h +++ b/wm/include/window_impl.h @@ -71,7 +71,6 @@ public: virtual void RegisterLifeCycleListener(sptr& listener) override; virtual void RegisterWindowChangeListener(sptr& listener) override; - virtual void RegisterWindowSystemBarChangeListener(sptr& listener) override; void UpdateRect(const struct Rect& rect); void UpdateMode(WindowMode mode); @@ -79,7 +78,6 @@ public: virtual void ConsumePointerEvent(std::shared_ptr& inputEvent) override; virtual void RequestFrame() override; void UpdateFocusStatus(bool focused); - void UpdateSystemBarProperty(const SystemBarProperty& prop); virtual void UpdateConfiguration(const std::shared_ptr& configuration) override; virtual WMError SetUIContent(std::shared_ptr context, @@ -130,7 +128,6 @@ private: WindowState state_ { STATE_INITIAL }; sptr lifecycleListener_; sptr windowChangeListener_; - sptr systemBarChangeListener_; std::shared_ptr surfaceNode_; std::string name_; std::unique_ptr uiContent_; diff --git a/wm/include/window_interface.h b/wm/include/window_interface.h index f3f03c0f..846ded86 100644 --- a/wm/include/window_interface.h +++ b/wm/include/window_interface.h @@ -30,14 +30,12 @@ public: TRANS_ID_UPDATE_WINDOW_RECT, TRANS_ID_UPDATE_WINDOW_MODE, TRANS_ID_UPDATE_FOCUS_STATUS, - TRANS_ID_UPDATE_SYSTEM_BAR_PROPERTY, }; virtual void UpdateWindowProperty(const WindowProperty& windowProperty) = 0; virtual void UpdateWindowRect(const struct Rect& rect) = 0; virtual void UpdateWindowMode(WindowMode mode) = 0; virtual void UpdateFocusStatus(bool focused) = 0; - virtual void UpdateSystemBarProperty(const SystemBarProperty& prop) = 0; }; } // namespace Rosen } // namespace OHOS diff --git a/wm/include/window_manager_agent.h b/wm/include/window_manager_agent.h index 60318d51..dd4717b4 100644 --- a/wm/include/window_manager_agent.h +++ b/wm/include/window_manager_agent.h @@ -27,6 +27,7 @@ public: void UpdateFocusStatus(uint32_t windowId, const sptr& abilityToken, WindowType windowType, int32_t displayId, bool focused) override; + void UpdateSystemBarProperties(uint64_t displayId, const SystemBarProps& props) override; }; } // namespace Rosen } // namespace OHOS diff --git a/wm/include/window_proxy.h b/wm/include/window_proxy.h index b7675950..8e1ea4a5 100644 --- a/wm/include/window_proxy.h +++ b/wm/include/window_proxy.h @@ -31,7 +31,6 @@ public: void UpdateWindowRect(const struct Rect& rect) override; void UpdateWindowMode(WindowMode mode) override; void UpdateFocusStatus(bool focused) override; - void UpdateSystemBarProperty(const SystemBarProperty& prop) override; private: static inline BrokerDelegator delegator_; diff --git a/wm/include/zidl/window_manager_agent_interface.h b/wm/include/zidl/window_manager_agent_interface.h index 5f12fc61..2ea31279 100644 --- a/wm/include/zidl/window_manager_agent_interface.h +++ b/wm/include/zidl/window_manager_agent_interface.h @@ -21,16 +21,23 @@ namespace OHOS { namespace Rosen { +enum class WindowManagerAgentType : uint32_t { + WINDOW_MANAGER_AGENT_TYPE_FOCUS, + WINDOW_MANAGER_AGENT_TYPE_SYSTEM_BAR, +}; + class IWindowManagerAgent : public IRemoteBroker { public: DECLARE_INTERFACE_DESCRIPTOR(u"OHOS.IWindowManagerAgent"); enum { TRANS_ID_UPDATE_FOCUS_STATUS = 1, + TRANS_ID_UPDATE_SYSTEM_BAR_PROPS = 2, }; virtual void UpdateFocusStatus(uint32_t windowId, const sptr& abilityToken, WindowType windowType, int32_t displayId, bool focused) = 0; + virtual void UpdateSystemBarProperties(uint64_t displayId, const SystemBarProps& props) = 0; }; } // namespace Rosen } // namespace OHOS diff --git a/wm/include/zidl/window_manager_agent_proxy.h b/wm/include/zidl/window_manager_agent_proxy.h index 4798dde4..e3011faa 100644 --- a/wm/include/zidl/window_manager_agent_proxy.h +++ b/wm/include/zidl/window_manager_agent_proxy.h @@ -29,6 +29,7 @@ public: void UpdateFocusStatus(uint32_t windowId, const sptr& abilityToken, WindowType windowType, int32_t displayId, bool focused) override; + void UpdateSystemBarProperties(uint64_t displayId, const SystemBarProps& props) override; private: static inline BrokerDelegator delegator_; diff --git a/wm/src/window_adapter.cpp b/wm/src/window_adapter.cpp index 08d1f93c..7e68e1ce 100644 --- a/wm/src/window_adapter.cpp +++ b/wm/src/window_adapter.cpp @@ -126,24 +126,26 @@ WMError WindowAdapter::SetSystemBarProperty(uint32_t windowId, WindowType type, return windowManagerServiceProxy_->SetSystemBarProperty(windowId, type, property); } -void WindowAdapter::RegisterFocusChangedListener(const sptr& windowManagerAgent) +void WindowAdapter::RegisterWindowManagerAgent(WindowManagerAgentType type, + const sptr& windowManagerAgent) { std::lock_guard lock(mutex_); if (!InitWMSProxyLocked()) { return; } - return windowManagerServiceProxy_->RegisterFocusChangedListener(windowManagerAgent); + return windowManagerServiceProxy_->RegisterWindowManagerAgent(type, windowManagerAgent); } -void WindowAdapter::UnregisterFocusChangedListener(const sptr& windowManagerAgent) +void WindowAdapter::UnregisterWindowManagerAgent(WindowManagerAgentType type, + const sptr& windowManagerAgent) { std::lock_guard lock(mutex_); if (!InitWMSProxyLocked()) { return; } - return windowManagerServiceProxy_->UnregisterFocusChangedListener(windowManagerAgent); + return windowManagerServiceProxy_->UnregisterWindowManagerAgent(type, windowManagerAgent); } bool WindowAdapter::InitWMSProxyLocked() diff --git a/wm/src/window_agent.cpp b/wm/src/window_agent.cpp index ad337d12..79f7a285 100644 --- a/wm/src/window_agent.cpp +++ b/wm/src/window_agent.cpp @@ -57,14 +57,5 @@ void WindowAgent::UpdateFocusStatus(bool focused) } window_->UpdateFocusStatus(focused); } - -void WindowAgent::UpdateSystemBarProperty(const SystemBarProperty& prop) -{ - if (window_ == nullptr) { - WLOGFE("window_ is nullptr"); - return; - } - window_->UpdateSystemBarProperty(prop); -} } // namespace Rosen } // namespace OHOS diff --git a/wm/src/window_impl.cpp b/wm/src/window_impl.cpp index e58209c8..bf220791 100644 --- a/wm/src/window_impl.cpp +++ b/wm/src/window_impl.cpp @@ -455,10 +455,6 @@ void WindowImpl::RegisterWindowChangeListener(sptr& liste windowChangeListener_ = listener; } -void WindowImpl::RegisterWindowSystemBarChangeListener(sptr& listener) -{ - systemBarChangeListener_ = listener; -} void WindowImpl::UpdateRect(const struct Rect& rect) { WLOGFI("winId:%{public}d, rect[%{public}d, %{public}d, %{public}d, %{public}d]", GetWindowId(), rect.posX_, @@ -539,16 +535,6 @@ void WindowImpl::UpdateFocusStatus(bool focused) } } -void WindowImpl::UpdateSystemBarProperty(const SystemBarProperty& prop) -{ - WLOGFI("winId:%{public}d, enable:%{public}d, backgroundColor:%{public}x, contentColor:%{public}x", GetWindowId(), - prop.enable_, prop.backgroundColor_, prop.contentColor_); - if (systemBarChangeListener_ != nullptr) { - systemBarChangeListener_->OnSystemBarPropertyChange(property_->GetDisplayId(), - property_->GetWindowType(), prop); - } -} - void WindowImpl::UpdateConfiguration(const std::shared_ptr& configuration) { if (uiContent_ != nullptr) { diff --git a/wm/src/window_manager.cpp b/wm/src/window_manager.cpp index 45713eb6..6753df7a 100644 --- a/wm/src/window_manager.cpp +++ b/wm/src/window_manager.cpp @@ -32,12 +32,14 @@ public: WindowType windowType, int32_t displayId) const; void NotifyUnfocused(uint32_t windowId, const sptr& abilityToken, WindowType windowType, int32_t displayId) const; - + void NotifySystemBarChanged(uint64_t displayId, const SystemBarProps& props) const; static inline SingletonDelegator delegator_; std::mutex mutex_; std::vector> focusChangedListeners_; sptr focusChangedListenerAgent_; + std::vector> systemBarChangedListeners_; + sptr systemBarChangedListenerAgent_; }; void WindowManager::Impl::NotifyFocused(uint32_t windowId, const sptr& abilityToken, @@ -60,6 +62,18 @@ void WindowManager::Impl::NotifyUnfocused(uint32_t windowId, const sptrOnSystemBarPropertyChange(displayId, props); + } +} + WindowManager::WindowManager() : pImpl_(std::make_unique()) { } @@ -79,7 +93,8 @@ void WindowManager::RegisterFocusChangedListener(const sptrfocusChangedListeners_.push_back(listener); if (pImpl_->focusChangedListenerAgent_ == nullptr) { pImpl_->focusChangedListenerAgent_ = new WindowManagerAgent(); - SingletonContainer::Get().RegisterFocusChangedListener(pImpl_->focusChangedListenerAgent_); + SingletonContainer::Get().RegisterWindowManagerAgent( + WindowManagerAgentType::WINDOW_MANAGER_AGENT_TYPE_FOCUS, pImpl_->focusChangedListenerAgent_); } } @@ -98,7 +113,45 @@ void WindowManager::UnregisterFocusChangedListener(const sptrfocusChangedListeners_.erase(iter); if (pImpl_->focusChangedListeners_.empty() && pImpl_->focusChangedListenerAgent_ != nullptr) { - SingletonContainer::Get().UnregisterFocusChangedListener(pImpl_->focusChangedListenerAgent_); + SingletonContainer::Get().UnregisterWindowManagerAgent( + WindowManagerAgentType::WINDOW_MANAGER_AGENT_TYPE_FOCUS, pImpl_->focusChangedListenerAgent_); + } +} + +void WindowManager::RegisterSystemBarChangedListener(const sptr& listener) +{ + if (listener == nullptr) { + WLOGFE("listener could not be null"); + return; + } + + std::lock_guard lock(pImpl_->mutex_); + pImpl_->systemBarChangedListeners_.push_back(listener); + if (pImpl_->systemBarChangedListenerAgent_ == nullptr) { + pImpl_->systemBarChangedListenerAgent_ = new WindowManagerAgent(); + SingletonContainer::Get().RegisterWindowManagerAgent( + WindowManagerAgentType::WINDOW_MANAGER_AGENT_TYPE_SYSTEM_BAR, pImpl_->systemBarChangedListenerAgent_); + } +} + +void WindowManager::UnregisterSystemBarChangedListener(const sptr& listener) +{ + if (listener == nullptr) { + WLOGFE("listener could not be null"); + return; + } + + std::lock_guard lock(pImpl_->mutex_); + auto iter = std::find(pImpl_->systemBarChangedListeners_.begin(), pImpl_->systemBarChangedListeners_.end(), + listener); + if (iter == pImpl_->systemBarChangedListeners_.end()) { + WLOGFE("could not find this listener"); + return; + } + pImpl_->systemBarChangedListeners_.erase(iter); + if (pImpl_->systemBarChangedListeners_.empty() && pImpl_->systemBarChangedListenerAgent_ != nullptr) { + SingletonContainer::Get().UnregisterWindowManagerAgent( + WindowManagerAgentType::WINDOW_MANAGER_AGENT_TYPE_SYSTEM_BAR, pImpl_->systemBarChangedListenerAgent_); } } @@ -112,5 +165,11 @@ void WindowManager::UpdateFocusStatus(uint32_t windowId, const sptrNotifyUnfocused(windowId, abilityToken, windowType, displayId); } } + +void WindowManager::UpdateSystemBarProperties(uint64_t displayId, + const SystemBarProps& props) const +{ + pImpl_->NotifySystemBarChanged(displayId, props); +} } // namespace Rosen } // namespace OHOS \ No newline at end of file diff --git a/wm/src/window_manager_agent.cpp b/wm/src/window_manager_agent.cpp index 83c13348..6767bb60 100644 --- a/wm/src/window_manager_agent.cpp +++ b/wm/src/window_manager_agent.cpp @@ -24,5 +24,10 @@ void WindowManagerAgent::UpdateFocusStatus(uint32_t windowId, const sptr().UpdateFocusStatus(windowId, abilityToken, windowType, displayId, focused); } + +void WindowManagerAgent::UpdateSystemBarProperties(uint64_t displayId, const SystemBarProps& props) +{ + SingletonContainer::Get().UpdateSystemBarProperties(displayId, props); +} } // namespace Rosen } // namespace OHOS diff --git a/wm/src/window_property.cpp b/wm/src/window_property.cpp index 6b22e7cb..b8253ef5 100644 --- a/wm/src/window_property.cpp +++ b/wm/src/window_property.cpp @@ -168,7 +168,7 @@ bool WindowProperty::MapMarshalling(Parcel& parcel) const if (!parcel.WriteUint32(static_cast(it.first))) { return false; } - // write val(UIState) + // write val(sysBarProps) if (!(parcel.WriteBool(it.second.enable_) && parcel.WriteUint32(it.second.backgroundColor_) && parcel.WriteUint32(it.second.contentColor_))) { return false; diff --git a/wm/src/window_proxy.cpp b/wm/src/window_proxy.cpp index fe12a88f..7334d6bb 100644 --- a/wm/src/window_proxy.cpp +++ b/wm/src/window_proxy.cpp @@ -53,26 +53,6 @@ void WindowProxy::UpdateWindowRect(const struct Rect& rect) return; } -void WindowProxy::UpdateSystemBarProperty(const SystemBarProperty& prop) -{ - MessageParcel data; - MessageParcel reply; - MessageOption option; - if (!data.WriteInterfaceToken(GetDescriptor())) { - WLOGFE("WriteInterfaceToken failed"); - return; - } - if (!(data.WriteBool(prop.enable_) && data.WriteUint32(prop.backgroundColor_) && - data.WriteUint32(prop.contentColor_))) { - WLOGFE("Write property failed"); - return; - } - if (Remote()->SendRequest(TRANS_ID_UPDATE_SYSTEM_BAR_PROPERTY, data, reply, option) != ERR_NONE) { - WLOGFE("SendRequest failed"); - } - return; -} - void WindowProxy::UpdateWindowMode(WindowMode mode) { MessageParcel data; diff --git a/wm/src/window_stub.cpp b/wm/src/window_stub.cpp index c0b6485f..06e9b8bd 100644 --- a/wm/src/window_stub.cpp +++ b/wm/src/window_stub.cpp @@ -49,11 +49,6 @@ int WindowStub::OnRemoteRequest(uint32_t code, MessageParcel &data, MessageParce UpdateFocusStatus(focused); break; } - case TRANS_ID_UPDATE_SYSTEM_BAR_PROPERTY: { - SystemBarProperty property = { data.ReadBool(), data.ReadUint32(), data.ReadUint32() }; - UpdateSystemBarProperty(property); - break; - } default: break; } diff --git a/wm/src/zidl/window_manager_agent_proxy.cpp b/wm/src/zidl/window_manager_agent_proxy.cpp index eea58411..774ae60c 100644 --- a/wm/src/zidl/window_manager_agent_proxy.cpp +++ b/wm/src/zidl/window_manager_agent_proxy.cpp @@ -62,6 +62,44 @@ void WindowManagerAgentProxy::UpdateFocusStatus(uint32_t windowId, const sptr(size))) { + WLOGFE("Write vector size failed"); + return; + } + for (auto it : props) { + // write key(type) + if (!data.WriteUint32(static_cast(it.first))) { + WLOGFE("Write type failed"); + return; + } + // write val(sysBarProps) + if (!(data.WriteBool(it.second.enable_) && data.WriteUint32(it.second.backgroundColor_) && + data.WriteUint32(it.second.contentColor_))) { + WLOGFE("Write sysBarProp failed"); + return; + } + } + if (Remote()->SendRequest(TRANS_ID_UPDATE_SYSTEM_BAR_PROPS, data, reply, option) != ERR_NONE) { + WLOGFE("SendRequest failed"); + } +} } // namespace Rosen } // namespace OHOS diff --git a/wm/src/zidl/window_manager_agent_stub.cpp b/wm/src/zidl/window_manager_agent_stub.cpp index 9ac69ed9..943aa26a 100644 --- a/wm/src/zidl/window_manager_agent_stub.cpp +++ b/wm/src/zidl/window_manager_agent_stub.cpp @@ -42,6 +42,19 @@ int WindowManagerAgentStub::OnRemoteRequest(uint32_t code, MessageParcel& data, UpdateFocusStatus(windowId, abilityToken, windowType, displayId, focused); break; } + case TRANS_ID_UPDATE_SYSTEM_BAR_PROPS: { + uint64_t displayId = data.ReadUint64(); + SystemBarProps props; + uint32_t size = data.ReadUint32(); + for (uint32_t i = 0; i < size; i++) { + WindowType type = static_cast(data.ReadUint32()); + SystemBarProperty prop = { data.ReadBool(), data.ReadUint32(), data.ReadUint32() }; + std::pair item = { type, prop }; + props.emplace_back(item); + } + UpdateSystemBarProperties(displayId, props); + break; + } default: break; } diff --git a/wmserver/include/window_controller.h b/wmserver/include/window_controller.h index f54f7c07..016102da 100644 --- a/wmserver/include/window_controller.h +++ b/wmserver/include/window_controller.h @@ -41,8 +41,10 @@ public: WMError SetWindowFlags(uint32_t windowId, uint32_t flags); WMError SetSystemBarProperty(uint32_t windowId, WindowType type, const SystemBarProperty& property); - void RegisterFocusChangedListener(const sptr& windowManagerAgent); - void UnregisterFocusChangedListener(const sptr& windowManagerAgent); + void RegisterWindowManagerAgent(WindowManagerAgentType type, + const sptr& windowManagerAgent); + void UnregisterWindowManagerAgent(WindowManagerAgentType type, + const sptr& windowManagerAgent); private: uint32_t GenWindowId(); diff --git a/wmserver/include/window_layout_policy.h b/wmserver/include/window_layout_policy.h index 0e10802a..e24deb66 100644 --- a/wmserver/include/window_layout_policy.h +++ b/wmserver/include/window_layout_policy.h @@ -50,13 +50,11 @@ private: sptr appWindowNode_ = new WindowNode(); sptr aboveAppWindowNode_ = new WindowNode(); Rect limitRect_ = {0, 0, 0, 0}; - std::map> avoidNodes_; const std::set avoidTypes_ { WindowType::WINDOW_TYPE_STATUS_BAR, WindowType::WINDOW_TYPE_NAVIGATION_BAR, }; void UpdateLimitRect(const sptr& node); - void RecordAvoidRect(const sptr& node); void UpdateLayoutRect(sptr& node); void LayoutWindowTree(); void LayoutWindowNode(sptr& node); diff --git a/wmserver/include/window_manager_interface.h b/wmserver/include/window_manager_interface.h index 4285e240..b32c8689 100644 --- a/wmserver/include/window_manager_interface.h +++ b/wmserver/include/window_manager_interface.h @@ -41,8 +41,8 @@ public: TRANS_ID_UPDATE_FLAGS, TRANS_ID_UPDATE_SYSTEM_BAR_PROPERTY, TRANS_ID_SEND_ABILITY_TOKEN, - TRANS_ID_REGISTER_FOCUS_CHANGED_LISTENER, - TRANS_ID_UNREGISTER_FOCUS_CHANGED_LISTENER, + TRANS_ID_REGISTER_WINDOW_MANAGER_AGENT, + TRANS_ID_UNREGISTER_WINDOW_MANAGER_AGENT, }; virtual WMError CreateWindow(sptr& window, sptr& property, const std::shared_ptr& surfaceNode, uint32_t& windowId) = 0; @@ -58,8 +58,10 @@ public: virtual WMError SetSystemBarProperty(uint32_t windowId, WindowType type, const SystemBarProperty& prop) = 0; virtual WMError SaveAbilityToken(const sptr& abilityToken, uint32_t windowId) = 0; - virtual void RegisterFocusChangedListener(const sptr& windowManagerAgent) = 0; - virtual void UnregisterFocusChangedListener(const sptr& windowManagerAgent) = 0; + virtual void RegisterWindowManagerAgent(WindowManagerAgentType type, + const sptr& windowManagerAgent) = 0; + virtual void UnregisterWindowManagerAgent(WindowManagerAgentType type, + const sptr& windowManagerAgent) = 0; }; } } diff --git a/wmserver/include/window_manager_proxy.h b/wmserver/include/window_manager_proxy.h index fbca792c..64694bb3 100644 --- a/wmserver/include/window_manager_proxy.h +++ b/wmserver/include/window_manager_proxy.h @@ -41,8 +41,10 @@ public: WMError SetWindowFlags(uint32_t windowId, uint32_t flags) override; WMError SetSystemBarProperty(uint32_t windowId, WindowType type, const SystemBarProperty& prop) override; - void RegisterFocusChangedListener(const sptr& windowManagerAgent) override; - void UnregisterFocusChangedListener(const sptr& windowManagerAgent) override; + void RegisterWindowManagerAgent(WindowManagerAgentType type, + const sptr& windowManagerAgent) override; + void UnregisterWindowManagerAgent(WindowManagerAgentType type, + const sptr& windowManagerAgent) override; private: static inline BrokerDelegator delegator_; diff --git a/wmserver/include/window_manager_service.h b/wmserver/include/window_manager_service.h index 05e9306b..3f542222 100644 --- a/wmserver/include/window_manager_service.h +++ b/wmserver/include/window_manager_service.h @@ -54,8 +54,10 @@ public: WMError SetWindowFlags(uint32_t windowId, uint32_t flags) override; WMError SetSystemBarProperty(uint32_t windowId, WindowType type, const SystemBarProperty& prop) override; - void RegisterFocusChangedListener(const sptr& windowManagerAgent) override; - void UnregisterFocusChangedListener(const sptr& windowManagerAgent) override; + void RegisterWindowManagerAgent(WindowManagerAgentType type, + const sptr& windowManagerAgent) override; + void UnregisterWindowManagerAgent(WindowManagerAgentType type, + const sptr& windowManagerAgent) override; // Inner interfaces WMError NotifyDisplaySuspend(); diff --git a/wmserver/include/window_node_container.h b/wmserver/include/window_node_container.h index 04430981..4051cce4 100644 --- a/wmserver/include/window_node_container.h +++ b/wmserver/include/window_node_container.h @@ -26,10 +26,16 @@ namespace OHOS { namespace Rosen { using UpdateFocusStatusFunc = std::function& abilityToken, WindowType windowType, int32_t displayId, bool focused)>; +using UpdateSystemBarPropsFunc = std::function; + +struct WindowNodeContainerCallbacks { + UpdateFocusStatusFunc focusStatusCallBack_; + UpdateSystemBarPropsFunc systemBarChangedCallBack_; +}; class WindowNodeContainer : public RefBase { public: - WindowNodeContainer(uint64_t screenId, uint32_t width, uint32_t height, UpdateFocusStatusFunc callback); + WindowNodeContainer(uint64_t screenId, uint32_t width, uint32_t height, WindowNodeContainerCallbacks callbacks); ~WindowNodeContainer(); WMError AddWindowNode(sptr& node, sptr& parentNode); WMError RemoveWindowNode(sptr& node); @@ -75,7 +81,7 @@ private: uint32_t focusedWindow_ { 0 }; Rect displayRect_; uint64_t screenId_ = 0; - UpdateFocusStatusFunc focusStatusCallBack_; + WindowNodeContainerCallbacks callbacks_; void DumpScreenWindowTree(); }; } diff --git a/wmserver/include/window_root.h b/wmserver/include/window_root.h index d2f79b03..55f43d75 100644 --- a/wmserver/include/window_root.h +++ b/wmserver/include/window_root.h @@ -68,17 +68,20 @@ public: WMError RequestFocus(uint32_t windowId); WMError MinimizeOtherFullScreenAbility(sptr& node); - void RegisterFocusChangedListener(const sptr& windowManagerAgent); - void UnregisterFocusChangedListener(const sptr& windowManagerAgent); + void RegisterWindowManagerAgent(WindowManagerAgentType type, + const sptr& windowManagerAgent); + void UnregisterWindowManagerAgent(WindowManagerAgentType type, + const sptr& windowManagerAgent); std::shared_ptr GetSurfaceNodeByAbilityToken(const sptr& abilityToken) const; private: void OnRemoteDied(const sptr& remoteObject); void ClearWindowManagerAgent(const sptr& remoteObject); - void UnregisterFocusChangedListener(const sptr& windowManagerAgent); + void UnregisterWindowManagerAgent(const sptr& object); void UpdateFocusStatus(uint32_t windowId, const sptr& abilityToken, WindowType windowType, int32_t displayId, bool focused); + void UpdateSystemBarProperties(uint64_t displayId, const SystemBarProps& props); WMError DestroyWindowInner(sptr& node); std::recursive_mutex& mutex_; @@ -86,7 +89,7 @@ private: std::map> windowNodeMap_; std::map, uint32_t> windowIdMap_; - std::vector> focusChangedListenerAgents_; + std::map>> windowManagerAgents_; sptr windowDeath_ = new WindowDeathRecipient(std::bind(&WindowRoot::OnRemoteDied, this, std::placeholders::_1)); diff --git a/wmserver/src/window_controller.cpp b/wmserver/src/window_controller.cpp index a26a7fd8..ade350d9 100644 --- a/wmserver/src/window_controller.cpp +++ b/wmserver/src/window_controller.cpp @@ -211,14 +211,16 @@ WMError WindowController::SetSystemBarProperty(uint32_t windowId, WindowType typ return res; } -void WindowController::RegisterFocusChangedListener(const sptr& windowManagerAgent) +void WindowController::RegisterWindowManagerAgent(WindowManagerAgentType type, + const sptr& windowManagerAgent) { - windowRoot_->RegisterFocusChangedListener(windowManagerAgent); + windowRoot_->RegisterWindowManagerAgent(type, windowManagerAgent); } -void WindowController::UnregisterFocusChangedListener(const sptr& windowManagerAgent) +void WindowController::UnregisterWindowManagerAgent(WindowManagerAgentType type, + const sptr& windowManagerAgent) { - windowRoot_->UnregisterFocusChangedListener(windowManagerAgent); + windowRoot_->UnregisterWindowManagerAgent(type, windowManagerAgent); } } } diff --git a/wmserver/src/window_layout_policy.cpp b/wmserver/src/window_layout_policy.cpp index b9d3c90e..b9c1b6ab 100644 --- a/wmserver/src/window_layout_policy.cpp +++ b/wmserver/src/window_layout_policy.cpp @@ -36,13 +36,11 @@ void WindowLayoutPolicy::UpdateDisplayInfo(const Rect& displayRect) { displayRect_ = displayRect; limitRect_ = displayRect_; - avoidNodes_.clear(); } void WindowLayoutPolicy::LayoutWindowTree() { limitRect_ = displayRect_; - avoidNodes_.clear(); std::vector> rootNodes = { aboveAppWindowNode_, appWindowNode_, belowAppWindowNode_ }; for (auto& node : rootNodes) { // ensure that the avoid area windows are traversed first LayoutWindowNode(node); @@ -61,7 +59,7 @@ void WindowLayoutPolicy::LayoutWindowNode(sptr& node) } UpdateLayoutRect(node); if (avoidTypes_.find(node->GetWindowType()) != avoidTypes_.end()) { - RecordAvoidRect(node); + UpdateLimitRect(node); } } for (auto& childNode : node->children_) { @@ -80,7 +78,7 @@ void WindowLayoutPolicy::RemoveWindowNode(sptr& node) WM_FUNCTION_TRACE(); auto type = node->GetWindowType(); // affect other windows, trigger off global layout - if (type == WindowType::WINDOW_TYPE_STATUS_BAR || type == WindowType::WINDOW_TYPE_NAVIGATION_BAR) { + if (avoidTypes_.find(type) != avoidTypes_.end()) { LayoutWindowTree(); } else if (type == WindowType::WINDOW_TYPE_DOCK_SLICE) { // split screen mode // TODO: change split screen @@ -93,7 +91,7 @@ void WindowLayoutPolicy::UpdateWindowNode(sptr& node) WM_FUNCTION_TRACE(); auto type = node->GetWindowType(); // affect other windows, trigger off global layout - if (type == WindowType::WINDOW_TYPE_STATUS_BAR || type == WindowType::WINDOW_TYPE_NAVIGATION_BAR) { + if (avoidTypes_.find(type) != avoidTypes_.end()) { LayoutWindowTree(); } else if (type == WindowType::WINDOW_TYPE_DOCK_SLICE) { // split screen mode // TODO: change split screen @@ -210,20 +208,5 @@ void WindowLayoutPolicy::UpdateLimitRect(const sptr& node) WLOGFI("Type: %{public}d, limitRect: %{public}d %{public}d %{public}d %{public}d", node->GetWindowType(), limitRect_.posX_, limitRect_.posY_, limitRect_.width_, limitRect_.height_); } - -void WindowLayoutPolicy::RecordAvoidRect(const sptr& node) -{ - uint32_t id = node->GetWindowId(); - if (avoidNodes_.find(id) == avoidNodes_.end()) { // new avoid rect - avoidNodes_.insert(std::pair>(id, node)); - UpdateLimitRect(node); - } else { // update existing avoid rect - limitRect_ = displayRect_; - avoidNodes_[id] = node; - for (auto item : avoidNodes_) { - UpdateLimitRect(item.second); - } - } -} } } diff --git a/wmserver/src/window_manager_proxy.cpp b/wmserver/src/window_manager_proxy.cpp index 04270b7b..d3e9625c 100644 --- a/wmserver/src/window_manager_proxy.cpp +++ b/wmserver/src/window_manager_proxy.cpp @@ -348,7 +348,8 @@ WMError WindowManagerProxy::SaveAbilityToken(const sptr& abilityT return static_cast(ret); } -void WindowManagerProxy::RegisterFocusChangedListener(const sptr& windowManagerAgent) +void WindowManagerProxy::RegisterWindowManagerAgent(WindowManagerAgentType type, + const sptr& windowManagerAgent) { MessageParcel data; MessageParcel reply; @@ -358,17 +359,23 @@ void WindowManagerProxy::RegisterFocusChangedListener(const sptr(type))) { + WLOGFE("Write type failed"); + return; + } + if (!data.WriteRemoteObject(windowManagerAgent->AsObject())) { WLOGFE("Write IWindowManagerAgent failed"); return; } - if (Remote()->SendRequest(TRANS_ID_REGISTER_FOCUS_CHANGED_LISTENER, data, reply, option) != ERR_NONE) { + if (Remote()->SendRequest(TRANS_ID_REGISTER_WINDOW_MANAGER_AGENT, data, reply, option) != ERR_NONE) { WLOGFE("SendRequest failed"); } } -void WindowManagerProxy::UnregisterFocusChangedListener(const sptr& windowManagerAgent) +void WindowManagerProxy::UnregisterWindowManagerAgent(WindowManagerAgentType type, + const sptr& windowManagerAgent) { MessageParcel data; MessageParcel reply; @@ -378,12 +385,17 @@ void WindowManagerProxy::UnregisterFocusChangedListener(const sptr(type))) { + WLOGFE("Write type failed"); + return; + } + if (!data.WriteRemoteObject(windowManagerAgent->AsObject())) { WLOGFE("Write IWindowManagerAgent failed"); return; } - if (Remote()->SendRequest(TRANS_ID_UNREGISTER_FOCUS_CHANGED_LISTENER, data, reply, option) != ERR_NONE) { + if (Remote()->SendRequest(TRANS_ID_UNREGISTER_WINDOW_MANAGER_AGENT, data, reply, option) != ERR_NONE) { WLOGFE("SendRequest failed"); } } diff --git a/wmserver/src/window_manager_service.cpp b/wmserver/src/window_manager_service.cpp index c62b771f..7b847858 100644 --- a/wmserver/src/window_manager_service.cpp +++ b/wmserver/src/window_manager_service.cpp @@ -205,24 +205,25 @@ WMError WindowManagerService::SaveAbilityToken(const sptr& abilit return windowController_->SaveAbilityToken(abilityToken, windowId); } -void WindowManagerService::RegisterFocusChangedListener(const sptr& windowManagerAgent) -{ - if ((windowManagerAgent == nullptr) || (windowManagerAgent->AsObject() == nullptr)) { - WLOGFE("failed to get window manager agent"); - return; - } - std::lock_guard lock(mutex_); - windowController_->RegisterFocusChangedListener(windowManagerAgent); -} - -void WindowManagerService::UnregisterFocusChangedListener(const sptr& windowManagerAgent) +void WindowManagerService::RegisterWindowManagerAgent(WindowManagerAgentType type, + const sptr& windowManagerAgent) { if ((windowManagerAgent == nullptr) || (windowManagerAgent->AsObject() == nullptr)) { WLOGFE("windowManagerAgent is null"); return; } std::lock_guard lock(mutex_); - windowController_->UnregisterFocusChangedListener(windowManagerAgent); + windowController_->RegisterWindowManagerAgent(type, windowManagerAgent); +} +void WindowManagerService::UnregisterWindowManagerAgent(WindowManagerAgentType type, + const sptr& windowManagerAgent) +{ + if ((windowManagerAgent == nullptr) || (windowManagerAgent->AsObject() == nullptr)) { + WLOGFE("windowManagerAgent is null"); + return; + } + std::lock_guard lock(mutex_); + windowController_->UnregisterWindowManagerAgent(type, windowManagerAgent); } void WindowManagerService::OnWindowEvent(Event event, uint32_t windowId) diff --git a/wmserver/src/window_manager_stub.cpp b/wmserver/src/window_manager_stub.cpp index 795f0469..a321f55c 100644 --- a/wmserver/src/window_manager_stub.cpp +++ b/wmserver/src/window_manager_stub.cpp @@ -118,18 +118,20 @@ int32_t WindowManagerStub::OnRemoteRequest(uint32_t code, MessageParcel &data, M reply.WriteInt32(static_cast(errCode)); break; } - case TRANS_ID_REGISTER_FOCUS_CHANGED_LISTENER: { + case TRANS_ID_REGISTER_WINDOW_MANAGER_AGENT: { sptr windowManagerAgentObject = data.ReadRemoteObject(); + WindowManagerAgentType type = static_cast(data.ReadUint32()); sptr windowManagerAgentProxy = iface_cast(windowManagerAgentObject); - RegisterFocusChangedListener(windowManagerAgentProxy); + RegisterWindowManagerAgent(type, windowManagerAgentProxy); break; } - case TRANS_ID_UNREGISTER_FOCUS_CHANGED_LISTENER: { + case TRANS_ID_UNREGISTER_WINDOW_MANAGER_AGENT: { sptr windowManagerAgentObject = data.ReadRemoteObject(); + WindowManagerAgentType type = static_cast(data.ReadUint32()); sptr windowManagerAgentProxy = iface_cast(windowManagerAgentObject); - UnregisterFocusChangedListener(windowManagerAgentProxy); + UnregisterWindowManagerAgent(type, windowManagerAgentProxy); break; } default: diff --git a/wmserver/src/window_node_container.cpp b/wmserver/src/window_node_container.cpp index ec268097..94b11f3f 100644 --- a/wmserver/src/window_node_container.cpp +++ b/wmserver/src/window_node_container.cpp @@ -30,7 +30,8 @@ namespace { } WindowNodeContainer::WindowNodeContainer(uint64_t screenId, uint32_t width, uint32_t height, - UpdateFocusStatusFunc callback) : screenId_(screenId), focusStatusCallBack_(callback) + WindowNodeContainerCallbacks callbacks) + : screenId_(screenId), callbacks_(callbacks) { struct RSDisplayNodeConfig config = {screenId}; displayNode_ = RSDisplayNode::Create(config); @@ -279,7 +280,7 @@ void WindowNodeContainer::UpdateFocusStatus(uint32_t id, bool focused) const if (node->abilityToken_ == nullptr) { WLOGFI("abilityToken is null, window : %{public}d", id); } - focusStatusCallBack_(node->GetWindowId(), node->abilityToken_, node->GetWindowType(), + callbacks_.focusStatusCallBack_(node->GetWindowId(), node->abilityToken_, node->GetWindowType(), node->GetDisplayId(), focused); } } @@ -364,17 +365,19 @@ void WindowNodeContainer::NotifySystemBarIfChanged() { DumpScreenWindowTree(); auto node = GetTopImmersiveNode(); + SystemBarProps props; if (node == nullptr) { // use default system bar + WLOGFI("no immersive window on top"); for (auto it : sysBarPropMap_) { if (it.second == SystemBarProperty()) { continue; } sysBarPropMap_[it.first] = SystemBarProperty(); - if (sysBarNodeMap_[it.first] != nullptr) { - sysBarNodeMap_[it.first]->GetWindowToken()->UpdateSystemBarProperty(SystemBarProperty()); - } + std::pair item = { it.first, SystemBarProperty() }; + props.emplace_back(item); } } else { // use node-defined system bar + WLOGFI("top immersive window id: %{public}d", node->GetWindowId()); auto& sysBarPropMap = node->GetSystemBarProperty(); for (auto it : sysBarPropMap_) { if (sysBarPropMap.find(it.first) == sysBarPropMap.end()) { @@ -389,11 +392,11 @@ void WindowNodeContainer::NotifySystemBarIfChanged() node->GetWindowId(), static_cast(it.first), prop.enable_, prop.backgroundColor_, prop.contentColor_); sysBarPropMap_[it.first] = prop; - if (sysBarNodeMap_[it.first] != nullptr) { - sysBarNodeMap_[it.first]->GetWindowToken()->UpdateSystemBarProperty(prop); - } + std::pair item = { it.first, prop }; + props.emplace_back(item); } } + callbacks_.systemBarChangedCallBack_(screenId_, props); } void WindowNodeContainer::TraverseContainer(std::vector>& windowNodes) diff --git a/wmserver/src/window_root.cpp b/wmserver/src/window_root.cpp index e726dae0..eb1c2be8 100644 --- a/wmserver/src/window_root.cpp +++ b/wmserver/src/window_root.cpp @@ -41,9 +41,15 @@ sptr WindowRoot::GetOrCreateWindowNodeContainer(int32_t dis UpdateFocusStatusFunc focusStatusFunc = std::bind(&WindowRoot::UpdateFocusStatus, this, std::placeholders::_1, std::placeholders::_2, std::placeholders::_3, std::placeholders::_4, std::placeholders::_5); + UpdateSystemBarPropsFunc sysBarUpdateFunc = std::bind(&WindowRoot::UpdateSystemBarProperties, this, + std::placeholders::_1, std::placeholders::_2); + WindowNodeContainerCallbacks callbacks = { + focusStatusFunc, + sysBarUpdateFunc + }; sptr container = new WindowNodeContainer(abstractDisplay->GetId(), static_cast(abstractDisplay->GetWidth()), static_cast(abstractDisplay->GetHeight()), - focusStatusFunc); + callbacks); windowNodeContainerMap_.insert({ displayId, container }); return container; } @@ -215,9 +221,10 @@ WMError WindowRoot::RequestFocus(uint32_t windowId) return container->SetFocusWindow(windowId); } -void WindowRoot::RegisterFocusChangedListener(const sptr& windowManagerAgent) +void WindowRoot::RegisterWindowManagerAgent(WindowManagerAgentType type, + const sptr& windowManagerAgent) { - focusChangedListenerAgents_.push_back(windowManagerAgent); + windowManagerAgents_[type].push_back(windowManagerAgent); if (windowManagerAgentDeath_ == nullptr) { WLOGFI("failed to create death Recipient ptr WindowManagerAgentDeathRecipient"); return; @@ -227,21 +234,24 @@ void WindowRoot::RegisterFocusChangedListener(const sptr& w } } -void WindowRoot::UnregisterFocusChangedListener(const sptr& windowManagerAgent) +void WindowRoot::UnregisterWindowManagerAgent(WindowManagerAgentType type, + const sptr& windowManagerAgent) { - auto iter = std::find(focusChangedListenerAgents_.begin(), focusChangedListenerAgents_.end(), windowManagerAgent); - if (iter == focusChangedListenerAgents_.end()) { + auto iter = std::find(windowManagerAgents_[type].begin(), windowManagerAgents_[type].end(), windowManagerAgent); + if (iter == windowManagerAgents_[type].end()) { WLOGFE("could not find this listener"); return; } - focusChangedListenerAgents_.erase(iter); + windowManagerAgents_[type].erase(iter); } -void WindowRoot::UnregisterFocusChangedListener(const sptr& object) +void WindowRoot::UnregisterWindowManagerAgent(const sptr& object) { - for (auto iter = focusChangedListenerAgents_.begin(); iter < focusChangedListenerAgents_.end(); ++iter) { - if ((*iter)->AsObject() != nullptr && (*iter)->AsObject() == object) { - iter = focusChangedListenerAgents_.erase(iter); + for (auto agents : windowManagerAgents_) { + for (auto iter = agents.second.begin(); iter < agents.second.end(); ++iter) { + if ((*iter)->AsObject() != nullptr && (*iter)->AsObject() == object) { + iter = agents.second.erase(iter); + } } } } @@ -249,7 +259,7 @@ void WindowRoot::UnregisterFocusChangedListener(const sptr& objec void WindowRoot::UpdateFocusStatus(uint32_t windowId, const sptr& abilityToken, WindowType windowType, int32_t displayId, bool focused) { - for (auto& windowManagerAgent : focusChangedListenerAgents_) { + for (auto& windowManagerAgent : windowManagerAgents_[WindowManagerAgentType::WINDOW_MANAGER_AGENT_TYPE_FOCUS]) { windowManagerAgent->UpdateFocusStatus(windowId, abilityToken, windowType, displayId, focused); } } @@ -266,6 +276,16 @@ std::shared_ptr WindowRoot::GetSurfaceNodeByAbilityToken(const sp return nullptr; } +void WindowRoot::UpdateSystemBarProperties(uint64_t displayId, const SystemBarProps& props) +{ + if (props.empty()) { + return; + } + for (auto& agent : windowManagerAgents_[WindowManagerAgentType::WINDOW_MANAGER_AGENT_TYPE_SYSTEM_BAR]) { + agent->UpdateSystemBarProperties(displayId, props); + } +} + void WindowRoot::OnRemoteDied(const sptr& remoteObject) { std::lock_guard lock(mutex_); @@ -285,7 +305,7 @@ void WindowRoot::ClearWindowManagerAgent(const sptr& remoteObject return; } std::lock_guard lock(mutex_); - UnregisterFocusChangedListener(remoteObject); + UnregisterWindowManagerAgent(remoteObject); remoteObject->RemoveDeathRecipient(windowManagerAgentDeath_); }