From 87aabbe56f80c7108680fc1270682ce8dcd4b2c4 Mon Sep 17 00:00:00 2001 From: wangh Date: Fri, 20 Oct 2023 15:43:15 +0800 Subject: [PATCH] add test for interactive notification Signed-off-by: wangh --- .../wms/window_fuzzer/window_fuzzer.cpp | 9 +++++++ .../window_agent_fuzzer.cpp | 1 + .../windowscene_fuzzer/windowscene_fuzzer.cpp | 6 +++++ .../unittest/scene_session_manager_test.cpp | 19 ++++++++++++++ .../unittest/session_stage_proxy_test.cpp | 13 ++++++++++ .../test/unittest/session_stage_stub_test.cpp | 16 ++++++++++++ window_scene/test/unittest/session_test.cpp | 25 +++++++++++++++++++ wm/test/unittest/window_agent_test.cpp | 18 +++++++++++++ wm/test/unittest/window_impl_test.cpp | 20 +++++++++++++++ wm/test/unittest/window_proxy_test.cpp | 14 +++++++++++ .../window_scene_session_impl_test.cpp | 2 ++ wm/test/unittest/window_session_impl_test.cpp | 25 +++++++++++++++++++ wm/test/unittest/window_stub_test.cpp | 19 ++++++++++++++ 13 files changed, 187 insertions(+) diff --git a/test/fuzztest/wms/window_fuzzer/window_fuzzer.cpp b/test/fuzztest/wms/window_fuzzer/window_fuzzer.cpp index 085496a971..3eff950205 100644 --- a/test/fuzztest/wms/window_fuzzer/window_fuzzer.cpp +++ b/test/fuzztest/wms/window_fuzzer/window_fuzzer.cpp @@ -195,6 +195,14 @@ public: void AfterInactive() override { } + + void AfterResumed() override + { + } + + void AfterPaused() override + { + } }; template @@ -449,6 +457,7 @@ void CheckWindowImplFunctionsPart4(sptr window, const uint8_t* data, bool boolVal; startPos += GetObject(boolVal, data + startPos, size - startPos); window->UpdateActiveStatus(boolVal); + window->NotifyForegroundInteractiveStatus(boolVal); Transform trans; startPos += GetObject(trans, data + startPos, size - startPos); diff --git a/test/fuzztest/wms/windowagent_fuzzer/window_agent_fuzzer.cpp b/test/fuzztest/wms/windowagent_fuzzer/window_agent_fuzzer.cpp index c0fa2ce8fb..e884c8e0d9 100644 --- a/test/fuzztest/wms/windowagent_fuzzer/window_agent_fuzzer.cpp +++ b/test/fuzztest/wms/windowagent_fuzzer/window_agent_fuzzer.cpp @@ -65,6 +65,7 @@ void CheckWindowAgentFunctionsPart1(sptr agent, const uint8_t* data startPos += GetObject(modeSupportInfo, data + startPos, size - startPos); agent->UpdateWindowModeSupportInfo(modeSupportInfo); agent->UpdateFocusStatus(boolVal); + agent->NotifyForegroundInteractiveStatus(boolVal); sptr avoidArea = new AvoidArea(); startPos += GetObject(rect, data + startPos, size - startPos); diff --git a/test/fuzztest/wms/windowscene_fuzzer/windowscene_fuzzer.cpp b/test/fuzztest/wms/windowscene_fuzzer/windowscene_fuzzer.cpp index ddd31aed74..470819f7b3 100644 --- a/test/fuzztest/wms/windowscene_fuzzer/windowscene_fuzzer.cpp +++ b/test/fuzztest/wms/windowscene_fuzzer/windowscene_fuzzer.cpp @@ -54,6 +54,12 @@ public: virtual void AfterInactive() override { } + virtual void AfterResumed() override + { + } + virtual void AfterPaused() override + { + } }; template diff --git a/window_scene/test/unittest/scene_session_manager_test.cpp b/window_scene/test/unittest/scene_session_manager_test.cpp index 8cb7f703ec..090f5434cd 100644 --- a/window_scene/test/unittest/scene_session_manager_test.cpp +++ b/window_scene/test/unittest/scene_session_manager_test.cpp @@ -1833,6 +1833,25 @@ HWTEST_F(SceneSessionManagerTest, RequestSceneSessionDestruction, Function | Sma delete scensession; } +/** + * @tc.name: NotifyForegroundInteractiveStatus + * @tc.desc: SceneSesionManager notify scene session interactive status + * @tc.type: FUNC +*/ +HWTEST_F(SceneSessionManagerTest, NotifyForegroundInteractiveStatus, Function | SmallTest | Level3) +{ + bool interactive = false; + SessionInfo info; + info.abilityName_ = "Foreground01"; + info.bundleName_ = "Foreground01"; + sptr scensession; + scensession = new (std::nothrow) SceneSession(info, nullptr); + int ret = 0; + ssm_->NotifyForegroundInteractiveStatus(scensession, interactive); + ASSERT_EQ(ret, 0); + delete scensession; +} + /** * @tc.name: AddClientDeathRecipient * @tc.desc: SceneSesionManager add client death recipient diff --git a/window_scene/test/unittest/session_stage_proxy_test.cpp b/window_scene/test/unittest/session_stage_proxy_test.cpp index 126214968e..275bb4cac1 100644 --- a/window_scene/test/unittest/session_stage_proxy_test.cpp +++ b/window_scene/test/unittest/session_stage_proxy_test.cpp @@ -239,6 +239,19 @@ HWTEST_F(SessionStageProxyTest, UpdateWindowMode, Function | SmallTest | Level1) ASSERT_TRUE((sessionStage_ != nullptr)); sessionStage_->UpdateWindowMode(mode); } + +/** + * @tc.name: NotifyForegroundInteractiveStatus + * @tc.desc: test function : NotifyForegroundInteractiveStatus + * @tc.type: FUNC + */ +HWTEST_F(SessionStageProxyTest, NotifyForegroundInteractiveStatus, Function | SmallTest | Level1) +{ + bool interactive = true; + ASSERT_TRUE((sessionStage_ != nullptr)); + sessionStage_->NotifyForegroundInteractiveStatus(interactive); +} + } } } \ No newline at end of file diff --git a/window_scene/test/unittest/session_stage_stub_test.cpp b/window_scene/test/unittest/session_stage_stub_test.cpp index 76eb133661..fd5318bbc1 100644 --- a/window_scene/test/unittest/session_stage_stub_test.cpp +++ b/window_scene/test/unittest/session_stage_stub_test.cpp @@ -280,6 +280,22 @@ HWTEST_F(SessionStageStubTest, HandleUpdateWindowMode, Function | SmallTest | Le ASSERT_TRUE((sessionStageStub_ != nullptr)); ASSERT_EQ(0, sessionStageStub_->HandleUpdateWindowMode(data, reply)); } + +/** + * @tc.name: HandleNotifyForegroundInteractiveStatus + * @tc.desc: test function : HandleNotifyForegroundInteractiveStatus + * @tc.type: FUNC + */ +HWTEST_F(SessionStageStubTest, HandleNotifyForegroundInteractiveStatus, Function | SmallTest | Level1) +{ + MessageParcel data; + MessageParcel reply; + + data.WriteBool(true); + ASSERT_TRUE((sessionStageStub_ != nullptr)); + ASSERT_EQ(0, sessionStageStub_->HandleNotifyForegroundInteractiveStatus(data, reply)); +} + } } } \ No newline at end of file diff --git a/window_scene/test/unittest/session_test.cpp b/window_scene/test/unittest/session_test.cpp index 51bbf624f9..445f8d11d6 100644 --- a/window_scene/test/unittest/session_test.cpp +++ b/window_scene/test/unittest/session_test.cpp @@ -2013,6 +2013,31 @@ HWTEST_F(WindowSessionTest, SetBufferAvailable, Function | SmallTest | Level2) session_->SetBufferAvailable(111); ASSERT_EQ(true, session_->GetBufferAvailable()); } + +/** + * @tc.name: NotifyForegroundInteractiveStatus + * @tc.desc: NotifyForegroundInteractiveStatus Test + * @tc.type: FUNC + */ +HWTEST_F(WindowSessionTest, NotifyForegroundInteractiveStatus, Function | SmallTest | Level2) +{ + ASSERT_NE(session_, nullptr); + + session_->sessionStage_ = nullptr; + bool interactive = true; + session_->NotifyForegroundInteractiveStatus(interactive); + + sptr mockSessionStage = new(std::nothrow) SessionStageMocker(); + ASSERT_NE(mockSessionStage, nullptr); + session_->sessionStage_ = mockSessionStage; + session_->state_ = SessionState::STATE_FOREGROUND; + interactive = false; + session_->NotifyForegroundInteractiveStatus(interactive); + + session_->state_ = SessionState::STATE_DISCONNECT; + ASSERT_EQ(WSError::WS_ERROR_INVALID_SESSION, session_->SetFocusable(false)); +} + } } // namespace Rosen } // namespace OHOS \ No newline at end of file diff --git a/wm/test/unittest/window_agent_test.cpp b/wm/test/unittest/window_agent_test.cpp index aaf27c0ff3..94683746be 100644 --- a/wm/test/unittest/window_agent_test.cpp +++ b/wm/test/unittest/window_agent_test.cpp @@ -402,6 +402,24 @@ HWTEST_F(WindowAgentTest, ConsumeKeyEvent, Function | SmallTest | Level2) ASSERT_EQ(0, res); } +/** + * @tc.name: NotifyForegroundInteractiveStatus + * @tc.desc: NotifyForegroundInteractiveStatus + * @tc.type: FUNC + */ +HWTEST_F(WindowAgentTest, NotifyForegroundInteractiveStatus, Function | SmallTest | Level2) +{ + auto res = 0; + bool interactive = false; + windowAgent_->NotifyForegroundInteractiveStatus(interactive); + ASSERT_EQ(0, res); + + interactive = true; + windowAgent_->window_ = nullptr; + windowAgent_->NotifyForegroundInteractiveStatus(interactive); + ASSERT_EQ(0, res); +} + } } } \ No newline at end of file diff --git a/wm/test/unittest/window_impl_test.cpp b/wm/test/unittest/window_impl_test.cpp index bae0b9bf85..930c0fe2c2 100644 --- a/wm/test/unittest/window_impl_test.cpp +++ b/wm/test/unittest/window_impl_test.cpp @@ -3743,6 +3743,26 @@ HWTEST_F(WindowImplTest, GetTopWindowWithId, Function | SmallTest | Level3) ASSERT_EQ(WMError::WM_OK, window->Destroy()); } + +/** + * @tc.name: NotifyForegroundInteractiveStatus + * @tc.desc: NotifyForegroundInteractiveStatus Test + * @tc.type: FUNC + */ +HWTEST_F(WindowImplTest, NotifyForegroundInteractiveStatus, Function | SmallTest | Level2) +{ + sptr option = new WindowOption(); + ASSERT_NE(option, nullptr); + sptr window = new WindowImpl(option); + ASSERT_NE(window, nullptr); + bool interactive = false; + window->NotifyForegroundInteractiveStatus(interactive); + window->SetWindowState(WindowState::STATE_DESTROYED); + interactive = true; + window->NotifyForegroundInteractiveStatus(interactive); + ASSERT_EQ(WindowState::STATE_DESTROYED, window->GetWindowState()); +} + } } // namespace Rosen } // namespace OHOS diff --git a/wm/test/unittest/window_proxy_test.cpp b/wm/test/unittest/window_proxy_test.cpp index bf352fc223..2f32ede037 100644 --- a/wm/test/unittest/window_proxy_test.cpp +++ b/wm/test/unittest/window_proxy_test.cpp @@ -284,6 +284,20 @@ HWTEST_F(WindowProxyTest, NotifyScreenshot, Function | SmallTest | Level2) ASSERT_EQ(err, WMError::WM_OK); } +/** + * @tc.name: NotifyForegroundInteractiveStatus + * @tc.desc: normal function + * @tc.type: FUNC + */ +HWTEST_F(WindowProxyTest, NotifyForegroundInteractiveStatus, Function | SmallTest | Level2) +{ + ASSERT_NE(windowProxy_, nullptr); + WMError err = WMError::WM_OK; + bool interactive = false; + windowProxy_->NotifyForegroundInteractiveStatus(interactive); + ASSERT_EQ(err, WMError::WM_OK); +} + } } } diff --git a/wm/test/unittest/window_scene_session_impl_test.cpp b/wm/test/unittest/window_scene_session_impl_test.cpp index 6b6a385412..14db65aa2c 100644 --- a/wm/test/unittest/window_scene_session_impl_test.cpp +++ b/wm/test/unittest/window_scene_session_impl_test.cpp @@ -44,6 +44,8 @@ public: MOCK_METHOD1(ForegroundFailed, void(int32_t)); MOCK_METHOD0(AfterActive, void(void)); MOCK_METHOD0(AfterInactive, void(void)); + MOCK_METHOD0(AfterResumed, void(void)); + MOCK_METHOD0(AfterPaused, void(void)); }; class WindowSceneSessionImplTest : public testing::Test { diff --git a/wm/test/unittest/window_session_impl_test.cpp b/wm/test/unittest/window_session_impl_test.cpp index faccb087c4..884e5c7252 100644 --- a/wm/test/unittest/window_session_impl_test.cpp +++ b/wm/test/unittest/window_session_impl_test.cpp @@ -40,6 +40,8 @@ public: MOCK_METHOD1(ForegroundFailed, void(int32_t)); MOCK_METHOD0(AfterActive, void(void)); MOCK_METHOD0(AfterInactive, void(void)); + MOCK_METHOD0(AfterResumed, void(void)); + MOCK_METHOD0(AfterPaused, void(void)); }; class WindowSessionImplTest : public testing::Test { @@ -974,6 +976,29 @@ HWTEST_F(WindowSessionImplTest, NotifyAfterUnfocused, Function | SmallTest | Lev GTEST_LOG_(INFO) << "WindowSessionImplTest: NotifyAfterUnfocused end"; } +/** + * @tc.name: NotifyForegroundInteractiveStatus + * @tc.desc: NotifyForegroundInteractiveStatus + * @tc.type: FUNC + */ +HWTEST_F(WindowSessionImplTest, NotifyForegroundInteractiveStatus, Function | SmallTest | Level2) +{ + GTEST_LOG_(INFO) << "WindowSessionImplTest: NotifyForegroundInteractiveStatus start"; + sptr option = new WindowOption(); + ASSERT_NE(option, nullptr); + option->SetWindowName("NotifyForegroundInteractiveStatus"); + sptr window = + new (std::nothrow) WindowSessionImpl(option); + ASSERT_NE(window, nullptr); + + int res = 0; + window->NotifyForegroundInteractiveStatus(true); + window->NotifyForegroundInteractiveStatus(false); + ASSERT_EQ(res, 0); + + GTEST_LOG_(INFO) << "WindowSessionImplTest: NotifyForegroundInteractiveStatus end"; +} + /** * @tc.name: NotifyBeforeDestroy * @tc.desc: NotifyBeforeDestroy diff --git a/wm/test/unittest/window_stub_test.cpp b/wm/test/unittest/window_stub_test.cpp index 30ac50c4f2..91584ab411 100644 --- a/wm/test/unittest/window_stub_test.cpp +++ b/wm/test/unittest/window_stub_test.cpp @@ -237,6 +237,25 @@ HWTEST_F(WindowStubTest, OnRemoteRequest08, Function | SmallTest | Level2) EXPECT_EQ(res, -1); } + +/** + * @tc.name: OnRemoteRequest09 + * @tc.desc: test TRANS_ID_NOTIFY_FOREGROUND_INTERACTIVE_STATUS success + * @tc.type: FUNC + */ +HWTEST_F(WindowStubTest, OnRemoteRequest09, Function | SmallTest | Level2) +{ + MessageParcel data; + MessageParcel reply; + MessageOption option(MessageOption::TF_ASYNC); + + data.WriteInterfaceToken(WindowStub::GetDescriptor()); + data.WriteBool(false); + uint32_t code = static_cast(IWindow::WindowMessage::TRANS_ID_NOTIFY_FOREGROUND_INTERACTIVE_STATUS); + int res = windowStub_->OnRemoteRequest(code, data, reply, option); + EXPECT_EQ(res, 0); +} + } } } -- Gitee