• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2022-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 "test/mock/core/common/mock_container.h"
17 
18 #include "core/common/ace_engine.h"
19 #include "core/common/container.h"
20 
21 namespace OHOS::Ace {
22 namespace {
23 int32_t g_id = 0;
24 } // namespace
25 
26 RefPtr<MockContainer> MockContainer::container_;
27 ColorMode MockContainer::mockColorMode_ = ColorMode::LIGHT;
MaybeRelease()28 bool Frontend::MaybeRelease()
29 {
30     return AceType::MaybeRelease();
31 }
32 
33 Frontend::~Frontend() = default;
34 
CurrentId()35 int32_t Container::CurrentId()
36 {
37     return g_id;
38 }
39 
SafelyId()40 int32_t Container::SafelyId()
41 {
42     return g_id;
43 }
44 
CurrentIdSafely()45 int32_t Container::CurrentIdSafely()
46 {
47     return g_id;
48 }
49 
CurrentIdSafelyWithCheck()50 int32_t Container::CurrentIdSafelyWithCheck()
51 {
52     return g_id;
53 }
54 
GetActive()55 RefPtr<Container> Container::GetActive()
56 {
57     RefPtr<Container> activeContainer;
58     return activeContainer;
59 }
60 
CurrentTaskExecutor()61 RefPtr<TaskExecutor> Container::CurrentTaskExecutor()
62 {
63     return MockContainer::Current()->GetTaskExecutor();
64 }
65 
CurrentTaskExecutorSafely()66 RefPtr<TaskExecutor> Container::CurrentTaskExecutorSafely()
67 {
68     return MockContainer::Current()->GetTaskExecutor();
69 }
70 
CurrentTaskExecutorSafelyWithCheck()71 RefPtr<TaskExecutor> Container::CurrentTaskExecutorSafelyWithCheck()
72 {
73     return MockContainer::Current()->GetTaskExecutor();
74 }
75 
UpdateCurrent(int32_t id)76 void Container::UpdateCurrent(int32_t id)
77 {
78     g_id = id;
79 }
80 
Current()81 RefPtr<Container> Container::Current()
82 {
83     return MockContainer::Current();
84 }
85 
CurrentSafely()86 RefPtr<Container> Container::CurrentSafely()
87 {
88     return MockContainer::Current();
89 }
90 
CurrentSafelyWithCheck()91 RefPtr<Container> Container::CurrentSafelyWithCheck()
92 {
93     return MockContainer::Current();
94 }
95 
Dump(const std::vector<std::string> &,std::vector<std::string> &)96 bool Container::Dump(const std::vector<std::string>& /* params */, std::vector<std::string>& /* info */)
97 {
98     return true;
99 }
100 
SetUp()101 void MockContainer::SetUp()
102 {
103     container_ = AceType::MakeRefPtr<MockContainer>();
104 }
105 
TearDown()106 void MockContainer::TearDown()
107 {
108     container_ = nullptr;
109 }
110 
Current()111 RefPtr<MockContainer> MockContainer::Current()
112 {
113     return container_;
114 }
115 
GetContainer(int32_t containerId)116 RefPtr<Container> Container::GetContainer(int32_t containerId)
117 {
118     return MockContainer::Current();
119 }
120 
CurrentColorMode()121 ColorMode Container::CurrentColorMode()
122 {
123     return MockContainer::mockColorMode_;
124 }
125 
SetMockColorMode(ColorMode mode)126 void MockContainer::SetMockColorMode(ColorMode mode)
127 {
128     mockColorMode_ = mode;
129 }
130 
GetMockColorMode()131 ColorMode MockContainer::GetMockColorMode()
132 {
133     return mockColorMode_;
134 }
135 
RequestAutoFill(const RefPtr<NG::FrameNode> & node,AceAutoFillType autoFillType,bool isNewPassWord,bool & isPopup,uint32_t & autoFillSessionId,bool isNative,const std::function<void ()> & onFinish,const std::function<void ()> & onUIExtNodeBindingCompleted)136 int32_t MockContainer::RequestAutoFill(const RefPtr<NG::FrameNode>& node, AceAutoFillType autoFillType,
137     bool isNewPassWord, bool& isPopup, uint32_t& autoFillSessionId, bool isNative,
138     const std::function<void()>& onFinish, const std::function<void()>& onUIExtNodeBindingCompleted)
139 {
140     if (autoFillType == AceAutoFillType::ACE_USER_NAME) {
141         isPopup = true; // if TextInputType::USER_NAME
142     } else if (autoFillType == AceAutoFillType::ACE_PASSWORD || autoFillType == AceAutoFillType::ACE_NEW_PASSWORD) {
143         isPopup = false; // if TextInputType::VISIBLE_PASSWORD or TextInputType::NEW_PASSWORD
144     }
145     if (autoFillType == AceAutoFillType::ACE_PASSWORD) {
146         return AceAutoFillError::ACE_AUTO_FILL_SUCCESS; // cover DoProcessAutoFill
147     }
148     return isPopup ? AceAutoFillError::ACE_AUTO_FILL_SUCCESS : AceAutoFillError::ACE_AUTO_FILL_DEFAULT;
149 }
150 
SetDisplayInfo(RefPtr<DisplayInfo> displayInfo)151 void MockContainer::SetDisplayInfo(RefPtr<DisplayInfo> displayInfo)
152 {
153     displayInfo_ = displayInfo;
154 }
155 
GetDisplayInfo()156 RefPtr<DisplayInfo> Container::GetDisplayInfo()
157 {
158     return MockContainer::Current()->GetMockDisplayInfo();
159 }
160 
InitIsFoldable()161 void Container::InitIsFoldable() {}
162 
IsFoldable()163 bool Container::IsFoldable()
164 {
165     return MockContainer::Current()->GetMockDisplayInfo()->GetIsFoldable();
166 }
167 
GetCurrentFoldStatus()168 FoldStatus Container::GetCurrentFoldStatus()
169 {
170     return MockContainer::Current()->GetMockDisplayInfo()->GetFoldStatus();
171 }
172 
GetCurrentFoldCreaseRegion()173 std::vector<Rect> Container::GetCurrentFoldCreaseRegion()
174 {
175     return {};
176 }
177 
GetFoucsed()178 RefPtr<Container> Container::GetFoucsed()
179 {
180     RefPtr<Container> foucsContainer;
181     AceEngine::Get().NotifyContainers([&foucsContainer](const RefPtr<Container>& container) {
182         auto pipeline = container->GetPipelineContext();
183         if (pipeline && pipeline->IsWindowFocused()) {
184             foucsContainer = container;
185         }
186     });
187     return foucsContainer;
188 }
189 
IsNodeInKeyGuardWindow(const RefPtr<NG::FrameNode> & node)190 bool Container::IsNodeInKeyGuardWindow(const RefPtr<NG::FrameNode>& node)
191 {
192     return false;
193 }
194 
GetKeyboardSafeArea()195 NG::SafeAreaInsets Container::GetKeyboardSafeArea()
196 {
197     return {};
198 }
199 
LessThanAPIVersion(PlatformVersion version)200 bool Container::LessThanAPIVersion(PlatformVersion version)
201 {
202     return static_cast<int32_t>(version) < 15
203                ? PipelineBase::GetCurrentContext() &&
204                      PipelineBase::GetCurrentContext()->GetMinPlatformVersion() < static_cast<int32_t>(version)
205                : LessThanAPITargetVersion(version);
206 }
GreatOrEqualAPIVersion(PlatformVersion version)207 bool Container::GreatOrEqualAPIVersion(PlatformVersion version)
208 {
209     return static_cast<int32_t>(version) < 15
210                ? PipelineBase::GetCurrentContext() &&
211                      PipelineBase::GetCurrentContext()->GetMinPlatformVersion() >= static_cast<int32_t>(version)
212                : GreatOrEqualAPITargetVersion(version);
213 }
214 
LessThanAPIVersionWithCheck(PlatformVersion version)215 bool Container::LessThanAPIVersionWithCheck(PlatformVersion version)
216 {
217     return static_cast<int32_t>(version) < 14
218                ? PipelineBase::GetCurrentContextSafelyWithCheck() &&
219                      PipelineBase::GetCurrentContextSafelyWithCheck()->GetMinPlatformVersion() <
220                          static_cast<int32_t>(version)
221                : LessThanAPITargetVersion(version);
222 }
223 
GreatOrEqualAPIVersionWithCheck(PlatformVersion version)224 bool Container::GreatOrEqualAPIVersionWithCheck(PlatformVersion version)
225 {
226     return static_cast<int32_t>(version) < 14
227                ? PipelineBase::GetCurrentContextSafelyWithCheck() &&
228                      PipelineBase::GetCurrentContextSafelyWithCheck()->GetMinPlatformVersion() >=
229                          static_cast<int32_t>(version)
230                : GreatOrEqualAPITargetVersion(version);
231 }
232 } // namespace OHOS::Ace
233