1 /*
2 * Copyright (c) 2024 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
18 #define private public
19 #include "auto_fill_manager_util.h"
20 #undef private
21
22 using namespace testing;
23 using namespace testing::ext;
24 using PopupDimensionUnit = OHOS::AbilityRuntime::AutoFill::PopupDimensionUnit;
25 using PopupPlacement = OHOS::AbilityRuntime::AutoFill::PopupPlacement;
26 namespace OHOS {
27 namespace AAFwk {
28 namespace {
29 AbilityRuntime::AutoFill::PopupSize popupSize {
30 .unit = AbilityRuntime::AutoFill::PopupDimensionUnit::PX,
31 .width = 3.0,
32 .height = 4.0
33 };
34
35 AbilityRuntime::AutoFill::PopupOffset popupOffset {
36 .unit = AbilityRuntime::AutoFill::PopupDimensionUnit::VP,
37 .deltaX = 6.1,
38 .deltaY = 7.1
39 };
40
41 AbilityRuntime::AutoFill::PopupLength popupLength {
42 .unit = AbilityRuntime::AutoFill::PopupDimensionUnit::FP,
43 .length = 10.0
44 };
45
46 AbilityRuntime::AutoFill::PopupLength arrowLength {
47 .unit = AbilityRuntime::AutoFill::PopupDimensionUnit::PERCENT,
48 .length = 20.0
49 };
50
__anonb32bb60c0202(const std::string &str) 51 std::function<void(std::string)> stringValue = [](const std::string &str) {
52 std::cout << "string value" << str << std::endl;
53 };
54 }
55 class AutoFillManagerUtilTest : public testing::Test {
56 public:
57 static void SetUpTestCase();
58 static void TearDownTestCase();
59 void SetUp() override;
60 void TearDown() override;
61 };
62
SetUpTestCase(void)63 void AutoFillManagerUtilTest::SetUpTestCase(void)
64 {}
65
TearDownTestCase(void)66 void AutoFillManagerUtilTest::TearDownTestCase(void)
67 {}
68
SetUp()69 void AutoFillManagerUtilTest::SetUp()
70 {}
71
TearDown()72 void AutoFillManagerUtilTest::TearDown()
73 {}
74
75 /**
76 * @tc.name: ConvertToPopupUIExtensionConfig_0100
77 * @tc.desc: ConvertToPopupUIExtensionConfig
78 */
79 HWTEST_F(AutoFillManagerUtilTest, ConvertToPopupUIExtensionConfig_0100, TestSize.Level1)
80 {
81 GTEST_LOG_(INFO) << "AutoFillManagerUtilTest, ConvertToPopupUIExtensionConfig_0100, TestSize.Level1";
82 auto popup = std::make_shared<AbilityRuntime::AutoFillManagerUtil>();
83
84 AbilityRuntime::AutoFill::AutoFillCustomConfig config = {
85 true,
86 "password123456",
87 1,
88 true,
89 true,
90 popupSize,
91 popupOffset,
92 popupLength,
93 arrowLength,
94 AbilityRuntime::AutoFill::PopupPlacement::NONE,
95 0xffffff,
96 0xffffff,
97 std::move(stringValue)
98 };
99
100 Ace::CustomPopupUIExtensionConfig popupConfig;
101 popup->ConvertToPopupUIExtensionConfig(config, popupConfig);
102
103 EXPECT_EQ(config.isShowInSubWindow, popupConfig.isShowInSubWindow);
104 EXPECT_EQ(config.inspectorId, popupConfig.inspectorId);
105 EXPECT_EQ(config.nodeId, popupConfig.nodeId);
106 EXPECT_EQ(config.isAutoCancel, popupConfig.isAutoCancel);
107 EXPECT_EQ(config.isEnableArrow, popupConfig.isEnableArrow);
108 EXPECT_TRUE(popupConfig.targetSize.has_value());
109 EXPECT_TRUE(popupConfig.targetOffset.has_value());
110 EXPECT_TRUE(popupConfig.targetSpace.has_value());
111 EXPECT_TRUE(popupConfig.arrowOffset.has_value());
112 EXPECT_TRUE(popupConfig.placement.has_value());
113 EXPECT_EQ(config.backgroundColor, popupConfig.backgroundColor);
114 EXPECT_EQ(config.maskColor, popupConfig.maskColor);
115 EXPECT_NE(popupConfig.onStateChange, NULL);
116 }
117
118 /**
119 * @tc.name: ConvertPopupUnit_0100
120 * @tc.desc: ConvertPopupUnit
121 */
122 HWTEST_F(AutoFillManagerUtilTest, ConvertPopupUnit_0100, TestSize.Level1)
123 {
124 GTEST_LOG_(INFO) << "AutoFillManagerUtilTest, ConvertPopupUnit_0100, TestSize.Level1";
125 auto popup = std::make_shared<AbilityRuntime::AutoFillManagerUtil>();
126
127 EXPECT_EQ(static_cast<int32_t>(popup->ConvertPopupUnit(PopupDimensionUnit::PX)),
128 static_cast<int32_t>(AbilityRuntime::AutoFill::PopupDimensionUnit::PX));
129
130 EXPECT_EQ(static_cast<int32_t>(popup->ConvertPopupUnit(PopupDimensionUnit::VP)),
131 static_cast<int32_t>(AbilityRuntime::AutoFill::PopupDimensionUnit::VP));
132
133 EXPECT_EQ(static_cast<int32_t>(popup->ConvertPopupUnit(PopupDimensionUnit::FP)),
134 static_cast<int32_t>(AbilityRuntime::AutoFill::PopupDimensionUnit::FP));
135
136 EXPECT_EQ(static_cast<int32_t>(popup->ConvertPopupUnit(PopupDimensionUnit::PERCENT)),
137 static_cast<int32_t>(AbilityRuntime::AutoFill::PopupDimensionUnit::PERCENT));
138
139 EXPECT_EQ(static_cast<int32_t>(popup->ConvertPopupUnit(PopupDimensionUnit::LPX)),
140 static_cast<int32_t>(AbilityRuntime::AutoFill::PopupDimensionUnit::LPX));
141
142 EXPECT_EQ(static_cast<int32_t>(popup->ConvertPopupUnit(PopupDimensionUnit::AUTO)),
143 static_cast<int32_t>(AbilityRuntime::AutoFill::PopupDimensionUnit::AUTO));
144
145 EXPECT_EQ(static_cast<int32_t>(popup->ConvertPopupUnit(PopupDimensionUnit::CALC)),
146 static_cast<int32_t>(AbilityRuntime::AutoFill::PopupDimensionUnit::CALC));
147 }
148
149 /**
150 * @tc.name: ConvertPopupPlacement_0100
151 * @tc.desc: ConvertPopupPlacement
152 */
153 HWTEST_F(AutoFillManagerUtilTest, ConvertPopupPlacement_0100, TestSize.Level1)
154 {
155 GTEST_LOG_(INFO) << "AutoFillManagerUtilTest, ConvertPopupPlacement_0100, TestSize.Level1";
156 auto popup = std::make_shared<AbilityRuntime::AutoFillManagerUtil>();
157
158 EXPECT_EQ(static_cast<int32_t>(popup->ConvertPopupPlacement(PopupPlacement::LEFT)),
159 static_cast<int32_t>(AbilityRuntime::AutoFill::PopupPlacement::LEFT));
160
161 EXPECT_EQ(static_cast<int32_t>(popup->ConvertPopupPlacement(PopupPlacement::RIGHT)),
162 static_cast<int32_t>(AbilityRuntime::AutoFill::PopupPlacement::RIGHT));
163
164 EXPECT_EQ(static_cast<int32_t>(popup->ConvertPopupPlacement(PopupPlacement::TOP_LEFT)),
165 static_cast<int32_t>(AbilityRuntime::AutoFill::PopupPlacement::TOP_LEFT));
166
167 EXPECT_EQ(static_cast<int32_t>(popup->ConvertPopupPlacement(PopupPlacement::TOP_RIGHT)),
168 static_cast<int32_t>(AbilityRuntime::AutoFill::PopupPlacement::TOP_RIGHT));
169
170 EXPECT_EQ(static_cast<int32_t>(popup->ConvertPopupPlacement(PopupPlacement::BOTTOM_LEFT)),
171 static_cast<int32_t>(AbilityRuntime::AutoFill::PopupPlacement::BOTTOM_LEFT));
172
173 EXPECT_EQ(static_cast<int32_t>(popup->ConvertPopupPlacement(PopupPlacement::BOTTOM_RIGHT)),
174 static_cast<int32_t>(AbilityRuntime::AutoFill::PopupPlacement::BOTTOM_RIGHT));
175
176 EXPECT_EQ(static_cast<int32_t>(popup->ConvertPopupPlacement(PopupPlacement::LEFT_TOP)),
177 static_cast<int32_t>(AbilityRuntime::AutoFill::PopupPlacement::LEFT_TOP));
178
179 EXPECT_EQ(static_cast<int32_t>(popup->ConvertPopupPlacement(PopupPlacement::LEFT_BOTTOM)),
180 static_cast<int32_t>(AbilityRuntime::AutoFill::PopupPlacement::LEFT_BOTTOM));
181
182 EXPECT_EQ(static_cast<int32_t>(popup->ConvertPopupPlacement(PopupPlacement::RIGHT_TOP)),
183 static_cast<int32_t>(AbilityRuntime::AutoFill::PopupPlacement::RIGHT_TOP));
184
185 EXPECT_EQ(static_cast<int32_t>(popup->ConvertPopupPlacement(PopupPlacement::RIGHT_BOTTOM)),
186 static_cast<int32_t>(AbilityRuntime::AutoFill::PopupPlacement::RIGHT_BOTTOM));
187 }
188 } // namespace AppExecFwk
189 } // namespace OHOS