• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2023-2024 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/inspector_filter.h"
34 #include "core/components_ng/base/simplified_inspector.h"
35 #include "core/components_ng/base/ui_node.h"
36 #include "core/components_ng/pattern/stage/stage_manager.h"
37 #include "core/components_ng/pattern/stage/stage_pattern.h"
38 #include "core/components_ng/pattern/stage/page_pattern.h"
39 #include "core/components_ng/pattern/text/span_node.h"
40 #include "core/components_v2/inspector/inspector_constants.h"
41 #include "core/pipeline_ng/pipeline_context.h"
42 #include "base/json/json_util.h"
43 #include "core/components_ng/pattern/custom/custom_node.h"
44 #include "test/mock/core/common/mock_container.h"
45 #include "test/mock/core/render/mock_render_context.h"
46 #include "test/mock/core/render/mock_rosen_render_context.h"
47 
48 using namespace testing;
49 using namespace testing::ext;
50 namespace OHOS::Ace::NG {
51 namespace {
52 std::string key = "key";
53 const std::string TEXT_NODE_TYPE = "Text";
54 const std::string TEST_TEXT = "SomeText";
55 const char INSPECTOR_TYPE[] = "$type";
56 const char INSPECTOR_ID[] = "$ID";
57 const char INSPECTOR_DEBUGLINE[] = "$debugLine";
58 const char INSPECTOR_ATTRS[] = "$attrs";
59 const char INSPECTOR_CHILDREN[] = "$children";
60 
61 class InspectorTestNode : public UINode {
62     DECLARE_ACE_TYPE(InspectorTestNode, UINode);
63 
64 public:
CreateTestNode(int32_t nodeId)65     static RefPtr<InspectorTestNode> CreateTestNode(int32_t nodeId)
66     {
67         auto node = MakeRefPtr<InspectorTestNode>(nodeId);
68         return node;
69     }
70 
IsAtomicNode() const71     bool IsAtomicNode() const override
72     {
73         return true;
74     }
75 
InspectorTestNode(int32_t nodeId)76     explicit InspectorTestNode(int32_t nodeId) : UINode("InspectorTestNode", nodeId) {}
77     ~InspectorTestNode() override = default;
78 };
79 }; // namespace
80 
81 class MockStageManager : public StageManager {
82 public:
MockStageManager(const RefPtr<FrameNode> & stage)83     explicit MockStageManager(const RefPtr<FrameNode>& stage)
84         : StageManager(stage)
85     {}
86 
87     ~MockStageManager() override = default;
88 
89     MOCK_METHOD(RefPtr<FrameNode>, GetLastPage, (), (const));
90 };
91 
92 class MockOverlayManager : public OverlayManager {
93 public:
MockOverlayManager(const RefPtr<FrameNode> & rootNode)94     explicit MockOverlayManager(const RefPtr<FrameNode>& rootNode)
95         : OverlayManager(rootNode)
96     {}
97 
98     ~MockOverlayManager() override = default;
99 
100     MOCK_METHOD(const WeakPtr<UINode>, GetRootNode, (), (const));
101 };
102 
103 class InspectorTestNg : public testing::Test {
104 public:
SetUpTestSuite()105     static void SetUpTestSuite()
106     {
107         MockPipelineContext::SetUp();
108     }
TearDownTestSuite()109     static void TearDownTestSuite()
110     {
111         MockPipelineContext::TearDown();
112     }
113 };
114 
115 /**
116  * @tc.name: InspectorTestNg001
117  * @tc.desc: Test the operation of Inspector
118  * @tc.type: FUNC
119  */
120 HWTEST_F(InspectorTestNg, InspectorTestNg001, TestSize.Level1)
121 {
122     auto id = ElementRegister::GetInstance()->MakeUniqueId();
123     RefPtr<FrameNode> ONE = FrameNode::CreateFrameNode("one", id, AceType::MakeRefPtr<Pattern>(), true);
124     auto id2 = ElementRegister::GetInstance()->MakeUniqueId();
125     const RefPtr<FrameNode> TWO = FrameNode::CreateFrameNode("two", id2, AceType::MakeRefPtr<Pattern>());
126     /**
127      * @tc.steps: step1. callback GetFrameNodeByKey
128      * @tc.expected: expect the function is run ok
129      */
130     auto nodePtr = Inspector::GetFrameNodeByKey(key);
131     EXPECT_EQ(nodePtr, nullptr);
132 
133     /**
134      * @tc.steps: step2. callback SetUp
135      * @tc.expected: expect context1 is not null
136      */
137     auto context1 = PipelineContext::GetCurrentContext();
138     ASSERT_NE(context1, nullptr);
139     auto nodePtr1 = Inspector::GetFrameNodeByKey(key);
140     EXPECT_EQ(nodePtr1, nullptr);
141 
142     /**
143      * @tc.steps: step3. callback GetFrameNodeByKey
144      * @tc.expected: expect nodePtr2 not null
145      */
146     context1->rootNode_ = ONE;
147     context1->rootNode_->AddChild(TWO);
148     auto rootNode = context1->GetRootElement();
149     ASSERT_NE(rootNode, nullptr);
150     auto nodePtr2 = Inspector::GetFrameNodeByKey(key);
151     EXPECT_EQ(nodePtr2, nullptr);
152 
153     auto nodePtr3 = Inspector::GetFrameNodeByKey("");
154     ASSERT_NE(nodePtr3, nullptr);
155 
156     context1->rootNode_ = nullptr;
157 }
158 
159 /**
160  * @tc.name: InspectorTestNg002
161  * @tc.desc: Test the operation of Inspector
162  * @tc.type: FUNC
163  */
164 HWTEST_F(InspectorTestNg, InspectorTestNg002, TestSize.Level1)
165 {
166     /**
167      * @tc.steps: step1. callback GetInspectorNodeByKey
168      * @tc.expected: expect the function is run ok
169      */
170     auto test = Inspector::GetInspectorNodeByKey(key);
171     EXPECT_EQ(test, "");
172 
173     /**
174      * @tc.steps: step2. callback SetUp
175      * @tc.expected: expect test1 is "".
176      */
177     auto context1 = PipelineContext::GetCurrentContext();
178     ASSERT_NE(context1, nullptr);
179     auto test1 = Inspector::GetInspectorNodeByKey(key);
180     EXPECT_EQ(test1, "");
181 
182     /**
183      * @tc.steps: step1. callback rootNode_
184      * @tc.expected: expect the function GetInspectorNodeByKey is return null
185      */
186     auto id = ElementRegister::GetInstance()->MakeUniqueId();
187     RefPtr<FrameNode> ONE = FrameNode::CreateFrameNode("one", id, AceType::MakeRefPtr<Pattern>(), true);
188     context1->rootNode_ = ONE;
189     ASSERT_NE(context1, nullptr);
190     auto test2 = Inspector::GetInspectorNodeByKey(key);
191     EXPECT_EQ(test2, "");
192     /**
193      * @tc.steps: step3. callback GetInspectorNodeByKey
194      * @tc.expected: expect nodePtr2 not null
195      */
196     auto test3 = Inspector::GetInspectorNodeByKey("");
197 
198     context1->rootNode_ = nullptr;
199 }
200 
201 /**
202  * @tc.name: InspectorTestNg003
203  * @tc.desc: Test the operation of Inspector
204  * @tc.type: FUNC
205  */
206 HWTEST_F(InspectorTestNg, InspectorTestNg003, TestSize.Level1)
207 {
208     /**
209      * @tc.steps: step1. callback GetInspector
210      * @tc.expected: expect the function is run ok
211      */
212     auto id = ElementRegister::GetInstance()->MakeUniqueId();
213     RefPtr<FrameNode> ONE = FrameNode::CreateFrameNode("one", id, AceType::MakeRefPtr<Pattern>(), true);
214     auto context1 = PipelineContext::GetCurrentContext();
215     ASSERT_NE(context1, nullptr);
216     context1->stageManager_ = AceType::MakeRefPtr<StageManager>(ONE);
217     auto id2 = ElementRegister::GetInstance()->MakeUniqueId();
218     const RefPtr<FrameNode> TWO = FrameNode::CreateFrameNode("stage", id2, AceType::MakeRefPtr<Pattern>());
219     ONE->AddChild(TWO);
220     auto id3 = ElementRegister::GetInstance()->MakeUniqueId();
221     const RefPtr<FrameNode> THREE = FrameNode::CreateFrameNode("three", id3, AceType::MakeRefPtr<Pattern>());
222     THREE->AddChild(ONE);
223 
224     /**
225      * @tc.steps: step2. call GetInspector
226      * @tc.expected: the return value is empty string
227      */
228     auto test1 = Inspector::GetInspector(false);
229     EXPECT_NE(test1, "");
230     auto test3 = Inspector::GetInspector(true);
231     EXPECT_NE(test3, "");
232     auto test4 = Inspector::GetInspectorOfNode(TWO);
233     EXPECT_NE(test4, "");
234 
235     RefPtr<MockPipelineContext> pipeline_bak = MockPipelineContext::pipeline_;
236     MockPipelineContext::pipeline_ = nullptr;
237     auto jsonRoot = JsonUtil::Create(true);
238     const char inspectorType[] = "$type";
239     const char inspectorRoot[] = "root";
240     jsonRoot->Put(inspectorType, inspectorRoot);
241     auto test5 = Inspector::GetInspector(false);
242     EXPECT_EQ(test5, jsonRoot->ToString());
243     MockPipelineContext::pipeline_ = pipeline_bak;
244 
245     InspectorFilter filter;
246     std::string testId = "test";
247     filter.SetFilterID(testId);
248     bool needThrow = false;
249     auto test6 = Inspector::GetInspector(false, filter, needThrow);
250     auto rootNode = context1->GetStageManager()->GetLastPage();
251     if (rootNode == nullptr) {
252         EXPECT_EQ(test6, jsonRoot->ToString());
253     } else {
254         EXPECT_NE(test6, "");
255     }
256     context1->stageManager_ = nullptr;
257 }
258 
259 /**
260  * @tc.name: InspectorTestNg004
261  * @tc.desc: Test the operation of View Inspector
262  * @tc.type: FUNC
263  */
264 HWTEST_F(InspectorTestNg, InspectorTestNg004, TestSize.Level1)
265 {
266     /**
267      * @tc.steps: step1. set rootNode and taskExecutor call SendEventByKey
268      * @tc.expected: expect return true
269      */
270     auto context = NG::PipelineContext::GetCurrentContext();
271     context->rootNode_ = FrameNode::CreateFrameNode("frameNode", 60, AceType::MakeRefPtr<Pattern>(), true);
272     context->rootNode_->SetGeometryNode(AceType::MakeRefPtr<GeometryNode>());
273     context->taskExecutor_ = AceType::MakeRefPtr<MockTaskExecutor>();
274     auto test3 = Inspector::SendEventByKey("", static_cast<int>(AceAction::ACTION_CLICK), "params");
275     EXPECT_EQ(test3, true);
276     test3 = Inspector::SendEventByKey("", static_cast<int>(AceAction::ACTION_LONG_CLICK), "params");
277     EXPECT_EQ(test3, true);
278     test3 = Inspector::SendEventByKey("", 31, "params");
279     EXPECT_EQ(test3, true);
280 
281     context->rootNode_ = nullptr;
282 }
283 
284 /**
285  * @tc.name: InspectorTestNg005
286  * @tc.desc: Test the operation of View Inspector
287  * @tc.type: FUNC
288  */
289 HWTEST_F(InspectorTestNg, InspectorTestNg005, TestSize.Level1)
290 {
291     /**
292      * @tc.steps: step1. callback HideAllMenus
293      * @tc.expected: expect the function is run ok
294      */
295     Inspector::HideAllMenus();
296     auto context = PipelineContext::GetCurrentContext();
297 
298     /**
299      * @tc.steps: step2. callback SetUp
300      * @tc.expected: step2. expect context1 is return null.
301      */
302     auto context1 = PipelineContext::GetCurrentContext();
303     ASSERT_NE(context1, nullptr);
304     Inspector::HideAllMenus();
305 }
306 
307 /**
308  * @tc.name: InspectorTestNg006
309  * @tc.desc: Test the operation of Inspector
310  * @tc.type: FUNC
311  */
312 HWTEST_F(InspectorTestNg, InspectorTestNg006, TestSize.Level1)
313 {
314     /**
315      * @tc.steps: step1. callback GetInspector
316      * @tc.expected: expect the function is run ok
317      */
318     auto context1 = PipelineContext::GetCurrentContext();
319     ASSERT_NE(context1, nullptr);
320 
321     auto id = ElementRegister::GetInstance()->MakeUniqueId();
322     RefPtr<FrameNode> ONE = FrameNode::CreateFrameNode("one", id, AceType::MakeRefPtr<Pattern>(), true);
323     context1->stageManager_ = AceType::MakeRefPtr<StageManager>(ONE);
324 
325     /**
326      * @tc.steps: step2 add child to two and create a temp node with tag "temp"
327                 call GetInspector
328      * @tc.expected: the return value is empty string
329      */
330     auto id2 = ElementRegister::GetInstance()->MakeUniqueId();
331     const RefPtr<FrameNode> TWO = FrameNode::CreateFrameNode("two", id2, AceType::MakeRefPtr<Pattern>());
332     ONE->children_.clear();
333     ONE->AddChild(TWO);
334     auto stageParent = FrameNode::CreateFrameNode("stageParent", 5, AceType::MakeRefPtr<Pattern>(), true);
335     stageParent->AddChild(ONE);
336 
337     const RefPtr<FrameNode> THREE = FrameNode::CreateFrameNode(
338         "three", ElementRegister::GetInstance()->MakeUniqueId(), AceType::MakeRefPtr<Pattern>());
339     const RefPtr<FrameNode> STAGE = FrameNode::CreateFrameNode(
340         "stage", ElementRegister::GetInstance()->MakeUniqueId(), AceType::MakeRefPtr<Pattern>(), true);
341     const RefPtr<FrameNode> PAGE = FrameNode::CreateFrameNode(
342         "page", ElementRegister::GetInstance()->MakeUniqueId(), AceType::MakeRefPtr<Pattern>(), true);
343     THREE->isInternal_ = true;
344     TWO->AddChild(PAGE);
345     TWO->AddChild(THREE);
346     TWO->AddChild(STAGE);
347     auto temp = FrameNode::CreateFrameNode("temp", 5, AceType::MakeRefPtr<Pattern>(), true);
348     STAGE->AddChild(temp);
349     ONE->tag_ = "stage";
350     auto test1 = Inspector::GetInspector(false);
351     EXPECT_NE(test1, "");
352 
353     PAGE->hostPageId_ = TWO->GetPageId();
354     auto test2 = Inspector::GetInspector(false);
355     EXPECT_NE(test2, "");
356 
357     PAGE->hostPageId_ = TWO->GetPageId() + 1;
358     test2 = Inspector::GetInspector(false);
359     EXPECT_NE(test2, "");
360 
361     TWO->children_.clear();
362     auto test3 = Inspector::GetInspector(false);
363     EXPECT_NE(test3, "");
364 
365     /**
366      *  ONE(stageNode)--TWO(GetLastPage())--PAGE
367      *                   |--THREE
368      *                   |--STAGE--temp
369      *                   |--frameNode
370      *                   |--frameNode2--frameNode3
371      */
372     /**
373      * @tc.steps: step3 add child to two and create a frame node tree
374             call GetInspector
375      * @tc.expected: the return value is not empty string
376      */
377     auto spanNode = SpanNode::GetOrCreateSpanNode(int32_t(191));
378     TWO->AddChild(spanNode);
379 
380     auto frameNode = FrameNode::CreateFrameNode("frameNode", 6, AceType::MakeRefPtr<Pattern>(), true);
381     TWO->AddChild(frameNode);
382     frameNode->isActive_ = true;
383     auto frameNode2 = FrameNode::CreateFrameNode("frameNode2", 62, AceType::MakeRefPtr<Pattern>(), true);
384     TWO->AddChild(frameNode2);
385     frameNode2->isActive_ = false;
386     auto frameNode3 = FrameNode::CreateFrameNode("frameNode3", 63, AceType::MakeRefPtr<Pattern>(), true);
387     frameNode2->AddChild(frameNode3);
388     test3 = Inspector::GetInspector(false);
389     EXPECT_NE(test3, "");
390     context1->stageManager_ = nullptr;
391 }
392 
393 /**
394  * @tc.name: InspectorTestNg007
395  * @tc.desc: Test the operation of Inspector
396  * @tc.type: FUNC
397  */
398 HWTEST_F(InspectorTestNg, InspectorTestNg007, TestSize.Level1)
399 {
400     /**
401      * @tc.steps: step1. callback GetInspector
402      * @tc.expected: expect the function is run ok
403      */
404     auto id = ElementRegister::GetInstance()->MakeUniqueId();
405     RefPtr<FrameNode> ONE = FrameNode::CreateFrameNode("one", id, AceType::MakeRefPtr<Pattern>(), true);
406     auto context1 = PipelineContext::GetCurrentContext();
407     ASSERT_NE(context1, nullptr);
408     context1->stageManager_ = AceType::MakeRefPtr<StageManager>(ONE);
409 
410     /**
411      * @tc.steps: step2. callback pop_back
412      * @tc.expected: expect clean children and pageRootNode is noll
413      */
414     auto pageRootNode = context1->GetStageManager()->GetLastPage();
415     auto test = Inspector::GetInspector(false);
416     auto str = "{\"$type\":\"root\",\"width\":\"720.000000\",\"height\":\"1280.000000\",\"$resolution\":\"1.000000\"}";
417     EXPECT_EQ(test, str);
418 
419     context1->stageManager_ = nullptr;
420 }
421 
422 /**
423  * @tc.name: InspectorTestNg008
424  * @tc.desc: Test the GetRectangleById
425  * @tc.type: FUNC
426  */
427 HWTEST_F(InspectorTestNg, InspectorTestNg008, TestSize.Level1)
428 {
429     /**
430      * @tc.steps: step1. creat frameNode
431      * @tc.expected: expect the function is run ok
432      */
433     auto id = ElementRegister::GetInstance()->MakeUniqueId();
434     RefPtr<FrameNode> ONE = FrameNode::CreateFrameNode("one", id, AceType::MakeRefPtr<Pattern>(), true);
435     auto context = NG::PipelineContext::GetCurrentContext();
436     ASSERT_NE(context, nullptr);
437 
438     /**
439      * @tc.steps: step2. assign value to rootNode_
440      * @tc.expected: rootNode_ pass non-null check.
441      */
442     context->rootNode_ = ONE;
443     context->rootNode_->SetGeometryNode(AceType::MakeRefPtr<GeometryNode>());
444 
445     /**
446      * @tc.steps: step3. construct assignments and call GetRectangleById.
447      * @tc.expected: expect the GetRectangleById is run ok and result is expected.
448      */
449     OHOS::Ace::NG::Rectangle rect;
450     string key = "";
451     Inspector::GetRectangleById(key, rect);
452     float zResult = 1.0f;
453     EXPECT_EQ(rect.scale.z, zResult);
454     context->rootNode_ = nullptr;
455 }
456 
457 /**
458  * @tc.name: InspectorTestNg009
459  * @tc.desc: Test the GetFrameNodeByKey
460  * @tc.type: FUNC
461  */
462 HWTEST_F(InspectorTestNg, InspectorTestNg009, TestSize.Level1)
463 {
464     auto id = ElementRegister::GetInstance()->MakeUniqueId();
465     RefPtr<FrameNode> ONE = FrameNode::CreateFrameNode("one", id, AceType::MakeRefPtr<Pattern>(), true);
466     auto id2 = ElementRegister::GetInstance()->MakeUniqueId();
467     const RefPtr<FrameNode> TWO = FrameNode::CreateFrameNode("two", id2, AceType::MakeRefPtr<Pattern>());
468     auto context = PipelineContext::GetCurrentContext();
469     ASSERT_NE(context, nullptr);
470     auto nodePtr = Inspector::GetFrameNodeByKey(key);
471     EXPECT_EQ(nodePtr, nullptr);
472 
473     Inspector::AddOffscreenNode(ONE);
474     nodePtr = Inspector::GetFrameNodeByKey("one");
475     EXPECT_EQ(nodePtr, 0);
476 
477     RefPtr<MockPipelineContext> pipeline_bak = MockPipelineContext::pipeline_;
478     MockPipelineContext::pipeline_ = nullptr;
479     context = PipelineContext::GetCurrentContext();
480     EXPECT_EQ(context, nullptr);
481     nodePtr = Inspector::GetFrameNodeByKey("two");
482     EXPECT_EQ(nodePtr, nullptr);
483     MockPipelineContext::pipeline_ = pipeline_bak;
484 }
485 
486 /**
487  * @tc.name: InspectorTestNg010
488  * @tc.desc: Test the GetRectangleById
489  * @tc.type: FUNC
490  */
491 HWTEST_F(InspectorTestNg, InspectorTestNg010, TestSize.Level1)
492 {
493     auto id = ElementRegister::GetInstance()->MakeUniqueId();
494     RefPtr<FrameNode> ONE = FrameNode::CreateFrameNode("one", id, AceType::MakeRefPtr<Pattern>(), true);
495     auto context = NG::PipelineContext::GetCurrentContext();
496     ASSERT_NE(context, nullptr);
497     context->rootNode_ = ONE;
498     context->rootNode_->SetGeometryNode(AceType::MakeRefPtr<GeometryNode>());
499     std::string key = "key";
500     OHOS::Ace::NG::Rectangle rect;
501     Inspector::GetRectangleById(key, rect);
502     EXPECT_EQ(rect.size.Width(), 0.0f);
503 
504     auto frameNode = Inspector::GetFrameNodeByKey("one");
505     RefPtr<RenderContext> renderContextBak = ONE->renderContext_;
506     ONE->renderContext_ = nullptr;
507     Inspector::GetRectangleById("one", rect);
508     EXPECT_EQ(rect.screenRect.Width(), 0.0f);
509     ONE->renderContext_ = renderContextBak;
510     EXPECT_EQ(rect.size.Width(), 0.0f);
511 }
512 
513 /**
514  * @tc.name: InspectorTestNg011
515  * @tc.desc: Test the operation of GetSubWindowInspector
516  * @tc.type: FUNC
517  */
518 HWTEST_F(InspectorTestNg, InspectorTestNg011, TestSize.Level1)
519 {
520     auto id = ElementRegister::GetInstance()->MakeUniqueId();
521     RefPtr<FrameNode> ONE = FrameNode::CreateFrameNode("one", id, AceType::MakeRefPtr<Pattern>(), true);
522     auto context = PipelineContext::GetCurrentContext();
523     ASSERT_NE(context, nullptr);
524     context->stageManager_ = AceType::MakeRefPtr<StageManager>(ONE);
525     auto pageRootNode = context->GetStageManager()->GetLastPage();
526     auto test = Inspector::GetSubWindowInspector(false);
527     auto str = "";
528     EXPECT_NE(test, str);
529     context->stageManager_ = nullptr;
530 }
531 
532 /**
533  * @tc.name: InspectorTestNg013
534  * @tc.desc: Test the function of InspectorFilter
535  * @tc.type: FUNC
536  */
537 HWTEST_F(InspectorTestNg, InspectorTestNg013, TestSize.Level1)
538 {
539     const char* hello = "hi";
540     InspectorFilter testFilter;
541     EXPECT_EQ(testFilter.CheckFilterAttr(FixedAttrBit::FIXED_ATTR_CONTENT, hello), true);
542     testFilter.SetFilterDepth(1);
543     std::string id = "id";
544     testFilter.SetFilterID(id);
545     testFilter.filterExt.emplace_back("abc");
546     testFilter.AddFilterAttr("focusable");
547     testFilter.AddFilterAttr("abc");
548     testFilter.AddFilterAttr("def");
549     EXPECT_EQ(testFilter.CheckFixedAttr(FixedAttrBit::FIXED_ATTR_CONTENT), false);
550     EXPECT_EQ(testFilter.CheckExtAttr("zzz"), false);
551     EXPECT_EQ(testFilter.CheckFilterAttr(FixedAttrBit::FIXED_ATTR_CONTENT, hello), false);
552     EXPECT_EQ(testFilter.IsFastFilter(), false);
553 }
554 
555 /**
556  * @tc.name: InspectorTestNg014
557  * @tc.desc: Test the function of InspectorFilter
558  * @tc.type: FUNC
559  */
560 HWTEST_F(InspectorTestNg, InspectorTestNg014, TestSize.Level1)
561 {
562     const char* hello = "hi";
563     InspectorFilter testFilter;
564     testFilter.AddFilterAttr("focusable");
565     EXPECT_EQ(testFilter.CheckFilterAttr(FixedAttrBit::FIXED_ATTR_FOCUSABLE, hello), true);
566 }
567 
568 /**
569  * @tc.name: InspectorTestNg015
570  * @tc.desc: Test the function of InspectorFilter
571  * @tc.type: FUNC
572  */
573 HWTEST_F(InspectorTestNg, InspectorTestNg015, TestSize.Level1)
574 {
575     const char* hello = "abc";
576     InspectorFilter testFilter;
577     testFilter.filterExt.emplace_back("abc");
578     testFilter.AddFilterAttr("focusable");
579     EXPECT_EQ(testFilter.CheckFilterAttr(FixedAttrBit::FIXED_ATTR_CONTENT, hello), true);
580 }
581 
582 /**
583  * @tc.name: InspectorTestNg016
584  * @tc.desc: Test the operation of GetInspectorTree
585  * @tc.type: FUNC
586  */
587 HWTEST_F(InspectorTestNg, InspectorTestNg016, TestSize.Level1)
588 {
589     // tc.steps: step1. callback GetInspectorTree
590     // tc.expected: expect the function is run ok
591     auto context1 = PipelineContext::GetCurrentContext();
592     ASSERT_NE(context1, nullptr);
593 
594     auto id = ElementRegister::GetInstance()->MakeUniqueId();
595     RefPtr<FrameNode> stageNode = FrameNode::CreateFrameNode("stage", id, AceType::MakeRefPtr<Pattern>(), true);
596     context1->stageManager_ = AceType::MakeRefPtr<StageManager>(stageNode);
597 
598     // tc.steps: step2 add lastPage and create a frame node tree to lastPage
599     auto id2 = ElementRegister::GetInstance()->MakeUniqueId();
600     const RefPtr<FrameNode> lastPage = FrameNode::CreateFrameNode("two", id2, AceType::MakeRefPtr<Pattern>());
601     stageNode->children_.clear();
602     stageNode->AddChild(lastPage);
603     auto stageParent = FrameNode::CreateFrameNode("stageParent", 5, AceType::MakeRefPtr<Pattern>(), true);
604     stageParent->AddChild(stageNode);
605     auto frameNode = FrameNode::CreateFrameNode("frameNode", 6, AceType::MakeRefPtr<Pattern>(), true);
606     lastPage->AddChild(frameNode);
607     frameNode->isActive_ = true;
608     auto frameNode2 = FrameNode::CreateFrameNode("frameNode2", 62, AceType::MakeRefPtr<Pattern>(), true);
609     lastPage->AddChild(frameNode2);
610     frameNode2->isActive_ = false;
611     auto frameNode3 = FrameNode::CreateFrameNode("frameNode3", 63, AceType::MakeRefPtr<Pattern>(), true);
612     frameNode2->AddChild(frameNode3);
613     NG::InspectorTreeMap treesInfos;
614     Inspector::GetInspectorTree(treesInfos);
615     EXPECT_TRUE(!treesInfos.empty());
616     context1->stageManager_ = nullptr;
617 }
618 
619 /**
620  * @tc.name: InspectorTestNg017
621  * @tc.desc: Test the operation of GetFrameNodeByKey
622  * @tc.type: FUNC
623  */
624 HWTEST_F(InspectorTestNg, InspectorTestNg017, TestSize.Level1)
625 {
626     // tc.steps: step1. add frameNode to arkui tree with inspector id text1
627     // tc.expected: expect the function GetFrameNodeByKey get the frameNode
628     std::string inspectorId = "text1";
629     auto rootNode = FrameNode::CreateFrameNode(V2::ROOT_ETS_TAG,
630         ElementRegister::GetInstance()->MakeUniqueId(), AceType::MakeRefPtr<Pattern>());
631     auto frameNode = FrameNode::CreateFrameNode(V2::TEXT_ETS_TAG,
632         ElementRegister::GetInstance()->MakeUniqueId(), AceType::MakeRefPtr<Pattern>());
633     frameNode->UpdateInspectorId(inspectorId);
634     auto context = PipelineContext::GetCurrentContext();
635     context->rootNode_ = rootNode;
636     rootNode->AddChild(frameNode);
637     auto searchedNode = Inspector::GetFrameNodeByKey(inspectorId);
638     EXPECT_EQ(frameNode, searchedNode);
639 
640     // tc.steps:    add offScreencreenNode to off screencreen node with inspector id text1
641     // tc.expected: expect the function GetFrameNodeByKey get the offScreencreenNode
642     auto offScreencreenNode = FrameNode::CreateFrameNode(V2::TEXT_ETS_TAG,
643         ElementRegister::GetInstance()->MakeUniqueId(), AceType::MakeRefPtr<Pattern>());
644     offScreencreenNode->UpdateInspectorId(inspectorId);
645     Inspector::AddOffscreenNode(offScreencreenNode);
646     searchedNode = Inspector::GetFrameNodeByKey(inspectorId);
647     EXPECT_EQ(offScreencreenNode, searchedNode);
648 
649     // tc.steps:    execute GetFrameNodeByKey when skipoffscreenNodes set true
650     // tc.expected: expect the function GetFrameNodeByKey get the frameNode
651     searchedNode = Inspector::GetFrameNodeByKey(inspectorId, false, true);
652     EXPECT_EQ(frameNode, searchedNode);
653 
654     // tc.steps:    execute GetFrameNodeByKey when remove offScreencreenNode
655     // tc.expected: expect the function GetFrameNodeByKey get the frameNode
656     Inspector::RemoveOffscreenNode(offScreencreenNode);
657     searchedNode = Inspector::GetFrameNodeByKey(inspectorId);
658     EXPECT_EQ(frameNode, searchedNode);
659 }
660 
661 /**
662  * @tc.name: InspectorTestNg018
663  * @tc.desc: Test the operation of GetInspectorNodeByKey
664  * @tc.type: FUNC
665  */
666 HWTEST_F(InspectorTestNg, InspectorTestNg018, TestSize.Level1)
667 {
668     // tc.steps: step1. add frameNode to arkui tree with inspector id text1
669     // tc.expected: expect the function GetInspectorNodeByKey get the frameNode
670     std::string inspectorId = "text1";
671     int32_t textNodeId = ElementRegister::GetInstance()->MakeUniqueId();
672     auto rootNode = FrameNode::CreateFrameNode(V2::ROOT_ETS_TAG,
673         ElementRegister::GetInstance()->MakeUniqueId(), AceType::MakeRefPtr<Pattern>());
674     auto frameNode = FrameNode::CreateFrameNode(V2::TEXT_ETS_TAG,
675         textNodeId, AceType::MakeRefPtr<Pattern>());
676     frameNode->UpdateInspectorId(inspectorId);
677     auto context = PipelineContext::GetCurrentContext();
678     context->rootNode_ = rootNode;
679     rootNode->AddChild(frameNode);
680     std::string searchedNodeStr = Inspector::GetInspectorNodeByKey(inspectorId);
681     auto searchedNode = JsonUtil::ParseJsonString(searchedNodeStr);
682     EXPECT_TRUE(searchedNode->IsValid());
683 
684     std::string nodeType = searchedNode->GetString(INSPECTOR_TYPE);
685     EXPECT_EQ(nodeType, TEXT_NODE_TYPE);
686 
687     int32_t nodeId = searchedNode->GetInt(INSPECTOR_ID);
688     EXPECT_EQ(textNodeId, nodeId);
689 
690     std::string debugLine = searchedNode->GetString(INSPECTOR_DEBUGLINE);
691     EXPECT_EQ(debugLine, "");
692 
693     auto attrJson = searchedNode->GetObject(INSPECTOR_ATTRS);
694     std::string accessibilityTextAttr = attrJson->GetString("accessibilityText");
695     EXPECT_EQ(accessibilityTextAttr, "");
696 
697     auto accessibilityProperty = frameNode->GetAccessibilityProperty<AccessibilityProperty>();
698     accessibilityProperty->SetAccessibilityText(TEST_TEXT);
699     searchedNodeStr = Inspector::GetInspectorNodeByKey(inspectorId);
700     searchedNode = JsonUtil::ParseJsonString(searchedNodeStr);
701     EXPECT_TRUE(searchedNode->IsValid());
702     attrJson = searchedNode->GetObject(INSPECTOR_ATTRS);
703     accessibilityTextAttr = attrJson->GetString("accessibilityText");
704     EXPECT_EQ(accessibilityTextAttr, TEST_TEXT);
705 }
706 
707 /**
708  * @tc.name: InspectorTestNg020
709  * @tc.desc: Test the operation of GetInspector
710  * @tc.type: FUNC
711  */
712 HWTEST_F(InspectorTestNg, InspectorTestNg020, TestSize.Level1)
713 {
714     auto context = PipelineContext::GetCurrentContext();
715     RefPtr<FrameNode> stageNode = FrameNode::CreateFrameNode(
716         "stage", ElementRegister::GetInstance()->MakeUniqueId(), AceType::MakeRefPtr<Pattern>(), true);
717     context->stageManager_ = AceType::MakeRefPtr<StageManager>(stageNode);
718     const RefPtr<FrameNode> PAGE = FrameNode::CreateFrameNode(
719         "page", ElementRegister::GetInstance()->MakeUniqueId(), AceType::MakeRefPtr<Pattern>(), true);
720     auto customNode = CustomNode::CreateCustomNode(1, "custom");
721     stageNode->AddChild(PAGE);
722     PAGE->AddChild(customNode);
723 
724     // tc.steps:    execute GetInspector when param isLayoutInspector is false
725     // tc.expected: expect the function GetInspector result without customNode
726     std::string searchedNodesStr = Inspector::GetInspector();
727     auto searchedNodes = JsonUtil::ParseJsonString(searchedNodesStr);
728     EXPECT_TRUE(searchedNodes->IsValid());
729     auto attrJson = searchedNodes->GetObject(INSPECTOR_CHILDREN);
730     EXPECT_TRUE(attrJson->IsNull());
731 }
732 
733 /**
734  * @tc.name: InspectorTestNg021
735  * @tc.desc: Test the operation of ParseWindowIdFromMsg
736  * @tc.type: FUNC
737  */
738 HWTEST_F(InspectorTestNg, InspectorTestNg021, TestSize.Level1)
739 {
740     std::string inspectorMsg = "";
741     auto result = Inspector::ParseWindowIdFromMsg(inspectorMsg);
742     EXPECT_EQ(result.first, 0);
743     EXPECT_EQ(result.second, -1);
744 
745     inspectorMsg = "invalid message";
746     result = Inspector::ParseWindowIdFromMsg(inspectorMsg);
747     EXPECT_EQ(result.first, 0);
748     EXPECT_EQ(result.second, -1);
749 
750     inspectorMsg = "{\"method\":\"ArkUI.xxx\", \"params\":{\"windowId\":\"10\"}}";
751     result = Inspector::ParseWindowIdFromMsg(inspectorMsg);
752     EXPECT_EQ(result.first, 0);
753     EXPECT_EQ(result.second, -1);
754 
755     inspectorMsg = "{\"method\":\"ArkUI.tree\", \"params\":{\"windowIds\":\"10\"}}";
756     result = Inspector::ParseWindowIdFromMsg(inspectorMsg);
757     EXPECT_EQ(result.first, 0);
758     EXPECT_EQ(result.second, 0);
759 
760     inspectorMsg = "{\"method\":\"ArkUI.tree\", \"paramss\":{\"windowId\":\"10\"}}";
761     result = Inspector::ParseWindowIdFromMsg(inspectorMsg);
762     EXPECT_EQ(result.first, 0);
763     EXPECT_EQ(result.second, 0);
764 
765     inspectorMsg = "{\"method\":\"ArkUI.tree\", \"params\":{\"windowId\":\"10\"}}";
766     result = Inspector::ParseWindowIdFromMsg(inspectorMsg);
767     EXPECT_EQ(result.first, 10);
768     EXPECT_EQ(result.second, 0);
769 
770     inspectorMsg = "{\"method\":\"ArkUI.tree.3D\", \"params\":{\"windowId\":\"10\"}}";
771     result = Inspector::ParseWindowIdFromMsg(inspectorMsg);
772     EXPECT_EQ(result.first, 10);
773     EXPECT_EQ(result.second, 1);
774 }
775 
776 
777 /**
778  * @tc.name: AddOffscreenNode_001
779  * @tc.desc: Test the operation of AddOffscreenNode
780  * @tc.type: FUNC
781  */
782 HWTEST_F(InspectorTestNg, AddOffscreenNode_001, TestSize.Level1)
783 {
784     int32_t num = Inspector::offscreenNodes.size();
785     RefPtr<FrameNode> one = nullptr;
786     Inspector::AddOffscreenNode(one);
787     EXPECT_EQ(Inspector::offscreenNodes.size(), num);
788 
789     auto id = ElementRegister::GetInstance()->MakeUniqueId();
790     one = FrameNode::CreateFrameNode("one", id, AceType::MakeRefPtr<Pattern>(), true);
791     auto context = PipelineContext::GetCurrentContext();
792     ASSERT_NE(context, nullptr);
793 
794     context->stageManager_ = AceType::MakeRefPtr<StageManager>(one);
795     num = Inspector::offscreenNodes.size();
796     Inspector::AddOffscreenNode(one);
797     EXPECT_EQ(Inspector::offscreenNodes.size(), num + 1);
798     context->stageManager_ = nullptr;
799 }
800 
801 /**
802  * @tc.name: RemoveOffscreenNode_001
803  * @tc.desc: Test the operation of RemoveOffscreenNode
804  * @tc.type: FUNC
805  */
806 HWTEST_F(InspectorTestNg, RemoveOffscreenNode_001, TestSize.Level1)
807 {
808     int32_t num = Inspector::offscreenNodes.size();
809     RefPtr<FrameNode> one = nullptr;
810     Inspector::RemoveOffscreenNode(one);
811     EXPECT_EQ(Inspector::offscreenNodes.size(), num);
812 
813     auto id = ElementRegister::GetInstance()->MakeUniqueId();
814     one = FrameNode::CreateFrameNode("one", id, AceType::MakeRefPtr<Pattern>(), true);
815     auto context = PipelineContext::GetCurrentContext();
816     ASSERT_NE(context, nullptr);
817     context->stageManager_ = AceType::MakeRefPtr<StageManager>(one);
818     Inspector::AddOffscreenNode(one);
819     num = Inspector::offscreenNodes.size();
820 
821     Inspector::RemoveOffscreenNode(one);
822     EXPECT_EQ(Inspector::offscreenNodes.size(), num - 1);
823     context->stageManager_ = nullptr;
824 }
825 
826 /**
827  * @tc.name: GetOffScreenTreeNodes_001
828  * @tc.desc: Test the operation of GetOffScreenTreeNodes
829  * @tc.type: FUNC
830  */
831 HWTEST_F(InspectorTestNg, GetOffScreenTreeNodes_001, TestSize.Level1)
832 {
833     auto id = ElementRegister::GetInstance()->MakeUniqueId();
834     RefPtr<FrameNode> one = FrameNode::CreateFrameNode("one", id, AceType::MakeRefPtr<Pattern>(), true);
835     auto context = PipelineContext::GetCurrentContext();
836     ASSERT_NE(context, nullptr);
837     context->stageManager_ = AceType::MakeRefPtr<StageManager>(one);
838     Inspector::AddOffscreenNode(one);
839     int32_t num = Inspector::offscreenNodes.size();
840     NG::InspectorTreeMap offNodes;
841     Inspector::GetOffScreenTreeNodes(offNodes);
842     EXPECT_EQ(offNodes.size(), num);
843     context->stageManager_ = nullptr;
844 }
845 
846 /**
847  * @tc.name: GetRecordAllPagesNodes_001
848  * @tc.desc: Test the operation of GetRecordAllPagesNodes
849  * (stageNode)--PageA--PageB--PageC
850  *                              |--frameNode
851  *                              |--frameNode1--frameNode3
852  *                              |--frameNode2
853  * @tc.type: FUNC
854  */
855 HWTEST_F(InspectorTestNg, GetRecordAllPagesNodes_001, TestSize.Level1)
856 {
857     // tc.steps: step1. call GetRecordAllPagesNodes
858     // tc.expected: expect the function is run ok
859     auto context1 = PipelineContext::GetCurrentContext();
860     ASSERT_NE(context1, nullptr);
861 
862     auto id = ElementRegister::GetInstance()->MakeUniqueId();
863     RefPtr<FrameNode> stageNode = FrameNode::CreateFrameNode("sageNode", id, AceType::MakeRefPtr<Pattern>(), true);
864     context1->stageManager_ = AceType::MakeRefPtr<StageManager>(stageNode);
865     stageNode->children_.clear();
866 
867     // tc.steps: step2 add lastPage and create a frame node tree to lastPage
868     auto id2 = ElementRegister::GetInstance()->MakeUniqueId();
869     const RefPtr<FrameNode> pageA = FrameNode::CreateFrameNode("PageA", id2,
870         AceType::MakeRefPtr<PagePattern>(AceType::MakeRefPtr<PageInfo>()));
871     stageNode->AddChild(pageA);
872     auto id3 = ElementRegister::GetInstance()->MakeUniqueId();
873     const RefPtr<FrameNode> pageB = FrameNode::CreateFrameNode("PageB", id3,
874         AceType::MakeRefPtr<PagePattern>(AceType::MakeRefPtr<PageInfo>()));
875     stageNode->AddChild(pageB);
876     auto id4 = ElementRegister::GetInstance()->MakeUniqueId();
877     const RefPtr<FrameNode> pageC = FrameNode::CreateFrameNode("PageC", id4,
878         AceType::MakeRefPtr<PagePattern>(AceType::MakeRefPtr<PageInfo>()));
879     stageNode->AddChild(pageC);
880 
881     auto frameNode = FrameNode::CreateFrameNode("frameNode0", 5, AceType::MakeRefPtr<Pattern>(), true);
882     pageC->AddChild(frameNode);
883     auto frameNode1 = FrameNode::CreateFrameNode("frameNode1", 6, AceType::MakeRefPtr<Pattern>(), true);
884     pageC->AddChild(frameNode1);
885     auto frameNode2 = FrameNode::CreateFrameNode("frameNode2", 62, AceType::MakeRefPtr<Pattern>(), true);
886     pageC->AddChild(frameNode2);
887     frameNode2->isActive_ = false;
888     auto frameNode3 = FrameNode::CreateFrameNode("frameNode3", 63, AceType::MakeRefPtr<Pattern>(), true);
889     frameNode1->AddChild(frameNode3);
890     frameNode3->isActive_ = true;
891     NG::InspectorTreeMap treesInfos;
892     Inspector::GetRecordAllPagesNodes(treesInfos);
893     EXPECT_TRUE(!treesInfos.empty());
894     context1->stageManager_ = nullptr;
895     auto node3 = treesInfos[63];
896     EXPECT_TRUE(node3 != nullptr);
897     EXPECT_EQ(node3->GetParentId(), 6);
898 }
899 
900 HWTEST_F(InspectorTestNg, GetRecordAllPagesNodes_002, TestSize.Level1)
901 {
902     auto context = PipelineContext::GetCurrentContext();
903     ASSERT_NE(context, nullptr);
904     // STEP1:Create stageNode->pageA->frameNode
905     RefPtr<FrameNode> stageNode = FrameNode::CreateFrameNode("stageNode", 1, AceType::MakeRefPtr<Pattern>(), true);
906     context->stageManager_ = AceType::MakeRefPtr<StageManager>(stageNode);
907     stageNode->children_.clear();
908     const RefPtr<FrameNode> pageA = FrameNode::CreateFrameNode("pageA", 2,
909         AceType::MakeRefPtr<PagePattern>(AceType::MakeRefPtr<PageInfo>()));
910     stageNode->AddChild(pageA);
911     auto frameNode = FrameNode::CreateFrameNode("frameNode0", 5, AceType::MakeRefPtr<Pattern>(), true);
912     pageA->AddChild(frameNode);
913     // STEP2:parent is CustomNode,stageNode->pageA->frameNode->customNode->customNodeChild
914     auto customNode = CustomNode::CreateCustomNode(100, "custom");
915     auto customNodeChild = FrameNode::CreateFrameNode("customNodeChild", 103, AceType::MakeRefPtr<Pattern>(), true);
916     customNodeChild->isActive_ = true;
917     customNode->AddChild(customNodeChild);
918     frameNode->AddChild(customNode);
919     // STEP3:parent is SpanNode,stageNode->pageA->frameNode->spanNode->spanNodeChild
920     auto spanNode = SpanNode::GetOrCreateSpanNode(int32_t(101));
921     auto spanNodeChild = FrameNode::CreateFrameNode("spanNodeChild", 104, AceType::MakeRefPtr<Pattern>(), true);
922     spanNodeChild->isActive_ = true;
923     spanNode->AddChild(spanNodeChild);
924     frameNode->AddChild(spanNode);
925     // STEP4:parent is TestNode,stageNode->pageA->frameNode->testNode->testNodeChild
926     auto testNode = InspectorTestNode::CreateTestNode(102);
927     auto testNodeChild = FrameNode::CreateFrameNode("testNodeChild", 105, AceType::MakeRefPtr<Pattern>(), true);
928     testNodeChild->isActive_ = true;
929     testNode->AddChild(testNodeChild);
930     frameNode->AddChild(testNode);
931     NG::InspectorTreeMap treesInfos;
932     Inspector::GetRecordAllPagesNodes(treesInfos);
933     auto treeNode = treesInfos[102];
934     EXPECT_TRUE(treeNode == nullptr);
935     treeNode = treesInfos[103];
936     EXPECT_TRUE(treeNode != nullptr);
937     EXPECT_EQ(treeNode->GetParentId(), 100);
938     treeNode = treesInfos[104];
939     EXPECT_TRUE(treeNode != nullptr);
940     EXPECT_EQ(treeNode->GetParentId(), 101);
941     treeNode = treesInfos[105];
942     EXPECT_TRUE(treeNode != nullptr);
943     EXPECT_EQ(treeNode->GetParentId(), 5);
944 }
945 
946 /**
947  * @tc.name: InspectorTestNg022
948  * @tc.desc: Test the method GetInspectorChildrenInfo
949  * @tc.type: FUNC
950  */
951 HWTEST_F(InspectorTestNg, InspectorTestNg022, TestSize.Level1)
952 {
953     /**
954      * @tc.steps: step1. test GetInspectorChildrenInfo
955      */
956     auto spanNode = SpanNode::GetOrCreateSpanNode(int32_t(191));
957     NG::InspectorTreeMap treesInfos;
958     EXPECT_TRUE(AceType::InstanceOf<SpanNode>(spanNode));
959     Inspector::GetInspectorChildrenInfo(spanNode, treesInfos, 1, 1);
960 
961     auto customNode = CustomNode::CreateCustomNode(1, "custom");
962     EXPECT_TRUE(AceType::InstanceOf<CustomNode>(customNode));
963     Inspector::GetInspectorChildrenInfo(spanNode, treesInfos, 1, 1);
964 
965     Inspector::GetInspectorChildrenInfo(spanNode, treesInfos, 1, 0);
966 }
967 
968 /**
969  * @tc.name: InspectorTestNg023
970  * @tc.desc: Test the method GetCustomNodeInfo
971  * @tc.type: FUNC
972  */
973 HWTEST_F(InspectorTestNg, InspectorTestNg023, TestSize.Level1)
974 {
975     /**
976      * @tc.steps: step1. Initialize context and create stage/page nodes
977      * @tc.expected: Context should be valid, stage/page nodes created successfully
978      */
979     auto context = PipelineContext::GetCurrentContext();
980     EXPECT_NE(context, nullptr);
981     auto stageId = ElementRegister::GetInstance()->MakeUniqueId();
982     auto stageNode = FrameNode::CreateFrameNode("stage", stageId, AceType::MakeRefPtr<Pattern>(), true);
983     context->stageManager_ = AceType::MakeRefPtr<StageManager>(stageNode);
984     auto pageNode = FrameNode::CreateFrameNode("page", 100, AceType::MakeRefPtr<Pattern>(), true);
985     stageNode->AddChild(pageNode);
986 
987     /**
988      * @tc.steps: step2. Build test node hierarchy
989      */
990     auto customNode = CustomNode::CreateCustomNode(101, V2::JS_VIEW_ETS_TAG);
991     customNode->UpdateInspectorId("custom_node_id");
992     customNode->extraInfo_ = { "pages", 15, 20 };
993     pageNode->AddChild(customNode);
994     auto frameNode = FrameNode::CreateFrameNode("button", 102, AceType::MakeRefPtr<Pattern>(), true);
995     frameNode->tag_ = V2::JS_VIEW_ETS_TAG;
996     customNode->AddChild(frameNode);
997     auto customNode2 = CustomNode::CreateCustomNode(103, V2::JS_VIEW_ETS_TAG);
998     frameNode->AddChild(customNode2);
999 
1000     /**
1001      * @tc.steps: step3. Execute inspection with ID filter
1002      * @tc.expected: Should return valid JSON without error flag
1003      */
1004     bool needThrow = false;
1005     InspectorFilter filter;
1006     std::string id = "custom_node_id";
1007     filter.SetFilterID(id);
1008     std::string result = Inspector::GetInspector(true, filter, needThrow);
1009     EXPECT_FALSE(needThrow);
1010 
1011     /**
1012      * @tc.steps: step4. Verify frame node inspection data
1013      * @tc.expected: Should return non-empty valid JSON
1014      */
1015     auto resultFrameNode = Inspector::GetInspectorOfNode(frameNode);
1016     auto jsonFrameNode = JsonUtil::ParseJsonString(resultFrameNode);
1017     ASSERT_NE(resultFrameNode, "");
1018     EXPECT_STREQ(jsonFrameNode->GetValue(INSPECTOR_DEBUGLINE)->GetString().c_str(), "");
1019 
1020     /**
1021      * @tc.steps: step5. Verify CustomNode specific attributes
1022      * @tc.expected: CustomNode should show debug info, FrameNode as build-in type
1023      */
1024     auto jsonValue = JsonUtil::ParseJsonString(result);
1025     ASSERT_NE(jsonValue, nullptr);
1026     EXPECT_STREQ(jsonValue->GetValue("type")->GetString().c_str(), "root");
1027     auto content = jsonValue->GetValue("content");
1028     ASSERT_FALSE(content->IsNull());
1029     auto childrenArray = content->GetValue(INSPECTOR_CHILDREN);
1030     ASSERT_TRUE(childrenArray->IsArray());
1031     bool foundCustomNode = false;
1032     for (int32_t i = 0; i < childrenArray->GetArraySize(); ++i) {
1033         auto node = childrenArray->GetArrayItem(i);
1034         if (node->GetValue(INSPECTOR_ID)->GetInt() == 101) {
1035             auto debugLine = JsonUtil::ParseJsonString(node->GetValue(INSPECTOR_DEBUGLINE)->GetString());
1036             EXPECT_STREQ("pages(15:20)", debugLine->GetValue("$line")->GetString().c_str());
1037             foundCustomNode = true;
1038         } else if (node->GetValue(INSPECTOR_ID)->GetInt() == 102) {
1039             EXPECT_STREQ("build-in", node->GetValue("type")->GetString().c_str());
1040         }
1041     }
1042     EXPECT_TRUE(foundCustomNode);
1043     context->stageManager_ = nullptr;
1044 }
1045 
1046 /**
1047  * @tc.name: InspectorTestNg024
1048  * @tc.desc: Test the GetRectangleById
1049  * @tc.type: FUNC
1050  */
1051 HWTEST_F(InspectorTestNg, InspectorTestNg024, TestSize.Level1)
1052 {
1053     // tc.steps: step1. add frameNode to arkui tree with inspector id test
1054     // tc.expected: expect the function GetFrameNodeByKey get the frameNode
1055     std::string inspectorId = "test";
1056     auto rootNode = FrameNode::CreateFrameNode(V2::ROOT_ETS_TAG,
1057         ElementRegister::GetInstance()->MakeUniqueId(), AceType::MakeRefPtr<Pattern>());
1058     auto frameNode = FrameNode::CreateFrameNode(V2::TEXT_ETS_TAG,
1059         ElementRegister::GetInstance()->MakeUniqueId(), AceType::MakeRefPtr<Pattern>());
1060     frameNode->UpdateInspectorId(inspectorId);
1061     auto context = PipelineContext::GetCurrentContext();
1062     ASSERT_NE(context, nullptr);
1063     context->rootNode_ = rootNode;
1064     context->rootNode_->SetGeometryNode(AceType::MakeRefPtr<GeometryNode>());
1065     rootNode->AddChild(frameNode);
1066     auto searchedNode = Inspector::GetFrameNodeByKey(inspectorId, true);
1067     EXPECT_NE(searchedNode, nullptr);
1068 
1069     OHOS::Ace::NG::Rectangle rect;
1070     Inspector::GetRectangleById(inspectorId, rect);
1071     EXPECT_EQ(rect.size.Width(), 0.0f);
1072     auto renderContext = searchedNode->GetRenderContext();
1073     EXPECT_NE(renderContext, nullptr);
1074 
1075     MockContainer::SetUp();
1076     MockContainer::Current()->taskExecutor_ = AceType::MakeRefPtr<MockTaskExecutor>();
1077     MockContainer::Current()->pipelineContext_ = MockPipelineContext::GetCurrentContext();
1078     MockContainer::Current()->pipelineContext_->taskExecutor_ = MockContainer::Current()->taskExecutor_;
1079     auto container = Container::Current();
1080     ASSERT_NE(container, nullptr);
1081     container->isDynamicRender_ = false;
1082     auto pipeline = searchedNode->GetContext();
1083     ASSERT_NE(pipeline, nullptr);
1084     Offset offfset(1.0, 1.0);
1085     pipeline->SetHostParentOffsetToWindow(Offset(offfset.GetX(), offfset.GetY()));
1086 
1087     Inspector::GetRectangleById(inspectorId, rect);
1088     EXPECT_EQ(rect.windowOffset, searchedNode->GetOffsetRelativeToWindow());
1089 
1090     container->isDynamicRender_ = true;
1091     container->uIContentType_ = UIContentType::UNDEFINED;
1092     Inspector::GetRectangleById(inspectorId, rect);
1093     EXPECT_EQ(rect.windowOffset, searchedNode->GetOffsetRelativeToWindow());
1094 
1095     container->uIContentType_ = UIContentType::DYNAMIC_COMPONENT;
1096     pipeline->GetHostParentOffsetToWindow();
1097     Inspector::GetRectangleById(inspectorId, rect);
1098     EXPECT_NE(rect.windowOffset, searchedNode->GetOffsetRelativeToWindow());
1099 }
1100 
1101 /**
1102  * @tc.name: InspectorTestNg025
1103  * @tc.desc: Test the GetRectangleById
1104  * @tc.type: FUNC
1105  */
1106 HWTEST_F(InspectorTestNg, InspectorTestNg025, TestSize.Level1)
1107 {
1108     // tc.steps: step1. add frameNode to arkui tree with inspector id test
1109     // tc.expected: expect the function GetFrameNodeByKey get the frameNode
1110     std::string inspectorId = "test";
1111     auto rootNode = FrameNode::CreateFrameNode(V2::ROOT_ETS_TAG,
1112         ElementRegister::GetInstance()->MakeUniqueId(), AceType::MakeRefPtr<Pattern>());
1113     auto frameNode = FrameNode::CreateFrameNode(V2::TEXT_ETS_TAG,
1114         ElementRegister::GetInstance()->MakeUniqueId(), AceType::MakeRefPtr<Pattern>());
1115     frameNode->UpdateInspectorId(inspectorId);
1116     auto context = PipelineContext::GetCurrentContext();
1117     ASSERT_NE(context, nullptr);
1118     context->rootNode_ = rootNode;
1119     context->rootNode_->SetGeometryNode(AceType::MakeRefPtr<GeometryNode>());
1120     rootNode->AddChild(frameNode);
1121     auto searchedNode = Inspector::GetFrameNodeByKey(inspectorId, true);
1122     EXPECT_NE(searchedNode, nullptr);
1123 
1124     OHOS::Ace::NG::Rectangle rect;
1125     Inspector::GetRectangleById(inspectorId, rect);
1126     EXPECT_EQ(rect.size.Width(), 0.0f);
1127     auto renderContext = AceType::DynamicCast<MockRenderContext>(searchedNode->GetRenderContext());
1128     EXPECT_NE(renderContext, nullptr);
1129 
1130     const double halfDimension = 200.0;
1131     renderContext->paintRect_ = { 2.0f, 2.0f, 3.0f, 3.0f };
1132     DimensionOffset offset = DimensionOffset(
1133         Dimension(halfDimension, DimensionUnit::PX), Dimension(halfDimension, DimensionUnit::PX));
1134     renderContext->UpdateTransformCenter(offset);
1135     EXPECT_TRUE(renderContext->GetTransformCenter().has_value());
1136     Inspector::GetRectangleById(inspectorId, rect);
1137     EXPECT_EQ(rect.scale.centerX, offset.GetX().ConvertToVp());
1138     EXPECT_EQ(rect.scale.centerY, offset.GetY().ConvertToVp());
1139 
1140     offset = DimensionOffset(
1141         Dimension(halfDimension, DimensionUnit::PX), Dimension(halfDimension, DimensionUnit::PERCENT));
1142     renderContext->UpdateTransformCenter(offset);
1143     Inspector::GetRectangleById(inspectorId, rect);
1144     EXPECT_EQ(rect.scale.centerX, offset.GetX().ConvertToVp());
1145     EXPECT_NE(rect.scale.centerY, offset.GetY().ConvertToVp());
1146 
1147     offset = DimensionOffset(
1148         Dimension(halfDimension, DimensionUnit::PERCENT), Dimension(halfDimension, DimensionUnit::PERCENT));
1149     renderContext->UpdateTransformCenter(offset);
1150     Inspector::GetRectangleById(inspectorId, rect);
1151     EXPECT_NE(rect.scale.centerX, offset.GetX().ConvertToVp());
1152     EXPECT_NE(rect.scale.centerY, offset.GetY().ConvertToVp());
1153 }
1154 
1155 /**
1156  * @tc.name: InspectorTestNg026
1157  * @tc.desc: Test the GetRectangleById
1158  * @tc.type: FUNC
1159  */
1160 HWTEST_F(InspectorTestNg, InspectorTestNg026, TestSize.Level1)
1161 {
1162     // tc.steps: step1. add frameNode to arkui tree with inspector id test
1163     // tc.expected: expect the function GetFrameNodeByKey get the frameNode
1164     std::string inspectorId = "test";
1165     auto rootNode = FrameNode::CreateFrameNode(V2::ROOT_ETS_TAG,
1166         ElementRegister::GetInstance()->MakeUniqueId(), AceType::MakeRefPtr<Pattern>());
1167     auto frameNode = FrameNode::CreateFrameNode(V2::TEXT_ETS_TAG,
1168         ElementRegister::GetInstance()->MakeUniqueId(), AceType::MakeRefPtr<Pattern>());
1169     frameNode->UpdateInspectorId(inspectorId);
1170     auto context = PipelineContext::GetCurrentContext();
1171     ASSERT_NE(context, nullptr);
1172     context->rootNode_ = rootNode;
1173     context->rootNode_->SetGeometryNode(AceType::MakeRefPtr<GeometryNode>());
1174     rootNode->AddChild(frameNode);
1175     auto searchedNode = Inspector::GetFrameNodeByKey(inspectorId, true);
1176     EXPECT_NE(searchedNode, nullptr);
1177 
1178     OHOS::Ace::NG::Rectangle rect;
1179     Inspector::GetRectangleById(inspectorId, rect);
1180     EXPECT_EQ(rect.size.Width(), 0.0f);
1181     auto renderContext = AceType::DynamicCast<MockRenderContext>(searchedNode->GetRenderContext());
1182     EXPECT_NE(renderContext, nullptr);
1183 
1184     CalcDimension x(30, DimensionUnit::VP);
1185     CalcDimension y(20, DimensionUnit::VP);
1186     CalcDimension z(20, DimensionUnit::VP);
1187     renderContext->UpdateTransformTranslate(TranslateOptions(x, y, z));
1188     Inspector::GetRectangleById(inspectorId, rect);
1189     EXPECT_EQ(rect.translate.x, x.ConvertToVp());
1190     EXPECT_EQ(rect.translate.y, y.ConvertToVp());
1191 
1192     CalcDimension x2(30, DimensionUnit::PERCENT);
1193     CalcDimension y2(20, DimensionUnit::PERCENT);
1194     CalcDimension z2(20, DimensionUnit::PERCENT);
1195     renderContext->UpdateTransformTranslate(TranslateOptions(x2, y2, z2));
1196     Inspector::GetRectangleById(inspectorId, rect);
1197     EXPECT_NE(rect.translate.x, x.ConvertToVp());
1198     EXPECT_NE(rect.translate.y, y.ConvertToVp());
1199 }
1200 
1201 /**
1202  * @tc.name: InspectorInvalid001
1203  * @tc.desc: Test the SendEventByKey
1204  * @tc.type: FUNC
1205  */
1206 HWTEST_F(InspectorTestNg, InspectorInvalid001, TestSize.Level1)
1207 {
1208     // 设置PipelineContext返回空指针
1209     RefPtr<MockPipelineContext> pipeline_bak = MockPipelineContext::pipeline_;
1210     MockPipelineContext::pipeline_ = nullptr;
1211     bool result = Inspector::SendEventByKey("testKey", 0, "");
1212     MockPipelineContext::pipeline_ = pipeline_bak;
1213     EXPECT_FALSE(result);
1214 }
1215 
1216 /**
1217  * @tc.name: InspectorInvalid002
1218  * @tc.desc: Test the SendEventByKey
1219  * @tc.type: FUNC
1220  */
1221 HWTEST_F(InspectorTestNg, InspectorInvalid002, TestSize.Level1)
1222 {
1223     auto context = PipelineContext::GetCurrentContext();
1224     auto rootNode = context->rootNode_;
1225     context->rootNode_ = nullptr;
1226     bool result = Inspector::SendEventByKey("testKey", 0, "");
1227     context->rootNode_ = rootNode;
1228     EXPECT_FALSE(result);
1229 }
1230 
1231 /**
1232  * @tc.name: InspectorInvalid003
1233  * @tc.desc: Test the operation of GetInspectorNodeByKey
1234  * @tc.type: FUNC
1235  */
1236 HWTEST_F(InspectorTestNg, InspectorInvalid003, TestSize.Level1)
1237 {
1238     // 设置PipelineContext返回空指针
1239     RefPtr<MockPipelineContext> pipeline_bak = MockPipelineContext::pipeline_;
1240     MockPipelineContext::pipeline_ = nullptr;
1241     std::string result = Inspector::GetInspectorNodeByKey("testKey");
1242     MockPipelineContext::pipeline_ = pipeline_bak;
1243     EXPECT_EQ(result, "");
1244 }
1245 
1246 /**
1247  * @tc.name: InspectorInvalid004
1248  * @tc.desc: Test the operation of GetInspectorNodeByKey
1249  * @tc.type: FUNC
1250  */
1251 HWTEST_F(InspectorTestNg, InspectorInvalid004, TestSize.Level1)
1252 {
1253     auto context = PipelineContext::GetCurrentContext();
1254     auto rootNode = context->rootNode_;
1255     context->rootNode_ = nullptr;
1256     std::string result = Inspector::GetInspectorNodeByKey("testKey");
1257     context->rootNode_ = rootNode;
1258     EXPECT_EQ(result, "");
1259 }
1260 
1261 /**
1262  * @tc.name: InspectorInvalid005
1263  * @tc.desc: Test the operation of GetRectangleById
1264  * @tc.type: FUNC
1265  */
1266 HWTEST_F(InspectorTestNg, InspectorInvalid005, TestSize.Level1)
1267 {
1268     // 设置PipelineContext返回空指针
1269     RefPtr<MockPipelineContext> pipeline_bak = MockPipelineContext::pipeline_;
1270     MockPipelineContext::pipeline_ = nullptr;
1271     OHOS::Ace::NG::Rectangle rect;
1272     Inspector::GetRectangleById("testKey", rect);
1273     MockPipelineContext::pipeline_ = pipeline_bak;
1274     EXPECT_EQ(rect.screenRect.height_, 0.0);
1275     EXPECT_EQ(rect.screenRect.width_, 0.0);
1276     EXPECT_EQ(rect.screenRect.x_, 0.0);
1277     EXPECT_EQ(rect.screenRect.y_, 0.0);
1278 }
1279 
1280 /**
1281  * @tc.name: InspectorInvalid006
1282  * @tc.desc: Test the operation of GetRectangleById
1283  * @tc.type: FUNC
1284  */
1285 HWTEST_F(InspectorTestNg, InspectorInvalid006, TestSize.Level1)
1286 {
1287     auto context = PipelineContext::GetCurrentContext();
1288     auto rootNode = context->rootNode_;
1289     context->rootNode_ = nullptr;
1290     OHOS::Ace::NG::Rectangle rect;
1291     Inspector::GetRectangleById("testKey", rect);
1292     context->rootNode_ = rootNode;
1293     EXPECT_EQ(rect.screenRect.height_, 0.0);
1294     EXPECT_EQ(rect.screenRect.width_, 0.0);
1295     EXPECT_EQ(rect.screenRect.x_, 0.0);
1296     EXPECT_EQ(rect.screenRect.y_, 0.0);
1297 }
1298 
1299 /**
1300  * @tc.name: InspectorInvalid007
1301  * @tc.desc: Test the operation of GetInspector
1302  * @tc.type: FUNC
1303  */
1304 HWTEST_F(InspectorTestNg, InspectorInvalid007, TestSize.Level1)
1305 {
1306     // 设置PipelineContext返回空指针
1307     RefPtr<MockPipelineContext> pipeline_bak = MockPipelineContext::pipeline_;
1308     MockPipelineContext::pipeline_ = nullptr;
1309     auto result = Inspector::GetInspector(false);
1310     MockPipelineContext::pipeline_ = pipeline_bak;
1311     EXPECT_EQ(result, "{\"$type\":\"root\"}");
1312 }
1313 
1314 /**
1315  * @tc.name: InspectorInvalid008
1316  * @tc.desc: Test the operation of GetInspector
1317  * @tc.type: FUNC
1318  */
1319 HWTEST_F(InspectorTestNg, InspectorInvalid008, TestSize.Level1)
1320 {
1321     auto stageNode = FrameNode::CreateFrameNode(
1322         V2::STAGE_ETS_TAG, ElementRegister::GetInstance()->MakeUniqueId(), AceType::MakeRefPtr<Pattern>());
1323     auto context = MockPipelineContext::GetCurrentContext();
1324     RefPtr<MockStageManager> stageManager = AceType::MakeRefPtr<MockStageManager>(stageNode);
1325     auto stageManagerBak = context->stageManager_;
1326     context->stageManager_ = stageManager;
1327     RefPtr<FrameNode> nullNode = nullptr;
1328     EXPECT_CALL(*stageManager, GetLastPage()).Times(1).WillOnce(Return(nullNode));
1329     auto result = Inspector::GetInspector(false);
1330     context->stageManager_ = stageManagerBak;
1331     EXPECT_EQ(result, "{\"$type\":\"root\",\"width\":\"720.000000\",\"height\":\"1280.000000\",\"$resolution\":\"1.000000\"}");
1332 }
1333 
1334 /**
1335  * @tc.name: InspectorInvalid009
1336  * @tc.desc: Test the operation of GetInspectorOfNode
1337  * @tc.type: FUNC
1338  */
1339 HWTEST_F(InspectorTestNg, InspectorInvalid009, TestSize.Level1)
1340 {
1341     // 设置PipelineContext返回空指针
1342     RefPtr<MockPipelineContext> pipeline_bak = MockPipelineContext::pipeline_;
1343     MockPipelineContext::pipeline_ = nullptr;
1344     auto frameNode = FrameNode::CreateFrameNode("button", 102, AceType::MakeRefPtr<Pattern>(), true);
1345     auto result = Inspector::GetInspectorOfNode(frameNode);
1346     MockPipelineContext::pipeline_ = pipeline_bak;
1347     EXPECT_EQ(result, "{}");
1348 }
1349 
1350 /**
1351  * @tc.name: InspectorInvalid010
1352  * @tc.desc: Test the operation of GetInspectorOfNode
1353  * @tc.type: FUNC
1354  */
1355 HWTEST_F(InspectorTestNg, InspectorInvalid010, TestSize.Level1)
1356 {
1357     auto stageNode = FrameNode::CreateFrameNode(
1358         V2::STAGE_ETS_TAG, ElementRegister::GetInstance()->MakeUniqueId(), AceType::MakeRefPtr<Pattern>());
1359     auto context = MockPipelineContext::GetCurrentContext();
1360     RefPtr<MockStageManager> stageManager = AceType::MakeRefPtr<MockStageManager>(stageNode);
1361     auto stageManagerBak = context->stageManager_;
1362     context->stageManager_ = stageManager;
1363     RefPtr<FrameNode> nullNode = nullptr;
1364     EXPECT_CALL(*stageManager, GetLastPage()).Times(1).WillOnce(Return(nullNode));
1365     auto frameNode = FrameNode::CreateFrameNode("button", 102, AceType::MakeRefPtr<Pattern>(), true);
1366     auto result = Inspector::GetInspectorOfNode(frameNode);
1367     context->stageManager_ = stageManagerBak;
1368     EXPECT_EQ(result, "{\"width\":\"720.000000\",\"height\":\"1280.000000\",\"$resolution\":\"1.000000\"}");
1369 }
1370 
1371 /**
1372  * @tc.name: InspectorInvalid011
1373  * @tc.desc: Test the operation of GetInspectorOfNode
1374  * @tc.type: FUNC
1375  */
1376 HWTEST_F(InspectorTestNg, InspectorInvalid011, TestSize.Level1)
1377 {
1378     auto result = Inspector::GetInspectorOfNode(nullptr);
1379     EXPECT_EQ(result, "{\"width\":\"720.000000\",\"height\":\"1280.000000\",\"$resolution\":\"1.000000\"}");
1380 }
1381 
1382 /**
1383  * @tc.name: InspectorInvalid012
1384  * @tc.desc: Test the operation of GetSubWindowInspector
1385  * @tc.type: FUNC
1386  */
1387 HWTEST_F(InspectorTestNg, InspectorInvalid012, TestSize.Level1)
1388 {
1389     // 设置PipelineContext返回空指针
1390     RefPtr<MockPipelineContext> pipeline_bak = MockPipelineContext::pipeline_;
1391     MockPipelineContext::pipeline_ = nullptr;
1392     auto result = Inspector::GetSubWindowInspector();
1393     MockPipelineContext::pipeline_ = pipeline_bak;
1394     EXPECT_EQ(result, "{\"$type\":\"root\"}");
1395 }
1396 
1397 /**
1398  * @tc.name: InspectorInvalid013
1399  * @tc.desc: Test the operation of GetSubWindowInspector
1400  * @tc.type: FUNC
1401  */
1402 HWTEST_F(InspectorTestNg, InspectorInvalid013, TestSize.Level1)
1403 {
1404     // auto rootNode = FrameNode::CreateFrameNode(
1405     //     V2::OVERLAY_ETS_TAG, ElementRegister::GetInstance()->MakeUniqueId(), AceType::MakeRefPtr<Pattern>());
1406     auto context = MockPipelineContext::GetCurrentContext();
1407     RefPtr<MockOverlayManager> overlayManager = AceType::MakeRefPtr<MockOverlayManager>(nullptr);
1408     overlayManager->rootNodeWeak_ = nullptr;
1409     auto overlayManagerBak = context->overlayManager_;
1410     context->overlayManager_ = overlayManager;
1411     auto result = Inspector::GetSubWindowInspector();
1412     context->overlayManager_ = overlayManagerBak;
1413     EXPECT_EQ(result, "{\"$type\":\"root\",\"width\":\"720.000000\",\"height\":\"1280.000000\",\"$resolution\":\"1.000000\"}");
1414 }
1415 
1416 /**
1417  * @tc.name: InspectorInvalid014
1418  * @tc.desc: Test the operation of GetInspectorTree
1419  * @tc.type: FUNC
1420  */
1421 HWTEST_F(InspectorTestNg, InspectorInvalid014, TestSize.Level1)
1422 {
1423     // 设置PipelineContext返回空指针
1424     RefPtr<MockPipelineContext> pipeline_bak = MockPipelineContext::pipeline_;
1425     MockPipelineContext::pipeline_ = nullptr;
1426     NG::InspectorTreeMap treesInfos;
1427     Inspector::GetInspectorTree(treesInfos);
1428     EXPECT_TRUE(treesInfos.empty());
1429     MockPipelineContext::pipeline_ = pipeline_bak;
1430 }
1431 
1432 /**
1433  * @tc.name: InspectorInvalid015
1434  * @tc.desc: Test the operation of GetInspectorTree
1435  * @tc.type: FUNC
1436  */
1437 HWTEST_F(InspectorTestNg, InspectorInvalid015, TestSize.Level1)
1438 {
1439     // 设置StageManager返回空指针
1440     auto context = MockPipelineContext::GetCurrentContext();
1441     auto stageManagerBak = context->stageManager_;
1442     context->stageManager_ = nullptr;
1443     NG::InspectorTreeMap treesInfos;
1444     Inspector::GetInspectorTree(treesInfos);
1445     EXPECT_TRUE(treesInfos.empty());
1446     context->stageManager_ = stageManagerBak;
1447 }
1448 
1449 /**
1450  * @tc.name: InspectorInvalid016
1451  * @tc.desc: Test the operation of GetInspectorTree
1452  * @tc.type: FUNC
1453  */
1454 HWTEST_F(InspectorTestNg, InspectorInvalid016, TestSize.Level1)
1455 {
1456     // 设置StageManager GetLastPage方法返回空指针
1457     auto stageNode = FrameNode::CreateFrameNode(
1458         V2::STAGE_ETS_TAG, ElementRegister::GetInstance()->MakeUniqueId(), AceType::MakeRefPtr<Pattern>());
1459     auto context = MockPipelineContext::GetCurrentContext();
1460     RefPtr<MockStageManager> stageManager = AceType::MakeRefPtr<MockStageManager>(stageNode);
1461     auto stageManagerBak = context->stageManager_;
1462     context->stageManager_ = stageManager;
1463     RefPtr<FrameNode> nullNode = nullptr;
1464     EXPECT_CALL(*stageManager, GetLastPage()).Times(1).WillOnce(Return(nullNode));
1465     NG::InspectorTreeMap treesInfos;
1466     Inspector::GetInspectorTree(treesInfos);
1467     EXPECT_TRUE(treesInfos.empty());
1468     context->stageManager_ = stageManagerBak;
1469 }
1470 
1471 /**
1472  * @tc.name: InspectorInvalid017
1473  * @tc.desc: Test the operation of GetInspectorTree
1474  * @tc.type: FUNC
1475  */
1476 HWTEST_F(InspectorTestNg, InspectorInvalid017, TestSize.Level1)
1477 {
1478     // 设置PipelineContext返回空指针
1479     RefPtr<MockPipelineContext> pipeline_bak = MockPipelineContext::pipeline_;
1480     MockPipelineContext::pipeline_ = nullptr;
1481     NG::InspectorTreeMap treesInfos;
1482     Inspector::GetRecordAllPagesNodes(treesInfos);
1483     EXPECT_TRUE(treesInfos.empty());
1484     MockPipelineContext::pipeline_ = pipeline_bak;
1485 }
1486 
1487 /**
1488  * @tc.name: InspectorInvalid018
1489  * @tc.desc: Test the operation of GetInspectorTree
1490  * @tc.type: FUNC
1491  */
1492 HWTEST_F(InspectorTestNg, InspectorInvalid018, TestSize.Level1)
1493 {
1494     // 设置StageManager返回空指针
1495     auto context = MockPipelineContext::GetCurrentContext();
1496     auto stageManagerBak = context->stageManager_;
1497     context->stageManager_ = nullptr;
1498     NG::InspectorTreeMap treesInfos;
1499     Inspector::GetRecordAllPagesNodes(treesInfos);
1500     EXPECT_TRUE(treesInfos.empty());
1501     context->stageManager_ = stageManagerBak;
1502 }
1503 
1504 /**
1505  * @tc.name: InspectorInvalid019
1506  * @tc.desc: Test the operation of GetInspectorTree
1507  * @tc.type: FUNC
1508  */
1509 HWTEST_F(InspectorTestNg, InspectorInvalid019, TestSize.Level1)
1510 {
1511     // 设置StageManager GetStageNode方法返回空指针
1512     auto context = MockPipelineContext::GetCurrentContext();
1513     RefPtr<MockStageManager> stageManager = AceType::MakeRefPtr<MockStageManager>(nullptr);
1514     auto stageManagerBak = context->stageManager_;
1515     context->stageManager_ = stageManager;
1516     NG::InspectorTreeMap treesInfos;
1517     Inspector::GetInspectorTree(treesInfos);
1518     EXPECT_TRUE(treesInfos.empty());
1519     context->stageManager_ = stageManagerBak;
1520 }
1521 
1522 /**
1523  * @tc.name: InspectorFilterTest001
1524  * @tc.desc: Test the operation of FilterEmptyInitially
1525  * @tc.type: FUNC
1526  */
1527 HWTEST_F(InspectorTestNg, InspectorFilterTest001, TestSize.Level1)
1528 {
1529     auto filter = std::make_unique<InspectorFilter>();
1530     EXPECT_TRUE(filter->FilterEmpty());
1531 }
1532 
1533 /**
1534 * @tc.name: InspectorFilterTest002
1535 * @tc.desc: Test the operation of FilterEmptyInitially
1536 * @tc.type: FUNC
1537 */
1538 HWTEST_F(InspectorTestNg, InspectorFilterTest002, TestSize.Level1)
1539 {
1540     auto filter = std::make_unique<InspectorFilter>();
1541     EXPECT_TRUE(filter->CheckFixedAttr(FIXED_ATTR_ID));
1542 }
1543 
1544 /**
1545 * @tc.name: InspectorFilterTest003
1546 * @tc.desc: Test the operation of FilterEmptyInitially
1547 * @tc.type: FUNC
1548 */
1549 HWTEST_F(InspectorTestNg, InspectorFilterTest003, TestSize.Level1)
1550 {
1551     auto filter = std::make_unique<InspectorFilter>();
1552     EXPECT_TRUE(filter->CheckExtAttr("some_attr"));
1553 }
1554 
1555 /**
1556 * @tc.name: InspectorFilterTest004
1557 * @tc.desc: Test the operation of FilterEmptyInitially
1558 * @tc.type: FUNC
1559 */
1560 HWTEST_F(InspectorTestNg, InspectorFilterTest004, TestSize.Level1)
1561 {
1562     auto filter = std::make_unique<InspectorFilter>();
1563     filter->AddFilterAttr("id");
1564     EXPECT_TRUE(filter->CheckFixedAttr(FIXED_ATTR_ID));
1565     EXPECT_FALSE(filter->CheckFixedAttr(FIXED_ATTR_CONTENT));
1566 }
1567 
1568 /**
1569 * @tc.name: InspectorFilterTest005
1570 * @tc.desc: Test the operation of FilterEmptyInitially
1571 * @tc.type: FUNC
1572 */
1573 HWTEST_F(InspectorTestNg, InspectorFilterTest005, TestSize.Level1)
1574 {
1575     auto filter = std::make_unique<InspectorFilter>();
1576     filter->AddFilterAttr("id");
1577     filter->AddFilterAttr("content");
1578 
1579     EXPECT_TRUE(filter->CheckFixedAttr(FIXED_ATTR_ID));
1580     EXPECT_TRUE(filter->CheckFixedAttr(FIXED_ATTR_CONTENT));
1581     EXPECT_FALSE(filter->CheckFixedAttr(FIXED_ATTR_SRC));
1582 }
1583 
1584 /**
1585 * @tc.name: InspectorFilterTest006
1586 * @tc.desc: Test the operation of FilterEmptyInitially
1587 * @tc.type: FUNC
1588 */
1589 HWTEST_F(InspectorTestNg, InspectorFilterTest006, TestSize.Level1)
1590 {
1591     auto filter = std::make_unique<InspectorFilter>();
1592     filter->AddFilterAttr("custom_attr");
1593 
1594     EXPECT_TRUE(filter->CheckExtAttr("custom_attr"));
1595     EXPECT_FALSE(filter->CheckExtAttr("other_attr"));
1596 }
1597 
1598 /**
1599 * @tc.name: InspectorFilterTest007
1600 * @tc.desc: Test the operation of FilterEmptyInitially
1601 * @tc.type: FUNC
1602 */
1603 HWTEST_F(InspectorTestNg, InspectorFilterTest007, TestSize.Level1)
1604 {
1605     auto filter = std::make_unique<InspectorFilter>();
1606     filter->AddFilterAttr("id");
1607 
1608     EXPECT_TRUE(filter->CheckFilterAttr(FIXED_ATTR_ID, nullptr));
1609     EXPECT_FALSE(filter->CheckFilterAttr(FIXED_ATTR_CONTENT, nullptr));
1610 }
1611 
1612 /**
1613 * @tc.name: InspectorFilterTest008
1614 * @tc.desc: Test the operation of FilterEmptyInitially
1615 * @tc.type: FUNC
1616 */
1617 HWTEST_F(InspectorTestNg, InspectorFilterTest008, TestSize.Level1)
1618 {
1619     auto filter = std::make_unique<InspectorFilter>();
1620     filter->AddFilterAttr("custom_attr");
1621 
1622     EXPECT_TRUE(filter->CheckFilterAttr(FIXED_ATTR_ID, "custom_attr"));
1623     EXPECT_FALSE(filter->CheckFilterAttr(FIXED_ATTR_ID, "other_attr"));
1624 }
1625 
1626 /**
1627 * @tc.name: InspectorFilterTest009
1628 * @tc.desc: Test the operation of FilterEmptyInitially
1629 * @tc.type: FUNC
1630 */
1631 HWTEST_F(InspectorTestNg, InspectorFilterTest009, TestSize.Level1)
1632 {
1633     auto filter = std::make_unique<InspectorFilter>();
1634     filter->AddFilterAttr("id");
1635     filter->AddFilterAttr("content");
1636 
1637    EXPECT_TRUE(filter->IsFastFilter());
1638 }
1639 
1640 /**
1641 * @tc.name: InspectorFilterTest010
1642 * @tc.desc: Test the operation of FilterEmptyInitially
1643 * @tc.type: FUNC
1644 */
1645 HWTEST_F(InspectorTestNg, InspectorFilterTest010, TestSize.Level1)
1646 {
1647     auto filter = std::make_unique<InspectorFilter>();
1648     filter->AddFilterAttr("custom_attr");
1649 
1650     EXPECT_FALSE(filter->IsFastFilter());
1651 }
1652 
1653 /**
1654 * @tc.name: InspectorFilterTest011
1655 * @tc.desc: Test the operation of FilterEmptyInitially
1656 * @tc.type: FUNC
1657 */
1658 HWTEST_F(InspectorTestNg, InspectorFilterTest011, TestSize.Level1)
1659 {
1660     auto filter = std::make_unique<InspectorFilter>();
1661     std::string id = "test_id";
1662     filter->SetFilterID(id);
1663 
1664     EXPECT_EQ(id, filter->GetFilterID());
1665 }
1666 
1667 /**
1668 * @tc.name: InspectorFilterTest012
1669 * @tc.desc: Test the operation of FilterEmptyInitially
1670 * @tc.type: FUNC
1671 */
1672 HWTEST_F(InspectorTestNg, InspectorFilterTest012, TestSize.Level1)
1673 {
1674     auto filter = std::make_unique<InspectorFilter>();
1675     size_t depth = 5;
1676     filter->SetFilterDepth(depth);
1677     EXPECT_EQ(depth, filter-> GetFilterDepth());
1678 }
1679 
HasInternalIds(const std::unique_ptr<JsonValue> & children)1680 bool HasInternalIds(const std::unique_ptr<JsonValue>& children)
1681 {
1682     auto hasInternalIds = false;
1683     CHECK_NULL_RETURN(children, false);
1684     for (size_t i = 0; i < children->GetArraySize(); i++) {
1685         auto child = children->GetArrayItem(i);
1686         if (child->GetValue("$type")->GetString() == "button") {
1687             auto internal = child->Contains("$INTERNAL_IDS");
1688             if (internal) {
1689                 hasInternalIds = true;
1690                 break;
1691             }
1692         }
1693     }
1694     return hasInternalIds;
1695 }
1696 
1697 /**
1698  * @tc.name: InspectorTestNg027
1699  * @tc.desc: Test the operation of GetInspector
1700  * @tc.type: FUNC
1701  */
1702 HWTEST_F(InspectorTestNg, InspectorTestNg027, TestSize.Level1)
1703 {
1704     auto context = PipelineContext::GetCurrentContext();
1705     ASSERT_NE(context, nullptr);
1706 
1707     auto id = ElementRegister::GetInstance()->MakeUniqueId();
1708     RefPtr<FrameNode> stageNode = FrameNode::CreateFrameNode("sageNode", id, AceType::MakeRefPtr<Pattern>(), true);
1709     context->stageManager_ = AceType::MakeRefPtr<StageManager>(stageNode);
1710     stageNode->children_.clear();
1711 
1712     auto id2 = ElementRegister::GetInstance()->MakeUniqueId();
1713     const RefPtr<FrameNode> pageA = FrameNode::CreateFrameNode("PageA", id2,
1714         AceType::MakeRefPtr<PagePattern>(AceType::MakeRefPtr<PageInfo>()));
1715     stageNode->AddChild(pageA);
1716     auto id3 = ElementRegister::GetInstance()->MakeUniqueId();
1717 
1718     auto button = FrameNode::CreateFrameNode("button", id3, AceType::MakeRefPtr<Pattern>(), true);
1719     pageA->AddChild(button);
1720 
1721     auto id4 = ElementRegister::GetInstance()->MakeUniqueId();
1722     auto text = FrameNode::CreateFrameNode("text", id4, AceType::MakeRefPtr<Pattern>(), true);
1723     button->AddChild(text);
1724     button->isActive_ = true;
1725 
1726     std::string tree = Inspector::GetInspector();
1727     auto jsonRoot  = JsonUtil::ParseJsonString(tree);
1728     ASSERT_NE(jsonRoot, nullptr);
1729 
1730     auto children = jsonRoot->GetValue("$children");
1731     ASSERT_TRUE(children->IsArray());
1732     auto hasInternalIds = HasInternalIds(children);
1733     ASSERT_FALSE(hasInternalIds);
1734 
1735     text->SetInternal();
1736     tree = Inspector::GetInspector();
1737     jsonRoot  = JsonUtil::ParseJsonString(tree);
1738     ASSERT_NE(jsonRoot, nullptr);
1739 
1740     children = jsonRoot->GetValue("$children");
1741     ASSERT_TRUE(children->IsArray());
1742     hasInternalIds = HasInternalIds(children);
1743     ASSERT_TRUE(hasInternalIds);
1744 }
1745 
1746 /**
1747  * @tc.name: GetOverlayNode_001
1748  * @tc.desc: Test the operation of GetOverlayNode in stage  overlay
1749  * column
1750  *    |--stage
1751  *       |--PageA
1752  *         |--frameNode
1753  *    |--overlay
1754  * @tc.type: FUNC
1755  */
1756 HWTEST_F(InspectorTestNg, GetOverlayNode_001, TestSize.Level1)
1757 {
1758     // tc.steps: step1. build tree
1759     auto context1 = PipelineContext::GetCurrentContext();
1760     ASSERT_NE(context1, nullptr);
1761     auto id0 = ElementRegister::GetInstance()->MakeUniqueId();
1762     RefPtr<FrameNode> columnNode = FrameNode::CreateFrameNode("Column", id0, AceType::MakeRefPtr<Pattern>(), false);
1763 
1764     auto id = ElementRegister::GetInstance()->MakeUniqueId();
1765     RefPtr<FrameNode> stageNode = FrameNode::CreateFrameNode("stage", id, AceType::MakeRefPtr<Pattern>(), false);
1766     context1->stageManager_ = AceType::MakeRefPtr<StageManager>(stageNode);
1767     stageNode->children_.clear();
1768     columnNode->AddChild(stageNode);
1769 
1770     auto overlayNode = FrameNode::CreateFrameNode(
1771         "overlayNode", ElementRegister::GetInstance()->MakeUniqueId(), AceType::MakeRefPtr<Pattern>(), false);
1772     columnNode->AddChild(overlayNode);
1773     auto testNode = FrameNode::CreateFrameNode(
1774         "testNode", ElementRegister::GetInstance()->MakeUniqueId(), AceType::MakeRefPtr<Pattern>(), false);
1775     overlayNode->AddChild(testNode);
1776 
1777     // tc.steps: step2 GetOverlayNode in containermodal
1778     auto id2 = ElementRegister::GetInstance()->MakeUniqueId();
1779     const RefPtr<FrameNode> pageA = FrameNode::CreateFrameNode("PageA", id2,
1780         AceType::MakeRefPtr<PagePattern>(AceType::MakeRefPtr<PageInfo>()));
1781     stageNode->AddChild(pageA);
1782 
1783     auto frameNode = FrameNode::CreateFrameNode(
1784         "frameNode0", ElementRegister::GetInstance()->MakeUniqueId(), AceType::MakeRefPtr<Pattern>(), false);
1785     pageA->AddChild(frameNode);
1786     NG::InspectorTreeMap treesInfos;
1787     Inspector::GetInspectorTree(treesInfos);
1788     auto it = treesInfos.find(testNode->GetId());
1789     EXPECT_TRUE(it != treesInfos.end());
1790 
1791     context1->stageManager_ = nullptr;
1792 }
1793 
1794 /**
1795  * @tc.name: GetOverlayNode_001
1796  * @tc.desc: Test the operation of GetOverlayNode in containermodal  overlay
1797  * column
1798  *    |--ContainerModal
1799  *       |--stage
1800  *          |--PageA
1801  *             |--frameNode
1802  *    |--overlay
1803  * @tc.type: FUNC
1804  */
1805 HWTEST_F(InspectorTestNg, GetOverlayNode_002, TestSize.Level1)
1806 {
1807     // tc.steps: step1. build tree
1808     auto context1 = PipelineContext::GetCurrentContext();
1809     ASSERT_NE(context1, nullptr);
1810 
1811     auto columnNode = FrameNode::CreateFrameNode(
1812         "Column", ElementRegister::GetInstance()->MakeUniqueId(), AceType::MakeRefPtr<Pattern>(), false);
1813 
1814     auto id0 = ElementRegister::GetInstance()->MakeUniqueId();
1815     RefPtr<FrameNode> contianerNode
1816         = FrameNode::CreateFrameNode(V2::CONTAINER_MODAL_ETS_TAG, id0, AceType::MakeRefPtr<Pattern>(), false);
1817     columnNode->AddChild(contianerNode);
1818 
1819     auto id = ElementRegister::GetInstance()->MakeUniqueId();
1820     RefPtr<FrameNode> stageNode = FrameNode::CreateFrameNode("stage", id, AceType::MakeRefPtr<Pattern>(), false);
1821     context1->stageManager_ = AceType::MakeRefPtr<StageManager>(stageNode);
1822     stageNode->children_.clear();
1823     contianerNode->AddChild(stageNode);
1824 
1825     auto overlayNode = FrameNode::CreateFrameNode(
1826         "overlayNode", ElementRegister::GetInstance()->MakeUniqueId(), AceType::MakeRefPtr<Pattern>(), false);
1827     columnNode->AddChild(overlayNode);
1828 
1829     auto testNode = FrameNode::CreateFrameNode(
1830         "testNode", ElementRegister::GetInstance()->MakeUniqueId(), AceType::MakeRefPtr<Pattern>(), false);
1831     overlayNode->AddChild(testNode);
1832 
1833     // tc.steps: step2 GetOverlayNode in containermodal
1834     auto id2 = ElementRegister::GetInstance()->MakeUniqueId();
1835     const RefPtr<FrameNode> pageA = FrameNode::CreateFrameNode("PageA", id2,
1836         AceType::MakeRefPtr<PagePattern>(AceType::MakeRefPtr<PageInfo>()));
1837     stageNode->AddChild(pageA);
1838 
1839     auto frameNode = FrameNode::CreateFrameNode(
1840         "frameNode0", ElementRegister::GetInstance()->MakeUniqueId(), AceType::MakeRefPtr<Pattern>(), false);
1841     pageA->AddChild(frameNode);
1842 
1843     NG::InspectorTreeMap treesInfos;
1844     Inspector::GetInspectorTree(treesInfos);
1845 
1846     auto it = treesInfos.find(testNode->GetId());
1847     EXPECT_TRUE(it != treesInfos.end());
1848 
1849     context1->stageManager_ = nullptr;
1850 }
1851 } // namespace OHOS::Ace::NG
1852