1 /*
2 * Copyright (c) 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 "root_scene_session.h"
17 #include <gtest/gtest.h>
18 #include "session_info.h"
19
20 using namespace testing;
21 using namespace testing::ext;
22
23 namespace OHOS {
24 namespace Rosen {
25 class RootSceneSessionTest : public testing::Test {
26 public:
27 static void SetUpTestCase();
28 static void TearDownTestCase();
29 void SetUp() override;
30 void TearDown() override;
31 };
32
LoadContentFuncTest(const std::string &,napi_env,napi_value,AbilityRuntime::Context *)33 void LoadContentFuncTest(const std::string&, napi_env, napi_value, AbilityRuntime::Context*)
34 {
35 }
36
SetUpTestCase()37 void RootSceneSessionTest::SetUpTestCase()
38 {
39 }
40
TearDownTestCase()41 void RootSceneSessionTest::TearDownTestCase()
42 {
43 }
44
SetUp()45 void RootSceneSessionTest::SetUp()
46 {
47 }
48
TearDown()49 void RootSceneSessionTest::TearDown()
50 {
51 }
52
53 namespace {
54 /**
55 * @tc.name: SetLoadContentFunc
56 * @tc.desc: test function : SetLoadContentFunc
57 * @tc.type: FUNC
58 */
59 HWTEST_F(RootSceneSessionTest, SetLoadContentFunc, Function | SmallTest | Level1)
60 {
61 RootSceneSession rootSceneSession;
62 RootSceneSession::LoadContentFunc loadContentFunc_ = LoadContentFuncTest;
63 rootSceneSession.SetLoadContentFunc(loadContentFunc_);
64 ASSERT_FALSE(rootSceneSession.IsVisible());
65 }
66
67 /**
68 * @tc.name: LoadContentFunc
69 * @tc.desc: test function : LoadContentFunc
70 * @tc.type: FUNC
71 */
72 HWTEST_F(RootSceneSessionTest, LoadContentFunc, Function | SmallTest | Level1)
73 {
74 RootSceneSession rootSceneSession;
75 std::string strTest("LoadContentFuncTest");
76 napi_env nativeEnv_ = nullptr;
77 napi_value nativeValue_ = nullptr;
78 AbilityRuntime::Context* conText_ = nullptr;
79 rootSceneSession.LoadContent(strTest, nativeEnv_, nativeValue_, conText_);
80 ASSERT_FALSE(rootSceneSession.IsVisible());
81 }
82
83 /**
84 * @tc.name: LoadContent
85 * @tc.desc: test function : LoadContent
86 * @tc.type: FUNC
87 */
88 HWTEST_F(RootSceneSessionTest, LoadContent, Function | SmallTest | Level1)
89 {
90 RootSceneSession rootSceneSession;
91 std::string strTest("LoadContentFuncTest");
92 napi_env nativeEnv_ = nullptr;
93 napi_value nativeValue_ = nullptr;
94 AbilityRuntime::Context* conText_ = nullptr;
95 RootSceneSession::LoadContentFunc loadContentFunc_ = LoadContentFuncTest;
96 rootSceneSession.SetLoadContentFunc(loadContentFunc_);
97 rootSceneSession.LoadContent(strTest, nativeEnv_, nativeValue_, conText_);
98 ASSERT_FALSE(rootSceneSession.IsVisible());
99 }
100
101 /**
102 * @tc.name: GetSystemAvoidAreaForRoot
103 * @tc.desc: test function : GetSystemAvoidAreaForRoot
104 * @tc.type: FUNC
105 */
106 HWTEST_F(RootSceneSessionTest, GetSystemAvoidAreaForRoot, Function | SmallTest | Level1)
107 {
108 RootSceneSession rootSceneSession;
109 AvoidArea avoidArea;
110 WSRect rect;
111 rootSceneSession.GetSystemAvoidAreaForRoot(rect, avoidArea);
112 EXPECT_TRUE(avoidArea.isEmptyAvoidArea());
113 }
114
115 /**
116 * @tc.name: GetKeyboardAvoidAreaForRoot
117 * @tc.desc: test function : GetKeyboardAvoidAreaForRoot
118 * @tc.type: FUNC
119 */
120 HWTEST_F(RootSceneSessionTest, GetKeyboardAvoidAreaForRoot, Function | SmallTest | Level1)
121 {
122 RootSceneSession rootSceneSession;
123 AvoidArea avoidArea;
124 WSRect rect;
125 rootSceneSession.GetKeyboardAvoidAreaForRoot(rect, avoidArea);
126 EXPECT_TRUE(avoidArea.isEmptyAvoidArea());
127 }
128
129 /**
130 * @tc.name: GetAINavigationBarAreaForRoot
131 * @tc.desc: test function : GetAINavigationBarAreaForRoot
132 * @tc.type: FUNC
133 */
134 HWTEST_F(RootSceneSessionTest, GetAINavigationBarAreaForRoot, Function | SmallTest | Level1)
135 {
136 RootSceneSession rootSceneSession;
137 AvoidArea avoidArea;
138 WSRect rect;
139 rootSceneSession.GetAINavigationBarAreaForRoot(rect, avoidArea);
140 EXPECT_TRUE(avoidArea.isEmptyAvoidArea());
141 }
142
143 /**
144 * @tc.name: GetCutoutAvoidAreaForRoot
145 * @tc.desc: test function : GetCutoutAvoidAreaForRoot
146 * @tc.type: FUNC
147 */
148 HWTEST_F(RootSceneSessionTest, GetCutoutAvoidAreaForRoot, Function | SmallTest | Level1)
149 {
150 RootSceneSession rootSceneSession;
151 AvoidArea avoidArea;
152 WSRect rect;
153 rootSceneSession.GetCutoutAvoidAreaForRoot(rect, avoidArea);
154 EXPECT_TRUE(avoidArea.isEmptyAvoidArea());
155 }
156
157 /**
158 * @tc.name: SetRootSessionRect
159 * @tc.desc: test function : SetRootSessionRect
160 * @tc.type: FUNC
161 */
162 HWTEST_F(RootSceneSessionTest, SetRootSessionRect, Function | SmallTest | Level1)
163 {
164 RootSceneSession rootSceneSession;
165 AvoidArea avoidArea;
166 WSRect rect;
167 rootSceneSession.SetRootSessionRect(rect);
168 ASSERT_EQ(rootSceneSession.winRect_, rect);
169 }
170
171 /**
172 * @tc.name: UpdateAvoidArea
173 * @tc.desc: test function : UpdateAvoidArea
174 * @tc.type: FUNC
175 */
176 HWTEST_F(RootSceneSessionTest, UpdateAvoidArea, Function | SmallTest | Level1)
177 {
178 RootSceneSession rootSceneSession;
179 AvoidArea avoidArea;
180 auto ret = rootSceneSession.UpdateAvoidArea(sptr<AvoidArea>::MakeSptr(avoidArea), AvoidAreaType::TYPE_SYSTEM);
181 ASSERT_EQ(WSError::WS_ERROR_NULLPTR, ret);
182 }
183 }
184 }
185 }