1 /*
2 * Copyright (c) 2023-2023 Huawei Device Co., Ltd.
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
6 *
7 * http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 */
15
16 #include <gtest/gtest.h>
17 #include "picture_in_picture_option.h"
18 #include "wm_common.h"
19 using namespace testing;
20 using namespace testing::ext;
21
22 namespace OHOS {
23 namespace Rosen {
24 class PictureInPictureOptionTest : public testing::Test {
25 public:
26 static void SetUpTestCase();
27
28 static void TearDownTestCase();
29
30 void SetUp() override;
31
32 void TearDown() override;
33 };
34
SetUpTestCase()35 void PictureInPictureOptionTest::SetUpTestCase() {}
36
TearDownTestCase()37 void PictureInPictureOptionTest::TearDownTestCase() {}
38
SetUp()39 void PictureInPictureOptionTest::SetUp() {}
40
TearDown()41 void PictureInPictureOptionTest::TearDown() {}
42
43 namespace {
44
45 /**
46 * @tc.name: ClearNapiRefs
47 * @tc.desc: ClearNapiRefs
48 * @tc.type: FUNC
49 */
50 HWTEST_F(PictureInPictureOptionTest, ClearNapiRefs, Function | SmallTest | Level2)
51 {
52 int num = 0;
53 napi_ref ref = reinterpret_cast<napi_ref>(&num);
54 ASSERT_NE(nullptr, ref);
55 sptr<PipOption> option = new PipOption();
56 option->SetNodeControllerRef(ref);
57 ASSERT_NE(nullptr, option->GetNodeControllerRef());
58 option->SetTypeNodeRef(ref);
59 ASSERT_NE(nullptr, option->GetTypeNodeRef());
60 option->SetStorageRef(ref);
61 ASSERT_NE(nullptr, option->GetStorageRef());
62 option->ClearNapiRefs(nullptr);
63 ASSERT_EQ(nullptr, option->GetNodeControllerRef());
64 ASSERT_EQ(nullptr, option->GetTypeNodeRef());
65 ASSERT_EQ(nullptr, option->GetStorageRef());
66 }
67
68 /**
69 * @tc.name: Context
70 * @tc.desc: SetContext/GetContext
71 * @tc.type: FUNC
72 */
73 HWTEST_F(PictureInPictureOptionTest, Context, TestSize.Level1)
74 {
75 void* contextPtr = nullptr;
76 sptr<PipOption> option = new PipOption();
77 option->SetContext(contextPtr);
78 ASSERT_EQ(contextPtr, option->GetContext());
79 }
80
81 /**
82 * @tc.name: PipTemplate
83 * @tc.desc: SetPipTemplate/GetPipTemplate
84 * @tc.type: FUNC
85 */
86 HWTEST_F(PictureInPictureOptionTest, PipTemplate, TestSize.Level1)
87 {
88 sptr<PipOption> option = new PipOption();
89 option->SetPipTemplate(100);
90 ASSERT_EQ(100, option->GetPipTemplate());
91 }
92
93 /**
94 * @tc.name: DefaultWindowSizeType
95 * @tc.desc: SetDefaultWindowSizeType/GetDefaultWindowSizeType
96 * @tc.type: FUNC
97 */
98 HWTEST_F(PictureInPictureOptionTest, DefaultWindowSizeType, Function | SmallTest | Level2)
99 {
100 sptr<PipOption> option = new PipOption();
101 option->SetDefaultWindowSizeType(100);
102 ASSERT_EQ(100, option->GetDefaultWindowSizeType());
103 }
104
105 /**
106 * @tc.name: PiPControlStatus
107 * @tc.desc: SetPiPControlStatus/GetControlStatus
108 * @tc.type: FUNC
109 */
110 HWTEST_F(PictureInPictureOptionTest, SetPiPControlStatus, TestSize.Level1)
111 {
112 auto option = sptr<PipOption>::MakeSptr();
113 ASSERT_NE(nullptr, option);
114 auto controlType = PiPControlType::VIDEO_PLAY_PAUSE;
115 auto status = PiPControlStatus::PLAY;
116 option->SetPiPControlStatus(controlType, status);
117 controlType = PiPControlType::END;
118 option->SetPiPControlStatus(controlType, status);
119 ASSERT_NE(0, option->GetControlStatus().size());
120 }
121
122 /**
123 * @tc.name: PiPControlEnable
124 * @tc.desc: SetPiPControlEnabled/GetControlEnable
125 * @tc.type: FUNC
126 */
127 HWTEST_F(PictureInPictureOptionTest, SetPiPControlEnabled, TestSize.Level1)
128 {
129 auto option = sptr<PipOption>::MakeSptr();
130 ASSERT_NE(nullptr, option);
131 auto controlType = PiPControlType::VIDEO_PLAY_PAUSE;
132 auto enabled = PiPControlStatus::ENABLED;
133 option->SetPiPControlEnabled(controlType, enabled);
134 controlType = PiPControlType::END;
135 option->SetPiPControlEnabled(controlType, enabled);
136 ASSERT_NE(0, option->GetControlEnable().size());
137 }
138
139 /**
140 * @tc.name: NavigationId
141 * @tc.desc: SetNavigationId/GetNavigationId
142 * @tc.type: FUNC
143 */
144 HWTEST_F(PictureInPictureOptionTest, NavigationId, TestSize.Level1)
145 {
146 sptr<PipOption> option = new PipOption();
147 std::string navigationId = "abc";
148 option->SetNavigationId(navigationId);
149 ASSERT_EQ(navigationId, option->GetNavigationId());
150 }
151
152 /**
153 * @tc.name: ControlGroup
154 * @tc.desc: SetControlGroup/GetControlGroup
155 * @tc.type: FUNC
156 */
157 HWTEST_F(PictureInPictureOptionTest, SetGetControlGroupTest, TestSize.Level1)
158 {
159 sptr<PipOption> option = new PipOption();
160 std::vector<std::uint32_t> controlGroup;
161 controlGroup.push_back(static_cast<uint32_t>(PiPControlGroup::VIDEO_CALL_MICROPHONE_SWITCH));
162 controlGroup.push_back(static_cast<uint32_t>(PiPControlGroup::VIDEO_CALL_HANG_UP_BUTTON));
163 controlGroup.push_back(static_cast<uint32_t>(PiPControlGroup::VIDEO_CALL_CAMERA_SWITCH));
164 option->SetControlGroup(controlGroup);
165 ASSERT_NE(option->GetControlGroup().size(), 0);
166 }
167
168 /**
169 * @tc.name: ContentSize
170 * @tc.desc: SetContentSize/GetContentSize
171 * @tc.type: FUNC
172 */
173 HWTEST_F(PictureInPictureOptionTest, ContentSize, TestSize.Level1)
174 {
175 sptr<PipOption> option = new PipOption();
176 uint32_t width = 800;
177 uint32_t height = 600;
178 option->SetContentSize(width, height);
179 uint32_t w = 0;
180 uint32_t h = 0;
181 option->GetContentSize(w, h);
182 ASSERT_EQ(width, w);
183 ASSERT_EQ(height, h);
184 }
185
186 /**
187 * @tc.name: NodeController
188 * @tc.desc: SetNodeControllerRef/GetNodeControllerRef
189 * @tc.type: FUNC
190 */
191 HWTEST_F(PictureInPictureOptionTest, NodeController, TestSize.Level1)
192 {
193 sptr<PipOption> option = sptr<PipOption>::MakeSptr();
194 option->SetNodeControllerRef(nullptr);
195 ASSERT_EQ(option->GetNodeControllerRef(), nullptr);
196 }
197
198 /**
199 * @tc.name: TypeNodeRef
200 * @tc.desc: SetTypeNodeRef/GetTypeNodeRef
201 * @tc.type: FUNC
202 */
203 HWTEST_F(PictureInPictureOptionTest, TypeNodeRef, TestSize.Level1)
204 {
205 sptr<PipOption> option = sptr<PipOption>::MakeSptr();
206 option->SetTypeNodeRef(nullptr);
207 ASSERT_EQ(option->GetTypeNodeRef(), nullptr);
208 }
209
210 /**
211 * @tc.name: StorageRef
212 * @tc.desc: SetStorageRef/GetStorageRef
213 * @tc.type: FUNC
214 */
215 HWTEST_F(PictureInPictureOptionTest, StorageRef, Function | SmallTest | Level2)
216 {
217 int num = 0;
218 napi_ref ref = reinterpret_cast<napi_ref>(&num);
219 ASSERT_NE(nullptr, ref);
220 sptr<PipOption> option = sptr<PipOption>::MakeSptr();
221 option->SetStorageRef(ref);
222 ASSERT_EQ(option->GetStorageRef(), ref);
223 }
224
225 /**
226 * @tc.name: TypeNodeEnabled
227 * @tc.desc: SetTypeNodeEnabled/IsTypeNodeEnabled
228 * @tc.type: FUNC
229 */
230 HWTEST_F(PictureInPictureOptionTest, TypeNodeEnabled, TestSize.Level1)
231 {
232 sptr<PipOption> option = sptr<PipOption>::MakeSptr();
233 option->SetTypeNodeEnabled(true);
234 ASSERT_TRUE(option->IsTypeNodeEnabled());
235 option->SetTypeNodeEnabled(false);
236 ASSERT_TRUE(!option->IsTypeNodeEnabled());
237 }
238
239 /**
240 * @tc.name: GetPiPTemplateInfo
241 * @tc.desc: GetPiPTemplateInfo/GetPipPriority
242 * @tc.type: FUNC
243 */
244 HWTEST_F(PictureInPictureOptionTest, GetPiPTemplateInfo, TestSize.Level1)
245 {
246 sptr<PipOption> option = new PipOption();
247 uint32_t pipTypeTemplate = 5;
248 uint32_t testValue = 0;
249 ASSERT_EQ(testValue, option->GetPipPriority(pipTypeTemplate));
250 ASSERT_EQ(testValue, option->GetPipPriority(pipTypeTemplate = 3));
251 ASSERT_EQ(testValue, option->GetPipPriority(pipTypeTemplate = 0));
252 ASSERT_EQ(testValue = 1, option->GetPipPriority(pipTypeTemplate = 1));
253 PiPTemplateInfo pipTemplateInfo;
254 option->SetDefaultWindowSizeType(testValue = 2);
255 option->GetPiPTemplateInfo(pipTemplateInfo);
256 ASSERT_EQ(testValue, pipTemplateInfo.defaultWindowSizeType);
257 }
258 } // namespace
259 } // namespace Rosen
260 } // namespace OHOS