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 #ifndef FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_MOCK_PIPELINE_CONTEXT_H 17 #define FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_MOCK_PIPELINE_CONTEXT_H 18 19 #include "gmock/gmock.h" 20 21 #include "core/pipeline_ng/pipeline_context.h" 22 23 namespace OHOS::Ace::NG { 24 class MockPipelineContext : public PipelineContext { 25 DECLARE_ACE_TYPE(MockPipelineContext, PipelineContext); 26 27 public: 28 MockPipelineContext() = default; 29 ~MockPipelineContext() override = default; 30 31 static void SetUp(); 32 static void TearDown(); 33 static void SetCurrentWindowRect(Rect rect); 34 static RefPtr<MockPipelineContext> GetCurrent(); 35 void SetRootSize(double rootWidth, double rootHeight); 36 void SetInstanceId(int32_t instanceId); 37 38 MOCK_CONST_METHOD0(GetSafeAreaWithoutProcess, SafeAreaInsets()); 39 MOCK_CONST_METHOD0(GetSelectOverlayManager, SafeAreaInsets()); 40 MOCK_METHOD(float, GetFontScale, ()); 41 MOCK_METHOD(SafeAreaInsets, GetSafeArea, (), (const)); 42 GetIsDeclarative()43 bool GetIsDeclarative() const override 44 { 45 return isDeclarative_; 46 } 47 48 static RefPtr<MockPipelineContext> pipeline_; IsWindowFocused()49 bool IsWindowFocused() const 50 { 51 return onFocus_; 52 } 53 SetUseFlushUITasks(bool enable)54 void SetUseFlushUITasks(bool enable) 55 { 56 useFlushUITasks_ = enable; 57 } 58 UseFlushUITasks()59 bool UseFlushUITasks() 60 { 61 return useFlushUITasks_; 62 } 63 SetBackCallback(std::function<void ()> callback)64 void SetBackCallback(std::function<void()> callback) 65 { 66 backCallback_ = callback; 67 } 68 CallRouterBackToPopPage()69 bool CallRouterBackToPopPage() override 70 { 71 if (backCallback_) { 72 backCallback_(); 73 return true; 74 } 75 return false; 76 } SetEnableSwipeBack(bool isEnable)77 void SetEnableSwipeBack(bool isEnable) {} 78 79 protected: 80 float fontScale_ = 1.0f; 81 bool isDeclarative_ = false; 82 double dipScale_ = 1.0; 83 std::function<void()> backCallback_; 84 RefPtr<TaskExecutor> taskExecutor_; 85 bool useFlushUITasks_ = false; 86 }; 87 } // namespace OHOS::Ace::NG 88 89 namespace OHOS::Ace { 90 void SetBoolStatus(bool value); 91 } // namespace OHOS::Ace 92 #endif // FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_MOCK_PIPELINE_CONTEXT_H 93