• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2022 Huawei Device Co., Ltd.
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at
6  *
7  *     http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14  */
15 
16 #include <cstring>
17 #include <gtest/gtest.h>
18 #include <gmock/gmock.h>
19 #include <securec.h>
20 #include <unordered_map>
21 
22 #define private public
23 #include "nweb.h"
24 #include "nweb_helper.h"
25 #include "nweb_config_helper.h"
26 #include "nweb_adapter_helper.h"
27 #include "nweb_create_window.h"
28 #include "nweb_c_api.h"
29 #include "nweb_init_params.h"
30 #include "application_context.h"
31 
32 using namespace testing;
33 using namespace testing::ext;
34 using namespace OHOS;
35 using namespace OHOS::Rosen;
36 using namespace OHOS::AbilityRuntime;
37 
38 namespace OHOS {
39 namespace {
40 const int DEFAULT_WIDTH = 2560;
41 const int DEFAULT_HEIGHT = 1396;
42 const int32_t MAX_WIDTH = 7681;
43 const int32_t LTPO_STRATEGY = 1;
44 const uint32_t MAX_URLS_COUNT = 100;
45 const std::string INSTALLATION_DIR = "/data/app/el1/bundle/public/com.ohos.arkwebcore";
46 std::shared_ptr<AbilityRuntime::ApplicationContext> g_applicationContext = nullptr;
47 } // namespace
48 
49 namespace AbilityRuntime {
GetApplicationContext()50 std::shared_ptr<ApplicationContext> Context::GetApplicationContext()
51 {
52     return g_applicationContext;
53 }
54 } // namespace AbilityRuntime
55 
56 namespace NWeb {
57 
58 class NwebHelperTest : public testing::Test {
59 public:
60     static void SetUpTestCase(void);
61     static void TearDownTestCase(void);
62     void SetUp();
63     void TearDown();
64 };
65 
66 class ApplicationContextMock : public ApplicationContext {
67 public:
68     MOCK_CONST_METHOD0(GetBaseDir, std::string());
69 };
70 
71 class MockNWebEngine : public OHOS::NWeb::NWebEngine {
72 public:
CreateNWeb(std::shared_ptr<NWebCreateInfo> create_info)73     std::shared_ptr<NWeb> CreateNWeb(std::shared_ptr<NWebCreateInfo> create_info)
74     {
75         return nullptr;
76     }
77 
GetNWeb(int32_t nweb_id)78     std::shared_ptr<NWeb> GetNWeb(int32_t nweb_id)
79     {
80         return nullptr;
81     }
82 
GetDataBase()83     std::shared_ptr<NWebDataBase> GetDataBase()
84     {
85         return nullptr;
86     }
87 
GetWebStorage()88     std::shared_ptr<NWebWebStorage> GetWebStorage()
89     {
90         return nullptr;
91     }
92 
GetCookieManager()93     std::shared_ptr<NWebCookieManager> GetCookieManager()
94     {
95         return nullptr;
96     }
97 
GetDownloadManager()98     std::shared_ptr<NWebDownloadManager> GetDownloadManager()
99     {
100         return nullptr;
101     }
102 
SetWebTag(int32_t nweb_id,const char * web_tag)103     void SetWebTag(int32_t nweb_id, const char* web_tag) {}
104 
InitializeWebEngine(std::shared_ptr<NWebEngineInitArgs> init_args)105     void InitializeWebEngine(std::shared_ptr<NWebEngineInitArgs> init_args) {}
106 
PrepareForPageLoad(const std::string & url,bool preconnectable,int32_t num_sockets)107     void PrepareForPageLoad(const std::string& url, bool preconnectable, int32_t num_sockets) {}
108 
SetWebDebuggingAccess(bool isEnableDebug)109     void SetWebDebuggingAccess(bool isEnableDebug) {}
110 
AddIntelligentTrackingPreventionBypassingList(const std::vector<std::string> & hosts)111     void AddIntelligentTrackingPreventionBypassingList(const std::vector<std::string>& hosts) {}
112 
RemoveIntelligentTrackingPreventionBypassingList(const std::vector<std::string> & hosts)113     void RemoveIntelligentTrackingPreventionBypassingList(const std::vector<std::string>& hosts) {}
ClearIntelligentTrackingPreventionBypassingList()114     void ClearIntelligentTrackingPreventionBypassingList() {}
115 
GetDefaultUserAgent()116     std::string GetDefaultUserAgent()
117     {
118         return "";
119     }
120 
PauseAllTimers()121     void PauseAllTimers() {}
122 
ResumeAllTimers()123     void ResumeAllTimers() {}
124 
PrefetchResource(const std::shared_ptr<NWebEnginePrefetchArgs> & pre_args,const std::map<std::string,std::string> & additional_http_headers,const std::string & cache_key,const uint32_t & cache_valid_time)125     void PrefetchResource(const std::shared_ptr<NWebEnginePrefetchArgs>& pre_args,
126         const std::map<std::string, std::string>& additional_http_headers, const std::string& cache_key,
127         const uint32_t& cache_valid_time)
128     {}
129 
SetRenderProcessMode(RenderProcessMode mode)130     void SetRenderProcessMode(RenderProcessMode mode)
131     {
132         process_mode_ = mode;
133     }
134 
GetRenderProcessMode()135     RenderProcessMode GetRenderProcessMode()
136     {
137         return process_mode_;
138     }
139 
ClearPrefetchedResource(const std::vector<std::string> & cache_key_list)140     void ClearPrefetchedResource(const std::vector<std::string>& cache_key_list) {}
141 
WarmupServiceWorker(const std::string & url)142     void WarmupServiceWorker(const std::string& url) {}
143 
SetHostIP(const std::string & hostName,const std::string & address,int32_t aliveTime)144     void SetHostIP(const std::string& hostName, const std::string& address, int32_t aliveTime) {}
145 
ClearHostIP(const std::string & hostName)146     void ClearHostIP(const std::string& hostName) {}
147 
SetAppCustomUserAgent(const std::string & userAgent)148     void SetAppCustomUserAgent(const std::string& userAgent) {}
149 
SetUserAgentForHosts(const std::string & userAgent,const std::vector<std::string> & hosts)150     void SetUserAgentForHosts(const std::string& userAgent, const std::vector<std::string>& hosts) {}
151 
EnableWholeWebPageDrawing()152     void EnableWholeWebPageDrawing() {}
153 
GetAdsBlockManager()154     std::shared_ptr<NWebAdsBlockManager> GetAdsBlockManager()
155     {
156         return nullptr;
157     }
158 
EnableBackForwardCache(bool nativeEmbed,bool mediaTakeOver)159     void EnableBackForwardCache(bool nativeEmbed, bool mediaTakeOver) {}
160 
RemoveAllCache(bool include_disk_files)161     void RemoveAllCache(bool include_disk_files) {}
162 
EnablePrivateNetworkAccess(bool enable)163     void EnablePrivateNetworkAccess(bool enable) {}
164 
IsPrivateNetworkAccessEnabled()165     bool IsPrivateNetworkAccessEnabled()
166     {
167         return false;
168     }
169 
170     MOCK_METHOD(void, SetWebDebuggingAccessAndPort,
171         (bool isEnableDebug, int32_t port), (override));
172 
173 private:
174     RenderProcessMode process_mode_ = RenderProcessMode::SINGLE_MODE;
175 };
176 
SetUpTestCase(void)177 void NwebHelperTest::SetUpTestCase(void)
178 {}
179 
TearDownTestCase(void)180 void NwebHelperTest::TearDownTestCase(void)
181 {}
182 
SetUp(void)183 void NwebHelperTest::SetUp(void)
184 {}
185 
TearDown(void)186 void NwebHelperTest::TearDown(void)
187 {}
188 
189 std::unordered_map<std::string, std::string> g_argsMap;
190 
191 /**
192  * @tc.name: NWebHelper_GetWebStorage_002
193  * @tc.desc: GetWebStorage.
194  * @tc.type: FUNC
195  * @tc.require: AR000GGHJ8
196  */
197 HWTEST_F(NwebHelperTest, NWebHelper_GetWebStorage_002, TestSize.Level1)
198 {
199     auto web_storage = NWebHelper::Instance().GetWebStorage();
200     EXPECT_EQ(web_storage, nullptr);
201     auto nwebEngineMock = std::make_shared<MockNWebEngine>();
202     NWebHelper::Instance().nwebEngine_ = nwebEngineMock;
203     auto web_storage1 = NWebHelper::Instance().GetWebStorage();
204     EXPECT_EQ(web_storage1, nullptr);
205     NWebAdapterHelper::Instance().ReadConfigIfNeeded();
206     std::string config = NWebAdapterHelper::Instance().ParsePerfConfig("web", "test");
207     EXPECT_TRUE(config.empty());
208     NWebConfigHelper::Instance().perfConfig_.emplace("web/test", "web_test");
209     config = NWebAdapterHelper::Instance().ParsePerfConfig("web", "test");
210     EXPECT_FALSE(config.empty());
211 }
212 
213 /**
214  * @tc.name: NWebHelper_GetDataBase_003
215  * @tc.desc: GetDataBase.
216  * @tc.type: FUNC
217  * @tc.require:issueI5OESN
218  */
219 HWTEST_F(NwebHelperTest, NWebHelper_GetDataBase_003, TestSize.Level1)
220 {
221     auto nwebEngineMock = std::make_shared<MockNWebEngine>();
222     NWebHelper::Instance().nwebEngine_ = nwebEngineMock;
223     auto dataBase = NWebHelper::Instance().GetDataBase();
224     EXPECT_EQ(dataBase, nullptr);
225 
226     std::shared_ptr<NWebCookieManager> cook = NWebHelper::Instance().GetCookieManager();
227     EXPECT_EQ(cook, nullptr);
228     NWebHelper::Instance().initFlag_ = true;
229     EXPECT_EQ(NWebHelper::Instance().GetCookieManager(), nullptr);
230     NWebHelper::Instance().initFlag_ = false;
231 
232     // Test NWebAdapterHelper::CreateNWeb
233     void *enhanceSurfaceInfo = nullptr;
234     int32_t temp = 1;
235     std::shared_ptr<NWeb> nweb =
236         NWebAdapterHelper::Instance().CreateNWeb(enhanceSurfaceInfo, GetInitArgs(),
237         DEFAULT_WIDTH, DEFAULT_HEIGHT);
238     EXPECT_EQ(nweb, nullptr);
239     enhanceSurfaceInfo = static_cast<void *>(&temp);
240     nweb = NWebAdapterHelper::Instance().CreateNWeb(enhanceSurfaceInfo, GetInitArgs(),
241                                                     DEFAULT_WIDTH, MAX_WIDTH);
242     EXPECT_EQ(nweb, nullptr);
243     nweb = NWebAdapterHelper::Instance().CreateNWeb(enhanceSurfaceInfo, GetInitArgs(),
244                                                     MAX_WIDTH, DEFAULT_HEIGHT);
245     EXPECT_EQ(nweb, nullptr);
246     nweb = NWebAdapterHelper::Instance().CreateNWeb(enhanceSurfaceInfo, GetInitArgs(),
247                                                     DEFAULT_WIDTH, DEFAULT_HEIGHT);
248     EXPECT_EQ(nweb, nullptr);
249     NWebHelper::Instance().nwebEngine_ = nullptr;
250     nweb = NWebAdapterHelper::Instance().CreateNWeb(enhanceSurfaceInfo, GetInitArgs(),
251                                                     DEFAULT_WIDTH, DEFAULT_HEIGHT);
252     EXPECT_EQ(nweb, nullptr);
253     EXPECT_EQ(NWebHelper::Instance().GetDataBase(), nullptr);
254 }
255 
256 /**
257  * @tc.name: NWebHelper_TryPreReadLib_004
258  * @tc.desc: TryPreReadLib.
259  * @tc.type: FUNC
260  * @tc.require: AR000GGHJ8
261  */
262 HWTEST_F(NwebHelperTest, NWebHelper_TryPreReadLib_004, TestSize.Level1)
263 {
264     std::string hapPath = "";
265     if (access(INSTALLATION_DIR.c_str(), F_OK) == 0) {
266         hapPath = INSTALLATION_DIR;
267     }
268     NWebHelper::Instance().TryPreReadLib(false, hapPath);
269     NWebHelper::Instance().TryPreReadLib(true, hapPath);
270     NWebHelper::Instance().SetBundlePath(INSTALLATION_DIR);
271     bool result = NWebAdapterHelper::Instance().Init(false);
272     EXPECT_FALSE(result);
273 }
274 
275 /**
276  * @tc.name: NWebHelper_GetConfigPath_005
277  * @tc.desc: GetConfigPath.
278  * @tc.type: FUNC
279  * @tc.require: AR000GGHJ8
280  */
281 HWTEST_F(NwebHelperTest, NWebHelper_GetConfigPath_005, TestSize.Level1)
282 {
283     std::string configFileName = "test";
284     std::string figPath = NWebConfigHelper::Instance().GetConfigPath(configFileName);
285     EXPECT_FALSE(figPath.empty());
286     std::shared_ptr<NWebEngineInitArgsImpl> initArgs = std::make_shared<NWebEngineInitArgsImpl>();
287     NWebAdapterHelper::Instance().ParseConfig(initArgs);
288     NWebHelper::Instance().PrepareForPageLoad("web_test", true, 0);
289     NWebHelper::Instance().WarmupServiceWorker("web_test");
290     NWebHelper::Instance().PrefetchResource(nullptr, {}, "web_test", 0);
291     NWebHelper::Instance().ClearPrefetchedResource({"web_test"});
292     NWebHelper::Instance().bundlePath_.clear();
293     NWebHelper::Instance().EnableBackForwardCache(true, true);
294     NWebHelper::Instance().SetCustomSchemeCmdLine("single-process");
295     NWebHelper::Instance().SetBundlePath(INSTALLATION_DIR);
296     bool result = NWebHelper::Instance().InitAndRun(false);
297     EXPECT_FALSE(result);
298     NWebHelper::Instance().SetConnectionTimeout(1);
299     NWebHelper::Instance().LoadWebEngine(true, false);
300 
301     auto nwebEngineMock = std::make_shared<MockNWebEngine>();
302     NWebHelper::Instance().nwebEngine_ = nwebEngineMock;
303     NWebHelper::Instance().PrefetchResource(nullptr, {}, "web_test", 0);
304     NWebHelper::Instance().ClearPrefetchedResource({"web_test"});
305     // To test SetRenderProcessMode and GetRenderProcessMode.
306     NWebHelper::Instance().SetRenderProcessMode(RenderProcessMode::SINGLE_MODE);
307     RenderProcessMode render_process_mode =
308         NWebHelper::Instance().GetRenderProcessMode();
309     EXPECT_EQ(render_process_mode, RenderProcessMode::SINGLE_MODE);
310     NWebHelper::Instance().SetRenderProcessMode(RenderProcessMode::MULTIPLE_MODE);
311     render_process_mode = NWebHelper::Instance().GetRenderProcessMode();
312     EXPECT_EQ(render_process_mode, RenderProcessMode::MULTIPLE_MODE);
313 
314     NWebHelper::Instance().nwebEngine_ = nullptr;
315     NWebHelper::Instance().SetRenderProcessMode(RenderProcessMode::MULTIPLE_MODE);
316     EXPECT_EQ(NWebHelper::Instance().GetRenderProcessMode(), RenderProcessMode::SINGLE_MODE);
317 }
318 
319 /**
320  * @tc.name: NWebHelper_LoadNWebSDK_006
321  * @tc.desc: LoadNWebSDK.
322  * @tc.type: FUNC
323  * @tc.require:
324  */
325 HWTEST_F(NwebHelperTest, NWebHelper_LoadNWebSDK_006, TestSize.Level1)
326 {
327     auto nwebEngineMock = std::make_shared<MockNWebEngine>();
328     NWebHelper::Instance().nwebEngine_ = nwebEngineMock;
329     bool result = NWebHelper::Instance().LoadNWebSDK();
330     EXPECT_TRUE(result);
331     static WebDownloadDelegateCallback *downloadCallback;
332     WebDownloader_CreateDownloadDelegateCallback(&downloadCallback);
333     EXPECT_EQ(downloadCallback, nullptr);
__anon3c63b7980202(NWebDownloadItem *downloadItem, WebBeforeDownloadCallbackWrapper *wrapper) 334     OnDownloadBeforeStart fun = [] (NWebDownloadItem *downloadItem, WebBeforeDownloadCallbackWrapper *wrapper) {};
335     WebDownloader_SetDownloadBeforeStart(downloadCallback, fun);
336     WebDownloadManager_PutDownloadCallback(downloadCallback);
__anon3c63b7980302(NWebDownloadItem *downloadItem, WebDownloadItemCallbackWrapper *wrapper) 337     OnDownloadDidUpdate didUpdate = [] (NWebDownloadItem *downloadItem, WebDownloadItemCallbackWrapper *wrapper) {};
338     WebDownloader_SetDownloadDidUpdate(downloadCallback, didUpdate);
339     NWebDownloadItem *downloadItem = nullptr;
340     WebDownloadItem_CreateWebDownloadItem(&downloadItem);
341     EXPECT_EQ(downloadItem, nullptr);
342     WebDownloader_ResumeDownloadStatic(downloadItem);
343     WebDownloader_StartDownload(1, "test_web");
344     WebDownload_Continue(nullptr, "test_web");
345     WebDownload_CancelBeforeDownload(nullptr);
346     WebDownload_PauseBeforeDownload(nullptr);
347     WebDownload_ResumeBeforeDownload(nullptr);
348     WebDownload_Cancel(nullptr);
349     WebDownload_Pause(nullptr);
350     WebDownload_Resume(nullptr);
351     long itemId = WebDownloadItem_GetDownloadItemId(downloadItem);
352     EXPECT_NE(itemId, -1);
353     WebDownloadItem_GetState(nullptr);
354     NWebDownloadItem *download = nullptr;
355     int speed = WebDownloadItem_CurrentSpeed(download);
356     EXPECT_EQ(speed, 0);
357     int complete = WebDownloadItem_PercentComplete(download);
358     EXPECT_EQ(complete, 0);
359     WebDownloadItem_SetReceivedBytes(downloadItem, 1);
360     WebDownloadItem_TotalBytes(downloadItem);
361     int64_t receivedBytes = WebDownloadItem_ReceivedBytes(downloadItem);
362     EXPECT_EQ(receivedBytes, 0);
363     char* originalUrl = WebDownloadItem_OriginalUrl(downloadItem);
364     EXPECT_EQ(originalUrl, nullptr);
365     char* fileName = WebDownloadItem_SuggestedFileName(downloadItem);
366     EXPECT_EQ(fileName, nullptr);
367     char* disposition = WebDownloadItem_ContentDisposition(downloadItem);
368     EXPECT_EQ(disposition, nullptr);
369 }
370 
371 /**
372  * @tc.name: NWebHelper_WebDownloadItem_IsPaused_007
373  * @tc.desc: WebDownloadItem_IsPaused.
374  * @tc.type: FUNC
375  * @tc.require:
376  */
377 HWTEST_F(NwebHelperTest, NWebHelper_WebDownloadItem_IsPaused_007, TestSize.Level1)
378 {
379     NWebHelper::Instance().nwebEngine_ = std::make_shared<MockNWebEngine>();
380     bool result = NWebHelper::Instance().LoadNWebSDK();
381     EXPECT_TRUE(result);
382     NWebDownloadItem *downloadItem = nullptr;
383     WebDownloadItem_CreateWebDownloadItem(&downloadItem);
384     EXPECT_EQ(downloadItem, nullptr);
385     NWebDownloadItem *download = nullptr;
386     bool isPaused = WebDownloadItem_IsPaused(download);
387     EXPECT_FALSE(isPaused);
388     char* method = WebDownloadItem_Method(downloadItem);
389     EXPECT_EQ(method, nullptr);
390     WebDownloadItem_LastErrorCode(downloadItem);
391     char* receivedSlices = WebDownloadItem_ReceivedSlices(downloadItem);
392     EXPECT_EQ(receivedSlices, nullptr);
393     char* lastModified = WebDownloadItem_LastModified(downloadItem);
394     EXPECT_EQ(lastModified, nullptr);
395     int nWebId = WebDownloadItem_NWebId(download);
396     EXPECT_EQ(nWebId, -1);
397     WebDownloadItem_Destroy(downloadItem);
398     DestroyBeforeDownloadCallbackWrapper(nullptr);
399     DestroyDownloadItemCallbackWrapper(nullptr);
400     WebDownloadItem_SetGuid(downloadItem, "test_web");
401     WebDownloadItem_SetUrl(downloadItem, "test_web");
402     WebDownloadItem_SetFullPath(downloadItem, "test_web");
403     WebDownloadItem_SetETag(downloadItem, "test_web");
404     WebDownloadItem_SetLastModified(downloadItem, "test_web");
405     WebDownloadItem_SetMimeType(downloadItem, "test_web");
406     WebDownloadItem_SetReceivedBytes(downloadItem, 1);
407     WebDownloadItem_SetTotalBytes(downloadItem, 1);
408     WebDownloadItem_SetReceivedSlices(downloadItem, "test_web");
409     char* guid = WebDownloadItem_Guid(downloadItem);
410     EXPECT_EQ(guid, nullptr);
411     int64_t totalBytes = WebDownloadItem_TotalBytes(downloadItem);
412     EXPECT_EQ(totalBytes, 0);
413     int64_t receivedBytes = WebDownloadItem_ReceivedBytes(downloadItem);
414     EXPECT_EQ(receivedBytes, 0);
415     char* fullPath = WebDownloadItem_FullPath(downloadItem);
416     EXPECT_EQ(fullPath, nullptr);
417     char* url = WebDownloadItem_Url(downloadItem);
418     EXPECT_EQ(url, nullptr);
419     char* eTag = WebDownloadItem_ETag(downloadItem);
420     EXPECT_EQ(eTag, nullptr);
421     char* mimeType = WebDownloadItem_MimeType(downloadItem);
422     EXPECT_EQ(mimeType, nullptr);
423     long itemId = WebDownloadItem_GetDownloadItemId(downloadItem);
424     auto state1 = WebDownload_GetItemState(nWebId, itemId);
425     auto state2 = WebDownload_GetItemStateByGuid("test_web");
426     WebDownload_GetItemStateByGuidV2("test_web");
427     EXPECT_EQ(state1, state2);
428 }
429 
430 /**
431  * @tc.name: NWebHelper_LoadWebEngine_008
432  * @tc.desc: LoadWebEngine.
433  * @tc.type: FUNC
434  * @tc.require: AR000GGHJ8
435  */
436 HWTEST_F(NwebHelperTest, NWebHelper_LoadWebEngine_008, TestSize.Level1)
437 {
438     NWebHelper::Instance().nwebEngine_ = nullptr;
439     std::shared_ptr<NWebCreateInfoImpl> create_info = std::make_shared<NWebCreateInfoImpl>();
440     std::shared_ptr<NWeb> nweb = NWebHelper::Instance().CreateNWeb(create_info);
441     EXPECT_EQ(nweb, nullptr);
442     nweb = NWebHelper::Instance().GetNWeb(1);
443     EXPECT_EQ(nweb, nullptr);
444     NWebHelper::Instance().SetWebTag(1, "webtag");
445     std::shared_ptr<NWebDOHConfigImpl> config = std::make_shared<NWebDOHConfigImpl>();
446     NWebHelper::Instance().SetHttpDns(config);
447     std::vector<std::string> hosts;
448     NWebHelper::Instance().AddIntelligentTrackingPreventionBypassingList(hosts);
449     NWebHelper::Instance().RemoveIntelligentTrackingPreventionBypassingList(hosts);
450     NWebHelper::Instance().ClearIntelligentTrackingPreventionBypassingList();
451     NWebHelper::Instance().GetDefaultUserAgent();
452     NWebHelper::Instance().SetAppCustomUserAgent("web_test");
453     NWebHelper::Instance().SetUserAgentForHosts("web_test", hosts);
454     NWebHelper::Instance().PauseAllTimers();
455     NWebHelper::Instance().ResumeAllTimers();
456     NWebHelper::Instance().SetWebDestroyMode(WebDestroyMode::NORMAL_MODE);
457 
458     auto nwebEngineMock = std::make_shared<MockNWebEngine>();
459     NWebHelper::Instance().nwebEngine_ = nwebEngineMock;
460     NWebHelper::Instance().SetHttpDns(config);
461     NWebHelper::Instance().PrepareForPageLoad("web_test", true, 0);
462     NWebHelper::Instance().WarmupServiceWorker("web_test");
463     NWebHelper::Instance().GetDataBase();
464     NWebHelper::Instance().SetConnectionTimeout(1);
465     NWebHelper::Instance().AddIntelligentTrackingPreventionBypassingList(hosts);
466     NWebHelper::Instance().RemoveIntelligentTrackingPreventionBypassingList(hosts);
467     NWebHelper::Instance().ClearIntelligentTrackingPreventionBypassingList();
468     NWebHelper::Instance().GetDefaultUserAgent();
469     NWebHelper::Instance().SetAppCustomUserAgent("web_test");
470     NWebHelper::Instance().SetUserAgentForHosts("web_test", hosts);
471     NWebHelper::Instance().PauseAllTimers();
472     NWebHelper::Instance().ResumeAllTimers();
473     NWebHelper::Instance().SetWebDestroyMode(WebDestroyMode::NORMAL_MODE);
474     EXPECT_NE(NWebHelper::Instance().nwebEngine_, nullptr);
475     NWebHelper::Instance().LoadWebEngine(true, false);
476     bool result = NWebHelper::Instance().GetWebEngine(true);
477     EXPECT_TRUE(result);
478     NWebHelper::Instance().SetWebTag(1, "webtag");
479     NWebHelper::Instance().SetWebDebuggingAccess(true);
480     NWebHelper::Instance().SetWebDebuggingAccessAndPort(true, 80);
481     NWebHelper::Instance().SaveSchemeVector("web_test", 8080);
482     result = NWebHelper::Instance().HasLoadWebEngine();
483     EXPECT_TRUE(result);
484     result = NWebHelper::Instance().RegisterCustomSchemes();
485     EXPECT_FALSE(result);
486 }
487 
488 /**
489  * @tc.name: NWebHelper_GetPerfConfig_001
490  * @tc.desc: GetPerfConfig.
491  * @tc.type: FUNC
492  * @tc.require:
493  */
494 HWTEST_F(NwebHelperTest, NWebHelper_GetPerfConfig_001, TestSize.Level1)
495 {
496     EXPECT_TRUE(NWebAdapterHelper::Instance().GetPerfConfig("test").empty());
497     NWebConfigHelper::Instance().ltpoConfig_["test"] = {OHOS::NWeb::FrameRateSetting{0, 0, 0}};
498     EXPECT_FALSE(NWebAdapterHelper::Instance().GetPerfConfig("test").empty());
499     NWebConfigHelper::Instance().ltpoConfig_.clear();
500 }
501 
502 /**
503  * @tc.name: NWebHelper_ParseNWebLTPOConfig_001
504  * @tc.desc: ParseNWebLTPOConfig.
505  * @tc.type: FUNC
506  * @tc.require:
507  */
508 HWTEST_F(NwebHelperTest, NWebHelper_ParseNWebLTPOConfig_001, TestSize.Level1)
509 {
510     EXPECT_TRUE(NWebConfigHelper::Instance().ltpoConfig_.empty());
511     std::shared_ptr<NWebEngineInitArgsImpl> initArgs = std::make_shared<NWebEngineInitArgsImpl>();
512     NWebAdapterHelper::Instance().ParseConfig(initArgs);
513     EXPECT_TRUE(NWebConfigHelper::Instance().ltpoConfig_.empty());
514 }
515 
516 /**
517  * @tc.name: NWebHelper_SetHostIP_001
518  * @tc.desc: SetHostIP.
519  * @tc.type: FUNC
520  * @tc.require:
521  */
522 HWTEST_F(NwebHelperTest, NWebHelper_SetHostIP_001, TestSize.Level1)
523 {
524     std::string hostName = "hello";
525     std::string address = "world";
526     int32_t aliveTime = 0;
527 
528     NWebHelper::Instance().nwebEngine_ = nullptr;
529     NWebHelper::Instance().SetHostIP(hostName, address, aliveTime);
530     EXPECT_EQ(NWebHelper::Instance().nwebEngine_, nullptr);
531 
532     auto nwebEngineMock = std::make_shared<MockNWebEngine>();
533     NWebHelper::Instance().nwebEngine_ = nwebEngineMock;
534     NWebHelper::Instance().SetHostIP(hostName, address, aliveTime);
535     EXPECT_NE(NWebHelper::Instance().nwebEngine_, nullptr);
536 
537     NWebHelper::Instance().nwebEngine_ = nullptr;
538 }
539 
540 /**
541  * @tc.name: NWebHelper_ClearHostIP_001
542  * @tc.desc: ClearHostIP.
543  * @tc.type: FUNC
544  * @tc.require:
545  */
546 HWTEST_F(NwebHelperTest, NWebHelper_ClearHostIP_001, TestSize.Level1)
547 {
548     int32_t nweb_id = 1;
549     auto nwebHelper = NWebHelper::Instance().GetNWeb(nweb_id);
550     EXPECT_EQ(nwebHelper, nullptr);
551 
552     std::string hostName = "name";
553     NWebHelper::Instance().nwebEngine_ = nullptr;
554     NWebHelper::Instance().ClearHostIP(hostName);
555     EXPECT_EQ(NWebHelper::Instance().nwebEngine_, nullptr);
556 
557     auto nwebengineMock = std::make_shared<MockNWebEngine>();
558     NWebHelper::Instance().nwebEngine_ = nwebengineMock;
559     NWebHelper::Instance().ClearHostIP(hostName);
560     EXPECT_NE(NWebHelper::Instance().nwebEngine_, nullptr);
561 
562     NWebHelper::Instance().nwebEngine_ = nullptr;
563 }
564 
565 /**
566  * @tc.name: NWebHelper_EnableWholeWebPageDrawing_001
567  * @tc.desc: EnableWholeWebPageDrawing.
568  * @tc.type: FUNC
569  * @tc.require:
570  */
571 HWTEST_F(NwebHelperTest, NWebHelper_EnableWholeWebPageDrawing_001, TestSize.Level1)
572 {
573     int32_t nweb_id = 1;
574     auto nwebHelper = NWebHelper::Instance().GetNWeb(nweb_id);
575     EXPECT_EQ(nwebHelper, nullptr);
576 
577     auto nwebengineMock = std::make_shared<MockNWebEngine>();
578     NWebHelper::Instance().nwebEngine_ = nwebengineMock;
579     NWebHelper::Instance().EnableWholeWebPageDrawing();
580     EXPECT_NE(NWebHelper::Instance().nwebEngine_, nullptr);
581 
582     NWebHelper::Instance().nwebEngine_ = nullptr;
583     NWebHelper::Instance().EnableWholeWebPageDrawing();
584 }
585 
586 /**
587  * @tc.name: NWebHelper_GetAdsBlockManager_001
588  * @tc.desc: GetAdsBlockManager.
589  * @tc.type: FUNC
590  * @tc.require:
591  */
592 HWTEST_F(NwebHelperTest, NWebHelper_GetAdsBlockManager_001, TestSize.Level1)
593 {
594     NWebHelper::Instance().nwebEngine_ = nullptr;
595     NWebHelper::Instance().bundlePath_ = "";
596     std::shared_ptr<NWebCreateInfoImpl> create_info = std::make_shared<NWebCreateInfoImpl>();
597     std::shared_ptr<NWeb> nweb = NWebHelper::Instance().CreateNWeb(create_info);
598     EXPECT_EQ(nweb, nullptr);
599     nweb = NWebHelper::Instance().GetNWeb(1);
600     EXPECT_EQ(nweb, nullptr);
601     auto manager = NWebHelper::Instance().GetAdsBlockManager();
602     EXPECT_EQ(manager, nullptr);
603     auto nwebengineMock = std::make_shared<MockNWebEngine>();
604     NWebHelper::Instance().nwebEngine_ = nwebengineMock;
605     auto manager1 = NWebHelper::Instance().GetAdsBlockManager();
606     EXPECT_EQ(manager1, nullptr);
607     NWebHelper::Instance().nwebEngine_ = nullptr;
608 }
609 
610 /**
611  * @tc.name: NWebHelper_TrimMemoryByPressureLevel_001
612  * @tc.desc: TrimMemoryByPressureLevel.
613  * @tc.type: FUNC
614  * @tc.require:
615  */
616 HWTEST_F(NwebHelperTest, NWebHelper_TrimMemoryByPressureLevel_001, TestSize.Level1)
617 {
618     int32_t nweb_id = 1;
619     auto nwebHelper = NWebHelper::Instance().GetNWeb(nweb_id);
620     EXPECT_EQ(nwebHelper, nullptr);
621 
622     int32_t memoryLevel = 1;
623     NWebHelper::Instance().nwebEngine_ = nullptr;
624     NWebHelper::Instance().TrimMemoryByPressureLevel(memoryLevel);
625     EXPECT_EQ(NWebHelper::Instance().nwebEngine_, nullptr);
626 
627     auto nwebengineMock = std::make_shared<MockNWebEngine>();
628     NWebHelper::Instance().nwebEngine_ = nwebengineMock;
629     EXPECT_EQ(NWebHelper::Instance().GetNWeb(nweb_id), nullptr);
630     NWebHelper::Instance().TrimMemoryByPressureLevel(memoryLevel);
631     EXPECT_NE(NWebHelper::Instance().nwebEngine_, nullptr);
632 
633     NWebHelper::Instance().nwebEngine_ = nullptr;
634 }
635 
636 /**
637  * @tc.name: NWebHelper_ParseNWebLTPOApp_001
638  * @tc.desc: ParseNWebLTPOApp.
639  * @tc.type: FUNC
640  * @tc.require:
641  */
642 HWTEST_F(NwebHelperTest, NWebHelper_ParseNWebLTPOApp_001, TestSize.Level1)
643 {
644     EXPECT_TRUE(NWebConfigHelper::Instance().ltpoAllowedApps_.empty());
645     EXPECT_FALSE(NWebConfigHelper::Instance().IsLTPODynamicApp(""));
646     std::shared_ptr<NWebEngineInitArgsImpl> initArgs = std::make_shared<NWebEngineInitArgsImpl>();
647     NWebAdapterHelper::Instance().ParseConfig(initArgs);
648     EXPECT_TRUE(NWebConfigHelper::Instance().ltpoAllowedApps_.empty());
649     EXPECT_FALSE(NWebConfigHelper::Instance().IsLTPODynamicApp(""));
650     EXPECT_FALSE(NWebAdapterHelper::Instance().IsLTPODynamicApp(""));
651 
652     NWebConfigHelper::Instance().ltpoStrategy_ = LTPO_STRATEGY;
653     NWebAdapterHelper::Instance().ParseConfig(initArgs);
654     EXPECT_EQ(NWebConfigHelper::Instance().GetLTPOStrategy(), LTPO_STRATEGY);
655     EXPECT_EQ(NWebAdapterHelper::Instance().GetLTPOStrategy(), LTPO_STRATEGY);
656 }
657 
658 /**
659  * @tc.name: NWebHelper_GetWebEngine_001
660  * @tc.desc: GetWebEngine.
661  * @tc.type: FUNC
662  * @tc.require:
663  */
664 HWTEST_F(NwebHelperTest, NWebHelper_GetWebEngine_001, TestSize.Level1)
665 {
666     NWebHelper::Instance().nwebEngine_ = nullptr;
667     NWebHelper::Instance().bundlePath_ = "";
668     g_applicationContext.reset();
669     bool result = NWebHelper::Instance().GetWebEngine(true);
670     EXPECT_FALSE(result);
671     ApplicationContextMock *contextMock = new ApplicationContextMock();
672     ASSERT_NE(contextMock, nullptr);
673     g_applicationContext.reset(contextMock);
674     result = NWebHelper::Instance().GetWebEngine(true);
675     EXPECT_FALSE(result);
676 }
677 
678 /**
679  * @tc.name: NWebHelper_InitWebEngine
680  * @tc.desc: InitWebEngine.
681  * @tc.type: FUNC
682  * @tc.require:
683  */
684 HWTEST_F(NwebHelperTest, NWebHelper_InitWebEngine, TestSize.Level1)
685 {
686     NWebHelper::Instance().initFlag_ = true;
687     bool resultBool = NWebHelper::Instance().InitWebEngine();
688     EXPECT_TRUE(resultBool);
689     NWebHelper::Instance().initFlag_ = false;
690     resultBool = NWebHelper::Instance().InitWebEngine();
691     EXPECT_FALSE(resultBool);
692     ApplicationContextMock *contextMock = new ApplicationContextMock();
693     ASSERT_NE(contextMock, nullptr);
694     g_applicationContext.reset(contextMock);
695     resultBool = NWebHelper::Instance().InitWebEngine();
696     EXPECT_FALSE(resultBool);
697 }
698 
699 /**
700  * @tc.name: NWebHelper_SetProxyOverride
701  * @tc.desc: SetProxyOverride.
702  * @tc.type: FUNC
703  * @tc.require:
704  */
705 HWTEST_F(NwebHelperTest, NWebHelper_SetProxyOverride, TestSize.Level1)
706 {
707     std::vector<std::string> proxyUrls = {"http://127.0.0.1:8080"};
708     std::vector<std::string> proxySchemeFilters = {"http", "https"};
709     std::vector<std::string> bypassRules = {"localhost", "127.0.0.1"};
710     bool reverseBypass = false;
711     NWebHelper::Instance().nwebEngine_ = nullptr;
712     NWebHelper::Instance().bundlePath_ = "";
713     NWebHelper::Instance().SetProxyOverride(proxyUrls, proxySchemeFilters, bypassRules, reverseBypass, nullptr);
714     NWebHelper::Instance().RemoveProxyOverride(nullptr);
715     auto nwebEngineMock = std::make_shared<MockNWebEngine>();
716     NWebHelper::Instance().nwebEngine_ = nwebEngineMock;
717     NWebHelper::Instance().initFlag_ = true;
718     NWebHelper::Instance().RemoveProxyOverride(nullptr);
719 }
720 
721 /**
722  * @tc.name: NWebHelper_RemoveAllCache
723  * @tc.desc: RemoveAllCache.
724  * @tc.type: FUNC
725  * @tc.require:
726  */
727 HWTEST_F(NwebHelperTest, NWebHelper_RemoveAllCache, TestSize.Level1)
728 {
729     auto nwebEngineMock = std::make_shared<MockNWebEngine>();
730     NWebHelper::Instance().nwebEngine_ = nwebEngineMock;
731     NWebHelper::Instance().initFlag_ = true;
732     bool includeDiskFiles = true;
733     NWebHelper::Instance().RemoveAllCache(includeDiskFiles);
734     NWebHelper::Instance().nwebEngine_ = nullptr;
735     NWebHelper::Instance().bundlePath_ = "";
736     NWebHelper::Instance().RemoveAllCache(includeDiskFiles);
737 }
738 
739 /**
740  * @tc.name: NWebHelper_GetBundleName_001
741  * @tc.desc: GetBundleName.
742  * @tc.type: FUNC
743  * @tc.require:
744  */
745 HWTEST_F(NwebHelperTest, NWebHelper_GetBundleName_001, TestSize.Level1)
746 {
747     std::string bundleName = NWebAdapterHelper::Instance().GetBundleName();
748     EXPECT_TRUE(bundleName.empty());
749     NWebConfigHelper::Instance().SetBundleName("testBundleName");
750     bundleName = NWebAdapterHelper::Instance().GetBundleName();
751     EXPECT_FALSE(bundleName.empty());
752 }
753 
754 /**
755  * @tc.name: WebApplicationStateChangeCallback_NotifyApplicationForeground_001
756  * @tc.desc: NotifyApplicationForeground.
757  * @tc.type: FUNC
758  * @tc.require:
759  */
760 HWTEST_F(NwebHelperTest,
761           WebApplicationStateChangeCallback_NotifyApplicationForeground_001, TestSize.Level1)
762 {
763     std::shared_ptr<WebApplicationStateChangeCallback> webApplicationStateCallback_ =
764         WebApplicationStateChangeCallback::GetInstance();
765     EXPECT_NE(webApplicationStateCallback_, nullptr);
766     std::shared_ptr<NWebCreateInfoImpl> create_info = std::make_shared<NWebCreateInfoImpl>();
767     std::shared_ptr<NWeb> nweb = NWebHelper::Instance().CreateNWeb(create_info);
768     EXPECT_EQ(nweb, nullptr);
769     webApplicationStateCallback_->nweb_ = nweb;
770     webApplicationStateCallback_->NotifyApplicationForeground();
771 }
772 
773 /**
774  * @tc.name: WebApplicationStateChangeCallback_NotifyApplicationBackground_001
775  * @tc.desc: NotifyApplicationBackground.
776  * @tc.type: FUNC
777  * @tc.require:
778  */
779 HWTEST_F(NwebHelperTest,
780           WebApplicationStateChangeCallback_NotifyApplicationBackground_001, TestSize.Level1)
781 {
782     std::shared_ptr<WebApplicationStateChangeCallback> webApplicationStateCallback_ =
783         WebApplicationStateChangeCallback::GetInstance();
784     EXPECT_NE(webApplicationStateCallback_, nullptr);
785     std::shared_ptr<NWebCreateInfoImpl> create_info = std::make_shared<NWebCreateInfoImpl>();
786     std::shared_ptr<NWeb> nweb = NWebHelper::Instance().CreateNWeb(create_info);
787     EXPECT_EQ(nweb, nullptr);
788     webApplicationStateCallback_->nweb_ = nweb;
789     webApplicationStateCallback_->NotifyApplicationBackground();
790 }
791 
792 /**
793  * @tc.name: SetWebDebuggingAccess
794  * @tc.desc: SetWebDebuggingAccess and SetWebDebuggingAccessAndPort.
795  * @tc.type: FUNC
796  * @tc.require:
797  */
798 HWTEST_F(NwebHelperTest, SetWebDebuggingAccess, TestSize.Level1)
799 {
800     NWebHelper::Instance().initFlag_ = false;
801     NWebHelper::Instance().nwebEngine_ = nullptr;
802 
803     auto nwebEngineMock = std::make_shared<MockNWebEngine>();
804     bool isEnableDebug = true;
805     int32_t port = 8888;
806     EXPECT_CALL(*nwebEngineMock, SetWebDebuggingAccessAndPort(isEnableDebug, port)).Times(1);
807 
808     NWebHelper::Instance().SetWebDebuggingAccess(isEnableDebug);
809     NWebHelper::Instance().SetWebDebuggingAccessAndPort(isEnableDebug, port);
810 
811     NWebHelper::Instance().initFlag_ = true;
812     NWebHelper::Instance().SetWebDebuggingAccess(isEnableDebug);
813     NWebHelper::Instance().SetWebDebuggingAccessAndPort(isEnableDebug, port);
814 
815     NWebHelper::Instance().nwebEngine_ = nwebEngineMock;
816     NWebHelper::Instance().SetWebDebuggingAccess(isEnableDebug);
817     NWebHelper::Instance().SetWebDebuggingAccessAndPort(isEnableDebug, port);
818 }
819 
820 /**
821  * @tc.name: NWebHelper_SetBlanklessLoadingCacheCapacity_001
822  * @tc.desc: test SetBlanklessLoadingCacheCapacity.
823  * @tc.type: FUNC
824  * @tc.require: ICACAG
825  */
826 HWTEST_F(NwebHelperTest, NWebHelper_SetBlanklessLoadingCacheCapacity_001, TestSize.Level1)
827 {
828     NWebHelper::Instance().nwebEngine_ = nullptr;
829     NWebHelper::Instance().SetBlanklessLoadingCacheCapacity(-1);
830     NWebHelper::Instance().SetBlanklessLoadingCacheCapacity(0);
831     NWebHelper::Instance().SetBlanklessLoadingCacheCapacity(10);
832     NWebHelper::Instance().SetBlanklessLoadingCacheCapacity(30);
833     NWebHelper::Instance().SetBlanklessLoadingCacheCapacity(100);
834     NWebHelper::Instance().SetBlanklessLoadingCacheCapacity(1000);
835     EXPECT_EQ(NWebHelper::Instance().nwebEngine_, nullptr);
836 }
837 
838 /**
839  * @tc.name: NWebHelper_SetBlanklessLoadingCacheCapacity_002
840  * @tc.desc: test SetBlanklessLoadingCacheCapacity.
841  * @tc.type: FUNC
842  * @tc.require: ICACAG
843  */
844 HWTEST_F(NwebHelperTest, NWebHelper_SetBlanklessLoadingCacheCapacity_002, TestSize.Level1)
845 {
846     auto nwebEngineMock = std::make_shared<MockNWebEngine>();
847     NWebHelper::Instance().nwebEngine_ = nwebEngineMock;
848     NWebHelper::Instance().SetBlanklessLoadingCacheCapacity(-1);
849     NWebHelper::Instance().SetBlanklessLoadingCacheCapacity(0);
850     NWebHelper::Instance().SetBlanklessLoadingCacheCapacity(10);
851     NWebHelper::Instance().SetBlanklessLoadingCacheCapacity(30);
852     NWebHelper::Instance().SetBlanklessLoadingCacheCapacity(100);
853     NWebHelper::Instance().SetBlanklessLoadingCacheCapacity(1000);
854     EXPECT_NE(NWebHelper::Instance().nwebEngine_, nullptr);
855 }
856 
857 /**
858  * @tc.name: NWebHelper_ClearBlanklessLoadingCache_001
859  * @tc.desc: test ClearBlanklessLoadingCache.
860  * @tc.type: FUNC
861  * @tc.require: ICACAG
862  */
863 HWTEST_F(NwebHelperTest, NWebHelper_ClearBlanklessLoadingCache_001, TestSize.Level1)
864 {
865     NWebHelper::Instance().nwebEngine_ = nullptr;
866     std::vector<std::string> blankLessLoadingCache;
867     NWebHelper::Instance().ClearBlanklessLoadingCache(blankLessLoadingCache);
868     blankLessLoadingCache.push_back("www.ClearBlanklessLoadingCache1.com");
869     NWebHelper::Instance().ClearBlanklessLoadingCache(blankLessLoadingCache);
870     blankLessLoadingCache.push_back("www.ClearBlanklessLoadingCache2.com");
871     NWebHelper::Instance().ClearBlanklessLoadingCache(blankLessLoadingCache);
872     for (uint32_t idx = 0; idx < MAX_URLS_COUNT; idx++) {
873         blankLessLoadingCache.push_back("www.ClearBlanklessLoadingCache3.com");
874     }
875     NWebHelper::Instance().ClearBlanklessLoadingCache(blankLessLoadingCache);
876     EXPECT_EQ(NWebHelper::Instance().nwebEngine_, nullptr);
877 }
878 
879 /**
880  * @tc.name: NWebHelper_ClearBlanklessLoadingCache_002
881  * @tc.desc: test ClearBlanklessLoadingCache.
882  * @tc.type: FUNC
883  * @tc.require: ICACAG
884  */
885 HWTEST_F(NwebHelperTest, NWebHelper_ClearBlanklessLoadingCache_002, TestSize.Level1)
886 {
887     auto nwebEngineMock = std::make_shared<MockNWebEngine>();
888     NWebHelper::Instance().nwebEngine_ = nwebEngineMock;
889     std::vector<std::string> blankLessLoadingCache;
890     NWebHelper::Instance().ClearBlanklessLoadingCache(blankLessLoadingCache);
891     blankLessLoadingCache.push_back("www.ClearBlanklessLoadingCache1.com");
892     NWebHelper::Instance().ClearBlanklessLoadingCache(blankLessLoadingCache);
893     blankLessLoadingCache.push_back("www.ClearBlanklessLoadingCache2.com");
894     NWebHelper::Instance().ClearBlanklessLoadingCache(blankLessLoadingCache);
895     for (uint32_t idx = 0; idx < MAX_URLS_COUNT; idx++) {
896         blankLessLoadingCache.push_back("www.ClearBlanklessLoadingCache3.com");
897     }
898     NWebHelper::Instance().ClearBlanklessLoadingCache(blankLessLoadingCache);
899     EXPECT_NE(NWebHelper::Instance().nwebEngine_, nullptr);
900 }
901 
902 /**
903  * @tc.name: NWebHelper_CheckBlankOptEnable_001
904  * @tc.desc: test CheckBlankOptEnable.
905  * @tc.type: FUNC
906  * @tc.require: ICACAG
907  */
908 HWTEST_F(NwebHelperTest, NWebHelper_CheckBlankOptEnable_001, TestSize.Level1)
909 {
910     NWebHelper::Instance().nwebEngine_ = nullptr;
911     EXPECT_EQ(NWebHelper::Instance().CheckBlankOptEnable("example", 0), "");
912 }
913 
914 /**
915  * @tc.name: NWebHelper_CheckBlankOptEnable_002
916  * @tc.desc: test CheckBlankOptEnable.
917  * @tc.type: FUNC
918  * @tc.require: ICACAG
919  */
920 HWTEST_F(NwebHelperTest, NWebHelper_CheckBlankOptEnable_002, TestSize.Level1)
921 {
922     auto nwebEngineMock = std::make_shared<MockNWebEngine>();
923     NWebHelper::Instance().nwebEngine_ = nwebEngineMock;
924     EXPECT_EQ(NWebHelper::Instance().CheckBlankOptEnable("example", 0), "");
925 }
926 
927 /**
928  * @tc.name: NWebHelper_EnablePrivateNetworkAccess_001
929  * @tc.desc: EnablePrivateNetworkAccess.
930  * @tc.type: FUNC
931  * @tc.require:
932  */
933 HWTEST_F(NwebHelperTest, NWebHelper_EnablePrivateNetworkAccess_001, TestSize.Level1)
934 {
935     int32_t nweb_id = 1;
936     auto nwebHelper = NWebHelper::Instance().GetNWeb(nweb_id);
937     EXPECT_EQ(nwebHelper, nullptr);
938 
939     auto nwebengineMock = std::make_shared<MockNWebEngine>();
940     NWebHelper::Instance().nwebEngine_ = nwebengineMock;
941     NWebHelper::Instance().EnablePrivateNetworkAccess(true);
942     NWebHelper::Instance().EnablePrivateNetworkAccess(false);
943     EXPECT_NE(NWebHelper::Instance().nwebEngine_, nullptr);
944 }
945 
946 /**
947  * @tc.name: NWebHelper_IsPrivateNetworkAccessEnabled_001
948  * @tc.desc: IsPrivateNetworkAccessEnabled.
949  * @tc.type: FUNC
950  * @tc.require:
951  */
952 HWTEST_F(NwebHelperTest, NWebHelper_IsPrivateNetworkAccessEnabled_001, TestSize.Level1)
953 {
954     int32_t nweb_id = 1;
955     auto nwebHelper = NWebHelper::Instance().GetNWeb(nweb_id);
956     EXPECT_EQ(nwebHelper, nullptr);
957 
958     auto nwebengineMock = std::make_shared<MockNWebEngine>();
959     NWebHelper::Instance().nwebEngine_ = nwebengineMock;
960     NWebHelper::Instance().IsPrivateNetworkAccessEnabled();
961     EXPECT_NE(NWebHelper::Instance().nwebEngine_, nullptr);
962 }
963 } // namespace OHOS::NWeb
964 }
965