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