• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2023 iSoftStone Information Technology (Group) 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 #include <cstdint>
16 #include <fcntl.h>
17 #include <functional>
18 #include <memory>
19 #include <optional>
20 #include <utility>
21 #include <vector>
22 
23 #include "gtest/gtest.h"
24 
25 #define protected public
26 #define private public
27 #include "test/mock/base/mock_task_executor.h"
28 #include "test/mock/core/pipeline/mock_pipeline_context.h"
29 
30 #include "base/utils/utils.h"
31 #include "core/common/ace_application_info.h"
32 #include "core/components_ng/base/inspector.h"
33 #include "core/components_ng/base/ui_node.h"
34 #include "core/components_ng/pattern/stage/stage_manager.h"
35 #include "core/components_ng/pattern/stage/stage_pattern.h"
36 #include "core/components_ng/pattern/text/span_node.h"
37 #include "core/components_v2/inspector/inspector_constants.h"
38 #include "core/pipeline_ng/pipeline_context.h"
39 
40 using namespace testing;
41 using namespace testing::ext;
42 namespace OHOS::Ace::NG {
43 namespace {
44 std::string key = "key";
45 }; // namespace
46 
47 class InspectorTestNg : public testing::Test {
48 public:
SetUpTestSuite()49     static void SetUpTestSuite()
50     {
51         MockPipelineContext::SetUp();
52     }
TearDownTestSuite()53     static void TearDownTestSuite()
54     {
55         MockPipelineContext::TearDown();
56     }
57 };
58 
59 /**
60  * @tc.name: InspectorTestNg001
61  * @tc.desc: Test the operation of Inspector
62  * @tc.type: FUNC
63  */
64 HWTEST_F(InspectorTestNg, InspectorTestNg001, TestSize.Level1)
65 {
66     auto id = ElementRegister::GetInstance()->MakeUniqueId();
67     RefPtr<FrameNode> ONE = FrameNode::CreateFrameNode("one", id, AceType::MakeRefPtr<Pattern>(), true);
68     auto id2 = ElementRegister::GetInstance()->MakeUniqueId();
69     const RefPtr<FrameNode> TWO = FrameNode::CreateFrameNode("two", id2, AceType::MakeRefPtr<Pattern>());
70     /**
71      * @tc.steps: step1. callback GetFrameNodeByKey
72      * @tc.expected: expect the function is run ok
73      */
74     auto nodePtr = Inspector::GetFrameNodeByKey(key);
75     EXPECT_EQ(nodePtr, nullptr);
76 
77     /**
78      * @tc.steps: step2. callback SetUp
79      * @tc.expected: expect context1 is not null
80      */
81     auto context1 = PipelineContext::GetCurrentContext();
82     ASSERT_NE(context1, nullptr);
83     auto nodePtr1 = Inspector::GetFrameNodeByKey(key);
84     EXPECT_EQ(nodePtr1, nullptr);
85 
86     /**
87      * @tc.steps: step3. callback GetFrameNodeByKey
88      * @tc.expected: expect nodePtr2 not null
89      */
90     context1->rootNode_ = ONE;
91     context1->rootNode_->AddChild(TWO);
92     auto rootNode = context1->GetRootElement();
93     ASSERT_NE(rootNode, nullptr);
94     auto nodePtr2 = Inspector::GetFrameNodeByKey(key);
95     EXPECT_EQ(nodePtr2, nullptr);
96 
97     auto nodePtr3 = Inspector::GetFrameNodeByKey("");
98     ASSERT_NE(nodePtr3, nullptr);
99 }
100 
101 /**
102  * @tc.name: InspectorTestNg002
103  * @tc.desc: Test the operation of Inspector
104  * @tc.type: FUNC
105  */
106 HWTEST_F(InspectorTestNg, InspectorTestNg002, TestSize.Level1)
107 {
108     /**
109      * @tc.steps: step1. callback GetInspectorNodeByKey
110      * @tc.expected: expect the function is run ok
111      */
112     auto test = Inspector::GetInspectorNodeByKey(key);
113     EXPECT_EQ(test, "");
114 
115     /**
116      * @tc.steps: step2. callback SetUp
117      * @tc.expected: expect test1 is "".
118      */
119     auto context1 = PipelineContext::GetCurrentContext();
120     ASSERT_NE(context1, nullptr);
121     auto test1 = Inspector::GetInspectorNodeByKey(key);
122     EXPECT_EQ(test1, "");
123 
124     /**
125      * @tc.steps: step1. callback rootNode_
126      * @tc.expected: expect the function GetInspectorNodeByKey is return null
127      */
128     auto id = ElementRegister::GetInstance()->MakeUniqueId();
129     RefPtr<FrameNode> ONE = FrameNode::CreateFrameNode("one", id, AceType::MakeRefPtr<Pattern>(), true);
130     context1->rootNode_ = ONE;
131     ASSERT_NE(context1, nullptr);
132     auto test2 = Inspector::GetInspectorNodeByKey(key);
133     EXPECT_EQ(test2, "");
134     /**
135      * @tc.steps: step3. callback GetInspectorNodeByKey
136      * @tc.expected: expect nodePtr2 not null
137      */
138     auto test3 = Inspector::GetInspectorNodeByKey("");
139 }
140 
141 /**
142  * @tc.name: InspectorTestNg003
143  * @tc.desc: Test the operation of Inspector
144  * @tc.type: FUNC
145  */
146 HWTEST_F(InspectorTestNg, InspectorTestNg003, TestSize.Level1)
147 {
148     /**
149      * @tc.steps: step1. callback GetInspector
150      * @tc.expected: expect the function is run ok
151      */
152     auto id = ElementRegister::GetInstance()->MakeUniqueId();
153     RefPtr<FrameNode> ONE = FrameNode::CreateFrameNode("one", id, AceType::MakeRefPtr<Pattern>(), true);
154     auto context1 = PipelineContext::GetCurrentContext();
155     ASSERT_NE(context1, nullptr);
156     context1->stageManager_ = AceType::MakeRefPtr<StageManager>(ONE);
157     auto id2 = ElementRegister::GetInstance()->MakeUniqueId();
158     const RefPtr<FrameNode> TWO = FrameNode::CreateFrameNode("stage", id2, AceType::MakeRefPtr<Pattern>());
159     ONE->AddChild(TWO);
160     auto id3 = ElementRegister::GetInstance()->MakeUniqueId();
161     const RefPtr<FrameNode> THREE = FrameNode::CreateFrameNode("three", id3, AceType::MakeRefPtr<Pattern>());
162     THREE->AddChild(ONE);
163 
164     /**
165      * @tc.steps: step2. call GetInspector
166      * @tc.expected: the return value is empty string
167      */
168     auto test1 = Inspector::GetInspector(false);
169     EXPECT_NE(test1, "");
170     auto test3 = Inspector::GetInspector(true);
171     EXPECT_NE(test3, "");
172     auto test4 = Inspector::GetInspectorOfNode(TWO);
173     EXPECT_NE(test4, "");
174 
175     RefPtr<MockPipelineContext> pipeline_bak = MockPipelineContext::pipeline_;
176     MockPipelineContext::pipeline_ = nullptr;
177     auto jsonRoot = JsonUtil::Create(true);
178     const char inspectorType[] = "$type";
179     const char inspectorRoot[] = "root";
180     jsonRoot->Put(inspectorType, inspectorRoot);
181     auto test5 = Inspector::GetInspector(false);
182     EXPECT_EQ(test5, jsonRoot->ToString());
183     MockPipelineContext::pipeline_ = pipeline_bak;
184 
185     InspectorFilter filter;
186     std::string testId = "test";
187     filter.SetFilterID(testId);
188     bool needThrow = false;
189     auto test6 = Inspector::GetInspector(false, filter, needThrow);
190     auto rootNode = context1->GetStageManager()->GetLastPage();
191     if (rootNode == nullptr) {
192         EXPECT_EQ(test6, jsonRoot->ToString());
193     } else {
194         EXPECT_NE(test6, "");
195     }
196     context1->stageManager_ = nullptr;
197 }
198 
199 /**
200  * @tc.name: InspectorTestNg004
201  * @tc.desc: Test the operation of View Inspector
202  * @tc.type: FUNC
203  */
204 HWTEST_F(InspectorTestNg, InspectorTestNg004, TestSize.Level1)
205 {
206     /**
207      * @tc.steps: step1. set rootNode and taskExecutor call SendEventByKey
208      * @tc.expected: expect return true
209      */
210     auto context = NG::PipelineContext::GetCurrentContext();
211     context->rootNode_ = FrameNode::CreateFrameNode("frameNode", 60, AceType::MakeRefPtr<Pattern>(), true);
212     context->rootNode_->SetGeometryNode(AceType::MakeRefPtr<GeometryNode>());
213     context->taskExecutor_ = AceType::MakeRefPtr<MockTaskExecutor>();
214     auto test3 = Inspector::SendEventByKey("", static_cast<int>(AceAction::ACTION_CLICK), "params");
215     EXPECT_EQ(test3, true);
216     test3 = Inspector::SendEventByKey("", static_cast<int>(AceAction::ACTION_LONG_CLICK), "params");
217     EXPECT_EQ(test3, true);
218     test3 = Inspector::SendEventByKey("", 31, "params");
219     EXPECT_EQ(test3, true);
220 }
221 
222 /**
223  * @tc.name: InspectorTestNg005
224  * @tc.desc: Test the operation of View Inspector
225  * @tc.type: FUNC
226  */
227 HWTEST_F(InspectorTestNg, InspectorTestNg005, TestSize.Level1)
228 {
229     /**
230      * @tc.steps: step1. callback HideAllMenus
231      * @tc.expected: expect the function is run ok
232      */
233     Inspector::HideAllMenus();
234     auto context = PipelineContext::GetCurrentContext();
235 
236     /**
237      * @tc.steps: step2. callback SetUp
238      * @tc.expected: step2. expect context1 is return null.
239      */
240     auto context1 = PipelineContext::GetCurrentContext();
241     ASSERT_NE(context1, nullptr);
242     Inspector::HideAllMenus();
243 }
244 
245 /**
246  * @tc.name: InspectorTestNg006
247  * @tc.desc: Test the operation of Inspector
248  * @tc.type: FUNC
249  */
250 HWTEST_F(InspectorTestNg, InspectorTestNg006, TestSize.Level1)
251 {
252     /**
253      * @tc.steps: step1. callback GetInspector
254      * @tc.expected: expect the function is run ok
255      */
256     auto context1 = PipelineContext::GetCurrentContext();
257     ASSERT_NE(context1, nullptr);
258 
259     auto id = ElementRegister::GetInstance()->MakeUniqueId();
260     RefPtr<FrameNode> ONE = FrameNode::CreateFrameNode("one", id, AceType::MakeRefPtr<Pattern>(), true);
261     context1->stageManager_ = AceType::MakeRefPtr<StageManager>(ONE);
262 
263     /**
264      * @tc.steps: step2 add child to two and create a temp node with tag "temp"
265                 call GetInspector
266      * @tc.expected: the return value is empty string
267      */
268     auto id2 = ElementRegister::GetInstance()->MakeUniqueId();
269     const RefPtr<FrameNode> TWO = FrameNode::CreateFrameNode("two", id2, AceType::MakeRefPtr<Pattern>());
270     ONE->children_.clear();
271     ONE->AddChild(TWO);
272     auto stageParent = FrameNode::CreateFrameNode("stageParent", 5, AceType::MakeRefPtr<Pattern>(), true);
273     stageParent->AddChild(ONE);
274 
275     const RefPtr<FrameNode> THREE = FrameNode::CreateFrameNode(
276         "three", ElementRegister::GetInstance()->MakeUniqueId(), AceType::MakeRefPtr<Pattern>());
277     const RefPtr<FrameNode> STAGE = FrameNode::CreateFrameNode(
278         "stage", ElementRegister::GetInstance()->MakeUniqueId(), AceType::MakeRefPtr<Pattern>(), true);
279     const RefPtr<FrameNode> PAGE = FrameNode::CreateFrameNode(
280         "page", ElementRegister::GetInstance()->MakeUniqueId(), AceType::MakeRefPtr<Pattern>(), true);
281     THREE->isInternal_ = true;
282     TWO->AddChild(PAGE);
283     TWO->AddChild(THREE);
284     TWO->AddChild(STAGE);
285     auto temp = FrameNode::CreateFrameNode("temp", 5, AceType::MakeRefPtr<Pattern>(), true);
286     STAGE->AddChild(temp);
287     ONE->tag_ = "stage";
288     auto test1 = Inspector::GetInspector(false);
289     EXPECT_NE(test1, "");
290 
291     PAGE->hostPageId_ = TWO->GetPageId();
292     auto test2 = Inspector::GetInspector(false);
293     EXPECT_NE(test2, "");
294 
295     PAGE->hostPageId_ = TWO->GetPageId() + 1;
296     test2 = Inspector::GetInspector(false);
297     EXPECT_NE(test2, "");
298 
299     TWO->children_.clear();
300     auto test3 = Inspector::GetInspector(false);
301     EXPECT_NE(test3, "");
302 
303     /**
304      *  ONE(stageNode)--TWO(GetLastPage())--PAGE
305      *                   |--THREE
306      *                   |--STAGE--temp
307      *                   |--frameNode
308      *                   |--frameNode2--frameNode3
309      */
310     /**
311      * @tc.steps: step3 add child to two and create a frame node tree
312             call GetInspector
313      * @tc.expected: the return value is not empty string
314      */
315     auto spanNode = SpanNode::GetOrCreateSpanNode(int32_t(191));
316     TWO->AddChild(spanNode);
317 
318     auto frameNode = FrameNode::CreateFrameNode("frameNode", 6, AceType::MakeRefPtr<Pattern>(), true);
319     TWO->AddChild(frameNode);
320     frameNode->isActive_ = true;
321     auto frameNode2 = FrameNode::CreateFrameNode("frameNode2", 62, AceType::MakeRefPtr<Pattern>(), true);
322     TWO->AddChild(frameNode2);
323     frameNode2->isActive_ = false;
324     auto frameNode3 = FrameNode::CreateFrameNode("frameNode3", 63, AceType::MakeRefPtr<Pattern>(), true);
325     frameNode2->AddChild(frameNode3);
326     test3 = Inspector::GetInspector(false);
327     EXPECT_NE(test3, "");
328     context1->stageManager_ = nullptr;
329 }
330 
331 /**
332  * @tc.name: InspectorTestNg007
333  * @tc.desc: Test the operation of Inspector
334  * @tc.type: FUNC
335  */
336 HWTEST_F(InspectorTestNg, InspectorTestNg007, TestSize.Level1)
337 {
338     /**
339      * @tc.steps: step1. callback GetInspector
340      * @tc.expected: expect the function is run ok
341      */
342     auto id = ElementRegister::GetInstance()->MakeUniqueId();
343     RefPtr<FrameNode> ONE = FrameNode::CreateFrameNode("one", id, AceType::MakeRefPtr<Pattern>(), true);
344     auto context1 = PipelineContext::GetCurrentContext();
345     ASSERT_NE(context1, nullptr);
346     context1->stageManager_ = AceType::MakeRefPtr<StageManager>(ONE);
347 
348     /**
349      * @tc.steps: step2. callback pop_back
350      * @tc.expected: expect clean children and pageRootNode is noll
351      */
352     auto pageRootNode = context1->GetStageManager()->GetLastPage();
353     auto test = Inspector::GetInspector(false);
354     auto str = "{\"$type\":\"root\",\"width\":\"720.000000\",\"height\":\"1280.000000\",\"$resolution\":\"1.000000\"}";
355     EXPECT_EQ(test, str);
356     context1->stageManager_ = nullptr;
357 }
358 
359 /**
360  * @tc.name: InspectorTestNg008
361  * @tc.desc: Test the GetRectangleById
362  * @tc.type: FUNC
363  */
364 HWTEST_F(InspectorTestNg, InspectorTestNg008, TestSize.Level1)
365 {
366     /**
367      * @tc.steps: step1. creat frameNode
368      * @tc.expected: expect the function is run ok
369      */
370     auto id = ElementRegister::GetInstance()->MakeUniqueId();
371     RefPtr<FrameNode> ONE = FrameNode::CreateFrameNode("one", id, AceType::MakeRefPtr<Pattern>(), true);
372     auto context = NG::PipelineContext::GetCurrentContext();
373     ASSERT_NE(context, nullptr);
374 
375     /**
376      * @tc.steps: step2. assign value to rootNode_
377      * @tc.expected: rootNode_ pass non-null check.
378      */
379     context->rootNode_ = ONE;
380     context->rootNode_->SetGeometryNode(AceType::MakeRefPtr<GeometryNode>());
381 
382     /**
383      * @tc.steps: step3. construct assignments and call GetRectangleById.
384      * @tc.expected: expect the GetRectangleById is run ok and result is expected.
385      */
386     OHOS::Ace::NG::Rectangle rect;
387     string key = "";
388     Inspector::GetRectangleById(key, rect);
389     float zResult = 1.0f;
390     EXPECT_EQ(rect.scale.z, zResult);
391     context->rootNode_ = nullptr;
392 }
393 
394 /**
395  * @tc.name: InspectorTestNg009
396  * @tc.desc: Test the GetFrameNodeByKey
397  * @tc.type: FUNC
398  */
399 HWTEST_F(InspectorTestNg, InspectorTestNg009, TestSize.Level1)
400 {
401     auto id = ElementRegister::GetInstance()->MakeUniqueId();
402     RefPtr<FrameNode> ONE = FrameNode::CreateFrameNode("one", id, AceType::MakeRefPtr<Pattern>(), true);
403     auto id2 = ElementRegister::GetInstance()->MakeUniqueId();
404     const RefPtr<FrameNode> TWO = FrameNode::CreateFrameNode("two", id2, AceType::MakeRefPtr<Pattern>());
405     auto context = PipelineContext::GetCurrentContext();
406     ASSERT_NE(context, nullptr);
407     auto nodePtr = Inspector::GetFrameNodeByKey(key);
408     EXPECT_EQ(nodePtr, nullptr);
409 
410     Inspector::AddOffscreenNode(ONE);
411     nodePtr = Inspector::GetFrameNodeByKey("one");
412     EXPECT_EQ(nodePtr, 0);
413 
414     RefPtr<MockPipelineContext> pipeline_bak = MockPipelineContext::pipeline_;
415     MockPipelineContext::pipeline_ = nullptr;
416     context = PipelineContext::GetCurrentContext();
417     EXPECT_EQ(context, nullptr);
418     nodePtr = Inspector::GetFrameNodeByKey("two");
419     EXPECT_EQ(nodePtr, nullptr);
420     MockPipelineContext::pipeline_ = pipeline_bak;
421 }
422 
423 /**
424  * @tc.name: InspectorTestNg010
425  * @tc.desc: Test the GetRectangleById
426  * @tc.type: FUNC
427  */
428 HWTEST_F(InspectorTestNg, InspectorTestNg010, TestSize.Level1)
429 {
430     auto id = ElementRegister::GetInstance()->MakeUniqueId();
431     RefPtr<FrameNode> ONE = FrameNode::CreateFrameNode("one", id, AceType::MakeRefPtr<Pattern>(), true);
432     auto context = NG::PipelineContext::GetCurrentContext();
433     ASSERT_NE(context, nullptr);
434     context->rootNode_ = ONE;
435     context->rootNode_->SetGeometryNode(AceType::MakeRefPtr<GeometryNode>());
436     std::string key = "key";
437     OHOS::Ace::NG::Rectangle rect;
438     Inspector::GetRectangleById(key, rect);
439     EXPECT_EQ(rect.size.Width(), 0.0f);
440 
441     auto frameNode = Inspector::GetFrameNodeByKey("one");
442     RefPtr<RenderContext> renderContextBak = ONE->renderContext_;
443     ONE->renderContext_ = nullptr;
444     Inspector::GetRectangleById("one", rect);
445     EXPECT_EQ(rect.screenRect.Width(), 0.0f);
446     ONE->renderContext_ = renderContextBak;
447     EXPECT_EQ(rect.size.Width(), 0.0f);
448 }
449 
450 /**
451  * @tc.name: InspectorTestNg011
452  * @tc.desc: Test the operation of GetSubWindowInspector
453  * @tc.type: FUNC
454  */
455 HWTEST_F(InspectorTestNg, InspectorTestNg011, TestSize.Level1)
456 {
457     auto id = ElementRegister::GetInstance()->MakeUniqueId();
458     RefPtr<FrameNode> ONE = FrameNode::CreateFrameNode("one", id, AceType::MakeRefPtr<Pattern>(), true);
459     auto context = PipelineContext::GetCurrentContext();
460     ASSERT_NE(context, nullptr);
461     context->stageManager_ = AceType::MakeRefPtr<StageManager>(ONE);
462     auto pageRootNode = context->GetStageManager()->GetLastPage();
463     auto test = Inspector::GetSubWindowInspector(false);
464     auto str = "";
465     EXPECT_NE(test, str);
466     context->stageManager_ = nullptr;
467 }
468 
469 /**
470  * @tc.name: InspectorTestNg012
471  * @tc.desc: Test the operation of GetSimplifiedInspector
472  * @tc.type: FUNC
473  */
474 HWTEST_F(InspectorTestNg, InspectorTestNg012, TestSize.Level1)
475 {
476     auto id = ElementRegister::GetInstance()->MakeUniqueId();
477     RefPtr<FrameNode> ONE = FrameNode::CreateFrameNode("one", id, AceType::MakeRefPtr<Pattern>(), true);
478     auto context = PipelineContext::GetCurrentContext();
479     ASSERT_NE(context, nullptr);
480     context->stageManager_ = AceType::MakeRefPtr<StageManager>(ONE);
481     int32_t containerId = 1;
482     std::string result = Inspector::GetSimplifiedInspector(containerId);
483     EXPECT_NE(result, "");
484     context->stageManager_ = nullptr;
485 }
486 
487 /**
488  * @tc.name: InspectorTestNg013
489  * @tc.desc: Test the function of InspectorFilter
490  * @tc.type: FUNC
491  */
492 HWTEST_F(InspectorTestNg, InspectorTestNg013, TestSize.Level1)
493 {
494     const char* hello = "hi";
495     InspectorFilter testFilter;
496     EXPECT_EQ(testFilter.CheckFilterAttr(FixedAttrBit::FIXED_ATTR_CONTENT, hello), true);
497     testFilter.SetFilterDepth(1);
498     std::string id = "id";
499     testFilter.SetFilterID(id);
500     testFilter.filterExt.emplace_back("abc");
501     testFilter.AddFilterAttr("focusable");
502     testFilter.AddFilterAttr("abc");
503     testFilter.AddFilterAttr("def");
504     EXPECT_EQ(testFilter.CheckFixedAttr(FixedAttrBit::FIXED_ATTR_CONTENT), false);
505     EXPECT_EQ(testFilter.CheckExtAttr("zzz"), false);
506     EXPECT_EQ(testFilter.CheckFilterAttr(FixedAttrBit::FIXED_ATTR_CONTENT, hello), false);
507     EXPECT_EQ(testFilter.IsFastFilter(), false);
508 }
509 
510 /**
511  * @tc.name: InspectorTestNg014
512  * @tc.desc: Test the function of InspectorFilter
513  * @tc.type: FUNC
514  */
515 HWTEST_F(InspectorTestNg, InspectorTestNg014, TestSize.Level1)
516 {
517     const char* hello = "hi";
518     InspectorFilter testFilter;
519     testFilter.AddFilterAttr("focusable");
520     EXPECT_EQ(testFilter.CheckFilterAttr(FixedAttrBit::FIXED_ATTR_FOCUSABLE, hello), true);
521 }
522 
523 /**
524  * @tc.name: InspectorTestNg015
525  * @tc.desc: Test the function of InspectorFilter
526  * @tc.type: FUNC
527  */
528 HWTEST_F(InspectorTestNg, InspectorTestNg015, TestSize.Level1)
529 {
530     const char* hello = "abc";
531     InspectorFilter testFilter;
532     testFilter.filterExt.emplace_back("abc");
533     testFilter.AddFilterAttr("focusable");
534     EXPECT_EQ(testFilter.CheckFilterAttr(FixedAttrBit::FIXED_ATTR_CONTENT, hello), true);
535 }
536 
537 /**
538  * @tc.name: AddOffscreenNode_001
539  * @tc.desc: Test the operation of AddOffscreenNode
540  * @tc.type: FUNC
541  */
542 HWTEST_F(InspectorTestNg, AddOffscreenNode_001, TestSize.Level1)
543 {
544     int32_t num = Inspector::offscreenNodes.size();
545     RefPtr<FrameNode> one = nullptr;
546     Inspector::AddOffscreenNode(one);
547     EXPECT_EQ(Inspector::offscreenNodes.size(), num);
548 
549     auto id = ElementRegister::GetInstance()->MakeUniqueId();
550     one = FrameNode::CreateFrameNode("one", id, AceType::MakeRefPtr<Pattern>(), true);
551     auto context = PipelineContext::GetCurrentContext();
552     ASSERT_NE(context, nullptr);
553 
554     context->stageManager_ = AceType::MakeRefPtr<StageManager>(one);
555     num = Inspector::offscreenNodes.size();
556     Inspector::AddOffscreenNode(one);
557     EXPECT_EQ(Inspector::offscreenNodes.size(), num + 1);
558     context->stageManager_ = nullptr;
559 }
560 
561 /**
562  * @tc.name: RemoveOffscreenNode_001
563  * @tc.desc: Test the operation of RemoveOffscreenNode
564  * @tc.type: FUNC
565  */
566 HWTEST_F(InspectorTestNg, RemoveOffscreenNode_001, TestSize.Level1)
567 {
568     int32_t num = Inspector::offscreenNodes.size();
569     RefPtr<FrameNode> one = nullptr;
570     Inspector::RemoveOffscreenNode(one);
571     EXPECT_EQ(Inspector::offscreenNodes.size(), num);
572 
573     auto id = ElementRegister::GetInstance()->MakeUniqueId();
574     one = FrameNode::CreateFrameNode("one", id, AceType::MakeRefPtr<Pattern>(), true);
575     auto context = PipelineContext::GetCurrentContext();
576     ASSERT_NE(context, nullptr);
577     context->stageManager_ = AceType::MakeRefPtr<StageManager>(one);
578     Inspector::AddOffscreenNode(one);
579     num = Inspector::offscreenNodes.size();
580 
581     Inspector::RemoveOffscreenNode(one);
582     EXPECT_EQ(Inspector::offscreenNodes.size(), num - 1);
583     context->stageManager_ = nullptr;
584 }
585 } // namespace OHOS::Ace::NG
586