diff --git a/wm/test/unittest/BUILD.gn b/wm/test/unittest/BUILD.gn index 6a9fca35b8219c7ffe9f51e5b56b30f2745948e8..ab89f0ab8c9f73615e3bc00ac6956eaa88aa92f5 100644 --- a/wm/test/unittest/BUILD.gn +++ b/wm/test/unittest/BUILD.gn @@ -30,6 +30,7 @@ group("unittest") { ":wm_pattern_detach_callback_test", ":wm_picture_in_picture_controller_test", ":wm_picture_in_picture_manager_test", + ":wm_picture_in_picture_option_new_test", ":wm_picture_in_picture_option_test", ":wm_root_scene_test", ":wm_screen_scene_test", @@ -586,6 +587,20 @@ ohos_unittest("wm_picture_in_picture_option_test") { ] } +ohos_unittest("wm_picture_in_picture_option_new_test") { + module_out_path = module_out_path + + sources = [ "picture_in_picture_option_new_test.cpp" ] + + deps = [ ":wm_unittest_common" ] + + external_deps = test_external_deps + external_deps += [ + "ability_runtime:runtime", + "ace_engine:ace_xcomponent_controller", + ] +} + ohos_unittest("wm_web_picture_in_picture_controller_interface_test") { module_out_path = module_out_path diff --git a/wm/test/unittest/picture_in_picture_option_new_test.cpp b/wm/test/unittest/picture_in_picture_option_new_test.cpp new file mode 100644 index 0000000000000000000000000000000000000000..e259ce8bb5b05145df041aaff541121a65673b86 --- /dev/null +++ b/wm/test/unittest/picture_in_picture_option_new_test.cpp @@ -0,0 +1,281 @@ +/* + * Copyright (c) 2023-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 "picture_in_picture_option.h" +#include "wm_common.h" +using namespace testing; +using namespace testing::ext; + +namespace OHOS { +namespace Rosen { +class PictureInPictureOptionNewTest : public testing::Test { +public: + static void SetUpTestCase(); + + static void TearDownTestCase(); + + void SetUp() override; + + void TearDown() override; +}; + +void PictureInPictureOptionNewTest::SetUpTestCase() {} + +void PictureInPictureOptionNewTest::TearDownTestCase() {} + +void PictureInPictureOptionNewTest::SetUp() {} + +void PictureInPictureOptionNewTest::TearDown() {} + +namespace { + +/** + * @tc.name: ClearNapiRefs + * @tc.desc: ClearNapiRefs + * @tc.type: FUNC + */ +HWTEST_F(PictureInPictureOptionNewTest, ClearNapiRefs, Function | SmallTest | Level2) +{ + int num = 0; + napi_ref ref = reinterpret_cast(&num); + ASSERT_NE(nullptr, ref); + sptr option = new PipOption(); + option->SetNodeControllerRef(ref); + ASSERT_NE(nullptr, option->GetNodeControllerRef()); + option->SetTypeNodeRef(ref); + ASSERT_NE(nullptr, option->GetTypeNodeRef()); + option->SetStorageRef(ref); + ASSERT_NE(nullptr, option->GetStorageRef()); + option->ClearNapiRefs(nullptr); + ASSERT_EQ(nullptr, option->GetNodeControllerRef()); + ASSERT_EQ(nullptr, option->GetTypeNodeRef()); + ASSERT_EQ(nullptr, option->GetStorageRef()); +} + +/** + * @tc.name: Context + * @tc.desc: SetContext/GetContext + * @tc.type: FUNC + */ +HWTEST_F(PictureInPictureOptionNewTest, Context, TestSize.Level1) +{ + void* contextPtr = nullptr; + sptr option = new PipOption(); + option->SetContext(contextPtr); + ASSERT_EQ(contextPtr, option->GetContext()); +} + +/** + * @tc.name: PipTemplate + * @tc.desc: SetPipTemplate/GetPipTemplate + * @tc.type: FUNC + */ +HWTEST_F(PictureInPictureOptionNewTest, PipTemplate, TestSize.Level1) +{ + sptr option = new PipOption(); + option->SetPipTemplate(100); + EXPECT_EQ(100, option->GetPipTemplate()); +} + +/** + * @tc.name: DefaultWindowSizeType + * @tc.desc: SetDefaultWindowSizeType/GetDefaultWindowSizeType + * @tc.type: FUNC + */ +HWTEST_F(PictureInPictureOptionNewTest, DefaultWindowSizeType, Function | SmallTest | Level2) +{ + sptr option = new PipOption(); + option->SetDefaultWindowSizeType(100); + EXPECT_EQ(100, option->GetDefaultWindowSizeType()); +} + +/** + * @tc.name: PiPControlStatus + * @tc.desc: SetPiPControlStatus/GetControlStatus + * @tc.type: FUNC + */ +HWTEST_F(PictureInPictureOptionNewTest, SetPiPControlStatus, TestSize.Level1) +{ + auto option = sptr::MakeSptr(); + ASSERT_NE(nullptr, option); + auto controlType = PiPControlType::VIDEO_PLAY_PAUSE; + auto status = PiPControlStatus::PLAY; + option->SetPiPControlStatus(controlType, status); + controlType = PiPControlType::END; + option->SetPiPControlStatus(controlType, status); + EXPECT_NE(0, option->GetControlStatus().size()); +} + +/** + * @tc.name: PiPControlEnable + * @tc.desc: SetPiPControlEnabled/GetControlEnable + * @tc.type: FUNC + */ +HWTEST_F(PictureInPictureOptionNewTest, SetPiPControlEnabled, TestSize.Level1) +{ + auto option = sptr::MakeSptr(); + ASSERT_NE(nullptr, option); + auto controlType = PiPControlType::VIDEO_PLAY_PAUSE; + auto enabled = PiPControlStatus::ENABLED; + option->SetPiPControlEnabled(controlType, enabled); + controlType = PiPControlType::END; + option->SetPiPControlEnabled(controlType, enabled); + EXPECT_NE(0, option->GetControlEnable().size()); +} + +/** + * @tc.name: NavigationId + * @tc.desc: SetNavigationId/GetNavigationId + * @tc.type: FUNC + */ +HWTEST_F(PictureInPictureOptionNewTest, NavigationId, TestSize.Level1) +{ + sptr option = new PipOption(); + std::string navigationId = "abc"; + option->SetNavigationId(navigationId); + EXPECT_EQ(navigationId, option->GetNavigationId()); +} + +/** + * @tc.name: ControlGroup + * @tc.desc: SetControlGroup/GetControlGroup + * @tc.type: FUNC + */ +HWTEST_F(PictureInPictureOptionNewTest, SetGetControlGroupTest, TestSize.Level1) +{ + sptr option = new PipOption(); + std::vector controlGroup; + controlGroup.push_back(static_cast(PiPControlGroup::VIDEO_CALL_MICROPHONE_SWITCH)); + controlGroup.push_back(static_cast(PiPControlGroup::VIDEO_CALL_HANG_UP_BUTTON)); + controlGroup.push_back(static_cast(PiPControlGroup::VIDEO_CALL_CAMERA_SWITCH)); + option->SetControlGroup(controlGroup); + EXPECT_NE(option->GetControlGroup().size(), 0); +} + +/** + * @tc.name: ContentSize + * @tc.desc: SetContentSize/GetContentSize + * @tc.type: FUNC + */ +HWTEST_F(PictureInPictureOptionNewTest, ContentSize, TestSize.Level1) +{ + sptr option = new PipOption(); + uint32_t width = 800; + uint32_t height = 600; + option->SetContentSize(width, height); + uint32_t w = 0; + uint32_t h = 0; + option->GetContentSize(w, h); + EXPECT_EQ(width, w); + EXPECT_EQ(height, h); +} + +/** + * @tc.name: NodeController + * @tc.desc: SetNodeControllerRef/GetNodeControllerRef + * @tc.type: FUNC + */ +HWTEST_F(PictureInPictureOptionNewTest, NodeController, TestSize.Level1) +{ + sptr option = sptr::MakeSptr(); + option->SetNodeControllerRef(nullptr); + ASSERT_EQ(option->GetNodeControllerRef(), nullptr); +} + +/** + * @tc.name: TypeNodeRef + * @tc.desc: SetTypeNodeRef/GetTypeNodeRef + * @tc.type: FUNC + */ +HWTEST_F(PictureInPictureOptionNewTest, TypeNodeRef, TestSize.Level1) +{ + sptr option = sptr::MakeSptr(); + option->SetTypeNodeRef(nullptr); + ASSERT_EQ(option->GetTypeNodeRef(), nullptr); +} + +/** + * @tc.name: StorageRef + * @tc.desc: SetStorageRef/GetStorageRef + * @tc.type: FUNC + */ +HWTEST_F(PictureInPictureOptionNewTest, StorageRef, Function | SmallTest | Level2) +{ + int num = 0; + napi_ref ref = reinterpret_cast(&num); + ASSERT_NE(nullptr, ref); + sptr option = sptr::MakeSptr(); + option->SetStorageRef(ref); + ASSERT_EQ(option->GetStorageRef(), ref); +} + +/** + * @tc.name: TypeNodeEnabled + * @tc.desc: SetTypeNodeEnabled/IsTypeNodeEnabled + * @tc.type: FUNC + */ +HWTEST_F(PictureInPictureOptionNewTest, TypeNodeEnabled001, TestSize.Level1) +{ + sptr option = sptr::MakeSptr(); + option->SetTypeNodeEnabled(true); + EXPECT_TRUE(option->IsTypeNodeEnabled()); +} + +/** + * @tc.name: TypeNodeEnabled + * @tc.desc: SetTypeNodeEnabled/IsTypeNodeEnabled + * @tc.type: FUNC + */ +HWTEST_F(PictureInPictureOptionNewTest, TypeNodeEnabled002, TestSize.Level1) +{ + sptr option = sptr::MakeSptr(); + option->SetTypeNodeEnabled(false); + EXPECT_TRUE(!option->IsTypeNodeEnabled()); +} + +/** + * @tc.name: GetPiPTemplateInfo + * @tc.desc: GetPiPTemplateInfo/GetPipPriority + * @tc.type: FUNC + */ +HWTEST_F(PictureInPictureOptionNewTest, GetPiPTemplateInfo001, TestSize.Level1) +{ + sptr option = new PipOption(); + uint32_t pipTypeTemplate = 5; + uint32_t testValue = 0; + EXPECT_EQ(testValue, option->GetPipPriority(pipTypeTemplate)); + EXPECT_EQ(testValue, option->GetPipPriority(pipTypeTemplate = 3)); + EXPECT_EQ(testValue, option->GetPipPriority(pipTypeTemplate = 0)); + EXPECT_EQ(testValue = 1, option->GetPipPriority(pipTypeTemplate = 1)); +} + +/** + * @tc.name: GetPiPTemplateInfo + * @tc.desc: GetPiPTemplateInfo/GetPipPriority + * @tc.type: FUNC + */ +HWTEST_F(PictureInPictureOptionNewTest, GetPiPTemplateInfo, TestSize.Level1) +{ + sptr option = new PipOption(); + uint32_t testValue = 0; + PiPTemplateInfo pipTemplateInfo; + option->SetDefaultWindowSizeType(testValue = 2); + option->GetPiPTemplateInfo(pipTemplateInfo); + EXPECT_EQ(testValue, pipTemplateInfo.defaultWindowSizeType); +} +} // namespace +} // namespace Rosen +} // namespace OHOS \ No newline at end of file