• 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 #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 #include "core/components_ng/base/node_render_status_monitor.h"
23 
24 namespace OHOS::Ace::NG {
25 class MockPipelineContext : public PipelineContext {
26     DECLARE_ACE_TYPE(MockPipelineContext, PipelineContext);
27 
28 public:
29     MockPipelineContext() = default;
30     ~MockPipelineContext() override = default;
31 
32     static void SetUp();
33     static void TearDown();
34     static void SetCurrentWindowRect(Rect rect);
35     static RefPtr<MockPipelineContext> GetCurrent();
36     void SetRootSize(double rootWidth, double rootHeight);
37     void SetInstanceId(int32_t instanceId);
38     void SetContainerModalButtonsRect(bool hasModalButtonsRect);
39     void SetContainerCustomTitleVisible(bool visible);
40     void SetContainerControlButtonVisible(bool visible);
41     void SetContainerModalButtonsRect(RectF buttons);
42     void SetContainerModalTitleHeight(int32_t height);
43 
44     MOCK_CONST_METHOD0(GetSafeAreaWithoutProcess, SafeAreaInsets());
45     MOCK_CONST_METHOD0(GetSelectOverlayManager, SafeAreaInsets());
46     MOCK_METHOD(float, GetFontScale, ());
47     MOCK_METHOD(SafeAreaInsets, GetSafeArea, (), (const));
48 
GetIsDeclarative()49     bool GetIsDeclarative() const override
50     {
51         return isDeclarative_;
52     }
53 
54     static RefPtr<MockPipelineContext> pipeline_;
IsWindowFocused()55     bool IsWindowFocused() const
56     {
57         return onFocus_;
58     }
59 
SetUseFlushUITasks(bool enable)60     void SetUseFlushUITasks(bool enable)
61     {
62         useFlushUITasks_ = enable;
63     }
64 
UseFlushUITasks()65     bool UseFlushUITasks()
66     {
67         return useFlushUITasks_;
68     }
69 
SetBackCallback(std::function<void ()> callback)70     void SetBackCallback(std::function<void()> callback)
71     {
72         backCallback_ = callback;
73     }
74 
75     bool CallRouterBackToPopPage(bool* isUserAccept = nullptr) override
76     {
77         if (backCallback_) {
78             backCallback_();
79             return true;
80         }
81         return false;
82     }
83 
SetBackgroundColorModeUpdated(bool backgroundColorModeUpdated)84     void SetBackgroundColorModeUpdated(bool backgroundColorModeUpdated) {}
85 
ReachResponseDeadline()86     bool ReachResponseDeadline() const override
87     {
88         if (responseTime_ > 0) {
89             return false;
90         }
91         return true;
92     }
93 
SetResponseTime(int32_t time)94     void SetResponseTime(int32_t time)
95     {
96         responseTime_ = time;
97     }
98 
DecResponseTime()99     void DecResponseTime()
100     {
101         if (responseTime_ > 0 && responseTime_ != INT32_MAX) {
102             responseTime_--;
103         }
104     }
105 
GetCurrentPageNameCallback()106     std::string GetCurrentPageNameCallback()
107     {
108         return "";
109     }
110 
Get()111     auto Get()
112     {
113         return this;
114     }
115 protected:
116     float fontScale_ = 1.0f;
117     bool isDeclarative_ = false;
118     double dipScale_ = 1.0;
119     std::function<void()> backCallback_;
120     RefPtr<TaskExecutor> taskExecutor_;
121     bool useFlushUITasks_ = false;
122     int32_t responseTime_ = INT32_MAX;
123 };
124 } // namespace OHOS::Ace::NG
125 
126 namespace OHOS::Ace {
127 void SetBoolStatus(bool value);
128 } // namespace OHOS::Ace
129 #endif // FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_MOCK_PIPELINE_CONTEXT_H
130