1 /*
2 * Copyright (c) 2022-2023 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 #define private public
20 #define protected public
21 #include "js_environment.h"
22 #include "js_runtime.h"
23 #include "js_runtime_utils.h"
24 #include "js_worker.h"
25 #undef private
26 #undef protected
27 #include "event_runner.h"
28 #include "mock_js_runtime.h"
29 #include "mock_jsnapi.h"
30 #include "hilog_tag_wrapper.h"
31 #include "js_runtime_lite.h"
32
33 using namespace testing;
34 using namespace testing::ext;
35 using namespace testing::mt;
36
37 namespace OHOS {
38 namespace AbilityRuntime {
39 namespace {
40 const std::string TEST_BUNDLE_NAME = "com.ohos.contactsdataability";
41 const std::string TEST_MODULE_NAME = ".ContactsDataAbility";
42 const std::string TEST_ABILITY_NAME = "ContactsDataAbility";
43 const std::string TEST_CODE_PATH = "/data/storage/el1/bundle";
44 const std::string TEST_HAP_PATH = "/system/app/com.ohos.contactsdataability/Contacts_DataAbility.hap";
45 const std::string TEST_LIB_PATH = "/data/storage/el1/bundle/lib/";
46 const std::string TEST_MODULE_PATH = "/data/storage/el1/bundle/curJsModulePath";
47 } // namespace
48 class JsRuntimeTest : public testing::Test {
49 public:
50 static void SetUpTestCase();
51 static void TearDownTestCase();
52 void SetUp() override;
53 void TearDown() override;
54
55 Runtime::Options options_;
56 };
57
SetUpTestCase()58 void JsRuntimeTest::SetUpTestCase()
59 {}
60
TearDownTestCase()61 void JsRuntimeTest::TearDownTestCase()
62 {}
63
SetUp()64 void JsRuntimeTest::SetUp()
65 {
66 Runtime::Options newOptions;
67 options_ = newOptions;
68 options_.bundleName = TEST_BUNDLE_NAME;
69 options_.codePath = TEST_CODE_PATH;
70 options_.loadAce = false;
71 options_.isBundle = true;
72 options_.preload = false;
73 std::shared_ptr<AppExecFwk::EventRunner> eventRunner = AppExecFwk::EventRunner::Create(TEST_ABILITY_NAME);
74 options_.eventRunner = eventRunner;
75 }
76
TearDown()77 void JsRuntimeTest::TearDown()
78 {}
79
80 /**
81 * @tc.name: JsperfProfilerCommandParse_100
82 * @tc.desc: JsRuntime test for JsperfProfilerCommandParse.
83 * @tc.type: FUNC
84 */
HWTEST_F(JsRuntimeTest, JsperfProfilerCommandParse_100, TestSize.Level1)85 HWTEST_F(JsRuntimeTest, JsperfProfilerCommandParse_100, TestSize.Level1)
86 {
87 auto jsRuntime = AbilityRuntime::JsRuntime::Create(options_);
88 std::string command = "";
89 constexpr int32_t defaultVal = 500;
90 constexpr int32_t emptyVal = 0;
91 ASSERT_EQ(jsRuntime->JsperfProfilerCommandParse(command, defaultVal), emptyVal);
92 command = "jsperfabc";
93 ASSERT_EQ(jsRuntime->JsperfProfilerCommandParse(command, defaultVal), defaultVal);
94 command = "jsperf";
95 ASSERT_EQ(jsRuntime->JsperfProfilerCommandParse(command, defaultVal), defaultVal);
96 command = "jsperf ";
97 ASSERT_EQ(jsRuntime->JsperfProfilerCommandParse(command, defaultVal), defaultVal);
98 command = "jsperf 1000";
99 ASSERT_NE(jsRuntime->JsperfProfilerCommandParse(command, defaultVal), defaultVal);
100 command = " jsperf 1000";
101 ASSERT_NE(jsRuntime->JsperfProfilerCommandParse(command, defaultVal), defaultVal);
102 jsRuntime.reset();
103 std::this_thread::sleep_for(std::chrono::milliseconds(200));
104 }
105
106 /**
107 * @tc.name: JsRuntimeTest_0100
108 * @tc.desc: JsRuntime Test
109 * @tc.type: FUNC
110 * @tc.require: issueI581SE
111 */
HWTEST_F(JsRuntimeTest, JsRuntimeTest_0100, TestSize.Level0)112 HWTEST_F(JsRuntimeTest, JsRuntimeTest_0100, TestSize.Level0)
113 {
114 options_.preload = true;
115 std::unique_ptr<Runtime> jsRuntime = JsRuntime::Create(options_);
116 EXPECT_TRUE(jsRuntime != nullptr);
117
118 jsRuntime = nullptr;
119 options_.preload = false;
120 jsRuntime = JsRuntime::Create(options_);
121 EXPECT_TRUE(jsRuntime != nullptr);
122 jsRuntime.reset();
123 std::this_thread::sleep_for(std::chrono::milliseconds(200));
124 }
125
126 /**
127 * @tc.name: JsRuntimeTest_0200
128 * @tc.desc: JsRuntime Test
129 * @tc.type: FUNC
130 * @tc.require: issueI581RO
131 */
HWTEST_F(JsRuntimeTest, JsRuntimeTest_0200, TestSize.Level0)132 HWTEST_F(JsRuntimeTest, JsRuntimeTest_0200, TestSize.Level0)
133 {
134 std::string appLibPathKey = TEST_BUNDLE_NAME + TEST_MODULE_NAME;
135 std::string libPath = TEST_LIB_PATH;
136
137 AppLibPathMap appLibPaths {};
138 JsRuntime::SetAppLibPath(appLibPaths);
139
140 appLibPaths[appLibPathKey].emplace_back(libPath);
141 EXPECT_NE(appLibPaths.size(), 0);
142 JsRuntime::SetAppLibPath(appLibPaths);
143 }
144
145 /**
146 * @tc.name: JsRuntimeUtilsTest_0100
147 * @tc.desc: JsRuntimeUtils Test
148 * @tc.type: FUNC
149 * @tc.require: issueI581RO
150 */
HWTEST_F(JsRuntimeTest, JsRuntimeUtilsTest_0100, TestSize.Level0)151 HWTEST_F(JsRuntimeTest, JsRuntimeUtilsTest_0100, TestSize.Level0)
152 {
153 auto runtime = AbilityRuntime::Runtime::Create(options_);
154 auto env = (static_cast<AbilityRuntime::JsRuntime&>(*runtime)).GetNapiEnv();
155
156 napi_ref callbackRef = nullptr;
157 napi_create_reference(env, CreateJsUndefined(env), 1, &callbackRef);
158 std::unique_ptr<NapiAsyncTask> task = std::make_unique<NapiAsyncTask>(callbackRef, nullptr, nullptr);
159 task->ResolveWithNoError(env, CreateJsUndefined(env));
160 EXPECT_TRUE(task->callbackRef_ == nullptr);
161
162 napi_deferred nativeDeferred = nullptr;
163 napi_value result;
164 napi_create_promise(env, &nativeDeferred, &result);
165 task = std::make_unique<NapiAsyncTask>(nativeDeferred, nullptr, nullptr);
166 task->ResolveWithNoError(env, CreateJsUndefined(env));
167 EXPECT_TRUE(task->deferred_ == nullptr);
168
169 task->deferred_ = nullptr;
170 task->callbackRef_ = nullptr;
171 task->ResolveWithNoError(env, CreateJsUndefined(env));
172 EXPECT_TRUE(task->deferred_ == nullptr);
173 EXPECT_TRUE(task->callbackRef_ == nullptr);
174 runtime.reset();
175 std::this_thread::sleep_for(std::chrono::milliseconds(200));
176 }
177
178 /**
179 * @tc.name: JsRuntimeGetLanguageTest_0100
180 * @tc.desc: JsRuntime Test
181 * @tc.type: FUNC
182 */
HWTEST_F(JsRuntimeTest, JsRuntimeGetLanguageTest_0100, TestSize.Level0)183 HWTEST_F(JsRuntimeTest, JsRuntimeGetLanguageTest_0100, TestSize.Level0)
184 {
185 options_.preload = true;
186 std::unique_ptr<Runtime> jsRuntime = JsRuntime::Create(options_);
187 EXPECT_TRUE(jsRuntime != nullptr);
188
189 JsRuntime::Language language = jsRuntime->GetLanguage();
190 EXPECT_TRUE(language == JsRuntime::Language::JS);
191 jsRuntime.reset();
192 std::this_thread::sleep_for(std::chrono::milliseconds(200));
193 }
194
195 /**
196 * @tc.name: JsRuntimeNotifyApplicationStateTest_0100
197 * @tc.desc: JsRuntime test for NotifyApplicationState when nativeEngine is nullptr.
198 * @tc.type: FUNC
199 */
HWTEST_F(JsRuntimeTest, JsRuntimeNotifyApplicationStateTest_0100, TestSize.Level0)200 HWTEST_F(JsRuntimeTest, JsRuntimeNotifyApplicationStateTest_0100, TestSize.Level0)
201 {
202 TAG_LOGI(AAFwkTag::TEST, "NotifyApplicationState start");
203
204 std::unique_ptr<JsRuntime> jsRuntime = std::make_unique<MockJsRuntime>();
205 EXPECT_TRUE(jsRuntime != nullptr);
206
207 bool isBackground = false;
208 jsRuntime->NotifyApplicationState(isBackground);
209
210 TAG_LOGI(AAFwkTag::TEST, "NotifyApplicationState end");
211 std::this_thread::sleep_for(std::chrono::milliseconds(200));
212 }
213
214 /**
215 * @tc.name: JsRuntimeNotifyApplicationStateTest_0200
216 * @tc.desc: JsRuntime test for NotifyApplicationState when nativeEngine is not nullptr.
217 * @tc.type: FUNC
218 */
HWTEST_F(JsRuntimeTest, JsRuntimeNotifyApplicationStateTest_0200, TestSize.Level0)219 HWTEST_F(JsRuntimeTest, JsRuntimeNotifyApplicationStateTest_0200, TestSize.Level0)
220 {
221 TAG_LOGI(AAFwkTag::TEST, "NotifyApplicationState start");
222
223 std::unique_ptr<Runtime> jsRuntime = JsRuntime::Create(options_);
224 EXPECT_TRUE(jsRuntime != nullptr);
225
226 bool isBackground = true;
227 jsRuntime->NotifyApplicationState(isBackground);
228
229 jsRuntime.reset();
230 std::this_thread::sleep_for(std::chrono::milliseconds(200));
231 TAG_LOGI(AAFwkTag::TEST, "NotifyApplicationState end");
232 }
233
234 /**
235 * @tc.name: JsRuntimeDumpHeapSnapshotTest_0100
236 * @tc.desc: JsRuntime test for DumpHeapSnapshot.
237 * @tc.type: FUNC
238 */
HWTEST_F(JsRuntimeTest, JsRuntimeDumpHeapSnapshotTest_0100, TestSize.Level0)239 HWTEST_F(JsRuntimeTest, JsRuntimeDumpHeapSnapshotTest_0100, TestSize.Level0)
240 {
241 TAG_LOGI(AAFwkTag::TEST, "DumpHeapSnapshot start");
242 MockJsRuntime mockJsRuntime;
243 bool isPrivate = false;
244 mockJsRuntime.DumpHeapSnapshot(isPrivate);
245 TAG_LOGI(AAFwkTag::TEST, "DumpHeapSnapshot end");
246 }
247
248 /**
249 * @tc.name: JsRuntimePreloadSystemModuleTest_0100
250 * @tc.desc: JsRuntime test for PreloadSystemModule.
251 * @tc.type: FUNC
252 */
HWTEST_F(JsRuntimeTest, JsRuntimePreloadSystemModuleTest_0100, TestSize.Level0)253 HWTEST_F(JsRuntimeTest, JsRuntimePreloadSystemModuleTest_0100, TestSize.Level0)
254 {
255 TAG_LOGI(AAFwkTag::TEST, "PreloadSystemModule start");
256
257 std::unique_ptr<Runtime> jsRuntime = JsRuntime::Create(options_);
258 EXPECT_TRUE(jsRuntime != nullptr);
259
260 std::string moduleName = "PreloadSystemModuleTest";
261 jsRuntime->PreloadSystemModule(moduleName);
262
263 jsRuntime.reset();
264 std::this_thread::sleep_for(std::chrono::milliseconds(200));
265 TAG_LOGI(AAFwkTag::TEST, "PreloadSystemModule end");
266 }
267
268 /**
269 * @tc.name: JsRuntimeRunSandboxScriptTest_0100
270 * @tc.desc: JsRuntime test for RunSandboxScript.
271 * @tc.type: FUNC
272 */
HWTEST_F(JsRuntimeTest, JsRuntimeRunSandboxScriptTest_0100, TestSize.Level0)273 HWTEST_F(JsRuntimeTest, JsRuntimeRunSandboxScriptTest_0100, TestSize.Level0)
274 {
275 TAG_LOGI(AAFwkTag::TEST, "RunSandboxScript start");
276
277 auto jsRuntime = std::make_unique<JsRuntime>();
278 std::string path = "";
279 std::string hapPath = "";
280 jsRuntime->RunSandboxScript(path, hapPath);
281 EXPECT_TRUE(jsRuntime != nullptr);
282 jsRuntime.reset();
283 std::this_thread::sleep_for(std::chrono::milliseconds(200));
284 TAG_LOGI(AAFwkTag::TEST, "RunSandboxScript end");
285 }
286
287 /**
288 * @tc.name: JsRuntimeLoadSystemModuleByEngineTest_0100
289 * @tc.desc: JsRuntime test for LoadSystemModuleByEngine.
290 * @tc.type: FUNC
291 */
HWTEST_F(JsRuntimeTest, JsRuntimeLoadSystemModuleByEngineTest_0100, TestSize.Level0)292 HWTEST_F(JsRuntimeTest, JsRuntimeLoadSystemModuleByEngineTest_0100, TestSize.Level0)
293 {
294 TAG_LOGI(AAFwkTag::TEST, "LoadSystemModuleByEngine start");
295
296 auto runtime = AbilityRuntime::JsRuntime::Create(options_);
297 auto env = (static_cast<AbilityRuntime::MockJsRuntime&>(*runtime)).GetNapiEnv();
298
299 std::string moduleName = "";
300 std::unique_ptr<NativeReference> ref = MockJsRuntime::LoadSystemModuleByEngine(env, moduleName, nullptr, 0);
301 EXPECT_EQ(ref, nullptr);
302
303 runtime.reset();
304 std::this_thread::sleep_for(std::chrono::milliseconds(200));
305 TAG_LOGI(AAFwkTag::TEST, "LoadSystemModuleByEngine end");
306 }
307
308 /**
309 * @tc.name: JsRuntimeFinishPreloadTest_0100
310 * @tc.desc: JsRuntime test for FinishPreload.
311 * @tc.type: FUNC
312 */
HWTEST_F(JsRuntimeTest, JsRuntimeFinishPreloadTest_0100, TestSize.Level0)313 HWTEST_F(JsRuntimeTest, JsRuntimeFinishPreloadTest_0100, TestSize.Level0)
314 {
315 TAG_LOGI(AAFwkTag::TEST, "FinishPreload start");
316
317 auto jsRuntime = std::make_unique<JsRuntime>();
318
319 jsRuntime->FinishPreload();
320 EXPECT_TRUE(jsRuntime != nullptr);
321
322 jsRuntime.reset();
323 std::this_thread::sleep_for(std::chrono::milliseconds(200));
324 TAG_LOGI(AAFwkTag::TEST, "FinishPreload end");
325 }
326
327 /**
328 * @tc.name: JsRuntimePostPreloadTest_0100
329 * @tc.desc: JsRuntime test for FinishPreload.
330 * @tc.type: FUNC
331 */
HWTEST_F(JsRuntimeTest, JsRuntimePostPreloadTest_0100, TestSize.Level0)332 HWTEST_F(JsRuntimeTest, JsRuntimePostPreloadTest_0100, TestSize.Level0)
333 {
334 TAG_LOGI(AAFwkTag::TEST, "PostPreload start");
335
336 auto jsRuntime = std::make_unique<JsRuntime>();
337
338 jsRuntime->PostPreload(options_);
339 EXPECT_TRUE(jsRuntime != nullptr);
340
341 jsRuntime.reset();
342 std::this_thread::sleep_for(std::chrono::milliseconds(200));
343 TAG_LOGI(AAFwkTag::TEST, "PostPreload end");
344 }
345
346 /**
347 * @tc.name: JsRuntimeLoadAotFileTest_0100
348 * @tc.desc: JsRuntime test for LoadAotFile.
349 * @tc.type: FUNC
350 */
HWTEST_F(JsRuntimeTest, JsRuntimeLoadAotFileTest_0100, TestSize.Level0)351 HWTEST_F(JsRuntimeTest, JsRuntimeLoadAotFileTest_0100, TestSize.Level0)
352 {
353 TAG_LOGI(AAFwkTag::TEST, "LoadAotFile start");
354
355 auto jsRuntime = std::make_unique<JsRuntime>();
356
357 jsRuntime->LoadAotFile(options_);
358 EXPECT_TRUE(jsRuntime != nullptr);
359
360 jsRuntime.reset();
361 std::this_thread::sleep_for(std::chrono::milliseconds(200));
362 TAG_LOGI(AAFwkTag::TEST, "LoadAotFile end");
363 }
364
365 /**
366 * @tc.name: JsRuntimeLoadModuleTest_0100
367 * @tc.desc: JsRuntime test for LoadModule.
368 * @tc.type: FUNC
369 */
HWTEST_F(JsRuntimeTest, JsRuntimeLoadModuleTest_0100, TestSize.Level0)370 HWTEST_F(JsRuntimeTest, JsRuntimeLoadModuleTest_0100, TestSize.Level0)
371 {
372 TAG_LOGI(AAFwkTag::TEST, "LoadModule start");
373
374 std::unique_ptr<Runtime> jsRuntime = JsRuntime::Create(options_);
375 EXPECT_TRUE(jsRuntime != nullptr);
376
377 std::string moduleName = TEST_MODULE_NAME;
378 std::string modulePath = TEST_MODULE_PATH;
379 std::string hapPath = TEST_HAP_PATH;
380 bool esmodule = true;
381 std::unique_ptr<NativeReference> ref = (static_cast<AbilityRuntime::JsRuntime&>(*jsRuntime)).LoadModule(moduleName,
382 modulePath, hapPath, esmodule);
383 EXPECT_EQ(ref, nullptr);
384 jsRuntime.reset();
385 std::this_thread::sleep_for(std::chrono::milliseconds(200));
386 TAG_LOGI(AAFwkTag::TEST, "LoadModule end");
387 }
388
389 /**
390 * @tc.name: JsRuntimeLoadSystemModuleTest_0100
391 * @tc.desc: JsRuntime test for LoadSystemModule (invoke the overwrite interface).
392 * @tc.type: FUNC
393 */
HWTEST_F(JsRuntimeTest, JsRuntimeLoadSystemModuleTest_0100, TestSize.Level0)394 HWTEST_F(JsRuntimeTest, JsRuntimeLoadSystemModuleTest_0100, TestSize.Level0)
395 {
396 TAG_LOGI(AAFwkTag::TEST, "LoadSystemModule start");
397
398 MockJsRuntime mockJsRuntime;
399 std::unique_ptr<NativeReference> ref = mockJsRuntime.LoadSystemModule("", nullptr, 0);
400 EXPECT_EQ(ref, nullptr);
401
402 std::this_thread::sleep_for(std::chrono::milliseconds(200));
403 TAG_LOGI(AAFwkTag::TEST, "LoadSystemModule end");
404 }
405
406 /**
407 * @tc.name: RuntimeSavePreloadedTest_0100
408 * @tc.desc: Runtime test for SavePreloaded.
409 * @tc.type: FUNC
410 */
HWTEST_F(JsRuntimeTest, RuntimeSavePreloadedTest_0100, TestSize.Level0)411 HWTEST_F(JsRuntimeTest, RuntimeSavePreloadedTest_0100, TestSize.Level0)
412 {
413 TAG_LOGI(AAFwkTag::TEST, "SavePreloaded start");
414
415 auto runtime = AbilityRuntime::Runtime::Create(options_);
416 runtime->SavePreloaded(nullptr);
417 EXPECT_TRUE(runtime != nullptr);
418
419 runtime.reset();
420 std::this_thread::sleep_for(std::chrono::milliseconds(200));
421 TAG_LOGI(AAFwkTag::TEST, "SavePreloaded end");
422 }
423
424 /**
425 * @tc.name: RuntimeSetModuleLoadCheckerTest_0100
426 * @tc.desc: Runtime test for SetModuleLoadChecker.
427 * @tc.type: FUNC
428 */
HWTEST_F(JsRuntimeTest, RuntimeSetModuleLoadCheckerTest_0100, TestSize.Level0)429 HWTEST_F(JsRuntimeTest, RuntimeSetModuleLoadCheckerTest_0100, TestSize.Level0)
430 {
431 TAG_LOGI(AAFwkTag::TEST, "SetModuleLoadChecker start");
432
433 auto runtime = AbilityRuntime::Runtime::Create(options_);
434 runtime->SetModuleLoadChecker(nullptr);
435 EXPECT_TRUE(runtime != nullptr);
436
437 runtime.reset();
438 std::this_thread::sleep_for(std::chrono::milliseconds(200));
439 TAG_LOGI(AAFwkTag::TEST, "SetModuleLoadChecker end");
440 }
441
442 /**
443 * @tc.name: JsRuntimeSuspendVMTest_0100
444 * @tc.desc: JsRuntime test for SuspendVM.
445 * @tc.type: FUNC
446 */
HWTEST_F(JsRuntimeTest, JsRuntimeSuspendVMTest_0100, TestSize.Level0)447 HWTEST_F(JsRuntimeTest, JsRuntimeSuspendVMTest_0100, TestSize.Level0)
448 {
449 TAG_LOGI(AAFwkTag::TEST, "SuspendVM start");
450
451 auto runtime = AbilityRuntime::JsRuntime::Create(options_);
452 auto result = runtime->SuspendVM(gettid());
453 EXPECT_EQ(result, false);
454
455 runtime.reset();
456 std::this_thread::sleep_for(std::chrono::milliseconds(200));
457 TAG_LOGI(AAFwkTag::TEST, "SuspendVM end");
458 }
459
460 /**
461 * @tc.name: JsRuntimeResumeVMTest_0100
462 * @tc.desc: JsRuntime test for ResumeVM.
463 * @tc.type: FUNC
464 */
HWTEST_F(JsRuntimeTest, JsRuntimeResumeVMTest_0100, TestSize.Level0)465 HWTEST_F(JsRuntimeTest, JsRuntimeResumeVMTest_0100, TestSize.Level0)
466 {
467 TAG_LOGI(AAFwkTag::TEST, "ResumeVM start");
468
469 auto runtime = AbilityRuntime::JsRuntime::Create(options_);
470 runtime->ResumeVM(gettid());
471 EXPECT_TRUE(runtime != nullptr);
472
473 runtime.reset();
474 std::this_thread::sleep_for(std::chrono::milliseconds(200));
475 TAG_LOGI(AAFwkTag::TEST, "ResumeVM end");
476 }
477
478 /**
479 * @tc.name: JsRuntimeSetDeviceDisconnectCallbackTest_0100
480 * @tc.desc: JsRuntime test for SetDeviceDisconnectCallback.
481 * @tc.type: FUNC
482 */
HWTEST_F(JsRuntimeTest, JsRuntimeSetDeviceDisconnectCallbackTest_0100, TestSize.Level0)483 HWTEST_F(JsRuntimeTest, JsRuntimeSetDeviceDisconnectCallbackTest_0100, TestSize.Level0)
484 {
485 TAG_LOGI(AAFwkTag::TEST, "SetDeviceDisconnectCallback start");
486
487 auto runtime = AbilityRuntime::JsRuntime::Create(options_);
488 std::function<bool()> task = [&]() {
489 return true;
490 };
491 runtime->SetDeviceDisconnectCallback(task);
492 EXPECT_TRUE(runtime != nullptr);
493
494 runtime.reset();
495 std::this_thread::sleep_for(std::chrono::milliseconds(200));
496 TAG_LOGI(AAFwkTag::TEST, "SetDeviceDisconnectCallback end");
497 }
498
499 /**
500 * @tc.name: JsRuntimeDetachCallbackFuncTest_0100
501 * @tc.desc: JsRuntime test for PostTask.
502 * @tc.type: FUNC
503 */
HWTEST_F(JsRuntimeTest, JsRuntimeDetachCallbackFuncTest_0100, TestSize.Level0)504 HWTEST_F(JsRuntimeTest, JsRuntimeDetachCallbackFuncTest_0100, TestSize.Level0)
505 {
506 TAG_LOGI(AAFwkTag::TEST, "DetachCallbackFunc start");
507
508 auto runtime = AbilityRuntime::JsRuntime::Create(options_);
509 auto env = (static_cast<AbilityRuntime::MockJsRuntime&>(*runtime)).GetNapiEnv();
510 int32_t value = 1;
511 int32_t number = 1;
512 auto result = AbilityRuntime::DetachCallbackFunc(env, &value, &number);
513 EXPECT_EQ(result, &value);
514
515 runtime.reset();
516 std::this_thread::sleep_for(std::chrono::milliseconds(200));
517 TAG_LOGI(AAFwkTag::TEST, "DetachCallbackFunc end");
518 }
519
520 /**
521 * @tc.name: JsRuntimeLoadSystemModulesTest_0100
522 * @tc.desc: JsRuntime test for LoadSystemModule.
523 * @tc.type: FUNC
524 */
HWTEST_F(JsRuntimeTest, JsRuntimeLoadSystemModulesTest_0100, TestSize.Level0)525 HWTEST_F(JsRuntimeTest, JsRuntimeLoadSystemModulesTest_0100, TestSize.Level0)
526 {
527 TAG_LOGI(AAFwkTag::TEST, "LoadSystemModule start");
528
529 auto jsRuntime = std::make_unique<JsRuntime>();
530 EXPECT_TRUE(jsRuntime != nullptr);
531
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 */
HWTEST_F(JsRuntimeTest, JsRuntimeStartDebugModeTest_0100, TestSize.Level0)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 */
HWTEST_F(JsRuntimeTest, JsRuntimeStopDebugModeTest_0100, TestSize.Level0)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 */
HWTEST_F(JsRuntimeTest, JsRuntimeInitConsoleModuleTest_0100, TestSize.Level0)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 */
HWTEST_F(JsRuntimeTest, JsRuntimeLoadRepairPatchTest_0100, TestSize.Level0)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 */
HWTEST_F(JsRuntimeTest, JsRuntimeUnLoadRepairPatchTest_0100, TestSize.Level0)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 */
HWTEST_F(JsRuntimeTest, JsRuntimeNotifyHotReloadPageTest_0100, TestSize.Level0)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 */
HWTEST_F(JsRuntimeTest, JsRuntimeUpdateModuleNameAndAssetPathTest_0100, TestSize.Level0)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 */
HWTEST_F(JsRuntimeTest, JsRuntimeUpdateModuleNameAndAssetPathTest_0200, TestSize.Level0)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 */
HWTEST_F(JsRuntimeTest, JsRuntimeUpdateModuleNameAndAssetPathTest_0300, TestSize.Level0)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 */
HWTEST_F(JsRuntimeTest, JsRuntimeInitialize_0100, TestSize.Level0)734 HWTEST_F(JsRuntimeTest, JsRuntimeInitialize_0100, TestSize.Level0)
735 {
736 TAG_LOGI(AAFwkTag::TEST, "Running in multi-thread, using default thread number.");
737
738 AbilityRuntime::Runtime::Options options;
739 options.loadAce = false;
740 options.preload = true;
741 options.isStageModel = false;
742
743 auto jsRuntime = AbilityRuntime::JsRuntime::Create(options);
744 ASSERT_NE(jsRuntime, nullptr);
745 EXPECT_NE(jsRuntime->GetEcmaVm(), nullptr);
746 EXPECT_NE(jsRuntime->GetNativeEnginePointer(), nullptr);
747
748 jsRuntime.reset();
749 std::this_thread::sleep_for(std::chrono::milliseconds(200));
750 }
751
752 /**
753 * @tc.name: JsRuntimeInitialize_0200
754 * @tc.desc: preload js runtime.
755 * @tc.type: FUNC
756 * @tc.require: issueI6KODF
757 */
HWTEST_F(JsRuntimeTest, JsRuntimeInitialize_0200, TestSize.Level0)758 HWTEST_F(JsRuntimeTest, JsRuntimeInitialize_0200, TestSize.Level0)
759 {
760 AbilityRuntime::Runtime::Options options;
761 options.preload = true;
762
763 auto jsRuntime = AbilityRuntime::JsRuntime::Create(options);
764 ASSERT_NE(jsRuntime, nullptr);
765 EXPECT_NE(jsRuntime->GetEcmaVm(), nullptr);
766 EXPECT_NE(jsRuntime->GetNativeEnginePointer(), nullptr);
767 jsRuntime.reset();
768
769 options.preload = false;
770 jsRuntime = AbilityRuntime::JsRuntime::Create(options);
771 ASSERT_NE(jsRuntime, nullptr);
772 EXPECT_NE(jsRuntime->GetEcmaVm(), nullptr);
773 EXPECT_NE(jsRuntime->GetNativeEnginePointer(), nullptr);
774
775 jsRuntime.reset();
776 std::this_thread::sleep_for(std::chrono::milliseconds(200));
777 }
778
779 /**
780 * @tc.name: RegisterQuickFixQueryFunc_0100
781 * @tc.desc: JsRuntime test for RegisterQuickFixQueryFunc.
782 * @tc.type: FUNC
783 */
HWTEST_F(JsRuntimeTest, RegisterQuickFixQueryFunc_0100, TestSize.Level0)784 HWTEST_F(JsRuntimeTest, RegisterQuickFixQueryFunc_0100, TestSize.Level0)
785 {
786 TAG_LOGI(AAFwkTag::TEST, "RegisterQuickFixQueryFunc start");
787
788 auto jsRuntime = std::make_unique<JsRuntime>();
789 EXPECT_TRUE(jsRuntime != nullptr);
790 std::string moudel = "<moudelName>";
791 std::string hqfFile = "<hqfFile>";
792 std::map<std::string, std::string> moduleAndPath;
793 moduleAndPath.insert(std::make_pair(moudel, hqfFile));
794 jsRuntime->RegisterQuickFixQueryFunc(moduleAndPath);
795 jsRuntime.reset();
796 std::this_thread::sleep_for(std::chrono::milliseconds(200));
797 TAG_LOGI(AAFwkTag::TEST, "RegisterQuickFixQueryFunc end");
798 }
799
800 /**
801 * @tc.name: RegisterUncaughtExceptionHandler_0100
802 * @tc.desc: JsRuntime test for RegisterUncaughtExceptionHandler.
803 * @tc.type: FUNC
804 */
HWTEST_F(JsRuntimeTest, RegisterUncaughtExceptionHandler_0100, TestSize.Level0)805 HWTEST_F(JsRuntimeTest, RegisterUncaughtExceptionHandler_0100, TestSize.Level0)
806 {
807 TAG_LOGI(AAFwkTag::TEST, "RegisterUncaughtExceptionHandler start");
808
809 AbilityRuntime::Runtime::Options options;
810 options.preload = false;
811 auto jsRuntime = AbilityRuntime::JsRuntime::Create(options);
812
813 ASSERT_NE(jsRuntime, nullptr);
814 JsEnv::UncaughtExceptionInfo uncaughtExceptionInfo;
815 jsRuntime->RegisterUncaughtExceptionHandler(uncaughtExceptionInfo);
816 jsRuntime.reset();
817 std::this_thread::sleep_for(std::chrono::milliseconds(200));
818 TAG_LOGI(AAFwkTag::TEST, "RegisterUncaughtExceptionHandler end");
819 }
820
821 /**
822 * @tc.name: RegisterUncaughtExceptionHandler_0200
823 * @tc.desc: JsRuntime test for RegisterUncaughtExceptionHandler.
824 * @tc.type: FUNC
825 */
HWTEST_F(JsRuntimeTest, RegisterUncaughtExceptionHandler_0200, TestSize.Level0)826 HWTEST_F(JsRuntimeTest, RegisterUncaughtExceptionHandler_0200, TestSize.Level0)
827 {
828 TAG_LOGI(AAFwkTag::TEST, "RegisterUncaughtExceptionHandler start");
829
830 AbilityRuntime::Runtime::Options options;
831 options.preload = true;
832 auto jsRuntime = AbilityRuntime::JsRuntime::Create(options);
833
834 ASSERT_NE(jsRuntime, nullptr);
835 JsEnv::UncaughtExceptionInfo uncaughtExceptionInfo;
836 jsRuntime->RegisterUncaughtExceptionHandler(uncaughtExceptionInfo);
837 jsRuntime.reset();
838 std::this_thread::sleep_for(std::chrono::milliseconds(200));
839 TAG_LOGI(AAFwkTag::TEST, "RegisterUncaughtExceptionHandler end");
840 }
841
842 /**
843 * @tc.name: ReadSourceMapData_0100
844 * @tc.desc: JsRuntime test for ReadSourceMapData.
845 * @tc.type: FUNC
846 */
HWTEST_F(JsRuntimeTest, ReadSourceMapData_0100, TestSize.Level0)847 HWTEST_F(JsRuntimeTest, ReadSourceMapData_0100, TestSize.Level0)
848 {
849 TAG_LOGI(AAFwkTag::TEST, "ReadSourceMapData start");
850
851 AbilityRuntime::Runtime::Options options;
852 options.preload = true;
853 auto jsRuntime = AbilityRuntime::JsRuntime::Create(options);
854
855 ASSERT_NE(jsRuntime, nullptr);
856
857 std::string hapPath = "";
858 std::string sourceMapPath = "";
859 std::string content = "";
860 auto result = jsRuntime->ReadSourceMapData(hapPath, sourceMapPath, content);
861 ASSERT_FALSE(result);
862 jsRuntime.reset();
863 std::this_thread::sleep_for(std::chrono::milliseconds(200));
864 TAG_LOGI(AAFwkTag::TEST, "ReadSourceMapData end");
865 }
866
867 /**
868 * @tc.name: StopDebugger_0100
869 * @tc.desc: JsRuntime test for StopDebugger.
870 * @tc.type: FUNC
871 */
HWTEST_F(JsRuntimeTest, StopDebugger_0100, TestSize.Level0)872 HWTEST_F(JsRuntimeTest, StopDebugger_0100, TestSize.Level0)
873 {
874 TAG_LOGI(AAFwkTag::TEST, "StopDebugger start");
875
876 AbilityRuntime::Runtime::Options options;
877 options.preload = true;
878 auto jsRuntime = AbilityRuntime::JsRuntime::Create(options);
879
880 ASSERT_NE(jsRuntime, nullptr);
881
882 jsRuntime->StopDebugger();
883 jsRuntime.reset();
884 std::this_thread::sleep_for(std::chrono::milliseconds(200));
885 TAG_LOGI(AAFwkTag::TEST, "StopDebugger end");
886 }
887
888 /**
889 * @tc.name: GetFileBuffer_0100
890 * @tc.desc: JsRuntime test for GetFileBuffer.
891 * @tc.type: FUNC
892 */
HWTEST_F(JsRuntimeTest, GetFileBuffer_0100, TestSize.Level0)893 HWTEST_F(JsRuntimeTest, GetFileBuffer_0100, TestSize.Level0)
894 {
895 TAG_LOGI(AAFwkTag::TEST, "GetFileBuffer start");
896
897 AbilityRuntime::Runtime::Options options;
898 options.preload = true;
899 auto jsRuntime = AbilityRuntime::JsRuntime::Create(options);
900
901 ASSERT_NE(jsRuntime, nullptr);
902
903 std::string filePath = "";
904 std::string fileFullName = "";
905 std::vector<uint8_t> buffer;
906 jsRuntime->GetFileBuffer(filePath, fileFullName, buffer);
907 jsRuntime.reset();
908 std::this_thread::sleep_for(std::chrono::milliseconds(200));
909 TAG_LOGI(AAFwkTag::TEST, "GetFileBuffer end");
910 }
911
912 /**
913 * @tc.name: GetFileBuffer_0200
914 * @tc.desc: JsRuntime test for GetFileBuffer.
915 * @tc.type: FUNC
916 */
HWTEST_F(JsRuntimeTest, GetFileBuffer_0200, TestSize.Level0)917 HWTEST_F(JsRuntimeTest, GetFileBuffer_0200, TestSize.Level0)
918 {
919 TAG_LOGI(AAFwkTag::TEST, "GetFileBuffer start");
920
921 AbilityRuntime::Runtime::Options options;
922 options.preload = true;
923 auto jsRuntime = AbilityRuntime::JsRuntime::Create(options);
924
925 ASSERT_NE(jsRuntime, nullptr);
926
927 std::string filePath = "";
928 std::string fileFullName = "";
929 std::vector<uint8_t> buffer;
930 jsRuntime->GetFileBuffer(filePath, fileFullName, buffer, false);
931 jsRuntime.reset();
932 std::this_thread::sleep_for(std::chrono::milliseconds(200));
933 TAG_LOGI(AAFwkTag::TEST, "GetFileBuffer end");
934 }
935
936 /**
937 * @tc.name: JsRuntimeRunScriptTest_0100
938 * @tc.desc: JsRuntime test for RunScript.
939 * @tc.type: FUNC
940 */
HWTEST_F(JsRuntimeTest, JsRuntimeRunScriptTest_0100, TestSize.Level0)941 HWTEST_F(JsRuntimeTest, JsRuntimeRunScriptTest_0100, TestSize.Level0)
942 {
943 TAG_LOGI(AAFwkTag::TEST, "RunScript start");
944
945 AbilityRuntime::Runtime::Options options;
946 options.preload = false;
947 auto jsRuntime = AbilityRuntime::JsRuntime::Create(options);
948
949 std::string srcPath = TEST_MODULE_PATH;
950 std::string hapPath = TEST_HAP_PATH;
951 jsRuntime->RunScript(srcPath, hapPath);
952 ASSERT_NE(jsRuntime, nullptr);
953
954 jsRuntime.reset();
955 std::this_thread::sleep_for(std::chrono::milliseconds(200));
956 TAG_LOGI(AAFwkTag::TEST, "RunScript end");
957 }
958
959 /**
960 * @tc.name: JsRuntimeLoadScriptTest_0100
961 * @tc.desc: JsRuntime test for LoadScript.
962 * @tc.type: FUNC
963 */
HWTEST_F(JsRuntimeTest, JsRuntimeLoadScriptTest_0100, TestSize.Level0)964 HWTEST_F(JsRuntimeTest, JsRuntimeLoadScriptTest_0100, TestSize.Level0)
965 {
966 AbilityRuntime::Runtime::Options options;
967 options.preload = false;
968 auto jsRuntime = AbilityRuntime::JsRuntime::Create(options);
969
970 std::string path = "/system/etc/strip.native.min.abc";
971 jsRuntime->LoadScript(path);
972 ASSERT_NE(jsRuntime, nullptr);
973 jsRuntime.reset();
974 std::this_thread::sleep_for(std::chrono::milliseconds(200));
975 }
976
977 /**
978 * @tc.name: JsRuntimeStopDebuggerTest_0100
979 * @tc.desc: JsRuntime test for StopDebugger.
980 * @tc.type: FUNC
981 */
HWTEST_F(JsRuntimeTest, JsRuntimeStopDebuggerTest_0100, TestSize.Level0)982 HWTEST_F(JsRuntimeTest, JsRuntimeStopDebuggerTest_0100, TestSize.Level0)
983 {
984 AbilityRuntime::Runtime::Options options;
985 options.preload = false;
986 auto jsRuntime = AbilityRuntime::JsRuntime::Create(options);
987 ASSERT_NE(jsRuntime, nullptr);
988
989 jsRuntime->StopDebugger();
990 jsRuntime.reset();
991 std::this_thread::sleep_for(std::chrono::milliseconds(200));
992 }
993
994 /**
995 * @tc.name: PostSyncTask_0100
996 * @tc.desc: Js runtime post sync task.
997 * @tc.type: FUNC
998 * @tc.require: issueI7C87T
999 */
HWTEST_F(JsRuntimeTest, PostSyncTask_0100, TestSize.Level0)1000 HWTEST_F(JsRuntimeTest, PostSyncTask_0100, TestSize.Level0)
1001 {
1002 auto jsRuntime = AbilityRuntime::JsRuntime::Create(options_);
1003 ASSERT_NE(jsRuntime, nullptr);
1004
1005 std::string taskName = "syncTask001";
1006 bool taskExecuted = false;
1007 auto task = [taskName, &taskExecuted]() {
1008 TAG_LOGI(AAFwkTag::TEST, "%{public}s called.", taskName.c_str());
1009 taskExecuted = true;
1010 };
1011 jsRuntime->PostSyncTask(task, taskName);
1012 EXPECT_EQ(taskExecuted, true);
1013 jsRuntime.reset();
1014 std::this_thread::sleep_for(std::chrono::milliseconds(200));
1015 }
1016
1017 /**
1018 * @tc.name: ReInitJsEnvImpl_0100
1019 * @tc.desc: Js runtime reinit js env impl.
1020 * @tc.type: FUNC
1021 * @tc.require: issueI7C87T
1022 */
HWTEST_F(JsRuntimeTest, ReInitJsEnvImpl_0100, TestSize.Level1)1023 HWTEST_F(JsRuntimeTest, ReInitJsEnvImpl_0100, TestSize.Level1)
1024 {
1025 auto jsRuntime = std::make_unique<JsRuntime>();
1026 EXPECT_TRUE(jsRuntime != nullptr);
1027
1028 // called when jsEnv is invalid.
1029 jsRuntime->ReInitJsEnvImpl(options_);
1030
1031 auto ret = jsRuntime->CreateJsEnv(options_);
1032 EXPECT_EQ(ret, true);
1033 jsRuntime->ReInitJsEnvImpl(options_);
1034 jsRuntime.reset();
1035 std::this_thread::sleep_for(std::chrono::milliseconds(200));
1036 }
1037
1038 /**
1039 * @tc.name: JsRuntimeStartProfilerTest_0100
1040 * @tc.desc: JsRuntime test for StartProfiler.
1041 * @tc.type: FUNC
1042 */
HWTEST_F(JsRuntimeTest, JsRuntimeStartProfilerTest_0100, TestSize.Level1)1043 HWTEST_F(JsRuntimeTest, JsRuntimeStartProfilerTest_0100, TestSize.Level1)
1044 {
1045 auto jsRuntime = AbilityRuntime::JsRuntime::Create(options_);
1046
1047 bool needBreakPoint = false;
1048 uint32_t instanceId = 1;
1049 jsRuntime->StartDebugger(needBreakPoint, instanceId);
1050
1051 AbilityRuntime::Runtime::DebugOption debugOption;
1052 debugOption.perfCmd = "profile jsperf 100";
1053 debugOption.isStartWithDebug = false;
1054 debugOption.processName = "test";
1055 debugOption.isDebugApp = true;
1056 debugOption.isStartWithNative = false;
1057 jsRuntime->StartProfiler(debugOption);
1058 ASSERT_NE(jsRuntime, nullptr);
1059 jsRuntime.reset();
1060 }
1061
1062 /**
1063 * @tc.name: PostTask_0100
1064 * @tc.desc: Js runtime post task.
1065 * @tc.type: FUNC
1066 * @tc.require: issueI7C87T
1067 */
HWTEST_F(JsRuntimeTest, PostTask_0100, TestSize.Level0)1068 HWTEST_F(JsRuntimeTest, PostTask_0100, TestSize.Level0)
1069 {
1070 TAG_LOGI(AAFwkTag::TEST, "PostTask_0100 start");
1071 auto jsRuntime = AbilityRuntime::JsRuntime::Create(options_);
1072 ASSERT_NE(jsRuntime, nullptr);
1073
1074 std::string taskName = "postTask001";
1075 bool taskExecuted = false;
1076 auto task = [taskName, &taskExecuted]() {
1077 TAG_LOGI(AAFwkTag::TEST, "%{public}s called.", taskName.c_str());
1078 taskExecuted = true;
1079 };
1080 int64_t delayTime = 10;
1081 jsRuntime->PostTask(task, taskName, delayTime);
1082 EXPECT_NE(taskExecuted, true);
1083 TAG_LOGI(AAFwkTag::TEST, "PostTask_0100 end");
1084 }
1085
1086 /**
1087 * @tc.name: RemoveTask_0100
1088 * @tc.desc: Js runtime remove task.
1089 * @tc.type: FUNC
1090 * @tc.require: issueI7C87T
1091 */
HWTEST_F(JsRuntimeTest, RemoveTask_0100, TestSize.Level0)1092 HWTEST_F(JsRuntimeTest, RemoveTask_0100, TestSize.Level0)
1093 {
1094 TAG_LOGI(AAFwkTag::TEST, "RemoveTask_0100 start");
1095 auto jsRuntime = AbilityRuntime::JsRuntime::Create(options_);
1096 ASSERT_NE(jsRuntime, nullptr);
1097
1098 std::string taskName = "removeTask001";
1099 bool taskExecuted = false;
1100 auto task = [taskName, &taskExecuted]() {
1101 TAG_LOGI(AAFwkTag::TEST, "%{public}s called.", taskName.c_str());
1102 taskExecuted = true;
1103 };
1104 int64_t delayTime = 10;
1105 jsRuntime->PostTask(task, taskName, delayTime);
1106 jsRuntime->RemoveTask(taskName);
1107 EXPECT_NE(taskExecuted, true);
1108 TAG_LOGI(AAFwkTag::TEST, "RemoveTask_0100 end");
1109 }
1110
1111 /**
1112 * @tc.name: StartDebugger_0100
1113 * @tc.desc: JsRuntime test for StartDebugger.
1114 * @tc.type: FUNC
1115 */
HWTEST_F(JsRuntimeTest, StartDebugger_0100, TestSize.Level0)1116 HWTEST_F(JsRuntimeTest, StartDebugger_0100, TestSize.Level0)
1117 {
1118 TAG_LOGI(AAFwkTag::TEST, "StartDebugger_0100 start");
1119
1120 AbilityRuntime::Runtime::Options options;
1121 options.preload = true;
1122 auto jsRuntime = AbilityRuntime::JsRuntime::Create(options);
1123
1124 ASSERT_NE(jsRuntime, nullptr);
1125
1126 bool needBreakPoint = false;
1127 uint32_t instanceId = 1;
1128
1129 jsRuntime->StartDebugger(needBreakPoint, instanceId);
1130 // debug mode is global option, maybe has started by other testcase, not check here.
1131 TAG_LOGI(AAFwkTag::TEST, "StartDebugger_0100 end");
1132 }
1133
1134 /**
1135 * @tc.name: ReloadFormComponent_0100
1136 * @tc.desc: JsRuntime test for ReloadFormComponent.
1137 * @tc.type: FUNC
1138 */
HWTEST_F(JsRuntimeTest, ReloadFormComponent_0100, TestSize.Level0)1139 HWTEST_F(JsRuntimeTest, ReloadFormComponent_0100, TestSize.Level0)
1140 {
1141 TAG_LOGI(AAFwkTag::TEST, "ReloadFormComponent_0100 start");
1142
1143 AbilityRuntime::Runtime::Options options;
1144 options.preload = true;
1145 auto jsRuntime = AbilityRuntime::JsRuntime::Create(options);
1146
1147 ASSERT_NE(jsRuntime, nullptr);
1148
1149 jsRuntime->ReloadFormComponent();
1150 jsRuntime.reset();
1151 TAG_LOGI(AAFwkTag::TEST, "ReloadFormComponent_0100 end");
1152 }
1153
1154 /**
1155 * @tc.name: SetRequestAotCallback_0100
1156 * @tc.desc: JsRuntime test for SetRequestAotCallback.
1157 * @tc.type: FUNC
1158 * @tc.require: issueI82L1A
1159 */
HWTEST_F(JsRuntimeTest, SetRequestAotCallback_0100, TestSize.Level0)1160 HWTEST_F(JsRuntimeTest, SetRequestAotCallback_0100, TestSize.Level0)
1161 {
1162 TAG_LOGI(AAFwkTag::TEST, "start");
1163
1164 AbilityRuntime::Runtime::Options options;
1165 options.preload = true;
1166 auto jsRuntime = AbilityRuntime::JsRuntime::Create(options);
1167 ASSERT_NE(jsRuntime, nullptr);
1168
1169 jsRuntime->SetRequestAotCallback();
1170 auto ret = panda::MockJSNApi::GetInstance()->RequestAot("bundleName", "moduleName", 0);
1171 EXPECT_NE(ret, -1);
1172 jsRuntime.reset();
1173 TAG_LOGI(AAFwkTag::TEST, "finish");
1174 }
1175
1176 /**
1177 * @tc.name: DestroyHeapProfiler_0100
1178 * @tc.desc: JsRuntime test for DestroyHeapProfiler.
1179 * @tc.type: FUNC
1180 */
HWTEST_F(JsRuntimeTest, DestroyHeapProfiler_0100, TestSize.Level0)1181 HWTEST_F(JsRuntimeTest, DestroyHeapProfiler_0100, TestSize.Level0)
1182 {
1183 TAG_LOGI(AAFwkTag::TEST, "DestroyHeapProfiler_0100 start");
1184
1185 AbilityRuntime::Runtime::Options options;
1186 options.preload = true;
1187 auto jsRuntime = AbilityRuntime::JsRuntime::Create(options);
1188
1189 jsRuntime->DestroyHeapProfiler();
1190 ASSERT_NE(jsRuntime, nullptr);
1191 jsRuntime.reset();
1192 TAG_LOGI(AAFwkTag::TEST, "DestroyHeapProfiler_0100 end");
1193 }
1194
1195 /**
1196 * @tc.name: ForceFullGC_0100
1197 * @tc.desc: JsRuntime test for ForceFullGC.
1198 * @tc.type: FUNC
1199 */
HWTEST_F(JsRuntimeTest, ForceFullGC_0100, TestSize.Level0)1200 HWTEST_F(JsRuntimeTest, ForceFullGC_0100, TestSize.Level0)
1201 {
1202 TAG_LOGI(AAFwkTag::TEST, "ForceFullGC_0100 start");
1203
1204 AbilityRuntime::Runtime::Options options;
1205 options.preload = true;
1206 auto jsRuntime = AbilityRuntime::JsRuntime::Create(options);
1207
1208 jsRuntime->ForceFullGC();
1209 ASSERT_NE(jsRuntime, nullptr);
1210 jsRuntime.reset();
1211 TAG_LOGI(AAFwkTag::TEST, "ForceFullGC_0100 end");
1212 }
1213
1214 /**
1215 * @tc.name: AllowCrossThreadExecution_0100
1216 * @tc.desc: JsRuntime test for AllowCrossThreadExecution.
1217 * @tc.type: FUNC
1218 */
HWTEST_F(JsRuntimeTest, AllowCrossThreadExecution_0100, TestSize.Level0)1219 HWTEST_F(JsRuntimeTest, AllowCrossThreadExecution_0100, TestSize.Level0)
1220 {
1221 TAG_LOGI(AAFwkTag::TEST, "AllowCrossThreadExecution_0100 start");
1222
1223 AbilityRuntime::Runtime::Options options;
1224 options.preload = true;
1225 auto jsRuntime = AbilityRuntime::JsRuntime::Create(options);
1226
1227 jsRuntime->AllowCrossThreadExecution();
1228 ASSERT_NE(jsRuntime, nullptr);
1229 TAG_LOGI(AAFwkTag::TEST, "AllowCrossThreadExecution_0100 end");
1230 }
1231
1232 /**
1233 * @tc.name: GetHeapPrepare_0100
1234 * @tc.desc: JsRuntime test for GetHeapPrepare.
1235 * @tc.type: FUNC
1236 */
HWTEST_F(JsRuntimeTest, GetHeapPrepare_0100, TestSize.Level0)1237 HWTEST_F(JsRuntimeTest, GetHeapPrepare_0100, TestSize.Level0)
1238 {
1239 TAG_LOGI(AAFwkTag::TEST, "GetHeapPrepare_0100 start");
1240
1241 AbilityRuntime::Runtime::Options options;
1242 options.preload = true;
1243 auto jsRuntime = AbilityRuntime::JsRuntime::Create(options);
1244
1245 jsRuntime->GetHeapPrepare();
1246 ASSERT_NE(jsRuntime, nullptr);
1247 TAG_LOGI(AAFwkTag::TEST, "GetHeapPrepare_0100 end");
1248 }
1249
1250 /**
1251 * @tc.name: InitLoop_0100
1252 * @tc.desc: JsRuntime test for InitLoop.
1253 * @tc.type: FUNC
1254 */
HWTEST_F(JsRuntimeTest, InitLoop_0100, TestSize.Level0)1255 HWTEST_F(JsRuntimeTest, InitLoop_0100, TestSize.Level0)
1256 {
1257 TAG_LOGI(AAFwkTag::TEST, "InitLoop_0100 start");
1258
1259 AbilityRuntime::Runtime::Options options;
1260 options.preload = true;
1261 auto jsRuntime = AbilityRuntime::JsRuntime::Create(options);
1262
1263 auto result = jsRuntime->InitLoop();
1264 ASSERT_EQ(result, true);
1265 jsRuntime.reset();
1266 TAG_LOGI(AAFwkTag::TEST, "InitLoop_0100 end");
1267 }
1268
1269 /**
1270 * @tc.name: InitSourceMap_0100
1271 * @tc.desc: JsRuntime test for InitSourceMap.
1272 * @tc.type: FUNC
1273 */
HWTEST_F(JsRuntimeTest, InitSourceMap_0100, TestSize.Level0)1274 HWTEST_F(JsRuntimeTest, InitSourceMap_0100, TestSize.Level0)
1275 {
1276 TAG_LOGI(AAFwkTag::TEST, "InitSourceMap_0100 start");
1277
1278 AbilityRuntime::Runtime::Options options;
1279 options.preload = true;
1280 auto jsRuntime = AbilityRuntime::JsRuntime::Create(options);
1281 auto operatorObj = std::make_shared<JsEnv::SourceMapOperator>("", true, true);
1282 jsRuntime->InitSourceMap(operatorObj);
1283 ASSERT_NE(jsRuntime, nullptr);
1284 jsRuntime.reset();
1285 TAG_LOGI(AAFwkTag::TEST, "InitSourceMap_0100 end");
1286 }
1287
1288 /**
1289 * @tc.name: Deinitialize_0100
1290 * @tc.desc: JsRuntime test for Deinitialize.
1291 * @tc.type: FUNC
1292 */
HWTEST_F(JsRuntimeTest, Deinitialize_0100, TestSize.Level0)1293 HWTEST_F(JsRuntimeTest, Deinitialize_0100, TestSize.Level0)
1294 {
1295 TAG_LOGI(AAFwkTag::TEST, "Deinitialize_0100 start");
1296
1297 AbilityRuntime::Runtime::Options options;
1298 options.preload = true;
1299 auto jsRuntime = AbilityRuntime::JsRuntime::Create(options);
1300
1301 jsRuntime->Deinitialize();
1302 ASSERT_NE(jsRuntime, nullptr);
1303 jsRuntime.reset();
1304 TAG_LOGI(AAFwkTag::TEST, "Deinitialize_0100 end");
1305 }
1306
1307 /**
1308 * @tc.name: GetPkgContextInfoListMap_0100
1309 * @tc.desc: JsRuntime test for GetPkgContextInfoListMap.
1310 * @tc.type: FUNC
1311 */
HWTEST_F(JsRuntimeTest, GetPkgContextInfoListMap_0100, TestSize.Level0)1312 HWTEST_F(JsRuntimeTest, GetPkgContextInfoListMap_0100, TestSize.Level0)
1313 {
1314 TAG_LOGI(AAFwkTag::TEST, "GetPkgContextInfoListMap_0100 start");
1315
1316 std::map<std::string, std::string> modulePkgContentMap;
1317 std::string pkgContentJsonString = R"({"library": {"packageName": "library", "bundleName": "com.xxx.xxxx",
1318 "moduleName": "library", "version": "1.0.0", "entryPath": "", "isSO": false}})";
1319 modulePkgContentMap["entry"] = pkgContentJsonString;
1320
1321 AbilityRuntime::Runtime::Options options;
1322 options.preload = true;
1323 auto jsRuntime = AbilityRuntime::JsRuntime::Create(options);
1324 std::map<std::string, std::vector<std::vector<std::string>>> ret;
1325 std::map<std::string, std::string> pkgAliasMap;
1326 JsRuntimeLite::GetInstance().GetPkgContextInfoListMap(modulePkgContentMap, ret, pkgAliasMap);
1327 std::string expectString = "library:packageName:library:bundleName:";
1328 expectString += "com.xxx.xxxx:moduleName:library:version:1.0.0:entryPath::isSO:false:";
1329 auto it = ret.find("entry");
1330 ASSERT_EQ(it, ret.end());
1331 std::string pkgRetString;
1332 for (const auto& vec : it->second) {
1333 for (const auto& str : vec) {
1334 pkgRetString += str + ":";
1335 }
1336 }
1337 ASSERT_EQ(pkgRetString, "");
1338 TAG_LOGI(AAFwkTag::TEST, "GetPkgContextInfoListMap_0100 end");
1339 }
1340
1341 /**
1342 * @tc.name: GetPkgContextInfoListMap_0200
1343 * @tc.desc: JsRuntime test for GetPkgContextInfoListMap.
1344 * @tc.type: FUNC
1345 */
HWTEST_F(JsRuntimeTest, GetPkgContextInfoListMap_0200, TestSize.Level0)1346 HWTEST_F(JsRuntimeTest, GetPkgContextInfoListMap_0200, TestSize.Level0)
1347 {
1348 TAG_LOGI(AAFwkTag::TEST, "GetPkgContextInfoListMap_0200 start");
1349
1350 std::map<std::string, std::string> modulePkgContentMap;
1351 std::string pkgContentJsonString = R"({"library": {"packageName": "library", "bundleName":
1352 "com.xxx.xxxx", "moduleName": "library", "version": "1.0.0", "entryPath": "", "isSO": false}})";
1353 modulePkgContentMap["entry"] = pkgContentJsonString;
1354
1355 std::string libraryString = R"({"library": {"packageName": "library","bundleName": "com.xxx.xxxx", "moduleName":
1356 "library", "version": "1.0.0", "entryPath": "", "isSO": false}})";
1357 modulePkgContentMap["library"] = libraryString;
1358
1359 AbilityRuntime::Runtime::Options options;
1360 options.preload = true;
1361 auto jsRuntime = AbilityRuntime::JsRuntime::Create(options);
1362 std::map<std::string, std::vector<std::vector<std::string>>> ret;
1363 std::map<std::string, std::string> pkgAliasMap;
1364 JsRuntimeLite::GetInstance().GetPkgContextInfoListMap(modulePkgContentMap, ret, pkgAliasMap);
1365 std::string expectString = "library:packageName:library:bundleName:";
1366 expectString += "com.xxx.xxxx:moduleName:library:version:1.0.0:entryPath::isSO:false:";
1367 auto it = ret.find("entry");
1368 ASSERT_EQ(it, ret.end());
1369 auto libraryIt = ret.find("library");
1370 ASSERT_EQ(libraryIt, ret.end());
1371 std::string pkgRetString;
1372 for (const auto& vec : it->second) {
1373 for (const auto& str : vec) {
1374 pkgRetString += str + ":";
1375 }
1376 }
1377 ASSERT_EQ(pkgRetString, "");
1378 TAG_LOGI(AAFwkTag::TEST, "GetPkgContextInfoListMap_0200 end");
1379 }
1380
1381 /**
1382 * @tc.name: CreateJsEnv_0100
1383 * @tc.desc: JsRuntime test for CreateJsEnv.
1384 * @tc.type: FUNC
1385 * @tc.require: issueI9CHSB
1386 */
HWTEST_F(JsRuntimeTest, CreateJsEnv_0100, TestSize.Level1)1387 HWTEST_F(JsRuntimeTest, CreateJsEnv_0100, TestSize.Level1)
1388 {
1389 auto jsRuntime = std::make_unique<JsRuntime>();
1390 auto ret = jsRuntime->CreateJsEnv(options_);
1391 EXPECT_EQ(ret, true);
1392 }
1393
1394 /**
1395 * @tc.name: DumpCpuProfile_0100
1396 * @tc.desc: JsRuntime test for DumpCpuProfile.
1397 * @tc.type: FUNC
1398 */
HWTEST_F(JsRuntimeTest, DumpCpuProfile_0100, TestSize.Level1)1399 HWTEST_F(JsRuntimeTest, DumpCpuProfile_0100, TestSize.Level1)
1400 {
1401 auto jsRuntime = std::make_unique<JsRuntime>();
1402 bool isPrivate = true;
1403 jsRuntime->DumpCpuProfile();
1404 EXPECT_TRUE(jsRuntime != nullptr);
1405 }
1406
1407 /**
1408 * @tc.name: DumpHeapSnapshot_0100
1409 * @tc.desc: JsRuntime test for DumpHeapSnapshot.
1410 * @tc.type: FUNC
1411 */
HWTEST_F(JsRuntimeTest, DumpHeapSnapshot_0100, TestSize.Level1)1412 HWTEST_F(JsRuntimeTest, DumpHeapSnapshot_0100, TestSize.Level1)
1413 {
1414 auto jsRuntime = std::make_unique<JsRuntime>();
1415 bool isPrivate = true;
1416 jsRuntime->DumpHeapSnapshot(isPrivate);
1417 EXPECT_TRUE(jsRuntime != nullptr);
1418 }
1419
1420 /**
1421 * @tc.name: DumpHeapSnapshot_0200
1422 * @tc.desc: JsRuntime test for DumpHeapSnapshot.
1423 * @tc.type: FUNC
1424 */
HWTEST_F(JsRuntimeTest, DumpHeapSnapshot_0200, TestSize.Level1)1425 HWTEST_F(JsRuntimeTest, DumpHeapSnapshot_0200, TestSize.Level1)
1426 {
1427 auto jsRuntime = std::make_unique<JsRuntime>();
1428 uint32_t tid = 1;
1429 bool isFullGC = true;
1430 jsRuntime->DumpHeapSnapshot(tid, isFullGC);
1431 EXPECT_TRUE(jsRuntime != nullptr);
1432 }
1433
1434 /**
1435 * @tc.name: AllowCrossThreadExecution_0200
1436 * @tc.desc: JsRuntime test for AllowCrossThreadExecution.
1437 * @tc.type: FUNC
1438 */
HWTEST_F(JsRuntimeTest, AllowCrossThreadExecution_0200, TestSize.Level1)1439 HWTEST_F(JsRuntimeTest, AllowCrossThreadExecution_0200, TestSize.Level1)
1440 {
1441 auto jsRuntime = std::make_unique<JsRuntime>();
1442 jsRuntime->AllowCrossThreadExecution();
1443 EXPECT_TRUE(jsRuntime != nullptr);
1444 }
1445
1446 /**
1447 * @tc.name: GetHeapPrepare_0200
1448 * @tc.desc: JsRuntime test for GetHeapPrepare.
1449 * @tc.type: FUNC
1450 */
HWTEST_F(JsRuntimeTest, GetHeapPrepare_0200, TestSize.Level1)1451 HWTEST_F(JsRuntimeTest, GetHeapPrepare_0200, TestSize.Level1)
1452 {
1453 auto jsRuntime = std::make_unique<JsRuntime>();
1454 jsRuntime->GetHeapPrepare();
1455 EXPECT_TRUE(jsRuntime != nullptr);
1456 }
1457
1458 /**
1459 * @tc.name: RegisterQuickFixQueryFunc_0200
1460 * @tc.desc: JsRuntime test for RegisterQuickFixQueryFunc.
1461 * @tc.type: FUNC
1462 */
HWTEST_F(JsRuntimeTest, RegisterQuickFixQueryFunc_0200, TestSize.Level1)1463 HWTEST_F(JsRuntimeTest, RegisterQuickFixQueryFunc_0200, TestSize.Level1)
1464 {
1465 auto jsRuntime = std::make_unique<JsRuntime>();
1466 std::map<std::string, std::string> moduleAndPath;
1467 jsRuntime->RegisterQuickFixQueryFunc(moduleAndPath);
1468 EXPECT_TRUE(jsRuntime != nullptr);
1469 }
1470
1471 /**
1472 * @tc.name: UpdatePkgContextInfoJson_0100
1473 * @tc.desc: JsRuntime test for UpdatePkgContextInfoJson.
1474 * @tc.type: FUNC
1475 */
HWTEST_F(JsRuntimeTest, UpdatePkgContextInfoJson_0100, TestSize.Level1)1476 HWTEST_F(JsRuntimeTest, UpdatePkgContextInfoJson_0100, TestSize.Level1)
1477 {
1478 auto jsRuntime = std::make_unique<JsRuntime>();
1479 EXPECT_NE(jsRuntime, nullptr);
1480 std::string moduleName = "moduleName";
1481 jsRuntime->pkgContextInfoJsonStringMap_.insert(std::make_pair(moduleName, "test2"));
1482 std::string hapPath = TEST_HAP_PATH;
1483 std::string packageName = "packageName";
1484 jsRuntime->UpdatePkgContextInfoJson(moduleName, hapPath, packageName);
1485 EXPECT_EQ(jsRuntime->pkgContextInfoJsonStringMap_[moduleName], "test2");
1486 }
1487 } // namespace AbilityRuntime
1488 } // namespace OHOS
1489