/* * Copyright (c) 2023 Huawei Device Co., Ltd. * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ #include #include #include #include #include #include "ability_context_impl.h" #include "accessibility_event_info.h" #include "color_parser.h" #include "extension/extension_business_info.h" #include "mock_session.h" #include "mock_session_stub.h" #include "mock_uicontent.h" #include "mock_window.h" #include "parameters.h" #include "window_helper.h" #include "window_session_impl.h" #include "wm_common.h" #include "window_manager_hilog.h" using namespace testing; using namespace testing::ext; namespace OHOS { namespace Rosen { namespace { std::string g_errLog; void MyLogCallback(const LogType type, const LogLevel level, const unsigned int domain, const char *tag, const char *msg) { g_errLog = msg; } class WindowSessionImplTest : public testing::Test { public: static void SetUpTestCase(); static void TearDownTestCase(); void SetUp() override; void TearDown() override; std::shared_ptr abilityContext_; private: static constexpr uint32_t WAIT_SYNC_IN_NS = 50000; }; void WindowSessionImplTest::SetUpTestCase() {} void WindowSessionImplTest::TearDownTestCase() {} void WindowSessionImplTest::SetUp() { abilityContext_ = std::make_shared(); } void WindowSessionImplTest::TearDown() { usleep(WAIT_SYNC_IN_NS); abilityContext_ = nullptr; } namespace { /** * @tc.name: CreateWindowAndDestroy01 * @tc.desc: Create window and destroy window * @tc.type: FUNC */ HWTEST_F(WindowSessionImplTest, CreateWindowAndDestroy01, TestSize.Level1) { sptr option = sptr::MakeSptr(); option->SetWindowName("CreateWindow01"); sptr window = sptr::MakeSptr(option); SessionInfo sessionInfo = { "CreateTestBundle", "CreateTestModule", "CreateTestAbility" }; sptr session = new (std::nothrow) SessionMocker(sessionInfo); ASSERT_NE(nullptr, session); ASSERT_EQ(WMError::WM_OK, window->Create(nullptr, session)); ASSERT_EQ(WMError::WM_OK, window->Create(abilityContext_, session)); ASSERT_EQ(WMError::WM_OK, window->Create(abilityContext_, session)); window->property_->SetPersistentId(1); ASSERT_EQ(WMError::WM_ERROR_INVALID_WINDOW, window->Destroy()); // session is null window = sptr::MakeSptr(option); ASSERT_EQ(WMError::WM_OK, window->Create(abilityContext_, nullptr)); ASSERT_EQ(WMError::WM_ERROR_INVALID_WINDOW, window->Destroy()); window = sptr::MakeSptr(option); ASSERT_EQ(WMError::WM_OK, window->Create(abilityContext_, session)); ASSERT_EQ(WMError::WM_ERROR_INVALID_WINDOW, window->Destroy(false)); } /** * @tc.name: CreateWindowAndDestroy02 * @tc.desc: Create window and destroy window * @tc.type: FUNC */ HWTEST_F(WindowSessionImplTest, CreateWindowAndDestroy02, TestSize.Level1) { std::string identityToken = "testToken"; sptr option = sptr::MakeSptr(); option->SetWindowName("CreateWindow01"); sptr window = sptr::MakeSptr(option); SessionInfo sessionInfo = { "CreateTestBundle", "CreateTestModule", "CreateTestAbility" }; sptr session = new (std::nothrow) SessionMocker(sessionInfo); ASSERT_NE(nullptr, session); ASSERT_EQ(WMError::WM_OK, window->Create(nullptr, session, identityToken)); ASSERT_EQ(WMError::WM_OK, window->Create(abilityContext_, session, identityToken)); ASSERT_EQ(WMError::WM_OK, window->Create(abilityContext_, session, identityToken)); window->property_->SetPersistentId(1); ASSERT_EQ(WMError::WM_ERROR_INVALID_WINDOW, window->Destroy()); // session is null window = sptr::MakeSptr(option); ASSERT_EQ(WMError::WM_OK, window->Create(abilityContext_, nullptr)); ASSERT_EQ(WMError::WM_ERROR_INVALID_WINDOW, window->Destroy()); window = sptr::MakeSptr(option); ASSERT_EQ(WMError::WM_OK, window->Create(abilityContext_, session, identityToken)); ASSERT_EQ(WMError::WM_ERROR_INVALID_WINDOW, window->Destroy(false)); } /** * @tc.name: Connect01 * @tc.desc: Connect session * @tc.type: FUNC */ HWTEST_F(WindowSessionImplTest, Connect01, TestSize.Level1) { sptr option = sptr::MakeSptr(); option->SetWindowName("Connect01"); sptr window = sptr::MakeSptr(option); window->property_->SetPersistentId(1); // connect with null session ASSERT_EQ(WMError::WM_ERROR_NULLPTR, window->Connect()); SessionInfo sessionInfo = { "CreateTestBundle", "CreateTestModule", "CreateTestAbility" }; sptr session = new (std::nothrow) SessionMocker(sessionInfo); ASSERT_NE(nullptr, session); window->hostSession_ = session; EXPECT_CALL(*(session), Connect(_, _, _, _, _, _, _)).WillOnce(Return(WSError::WS_ERROR_NULLPTR)); ASSERT_EQ(WMError::WM_ERROR_NULLPTR, window->Connect()); EXPECT_CALL(*(session), Connect(_, _, _, _, _, _, _)).WillOnce(Return(WSError::WS_OK)); ASSERT_EQ(WMError::WM_OK, window->Connect()); ASSERT_EQ(WMError::WM_OK, window->Destroy()); } /** * @tc.name: Connect_RegisterWindowScaleCallback * @tc.desc: Connect test RegisterWindowScaleCallback * @tc.type: FUNC */ HWTEST_F(WindowSessionImplTest, Connect_RegisterWindowScaleCallback, TestSize.Level1) { sptr option = sptr::MakeSptr(); option->SetWindowName("Connect_RegisterWindowScaleCallback"); sptr window = sptr::MakeSptr(option); SessionInfo sessionInfo = { "CreateTestBundle", "CreateTestModule", "CreateTestAbility" }; sptr session = sptr::MakeSptr(sessionInfo); window->hostSession_ = session; window->property_->SetPersistentId(1); EXPECT_CALL(*(session), Connect(_, _, _, _, _, _, _)).WillRepeatedly(Return(WSError::WS_OK)); window->property_->SetWindowType(WindowType::WINDOW_TYPE_UI_EXTENSION); EXPECT_EQ(WMError::WM_OK, window->Connect()); window->property_->SetWindowType(WindowType::WINDOW_TYPE_APP_MAIN_WINDOW); sptr compatibleModeProperty = sptr::MakeSptr(); compatibleModeProperty->SetIsAdaptToSimulationScale(true); window->property_->SetCompatibleModeProperty(compatibleModeProperty); EXPECT_EQ(WMError::WM_OK, window->Connect()); EXPECT_EQ(WMError::WM_OK, window->Destroy()); } /** * @tc.name: Show01 * @tc.desc: Show session * @tc.type: FUNC */ HWTEST_F(WindowSessionImplTest, Show01, TestSize.Level1) { sptr option = sptr::MakeSptr(); option->SetWindowName("Show01"); sptr window = new (std::nothrow) WindowSessionImpl(option); ASSERT_NE(nullptr, window); window->property_->SetPersistentId(1); // show with null session ASSERT_EQ(WMError::WM_ERROR_INVALID_WINDOW, window->Show()); SessionInfo sessionInfo = { "CreateTestBundle", "CreateTestModule", "CreateTestAbility" }; sptr session = new (std::nothrow) SessionMocker(sessionInfo); ASSERT_NE(nullptr, session); window->hostSession_ = session; EXPECT_CALL(*(session), Foreground(_, _, _)).WillOnce(Return(WSError::WS_OK)); ASSERT_EQ(WMError::WM_OK, window->Show()); ASSERT_EQ(WMError::WM_OK, window->Show()); window->state_ = WindowState::STATE_CREATED; EXPECT_CALL(*(session), Foreground(_, _, _)).WillOnce(Return(WSError::WS_ERROR_INVALID_SESSION)); ASSERT_EQ(WMError::WM_ERROR_INVALID_SESSION, window->Show()); ASSERT_EQ(WMError::WM_OK, window->Destroy()); } /** * @tc.name: Hide01 * @tc.desc: Hide session * @tc.type: FUNC */ HWTEST_F(WindowSessionImplTest, Hide01, TestSize.Level1) { sptr option = sptr::MakeSptr(); option->SetWindowName("Hide01"); sptr window = new (std::nothrow) WindowSessionImpl(option); ASSERT_NE(nullptr, window); window->property_->SetPersistentId(1); // show with null session ASSERT_EQ(WMError::WM_ERROR_INVALID_WINDOW, window->Hide()); SessionInfo sessionInfo = { "CreateTestBundle", "CreateTestModule", "CreateTestAbility" }; sptr session = new (std::nothrow) SessionMocker(sessionInfo); ASSERT_NE(nullptr, session); window->hostSession_ = session; ASSERT_EQ(WMError::WM_OK, window->Hide()); ASSERT_EQ(WMError::WM_OK, window->Hide()); window->state_ = WindowState::STATE_CREATED; ASSERT_EQ(WMError::WM_OK, window->Hide()); window->state_ = WindowState::STATE_SHOWN; window->property_->type_ = WindowType::WINDOW_TYPE_FLOAT; ASSERT_EQ(WMError::WM_OK, window->Hide()); window->property_->type_ = WindowType::WINDOW_TYPE_APP_MAIN_WINDOW; ASSERT_EQ(WMError::WM_OK, window->Destroy()); } /** * @tc.name: SetWindowType01 * @tc.desc: SetWindowType * @tc.type: FUNC */ HWTEST_F(WindowSessionImplTest, SetWindowType01, TestSize.Level1) { GTEST_LOG_(INFO) << "WindowSessionImplTest: SetWindowType01 start"; sptr option = sptr::MakeSptr(); sptr window = sptr::MakeSptr(option); ASSERT_NE(window->property_, nullptr); window->property_->SetPersistentId(1); option->SetWindowName("SetWindowType01"); WindowType type = WindowType::WINDOW_TYPE_BOOT_ANIMATION; option->SetWindowType(type); window = sptr::MakeSptr(option); ASSERT_NE(window, nullptr); WindowType type1 = WindowType::WINDOW_TYPE_POINTER; option->SetWindowType(type1); window = sptr::MakeSptr(option); ASSERT_NE(window, nullptr); WindowType type2 = WindowType::WINDOW_TYPE_APP_MAIN_WINDOW; option->SetWindowType(type2); window = sptr::MakeSptr(option); ASSERT_NE(window, nullptr); WindowType type3 = WindowType::APP_MAIN_WINDOW_END; option->SetWindowType(type3); window = sptr::MakeSptr(option); ASSERT_NE(window, nullptr); GTEST_LOG_(INFO) << "WindowSessionImplTest: SetWindowType01 end"; } /** * @tc.name: ColorSpace * @tc.desc: SetColorSpace and GetColorSpace * @tc.type: FUNC */ HWTEST_F(WindowSessionImplTest, ColorSpace, TestSize.Level1) { GTEST_LOG_(INFO) << "WindowSessionImplTest: ColorSpace start"; sptr option = sptr::MakeSptr(); option->SetWindowName("ColorSpace"); sptr window = new (std::nothrow) WindowSessionImpl(option); ASSERT_NE(window, nullptr); ASSERT_NE(window->property_, nullptr); window->property_->SetPersistentId(1); window->SetColorSpace(ColorSpace::COLOR_SPACE_DEFAULT); ColorSpace colorSpace = window->GetColorSpace(); ASSERT_EQ(colorSpace, ColorSpace::COLOR_SPACE_DEFAULT); SessionInfo sessionInfo = { "CreateTestBundle", "CreateTestModule", "CreateTestAbility" }; sptr session = new (std::nothrow) SessionMocker(sessionInfo); ASSERT_NE(session, nullptr); window->hostSession_ = session; window->state_ = WindowState::STATE_CREATED; ASSERT_FALSE(window->IsWindowSessionInvalid()); window->surfaceNode_ = nullptr; window->SetColorSpace(ColorSpace::COLOR_SPACE_WIDE_GAMUT); ColorSpace colorSpace1 = window->GetColorSpace(); ASSERT_EQ(colorSpace1, ColorSpace::COLOR_SPACE_DEFAULT); struct RSSurfaceNodeConfig config; window->surfaceNode_ = RSSurfaceNode::Create(config); window->SetColorSpace(ColorSpace::COLOR_SPACE_WIDE_GAMUT); ColorSpace colorSpace2 = window->GetColorSpace(); ASSERT_EQ(colorSpace2, ColorSpace::COLOR_SPACE_WIDE_GAMUT); GTEST_LOG_(INFO) << "WindowSessionImplTest: ColorSpace end"; } /** * @tc.name: MakeSubOrDialogWindowDragableAndMoveble02 * @tc.desc: MakeSubOrDialogWindowDragableAndMoveble * @tc.type: FUNC */ HWTEST_F(WindowSessionImplTest, MakeSubOrDialogWindowDragableAndMoveble02, TestSize.Level1) { GTEST_LOG_(INFO) << "WindowSessionImplTest: MakeSubOrDialogWindowDragableAndMoveble02 start"; sptr option = sptr::MakeSptr(); option->SetDialogDecorEnable(true); option->SetWindowName("MakeSubOrDialogWindowDragableAndMoveble02"); sptr window = new (std::nothrow) WindowSessionImpl(option); ASSERT_NE(nullptr, window); window->property_->SetWindowType(WindowType::WINDOW_TYPE_DIALOG); window->windowSystemConfig_.windowUIType_ = WindowUIType::PC_WINDOW; window->MakeSubOrDialogWindowDragableAndMoveble(); ASSERT_EQ(true, window->property_->IsDecorEnable()); GTEST_LOG_(INFO) << "WindowSessionImplTest: MakeSubOrDialogWindowDragableAndMoveble02 end"; } /** * @tc.name: MakeSubOrDialogWindowDragableAndMoveble03 * @tc.desc: MakeSubOrDialogWindowDragableAndMoveble * @tc.type: FUNC */ HWTEST_F(WindowSessionImplTest, MakeSubOrDialogWindowDragableAndMoveble03, TestSize.Level1) { GTEST_LOG_(INFO) << "WindowSessionImplTest: MakeSubOrDialogWindowDragableAndMoveble03 start"; sptr option = sptr::MakeSptr(); option->SetDialogDecorEnable(true); option->SetWindowName("MakeSubOrDialogWindowDragableAndMoveble03"); sptr window = new (std::nothrow) WindowSessionImpl(option); ASSERT_NE(nullptr, window); window->property_->SetWindowType(WindowType::WINDOW_TYPE_DIALOG); window->windowSystemConfig_.windowUIType_ = WindowUIType::PHONE_WINDOW; window->MakeSubOrDialogWindowDragableAndMoveble(); ASSERT_EQ(false, window->property_->IsDecorEnable()); GTEST_LOG_(INFO) << "WindowSessionImplTest: MakeSubOrDialogWindowDragableAndMoveble03 end"; } /** * @tc.name: MakeSubOrDialogWindowDragableAndMoveble * @tc.desc: MakeSubOrDialogWindowDragableAndMoveble04 * @tc.type: FUNC */ HWTEST_F(WindowSessionImplTest, MakeSubOrDialogWindowDragableAndMoveble04, TestSize.Level1) { GTEST_LOG_(INFO) << "WindowSessionImplTest: MakeSubOrDialogWindowDragableAndMoveble04 start"; sptr option = sptr::MakeSptr(); ASSERT_NE(nullptr, option); option->SetSubWindowDecorEnable(true); option->SetWindowName("MakeSubOrDialogWindowDragableAndMoveble04"); sptr window = new (std::nothrow) WindowSessionImpl(option); ASSERT_NE(nullptr, window); window->property_->SetWindowType(WindowType::WINDOW_TYPE_APP_SUB_WINDOW); window->windowSystemConfig_.freeMultiWindowSupport_ = true; window->windowSystemConfig_.freeMultiWindowEnable_ = true; window->MakeSubOrDialogWindowDragableAndMoveble(); ASSERT_TRUE(window->property_->IsDecorEnable()); GTEST_LOG_(INFO) << "WindowSessionImplTest: MakeSubOrDialogWindowDragableAndMoveble04 end"; } /** * @tc.name: MakeSubOrDialogWindowDragableAndMoveble05 * @tc.desc: MakeSubOrDialogWindowDragableAndMoveble * @tc.type: FUNC */ HWTEST_F(WindowSessionImplTest, MakeSubOrDialogWindowDragableAndMoveble05, TestSize.Level1) { GTEST_LOG_(INFO) << "WindowSessionImplTest: MakeSubOrDialogWindowDragableAndMoveble05 start"; sptr option = sptr::MakeSptr(); option->SetSubWindowDecorEnable(true); option->SetWindowName("MakeSubOrDialogWindowDragableAndMoveble05"); sptr window = sptr::MakeSptr(option); window->property_->SetWindowType(WindowType::WINDOW_TYPE_APP_SUB_WINDOW); window->windowSystemConfig_.windowUIType_ = WindowUIType::PC_WINDOW; EXPECT_EQ(false, window->property_->IsDecorEnable()); window->MakeSubOrDialogWindowDragableAndMoveble(); EXPECT_EQ(true, window->property_->IsDecorEnable()); window->property_->SetDecorEnable(false); sptr option1 = sptr::MakeSptr(); option->SetWindowName("MakeSubOrDialogWindowDragableAndMoveble05_mainWindow"); sptr mainWindow = sptr::MakeSptr(option1); mainWindow->property_->SetPersistentId(1); mainWindow->property_->SetWindowType(WindowType::WINDOW_TYPE_APP_MAIN_WINDOW); WindowSessionImpl::windowSessionMap_.clear(); WindowSessionImpl::windowSessionMap_.insert(std::make_pair(mainWindow->GetWindowName(), std::pair>(mainWindow->GetWindowId(), mainWindow))); window->MakeSubOrDialogWindowDragableAndMoveble(); EXPECT_EQ(true, window->property_->IsDecorEnable()); sptr compatibleModeProperty = sptr::MakeSptr(); compatibleModeProperty->SetIsAdaptToSubWindow(true); mainWindow->context_ = std::make_shared(); window->context_ = mainWindow->context_; window->property_->SetDecorEnable(false); window->MakeSubOrDialogWindowDragableAndMoveble(); EXPECT_EQ(false, window->property_->IsDecorEnable()); GTEST_LOG_(INFO) << "WindowSessionImplTest: MakeSubOrDialogWindowDragableAndMoveble05 end"; } /** * @tc.name: WindowSessionCreateCheck01 * @tc.desc: WindowSessionCreateCheck01 * @tc.type: FUNC */ HWTEST_F(WindowSessionImplTest, WindowSessionCreateCheck01, TestSize.Level1) { GTEST_LOG_(INFO) << "WindowSessionImplTest: WindowSessionCreateCheck01 start"; sptr option = sptr::MakeSptr(); option->SetWindowName("WindowSessionCreateCheck"); sptr window = new (std::nothrow) WindowSessionImpl(option); ASSERT_NE(nullptr, window); sptr option1 = sptr::MakeSptr(); option1->SetWindowName("WindowSessionCreateCheck"); // set the same name sptr window1 = new (std::nothrow) WindowSessionImpl(option1); ASSERT_NE(nullptr, window1); WMError res = window1->WindowSessionCreateCheck(); ASSERT_EQ(res, WMError::WM_OK); GTEST_LOG_(INFO) << "WindowSessionImplTest: WindowSessionCreateCheck01 end"; } /** * @tc.name: WindowSessionCreateCheck * @tc.desc: WindowSessionCreateCheck03 * @tc.type: FUNC */ HWTEST_F(WindowSessionImplTest, WindowSessionCreateCheck03, TestSize.Level1) { GTEST_LOG_(INFO) << "WindowSessionImplTest: WindowSessionCreateCheck03 start"; sptr option = sptr::MakeSptr(); std::string name = "WindowSessionCreateCheck03"; option->SetWindowName(name); sptr window = new (std::nothrow) WindowSessionImpl(option); ASSERT_NE(window, nullptr); window->windowSessionMap_[name] = std::pair>(1, window); WMError res = window->WindowSessionCreateCheck(); ASSERT_EQ(res, WMError::WM_ERROR_REPEAT_OPERATION); GTEST_LOG_(INFO) << "WindowSessionImplTest: WindowSessionCreateCheck03 end"; } /** * @tc.name: SetActive * @tc.desc: SetActive * @tc.type: FUNC */ HWTEST_F(WindowSessionImplTest, SetActive, TestSize.Level1) { GTEST_LOG_(INFO) << "WindowSessionImplTest: SetActive start"; sptr option = sptr::MakeSptr(); option->SetWindowName("WindowSessionCreateCheck"); sptr window = new (std::nothrow) WindowSessionImpl(option); ASSERT_NE(window, nullptr); WSError res1 = window->SetActive(true); ASSERT_EQ(res1, WSError::WS_OK); res1 = window->SetActive(false); ASSERT_EQ(res1, WSError::WS_OK); GTEST_LOG_(INFO) << "WindowSessionImplTest: SetActive end"; } /** * @tc.name: UpdateFocus * @tc.desc: UpdateFocus * @tc.type: FUNC */ HWTEST_F(WindowSessionImplTest, UpdateFocus, TestSize.Level1) { GTEST_LOG_(INFO) << "WindowSessionImplTest: UpdateFocus start"; sptr option = sptr::MakeSptr(); option->SetWindowName("WindowSessionCreateCheck"); sptr window = new (std::nothrow) WindowSessionImpl(option); ASSERT_NE(window, nullptr); WSError res = window->UpdateFocus(true); ASSERT_EQ(res, WSError::WS_OK); res = window->UpdateFocus(false); ASSERT_EQ(res, WSError::WS_OK); GTEST_LOG_(INFO) << "WindowSessionImplTest: UpdateFocus end"; } /** * @tc.name: RequestFocusByClient * @tc.desc: RequestFocusByClient Test * @tc.type: FUNC */ HWTEST_F(WindowSessionImplTest, RequestFocusByClient, TestSize.Level1) { GTEST_LOG_(INFO) << "WindowSessionImplTest: RequestFocusByClient start"; sptr option = sptr::MakeSptr(); option->SetWindowName("WindowRequestFocusByClientCheck"); sptr window = new (std::nothrow) WindowSessionImpl(option); ASSERT_NE(window, nullptr); WMError res = window->RequestFocusByClient(true); ASSERT_EQ(res, WMError::WM_ERROR_INVALID_WINDOW); res = window->RequestFocusByClient(false); ASSERT_EQ(res, WMError::WM_ERROR_INVALID_WINDOW); window->property_->SetPersistentId(1); SessionInfo sessionInfo = { "RequestFocusByClient", "RequestFocusByClient", "RequestFocusByClient" }; sptr session = sptr::MakeSptr(sessionInfo); ASSERT_NE(session, nullptr); window->hostSession_ = session; window->state_ = WindowState::STATE_INITIAL; res = window->RequestFocusByClient(true); ASSERT_EQ(res, WMError::WM_OK); res = window->RequestFocusByClient(false); ASSERT_EQ(res, WMError::WM_OK); GTEST_LOG_(INFO) << "WindowSessionImplTest: RequestFocusByClient end"; } /** * @tc.name: CreateWindowAndDestroy01 * @tc.desc: GetPersistentId * @tc.type: FUNC */ HWTEST_F(WindowSessionImplTest, GetPersistentId01, TestSize.Level1) { GTEST_LOG_(INFO) << "WindowSessionImplTest: GetPersistentId start"; sptr option = sptr::MakeSptr(); sptr window = sptr::MakeSptr(option); ASSERT_NE(window->property_, nullptr); window->property_->SetPersistentId(1); const int32_t res2 = window->GetPersistentId(); ASSERT_EQ(res2, 1); GTEST_LOG_(INFO) << "WindowSessionImplTest: GetPersistentId end"; } /** * @tc.name: GetFloatingWindowParentId * @tc.desc: GetFloatingWindowParentId and UpdateTitleButtonVisibility * @tc.type: FUNC */ HWTEST_F(WindowSessionImplTest, GetFloatingWindowParentId, TestSize.Level1) { GTEST_LOG_(INFO) << "WindowSessionImplTest: GetFloatingWindowParentId start"; sptr option = sptr::MakeSptr(); option->SetWindowName("Connect"); sptr window = new (std::nothrow) WindowSessionImpl(option); ASSERT_NE(nullptr, window); window->property_->SetPersistentId(1); // connect with null session ASSERT_EQ(WMError::WM_ERROR_NULLPTR, window->Connect()); SessionInfo sessionInfo = { "CreateTestBundle", "CreateTestModule", "CreateTestAbility" }; sptr session = new (std::nothrow) SessionMocker(sessionInfo); ASSERT_NE(nullptr, session); window->hostSession_ = session; EXPECT_CALL(*(session), Connect(_, _, _, _, _, _, _)).WillOnce(Return(WSError::WS_ERROR_NULLPTR)); ASSERT_EQ(WMError::WM_ERROR_NULLPTR, window->Connect()); EXPECT_CALL(*(session), Connect(_, _, _, _, _, _, _)).WillOnce(Return(WSError::WS_OK)); ASSERT_EQ(WMError::WM_OK, window->Connect()); window->UpdateTitleButtonVisibility(); int32_t res = window->GetFloatingWindowParentId(); ASSERT_EQ(res, INVALID_SESSION_ID); GTEST_LOG_(INFO) << "WindowSessionImplTest: GetFloatingWindowParentId start"; } /** * @tc.name: UpdateDecorEnable * @tc.desc: UpdateDecorEnable * @tc.type: FUNC */ HWTEST_F(WindowSessionImplTest, UpdateDecorEnable, TestSize.Level1) { GTEST_LOG_(INFO) << "WindowSessionImplTest: UpdateDecorEnable start"; sptr option = sptr::MakeSptr(); option->SetWindowName("UpdateDecorEnable"); sptr window = sptr::MakeSptr(option); WindowMode mode = WindowMode::WINDOW_MODE_UNDEFINED; window->UpdateDecorEnable(true, mode); ASSERT_EQ(window->property_->windowMode_, mode); mode = WindowMode::WINDOW_MODE_UNDEFINED; window->UpdateDecorEnable(false, mode); ASSERT_EQ(window->property_->windowMode_, mode); mode = WindowMode::WINDOW_MODE_FULLSCREEN; window->property_->compatibleModeProperty_->SetDisableDecorFullscreen(true); window->UpdateDecorEnable(false, mode); ASSERT_EQ(window->property_->windowMode_, mode); GTEST_LOG_(INFO) << "WindowSessionImplTest: UpdateDecorEnable end"; } /** * @tc.name: NotifyModeChange * @tc.desc: NotifyModeChange * @tc.type: FUNC */ HWTEST_F(WindowSessionImplTest, NotifyModeChange, TestSize.Level1) { GTEST_LOG_(INFO) << "WindowSessionImplTest: NotifyModeChange start"; sptr option = sptr::MakeSptr(); option->SetWindowName("NotifyModeChange"); sptr window = sptr::MakeSptr(option); SessionInfo sessionInfo = { "CreateTestBundle", "CreateTestModule", "CreateTestAbility" }; sptr session = sptr::MakeSptr(sessionInfo); window->hostSession_ = session; WindowMode mode = WindowMode::WINDOW_MODE_UNDEFINED; window->NotifyModeChange(mode, true); window->NotifyModeChange(mode, false); ASSERT_EQ(window->property_->windowMode_, mode); ASSERT_EQ(window->property_->isDecorEnable_, false); GTEST_LOG_(INFO) << "WindowSessionImplTest: NotifyModeChange end"; } /** * @tc.name: RequestVsyncSucc * @tc.desc: RequestVsync Test Succ * @tc.type: FUNC */ HWTEST_F(WindowSessionImplTest, RequestVsyncSucc, TestSize.Level1) { sptr option = sptr::MakeSptr(); option->SetWindowName("RequestVsyncSucc"); sptr window = new (std::nothrow) WindowSessionImpl(option); ASSERT_NE(window, nullptr); std::shared_ptr vsyncCallback = std::make_shared(); window->state_ = WindowState::STATE_SHOWN; ASSERT_EQ(WindowState::STATE_SHOWN, window->GetWindowState()); ASSERT_NE(window->vsyncStation_, nullptr); window->RequestVsync(vsyncCallback); window->vsyncStation_ = nullptr; window->RequestVsync(vsyncCallback); } /** * @tc.name: RequestVsyncErr * @tc.desc: RequestVsync Test Err * @tc.type: FUNC */ HWTEST_F(WindowSessionImplTest, RequestVsyncErr, TestSize.Level1) { sptr option = sptr::MakeSptr(); option->SetWindowName("RequestVsyncErr"); sptr window = new (std::nothrow) WindowSessionImpl(option); ASSERT_NE(window, nullptr); std::shared_ptr vsyncCallback = std::make_shared(); window->state_ = WindowState::STATE_DESTROYED; ASSERT_EQ(WindowState::STATE_DESTROYED, window->GetWindowState()); window->vsyncStation_ = nullptr; window->RequestVsync(vsyncCallback); } /** * @tc.name: ClearVsync * @tc.desc: Clear vsync test * @tc.type: FUNC */ HWTEST_F(WindowSessionImplTest, ClearVsync, TestSize.Level1) { sptr option = sptr::MakeSptr(); option->SetWindowName("ClearVsync"); sptr window = new (std::nothrow) WindowSessionImpl(option); ASSERT_NE(window, nullptr); window->ClearVsyncStation(); ASSERT_NE(window, nullptr); } /** * @tc.name: SetFocusable * @tc.desc: SetFocusable * @tc.type: FUNC */ HWTEST_F(WindowSessionImplTest, SetFocusable, TestSize.Level1) { GTEST_LOG_(INFO) << "WindowSessionImplTest: SetFocusable start"; sptr option = sptr::MakeSptr(); option->SetWindowName("SetFocusable"); sptr window = sptr::MakeSptr(option); SessionInfo sessionInfo = { "CreateTestBundle", "CreateTestModule", "CreateTestAbility" }; sptr session = new (std::nothrow) SessionMocker(sessionInfo); ASSERT_NE(nullptr, session); ASSERT_EQ(WMError::WM_OK, window->Create(nullptr, session)); window->hostSession_ = session; window->property_->SetPersistentId(1); ASSERT_FALSE(window->GetPersistentId() == INVALID_SESSION_ID); ASSERT_FALSE(window->IsWindowSessionInvalid()); WMError res = window->SetFocusable(true); ASSERT_EQ(res, WMError::WM_OK); ASSERT_EQ(WMError::WM_OK, window->Destroy()); // session is null window = sptr::MakeSptr(option); ASSERT_EQ(WMError::WM_OK, window->Create(abilityContext_, nullptr)); res = window->SetFocusable(true); ASSERT_EQ(res, WMError::WM_ERROR_INVALID_WINDOW); res = window->SetFocusable(false); ASSERT_EQ(res, WMError::WM_ERROR_INVALID_WINDOW); ASSERT_EQ(WMError::WM_ERROR_INVALID_WINDOW, window->Destroy()); GTEST_LOG_(INFO) << "WindowSessionImplTest: SetFocusable end"; } /** * @tc.name: SetTouchable * @tc.desc: SetTouchable * @tc.type: FUNC */ HWTEST_F(WindowSessionImplTest, SetTouchable, TestSize.Level1) { GTEST_LOG_(INFO) << "WindowSessionImplTest: SetTouchable start"; sptr option = sptr::MakeSptr(); option->SetWindowName("SetTouchable"); sptr window = sptr::MakeSptr(option); SessionInfo sessionInfo = { "CreateTestBundle", "CreateTestModule", "CreateTestAbility" }; sptr session = new (std::nothrow) SessionMocker(sessionInfo); ASSERT_NE(nullptr, session); ASSERT_EQ(WMError::WM_OK, window->Create(nullptr, session)); ASSERT_NE(window->property_, nullptr); window->hostSession_ = session; window->property_->SetPersistentId(1); ASSERT_FALSE(window->IsWindowSessionInvalid()); WMError res = window->SetTouchable(true); ASSERT_EQ(res, WMError::WM_OK); ASSERT_NE(window->property_, nullptr); ASSERT_TRUE(window->property_->touchable_); ASSERT_EQ(WMError::WM_OK, window->Destroy()); // session is null window = sptr::MakeSptr(option); ASSERT_EQ(WMError::WM_OK, window->Create(abilityContext_, nullptr)); res = window->SetTouchable(true); ASSERT_EQ(res, WMError::WM_ERROR_INVALID_WINDOW); res = window->SetTouchable(false); ASSERT_EQ(res, WMError::WM_ERROR_INVALID_WINDOW); ASSERT_EQ(WMError::WM_ERROR_INVALID_WINDOW, window->Destroy()); GTEST_LOG_(INFO) << "WindowSessionImplTest: SetTouchable end"; } /** * @tc.name: SetBrightness01 * @tc.desc: SetBrightness * @tc.type: FUNC */ HWTEST_F(WindowSessionImplTest, SetBrightness01, TestSize.Level1) { GTEST_LOG_(INFO) << "WindowSessionImplTest: SetBrightness01 start"; sptr option = sptr::MakeSptr(); option->SetWindowName("SetBrightness01"); sptr window = sptr::MakeSptr(option); SessionInfo sessionInfo = { "CreateTestBundle", "CreateTestModule", "CreateTestAbility" }; sptr session = new (std::nothrow) SessionMocker(sessionInfo); EXPECT_NE(nullptr, session); EXPECT_EQ(WMError::WM_OK, window->Create(nullptr, session)); EXPECT_NE(nullptr, window->property_); window->property_->SetPersistentId(1); float brightness = -0.5f; // brightness < 0 WMError res = window->SetBrightness(brightness); EXPECT_EQ(res, WMError::WM_ERROR_INVALID_PARAM); brightness = 2.0f; // brightness > 1 res = window->SetBrightness(brightness); EXPECT_EQ(res, WMError::WM_ERROR_INVALID_PARAM); brightness = 0.5f; window->hostSession_ = session; EXPECT_FALSE(window->IsWindowSessionInvalid()); res = window->SetBrightness(brightness); EXPECT_EQ(res, WMError::WM_OK); ASSERT_EQ(WMError::WM_OK, window->Destroy()); GTEST_LOG_(INFO) << "WindowSessionImplTest: SetBrightness01 end"; } /** * @tc.name: SetBrightness02 * @tc.desc: SetBrightness * @tc.type: FUNC */ HWTEST_F(WindowSessionImplTest, SetBrightness02, TestSize.Level1) { GTEST_LOG_(INFO) << "WindowSessionImplTest: SetBrightness02 start"; sptr option = sptr::MakeSptr(); option->SetWindowName("SetBrightness02"); sptr window = sptr::MakeSptr(option); SessionInfo sessionInfo = { "CreateTestBundle", "CreateTestModule", "CreateTestAbility" }; sptr session = new (std::nothrow) SessionMocker(sessionInfo); EXPECT_NE(nullptr, session); EXPECT_EQ(WMError::WM_OK, window->Create(nullptr, session)); window->hostSession_ = session; EXPECT_NE(nullptr, window->property_); window->property_->SetPersistentId(1); window->property_->SetWindowType(WindowType::APP_MAIN_WINDOW_END); float brightness = 0.5f; WMError res = window->SetBrightness(brightness); EXPECT_EQ(res, WMError::WM_ERROR_INVALID_TYPE); window->property_->SetWindowType(WindowType::APP_SUB_WINDOW_BASE); res = window->SetBrightness(brightness); EXPECT_EQ(res, WMError::WM_OK); window->property_->SetWindowType(WindowType::WINDOW_TYPE_WALLET_SWIPE_CARD); res = window->SetBrightness(brightness); EXPECT_EQ(res, WMError::WM_OK); ASSERT_EQ(WMError::WM_OK, window->Destroy()); GTEST_LOG_(INFO) << "WindowSessionImplTest: SetBrightness02 end"; } /** * @tc.name: GetContentInfo * @tc.desc: GetContentInfo * @tc.type: FUNC */ HWTEST_F(WindowSessionImplTest, GetContentInfo, TestSize.Level1) { GTEST_LOG_(INFO) << "WindowSessionImplTest: GetContentInfo start"; sptr option = sptr::MakeSptr(); option->SetWindowName("GetContentInfo"); sptr window = sptr::MakeSptr(option); SessionInfo sessionInfo = { "CreateTestBundle", "CreateTestModule", "CreateTestAbility" }; sptr session = new (std::nothrow) SessionMocker(sessionInfo); ASSERT_NE(nullptr, session); ASSERT_EQ(WMError::WM_OK, window->Create(nullptr, session)); std::string res = window->GetContentInfo(); ASSERT_EQ(res, ""); window->uiContent_ = nullptr; res = window->GetContentInfo(); ASSERT_EQ(res, ""); ASSERT_EQ(WMError::WM_ERROR_INVALID_WINDOW, window->Destroy()); GTEST_LOG_(INFO) << "WindowSessionImplTest: GetContentInfo end"; } /** * @tc.name: OnNewWant * @tc.desc: OnNewWant * @tc.type: FUNC */ HWTEST_F(WindowSessionImplTest, OnNewWant, TestSize.Level1) { GTEST_LOG_(INFO) << "WindowSessionImplTest: OnNewWant start"; sptr option = sptr::MakeSptr(); option->SetWindowName("OnNewWant"); sptr window = sptr::MakeSptr(option); SessionInfo sessionInfo = { "CreateTestBundle", "CreateTestModule", "CreateTestAbility" }; sptr session = new (std::nothrow) SessionMocker(sessionInfo); ASSERT_NE(nullptr, session); ASSERT_EQ(WMError::WM_OK, window->Create(nullptr, session)); AAFwk::Want want; window->uiContent_ = nullptr; window->OnNewWant(want); ASSERT_EQ(window->GetUIContentSharedPtr(), nullptr); window->uiContent_ = std::make_unique(); window->OnNewWant(want); ASSERT_NE(window->GetUIContentSharedPtr(), nullptr); ASSERT_EQ(WMError::WM_ERROR_INVALID_WINDOW, window->Destroy()); GTEST_LOG_(INFO) << "WindowSessionImplTest: OnNewWant end"; } /** * @tc.name: SetAPPWindowLabel * @tc.desc: SetAPPWindowLabel * @tc.type: FUNC */ HWTEST_F(WindowSessionImplTest, SetAPPWindowLabel, TestSize.Level1) { GTEST_LOG_(INFO) << "WindowSessionImplTest: SetAPPWindowLabel start"; sptr option = sptr::MakeSptr(); option->SetWindowName("SetAPPWindowLabel"); sptr window = sptr::MakeSptr(option); SessionInfo sessionInfo = { "CreateTestBundle", "CreateTestModule", "CreateTestAbility" }; sptr session = new (std::nothrow) SessionMocker(sessionInfo); ASSERT_NE(nullptr, session); ASSERT_EQ(WMError::WM_OK, window->Create(nullptr, session)); std::string label = "label"; window->uiContent_ = nullptr; WMError res = window->SetAPPWindowLabel(label); ASSERT_EQ(res, WMError::WM_ERROR_NULLPTR); window->uiContent_ = std::make_unique(); res = window->SetAPPWindowLabel(label); ASSERT_EQ(res, WMError::WM_OK); ASSERT_EQ(WMError::WM_ERROR_INVALID_WINDOW, window->Destroy()); GTEST_LOG_(INFO) << "WindowSessionImplTest: SetAPPWindowLabel end"; } /** * @tc.name: RegisterListener01 * @tc.desc: RegisterListener and UnregisterListener * @tc.type: FUNC */ HWTEST_F(WindowSessionImplTest, RegisterListener01, TestSize.Level1) { GTEST_LOG_(INFO) << "WindowSessionImplTest: RegisterListener01 start"; sptr option = sptr::MakeSptr(); option->SetWindowName("RegisterListener01"); sptr window = sptr::MakeSptr(option); SessionInfo sessionInfo = { "CreateTestBundle", "CreateTestModule", "CreateTestAbility" }; sptr session = new (std::nothrow) SessionMocker(sessionInfo); ASSERT_NE(nullptr, session); ASSERT_EQ(WMError::WM_OK, window->Create(nullptr, session)); window->hostSession_ = session; ASSERT_NE(window->property_, nullptr); window->property_->SetPersistentId(1); sptr listener = nullptr; WMError res = window->RegisterLifeCycleListener(listener); ASSERT_EQ(res, WMError::WM_ERROR_NULLPTR); res = window->UnregisterLifeCycleListener(listener); ASSERT_EQ(res, WMError::WM_ERROR_NULLPTR); sptr listener1 = nullptr; res = window->RegisterOccupiedAreaChangeListener(listener1); ASSERT_EQ(res, WMError::WM_ERROR_NULLPTR); res = window->UnregisterOccupiedAreaChangeListener(listener1); ASSERT_EQ(res, WMError::WM_ERROR_NULLPTR); sptr listener2 = nullptr; res = window->RegisterWindowChangeListener(listener2); ASSERT_EQ(res, WMError::WM_ERROR_NULLPTR); res = window->UnregisterWindowChangeListener(listener2); ASSERT_EQ(res, WMError::WM_ERROR_NULLPTR); sptr listener3 = nullptr; window->RegisterDialogDeathRecipientListener(listener3); window->UnregisterDialogDeathRecipientListener(listener3); sptr listener4 = nullptr; res = window->RegisterDialogTargetTouchListener(listener4); ASSERT_EQ(res, WMError::WM_ERROR_NULLPTR); res = window->UnregisterDialogTargetTouchListener(listener4); ASSERT_EQ(res, WMError::WM_ERROR_NULLPTR); sptr listener5 = nullptr; res = window->RegisterWindowStatusChangeListener(listener5); ASSERT_EQ(res, WMError::WM_ERROR_NULLPTR); res = window->UnregisterWindowStatusChangeListener(listener5); ASSERT_EQ(res, WMError::WM_ERROR_NULLPTR); sptr listener6 = nullptr; res = window->RegisterWindowCrossAxisListener(listener6); ASSERT_EQ(res, WMError::WM_ERROR_NULLPTR); res = window->UnregisterWindowCrossAxisListener(listener6); ASSERT_EQ(res, WMError::WM_ERROR_NULLPTR); ASSERT_EQ(WMError::WM_OK, window->Destroy()); GTEST_LOG_(INFO) << "WindowSessionImplTest: RegisterListener01 end"; } /** * @tc.name: RegisterListener02 * @tc.desc: RegisterListener and UnregisterListener * @tc.type: FUNC */ HWTEST_F(WindowSessionImplTest, RegisterListener02, TestSize.Level1) { GTEST_LOG_(INFO) << "WindowSessionImplTest: RegisterListener02 start"; sptr option = sptr::MakeSptr(); option->SetWindowName("RegisterListener02"); sptr window = sptr::MakeSptr(option); SessionInfo sessionInfo = { "CreateTestBundle", "CreateTestModule", "CreateTestAbility" }; sptr session = new (std::nothrow) SessionMocker(sessionInfo); ASSERT_NE(nullptr, session); ASSERT_EQ(WMError::WM_OK, window->Create(nullptr, session)); window->hostSession_ = session; ASSERT_NE(window->property_, nullptr); window->property_->SetPersistentId(1); sptr listener5 = nullptr; WMError res = window->RegisterScreenshotListener(listener5); ASSERT_EQ(res, WMError::WM_ERROR_NULLPTR); res = window->UnregisterScreenshotListener(listener5); ASSERT_EQ(res, WMError::WM_ERROR_NULLPTR); sptr listener6 = nullptr; res = window->RegisterAvoidAreaChangeListener(listener6); ASSERT_EQ(res, WMError::WM_ERROR_NULLPTR); res = window->UnregisterAvoidAreaChangeListener(listener6); ASSERT_EQ(res, WMError::WM_ERROR_NULLPTR); sptr listener7 = nullptr; res = window->RegisterTouchOutsideListener(listener7); ASSERT_EQ(res, WMError::WM_ERROR_NULLPTR); res = window->UnregisterTouchOutsideListener(listener7); ASSERT_EQ(res, WMError::WM_ERROR_NULLPTR); IWindowVisibilityListenerSptr listener8 = nullptr; res = window->RegisterWindowVisibilityChangeListener(listener8); ASSERT_EQ(res, WMError::WM_ERROR_NULLPTR); res = window->UnregisterWindowVisibilityChangeListener(listener8); ASSERT_EQ(res, WMError::WM_ERROR_NULLPTR); IDisplayIdChangeListenerSptr listener9 = nullptr; res = window->RegisterDisplayIdChangeListener(listener9); ASSERT_EQ(res, WMError::WM_ERROR_NULLPTR); res = window->UnregisterDisplayIdChangeListener(listener9); ASSERT_EQ(res, WMError::WM_ERROR_NULLPTR); sptr listener10 = nullptr; res = window->RegisterWindowTitleButtonRectChangeListener(listener10); ASSERT_EQ(res, WMError::WM_ERROR_NULLPTR); res = window->UnregisterWindowTitleButtonRectChangeListener(listener10); ASSERT_EQ(res, WMError::WM_ERROR_NULLPTR); ASSERT_EQ(WMError::WM_OK, window->Destroy()); GTEST_LOG_(INFO) << "WindowSessionImplTest: RegisterListener02 end"; } /** * @tc.name: RegisterListener03 * @tc.desc: RegisterListener and UnregisterListener * @tc.type: FUNC */ HWTEST_F(WindowSessionImplTest, RegisterListener03, TestSize.Level1) { GTEST_LOG_(INFO) << "WindowSessionImplTest: RegisterListener03 start"; sptr option = sptr::MakeSptr(); option->SetWindowName("RegisterListener03"); sptr window = sptr::MakeSptr(option); SessionInfo sessionInfo = { "CreateTestBundle", "CreateTestModule", "CreateTestAbility" }; sptr session = sptr::MakeSptr(sessionInfo); ASSERT_NE(nullptr, session); ASSERT_EQ(WMError::WM_OK, window->Create(nullptr, session)); window->hostSession_ = session; ASSERT_NE(window->property_, nullptr); window->property_->SetPersistentId(1); sptr listener6 = nullptr; WMError res = window->RegisterDisplayMoveListener(listener6); ASSERT_EQ(res, WMError::WM_ERROR_NULLPTR); res = window->UnregisterDisplayMoveListener(listener6); ASSERT_EQ(res, WMError::WM_ERROR_NULLPTR); sptr listener7 = nullptr; res = window->RegisterWindowRectChangeListener(listener7); ASSERT_EQ(res, WMError::WM_ERROR_NULLPTR); sptr listener10 = nullptr; res = window->RegisterSubWindowCloseListeners(listener10); ASSERT_EQ(res, WMError::WM_ERROR_NULLPTR); res = window->UnregisterSubWindowCloseListeners(listener10); ASSERT_EQ(res, WMError::WM_ERROR_NULLPTR); sptr listener11 = nullptr; res = window->RegisterSwitchFreeMultiWindowListener(listener11); ASSERT_EQ(res, WMError::WM_ERROR_NULLPTR); res = window->UnregisterSwitchFreeMultiWindowListener(listener11); ASSERT_EQ(res, WMError::WM_ERROR_NULLPTR); sptr listener12 = nullptr; res = window->RegisterMainWindowCloseListeners(listener12); EXPECT_EQ(res, WMError::WM_ERROR_NULLPTR); res = window->UnregisterMainWindowCloseListeners(listener12); EXPECT_EQ(res, WMError::WM_ERROR_NULLPTR); ISystemDensityChangeListenerSptr listener13 = nullptr; res = window->RegisterSystemDensityChangeListener(listener13); ASSERT_EQ(res, WMError::WM_ERROR_NULLPTR); res = window->UnregisterSystemDensityChangeListener(listener13); ASSERT_EQ(res, WMError::WM_ERROR_NULLPTR); EXPECT_EQ(WMError::WM_OK, window->Destroy()); GTEST_LOG_(INFO) << "WindowSessionImplTest: RegisterListener03 end"; } /** * @tc.name: RegisterListener04 * @tc.desc: RegisterListener and UnregisterListener * @tc.type: FUNC */ HWTEST_F(WindowSessionImplTest, RegisterListener04, TestSize.Level1) { GTEST_LOG_(INFO) << "WindowSessionImplTest: RegisterListener04 start"; sptr option = sptr::MakeSptr(); option->SetWindowName("RegisterListener04"); sptr window = sptr::MakeSptr(option); SessionInfo sessionInfo = { "CreateTestBundle", "CreateTestModule", "CreateTestAbility" }; sptr session = sptr::MakeSptr(sessionInfo); ASSERT_EQ(WMError::WM_OK, window->Create(nullptr, session)); window->hostSession_ = session; window->property_->SetPersistentId(1); sptr listener14 = nullptr; WMError res = window->RegisterWindowWillCloseListeners(listener14); ASSERT_EQ(res, WMError::WM_ERROR_NULLPTR); res = window->UnRegisterWindowWillCloseListeners(listener14); ASSERT_EQ(res, WMError::WM_ERROR_NULLPTR); EXPECT_EQ(WMError::WM_OK, window->Destroy()); GTEST_LOG_(INFO) << "WindowSessionImplTest: RegisterListener04 end"; } /** * @tc.name: RegisterListener05 * @tc.desc: RegisterListener and UnregisterListener * @tc.type: FUNC */ HWTEST_F(WindowSessionImplTest, RegisterListener05, TestSize.Level1) { GTEST_LOG_(INFO) << "WindowSessionImplTest: RegisterListener05 start"; sptr listenerOption = sptr::MakeSptr(); ASSERT_NE(nullptr, listenerOption); listenerOption->SetWindowName("RegisterListener05"); sptr listenerwindow = sptr::MakeSptr(listenerOption); SessionInfo sessionInfo = { "CreateTestBundle", "CreateTestModule", "CreateTestAbility" }; sptr session = sptr::MakeSptr(sessionInfo); EXPECT_EQ(WMError::WM_OK, listenerwindow->Create(nullptr, session)); listenerwindow->hostSession_ = session; ASSERT_NE(nullptr, listenerwindow->property_); listenerwindow->property_->SetPersistentId(1); sptr listener = nullptr; WMError res = listenerwindow->RegisterWindowStageLifeCycleListener(listener); EXPECT_EQ(res, WMError::WM_ERROR_NULLPTR); res = listenerwindow->UnregisterWindowStageLifeCycleListener(listener); EXPECT_EQ(res, WMError::WM_ERROR_NULLPTR); EXPECT_EQ(WMError::WM_OK, listenerwindow->Destroy()); GTEST_LOG_(INFO) << "WindowSessionImplTest: RegisterListener05 end"; } /** * @tc.name: NotifyDisplayMove * @tc.desc: NotifyDisplayMove * @tc.type: FUNC */ HWTEST_F(WindowSessionImplTest, NotifyDisplayMove, TestSize.Level1) { GTEST_LOG_(INFO) << "WindowSessionImplTest: NotifyDisplayMove start"; sptr option = sptr::MakeSptr(); option->SetWindowName("NotifyDisplayMove"); sptr window = sptr::MakeSptr(option); SessionInfo sessionInfo = { "CreateTestBundle", "CreateTestModule", "CreateTestAbility" }; sptr session = sptr::MakeSptr(sessionInfo); ASSERT_EQ(WMError::WM_OK, window->Create(nullptr, session)); DisplayId from = 0; DisplayId to = 2; window->NotifyDisplayMove(from, to); ASSERT_EQ(WMError::WM_ERROR_INVALID_WINDOW, window->Destroy()); GTEST_LOG_(INFO) << "WindowSessionImplTest: NotifyDisplayMove end"; } /** * @tc.name: NotifyAfterForeground * @tc.desc: NotifyAfterForeground * @tc.type: FUNC */ HWTEST_F(WindowSessionImplTest, NotifyAfterForeground, TestSize.Level1) { GTEST_LOG_(INFO) << "WindowSessionImplTest: NotifyAfterForeground start"; sptr option = sptr::MakeSptr(); option->SetWindowName("NotifyAfterForeground"); sptr window = sptr::MakeSptr(option); SessionInfo sessionInfo = { "CreateTestBundle", "CreateTestModule", "CreateTestAbility" }; sptr session = sptr::MakeSptr(sessionInfo); ASSERT_NE(nullptr, session); ASSERT_EQ(WMError::WM_OK, window->Create(nullptr, session)); window->NotifyAfterForeground(true, true); window->NotifyAfterForeground(false, false); window->vsyncStation_ = nullptr; window->NotifyAfterForeground(false, false); ASSERT_EQ(WMError::WM_ERROR_INVALID_WINDOW, window->Destroy()); GTEST_LOG_(INFO) << "WindowSessionImplTest: NotifyAfterForeground end"; } /** * @tc.name: NotifyAfterBackground * @tc.desc: NotifyAfterBackground * @tc.type: FUNC */ HWTEST_F(WindowSessionImplTest, NotifyAfterBackground, TestSize.Level1) { GTEST_LOG_(INFO) << "WindowSessionImplTest: NotifyAfterBackground start"; sptr option = sptr::MakeSptr(); option->SetWindowName("NotifyAfterBackground"); sptr window = sptr::MakeSptr(option); SessionInfo sessionInfo = { "CreateTestBundle", "CreateTestModule", "CreateTestAbility" }; sptr session = sptr::MakeSptr(sessionInfo); ASSERT_EQ(WMError::WM_OK, window->Create(nullptr, session)); window->NotifyAfterBackground(true, true); window->NotifyAfterBackground(false, false); window->vsyncStation_ = nullptr; window->NotifyAfterBackground(false, false); ASSERT_EQ(WMError::WM_ERROR_INVALID_WINDOW, window->Destroy()); GTEST_LOG_(INFO) << "WindowSessionImplTest: NotifyAfterBackground end"; } /** * @tc.name: NotifyForegroundInteractiveStatus * @tc.desc: NotifyForegroundInteractiveStatus * @tc.type: FUNC */ HWTEST_F(WindowSessionImplTest, NotifyForegroundInteractiveStatus, TestSize.Level1) { g_errLog.clear(); LOG_SetCallback(MyLogCallback); GTEST_LOG_(INFO) << "WindowSessionImplTest: NotifyForegroundInteractiveStatus start"; sptr option = new WindowOption(); ASSERT_NE(option, nullptr); option->SetWindowName("NotifyForegroundInteractiveStatus"); sptr foreWindow = sptr::MakeSptr(option);; ASSERT_NE(foreWindow, nullptr); SessionInfo sessionInfo = { "CreateTestBundle", "CreateTestModule", "CreateTestAbility" }; sptr session = new (std::nothrow) SessionMocker(sessionInfo); ASSERT_NE(session, nullptr); foreWindow->property_->SetPersistentId(1); foreWindow->hostSession_ = session; foreWindow->state_ = WindowState::STATE_SHOWN; EXPECT_FALSE(foreWindow->IsWindowSessionInvalid()); foreWindow->isDidForeground_ = false; foreWindow->NotifyForegroundInteractiveStatus(true); foreWindow->NotifyForegroundInteractiveStatus(false); EXPECT_TRUE(g_errLog.find("isDidForeground:") == std::string::npos); EXPECT_EQ(WMError::WM_OK, foreWindow->Destroy()); LOG_SetCallback(nullptr); GTEST_LOG_(INFO) << "WindowSessionImplTest: NotifyForegroundInteractiveStatus end"; } /** * @tc.name: NotifyForegroundInteractiveStatus01 * @tc.desc: NotifyForegroundInteractiveStatus01 * @tc.type: FUNC */ HWTEST_F(WindowSessionImplTest, NotifyForegroundInteractiveStatus01, TestSize.Level1) { g_errLog.clear(); LOG_SetCallback(MyLogCallback); GTEST_LOG_(INFO) << "WindowSessionImplTest: NotifyForegroundInteractiveStatus01 start"; sptr option = new WindowOption(); ASSERT_NE(option, nullptr); option->SetWindowName("NotifyForegroundInteractiveStatus01"); sptr foreWindow1 = new (std::nothrow) WindowSessionImpl(option); ASSERT_NE(foreWindow1, nullptr); SessionInfo sessionInfo = { "CreateTestBundle", "CreateTestModule", "CreateTestAbility" }; sptr session = new (std::nothrow) SessionMocker(sessionInfo); ASSERT_NE(session, nullptr); foreWindow1->property_->SetPersistentId(1); foreWindow1->hostSession_ = session; foreWindow1->state_ = WindowState::STATE_SHOWN; EXPECT_FALSE(foreWindow1->IsWindowSessionInvalid()); foreWindow1->isDidForeground_ = true; foreWindow1->NotifyForegroundInteractiveStatus(true); EXPECT_TRUE(g_errLog.find("isDidForeground:") == std::string::npos); ASSERT_NE(nullptr, foreWindow1->property_); foreWindow1->property_->SetPersistentId(1); foreWindow1->property_->SetUseControlState(true); foreWindow1->NotifyForegroundInteractiveStatus(false); foreWindow1->NotifyForegroundInteractiveStatus(true); EXPECT_TRUE(g_errLog.find("useControlState:") != std::string::npos); foreWindow1->property_->SetUseControlState(false); foreWindow1->NotifyForegroundInteractiveStatus(false); foreWindow1->NotifyForegroundInteractiveStatus(true); EXPECT_EQ(WMError::WM_OK, foreWindow1->Destroy()); LOG_SetCallback(nullptr); GTEST_LOG_(INFO) << "WindowSessionImplTest: NotifyForegroundInteractiveStatus01 end"; } /** * @tc.name: NotifyLifecyclePausedStatus * @tc.desc: NotifyLifecyclePausedStatus * @tc.type: FUNC */ HWTEST_F(WindowSessionImplTest, NotifyLifecyclePausedStatus, TestSize.Level1) { g_errLog.clear(); LOG_SetCallback(MyLogCallback); GTEST_LOG_(INFO) << "WindowSessionImplTest: NotifyLifecyclePausedStatus start"; sptr option = new WindowOption(); ASSERT_NE(nullptr, option); option->SetWindowName("NotifyLifecyclePausedStatus"); sptr window = new (std::nothrow) WindowSessionImpl(option); ASSERT_NE(nullptr, window); window->property_->SetPersistentId(1); window->state_ = WindowState::STATE_SHOWN; window->NotifyLifecyclePausedStatus(); window->state_ = WindowState::STATE_DESTROYED; window->NotifyLifecyclePausedStatus(); SessionInfo sessionInfo = { "CreateTestBundle", "CreateTestModule", "CreateTestAbility" }; sptr session = new (std::nothrow) SessionMocker(sessionInfo); ASSERT_NE(nullptr, session); window->hostSession_ = session; window->state_ = WindowState::STATE_SHOWN; EXPECT_FALSE(window->IsWindowSessionInvalid()); window->NotifyLifecyclePausedStatus(); window->state_ = WindowState::STATE_DESTROYED; window->NotifyLifecyclePausedStatus(); EXPECT_TRUE(g_errLog.find("isDidForeground:") == std::string::npos); EXPECT_EQ(WMError::WM_ERROR_INVALID_WINDOW, window->Destroy()); LOG_SetCallback(nullptr); GTEST_LOG_(INFO) << "WindowSessionImplTest: NotifyLifecyclePausedStatus end"; } /** * @tc.name: NotifyAfterLifecycleForeground * @tc.desc: NotifyAfterLifecycleForeground * @tc.type: FUNC */ HWTEST_F(WindowSessionImplTest, NotifyAfterLifecycleForeground, TestSize.Level1) { GTEST_LOG_(INFO) << "WindowSessionImplTest: NotifyAfterLifecycleForeground start"; sptr foreOption = sptr::MakeSptr(); ASSERT_NE(nullptr, foreOption); foreOption->SetWindowName("NotifyAfterLifecycleForeground"); sptr foreWindow = sptr::MakeSptr(foreOption); ASSERT_NE(nullptr, foreWindow); SessionInfo sessionInfo = { "CreateTestBundle", "CreateTestModule", "CreateTestAbility" }; sptr session = new (std::nothrow) SessionMocker(sessionInfo); ASSERT_NE(nullptr, session); EXPECT_EQ(WMError::WM_OK, foreWindow->Create(nullptr, session)); foreWindow->NotifyAfterLifecycleForeground(); EXPECT_EQ(WMError::WM_ERROR_INVALID_WINDOW, foreWindow->Destroy()); GTEST_LOG_(INFO) << "WindowSessionImplTest: NotifyAfterLifecycleForeground end"; } /** * @tc.name: NotifyAfterLifecycleBackground * @tc.desc: NotifyAfterLifecycleBackground * @tc.type: FUNC */ HWTEST_F(WindowSessionImplTest, NotifyAfterLifecycleBackground, TestSize.Level1) { GTEST_LOG_(INFO) << "WindowSessionImplTest: NotifyAfterLifecycleBackground start"; sptr backOption = sptr::MakeSptr(); ASSERT_NE(nullptr, backOption); backOption->SetWindowName("NotifyAfterLifecycleBackground"); sptr window = sptr::MakeSptr(backOption); SessionInfo sessionInfo = { "CreateTestBundle", "CreateTestModule", "CreateTestAbility" }; sptr session = new (std::nothrow) SessionMocker(sessionInfo); ASSERT_NE(nullptr, session); EXPECT_EQ(WMError::WM_OK, window->Create(nullptr, session)); window->NotifyAfterLifecycleBackground(); EXPECT_EQ(WMError::WM_ERROR_INVALID_WINDOW, window->Destroy()); GTEST_LOG_(INFO) << "WindowSessionImplTest: NotifyAfterLifecycleBackground end"; } /** * @tc.name: Notify03 * @tc.desc: NotifyCloseExistPipWindow NotifyAfterLifecycleResumed * @tc.type: FUNC */ HWTEST_F(WindowSessionImplTest, NotifyAfterLifecycleResumed, TestSize.Level1) { sptr notifyOption = sptr::MakeSptr(); ASSERT_NE(nullptr, notifyOption); notifyOption->SetWindowName("NotifyAfterLifecycleResumed"); sptr notifyWindow = sptr::MakeSptr(notifyOption); ASSERT_NE(nullptr, notifyWindow); SessionInfo sessionInfo = { "CreateTestBundle", "CreateTestModule", "CreateTestAbility" }; sptr session = sptr::MakeSptr(sessionInfo); EXPECT_EQ(WMError::WM_OK, notifyWindow->Create(nullptr, session)); notifyWindow->NotifyAfterLifecycleResumed(); EXPECT_EQ(false, notifyWindow->isInteractiveStateFlag_); notifyWindow->state_ = WindowState::STATE_CREATED; notifyWindow->isDidForeground_ = true; notifyWindow->NotifyAfterLifecycleResumed(); notifyWindow->state_ = WindowState::STATE_SHOWN; notifyWindow->isDidForeground_ = false; notifyWindow->NotifyAfterLifecycleResumed(); notifyWindow->state_ = WindowState::STATE_CREATED; notifyWindow->isDidForeground_ = false; notifyWindow->NotifyAfterLifecycleResumed(); notifyWindow->state_ = WindowState::STATE_SHOWN; notifyWindow->isDidForeground_ = true; notifyWindow->NotifyAfterLifecycleResumed(); EXPECT_EQ(true, notifyWindow->isInteractiveStateFlag_); notifyWindow->NotifyAfterLifecycleResumed(); ASSERT_NE(nullptr, notifyWindow->property_); notifyWindow->property_->SetPersistentId(1); notifyWindow->property_->SetUseControlState(true); notifyWindow->NotifyAfterLifecycleResumed(); WSError res = notifyWindow->NotifyCloseExistPipWindow(); EXPECT_EQ(res, WSError::WS_OK); EXPECT_EQ(WMError::WM_ERROR_INVALID_WINDOW, notifyWindow->Destroy()); } /** * @tc.name: Notify03 * @tc.desc: NotifyCloseExistPipWindow NotifyAfterLifecyclePaused * @tc.type: FUNC */ HWTEST_F(WindowSessionImplTest, NotifyAfterLifecyclePaused, TestSize.Level1) { sptr pauseOption = sptr::MakeSptr(); ASSERT_NE(nullptr, pauseOption); pauseOption->SetWindowName("NotifyAfterLifecyclePaused"); sptr pauseWindow = sptr::MakeSptr(pauseOption); ASSERT_NE(nullptr, pauseWindow); SessionInfo sessionInfo = { "CreateTestBundle", "CreateTestModule", "CreateTestAbility" }; sptr session = sptr::MakeSptr(sessionInfo); EXPECT_EQ(WMError::WM_OK, pauseWindow->Create(nullptr, session)); pauseWindow->NotifyAfterLifecycleResumed(); pauseWindow->NotifyAfterLifecyclePaused(); EXPECT_EQ(false, pauseWindow->isInteractiveStateFlag_); pauseWindow->NotifyAfterLifecyclePaused(); WSError res = pauseWindow->NotifyCloseExistPipWindow(); EXPECT_EQ(res, WSError::WS_OK); EXPECT_EQ(WMError::WM_ERROR_INVALID_WINDOW, pauseWindow->Destroy()); } /** * @tc.name: Notify04 * @tc.desc: NotifyAppUseControlStatus * @tc.type: FUNC */ HWTEST_F(WindowSessionImplTest, NotifyAppUseControlStatusWhenSetStateThenReturnOK, TestSize.Level1) { sptr appOption = sptr::MakeSptr(); ASSERT_NE(nullptr, appOption); appOption->SetWindowName("NotifyAppUseControlStatus"); sptr window = sptr::MakeSptr(appOption); ASSERT_NE(nullptr, window); SessionInfo sessionInfo = { "CreateTestBundle", "CreateTestModule", "CreateTestAbility" }; sptr session = sptr::MakeSptr(sessionInfo); EXPECT_EQ(WMError::WM_OK, window->Create(nullptr, session)); window->property_->SetPersistentId(1); window->hostSession_ = session; window->state_ = WindowState::STATE_HIDDEN; window->NotifyAppUseControlStatus(true); window->state_ = WindowState::STATE_SHOWN; window->NotifyAppUseControlStatus(true); EXPECT_FALSE(window->IsWindowSessionInvalid()); window->state_ = WindowState::STATE_HIDDEN; window->NotifyAppUseControlStatus(true); window->state_ = WindowState::STATE_SHOWN; window->NotifyAppUseControlStatus(true); window->NotifyAppUseControlStatus(false); WSError res = window->NotifyCloseExistPipWindow(); EXPECT_EQ(res, WSError::WS_OK); EXPECT_EQ(WMError::WS_OK, window->Destroy()); } /** * @tc.name: MarkProcessed * @tc.desc: MarkProcessed * @tc.type: FUNC */ HWTEST_F(WindowSessionImplTest, MarkProcessed, TestSize.Level1) { GTEST_LOG_(INFO) << "WindowSessionImplTest: MarkProcessed start"; sptr option = sptr::MakeSptr(); option->SetWindowName("MarkProcessed"); sptr window = sptr::MakeSptr(option); SessionInfo sessionInfo = { "CreateTestBundle", "CreateTestModule", "CreateTestAbility" }; sptr session = new (std::nothrow) SessionMocker(sessionInfo); ASSERT_NE(nullptr, session); ASSERT_EQ(WMError::WM_OK, window->Create(nullptr, session)); int32_t eventId = 1; window->state_ = WindowState::STATE_DESTROYED; window->hostSession_ = session; ASSERT_EQ(window->GetPersistentId(), INVALID_SESSION_ID); ASSERT_EQ(window->state_, WindowState::STATE_DESTROYED); WSError res = window->MarkProcessed(eventId); ASSERT_EQ(res, WSError::WS_DO_NOTHING); window->hostSession_ = nullptr; res = window->MarkProcessed(eventId); ASSERT_EQ(res, WSError::WS_DO_NOTHING); ASSERT_EQ(WMError::WM_ERROR_INVALID_WINDOW, window->Destroy()); GTEST_LOG_(INFO) << "WindowSessionImplTest: MarkProcessed end"; } /** * @tc.name: Notify01 * @tc.desc: NotifyDestroy NotifyTouchDialogTarget NotifyScreenshot * @tc.type: FUNC */ HWTEST_F(WindowSessionImplTest, Notify01, TestSize.Level1) { GTEST_LOG_(INFO) << "WindowSessionImplTest: Notify01 start"; sptr option = sptr::MakeSptr(); option->SetWindowName("Notify01"); sptr window = sptr::MakeSptr(option); SessionInfo sessionInfo = { "CreateTestBundle", "CreateTestModule", "CreateTestAbility" }; sptr session = new (std::nothrow) SessionMocker(sessionInfo); ASSERT_NE(nullptr, session); ASSERT_EQ(WMError::WM_OK, window->Create(nullptr, session)); window->NotifyTouchDialogTarget(); window->uiContent_ = nullptr; window->NotifyScreenshot(); window->uiContent_ = std::make_unique(); window->NotifyScreenshot(); WSError res = window->NotifyDestroy(); ASSERT_EQ(res, WSError::WS_OK); ASSERT_EQ(WMError::WM_ERROR_INVALID_WINDOW, window->Destroy()); GTEST_LOG_(INFO) << "WindowSessionImplTest: Notify01 end"; } /** * @tc.name: NotifyKeyEvent * @tc.desc: NotifyKeyEvent * @tc.type: FUNC */ HWTEST_F(WindowSessionImplTest, NotifyKeyEvent, TestSize.Level1) { GTEST_LOG_(INFO) << "WindowSessionImplTest: NotifyKeyEvent start"; sptr option = sptr::MakeSptr(); option->SetWindowName("NotifyKeyEvent"); sptr window = sptr::MakeSptr(option); SessionInfo sessionInfo = { "CreateTestBundle", "CreateTestModule", "CreateTestAbility" }; sptr session = sptr::MakeSptr(sessionInfo); ASSERT_EQ(WMError::WM_OK, window->Create(nullptr, session)); std::shared_ptr keyEvent = MMI::KeyEvent::Create(); bool isConsumed = false; bool notifyInputMethod = false; keyEvent->SetKeyCode(MMI::KeyEvent::KEYCODE_VIRTUAL_MULTITASK); window->NotifyKeyEvent(keyEvent, isConsumed, notifyInputMethod); keyEvent->SetKeyCode(MMI::KeyEvent::KEYCODE_BACK); window->NotifyKeyEvent(keyEvent, isConsumed, notifyInputMethod); notifyInputMethod = true; window->NotifyKeyEvent(keyEvent, isConsumed, notifyInputMethod); keyEvent = nullptr; window->NotifyKeyEvent(keyEvent, isConsumed, notifyInputMethod); ASSERT_EQ(WMError::WM_ERROR_INVALID_WINDOW, window->Destroy()); GTEST_LOG_(INFO) << "WindowSessionImplTest: NotifyKeyEvent end"; } /** * @tc.name: UpdateProperty01 * @tc.desc: UpdateProperty * @tc.type: FUNC */ HWTEST_F(WindowSessionImplTest, UpdateProperty01, TestSize.Level1) { GTEST_LOG_(INFO) << "WindowSessionImplTest: UpdateProperty01 start"; sptr option = sptr::MakeSptr(); option->SetWindowName("UpdateProperty01"); sptr window = sptr::MakeSptr(option); SessionInfo sessionInfo = { "CreateTestBundle", "CreateTestModule", "CreateTestAbility" }; sptr session = sptr::MakeSptr(sessionInfo); ASSERT_EQ(WMError::WM_OK, window->Create(nullptr, session)); ASSERT_NE(nullptr, window->property_); window->property_->SetPersistentId(1); WMError res = window->UpdateProperty(WSPropertyChangeAction::ACTION_UPDATE_RECT); ASSERT_EQ(res, WMError::WM_ERROR_INVALID_WINDOW); ASSERT_EQ(WMError::WM_ERROR_INVALID_WINDOW, window->Destroy()); } /** * @tc.name: UpdateProperty02 * @tc.desc: UpdateProperty * @tc.type: FUNC */ HWTEST_F(WindowSessionImplTest, UpdateProperty02, TestSize.Level1) { GTEST_LOG_(INFO) << "WindowSessionImplTest: UpdateProperty02 start"; sptr option = sptr::MakeSptr(); option->SetWindowName("UpdateProperty02"); // session is null sptr window = sptr::MakeSptr(option); ASSERT_EQ(WMError::WM_OK, window->Create(abilityContext_, nullptr)); WMError res = window->UpdateProperty(WSPropertyChangeAction::ACTION_UPDATE_RECT); ASSERT_EQ(res, WMError::WM_ERROR_INVALID_WINDOW); ASSERT_EQ(WMError::WM_ERROR_INVALID_WINDOW, window->Destroy()); GTEST_LOG_(INFO) << "WindowSessionImplTest: UpdateProperty02 end"; } /** * @tc.name: Find * @tc.desc: Find * @tc.type: FUNC */ HWTEST_F(WindowSessionImplTest, Find, TestSize.Level1) { GTEST_LOG_(INFO) << "WindowSessionImplTest: Find start"; sptr option = sptr::MakeSptr(); option->SetWindowName("Find"); sptr window = sptr::MakeSptr(option); SessionInfo sessionInfo = { "CreateTestBundle", "CreateTestModule", "CreateTestAbility" }; sptr session = new (std::nothrow) SessionMocker(sessionInfo); ASSERT_NE(nullptr, session); ASSERT_EQ(WMError::WM_OK, window->Create(nullptr, session)); std::string name = "Find"; sptr res = window->Find(name); ASSERT_EQ(res, nullptr); name = "111"; res = window->Find(name); ASSERT_EQ(res, nullptr); ASSERT_EQ(WMError::WM_ERROR_INVALID_WINDOW, window->Destroy()); GTEST_LOG_(INFO) << "WindowSessionImplTest: Find end"; } /** * @tc.name: SetBackgroundColor01 * @tc.desc: SetBackgroundColor string * @tc.type: FUNC */ HWTEST_F(WindowSessionImplTest, SetBackgroundColor01, TestSize.Level1) { GTEST_LOG_(INFO) << "WindowSessionImplTest: SetBackgroundColor01 start"; sptr option = sptr::MakeSptr(); option->SetWindowName("SetBackgroundColor01"); sptr window = sptr::MakeSptr(option); SessionInfo sessionInfo = { "CreateTestBundle", "CreateTestModule", "CreateTestAbility" }; sptr session = new (std::nothrow) SessionMocker(sessionInfo); ASSERT_NE(nullptr, session); ASSERT_EQ(WMError::WM_OK, window->Create(abilityContext_, session)); std::string color = "Blue"; WMError res = window->SetBackgroundColor(color); ASSERT_EQ(res, WMError::WM_ERROR_INVALID_WINDOW); color = "111"; res = window->SetBackgroundColor(color); ASSERT_EQ(res, WMError::WM_ERROR_INVALID_WINDOW); ASSERT_EQ(WMError::WM_ERROR_INVALID_WINDOW, window->Destroy()); // session is null window = new WindowSessionImpl(option); ASSERT_EQ(WMError::WM_OK, window->Create(abilityContext_, nullptr)); res = window->SetBackgroundColor(color); ASSERT_EQ(res, WMError::WM_ERROR_INVALID_WINDOW); ASSERT_EQ(WMError::WM_ERROR_INVALID_WINDOW, window->Destroy()); GTEST_LOG_(INFO) << "WindowSessionImplTest: SetBackgroundColor01 end"; } /** * @tc.name: SetBackgroundColor02 * @tc.desc: SetBackgroundColor(uint32_t) and GetBackgroundColor * @tc.type: FUNC */ HWTEST_F(WindowSessionImplTest, SetBackgroundColor02, TestSize.Level1) { GTEST_LOG_(INFO) << "WindowSessionImplTest: SetBackgroundColor02 start"; sptr option = sptr::MakeSptr(); option->SetWindowName("SetBackgroundColor02"); sptr window = sptr::MakeSptr(option); SessionInfo sessionInfo = { "CreateTestBundle", "CreateTestModule", "CreateTestAbility" }; sptr session = new (std::nothrow) SessionMocker(sessionInfo); ASSERT_NE(nullptr, session); ASSERT_EQ(WMError::WM_OK, window->Create(nullptr, session)); WMError res = window->SetBackgroundColor(0xffffffff); ASSERT_EQ(res, WMError::WM_ERROR_INVALID_OPERATION); uint32_t ret = window->GetBackgroundColor(); ASSERT_EQ(ret, 0xffffffff); ASSERT_EQ(WMError::WM_ERROR_INVALID_WINDOW, window->Destroy()); GTEST_LOG_(INFO) << "WindowSessionImplTest: SetBackgroundColor02 end"; } /** * @tc.name: SetAPPWindowIcon * @tc.desc: SetAPPWindowIcon * @tc.type: FUNC */ HWTEST_F(WindowSessionImplTest, SetAPPWindowIcon, TestSize.Level1) { GTEST_LOG_(INFO) << "WindowSessionImplTest: SetAPPWindowIcon start"; sptr option = sptr::MakeSptr(); option->SetWindowName("SetAPPWindowIcon"); sptr window = sptr::MakeSptr(option); SessionInfo sessionInfo = { "CreateTestBundle", "CreateTestModule", "CreateTestAbility" }; sptr session = new (std::nothrow) SessionMocker(sessionInfo); ASSERT_NE(nullptr, session); ASSERT_EQ(WMError::WM_OK, window->Create(nullptr, session)); std::shared_ptr icon1(nullptr); WMError res = window->SetAPPWindowIcon(icon1); ASSERT_EQ(res, WMError::WM_ERROR_NULLPTR); std::shared_ptr icon2 = std::shared_ptr(); res = window->SetAPPWindowIcon(icon2); ASSERT_EQ(res, WMError::WM_ERROR_NULLPTR); Media::InitializationOptions opts; opts.size.width = 200; // 200 test width opts.size.height = 300; // 300 test height opts.pixelFormat = Media::PixelFormat::ARGB_8888; opts.alphaType = Media::AlphaType::IMAGE_ALPHA_TYPE_OPAQUE; std::unique_ptr pixelMapPtr = Media::PixelMap::Create(opts); ASSERT_NE(pixelMapPtr.get(), nullptr); window->uiContent_ = std::make_unique(); res = window->SetAPPWindowIcon(std::shared_ptr(pixelMapPtr.release())); ASSERT_EQ(res, WMError::WM_OK); ASSERT_NE(window->GetUIContentSharedPtr(), nullptr); ASSERT_EQ(WMError::WM_ERROR_INVALID_WINDOW, window->Destroy()); GTEST_LOG_(INFO) << "WindowSessionImplTest: SetAPPWindowIcon end"; } /** * @tc.name: Notify02 * @tc.desc: NotifyAvoidAreaChange NotifyPointerEvent NotifyTouchOutside NotifyWindowVisibility * @tc.type: FUNC */ HWTEST_F(WindowSessionImplTest, Notify02, TestSize.Level1) { GTEST_LOG_(INFO) << "WindowSessionImplTest: Notify02 start"; sptr option = sptr::MakeSptr(); option->SetWindowName("Notify02"); sptr window = sptr::MakeSptr(option); SessionInfo sessionInfo = { "CreateTestBundle", "CreateTestModule", "CreateTestAbility" }; sptr session = sptr::MakeSptr(sessionInfo); ASSERT_EQ(WMError::WM_OK, window->Create(nullptr, session)); sptr avoidArea = new AvoidArea(); avoidArea->topRect_ = { 1, 0, 0, 0 }; avoidArea->leftRect_ = { 0, 1, 0, 0 }; avoidArea->rightRect_ = { 0, 0, 1, 0 }; avoidArea->bottomRect_ = { 0, 0, 0, 1 }; AvoidAreaType type = AvoidAreaType::TYPE_SYSTEM; window->NotifyAvoidAreaChange(avoidArea, type); std::shared_ptr pointerEvent = MMI::PointerEvent::Create(); window->NotifyPointerEvent(pointerEvent); WSError res = window->NotifyTouchOutside(); ASSERT_EQ(res, WSError::WS_OK); res = window->NotifyWindowVisibility(true); ASSERT_EQ(res, WSError::WS_OK); bool terminateCloseProcess = false; window->NotifySubWindowClose(terminateCloseProcess); bool enable = false; window->NotifySwitchFreeMultiWindow(enable); ASSERT_EQ(WMError::WM_ERROR_INVALID_WINDOW, window->Destroy()); GTEST_LOG_(INFO) << "WindowSessionImplTest: Notify02 end"; } /** * @tc.name: SetAceAbilityHandler * @tc.desc: SetAceAbilityHandler * @tc.type: FUNC */ HWTEST_F(WindowSessionImplTest, SetAceAbilityHandler, TestSize.Level1) { GTEST_LOG_(INFO) << "WindowSessionImplTest: SetAceAbilityHandler start"; sptr option = sptr::MakeSptr(); option->SetWindowName("SetAceAbilityHandler"); sptr window = sptr::MakeSptr(option); SessionInfo sessionInfo = { "CreateTestBundle", "CreateTestModule", "CreateTestAbility" }; sptr session = sptr::MakeSptr(sessionInfo); ASSERT_EQ(WMError::WM_OK, window->Create(nullptr, session)); sptr handler = sptr(); ASSERT_EQ(handler, nullptr); GTEST_LOG_(INFO) << "WindowSessionImplTest: SetAceAbilityHandler 111"; window->SetAceAbilityHandler(handler); ASSERT_EQ(WMError::WM_ERROR_INVALID_WINDOW, window->Destroy()); GTEST_LOG_(INFO) << "WindowSessionImplTest: SetAceAbilityHandler end"; } /** * @tc.name: SetRaiseByClickEnabled01 * @tc.desc: SetRaiseByClickEnabled and check the retCode * @tc.type: FUNC */ HWTEST_F(WindowSessionImplTest, SetRaiseByClickEnabled01, TestSize.Level1) { sptr option = sptr::MakeSptr(); option->SetWindowName("SetRaiseByClickEnabled01"); option->SetWindowType(WindowType::WINDOW_TYPE_APP_MAIN_WINDOW); sptr window = new (std::nothrow) WindowSessionImpl(option); ASSERT_NE(nullptr, window); WMError retCode = window->SetRaiseByClickEnabled(true); ASSERT_EQ(retCode, WMError::WM_ERROR_INVALID_PARENT); option->SetWindowName("SetRaiseByClickForFloatWindow"); option->SetWindowType(WindowType::WINDOW_TYPE_FLOAT); sptr floatWindow = new (std::nothrow) WindowSessionImpl(option); floatWindow->property_->SetParentPersistentId(1); retCode = floatWindow->SetRaiseByClickEnabled(true); ASSERT_EQ(retCode, WMError::WM_ERROR_INVALID_CALLING); option->SetWindowName("SetRaiseByClickForSubWindow"); option->SetWindowType(WindowType::WINDOW_TYPE_APP_SUB_WINDOW); sptr subWindow = new (std::nothrow) WindowSessionImpl(option); ASSERT_NE(nullptr, subWindow); subWindow->property_->SetParentPersistentId(1); subWindow->Hide(); retCode = subWindow->SetRaiseByClickEnabled(true); ASSERT_EQ(retCode, WMError::WM_DO_NOTHING); subWindow->state_ = WindowState::STATE_SHOWN; retCode = subWindow->SetRaiseByClickEnabled(true); ASSERT_EQ(retCode, WMError::WM_ERROR_INVALID_WINDOW); subWindow->property_->SetParentPersistentId(2); subWindow->SetRaiseByClickEnabled(true); ASSERT_EQ(subWindow->property_->GetRaiseEnabled(), true); } /** * @tc.name: HideNonSystemFloatingWindows01 * @tc.desc: HideNonSystemFloatingWindows and check the retCode * @tc.type: FUNC */ HWTEST_F(WindowSessionImplTest, HideNonSystemFloatingWindows01, TestSize.Level1) { sptr option = sptr::MakeSptr(); option->SetWindowName("HideNonSystemFloatingWindows01"); sptr window = new (std::nothrow) WindowSessionImpl(option); ASSERT_NE(nullptr, window); WMError retCode = window->HideNonSystemFloatingWindows(false); ASSERT_EQ(retCode, WMError::WM_ERROR_INVALID_WINDOW); window->property_->SetPersistentId(1); SessionInfo sessionInfo = { "CreateTestBundle", "CreateTestModule", "CreateTestAbility" }; sptr session = new (std::nothrow) SessionMocker(sessionInfo); ASSERT_NE(nullptr, session); window->hostSession_ = session; window->state_ = WindowState::STATE_CREATED; window->HideNonSystemFloatingWindows(false); } /** * @tc.name: UpdateWindowModetest01 * @tc.desc: UpdateWindowMode * @tc.type: FUNC */ HWTEST_F(WindowSessionImplTest, UpdateWindowMode, TestSize.Level1) { GTEST_LOG_(INFO) << "WindowSessionImplTest: UpdateWindowModetest01 start"; sptr option = sptr::MakeSptr(); ASSERT_NE(option, nullptr); option->SetWindowName("UpdateWindowMode"); sptr window = new (std::nothrow) WindowSessionImpl(option); ASSERT_NE(window, nullptr); WindowMode mode = WindowMode{ 0 }; auto ret = window->UpdateWindowMode(mode); ASSERT_EQ(ret, WSError::WS_OK); GTEST_LOG_(INFO) << "WindowSessionImplTest: UpdateWindowModetest01 end"; } /** * @tc.name: UpdateDensitytest01 * @tc.desc: UpdateDensity * @tc.type: FUNC */ HWTEST_F(WindowSessionImplTest, UpdateDensity, TestSize.Level1) { GTEST_LOG_(INFO) << "WindowSessionImplTest: UpdateDensitytest01 start"; sptr option = sptr::MakeSptr(); option->SetWindowName("UpdateDensity"); sptr window = new (std::nothrow) WindowSessionImpl(option); ASSERT_NE(window, nullptr); ASSERT_NE(window->property_, nullptr); Rect rect1; rect1.posX_ = 1; rect1.posY_ = 2; rect1.height_ = 3; rect1.width_ = 4; window->property_->SetWindowRect(rect1); auto rect2 = window->GetRect(); ASSERT_EQ(1, rect2.posX_); ASSERT_EQ(2, rect2.posY_); ASSERT_EQ(3, rect2.height_); ASSERT_EQ(4, rect2.width_); window->UpdateDensity(); GTEST_LOG_(INFO) << "WindowSessionImplTest: UpdateDensitytest01 end"; } /** * @tc.name: UpdateDisplayIdtest01 * @tc.desc: UpdateDisplayId * @tc.type: FUNC */ HWTEST_F(WindowSessionImplTest, UpdateDisplayId, TestSize.Level1) { GTEST_LOG_(INFO) << "WindowSessionImplTest: UpdateDisplayIdtest01 start"; sptr option = sptr::MakeSptr(); option->SetWindowName("UpdateDisplayId"); sptr window = new (std::nothrow) WindowSessionImpl(option); ASSERT_NE(window, nullptr); uint64_t newDisplayId = 2; auto ret = window->UpdateDisplayId(newDisplayId); ASSERT_EQ(ret, WSError::WS_OK); uint64_t displayId = window->property_->GetDisplayId(); ASSERT_EQ(newDisplayId, displayId); GTEST_LOG_(INFO) << "WindowSessionImplTest: UpdateDisplayIdtest01 end"; } /** * @tc.name: IsFloatingWindowAppTypetest01 * @tc.desc: IsFloatingWindowAppType * @tc.type: FUNC */ HWTEST_F(WindowSessionImplTest, IsFloatingWindowAppType, TestSize.Level1) { GTEST_LOG_(INFO) << "WindowSessionImplTest: IsFloatingWindowAppTypetest01 start"; sptr option = sptr::MakeSptr(); option->SetWindowName("IsFloatingWindowAppType"); sptr window = new (std::nothrow) WindowSessionImpl(option); ASSERT_NE(window, nullptr); window->IsFloatingWindowAppType(); ASSERT_NE(window, nullptr); GTEST_LOG_(INFO) << "WindowSessionImplTest: IsFloatingWindowAppTypetest01 end"; } /** * @tc.name: SetUniqueVirtualPixelRatio * @tc.desc: SetUniqueVirtualPixelRatio * @tc.type: FUNC */ HWTEST_F(WindowSessionImplTest, SetUniqueVirtualPixelRatio, TestSize.Level1) { sptr option = new (std::nothrow) WindowOption(); ASSERT_NE(option, nullptr); option->SetWindowName("SetUniqueVirtualPixelRatio"); sptr window = new (std::nothrow) WindowSessionImpl(option); ASSERT_NE(window, nullptr); window->SetUniqueVirtualPixelRatio(true, 3.25f); window->SetUniqueVirtualPixelRatio(false, 3.25f); } /** * @tc.name: EnableDrag * @tc.desc: EnableDrag Test * @tc.type: FUNC */ HWTEST_F(WindowSessionImplTest, EnableDrag, TestSize.Level1) { sptr option = sptr::MakeSptr(); option->SetWindowName("EnableDrag"); sptr window = sptr::MakeSptr(option); window->property_->SetPersistentId(2101); window->property_->SetWindowType(WindowType::WINDOW_TYPE_GLOBAL_SEARCH); SessionInfo sessionInfo = { "CreateTestBundle", "CreateTestModule", "CreateTestAbility" }; sptr session = sptr::MakeSptr(sessionInfo); window->hostSession_ = session; window->windowSystemConfig_.windowUIType_ = WindowUIType::INVALID_WINDOW; auto result = window->EnableDrag(true); ASSERT_EQ(result, WMError::WM_ERROR_DEVICE_NOT_SUPPORT); window->windowSystemConfig_.windowUIType_ = WindowUIType::PHONE_WINDOW; window->property_->type_ = WindowType::WINDOW_TYPE_APP_MAIN_WINDOW; result = window->EnableDrag(true); ASSERT_EQ(result, WMError::WM_ERROR_INVALID_CALLING); window->windowSystemConfig_.windowUIType_ = WindowUIType::PC_WINDOW; window->property_->type_ = WindowType::WINDOW_TYPE_APP_SUB_WINDOW; result = window->EnableDrag(true); ASSERT_NE(result, WMError::WM_ERROR_DEVICE_NOT_SUPPORT); } /** * @tc.name: AddSetUIContentTimeoutCheck * @tc.desc: AddSetUIContentTimeoutCheck * @tc.type: FUNC */ HWTEST_F(WindowSessionImplTest, AddSetUIContentTimeoutCheck_test, TestSize.Level1) { sptr option = new (std::nothrow) WindowOption(); ASSERT_NE(option, nullptr); sptr window = new (std::nothrow) WindowSessionImpl(option); ASSERT_NE(window, nullptr); window->handler_ = nullptr; option->SetWindowName("AddSetUIContentTimeoutCheck_test"); option->SetBundleName("UTtest"); WindowType type1 = WindowType::APP_MAIN_WINDOW_BASE; option->SetWindowType(type1); sptr window1 = new (std::nothrow) WindowSessionImpl(option); ASSERT_NE(window1, nullptr); window1->AddSetUIContentTimeoutCheck(); WindowType type2 = WindowType::WINDOW_TYPE_UI_EXTENSION; option->SetWindowType(type2); sptr window2 = new (std::nothrow) WindowSessionImpl(option); ASSERT_NE(window2, nullptr); window2->AddSetUIContentTimeoutCheck(); EXPECT_EQ(WindowType::WINDOW_TYPE_UI_EXTENSION, window2->property_->GetWindowType()); } /** * @tc.name: FindMainWindowWithContext01 * @tc.desc: FindMainWindowWithContext * @tc.type: FUNC */ HWTEST_F(WindowSessionImplTest, FindMainWindowWithContext01, TestSize.Level1) { sptr option = new (std::nothrow) WindowOption(); option->SetWindowTag(WindowTag::MAIN_WINDOW); option->SetWindowName("FindMainWindowWithContext01"); sptr windowSession = new (std::nothrow) WindowSessionImpl(option); ASSERT_NE(nullptr, windowSession); windowSession->SetWindowType(WindowType::WINDOW_TYPE_DIALOG); ASSERT_TRUE(windowSession->FindMainWindowWithContext() == nullptr); windowSession->SetWindowType(WindowType::ABOVE_APP_SYSTEM_WINDOW_END); ASSERT_TRUE(windowSession->FindMainWindowWithContext() == nullptr); windowSession->property_->SetPersistentId(1002); windowSession->property_->SetWindowType(WindowType::WINDOW_TYPE_APP_MAIN_WINDOW); SessionInfo sessionInfo = { "CreateTestBundle", "CreateTestModule", "CreateTestAbility" }; sptr session = new (std::nothrow) SessionMocker(sessionInfo); ASSERT_NE(nullptr, session); ASSERT_EQ(WMError::WM_OK, windowSession->Create(abilityContext_, session)); windowSession->Destroy(true); } /** * @tc.name: FindExtensionWindowWithContext01 * @tc.desc: FindExtensionWindowWithContext * @tc.type: FUNC */ HWTEST_F(WindowSessionImplTest, FindExtensionWindowWithContext01, TestSize.Level1) { sptr option = sptr::MakeSptr(); option->SetWindowName("FindExtensionWindowWithContext01"); sptr windowSession = sptr::MakeSptr(option); ASSERT_TRUE(windowSession->FindExtensionWindowWithContext() == nullptr); windowSession->property_->SetPersistentId(12345); windowSession->property_->SetWindowType(WindowType::WINDOW_TYPE_UI_EXTENSION); windowSession->context_ = abilityContext_; WindowSessionImpl::GetWindowExtensionSessionSet().insert(windowSession); ASSERT_TRUE(nullptr != windowSession->FindExtensionWindowWithContext()); windowSession->Destroy(true); } /** * @tc.name: SetUIContentComplete * @tc.desc: SetUIContentComplete * @tc.type: FUNC */ HWTEST_F(WindowSessionImplTest, SetUIContentComplete, TestSize.Level1) { sptr option = new (std::nothrow) WindowOption(); ASSERT_NE(option, nullptr); sptr window = new (std::nothrow) WindowSessionImpl(option); ASSERT_NE(window, nullptr); window->SetUIContentComplete(); EXPECT_EQ(window->setUIContentCompleted_.load(), true); window->SetUIContentComplete(); EXPECT_EQ(window->setUIContentCompleted_.load(), true); } /** * @tc.name: NotifySetUIContentComplete * @tc.desc: NotifySetUIContentComplete * @tc.type: FUNC */ HWTEST_F(WindowSessionImplTest, NotifySetUIContentComplete, TestSize.Level1) { sptr option = new (std::nothrow) WindowOption(); ASSERT_NE(nullptr, option); option->SetWindowName("NotifySetUIContent"); option->SetWindowType(WindowType::APP_MAIN_WINDOW_BASE); sptr window = new (std::nothrow) WindowSessionImpl(option); ASSERT_NE(nullptr, window); window->NotifySetUIContentComplete(); EXPECT_EQ(window->setUIContentCompleted_.load(), true); option->SetWindowType(WindowType::APP_SUB_WINDOW_BASE); window = new (std::nothrow) WindowSessionImpl(option); ASSERT_NE(nullptr, window); window->NotifySetUIContentComplete(); EXPECT_EQ(window->setUIContentCompleted_.load(), true); option->SetWindowType(WindowType::SYSTEM_WINDOW_BASE); window = new (std::nothrow) WindowSessionImpl(option); ASSERT_NE(nullptr, window); window->NotifySetUIContentComplete(); EXPECT_EQ(window->setUIContentCompleted_.load(), true); } /** * @tc.name: SetUIExtensionDestroyComplete * @tc.desc: SetUIExtensionDestroyComplete * @tc.type: FUNC */ HWTEST_F(WindowSessionImplTest, SetUIExtensionDestroyComplete, TestSize.Level1) { sptr option = sptr::MakeSptr(); sptr window = sptr::MakeSptr(option); window->SetUIExtensionDestroyComplete(); EXPECT_EQ(window->setUIExtensionDestroyCompleted_.load(), true); window->SetUIExtensionDestroyComplete(); EXPECT_EQ(window->setUIExtensionDestroyCompleted_.load(), true); } /** * @tc.name: SetUIExtensionDestroyCompleteInSubWindow * @tc.desc: SetUIExtensionDestroyCompleteInSubWindow * @tc.type: FUNC */ HWTEST_F(WindowSessionImplTest, SetUIExtensionDestroyCompleteInSubWindow, TestSize.Level1) { sptr subWindowOption = sptr::MakeSptr(); subWindowOption->SetWindowName("subWindow"); sptr subWindowSession = sptr::MakeSptr(subWindowOption); subWindowSession->property_->SetWindowType(WindowType::WINDOW_TYPE_APP_SUB_WINDOW); subWindowSession->context_ = abilityContext_; subWindowSession->SetUIExtensionDestroyCompleteInSubWindow(); sptr option = sptr::MakeSptr(); option->SetWindowName("SetUIExtensionDestroyCompleteInSubWindow"); sptr windowSession = sptr::MakeSptr(option); ASSERT_TRUE(windowSession->FindExtensionWindowWithContext() == nullptr); windowSession->property_->SetPersistentId(12345); windowSession->property_->SetWindowType(WindowType::WINDOW_TYPE_UI_EXTENSION); windowSession->context_ = abilityContext_; WindowSessionImpl::GetWindowExtensionSessionSet().insert(windowSession); ASSERT_TRUE(nullptr != windowSession->FindExtensionWindowWithContext()); windowSession->AddSetUIExtensionDestroyTimeoutCheck(); EXPECT_EQ(windowSession->startUIExtensionDestroyTimer_.load(), true); subWindowSession->SetUIExtensionDestroyCompleteInSubWindow(); EXPECT_EQ(windowSession->startUIExtensionDestroyTimer_.load(), false); } /** * @tc.name: AddSetUIExtensionDestroyTimeoutCheck * @tc.desc: AddSetUIExtensionDestroyTimeoutCheck * @tc.type: FUNC */ HWTEST_F(WindowSessionImplTest, AddSetUIExtensionDestroyTimeoutCheck, TestSize.Level1) { sptr option = sptr::MakeSptr(); option->SetWindowName("AddSetUIExtensionDestroyTimeoutCheck"); option->SetBundleName("UTtest"); option->SetWindowType(WindowType::WINDOW_TYPE_UI_EXTENSION); sptr window = sptr::MakeSptr(option); window->AddSetUIExtensionDestroyTimeoutCheck(); EXPECT_EQ(WindowType::WINDOW_TYPE_UI_EXTENSION, window->property_->GetWindowType()); EXPECT_EQ(window->startUIExtensionDestroyTimer_.load(), true); } /** * @tc.name: GetStatusBarHeight * @tc.desc: GetStatusBarHeight test * @tc.type: FUNC */ HWTEST_F(WindowSessionImplTest, GetStatusBarHeight, TestSize.Level1) { sptr option = sptr::MakeSptr(); option->SetWindowName("GetStatusBarHeight"); sptr window = sptr::MakeSptr(option); ASSERT_NE(window, nullptr); ASSERT_EQ(0, window->GetStatusBarHeight()); } /** * @tc.name: GetWindowStatusInner * @tc.desc: GetWindowStatusInner test * @tc.type: FUNC */ HWTEST_F(WindowSessionImplTest, GetWindowStatusInner, TestSize.Level1) { sptr option = sptr::MakeSptr(); option->SetWindowName("GetWindowStatusInner"); sptr window = sptr::MakeSptr(option); window->property_->SetPersistentId(1); SessionInfo sessionInfo = { "CreateTestBundle", "CreateTestModule", "CreateTestAbility" }; sptr session = sptr::MakeSptr(sessionInfo); window->hostSession_ = session; EXPECT_EQ(WindowStatus::WINDOW_STATUS_UNDEFINED, window->GetWindowStatusInner(WindowMode::WINDOW_MODE_PIP)); window->SetTargetAPIVersion(14); window->windowSystemConfig_.windowUIType_ = WindowUIType::PC_WINDOW; EXPECT_EQ(WindowStatus::WINDOW_STATUS_FULLSCREEN, window->GetWindowStatusInner(WindowMode::WINDOW_MODE_FULLSCREEN)); window->SetTargetAPIVersion(12); EXPECT_EQ(WindowStatus::WINDOW_STATUS_FULLSCREEN, window->GetWindowStatusInner(WindowMode::WINDOW_MODE_FULLSCREEN)); EXPECT_EQ(WindowStatus::WINDOW_STATUS_SPLITSCREEN, window->GetWindowStatusInner(WindowMode::WINDOW_MODE_SPLIT_PRIMARY)); EXPECT_EQ(WindowStatus::WINDOW_STATUS_SPLITSCREEN, window->GetWindowStatusInner(WindowMode::WINDOW_MODE_SPLIT_SECONDARY)); window->property_->maximizeMode_ = MaximizeMode::MODE_AVOID_SYSTEM_BAR; EXPECT_EQ(WindowStatus::WINDOW_STATUS_MAXIMIZE, window->GetWindowStatusInner(WindowMode::WINDOW_MODE_FLOATING)); window->property_->maximizeMode_ = MaximizeMode::MODE_FULL_FILL; EXPECT_EQ(WindowStatus::WINDOW_STATUS_FLOATING, window->GetWindowStatusInner(WindowMode::WINDOW_MODE_FLOATING)); window->state_ = WindowState::STATE_HIDDEN; EXPECT_EQ(WindowStatus::WINDOW_STATUS_MINIMIZE, window->GetWindowStatusInner(WindowMode::WINDOW_MODE_PIP)); } /** * @tc.name: GetBackgroundColor01 * @tc.desc: GetBackgroundColor01 test * @tc.type: FUNC */ HWTEST_F(WindowSessionImplTest, GetBackgroundColor01, TestSize.Level1) { sptr option = sptr::MakeSptr(); option->SetWindowName("GetBackgroundColor01"); sptr window = sptr::MakeSptr(option); window->uiContent_ = std::make_unique(); EXPECT_EQ(0, window->GetBackgroundColor()); } /** * @tc.name: GetBackgroundColor02 * @tc.desc: GetBackgroundColor02 test * @tc.type: FUNC */ HWTEST_F(WindowSessionImplTest, GetBackgroundColor02, TestSize.Level1) { sptr option = sptr::MakeSptr(); option->SetWindowName("GetBackgroundColor02"); sptr window = sptr::MakeSptr(option); sptr handler = sptr(); window->SetAceAbilityHandler(handler); EXPECT_EQ(0xffffffff, window->GetBackgroundColor()); } /** * @tc.name: GetBackgroundColor03 * @tc.desc: GetBackgroundColor03 test * @tc.type: FUNC */ HWTEST_F(WindowSessionImplTest, GetBackgroundColor03, TestSize.Level1) { sptr option = sptr::MakeSptr(); option->SetWindowName("GetBackgroundColor03"); sptr window = sptr::MakeSptr(option); EXPECT_EQ(0xffffffff, window->GetBackgroundColor()); } /** * @tc.name: GetExtensionConfig * @tc.desc: GetExtensionConfig test * @tc.type: FUNC */ HWTEST_F(WindowSessionImplTest, GetExtensionConfig, TestSize.Level1) { sptr option = sptr::MakeSptr(); option->SetWindowName("GetExtensionConfig"); sptr window = sptr::MakeSptr(option); SessionInfo sessionInfo; window->hostSession_ = sptr::MakeSptr(sessionInfo); window->crossAxisState_ = CrossAxisState::STATE_CROSS; AAFwk::WantParams want; window->GetExtensionConfig(want); EXPECT_EQ(want.GetIntParam(Extension::CROSS_AXIS_FIELD, 0), static_cast(CrossAxisState::STATE_CROSS)); window->crossAxisState_ = CrossAxisState::STATE_INVALID; window->GetExtensionConfig(want); EXPECT_EQ(want.GetIntParam(Extension::CROSS_AXIS_FIELD, 0), static_cast(CrossAxisState::STATE_INVALID)); window->crossAxisState_ = CrossAxisState::STATE_NO_CROSS; window->GetExtensionConfig(want); EXPECT_EQ(want.GetIntParam(Extension::CROSS_AXIS_FIELD, 0), static_cast(CrossAxisState::STATE_NO_CROSS)); window->crossAxisState_ = CrossAxisState::STATE_END; window->GetExtensionConfig(want); EXPECT_EQ(want.GetIntParam(Extension::CROSS_AXIS_FIELD, 0), static_cast(CrossAxisState::STATE_END)); bool isHostWindowDelayRaiseEnabled = true; window->property_->SetWindowDelayRaiseEnabled(isHostWindowDelayRaiseEnabled); window->GetExtensionConfig(want); EXPECT_EQ(want.GetIntParam(Extension::HOST_WINDOW_DELAY_RAISE_STATE_FIELD, 0), static_cast(isHostWindowDelayRaiseEnabled)); isHostWindowDelayRaiseEnabled = false; window->property_->SetWindowDelayRaiseEnabled(isHostWindowDelayRaiseEnabled); window->GetExtensionConfig(want); EXPECT_EQ(want.GetIntParam(Extension::HOST_WINDOW_DELAY_RAISE_STATE_FIELD, 0), static_cast(isHostWindowDelayRaiseEnabled)); } /** * @tc.name: OnExtensionMessage * @tc.desc: OnExtensionMessage test * @tc.type: FUNC */ HWTEST_F(WindowSessionImplTest, OnExtensionMessage, TestSize.Level1) { sptr option = sptr::MakeSptr(); option->SetWindowName("OnExtensionMessage"); sptr window = sptr::MakeSptr(option); uint32_t code = 9999; int32_t persistentId = 1111; AAFwk::Want want; auto ret = window->OnExtensionMessage(code, persistentId, want); EXPECT_EQ(WMError::WM_OK, ret); code = static_cast(Extension::Businesscode::NOTIFY_HOST_WINDOW_TO_RAISE); window->hostSession_ = nullptr; ASSERT_EQ(nullptr, window->GetHostSession()); ret = window->OnExtensionMessage(code, persistentId, want); EXPECT_EQ(WMError::WM_ERROR_INVALID_WINDOW, ret); SessionInfo sessionInfo; window->hostSession_ = sptr::MakeSptr(sessionInfo); window->property_->SetPersistentId(1); ASSERT_FALSE(window->GetPersistentId() == INVALID_SESSION_ID); window->state_ = WindowState::STATE_CREATED; ASSERT_FALSE(window->state_ == WindowState::STATE_DESTROYED); window->property_->SetWindowType(WindowType::WINDOW_TYPE_APP_MAIN_WINDOW); ASSERT_EQ(true, WindowHelper::IsAppWindow(window->GetType())); ret = window->OnExtensionMessage(code, persistentId, want); EXPECT_EQ(WMError::WM_OK, ret); code = static_cast(Extension::Businesscode::REGISTER_HOST_WINDOW_RECT_CHANGE_LISTENER); EXPECT_EQ(WMError::WM_OK, window->OnExtensionMessage(code, persistentId, want)); code = static_cast(Extension::Businesscode::UNREGISTER_HOST_WINDOW_RECT_CHANGE_LISTENER); EXPECT_EQ(WMError::WM_OK, window->OnExtensionMessage(code, persistentId, want)); } /** * @tc.name: OnExtensionMessage_KeyboardListener * @tc.desc: OnExtensionMessage_KeyboardListener test * @tc.type: FUNC */ HWTEST_F(WindowSessionImplTest, OnExtensionMessage_KeyboardListener, TestSize.Level1) { sptr option = sptr::MakeSptr(); option->SetWindowName("OnExtensionMessage"); sptr window = sptr::MakeSptr(option); uint32_t code = 9999; int32_t persistentId = 1111; AAFwk::Want want; ASSERT_TRUE(window->keyboardDidShowUIExtListeners_.empty()); code = static_cast(Extension::Businesscode::REGISTER_KEYBOARD_DID_SHOW_LISTENER); EXPECT_EQ(WMError::WM_OK, window->OnExtensionMessage(code, persistentId, want)); ASSERT_FALSE(window->keyboardDidShowUIExtListeners_.empty()); EXPECT_EQ(WMError::WM_OK, window->OnExtensionMessage(code, persistentId, want)); code = static_cast(Extension::Businesscode::UNREGISTER_KEYBOARD_DID_SHOW_LISTENER); EXPECT_EQ(WMError::WM_OK, window->OnExtensionMessage(code, persistentId, want)); ASSERT_TRUE(window->keyboardDidShowUIExtListeners_.empty()); EXPECT_EQ(WMError::WM_OK, window->OnExtensionMessage(code, persistentId, want)); ASSERT_TRUE(window->keyboardDidHideUIExtListeners_.empty()); code = static_cast(Extension::Businesscode::REGISTER_KEYBOARD_DID_HIDE_LISTENER); EXPECT_EQ(WMError::WM_OK, window->OnExtensionMessage(code, persistentId, want)); ASSERT_FALSE(window->keyboardDidHideUIExtListeners_.empty()); EXPECT_EQ(WMError::WM_OK, window->OnExtensionMessage(code, persistentId, want)); code = static_cast(Extension::Businesscode::UNREGISTER_KEYBOARD_DID_HIDE_LISTENER); EXPECT_EQ(WMError::WM_OK, window->OnExtensionMessage(code, persistentId, want)); ASSERT_TRUE(window->keyboardDidHideUIExtListeners_.empty()); EXPECT_EQ(WMError::WM_OK, window->OnExtensionMessage(code, persistentId, want)); } /** * @tc.name: RegisterWaterfallModeChangeListener * @tc.desc: RegisterWaterfallModeChangeListener Test * @tc.type: FUNC */ HWTEST_F(WindowSessionImplTest, RegisterWaterfallModeChangeListener, TestSize.Level1) { sptr option = sptr::MakeSptr(); option->SetWindowName("waterfall"); sptr window = sptr::MakeSptr(option); sptr listener = sptr::MakeSptr(); auto ret = window->RegisterWaterfallModeChangeListener(listener); ASSERT_EQ(WMError::WM_OK, ret); listener = nullptr; ret = window->RegisterWaterfallModeChangeListener(listener); ASSERT_EQ(WMError::WM_ERROR_NULLPTR, ret); auto listeners = window->GetWaterfallModeChangeListeners(); ASSERT_EQ(listeners.size(), 1); } /** * @tc.name: UnregisterWaterfallModeChangeListener * @tc.desc: UnregisterWaterfallModeChangeListener Test * @tc.type: FUNC */ HWTEST_F(WindowSessionImplTest, UnregisterWaterfallModeChangeListener, TestSize.Level1) { sptr option = sptr::MakeSptr(); option->SetWindowName("waterfall"); sptr window = sptr::MakeSptr(option); window->waterfallModeChangeListeners_.clear(); sptr listener = sptr::MakeSptr(); auto ret = window->RegisterWaterfallModeChangeListener(listener); ASSERT_EQ(WMError::WM_OK, ret); auto listeners = window->GetWaterfallModeChangeListeners(); ASSERT_EQ(listeners.size(), 1); ret = window->UnregisterWaterfallModeChangeListener(listener); ASSERT_EQ(WMError::WM_OK, ret); listeners = window->GetWaterfallModeChangeListeners(); ASSERT_EQ(listeners.size(), 0); listener = nullptr; ret = window->UnregisterWaterfallModeChangeListener(listener); ASSERT_EQ(WMError::WM_ERROR_NULLPTR, ret); } /** * @tc.name: GetRouterStackInfo * @tc.desc: GetRouterStackInfo * @tc.type: FUNC */ HWTEST_F(WindowSessionImplTest, GetRouterStackInfo, TestSize.Level1) { sptr option = sptr::MakeSptr(); option->SetWindowName("GetRouterStackInfo"); sptr window = sptr::MakeSptr(option); window->uiContent_ = std::make_unique(); std::string testInfo; auto res = window->GetRouterStackInfo(testInfo); EXPECT_EQ(res, WMError::WM_OK); window->uiContent_ = nullptr; res = window->GetRouterStackInfo(testInfo); EXPECT_EQ(res, WMError::WM_ERROR_NULLPTR); } /** * @tc.name: IsWaterfallModeEnabled * @tc.desc: IsWaterfallModeEnabled * @tc.type: FUNC */ HWTEST_F(WindowSessionImplTest, IsWaterfallModeEnabled, TestSize.Level1) { sptr option = sptr::MakeSptr(); option->SetWindowName("IsWaterfallModeEnabled"); sptr window = sptr::MakeSptr(option); window->hostSession_ = nullptr; EXPECT_EQ(window->IsWaterfallModeEnabled(), false); auto mockHostSession = sptr::MakeSptr(); window->hostSession_ = mockHostSession; window->property_->persistentId_ = 1234; EXPECT_CALL(*mockHostSession, GetWaterfallMode(_)).WillOnce(DoAll(SetArgReferee<0>(true), Return(WSError::WS_OK))); EXPECT_EQ(window->IsWaterfallModeEnabled(), true); } /** * @tc.name: NotifyWaterfallModeChange * @tc.desc: NotifyWaterfallModeChange Test * @tc.type: FUNC */ HWTEST_F(WindowSessionImplTest, NotifyWaterfallModeChange, TestSize.Level1) { sptr option = sptr::MakeSptr(); option->SetWindowName("waterfall"); sptr window = sptr::MakeSptr(option); window->state_ = WindowState::STATE_SHOWN; sptr listener = sptr::MakeSptr(); auto ret = window->RegisterWaterfallModeChangeListener(listener); ASSERT_EQ(WMError::WM_OK, ret); window->NotifyWaterfallModeChange(true); } /** * @tc.name: NotifyAcrossDisplaysChange * @tc.desc: NotifyAcrossDisplaysChange Test * @tc.type: FUNC */ HWTEST_F(WindowSessionImplTest, NotifyAcrossDisplaysChange, TestSize.Level1) { sptr option = sptr::MakeSptr(); option->SetWindowName("waterfall"); sptr window = sptr::MakeSptr(option); window->property_->SetPersistentId(1); window->state_ = WindowState::STATE_SHOWN; sptr listener = sptr::MakeSptr(); window->acrossDisplaysChangeListeners_[1].push_back(listener); window->RegisterAcrossDisplaysChangeListener(listener); auto ret = window->NotifyAcrossDisplaysChange(true); EXPECT_EQ(WMError::WM_OK, ret); ret = window->NotifyAcrossDisplaysChange(true); EXPECT_EQ(WMError::WM_DO_NOTHING, ret); window->acrossDisplaysChangeListeners_[1].push_back(nullptr); ret = window->NotifyAcrossDisplaysChange(false); EXPECT_EQ(WMError::WM_OK, ret); } /** * @tc.name: CreateSubWindowOutlineEnabled * @tc.desc: CreateSubWindowOutlineEnabled Test * @tc.type: FUNC */ HWTEST_F(WindowSessionImplTest, CreateSubWindowOutlineEnabled, TestSize.Level1) { sptr option1 = sptr::MakeSptr(); option1->SetWindowName("CreateSubWindowOutlineEnabled01"); option1->SetWindowType(WindowType::WINDOW_TYPE_APP_SUB_WINDOW); sptr window1 = sptr::MakeSptr(option1); ASSERT_EQ(false, window1->property_->IsSubWindowOutlineEnabled()); sptr option2 = sptr::MakeSptr(); option2->SetWindowName("CreateSubWindowOutlineEnabled02"); option2->SetWindowType(WindowType::WINDOW_TYPE_APP_SUB_WINDOW); option2->SetSubWindowOutlineEnabled(false); sptr window2 = sptr::MakeSptr(option2); ASSERT_EQ(false, window2->property_->IsSubWindowOutlineEnabled()); sptr option3 = sptr::MakeSptr(); option3->SetWindowName("CreateSubWindowOutlineEnabled03"); option3->SetWindowType(WindowType::WINDOW_TYPE_APP_SUB_WINDOW); option3->SetSubWindowOutlineEnabled(true); sptr window3 = sptr::MakeSptr(option3); ASSERT_EQ(true, window3->property_->IsSubWindowOutlineEnabled()); } /** * @tc.name: GetAttachStateSyncResult * @tc.desc: GetAttachStateSyncResult Test * @tc.type: FUNC */ HWTEST_F(WindowSessionImplTest, GetAttachStateSyncResult, TestSize.Level1) { g_errLog.clear(); LOG_SetCallback(MyLogCallback); sptr option = sptr::MakeSptr(); option->SetWindowName("GetAttachStateSyncResult"); option->SetWindowType(WindowType::WINDOW_TYPE_INPUT_METHOD_FLOAT); sptr window = sptr::MakeSptr(option); window->lifecycleCallback_ = sptr::MakeSptr(); window->GetAttachStateSyncResult(true, true); EXPECT_TRUE(g_errLog.find("get attach state sync result") == std::string::npos); window->GetAttachStateSyncResult(true, false); EXPECT_TRUE(g_errLog.find("get attach state sync result") == std::string::npos); window->lifecycleCallback_ = nullptr; window->property_->SetWindowType(WindowType::WINDOW_TYPE_APP_SUB_WINDOW); window->GetAttachStateSyncResult(true, true); EXPECT_TRUE(g_errLog.find("lifecycleCallback is null") != std::string::npos); EXPECT_TRUE(g_errLog.find("get attach state sync result") == std::string::npos); window->lifecycleCallback_ = sptr::MakeSptr(); window->GetAttachStateSyncResult(false, true); EXPECT_TRUE(g_errLog.find("get attach state sync result") == std::string::npos); window->GetAttachStateSyncResult(true, true); EXPECT_TRUE(g_errLog.find("get attach state sync result") != std::string::npos); window->GetAttachStateSyncResult(true, false); EXPECT_TRUE(g_errLog.find("get attach state sync result") != std::string::npos); } } } // namespace } // namespace Rosen } // namespace OHOS