From f2bd3b5c6145fb40ea264ade2f7d5d61f9aa3066 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=99=BD=E9=92=B0=E8=83=9C?= Date: Thu, 10 Jul 2025 14:51:52 +0800 Subject: [PATCH 1/4] =?UTF-8?q?=E7=AA=97=E5=8F=A3=E5=8F=91=E9=80=81?= =?UTF-8?q?=E5=9D=90=E6=A0=87=E5=8F=98=E5=8C=96=E6=97=B6=E9=80=9A=E7=9F=A5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: 白钰胜 --- interfaces/innerkits/wm/window.h | 36 +++++++++++++ previewer/include/window.h | 12 +++++ .../include/zidl/session_stage_interface.h | 2 +- .../include/zidl/session_stage_proxy.h | 2 +- .../src/zidl/session_stage_proxy.cpp | 7 ++- .../container/src/zidl/session_stage_stub.cpp | 5 ++ window_scene/session/host/src/session.cpp | 3 +- window_scene/test/mock/mock_session_stage.h | 5 +- .../unittest/layout/session_layout_test.cpp | 2 +- .../session_stage_proxy_layout_test.cpp | 25 +++++++++ .../test/unittest/session_layout_test.cpp | 2 +- .../test/unittest/session_stage_stub_test.cpp | 5 +- window_scene/test/unittest/session_test.cpp | 2 +- wm/include/window_extension_session_impl.h | 2 +- wm/include/window_session_impl.h | 10 +++- wm/src/window_extension_session_impl.cpp | 3 +- wm/src/window_scene_session_impl.cpp | 1 + wm/src/window_session_impl.cpp | 54 ++++++++++++++++++- wm/test/mock/mock_window.h | 5 ++ .../window_session_impl_layout_test.cpp | 26 +++++++-- 20 files changed, 191 insertions(+), 18 deletions(-) diff --git a/interfaces/innerkits/wm/window.h b/interfaces/innerkits/wm/window.h index af2b5be670..dae0a1e790 100644 --- a/interfaces/innerkits/wm/window.h +++ b/interfaces/innerkits/wm/window.h @@ -273,6 +273,20 @@ public: virtual void OnWindowStatusDidChange(WindowStatus status) {} }; +/** + * @class IWindowCoordinateChangeListener + * + * @brief IWindowCoordinateChangeListener is used to observe the window coordinate when window coordinate changed + * and layout finished. + */ +class IWindowCoordinateChangeListener : virtual public RefBase { +public: + /** + * @brief Notify caller when window coordinate changed. + */ + virtual void OnWindowCoordinateChange(WindowSizeChangeReason reason) {} +}; + /** * @class IAvoidAreaChangedListener * @@ -3090,6 +3104,28 @@ public: return WMError::WM_ERROR_DEVICE_NOT_SUPPORT; } + /** + * @brief Register window coordinate change listener. + * + * @param listener IWindowCoordinateChangeListener. + * @return WM_OK means register success, others means register failed. + */ + virtual WMError RegisterWindowCoordinateChangeListener(const sptr& listener) + { + return WMError::WM_ERROR_DEVICE_NOT_SUPPORT; + } + + /** + * @brief Unregister window coordinate change listener. + * + * @param listener IWindowCoordinateChangeListener. + * @return WM_OK means unregister success, others means unregister failed. + */ + virtual WMError UnregisterWindowCoordinateChangeListener(const sptr& listener) + { + return WMError::WM_ERROR_DEVICE_NOT_SUPPORT; + } + /** * @brief Set Specific System Bar(include status bar and nav bar) Enable and Animation Properties * diff --git a/previewer/include/window.h b/previewer/include/window.h index 7cbbd09e29..209c5a5612 100644 --- a/previewer/include/window.h +++ b/previewer/include/window.h @@ -80,6 +80,10 @@ class IIgnoreViewSafeAreaListener : virtual public RefBase { public: virtual void SetIgnoreViewSafeArea(bool ignoreViewSafeArea) = 0; }; +class IWindowCoordinateChangeListener : virtual public RefBase { +public: + virtual void OnWindowCoordinateChange(WindowSizeChangeReason reason) {} +}; class IAvoidAreaChangedListener : virtual public RefBase { public: virtual void OnAvoidAreaChanged(const AvoidArea avoidArea, AvoidAreaType type) {} @@ -463,6 +467,14 @@ public: { return WMError::WM_ERROR_DEVICE_NOT_SUPPORT; } + virtual WMError RegisterWindowCoordinateChangeListener(const sptr& listener) + { + return WMError::WM_ERROR_DEVICE_NOT_SUPPORT; + } + virtual WMError UnregisterWindowCoordinateChangeListener(const sptr& listener) + { + return WMError::WM_ERROR_DEVICE_NOT_SUPPORT; + } virtual WMError SetSingleFrameComposerEnabled(bool enable) = 0; virtual WMError SetLandscapeMultiWindow(bool isLandscapeMultiWindow) = 0; virtual WMError SetDecorVisible(bool isVisible) { return WMError::WM_ERROR_DEVICE_NOT_SUPPORT; } diff --git a/window_scene/session/container/include/zidl/session_stage_interface.h b/window_scene/session/container/include/zidl/session_stage_interface.h index aaec73ccf2..edc9459241 100644 --- a/window_scene/session/container/include/zidl/session_stage_interface.h +++ b/window_scene/session/container/include/zidl/session_stage_interface.h @@ -54,7 +54,7 @@ public: */ virtual WSError UpdateRect(const WSRect& rect, SizeChangeReason reason, const SceneAnimationConfig& config = { nullptr, ROTATE_ANIMATION_DURATION }, - const std::map& avoidAreas = {}) = 0; + const std::map& avoidAreas = {}, bool isWindowCoordinateChange = true) = 0; /** * @brief Update the window's rectangle in global coordinates from server-side state. diff --git a/window_scene/session/container/include/zidl/session_stage_proxy.h b/window_scene/session/container/include/zidl/session_stage_proxy.h index dd564627e9..b472265d39 100644 --- a/window_scene/session/container/include/zidl/session_stage_proxy.h +++ b/window_scene/session/container/include/zidl/session_stage_proxy.h @@ -34,7 +34,7 @@ public: WSError SetActive(bool active) override; WSError UpdateRect(const WSRect& rect, SizeChangeReason reason, const SceneAnimationConfig& config = { nullptr, ROTATE_ANIMATION_DURATION }, - const std::map& avoidAreas = {}) override; + const std::map& avoidAreas = {}, bool isWindowCoordinateChange = true) override; WSError UpdateGlobalDisplayRectFromServer(const WSRect& rect, SizeChangeReason reason) override; void UpdateDensity() override; WSError UpdateOrientation() override; diff --git a/window_scene/session/container/src/zidl/session_stage_proxy.cpp b/window_scene/session/container/src/zidl/session_stage_proxy.cpp index f40a62771e..0261dcddf7 100644 --- a/window_scene/session/container/src/zidl/session_stage_proxy.cpp +++ b/window_scene/session/container/src/zidl/session_stage_proxy.cpp @@ -172,7 +172,8 @@ WSError SessionStageProxy::UpdateDisplayId(uint64_t displayId) } WSError SessionStageProxy::UpdateRect(const WSRect& rect, SizeChangeReason reason, - const SceneAnimationConfig& config, const std::map& avoidAreas) + const SceneAnimationConfig& config, const std::map& avoidAreas, + bool isWindowCoordinateChange) { MessageParcel data; MessageParcel reply; @@ -228,6 +229,10 @@ WSError SessionStageProxy::UpdateRect(const WSRect& rect, SizeChangeReason reaso return WSError::WS_ERROR_IPC_FAILED; } } + if (!data.WriteBool(isWindowCoordinateChange)) { + TLOGE(WmsLogTag::WMS_IMMS, "Write isWindowCoordinateChange failed"); + return WSError::WS_ERROR_IPC_FAILED; + } sptr remote = Remote(); if (remote == nullptr) { diff --git a/window_scene/session/container/src/zidl/session_stage_stub.cpp b/window_scene/session/container/src/zidl/session_stage_stub.cpp index a363e5e4e1..81f86f4722 100644 --- a/window_scene/session/container/src/zidl/session_stage_stub.cpp +++ b/window_scene/session/container/src/zidl/session_stage_stub.cpp @@ -310,6 +310,11 @@ int SessionStageStub::HandleUpdateRect(MessageParcel& data, MessageParcel& reply } avoidAreas[static_cast(type)] = *area; } + bool isWindowCoordinateChange = false; + if (!data.ReadBool(isWindowCoordinateChange)) { + TLOGE(WmsLogTag::WMS_LAYOUT, "read isWindowCoordinateChange failed"); + return ERR_INVALID_DATA; + } WSError errCode = UpdateRect(rect, reason, config, avoidAreas); reply.WriteUint32(static_cast(errCode)); return ERR_NONE; diff --git a/window_scene/session/host/src/session.cpp b/window_scene/session/host/src/session.cpp index 9557b4a38b..cce7630000 100644 --- a/window_scene/session/host/src/session.cpp +++ b/window_scene/session/host/src/session.cpp @@ -1196,7 +1196,8 @@ WSError Session::UpdateRectWithLayoutInfo(const WSRect& rect, SizeChangeReason r UpdateClientRectPosYAndDisplayId(updateRect); updateRect = IsNeedConvertToRelativeRect(reason) ? GetLayoutController()->ConvertGlobalRectToRelative(updateRect, GetDisplayId()) : updateRect; - sessionStage_->UpdateRect(updateRect, reason, config, avoidAreas); + bool isWindowCoordinateChanged = updateReason != "ScreenFoldStatusChanged"; + sessionStage_->UpdateRect(updateRect, reason, config, avoidAreas, isWindowCoordinateChanged); SetClientRect(rect); RectCheckProcess(); } else { diff --git a/window_scene/test/mock/mock_session_stage.h b/window_scene/test/mock/mock_session_stage.h index c3c6aa22d8..f12adab919 100644 --- a/window_scene/test/mock/mock_session_stage.h +++ b/window_scene/test/mock/mock_session_stage.h @@ -27,8 +27,9 @@ public: ~SessionStageMocker() {}; MOCK_METHOD1(SetActive, WSError(bool active)); - MOCK_METHOD4(UpdateRect, WSError(const WSRect& rect, SizeChangeReason reason, - const SceneAnimationConfig& config, const std::map& avoidAreas)); + MOCK_METHOD5(UpdateRect, WSError(const WSRect& rect, SizeChangeReason reason, + const SceneAnimationConfig& config, const std::map& avoidAreas, + bool isWindowCoordinateChanged)); MOCK_METHOD(WSError, UpdateGlobalDisplayRectFromServer, (const WSRect& rect, SizeChangeReason reason), (override)); MOCK_METHOD0(UpdateDensity, void(void)); MOCK_METHOD0(UpdateOrientation, WSError(void)); diff --git a/window_scene/test/unittest/layout/session_layout_test.cpp b/window_scene/test/unittest/layout/session_layout_test.cpp index 4aa8996a91..743fe3b87e 100644 --- a/window_scene/test/unittest/layout/session_layout_test.cpp +++ b/window_scene/test/unittest/layout/session_layout_test.cpp @@ -140,7 +140,7 @@ HWTEST_F(SessionLayoutTest, UpdateRect01, TestSize.Level1) Session::SetBackgroundUpdateRectNotifyEnabled(true); sptr mockSessionStage = sptr::MakeSptr(); session_->sessionStage_ = mockSessionStage; - EXPECT_CALL(*(mockSessionStage), UpdateRect(_, _, _, _)).Times(AtLeast(1)).WillOnce(Return(WSError::WS_OK)); + EXPECT_CALL(*(mockSessionStage), UpdateRect(_, _, _, _, _)).Times(AtLeast(1)).WillOnce(Return(WSError::WS_OK)); WSRect rect = { 0, 0, 0, 0 }; ASSERT_EQ(WSError::WS_ERROR_INVALID_SESSION, diff --git a/window_scene/test/unittest/layout/session_stage_proxy_layout_test.cpp b/window_scene/test/unittest/layout/session_stage_proxy_layout_test.cpp index f5bbdac153..0aa0d8db3a 100644 --- a/window_scene/test/unittest/layout/session_stage_proxy_layout_test.cpp +++ b/window_scene/test/unittest/layout/session_stage_proxy_layout_test.cpp @@ -58,6 +58,31 @@ HWTEST_F(SessionStageProxyLayoutTest, NotifySingleHandTransformChange, TestSize. ASSERT_TRUE((sessionStage_ != nullptr)); GTEST_LOG_(INFO) << "SessionStageProxyLayoutTest: NotifySingleHandTransformChange end"; } + +/** + * @tc.name: UpdateRect_WriteBoolErrorCase + * @tc.desc: test function : UpdateRect + * @tc.type: FUNC + */ +HWTEST_F(SessionStageProxyLayoutTest, UpdateRect_WriteBoolErrorCase, TestSize.Level1) +{ + ASSERT_TRUE(sessionStage_ != nullptr); + GTEST_LOG_(INFO) << "SessionStageProxyLayoutTest: UpdateRect_WriteBoolErrorCase start"; + MockMessageParcel::ClearAllErrorFlag(); + MockMessageParcel::SetWriteBoolErrorFlag(true); + WSRect rect; + SizeChangeReason reason = SizeChangeReason::UNDEFINED; + SceneAnimationConfig config { .rsTransaction_ = nullptr, .animationDuration_ = 400 }; + const std::map avoidAreas = {}; + bool isWindowCoordinateChanged = true; + WSError ret = sessionStage_->UpdateRect(rect, reason, config, avoidAreas, isWindowCoordinateChanged); + EXPECT_EQ(ret, WSError::WS_ERROR_IPC_FAILED); + + MockMessageParcel::SetWriteBoolErrorFlag(false); + ret = sessionStage_->UpdateRect(rect, reason, config, avoidAreas, isWindowCoordinateChanged); + EXPECT_EQ(ret, WSError::WS_OK); + GTEST_LOG_(INFO) << "SessionStageProxyLayoutTest: UpdateRect_WriteBoolErrorCase end"; +} } // namespace } // namespace Rosen } // namespace OHOS \ No newline at end of file diff --git a/window_scene/test/unittest/session_layout_test.cpp b/window_scene/test/unittest/session_layout_test.cpp index 115b67a3d1..ecf8f3f496 100644 --- a/window_scene/test/unittest/session_layout_test.cpp +++ b/window_scene/test/unittest/session_layout_test.cpp @@ -140,7 +140,7 @@ HWTEST_F(SessionLayoutTest, UpdateRect01, TestSize.Level1) Session::SetBackgroundUpdateRectNotifyEnabled(true); sptr mockSessionStage = sptr::MakeSptr(); session_->sessionStage_ = mockSessionStage; - EXPECT_CALL(*(mockSessionStage), UpdateRect(_, _, _, _)).Times(AtLeast(1)).WillOnce(Return(WSError::WS_OK)); + EXPECT_CALL(*(mockSessionStage), UpdateRect(_, _, _, _, _)).Times(AtLeast(1)).WillOnce(Return(WSError::WS_OK)); WSRect rect = { 0, 0, 0, 0 }; ASSERT_EQ(WSError::WS_ERROR_INVALID_SESSION, diff --git a/window_scene/test/unittest/session_stage_stub_test.cpp b/window_scene/test/unittest/session_stage_stub_test.cpp index 631f2437f2..82eaa062de 100644 --- a/window_scene/test/unittest/session_stage_stub_test.cpp +++ b/window_scene/test/unittest/session_stage_stub_test.cpp @@ -117,9 +117,10 @@ HWTEST_F(SessionStageStubTest, HandleUpdateRect, TestSize.Level1) data.WriteBool(false); data.WriteInt32(1); data.WriteUint32(0); + data.WriteBool(true); uint32_t code = static_cast(SessionStageInterfaceCode::TRANS_ID_NOTIFY_SIZE_CHANGE); - ASSERT_TRUE((sessionStageStub_ != nullptr)); - ASSERT_EQ(0, sessionStageStub_->OnRemoteRequest(code, data, reply, option)); + ASSERT_TRUE(sessionStageStub_ != nullptr); + EXPECT_EQ(0, sessionStageStub_->OnRemoteRequest(code, data, reply, option)); } /** diff --git a/window_scene/test/unittest/session_test.cpp b/window_scene/test/unittest/session_test.cpp index fda031d459..de69ac8f79 100644 --- a/window_scene/test/unittest/session_test.cpp +++ b/window_scene/test/unittest/session_test.cpp @@ -160,7 +160,7 @@ HWTEST_F(WindowSessionTest, SetActive01, TestSize.Level1) sptr mockSessionStage = sptr::MakeSptr(); EXPECT_NE(nullptr, mockSessionStage); EXPECT_CALL(*(mockSessionStage), SetActive(_)).WillOnce(Return(WSError::WS_OK)); - EXPECT_CALL(*(mockSessionStage), UpdateRect(_, _, _, _)).Times(0).WillOnce(Return(WSError::WS_OK)); + EXPECT_CALL(*(mockSessionStage), UpdateRect(_, _, _, _, _)).Times(0).WillOnce(Return(WSError::WS_OK)); session_->sessionStage_ = mockSessionStage; ASSERT_EQ(WSError::WS_ERROR_INVALID_SESSION, session_->SetActive(true)); diff --git a/wm/include/window_extension_session_impl.h b/wm/include/window_extension_session_impl.h index 8ecaf4f8a5..5d7786be99 100644 --- a/wm/include/window_extension_session_impl.h +++ b/wm/include/window_extension_session_impl.h @@ -81,7 +81,7 @@ public: void SetUniqueVirtualPixelRatio(bool useUniqueDensity, float virtualPixelRatio) override {} WSError UpdateRect(const WSRect& rect, SizeChangeReason reason, const SceneAnimationConfig& config = { nullptr, ROTATE_ANIMATION_DURATION }, - const std::map& avoidAreas = {}) override; + const std::map& avoidAreas = {}, bool isWindowCoordinateChange = true) override; WMError GetAvoidAreaByType(AvoidAreaType type, AvoidArea& avoidArea, const Rect& rect = Rect::EMPTY_RECT, int32_t apiVersion = API_VERSION_INVALID) override; diff --git a/wm/include/window_session_impl.h b/wm/include/window_session_impl.h index cd068f19f9..3c1087d9c6 100644 --- a/wm/include/window_session_impl.h +++ b/wm/include/window_session_impl.h @@ -210,7 +210,7 @@ public: WSError SetActive(bool active) override; WSError UpdateRect(const WSRect& rect, SizeChangeReason reason, const SceneAnimationConfig& config = { nullptr, ROTATE_ANIMATION_DURATION }, - const std::map& avoidAreas = {}) override; + const std::map& avoidAreas = {}, bool isWindowCoordinateChange = true) override; void UpdateDensity() override; void SetUniqueVirtualPixelRatio(bool useUniqueDensity, float virtualPixelRatio) override; WSError UpdateOrientation() override; @@ -459,6 +459,8 @@ public: WMError SetDragKeyFramePolicy(const KeyFramePolicy& keyFramePolicy) override; WMError RegisterWindowStatusDidChangeListener(const sptr& listener) override; WMError UnregisterWindowStatusDidChangeListener(const sptr& listener) override; + WMError RegisterWindowCoordinateChangeListener(const sptr& listener) override; + WMError UnregisterWindowCoordinateChangeListener(const sptr& listener) override; WSError NotifyLayoutFinishAfterWindowModeChange(WindowMode mode) override { return WSError::WS_OK; } WMError UpdateWindowModeForUITest(int32_t updateMode) override { return WMError::WM_OK; } /* @@ -761,6 +763,7 @@ protected: template EnableIfSame>> GetListeners(); void NotifyWindowStatusDidChange(WindowMode mode); + void NotifyWindowCoordinateChange(WindowSizeChangeReason reason); void NotifyFirstValidLayoutUpdate(const Rect& preRect, const Rect& newRect); std::atomic_bool hasSetEnableDrag_ = false; @@ -870,6 +873,9 @@ private: template EnableIfSame>> GetListeners(); template + EnableIfSame>> + GetListeners(); + template EnableIfSame>> GetListeners(); template EnableIfSame>> @@ -982,6 +988,7 @@ private: static std::recursive_mutex windowNoInteractionListenerMutex_; static std::recursive_mutex windowStatusChangeListenerMutex_; static std::recursive_mutex windowStatusDidChangeListenerMutex_; + static std::recursive_mutex windowCoordinateChangeListenerMutex_; static std::mutex displayMoveListenerMutex_; static std::mutex windowRectChangeListenerMutex_; static std::mutex rectChangeInGlobalDisplayListenerMutex_; @@ -1021,6 +1028,7 @@ private: static std::map> windowNoInteractionListeners_; static std::map>> windowStatusChangeListeners_; static std::map>> windowStatusDidChangeListeners_; + static std::map>> windowCoordinateChangeListeners_; static std::map>> windowRectChangeListeners_; static std::map>> rectChangeInGlobalDisplayListeners_; static std::map>> secureLimitChangeListeners_; diff --git a/wm/src/window_extension_session_impl.cpp b/wm/src/window_extension_session_impl.cpp index 4bb3a801ce..bfa38e39ae 100644 --- a/wm/src/window_extension_session_impl.cpp +++ b/wm/src/window_extension_session_impl.cpp @@ -863,7 +863,8 @@ WMError WindowExtensionSessionImpl::SetUIContentInner(const std::string& content } WSError WindowExtensionSessionImpl::UpdateRect(const WSRect& rect, SizeChangeReason reason, - const SceneAnimationConfig& config, const std::map& avoidAreas) + const SceneAnimationConfig& config, const std::map& avoidAreas, + bool isWindowCoordinateChange) { auto wmReason = static_cast(reason); Rect wmRect = {rect.posX_, rect.posY_, rect.width_, rect.height_}; diff --git a/wm/src/window_scene_session_impl.cpp b/wm/src/window_scene_session_impl.cpp index 45152d0072..57cf8ea747 100644 --- a/wm/src/window_scene_session_impl.cpp +++ b/wm/src/window_scene_session_impl.cpp @@ -5911,6 +5911,7 @@ WSError WindowSceneSessionImpl::UpdateDisplayId(DisplayId displayId) if (displayIdChanged) { TLOGI(WmsLogTag::WMS_ATTRIBUTE, "wid: %{public}d, displayId: %{public}" PRIu64, GetPersistentId(), displayId); NotifyDisplayIdChange(displayId); + NotifyWindowCoordinateChange(WindowSizeChangeReason::UNDEFINED); } return WSError::WS_OK; } diff --git a/wm/src/window_session_impl.cpp b/wm/src/window_session_impl.cpp index da89ec2483..907d3148cd 100644 --- a/wm/src/window_session_impl.cpp +++ b/wm/src/window_session_impl.cpp @@ -190,6 +190,7 @@ std::recursive_mutex WindowSessionImpl::windowVisibilityChangeListenerMutex_; std::recursive_mutex WindowSessionImpl::windowNoInteractionListenerMutex_; std::recursive_mutex WindowSessionImpl::windowStatusChangeListenerMutex_; std::recursive_mutex WindowSessionImpl::windowStatusDidChangeListenerMutex_; +std::recursive_mutex WindowSessionImpl::windowCoordinateChangeListenerMutex_; std::recursive_mutex WindowSessionImpl::windowTitleButtonRectChangeListenerMutex_; std::mutex WindowSessionImpl::displayMoveListenerMutex_; std::mutex WindowSessionImpl::windowRectChangeListenerMutex_; @@ -215,6 +216,7 @@ std::recursive_mutex WindowSessionImpl::subWindowSessionMutex_; std::map>> WindowSessionImpl::subWindowSessionMap_; std::map>> WindowSessionImpl::windowStatusChangeListeners_; std::map>> WindowSessionImpl::windowStatusDidChangeListeners_; +std::map>> WindowSessionImpl::windowCoordinateChangeListeners_; bool WindowSessionImpl::isUIExtensionAbilityProcess_ = false; #define CALL_LIFECYCLE_LISTENER(windowLifecycleCb, listeners) \ @@ -1059,7 +1061,8 @@ WSError WindowSessionImpl::SetActive(bool active) /** @note @window.layout */ WSError WindowSessionImpl::UpdateRect(const WSRect& rect, SizeChangeReason reason, - const SceneAnimationConfig& config, const std::map& avoidAreas) + const SceneAnimationConfig& config, const std::map& avoidAreas, + bool isWindowCoordinateChange) { // delete after replace ws_common.h with wm_common.h auto wmReason = static_cast(reason); @@ -1094,6 +1097,9 @@ WSError WindowSessionImpl::UpdateRect(const WSRect& rect, SizeChangeReason reaso } else { UpdateRectForOtherReason(wmRect, preRect, wmReason, config.rsTransaction_, avoidAreas); } + if (isWindowCoordinateChange) { + NotifyWindowCoordinateChange(wmReason); + } if (wmReason == WindowSizeChangeReason::MOVE || wmReason == WindowSizeChangeReason::RESIZE || wmReason == WindowSizeChangeReason::MOVE_WITH_ANIMATION || @@ -3240,6 +3246,20 @@ WMError WindowSessionImpl::UnregisterWindowStatusDidChangeListener(const sptr& listener) +{ + TLOGD(WmsLogTag::WMS_LAYOUT, "in"); + std::lock_guard lockListener(windowCoordinateChangeListenerMutex_); + return RegisterListener(windowCoordinateChangeListeners_[GetPersistentId()], listener); +} + +WMError WindowSessionImpl::UnregisterWindowCoordinateChangeListener(const sptr& listener) +{ + TLOGD(WmsLogTag::WMS_LAYOUT, "in"); + std::lock_guard lockListener(windowCoordinateChangeListenerMutex_); + return UnregisterListener(windowCoordinateChangeListeners_[GetPersistentId()], listener); +} + WMError WindowSessionImpl::SetDecorVisible(bool isVisible) { if (IsWindowSessionInvalid()) { @@ -4257,6 +4277,16 @@ EnableIfSame +EnableIfSame>> WindowSessionImpl::GetListeners() +{ + std::vector> windowCoordinateChangeListeners; + for (auto& listener : windowCoordinateChangeListeners_[GetPersistentId()]) { + windowCoordinateChangeListeners.push_back(listener); + } + return windowCoordinateChangeListeners; +} + void WindowSessionImpl::ClearListenersById(int32_t persistentId) { TLOGI(WmsLogTag::WMS_LIFE, "Called id: %{public}d.", GetPersistentId()); @@ -4300,6 +4330,10 @@ void WindowSessionImpl::ClearListenersById(int32_t persistentId) std::lock_guard lockListener(windowStatusDidChangeListenerMutex_); ClearUselessListeners(windowStatusDidChangeListeners_, persistentId); } + { + std::lock_guard lockListener(windowCoordinateChangeListenerMutex_); + ClearUselessListeners(windowCoordinateChangeListeners_, persistentId); + } { std::lock_guard lockListener(windowTitleButtonRectChangeListenerMutex_); ClearUselessListeners(windowTitleButtonRectChangeListeners_, persistentId); @@ -6942,6 +6976,24 @@ void WindowSessionImpl::NotifyWindowStatusDidChange(WindowMode mode) } } +/** @note @window.layout */ +void WindowSessionImpl::NotifyWindowCoordinateChange(WindowSizeChangeReason reason) +{ + std::vector> windowCoordinateChangeListeners; + { + std::lock_guard lockListener(windowCoordinateChangeListenerMutex_); + windowCoordinateChangeListeners = GetListeners(); + } + const auto& windowRect = GetRect(); + TLOGD(WmsLogTag::WMS_LAYOUT, "Id:%{public}d, listenerSize:%{public}zu, rect:%{public}s", + GetPersistentId(), windowCoordinateChangeListeners.size(), windowRect.ToString().c_str()); + for (auto& listener : windowCoordinateChangeListeners) { + if (listener != nullptr) { + listener->OnWindowCoordinateChange(reason); + } + } +} + void WindowSessionImpl::NotifyFirstValidLayoutUpdate(const Rect& preRect, const Rect& newRect) { bool isFirstValidLayoutUpdate = true; diff --git a/wm/test/mock/mock_window.h b/wm/test/mock/mock_window.h index 3552ccffb6..c789ba1025 100644 --- a/wm/test/mock/mock_window.h +++ b/wm/test/mock/mock_window.h @@ -79,6 +79,11 @@ public: MOCK_METHOD1(OnWindowStatusDidChange, void(WindowStatus status)); }; +class MockWindowCoordinateChangeListener : public IWindowCoordinateChangeListener { +public: + MOCK_METHOD1(OnWindowCoordinateChange, void(WindowSizeChangeReason reason)); +}; + class MockIOccupiedAreaChangeListener : public IOccupiedAreaChangeListener { public: MOCK_METHOD2(OnSizeChange, void(const sptr& info, diff --git a/wm/test/unittest/layout/window_session_impl_layout_test.cpp b/wm/test/unittest/layout/window_session_impl_layout_test.cpp index fd8fabe774..fb32285dae 100644 --- a/wm/test/unittest/layout/window_session_impl_layout_test.cpp +++ b/wm/test/unittest/layout/window_session_impl_layout_test.cpp @@ -136,15 +136,17 @@ HWTEST_F(WindowSessionImplLayoutTest, UpdateRect02, TestSize.Level0) window->property_->SetWindowRect(rectW); SizeChangeReason reason = SizeChangeReason::ROTATION; WSError res = window->UpdateRect(rect, reason); - ASSERT_EQ(res, WSError::WS_OK); + EXPECT_EQ(res, WSError::WS_OK); rect.height_ = 50; rect.width_ = 50; rectW.height_ = 50; rectW.width_ = 50; window->property_->SetWindowRect(rectW); - res = window->UpdateRect(rect, reason); - ASSERT_EQ(res, WSError::WS_OK); + const SceneAnimationConfig& config = { nullptr, ROTATE_ANIMATION_DURATION }; + const std::map& avoidAreas = {}; + res = window->UpdateRect(rect, reason, config, avoidAreas, false); + EXPECT_EQ(res, WSError::WS_OK); Rect nowRect = window->property_->GetWindowRect(); EXPECT_EQ(nowRect.posX_, rect.posX_); EXPECT_EQ(nowRect.posY_, rect.posY_); @@ -334,6 +336,24 @@ HWTEST_F(WindowSessionImplLayoutTest, NotifyTransformChange_TestUIContent, TestS GTEST_LOG_(INFO) << "WindowSessionImplLayoutTest: NotifyTransformChange_TestUIContent end"; } +/** + * @tc.name: NotifyWindowCoordinateChange + * @tc.desc: NotifyWindowCoordinateChange + * @tc.type: FUNC + */ +HWTEST_F(WindowSessionImplLayoutTest, NotifyWindowCoordinateChange, TestSize.Level1) +{ + GTEST_LOG_(INFO) << "WindowSessionImplLayoutTest: NotifyWindowCoordinateChange start"; + auto window = GetTestWindowImpl("NotifyWindowCoordinateChange"); + auto listeners = GetListenerList(); + EXPECT_NE(listeners.size(), 0); + listeners.insert(listeners.begin(), nullptr); + window->windowCoordinateChangeListeners_.insert({ window->GetPersistentId(), listeners }); + window->NotifyWindowCoordinateChange(WindowSizeChangeReason::UNDEFINED); + EXPECT_EQ(WMError::WM_ERROR_INVALID_WINDOW, window->Destroy()); + GTEST_LOG_(INFO) << "WindowSessionImplLayoutTest: NotifyWindowCoordinateChange end"; +} + /** * @tc.name: NotifyAfterUIContentReady * @tc.desc: NotifyAfterUIContentReady -- Gitee From 1067c6a2be6161c8446e16db1dce04eea8f101ce Mon Sep 17 00:00:00 2001 From: Zhuangwenbing Date: Fri, 12 Sep 2025 19:18:40 +0800 Subject: [PATCH 2/4] =?UTF-8?q?=E7=AA=97=E5=8F=A3=E5=8F=91=E9=80=81?= =?UTF-8?q?=E5=9D=90=E6=A0=87=E5=8F=98=E5=8C=96=E6=97=B6=E9=80=9A=E7=9F=A5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Zhuangwenbing --- .../layout/window_session_impl_layout_test.cpp | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/wm/test/unittest/layout/window_session_impl_layout_test.cpp b/wm/test/unittest/layout/window_session_impl_layout_test.cpp index 028b8f32b1..bd175f93fd 100644 --- a/wm/test/unittest/layout/window_session_impl_layout_test.cpp +++ b/wm/test/unittest/layout/window_session_impl_layout_test.cpp @@ -358,21 +358,21 @@ HWTEST_F(WindowSessionImplLayoutTest, NotifyTransformChange_TestUIContent, TestS } /** - * @tc.name: NotifyWindowStatusDidChange - * @tc.desc: NotifyWindowStatusDidChange + * @tc.name: NotifyWindowCoordinateChange + * @tc.desc: NotifyWindowCoordinateChange * @tc.type: FUNC */ -HWTEST_F(WindowSessionImplLayoutTest, NotifyWindowStatusDidChange, TestSize.Level1) +HWTEST_F(WindowSessionImplLayoutTest, NotifyWindowCoordinateChange, TestSize.Level1) { - GTEST_LOG_(INFO) << "WindowSessionImplLayoutTest: NotifyWindowStatusDidChange start"; - auto window = GetTestWindowImpl("NotifyWindowStatusDidChange"); - auto listeners = GetListenerList(); + GTEST_LOG_(INFO) << "WindowSessionImplLayoutTest: NotifyWindowCoordinateChange start"; + auto window = GetTestWindowImpl("NotifyWindowCoordinateChange"); + auto listeners = GetListenerList(); EXPECT_NE(listeners.size(), 0); listeners.insert(listeners.begin(), nullptr); - window->windowStatusDidChangeListeners_.insert({ window->GetPersistentId(), listeners }); - window->NotifyWindowStatusDidChange(WindowMode::WINDOW_MODE_FLOATING); + window->windowCoordinateChangeListeners_.insert({ window->GetPersistentId(), listeners }); + window->NotifyWindowCoordinateChange(WindowSizeChangeReason::UNDEFINED); EXPECT_EQ(WMError::WM_ERROR_INVALID_WINDOW, window->Destroy()); - GTEST_LOG_(INFO) << "WindowSessionImplLayoutTest: NotifyWindowStatusDidChange end"; + GTEST_LOG_(INFO) << "WindowSessionImplLayoutTest: NotifyWindowCoordinateChange end"; } /** -- Gitee From 34c27c88d977a6a170f0a5a59261a94eef61d21e Mon Sep 17 00:00:00 2001 From: Zhuangwenbing Date: Fri, 12 Sep 2025 11:26:07 +0000 Subject: [PATCH 3/4] =?UTF-8?q?=E5=88=A0=E9=99=A4=E6=96=87=E4=BB=B6=20wind?= =?UTF-8?q?ow=5Fscene/test/unittest/session=5Flayout=5Ftest.cpp?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../test/unittest/session_layout_test.cpp | 395 ------------------ 1 file changed, 395 deletions(-) delete mode 100644 window_scene/test/unittest/session_layout_test.cpp diff --git a/window_scene/test/unittest/session_layout_test.cpp b/window_scene/test/unittest/session_layout_test.cpp deleted file mode 100644 index ecf8f3f496..0000000000 --- a/window_scene/test/unittest/session_layout_test.cpp +++ /dev/null @@ -1,395 +0,0 @@ -/* - * Copyright (c) 2024 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include -#include -#include -#include - -#include "mock/mock_session_stage.h" -#include "mock/mock_window_event_channel.h" -#include "mock/mock_pattern_detach_callback.h" -#include "session/host/include/extension_session.h" -#include "session/host/include/move_drag_controller.h" -#include "session/host/include/scene_session.h" -#include "session_manager/include/scene_session_manager.h" -#include "session/host/include/session.h" -#include "session_info.h" -#include "key_event.h" -#include "wm_common.h" -#include "window_manager_hilog.h" - -using namespace testing; -using namespace testing::ext; - -namespace OHOS { -namespace Rosen { -namespace { -const std::string UNDEFINED = "undefined"; -} - -class SessionLayoutTest : public testing::Test { -public: - static void SetUpTestCase(); - static void TearDownTestCase(); - void SetUp() override; - void TearDown() override; - int32_t GetTaskCount(); - sptr ssm_; - -private: - RSSurfaceNode::SharedPtr CreateRSSurfaceNode(); - sptr session_ = nullptr; - static constexpr uint32_t WAIT_SYNC_IN_NS = 500000; - - class TLifecycleListener : public ILifecycleListener { - public: - virtual ~TLifecycleListener() {} - void OnActivation() override {} - void OnConnect() override {} - void OnForeground() override {} - void OnBackground() override {} - void OnDisconnect() override {} - void OnExtensionDied() override {} - void OnExtensionTimeout(int32_t errorCode) override {} - void OnAccessibilityEvent(const Accessibility::AccessibilityEventInfo& info, - int64_t uiExtensionIdLevel) override - { - } - void OnDrawingCompleted() override {} - void OnAppRemoveStartingWindow() override {} - }; - std::shared_ptr lifecycleListener_ = std::make_shared(); - - sptr mockSessionStage_ = nullptr; - sptr mockEventChannel_ = nullptr; -}; - -void SessionLayoutTest::SetUpTestCase() {} - -void SessionLayoutTest::TearDownTestCase() {} - -void SessionLayoutTest::SetUp() -{ - SessionInfo info; - info.abilityName_ = "testSession1"; - info.moduleName_ = "testSession2"; - info.bundleName_ = "testSession3"; - session_ = sptr::MakeSptr(info); - session_->surfaceNode_ = CreateRSSurfaceNode(); - ssm_ = sptr::MakeSptr(); - session_->SetEventHandler(ssm_->taskScheduler_->GetEventHandler(), ssm_->eventHandler_); - auto isScreenLockedCallback = [this]() { return ssm_->IsScreenLocked(); }; - session_->RegisterIsScreenLockedCallback(isScreenLockedCallback); - mockSessionStage_ = sptr::MakeSptr(); - mockEventChannel_ = sptr::MakeSptr(mockSessionStage_); -} - -void SessionLayoutTest::TearDown() -{ - session_ = nullptr; - usleep(WAIT_SYNC_IN_NS); -} - -RSSurfaceNode::SharedPtr SessionLayoutTest::CreateRSSurfaceNode() -{ - struct RSSurfaceNodeConfig rsSurfaceNodeConfig; - rsSurfaceNodeConfig.SurfaceNodeName = "WindowSessionTestSurfaceNode"; - auto surfaceNode = RSSurfaceNode::Create(rsSurfaceNodeConfig); - if (surfaceNode == nullptr) { - GTEST_LOG_(INFO) << "SessionLayoutTest::CreateRSSurfaceNode surfaceNode is nullptr"; - } - return surfaceNode; -} - -int32_t SessionLayoutTest::GetTaskCount() -{ - std::string dumpInfo = session_->handler_->GetEventRunner()->GetEventQueue()->DumpCurrentQueueSize(); - std::regex pattern("\\d+"); - std::smatch matches; - int32_t taskNum = 0; - while (std::regex_search(dumpInfo, matches, pattern)) { - taskNum += std::stoi(matches.str()); - dumpInfo = matches.suffix(); - } - return taskNum; -} - -namespace { -/** - * @tc.name: UpdateRect01 - * @tc.desc: update rect - * @tc.type: FUNC - * @tc.require: #I6JLSI - */ -HWTEST_F(SessionLayoutTest, UpdateRect01, TestSize.Level1) -{ - bool preBackgroundUpdateRectNotifyEnabled = Session::IsBackgroundUpdateRectNotifyEnabled(); - Session::SetBackgroundUpdateRectNotifyEnabled(true); - sptr mockSessionStage = sptr::MakeSptr(); - session_->sessionStage_ = mockSessionStage; - EXPECT_CALL(*(mockSessionStage), UpdateRect(_, _, _, _, _)).Times(AtLeast(1)).WillOnce(Return(WSError::WS_OK)); - - WSRect rect = { 0, 0, 0, 0 }; - ASSERT_EQ(WSError::WS_ERROR_INVALID_SESSION, - session_->UpdateRect(rect, SizeChangeReason::UNDEFINED, "SessionLayoutTest")); - sptr mockEventChannel = sptr::MakeSptr(mockSessionStage); - SystemSessionConfig sessionConfig; - sptr property = sptr::MakeSptr(); - ASSERT_EQ(WSError::WS_OK, session_->Connect(mockSessionStage, mockEventChannel, nullptr, sessionConfig, property)); - - rect = { 0, 0, 100, 100 }; - ASSERT_EQ(WSError::WS_ERROR_INVALID_SESSION, - session_->UpdateRect(rect, SizeChangeReason::UNDEFINED, "SessionLayoutTest")); - ASSERT_EQ(rect, session_->GetSessionRect()); - - rect = { 0, 0, 200, 200 }; - session_->UpdateSessionState(SessionState::STATE_ACTIVE); - ASSERT_EQ(WSError::WS_OK, session_->UpdateRect(rect, SizeChangeReason::UNDEFINED, "SessionLayoutTest")); - ASSERT_EQ(rect, session_->GetSessionRect()); - - rect = { 0, 0, 300, 300 }; - session_->sessionStage_ = nullptr; - ASSERT_EQ(WSError::WS_OK, session_->UpdateRect(rect, SizeChangeReason::UNDEFINED, "SessionLayoutTest")); - ASSERT_EQ(rect, session_->GetSessionRect()); - Session::SetBackgroundUpdateRectNotifyEnabled(preBackgroundUpdateRectNotifyEnabled); -} - -/** - * @tc.name: UpdateRect_TestForeground - * @tc.desc: update rect - * @tc.type: FUNC - * @tc.require: #I6JLSI - */ -HWTEST_F(SessionLayoutTest, UpdateRect_TestForeground, TestSize.Level1) -{ - bool preBackgroundUpdateRectNotifyEnabled = Session::IsBackgroundUpdateRectNotifyEnabled(); - Session::SetBackgroundUpdateRectNotifyEnabled(false); - sptr mockSessionStage = sptr::MakeSptr(); - session_->sessionStage_ = mockSessionStage; - - WSRect rect = { 0, 0, 100, 100 }; - session_->UpdateSessionState(SessionState::STATE_ACTIVE); - ASSERT_EQ(WSError::WS_OK, session_->UpdateRect(rect, SizeChangeReason::UNDEFINED, "SessionLayoutTest")); - session_->UpdateSessionState(SessionState::STATE_BACKGROUND); - ASSERT_EQ(WSError::WS_DO_NOTHING, session_->UpdateRect(rect, SizeChangeReason::UNDEFINED, "SessionLayoutTest")); - Session::SetBackgroundUpdateRectNotifyEnabled(preBackgroundUpdateRectNotifyEnabled); -} - -/** - * @tc.name: UpdateSessionRect01 - * @tc.desc: UpdateSessionRect - * @tc.type: FUNC - */ -HWTEST_F(SessionLayoutTest, UpdateSessionRect01, TestSize.Level1) -{ - SessionInfo info; - info.abilityName_ = "testSession1"; - info.bundleName_ = "testSession3"; - sptr sceneSession = sptr::MakeSptr(info, nullptr); - WSRect rect = { 0, 0, 320, 240 }; // width: 320, height: 240 - auto result = sceneSession->UpdateSessionRect(rect, SizeChangeReason::RESIZE); - ASSERT_EQ(result, WSError::WS_OK); - - result = sceneSession->UpdateSessionRect(rect, SizeChangeReason::RESIZE); - ASSERT_EQ(result, WSError::WS_OK); -} - -/** - * @tc.name: SetSingleHandTransform - * @tc.desc: SetSingleHandTransform - * @tc.type: FUNC - */ -HWTEST_F(SessionLayoutTest, SetSingleHandTransform, TestSize.Level1) -{ - SessionInfo info; - info.abilityName_ = "SetSingleHandTransform"; - info.bundleName_ = "SetSingleHandTransform"; - sptr session = sptr::MakeSptr(info); - SingleHandTransform transform; - session->SetSingleHandTransform(transform); - ASSERT_EQ(transform, session->GetSingleHandTransform()); -} - -/** - * @tc.name: IsDraggingReason - * @tc.desc: IsDraggingReason - * @tc.type: FUNC - */ -HWTEST_F(SessionLayoutTest, IsDraggingReason, TestSize.Level1) -{ - SessionInfo info; - info.abilityName_ = "IsDraggingReason"; - info.bundleName_ = "IsDraggingReason"; - sptr session = sptr::MakeSptr(info); - ASSERT_EQ(false, session->IsDraggingReason(SizeChangeReason::UNDEFINED)); - ASSERT_EQ(true, session->IsDraggingReason(SizeChangeReason::DRAG)); - ASSERT_EQ(true, session->IsDraggingReason(SizeChangeReason::DRAG_START)); - ASSERT_EQ(true, session->IsDraggingReason(SizeChangeReason::DRAG_MOVE)); -} - -/** - * @tc.name: SetDragStart - * @tc.desc: SetDragStart - * @tc.type: FUNC - */ -HWTEST_F(SessionLayoutTest, SetDragStart, TestSize.Level1) -{ - SessionInfo info; - info.abilityName_ = "SetDragStart"; - info.bundleName_ = "SetDragStart"; - sptr session = sptr::MakeSptr(info); - session->SetDragStart(true); - ASSERT_EQ(true, session->IsDragStart()); - session->SetDragStart(false); - ASSERT_EQ(false, session->IsDragStart()); -} - -/** - * @tc.name: SetHasRequestedVsyncFunc - * @tc.desc: SetHasRequestedVsyncFunc - * @tc.type: FUNC - */ -HWTEST_F(SessionLayoutTest, SetHasRequestedVsyncFunc, TestSize.Level1) -{ - SessionInfo info; - info.abilityName_ = "SetHasRequestedVsyncFunc"; - info.bundleName_ = "SetHasRequestedVsyncFunc"; - sptr session = sptr::MakeSptr(info); - session->SetHasRequestedVsyncFunc(nullptr); - ASSERT_EQ(nullptr, session->hasRequestedVsyncFunc_); - session->SetHasRequestedVsyncFunc([](bool& hasRequestedVsync) { - hasRequestedVsync = true; - return WSError::WS_OK; - }); - ASSERT_NE(nullptr, session->hasRequestedVsyncFunc_); -} - -/** - * @tc.name: SetRequestNextVsyncWhenModeChangeFunc - * @tc.desc: SetRequestNextVsyncWhenModeChangeFunc - * @tc.type: FUNC - */ -HWTEST_F(SessionLayoutTest, SetRequestNextVsyncWhenModeChangeFunc, TestSize.Level1) -{ - SessionInfo info; - info.abilityName_ = "SetRequestNextVsyncWhenModeChangeFunc"; - info.bundleName_ = "SetRequestNextVsyncWhenModeChangeFunc"; - sptr session = sptr::MakeSptr(info); - session->SetRequestNextVsyncWhenModeChangeFunc(nullptr); - ASSERT_EQ(nullptr, session->requestNextVsyncWhenModeChangeFunc_); - session->SetRequestNextVsyncWhenModeChangeFunc([](const std::shared_ptr& vsyncCallback) { - return WSError::WS_OK; - }); - ASSERT_NE(nullptr, session->requestNextVsyncWhenModeChangeFunc_); -} - -/** - * @tc.name: RequestNextVsyncWhenModeChange - * @tc.desc: RequestNextVsyncWhenModeChange - * @tc.type: FUNC - */ -HWTEST_F(SessionLayoutTest, RequestNextVsyncWhenModeChange, TestSize.Level1) -{ - SessionInfo info; - info.abilityName_ = "RequestNextVsyncWhenModeChange"; - info.bundleName_ = "RequestNextVsyncWhenModeChange"; - sptr session = sptr::MakeSptr(info); - auto ret = session->RequestNextVsyncWhenModeChange(); - EXPECT_EQ(WSError::WS_ERROR_NULLPTR, ret); - session->SetHasRequestedVsyncFunc([](bool& hasRequestedVsync) { - hasRequestedVsync = true; - return WSError::WS_OK; - }); - ret = session->RequestNextVsyncWhenModeChange(); - EXPECT_EQ(WSError::WS_OK, ret); -} - -/** - * @tc.name: InitVsyncCallbackForModeChangeAndRequestNextVsync - * @tc.desc: InitVsyncCallbackForModeChangeAndRequestNextVsync - * @tc.type: FUNC - */ -HWTEST_F(SessionLayoutTest, InitVsyncCallbackForModeChangeAndRequestNextVsync, TestSize.Level1) -{ - SessionInfo info; - info.abilityName_ = "InitVsyncCallbackForModeChangeAndRequestNextVsync"; - info.bundleName_ = "InitVsyncCallbackForModeChangeAndRequestNextVsync"; - sptr session = sptr::MakeSptr(info); - session->isWindowModeDirty_.store(true); - session->timesToWaitForVsync_.store(2); - session->requestNextVsyncWhenModeChangeFunc_ = nullptr; - session->InitVsyncCallbackForModeChangeAndRequestNextVsync(); - usleep(WAIT_SYNC_IN_NS); - EXPECT_EQ(session->timesToWaitForVsync_.load(), 2); - - session->SetRequestNextVsyncWhenModeChangeFunc([](const std::shared_ptr& vsyncCallback) { - vsyncCallback->onCallback(1, 1); - return WSError::WS_OK; - }); - session->InitVsyncCallbackForModeChangeAndRequestNextVsync(); - usleep(WAIT_SYNC_IN_NS); - EXPECT_NE(session->timesToWaitForVsync_.load(), 2); -} - -/** - * @tc.name: OnVsyncReceivedAfterModeChanged - * @tc.desc: OnVsyncReceivedAfterModeChanged - * @tc.type: FUNC - */ -HWTEST_F(SessionLayoutTest, OnVsyncReceivedAfterModeChanged, TestSize.Level1) -{ - SessionInfo info; - info.abilityName_ = "OnVsyncReceivedAfterModeChanged"; - info.bundleName_ = "OnVsyncReceivedAfterModeChanged"; - sptr session = sptr::MakeSptr(info); - session->isWindowModeDirty_.store(false); - session->timesToWaitForVsync_.store(2); - session->OnVsyncReceivedAfterModeChanged(); - usleep(WAIT_SYNC_IN_NS); - EXPECT_EQ(session->timesToWaitForVsync_.load(), 2); - - session->SetRequestNextVsyncWhenModeChangeFunc([](const std::shared_ptr& vsyncCallback) { - vsyncCallback->onCallback(1, 1); - return WSError::WS_OK; - }); - session->isWindowModeDirty_.store(true); - session->OnVsyncReceivedAfterModeChanged(); - usleep(WAIT_SYNC_IN_NS); - EXPECT_NE(session->timesToWaitForVsync_.load(), 2); - - session->isWindowModeDirty_.store(true); - session->timesToWaitForVsync_.store(-1); - session->OnVsyncReceivedAfterModeChanged(); - usleep(WAIT_SYNC_IN_NS); - EXPECT_EQ(session->timesToWaitForVsync_.load(), 0); - - session->isWindowModeDirty_.store(true); - session->timesToWaitForVsync_.store(1); - session->sessionStage_ = nullptr; - session->OnVsyncReceivedAfterModeChanged(); - usleep(WAIT_SYNC_IN_NS); - EXPECT_EQ(session->isWindowModeDirty_.load(), false); - - session->isWindowModeDirty_.store(true); - session->timesToWaitForVsync_.store(1); - session->sessionStage_ = sptr::MakeSptr(); - session->OnVsyncReceivedAfterModeChanged(); - usleep(WAIT_SYNC_IN_NS); - EXPECT_EQ(session->isWindowModeDirty_.load(), false); -} -} // namespace -} // namespace Rosen -} // namespace OHOS -- Gitee From 5863bf11ae853370238b1f15cda3b119c129391c Mon Sep 17 00:00:00 2001 From: Zhuangwenbing Date: Fri, 12 Sep 2025 11:26:19 +0000 Subject: [PATCH 4/4] =?UTF-8?q?=E5=88=A0=E9=99=A4=E6=96=87=E4=BB=B6=20wind?= =?UTF-8?q?ow=5Fscene/test/unittest/layout/session=5Fstage=5Fproxy=5Flayou?= =?UTF-8?q?t=5Ftest.cpp?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../session_stage_proxy_layout_test.cpp | 88 ------------------- 1 file changed, 88 deletions(-) delete mode 100644 window_scene/test/unittest/layout/session_stage_proxy_layout_test.cpp diff --git a/window_scene/test/unittest/layout/session_stage_proxy_layout_test.cpp b/window_scene/test/unittest/layout/session_stage_proxy_layout_test.cpp deleted file mode 100644 index 0aa0d8db3a..0000000000 --- a/window_scene/test/unittest/layout/session_stage_proxy_layout_test.cpp +++ /dev/null @@ -1,88 +0,0 @@ -/* - * Copyright (c) 2025 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 "iremote_object_mocker.h" -#include "mock_message_parcel.h" -#include "session/container/include/zidl/session_stage_proxy.h" -#include "window_manager_hilog.h" -#include "wm_common.h" - -using namespace testing; -using namespace testing::ext; - -namespace OHOS { -namespace Rosen { -class SessionStageProxyLayoutTest : public testing::Test { -public: - static void SetUpTestCase(); - static void TearDownTestCase(); - void SetUp() override; - void TearDown() override; - sptr iRemoteObjectMocker = sptr::MakeSptr(); - sptr sessionStage_ = sptr::MakeSptr(iRemoteObjectMocker); -}; - -void SessionStageProxyLayoutTest::SetUpTestCase() {} - -void SessionStageProxyLayoutTest::TearDownTestCase() {} - -void SessionStageProxyLayoutTest::SetUp() {} - -void SessionStageProxyLayoutTest::TearDown() {} - -namespace { -/** - * @tc.name: NotifySingleHandTransformChange - * @tc.desc: test function : NotifySingleHandTransformChange - * @tc.type: FUNC - */ -HWTEST_F(SessionStageProxyLayoutTest, NotifySingleHandTransformChange, TestSize.Level1) -{ - GTEST_LOG_(INFO) << "SessionStageProxyLayoutTest: NotifySingleHandTransformChange start"; - SingleHandTransform singleHandTransform; - sessionStage_->NotifySingleHandTransformChange(singleHandTransform); - ASSERT_TRUE((sessionStage_ != nullptr)); - GTEST_LOG_(INFO) << "SessionStageProxyLayoutTest: NotifySingleHandTransformChange end"; -} - -/** - * @tc.name: UpdateRect_WriteBoolErrorCase - * @tc.desc: test function : UpdateRect - * @tc.type: FUNC - */ -HWTEST_F(SessionStageProxyLayoutTest, UpdateRect_WriteBoolErrorCase, TestSize.Level1) -{ - ASSERT_TRUE(sessionStage_ != nullptr); - GTEST_LOG_(INFO) << "SessionStageProxyLayoutTest: UpdateRect_WriteBoolErrorCase start"; - MockMessageParcel::ClearAllErrorFlag(); - MockMessageParcel::SetWriteBoolErrorFlag(true); - WSRect rect; - SizeChangeReason reason = SizeChangeReason::UNDEFINED; - SceneAnimationConfig config { .rsTransaction_ = nullptr, .animationDuration_ = 400 }; - const std::map avoidAreas = {}; - bool isWindowCoordinateChanged = true; - WSError ret = sessionStage_->UpdateRect(rect, reason, config, avoidAreas, isWindowCoordinateChanged); - EXPECT_EQ(ret, WSError::WS_ERROR_IPC_FAILED); - - MockMessageParcel::SetWriteBoolErrorFlag(false); - ret = sessionStage_->UpdateRect(rect, reason, config, avoidAreas, isWindowCoordinateChanged); - EXPECT_EQ(ret, WSError::WS_OK); - GTEST_LOG_(INFO) << "SessionStageProxyLayoutTest: UpdateRect_WriteBoolErrorCase end"; -} -} // namespace -} // namespace Rosen -} // namespace OHOS \ No newline at end of file -- Gitee