• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2024 Huawei Device Co., Ltd.
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at
6  *
7  *     http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14  */
15 
16 #include <cstring>
17 #include <gtest/gtest.h>
18 #include <gmock/gmock.h>
19 #include <memory>
20 #include <unordered_map>
21 #include <libxml/parser.h>
22 #include <libxml/tree.h>
23 #include "parameters.h"
24 
25 #define private public
26 #include "nweb.h"
27 #include "nweb_adapter_helper.h"
28 #include "nweb_c_api.h"
29 #include "nweb_config_helper.h"
30 #include "nweb_helper.h"
31 #include "nweb_init_params.h"
32 
33 
34 using namespace testing;
35 using namespace testing::ext;
36 using namespace OHOS::NWeb;
37 
38 namespace OHOS {
39 namespace NWebConfig {
40 
41 const auto XML_ATTR_NAME = "name";
42 
43 class MockNWebConfigHelper : public NWebConfigHelper {
44 public:
45     MOCK_METHOD1(ParseConfig, void(std::shared_ptr<NWebEngineInitArgsImpl> initArgs));
46     MOCK_METHOD1(ParseNWebLTPOConfig, void(xmlNodePtr nodePtr));
47     MOCK_METHOD2(ParseDeleteConfig, void(const xmlNodePtr &rootPtr,
48         std::shared_ptr<NWebEngineInitArgsImpl> initArgs));
49     MOCK_METHOD2(ParseWebConfigXml, void(const std::string& configFilePath,
50         std::shared_ptr<NWebEngineInitArgsImpl> initArgs));
51 };
52 
53 class NWebConfigHelperTest : public ::testing::Test {
54 protected:
55     std::shared_ptr<NWebEngineInitArgsImpl> initArgs = std::make_shared<NWebEngineInitArgsImpl>();
56     xmlNodePtr rootElement;
57     xmlNodePtr childNodePtr;
58     std::unique_ptr<xmlChar[]> content;
59     NWebConfigHelper &helper = NWebConfigHelper::Instance();
SetUp()60     void SetUp() override
61     {
62         rootElement = xmlNewNode(NULL, BAD_CAST "root");
63         childNodePtr = xmlNewNode(NULL, BAD_CAST "child");
64         int contentSize = 10;
65         content = std::make_unique<xmlChar[]>(contentSize);
66     }
TearDown()67     void TearDown() override {
68         if (rootElement != nullptr) {
69             xmlFreeNode(rootElement);
70         }
71         if (childNodePtr != nullptr) {
72             xmlFreeNode(childNodePtr);
73         }
74     }
75 };
76 
77 /**
78  * @tc.name: ParseWebConfigXml_FileNotFound
79  * @tc.desc: ParseWebConfigXml.
80  * @tc.type: FUNC
81  * @tc.require:
82  */
83 HWTEST_F(NWebConfigHelperTest, ParseWebConfigXml_FileNotFound, TestSize.Level0)
84 {
85     std::string configFilePath = "nonexistent.xml";
86     EXPECT_NE(initArgs, nullptr);
87     NWebConfigHelper::Instance().ParseWebConfigXml(configFilePath, initArgs);
88 }
89 
90 /**
91  * @tc.name: GetPerfConfig_ShouldReturnEmptyVector_WhenSettingNameNotExist
92  * @tc.desc: GetPerfConfig.
93  * @tc.type: FUNC
94  * @tc.require:
95  */
96 HWTEST_F(NWebConfigHelperTest, GetPerfConfig_ShouldReturnEmptyVector_WhenSettingNameNotExist, TestSize.Level0)
97 {
98     std::string settingName = "NonExistentSetting";
99     std::vector<FrameRateSetting> result = NWebConfigHelper::Instance().GetPerfConfig(settingName);
100     EXPECT_TRUE(result.empty());
101 }
102 
103 /**
104  * @tc.name: ParsePerfConfig_ShouldReturnEmptyString_WhenConfigNotFound
105  * @tc.desc: ParsePerfConfig.
106  * @tc.type: FUNC
107  * @tc.require:
108  */
109 HWTEST_F(NWebConfigHelperTest, ParsePerfConfig_ShouldReturnEmptyString_WhenConfigNotFound, TestSize.Level0)
110 {
111     std::string configNodeName = "non_existent_config";
112     std::string argsNodeName = "non_existent_args";
113     std::string result = NWebConfigHelper::Instance().ParsePerfConfig(configNodeName, argsNodeName);
114     EXPECT_EQ(result, "");
115 }
116 
117 /**
118  * @tc.name: ParsePerfConfig_ShouldReturnValue_WhenConfigFound
119  * @tc.desc: ParsePerfConfig.
120  * @tc.type: FUNC
121  * @tc.require:
122  */
123 HWTEST_F(NWebConfigHelperTest, ParsePerfConfig_ShouldReturnValue_WhenConfigFound, TestSize.Level0)
124 {
125     std::string configNodeName = "existent_config";
126     std::string argsNodeName = "existent_args";
127     std::string expectedValue = "expected_value";
128     NWebConfigHelper::Instance().perfConfig_[configNodeName + "/" + argsNodeName] = expectedValue;
129     std::string result = NWebConfigHelper::Instance().ParsePerfConfig(configNodeName, argsNodeName);
130     EXPECT_EQ(result, expectedValue);
131 }
132 
133 /**
134  * @tc.name: ParsePerfConfig_NullNode
135  * @tc.desc: ParsePerfConfig.
136  * @tc.type: FUNC
137  * @tc.require:
138  */
139 HWTEST_F(NWebConfigHelperTest, ParsePerfConfig_NullNode, TestSize.Level0)
140 {
141     xmlNodePtr node = xmlNewNode(nullptr, BAD_CAST "node");
142     NWebConfigHelper::Instance().ParsePerfConfig(node);
143     EXPECT_FALSE(NWebConfigHelper::Instance().perfConfig_.empty());
144 }
145 
146 /**
147  * @tc.name: ParsePerfConfig_CommentNode
148  * @tc.desc: ParsePerfConfig.
149  * @tc.type: FUNC
150  * @tc.require:
151  */
152 HWTEST_F(NWebConfigHelperTest, ParsePerfConfig_CommentNode, TestSize.Level0)
153 {
154     xmlNodePtr node = xmlNewNode(nullptr, BAD_CAST "comment");
155     NWebConfigHelper::Instance().ParsePerfConfig(node);
156     EXPECT_FALSE(NWebConfigHelper::Instance().perfConfig_.empty());
157     xmlFreeNode(node);
158 }
159 
160 /**
161  * @tc.name: ParseDeleteConfig_NullRootPtr
162  * @tc.desc: ParseDeleteConfig.
163  * @tc.type: FUNC
164  * @tc.require:
165  */
166 HWTEST_F(NWebConfigHelperTest, ParseDeleteConfig_NullRootPtr, TestSize.Level0)
167 {
168     xmlNodePtr rootPtr = xmlNewNode(nullptr, BAD_CAST "valid");
169     xmlNodePtr childNodePtr = xmlNewNode(nullptr, BAD_CAST "child");
170     EXPECT_NE(rootPtr, nullptr);
171     EXPECT_NE(childNodePtr, nullptr);
172     xmlAddChild(rootPtr, childNodePtr);
173     NWebConfigHelper::Instance().ParseDeleteConfig(rootPtr, initArgs);
174 }
175 
176 /**
177  * @tc.name: ParseDeleteConfig_ValidNode
178  * @tc.desc: ParseDeleteConfig.
179  * @tc.type: FUNC
180  * @tc.require:
181  */
182 HWTEST_F(NWebConfigHelperTest, ParseDeleteConfig_ValidNode, TestSize.Level0)
183 {
184     xmlNodePtr rootPtr = xmlNewNode(nullptr, BAD_CAST "valid");
185     xmlNodePtr childNodePtr = xmlNewNode(nullptr, BAD_CAST "child");
186     EXPECT_NE(rootPtr, nullptr);
187     EXPECT_NE(childNodePtr, nullptr);
188     xmlAddChild(rootPtr, childNodePtr);
189     xmlChar *content = xmlNodeGetContent(childNodePtr);
190     xmlNodeSetContent(childNodePtr, content);
191     xmlFree(content);
192     NWebConfigHelper::Instance().ParseDeleteConfig(rootPtr, initArgs);
193 }
194 
195 /**
196  * @tc.name: ParseDeleteConfig_InvalidChildNode
197  * @tc.desc: ParseDeleteConfig.
198  * @tc.type: FUNC
199  * @tc.require:
200  */
201 HWTEST_F(NWebConfigHelperTest, ParseDeleteConfig_InvalidChildNode, TestSize.Level0)
202 {
203     xmlNodePtr rootPtr = xmlNewNode(nullptr, BAD_CAST "valid");
204     xmlNodePtr childNodePtr = xmlNewNode(nullptr, BAD_CAST "invalid");
205     EXPECT_NE(rootPtr, nullptr);
206     EXPECT_NE(childNodePtr, nullptr);
207     xmlAddChild(rootPtr, childNodePtr);
208     NWebConfigHelper::Instance().ParseDeleteConfig(rootPtr, initArgs);
209 }
210 
211 /**
212  * @tc.name: ParseDeleteConfig_NullContent
213  * @tc.desc: ParseDeleteConfig.
214  * @tc.type: FUNC
215  * @tc.require:
216  */
217 HWTEST_F(NWebConfigHelperTest, ParseDeleteConfig_NullContent, TestSize.Level0)
218 {
219     xmlNodePtr rootPtr = xmlNewNode(nullptr, BAD_CAST "valid");
220     xmlNodePtr childNodePtr = xmlNewNode(nullptr, BAD_CAST "child");
221     EXPECT_NE(rootPtr, nullptr);
222     EXPECT_NE(childNodePtr, nullptr);
223     xmlAddChild(rootPtr, childNodePtr);
224     NWebConfigHelper::Instance().ParseDeleteConfig(rootPtr, initArgs);
225 }
226 
227 /**
228  * @tc.name: ParseDeleteConfig_NotFoundConfig
229  * @tc.desc: ParseDeleteConfig.
230  * @tc.type: FUNC
231  * @tc.require:
232  */
233 HWTEST_F(NWebConfigHelperTest, ParseDeleteConfig_NotFoundConfig, TestSize.Level0)
234 {
235     xmlNodePtr rootPtr = xmlNewNode(nullptr, BAD_CAST "valid");
236     xmlNodePtr childNodePtr = xmlNewNode(nullptr, BAD_CAST "child");
237     EXPECT_NE(rootPtr, nullptr);
238     EXPECT_NE(childNodePtr, nullptr);
239     xmlAddChild(rootPtr, childNodePtr);
240     xmlChar *content = xmlNodeGetContent(childNodePtr);
241     xmlNodeSetContent(childNodePtr, content);
242     xmlFree(content);
243     NWebConfigHelper::Instance().ParseDeleteConfig(rootPtr, initArgs);
244 }
245 
246 /**
247  * @tc.name: ParseDeleteConfig_EmptyParam
248  * @tc.desc: ParseDeleteConfig.
249  * @tc.type: FUNC
250  * @tc.require:
251  */
252 HWTEST_F(NWebConfigHelperTest, ParseDeleteConfig_EmptyParam, TestSize.Level0)
253 {
254     xmlNodePtr rootPtr = xmlNewNode(nullptr, BAD_CAST "valid");
255     xmlNodePtr childNodePtr = xmlNewNode(nullptr, BAD_CAST "child");
256     EXPECT_NE(rootPtr, nullptr);
257     EXPECT_NE(childNodePtr, nullptr);
258     xmlAddChild(rootPtr, childNodePtr);
259     xmlChar *content = xmlNodeGetContent(childNodePtr);
260     xmlNodeSetContent(childNodePtr, content);
261     xmlFree(content);
262     NWebConfigHelper::Instance().ParseDeleteConfig(rootPtr, initArgs);
263 }
264 
265 /**
266  * @tc.name  : safeGetPropAsInt_ShouldReturnDefaultValue_WhenPropNotExist
267  * @tc.number: OHOS_NWEB_001
268  * @tc.desc  : Test safeGetPropAsInt function when the property does not exist.
269  */
270 HWTEST_F(NWebConfigHelperTest, safeGetPropAsInt_ShouldReturnDefaultValue_WhenPropNotExist,
271     testing::ext::TestSize.Level0)
272 {
273     int defaultValue = 10;
274     int result = NWebConfigHelper::Instance().safeGetPropAsInt(rootElement,
275       BAD_CAST "non_existent_prop", defaultValue);
276     EXPECT_EQ(result, defaultValue);
277 }
278 
279 /**
280  * @tc.name  : safeGetPropAsInt_ShouldReturnPropValue_WhenPropExist
281  * @tc.number: OHOS_NWEB_002
282  * @tc.desc  : Test safeGetPropAsInt function when the property exists.
283  */
284 HWTEST_F(NWebConfigHelperTest, safeGetPropAsInt_ShouldReturnPropValue_WhenPropExist, testing::ext::TestSize.Level0)
285 {
286     xmlNewProp(rootElement, BAD_CAST "test_prop", BAD_CAST "20");
287     int result = NWebConfigHelper::Instance().safeGetPropAsInt(rootElement, BAD_CAST "test_prop", 10);
288     EXPECT_EQ(result, 20);
289 }
290 
291 /**
292  * @tc.name  : safeGetPropAsInt_ShouldReturnDefaultValue_WhenPropValueNotInt
293  * @tc.number: OHOS_NWEB_003
294  * @tc.desc  : Test safeGetPropAsInt function when the property value is not an integer.
295  */
296 HWTEST_F(NWebConfigHelperTest, safeGetPropAsInt_ShouldReturnDefaultValue_WhenPropValueNotInt,
297     testing::ext::TestSize.Level0)
298 {
299     xmlNewProp(rootElement, BAD_CAST "test_prop", BAD_CAST "not_an_integer");
300     int defaultValue = 0;
301     int result = NWebConfigHelper::Instance().safeGetPropAsInt(rootElement, BAD_CAST "test_prop", defaultValue);
302     EXPECT_EQ(result, defaultValue);
303 }
304 
305 /**
306  * @tc.name  : WriteConfigValueToSysPara_ShouldSetParameter_WhenConfigNameIsFlowBufferConfigMaxFdNumber
307  * @tc.number: NWebConfigHelperTest_001
308  * @tc.desc  : Test WriteConfigValueToSysPara method when configName is "flowBufferConfig/maxFdNumber"
309  */
310 HWTEST_F(NWebConfigHelperTest,
311     WriteConfigValueToSysPara_ShouldSetParameter_WhenConfigNameIsFlowBufferConfigMaxFdNumber, TestSize.Level0)
312 {
313     std::string configName = "flowBufferConfig/maxFdNumber";
314     std::string value = "1024";
315     NWebConfigHelper::Instance().WriteConfigValueToSysPara(configName, value);
316     std::string actualValue = OHOS::system::GetParameter("web.flowbuffer.maxfd", "");
317     EXPECT_EQ(value, actualValue);
318 }
319 
320 /**
321  * @tc.name  : WriteConfigValueToSysPara_ShouldNotSetParameter_WhenConfigNameIsNotFlowBufferConfigMaxFdNumber
322  * @tc.number: NWebConfigHelperTest_002
323  * @tc.desc  : Test WriteConfigValueToSysPara method when configName is not "flowBufferConfig/maxFdNumber"
324  */
325 HWTEST_F(NWebConfigHelperTest,
326     WriteConfigValueToSysPara_ShouldNotSetParameter_WhenConfigNameIsNotFlowBufferConfigMaxFdNumber, TestSize.Level0)
327 {
328     std::string configName = "someOtherConfig";
329     std::string value = "1024";
330     NWebConfigHelper::Instance().WriteConfigValueToSysPara(configName, value);
331     std::string actualValue = OHOS::system::GetParameter("web.flowbuffer.maxfd", "");
332     EXPECT_EQ(value, actualValue);
333 }
334 
335 /**
336  * @tc.name  : ParseNWebLTPOConfig_ShouldHandleInvalidNode_WhenNodeIsNull
337  * @tc.number: NWebConfigHelperTest_001
338  * @tc.desc  : Test when node is null then ParseNWebLTPOConfig should handle it correctly
339  */
340 HWTEST_F(NWebConfigHelperTest, ParseNWebLTPOConfig_ShouldHandleInvalidNode_WhenNodeIsNull, TestSize.Level0)
341 {
342     xmlNodePtr rootPtr = xmlNewNode(nullptr, BAD_CAST "valid");
343     xmlNodePtr childNodePtr = xmlNewNode(nullptr, BAD_CAST "child");
344     EXPECT_NE(rootPtr, nullptr);
345     EXPECT_NE(childNodePtr, nullptr);
346     xmlAddChild(rootPtr, childNodePtr);
347     NWebConfigHelper::Instance().ParseNWebLTPOConfig(rootPtr);
348 }
349 
350 /**
351  * @tc.name  : ParseNWebLTPOConfig_ShouldHandleInvalidNode_WhenNodeIsComment
352  * @tc.number: NWebConfigHelperTest_002
353  * @tc.desc  : Test when node is a comment then ParseNWebLTPOConfig should handle it correctly
354  */
355 HWTEST_F(NWebConfigHelperTest, ParseNWebLTPOConfig_ShouldHandleInvalidNode_WhenNodeIsComment, TestSize.Level0)
356 {
357     xmlNodePtr nodePtr = xmlNewComment((xmlChar *)"This is a comment");
358     xmlNodePtr childNodePtr = xmlNewNode(nullptr, BAD_CAST "child");
359     EXPECT_NE(nodePtr, nullptr);
360     EXPECT_NE(childNodePtr, nullptr);
361     xmlAddChild(nodePtr, childNodePtr);
362     NWebConfigHelper::Instance().ParseNWebLTPOConfig(nodePtr);
363     xmlFreeNode(nodePtr);
364 }
365 
366 /**
367  * @tc.name  : ParseNWebLTPOConfig_ShouldHandleValidNode_WhenNameIsValid
368  * @tc.number: NWebConfigHelperTest_004
369  * @tc.desc  : Test when node and name are valid then ParseNWebLTPOConfig should handle it correctly
370  */
371 HWTEST_F(NWebConfigHelperTest, ParseNWebLTPOConfig_ShouldHandleValidNode_WhenNameIsValid, TestSize.Level0)
372 {
373     xmlNodePtr nodePtr = xmlNewNode(nullptr, BAD_CAST "testNode");
374     EXPECT_NE(nodePtr, nullptr);
375     xmlNewProp(nodePtr, BAD_CAST(XML_ATTR_NAME), BAD_CAST("validName"));
376     NWebConfigHelper::Instance().ParseNWebLTPOConfig(nodePtr);
377     xmlFreeNode(nodePtr);
378 }
379 
380 /**
381  * @tc.name  : ParseNWebLTPOConfig_ShouldHandleInvalidDynamicNode_WhenDynamicNodeIsComment
382  * @tc.number: NWebConfigHelperTest_006
383  * @tc.desc  : Test when dynamic node is a comment then ParseNWebLTPOConfig should handle it correctly
384  */
385 HWTEST_F(NWebConfigHelperTest, ParseNWebLTPOConfig_ShouldHandleInvalidDynamicNode_WhenDynamicNodeIsComment,
386     TestSize.Level0)
387 {
388     xmlNodePtr nodePtr = xmlNewNode(nullptr, BAD_CAST "testNode");
389     EXPECT_NE(nodePtr, nullptr);
390     xmlNewProp(nodePtr, BAD_CAST(XML_ATTR_NAME), BAD_CAST("validName"));
391     xmlNodePtr dynamicNodePtr = xmlNewComment((xmlChar *)"This is a comment");
392     EXPECT_NE(dynamicNodePtr, nullptr);
393     xmlAddChild(nodePtr, dynamicNodePtr);
394     NWebConfigHelper::Instance().ParseNWebLTPOConfig(nodePtr);
395     xmlFreeNode(nodePtr);
396 }
397 
398 /**
399  * @tc.name  : GetChildrenNode_ShouldReturnNode_WhenNodeExists
400  * @tc.number: NWebConfigHelperTest_001
401  * @tc.desc  : Test GetChildrenNode function when the node exists
402  */
403 HWTEST_F(NWebConfigHelperTest, GetChildrenNode_ShouldReturnNode_WhenNodeExists, TestSize.Level0)
404 {
405     xmlNodePtr rootNode = xmlNewNode(nullptr, BAD_CAST "root");
406     xmlNodePtr childNode = nullptr;
407     xmlAddChild(rootNode, childNode);
408     xmlNodePtr resultNode = NWebConfigHelper::Instance().GetChildrenNode(rootNode, "child");
409     EXPECT_EQ(resultNode, childNode);
410     xmlFreeNode(rootNode);
411     xmlFreeNode(childNode);
412 }
413 
414 /**
415  * @tc.name  : GetChildrenNode_ShouldReturnNull_WhenNodeNotExists
416  * @tc.number: NWebConfigHelperTest_002
417  * @tc.desc  : Test GetChildrenNode function when the node does not exist
418  */
419 HWTEST_F(NWebConfigHelperTest, GetChildrenNode_ShouldReturnNull_WhenNodeNotExists, TestSize.Level0)
420 {
421     xmlNodePtr rootNode = xmlNewNode(nullptr, BAD_CAST "root");
422     xmlNodePtr childNode = nullptr;
423     xmlAddChild(rootNode, childNode);
424     xmlNodePtr resultNode = NWebConfigHelper::Instance().GetChildrenNode(rootNode, "non_existent_child");
425     EXPECT_EQ(resultNode, nullptr);
426     xmlFreeNode(rootNode);
427     xmlFreeNode(childNode);
428 }
429 
430 /**
431  * @tc.name  : GetChildrenNode_ShouldReturnNull_WhenNodeNameIsEmpty
432  * @tc.number: NWebConfigHelperTest_004
433  * @tc.desc  : Test GetChildrenNode function when the node name is empty
434  */
435 HWTEST_F(NWebConfigHelperTest, GetChildrenNode_ShouldReturnNull_WhenNodeNameIsEmpty, TestSize.Level0)
436 {
437     xmlNodePtr rootNode = xmlNewNode(nullptr, BAD_CAST "root");
438     xmlNodePtr resultNode = NWebConfigHelper::Instance().GetChildrenNode(rootNode, "");
439     EXPECT_EQ(resultNode, nullptr);
440     xmlFreeNode(rootNode);
441 }
442 
443 /**
444  * @tc.name  : ReadConfig_ShouldHandleInvalidNode_WhenNodeIsNull
445  * @tc.number: NWebConfigHelperTest_001
446  * @tc.desc  : Test when node is null then ReadConfig should skip the node
447  */
448 HWTEST_F(NWebConfigHelperTest, ReadConfig_ShouldHandleInvalidNode_WhenNodeIsNull, TestSize.Level0)
449 {
450     rootElement->xmlChildrenNode = nullptr;
451     NWebConfigHelper::Instance().ReadConfig(rootElement, initArgs);
452     EXPECT_EQ(initArgs->GetArgsToAdd().size(), 0);
453 }
454 
455 /**
456  * @tc.name  : ReadConfig_ShouldHandleInvalidNode_WhenNodeIsComment
457  * @tc.number: NWebConfigHelperTest_002
458  * @tc.desc  : Test when node is a comment then ReadConfig should skip the node
459  */
460 HWTEST_F(NWebConfigHelperTest, ReadConfig_ShouldHandleInvalidNode_WhenNodeIsComment, TestSize.Level0)
461 {
462     rootElement->type = xmlElementType::XML_COMMENT_NODE;
463     NWebConfigHelper::Instance().ReadConfig(rootElement, initArgs);
464     EXPECT_EQ(initArgs->GetArgsToAdd().size(), 0);
465 }
466 
467 /**
468  * @tc.name  : ReadConfig_ShouldHandleInvalidNode_WhenChildNodeIsNull
469  * @tc.number: NWebConfigHelperTest_003
470  * @tc.desc  : Test when child node is null then ReadConfig should skip the child node
471  */
472 HWTEST_F(NWebConfigHelperTest, ReadConfig_ShouldHandleInvalidNode_WhenChildNodeIsNull, TestSize.Level0)
473 {
474     xmlNodePtr rootElement = xmlNewNode(nullptr, BAD_CAST "root");
475     xmlNodePtr childNodePtr = xmlNewNode(nullptr, BAD_CAST "child");
476     rootElement->xmlChildrenNode = childNodePtr;
477     childNodePtr->xmlChildrenNode = nullptr;
478     NWebConfigHelper::Instance().ReadConfig(rootElement, initArgs);
479     EXPECT_EQ(initArgs->GetArgsToAdd().size(), 0);
480 }
481 
482 /**
483  * @tc.name  : ReadConfig_ShouldHandleInvalidNode_WhenChildNodeIsComment
484  * @tc.number: NWebConfigHelperTest_004
485  * @tc.desc  : Test when child node is a comment then ReadConfig should skip the child node
486  */
487 HWTEST_F(NWebConfigHelperTest, ReadConfig_ShouldHandleInvalidNode_WhenChildNodeIsComment, TestSize.Level0)
488 {
489     xmlNodePtr rootElement = xmlNewNode(nullptr, BAD_CAST "root");
490     xmlNodePtr childNodePtr = xmlNewNode(nullptr, BAD_CAST "child");
491     rootElement->xmlChildrenNode = childNodePtr;
492     childNodePtr->type = xmlElementType::XML_COMMENT_NODE;
493     NWebConfigHelper::Instance().ReadConfig(rootElement, initArgs);
494     EXPECT_EQ(initArgs->GetArgsToAdd().size(), 0);
495 }
496 
497 /**
498  * @tc.name  : ReadConfig_ShouldHandleInvalidNode_WhenContentIsNull
499  * @tc.number: NWebConfigHelperTest_005
500  * @tc.desc  : Test when content is null then ReadConfig should skip the node
501  */
502 HWTEST_F(NWebConfigHelperTest, ReadConfig_ShouldHandleInvalidNode_WhenContentIsNull, TestSize.Level0)
503 {
504     xmlNodePtr rootElement = xmlNewNode(nullptr, BAD_CAST "root");
505     xmlNodePtr childNodePtr = xmlNewNode(nullptr, BAD_CAST "child");
506     rootElement->xmlChildrenNode = childNodePtr;
507     childNodePtr->xmlChildrenNode = nullptr;
508     NWebConfigHelper::Instance().ReadConfig(rootElement, initArgs);
509     EXPECT_EQ(initArgs->GetArgsToAdd().size(), 0);
510 }
511 
512 /**
513  * @tc.name  : ReadConfig_ShouldHandleValidNode_WhenContentIsValid
514  * @tc.number: NWebConfigHelperTest_006
515  * @tc.desc  : Test when content is valid then ReadConfig should add the param to initArgs
516  */
517 HWTEST_F(NWebConfigHelperTest, ReadConfig_ShouldHandleValidNode_WhenContentIsValid, TestSize.Level0)
518 {
519     xmlNodePtr rootElement = xmlNewNode(nullptr, BAD_CAST "root");
520     xmlNodePtr childNodePtr = xmlNewNode(nullptr, BAD_CAST "child");rootElement->xmlChildrenNode = childNodePtr;
521     rootElement->content = (xmlChar *)"valid_content";
522     rootElement->type = XML_TEXT_NODE;
523     childNodePtr->xmlChildrenNode = nullptr;
524     NWebConfigHelper::Instance().ReadConfig(rootElement, initArgs);
525     EXPECT_EQ(initArgs->GetArgsToAdd().size(), 0);
526 }
527 
528 /**
529  * @tc.name  : GetConfigPath_ShouldReturnSystemPath_WhenConfigPathIsInvalid
530  * @tc.number: NWebConfigHelperTest_001
531  * @tc.desc  : Test scenario for GetConfigPath when config path is invalid
532  */
533 HWTEST_F(NWebConfigHelperTest, GetConfigPath_ShouldReturnSystemPath_WhenConfigPathIsInvalid, TestSize.Level0)
534 {
535     std::string configFileName = "invalid_config_file";
536     std::string expectedPath = "/system/" + configFileName;
537     EXPECT_EQ(NWebConfigHelper::Instance().GetConfigPath(configFileName), expectedPath);
538 }
539 
540 /**
541  * @tc.name  : NWebConfigHelper_ReadConfigIfNeeded_ShouldParseConfig_WhenPerfConfigEmpty
542  * @tc.number: NWebConfigHelper_Test_001
543  * @tc.desc  : Test that ReadConfigIfNeeded parses config when perfConfig is empty
544  */
545 HWTEST_F(NWebConfigHelperTest, NWebConfigHelper_ReadConfigIfNeeded_ShouldParseConfig_WhenPerfConfigEmpty,
546     TestSize.Level0)
547 {
548     NWebConfigHelper::Instance().perfConfig_.clear();
549     EXPECT_TRUE(NWebConfigHelper::Instance().perfConfig_.empty());
550     NWebConfigHelper::Instance().ReadConfigIfNeeded();
551 }
552 
553 /**
554  * @tc.name  : NWebConfigHelper_ReadConfigIfNeeded_ShouldNotParseConfig_WhenPerfConfigNotEmpty
555  * @tc.number: NWebConfigHelper_Test_002
556  * @tc.desc  : Test that ReadConfigIfNeeded does not parse config when perfConfig is not empty
557  */
558 HWTEST_F(NWebConfigHelperTest, NWebConfigHelper_ReadConfigIfNeeded_ShouldNotParseConfig_WhenPerfConfigNotEmpty,
559     TestSize.Level0)
560 {
561     NWebConfigHelper::Instance().perfConfig_.insert(std::make_pair("some_config", ""));
562     NWebConfigHelper::Instance().ReadConfigIfNeeded();
563     MockNWebConfigHelper *mock = new MockNWebConfigHelper();
564     EXPECT_CALL(*mock, ParseConfig(initArgs)).Times(0);
565     delete mock;
566 }
567 } // NWebConfig
568 } // OHOS```