• 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 #include "gtest/gtest.h"
17 
18 #define protected public
19 #define private public
20 #include "core/components_ng/base/view_stack_processor.h"
21 #include "core/components_ng/pattern/navigation/navigation_layout_property.h"
22 #include "core/components_ng/pattern/navigation/navigation_group_node.h"
23 #include "core/components_ng/pattern/navigation/navigation_pattern.h"
24 #include "core/components_ng/pattern/navigation/navigation_view.h"
25 
26 using namespace testing;
27 using namespace testing::ext;
28 namespace OHOS::Ace::NG {
29 class NavigationPatternTestNg : public testing::Test {
30 public:
SetUpTestSuite()31     static void SetUpTestSuite() {};
TearDownTestSuite()32     static void TearDownTestSuite() {};
33 protected:
34 };
35 
36 /**
37  * @tc.name: NavigationPatternTest_001
38  * @tc.desc: Test REPLACE navigator.
39  * @tc.type: FUNC
40  */
41 HWTEST_F(NavigationPatternTestNg, NavigationPatternTest_001, TestSize.Level1)
42 {
43     NavigationView navigationView;
44     navigationView.Create();
45     navigationView.SetTitle("navigationView", false);
46 
47     RefPtr<FrameNode> frameNode = AceType::DynamicCast<FrameNode>(ViewStackProcessor::GetInstance()->Finish());
48     EXPECT_NE(frameNode, nullptr);
49     RefPtr<NavigationLayoutProperty> navigationLayoutProperty =
50         frameNode->GetLayoutProperty<NavigationLayoutProperty>();
51     EXPECT_NE(navigationLayoutProperty, nullptr);
52 }
53 
54 /**
55  * @tc.name: NavigationPatternTest_002
56  * @tc.desc: Test NavigationPattern OnModifyDone.
57  * @tc.type: FUNC
58  */
59 HWTEST_F(NavigationPatternTestNg, NavigationPatternTest_002, TestSize.Level1)
60 {
61     NavigationView navigationView;
62     navigationView.Create();
63     navigationView.SetTitle("navigationView", false);
64     RefPtr<FrameNode> frameNode = AceType::DynamicCast<FrameNode>(ViewStackProcessor::GetInstance()->Finish());
65     EXPECT_NE(frameNode, nullptr);
66     RefPtr<NavigationLayoutProperty> navigationLayoutProperty =
67         frameNode->GetLayoutProperty<NavigationLayoutProperty>();
68     EXPECT_NE(navigationLayoutProperty, nullptr);
69 
70     auto hostNode = AceType::DynamicCast<NavigationGroupNode>(frameNode);
71     EXPECT_NE(hostNode, nullptr);
72 
73     NavigationPattern navigationPattern;
74     navigationPattern.OnModifyDone();
75 }
76 
77 /**
78  * @tc.name: NavigationPatternTest_003
79  * @tc.desc: Various situations of Test NavigationPattern OnDirtyLayoutWrapperSwap.
80  * @tc.type: FUNC
81  */
82 HWTEST_F(NavigationPatternTestNg, NavigationPatternTest_003, TestSize.Level1)
83 {
84     NavigationView navigationView;
85     navigationView.Create();
86     navigationView.SetTitle("navigationView", false);
87     RefPtr<FrameNode> frameNode = AceType::DynamicCast<FrameNode>(ViewStackProcessor::GetInstance()->Finish());
88     EXPECT_NE(frameNode, nullptr);
89     RefPtr<NavigationLayoutProperty> navigationLayoutProperty =
90         frameNode->GetLayoutProperty<NavigationLayoutProperty>();
91     EXPECT_NE(navigationLayoutProperty, nullptr);
92 
93     auto hostNode = AceType::DynamicCast<NavigationGroupNode>(frameNode);
94     EXPECT_NE(hostNode, nullptr);
95     RefPtr<NavigationPattern> pattern = frameNode->GetPattern<NavigationPattern>();
96     EXPECT_NE(pattern, nullptr);
97     pattern->OnModifyDone();
98     RefPtr<GeometryNode> geometryNode = AceType::MakeRefPtr<GeometryNode>();
99     EXPECT_NE(geometryNode, nullptr);
100     auto layoutWrapper = AceType::MakeRefPtr<LayoutWrapper>(frameNode, geometryNode, frameNode->GetLayoutProperty());
101     EXPECT_NE(layoutWrapper, nullptr);
102 
103     DirtySwapConfig config;
104     config.skipMeasure = true;
105     config.skipLayout = true;
106     std::vector<DirtySwapConfig> configValue;
107     configValue.push_back(config);
108     config.skipLayout = false;
109     configValue.push_back(config);
110     config.skipMeasure = false;
111     configValue.push_back(config);
112     config.skipLayout = true;
113     configValue.push_back(config);
114 
115     for (auto &iter : configValue) {
116         EXPECT_EQ(pattern->OnDirtyLayoutWrapperSwap(layoutWrapper, iter), false);
117     }
118 }
119 
120 /**
121  * @tc.name: NavigationPatternTest_004
122  * @tc.desc: Test Two level nesting of layoutWrapper.
123  * @tc.type: FUNC
124  */
125 HWTEST_F(NavigationPatternTestNg, NavigationPatternTest_004, TestSize.Level1)
126 {
127     NavigationView navigationView;
128     navigationView.Create();
129     navigationView.SetTitle("navigationView", false);
130     RefPtr<FrameNode> frameNode = AceType::DynamicCast<FrameNode>(ViewStackProcessor::GetInstance()->Finish());
131     EXPECT_NE(frameNode, nullptr);
132     RefPtr<NavigationLayoutProperty> navigationLayoutProperty =
133         frameNode->GetLayoutProperty<NavigationLayoutProperty>();
134     EXPECT_NE(navigationLayoutProperty, nullptr);
135     auto hostNode = AceType::DynamicCast<NavigationGroupNode>(frameNode);
136     EXPECT_NE(hostNode, nullptr);
137 
138     RefPtr<NavigationPattern> pattern = frameNode->GetPattern<NavigationPattern>();
139     EXPECT_NE(pattern, nullptr);
140     pattern->OnModifyDone();
141     RefPtr<GeometryNode> geometryNode = AceType::MakeRefPtr<GeometryNode>();
142     EXPECT_NE(geometryNode, nullptr);
143     auto layoutWrapper = AceType::MakeRefPtr<LayoutWrapper>(frameNode, geometryNode, frameNode->GetLayoutProperty());
144     EXPECT_NE(layoutWrapper, nullptr);
145 
146     DirtySwapConfig config;
147     config.skipMeasure = true;
148     config.skipLayout = true;
149     bool result = pattern->OnDirtyLayoutWrapperSwap(layoutWrapper, config);
150     EXPECT_EQ(result, false);
151 
152     auto setNavigation = AceType::MakeRefPtr<NavigationLayoutAlgorithm>();
153     auto layoutAlgorithmWrapper = AceType::MakeRefPtr<LayoutAlgorithmWrapper>(setNavigation);
154     layoutWrapper->SetLayoutAlgorithm(layoutAlgorithmWrapper);
155     result = pattern->OnDirtyLayoutWrapperSwap(layoutWrapper, config);
156     EXPECT_EQ(result, false);
157 }
158 
159 /**
160  * @tc.name: NavigationPatternTest_005
161  * @tc.desc: Test REPLACE navigator.
162  * @tc.type: FUNC
163  */
164 HWTEST_F(NavigationPatternTestNg, NavigationPatternTest_005, TestSize.Level1)
165 {
166     NavigationView navigationView;
167     navigationView.Create();
168     navigationView.SetTitle("navigationView", false);
169 
170     RefPtr<FrameNode> frameNode = AceType::DynamicCast<FrameNode>(ViewStackProcessor::GetInstance()->Finish());
171     EXPECT_NE(frameNode, nullptr);
172     navigationView.SetCustomTitle(frameNode);
173     RefPtr<UINode> uiNode = nullptr;
174     navigationView.SetCustomTitle(uiNode);
175 
176     RefPtr<NavigationLayoutProperty> navigationLayoutProperty =
177         frameNode->GetLayoutProperty<NavigationLayoutProperty>();
178     EXPECT_NE(navigationLayoutProperty, nullptr);
179 }
180 }