• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2022-2025 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 <gtest/gtest.h>
17 #include <gtest/hwext/gtest-multithread.h>
18 
19 #include "ark_native_engine.h"
20 #define private public
21 #define protected public
22 #include "js_environment.h"
23 #include "js_runtime.h"
24 #include "js_runtime_utils.h"
25 #include "js_worker.h"
26 #undef private
27 #undef protected
28 #include "event_runner.h"
29 #include "mock_js_runtime.h"
30 #include "mock_jsnapi.h"
31 #include "hilog_tag_wrapper.h"
32 #include "js_runtime_lite.h"
33 
34 using namespace testing;
35 using namespace testing::ext;
36 using namespace testing::mt;
37 
38 namespace OHOS {
39 namespace AbilityRuntime {
40 namespace {
41 const std::string TEST_BUNDLE_NAME = "com.ohos.contactsdataability";
42 const std::string TEST_MODULE_NAME = ".ContactsDataAbility";
43 const std::string TEST_ABILITY_NAME = "ContactsDataAbility";
44 const std::string TEST_CODE_PATH = "/data/storage/el1/bundle";
45 const std::string TEST_HAP_PATH = "/system/app/com.ohos.contactsdataability/Contacts_DataAbility.hap";
46 const std::string TEST_LIB_PATH = "/data/storage/el1/bundle/lib/";
47 const std::string TEST_MODULE_PATH = "/data/storage/el1/bundle/curJsModulePath";
48 }  // namespace
49 class JsRuntimeTest : public testing::Test {
50 public:
51     static void SetUpTestCase();
52     static void TearDownTestCase();
53     void SetUp() override;
54     void TearDown() override;
55 
56     static std::unique_ptr<AbilityRuntime::JsRuntime> jsRuntimePtr;
57 };
58 
59 std::unique_ptr<AbilityRuntime::JsRuntime> JsRuntimeTest::jsRuntimePtr = nullptr;
60 Runtime::Options options_;
61 
SetUpTestCase()62 void JsRuntimeTest::SetUpTestCase()
63 {
64     options_.bundleName = TEST_BUNDLE_NAME;
65     options_.codePath = TEST_CODE_PATH;
66     options_.loadAce = false;
67     options_.isBundle = true;
68     options_.preload = false;
69     std::shared_ptr<AppExecFwk::EventRunner> eventRunner = AppExecFwk::EventRunner::Create(TEST_ABILITY_NAME);
70     options_.eventRunner = eventRunner;
71     jsRuntimePtr = AbilityRuntime::JsRuntime::Create(options_);
72 }
73 
TearDownTestCase()74 void JsRuntimeTest::TearDownTestCase()
75 {
76     jsRuntimePtr.reset();
77 }
78 
SetUp()79 void JsRuntimeTest::SetUp()
80 {
81 }
82 
TearDown()83 void JsRuntimeTest::TearDown()
84 {
85 }
86 
87 /**
88  * @tc.name: JsperfProfilerCommandParse_100
89  * @tc.desc: JsRuntime test for JsperfProfilerCommandParse.
90  * @tc.type: FUNC
91  */
92 HWTEST_F(JsRuntimeTest, JsperfProfilerCommandParse_100, TestSize.Level1)
93 {
94     TAG_LOGI(AAFwkTag::TEST, "JsperfProfilerCommandParse_100 start");
95     auto jsRuntime = std::make_shared<AbilityRuntime::JsRuntime>();
96     std::string command = "";
97     constexpr int32_t defaultVal = 500;
98     constexpr int32_t emptyVal = 0;
99     ASSERT_EQ(jsRuntime->JsperfProfilerCommandParse(command, defaultVal), emptyVal);
100     command = "jsperfabc";
101     ASSERT_EQ(jsRuntime->JsperfProfilerCommandParse(command, defaultVal), defaultVal);
102     command = "jsperf";
103     ASSERT_EQ(jsRuntime->JsperfProfilerCommandParse(command, defaultVal), defaultVal);
104     command = "jsperf ";
105     ASSERT_EQ(jsRuntime->JsperfProfilerCommandParse(command, defaultVal), defaultVal);
106     command = "jsperf 1000";
107     ASSERT_NE(jsRuntime->JsperfProfilerCommandParse(command, defaultVal), defaultVal);
108     command = " jsperf 1000";
109     ASSERT_NE(jsRuntime->JsperfProfilerCommandParse(command, defaultVal), defaultVal);
110     jsRuntime.reset();
111     std::this_thread::sleep_for(std::chrono::milliseconds(200));
112     TAG_LOGI(AAFwkTag::TEST, "JsperfProfilerCommandParse_100 end");
113 }
114 
115 /**
116  * @tc.name: JsRuntimeTestCreate_0100
117  * @tc.desc: JsRuntime Test for Create
118  * @tc.type: FUNC
119  * @tc.require: issueI581SE
120  */
121 HWTEST_F(JsRuntimeTest, JsRuntimeTestCreate_0100, TestSize.Level0)
122 {
123     TAG_LOGI(AAFwkTag::TEST, "Create_0100 start");
124 
125     Runtime::Options options;
126     options.preload = true;
127     options.isStageModel = false;
128     options.isTestFramework = false;
129     JsRuntime jsRuntime;
130     jsRuntime.preloaded_ = true;
131     std::unique_ptr<JsRuntime> jsRuntimePtr1 = jsRuntime.Create(options);
132     EXPECT_TRUE(jsRuntimePtr1 != nullptr);
133 
134     jsRuntimePtr1.reset();
135     std::this_thread::sleep_for(std::chrono::milliseconds(200));
136     TAG_LOGI(AAFwkTag::TEST, "Create_0100 end");
137 }
138 
139 /**
140  * @tc.name: JsRuntimeTestSetAppLibPath_0100
141  * @tc.desc: JsRuntime Test for SetAppLibPath
142  * @tc.type: FUNC
143  * @tc.require: issueI581RO
144  */
145 HWTEST_F(JsRuntimeTest, JsRuntimeTestSetAppLibPath_0100, TestSize.Level2)
146 {
147     TAG_LOGI(AAFwkTag::TEST, "SetAppLibPath_0100 start");
148     std::string appLibPathKey = TEST_BUNDLE_NAME + TEST_MODULE_NAME;
149     std::string libPath = TEST_LIB_PATH;
150 
151     AppLibPathMap appLibPaths {};
152     JsRuntime::SetAppLibPath(appLibPaths);
153 
154     appLibPaths[appLibPathKey].emplace_back(libPath);
155     JsRuntime::SetAppLibPath(appLibPaths);
156     EXPECT_NE(appLibPaths.size(), 0);
157     TAG_LOGI(AAFwkTag::TEST, "SetAppLibPath_0100 end");
158 }
159 
160 /**
161  * @tc.name: JsRuntimeUtilsTest_0100
162  * @tc.desc: JsRuntimeUtils Test
163  * @tc.type: FUNC
164  * @tc.require: issueI581RO
165  */
166 HWTEST_F(JsRuntimeTest, JsRuntimeUtilsTest_0100, TestSize.Level0)
167 {
168     TAG_LOGI(AAFwkTag::TEST, "UtilsTest_0100 start");
169 
170     auto env = (static_cast<AbilityRuntime::JsRuntime&>(*jsRuntimePtr)).GetNapiEnv();
171     napi_ref callbackRef = nullptr;
172     napi_create_reference(env, CreateJsUndefined(env), 1, &callbackRef);
173     std::unique_ptr<NapiAsyncTask> task = std::make_unique<NapiAsyncTask>(callbackRef, nullptr, nullptr);
174     task->ResolveWithNoError(env, CreateJsUndefined(env));
175     EXPECT_TRUE(task->callbackRef_ == nullptr);
176 
177     napi_deferred nativeDeferred = nullptr;
178     napi_value result;
179     napi_create_promise(env, &nativeDeferred, &result);
180     task = std::make_unique<NapiAsyncTask>(nativeDeferred, nullptr, nullptr);
181     task->ResolveWithNoError(env, CreateJsUndefined(env));
182     EXPECT_TRUE(task->deferred_ == nullptr);
183 
184     task->deferred_ = nullptr;
185     task->callbackRef_ = nullptr;
186     task->ResolveWithNoError(env, CreateJsUndefined(env));
187     EXPECT_TRUE(task->deferred_ == nullptr);
188     EXPECT_TRUE(task->callbackRef_ == nullptr);
189     std::this_thread::sleep_for(std::chrono::milliseconds(200));
190     TAG_LOGI(AAFwkTag::TEST, "UtilsTest_0100 end");
191 }
192 
193 /**
194  * @tc.name: JsRuntimeGetLanguageTest_0100
195  * @tc.desc: JsRuntime Test
196  * @tc.type: FUNC
197  */
198 HWTEST_F(JsRuntimeTest, JsRuntimeGetLanguageTest_0100, TestSize.Level0)
199 {
200     TAG_LOGI(AAFwkTag::TEST, "GetLanguageTest_0100 start");
201 
202     std::shared_ptr<JsRuntime> jsRuntime = std::make_shared<AbilityRuntime::JsRuntime>();
203     EXPECT_TRUE(jsRuntime != nullptr);
204     Runtime::Language language = jsRuntime->GetLanguage();
205     EXPECT_TRUE(language ==JsRuntime::Language::JS);
206     jsRuntime.reset();
207     std::this_thread::sleep_for(std::chrono::milliseconds(200));
208     TAG_LOGI(AAFwkTag::TEST, "GetLanguageTest_0100 end");
209 }
210 
211 /**
212  * @tc.name: JsRuntimeNotifyApplicationStateTest_0100
213  * @tc.desc: JsRuntime test
214  * @tc.type: FUNC
215  */
216 HWTEST_F(JsRuntimeTest, JsRuntimeNotifyApplicationStateTest_0100, TestSize.Level2)
217 {
218     TAG_LOGI(AAFwkTag::TEST, "NotifyApplicationState start");
219 
220     bool isBackground = false;
221     jsRuntimePtr->NotifyApplicationState(isBackground);
222     ASSERT_TRUE(jsRuntimePtr != nullptr);
223 
224     TAG_LOGI(AAFwkTag::TEST, "NotifyApplicationState end");
225     std::this_thread::sleep_for(std::chrono::milliseconds(200));
226 }
227 
228 /**
229  * @tc.name: JsRuntimeNotifyApplicationStateTest_0200
230  * @tc.desc: JsRuntime test for NotifyApplicationState when nativeEngine is not nullptr.
231  * @tc.type: FUNC
232  */
233 HWTEST_F(JsRuntimeTest, JsRuntimeNotifyApplicationStateTest_0200, TestSize.Level2)
234 {
235     TAG_LOGI(AAFwkTag::TEST, "NotifyApplicationState start");
236 
237     std::unique_ptr<JsRuntime> jsRuntime = std::make_unique<AbilityRuntime::JsRuntime>();
238     EXPECT_TRUE(jsRuntime != nullptr);
239     bool isBackground = true;
240     jsRuntime->NotifyApplicationState(isBackground);
241     jsRuntime.reset();
242     std::this_thread::sleep_for(std::chrono::milliseconds(200));
243 
244     TAG_LOGI(AAFwkTag::TEST, "NotifyApplicationState end");
245 }
246 
247 /**
248  * @tc.name: JsRuntimeDumpHeapSnapshotTest_0100
249  * @tc.desc: JsRuntime test for DumpHeapSnapshot.
250  * @tc.type: FUNC
251  */
252 HWTEST_F(JsRuntimeTest, JsRuntimeDumpHeapSnapshotTest_0100, TestSize.Level2)
253 {
254     TAG_LOGI(AAFwkTag::TEST, "DumpHeapSnapshot start");
255     std::unique_ptr<JsRuntime> jsRuntime = std::make_unique<AbilityRuntime::JsRuntime>();
256     jsRuntime->DumpHeapSnapshot(false);
257     EXPECT_TRUE(jsRuntime != nullptr);
258     TAG_LOGI(AAFwkTag::TEST, "DumpHeapSnapshot end");
259 }
260 
261 /**
262  * @tc.name: JsRuntimePreloadSystemModuleTest_0100
263  * @tc.desc: JsRuntime test for PreloadSystemModule.
264  * @tc.type: FUNC
265  */
266 HWTEST_F(JsRuntimeTest, JsRuntimePreloadSystemModuleTest_0100, TestSize.Level2)
267 {
268     TAG_LOGI(AAFwkTag::TEST, "PreloadSystemModule start");
269 
270     std::unique_ptr<JsRuntime> jsRuntime = std::make_unique<AbilityRuntime::JsRuntime>();
271     std::string moduleName = "PreloadSystemModuleTest";
272     jsRuntime->PreloadSystemModule(moduleName);
273     EXPECT_TRUE(jsRuntime != nullptr);
274     std::this_thread::sleep_for(std::chrono::milliseconds(200));
275 
276     TAG_LOGI(AAFwkTag::TEST, "PreloadSystemModule end");
277 }
278 
279 /**
280  * @tc.name: JsRuntimeRunSandboxScriptTest_0100
281  * @tc.desc: JsRuntime test for RunSandboxScript.
282  * @tc.type: FUNC
283  */
284 HWTEST_F(JsRuntimeTest, JsRuntimeRunSandboxScriptTest_0100, TestSize.Level2)
285 {
286     TAG_LOGI(AAFwkTag::TEST, "RunSandboxScript start");
287 
288     auto jsRuntime = std::make_unique<AbilityRuntime::JsRuntime>();
289     std::string path = "";
290     std::string hapPath = "";
291     auto test = jsRuntime->RunSandboxScript(path, hapPath);
292     EXPECT_EQ(test, false);
293     jsRuntime.reset();
294     std::this_thread::sleep_for(std::chrono::milliseconds(200));
295     TAG_LOGI(AAFwkTag::TEST, "RunSandboxScript end");
296 }
297 
298 /**
299  * @tc.name: JsRuntimeLoadSystemModuleByEngineTest_0100
300  * @tc.desc: JsRuntime test for LoadSystemModuleByEngine.
301  * @tc.type: FUNC
302  */
303 HWTEST_F(JsRuntimeTest, JsRuntimeLoadSystemModuleByEngineTest_0100, TestSize.Level2)
304 {
305     TAG_LOGI(AAFwkTag::TEST, "LoadSystemModuleByEngine start");
306 
307     std::string moduleName = "";
308     std::unique_ptr<JsRuntime> jsRuntime = std::make_unique<AbilityRuntime::JsRuntime>();
309 
310     auto ref = jsRuntime->LoadSystemModuleByEngine(nullptr, moduleName, nullptr, 0);
311     EXPECT_EQ(ref, nullptr);
312     jsRuntime.reset();
313     std::this_thread::sleep_for(std::chrono::milliseconds(200));
314     TAG_LOGI(AAFwkTag::TEST, "LoadSystemModuleByEngine end");
315 }
316 
317 /**
318  * @tc.name: JsRuntimeFinishPreloadTest_0100
319  * @tc.desc: JsRuntime test for FinishPreload.
320  * @tc.type: FUNC
321  */
322 HWTEST_F(JsRuntimeTest, JsRuntimeFinishPreloadTest_0100, TestSize.Level2)
323 {
324     TAG_LOGI(AAFwkTag::TEST, "FinishPreload start");
325 
326     auto jsRuntime = std::make_unique<JsRuntime>();
327 
328     jsRuntime->FinishPreload();
329     EXPECT_TRUE(jsRuntime != nullptr);
330 
331     jsRuntime.reset();
332     std::this_thread::sleep_for(std::chrono::milliseconds(200));
333     TAG_LOGI(AAFwkTag::TEST, "FinishPreload end");
334 }
335 
336 /**
337  * @tc.name: JsRuntimePostPreloadTest_0100
338  * @tc.desc: JsRuntime test for FinishPreload.
339  * @tc.type: FUNC
340  */
341 HWTEST_F(JsRuntimeTest, JsRuntimePostPreloadTest_0100, TestSize.Level2)
342 {
343     TAG_LOGI(AAFwkTag::TEST, "PostPreload start");
344 
345     auto jsRuntime = std::make_unique<JsRuntime>();
346 
347     jsRuntime->PostPreload(options_);
348     EXPECT_TRUE(jsRuntime != nullptr);
349 
350     jsRuntime.reset();
351     std::this_thread::sleep_for(std::chrono::milliseconds(200));
352     TAG_LOGI(AAFwkTag::TEST, "PostPreload end");
353 }
354 
355 /**
356  * @tc.name: JsRuntimeLoadAotFileTest_0100
357  * @tc.desc: JsRuntime test for LoadAotFile.
358  * @tc.type: FUNC
359  */
360 HWTEST_F(JsRuntimeTest, JsRuntimeLoadAotFileTest_0100, TestSize.Level2)
361 {
362     TAG_LOGI(AAFwkTag::TEST, "LoadAotFile start");
363 
364     auto jsRuntime = std::make_unique<JsRuntime>();
365 
366     jsRuntime->LoadAotFile(options_);
367     EXPECT_TRUE(jsRuntime != nullptr);
368 
369     jsRuntime.reset();
370     std::this_thread::sleep_for(std::chrono::milliseconds(200));
371     TAG_LOGI(AAFwkTag::TEST, "LoadAotFile end");
372 }
373 
374 /**
375  * @tc.name: JsRuntimeLoadModuleTest_0100
376  * @tc.desc: JsRuntime test for LoadModule.
377  * @tc.type: FUNC
378  */
379 HWTEST_F(JsRuntimeTest, JsRuntimeLoadModuleTest_0100, TestSize.Level1)
380 {
381     TAG_LOGI(AAFwkTag::TEST, "LoadModule start");
382 
383     std::unique_ptr<JsRuntime> jsRuntime = std::make_unique<AbilityRuntime::JsRuntime>();
384 
385     std::string moduleName = TEST_MODULE_NAME;
386     std::string modulePath = TEST_MODULE_PATH;
387     std::string hapPath = TEST_HAP_PATH;
388     auto ref = jsRuntimePtr->LoadModule(moduleName, modulePath, hapPath);
389     EXPECT_EQ(ref, nullptr);
390     jsRuntime.reset();
391     std::this_thread::sleep_for(std::chrono::milliseconds(200));
392     TAG_LOGI(AAFwkTag::TEST, "LoadModule end");
393 }
394 
395 /**
396  * @tc.name: JsRuntimeLoadSystemModuleTest_0100
397  * @tc.desc: JsRuntime test for LoadSystemModule (invoke the overwrite interface).
398  * @tc.type: FUNC
399  */
400 HWTEST_F(JsRuntimeTest, JsRuntimeLoadSystemModuleTest_0100, TestSize.Level1)
401 {
402     TAG_LOGI(AAFwkTag::TEST, "LoadSystemModule start");
403 
404     std::unique_ptr<JsRuntime> jsRuntime = std::make_unique<AbilityRuntime::JsRuntime>();
405     std::string moduleName = TEST_MODULE_NAME;
406     auto ref = jsRuntime->LoadSystemModule(moduleName, nullptr, 0);
407     EXPECT_EQ(ref, nullptr);
408     jsRuntime.reset();
409     std::this_thread::sleep_for(std::chrono::milliseconds(200));
410     TAG_LOGI(AAFwkTag::TEST, "LoadSystemModule end");
411 }
412 
413 /**
414  * @tc.name: RuntimeSavePreloadedTest_0100
415  * @tc.desc: Runtime test for SavePreloaded.
416  * @tc.type: FUNC
417  */
418 HWTEST_F(JsRuntimeTest, RuntimeSavePreloadedTest_0100, TestSize.Level1)
419 {
420     TAG_LOGI(AAFwkTag::TEST, "SavePreloaded start");
421 
422     Runtime::SavePreloaded(nullptr);
423     auto result = Runtime::GetPreloaded(Runtime::Language::JS);
424     EXPECT_EQ(result, nullptr);
425 
426     std::this_thread::sleep_for(std::chrono::milliseconds(200));
427     TAG_LOGI(AAFwkTag::TEST, "SavePreloaded end");
428 }
429 
430 /**
431  * @tc.name: RuntimeSetModuleLoadCheckerTest_0100
432  * @tc.desc: Runtime test for SetModuleLoadChecker.
433  * @tc.type: FUNC
434  */
435 HWTEST_F(JsRuntimeTest, RuntimeSetModuleLoadCheckerTest_0100, TestSize.Level1)
436 {
437     TAG_LOGI(AAFwkTag::TEST, "SetModuleLoadChecker start");
438 
439     std::unique_ptr<JsRuntime> jsRuntime = std::make_unique<AbilityRuntime::JsRuntime>();
440     jsRuntime->SetModuleLoadChecker(nullptr);
441     EXPECT_TRUE(jsRuntime != nullptr);
442     jsRuntime.reset();
443     std::this_thread::sleep_for(std::chrono::milliseconds(200));
444     TAG_LOGI(AAFwkTag::TEST, "SetModuleLoadChecker end");
445 }
446 
447 /**
448  * @tc.name: JsRuntimeSuspendVMTest_0100
449  * @tc.desc: JsRuntime test for SuspendVM.
450  * @tc.type: FUNC
451  */
452 HWTEST_F(JsRuntimeTest, JsRuntimeSuspendVMTest_0100, TestSize.Level1)
453 {
454     TAG_LOGI(AAFwkTag::TEST, "SuspendVM start");
455 
456     auto jsRuntime = std::make_unique<AbilityRuntime::JsRuntime>();
457     auto result = jsRuntime->SuspendVM(gettid());
458     EXPECT_EQ(result, false);
459 
460     jsRuntime.reset();
461     std::this_thread::sleep_for(std::chrono::milliseconds(200));
462     TAG_LOGI(AAFwkTag::TEST, "SuspendVM end");
463 }
464 
465 /**
466  * @tc.name: JsRuntimeResumeVMTest_0100
467  * @tc.desc: JsRuntime test for ResumeVM.
468  * @tc.type: FUNC
469  */
470 HWTEST_F(JsRuntimeTest, JsRuntimeResumeVMTest_0100, TestSize.Level1)
471 {
472     TAG_LOGI(AAFwkTag::TEST, "ResumeVM start");
473 
474     auto jsRuntime = std::make_unique<AbilityRuntime::JsRuntime>();
475     jsRuntime->ResumeVM(gettid());
476     EXPECT_TRUE(jsRuntime != nullptr);
477 
478     jsRuntime.reset();
479     std::this_thread::sleep_for(std::chrono::milliseconds(200));
480     TAG_LOGI(AAFwkTag::TEST, "ResumeVM end");
481 }
482 
483 /**
484  * @tc.name: JsRuntimeSetDeviceDisconnectCallbackTest_0100
485  * @tc.desc: JsRuntime test for SetDeviceDisconnectCallback.
486  * @tc.type: FUNC
487  */
488 HWTEST_F(JsRuntimeTest, JsRuntimeSetDeviceDisconnectCallbackTest_0100, TestSize.Level2)
489 {
490     TAG_LOGI(AAFwkTag::TEST, "SetDeviceDisconnectCallback start");
491 
492     auto jsRuntime = std::make_unique<AbilityRuntime::JsRuntime>();
__anon9ee3b5ae0202() 493     std::function<bool()> task = [&]() {
494         return true;
495     };
496     jsRuntime->SetDeviceDisconnectCallback(task);
497     EXPECT_TRUE(jsRuntime != nullptr);
498 
499     jsRuntime.reset();
500     std::this_thread::sleep_for(std::chrono::milliseconds(200));
501     TAG_LOGI(AAFwkTag::TEST, "SetDeviceDisconnectCallback end");
502 }
503 
504 /**
505  * @tc.name: JsRuntimeDetachCallbackFuncTest_0100
506  * @tc.desc: JsRuntime test for PostTask.
507  * @tc.type: FUNC
508  */
509 HWTEST_F(JsRuntimeTest, JsRuntimeDetachCallbackFuncTest_0100, TestSize.Level2)
510 {
511     TAG_LOGI(AAFwkTag::TEST, "DetachCallbackFunc start");
512 
513     int32_t value = 1;
514     int32_t number = 1;
515     auto result = AbilityRuntime::DetachCallbackFunc(nullptr, &value, &number);
516     EXPECT_EQ(result, &value);
517 
518     std::this_thread::sleep_for(std::chrono::milliseconds(200));
519     TAG_LOGI(AAFwkTag::TEST, "DetachCallbackFunc end");
520 }
521 
522 /**
523  * @tc.name: JsRuntimeLoadSystemModulesTest_0100
524  * @tc.desc: JsRuntime test for LoadSystemModule.
525  * @tc.type: FUNC
526  */
527 HWTEST_F(JsRuntimeTest, JsRuntimeLoadSystemModulesTest_0100, TestSize.Level2)
528 {
529     TAG_LOGI(AAFwkTag::TEST, "LoadSystemModule start");
530 
531     auto jsRuntime = std::make_unique<AbilityRuntime::JsRuntime>();
532     std::string moduleName = "PreloadSystemModuleTest";
533     napi_value object = nullptr;
534     std::unique_ptr<NativeReference> ref = jsRuntime->LoadSystemModule(moduleName, &object, 0);
535     EXPECT_EQ(ref, nullptr);
536 
537     jsRuntime.reset();
538     std::this_thread::sleep_for(std::chrono::milliseconds(200));
539     TAG_LOGI(AAFwkTag::TEST, "LoadSystemModule end");
540 }
541 
542 /**
543  * @tc.name: JsRuntimeStartDebugModeTest_0100
544  * @tc.desc: JsRuntime test for StartDebugMode.
545  * @tc.type: FUNC
546  */
547 HWTEST_F(JsRuntimeTest, JsRuntimeStartDebugModeTest_0100, TestSize.Level2)
548 {
549     TAG_LOGI(AAFwkTag::TEST, "JsRuntimeStartDebugModeTest_0100 start");
550 
551     auto jsRuntime = std::make_unique<JsRuntime>();
552     AbilityRuntime::Runtime::DebugOption debugOption;
553     debugOption.isStartWithDebug = true;
554     debugOption.processName = "test";
555     debugOption.isDebugApp = true;
556     debugOption.isStartWithNative = false;
557     debugOption.isDeveloperMode = true;
558     jsRuntime->StartDebugMode(debugOption);
559     EXPECT_TRUE(jsRuntime != nullptr);
560 
561     jsRuntime.reset();
562     std::this_thread::sleep_for(std::chrono::milliseconds(200));
563     TAG_LOGI(AAFwkTag::TEST, "JsRuntimeStartDebugModeTest_0100 end");
564 }
565 
566 /**
567  * @tc.name: JsRuntimeStartDebugModeTest_0200
568  * @tc.desc: JsRuntime test for StartDebugMode.
569  * @tc.type: FUNC
570  */
571 HWTEST_F(JsRuntimeTest, JsRuntimeStartDebugModeTest_0200, TestSize.Level2)
572 {
573     TAG_LOGI(AAFwkTag::TEST, "JsRuntimeStartDebugModeTest_0200 start");
574 
575     auto jsRuntime = std::make_unique<JsRuntime>();
576     AbilityRuntime::Runtime::DebugOption debugOption;
577     debugOption.isStartWithDebug = true;
578     debugOption.processName = "test";
579     debugOption.isDebugApp = true;
580     debugOption.isStartWithNative = false;
581     debugOption.isDeveloperMode = false;
582     debugOption.isDebugFromLocal = true;
583     jsRuntime->StartDebugMode(debugOption);
584     EXPECT_TRUE(jsRuntime != nullptr);
585 
586     jsRuntime.reset();
587     std::this_thread::sleep_for(std::chrono::milliseconds(200));
588     TAG_LOGI(AAFwkTag::TEST, "JsRuntimeStartDebugModeTest_0200 end");
589 }
590 
591 /**
592  * @tc.name: JsRuntimeStopDebugModeTest_0100
593  * @tc.desc: JsRuntime test for StopDebugMode.
594  * @tc.type: FUNC
595  */
596 HWTEST_F(JsRuntimeTest, JsRuntimeStopDebugModeTest_0100, TestSize.Level2)
597 {
598     TAG_LOGI(AAFwkTag::TEST, "StopDebugMode start");
599 
600     auto jsRuntime = std::make_unique<JsRuntime>();
601 
602     jsRuntime->StopDebugMode();
603     EXPECT_TRUE(jsRuntime != nullptr);
604 
605     jsRuntime.reset();
606     std::this_thread::sleep_for(std::chrono::milliseconds(200));
607     TAG_LOGI(AAFwkTag::TEST, "StopDebugMode end");
608 }
609 
610 /**
611  * @tc.name: JsRuntimeInitConsoleModuleTest_0100
612  * @tc.desc: JsRuntime test for InitConsoleModule.
613  * @tc.type: FUNC
614  */
615 HWTEST_F(JsRuntimeTest, JsRuntimeInitConsoleModuleTest_0100, TestSize.Level2)
616 {
617     TAG_LOGI(AAFwkTag::TEST, "InitConsoleModule start");
618 
619     auto jsRuntime = std::make_unique<JsRuntime>();
620 
621     jsRuntime->InitConsoleModule();
622     EXPECT_TRUE(jsRuntime != nullptr);
623 
624     jsRuntime.reset();
625     std::this_thread::sleep_for(std::chrono::milliseconds(200));
626     TAG_LOGI(AAFwkTag::TEST, "InitConsoleModule end");
627 }
628 
629 /**
630  * @tc.name: JsRuntimeLoadRepairPatchTest_0100
631  * @tc.desc: JsRuntime test for LoadRepairPatch.
632  * @tc.type: FUNC
633  */
634 HWTEST_F(JsRuntimeTest, JsRuntimeLoadRepairPatchTest_0100, TestSize.Level2)
635 {
636     TAG_LOGI(AAFwkTag::TEST, "LoadRepairPatch start");
637 
638     auto jsRuntime = std::make_unique<JsRuntime>();
639     EXPECT_TRUE(jsRuntime != nullptr);
640 
641     std::string hqfFile = "<hqfFile>";
642     std::string hapPath = "<hapPath>";
643     bool lrp = jsRuntime->LoadRepairPatch(hqfFile, hapPath);
644     EXPECT_EQ(lrp, false);
645 
646     jsRuntime.reset();
647     std::this_thread::sleep_for(std::chrono::milliseconds(200));
648     TAG_LOGI(AAFwkTag::TEST, "LoadRepairPatch end");
649 }
650 
651 /**
652  * @tc.name: JsRuntimeUnLoadRepairPatchTest_0100
653  * @tc.desc: JsRuntime test for UnLoadRepairPatch.
654  * @tc.type: FUNC
655  */
656 HWTEST_F(JsRuntimeTest, JsRuntimeUnLoadRepairPatchTest_0100, TestSize.Level2)
657 {
658     TAG_LOGI(AAFwkTag::TEST, "UnLoadRepairPatch start");
659 
660     auto jsRuntime = std::make_unique<JsRuntime>();
661     EXPECT_TRUE(jsRuntime != nullptr);
662 
663     std::string hqfFile = "<hqfFile>";
664     bool lrp = jsRuntime->UnLoadRepairPatch(hqfFile);
665     EXPECT_EQ(lrp, false);
666 
667     jsRuntime.reset();
668     std::this_thread::sleep_for(std::chrono::milliseconds(200));
669     TAG_LOGI(AAFwkTag::TEST, "UnLoadRepairPatch end");
670 }
671 
672 /**
673  * @tc.name: JsRuntimeNotifyHotReloadPageTest_0100
674  * @tc.desc: JsRuntime test for NotifyHotReloadPage.
675  * @tc.type: FUNC
676  */
677 HWTEST_F(JsRuntimeTest, JsRuntimeNotifyHotReloadPageTest_0100, TestSize.Level2)
678 {
679     TAG_LOGI(AAFwkTag::TEST, "NotifyHotReloadPage start");
680 
681     auto jsRuntime = std::make_unique<JsRuntime>();
682     EXPECT_TRUE(jsRuntime != nullptr);
683 
684     bool lrp = jsRuntime->NotifyHotReloadPage();
685     EXPECT_EQ(lrp, true);
686 
687     jsRuntime.reset();
688     std::this_thread::sleep_for(std::chrono::milliseconds(200));
689     TAG_LOGI(AAFwkTag::TEST, "NotifyHotReloadPage end");
690 }
691 
692 /**
693  * @tc.name: JsRuntimeUpdateModuleNameAndAssetPathTest_0100
694  * @tc.desc: JsRuntime test for UpdateModuleNameAndAssetPath.
695  * @tc.type: FUNC
696  */
697 HWTEST_F(JsRuntimeTest, JsRuntimeUpdateModuleNameAndAssetPathTest_0100, TestSize.Level2)
698 {
699     TAG_LOGI(AAFwkTag::TEST, "UpdateModuleNameAndAssetPath start");
700 
701     auto jsRuntime = std::make_unique<JsRuntime>();
702     EXPECT_TRUE(jsRuntime != nullptr);
703 
704     std::string moduleName = "moduleName";
705     jsRuntime->UpdateModuleNameAndAssetPath(moduleName);
706 
707     jsRuntime.reset();
708     std::this_thread::sleep_for(std::chrono::milliseconds(200));
709     TAG_LOGI(AAFwkTag::TEST, "UpdateModuleNameAndAssetPath end");
710 }
711 
712 /**
713  * @tc.name: JsRuntimeUpdateModuleNameAndAssetPathTest_0200
714  * @tc.desc: JsRuntime test for UpdateModuleNameAndAssetPath.
715  * @tc.type: FUNC
716  */
717 HWTEST_F(JsRuntimeTest, JsRuntimeUpdateModuleNameAndAssetPathTest_0200, TestSize.Level2)
718 {
719     TAG_LOGI(AAFwkTag::TEST, "JsRuntimeUpdateModuleNameAndAssetPathTest_0200 start");
720 
721     auto jsRuntime = std::make_unique<JsRuntime>();
722     EXPECT_TRUE(jsRuntime != nullptr);
723 
724     jsRuntime->isBundle_ = false;
725     std::string moduleName = "moduleName";
726     jsRuntime->UpdateModuleNameAndAssetPath(moduleName);
727 
728     jsRuntime.reset();
729     std::this_thread::sleep_for(std::chrono::milliseconds(200));
730     TAG_LOGI(AAFwkTag::TEST, "JsRuntimeUpdateModuleNameAndAssetPathTest_0200 end");
731 }
732 
733 /**
734  * @tc.name: JsRuntimeUpdateModuleNameAndAssetPathTest_0300
735  * @tc.desc: JsRuntime test for UpdateModuleNameAndAssetPath.
736  * @tc.type: FUNC
737  */
738 HWTEST_F(JsRuntimeTest, JsRuntimeUpdateModuleNameAndAssetPathTest_0300, TestSize.Level2)
739 {
740     TAG_LOGI(AAFwkTag::TEST, "JsRuntimeUpdateModuleNameAndAssetPathTest_0300 start");
741 
742     auto jsRuntime = std::make_unique<JsRuntime>();
743     EXPECT_TRUE(jsRuntime != nullptr);
744 
745     jsRuntime->isBundle_ = false;
746     std::string moduleName = "";
747     jsRuntime->UpdateModuleNameAndAssetPath(moduleName);
748 
749     jsRuntime.reset();
750     std::this_thread::sleep_for(std::chrono::milliseconds(200));
751     TAG_LOGI(AAFwkTag::TEST, "JsRuntimeUpdateModuleNameAndAssetPathTest_0300 end");
752 }
753 
754 /**
755  * @tc.name: JsRuntimeInitialize_0100
756  * @tc.desc: Initialize js runtime in multi thread.
757  * @tc.type: FUNC
758  * @tc.require: issueI6KODF
759  */
760 HWTEST_F(JsRuntimeTest, JsRuntimeInitialize_0100, TestSize.Level2)
761 {
762     TAG_LOGI(AAFwkTag::TEST, "Running in multi-thread, using default thread number.");
763 
764     auto jsRuntime = std::make_unique<AbilityRuntime::JsRuntime>();
765     jsRuntime->preloaded_ = true;
766     AbilityRuntime::Runtime::Options options;
767     options.isStageModel = false;
768     options.isTestFramework = false;
769     options.preload = true;
770     options.versionCode = 1000;
771     bool result = jsRuntime->Initialize(options);
772     EXPECT_EQ(result, true);
773 
774     std::this_thread::sleep_for(std::chrono::milliseconds(200));
775     TAG_LOGI(AAFwkTag::TEST, "Initialize_0100 end");
776 }
777 
778 /**
779  * @tc.name: RegisterQuickFixQueryFunc_0100
780  * @tc.desc: JsRuntime test for RegisterQuickFixQueryFunc.
781  * @tc.type: FUNC
782  */
783 HWTEST_F(JsRuntimeTest, RegisterQuickFixQueryFunc_0100, TestSize.Level2)
784 {
785     TAG_LOGI(AAFwkTag::TEST, "RegisterQuickFixQueryFunc start");
786 
787     auto jsRuntime = std::make_unique<JsRuntime>();
788     EXPECT_TRUE(jsRuntime != nullptr);
789     std::string moudel = "<moudelName>";
790     std::string hqfFile = "<hqfFile>";
791     std::map<std::string, std::string> moduleAndPath;
792     moduleAndPath.insert(std::make_pair(moudel, hqfFile));
793     jsRuntime->RegisterQuickFixQueryFunc(moduleAndPath);
794     jsRuntime.reset();
795     std::this_thread::sleep_for(std::chrono::milliseconds(200));
796     TAG_LOGI(AAFwkTag::TEST, "RegisterQuickFixQueryFunc end");
797 }
798 
799 /**
800  * @tc.name: RegisterUncaughtExceptionHandler_0100
801  * @tc.desc: JsRuntime test for RegisterUncaughtExceptionHandler.
802  * @tc.type: FUNC
803  */
804 HWTEST_F(JsRuntimeTest, RegisterUncaughtExceptionHandler_0100, TestSize.Level2)
805 {
806     TAG_LOGI(AAFwkTag::TEST, "RegisterUncaughtExceptionHandler start");
807 
808     auto jsRuntime = std::make_unique<JsRuntime>();
809     ASSERT_NE(jsRuntime, nullptr);
810     JsEnv::UncaughtExceptionInfo uncaughtExceptionInfo;
811     jsRuntime->RegisterUncaughtExceptionHandler(uncaughtExceptionInfo);
812     jsRuntime.reset();
813     std::this_thread::sleep_for(std::chrono::milliseconds(200));
814     TAG_LOGI(AAFwkTag::TEST, "RegisterUncaughtExceptionHandler end");
815 }
816 
817 /**
818  * @tc.name: ReadSourceMapData_0100
819  * @tc.desc: JsRuntime test for ReadSourceMapData.
820  * @tc.type: FUNC
821  */
822 HWTEST_F(JsRuntimeTest, ReadSourceMapData_0100, TestSize.Level2)
823 {
824     TAG_LOGI(AAFwkTag::TEST, "ReadSourceMapData start");
825 
826     auto jsRuntime = std::make_unique<JsRuntime>();
827     ASSERT_NE(jsRuntime, nullptr);
828     std::string hapPath = "";
829     std::string sourceMapPath = "";
830     std::string content = "";
831     auto result = jsRuntime->ReadSourceMapData(hapPath, sourceMapPath, content);
832     ASSERT_FALSE(result);
833 
834     std::this_thread::sleep_for(std::chrono::milliseconds(200));
835     TAG_LOGI(AAFwkTag::TEST, "ReadSourceMapData end");
836 }
837 
838 /**
839  * @tc.name: StopDebugger_0100
840  * @tc.desc: JsRuntime test for StopDebugger.
841  * @tc.type: FUNC
842  */
843 HWTEST_F(JsRuntimeTest, StopDebugger_0100, TestSize.Level2)
844 {
845     TAG_LOGI(AAFwkTag::TEST, "StopDebugger_0100 start");
846 
847     auto jsRuntime = std::make_unique<JsRuntime>();
848     ASSERT_NE(jsRuntime, nullptr);
849     jsRuntime->StopDebugger();
850     jsRuntime.reset();
851     std::this_thread::sleep_for(std::chrono::milliseconds(200));
852     TAG_LOGI(AAFwkTag::TEST, "StopDebugger_0100 end");
853 }
854 
855 /**
856  * @tc.name: GetFileBuffer_0100
857  * @tc.desc: JsRuntime test for GetFileBuffer.
858  * @tc.type: FUNC
859  */
860 HWTEST_F(JsRuntimeTest, GetFileBuffer_0100, TestSize.Level2)
861 {
862     TAG_LOGI(AAFwkTag::TEST, "GetFileBuffer_0100 start");
863 
864     auto jsRuntime = std::make_unique<JsRuntime>();
865     ASSERT_NE(jsRuntime, nullptr);
866     std::string filePath = "";
867     std::string fileFullName = "";
868     std::vector<uint8_t> buffer;
869     bool result = jsRuntime->GetFileBuffer(filePath, fileFullName, buffer);
870     EXPECT_EQ(result, false);
871     jsRuntime.reset();
872     std::this_thread::sleep_for(std::chrono::milliseconds(200));
873     TAG_LOGI(AAFwkTag::TEST, "GetFileBuffer_0100 end");
874 }
875 
876 /**
877  * @tc.name: JsRuntimeRunScriptTest_0100
878  * @tc.desc: JsRuntime test for RunScript.
879  * @tc.type: FUNC
880  */
881 HWTEST_F(JsRuntimeTest, JsRuntimeRunScriptTest_0100, TestSize.Level2)
882 {
883     TAG_LOGI(AAFwkTag::TEST, "RunScript_0100 start");
884 
885     auto jsRuntime = std::make_unique<AbilityRuntime::JsRuntime>();
886     std::string srcPath = TEST_MODULE_PATH;
887     std::string hapPath = TEST_HAP_PATH;
888     auto result = jsRuntime->RunScript(srcPath, hapPath);
889     EXPECT_EQ(result, false);
890     jsRuntime.reset();
891     std::this_thread::sleep_for(std::chrono::milliseconds(200));
892     TAG_LOGI(AAFwkTag::TEST, "RunScript_0100 end");
893 }
894 
895 /**
896  * @tc.name: JsRuntimeLoadScriptTest_0100
897  * @tc.desc: JsRuntime test for LoadScript.
898  * @tc.type: FUNC
899  */
900 HWTEST_F(JsRuntimeTest, JsRuntimeLoadScriptTest_0100, TestSize.Level2)
901 {
902     TAG_LOGI(AAFwkTag::TEST, "LoadScriptTest_0100 start");
903     auto jsRuntime = std::make_unique<AbilityRuntime::JsRuntime>();
904     std::string path = "/system/etc/strip.native.min.abc";
905     auto result = jsRuntime->LoadScript(path);
906     EXPECT_EQ(result, false);
907     jsRuntime.reset();
908     std::this_thread::sleep_for(std::chrono::milliseconds(200));
909     TAG_LOGI(AAFwkTag::TEST, "LoadScriptTest_0100 end");
910 }
911 
912 /**
913  * @tc.name: JsRuntimeStopDebuggerTest_0100
914  * @tc.desc: JsRuntime test for StopDebugger.
915  * @tc.type: FUNC
916  */
917 HWTEST_F(JsRuntimeTest, JsRuntimeStopDebuggerTest_0100, TestSize.Level2)
918 {
919     TAG_LOGI(AAFwkTag::TEST, "StopDebuggerTest_0100 start");
920     auto jsRuntime = std::make_unique<AbilityRuntime::JsRuntime>();
921     ASSERT_NE(jsRuntime, nullptr);
922 
923     jsRuntime->StopDebugger();
924     jsRuntime.reset();
925     std::this_thread::sleep_for(std::chrono::milliseconds(200));
926     TAG_LOGI(AAFwkTag::TEST, "StopDebuggerTest_0100 end");
927 }
928 
929 /**
930  * @tc.name: PostSyncTask_0100
931  * @tc.desc: Js runtime post sync task.
932  * @tc.type: FUNC
933  * @tc.require: issueI7C87T
934  */
935 HWTEST_F(JsRuntimeTest, PostSyncTask_0100, TestSize.Level1)
936 {
937     TAG_LOGI(AAFwkTag::TEST, "PostSyncTask_0100 start");
938 
939     auto jsRuntime = std::make_unique<AbilityRuntime::JsRuntime>();
940     ASSERT_NE(jsRuntime, nullptr);
941     std::string taskName = "syncTask001";
942     bool taskExecuted = false;
__anon9ee3b5ae0302() 943     auto task = [taskName, &taskExecuted]() {
944         TAG_LOGI(AAFwkTag::TEST, "%{public}s called.", taskName.c_str());
945         taskExecuted = true;
946     };
947     jsRuntime->PostSyncTask(task, taskName);
948     EXPECT_NE(taskExecuted, true);
949     std::this_thread::sleep_for(std::chrono::milliseconds(200));
950     TAG_LOGI(AAFwkTag::TEST, "PostSyncTask_0100 end");
951 }
952 
953 /**
954  * @tc.name: ReInitJsEnvImpl_0100
955  * @tc.desc: Js runtime reinit js env impl.
956  * @tc.type: FUNC
957  * @tc.require: issueI7C87T
958  */
959 HWTEST_F(JsRuntimeTest, ReInitJsEnvImpl_0100, TestSize.Level1)
960 {
961     TAG_LOGI(AAFwkTag::TEST, "ReInitJsEnvImpl_0100 start");
962     auto jsRuntime = std::make_unique<JsRuntime>();
963     EXPECT_TRUE(jsRuntime != nullptr);
964 
965     jsRuntime->ReInitJsEnvImpl(options_);
966     jsRuntime.reset();
967     std::this_thread::sleep_for(std::chrono::milliseconds(200));
968     TAG_LOGI(AAFwkTag::TEST, "ReInitJsEnvImpl_0100 end");
969 }
970 
971 /**
972  * @tc.name: PostTask_0100
973  * @tc.desc: Js runtime post task.
974  * @tc.type: FUNC
975  * @tc.require: issueI7C87T
976  */
977 HWTEST_F(JsRuntimeTest, PostTask_0100, TestSize.Level1)
978 {
979     TAG_LOGI(AAFwkTag::TEST, "PostTask_0100 start");
980 
981     auto jsRuntime = std::make_unique<JsRuntime>();
982     std::string taskName = "postTask001";
983     bool taskExecuted = false;
__anon9ee3b5ae0402() 984     auto task = [taskName, &taskExecuted]() {
985         TAG_LOGI(AAFwkTag::TEST, "%{public}s called.", taskName.c_str());
986         taskExecuted = true;
987     };
988     int64_t delayTime = 10;
989     jsRuntime->PostTask(task, taskName, delayTime);
990     EXPECT_NE(taskExecuted, true);
991     TAG_LOGI(AAFwkTag::TEST, "PostTask_0100 end");
992 }
993 
994 /**
995  * @tc.name: RemoveTask_0100
996  * @tc.desc: Js runtime remove task.
997  * @tc.type: FUNC
998  * @tc.require: issueI7C87T
999  */
1000 HWTEST_F(JsRuntimeTest, RemoveTask_0100, TestSize.Level1)
1001 {
1002     TAG_LOGI(AAFwkTag::TEST, "RemoveTask_0100 start");
1003 
1004     auto jsRuntime = std::make_unique<JsRuntime>();
1005     ASSERT_TRUE(jsRuntime != nullptr);
1006 
1007     std::string taskName = "removeTask001";
1008     bool taskExecuted = false;
__anon9ee3b5ae0502() 1009     auto task = [taskName, &taskExecuted]() {
1010         TAG_LOGI(AAFwkTag::TEST, "%{public}s called.", taskName.c_str());
1011         taskExecuted = true;
1012     };
1013     int64_t delayTime = 10;
1014     jsRuntime->PostTask(task, taskName, delayTime);
1015     jsRuntime->RemoveTask(taskName);
1016     EXPECT_NE(taskExecuted, true);
1017     TAG_LOGI(AAFwkTag::TEST, "RemoveTask_0100 end");
1018 }
1019 
1020 /**
1021  * @tc.name: StartDebugger_0100
1022  * @tc.desc: JsRuntime test for StartDebugger.
1023  * @tc.type: FUNC
1024  */
1025 HWTEST_F(JsRuntimeTest, StartDebugger_0100, TestSize.Level1)
1026 {
1027     TAG_LOGI(AAFwkTag::TEST, "StartDebugger_0100 start");
1028 
1029     auto jsRuntime = std::make_unique<AbilityRuntime::JsRuntime>();
1030     ASSERT_NE(jsRuntime, nullptr);
1031 
1032     bool needBreakPoint = false;
1033     uint32_t instanceId = 1;
1034 
1035     auto result = jsRuntime->StartDebugger(needBreakPoint, instanceId);
1036     EXPECT_EQ(result, true);
1037     // debug mode is global option, maybe has started by other testcase, not check here.
1038     TAG_LOGI(AAFwkTag::TEST, "StartDebugger_0100 end");
1039 }
1040 
1041 /**
1042  * @tc.name: ReloadFormComponent_0100
1043  * @tc.desc: JsRuntime test for ReloadFormComponent.
1044  * @tc.type: FUNC
1045  */
1046 HWTEST_F(JsRuntimeTest, ReloadFormComponent_0100, TestSize.Level2)
1047 {
1048     TAG_LOGI(AAFwkTag::TEST, "ReloadFormComponent_0100 start");
1049 
1050     auto jsRuntime = std::make_unique<AbilityRuntime::JsRuntime>();
1051     ASSERT_NE(jsRuntime, nullptr);
1052 
1053     jsRuntime->ReloadFormComponent();
1054     jsRuntime.reset();
1055     TAG_LOGI(AAFwkTag::TEST, "ReloadFormComponent_0100 end");
1056 }
1057 
1058 /**
1059  * @tc.name: SetRequestAotCallback_0100
1060  * @tc.desc: JsRuntime test for SetRequestAotCallback.
1061  * @tc.type: FUNC
1062  * @tc.require: issueI82L1A
1063  */
1064 HWTEST_F(JsRuntimeTest, SetRequestAotCallback_0100, TestSize.Level2)
1065 {
1066     TAG_LOGI(AAFwkTag::TEST, "start");
1067 
1068     auto jsRuntime = std::make_unique<AbilityRuntime::JsRuntime>();
1069     ASSERT_NE(jsRuntime, nullptr);
1070 
1071     jsRuntime->SetRequestAotCallback();
1072     auto ret = panda::MockJSNApi::GetInstance()->RequestAot("bundleName", "moduleName", 0);
1073     EXPECT_NE(ret, -1);
1074     jsRuntime.reset();
1075     TAG_LOGI(AAFwkTag::TEST, "finish");
1076 }
1077 
1078 /**
1079  * @tc.name: DestroyHeapProfiler_0100
1080  * @tc.desc: JsRuntime test for DestroyHeapProfiler.
1081  * @tc.type: FUNC
1082  */
1083 HWTEST_F(JsRuntimeTest, DestroyHeapProfiler_0100, TestSize.Level2)
1084 {
1085     TAG_LOGI(AAFwkTag::TEST, "DestroyHeapProfiler_0100 start");
1086 
1087     auto jsRuntime = std::make_unique<AbilityRuntime::JsRuntime>();
1088 
1089     jsRuntime->DestroyHeapProfiler();
1090     ASSERT_NE(jsRuntime, nullptr);
1091     jsRuntime.reset();
1092     TAG_LOGI(AAFwkTag::TEST, "DestroyHeapProfiler_0100 end");
1093 }
1094 
1095 /**
1096  * @tc.name: ForceFullGC_0100
1097  * @tc.desc: JsRuntime test for ForceFullGC.
1098  * @tc.type: FUNC
1099  */
1100 HWTEST_F(JsRuntimeTest, ForceFullGC_0100, TestSize.Level2)
1101 {
1102     TAG_LOGI(AAFwkTag::TEST, "ForceFullGC_0100 start");
1103 
1104     auto jsRuntime = std::make_unique<AbilityRuntime::JsRuntime>();
1105 
1106     jsRuntime->ForceFullGC();
1107     ASSERT_NE(jsRuntime, nullptr);
1108     jsRuntime.reset();
1109     TAG_LOGI(AAFwkTag::TEST, "ForceFullGC_0100 end");
1110 }
1111 
1112 /**
1113  * @tc.name: AllowCrossThreadExecution_0100
1114  * @tc.desc: JsRuntime test for AllowCrossThreadExecution.
1115  * @tc.type: FUNC
1116  */
1117 HWTEST_F(JsRuntimeTest, AllowCrossThreadExecution_0100, TestSize.Level2)
1118 {
1119     TAG_LOGI(AAFwkTag::TEST, "AllowCrossThreadExecution_0100 start");
1120 
1121     auto jsRuntime = std::make_unique<AbilityRuntime::JsRuntime>();
1122 
1123     jsRuntime->AllowCrossThreadExecution();
1124     ASSERT_NE(jsRuntime, nullptr);
1125     TAG_LOGI(AAFwkTag::TEST, "AllowCrossThreadExecution_0100 end");
1126 }
1127 
1128 /**
1129  * @tc.name: GetHeapPrepare_0100
1130  * @tc.desc: JsRuntime test for GetHeapPrepare.
1131  * @tc.type: FUNC
1132  */
1133 HWTEST_F(JsRuntimeTest, GetHeapPrepare_0100, TestSize.Level2)
1134 {
1135     TAG_LOGI(AAFwkTag::TEST, "GetHeapPrepare_0100 start");
1136 
1137     auto jsRuntime = std::make_unique<AbilityRuntime::JsRuntime>();
1138 
1139     jsRuntime->GetHeapPrepare();
1140     ASSERT_NE(jsRuntime, nullptr);
1141     TAG_LOGI(AAFwkTag::TEST, "GetHeapPrepare_0100 end");
1142 }
1143 
1144 /**
1145  * @tc.name: InitLoop_0100
1146  * @tc.desc: JsRuntime test for InitLoop.
1147  * @tc.type: FUNC
1148  */
1149 HWTEST_F(JsRuntimeTest, InitLoop_0100, TestSize.Level1)
1150 {
1151     TAG_LOGI(AAFwkTag::TEST, "InitLoop_0100 start");
1152 
1153     auto jsRuntime = std::make_unique<AbilityRuntime::JsRuntime>();
1154 
1155     auto result = jsRuntime->InitLoop();
1156     EXPECT_EQ(result, false);
1157     jsRuntime.reset();
1158     TAG_LOGI(AAFwkTag::TEST, "InitLoop_0100 end");
1159 }
1160 
1161 /**
1162  * @tc.name: InitSourceMap_0100
1163  * @tc.desc: JsRuntime test for InitSourceMap.
1164  * @tc.type: FUNC
1165  */
1166 HWTEST_F(JsRuntimeTest, InitSourceMap_0100, TestSize.Level1)
1167 {
1168     TAG_LOGI(AAFwkTag::TEST, "InitSourceMap_0100 start");
1169 
1170     auto jsRuntime = std::make_unique<AbilityRuntime::JsRuntime>();
1171     auto operatorObj = std::make_shared<JsEnv::SourceMapOperator>("");
1172     jsRuntime->InitSourceMap(operatorObj);
1173     ASSERT_NE(jsRuntime, nullptr);
1174     jsRuntime.reset();
1175     TAG_LOGI(AAFwkTag::TEST, "InitSourceMap_0100 end");
1176 }
1177 
1178 HWTEST_F(JsRuntimeTest, InitSourceMap_0200, TestSize.Level1)
1179 {
1180     TAG_LOGI(AAFwkTag::TEST, "InitSourceMap_0200 start");
1181 
1182     auto mapObj = std::make_shared<JsEnv::SourceMap>();
1183     bool hasFile = false;
1184     mapObj->Init(hasFile, TEST_HAP_PATH);
1185     EXPECT_FALSE(hasFile);
1186     TAG_LOGI(AAFwkTag::TEST, "InitSourceMap_0200 end");
1187 }
1188 
1189 /**
1190  * @tc.name: Deinitialize_0100
1191  * @tc.desc: JsRuntime test for Deinitialize.
1192  * @tc.type: FUNC
1193  */
1194 HWTEST_F(JsRuntimeTest, Deinitialize_0100, TestSize.Level2)
1195 {
1196     TAG_LOGI(AAFwkTag::TEST, "Deinitialize_0100 start");
1197 
1198     auto jsRuntime = std::make_unique<AbilityRuntime::JsRuntime>();
1199 
1200     jsRuntime->Deinitialize();
1201     ASSERT_NE(jsRuntime, nullptr);
1202     jsRuntime.reset();
1203     TAG_LOGI(AAFwkTag::TEST, "Deinitialize_0100 end");
1204 }
1205 
1206 /**
1207  * @tc.name: GetPkgContextInfoListMap_0100
1208  * @tc.desc: JsRuntime test for GetPkgContextInfoListMap.
1209  * @tc.type: FUNC
1210  */
1211 HWTEST_F(JsRuntimeTest, GetPkgContextInfoListMap_0100, TestSize.Level2)
1212 {
1213     TAG_LOGI(AAFwkTag::TEST, "GetPkgContextInfoListMap_0100 start");
1214 
1215     std::map<std::string, std::string> modulePkgContentMap;
1216     std::string pkgContentJsonString = R"({"library": {"packageName": "library", "bundleName": "com.xxx.xxxx",
1217         "moduleName": "library", "version": "1.0.0", "entryPath": "", "isSO": false}})";
1218     modulePkgContentMap["entry"] = pkgContentJsonString;
1219 
1220     AbilityRuntime::Runtime::Options options;
1221     options.preload = true;
1222     auto jsRuntime = AbilityRuntime::JsRuntime::Create(options);
1223     std::map<std::string, std::vector<std::vector<std::string>>> ret;
1224     std::map<std::string, std::string> pkgAliasMap;
1225     JsRuntimeLite::GetInstance().GetPkgContextInfoListMap(modulePkgContentMap, ret, pkgAliasMap);
1226     std::string expectString = "library:packageName:library:bundleName:";
1227     expectString += "com.xxx.xxxx:moduleName:library:version:1.0.0:entryPath::isSO:false:";
1228     auto it = ret.find("entry");
1229     ASSERT_EQ(it, ret.end());
1230     jsRuntime.reset();
1231     TAG_LOGI(AAFwkTag::TEST, "GetPkgContextInfoListMap_0100 end");
1232 }
1233 
1234 /**
1235  * @tc.name: GetPkgContextInfoListMap_0200
1236  * @tc.desc: JsRuntime test for GetPkgContextInfoListMap.
1237  * @tc.type: FUNC
1238  */
1239 HWTEST_F(JsRuntimeTest, GetPkgContextInfoListMap_0200, TestSize.Level2)
1240 {
1241     TAG_LOGI(AAFwkTag::TEST, "GetPkgContextInfoListMap_0200 start");
1242 
1243     std::map<std::string, std::string> modulePkgContentMap;
1244     std::string pkgContentJsonString = R"({"library": {"packageName": "library", "bundleName":
1245         "com.xxx.xxxx", "moduleName": "library", "version": "1.0.0", "entryPath": "", "isSO": false}})";
1246     modulePkgContentMap["entry"] = pkgContentJsonString;
1247 
1248     std::string libraryString = R"({"library": {"packageName": "library","bundleName": "com.xxx.xxxx", "moduleName":
1249         "library", "version": "1.0.0", "entryPath": "", "isSO": false}})";
1250     modulePkgContentMap["library"] = libraryString;
1251 
1252     AbilityRuntime::Runtime::Options options;
1253     options.preload = true;
1254     auto jsRuntime = AbilityRuntime::JsRuntime::Create(options);
1255     std::map<std::string, std::vector<std::vector<std::string>>> ret;
1256     std::map<std::string, std::string> pkgAliasMap;
1257     JsRuntimeLite::GetInstance().GetPkgContextInfoListMap(modulePkgContentMap, ret, pkgAliasMap);
1258     std::string expectString = "library:packageName:library:bundleName:";
1259     expectString += "com.xxx.xxxx:moduleName:library:version:1.0.0:entryPath::isSO:false:";
1260     auto it = ret.find("entry");
1261     ASSERT_EQ(it, ret.end());
1262     auto libraryIt = ret.find("library");
1263     ASSERT_EQ(libraryIt, ret.end());
1264     jsRuntime.reset();
1265     TAG_LOGI(AAFwkTag::TEST, "GetPkgContextInfoListMap_0200 end");
1266 }
1267 
1268 /**
1269  * @tc.name: CreateJsEnv_0100
1270  * @tc.desc: JsRuntime test for CreateJsEnv.
1271  * @tc.type: FUNC
1272  * @tc.require: issueI9CHSB
1273  */
1274 HWTEST_F(JsRuntimeTest, CreateJsEnv_0100, TestSize.Level1)
1275 {
1276     TAG_LOGI(AAFwkTag::TEST, "CreateJsEnv_0100 start");
1277     auto jsRuntime = std::make_unique<JsRuntime>();
1278     auto ret = jsRuntime->CreateJsEnv(options_);
1279     EXPECT_EQ(ret, true);
1280     jsRuntime.reset();
1281     TAG_LOGI(AAFwkTag::TEST, "CreateJsEnv_0100 start");
1282 }
1283 
1284 /**
1285  * @tc.name: DumpCpuProfile_0100
1286  * @tc.desc: JsRuntime test for DumpCpuProfile.
1287  * @tc.type: FUNC
1288  */
1289 HWTEST_F(JsRuntimeTest, DumpCpuProfile_0100, TestSize.Level1)
1290 {
1291     TAG_LOGI(AAFwkTag::TEST, "DumpCpuProfile_0100 start");
1292     auto jsRuntime = std::make_unique<JsRuntime>();
1293     bool isPrivate = true;
1294     jsRuntime->DumpCpuProfile();
1295     EXPECT_TRUE(jsRuntime != nullptr);
1296     TAG_LOGI(AAFwkTag::TEST, "DumpCpuProfile_0100 end");
1297 }
1298 
1299 /**
1300  * @tc.name: DumpHeapSnapshot_0100
1301  * @tc.desc: JsRuntime test for DumpHeapSnapshot.
1302  * @tc.type: FUNC
1303  */
1304 HWTEST_F(JsRuntimeTest, DumpHeapSnapshot_0100, TestSize.Level1)
1305 {
1306     TAG_LOGI(AAFwkTag::TEST, "DumpHeapSnapshot_0100 start");
1307     auto jsRuntime = std::make_unique<JsRuntime>();
1308     bool isPrivate = true;
1309     jsRuntime->DumpHeapSnapshot(isPrivate);
1310     EXPECT_TRUE(jsRuntime != nullptr);
1311     TAG_LOGI(AAFwkTag::TEST, "DumpHeapSnapshot end");
1312 }
1313 
1314 /**
1315  * @tc.name: DumpHeapSnapshot_0200
1316  * @tc.desc: JsRuntime test for DumpHeapSnapshot.
1317  * @tc.type: FUNC
1318  */
1319 HWTEST_F(JsRuntimeTest, DumpHeapSnapshot_0200, TestSize.Level1)
1320 {
1321     TAG_LOGI(AAFwkTag::TEST, "DumpHeapSnapshot_0100 start");
1322     auto jsRuntime = std::make_unique<JsRuntime>();
1323     uint32_t tid = 1;
1324     bool isFullGC = true;
1325     jsRuntime->DumpHeapSnapshot(tid, isFullGC);
1326     EXPECT_TRUE(jsRuntime != nullptr);
1327     TAG_LOGI(AAFwkTag::TEST, "DumpHeapSnapshot end");
1328 }
1329 
1330 /**
1331  * @tc.name: AllowCrossThreadExecution_0200
1332  * @tc.desc: JsRuntime test for AllowCrossThreadExecution.
1333  * @tc.type: FUNC
1334  */
1335 HWTEST_F(JsRuntimeTest, AllowCrossThreadExecution_0200, TestSize.Level1)
1336 {
1337     TAG_LOGI(AAFwkTag::TEST, "AllowCrossThreadExecution_0200 start");
1338     auto jsRuntime = std::make_unique<JsRuntime>();
1339     jsRuntime->AllowCrossThreadExecution();
1340     EXPECT_TRUE(jsRuntime != nullptr);
1341     TAG_LOGI(AAFwkTag::TEST, "AllowCrossThreadExecution_0200 end");
1342 }
1343 
1344 /**
1345  * @tc.name: GetHeapPrepare_0200
1346  * @tc.desc: JsRuntime test for GetHeapPrepare.
1347  * @tc.type: FUNC
1348  */
1349 HWTEST_F(JsRuntimeTest, GetHeapPrepare_0200, TestSize.Level1)
1350 {
1351     TAG_LOGI(AAFwkTag::TEST, "GetHeapPrepare_0200 start");
1352     auto jsRuntime = std::make_unique<JsRuntime>();
1353     jsRuntime->GetHeapPrepare();
1354     EXPECT_TRUE(jsRuntime != nullptr);
1355     TAG_LOGI(AAFwkTag::TEST, "GetHeapPrepare_0200 end");
1356 }
1357 
1358 /**
1359  * @tc.name: RegisterQuickFixQueryFunc_0200
1360  * @tc.desc: JsRuntime test for RegisterQuickFixQueryFunc.
1361  * @tc.type: FUNC
1362  */
1363 HWTEST_F(JsRuntimeTest, RegisterQuickFixQueryFunc_0200, TestSize.Level1)
1364 {
1365     TAG_LOGI(AAFwkTag::TEST, "RegisterQuickFixQueryFunc_0200 start");
1366     auto jsRuntime = std::make_unique<JsRuntime>();
1367     std::map<std::string, std::string> moduleAndPath;
1368     jsRuntime->RegisterQuickFixQueryFunc(moduleAndPath);
1369     EXPECT_TRUE(jsRuntime != nullptr);
1370     TAG_LOGI(AAFwkTag::TEST, "RegisterQuickFixQueryFunc_0200 end");
1371 }
1372 
1373 /**
1374  * @tc.name: UpdatePkgContextInfoJson_0100
1375  * @tc.desc: JsRuntime test for UpdatePkgContextInfoJson.
1376  * @tc.type: FUNC
1377  */
1378 HWTEST_F(JsRuntimeTest, UpdatePkgContextInfoJson_0100, TestSize.Level1)
1379 {
1380     TAG_LOGI(AAFwkTag::TEST, "UpdatePkgContextInfoJson_0100 start");
1381     auto jsRuntime = std::make_unique<JsRuntime>();
1382     EXPECT_TRUE(jsRuntime != nullptr);
1383     std::string moduleName = "moduleName";
1384     std::string hapPath = TEST_HAP_PATH;
1385     std::string packageName = "packageName";
1386     jsRuntime->UpdatePkgContextInfoJson(moduleName, hapPath, packageName);
1387     TAG_LOGI(AAFwkTag::TEST, "UpdatePkgContextInfoJson_0100 end");
1388 }
1389 
1390 HWTEST_F(JsRuntimeTest, SetPkgContextInfoJson_0100, TestSize.Level1)
1391 {
1392     TAG_LOGI(AAFwkTag::TEST, "SetPkgContextInfoJson_0100 start");
1393     auto jsRuntime = std::make_unique<JsRuntime>();
1394     EXPECT_TRUE(jsRuntime != nullptr);
1395     std::string moduleName = "moduleName";
1396     std::string hapPath = TEST_HAP_PATH;
1397     std::string packageName = "packageName";
1398     jsRuntime->SetPkgContextInfoJson(moduleName, hapPath, packageName);
1399     EXPECT_FALSE(jsRuntime->pkgContextInfoJsonStringMap_.empty());
1400     TAG_LOGI(AAFwkTag::TEST, "SetPkgContextInfoJson_0100 end");
1401 }
1402 
1403 /**
1404  * @tc.name: JsRuntimePreloadModuleandDoCleanWorkAfterStageCleaned_0100
1405  * @tc.desc: JsRuntime test for JsRuntimePreloadModule and DoCleanWorkAfterStageCleaned.
1406  * @tc.type: FUNC
1407  */
1408 HWTEST_F(JsRuntimeTest, JsRuntimePreloadModuleandDoCleanWorkAfterStageCleaned_0100, TestSize.Level1)
1409 {
1410     TAG_LOGI(AAFwkTag::TEST, "PreloadModule_0100 start");
1411     auto jsRuntime = std::make_unique<JsRuntime>();
1412     EXPECT_TRUE(jsRuntime != nullptr);
1413     jsRuntime->DoCleanWorkAfterStageCleaned();
1414     std::string moduleName = TEST_MODULE_NAME;
1415     std::string srcPath = TEST_LIB_PATH;
1416     std::string hapPath = TEST_HAP_PATH;
1417     bool isEsMode = true;
1418     bool useCommonTrunk = true;
1419     jsRuntime->PreloadModule(moduleName, srcPath, hapPath, isEsMode, useCommonTrunk);
1420     jsRuntime->PreloadModule(moduleName, hapPath, isEsMode, useCommonTrunk);
1421     EXPECT_EQ(jsRuntime->preloadList_.size(), 1);
1422     jsRuntime.reset();
1423     TAG_LOGI(AAFwkTag::TEST, "PreloadModule_0100 end");
1424 }
1425 
1426 /**
1427  * @tc.name: JsRuntimePreloadMainAbility_0100
1428  * @tc.desc: JsRuntime test for JsRuntimePreloadMainAbility.
1429  * @tc.type: FUNC
1430  */
1431 HWTEST_F(JsRuntimeTest, JsRuntimePreloadMainAbility_0100, TestSize.Level1)
1432 {
1433     TAG_LOGI(AAFwkTag::TEST, "PreloadMainAbility_0100 start");
1434     auto jsRuntime = std::make_unique<JsRuntime>();
1435     EXPECT_TRUE(jsRuntime != nullptr);
1436     std::string moduleName = TEST_MODULE_NAME;
1437     std::string srcPath = TEST_MODULE_PATH;
1438     std::string hapPath = TEST_HAP_PATH;
1439     std::string srcEntrance = TEST_LIB_PATH;
1440     bool isEsMode = true;
1441     jsRuntime->PreloadMainAbility(moduleName, srcPath, hapPath, isEsMode, srcEntrance);
1442     EXPECT_EQ(jsRuntime->preloadList_.size(), 1);
1443     jsRuntime.reset();
1444     TAG_LOGI(AAFwkTag::TEST, "PreloadMainAbility_0100 end");
1445 }
1446 
1447 /**
1448  * @tc.name: JsRuntimeSetStopPreloadSoCallback_0100
1449  * @tc.desc: JsRuntime test for JsRuntimeSetStopPreloadSoCallback.
1450  * @tc.type: FUNC
1451  */
1452 HWTEST_F(JsRuntimeTest, JsRuntimeSetStopPreloadSoCallback_0100, TestSize.Level1)
1453 {
1454     TAG_LOGI(AAFwkTag::TEST, "SetStopPreloadSoCallback_0100 start");
__anon9ee3b5ae0602() 1455     auto callBack = []() {};
1456     jsRuntimePtr->SetStopPreloadSoCallback(callBack);
1457     ASSERT_TRUE(jsRuntimePtr != nullptr);
1458     TAG_LOGI(AAFwkTag::TEST, "SetStopPreloadSoCallback_0100 start");
1459 }
1460 
1461 /**
1462  * @tc.name: SetDebugOption_0100
1463  * @tc.desc: JsRuntime test for SetDebugOption.
1464  * @tc.type: FUNC
1465  */
1466 HWTEST_F(JsRuntimeTest, SetDebugOption_0100, TestSize.Level1)
1467 {
1468     TAG_LOGI(AAFwkTag::TEST, "SetDebugOption_0100 start");
1469     Runtime::DebugOption debugOption;
1470     std::string bundleName = "com.ohos.example.bundleName";
1471     debugOption.bundleName = bundleName;
1472     debugOption.processName = "com.ohos.example.bundleName";
1473     auto jsRuntime = std::make_unique<JsRuntime>();
1474     jsRuntime->SetDebugOption(debugOption);
1475     EXPECT_EQ(jsRuntime->debugOption_.bundleName, bundleName);
1476     TAG_LOGI(AAFwkTag::TEST, "SetDebugOption_0100 end");
1477 }
1478 
1479 /**
1480  * @tc.name: StartLocalDebugMode_0100
1481  * @tc.desc: JsRuntime test for StartLocalDebugMode.
1482  * @tc.type: FUNC
1483  */
1484 HWTEST_F(JsRuntimeTest, StartLocalDebugMode_0100, TestSize.Level1)
1485 {
1486     TAG_LOGI(AAFwkTag::TEST, "StartLocalDebugMode_0100 start");
1487     bool isDebugFromLocal = false;
1488     auto jsRuntime = std::make_unique<JsRuntime>();
1489     Runtime::DebugOption debugOption;
1490     jsRuntime->SetDebugOption(debugOption);
1491     jsRuntime->debugOption_.isDeveloperMode = false;
1492     jsRuntime->StartLocalDebugMode(isDebugFromLocal);
1493     EXPECT_EQ(jsRuntime->debugOption_.isDebugFromLocal, false);
1494 
1495     isDebugFromLocal = true;
1496     jsRuntime->StartLocalDebugMode(isDebugFromLocal);
1497     EXPECT_EQ(jsRuntime->debugOption_.isDebugFromLocal, true);
1498     TAG_LOGI(AAFwkTag::TEST, "StartLocalDebugMode_0100 end");
1499 }
1500 
1501 /**
1502  * @tc.name: StartProfiler_0100
1503  * @tc.desc: JsRuntime test for StartProfiler.
1504  * @tc.type: FUNC
1505  */
1506 HWTEST_F(JsRuntimeTest, StartProfiler_0100, TestSize.Level1)
1507 {
1508     TAG_LOGI(AAFwkTag::TEST, "StartProfiler_0100 start");
1509     Runtime::DebugOption debugOption;
1510     debugOption.isDebugFromLocal = true;
1511     debugOption.isDeveloperMode = true;
1512     auto jsRuntime = std::make_unique<JsRuntime>();
1513     EXPECT_NE(jsRuntime, nullptr);
1514     jsRuntime->StartProfiler(debugOption);
1515     EXPECT_EQ(jsRuntime->jsEnv_, nullptr);
1516     TAG_LOGI(AAFwkTag::TEST, "StartProfiler_0100 end");
1517 }
1518 
1519 /**
1520  * @tc.name: LoadScript_0200
1521  * @tc.desc: LoadScript
1522  * @tc.type: FUNC
1523  */
1524 HWTEST_F(JsRuntimeTest, LoadScript_0200, TestSize.Level1)
1525 {
1526     TAG_LOGI(AAFwkTag::TEST, "LoadScript_0200 start");
1527 
1528     auto jsRuntime = std::make_unique<JsRuntime>();
1529     jsRuntime->jsEnv_ = std::make_shared<JsEnv::JsEnvironment>();
1530     jsRuntime->jsEnv_->engine_ = nullptr;
1531 
1532     auto ret = jsRuntime->LoadScript("MyPath", nullptr, false);
1533     EXPECT_EQ(ret, false);
1534 
1535     jsRuntime.reset();
1536     std::this_thread::sleep_for(std::chrono::milliseconds(200));
1537     TAG_LOGI(AAFwkTag::TEST, "LoadScript_0200 end");
1538 }
1539 
1540 /**
1541  * @tc.name: LoadScript_0300
1542  * @tc.desc: LoadScript
1543  * @tc.type: FUNC
1544  */
1545 HWTEST_F(JsRuntimeTest, LoadScript_0300, TestSize.Level1)
1546 {
1547     TAG_LOGI(AAFwkTag::TEST, "LoadScript_0300 start");
1548 
1549     auto jsRuntime = std::make_unique<JsRuntime>();
1550     jsRuntime->jsEnv_ = nullptr;
1551 
1552     auto ret = jsRuntime->LoadScript("MyPath", nullptr, 0, false, "");
1553     EXPECT_EQ(ret, false);
1554 
1555     jsRuntime.reset();
1556     std::this_thread::sleep_for(std::chrono::milliseconds(200));
1557     TAG_LOGI(AAFwkTag::TEST, "LoadScript_0300 end");
1558 }
1559 
1560 /**
1561  * @tc.name: LoadScript_0400
1562  * @tc.desc: LoadScript
1563  * @tc.type: FUNC
1564  */
1565 HWTEST_F(JsRuntimeTest, LoadScript_0400, TestSize.Level1)
1566 {
1567     TAG_LOGI(AAFwkTag::TEST, "LoadScript_0400 start");
1568 
1569     auto jsRuntime = std::make_unique<JsRuntime>();
1570     jsRuntime->jsEnv_ = std::make_shared<JsEnv::JsEnvironment>();
1571     jsRuntime->isOhmUrl_ = true;
1572     jsRuntime->moduleName_ = "moduleName";
1573 
1574     auto ret = jsRuntime->LoadScript("MyPath", nullptr, 0, false, "");
1575     EXPECT_EQ(ret, false);
1576 
1577     jsRuntime.reset();
1578     std::this_thread::sleep_for(std::chrono::milliseconds(200));
1579     TAG_LOGI(AAFwkTag::TEST, "LoadScript_0400 end");
1580 }
1581 
1582 /**
1583  * @tc.name: LoadScript_0500
1584  * @tc.desc: LoadScript
1585  * @tc.type: FUNC
1586  */
1587 HWTEST_F(JsRuntimeTest, LoadScript_0500, TestSize.Level1)
1588 {
1589     TAG_LOGI(AAFwkTag::TEST, "LoadScript_0500 start");
1590 
1591     auto jsRuntime = std::make_unique<JsRuntime>();
1592     jsRuntime->jsEnv_ = std::make_shared<JsEnv::JsEnvironment>();
1593     jsRuntime->isOhmUrl_ = false;
1594     jsRuntime->moduleName_ = "moduleName";
1595 
1596     auto ret = jsRuntime->LoadScript("MyPath", nullptr, 0, false, "");
1597     EXPECT_EQ(ret, false);
1598 
1599     jsRuntime.reset();
1600     std::this_thread::sleep_for(std::chrono::milliseconds(200));
1601     TAG_LOGI(AAFwkTag::TEST, "LoadScript_0500 end");
1602 }
1603 
1604 /**
1605  * @tc.name: LoadSystemModuleByEngine_0200
1606  * @tc.desc: LoadSystemModuleByEngine
1607  * @tc.type: FUNC
1608  */
1609 HWTEST_F(JsRuntimeTest, LoadSystemModuleByEngine_0200, TestSize.Level1)
1610 {
1611     TAG_LOGI(AAFwkTag::TEST, "LoadSystemModuleByEngine_0200 start");
1612 
1613     auto jsRuntime = std::make_unique<JsRuntime>();
1614     jsRuntime->jsEnv_ = std::make_shared<JsEnv::JsEnvironment>();
1615     napi_env env = {};
1616     jsRuntime->jsEnv_->engine_ = reinterpret_cast<NativeEngine*>(env);
1617 
1618     auto ret = jsRuntime->LoadSystemModuleByEngine(env, "", nullptr, 0);
1619     EXPECT_EQ(ret, nullptr);
1620 
1621     jsRuntime.reset();
1622     std::this_thread::sleep_for(std::chrono::milliseconds(200));
1623     TAG_LOGI(AAFwkTag::TEST, "LoadSystemModuleByEngine_0200 end");
1624 }
1625 
1626 /**
1627  * @tc.name: Deinitialize_0200
1628  * @tc.desc: Deinitialize
1629  * @tc.type: FUNC
1630  */
1631 HWTEST_F(JsRuntimeTest, Deinitialize_0200, TestSize.Level1)
1632 {
1633     TAG_LOGI(AAFwkTag::TEST, "Deinitialize_0200 start");
1634 
1635     auto jsRuntime = std::make_unique<AbilityRuntime::JsRuntime>();
1636     std::string moduleName = "PreloadSystemModuleTest";
1637     napi_value object = nullptr;
1638     std::unique_ptr<NativeReference> nativeRef = jsRuntime->LoadSystemModule(moduleName, &object, 0);
1639     jsRuntime->modules_.emplace("moduleName", nativeRef.get());
1640     jsRuntime->jsEnv_ = nullptr;
1641 
1642     jsRuntime->Deinitialize();
1643     EXPECT_EQ(jsRuntime->modules_.size(), 0);
1644 
1645     jsRuntime.reset();
1646     std::this_thread::sleep_for(std::chrono::milliseconds(200));
1647     TAG_LOGI(AAFwkTag::TEST, "Deinitialize_0200 end");
1648 }
1649 
1650 /**
1651  * @tc.name: RunScript_0200
1652  * @tc.desc: RunScript
1653  * @tc.type: FUNC
1654  */
1655 HWTEST_F(JsRuntimeTest, RunScript_0200, TestSize.Level1)
1656 {
1657     TAG_LOGI(AAFwkTag::TEST, "RunScript_0200 start");
1658 
1659     auto jsRuntime = std::make_unique<JsRuntime>();
1660     jsRuntime->jsEnv_ = std::make_shared<JsEnv::JsEnvironment>();
1661     panda::RuntimeOption pandaOption;
1662     jsRuntime->jsEnv_->vm_ = panda::JSNApi::CreateJSVM(pandaOption);
1663 
1664     auto ret = jsRuntime->RunScript("", "", false);
1665     EXPECT_EQ(ret, false);
1666 
1667     jsRuntime.reset();
1668     std::this_thread::sleep_for(std::chrono::milliseconds(200));
1669     TAG_LOGI(AAFwkTag::TEST, "RunScript_0200 end");
1670 }
1671 
1672 /**
1673  * @tc.name: RunScript_0300
1674  * @tc.desc: RunScript
1675  * @tc.type: FUNC
1676  */
1677 HWTEST_F(JsRuntimeTest, RunScript_0300, TestSize.Level1)
1678 {
1679     TAG_LOGI(AAFwkTag::TEST, "RunScript_0300 start");
1680 
1681     auto jsRuntime = std::make_unique<JsRuntime>();
1682     jsRuntime->jsEnv_ = std::make_shared<JsEnv::JsEnvironment>();
1683     panda::RuntimeOption pandaOption;
1684     jsRuntime->jsEnv_->vm_ = panda::JSNApi::CreateJSVM(pandaOption);
1685 
1686     auto ret = jsRuntime->RunScript("MockPath", "", true);
1687     EXPECT_EQ(ret, false);
1688 
1689     jsRuntime.reset();
1690     std::this_thread::sleep_for(std::chrono::milliseconds(200));
1691     TAG_LOGI(AAFwkTag::TEST, "RunScript_0300 end");
1692 }
1693 
1694 /**
1695  * @tc.name: RunSandboxScript_0300
1696  * @tc.desc: RunSandboxScript
1697  * @tc.type: FUNC
1698  */
1699 HWTEST_F(JsRuntimeTest, RunSandboxScript_0300, TestSize.Level1)
1700 {
1701     TAG_LOGI(AAFwkTag::TEST, "RunSandboxScript_0300 start");
1702 
1703     auto jsRuntime = std::make_unique<JsRuntime>();
1704     std::string bundleName(PATH_MAX, 'a');
1705     const std::string& codePath = bundleName;
1706     const std::string& modulePath = "";
1707     std::string fileName = "";
1708     jsRuntime->codePath_ = codePath;
1709 
1710     auto ret = jsRuntime->RunSandboxScript(modulePath, fileName);
1711     EXPECT_EQ(ret, false);
1712 
1713     jsRuntime.reset();
1714     std::this_thread::sleep_for(std::chrono::milliseconds(200));
1715     TAG_LOGI(AAFwkTag::TEST, "RunSandboxScript_0300 end");
1716 }
1717 
1718 /**
1719  * @tc.name: RunSandboxScript_0300
1720  * @tc.desc: RunSandboxScript
1721  * @tc.type: FUNC
1722  */
1723 HWTEST_F(JsRuntimeTest, RunSandboxScript_0400, TestSize.Level1)
1724 {
1725     TAG_LOGI(AAFwkTag::TEST, "RunSandboxScript_0400 start");
1726 
1727     auto jsRuntime = std::make_unique<JsRuntime>();
1728     std::string bundleName(PATH_MAX, 'a');
1729     const std::string& codePath = bundleName;
1730     const std::string& modulePath = "";
1731     std::string fileName = "HelloWorld";
1732     jsRuntime->codePath_ = codePath;
1733 
1734     auto ret = jsRuntime->RunSandboxScript(modulePath, fileName);
1735     EXPECT_EQ(ret, false);
1736 
1737     jsRuntime.reset();
1738     std::this_thread::sleep_for(std::chrono::milliseconds(200));
1739     TAG_LOGI(AAFwkTag::TEST, "RunSandboxScript_0400 end");
1740 }
1741 
1742 /**
1743  * @tc.name: RemoveTask_0300
1744  * @tc.desc: RemoveTask
1745  * @tc.type: FUNC
1746  */
1747 HWTEST_F(JsRuntimeTest, RemoveTask_0300, TestSize.Level1)
1748 {
1749     TAG_LOGI(AAFwkTag::TEST, "RemoveTask_0300 start");
1750 
1751     auto jsRuntime = std::make_unique<JsRuntime>();
1752     jsRuntime->jsEnv_ = std::make_shared<JsEnv::JsEnvironment>();
1753     std::string taskName = "removeTask003";
1754     bool taskExecuted = false;
__anon9ee3b5ae0702() 1755     auto task = [taskName, &taskExecuted]() {
1756         TAG_LOGI(AAFwkTag::TEST, "%{public}s called.", taskName.c_str());
1757         taskExecuted = true;
1758     };
1759     int64_t delayTime = 20;
1760     jsRuntime->PostTask(task, taskName, delayTime);
1761     jsRuntime->RemoveTask(taskName);
1762     std::this_thread::sleep_for(std::chrono::milliseconds(1000));
1763     EXPECT_EQ(taskExecuted, false);
1764 
1765     jsRuntime.reset();
1766     std::this_thread::sleep_for(std::chrono::milliseconds(200));
1767     TAG_LOGI(AAFwkTag::TEST, "RemoveTask_0300 end");
1768 }
1769 
1770 /**
1771  * @tc.name: SuspendVM_0200
1772  * @tc.desc: SuspendVM
1773  * @tc.type: FUNC
1774  */
1775 HWTEST_F(JsRuntimeTest, SuspendVM_0200, TestSize.Level1)
1776 {
1777     TAG_LOGI(AAFwkTag::TEST, "SuspendVM_0200 start");
1778 
1779     auto jsRuntime = std::make_unique<JsRuntime>();
1780     jsRuntime->jsEnv_ = std::make_shared<JsEnv::JsEnvironment>();
1781     napi_env env = {};
1782     jsRuntime->jsEnv_->engine_ = reinterpret_cast<NativeEngine*>(env);
1783     auto ret = jsRuntime->SuspendVM(3);
1784     EXPECT_EQ(ret, false);
1785 
1786     jsRuntime.reset();
1787     std::this_thread::sleep_for(std::chrono::milliseconds(200));
1788     TAG_LOGI(AAFwkTag::TEST, "SuspendVM_0200 end");
1789 }
1790 
1791 /**
1792  * @tc.name: PopPreloadObj_0100
1793  * @tc.desc: PopPreloadObj
1794  * @tc.type: FUNC
1795  */
1796 HWTEST_F(JsRuntimeTest, PopPreloadObj_0100, TestSize.Level1)
1797 {
1798     TAG_LOGI(AAFwkTag::TEST, "PopPreloadObj_0100 start");
1799 
1800     auto jsRuntime = std::make_unique<JsRuntime>();
1801     napi_ref ref = nullptr;
1802     napi_value value = {};
1803     napi_env env_ = {};
1804     napi_create_reference(env_, value, 1, &ref);
1805     auto navRef = std::unique_ptr<NativeReference>(reinterpret_cast<NativeReference *>(ref));
1806     std::map<std::string, std::unique_ptr<NativeReference>> preloadObjMap;
1807     preloadObjMap.emplace("PreloadObj", nullptr);
1808     preloadObjMap.emplace("PreloadObj1", std::move(navRef));
1809     jsRuntime->preloadList_ = std::move(preloadObjMap);
1810 
1811     std::unique_ptr<NativeReference> obj = nullptr;
1812     auto ret = jsRuntime->PopPreloadObj("PreloadObj", obj);
1813     EXPECT_EQ(ret, false);
1814     EXPECT_EQ(obj, nullptr);
1815     EXPECT_EQ(jsRuntime->preloadList_.size(), 1);
1816 
1817     jsRuntime.reset();
1818     std::this_thread::sleep_for(std::chrono::milliseconds(200));
1819     TAG_LOGI(AAFwkTag::TEST, "PopPreloadObj_0100 end");
1820 }
1821 
1822 /**
1823  * @tc.name: UpdateModuleNameAndAssetPath_0400
1824  * @tc.desc: UpdateModuleNameAndAssetPath
1825  * @tc.type: FUNC
1826  */
1827 HWTEST_F(JsRuntimeTest, UpdateModuleNameAndAssetPath_0400, TestSize.Level1)
1828 {
1829     TAG_LOGI(AAFwkTag::TEST, "UpdateModuleNameAndAssetPath_0400 start");
1830 
1831     auto jsRuntime = std::make_unique<JsRuntime>();
1832     jsRuntime->jsEnv_ = std::make_shared<JsEnv::JsEnvironment>();
1833     jsRuntime->isBundle_ = false;
1834     panda::RuntimeOption pandaOption;
1835     jsRuntime->jsEnv_->vm_ = panda::JSNApi::CreateJSVM(pandaOption);
1836     jsRuntime->moduleName_ = "";
1837 
1838     jsRuntime->UpdateModuleNameAndAssetPath("moduleName");
1839     EXPECT_EQ(jsRuntime->moduleName_, "moduleName");
1840 
1841     jsRuntime.reset();
1842     std::this_thread::sleep_for(std::chrono::milliseconds(200));
1843     TAG_LOGI(AAFwkTag::TEST, "UpdateModuleNameAndAssetPath_0400 end");
1844 }
1845 
1846 /**
1847  * @tc.name: ExecuteSecureWithOhmUrl_0100
1848  * @tc.desc: basic function test of ExecuteSecureWithOhmUrl and GetExportObjectFromOhmUrl.
1849  * @tc.type: FUNC
1850  * @tc.require: issueIC77WI
1851  */
1852 HWTEST_F(JsRuntimeTest, ExecuteSecureWithOhmUrl_0100, TestSize.Level1)
1853 {
1854     TAG_LOGI(AAFwkTag::TEST, "ExecuteSecureWithOhmUrl_0100 start");
1855 
1856     auto jsRuntime = std::make_unique<JsRuntime>();
1857     jsRuntime->jsEnv_ = std::make_shared<JsEnv::JsEnvironment>();
1858     jsRuntime->isBundle_ = false;
1859     panda::RuntimeOption pandaOption;
1860     jsRuntime->jsEnv_->vm_ = panda::JSNApi::CreateJSVM(pandaOption);
1861     jsRuntime->moduleName_ = "";
1862 
1863     std::string moduleName = "moduleName";
1864     std::string hapPath = "hapPath";
1865     std::string srcEntrance = "srcEntrance";
1866     auto ret = jsRuntime->ExecuteSecureWithOhmUrl(moduleName, hapPath, srcEntrance);
1867     EXPECT_EQ(ret, false);
1868 
1869     std::string key = "key";
1870     auto retVal = jsRuntime->GetExportObjectFromOhmUrl(srcEntrance, key);
1871     EXPECT_EQ(retVal, nullptr);
1872 
1873     jsRuntime.reset();
1874     std::this_thread::sleep_for(std::chrono::milliseconds(200));
1875     TAG_LOGI(AAFwkTag::TEST, "ExecuteSecureWithOhmUrl_0100 end");
1876 }
1877 
1878 /**
1879  * @tc.name: RegisterUncatchableExceptionHandler_0100
1880  * @tc.desc: JsRuntime test for RegisterUncatchableExceptionHandler.
1881  * @tc.type: FUNC
1882  * @tc.require:
1883  */
1884 HWTEST_F(JsRuntimeTest, RegisterUncatchableExceptionHandler_0100, TestSize.Level1)
1885 {
1886     TAG_LOGI(AAFwkTag::TEST, "RegisterUncatchableExceptionHandler_0100 start");
1887     auto jsRuntime = std::make_unique<JsRuntime>();
1888     EXPECT_NE(jsRuntime, nullptr);
1889     auto ret = jsRuntime->CreateJsEnv(options_);
1890     jsRuntime->RegisterUncatchableExceptionHandler(nullptr);
1891     EXPECT_NE(jsRuntime, nullptr);
1892     TAG_LOGI(AAFwkTag::TEST, "RegisterUncatchableExceptionHandler_0100 end");
1893 }
1894 } // namespace AbilityRuntime
1895 } // namespace OHOS