1 /*
2 * Copyright (c) 2023-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 #define private public
17 #include "js_environment.h"
18 #undef private
19
20 #include <gtest/gtest.h>
21 #include <gtest/hwext/gtest-multithread.h>
22 #include <cstdarg>
23 #include <string>
24
25 #include "ecmascript/napi/include/jsnapi.h"
26 #include "ohos_js_env_logger.h"
27 #include "ohos_js_environment_impl.h"
28 #include "worker_info.h"
29
30 using namespace testing;
31 using namespace testing::ext;
32 using namespace testing::mt;
33
34 namespace {
35 bool callbackModuleFlag;
36 }
37
38 namespace OHOS {
39 namespace JsEnv {
40 class JsEnvironmentTest : public testing::Test {
41 public:
42 static void SetUpTestCase();
43 static void TearDownTestCase();
44 void SetUp() override;
45 void TearDown() override;
46 };
47
SetUpTestCase()48 void JsEnvironmentTest::SetUpTestCase()
49 {
50 AbilityRuntime::OHOSJsEnvLogger::RegisterJsEnvLogger();
51 }
52
TearDownTestCase()53 void JsEnvironmentTest::TearDownTestCase()
54 {}
55
SetUp()56 void JsEnvironmentTest::SetUp()
57 {}
58
TearDown()59 void JsEnvironmentTest::TearDown()
60 {}
61
62 namespace {
CallBackModuleFunc()63 void CallBackModuleFunc()
64 {
65 callbackModuleFlag = true;
66 }
67 }
68
69 /**
70 * @tc.name: JsEnvInitialize_0100
71 * @tc.desc: Initialize js environment.
72 * @tc.type: FUNC
73 * @tc.require: issueI6KODF
74 */
75 HWTEST_F(JsEnvironmentTest, JsEnvInitialize_0100, TestSize.Level0)
76 {
77 auto jsEnv = std::make_shared<JsEnvironment>(std::make_unique<AbilityRuntime::OHOSJsEnvironmentImpl>());
78 ASSERT_NE(jsEnv, nullptr);
79 ASSERT_EQ(jsEnv->GetVM(), nullptr);
80 ASSERT_EQ(jsEnv->GetNativeEngine(), nullptr);
81
82 panda::RuntimeOption pandaOption;
83 auto ret = jsEnv->Initialize(pandaOption, static_cast<void*>(this));
84 ASSERT_EQ(ret, true);
85
86 auto vm = jsEnv->GetVM();
87 EXPECT_NE(vm, nullptr);
88
89 auto nativeEngine = jsEnv->GetNativeEngine();
90 EXPECT_NE(nativeEngine, nullptr);
91 }
92
93 /**
94 * @tc.name: JsEnvInitialize_0200
95 * @tc.desc: Initialize js environment in multi thread.
96 * @tc.type: FUNC
97 * @tc.require: issueI6KODF
98 */
99 HWTEST_F(JsEnvironmentTest, JsEnvInitialize_0200, TestSize.Level0)
100 {
101 auto jsEnv = std::make_shared<JsEnvironment>(std::make_unique<AbilityRuntime::OHOSJsEnvironmentImpl>());
102 ASSERT_NE(jsEnv, nullptr);
103
104 panda::RuntimeOption pandaOption;
105 ASSERT_EQ(jsEnv->Initialize(pandaOption, nullptr), true);
106 EXPECT_NE(jsEnv->GetVM(), nullptr);
107 EXPECT_NE(jsEnv->GetNativeEngine(), nullptr);
108 }
109
110 /**
111 * @tc.name: LoadScript_0100
112 * @tc.desc: load script with invalid engine.
113 * @tc.type: FUNC
114 * @tc.require: issueI6KODF
115 */
116 HWTEST_F(JsEnvironmentTest, LoadScript_0100, TestSize.Level2)
117 {
118 auto jsEnv = std::make_shared<JsEnvironment>(std::make_unique<AbilityRuntime::OHOSJsEnvironmentImpl>());
119 ASSERT_NE(jsEnv, nullptr);
120
121 EXPECT_EQ(jsEnv->LoadScript(""), false);
122 }
123
124 /**
125 * @tc.name: LoadScript_0200
126 * @tc.desc: load script with specify path.
127 * @tc.type: FUNC
128 * @tc.require: issueI6KODF
129 */
130 HWTEST_F(JsEnvironmentTest, LoadScript_0200, TestSize.Level2)
131 {
132 auto jsEnv = std::make_shared<JsEnvironment>(std::make_unique<AbilityRuntime::OHOSJsEnvironmentImpl>());
133 ASSERT_NE(jsEnv, nullptr);
134
135 panda::RuntimeOption pandaOption;
136 auto ret = jsEnv->Initialize(pandaOption, static_cast<void*>(this));
137 ASSERT_EQ(ret, true);
138
139 EXPECT_EQ(jsEnv->LoadScript("/system/etc/strip.native.min.abc"), true);
140 }
141
142 /**
143 * @tc.name: JsEnvInitTimerModule_0100
144 * @tc.desc: Initialize timer module.
145 * @tc.type: FUNC
146 * @tc.require: issueI6Z5M5
147 */
148 HWTEST_F(JsEnvironmentTest, JsEnvInitTimerModule_0100, TestSize.Level2)
149 {
150 auto jsEnv = std::make_shared<JsEnvironment>(std::make_unique<AbilityRuntime::OHOSJsEnvironmentImpl>());
151 ASSERT_NE(jsEnv, nullptr);
152
153 // Init timer module when native engine is invalid.
154 jsEnv->InitTimerModule();
155
156 panda::RuntimeOption pandaOption;
157 auto ret = jsEnv->Initialize(pandaOption, static_cast<void*>(this));
158 ASSERT_EQ(ret, true);
159
160 // Init timer module when native engine has created.
161 jsEnv->InitTimerModule();
162 }
163
164 /**
165 * @tc.name: PostTask_0100
166 * @tc.desc: PostTask
167 * @tc.type: FUNC
168 * @tc.require: issue
169 */
170 HWTEST_F(JsEnvironmentTest, PostTask_0100, TestSize.Level2)
171 {
172 auto jsEnv = std::make_shared<JsEnvironment>(std::make_unique<AbilityRuntime::OHOSJsEnvironmentImpl>());
173 ASSERT_NE(jsEnv, nullptr);
174
175 // Init timer module when native engine is invalid.
176 std::function<void()> task = CallBackModuleFunc;
177 std::string name = "NAME";
178 int64_t delayTime = 10;
179 jsEnv->PostTask(task, name, delayTime);
180 }
181
182 /**
183 * @tc.name: RemoveTask_0100
184 * @tc.desc: RemoveTask
185 * @tc.type: FUNC
186 * @tc.require: issue
187 */
188 HWTEST_F(JsEnvironmentTest, RemoveTask_0100, TestSize.Level2)
189 {
190 auto jsEnv = std::make_shared<JsEnvironment>(std::make_unique<AbilityRuntime::OHOSJsEnvironmentImpl>());
191 ASSERT_NE(jsEnv, nullptr);
192
193 std::string name = "NAME";
194 jsEnv->RemoveTask(name);
195 }
196
197 /**
198 * @tc.name: InitSyscapModule_0100
199 * @tc.desc: InitSyscapModule
200 * @tc.type: FUNC
201 * @tc.require: issue
202 */
203 HWTEST_F(JsEnvironmentTest, InitSyscapModule_0100, TestSize.Level2)
204 {
205 auto jsEnv = std::make_shared<JsEnvironment>(std::make_unique<AbilityRuntime::OHOSJsEnvironmentImpl>());
206 ASSERT_NE(jsEnv, nullptr);
207
208 jsEnv->InitSyscapModule();
209 }
210
211 /**
212 * @tc.name: RegisterUncaughtExceptionHandler_0100
213 * @tc.desc: RegisterUncaughtExceptionHandler
214 * @tc.type: FUNC
215 * @tc.require: issue
216 */
217 HWTEST_F(JsEnvironmentTest, RegisterUncaughtExceptionHandler_0100, TestSize.Level2)
218 {
219 auto jsEnv = std::make_shared<JsEnvironment>(std::make_unique<AbilityRuntime::OHOSJsEnvironmentImpl>());
220 ASSERT_NE(jsEnv, nullptr);
221
222 JsEnv::UncaughtExceptionInfo uncaughtExceptionInfo;
223 jsEnv->RegisterUncaughtExceptionHandler(uncaughtExceptionInfo);
224 }
225
226 /**
227 * @tc.name: StartDebugger_0100
228 * @tc.desc: StartDebugger
229 * @tc.type: FUNC
230 * @tc.require: issue
231 */
232 HWTEST_F(JsEnvironmentTest, StartDebugger_0100, TestSize.Level2)
233 {
234 auto jsEnv = std::make_shared<JsEnvironment>(std::make_unique<AbilityRuntime::OHOSJsEnvironmentImpl>());
235 ASSERT_NE(jsEnv, nullptr);
236
237 std::string option = "ark:1234@Debugger";
238 uint32_t socketFd = 10;
239 bool isDebugApp = true;
240 bool result = jsEnv->StartDebugger(option, socketFd, isDebugApp);
241 ASSERT_EQ(result, false);
242 }
243
244 /**
245 * @tc.name: StartDebugger_0200
246 * @tc.desc: StartDebugger
247 * @tc.type: FUNC
248 * @tc.require: issue
249 */
250 HWTEST_F(JsEnvironmentTest, StartDebugger_0200, TestSize.Level2)
251 {
252 auto jsEnv = std::make_shared<JsEnvironment>(std::make_unique<AbilityRuntime::OHOSJsEnvironmentImpl>());
253 ASSERT_NE(jsEnv, nullptr);
254 panda::RuntimeOption pandaOption;
255 auto ret = jsEnv->Initialize(pandaOption, static_cast<void*>(this));
256 ASSERT_EQ(ret, true);
257
258 std::string option = "ark:1234@Debugger";
259 uint32_t socketFd = 10;
260 bool isDebugApp = true;
261 bool result = jsEnv->StartDebugger(option, socketFd, isDebugApp);
262 ASSERT_EQ(result, false);
263 }
264
265 /**
266 * @tc.name: StopDebugger_0100
267 * @tc.desc: StopDebugger
268 * @tc.type: FUNC
269 * @tc.require: issue
270 */
271 HWTEST_F(JsEnvironmentTest, StopDebugger_0100, TestSize.Level2)
272 {
273 auto jsEnv = std::make_shared<JsEnvironment>(std::make_unique<AbilityRuntime::OHOSJsEnvironmentImpl>());
274 ASSERT_NE(jsEnv, nullptr);
275
276 jsEnv->StopDebugger();
277 }
278
279 /**
280 * @tc.name: StopDebugger_0200
281 * @tc.desc: StopDebugger
282 * @tc.type: FUNC
283 * @tc.require: issue
284 */
285 HWTEST_F(JsEnvironmentTest, StopDebugger_0200, TestSize.Level2)
286 {
287 auto jsEnv = std::make_shared<JsEnvironment>(std::make_unique<AbilityRuntime::OHOSJsEnvironmentImpl>());
288
289 panda::RuntimeOption pandaOption;
290 jsEnv->Initialize(pandaOption, static_cast<void*>(this));
291 jsEnv->StopDebugger();
292 ASSERT_NE(jsEnv, nullptr);
293 }
294
295 /**
296 * @tc.name: StopDebugger_0300
297 * @tc.desc: StopDebugger
298 * @tc.type: FUNC
299 * @tc.require: issue
300 */
301 HWTEST_F(JsEnvironmentTest, StopDebugger_0300, TestSize.Level2)
302 {
303 auto jsEnv = std::make_shared<JsEnvironment>(std::make_unique<AbilityRuntime::OHOSJsEnvironmentImpl>());
304
305 panda::RuntimeOption pandaOption;
306 jsEnv->Initialize(pandaOption, static_cast<void*>(this));
307 std::string option = "ark:1234@Debugger";
308 jsEnv->StopDebugger(option);
309 ASSERT_NE(jsEnv, nullptr);
310 }
311
312 /**
313 * @tc.name: InitConsoleModule_0100
314 * @tc.desc: InitConsoleModule
315 * @tc.type: FUNC
316 * @tc.require: issue
317 */
318 HWTEST_F(JsEnvironmentTest, InitConsoleModule_0100, TestSize.Level2)
319 {
320 auto jsEnv = std::make_shared<JsEnvironment>(std::make_unique<AbilityRuntime::OHOSJsEnvironmentImpl>());
321 ASSERT_NE(jsEnv, nullptr);
322
323 jsEnv->InitConsoleModule();
324
325 panda::RuntimeOption pandaOption;
326 auto ret = jsEnv->Initialize(pandaOption, static_cast<void*>(this));
327 ASSERT_EQ(ret, true);
328
329 jsEnv->InitConsoleModule();
330 }
331
332 /**
333 * @tc.name: StartProfiler_0100
334 * @tc.desc: StartProfiler
335 * @tc.type: FUNC
336 */
337 HWTEST_F(JsEnvironmentTest, StartProfiler_0100, TestSize.Level1)
338 {
339 auto jsEnv = std::make_shared<JsEnvironment>(std::make_unique<AbilityRuntime::OHOSJsEnvironmentImpl>());
340 ASSERT_NE(jsEnv, nullptr);
341
342 const char* libraryPath = "LIBRARYPATH";
343 jsEnv->StartProfiler(libraryPath, 0, JsEnvironment::PROFILERTYPE::PROFILERTYPE_CPU, 0, 0, true);
344 ASSERT_EQ(jsEnv->GetVM(), nullptr);
345 }
346
347 /**
348 * @tc.name: StartProfiler_0200
349 * @tc.desc: StartProfiler
350 * @tc.type: FUNC
351 */
352 HWTEST_F(JsEnvironmentTest, StartProfiler_0200, TestSize.Level1)
353 {
354 auto jsEnv = std::make_shared<JsEnvironment>(std::make_unique<AbilityRuntime::OHOSJsEnvironmentImpl>());
355 ASSERT_NE(jsEnv, nullptr);
356
357 panda::RuntimeOption pandaOption;
358 auto ret = jsEnv->Initialize(pandaOption, static_cast<void*>(this));
359 ASSERT_EQ(ret, true);
360
361 const char* libraryPath = "LIBRARYPATH";
362 jsEnv->StartProfiler(libraryPath, 0, JsEnvironment::PROFILERTYPE::PROFILERTYPE_HEAP, 0, 0, true);
363 ASSERT_NE(jsEnv->GetVM(), nullptr);
364 }
365
366 /**
367 * @tc.name: PostSyncTask_0100
368 * @tc.desc: Js environment post sync task.
369 * @tc.type: FUNC
370 * @tc.require: issueI7C87T
371 */
372 HWTEST_F(JsEnvironmentTest, PostSyncTask_0100, TestSize.Level2)
373 {
374 auto runner = AppExecFwk::EventRunner::Create("TASK_RUNNER");
375 ASSERT_NE(runner, nullptr);
376 auto jsEnv = std::make_shared<JsEnvironment>(std::make_unique<AbilityRuntime::OHOSJsEnvironmentImpl>(runner));
377 ASSERT_NE(jsEnv, nullptr);
378 panda::RuntimeOption pandaOption;
379 ASSERT_EQ(jsEnv->Initialize(pandaOption, static_cast<void*>(this)), true);
380 ASSERT_EQ(jsEnv->InitLoop(), true);
381
382 std::string taskName = "syncTask001";
383 bool taskExecuted = false;
__anon8616e42c0302() 384 auto task = [taskName, &taskExecuted]() {
385 taskExecuted = true;
386 };
387 jsEnv->PostSyncTask(task, taskName);
388 EXPECT_EQ(taskExecuted, true);
389 }
390
391 /**
392 * @tc.name: SetRequestAotCallback_0100
393 * @tc.desc: Js environment SetRequestAotCallback.
394 * @tc.type: FUNC
395 * @tc.require: issueI82L1A
396 */
397 HWTEST_F(JsEnvironmentTest, SetRequestAotCallback_0100, TestSize.Level2)
398 {
399 auto jsEnv = std::make_shared<JsEnvironment>(std::make_unique<AbilityRuntime::OHOSJsEnvironmentImpl>());
400 ASSERT_NE(jsEnv, nullptr);
401
__anon8616e42c0402(const std::string& bundleName, const std::string& moduleName, int32_t triggerMode) 402 auto callback = [](const std::string& bundleName, const std::string& moduleName, int32_t triggerMode) -> int32_t {
403 return 0;
404 };
405 jsEnv->SetRequestAotCallback(callback);
406 }
407
408 /**
409 * @tc.name: ParseHdcRegisterOption_0100
410 * @tc.desc: Js environment ParseHdcRegisterOption.
411 * @tc.type: FUNC
412 */
413 HWTEST_F(JsEnvironmentTest, ParseHdcRegisterOption_0100, TestSize.Level2)
414 {
415 auto jsEnv = std::make_shared<JsEnvironment>(std::make_unique<AbilityRuntime::OHOSJsEnvironmentImpl>());
416 ASSERT_NE(jsEnv, nullptr);
417 std::string option1 = "";
418 int result1 = jsEnv->ParseHdcRegisterOption(option1);
419 ASSERT_EQ(result1, -1);
420 std::string option2 = "@";
421 int result2 = jsEnv->ParseHdcRegisterOption(option2);
422 ASSERT_EQ(result2, -1);
423 std::string option3 = ":";
424 int result3 = jsEnv->ParseHdcRegisterOption(option3);
425 ASSERT_EQ(result3, -1);
426 std::string option4 = "ark:123@Debugger";
427 int result4 = jsEnv->ParseHdcRegisterOption(option4);
428 ASSERT_EQ(result4, 123);
429 std::string option5 = "ark:123@456@Debugger";
430 int result5 = jsEnv->ParseHdcRegisterOption(option5);
431 ASSERT_EQ(result5, 456);
432 }
433
434 /**
435 * @tc.name: SetDeviceDisconnectCallback_0100
436 * @tc.desc: Js environment SetDeviceDisconnectCallback.
437 * @tc.type: FUNC
438 * @tc.require: issueI82L1A
439 */
440 HWTEST_F(JsEnvironmentTest, SetDeviceDisconnectCallback_0100, TestSize.Level2)
441 {
442 auto jsEnv = std::make_shared<JsEnvironment>(std::make_unique<AbilityRuntime::OHOSJsEnvironmentImpl>());
443 ASSERT_NE(jsEnv, nullptr);
444 panda::RuntimeOption pandaOption;
445 auto ret = jsEnv->Initialize(pandaOption, static_cast<void*>(this));
446 ASSERT_EQ(ret, true);
447
448 bool taskExecuted = false;
__anon8616e42c0502() 449 auto task = [&taskExecuted]() {
450 return true;
451 };
452 jsEnv->SetDeviceDisconnectCallback(task);
453 ASSERT_EQ(taskExecuted, false);
454 }
455
456 /**
457 * @tc.name: DestroyHeapProfiler_0100
458 * @tc.desc: Js environment DestroyHeapProfiler.
459 * @tc.type: FUNC
460 */
461 HWTEST_F(JsEnvironmentTest, DestroyHeapProfiler_0100, TestSize.Level2)
462 {
463 auto jsEnv = std::make_shared<JsEnvironment>(std::make_unique<AbilityRuntime::OHOSJsEnvironmentImpl>());
464 jsEnv->DestroyHeapProfiler();
465 ASSERT_NE(jsEnv, nullptr);
466 }
467
468 /**
469 * @tc.name: NotifyDebugMode_0100
470 * @tc.desc: Js environment NotifyDebugMode.
471 * @tc.type: FUNC
472 */
473 HWTEST_F(JsEnvironmentTest, NotifyDebugMode_0100, TestSize.Level2)
474 {
475 auto jsEnv = std::make_shared<JsEnvironment>(std::make_unique<AbilityRuntime::OHOSJsEnvironmentImpl>());
476 int tid = 1;
477 char* libraryPath;
478 uint32_t instanceId = 1;
479 bool debug = true;
480 bool debugMode = true;
481 jsEnv->NotifyDebugMode(tid, libraryPath, instanceId, debug, debugMode);
482 ASSERT_NE(jsEnv, nullptr);
483 }
484
485 /**
486 * @tc.name: GetDebuggerPostTask_0100
487 * @tc.desc: Js environment GetDebuggerPostTask.
488 * @tc.type: FUNC
489 */
490 HWTEST_F(JsEnvironmentTest, GetDebuggerPostTask_0100, TestSize.Level2)
491 {
492 auto jsEnv = std::make_shared<JsEnvironment>(std::make_unique<AbilityRuntime::OHOSJsEnvironmentImpl>());
493 jsEnv->GetDebuggerPostTask();
494 ASSERT_NE(jsEnv, nullptr);
495 }
496
497 /**
498 * @tc.name: GetDebuggerPostTask_0200
499 * @tc.desc: Js environment GetDebuggerPostTask.
500 * @tc.type: FUNC
501 */
502 HWTEST_F(JsEnvironmentTest, GetDebuggerPostTask_0200, TestSize.Level2)
503 {
504 auto jsEnv = std::make_shared<JsEnvironment>(std::make_unique<AbilityRuntime::OHOSJsEnvironmentImpl>());
505 auto poster = jsEnv->GetDebuggerPostTask();
506 ASSERT_NE(jsEnv, nullptr);
__anon8616e42c0602() 507 poster([]() {
508 std::string temp;
509 });
510 }
511
512 /**
513 * @tc.name: GetHeapPrepare_0100
514 * @tc.desc: Js environment GetHeapPrepare.
515 * @tc.type: FUNC
516 */
517 HWTEST_F(JsEnvironmentTest, GetHeapPrepare_0100, TestSize.Level2)
518 {
519 auto jsEnv = std::make_shared<JsEnvironment>(std::make_unique<AbilityRuntime::OHOSJsEnvironmentImpl>());
520 jsEnv->GetHeapPrepare();
521 ASSERT_NE(jsEnv, nullptr);
522 }
523
524 /**
525 * @tc.name: GetHeapPrepare_0200
526 * @tc.desc: Js environment GetHeapPrepare.
527 * @tc.type: FUNC
528 */
529 HWTEST_F(JsEnvironmentTest, GetHeapPrepare_0200, TestSize.Level2)
530 {
531 auto jsEnv = std::make_shared<JsEnvironment>(std::make_unique<AbilityRuntime::OHOSJsEnvironmentImpl>());
532 panda::RuntimeOption pandaOption;
533 jsEnv->Initialize(pandaOption, static_cast<void*>(this));
534 jsEnv->GetHeapPrepare();
535 ASSERT_NE(jsEnv, nullptr);
536 }
537
538 /**
539 * @tc.name: GetSourceMapOperator_0100
540 * @tc.desc: Js environment GetSourceMapOperator.
541 * @tc.type: FUNC
542 */
543 HWTEST_F(JsEnvironmentTest, GetSourceMapOperator_0100, TestSize.Level2)
544 {
545 auto jsEnv = std::make_shared<JsEnvironment>(std::make_unique<AbilityRuntime::OHOSJsEnvironmentImpl>());
546 jsEnv->GetSourceMapOperator();
547 ASSERT_NE(jsEnv, nullptr);
548 }
549
550 /**
551 * @tc.name: initworkermodule_0100
552 * @tc.desc: Js environment initworkermodule.
553 * @tc.type: FUNC
554 */
555 HWTEST_F(JsEnvironmentTest, initworkermodule_0100, TestSize.Level2)
556 {
557 auto jsEnv = std::make_shared<JsEnvironment>(std::make_unique<AbilityRuntime::OHOSJsEnvironmentImpl>());
558 std::shared_ptr<WorkerInfo> workerInfo = std::make_shared<WorkerInfo>();
559 jsEnv->InitWorkerModule(workerInfo);
560 ASSERT_NE(jsEnv, nullptr);
561 }
562
563 /**
564 * @tc.name: InitSourceMap_0100
565 * @tc.desc: Js environment InitSourceMap.
566 * @tc.type: FUNC
567 */
568 HWTEST_F(JsEnvironmentTest, InitSourceMap_0100, TestSize.Level2)
569 {
570 auto jsEnv = std::make_shared<JsEnvironment>(std::make_unique<AbilityRuntime::OHOSJsEnvironmentImpl>());
571 std::shared_ptr<JsEnv::SourceMapOperator> operatorObj = nullptr;
572 jsEnv->InitSourceMap(operatorObj);
573 ASSERT_NE(jsEnv, nullptr);
574 }
575
576 /**
577 * @tc.name: DeInitLoop_0100
578 * @tc.desc: Js environment DeInitLoop.
579 * @tc.type: FUNC
580 */
581 HWTEST_F(JsEnvironmentTest, DeInitLoop_0100, TestSize.Level2)
582 {
583 auto jsEnv = std::make_shared<JsEnvironment>(std::make_unique<AbilityRuntime::OHOSJsEnvironmentImpl>());
584 jsEnv->DeInitLoop();
585 ASSERT_NE(jsEnv, nullptr);
586 }
587
588 /**
589 * @tc.name: SetModuleLoadChecker_0100
590 * @tc.desc: Js environment SetModuleLoadChecker.
591 * @tc.type: FUNC
592 */
593 HWTEST_F(JsEnvironmentTest, SetModuleLoadChecker_0100, TestSize.Level2)
594 {
595 auto jsEnv = std::make_shared<JsEnvironment>(std::make_unique<AbilityRuntime::OHOSJsEnvironmentImpl>());
596 std::shared_ptr<ModuleCheckerDelegate> moduleCheckerDelegate = nullptr;
597 jsEnv->SetModuleLoadChecker(moduleCheckerDelegate);
598 ASSERT_NE(jsEnv, nullptr);
599 }
600
601 /**
602 * @tc.name: ReInitJsEnvImpl_0100
603 * @tc.desc: Js environment ReInitJsEnvImpl.
604 * @tc.type: FUNC
605 */
606 HWTEST_F(JsEnvironmentTest, ReInitJsEnvImpl_0100, TestSize.Level2)
607 {
608 auto jsEnv = std::make_shared<JsEnvironment>(std::make_unique<AbilityRuntime::OHOSJsEnvironmentImpl>());
609 jsEnv->ReInitJsEnvImpl(std::make_unique<AbilityRuntime::OHOSJsEnvironmentImpl>());
610 ASSERT_NE(jsEnv->impl_, nullptr);
611 }
612
613 /**
614 * @tc.name: GetDebugMode_0100
615 * @tc.desc: Js environment GetDebugMode.
616 * @tc.type: FUNC
617 */
618 HWTEST_F(JsEnvironmentTest, GetDebugMode_0100, TestSize.Level2)
619 {
620 auto jsEnv = std::make_shared<JsEnvironment>(std::make_unique<AbilityRuntime::OHOSJsEnvironmentImpl>());
621 auto result = jsEnv->GetDebugMode();
622 ASSERT_EQ(result, false);
623 }
624
625 /**
626 * @tc.name: RegisterUncatchableExceptionHandler_0100
627 * @tc.desc: Js environment RegisterUncatchableExceptionHandler.
628 * @tc.type: FUNC
629 */
630 HWTEST_F(JsEnvironmentTest, RegisterUncatchableExceptionHandler_0100, TestSize.Level1)
631 {
632 auto jsEnv = std::make_shared<JsEnvironment>(std::make_unique<AbilityRuntime::OHOSJsEnvironmentImpl>());
633 jsEnv->RegisterUncatchableExceptionHandler(nullptr);
634 EXPECT_NE(jsEnv, nullptr);
635 UncatchableTask task;
636 jsEnv->RegisterUncatchableExceptionHandler(task);
637 EXPECT_NE(jsEnv, nullptr);
638 }
639 } // namespace JsEnv
640 } // namespace OHOS
641