• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2022 Huawei Device Co., Ltd.
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at
6  *
7  *     http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14  */
15 
16 #include "agent/debugger_impl.h"
17 #include "ecmascript/tests/test_helper.h"
18 #include "protocol_channel.h"
19 #include "protocol_handler.h"
20 
21 using namespace panda::ecmascript;
22 using namespace panda::ecmascript::tooling;
23 namespace panda::ecmascript::tooling {
24 class DebuggerImplFriendTest {
25 public:
DebuggerImplFriendTest(std::unique_ptr<DebuggerImpl> & debuggerImpl)26     explicit DebuggerImplFriendTest(std::unique_ptr<DebuggerImpl> &debuggerImpl)
27     {
28         debuggerImpl_ = std::move(debuggerImpl);
29     }
30 
CheckAndGenerateCondFunc(const std::optional<std::string> condition)31     void CheckAndGenerateCondFunc(const std::optional<std::string> condition)
32     {
33         debuggerImpl_->CheckAndGenerateCondFunc(condition);
34     }
35 
ConvertToLocal(const std::string & varValue)36     Local<JSValueRef> ConvertToLocal(const std::string &varValue)
37     {
38         return debuggerImpl_->ConvertToLocal(varValue);
39     }
40 
GetMixStackEnabled()41     bool GetMixStackEnabled()
42     {
43         return debuggerImpl_->mixStackEnabled_;
44     }
45 
DecodeAndCheckBase64(const std::string & src,std::vector<uint8_t> & dest)46     bool DecodeAndCheckBase64(const std::string &src, std::vector<uint8_t> &dest)
47     {
48         return debuggerImpl_->DecodeAndCheckBase64(src, dest);
49     }
50 private:
51     std::unique_ptr<DebuggerImpl> debuggerImpl_;
52 };
53 }
54 
55 namespace panda::test {
56 class DebuggerImplTest : public testing::Test {
57 public:
SetUpTestCase()58     static void SetUpTestCase()
59     {
60         GTEST_LOG_(INFO) << "SetUpTestCase";
61     }
62 
TearDownTestCase()63     static void TearDownTestCase()
64     {
65         GTEST_LOG_(INFO) << "TearDownCase";
66     }
67 
SetUp()68     void SetUp() override
69     {
70         TestHelper::CreateEcmaVMWithScope(ecmaVm, thread, scope);
71     }
72 
TearDown()73     void TearDown() override
74     {
75         TestHelper::DestroyEcmaVMWithScope(ecmaVm, scope);
76     }
77 
78 protected:
79     EcmaVM *ecmaVm {nullptr};
80     EcmaHandleScope *scope {nullptr};
81     JSThread *thread {nullptr};
82 };
83 
HWTEST_F_L0(DebuggerImplTest,NotifyScriptParsed__001)84 HWTEST_F_L0(DebuggerImplTest, NotifyScriptParsed__001)
85 {
86     std::string outStrForCallbackCheck = "";
87     std::function<void(const void*, const std::string &)> callback =
88         [&outStrForCallbackCheck]([[maybe_unused]] const void *ptr, const std::string &inStrOfReply) {
89             outStrForCallbackCheck = inStrOfReply;};
90     ProtocolChannel *protocolChannel = new ProtocolHandler(callback, ecmaVm);
91     auto runtimeImpl = std::make_unique<RuntimeImpl>(ecmaVm, protocolChannel);
92     auto debuggerImpl = std::make_unique<DebuggerImpl>(ecmaVm, protocolChannel, runtimeImpl.get());
93 
94     // DebuggerImpl::NotifyScriptParsed -- fileName.substr(0, DATA_APP_PATH.length()) != DATA_APP_PATH
95     std::string strFilename = "filename";
96     EXPECT_FALSE(debuggerImpl->NotifyScriptParsed(strFilename, ""));
97 
98     // DebuggerImpl::NotifyScriptParsed -- fileName.substr(0, DATA_APP_PATH.length()) != DATA_APP_PATH
99     strFilename = "/filename";
100     EXPECT_FALSE(debuggerImpl->NotifyScriptParsed(strFilename, ""));
101 
102     if (protocolChannel) {
103         delete protocolChannel;
104         protocolChannel = nullptr;
105     }
106 }
107 
HWTEST_F_L0(DebuggerImplTest,NotifyScriptParsed__002)108 HWTEST_F_L0(DebuggerImplTest, NotifyScriptParsed__002)
109 {
110     std::string outStrForCallbackCheck = "";
111     std::function<void(const void*, const std::string &)> callback =
112         [&outStrForCallbackCheck]([[maybe_unused]] const void *ptr, const std::string &inStrOfReply) {
113             outStrForCallbackCheck = inStrOfReply;};
114     ProtocolChannel *protocolChannel = new ProtocolHandler(callback, ecmaVm);
115     auto runtimeImpl = std::make_unique<RuntimeImpl>(ecmaVm, protocolChannel);
116     auto debuggerImpl = std::make_unique<DebuggerImpl>(ecmaVm, protocolChannel, runtimeImpl.get());
117     ecmaVm->GetJsDebuggerManager()->SetIsDebugApp(true);
118     ecmaVm->GetJsDebuggerManager()->SetDebugMode(true);
119     // DebuggerImpl::NotifyScriptParsed -- fileName.substr(0, DATA_APP_PATH.length()) != DATA_APP_PATH
120     std::string strFilename = "";
121     EXPECT_FALSE(debuggerImpl->NotifyScriptParsed(strFilename, ""));
122     ecmaVm->GetJsDebuggerManager()->SetIsDebugApp(false);
123     ecmaVm->GetJsDebuggerManager()->SetDebugMode(false);
124     if (protocolChannel) {
125         delete protocolChannel;
126         protocolChannel = nullptr;
127     }
128 }
129 
HWTEST_F_L0(DebuggerImplTest,GenerateCallFrames__001)130 HWTEST_F_L0(DebuggerImplTest, GenerateCallFrames__001)
131 {
132 }
133 
HWTEST_F_L0(DebuggerImplTest,Dispatcher_Dispatch_Enable__001)134 HWTEST_F_L0(DebuggerImplTest, Dispatcher_Dispatch_Enable__001)
135 {
136     std::string outStrForCallbackCheck = "";
137     std::function<void(const void*, const std::string &)> callback =
138         [&outStrForCallbackCheck]([[maybe_unused]] const void *ptr, const std::string &inStrOfReply) {
139             outStrForCallbackCheck = inStrOfReply;};
140     ProtocolChannel *protocolChannel = new ProtocolHandler(callback, ecmaVm);
141     auto runtimeImpl = std::make_unique<RuntimeImpl>(ecmaVm, protocolChannel);
142     auto debuggerImpl = std::make_unique<DebuggerImpl>(ecmaVm, protocolChannel, runtimeImpl.get());
143     auto dispatcherImpl = std::make_unique<DebuggerImpl::DispatcherImpl>(protocolChannel, std::move(debuggerImpl));
144 
145     // DebuggerImpl::DispatcherImpl::Enable -- params == nullptr
146     std::string msg = std::string() +
147         R"({
148             "id":0,
149             "method":"Debugger.enable",
150             "params":{
151                 "maxScriptsCacheSize":"NotIntValue"
152             }
153         })";
154     DispatchRequest request(msg);
155     dispatcherImpl->Dispatch(request);
156 
157     EXPECT_STREQ(outStrForCallbackCheck.c_str(), R"({"id":0,"result":{"code":1,"message":"wrong params"}})");
158     if (protocolChannel) {
159         delete protocolChannel;
160         protocolChannel = nullptr;
161     }
162 }
163 
HWTEST_F_L0(DebuggerImplTest,Dispatcher_Dispatch_Enable__002)164 HWTEST_F_L0(DebuggerImplTest, Dispatcher_Dispatch_Enable__002)
165 {
166     std::string outStrForCallbackCheck = "";
167     std::function<void(const void*, const std::string &)> callback =
168         [&outStrForCallbackCheck]([[maybe_unused]] const void *ptr, const std::string &inStrOfReply) {
169             outStrForCallbackCheck = inStrOfReply;};
170     ProtocolChannel *protocolChannel = new ProtocolHandler(callback, ecmaVm);
171     auto runtimeImpl = std::make_unique<RuntimeImpl>(ecmaVm, protocolChannel);
172     auto debuggerImpl = std::make_unique<DebuggerImpl>(ecmaVm, protocolChannel, runtimeImpl.get());
173     auto dispatcherImpl = std::make_unique<DebuggerImpl::DispatcherImpl>(protocolChannel, std::move(debuggerImpl));
174     EXPECT_FALSE(ecmaVm->GetJsDebuggerManager()->IsDebugMode());
175 
176     std::string msg = std::string() +
177         R"({
178             "id":0,
179             "method":"Debugger.enable",
180             "params":{
181                 "maxScriptsCacheSize":1024
182             }
183         })";
184     DispatchRequest request(msg);
185     dispatcherImpl->Dispatch(request);
186 
187     bool condition = outStrForCallbackCheck.find("protocols") != std::string::npos &&
188         outStrForCallbackCheck.find("debuggerId") != std::string::npos;
189     EXPECT_TRUE(condition);
190     EXPECT_TRUE(ecmaVm->GetJsDebuggerManager()->IsDebugMode());
191     if (protocolChannel) {
192         delete protocolChannel;
193         protocolChannel = nullptr;
194     }
195 }
196 
HWTEST_F_L0(DebuggerImplTest,Dispatcher_Dispatch_Enable_Accelerate_Launch_Mode)197 HWTEST_F_L0(DebuggerImplTest, Dispatcher_Dispatch_Enable_Accelerate_Launch_Mode)
198 {
199     std::string outStrForCallbackCheck = "";
200     std::function<void(const void*, const std::string &)> callback =
201         [&outStrForCallbackCheck]([[maybe_unused]] const void *ptr, const std::string &inStrOfReply) {
202             outStrForCallbackCheck = inStrOfReply;};
203     ProtocolChannel *protocolChannel = new ProtocolHandler(callback, ecmaVm);
204     auto runtimeImpl = std::make_unique<RuntimeImpl>(ecmaVm, protocolChannel);
205     auto debuggerImpl = std::make_unique<DebuggerImpl>(ecmaVm, protocolChannel, runtimeImpl.get());
206     auto dispatcherImpl = std::make_unique<DebuggerImpl::DispatcherImpl>(protocolChannel, std::move(debuggerImpl));
207     EXPECT_FALSE(ecmaVm->GetJsDebuggerManager()->IsDebugMode());
208 
209     std::string msg = std::string() +
210         R"({
211             "id":0,
212             "method":"Debugger.enable",
213             "params":{
214                 "maxScriptsCacheSize":1024,
215                 "options":[
216                     "enableLaunchAccelerate"
217                 ]
218             }
219         })";
220     DispatchRequest request(msg);
221     dispatcherImpl->Dispatch(request);
222 
223     bool condition = outStrForCallbackCheck.find("protocols") != std::string::npos &&
224         outStrForCallbackCheck.find("debuggerId") != std::string::npos &&
225         outStrForCallbackCheck.find("saveAllPossibleBreakpoints") != std::string::npos;
226     EXPECT_TRUE(condition);
227     EXPECT_TRUE(ecmaVm->GetJsDebuggerManager()->IsDebugMode());
228     if (protocolChannel) {
229         delete protocolChannel;
230         protocolChannel = nullptr;
231     }
232 }
233 
HWTEST_F_L0(DebuggerImplTest,Dispatcher_Dispatch_Disable__001)234 HWTEST_F_L0(DebuggerImplTest, Dispatcher_Dispatch_Disable__001)
235 {
236     std::string outStrForCallbackCheck = "";
237     std::function<void(const void*, const std::string &)> callback =
238         [&outStrForCallbackCheck]([[maybe_unused]] const void *ptr, const std::string &inStrOfReply) {
239             outStrForCallbackCheck = inStrOfReply;};
240     ProtocolChannel *protocolChannel = new ProtocolHandler(callback, ecmaVm);
241     auto runtimeImpl = std::make_unique<RuntimeImpl>(ecmaVm, protocolChannel);
242     auto debuggerImpl = std::make_unique<DebuggerImpl>(ecmaVm, protocolChannel, runtimeImpl.get());
243     auto dispatcherImpl = std::make_unique<DebuggerImpl::DispatcherImpl>(protocolChannel, std::move(debuggerImpl));
244     ecmaVm->GetJsDebuggerManager()->SetDebugMode(true);
245 
246     std::string msg = std::string() +
247         R"({
248             "id":0,
249             "method":"Debugger.disable"
250         })";
251     DispatchRequest request(msg);
252 
253     dispatcherImpl->Dispatch(request);
254     EXPECT_STREQ(outStrForCallbackCheck.c_str(), R"({"id":0,"result":{}})");
255     EXPECT_FALSE(ecmaVm->GetJsDebuggerManager()->IsDebugMode());
256     if (protocolChannel) {
257         delete protocolChannel;
258         protocolChannel = nullptr;
259     }
260 }
261 
HWTEST_F_L0(DebuggerImplTest,Dispatcher_Dispatch_EvaluateOnCallFrame__001)262 HWTEST_F_L0(DebuggerImplTest, Dispatcher_Dispatch_EvaluateOnCallFrame__001)
263 {
264     std::string outStrForCallbackCheck = "";
265     std::function<void(const void*, const std::string &)> callback =
266         [&outStrForCallbackCheck]([[maybe_unused]] const void *ptr, const std::string &inStrOfReply) {
267             outStrForCallbackCheck = inStrOfReply;};
268     ProtocolChannel *protocolChannel = new ProtocolHandler(callback, ecmaVm);
269     auto runtimeImpl = std::make_unique<RuntimeImpl>(ecmaVm, protocolChannel);
270     auto debuggerImpl = std::make_unique<DebuggerImpl>(ecmaVm, protocolChannel, runtimeImpl.get());
271     auto dispatcherImpl = std::make_unique<DebuggerImpl::DispatcherImpl>(protocolChannel, std::move(debuggerImpl));
272 
273     // DebuggerImpl::DispatcherImpl::EvaluateOnCallFrame -- params == nullptr
274     std::string msg = std::string() +
275         R"({
276             "id":0,
277             "method":"Debugger.evaluateOnCallFrame",
278             "params":{}
279         })";
280     DispatchRequest request(msg);
281 
282     dispatcherImpl->Dispatch(request);
283     EXPECT_STREQ(outStrForCallbackCheck.c_str(), R"({"id":0,"result":{"code":1,"message":"wrong params"}})");
284     if (protocolChannel) {
285         delete protocolChannel;
286         protocolChannel = nullptr;
287     }
288 }
289 
HWTEST_F_L0(DebuggerImplTest,Dispatcher_Dispatch_EvaluateOnCallFrame__002)290 HWTEST_F_L0(DebuggerImplTest, Dispatcher_Dispatch_EvaluateOnCallFrame__002)
291 {
292     std::string outStrForCallbackCheck = "";
293     std::function<void(const void*, const std::string &)> callback =
294         [&outStrForCallbackCheck]([[maybe_unused]] const void *ptr, const std::string &inStrOfReply) {
295             outStrForCallbackCheck = inStrOfReply;};
296     ProtocolChannel *protocolChannel = new ProtocolHandler(callback, ecmaVm);
297     auto runtimeImpl = std::make_unique<RuntimeImpl>(ecmaVm, protocolChannel);
298     auto debuggerImpl = std::make_unique<DebuggerImpl>(ecmaVm, protocolChannel, runtimeImpl.get());
299     auto dispatcherImpl = std::make_unique<DebuggerImpl::DispatcherImpl>(protocolChannel, std::move(debuggerImpl));
300 
301     // DebuggerImpl::EvaluateOnCallFrame -- callFrameId < 0
302     std::string msg = std::string() +
303         R"({
304             "id":0,
305             "method":"Debugger.evaluateOnCallFrame",
306             "params":{
307                 "callFrameId":"-1",
308                 "expression":"the expression"
309             }
310         })";
311     DispatchRequest request(msg);
312 
313     dispatcherImpl->Dispatch(request);
314     EXPECT_STREQ(outStrForCallbackCheck.c_str(), R"({"id":0,"result":{"code":1,"message":"Invalid callFrameId."}})");
315     if (protocolChannel) {
316         delete protocolChannel;
317         protocolChannel = nullptr;
318     }
319 }
320 
HWTEST_F_L0(DebuggerImplTest,Dispatcher_Dispatch_EvaluateOnCallFrame__003)321 HWTEST_F_L0(DebuggerImplTest, Dispatcher_Dispatch_EvaluateOnCallFrame__003)
322 {
323     std::string outStrForCallbackCheck = "";
324     std::function<void(const void*, const std::string &)> callback =
325         [&outStrForCallbackCheck]([[maybe_unused]] const void *ptr, const std::string &inStrOfReply) {
326             outStrForCallbackCheck = inStrOfReply;};
327     ProtocolChannel *protocolChannel = new ProtocolHandler(callback, ecmaVm);
328     auto runtimeImpl = std::make_unique<RuntimeImpl>(ecmaVm, protocolChannel);
329     auto debuggerImpl = std::make_unique<DebuggerImpl>(ecmaVm, protocolChannel, runtimeImpl.get());
330     auto dispatcherImpl = std::make_unique<DebuggerImpl::DispatcherImpl>(protocolChannel, std::move(debuggerImpl));
331 
332     // DebuggerImpl::EvaluateOnCallFrame -- callFrameId >= static_cast<CallFrameId>(callFrameHandlers_.size())
333     std::string msg = std::string() +
334         R"({
335             "id":0,
336             "method":"Debugger.evaluateOnCallFrame",
337             "params":{
338                 "callFrameId":"0",
339                 "expression":"the expression"
340             }
341         })";
342     DispatchRequest request(msg);
343 
344     dispatcherImpl->Dispatch(request);
345     EXPECT_STREQ(outStrForCallbackCheck.c_str(), R"({"id":0,"result":{"code":1,"message":"Invalid callFrameId."}})");
346     if (protocolChannel) {
347         delete protocolChannel;
348         protocolChannel = nullptr;
349     }
350 }
351 
HWTEST_F_L0(DebuggerImplTest,Dispatcher_Dispatch_GetPossibleBreakpoints__001)352 HWTEST_F_L0(DebuggerImplTest, Dispatcher_Dispatch_GetPossibleBreakpoints__001)
353 {
354     std::string outStrForCallbackCheck = "";
355     std::function<void(const void*, const std::string &)> callback =
356         [&outStrForCallbackCheck]([[maybe_unused]] const void *ptr, const std::string &inStrOfReply) {
357             outStrForCallbackCheck = inStrOfReply;};
358     ProtocolChannel *protocolChannel = new ProtocolHandler(callback, ecmaVm);
359     auto runtimeImpl = std::make_unique<RuntimeImpl>(ecmaVm, protocolChannel);
360     auto debuggerImpl = std::make_unique<DebuggerImpl>(ecmaVm, protocolChannel, runtimeImpl.get());
361     auto dispatcherImpl = std::make_unique<DebuggerImpl::DispatcherImpl>(protocolChannel, std::move(debuggerImpl));
362 
363     // DebuggerImpl::DispatcherImpl::GetPossibleBreakpoints -- params == nullptr
364     std::string msg = std::string() +
365         R"({
366             "id":0,
367             "method":"Debugger.getPossibleBreakpoints",
368             "params":{}
369         })";
370     DispatchRequest request(msg);
371 
372     dispatcherImpl->Dispatch(request);
373     EXPECT_STREQ(outStrForCallbackCheck.c_str(), R"({"id":0,"result":{"code":1,"message":"wrong params"}})");
374     if (protocolChannel) {
375         delete protocolChannel;
376         protocolChannel = nullptr;
377     }
378 }
379 
HWTEST_F_L0(DebuggerImplTest,Dispatcher_Dispatch_GetPossibleBreakpoints__002)380 HWTEST_F_L0(DebuggerImplTest, Dispatcher_Dispatch_GetPossibleBreakpoints__002)
381 {
382     std::string outStrForCallbackCheck = "";
383     std::function<void(const void*, const std::string &)> callback =
384         [&outStrForCallbackCheck]([[maybe_unused]] const void *ptr, const std::string &inStrOfReply) {
385             outStrForCallbackCheck = inStrOfReply;};
386     ProtocolChannel *protocolChannel = new ProtocolHandler(callback, ecmaVm);
387     auto runtimeImpl = std::make_unique<RuntimeImpl>(ecmaVm, protocolChannel);
388     auto debuggerImpl = std::make_unique<DebuggerImpl>(ecmaVm, protocolChannel, runtimeImpl.get());
389     auto dispatcherImpl = std::make_unique<DebuggerImpl::DispatcherImpl>(protocolChannel, std::move(debuggerImpl));
390 
391     // DebuggerImpl::GetPossibleBreakpoints -- iter == scripts_.end()
392     std::string msg = std::string() +
393         R"({
394             "id":0,
395             "method":"Debugger.getPossibleBreakpoints",
396             "params":{
397                 "start":{
398                     "scriptId":"0",
399                     "lineNumber":1,
400                     "columnNumber":0
401                 },
402                 "end":{
403                     "scriptId":"0",
404                     "lineNumber":1,
405                     "columnNumber":0
406                 },
407                 "restrictToFunction":true
408             }
409         })";
410     DispatchRequest request(msg);
411 
412     dispatcherImpl->Dispatch(request);
413     EXPECT_STREQ(outStrForCallbackCheck.c_str(), R"({"id":0,"result":{"code":1,"message":"Unknown file name."}})");
414     if (protocolChannel) {
415         delete protocolChannel;
416         protocolChannel = nullptr;
417     }
418 }
419 
HWTEST_F_L0(DebuggerImplTest,Dispatcher_Dispatch_GetScriptSource__001)420 HWTEST_F_L0(DebuggerImplTest, Dispatcher_Dispatch_GetScriptSource__001)
421 {
422     std::string outStrForCallbackCheck = "";
423     std::function<void(const void*, const std::string &)> callback =
424         [&outStrForCallbackCheck]([[maybe_unused]] const void *ptr, const std::string &inStrOfReply) {
425             outStrForCallbackCheck = inStrOfReply;};
426     ProtocolChannel *protocolChannel = new ProtocolHandler(callback, ecmaVm);
427     auto runtimeImpl = std::make_unique<RuntimeImpl>(ecmaVm, protocolChannel);
428     auto debuggerImpl = std::make_unique<DebuggerImpl>(ecmaVm, protocolChannel, runtimeImpl.get());
429     auto dispatcherImpl = std::make_unique<DebuggerImpl::DispatcherImpl>(protocolChannel, std::move(debuggerImpl));
430 
431     // DebuggerImpl::DispatcherImpl::GetScriptSource -- params == nullptr
432     std::string msg = std::string() +
433         R"({
434             "id":0,
435             "method":"Debugger.getScriptSource",
436             "params":{}
437         })";
438     DispatchRequest request(msg);
439 
440     dispatcherImpl->Dispatch(request);
441     EXPECT_STREQ(outStrForCallbackCheck.c_str(), R"({"id":0,"result":{"code":1,"message":"wrong params"}})");
442     if (protocolChannel) {
443         delete protocolChannel;
444         protocolChannel = nullptr;
445     }
446 }
447 
HWTEST_F_L0(DebuggerImplTest,Dispatcher_Dispatch_GetScriptSource__002)448 HWTEST_F_L0(DebuggerImplTest, Dispatcher_Dispatch_GetScriptSource__002)
449 {
450     std::string outStrForCallbackCheck = "";
451     std::function<void(const void*, const std::string &)> callback =
452         [&outStrForCallbackCheck]([[maybe_unused]] const void *ptr, const std::string &inStrOfReply) {
453             outStrForCallbackCheck = inStrOfReply;};
454     ProtocolChannel *protocolChannel = new ProtocolHandler(callback, ecmaVm);
455     auto runtimeImpl = std::make_unique<RuntimeImpl>(ecmaVm, protocolChannel);
456     auto debuggerImpl = std::make_unique<DebuggerImpl>(ecmaVm, protocolChannel, runtimeImpl.get());
457     auto dispatcherImpl = std::make_unique<DebuggerImpl::DispatcherImpl>(protocolChannel, std::move(debuggerImpl));
458 
459     // DebuggerImpl::GetScriptSource -- iter == scripts_.end()
460     std::string msg = std::string() +
461         R"({
462             "id":0,
463             "method":"Debugger.getScriptSource",
464             "params":{
465                 "scriptId":"0"
466             }
467         })";
468     DispatchRequest request(msg);
469 
470     dispatcherImpl->Dispatch(request);
471     EXPECT_STREQ(outStrForCallbackCheck.c_str(), R"({"id":0,"result":{"code":1,"message":"unknown script id: 0"}})");
472     if (protocolChannel) {
473         delete protocolChannel;
474         protocolChannel = nullptr;
475     }
476 }
477 
HWTEST_F_L0(DebuggerImplTest,Dispatcher_Dispatch_Pause__001)478 HWTEST_F_L0(DebuggerImplTest, Dispatcher_Dispatch_Pause__001)
479 {
480     std::string outStrForCallbackCheck = "";
481     std::function<void(const void*, const std::string &)> callback =
482         [&outStrForCallbackCheck]([[maybe_unused]] const void *ptr, const std::string &inStrOfReply) {
483             outStrForCallbackCheck = inStrOfReply;};
484     ProtocolChannel *protocolChannel = new ProtocolHandler(callback, ecmaVm);
485     auto runtimeImpl = std::make_unique<RuntimeImpl>(ecmaVm, protocolChannel);
486     auto debuggerImpl = std::make_unique<DebuggerImpl>(ecmaVm, protocolChannel, runtimeImpl.get());
487     auto dispatcherImpl = std::make_unique<DebuggerImpl::DispatcherImpl>(protocolChannel, std::move(debuggerImpl));
488 
489     // DDebuggerImpl::DispatcherImpl::GetScriptSource -- params == nullptr
490     std::string msg = std::string() +
491         R"({
492             "id":0,
493             "method":"Debugger.pause"
494         })";
495     DispatchRequest request(msg);
496 
497     dispatcherImpl->Dispatch(request);
498     EXPECT_STREQ(outStrForCallbackCheck.c_str(), R"({"id":0,"result":{}})");
499     if (protocolChannel) {
500         delete protocolChannel;
501         protocolChannel = nullptr;
502     }
503 }
504 
HWTEST_F_L0(DebuggerImplTest,Dispatcher_Dispatch_RemoveBreakpoint__001)505 HWTEST_F_L0(DebuggerImplTest, Dispatcher_Dispatch_RemoveBreakpoint__001)
506 {
507     std::string outStrForCallbackCheck = "";
508     std::function<void(const void*, const std::string &)> callback =
509         [&outStrForCallbackCheck]([[maybe_unused]] const void *ptr, const std::string &inStrOfReply) {
510             outStrForCallbackCheck = inStrOfReply;};
511     ProtocolChannel *protocolChannel = new ProtocolHandler(callback, ecmaVm);
512     auto runtimeImpl = std::make_unique<RuntimeImpl>(ecmaVm, protocolChannel);
513     auto debuggerImpl = std::make_unique<DebuggerImpl>(ecmaVm, protocolChannel, runtimeImpl.get());
514     auto dispatcherImpl = std::make_unique<DebuggerImpl::DispatcherImpl>(protocolChannel, std::move(debuggerImpl));
515 
516     // DDebuggerImpl::DispatcherImpl::RemoveBreakpoint -- params == nullptr
517     std::string msg = std::string() +
518         R"({
519             "id":0,
520             "method":"Debugger.removeBreakpoint",
521             "params":{}
522         })";
523     DispatchRequest request(msg);
524 
525     dispatcherImpl->Dispatch(request);
526     EXPECT_STREQ(outStrForCallbackCheck.c_str(), R"({"id":0,"result":{"code":1,"message":"wrong params"}})");
527     if (protocolChannel) {
528         delete protocolChannel;
529         protocolChannel = nullptr;
530     }
531 }
532 
HWTEST_F_L0(DebuggerImplTest,Dispatcher_Dispatch_RemoveBreakpoint__002)533 HWTEST_F_L0(DebuggerImplTest, Dispatcher_Dispatch_RemoveBreakpoint__002)
534 {
535     std::string outStrForCallbackCheck = "";
536     std::function<void(const void*, const std::string &)> callback =
537         [&outStrForCallbackCheck]([[maybe_unused]] const void *ptr, const std::string &inStrOfReply) {
538             outStrForCallbackCheck = inStrOfReply;};
539     ProtocolChannel *protocolChannel = new ProtocolHandler(callback, ecmaVm);
540     auto runtimeImpl = std::make_unique<RuntimeImpl>(ecmaVm, protocolChannel);
541     auto debuggerImpl = std::make_unique<DebuggerImpl>(ecmaVm, protocolChannel, runtimeImpl.get());
542     auto dispatcherImpl = std::make_unique<DebuggerImpl::DispatcherImpl>(protocolChannel, std::move(debuggerImpl));
543 
544     // DDebuggerImpl::RemoveBreakpoint -- !BreakpointDetails::ParseBreakpointId(id, &metaData)
545     std::string msg = std::string() +
546         R"({
547             "id":0,
548             "method":"Debugger.removeBreakpoint",
549             "params":{
550                 "breakpointId":"id:0:0"
551             }
552         })";
553     DispatchRequest request(msg);
554 
555     dispatcherImpl->Dispatch(request);
556     EXPECT_STREQ(outStrForCallbackCheck.c_str(),
557         R"({"id":0,"result":{"code":1,"message":"Parse breakpoint id failed"}})");
558     if (protocolChannel) {
559         delete protocolChannel;
560         protocolChannel = nullptr;
561     }
562 }
563 
HWTEST_F_L0(DebuggerImplTest,Dispatcher_Dispatch_RemoveBreakpoint__003)564 HWTEST_F_L0(DebuggerImplTest, Dispatcher_Dispatch_RemoveBreakpoint__003)
565 {
566     std::string outStrForCallbackCheck = "";
567     std::function<void(const void*, const std::string &)> callback =
568         [&outStrForCallbackCheck]([[maybe_unused]] const void *ptr, const std::string &inStrOfReply) {
569             outStrForCallbackCheck = inStrOfReply;};
570     ProtocolChannel *protocolChannel = new ProtocolHandler(callback, ecmaVm);
571     auto runtimeImpl = std::make_unique<RuntimeImpl>(ecmaVm, protocolChannel);
572     auto debuggerImpl = std::make_unique<DebuggerImpl>(ecmaVm, protocolChannel, runtimeImpl.get());
573     auto dispatcherImpl = std::make_unique<DebuggerImpl::DispatcherImpl>(protocolChannel, std::move(debuggerImpl));
574 
575     // DDebuggerImpl::RemoveBreakpoint -- !MatchScripts(scriptFunc, metaData.url_, ScriptMatchType::URL)
576     std::string msg = std::string() +
577         R"({
578             "id":0,
579             "method":"Debugger.removeBreakpoint",
580             "params":{
581                 "breakpointId":"id:0:0:url"
582             }
583         })";
584     DispatchRequest request(msg);
585 
586     dispatcherImpl->Dispatch(request);
587     EXPECT_STREQ(outStrForCallbackCheck.c_str(),
588         R"({"id":0,"result":{"code":1,"message":"Unknown file name."}})");
589     if (protocolChannel) {
590         delete protocolChannel;
591         protocolChannel = nullptr;
592     }
593 }
594 
HWTEST_F_L0(DebuggerImplTest,Dispatcher_Dispatch_RemoveBreakpointsByUrl__001)595 HWTEST_F_L0(DebuggerImplTest, Dispatcher_Dispatch_RemoveBreakpointsByUrl__001)
596 {
597     std::string outStrForCallbackCheck = "";
598     std::function<void(const void*, const std::string &)> callback =
599         [&outStrForCallbackCheck]([[maybe_unused]] const void *ptr, const std::string &inStrOfReply) {
600             outStrForCallbackCheck = inStrOfReply;};
601     ProtocolChannel *protocolChannel = new ProtocolHandler(callback, ecmaVm);
602     auto runtimeImpl = std::make_unique<RuntimeImpl>(ecmaVm, protocolChannel);
603     auto debuggerImpl = std::make_unique<DebuggerImpl>(ecmaVm, protocolChannel, runtimeImpl.get());
604     auto dispatcherImpl = std::make_unique<DebuggerImpl::DispatcherImpl>(protocolChannel, std::move(debuggerImpl));
605 
606     std::string msg = std::string() +
607         R"({
608             "id":0,
609             "method":"Debugger.removeBreakpointsByUrl",
610             "params":{}
611         })";
612     DispatchRequest request(msg);
613 
614     dispatcherImpl->Dispatch(request);
615     EXPECT_STREQ(outStrForCallbackCheck.c_str(), R"({"id":0,"result":{"code":1,"message":"wrong params"}})");
616     if (protocolChannel) {
617         delete protocolChannel;
618         protocolChannel = nullptr;
619     }
620 }
621 
HWTEST_F_L0(DebuggerImplTest,Dispatcher_Dispatch_RemoveBreakpointsByUrl__002)622 HWTEST_F_L0(DebuggerImplTest, Dispatcher_Dispatch_RemoveBreakpointsByUrl__002)
623 {
624     std::string outStrForCallbackCheck = "";
625     std::function<void(const void*, const std::string &)> callback =
626         [&outStrForCallbackCheck]([[maybe_unused]] const void *ptr, const std::string &inStrOfReply) {
627             outStrForCallbackCheck = inStrOfReply;};
628     ProtocolChannel *protocolChannel = new ProtocolHandler(callback, ecmaVm);
629     auto runtimeImpl = std::make_unique<RuntimeImpl>(ecmaVm, protocolChannel);
630     auto debuggerImpl = std::make_unique<DebuggerImpl>(ecmaVm, protocolChannel, runtimeImpl.get());
631     auto dispatcherImpl = std::make_unique<DebuggerImpl::DispatcherImpl>(protocolChannel, std::move(debuggerImpl));
632 
633     std::string msg = std::string() +
634         R"({
635             "id":0,
636             "method":"Debugger.removeBreakpointsByUrl",
637             "params":{
638                 "url":"1"
639             }
640         })";
641     DispatchRequest request(msg);
642 
643     dispatcherImpl->Dispatch(request);
644     EXPECT_STREQ(outStrForCallbackCheck.c_str(), R"({"id":0,"result":{"code":1,"message":"Unknown url"}})");
645     if (protocolChannel) {
646         delete protocolChannel;
647         protocolChannel = nullptr;
648     }
649 }
650 
HWTEST_F_L0(DebuggerImplTest,Dispatcher_Dispatch_Resume__001)651 HWTEST_F_L0(DebuggerImplTest, Dispatcher_Dispatch_Resume__001)
652 {
653     std::string outStrForCallbackCheck = "";
654     std::function<void(const void*, const std::string &)> callback =
655         [&outStrForCallbackCheck]([[maybe_unused]] const void *ptr, const std::string &inStrOfReply) {
656             outStrForCallbackCheck = inStrOfReply;};
657     ProtocolChannel *protocolChannel = new ProtocolHandler(callback, ecmaVm);
658     auto runtimeImpl = std::make_unique<RuntimeImpl>(ecmaVm, protocolChannel);
659     auto debuggerImpl = std::make_unique<DebuggerImpl>(ecmaVm, protocolChannel, runtimeImpl.get());
660     debuggerImpl->SetDebuggerState(DebuggerState::PAUSED);
661     auto dispatcherImpl = std::make_unique<DebuggerImpl::DispatcherImpl>(protocolChannel, std::move(debuggerImpl));
662 
663     // DebuggerImpl::DispatcherImpl::Resume -- params == nullptr
664     std::string msg = std::string() +
665         R"({
666             "id":0,
667             "method":"Debugger.resume",
668             "params":{
669                 "terminateOnResume":"NotBool"
670             }
671         })";
672     DispatchRequest request(msg);
673 
674     dispatcherImpl->Dispatch(request);
675     EXPECT_STREQ(outStrForCallbackCheck.c_str(), R"({"id":0,"result":{"code":1,"message":"wrong params"}})");
676     if (protocolChannel) {
677         delete protocolChannel;
678         protocolChannel = nullptr;
679     }
680 }
681 
HWTEST_F_L0(DebuggerImplTest,Dispatcher_Dispatch_Resume__002)682 HWTEST_F_L0(DebuggerImplTest, Dispatcher_Dispatch_Resume__002)
683 {
684     std::string outStrForCallbackCheck = "";
685     std::function<void(const void*, const std::string &)> callback =
686         [&outStrForCallbackCheck]([[maybe_unused]] const void *ptr, const std::string &inStrOfReply) {
687             outStrForCallbackCheck = inStrOfReply;};
688     ProtocolChannel *protocolChannel = new ProtocolHandler(callback, ecmaVm);
689     auto runtimeImpl = std::make_unique<RuntimeImpl>(ecmaVm, protocolChannel);
690     auto debuggerImpl = std::make_unique<DebuggerImpl>(ecmaVm, protocolChannel, runtimeImpl.get());
691     debuggerImpl->SetDebuggerState(DebuggerState::PAUSED);
692     auto dispatcherImpl = std::make_unique<DebuggerImpl::DispatcherImpl>(protocolChannel, std::move(debuggerImpl));
693 
694     std::string msg = std::string() +
695         R"({
696             "id":0,
697             "method":"Debugger.resume",
698             "params":{
699                 "terminateOnResume":true
700             }
701         })";
702     DispatchRequest request(msg);
703 
704     dispatcherImpl->Dispatch(request);
705     EXPECT_STREQ(outStrForCallbackCheck.c_str(), R"({"id":0,"result":{}})");
706     if (protocolChannel) {
707         delete protocolChannel;
708         protocolChannel = nullptr;
709     }
710 }
711 
HWTEST_F_L0(DebuggerImplTest,Dispatcher_Dispatch_SetAsyncCallStackDepth__001)712 HWTEST_F_L0(DebuggerImplTest, Dispatcher_Dispatch_SetAsyncCallStackDepth__001)
713 {
714     std::string outStrForCallbackCheck = "";
715     std::function<void(const void*, const std::string &)> callback =
716         [&outStrForCallbackCheck]([[maybe_unused]] const void *ptr, const std::string &inStrOfReply) {
717             outStrForCallbackCheck = inStrOfReply;};
718     ProtocolChannel *protocolChannel = new ProtocolHandler(callback, ecmaVm);
719     auto runtimeImpl = std::make_unique<RuntimeImpl>(ecmaVm, protocolChannel);
720     auto debuggerImpl = std::make_unique<DebuggerImpl>(ecmaVm, protocolChannel, runtimeImpl.get());
721     auto dispatcherImpl = std::make_unique<DebuggerImpl::DispatcherImpl>(protocolChannel, std::move(debuggerImpl));
722 
723     std::string msg = std::string() +
724         R"({
725             "id":0,
726             "method":"Debugger.setAsyncCallStackDepth"
727         })";
728     DispatchRequest request(msg);
729 
730     dispatcherImpl->Dispatch(request);
731     EXPECT_STREQ(outStrForCallbackCheck.c_str(),
732         R"({"id":0,"result":{"code":1,"message":"SetAsyncCallStackDepth not support now"}})");
733     if (protocolChannel) {
734         delete protocolChannel;
735         protocolChannel = nullptr;
736     }
737 }
738 
HWTEST_F_L0(DebuggerImplTest,Dispatcher_Dispatch_SetBreakpointByUrl__001)739 HWTEST_F_L0(DebuggerImplTest, Dispatcher_Dispatch_SetBreakpointByUrl__001)
740 {
741     std::string outStrForCallbackCheck = "";
742     std::function<void(const void*, const std::string &)> callback =
743         [&outStrForCallbackCheck]([[maybe_unused]] const void *ptr, const std::string &inStrOfReply) {
744             outStrForCallbackCheck = inStrOfReply;};
745     ProtocolChannel *protocolChannel = new ProtocolHandler(callback, ecmaVm);
746     auto runtimeImpl = std::make_unique<RuntimeImpl>(ecmaVm, protocolChannel);
747     auto debuggerImpl = std::make_unique<DebuggerImpl>(ecmaVm, protocolChannel, runtimeImpl.get());
748     auto dispatcherImpl = std::make_unique<DebuggerImpl::DispatcherImpl>(protocolChannel, std::move(debuggerImpl));
749 
750     // DebuggerImpl::DispatcherImpl::SetBreakpointByUrl -- params == nullptr
751     std::string msg = std::string() +
752         R"({
753             "id":0,
754             "method":"Debugger.setBreakpointByUrl",
755             "params":{}
756         })";
757     DispatchRequest request(msg);
758 
759     dispatcherImpl->Dispatch(request);
760     EXPECT_STREQ(outStrForCallbackCheck.c_str(), R"({"id":0,"result":{"code":1,"message":"wrong params"}})");
761     if (protocolChannel) {
762         delete protocolChannel;
763         protocolChannel = nullptr;
764     }
765 }
766 
HWTEST_F_L0(DebuggerImplTest,Dispatcher_Dispatch_SetBreakpointByUrl__002)767 HWTEST_F_L0(DebuggerImplTest, Dispatcher_Dispatch_SetBreakpointByUrl__002)
768 {
769     std::string outStrForCallbackCheck = "";
770     std::function<void(const void*, const std::string &)> callback =
771         [&outStrForCallbackCheck]([[maybe_unused]] const void *ptr, const std::string &inStrOfReply) {
772             outStrForCallbackCheck = inStrOfReply;};
773     ProtocolChannel *protocolChannel = new ProtocolHandler(callback, ecmaVm);
774     auto runtimeImpl = std::make_unique<RuntimeImpl>(ecmaVm, protocolChannel);
775     auto debuggerImpl = std::make_unique<DebuggerImpl>(ecmaVm, protocolChannel, runtimeImpl.get());
776     auto dispatcherImpl = std::make_unique<DebuggerImpl::DispatcherImpl>(protocolChannel, std::move(debuggerImpl));
777     ecmaVm->GetJsDebuggerManager()->SetDebugMode(true);
778 
779     // DebuggerImpl::SetBreakpointByUrl -- extractor == nullptr
780     std::string msg = std::string() +
781         R"({
782             "id":0,
783             "method":"Debugger.setBreakpointByUrl",
784             "params":{
785                 "lineNumber":0,
786                 "url":"url_str",
787                 "urlRegex":"urlRegex_str",
788                 "scriptHash":"scriptHash_str",
789                 "columnNumber":0,
790                 "condition":"condition_str"
791             }
792         })";
793     DispatchRequest request(msg);
794 
795     dispatcherImpl->Dispatch(request);
796     EXPECT_STREQ(outStrForCallbackCheck.c_str(), R"({"id":0,"result":{"code":1,"message":"Unknown file name."}})");
797     if (protocolChannel) {
798         delete protocolChannel;
799         protocolChannel = nullptr;
800     }
801 }
802 
HWTEST_F_L0(DebuggerImplTest,Dispatcher_Dispatch_SetPauseOnExceptions__001)803 HWTEST_F_L0(DebuggerImplTest, Dispatcher_Dispatch_SetPauseOnExceptions__001)
804 {
805     std::string outStrForCallbackCheck = "";
806     std::function<void(const void*, const std::string &)> callback =
807         [&outStrForCallbackCheck]([[maybe_unused]] const void *ptr, const std::string &inStrOfReply) {
808             outStrForCallbackCheck = inStrOfReply;};
809     ProtocolChannel *protocolChannel = new ProtocolHandler(callback, ecmaVm);
810     auto runtimeImpl = std::make_unique<RuntimeImpl>(ecmaVm, protocolChannel);
811     auto debuggerImpl = std::make_unique<DebuggerImpl>(ecmaVm, protocolChannel, runtimeImpl.get());
812     auto dispatcherImpl = std::make_unique<DebuggerImpl::DispatcherImpl>(protocolChannel, std::move(debuggerImpl));
813 
814     // DebuggerImpl::DispatcherImpl::SetPauseOnExceptions -- params == nullptr
815     std::string msg = std::string() +
816         R"({
817             "id":0,
818             "method":"Debugger.setPauseOnExceptions",
819             "params":{}
820         })";
821     DispatchRequest request(msg);
822 
823     dispatcherImpl->Dispatch(request);
824     EXPECT_STREQ(outStrForCallbackCheck.c_str(), R"({"id":0,"result":{"code":1,"message":"wrong params"}})");
825     if (protocolChannel) {
826         delete protocolChannel;
827         protocolChannel = nullptr;
828     }
829 }
830 
HWTEST_F_L0(DebuggerImplTest,Dispatcher_Dispatch_SetPauseOnExceptions__002)831 HWTEST_F_L0(DebuggerImplTest, Dispatcher_Dispatch_SetPauseOnExceptions__002)
832 {
833     std::string outStrForCallbackCheck = "";
834     std::function<void(const void*, const std::string &)> callback =
835         [&outStrForCallbackCheck]([[maybe_unused]] const void *ptr, const std::string &inStrOfReply) {
836             outStrForCallbackCheck = inStrOfReply;};
837     ProtocolChannel *protocolChannel = new ProtocolHandler(callback, ecmaVm);
838     auto runtimeImpl = std::make_unique<RuntimeImpl>(ecmaVm, protocolChannel);
839     auto debuggerImpl = std::make_unique<DebuggerImpl>(ecmaVm, protocolChannel, runtimeImpl.get());
840     auto dispatcherImpl = std::make_unique<DebuggerImpl::DispatcherImpl>(protocolChannel, std::move(debuggerImpl));
841 
842     std::string msg = std::string() +
843         R"({
844             "id":0,
845             "method":"Debugger.setPauseOnExceptions",
846             "params":{
847                 "state":"all"
848             }
849         })";
850     DispatchRequest request(msg);
851 
852     dispatcherImpl->Dispatch(request);
853     EXPECT_STREQ(outStrForCallbackCheck.c_str(), R"({"id":0,"result":{}})");
854     if (protocolChannel) {
855         delete protocolChannel;
856         protocolChannel = nullptr;
857     }
858 }
859 
HWTEST_F_L0(DebuggerImplTest,Dispatcher_Dispatch_StepInto__001)860 HWTEST_F_L0(DebuggerImplTest, Dispatcher_Dispatch_StepInto__001)
861 {
862     std::string outStrForCallbackCheck = "";
863     std::function<void(const void*, const std::string &)> callback =
864         [&outStrForCallbackCheck]([[maybe_unused]] const void *ptr, const std::string &inStrOfReply) {
865             outStrForCallbackCheck = inStrOfReply;};
866     ProtocolChannel *protocolChannel = new ProtocolHandler(callback, ecmaVm);
867     auto runtimeImpl = std::make_unique<RuntimeImpl>(ecmaVm, protocolChannel);
868     auto debuggerImpl = std::make_unique<DebuggerImpl>(ecmaVm, protocolChannel, runtimeImpl.get());
869     auto dispatcherImpl = std::make_unique<DebuggerImpl::DispatcherImpl>(protocolChannel, std::move(debuggerImpl));
870 
871     // DebuggerImpl::DispatcherImpl::StepInto -- params == nullptr
872     std::string msg = std::string() +
873         R"({
874             "id":0,
875             "method":"Debugger.stepInto",
876             "params":{
877                 "breakOnAsyncCall":"Str"
878             }
879         })";
880     DispatchRequest request(msg);
881 
882     dispatcherImpl->Dispatch(request);
883     EXPECT_STREQ(outStrForCallbackCheck.c_str(), R"({"id":0,"result":{"code":1,"message":"wrong params"}})");
884     if (protocolChannel) {
885         delete protocolChannel;
886         protocolChannel = nullptr;
887     }
888 }
889 
HWTEST_F_L0(DebuggerImplTest,Dispatcher_Dispatch_SetMixedDebugEnabled__001)890 HWTEST_F_L0(DebuggerImplTest, Dispatcher_Dispatch_SetMixedDebugEnabled__001)
891 {
892     std::string outStrForCallbackCheck = "";
893     std::function<void(const void*, const std::string &)> callback =
894         [&outStrForCallbackCheck]([[maybe_unused]] const void *ptr, const std::string &inStrOfReply) {
895             outStrForCallbackCheck = inStrOfReply;};
896     ProtocolChannel *protocolChannel = new ProtocolHandler(callback, ecmaVm);
897     auto runtimeImpl = std::make_unique<RuntimeImpl>(ecmaVm, protocolChannel);
898     auto debuggerImpl = std::make_unique<DebuggerImpl>(ecmaVm, protocolChannel, runtimeImpl.get());
899     auto dispatcherImpl = std::make_unique<DebuggerImpl::DispatcherImpl>(protocolChannel, std::move(debuggerImpl));
900 
901     // DebuggerImpl::DispatcherImpl::SetMixedDebugEnabled -- Params == nullptr
902     std::string msg = std::string() +
903         R"({
904             "id":0,
905             "method":"Debugger.setMixedDebugEnabled",
906             "params":{
907                 "enabled":"NotBoolValue"
908             }
909         })";
910     DispatchRequest request(msg);
911 
912     dispatcherImpl->Dispatch(request);
913     EXPECT_STREQ(outStrForCallbackCheck.c_str(), R"({"id":0,"result":{"code":1,"message":"wrong params"}})");
914     if (protocolChannel) {
915         delete protocolChannel;
916         protocolChannel = nullptr;
917     }
918 }
919 
HWTEST_F_L0(DebuggerImplTest,Dispatcher_Dispatch_SetMixedDebugEnabled__002)920 HWTEST_F_L0(DebuggerImplTest, Dispatcher_Dispatch_SetMixedDebugEnabled__002)
921 {
922     std::string outStrForCallbackCheck = "";
923     std::function<void(const void*, const std::string &)> callback =
924         [&outStrForCallbackCheck]([[maybe_unused]] const void *ptr, const std::string &inStrOfReply) {
925             outStrForCallbackCheck = inStrOfReply;};
926     ProtocolChannel *protocolChannel = new ProtocolHandler(callback, ecmaVm);
927     auto runtimeImpl = std::make_unique<RuntimeImpl>(ecmaVm, protocolChannel);
928     auto debuggerImpl = std::make_unique<DebuggerImpl>(ecmaVm, protocolChannel, runtimeImpl.get());
929     auto dispatcherImpl = std::make_unique<DebuggerImpl::DispatcherImpl>(protocolChannel, std::move(debuggerImpl));
930     EXPECT_FALSE(ecmaVm->GetJsDebuggerManager()->IsMixedDebugEnabled());
931 
932     std::string msg = std::string() +
933         R"({
934             "id":0,
935             "method":"Debugger.setMixedDebugEnabled",
936             "params":{
937                 "enabled":true,
938                 "mixedStackEnabled":true
939             }
940         })";
941     DispatchRequest request(msg);
942 
943     dispatcherImpl->Dispatch(request);
944     EXPECT_TRUE(ecmaVm->GetJsDebuggerManager()->IsMixedDebugEnabled());
945     EXPECT_STREQ(outStrForCallbackCheck.c_str(), R"({"id":0,"result":{}})");
946     if (protocolChannel) {
947         delete protocolChannel;
948         protocolChannel = nullptr;
949     }
950 }
951 
HWTEST_F_L0(DebuggerImplTest,Dispatcher_Dispatch_SetBlackboxPatterns__001)952 HWTEST_F_L0(DebuggerImplTest, Dispatcher_Dispatch_SetBlackboxPatterns__001)
953 {
954     std::string outStrForCallbackCheck = "";
955     std::function<void(const void*, const std::string &)> callback =
956         [&outStrForCallbackCheck]([[maybe_unused]] const void *ptr, const std::string &inStrOfReply) {
957             outStrForCallbackCheck = inStrOfReply;};
958     ProtocolChannel *protocolChannel = new ProtocolHandler(callback, ecmaVm);
959     auto runtimeImpl = std::make_unique<RuntimeImpl>(ecmaVm, protocolChannel);
960     auto debuggerImpl = std::make_unique<DebuggerImpl>(ecmaVm, protocolChannel, runtimeImpl.get());
961     auto dispatcherImpl = std::make_unique<DebuggerImpl::DispatcherImpl>(protocolChannel, std::move(debuggerImpl));
962 
963     std::string msg = std::string() +
964         R"({
965             "id":0,
966             "method":"Debugger.setBlackboxPatterns"
967         })";
968     DispatchRequest request(msg);
969 
970     dispatcherImpl->Dispatch(request);
971     EXPECT_STREQ(outStrForCallbackCheck.c_str(),
972         R"({"id":0,"result":{"code":1,"message":"SetBlackboxPatterns not support now"}})");
973     if (protocolChannel) {
974         delete protocolChannel;
975         protocolChannel = nullptr;
976     }
977 }
978 
HWTEST_F_L0(DebuggerImplTest,Dispatcher_Dispatch_ReplyNativeCalling__001)979 HWTEST_F_L0(DebuggerImplTest, Dispatcher_Dispatch_ReplyNativeCalling__001)
980 {
981     std::string outStrForCallbackCheck = "";
982     std::function<void(const void*, const std::string &)> callback =
983         [&outStrForCallbackCheck]([[maybe_unused]] const void *ptr, const std::string &inStrOfReply) {
984             outStrForCallbackCheck = inStrOfReply;};
985     ProtocolChannel *protocolChannel = new ProtocolHandler(callback, ecmaVm);
986     auto runtimeImpl = std::make_unique<RuntimeImpl>(ecmaVm, protocolChannel);
987     auto debuggerImpl = std::make_unique<DebuggerImpl>(ecmaVm, protocolChannel, runtimeImpl.get());
988     auto dispatcherImpl = std::make_unique<DebuggerImpl::DispatcherImpl>(protocolChannel, std::move(debuggerImpl));
989 
990     // DebuggerImpl::DispatcherImpl::ReplyNativeCalling -- params == nullptr
991     std::string msg = std::string() +
992         R"({
993             "id":0,
994             "method":"Debugger.replyNativeCalling",
995             "params":{
996                 "userCode":"NotBoolValue"
997             }
998         })";
999     DispatchRequest request(msg);
1000 
1001     dispatcherImpl->Dispatch(request);
1002     EXPECT_STREQ(outStrForCallbackCheck.c_str(), R"({"id":0,"result":{"code":1,"message":"wrong params"}})");
1003     if (protocolChannel) {
1004         delete protocolChannel;
1005         protocolChannel = nullptr;
1006     }
1007 }
1008 
HWTEST_F_L0(DebuggerImplTest,Dispatcher_Dispatch_ReplyNativeCalling__002)1009 HWTEST_F_L0(DebuggerImplTest, Dispatcher_Dispatch_ReplyNativeCalling__002)
1010 {
1011     std::string outStrForCallbackCheck = "";
1012     std::function<void(const void*, const std::string &)> callback =
1013         [&outStrForCallbackCheck]([[maybe_unused]] const void *ptr, const std::string &inStrOfReply) {
1014             outStrForCallbackCheck = inStrOfReply;};
1015     ProtocolChannel *protocolChannel = new ProtocolHandler(callback, ecmaVm);
1016     auto runtimeImpl = std::make_unique<RuntimeImpl>(ecmaVm, protocolChannel);
1017     auto debuggerImpl = std::make_unique<DebuggerImpl>(ecmaVm, protocolChannel, runtimeImpl.get());
1018     auto dispatcherImpl = std::make_unique<DebuggerImpl::DispatcherImpl>(protocolChannel, std::move(debuggerImpl));
1019 
1020     std::string msg = std::string() +
1021         R"({
1022             "id":0,
1023             "method":"Debugger.replyNativeCalling",
1024             "params":{
1025                 "userCode":true
1026             }
1027         })";
1028     DispatchRequest request(msg);
1029 
1030     dispatcherImpl->Dispatch(request);
1031     EXPECT_STREQ(outStrForCallbackCheck.c_str(), R"({"id":0,"result":{}})");
1032     if (protocolChannel) {
1033         delete protocolChannel;
1034         protocolChannel = nullptr;
1035     }
1036 }
1037 
HWTEST_F_L0(DebuggerImplTest,Dispatcher_Dispatch_ContinueToLocation__001)1038 HWTEST_F_L0(DebuggerImplTest, Dispatcher_Dispatch_ContinueToLocation__001)
1039 {
1040     std::string outStrForCallbackCheck = "";
1041     std::function<void(const void*, const std::string &)> callback =
1042         [&outStrForCallbackCheck]([[maybe_unused]] const void *ptr, const std::string &inStrOfReply) {
1043             outStrForCallbackCheck = inStrOfReply;};
1044     ProtocolChannel *protocolChannel = new ProtocolHandler(callback, ecmaVm);
1045     auto runtimeImpl = std::make_unique<RuntimeImpl>(ecmaVm, protocolChannel);
1046     auto debuggerImpl = std::make_unique<DebuggerImpl>(ecmaVm, protocolChannel, runtimeImpl.get());
1047     auto dispatcherImpl = std::make_unique<DebuggerImpl::DispatcherImpl>(protocolChannel, std::move(debuggerImpl));
1048 
1049     std::string msg = std::string() +
1050         R"({
1051             "id":0,
1052             "method":"Debugger.continueToLocation",
1053             "params":{}
1054         })";
1055     DispatchRequest request(msg);
1056 
1057     dispatcherImpl->Dispatch(request);
1058     EXPECT_STREQ(outStrForCallbackCheck.c_str(), R"({"id":0,"result":{"code":1,"message":"wrong params"}})");
1059     if (protocolChannel) {
1060         delete protocolChannel;
1061         protocolChannel = nullptr;
1062     }
1063 }
1064 
HWTEST_F_L0(DebuggerImplTest,Dispatcher_Dispatch_ContinueToLocation__002)1065 HWTEST_F_L0(DebuggerImplTest, Dispatcher_Dispatch_ContinueToLocation__002)
1066 {
1067     std::string outStrForCallbackCheck = "";
1068     std::function<void(const void*, const std::string &)> callback =
1069         [&outStrForCallbackCheck]([[maybe_unused]] const void *ptr, const std::string &inStrOfReply) {
1070             outStrForCallbackCheck = inStrOfReply;};
1071     ProtocolChannel *protocolChannel = new ProtocolHandler(callback, ecmaVm);
1072     auto runtimeImpl = std::make_unique<RuntimeImpl>(ecmaVm, protocolChannel);
1073     auto debuggerImpl = std::make_unique<DebuggerImpl>(ecmaVm, protocolChannel, runtimeImpl.get());
1074     auto dispatcherImpl = std::make_unique<DebuggerImpl::DispatcherImpl>(protocolChannel, std::move(debuggerImpl));
1075 
1076     std::string msg = std::string() +
1077         R"({
1078             "id":0,
1079             "method":"Debugger.continueToLocation",
1080             "params":{
1081                 "location":{
1082                     "scriptId":"2",
1083                     "lineNumber":3,
1084                     "columnNumber":20
1085                 },
1086                 "targetCallFrames":"testTargetCallFrames"
1087             }
1088         })";
1089     DispatchRequest request(msg);
1090 
1091     dispatcherImpl->Dispatch(request);
1092     EXPECT_STREQ(outStrForCallbackCheck.c_str(), R"({"id":0,"result":{}})");
1093     if (protocolChannel) {
1094         delete protocolChannel;
1095         protocolChannel = nullptr;
1096     }
1097 }
1098 
HWTEST_F_L0(DebuggerImplTest,Dispatcher_Dispatch_SetBreakpointsActive__001)1099 HWTEST_F_L0(DebuggerImplTest, Dispatcher_Dispatch_SetBreakpointsActive__001)
1100 {
1101     std::string outStrForCallbackCheck = "";
1102     std::function<void(const void*, const std::string &)> callback =
1103         [&outStrForCallbackCheck]([[maybe_unused]] const void *ptr, const std::string &inStrOfReply) {
1104             outStrForCallbackCheck = inStrOfReply;};
1105     ProtocolChannel *protocolChannel = new ProtocolHandler(callback, ecmaVm);
1106     auto runtimeImpl = std::make_unique<RuntimeImpl>(ecmaVm, protocolChannel);
1107     auto debuggerImpl = std::make_unique<DebuggerImpl>(ecmaVm, protocolChannel, runtimeImpl.get());
1108     auto dispatcherImpl = std::make_unique<DebuggerImpl::DispatcherImpl>(protocolChannel, std::move(debuggerImpl));
1109 
1110     std::string msg = std::string() +
1111         R"({
1112             "id":0,
1113             "method":"Debugger.setBreakpointsActive",
1114             "params":{}
1115         })";
1116     DispatchRequest request(msg);
1117 
1118     dispatcherImpl->Dispatch(request);
1119     EXPECT_STREQ(outStrForCallbackCheck.c_str(), R"({"id":0,"result":{"code":1,"message":"wrong params"}})");
1120     if (protocolChannel) {
1121         delete protocolChannel;
1122         protocolChannel = nullptr;
1123     }
1124 }
1125 
HWTEST_F_L0(DebuggerImplTest,Dispatcher_Dispatch_SetBreakpointsActive__002)1126 HWTEST_F_L0(DebuggerImplTest, Dispatcher_Dispatch_SetBreakpointsActive__002)
1127 {
1128     std::string outStrForCallbackCheck = "";
1129     std::function<void(const void*, const std::string &)> callback =
1130         [&outStrForCallbackCheck]([[maybe_unused]] const void *ptr, const std::string &inStrOfReply) {
1131             outStrForCallbackCheck = inStrOfReply;};
1132     ProtocolChannel *protocolChannel = new ProtocolHandler(callback, ecmaVm);
1133     auto runtimeImpl = std::make_unique<RuntimeImpl>(ecmaVm, protocolChannel);
1134     auto debuggerImpl = std::make_unique<DebuggerImpl>(ecmaVm, protocolChannel, runtimeImpl.get());
1135     auto dispatcherImpl = std::make_unique<DebuggerImpl::DispatcherImpl>(protocolChannel, std::move(debuggerImpl));
1136 
1137     std::string msg = std::string() +
1138         R"({
1139             "id":0,
1140             "method":"Debugger.setBreakpointsActive",
1141             "params":{
1142                 "active":true
1143             }
1144         })";
1145     DispatchRequest request(msg);
1146 
1147     dispatcherImpl->Dispatch(request);
1148     EXPECT_STREQ(outStrForCallbackCheck.c_str(), R"({"id":0,"result":{}})");
1149     if (protocolChannel) {
1150         delete protocolChannel;
1151         protocolChannel = nullptr;
1152     }
1153 }
1154 
HWTEST_F_L0(DebuggerImplTest,Dispatcher_Dispatch_SetSkipAllPauses__001)1155 HWTEST_F_L0(DebuggerImplTest, Dispatcher_Dispatch_SetSkipAllPauses__001)
1156 {
1157     std::string outStrForCallbackCheck = "";
1158     std::function<void(const void*, const std::string &)> callback =
1159         [&outStrForCallbackCheck]([[maybe_unused]] const void *ptr, const std::string &inStrOfReply) {
1160             outStrForCallbackCheck = inStrOfReply;};
1161     ProtocolChannel *protocolChannel = new ProtocolHandler(callback, ecmaVm);
1162     auto runtimeImpl = std::make_unique<RuntimeImpl>(ecmaVm, protocolChannel);
1163     auto debuggerImpl = std::make_unique<DebuggerImpl>(ecmaVm, protocolChannel, runtimeImpl.get());
1164     auto dispatcherImpl = std::make_unique<DebuggerImpl::DispatcherImpl>(protocolChannel, std::move(debuggerImpl));
1165 
1166     std::string msg = std::string() +
1167         R"({
1168             "id":0,
1169             "method":"Debugger.setSkipAllPauses",
1170             "params":{}
1171         })";
1172     DispatchRequest request(msg);
1173 
1174     dispatcherImpl->Dispatch(request);
1175     EXPECT_STREQ(outStrForCallbackCheck.c_str(), R"({"id":0,"result":{"code":1,"message":"wrong params"}})");
1176     if (protocolChannel) {
1177         delete protocolChannel;
1178         protocolChannel = nullptr;
1179     }
1180 }
1181 
HWTEST_F_L0(DebuggerImplTest,Dispatcher_Dispatch_SetSkipAllPauses__002)1182 HWTEST_F_L0(DebuggerImplTest, Dispatcher_Dispatch_SetSkipAllPauses__002)
1183 {
1184     std::string outStrForCallbackCheck = "";
1185     std::function<void(const void*, const std::string &)> callback =
1186         [&outStrForCallbackCheck]([[maybe_unused]] const void *ptr, const std::string &inStrOfReply) {
1187             outStrForCallbackCheck = inStrOfReply;};
1188     ProtocolChannel *protocolChannel = new ProtocolHandler(callback, ecmaVm);
1189     auto runtimeImpl = std::make_unique<RuntimeImpl>(ecmaVm, protocolChannel);
1190     auto debuggerImpl = std::make_unique<DebuggerImpl>(ecmaVm, protocolChannel, runtimeImpl.get());
1191     auto dispatcherImpl = std::make_unique<DebuggerImpl::DispatcherImpl>(protocolChannel, std::move(debuggerImpl));
1192 
1193     std::string msg = std::string() +
1194         R"({
1195             "id":0,
1196             "method":"Debugger.setSkipAllPauses",
1197             "params":{
1198                 "skip":true
1199             }
1200         })";
1201     DispatchRequest request(msg);
1202 
1203     dispatcherImpl->Dispatch(request);
1204     EXPECT_STREQ(outStrForCallbackCheck.c_str(), R"({"id":0,"result":{}})");
1205     if (protocolChannel) {
1206         delete protocolChannel;
1207         protocolChannel = nullptr;
1208     }
1209 }
1210 
HWTEST_F_L0(DebuggerImplTest,Dispatcher_Dispatch_GetPossibleAndSetBreakpoint__001)1211 HWTEST_F_L0(DebuggerImplTest, Dispatcher_Dispatch_GetPossibleAndSetBreakpoint__001)
1212 {
1213     std::string outStrForCallbackCheck = "";
1214     std::function<void(const void*, const std::string &)> callback =
1215         [&outStrForCallbackCheck]([[maybe_unused]] const void *ptr, const std::string &inStrOfReply) {
1216             outStrForCallbackCheck = inStrOfReply;};
1217     ProtocolChannel *protocolChannel = new ProtocolHandler(callback, ecmaVm);
1218     auto runtimeImpl = std::make_unique<RuntimeImpl>(ecmaVm, protocolChannel);
1219     auto debuggerImpl = std::make_unique<DebuggerImpl>(ecmaVm, protocolChannel, runtimeImpl.get());
1220     ecmaVm->GetJsDebuggerManager()->SetDebugMode(true);
1221     auto dispatcherImpl = std::make_unique<DebuggerImpl::DispatcherImpl>(protocolChannel, std::move(debuggerImpl));
1222 
1223     std::string msg = std::string() +
1224         R"({
1225             "id":0,
1226             "method":"Debugger.getPossibleAndSetBreakpointByUrl",
1227             "params":{}
1228         })";
1229     DispatchRequest request(msg);
1230 
1231     dispatcherImpl->Dispatch(request);
1232     EXPECT_STREQ(outStrForCallbackCheck.c_str(),
1233         R"({"id":0,"result":{"code":1,"message":"GetPossibleAndSetBreakpointByUrl: no pennding breakpoint exists"}})");
1234     if (protocolChannel) {
1235         delete protocolChannel;
1236         protocolChannel = nullptr;
1237     }
1238 }
1239 
HWTEST_F_L0(DebuggerImplTest,Dispatcher_Dispatch_GetPossibleAndSetBreakpoint__002)1240 HWTEST_F_L0(DebuggerImplTest, Dispatcher_Dispatch_GetPossibleAndSetBreakpoint__002)
1241 {
1242     std::string outStrForCallbackCheck = "";
1243     std::function<void(const void*, const std::string &)> callback =
1244         [&outStrForCallbackCheck]([[maybe_unused]] const void *ptr, const std::string &inStrOfReply) {
1245             outStrForCallbackCheck = inStrOfReply;};
1246     ProtocolChannel *protocolChannel = new ProtocolHandler(callback, ecmaVm);
1247     auto runtimeImpl = std::make_unique<RuntimeImpl>(ecmaVm, protocolChannel);
1248     auto debuggerImpl = std::make_unique<DebuggerImpl>(ecmaVm, protocolChannel, runtimeImpl.get());
1249     ecmaVm->GetJsDebuggerManager()->SetDebugMode(true);
1250     auto dispatcherImpl = std::make_unique<DebuggerImpl::DispatcherImpl>(protocolChannel, std::move(debuggerImpl));
1251 
1252     std::string msg = std::string() +
1253         R"({
1254             "id":0,
1255             "method":"Debugger.getPossibleAndSetBreakpointByUrl",
1256             "params":{
1257                 "locations":[
1258                     {
1259                         "lineNumber":3,
1260                         "columnNumber":20,
1261                         "url":"Index.ets"
1262                     }]
1263             }
1264         })";
1265     DispatchRequest request(msg);
1266 
1267     dispatcherImpl->Dispatch(request);
1268     EXPECT_STREQ(outStrForCallbackCheck.c_str(),
1269         R"({"id":0,"result":{"locations":[{"lineNumber":3,"columnNumber":20,"id":"invalid","scriptId":0}]}})");
1270     if (protocolChannel) {
1271         delete protocolChannel;
1272         protocolChannel = nullptr;
1273     }
1274 }
1275 
HWTEST_F_L0(DebuggerImplTest,Dispatcher_Dispatch_DropFrame__001)1276 HWTEST_F_L0(DebuggerImplTest, Dispatcher_Dispatch_DropFrame__001)
1277 {
1278     std::string outStrForCallbackCheck = "";
1279     std::function<void(const void*, const std::string &)> callback =
1280         [&outStrForCallbackCheck]([[maybe_unused]] const void *ptr, const std::string &inStrOfReply) {
1281             outStrForCallbackCheck = inStrOfReply;};
1282     ProtocolChannel *protocolChannel = new ProtocolHandler(callback, ecmaVm);
1283     auto runtimeImpl = std::make_unique<RuntimeImpl>(ecmaVm, protocolChannel);
1284     auto debuggerImpl = std::make_unique<DebuggerImpl>(ecmaVm, protocolChannel, runtimeImpl.get());
1285     debuggerImpl->SetDebuggerState(DebuggerState::PAUSED);
1286     auto dispatcherImpl = std::make_unique<DebuggerImpl::DispatcherImpl>(protocolChannel, std::move(debuggerImpl));
1287 
1288     std::string msg = std::string() +
1289         R"({
1290             "id":0,
1291             "method":"Debugger.dropFrame",
1292             "params":{
1293                 "droppedDepth":3
1294             }
1295         })";
1296     DispatchRequest request(msg);
1297 
1298     dispatcherImpl->Dispatch(request);
1299     EXPECT_STREQ(outStrForCallbackCheck.c_str(),
1300         R"({"id":0,"result":{"code":1,"message":"Not yet support dropping multiple frames"}})");
1301     if (protocolChannel) {
1302         delete protocolChannel;
1303         protocolChannel = nullptr;
1304     }
1305 }
1306 
HWTEST_F_L0(DebuggerImplTest,DispatcherImplCallFunctionOn)1307 HWTEST_F_L0(DebuggerImplTest, DispatcherImplCallFunctionOn)
1308 {
1309     std::string outStrForCallbackCheck = "";
1310     std::function<void(const void*, const std::string &)> callback =
1311         [&outStrForCallbackCheck]([[maybe_unused]] const void *ptr, const std::string &inStrOfReply) {
1312             outStrForCallbackCheck = inStrOfReply;};
1313     ProtocolChannel *protocolChannel = new ProtocolHandler(callback, ecmaVm);
1314     auto runtimeImpl = std::make_unique<RuntimeImpl>(ecmaVm, protocolChannel);
1315     auto debuggerImpl = std::make_unique<DebuggerImpl>(ecmaVm, protocolChannel, runtimeImpl.get());
1316     auto dispatcherImpl = std::make_unique<DebuggerImpl::DispatcherImpl>(protocolChannel, std::move(debuggerImpl));
1317 
1318     std::string msg = std::string() + R"({"id":0,"method":"Debugger.callFunctionOn","params":{
1319         "callFrameId":"0", "functionDeclaration":0}})";
1320     DispatchRequest request(msg);
1321     dispatcherImpl->CallFunctionOn(request);
1322     ASSERT_TRUE(outStrForCallbackCheck.find("wrong params") != std::string::npos);
1323 
1324     msg = std::string() + R"({"id":0,"method":"Debugger.callFunctionOn","params":{
1325         "callFrameId":"0", "functionDeclaration":"test"}})";
1326     DispatchRequest request1(msg);
1327     dispatcherImpl->CallFunctionOn(request1);
1328     ASSERT_TRUE(outStrForCallbackCheck.find("Unsupport eval now") == std::string::npos);
1329     if (protocolChannel != nullptr) {
1330         delete protocolChannel;
1331         protocolChannel = nullptr;
1332     }
1333 }
1334 
HWTEST_F_L0(DebuggerImplTest,Dispatcher_Dispatch_SmartStepInto__001)1335 HWTEST_F_L0(DebuggerImplTest, Dispatcher_Dispatch_SmartStepInto__001)
1336 {
1337     std::string outStrForCallbackCheck = "";
1338     std::function<void(const void*, const std::string &)> callback =
1339         [&outStrForCallbackCheck]([[maybe_unused]] const void *ptr, const std::string &inStrOfReply) {
1340             outStrForCallbackCheck = inStrOfReply;};
1341     ProtocolChannel *protocolChannel = new ProtocolHandler(callback, ecmaVm);
1342     auto runtimeImpl = std::make_unique<RuntimeImpl>(ecmaVm, protocolChannel);
1343     auto debuggerImpl = std::make_unique<DebuggerImpl>(ecmaVm, protocolChannel, runtimeImpl.get());
1344     auto dispatcherImpl = std::make_unique<DebuggerImpl::DispatcherImpl>(protocolChannel, std::move(debuggerImpl));
1345 
1346     std::string msg = std::string() +
1347         R"({
1348             "id":0,
1349             "method":"Debugger.smartStepInto",
1350             "params":{}
1351         })";
1352     DispatchRequest request(msg);
1353 
1354     dispatcherImpl->Dispatch(request);
1355     EXPECT_STREQ(outStrForCallbackCheck.c_str(),
1356         R"({"id":0,"result":{"code":1,"message":"wrong params"}})");
1357     if (protocolChannel) {
1358         delete protocolChannel;
1359         protocolChannel = nullptr;
1360     }
1361 }
1362 
HWTEST_F_L0(DebuggerImplTest,Dispatcher_Dispatch_SmartStepInto__002)1363 HWTEST_F_L0(DebuggerImplTest, Dispatcher_Dispatch_SmartStepInto__002)
1364 {
1365     std::string outStrForCallbackCheck = "";
1366     std::function<void(const void*, const std::string &)> callback =
1367         [&outStrForCallbackCheck]([[maybe_unused]] const void *ptr, const std::string &inStrOfReply) {
1368             outStrForCallbackCheck = inStrOfReply;};
1369     ProtocolChannel *protocolChannel = new ProtocolHandler(callback, ecmaVm);
1370     auto runtimeImpl = std::make_unique<RuntimeImpl>(ecmaVm, protocolChannel);
1371     auto debuggerImpl = std::make_unique<DebuggerImpl>(ecmaVm, protocolChannel, runtimeImpl.get());
1372     auto dispatcherImpl = std::make_unique<DebuggerImpl::DispatcherImpl>(protocolChannel, std::move(debuggerImpl));
1373 
1374     std::string msg = std::string() +
1375         R"({
1376             "id":0,
1377             "method":"Debugger.smartStepInto",
1378             "params":{
1379                 "lineNumber":0,
1380                 "url":"url_str",
1381                 "urlRegex":"urlRegex_str",
1382                 "scriptHash":"scriptHash_str",
1383                 "columnNumber":0,
1384                 "condition":"condition_str"
1385             }
1386         })";
1387     DispatchRequest request(msg);
1388 
1389     dispatcherImpl->Dispatch(request);
1390     EXPECT_STREQ(outStrForCallbackCheck.c_str(),
1391         R"({"id":0,"result":{"code":1,"message":"Can only perform operation while paused"}})");
1392     if (protocolChannel) {
1393         delete protocolChannel;
1394         protocolChannel = nullptr;
1395     }
1396 }
1397 
HWTEST_F_L0(DebuggerImplTest,Dispatcher_Dispatch_SmartStepInto__003)1398 HWTEST_F_L0(DebuggerImplTest, Dispatcher_Dispatch_SmartStepInto__003)
1399 {
1400     std::string outStrForCallbackCheck = "";
1401     std::function<void(const void*, const std::string &)> callback =
1402         [&outStrForCallbackCheck]([[maybe_unused]] const void *ptr, const std::string &inStrOfReply) {
1403             outStrForCallbackCheck = inStrOfReply;};
1404     ProtocolChannel *protocolChannel = new ProtocolHandler(callback, ecmaVm);
1405     auto runtimeImpl = std::make_unique<RuntimeImpl>(ecmaVm, protocolChannel);
1406     auto debuggerImpl = std::make_unique<DebuggerImpl>(ecmaVm, protocolChannel, runtimeImpl.get());
1407     debuggerImpl->SetDebuggerState(DebuggerState::PAUSED);
1408     auto dispatcherImpl = std::make_unique<DebuggerImpl::DispatcherImpl>(protocolChannel, std::move(debuggerImpl));
1409 
1410     std::string msg = std::string() +
1411         R"({
1412             "id":0,
1413             "method":"Debugger.smartStepInto",
1414             "params":{
1415                 "lineNumber":0,
1416                 "url":"url_str",
1417                 "urlRegex":"urlRegex_str",
1418                 "scriptHash":"scriptHash_str",
1419                 "columnNumber":0,
1420                 "condition":"condition_str"
1421             }
1422         })";
1423     DispatchRequest request(msg);
1424 
1425     dispatcherImpl->Dispatch(request);
1426     EXPECT_STREQ(outStrForCallbackCheck.c_str(),
1427         R"({"id":0,"result":{"code":1,"message":"SetBreakpointByUrl: debugger agent is not enabled"}})");
1428     if (protocolChannel) {
1429         delete protocolChannel;
1430         protocolChannel = nullptr;
1431     }
1432 }
1433 
HWTEST_F_L0(DebuggerImplTest,Dispatcher_Dispatch_SetNativeRange__001)1434 HWTEST_F_L0(DebuggerImplTest, Dispatcher_Dispatch_SetNativeRange__001)
1435 {
1436     std::string outStrForCallbackCheck = "";
1437     std::function<void(const void*, const std::string &)> callback =
1438         [&outStrForCallbackCheck]([[maybe_unused]] const void *ptr, const std::string &inStrOfReply) {
1439             outStrForCallbackCheck = inStrOfReply;};
1440     ProtocolChannel *protocolChannel = new ProtocolHandler(callback, ecmaVm);
1441     auto runtimeImpl = std::make_unique<RuntimeImpl>(ecmaVm, protocolChannel);
1442     auto debuggerImpl = std::make_unique<DebuggerImpl>(ecmaVm, protocolChannel, runtimeImpl.get());
1443     auto dispatcherImpl = std::make_unique<DebuggerImpl::DispatcherImpl>(protocolChannel, std::move(debuggerImpl));
1444 
1445     std::string msg = std::string() +
1446         R"({
1447             "id":0,
1448             "method":"Debugger.setNativeRange",
1449             "params":{
1450                 "nativeRange":""
1451             }
1452         })";
1453     DispatchRequest request(msg);
1454 
1455     dispatcherImpl->Dispatch(request);
1456     EXPECT_STREQ(outStrForCallbackCheck.c_str(),
1457         R"({"id":0,"result":{"code":1,"message":"wrong params"}})");
1458     if (protocolChannel) {
1459         delete protocolChannel;
1460         protocolChannel = nullptr;
1461     }
1462 }
1463 
HWTEST_F_L0(DebuggerImplTest,Dispatcher_Dispatch_SetNativeRange__002)1464 HWTEST_F_L0(DebuggerImplTest, Dispatcher_Dispatch_SetNativeRange__002)
1465 {
1466     std::string outStrForCallbackCheck = "";
1467     std::function<void(const void*, const std::string &)> callback =
1468         [&outStrForCallbackCheck]([[maybe_unused]] const void *ptr, const std::string &inStrOfReply) {
1469             outStrForCallbackCheck = inStrOfReply;};
1470     ProtocolChannel *protocolChannel = new ProtocolHandler(callback, ecmaVm);
1471     auto runtimeImpl = std::make_unique<RuntimeImpl>(ecmaVm, protocolChannel);
1472     auto debuggerImpl = std::make_unique<DebuggerImpl>(ecmaVm, protocolChannel, runtimeImpl.get());
1473     auto dispatcherImpl = std::make_unique<DebuggerImpl::DispatcherImpl>(protocolChannel, std::move(debuggerImpl));
1474 
1475     std::string msg = std::string() +
1476         R"({
1477             "id":0,
1478             "method":"Debugger.setNativeRange",
1479             "params":{}
1480         })";
1481     DispatchRequest request(msg);
1482 
1483     dispatcherImpl->Dispatch(request);
1484     EXPECT_STREQ(outStrForCallbackCheck.c_str(),
1485         R"({"id":0,"result":{}})");
1486     if (protocolChannel) {
1487         delete protocolChannel;
1488         protocolChannel = nullptr;
1489     }
1490 }
1491 
HWTEST_F_L0(DebuggerImplTest,Dispatcher_Dispatch_ResetSingleStepper__001)1492 HWTEST_F_L0(DebuggerImplTest, Dispatcher_Dispatch_ResetSingleStepper__001)
1493 {
1494     std::string outStrForCallbackCheck = "";
1495     std::function<void(const void*, const std::string &)> callback =
1496         [&outStrForCallbackCheck]([[maybe_unused]] const void *ptr, const std::string &inStrOfReply) {
1497             outStrForCallbackCheck = inStrOfReply;};
1498     ProtocolChannel *protocolChannel = new ProtocolHandler(callback, ecmaVm);
1499     auto runtimeImpl = std::make_unique<RuntimeImpl>(ecmaVm, protocolChannel);
1500     auto debuggerImpl = std::make_unique<DebuggerImpl>(ecmaVm, protocolChannel, runtimeImpl.get());
1501     auto dispatcherImpl = std::make_unique<DebuggerImpl::DispatcherImpl>(protocolChannel, std::move(debuggerImpl));
1502 
1503     std::string msg = std::string() +
1504         R"({
1505             "id":0,
1506             "method":"Debugger.resetSingleStepper",
1507             "params":{
1508                 "resetSingleStepper":"test"
1509             }
1510         })";
1511     DispatchRequest request(msg);
1512 
1513     dispatcherImpl->Dispatch(request);
1514     EXPECT_STREQ(outStrForCallbackCheck.c_str(),
1515         R"({"id":0,"result":{"code":1,"message":"wrong params"}})");
1516     if (protocolChannel) {
1517         delete protocolChannel;
1518         protocolChannel = nullptr;
1519     }
1520 }
1521 
HWTEST_F_L0(DebuggerImplTest,Dispatcher_Dispatch_ResetSingleStepper__002)1522 HWTEST_F_L0(DebuggerImplTest, Dispatcher_Dispatch_ResetSingleStepper__002)
1523 {
1524     std::string outStrForCallbackCheck = "";
1525     std::function<void(const void*, const std::string &)> callback =
1526         [&outStrForCallbackCheck]([[maybe_unused]] const void *ptr, const std::string &inStrOfReply) {
1527             outStrForCallbackCheck = inStrOfReply;};
1528     ProtocolChannel *protocolChannel = new ProtocolHandler(callback, ecmaVm);
1529     auto runtimeImpl = std::make_unique<RuntimeImpl>(ecmaVm, protocolChannel);
1530     auto debuggerImpl = std::make_unique<DebuggerImpl>(ecmaVm, protocolChannel, runtimeImpl.get());
1531     auto dispatcherImpl = std::make_unique<DebuggerImpl::DispatcherImpl>(protocolChannel, std::move(debuggerImpl));
1532 
1533     std::string msg = std::string() +
1534         R"({
1535             "id":0,
1536             "method":"Debugger.resetSingleStepper",
1537             "params":{
1538                 "resetSingleStepper":true
1539             }
1540         })";
1541     DispatchRequest request(msg);
1542 
1543     dispatcherImpl->Dispatch(request);
1544     EXPECT_STREQ(outStrForCallbackCheck.c_str(),
1545         R"({"id":0,"result":{}})");
1546     if (protocolChannel) {
1547         delete protocolChannel;
1548         protocolChannel = nullptr;
1549     }
1550 }
1551 
HWTEST_F_L0(DebuggerImplTest,Dispatcher_Dispatch_ClientDisconnect)1552 HWTEST_F_L0(DebuggerImplTest, Dispatcher_Dispatch_ClientDisconnect)
1553 {
1554     std::string outStrForCallbackCheck = "";
1555     std::function<void(const void*, const std::string &)> callback =
1556         [&outStrForCallbackCheck]([[maybe_unused]] const void *ptr, const std::string &inStrOfReply) {
1557             outStrForCallbackCheck = inStrOfReply;};
1558     ProtocolChannel *protocolChannel = new ProtocolHandler(callback, ecmaVm);
1559     auto runtimeImpl = std::make_unique<RuntimeImpl>(ecmaVm, protocolChannel);
1560     auto debuggerImpl = std::make_unique<DebuggerImpl>(ecmaVm, protocolChannel, runtimeImpl.get());
1561     auto dispatcherImpl = std::make_unique<DebuggerImpl::DispatcherImpl>(protocolChannel, std::move(debuggerImpl));
1562 
1563     std::string msg = std::string() +
1564         R"({
1565             "id":0,
1566             "method":"Debugger.clientDisconnect",
1567             "params":{}
1568         })";
1569     DispatchRequest request(msg);
1570 
1571     dispatcherImpl->Dispatch(request);
1572     EXPECT_STREQ(outStrForCallbackCheck.c_str(), R"()");
1573     if (protocolChannel) {
1574         delete protocolChannel;
1575         protocolChannel = nullptr;
1576     }
1577 }
1578 
HWTEST_F_L0(DebuggerImplTest,Dispatcher_Dispatch_CallFunctionOn__001)1579 HWTEST_F_L0(DebuggerImplTest, Dispatcher_Dispatch_CallFunctionOn__001)
1580 {
1581     std::string outStrForCallbackCheck = "";
1582     std::function<void(const void*, const std::string &)> callback =
1583         [&outStrForCallbackCheck]([[maybe_unused]] const void *ptr, const std::string &inStrOfReply) {
1584             outStrForCallbackCheck = inStrOfReply;};
1585     ProtocolChannel *protocolChannel = new ProtocolHandler(callback, ecmaVm);
1586     auto runtimeImpl = std::make_unique<RuntimeImpl>(ecmaVm, protocolChannel);
1587     auto debuggerImpl = std::make_unique<DebuggerImpl>(ecmaVm, protocolChannel, runtimeImpl.get());
1588     auto dispatcherImpl = std::make_unique<DebuggerImpl::DispatcherImpl>(protocolChannel, std::move(debuggerImpl));
1589 
1590     std::string msg = std::string() +
1591         R"({
1592             "id":0,
1593             "method":"Debugger.callFunctionOn",
1594             "params":{
1595                 "callFrameId":"1",
1596                 "functionDeclaration":"test"
1597             }
1598         })";
1599     DispatchRequest request(msg);
1600 
1601     dispatcherImpl->Dispatch(request);
1602     EXPECT_STREQ(outStrForCallbackCheck.c_str(),
1603         R"({"id":0,"result":{"code":1,"message":"Invalid callFrameId."}})");
1604     if (protocolChannel) {
1605         delete protocolChannel;
1606         protocolChannel = nullptr;
1607     }
1608 }
1609 
HWTEST_F_L0(DebuggerImplTest,Dispatcher_Dispatch_CallFunctionOn__002)1610 HWTEST_F_L0(DebuggerImplTest, Dispatcher_Dispatch_CallFunctionOn__002)
1611 {
1612     std::string outStrForCallbackCheck = "";
1613     std::function<void(const void*, const std::string &)> callback =
1614         [&outStrForCallbackCheck]([[maybe_unused]] const void *ptr, const std::string &inStrOfReply) {
1615             outStrForCallbackCheck = inStrOfReply;};
1616     ProtocolChannel *protocolChannel = new ProtocolHandler(callback, ecmaVm);
1617     auto runtimeImpl = std::make_unique<RuntimeImpl>(ecmaVm, protocolChannel);
1618     auto debuggerImpl = std::make_unique<DebuggerImpl>(ecmaVm, protocolChannel, runtimeImpl.get());
1619     auto dispatcherImpl = std::make_unique<DebuggerImpl::DispatcherImpl>(protocolChannel, std::move(debuggerImpl));
1620 
1621     std::string msg = std::string() +
1622         R"({
1623             "id":0,
1624             "method":"Debugger.callFunctionOn",
1625             "params":{
1626                 "callFrameId":"0",
1627                 "functionDeclaration":0
1628             }
1629         })";
1630     DispatchRequest request(msg);
1631 
1632     dispatcherImpl->Dispatch(request);
1633     EXPECT_STREQ(outStrForCallbackCheck.c_str(),
1634         R"({"id":0,"result":{"code":1,"message":"wrong params"}})");
1635     if (protocolChannel) {
1636         delete protocolChannel;
1637         protocolChannel = nullptr;
1638     }
1639 }
1640 
HWTEST_F_L0(DebuggerImplTest,NativeOutTest)1641 HWTEST_F_L0(DebuggerImplTest, NativeOutTest)
1642 {
1643     std::string outStrForCallbackCheck = "";
1644     std::function<void(const void*, const std::string &)> callback =
1645         [&outStrForCallbackCheck]([[maybe_unused]] const void *ptr, const std::string &inStrOfReply) {
1646             outStrForCallbackCheck = inStrOfReply;};
1647     ProtocolChannel *protocolChannel = new ProtocolHandler(callback, ecmaVm);
1648     auto runtimeImpl = std::make_unique<RuntimeImpl>(ecmaVm, protocolChannel);
1649     auto debuggerImpl = std::make_unique<DebuggerImpl>(ecmaVm, protocolChannel, runtimeImpl.get());
1650     std::unique_ptr<JSPtHooks> jspthooks = std::make_unique<JSPtHooks>(debuggerImpl.get());
1651     bool result1 = jspthooks->NativeOut();
1652     ASSERT_TRUE(!result1);
1653     bool value = true;
1654     debuggerImpl->SetNativeOutPause(value);
1655     bool result2 = jspthooks->NativeOut();
1656     ASSERT_TRUE(result2);
1657     ASSERT_NE(jspthooks, nullptr);
1658 }
1659 
HWTEST_F_L0(DebuggerImplTest,NotifyNativeReturn__001)1660 HWTEST_F_L0(DebuggerImplTest, NotifyNativeReturn__001)
1661 {
1662     std::string outStrForCallbackCheck = "";
1663     std::function<void(const void*, const std::string &)> callback =
1664         [&outStrForCallbackCheck]([[maybe_unused]] const void *ptr, const std::string &inStrOfReply) {
1665             outStrForCallbackCheck = inStrOfReply;};
1666     ProtocolChannel *protocolChannel = new ProtocolHandler(callback, ecmaVm);
1667 
1668     auto runtimeImpl = std::make_unique<RuntimeImpl>(ecmaVm, protocolChannel);
1669     auto debuggerImpl = std::make_unique<DebuggerImpl>(ecmaVm, protocolChannel, runtimeImpl.get());
1670     std::unique_ptr<PtJson> json = PtJson::CreateObject();
1671     json->Add("enabled", false);
1672     json->Add("mixedStackEnabled", false);
1673     std::unique_ptr<SetMixedDebugParams> params = SetMixedDebugParams::Create(*json);
1674     debuggerImpl->SetMixedDebugEnabled(*params);
1675     debuggerImpl->NotifyNativeReturn(nullptr);
1676     auto debugger = std::make_unique<DebuggerImplFriendTest>(debuggerImpl);
1677     ASSERT_TRUE(!debugger->GetMixStackEnabled());
1678     if (protocolChannel) {
1679         delete protocolChannel;
1680         protocolChannel = nullptr;
1681     }
1682 }
1683 
HWTEST_F_L0(DebuggerImplTest,NotifyNativeReturn__002)1684 HWTEST_F_L0(DebuggerImplTest, NotifyNativeReturn__002)
1685 {
1686     std::string outStrForCallbackCheck = "";
1687     std::function<void(const void*, const std::string &)> callback =
1688         [&outStrForCallbackCheck]([[maybe_unused]] const void *ptr, const std::string &inStrOfReply) {
1689             outStrForCallbackCheck = inStrOfReply;};
1690     ProtocolChannel *protocolChannel = new ProtocolHandler(callback, ecmaVm);
1691 
1692     auto runtimeImpl = std::make_unique<RuntimeImpl>(ecmaVm, protocolChannel);
1693     auto debuggerImpl = std::make_unique<DebuggerImpl>(ecmaVm, protocolChannel, runtimeImpl.get());
1694     std::unique_ptr<PtJson> json = PtJson::CreateObject();
1695     json->Add("enabled", false);
1696     json->Add("mixedStackEnabled", true);
1697     std::unique_ptr<SetMixedDebugParams> params = SetMixedDebugParams::Create(*json);
1698     debuggerImpl->SetMixedDebugEnabled(*params);
1699     debuggerImpl->NotifyNativeReturn(nullptr);
1700     auto debugger = std::make_unique<DebuggerImplFriendTest>(debuggerImpl);
1701     ASSERT_TRUE(debugger->GetMixStackEnabled());
1702     if (protocolChannel) {
1703         delete protocolChannel;
1704         protocolChannel = nullptr;
1705     }
1706 }
1707 
HWTEST_F_L0(DebuggerImplTest,NotifyReturnNative__001)1708 HWTEST_F_L0(DebuggerImplTest, NotifyReturnNative__001)
1709 {
1710     std::string outStrForCallbackCheck = "";
1711     std::function<void(const void*, const std::string &)> callback =
1712         [&outStrForCallbackCheck]([[maybe_unused]] const void *ptr, const std::string &inStrOfReply) {
1713             outStrForCallbackCheck = inStrOfReply;};
1714     ProtocolChannel *protocolChannel = new ProtocolHandler(callback, ecmaVm);
1715 
1716     auto runtimeImpl = std::make_unique<RuntimeImpl>(ecmaVm, protocolChannel);
1717     auto debuggerImpl = std::make_unique<DebuggerImpl>(ecmaVm, protocolChannel, runtimeImpl.get());
1718     std::unique_ptr<PtJson> json = PtJson::CreateObject();
1719     json->Add("enabled", false);
1720     json->Add("mixedStackEnabled", true);
1721     std::unique_ptr<SetMixedDebugParams> params = SetMixedDebugParams::Create(*json);
1722     debuggerImpl->SetMixedDebugEnabled(*params);
1723     debuggerImpl->NotifyReturnNative();
1724     auto debugger = std::make_unique<DebuggerImplFriendTest>(debuggerImpl);
1725     ASSERT_TRUE(debugger->GetMixStackEnabled());
1726     if (protocolChannel) {
1727         delete protocolChannel;
1728         protocolChannel = nullptr;
1729     }
1730 }
1731 
HWTEST_F_L0(DebuggerImplTest,NotifyReturnNative__002)1732 HWTEST_F_L0(DebuggerImplTest, NotifyReturnNative__002)
1733 {
1734     std::string outStrForCallbackCheck = "";
1735     std::function<void(const void*, const std::string &)> callback =
1736         [&outStrForCallbackCheck]([[maybe_unused]] const void *ptr, const std::string &inStrOfReply) {
1737             outStrForCallbackCheck = inStrOfReply;};
1738     ProtocolChannel *protocolChannel = new ProtocolHandler(callback, ecmaVm);
1739 
1740     auto runtimeImpl = std::make_unique<RuntimeImpl>(ecmaVm, protocolChannel);
1741     auto debuggerImpl = std::make_unique<DebuggerImpl>(ecmaVm, protocolChannel, runtimeImpl.get());
1742     std::unique_ptr<PtJson> json = PtJson::CreateObject();
1743     json->Add("enabled", false);
1744     json->Add("mixedStackEnabled", false);
1745     std::unique_ptr<SetMixedDebugParams> params = SetMixedDebugParams::Create(*json);
1746     debuggerImpl->SetMixedDebugEnabled(*params);
1747     debuggerImpl->NotifyReturnNative();
1748     auto debugger = std::make_unique<DebuggerImplFriendTest>(debuggerImpl);
1749     ASSERT_TRUE(!debugger->GetMixStackEnabled());
1750     if (protocolChannel) {
1751         delete protocolChannel;
1752         protocolChannel = nullptr;
1753     }
1754 }
1755 
HWTEST_F_L0(DebuggerImplTest,NotifyNativeCalling__001)1756 HWTEST_F_L0(DebuggerImplTest, NotifyNativeCalling__001)
1757 {
1758     std::string outStrForCallbackCheck = "";
1759     std::function<void(const void*, const std::string &)> callback =
1760         [&outStrForCallbackCheck]([[maybe_unused]] const void *ptr, const std::string &inStrOfReply) {
1761             outStrForCallbackCheck = inStrOfReply;};
1762     ProtocolChannel *protocolChannel = new ProtocolHandler(callback, ecmaVm);
1763 
1764     auto runtimeImpl = std::make_unique<RuntimeImpl>(ecmaVm, protocolChannel);
1765     auto debuggerImpl = std::make_unique<DebuggerImpl>(ecmaVm, protocolChannel, runtimeImpl.get());
1766     std::unique_ptr<PtJson> json = PtJson::CreateObject();
1767     json->Add("enabled", false);
1768     json->Add("mixedStackEnabled", false);
1769     std::unique_ptr<SetMixedDebugParams> params = SetMixedDebugParams::Create(*json);
1770     debuggerImpl->SetMixedDebugEnabled(*params);
1771     debuggerImpl->NotifyNativeCalling(nullptr);
1772     auto debugger = std::make_unique<DebuggerImplFriendTest>(debuggerImpl);
1773     ASSERT_TRUE(!debugger->GetMixStackEnabled());
1774     if (protocolChannel) {
1775         delete protocolChannel;
1776         protocolChannel = nullptr;
1777     }
1778 }
1779 
HWTEST_F_L0(DebuggerImplTest,NotifyNativeCalling__002)1780 HWTEST_F_L0(DebuggerImplTest, NotifyNativeCalling__002)
1781 {
1782     std::string outStrForCallbackCheck = "";
1783     std::function<void(const void*, const std::string &)> callback =
1784         [&outStrForCallbackCheck]([[maybe_unused]] const void *ptr, const std::string &inStrOfReply) {
1785             outStrForCallbackCheck = inStrOfReply;};
1786     ProtocolChannel *protocolChannel = new ProtocolHandler(callback, ecmaVm);
1787 
1788     auto runtimeImpl = std::make_unique<RuntimeImpl>(ecmaVm, protocolChannel);
1789     auto debuggerImpl = std::make_unique<DebuggerImpl>(ecmaVm, protocolChannel, runtimeImpl.get());
1790     std::unique_ptr<PtJson> json = PtJson::CreateObject();
1791     json->Add("enabled", false);
1792     json->Add("mixedStackEnabled", true);
1793     std::unique_ptr<SetMixedDebugParams> params = SetMixedDebugParams::Create(*json);
1794     debuggerImpl->SetMixedDebugEnabled(*params);
1795     debuggerImpl->NotifyNativeCalling(nullptr);
1796     auto debugger = std::make_unique<DebuggerImplFriendTest>(debuggerImpl);
1797     ASSERT_TRUE(debugger->GetMixStackEnabled());
1798     if (protocolChannel) {
1799         delete protocolChannel;
1800         protocolChannel = nullptr;
1801     }
1802 }
1803 
HWTEST_F_L0(DebuggerImplTest,CheckAndGenerateCondFunc__001)1804 HWTEST_F_L0(DebuggerImplTest, CheckAndGenerateCondFunc__001)
1805 {
1806     std::string outStrForCallbackCheck = "";
1807     std::function<void(const void*, const std::string &)> callback =
1808         [&outStrForCallbackCheck]([[maybe_unused]] const void *ptr, const std::string &inStrOfReply) {
1809             outStrForCallbackCheck = inStrOfReply;};
1810     ProtocolChannel *protocolChannel = new ProtocolHandler(callback, ecmaVm);
1811     auto runtimeImpl = std::make_unique<RuntimeImpl>(ecmaVm, protocolChannel);
1812     auto debuggerImpl = std::make_unique<DebuggerImpl>(ecmaVm, protocolChannel, runtimeImpl.get());
1813     auto debugger = std::make_unique<DebuggerImplFriendTest>(debuggerImpl);
1814     std::vector<uint8_t> dest;
1815     debugger->CheckAndGenerateCondFunc("");
1816     ASSERT_TRUE(!debugger->DecodeAndCheckBase64("", dest));
1817     std::string msg = "UEFOREEAAAAAAAAADAACAEgBAAAAAAAAAAAAAAIAAAA8AAAAAQAA";
1818     msg += "AEQBAAAAAAARAAAAAEAAABEAAAAkQAAAMQAAAB8AAAASAEAAAIAAABsAAAAAgAAAHQAAAD//////////";
1819     debugger->CheckAndGenerateCondFunc(msg);
1820     ASSERT_TRUE(debugger->DecodeAndCheckBase64(msg, dest));
1821 }
1822 
HWTEST_F_L0(DebuggerImplTest,ConvertToLocal__001)1823 HWTEST_F_L0(DebuggerImplTest, ConvertToLocal__001)
1824 {
1825     std::string outStrForCallbackCheck = "";
1826     std::function<void(const void*, const std::string &)> callback =
1827         [&outStrForCallbackCheck]([[maybe_unused]] const void *ptr, const std::string &inStrOfReply) {
1828             outStrForCallbackCheck = inStrOfReply;};
1829     ProtocolChannel *protocolChannel = new ProtocolHandler(callback, ecmaVm);
1830     auto runtimeImpl = std::make_unique<RuntimeImpl>(ecmaVm, protocolChannel);
1831     auto debuggerImpl = std::make_unique<DebuggerImpl>(ecmaVm, protocolChannel, runtimeImpl.get());
1832     auto debugger = std::make_unique<DebuggerImplFriendTest>(debuggerImpl);
1833     Local<JSValueRef> taggedValue = debugger->ConvertToLocal("");
1834     ASSERT_TRUE(!taggedValue.IsEmpty());
1835     taggedValue = debugger->ConvertToLocal("false");
1836     ASSERT_TRUE(!taggedValue.IsEmpty());
1837     taggedValue = debugger->ConvertToLocal("true");
1838     ASSERT_TRUE(!taggedValue.IsEmpty());
1839     taggedValue = debugger->ConvertToLocal("undefined");
1840     ASSERT_TRUE(!taggedValue.IsEmpty());
1841     taggedValue = debugger->ConvertToLocal("\"test\"");
1842     ASSERT_TRUE(!taggedValue.IsEmpty());
1843     taggedValue = debugger->ConvertToLocal("test");
1844     ASSERT_TRUE(taggedValue.IsEmpty());
1845     taggedValue = debugger->ConvertToLocal("1");
1846     ASSERT_TRUE(!taggedValue.IsEmpty());
1847 }
1848 }  // namespace panda::test
1849