• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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     option->SetNodeControllerRef(nullptr);
68     option->SetTypeNodeRef(nullptr);
69     option->SetStorageRef(nullptr);
70     option->ClearNapiRefs(nullptr);
71     ASSERT_EQ(nullptr, option->GetNodeControllerRef());
72     ASSERT_EQ(nullptr, option->GetTypeNodeRef());
73     ASSERT_EQ(nullptr, option->GetStorageRef());
74 }
75 
76 /**
77  * @tc.name: Context
78  * @tc.desc: SetContext/GetContext
79  * @tc.type: FUNC
80  */
81 HWTEST_F(PictureInPictureOptionTest, Context, Function | SmallTest | Level2)
82 {
83     void* contextPtr = nullptr;
84     sptr<PipOption> option = new PipOption();
85     option->SetContext(contextPtr);
86     ASSERT_EQ(contextPtr, option->GetContext());
87 }
88 
89 /**
90  * @tc.name: PipTemplate
91  * @tc.desc: SetPipTemplate/GetPipTemplate
92  * @tc.type: FUNC
93  */
94 HWTEST_F(PictureInPictureOptionTest, PipTemplate, Function | SmallTest | Level2)
95 {
96     sptr<PipOption> option = new PipOption();
97     option->SetPipTemplate(100);
98     ASSERT_EQ(100, option->GetPipTemplate());
99 }
100 
101 /**
102  * @tc.name: PiPControlStatus
103  * @tc.desc: SetPiPControlStatus/GetControlStatus
104  * @tc.type: FUNC
105  */
106 HWTEST_F(PictureInPictureOptionTest, SetPiPControlStatus, Function | SmallTest | Level2)
107 {
108     auto option = sptr<PipOption>::MakeSptr();
109     ASSERT_NE(nullptr, option);
110     auto controlType = PiPControlType::VIDEO_PLAY_PAUSE;
111     auto status = PiPControlStatus::PLAY;
112     option->SetPiPControlStatus(controlType, status);
113     controlType = PiPControlType::END;
114     option->SetPiPControlStatus(controlType, status);
115     ASSERT_NE(0, option->GetControlStatus().size());
116 }
117 
118 /**
119  * @tc.name: PiPControlEnable
120  * @tc.desc: SetPiPControlEnabled/GetControlEnable
121  * @tc.type: FUNC
122  */
123 HWTEST_F(PictureInPictureOptionTest, SetPiPControlEnabled, Function | SmallTest | Level2)
124 {
125     auto option = sptr<PipOption>::MakeSptr();
126     ASSERT_NE(nullptr, option);
127     auto controlType = PiPControlType::VIDEO_PLAY_PAUSE;
128     auto enabled = PiPControlStatus::ENABLED;
129     option->SetPiPControlEnabled(controlType, enabled);
130     controlType = PiPControlType::END;
131     option->SetPiPControlEnabled(controlType, enabled);
132     ASSERT_NE(0, option->GetControlEnable().size());
133 }
134 
135 /**
136  * @tc.name: NavigationId
137  * @tc.desc: SetNavigationId/GetNavigationId
138  * @tc.type: FUNC
139  */
140 HWTEST_F(PictureInPictureOptionTest, NavigationId, Function | SmallTest | Level2)
141 {
142     sptr<PipOption> option = new PipOption();
143     std::string navigationId = "abc";
144     option->SetNavigationId(navigationId);
145     ASSERT_EQ(navigationId, option->GetNavigationId());
146 }
147 
148 /**
149  * @tc.name: ControlGroup
150  * @tc.desc: SetControlGroup/GetControlGroup
151  * @tc.type: FUNC
152  */
153 HWTEST_F(PictureInPictureOptionTest, SetGetControlGroupTest, Function | SmallTest | Level2)
154 {
155     sptr<PipOption> option = new PipOption();
156     std::vector<std::uint32_t> controlGroup;
157     controlGroup.push_back(static_cast<uint32_t>(PiPControlGroup::VIDEO_CALL_MICROPHONE_SWITCH));
158     controlGroup.push_back(static_cast<uint32_t>(PiPControlGroup::VIDEO_CALL_HANG_UP_BUTTON));
159     controlGroup.push_back(static_cast<uint32_t>(PiPControlGroup::VIDEO_CALL_CAMERA_SWITCH));
160     option->SetControlGroup(controlGroup);
161     ASSERT_NE(option->GetControlGroup().size(), 0);
162 }
163 
164 /**
165  * @tc.name: ContentSize
166  * @tc.desc: SetContentSize/GetContentSize
167  * @tc.type: FUNC
168  */
169 HWTEST_F(PictureInPictureOptionTest, ContentSize, Function | SmallTest | Level2)
170 {
171     sptr<PipOption> option = new PipOption();
172     uint32_t width = 800;
173     uint32_t height = 600;
174     option->SetContentSize(width, height);
175     uint32_t w = 0;
176     uint32_t h = 0;
177     option->GetContentSize(w, h);
178     ASSERT_EQ(width, w);
179     ASSERT_EQ(height, h);
180 }
181 
182 /**
183  * @tc.name: NodeController
184  * @tc.desc: SetNodeControllerRef/GetNodeControllerRef
185  * @tc.type: FUNC
186  */
187 HWTEST_F(PictureInPictureOptionTest, NodeController, Function | SmallTest | Level2)
188 {
189     sptr<PipOption> option = sptr<PipOption>::MakeSptr();
190     option->SetNodeControllerRef(nullptr);
191     ASSERT_EQ(option->GetNodeControllerRef(), nullptr);
192 }
193 
194 /**
195  * @tc.name: TypeNodeRef
196  * @tc.desc: SetTypeNodeRef/GetTypeNodeRef
197  * @tc.type: FUNC
198  */
199 HWTEST_F(PictureInPictureOptionTest, TypeNodeRef, Function | SmallTest | Level2)
200 {
201     sptr<PipOption> option = sptr<PipOption>::MakeSptr();
202     option->SetTypeNodeRef(nullptr);
203     ASSERT_EQ(option->GetTypeNodeRef(), nullptr);
204 }
205 
206 /**
207  * @tc.name: StorageRef
208  * @tc.desc: SetStorageRef/GetStorageRef
209  * @tc.type: FUNC
210  */
211 HWTEST_F(PictureInPictureOptionTest, StorageRef, Function | SmallTest | Level2)
212 {
213     int num = 0;
214     napi_ref ref = reinterpret_cast<napi_ref>(&num);
215     ASSERT_NE(nullptr, ref);
216     sptr<PipOption> option = sptr<PipOption>::MakeSptr();
217     option->SetStorageRef(ref);
218     ASSERT_EQ(option->GetStorageRef(), ref);
219 }
220 
221 /**
222  * @tc.name: GetPipContentCallbackRef
223  * @tc.desc: RegisterPipContentListenerWithType/GetPipContentCallbackRef
224  * @tc.type: FUNC
225  */
226 HWTEST_F(PictureInPictureOptionTest, GetPipContentCallbackRef, Function | SmallTest | Level2)
227 {
228     sptr<PipOption> option = sptr<PipOption>::MakeSptr();
229     option->RegisterPipContentListenerWithType("nodeUpdate", nullptr);
230     ASSERT_EQ(option->GetPipContentCallbackRef("nodeUpdate"), nullptr);
231 }
232 
233 /**
234  * @tc.name: TypeNodeEnabled
235  * @tc.desc: SetTypeNodeEnabled/IsTypeNodeEnabled
236  * @tc.type: FUNC
237  */
238 HWTEST_F(PictureInPictureOptionTest, TypeNodeEnabled, Function | SmallTest | Level2)
239 {
240     sptr<PipOption> option = sptr<PipOption>::MakeSptr();
241     option->SetTypeNodeEnabled(true);
242     ASSERT_TRUE(option->IsTypeNodeEnabled());
243     option->SetTypeNodeEnabled(false);
244     ASSERT_TRUE(!option->IsTypeNodeEnabled());
245 }
246 } // namespace
247 } // namespace Rosen
248 } // namespace OHOS