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