• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2022 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 #ifndef FOUNDATION_ACE_TEST_MOCK_CORE_COMMON_MOCK_CONTAINER_H
17 #define FOUNDATION_ACE_TEST_MOCK_CORE_COMMON_MOCK_CONTAINER_H
18 
19 #include "gmock/gmock.h"
20 
21 #include "core/common/ace_view.h"
22 #include "core/common/container.h"
23 
24 namespace OHOS::Ace {
25 class MockContainer final : public Container {
26     DECLARE_ACE_TYPE(MockContainer, Container);
27 
28 public:
pipelineContext_(pipelineContext)29     explicit MockContainer(RefPtr<PipelineBase> pipelineContext = nullptr) : pipelineContext_(pipelineContext) {}
30 
GetPipelineContext()31     RefPtr<PipelineBase> GetPipelineContext() const override
32     {
33         return pipelineContext_;
34     }
35 
GetTaskExecutor()36     RefPtr<TaskExecutor> GetTaskExecutor() const override
37     {
38         return taskExecutor_;
39     }
40 
GetMockDisplayInfo()41     RefPtr<DisplayInfo> GetMockDisplayInfo()
42     {
43         return displayInfo_;
44     }
45 
46     static void SetUp();
47     static void TearDown();
48     static RefPtr<MockContainer> Current();
49     static RefPtr<MockContainer> GetContainer(int32_t containerId);
50     void SetDisplayInfo(RefPtr<DisplayInfo> displayInfo);
51 
SetIsFormRender(bool isFormRender)52     void SetIsFormRender(bool isFormRender) override
53     {
54         isFormRender_ = isFormRender;
55     }
56 
IsFormRender()57     bool IsFormRender() const override
58     {
59         return isFormRender_;
60     }
61 
IsUIExtensionWindow()62     bool IsUIExtensionWindow() override
63     {
64         return isUIExtensionWindow_;
65     }
66 
SetIsUIExtensionWindow(bool isUIExtensionWindow)67     void SetIsUIExtensionWindow(bool isUIExtensionWindow)
68     {
69         isUIExtensionWindow_ = isUIExtensionWindow;
70     }
71 
IsScenceBoardWindow()72     bool IsScenceBoardWindow() override
73     {
74         return isScenceBoardWindow_;
75     }
76 
SetIsScenceBoardWindow(bool isScenceBoardWindow)77     void SetIsScenceBoardWindow(bool isScenceBoardWindow)
78     {
79         isScenceBoardWindow_ = isScenceBoardWindow;
80     }
81 
82     MOCK_METHOD(void, Initialize, (), (override));
83     MOCK_METHOD(void, Destroy, (), (override));
84     MOCK_METHOD(int32_t, GetInstanceId, (), (const, override));
85     MOCK_METHOD(std::string, GetHostClassName, (), (const, override));
86 
87     MOCK_METHOD(RefPtr<Frontend>, GetFrontend, (), (const, override));
88     MOCK_METHOD(RefPtr<AssetManager>, GetAssetManager, (), (const, override));
89     MOCK_METHOD(RefPtr<PlatformResRegister>, GetPlatformResRegister, (), (const, override));
90     MOCK_METHOD(int32_t, GetViewWidth, (), (const, override));
91     MOCK_METHOD(int32_t, GetViewHeight, (), (const, override));
92     MOCK_METHOD(int32_t, GetViewPosX, (), (const, override));
93     MOCK_METHOD(int32_t, GetViewPosY, (), (const, override));
94     MOCK_METHOD(uint32_t, GetWindowId, (), (const, override));
95     MOCK_METHOD(void*, GetView, (), (const, override));
96     MOCK_METHOD(RefPtr<AceView>, GetAceView, (), (const, override));
97 
98     MOCK_METHOD(void, DumpHeapSnapshot, (bool isPrivate), (override));
99     MOCK_METHOD(void, TriggerGarbageCollection, (), (override));
100     MOCK_METHOD(bool, WindowIsShow, (), (const, override));
101     static RefPtr<MockContainer> container_;
102 
103 private:
104     RefPtr<TaskExecutor> taskExecutor_;
105     RefPtr<PipelineBase> pipelineContext_;
106     bool isFormRender_ = false;
107     bool isUIExtensionWindow_ = false;
108     bool isScenceBoardWindow_ = false;
109     RefPtr<DisplayInfo> displayInfo_ = MakeRefPtr<DisplayInfo>();
110 };
111 } // namespace OHOS::Ace
112 #endif // FOUNDATION_ACE_TEST_MOCK_CORE_COMMON_MOCK_CONTAINER_H
113