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: 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 GetResourceConfiguration()82 ResourceConfiguration GetResourceConfiguration() const override 83 { 84 return ResourceConfiguration(); 85 } 86 87 MOCK_METHOD(void, Initialize, (), (override)); 88 MOCK_METHOD(void, Destroy, (), (override)); 89 MOCK_METHOD(int32_t, GetInstanceId, (), (const, override)); 90 MOCK_METHOD(std::string, GetHostClassName, (), (const, override)); 91 92 MOCK_METHOD(RefPtr<Frontend>, GetFrontend, (), (const, override)); 93 MOCK_METHOD(RefPtr<AssetManager>, GetAssetManager, (), (const, override)); 94 MOCK_METHOD(RefPtr<PlatformResRegister>, GetPlatformResRegister, (), (const, override)); 95 MOCK_METHOD(int32_t, GetViewWidth, (), (const, override)); 96 MOCK_METHOD(int32_t, GetViewHeight, (), (const, override)); 97 MOCK_METHOD(int32_t, GetViewPosX, (), (const, override)); 98 MOCK_METHOD(int32_t, GetViewPosY, (), (const, override)); 99 MOCK_METHOD(uint32_t, GetWindowId, (), (const, override)); 100 MOCK_METHOD(void*, GetView, (), (const, override)); 101 MOCK_METHOD(RefPtr<AceView>, GetAceView, (), (const, override)); 102 103 MOCK_METHOD(void, DumpHeapSnapshot, (bool isPrivate), (override)); 104 MOCK_METHOD(void, TriggerGarbageCollection, (), (override)); 105 MOCK_METHOD(bool, WindowIsShow, (), (const, override)); 106 static RefPtr<MockContainer> container_; 107 108 private: 109 RefPtr<TaskExecutor> taskExecutor_; 110 RefPtr<PipelineBase> pipelineContext_; 111 bool isFormRender_ = false; 112 bool isUIExtensionWindow_ = false; 113 bool isScenceBoardWindow_ = false; 114 RefPtr<DisplayInfo> displayInfo_ = MakeRefPtr<DisplayInfo>(); 115 }; 116 } // namespace OHOS::Ace 117 #endif // FOUNDATION_ACE_TEST_MOCK_CORE_COMMON_MOCK_CONTAINER_H 118