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 #include "core/pipeline/pipeline_base.h" 24 25 namespace OHOS::Ace { 26 class MockContainer final : public Container { 27 DECLARE_ACE_TYPE(MockContainer, Container); 28 29 public: pipelineContext_(pipelineContext)30 explicit MockContainer(RefPtr<PipelineBase> pipelineContext = nullptr) : pipelineContext_(pipelineContext) {} 31 GetPipelineContext()32 RefPtr<PipelineBase> GetPipelineContext() const override 33 { 34 return pipelineContext_; 35 } 36 GetTaskExecutor()37 RefPtr<TaskExecutor> GetTaskExecutor() const override 38 { 39 return taskExecutor_; 40 } 41 GetMockDisplayInfo()42 RefPtr<DisplayInfo> GetMockDisplayInfo() 43 { 44 return displayInfo_; 45 } 46 47 static void SetUp(); 48 static void SetUp(RefPtr<PipelineBase> pipelineContext); 49 static void TearDown(); 50 static RefPtr<MockContainer> Current(); 51 static RefPtr<MockContainer> GetContainer(int32_t containerId); 52 static void SetMockColorMode(ColorMode mode); 53 static ColorMode GetMockColorMode(); 54 void SetDisplayInfo(RefPtr<DisplayInfo> displayInfo); 55 SetIsFormRender(bool isFormRender)56 void SetIsFormRender(bool isFormRender) override 57 { 58 isFormRender_ = isFormRender; 59 } 60 IsFormRender()61 bool IsFormRender() const override 62 { 63 return isFormRender_; 64 } 65 IsUIExtensionWindow()66 bool IsUIExtensionWindow() override 67 { 68 return isUIExtensionWindow_; 69 } 70 SetIsUIExtensionWindow(bool isUIExtensionWindow)71 void SetIsUIExtensionWindow(bool isUIExtensionWindow) 72 { 73 isUIExtensionWindow_ = isUIExtensionWindow; 74 } 75 IsSceneBoardWindow()76 bool IsSceneBoardWindow() override 77 { 78 return isSceneBoardWindow_; 79 } 80 SetIsSceneBoardWindow(bool isSceneBoardWindow)81 void SetIsSceneBoardWindow(bool isSceneBoardWindow) 82 { 83 isSceneBoardWindow_ = isSceneBoardWindow; 84 } 85 IsCrossAxisWindow()86 bool IsCrossAxisWindow() 87 { 88 return isCrossAxisWindow_; 89 } 90 SetColorMode(ColorMode mode)91 void SetColorMode(ColorMode mode) override 92 { 93 mockColorMode_ = mode; 94 } 95 GetColorMode()96 ColorMode GetColorMode() const override 97 { 98 return mockColorMode_; 99 } 100 IsSubContainer()101 bool IsSubContainer() const override 102 { 103 return isSubContainer_; 104 } 105 IsDialogContainer()106 bool IsDialogContainer() const override 107 { 108 return isDialogContainer_; 109 } 110 IsFreeMultiWindow()111 bool IsFreeMultiWindow() const override 112 { 113 return isFreeMultiWindow_; 114 } 115 ResetContainer()116 void ResetContainer() 117 { 118 CHECK_NULL_VOID(container_); 119 container_->isFormRender_ = false; 120 container_->isUIExtensionWindow_ = false; 121 container_->isSubContainer_ = false; 122 container_->isSceneBoardWindow_ = false; 123 container_->isCrossAxisWindow_ = false; 124 container_->isFreeMultiWindow_ = false; 125 container_->SetApiTargetVersion(0); 126 UpdateCurrent(0); 127 } 128 129 int32_t RequestAutoFill(const RefPtr<NG::FrameNode>& node, AceAutoFillType autoFillType, bool isNewPassWord, 130 bool& isPopup, uint32_t& autoFillSessionId, bool isNative = true, 131 const std::function<void()>& onFinish = nullptr, 132 const std::function<void()>& onUIExtNodeBindingCompleted = nullptr) override; 133 GetResourceConfiguration()134 ResourceConfiguration GetResourceConfiguration() const override 135 { 136 return ResourceConfiguration(); 137 } 138 139 static bool IsNodeInKeyGuardWindow(const RefPtr<NG::FrameNode>& node); 140 141 MOCK_METHOD(void, Initialize, (), (override)); 142 MOCK_METHOD(void, Destroy, (), (override)); 143 MOCK_METHOD(int32_t, GetInstanceId, (), (const, override)); 144 MOCK_METHOD(std::string, GetHostClassName, (), (const, override)); 145 146 MOCK_METHOD(RefPtr<Frontend>, GetFrontend, (), (const, override)); 147 MOCK_METHOD(RefPtr<AssetManager>, GetAssetManager, (), (const, override)); 148 MOCK_METHOD(RefPtr<PlatformResRegister>, GetPlatformResRegister, (), (const, override)); 149 MOCK_METHOD(int32_t, GetViewWidth, (), (const, override)); 150 MOCK_METHOD(int32_t, GetViewHeight, (), (const, override)); 151 MOCK_METHOD(int32_t, GetViewPosX, (), (const, override)); 152 MOCK_METHOD(int32_t, GetViewPosY, (), (const, override)); 153 MOCK_METHOD(uint32_t, GetWindowId, (), (const, override)); 154 MOCK_METHOD(void*, GetView, (), (const, override)); 155 MOCK_METHOD(RefPtr<AceView>, GetAceView, (), (const, override)); 156 157 MOCK_METHOD(void, DumpHeapSnapshot, (bool isPrivate), (override)); 158 MOCK_METHOD(void, TriggerGarbageCollection, (), (override)); 159 MOCK_METHOD(bool, WindowIsShow, (), (const, override)); 160 MOCK_METHOD(bool, IsMainWindow, (), (const, override)); 161 MOCK_METHOD(Rect, GetGlobalScaledRect, (), (const, override)); 162 static RefPtr<MockContainer> container_; 163 static ColorMode mockColorMode_; 164 165 private: 166 RefPtr<TaskExecutor> taskExecutor_; 167 RefPtr<PipelineBase> pipelineContext_; 168 bool isFormRender_ = false; 169 bool isUIExtensionWindow_ = false; 170 bool isSubContainer_ = false; 171 bool isDialogContainer_ = false; 172 bool isFreeMultiWindow_ = false; 173 bool isSceneBoardWindow_ = false; 174 bool isCrossAxisWindow_ = false; 175 RefPtr<DisplayInfo> displayInfo_ = MakeRefPtr<DisplayInfo>(); 176 }; 177 } // namespace OHOS::Ace 178 #endif // FOUNDATION_ACE_TEST_MOCK_CORE_COMMON_MOCK_CONTAINER_H 179