• 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/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/stage/page_pattern.h"
37 #include "core/components_ng/pattern/text/span_node.h"
38 #include "core/components_v2/inspector/inspector_constants.h"
39 #include "core/pipeline_ng/pipeline_context.h"
40 #include "base/json/json_util.h"
41 #include "core/components_ng/pattern/custom/custom_node.h"
42 
43 using namespace testing;
44 using namespace testing::ext;
45 namespace OHOS::Ace::NG {
46 namespace {
47 std::string key = "key";
48 const std::string TEXT_NODE_TYPE = "Text";
49 const std::string TEST_TEXT = "SomeText";
50 const char INSPECTOR_TYPE[] = "$type";
51 const char INSPECTOR_ID[] = "$ID";
52 const char INSPECTOR_DEBUGLINE[] = "$debugLine";
53 const char INSPECTOR_ATTRS[] = "$attrs";
54 const char INSPECTOR_CHILDREN[] = "$children";
55 }; // namespace
56 
57 class InspectorTestNg : public testing::Test {
58 public:
SetUpTestSuite()59     static void SetUpTestSuite()
60     {
61         MockPipelineContext::SetUp();
62     }
TearDownTestSuite()63     static void TearDownTestSuite()
64     {
65         MockPipelineContext::TearDown();
66     }
67 };
68 
69 /**
70  * @tc.name: InspectorTestNg001
71  * @tc.desc: Test the operation of Inspector
72  * @tc.type: FUNC
73  */
74 HWTEST_F(InspectorTestNg, InspectorTestNg001, TestSize.Level1)
75 {
76     auto id = ElementRegister::GetInstance()->MakeUniqueId();
77     RefPtr<FrameNode> ONE = FrameNode::CreateFrameNode("one", id, AceType::MakeRefPtr<Pattern>(), true);
78     auto id2 = ElementRegister::GetInstance()->MakeUniqueId();
79     const RefPtr<FrameNode> TWO = FrameNode::CreateFrameNode("two", id2, AceType::MakeRefPtr<Pattern>());
80     /**
81      * @tc.steps: step1. callback GetFrameNodeByKey
82      * @tc.expected: expect the function is run ok
83      */
84     auto nodePtr = Inspector::GetFrameNodeByKey(key);
85     EXPECT_EQ(nodePtr, nullptr);
86 
87     /**
88      * @tc.steps: step2. callback SetUp
89      * @tc.expected: expect context1 is not null
90      */
91     auto context1 = PipelineContext::GetCurrentContext();
92     ASSERT_NE(context1, nullptr);
93     auto nodePtr1 = Inspector::GetFrameNodeByKey(key);
94     EXPECT_EQ(nodePtr1, nullptr);
95 
96     /**
97      * @tc.steps: step3. callback GetFrameNodeByKey
98      * @tc.expected: expect nodePtr2 not null
99      */
100     context1->rootNode_ = ONE;
101     context1->rootNode_->AddChild(TWO);
102     auto rootNode = context1->GetRootElement();
103     ASSERT_NE(rootNode, nullptr);
104     auto nodePtr2 = Inspector::GetFrameNodeByKey(key);
105     EXPECT_EQ(nodePtr2, nullptr);
106 
107     auto nodePtr3 = Inspector::GetFrameNodeByKey("");
108     ASSERT_NE(nodePtr3, nullptr);
109 
110     context1->rootNode_ = nullptr;
111 }
112 
113 /**
114  * @tc.name: InspectorTestNg002
115  * @tc.desc: Test the operation of Inspector
116  * @tc.type: FUNC
117  */
118 HWTEST_F(InspectorTestNg, InspectorTestNg002, TestSize.Level1)
119 {
120     /**
121      * @tc.steps: step1. callback GetInspectorNodeByKey
122      * @tc.expected: expect the function is run ok
123      */
124     auto test = Inspector::GetInspectorNodeByKey(key);
125     EXPECT_EQ(test, "");
126 
127     /**
128      * @tc.steps: step2. callback SetUp
129      * @tc.expected: expect test1 is "".
130      */
131     auto context1 = PipelineContext::GetCurrentContext();
132     ASSERT_NE(context1, nullptr);
133     auto test1 = Inspector::GetInspectorNodeByKey(key);
134     EXPECT_EQ(test1, "");
135 
136     /**
137      * @tc.steps: step1. callback rootNode_
138      * @tc.expected: expect the function GetInspectorNodeByKey is return null
139      */
140     auto id = ElementRegister::GetInstance()->MakeUniqueId();
141     RefPtr<FrameNode> ONE = FrameNode::CreateFrameNode("one", id, AceType::MakeRefPtr<Pattern>(), true);
142     context1->rootNode_ = ONE;
143     ASSERT_NE(context1, nullptr);
144     auto test2 = Inspector::GetInspectorNodeByKey(key);
145     EXPECT_EQ(test2, "");
146     /**
147      * @tc.steps: step3. callback GetInspectorNodeByKey
148      * @tc.expected: expect nodePtr2 not null
149      */
150     auto test3 = Inspector::GetInspectorNodeByKey("");
151 
152     context1->rootNode_ = nullptr;
153 }
154 
155 /**
156  * @tc.name: InspectorTestNg003
157  * @tc.desc: Test the operation of Inspector
158  * @tc.type: FUNC
159  */
160 HWTEST_F(InspectorTestNg, InspectorTestNg003, TestSize.Level1)
161 {
162     /**
163      * @tc.steps: step1. callback GetInspector
164      * @tc.expected: expect the function is run ok
165      */
166     auto id = ElementRegister::GetInstance()->MakeUniqueId();
167     RefPtr<FrameNode> ONE = FrameNode::CreateFrameNode("one", id, AceType::MakeRefPtr<Pattern>(), true);
168     auto context1 = PipelineContext::GetCurrentContext();
169     ASSERT_NE(context1, nullptr);
170     context1->stageManager_ = AceType::MakeRefPtr<StageManager>(ONE);
171     auto id2 = ElementRegister::GetInstance()->MakeUniqueId();
172     const RefPtr<FrameNode> TWO = FrameNode::CreateFrameNode("stage", id2, AceType::MakeRefPtr<Pattern>());
173     ONE->AddChild(TWO);
174     auto id3 = ElementRegister::GetInstance()->MakeUniqueId();
175     const RefPtr<FrameNode> THREE = FrameNode::CreateFrameNode("three", id3, AceType::MakeRefPtr<Pattern>());
176     THREE->AddChild(ONE);
177 
178     /**
179      * @tc.steps: step2. call GetInspector
180      * @tc.expected: the return value is empty string
181      */
182     auto test1 = Inspector::GetInspector(false);
183     EXPECT_NE(test1, "");
184     auto test3 = Inspector::GetInspector(true);
185     EXPECT_NE(test3, "");
186     auto test4 = Inspector::GetInspectorOfNode(TWO);
187     EXPECT_NE(test4, "");
188 
189     RefPtr<MockPipelineContext> pipeline_bak = MockPipelineContext::pipeline_;
190     MockPipelineContext::pipeline_ = nullptr;
191     auto jsonRoot = JsonUtil::Create(true);
192     const char inspectorType[] = "$type";
193     const char inspectorRoot[] = "root";
194     jsonRoot->Put(inspectorType, inspectorRoot);
195     auto test5 = Inspector::GetInspector(false);
196     EXPECT_EQ(test5, jsonRoot->ToString());
197     MockPipelineContext::pipeline_ = pipeline_bak;
198 
199     InspectorFilter filter;
200     std::string testId = "test";
201     filter.SetFilterID(testId);
202     bool needThrow = false;
203     auto test6 = Inspector::GetInspector(false, filter, needThrow);
204     auto rootNode = context1->GetStageManager()->GetLastPage();
205     if (rootNode == nullptr) {
206         EXPECT_EQ(test6, jsonRoot->ToString());
207     } else {
208         EXPECT_NE(test6, "");
209     }
210     context1->stageManager_ = nullptr;
211 }
212 
213 /**
214  * @tc.name: InspectorTestNg004
215  * @tc.desc: Test the operation of View Inspector
216  * @tc.type: FUNC
217  */
218 HWTEST_F(InspectorTestNg, InspectorTestNg004, TestSize.Level1)
219 {
220     /**
221      * @tc.steps: step1. set rootNode and taskExecutor call SendEventByKey
222      * @tc.expected: expect return true
223      */
224     auto context = NG::PipelineContext::GetCurrentContext();
225     context->rootNode_ = FrameNode::CreateFrameNode("frameNode", 60, AceType::MakeRefPtr<Pattern>(), true);
226     context->rootNode_->SetGeometryNode(AceType::MakeRefPtr<GeometryNode>());
227     context->taskExecutor_ = AceType::MakeRefPtr<MockTaskExecutor>();
228     auto test3 = Inspector::SendEventByKey("", static_cast<int>(AceAction::ACTION_CLICK), "params");
229     EXPECT_EQ(test3, true);
230     test3 = Inspector::SendEventByKey("", static_cast<int>(AceAction::ACTION_LONG_CLICK), "params");
231     EXPECT_EQ(test3, true);
232     test3 = Inspector::SendEventByKey("", 31, "params");
233     EXPECT_EQ(test3, true);
234 
235     context->rootNode_ = nullptr;
236 }
237 
238 /**
239  * @tc.name: InspectorTestNg005
240  * @tc.desc: Test the operation of View Inspector
241  * @tc.type: FUNC
242  */
243 HWTEST_F(InspectorTestNg, InspectorTestNg005, TestSize.Level1)
244 {
245     /**
246      * @tc.steps: step1. callback HideAllMenus
247      * @tc.expected: expect the function is run ok
248      */
249     Inspector::HideAllMenus();
250     auto context = PipelineContext::GetCurrentContext();
251 
252     /**
253      * @tc.steps: step2. callback SetUp
254      * @tc.expected: step2. expect context1 is return null.
255      */
256     auto context1 = PipelineContext::GetCurrentContext();
257     ASSERT_NE(context1, nullptr);
258     Inspector::HideAllMenus();
259 }
260 
261 /**
262  * @tc.name: InspectorTestNg006
263  * @tc.desc: Test the operation of Inspector
264  * @tc.type: FUNC
265  */
266 HWTEST_F(InspectorTestNg, InspectorTestNg006, TestSize.Level1)
267 {
268     /**
269      * @tc.steps: step1. callback GetInspector
270      * @tc.expected: expect the function is run ok
271      */
272     auto context1 = PipelineContext::GetCurrentContext();
273     ASSERT_NE(context1, nullptr);
274 
275     auto id = ElementRegister::GetInstance()->MakeUniqueId();
276     RefPtr<FrameNode> ONE = FrameNode::CreateFrameNode("one", id, AceType::MakeRefPtr<Pattern>(), true);
277     context1->stageManager_ = AceType::MakeRefPtr<StageManager>(ONE);
278 
279     /**
280      * @tc.steps: step2 add child to two and create a temp node with tag "temp"
281                 call GetInspector
282      * @tc.expected: the return value is empty string
283      */
284     auto id2 = ElementRegister::GetInstance()->MakeUniqueId();
285     const RefPtr<FrameNode> TWO = FrameNode::CreateFrameNode("two", id2, AceType::MakeRefPtr<Pattern>());
286     ONE->children_.clear();
287     ONE->AddChild(TWO);
288     auto stageParent = FrameNode::CreateFrameNode("stageParent", 5, AceType::MakeRefPtr<Pattern>(), true);
289     stageParent->AddChild(ONE);
290 
291     const RefPtr<FrameNode> THREE = FrameNode::CreateFrameNode(
292         "three", ElementRegister::GetInstance()->MakeUniqueId(), AceType::MakeRefPtr<Pattern>());
293     const RefPtr<FrameNode> STAGE = FrameNode::CreateFrameNode(
294         "stage", ElementRegister::GetInstance()->MakeUniqueId(), AceType::MakeRefPtr<Pattern>(), true);
295     const RefPtr<FrameNode> PAGE = FrameNode::CreateFrameNode(
296         "page", ElementRegister::GetInstance()->MakeUniqueId(), AceType::MakeRefPtr<Pattern>(), true);
297     THREE->isInternal_ = true;
298     TWO->AddChild(PAGE);
299     TWO->AddChild(THREE);
300     TWO->AddChild(STAGE);
301     auto temp = FrameNode::CreateFrameNode("temp", 5, AceType::MakeRefPtr<Pattern>(), true);
302     STAGE->AddChild(temp);
303     ONE->tag_ = "stage";
304     auto test1 = Inspector::GetInspector(false);
305     EXPECT_NE(test1, "");
306 
307     PAGE->hostPageId_ = TWO->GetPageId();
308     auto test2 = Inspector::GetInspector(false);
309     EXPECT_NE(test2, "");
310 
311     PAGE->hostPageId_ = TWO->GetPageId() + 1;
312     test2 = Inspector::GetInspector(false);
313     EXPECT_NE(test2, "");
314 
315     TWO->children_.clear();
316     auto test3 = Inspector::GetInspector(false);
317     EXPECT_NE(test3, "");
318 
319     /**
320      *  ONE(stageNode)--TWO(GetLastPage())--PAGE
321      *                   |--THREE
322      *                   |--STAGE--temp
323      *                   |--frameNode
324      *                   |--frameNode2--frameNode3
325      */
326     /**
327      * @tc.steps: step3 add child to two and create a frame node tree
328             call GetInspector
329      * @tc.expected: the return value is not empty string
330      */
331     auto spanNode = SpanNode::GetOrCreateSpanNode(int32_t(191));
332     TWO->AddChild(spanNode);
333 
334     auto frameNode = FrameNode::CreateFrameNode("frameNode", 6, AceType::MakeRefPtr<Pattern>(), true);
335     TWO->AddChild(frameNode);
336     frameNode->isActive_ = true;
337     auto frameNode2 = FrameNode::CreateFrameNode("frameNode2", 62, AceType::MakeRefPtr<Pattern>(), true);
338     TWO->AddChild(frameNode2);
339     frameNode2->isActive_ = false;
340     auto frameNode3 = FrameNode::CreateFrameNode("frameNode3", 63, AceType::MakeRefPtr<Pattern>(), true);
341     frameNode2->AddChild(frameNode3);
342     test3 = Inspector::GetInspector(false);
343     EXPECT_NE(test3, "");
344     context1->stageManager_ = nullptr;
345 }
346 
347 /**
348  * @tc.name: InspectorTestNg007
349  * @tc.desc: Test the operation of Inspector
350  * @tc.type: FUNC
351  */
352 HWTEST_F(InspectorTestNg, InspectorTestNg007, TestSize.Level1)
353 {
354     /**
355      * @tc.steps: step1. callback GetInspector
356      * @tc.expected: expect the function is run ok
357      */
358     auto id = ElementRegister::GetInstance()->MakeUniqueId();
359     RefPtr<FrameNode> ONE = FrameNode::CreateFrameNode("one", id, AceType::MakeRefPtr<Pattern>(), true);
360     auto context1 = PipelineContext::GetCurrentContext();
361     ASSERT_NE(context1, nullptr);
362     context1->stageManager_ = AceType::MakeRefPtr<StageManager>(ONE);
363 
364     /**
365      * @tc.steps: step2. callback pop_back
366      * @tc.expected: expect clean children and pageRootNode is noll
367      */
368     auto pageRootNode = context1->GetStageManager()->GetLastPage();
369     auto test = Inspector::GetInspector(false);
370     auto str = "{\"$type\":\"root\",\"width\":\"720.000000\",\"height\":\"1280.000000\",\"$resolution\":\"1.000000\"}";
371     EXPECT_EQ(test, str);
372 
373     context1->stageManager_ = nullptr;
374 }
375 
376 /**
377  * @tc.name: InspectorTestNg008
378  * @tc.desc: Test the GetRectangleById
379  * @tc.type: FUNC
380  */
381 HWTEST_F(InspectorTestNg, InspectorTestNg008, TestSize.Level1)
382 {
383     /**
384      * @tc.steps: step1. creat frameNode
385      * @tc.expected: expect the function is run ok
386      */
387     auto id = ElementRegister::GetInstance()->MakeUniqueId();
388     RefPtr<FrameNode> ONE = FrameNode::CreateFrameNode("one", id, AceType::MakeRefPtr<Pattern>(), true);
389     auto context = NG::PipelineContext::GetCurrentContext();
390     ASSERT_NE(context, nullptr);
391 
392     /**
393      * @tc.steps: step2. assign value to rootNode_
394      * @tc.expected: rootNode_ pass non-null check.
395      */
396     context->rootNode_ = ONE;
397     context->rootNode_->SetGeometryNode(AceType::MakeRefPtr<GeometryNode>());
398 
399     /**
400      * @tc.steps: step3. construct assignments and call GetRectangleById.
401      * @tc.expected: expect the GetRectangleById is run ok and result is expected.
402      */
403     OHOS::Ace::NG::Rectangle rect;
404     string key = "";
405     Inspector::GetRectangleById(key, rect);
406     float zResult = 1.0f;
407     EXPECT_EQ(rect.scale.z, zResult);
408     context->rootNode_ = nullptr;
409 }
410 
411 /**
412  * @tc.name: InspectorTestNg009
413  * @tc.desc: Test the GetFrameNodeByKey
414  * @tc.type: FUNC
415  */
416 HWTEST_F(InspectorTestNg, InspectorTestNg009, TestSize.Level1)
417 {
418     auto id = ElementRegister::GetInstance()->MakeUniqueId();
419     RefPtr<FrameNode> ONE = FrameNode::CreateFrameNode("one", id, AceType::MakeRefPtr<Pattern>(), true);
420     auto id2 = ElementRegister::GetInstance()->MakeUniqueId();
421     const RefPtr<FrameNode> TWO = FrameNode::CreateFrameNode("two", id2, AceType::MakeRefPtr<Pattern>());
422     auto context = PipelineContext::GetCurrentContext();
423     ASSERT_NE(context, nullptr);
424     auto nodePtr = Inspector::GetFrameNodeByKey(key);
425     EXPECT_EQ(nodePtr, nullptr);
426 
427     Inspector::AddOffscreenNode(ONE);
428     nodePtr = Inspector::GetFrameNodeByKey("one");
429     EXPECT_EQ(nodePtr, 0);
430 
431     RefPtr<MockPipelineContext> pipeline_bak = MockPipelineContext::pipeline_;
432     MockPipelineContext::pipeline_ = nullptr;
433     context = PipelineContext::GetCurrentContext();
434     EXPECT_EQ(context, nullptr);
435     nodePtr = Inspector::GetFrameNodeByKey("two");
436     EXPECT_EQ(nodePtr, nullptr);
437     MockPipelineContext::pipeline_ = pipeline_bak;
438 }
439 
440 /**
441  * @tc.name: InspectorTestNg010
442  * @tc.desc: Test the GetRectangleById
443  * @tc.type: FUNC
444  */
445 HWTEST_F(InspectorTestNg, InspectorTestNg010, TestSize.Level1)
446 {
447     auto id = ElementRegister::GetInstance()->MakeUniqueId();
448     RefPtr<FrameNode> ONE = FrameNode::CreateFrameNode("one", id, AceType::MakeRefPtr<Pattern>(), true);
449     auto context = NG::PipelineContext::GetCurrentContext();
450     ASSERT_NE(context, nullptr);
451     context->rootNode_ = ONE;
452     context->rootNode_->SetGeometryNode(AceType::MakeRefPtr<GeometryNode>());
453     std::string key = "key";
454     OHOS::Ace::NG::Rectangle rect;
455     Inspector::GetRectangleById(key, rect);
456     EXPECT_EQ(rect.size.Width(), 0.0f);
457 
458     auto frameNode = Inspector::GetFrameNodeByKey("one");
459     RefPtr<RenderContext> renderContextBak = ONE->renderContext_;
460     ONE->renderContext_ = nullptr;
461     Inspector::GetRectangleById("one", rect);
462     EXPECT_EQ(rect.screenRect.Width(), 0.0f);
463     ONE->renderContext_ = renderContextBak;
464     EXPECT_EQ(rect.size.Width(), 0.0f);
465 }
466 
467 /**
468  * @tc.name: InspectorTestNg011
469  * @tc.desc: Test the operation of GetSubWindowInspector
470  * @tc.type: FUNC
471  */
472 HWTEST_F(InspectorTestNg, InspectorTestNg011, TestSize.Level1)
473 {
474     auto id = ElementRegister::GetInstance()->MakeUniqueId();
475     RefPtr<FrameNode> ONE = FrameNode::CreateFrameNode("one", id, AceType::MakeRefPtr<Pattern>(), true);
476     auto context = PipelineContext::GetCurrentContext();
477     ASSERT_NE(context, nullptr);
478     context->stageManager_ = AceType::MakeRefPtr<StageManager>(ONE);
479     auto pageRootNode = context->GetStageManager()->GetLastPage();
480     auto test = Inspector::GetSubWindowInspector(false);
481     auto str = "";
482     EXPECT_NE(test, str);
483     context->stageManager_ = nullptr;
484 }
485 
486 /**
487  * @tc.name: InspectorTestNg012
488  * @tc.desc: Test the operation of GetSimplifiedInspector
489  * @tc.type: FUNC
490  */
491 HWTEST_F(InspectorTestNg, InspectorTestNg012, TestSize.Level1)
492 {
493     auto id = ElementRegister::GetInstance()->MakeUniqueId();
494     RefPtr<FrameNode> ONE = FrameNode::CreateFrameNode("one", id, AceType::MakeRefPtr<Pattern>(), true);
495     auto context = PipelineContext::GetCurrentContext();
496     ASSERT_NE(context, nullptr);
497     context->stageManager_ = AceType::MakeRefPtr<StageManager>(ONE);
498     int32_t containerId = 1;
499     std::string result = Inspector::GetSimplifiedInspector(containerId, { false });
500     EXPECT_NE(result, "");
501     context->stageManager_ = nullptr;
502 }
503 
504 /**
505  * @tc.name: InspectorTestNg013
506  * @tc.desc: Test the function of InspectorFilter
507  * @tc.type: FUNC
508  */
509 HWTEST_F(InspectorTestNg, InspectorTestNg013, TestSize.Level1)
510 {
511     const char* hello = "hi";
512     InspectorFilter testFilter;
513     EXPECT_EQ(testFilter.CheckFilterAttr(FixedAttrBit::FIXED_ATTR_CONTENT, hello), true);
514     testFilter.SetFilterDepth(1);
515     std::string id = "id";
516     testFilter.SetFilterID(id);
517     testFilter.filterExt.emplace_back("abc");
518     testFilter.AddFilterAttr("focusable");
519     testFilter.AddFilterAttr("abc");
520     testFilter.AddFilterAttr("def");
521     EXPECT_EQ(testFilter.CheckFixedAttr(FixedAttrBit::FIXED_ATTR_CONTENT), false);
522     EXPECT_EQ(testFilter.CheckExtAttr("zzz"), false);
523     EXPECT_EQ(testFilter.CheckFilterAttr(FixedAttrBit::FIXED_ATTR_CONTENT, hello), false);
524     EXPECT_EQ(testFilter.IsFastFilter(), false);
525 }
526 
527 /**
528  * @tc.name: InspectorTestNg014
529  * @tc.desc: Test the function of InspectorFilter
530  * @tc.type: FUNC
531  */
532 HWTEST_F(InspectorTestNg, InspectorTestNg014, TestSize.Level1)
533 {
534     const char* hello = "hi";
535     InspectorFilter testFilter;
536     testFilter.AddFilterAttr("focusable");
537     EXPECT_EQ(testFilter.CheckFilterAttr(FixedAttrBit::FIXED_ATTR_FOCUSABLE, hello), true);
538 }
539 
540 /**
541  * @tc.name: InspectorTestNg015
542  * @tc.desc: Test the function of InspectorFilter
543  * @tc.type: FUNC
544  */
545 HWTEST_F(InspectorTestNg, InspectorTestNg015, TestSize.Level1)
546 {
547     const char* hello = "abc";
548     InspectorFilter testFilter;
549     testFilter.filterExt.emplace_back("abc");
550     testFilter.AddFilterAttr("focusable");
551     EXPECT_EQ(testFilter.CheckFilterAttr(FixedAttrBit::FIXED_ATTR_CONTENT, hello), true);
552 }
553 
554 /**
555  * @tc.name: InspectorTestNg016
556  * @tc.desc: Test the operation of GetInspectorTree
557  * @tc.type: FUNC
558  */
559 HWTEST_F(InspectorTestNg, InspectorTestNg016, TestSize.Level1)
560 {
561     // tc.steps: step1. callback GetInspectorTree
562     // tc.expected: expect the function is run ok
563     auto context1 = PipelineContext::GetCurrentContext();
564     ASSERT_NE(context1, nullptr);
565 
566     auto id = ElementRegister::GetInstance()->MakeUniqueId();
567     RefPtr<FrameNode> stageNode = FrameNode::CreateFrameNode("stage", id, AceType::MakeRefPtr<Pattern>(), true);
568     context1->stageManager_ = AceType::MakeRefPtr<StageManager>(stageNode);
569 
570     // tc.steps: step2 add lastPage and create a frame node tree to lastPage
571     auto id2 = ElementRegister::GetInstance()->MakeUniqueId();
572     const RefPtr<FrameNode> lastPage = FrameNode::CreateFrameNode("two", id2, AceType::MakeRefPtr<Pattern>());
573     stageNode->children_.clear();
574     stageNode->AddChild(lastPage);
575     auto stageParent = FrameNode::CreateFrameNode("stageParent", 5, AceType::MakeRefPtr<Pattern>(), true);
576     stageParent->AddChild(stageNode);
577     auto frameNode = FrameNode::CreateFrameNode("frameNode", 6, AceType::MakeRefPtr<Pattern>(), true);
578     lastPage->AddChild(frameNode);
579     frameNode->isActive_ = true;
580     auto frameNode2 = FrameNode::CreateFrameNode("frameNode2", 62, AceType::MakeRefPtr<Pattern>(), true);
581     lastPage->AddChild(frameNode2);
582     frameNode2->isActive_ = false;
583     auto frameNode3 = FrameNode::CreateFrameNode("frameNode3", 63, AceType::MakeRefPtr<Pattern>(), true);
584     frameNode2->AddChild(frameNode3);
585     NG::InspectorTreeMap treesInfos;
586     Inspector::GetInspectorTree(treesInfos);
587     EXPECT_TRUE(!treesInfos.empty());
588     context1->stageManager_ = nullptr;
589 }
590 
591 /**
592  * @tc.name: InspectorTestNg017
593  * @tc.desc: Test the operation of GetFrameNodeByKey
594  * @tc.type: FUNC
595  */
596 HWTEST_F(InspectorTestNg, InspectorTestNg017, TestSize.Level1)
597 {
598     // tc.steps: step1. add frameNode to arkui tree with inspector id text1
599     // tc.expected: expect the function GetFrameNodeByKey get the frameNode
600     std::string inspectorId = "text1";
601     auto rootNode = FrameNode::CreateFrameNode(V2::ROOT_ETS_TAG,
602         ElementRegister::GetInstance()->MakeUniqueId(), AceType::MakeRefPtr<Pattern>());
603     auto frameNode = FrameNode::CreateFrameNode(V2::TEXT_ETS_TAG,
604         ElementRegister::GetInstance()->MakeUniqueId(), AceType::MakeRefPtr<Pattern>());
605     frameNode->UpdateInspectorId(inspectorId);
606     auto context = PipelineContext::GetCurrentContext();
607     context->rootNode_ = rootNode;
608     rootNode->AddChild(frameNode);
609     auto searchedNode = Inspector::GetFrameNodeByKey(inspectorId);
610     EXPECT_EQ(frameNode, searchedNode);
611 
612     // tc.steps:    add offScreencreenNode to off screencreen node with inspector id text1
613     // tc.expected: expect the function GetFrameNodeByKey get the offScreencreenNode
614     auto offScreencreenNode = FrameNode::CreateFrameNode(V2::TEXT_ETS_TAG,
615         ElementRegister::GetInstance()->MakeUniqueId(), AceType::MakeRefPtr<Pattern>());
616     offScreencreenNode->UpdateInspectorId(inspectorId);
617     Inspector::AddOffscreenNode(offScreencreenNode);
618     searchedNode = Inspector::GetFrameNodeByKey(inspectorId);
619     EXPECT_EQ(offScreencreenNode, searchedNode);
620 
621     // tc.steps:    execute GetFrameNodeByKey when skipoffscreenNodes set true
622     // tc.expected: expect the function GetFrameNodeByKey get the frameNode
623     searchedNode = Inspector::GetFrameNodeByKey(inspectorId, false, true);
624     EXPECT_EQ(frameNode, searchedNode);
625 
626     // tc.steps:    execute GetFrameNodeByKey when remove offScreencreenNode
627     // tc.expected: expect the function GetFrameNodeByKey get the frameNode
628     Inspector::RemoveOffscreenNode(offScreencreenNode);
629     searchedNode = Inspector::GetFrameNodeByKey(inspectorId);
630     EXPECT_EQ(frameNode, searchedNode);
631 }
632 
633 /**
634  * @tc.name: InspectorTestNg018
635  * @tc.desc: Test the operation of GetInspectorNodeByKey
636  * @tc.type: FUNC
637  */
638 HWTEST_F(InspectorTestNg, InspectorTestNg018, TestSize.Level1)
639 {
640     // tc.steps: step1. add frameNode to arkui tree with inspector id text1
641     // tc.expected: expect the function GetInspectorNodeByKey get the frameNode
642     std::string inspectorId = "text1";
643     int32_t textNodeId = ElementRegister::GetInstance()->MakeUniqueId();
644     auto rootNode = FrameNode::CreateFrameNode(V2::ROOT_ETS_TAG,
645         ElementRegister::GetInstance()->MakeUniqueId(), AceType::MakeRefPtr<Pattern>());
646     auto frameNode = FrameNode::CreateFrameNode(V2::TEXT_ETS_TAG,
647         textNodeId, AceType::MakeRefPtr<Pattern>());
648     frameNode->UpdateInspectorId(inspectorId);
649     auto context = PipelineContext::GetCurrentContext();
650     context->rootNode_ = rootNode;
651     rootNode->AddChild(frameNode);
652     std::string searchedNodeStr = Inspector::GetInspectorNodeByKey(inspectorId);
653     auto searchedNode = JsonUtil::ParseJsonString(searchedNodeStr);
654     EXPECT_TRUE(searchedNode->IsValid());
655 
656     std::string nodeType = searchedNode->GetString(INSPECTOR_TYPE);
657     EXPECT_EQ(nodeType, TEXT_NODE_TYPE);
658 
659     int32_t nodeId = searchedNode->GetInt(INSPECTOR_ID);
660     EXPECT_EQ(textNodeId, nodeId);
661 
662     std::string debugLine = searchedNode->GetString(INSPECTOR_DEBUGLINE);
663     EXPECT_EQ(debugLine, "");
664 
665     auto attrJson = searchedNode->GetObject(INSPECTOR_ATTRS);
666     std::string accessibilityTextAttr = attrJson->GetString("accessibilityText");
667     EXPECT_EQ(accessibilityTextAttr, "");
668 
669     auto accessibilityProperty = frameNode->GetAccessibilityProperty<AccessibilityProperty>();
670     accessibilityProperty->SetAccessibilityText(TEST_TEXT);
671     searchedNodeStr = Inspector::GetInspectorNodeByKey(inspectorId);
672     searchedNode = JsonUtil::ParseJsonString(searchedNodeStr);
673     EXPECT_TRUE(searchedNode->IsValid());
674     attrJson = searchedNode->GetObject(INSPECTOR_ATTRS);
675     accessibilityTextAttr = attrJson->GetString("accessibilityText");
676     EXPECT_EQ(accessibilityTextAttr, TEST_TEXT);
677 }
678 
679 /**
680  * @tc.name: InspectorTestNg020
681  * @tc.desc: Test the operation of GetInspector
682  * @tc.type: FUNC
683  */
684 HWTEST_F(InspectorTestNg, InspectorTestNg020, TestSize.Level1)
685 {
686     auto context = PipelineContext::GetCurrentContext();
687     RefPtr<FrameNode> stageNode = FrameNode::CreateFrameNode(
688         "stage", ElementRegister::GetInstance()->MakeUniqueId(), AceType::MakeRefPtr<Pattern>(), true);
689     context->stageManager_ = AceType::MakeRefPtr<StageManager>(stageNode);
690     const RefPtr<FrameNode> PAGE = FrameNode::CreateFrameNode(
691         "page", ElementRegister::GetInstance()->MakeUniqueId(), AceType::MakeRefPtr<Pattern>(), true);
692     auto customNode = CustomNode::CreateCustomNode(1, "custom");
693     stageNode->AddChild(PAGE);
694     PAGE->AddChild(customNode);
695 
696     // tc.steps:    execute GetInspector when param isLayoutInspector is false
697     // tc.expected: expect the function GetInspector result without customNode
698     std::string searchedNodesStr = Inspector::GetInspector();
699     auto searchedNodes = JsonUtil::ParseJsonString(searchedNodesStr);
700     EXPECT_TRUE(searchedNodes->IsValid());
701     auto attrJson = searchedNodes->GetObject(INSPECTOR_CHILDREN);
702     EXPECT_TRUE(attrJson->IsNull());
703 }
704 
705 /**
706  * @tc.name: InspectorTestNg021
707  * @tc.desc: Test the operation of ParseWindowIdFromMsg
708  * @tc.type: FUNC
709  */
710 HWTEST_F(InspectorTestNg, InspectorTestNg021, TestSize.Level1)
711 {
712     std::string inspectorMsg = "";
713     auto windowId = Inspector::ParseWindowIdFromMsg(inspectorMsg);
714     EXPECT_EQ(windowId, 0);
715 
716     inspectorMsg = "invalid message";
717     windowId = Inspector::ParseWindowIdFromMsg(inspectorMsg);
718     EXPECT_EQ(windowId, 0);
719 
720     inspectorMsg = "{\"method\":\"ArkUI.xxx\", \"params\":{\"windowId\":\"10\"}}";
721     windowId = Inspector::ParseWindowIdFromMsg(inspectorMsg);
722     EXPECT_EQ(windowId, 0);
723 
724     inspectorMsg = "{\"method\":\"ArkUI.tree\", \"params\":{\"windowIds\":\"10\"}}";
725     windowId = Inspector::ParseWindowIdFromMsg(inspectorMsg);
726     EXPECT_EQ(windowId, 0);
727 
728     inspectorMsg = "{\"method\":\"ArkUI.tree\", \"paramss\":{\"windowId\":\"10\"}}";
729     windowId = Inspector::ParseWindowIdFromMsg(inspectorMsg);
730     EXPECT_EQ(windowId, 0);
731 
732     inspectorMsg = "{\"method\":\"ArkUI.tree\", \"params\":{\"windowId\":\"10\"}}";
733     windowId = Inspector::ParseWindowIdFromMsg(inspectorMsg);
734     EXPECT_EQ(windowId, 10);
735 }
736 
737 /**
738  * @tc.name: AddOffscreenNode_001
739  * @tc.desc: Test the operation of AddOffscreenNode
740  * @tc.type: FUNC
741  */
742 HWTEST_F(InspectorTestNg, AddOffscreenNode_001, TestSize.Level1)
743 {
744     int32_t num = Inspector::offscreenNodes.size();
745     RefPtr<FrameNode> one = nullptr;
746     Inspector::AddOffscreenNode(one);
747     EXPECT_EQ(Inspector::offscreenNodes.size(), num);
748 
749     auto id = ElementRegister::GetInstance()->MakeUniqueId();
750     one = FrameNode::CreateFrameNode("one", id, AceType::MakeRefPtr<Pattern>(), true);
751     auto context = PipelineContext::GetCurrentContext();
752     ASSERT_NE(context, nullptr);
753 
754     context->stageManager_ = AceType::MakeRefPtr<StageManager>(one);
755     num = Inspector::offscreenNodes.size();
756     Inspector::AddOffscreenNode(one);
757     EXPECT_EQ(Inspector::offscreenNodes.size(), num + 1);
758     context->stageManager_ = nullptr;
759 }
760 
761 /**
762  * @tc.name: RemoveOffscreenNode_001
763  * @tc.desc: Test the operation of RemoveOffscreenNode
764  * @tc.type: FUNC
765  */
766 HWTEST_F(InspectorTestNg, RemoveOffscreenNode_001, TestSize.Level1)
767 {
768     int32_t num = Inspector::offscreenNodes.size();
769     RefPtr<FrameNode> one = nullptr;
770     Inspector::RemoveOffscreenNode(one);
771     EXPECT_EQ(Inspector::offscreenNodes.size(), num);
772 
773     auto id = ElementRegister::GetInstance()->MakeUniqueId();
774     one = FrameNode::CreateFrameNode("one", id, AceType::MakeRefPtr<Pattern>(), true);
775     auto context = PipelineContext::GetCurrentContext();
776     ASSERT_NE(context, nullptr);
777     context->stageManager_ = AceType::MakeRefPtr<StageManager>(one);
778     Inspector::AddOffscreenNode(one);
779     num = Inspector::offscreenNodes.size();
780 
781     Inspector::RemoveOffscreenNode(one);
782     EXPECT_EQ(Inspector::offscreenNodes.size(), num - 1);
783     context->stageManager_ = nullptr;
784 }
785 
786 /**
787  * @tc.name: GetOffScreenTreeNodes_001
788  * @tc.desc: Test the operation of GetOffScreenTreeNodes
789  * @tc.type: FUNC
790  */
791 HWTEST_F(InspectorTestNg, GetOffScreenTreeNodes_001, TestSize.Level1)
792 {
793     auto id = ElementRegister::GetInstance()->MakeUniqueId();
794     RefPtr<FrameNode> one = FrameNode::CreateFrameNode("one", id, AceType::MakeRefPtr<Pattern>(), true);
795     auto context = PipelineContext::GetCurrentContext();
796     ASSERT_NE(context, nullptr);
797     context->stageManager_ = AceType::MakeRefPtr<StageManager>(one);
798     Inspector::AddOffscreenNode(one);
799     int32_t num = Inspector::offscreenNodes.size();
800     NG::InspectorTreeMap offNodes;
801     Inspector::GetOffScreenTreeNodes(offNodes);
802     EXPECT_EQ(offNodes.size(), num);
803     context->stageManager_ = nullptr;
804 }
805 
806 /**
807  * @tc.name: GetRecordAllPagesNodes_001
808  * @tc.desc: Test the operation of GetRecordAllPagesNodes
809  * (stageNode)--PageA--PageB--PageC
810  *                              |--frameNode
811  *                              |--frameNode1--frameNode3
812  *                              |--frameNode2
813  * @tc.type: FUNC
814  */
815 HWTEST_F(InspectorTestNg, GetRecordAllPagesNodes_001, TestSize.Level1)
816 {
817     // tc.steps: step1. call GetRecordAllPagesNodes
818     // tc.expected: expect the function is run ok
819     auto context1 = PipelineContext::GetCurrentContext();
820     ASSERT_NE(context1, nullptr);
821 
822     auto id = ElementRegister::GetInstance()->MakeUniqueId();
823     RefPtr<FrameNode> stageNode = FrameNode::CreateFrameNode("sageNode", id, AceType::MakeRefPtr<Pattern>(), true);
824     context1->stageManager_ = AceType::MakeRefPtr<StageManager>(stageNode);
825     stageNode->children_.clear();
826 
827     // tc.steps: step2 add lastPage and create a frame node tree to lastPage
828     auto id2 = ElementRegister::GetInstance()->MakeUniqueId();
829     const RefPtr<FrameNode> pageA = FrameNode::CreateFrameNode("PageA", id2,
830         AceType::MakeRefPtr<PagePattern>(AceType::MakeRefPtr<PageInfo>()));
831     stageNode->AddChild(pageA);
832     auto id3 = ElementRegister::GetInstance()->MakeUniqueId();
833     const RefPtr<FrameNode> pageB = FrameNode::CreateFrameNode("PageB", id3,
834         AceType::MakeRefPtr<PagePattern>(AceType::MakeRefPtr<PageInfo>()));
835     stageNode->AddChild(pageB);
836     auto id4 = ElementRegister::GetInstance()->MakeUniqueId();
837     const RefPtr<FrameNode> pageC = FrameNode::CreateFrameNode("PageC", id4,
838         AceType::MakeRefPtr<PagePattern>(AceType::MakeRefPtr<PageInfo>()));
839     stageNode->AddChild(pageC);
840 
841     auto frameNode = FrameNode::CreateFrameNode("frameNode0", 5, AceType::MakeRefPtr<Pattern>(), true);
842     pageC->AddChild(frameNode);
843     auto frameNode1 = FrameNode::CreateFrameNode("frameNode1", 6, AceType::MakeRefPtr<Pattern>(), true);
844     pageC->AddChild(frameNode1);
845     auto frameNode2 = FrameNode::CreateFrameNode("frameNode2", 62, AceType::MakeRefPtr<Pattern>(), true);
846     pageC->AddChild(frameNode2);
847     frameNode2->isActive_ = false;
848     auto frameNode3 = FrameNode::CreateFrameNode("frameNode3", 63, AceType::MakeRefPtr<Pattern>(), true);
849     frameNode1->AddChild(frameNode3);
850     frameNode3->isActive_ = true;
851     NG::InspectorTreeMap treesInfos;
852     Inspector::GetRecordAllPagesNodes(treesInfos);
853     EXPECT_TRUE(!treesInfos.empty());
854     context1->stageManager_ = nullptr;
855 }
856 } // namespace OHOS::Ace::NG
857