• 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.Level0)
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.Level0)
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.Level0)
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.Level0)
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.Level0)
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.Level0)
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.Level0)
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.Level0)
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.Level0)
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.Level0)
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.Level0)
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.Level0)
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.Level0)
419 {
420     TAG_LOGI(AAFwkTag::TEST, "SavePreloaded start");
421 
422     Runtime::SavePreloaded(nullptr);
423     auto result = Runtime::GetPreloaded();
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.Level0)
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.Level0)
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.Level0)
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.Level0)
489 {
490     TAG_LOGI(AAFwkTag::TEST, "SetDeviceDisconnectCallback start");
491 
492     auto jsRuntime = std::make_unique<AbilityRuntime::JsRuntime>();
__anon250aa48c0202() 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.Level0)
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.Level0)
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.Level0)
548 {
549     TAG_LOGI(AAFwkTag::TEST, "StartDebugMode 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     jsRuntime->StartDebugMode(debugOption);
558     EXPECT_TRUE(jsRuntime != nullptr);
559 
560     jsRuntime.reset();
561     std::this_thread::sleep_for(std::chrono::milliseconds(200));
562     TAG_LOGI(AAFwkTag::TEST, "StartDebugMode end");
563 }
564 
565 /**
566  * @tc.name: JsRuntimeStopDebugModeTest_0100
567  * @tc.desc: JsRuntime test for StopDebugMode.
568  * @tc.type: FUNC
569  */
570 HWTEST_F(JsRuntimeTest, JsRuntimeStopDebugModeTest_0100, TestSize.Level0)
571 {
572     TAG_LOGI(AAFwkTag::TEST, "StopDebugMode start");
573 
574     auto jsRuntime = std::make_unique<JsRuntime>();
575 
576     jsRuntime->StopDebugMode();
577     EXPECT_TRUE(jsRuntime != nullptr);
578 
579     jsRuntime.reset();
580     std::this_thread::sleep_for(std::chrono::milliseconds(200));
581     TAG_LOGI(AAFwkTag::TEST, "StopDebugMode end");
582 }
583 
584 /**
585  * @tc.name: JsRuntimeInitConsoleModuleTest_0100
586  * @tc.desc: JsRuntime test for InitConsoleModule.
587  * @tc.type: FUNC
588  */
589 HWTEST_F(JsRuntimeTest, JsRuntimeInitConsoleModuleTest_0100, TestSize.Level0)
590 {
591     TAG_LOGI(AAFwkTag::TEST, "InitConsoleModule start");
592 
593     auto jsRuntime = std::make_unique<JsRuntime>();
594 
595     jsRuntime->InitConsoleModule();
596     EXPECT_TRUE(jsRuntime != nullptr);
597 
598     jsRuntime.reset();
599     std::this_thread::sleep_for(std::chrono::milliseconds(200));
600     TAG_LOGI(AAFwkTag::TEST, "InitConsoleModule end");
601 }
602 
603 /**
604  * @tc.name: JsRuntimeLoadRepairPatchTest_0100
605  * @tc.desc: JsRuntime test for LoadRepairPatch.
606  * @tc.type: FUNC
607  */
608 HWTEST_F(JsRuntimeTest, JsRuntimeLoadRepairPatchTest_0100, TestSize.Level0)
609 {
610     TAG_LOGI(AAFwkTag::TEST, "LoadRepairPatch start");
611 
612     auto jsRuntime = std::make_unique<JsRuntime>();
613     EXPECT_TRUE(jsRuntime != nullptr);
614 
615     std::string hqfFile = "<hqfFile>";
616     std::string hapPath = "<hapPath>";
617     bool lrp = jsRuntime->LoadRepairPatch(hqfFile, hapPath);
618     EXPECT_EQ(lrp, false);
619 
620     jsRuntime.reset();
621     std::this_thread::sleep_for(std::chrono::milliseconds(200));
622     TAG_LOGI(AAFwkTag::TEST, "LoadRepairPatch end");
623 }
624 
625 /**
626  * @tc.name: JsRuntimeUnLoadRepairPatchTest_0100
627  * @tc.desc: JsRuntime test for UnLoadRepairPatch.
628  * @tc.type: FUNC
629  */
630 HWTEST_F(JsRuntimeTest, JsRuntimeUnLoadRepairPatchTest_0100, TestSize.Level0)
631 {
632     TAG_LOGI(AAFwkTag::TEST, "UnLoadRepairPatch start");
633 
634     auto jsRuntime = std::make_unique<JsRuntime>();
635     EXPECT_TRUE(jsRuntime != nullptr);
636 
637     std::string hqfFile = "<hqfFile>";
638     bool lrp = jsRuntime->UnLoadRepairPatch(hqfFile);
639     EXPECT_EQ(lrp, false);
640 
641     jsRuntime.reset();
642     std::this_thread::sleep_for(std::chrono::milliseconds(200));
643     TAG_LOGI(AAFwkTag::TEST, "UnLoadRepairPatch end");
644 }
645 
646 /**
647  * @tc.name: JsRuntimeNotifyHotReloadPageTest_0100
648  * @tc.desc: JsRuntime test for NotifyHotReloadPage.
649  * @tc.type: FUNC
650  */
651 HWTEST_F(JsRuntimeTest, JsRuntimeNotifyHotReloadPageTest_0100, TestSize.Level0)
652 {
653     TAG_LOGI(AAFwkTag::TEST, "NotifyHotReloadPage start");
654 
655     auto jsRuntime = std::make_unique<JsRuntime>();
656     EXPECT_TRUE(jsRuntime != nullptr);
657 
658     bool lrp = jsRuntime->NotifyHotReloadPage();
659     EXPECT_EQ(lrp, true);
660 
661     jsRuntime.reset();
662     std::this_thread::sleep_for(std::chrono::milliseconds(200));
663     TAG_LOGI(AAFwkTag::TEST, "NotifyHotReloadPage end");
664 }
665 
666 /**
667  * @tc.name: JsRuntimeUpdateModuleNameAndAssetPathTest_0100
668  * @tc.desc: JsRuntime test for UpdateModuleNameAndAssetPath.
669  * @tc.type: FUNC
670  */
671 HWTEST_F(JsRuntimeTest, JsRuntimeUpdateModuleNameAndAssetPathTest_0100, TestSize.Level0)
672 {
673     TAG_LOGI(AAFwkTag::TEST, "UpdateModuleNameAndAssetPath start");
674 
675     auto jsRuntime = std::make_unique<JsRuntime>();
676     EXPECT_TRUE(jsRuntime != nullptr);
677 
678     std::string moduleName = "moduleName";
679     jsRuntime->UpdateModuleNameAndAssetPath(moduleName);
680 
681     jsRuntime.reset();
682     std::this_thread::sleep_for(std::chrono::milliseconds(200));
683     TAG_LOGI(AAFwkTag::TEST, "UpdateModuleNameAndAssetPath end");
684 }
685 
686 /**
687  * @tc.name: JsRuntimeUpdateModuleNameAndAssetPathTest_0200
688  * @tc.desc: JsRuntime test for UpdateModuleNameAndAssetPath.
689  * @tc.type: FUNC
690  */
691 HWTEST_F(JsRuntimeTest, JsRuntimeUpdateModuleNameAndAssetPathTest_0200, TestSize.Level0)
692 {
693     TAG_LOGI(AAFwkTag::TEST, "JsRuntimeUpdateModuleNameAndAssetPathTest_0200 start");
694 
695     auto jsRuntime = std::make_unique<JsRuntime>();
696     EXPECT_TRUE(jsRuntime != nullptr);
697 
698     jsRuntime->isBundle_ = false;
699     std::string moduleName = "moduleName";
700     jsRuntime->UpdateModuleNameAndAssetPath(moduleName);
701 
702     jsRuntime.reset();
703     std::this_thread::sleep_for(std::chrono::milliseconds(200));
704     TAG_LOGI(AAFwkTag::TEST, "JsRuntimeUpdateModuleNameAndAssetPathTest_0200 end");
705 }
706 
707 /**
708  * @tc.name: JsRuntimeUpdateModuleNameAndAssetPathTest_0300
709  * @tc.desc: JsRuntime test for UpdateModuleNameAndAssetPath.
710  * @tc.type: FUNC
711  */
712 HWTEST_F(JsRuntimeTest, JsRuntimeUpdateModuleNameAndAssetPathTest_0300, TestSize.Level0)
713 {
714     TAG_LOGI(AAFwkTag::TEST, "JsRuntimeUpdateModuleNameAndAssetPathTest_0300 start");
715 
716     auto jsRuntime = std::make_unique<JsRuntime>();
717     EXPECT_TRUE(jsRuntime != nullptr);
718 
719     jsRuntime->isBundle_ = false;
720     std::string moduleName = "";
721     jsRuntime->UpdateModuleNameAndAssetPath(moduleName);
722 
723     jsRuntime.reset();
724     std::this_thread::sleep_for(std::chrono::milliseconds(200));
725     TAG_LOGI(AAFwkTag::TEST, "JsRuntimeUpdateModuleNameAndAssetPathTest_0300 end");
726 }
727 
728 /**
729  * @tc.name: JsRuntimeInitialize_0100
730  * @tc.desc: Initialize js runtime in multi thread.
731  * @tc.type: FUNC
732  * @tc.require: issueI6KODF
733  */
734 HWTEST_F(JsRuntimeTest, JsRuntimeInitialize_0100, TestSize.Level0)
735 {
736     TAG_LOGI(AAFwkTag::TEST, "Running in multi-thread, using default thread number.");
737 
738     auto jsRuntime = std::make_unique<AbilityRuntime::JsRuntime>();
739     jsRuntime->preloaded_ = true;
740     AbilityRuntime::Runtime::Options options;
741     options.isStageModel = false;
742     options.isTestFramework = false;
743     options.preload = true;
744     bool result = jsRuntime->Initialize(options);
745     EXPECT_EQ(result, true);
746 
747     std::this_thread::sleep_for(std::chrono::milliseconds(200));
748     TAG_LOGI(AAFwkTag::TEST, "Initialize_0100 end");
749 }
750 
751 /**
752  * @tc.name: RegisterQuickFixQueryFunc_0100
753  * @tc.desc: JsRuntime test for RegisterQuickFixQueryFunc.
754  * @tc.type: FUNC
755  */
756 HWTEST_F(JsRuntimeTest, RegisterQuickFixQueryFunc_0100, TestSize.Level0)
757 {
758     TAG_LOGI(AAFwkTag::TEST, "RegisterQuickFixQueryFunc start");
759 
760     auto jsRuntime = std::make_unique<JsRuntime>();
761     EXPECT_TRUE(jsRuntime != nullptr);
762     std::string moudel = "<moudelName>";
763     std::string hqfFile = "<hqfFile>";
764     std::map<std::string, std::string> moduleAndPath;
765     moduleAndPath.insert(std::make_pair(moudel, hqfFile));
766     jsRuntime->RegisterQuickFixQueryFunc(moduleAndPath);
767     jsRuntime.reset();
768     std::this_thread::sleep_for(std::chrono::milliseconds(200));
769     TAG_LOGI(AAFwkTag::TEST, "RegisterQuickFixQueryFunc end");
770 }
771 
772 /**
773  * @tc.name: RegisterUncaughtExceptionHandler_0100
774  * @tc.desc: JsRuntime test for RegisterUncaughtExceptionHandler.
775  * @tc.type: FUNC
776  */
777 HWTEST_F(JsRuntimeTest, RegisterUncaughtExceptionHandler_0100, TestSize.Level0)
778 {
779     TAG_LOGI(AAFwkTag::TEST, "RegisterUncaughtExceptionHandler start");
780 
781     auto jsRuntime = std::make_unique<JsRuntime>();
782     ASSERT_NE(jsRuntime, nullptr);
783     JsEnv::UncaughtExceptionInfo uncaughtExceptionInfo;
784     jsRuntime->RegisterUncaughtExceptionHandler(uncaughtExceptionInfo);
785     jsRuntime.reset();
786     std::this_thread::sleep_for(std::chrono::milliseconds(200));
787     TAG_LOGI(AAFwkTag::TEST, "RegisterUncaughtExceptionHandler end");
788 }
789 
790 /**
791  * @tc.name: ReadSourceMapData_0100
792  * @tc.desc: JsRuntime test for ReadSourceMapData.
793  * @tc.type: FUNC
794  */
795 HWTEST_F(JsRuntimeTest, ReadSourceMapData_0100, TestSize.Level0)
796 {
797     TAG_LOGI(AAFwkTag::TEST, "ReadSourceMapData start");
798 
799     auto jsRuntime = std::make_unique<JsRuntime>();
800     ASSERT_NE(jsRuntime, nullptr);
801     std::string hapPath = "";
802     std::string sourceMapPath = "";
803     std::string content = "";
804     auto result = jsRuntime->ReadSourceMapData(hapPath, sourceMapPath, content);
805     ASSERT_FALSE(result);
806 
807     std::this_thread::sleep_for(std::chrono::milliseconds(200));
808     TAG_LOGI(AAFwkTag::TEST, "ReadSourceMapData end");
809 }
810 
811 /**
812  * @tc.name: StopDebugger_0100
813  * @tc.desc: JsRuntime test for StopDebugger.
814  * @tc.type: FUNC
815  */
816 HWTEST_F(JsRuntimeTest, StopDebugger_0100, TestSize.Level0)
817 {
818     TAG_LOGI(AAFwkTag::TEST, "StopDebugger_0100 start");
819 
820     auto jsRuntime = std::make_unique<JsRuntime>();
821     ASSERT_NE(jsRuntime, nullptr);
822     jsRuntime->StopDebugger();
823     jsRuntime.reset();
824     std::this_thread::sleep_for(std::chrono::milliseconds(200));
825     TAG_LOGI(AAFwkTag::TEST, "StopDebugger_0100 end");
826 }
827 
828 /**
829  * @tc.name: GetFileBuffer_0100
830  * @tc.desc: JsRuntime test for GetFileBuffer.
831  * @tc.type: FUNC
832  */
833 HWTEST_F(JsRuntimeTest, GetFileBuffer_0100, TestSize.Level0)
834 {
835     TAG_LOGI(AAFwkTag::TEST, "GetFileBuffer_0100 start");
836 
837     auto jsRuntime = std::make_unique<JsRuntime>();
838     ASSERT_NE(jsRuntime, nullptr);
839     std::string filePath = "";
840     std::string fileFullName = "";
841     std::vector<uint8_t> buffer;
842     bool result = jsRuntime->GetFileBuffer(filePath, fileFullName, buffer);
843     EXPECT_EQ(result, false);
844     jsRuntime.reset();
845     std::this_thread::sleep_for(std::chrono::milliseconds(200));
846     TAG_LOGI(AAFwkTag::TEST, "GetFileBuffer_0100 end");
847 }
848 
849 /**
850  * @tc.name: JsRuntimeRunScriptTest_0100
851  * @tc.desc: JsRuntime test for RunScript.
852  * @tc.type: FUNC
853  */
854 HWTEST_F(JsRuntimeTest, JsRuntimeRunScriptTest_0100, TestSize.Level0)
855 {
856     TAG_LOGI(AAFwkTag::TEST, "RunScript_0100 start");
857 
858     auto jsRuntime = std::make_unique<AbilityRuntime::JsRuntime>();
859     std::string srcPath = TEST_MODULE_PATH;
860     std::string hapPath = TEST_HAP_PATH;
861     auto result = jsRuntime->RunScript(srcPath, hapPath);
862     EXPECT_EQ(result, false);
863     jsRuntime.reset();
864     std::this_thread::sleep_for(std::chrono::milliseconds(200));
865     TAG_LOGI(AAFwkTag::TEST, "RunScript_0100 end");
866 }
867 
868 /**
869  * @tc.name: JsRuntimeLoadScriptTest_0100
870  * @tc.desc: JsRuntime test for LoadScript.
871  * @tc.type: FUNC
872  */
873 HWTEST_F(JsRuntimeTest, JsRuntimeLoadScriptTest_0100, TestSize.Level0)
874 {
875     TAG_LOGI(AAFwkTag::TEST, "LoadScriptTest_0100 start");
876     auto jsRuntime = std::make_unique<AbilityRuntime::JsRuntime>();
877     std::string path = "/system/etc/strip.native.min.abc";
878     auto result = jsRuntime->LoadScript(path);
879     EXPECT_EQ(result, false);
880     jsRuntime.reset();
881     std::this_thread::sleep_for(std::chrono::milliseconds(200));
882     TAG_LOGI(AAFwkTag::TEST, "LoadScriptTest_0100 end");
883 }
884 
885 /**
886  * @tc.name: JsRuntimeStopDebuggerTest_0100
887  * @tc.desc: JsRuntime test for StopDebugger.
888  * @tc.type: FUNC
889  */
890 HWTEST_F(JsRuntimeTest, JsRuntimeStopDebuggerTest_0100, TestSize.Level0)
891 {
892     TAG_LOGI(AAFwkTag::TEST, "StopDebuggerTest_0100 start");
893     auto jsRuntime = std::make_unique<AbilityRuntime::JsRuntime>();
894     ASSERT_NE(jsRuntime, nullptr);
895 
896     jsRuntime->StopDebugger();
897     jsRuntime.reset();
898     std::this_thread::sleep_for(std::chrono::milliseconds(200));
899     TAG_LOGI(AAFwkTag::TEST, "StopDebuggerTest_0100 end");
900 }
901 
902 /**
903  * @tc.name: PostSyncTask_0100
904  * @tc.desc: Js runtime post sync task.
905  * @tc.type: FUNC
906  * @tc.require: issueI7C87T
907  */
908 HWTEST_F(JsRuntimeTest, PostSyncTask_0100, TestSize.Level0)
909 {
910     TAG_LOGI(AAFwkTag::TEST, "PostSyncTask_0100 start");
911 
912     auto jsRuntime = std::make_unique<AbilityRuntime::JsRuntime>();
913     ASSERT_NE(jsRuntime, nullptr);
914     std::string taskName = "syncTask001";
915     bool taskExecuted = false;
__anon250aa48c0302() 916     auto task = [taskName, &taskExecuted]() {
917         TAG_LOGI(AAFwkTag::TEST, "%{public}s called.", taskName.c_str());
918         taskExecuted = true;
919     };
920     jsRuntime->PostSyncTask(task, taskName);
921     EXPECT_NE(taskExecuted, true);
922     std::this_thread::sleep_for(std::chrono::milliseconds(200));
923     TAG_LOGI(AAFwkTag::TEST, "PostSyncTask_0100 end");
924 }
925 
926 /**
927  * @tc.name: ReInitJsEnvImpl_0100
928  * @tc.desc: Js runtime reinit js env impl.
929  * @tc.type: FUNC
930  * @tc.require: issueI7C87T
931  */
932 HWTEST_F(JsRuntimeTest, ReInitJsEnvImpl_0100, TestSize.Level1)
933 {
934     TAG_LOGI(AAFwkTag::TEST, "ReInitJsEnvImpl_0100 start");
935     auto jsRuntime = std::make_unique<JsRuntime>();
936     EXPECT_TRUE(jsRuntime != nullptr);
937 
938     jsRuntime->ReInitJsEnvImpl(options_);
939     jsRuntime.reset();
940     std::this_thread::sleep_for(std::chrono::milliseconds(200));
941     TAG_LOGI(AAFwkTag::TEST, "ReInitJsEnvImpl_0100 end");
942 }
943 
944 /**
945  * @tc.name: PostTask_0100
946  * @tc.desc: Js runtime post task.
947  * @tc.type: FUNC
948  * @tc.require: issueI7C87T
949  */
950 HWTEST_F(JsRuntimeTest, PostTask_0100, TestSize.Level0)
951 {
952     TAG_LOGI(AAFwkTag::TEST, "PostTask_0100 start");
953 
954     auto jsRuntime = std::make_unique<JsRuntime>();
955     std::string taskName = "postTask001";
956     bool taskExecuted = false;
__anon250aa48c0402() 957     auto task = [taskName, &taskExecuted]() {
958         TAG_LOGI(AAFwkTag::TEST, "%{public}s called.", taskName.c_str());
959         taskExecuted = true;
960     };
961     int64_t delayTime = 10;
962     jsRuntime->PostTask(task, taskName, delayTime);
963     EXPECT_NE(taskExecuted, true);
964     TAG_LOGI(AAFwkTag::TEST, "PostTask_0100 end");
965 }
966 
967 /**
968  * @tc.name: RemoveTask_0100
969  * @tc.desc: Js runtime remove task.
970  * @tc.type: FUNC
971  * @tc.require: issueI7C87T
972  */
973 HWTEST_F(JsRuntimeTest, RemoveTask_0100, TestSize.Level0)
974 {
975     TAG_LOGI(AAFwkTag::TEST, "RemoveTask_0100 start");
976 
977     auto jsRuntime = std::make_unique<JsRuntime>();
978     ASSERT_TRUE(jsRuntime != nullptr);
979 
980     std::string taskName = "removeTask001";
981     bool taskExecuted = false;
__anon250aa48c0502() 982     auto task = [taskName, &taskExecuted]() {
983         TAG_LOGI(AAFwkTag::TEST, "%{public}s called.", taskName.c_str());
984         taskExecuted = true;
985     };
986     int64_t delayTime = 10;
987     jsRuntime->PostTask(task, taskName, delayTime);
988     jsRuntime->RemoveTask(taskName);
989     EXPECT_NE(taskExecuted, true);
990     TAG_LOGI(AAFwkTag::TEST, "RemoveTask_0100 end");
991 }
992 
993 /**
994  * @tc.name: StartDebugger_0100
995  * @tc.desc: JsRuntime test for StartDebugger.
996  * @tc.type: FUNC
997  */
998 HWTEST_F(JsRuntimeTest, StartDebugger_0100, TestSize.Level0)
999 {
1000     TAG_LOGI(AAFwkTag::TEST, "StartDebugger_0100 start");
1001 
1002     auto jsRuntime = std::make_unique<AbilityRuntime::JsRuntime>();
1003     ASSERT_NE(jsRuntime, nullptr);
1004 
1005     bool needBreakPoint = false;
1006     uint32_t instanceId = 1;
1007 
1008     auto result = jsRuntime->StartDebugger(needBreakPoint, instanceId);
1009     EXPECT_EQ(result, true);
1010     // debug mode is global option, maybe has started by other testcase, not check here.
1011     TAG_LOGI(AAFwkTag::TEST, "StartDebugger_0100 end");
1012 }
1013 
1014 /**
1015  * @tc.name: ReloadFormComponent_0100
1016  * @tc.desc: JsRuntime test for ReloadFormComponent.
1017  * @tc.type: FUNC
1018  */
1019 HWTEST_F(JsRuntimeTest, ReloadFormComponent_0100, TestSize.Level0)
1020 {
1021     TAG_LOGI(AAFwkTag::TEST, "ReloadFormComponent_0100 start");
1022 
1023     auto jsRuntime = std::make_unique<AbilityRuntime::JsRuntime>();
1024     ASSERT_NE(jsRuntime, nullptr);
1025 
1026     jsRuntime->ReloadFormComponent();
1027     jsRuntime.reset();
1028     TAG_LOGI(AAFwkTag::TEST, "ReloadFormComponent_0100 end");
1029 }
1030 
1031 /**
1032  * @tc.name: SetRequestAotCallback_0100
1033  * @tc.desc: JsRuntime test for SetRequestAotCallback.
1034  * @tc.type: FUNC
1035  * @tc.require: issueI82L1A
1036  */
1037 HWTEST_F(JsRuntimeTest, SetRequestAotCallback_0100, TestSize.Level0)
1038 {
1039     TAG_LOGI(AAFwkTag::TEST, "start");
1040 
1041     auto jsRuntime = std::make_unique<AbilityRuntime::JsRuntime>();
1042     ASSERT_NE(jsRuntime, nullptr);
1043 
1044     jsRuntime->SetRequestAotCallback();
1045     auto ret = panda::MockJSNApi::GetInstance()->RequestAot("bundleName", "moduleName", 0);
1046     EXPECT_NE(ret, -1);
1047     jsRuntime.reset();
1048     TAG_LOGI(AAFwkTag::TEST, "finish");
1049 }
1050 
1051 /**
1052  * @tc.name: DestroyHeapProfiler_0100
1053  * @tc.desc: JsRuntime test for DestroyHeapProfiler.
1054  * @tc.type: FUNC
1055  */
1056 HWTEST_F(JsRuntimeTest, DestroyHeapProfiler_0100, TestSize.Level0)
1057 {
1058     TAG_LOGI(AAFwkTag::TEST, "DestroyHeapProfiler_0100 start");
1059 
1060     auto jsRuntime = std::make_unique<AbilityRuntime::JsRuntime>();
1061 
1062     jsRuntime->DestroyHeapProfiler();
1063     ASSERT_NE(jsRuntime, nullptr);
1064     jsRuntime.reset();
1065     TAG_LOGI(AAFwkTag::TEST, "DestroyHeapProfiler_0100 end");
1066 }
1067 
1068 /**
1069  * @tc.name: ForceFullGC_0100
1070  * @tc.desc: JsRuntime test for ForceFullGC.
1071  * @tc.type: FUNC
1072  */
1073 HWTEST_F(JsRuntimeTest, ForceFullGC_0100, TestSize.Level0)
1074 {
1075     TAG_LOGI(AAFwkTag::TEST, "ForceFullGC_0100 start");
1076 
1077     auto jsRuntime = std::make_unique<AbilityRuntime::JsRuntime>();
1078 
1079     jsRuntime->ForceFullGC();
1080     ASSERT_NE(jsRuntime, nullptr);
1081     jsRuntime.reset();
1082     TAG_LOGI(AAFwkTag::TEST, "ForceFullGC_0100 end");
1083 }
1084 
1085 /**
1086  * @tc.name: AllowCrossThreadExecution_0100
1087  * @tc.desc: JsRuntime test for AllowCrossThreadExecution.
1088  * @tc.type: FUNC
1089  */
1090 HWTEST_F(JsRuntimeTest, AllowCrossThreadExecution_0100, TestSize.Level0)
1091 {
1092     TAG_LOGI(AAFwkTag::TEST, "AllowCrossThreadExecution_0100 start");
1093 
1094     auto jsRuntime = std::make_unique<AbilityRuntime::JsRuntime>();
1095 
1096     jsRuntime->AllowCrossThreadExecution();
1097     ASSERT_NE(jsRuntime, nullptr);
1098     TAG_LOGI(AAFwkTag::TEST, "AllowCrossThreadExecution_0100 end");
1099 }
1100 
1101 /**
1102  * @tc.name: GetHeapPrepare_0100
1103  * @tc.desc: JsRuntime test for GetHeapPrepare.
1104  * @tc.type: FUNC
1105  */
1106 HWTEST_F(JsRuntimeTest, GetHeapPrepare_0100, TestSize.Level0)
1107 {
1108     TAG_LOGI(AAFwkTag::TEST, "GetHeapPrepare_0100 start");
1109 
1110     auto jsRuntime = std::make_unique<AbilityRuntime::JsRuntime>();
1111 
1112     jsRuntime->GetHeapPrepare();
1113     ASSERT_NE(jsRuntime, nullptr);
1114     TAG_LOGI(AAFwkTag::TEST, "GetHeapPrepare_0100 end");
1115 }
1116 
1117 /**
1118  * @tc.name: InitLoop_0100
1119  * @tc.desc: JsRuntime test for InitLoop.
1120  * @tc.type: FUNC
1121  */
1122 HWTEST_F(JsRuntimeTest, InitLoop_0100, TestSize.Level0)
1123 {
1124     TAG_LOGI(AAFwkTag::TEST, "InitLoop_0100 start");
1125 
1126     auto jsRuntime = std::make_unique<AbilityRuntime::JsRuntime>();
1127 
1128     auto result = jsRuntime->InitLoop();
1129     EXPECT_EQ(result, false);
1130     jsRuntime.reset();
1131     TAG_LOGI(AAFwkTag::TEST, "InitLoop_0100 end");
1132 }
1133 
1134 /**
1135  * @tc.name: InitSourceMap_0100
1136  * @tc.desc: JsRuntime test for InitSourceMap.
1137  * @tc.type: FUNC
1138  */
1139 HWTEST_F(JsRuntimeTest, InitSourceMap_0100, TestSize.Level0)
1140 {
1141     TAG_LOGI(AAFwkTag::TEST, "InitSourceMap_0100 start");
1142 
1143     auto jsRuntime = std::make_unique<AbilityRuntime::JsRuntime>();
1144     auto operatorObj = std::make_shared<JsEnv::SourceMapOperator>("");
1145     jsRuntime->InitSourceMap(operatorObj);
1146     ASSERT_NE(jsRuntime, nullptr);
1147     jsRuntime.reset();
1148     TAG_LOGI(AAFwkTag::TEST, "InitSourceMap_0100 end");
1149 }
1150 
1151 HWTEST_F(JsRuntimeTest, InitSourceMap_0200, TestSize.Level0)
1152 {
1153     TAG_LOGI(AAFwkTag::TEST, "InitSourceMap_0200 start");
1154 
1155     auto mapObj = std::make_shared<JsEnv::SourceMap>();
1156     bool hasFile = false;
1157     mapObj->Init(hasFile, TEST_HAP_PATH);
1158     EXPECT_FALSE(hasFile);
1159     TAG_LOGI(AAFwkTag::TEST, "InitSourceMap_0200 end");
1160 }
1161 
1162 /**
1163  * @tc.name: Deinitialize_0100
1164  * @tc.desc: JsRuntime test for Deinitialize.
1165  * @tc.type: FUNC
1166  */
1167 HWTEST_F(JsRuntimeTest, Deinitialize_0100, TestSize.Level0)
1168 {
1169     TAG_LOGI(AAFwkTag::TEST, "Deinitialize_0100 start");
1170 
1171     auto jsRuntime = std::make_unique<AbilityRuntime::JsRuntime>();
1172 
1173     jsRuntime->Deinitialize();
1174     ASSERT_NE(jsRuntime, nullptr);
1175     jsRuntime.reset();
1176     TAG_LOGI(AAFwkTag::TEST, "Deinitialize_0100 end");
1177 }
1178 
1179 /**
1180  * @tc.name: GetPkgContextInfoListMap_0100
1181  * @tc.desc: JsRuntime test for GetPkgContextInfoListMap.
1182  * @tc.type: FUNC
1183  */
1184 HWTEST_F(JsRuntimeTest, GetPkgContextInfoListMap_0100, TestSize.Level0)
1185 {
1186     TAG_LOGI(AAFwkTag::TEST, "GetPkgContextInfoListMap_0100 start");
1187 
1188     std::map<std::string, std::string> modulePkgContentMap;
1189     std::string pkgContentJsonString = R"({"library": {"packageName": "library", "bundleName": "com.xxx.xxxx",
1190         "moduleName": "library", "version": "1.0.0", "entryPath": "", "isSO": false}})";
1191     modulePkgContentMap["entry"] = pkgContentJsonString;
1192 
1193     AbilityRuntime::Runtime::Options options;
1194     options.preload = true;
1195     auto jsRuntime = AbilityRuntime::JsRuntime::Create(options);
1196     std::map<std::string, std::vector<std::vector<std::string>>> ret;
1197     std::map<std::string, std::string> pkgAliasMap;
1198     JsRuntimeLite::GetInstance().GetPkgContextInfoListMap(modulePkgContentMap, ret, pkgAliasMap);
1199     std::string expectString = "library:packageName:library:bundleName:";
1200     expectString += "com.xxx.xxxx:moduleName:library:version:1.0.0:entryPath::isSO:false:";
1201     auto it = ret.find("entry");
1202     ASSERT_EQ(it, ret.end());
1203     std::string pkgRetString;
1204     for (const auto& vec : it->second) {
1205         for (const auto& str : vec) {
1206             pkgRetString += str + ":";
1207         }
1208     }
1209     ASSERT_EQ(pkgRetString, "");
1210     jsRuntime.reset();
1211     TAG_LOGI(AAFwkTag::TEST, "GetPkgContextInfoListMap_0100 end");
1212 }
1213 
1214 /**
1215  * @tc.name: GetPkgContextInfoListMap_0200
1216  * @tc.desc: JsRuntime test for GetPkgContextInfoListMap.
1217  * @tc.type: FUNC
1218  */
1219 HWTEST_F(JsRuntimeTest, GetPkgContextInfoListMap_0200, TestSize.Level0)
1220 {
1221     TAG_LOGI(AAFwkTag::TEST, "GetPkgContextInfoListMap_0200 start");
1222 
1223     std::map<std::string, std::string> modulePkgContentMap;
1224     std::string pkgContentJsonString = R"({"library": {"packageName": "library", "bundleName":
1225         "com.xxx.xxxx", "moduleName": "library", "version": "1.0.0", "entryPath": "", "isSO": false}})";
1226     modulePkgContentMap["entry"] = pkgContentJsonString;
1227 
1228     std::string libraryString = R"({"library": {"packageName": "library","bundleName": "com.xxx.xxxx", "moduleName":
1229         "library", "version": "1.0.0", "entryPath": "", "isSO": false}})";
1230     modulePkgContentMap["library"] = libraryString;
1231 
1232     AbilityRuntime::Runtime::Options options;
1233     options.preload = true;
1234     auto jsRuntime = AbilityRuntime::JsRuntime::Create(options);
1235     std::map<std::string, std::vector<std::vector<std::string>>> ret;
1236     std::map<std::string, std::string> pkgAliasMap;
1237     JsRuntimeLite::GetInstance().GetPkgContextInfoListMap(modulePkgContentMap, ret, pkgAliasMap);
1238     std::string expectString = "library:packageName:library:bundleName:";
1239     expectString += "com.xxx.xxxx:moduleName:library:version:1.0.0:entryPath::isSO:false:";
1240     auto it = ret.find("entry");
1241     ASSERT_EQ(it, ret.end());
1242     auto libraryIt = ret.find("library");
1243     ASSERT_EQ(libraryIt, ret.end());
1244     std::string pkgRetString;
1245     for (const auto& vec : it->second) {
1246         for (const auto& str : vec) {
1247             pkgRetString += str + ":";
1248         }
1249     }
1250     ASSERT_EQ(pkgRetString, "");
1251     jsRuntime.reset();
1252     TAG_LOGI(AAFwkTag::TEST, "GetPkgContextInfoListMap_0200 end");
1253 }
1254 
1255 /**
1256  * @tc.name: CreateJsEnv_0100
1257  * @tc.desc: JsRuntime test for CreateJsEnv.
1258  * @tc.type: FUNC
1259  * @tc.require: issueI9CHSB
1260  */
1261 HWTEST_F(JsRuntimeTest, CreateJsEnv_0100, TestSize.Level1)
1262 {
1263     TAG_LOGI(AAFwkTag::TEST, "CreateJsEnv_0100 start");
1264     auto jsRuntime = std::make_unique<JsRuntime>();
1265     auto ret = jsRuntime->CreateJsEnv(options_);
1266     EXPECT_EQ(ret, true);
1267     jsRuntime.reset();
1268     TAG_LOGI(AAFwkTag::TEST, "CreateJsEnv_0100 start");
1269 }
1270 
1271 /**
1272  * @tc.name: DumpCpuProfile_0100
1273  * @tc.desc: JsRuntime test for DumpCpuProfile.
1274  * @tc.type: FUNC
1275  */
1276 HWTEST_F(JsRuntimeTest, DumpCpuProfile_0100, TestSize.Level1)
1277 {
1278     TAG_LOGI(AAFwkTag::TEST, "DumpCpuProfile_0100 start");
1279     auto jsRuntime = std::make_unique<JsRuntime>();
1280     bool isPrivate = true;
1281     jsRuntime->DumpCpuProfile();
1282     EXPECT_TRUE(jsRuntime != nullptr);
1283     TAG_LOGI(AAFwkTag::TEST, "DumpCpuProfile_0100 end");
1284 }
1285 
1286 /**
1287  * @tc.name: DumpHeapSnapshot_0100
1288  * @tc.desc: JsRuntime test for DumpHeapSnapshot.
1289  * @tc.type: FUNC
1290  */
1291 HWTEST_F(JsRuntimeTest, DumpHeapSnapshot_0100, TestSize.Level1)
1292 {
1293     TAG_LOGI(AAFwkTag::TEST, "DumpHeapSnapshot_0100 start");
1294     auto jsRuntime = std::make_unique<JsRuntime>();
1295     bool isPrivate = true;
1296     jsRuntime->DumpHeapSnapshot(isPrivate);
1297     EXPECT_TRUE(jsRuntime != nullptr);
1298     TAG_LOGI(AAFwkTag::TEST, "DumpHeapSnapshot end");
1299 }
1300 
1301 /**
1302  * @tc.name: DumpHeapSnapshot_0200
1303  * @tc.desc: JsRuntime test for DumpHeapSnapshot.
1304  * @tc.type: FUNC
1305  */
1306 HWTEST_F(JsRuntimeTest, DumpHeapSnapshot_0200, TestSize.Level1)
1307 {
1308     TAG_LOGI(AAFwkTag::TEST, "DumpHeapSnapshot_0100 start");
1309     auto jsRuntime = std::make_unique<JsRuntime>();
1310     uint32_t tid = 1;
1311     bool isFullGC = true;
1312     jsRuntime->DumpHeapSnapshot(tid, isFullGC);
1313     EXPECT_TRUE(jsRuntime != nullptr);
1314     TAG_LOGI(AAFwkTag::TEST, "DumpHeapSnapshot end");
1315 }
1316 
1317 /**
1318  * @tc.name: AllowCrossThreadExecution_0200
1319  * @tc.desc: JsRuntime test for AllowCrossThreadExecution.
1320  * @tc.type: FUNC
1321  */
1322 HWTEST_F(JsRuntimeTest, AllowCrossThreadExecution_0200, TestSize.Level1)
1323 {
1324     TAG_LOGI(AAFwkTag::TEST, "AllowCrossThreadExecution_0200 start");
1325     auto jsRuntime = std::make_unique<JsRuntime>();
1326     jsRuntime->AllowCrossThreadExecution();
1327     EXPECT_TRUE(jsRuntime != nullptr);
1328     TAG_LOGI(AAFwkTag::TEST, "AllowCrossThreadExecution_0200 end");
1329 }
1330 
1331 /**
1332  * @tc.name: GetHeapPrepare_0200
1333  * @tc.desc: JsRuntime test for GetHeapPrepare.
1334  * @tc.type: FUNC
1335  */
1336 HWTEST_F(JsRuntimeTest, GetHeapPrepare_0200, TestSize.Level1)
1337 {
1338     TAG_LOGI(AAFwkTag::TEST, "GetHeapPrepare_0200 start");
1339     auto jsRuntime = std::make_unique<JsRuntime>();
1340     jsRuntime->GetHeapPrepare();
1341     EXPECT_TRUE(jsRuntime != nullptr);
1342     TAG_LOGI(AAFwkTag::TEST, "GetHeapPrepare_0200 end");
1343 }
1344 
1345 /**
1346  * @tc.name: RegisterQuickFixQueryFunc_0200
1347  * @tc.desc: JsRuntime test for RegisterQuickFixQueryFunc.
1348  * @tc.type: FUNC
1349  */
1350 HWTEST_F(JsRuntimeTest, RegisterQuickFixQueryFunc_0200, TestSize.Level1)
1351 {
1352     TAG_LOGI(AAFwkTag::TEST, "RegisterQuickFixQueryFunc_0200 start");
1353     auto jsRuntime = std::make_unique<JsRuntime>();
1354     std::map<std::string, std::string> moduleAndPath;
1355     jsRuntime->RegisterQuickFixQueryFunc(moduleAndPath);
1356     EXPECT_TRUE(jsRuntime != nullptr);
1357     TAG_LOGI(AAFwkTag::TEST, "RegisterQuickFixQueryFunc_0200 end");
1358 }
1359 
1360 /**
1361  * @tc.name: UpdatePkgContextInfoJson_0100
1362  * @tc.desc: JsRuntime test for UpdatePkgContextInfoJson.
1363  * @tc.type: FUNC
1364  */
1365 HWTEST_F(JsRuntimeTest, UpdatePkgContextInfoJson_0100, TestSize.Level1)
1366 {
1367     TAG_LOGI(AAFwkTag::TEST, "UpdatePkgContextInfoJson_0100 start");
1368     auto jsRuntime = std::make_unique<JsRuntime>();
1369     EXPECT_TRUE(jsRuntime != nullptr);
1370     std::string moduleName = "moduleName";
1371     std::string hapPath = TEST_HAP_PATH;
1372     std::string packageName = "packageName";
1373     jsRuntime->UpdatePkgContextInfoJson(moduleName, hapPath, packageName);
1374     TAG_LOGI(AAFwkTag::TEST, "UpdatePkgContextInfoJson_0100 end");
1375 }
1376 
1377 HWTEST_F(JsRuntimeTest, SetPkgContextInfoJson_0100, TestSize.Level1)
1378 {
1379     TAG_LOGI(AAFwkTag::TEST, "SetPkgContextInfoJson_0100 start");
1380     auto jsRuntime = std::make_unique<JsRuntime>();
1381     EXPECT_TRUE(jsRuntime != nullptr);
1382     std::string moduleName = "moduleName";
1383     std::string hapPath = TEST_HAP_PATH;
1384     std::string packageName = "packageName";
1385     jsRuntime->SetPkgContextInfoJson(moduleName, hapPath, packageName);
1386     EXPECT_FALSE(jsRuntime->pkgContextInfoJsonStringMap_.empty());
1387     TAG_LOGI(AAFwkTag::TEST, "SetPkgContextInfoJson_0100 end");
1388 }
1389 
1390 /**
1391  * @tc.name: JsRuntimePreloadModuleandDoCleanWorkAfterStageCleaned_0100
1392  * @tc.desc: JsRuntime test for JsRuntimePreloadModule and DoCleanWorkAfterStageCleaned.
1393  * @tc.type: FUNC
1394  */
1395 HWTEST_F(JsRuntimeTest, JsRuntimePreloadModuleandDoCleanWorkAfterStageCleaned_0100, TestSize.Level1)
1396 {
1397     TAG_LOGI(AAFwkTag::TEST, "PreloadModule_0100 start");
1398     auto jsRuntime = std::make_unique<JsRuntime>();
1399     EXPECT_TRUE(jsRuntime != nullptr);
1400     jsRuntime->DoCleanWorkAfterStageCleaned();
1401     std::string moduleName = TEST_MODULE_NAME;
1402     std::string srcPath = TEST_LIB_PATH;
1403     std::string hapPath = TEST_HAP_PATH;
1404     bool isEsMode = true;
1405     bool useCommonTrunk = true;
1406     jsRuntime->PreloadModule(moduleName, srcPath, hapPath, isEsMode, useCommonTrunk);
1407     EXPECT_EQ(jsRuntime->preloadList_.size(), 1);
1408     jsRuntime.reset();
1409     TAG_LOGI(AAFwkTag::TEST, "PreloadModule_0100 end");
1410 }
1411 
1412 /**
1413  * @tc.name: JsRuntimePreloadMainAbility_0100
1414  * @tc.desc: JsRuntime test for JsRuntimePreloadMainAbility.
1415  * @tc.type: FUNC
1416  */
1417 HWTEST_F(JsRuntimeTest, JsRuntimePreloadMainAbility_0100, TestSize.Level1)
1418 {
1419     TAG_LOGI(AAFwkTag::TEST, "PreloadMainAbility_0100 start");
1420     auto jsRuntime = std::make_unique<JsRuntime>();
1421     EXPECT_TRUE(jsRuntime != nullptr);
1422     std::string moduleName = TEST_MODULE_NAME;
1423     std::string srcPath = TEST_MODULE_PATH;
1424     std::string hapPath = TEST_HAP_PATH;
1425     std::string srcEntrance = TEST_LIB_PATH;
1426     bool isEsMode = true;
1427     jsRuntime->PreloadMainAbility(moduleName, srcPath, hapPath, isEsMode, srcEntrance);
1428     EXPECT_EQ(jsRuntime->preloadList_.size(), 1);
1429     jsRuntime.reset();
1430     TAG_LOGI(AAFwkTag::TEST, "PreloadMainAbility_0100 end");
1431 }
1432 
1433 /**
1434  * @tc.name: JsRuntimeSetStopPreloadSoCallback_0100
1435  * @tc.desc: JsRuntime test for JsRuntimeSetStopPreloadSoCallback.
1436  * @tc.type: FUNC
1437  */
1438 HWTEST_F(JsRuntimeTest, JsRuntimeSetStopPreloadSoCallback_0100, TestSize.Level1)
1439 {
1440     TAG_LOGI(AAFwkTag::TEST, "SetStopPreloadSoCallback_0100 start");
__anon250aa48c0602() 1441     auto callBack = []() {};
1442     jsRuntimePtr->SetStopPreloadSoCallback(callBack);
1443     ASSERT_TRUE(jsRuntimePtr != nullptr);
1444     TAG_LOGI(AAFwkTag::TEST, "SetStopPreloadSoCallback_0100 start");
1445 }
1446 
1447 /**
1448  * @tc.name: StartProfiler_0100
1449  * @tc.desc: JsRuntime test for StartProfiler.
1450  * @tc.type: FUNC
1451  */
1452 HWTEST_F(JsRuntimeTest, StartProfiler_0100, TestSize.Level1)
1453 {
1454     TAG_LOGI(AAFwkTag::TEST, "StartProfiler_0100 start");
1455     Runtime::DebugOption debugOption;
1456     debugOption.isDebugFromLocal = true;
1457     debugOption.isDeveloperMode = true;
1458     auto jsRuntime = std::make_unique<JsRuntime>();
1459     EXPECT_NE(jsRuntime, nullptr);
1460     jsRuntime->StartProfiler(debugOption);
1461     EXPECT_EQ(jsRuntime->jsEnv_, nullptr);
1462     TAG_LOGI(AAFwkTag::TEST, "StartProfiler_0100 end");
1463 }
1464 } // namespace AbilityRuntime
1465 } // namespace OHOS