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_EvaluateOnCallFrame__004)352 HWTEST_F_L0(DebuggerImplTest, Dispatcher_Dispatch_EvaluateOnCallFrame__004)
353 {
354 ProtocolChannel *protocolChannel = new ProtocolHandler(nullptr, ecmaVm);
355 auto runtimeImpl = std::make_unique<RuntimeImpl>(ecmaVm, protocolChannel);
356 auto debuggerImpl = std::make_unique<DebuggerImpl>(ecmaVm, protocolChannel, runtimeImpl.get());
357 auto dispatcherImpl = std::make_unique<DebuggerImpl::DispatcherImpl>(protocolChannel, std::move(debuggerImpl));
358 int32_t callId = 0;
359 std::string msg = std::string() +
360 R"({
361 "id":0,
362 "method":"Debugger.evaluateOnCallFrame",
363 "params":{
364 "callFrameId":"-1",
365 "expression":"the expression"
366 }
367 })";
368 std::unique_ptr<EvaluateOnCallFrameParams> params =
369 EvaluateOnCallFrameParams::Create(DispatchRequest(msg).GetParams());
370 std::string result = dispatcherImpl->EvaluateOnCallFrame(callId, std::move(params));
371 EXPECT_STREQ(result.c_str(), R"({"id":0,"result":{"code":1,"message":"Invalid callFrameId."}})");
372 if (protocolChannel) {
373 delete protocolChannel;
374 protocolChannel = nullptr;
375 }
376 }
377
HWTEST_F_L0(DebuggerImplTest,Dispatcher_Dispatch_GetPossibleBreakpoints__001)378 HWTEST_F_L0(DebuggerImplTest, Dispatcher_Dispatch_GetPossibleBreakpoints__001)
379 {
380 std::string outStrForCallbackCheck = "";
381 std::function<void(const void*, const std::string &)> callback =
382 [&outStrForCallbackCheck]([[maybe_unused]] const void *ptr, const std::string &inStrOfReply) {
383 outStrForCallbackCheck = inStrOfReply;};
384 ProtocolChannel *protocolChannel = new ProtocolHandler(callback, ecmaVm);
385 auto runtimeImpl = std::make_unique<RuntimeImpl>(ecmaVm, protocolChannel);
386 auto debuggerImpl = std::make_unique<DebuggerImpl>(ecmaVm, protocolChannel, runtimeImpl.get());
387 auto dispatcherImpl = std::make_unique<DebuggerImpl::DispatcherImpl>(protocolChannel, std::move(debuggerImpl));
388
389 // DebuggerImpl::DispatcherImpl::GetPossibleBreakpoints -- params == nullptr
390 std::string msg = std::string() +
391 R"({
392 "id":0,
393 "method":"Debugger.getPossibleBreakpoints",
394 "params":{}
395 })";
396 DispatchRequest request(msg);
397
398 dispatcherImpl->Dispatch(request);
399 EXPECT_STREQ(outStrForCallbackCheck.c_str(), R"({"id":0,"result":{"code":1,"message":"wrong params"}})");
400 if (protocolChannel) {
401 delete protocolChannel;
402 protocolChannel = nullptr;
403 }
404 }
405
HWTEST_F_L0(DebuggerImplTest,Dispatcher_Dispatch_GetPossibleBreakpoints__002)406 HWTEST_F_L0(DebuggerImplTest, Dispatcher_Dispatch_GetPossibleBreakpoints__002)
407 {
408 std::string outStrForCallbackCheck = "";
409 std::function<void(const void*, const std::string &)> callback =
410 [&outStrForCallbackCheck]([[maybe_unused]] const void *ptr, const std::string &inStrOfReply) {
411 outStrForCallbackCheck = inStrOfReply;};
412 ProtocolChannel *protocolChannel = new ProtocolHandler(callback, ecmaVm);
413 auto runtimeImpl = std::make_unique<RuntimeImpl>(ecmaVm, protocolChannel);
414 auto debuggerImpl = std::make_unique<DebuggerImpl>(ecmaVm, protocolChannel, runtimeImpl.get());
415 auto dispatcherImpl = std::make_unique<DebuggerImpl::DispatcherImpl>(protocolChannel, std::move(debuggerImpl));
416
417 // DebuggerImpl::GetPossibleBreakpoints -- iter == scripts_.end()
418 std::string msg = std::string() +
419 R"({
420 "id":0,
421 "method":"Debugger.getPossibleBreakpoints",
422 "params":{
423 "start":{
424 "scriptId":"0",
425 "lineNumber":1,
426 "columnNumber":0
427 },
428 "end":{
429 "scriptId":"0",
430 "lineNumber":1,
431 "columnNumber":0
432 },
433 "restrictToFunction":true
434 }
435 })";
436 DispatchRequest request(msg);
437
438 dispatcherImpl->Dispatch(request);
439 EXPECT_STREQ(outStrForCallbackCheck.c_str(), R"({"id":0,"result":{"code":1,"message":"Unknown file name."}})");
440 if (protocolChannel) {
441 delete protocolChannel;
442 protocolChannel = nullptr;
443 }
444 }
445
HWTEST_F_L0(DebuggerImplTest,Dispatcher_Dispatch_GetScriptSource__001)446 HWTEST_F_L0(DebuggerImplTest, Dispatcher_Dispatch_GetScriptSource__001)
447 {
448 std::string outStrForCallbackCheck = "";
449 std::function<void(const void*, const std::string &)> callback =
450 [&outStrForCallbackCheck]([[maybe_unused]] const void *ptr, const std::string &inStrOfReply) {
451 outStrForCallbackCheck = inStrOfReply;};
452 ProtocolChannel *protocolChannel = new ProtocolHandler(callback, ecmaVm);
453 auto runtimeImpl = std::make_unique<RuntimeImpl>(ecmaVm, protocolChannel);
454 auto debuggerImpl = std::make_unique<DebuggerImpl>(ecmaVm, protocolChannel, runtimeImpl.get());
455 auto dispatcherImpl = std::make_unique<DebuggerImpl::DispatcherImpl>(protocolChannel, std::move(debuggerImpl));
456
457 // DebuggerImpl::DispatcherImpl::GetScriptSource -- params == nullptr
458 std::string msg = std::string() +
459 R"({
460 "id":0,
461 "method":"Debugger.getScriptSource",
462 "params":{}
463 })";
464 DispatchRequest request(msg);
465
466 dispatcherImpl->Dispatch(request);
467 EXPECT_STREQ(outStrForCallbackCheck.c_str(), R"({"id":0,"result":{"code":1,"message":"wrong params"}})");
468 if (protocolChannel) {
469 delete protocolChannel;
470 protocolChannel = nullptr;
471 }
472 }
473
HWTEST_F_L0(DebuggerImplTest,Dispatcher_Dispatch_GetScriptSource__002)474 HWTEST_F_L0(DebuggerImplTest, Dispatcher_Dispatch_GetScriptSource__002)
475 {
476 std::string outStrForCallbackCheck = "";
477 std::function<void(const void*, const std::string &)> callback =
478 [&outStrForCallbackCheck]([[maybe_unused]] const void *ptr, const std::string &inStrOfReply) {
479 outStrForCallbackCheck = inStrOfReply;};
480 ProtocolChannel *protocolChannel = new ProtocolHandler(callback, ecmaVm);
481 auto runtimeImpl = std::make_unique<RuntimeImpl>(ecmaVm, protocolChannel);
482 auto debuggerImpl = std::make_unique<DebuggerImpl>(ecmaVm, protocolChannel, runtimeImpl.get());
483 auto dispatcherImpl = std::make_unique<DebuggerImpl::DispatcherImpl>(protocolChannel, std::move(debuggerImpl));
484
485 // DebuggerImpl::GetScriptSource -- iter == scripts_.end()
486 std::string msg = std::string() +
487 R"({
488 "id":0,
489 "method":"Debugger.getScriptSource",
490 "params":{
491 "scriptId":"0"
492 }
493 })";
494 DispatchRequest request(msg);
495
496 dispatcherImpl->Dispatch(request);
497 EXPECT_STREQ(outStrForCallbackCheck.c_str(), R"({"id":0,"result":{"code":1,"message":"unknown script id: 0"}})");
498 if (protocolChannel) {
499 delete protocolChannel;
500 protocolChannel = nullptr;
501 }
502 }
503
HWTEST_F_L0(DebuggerImplTest,Dispatcher_Dispatch_Pause__001)504 HWTEST_F_L0(DebuggerImplTest, Dispatcher_Dispatch_Pause__001)
505 {
506 std::string outStrForCallbackCheck = "";
507 std::function<void(const void*, const std::string &)> callback =
508 [&outStrForCallbackCheck]([[maybe_unused]] const void *ptr, const std::string &inStrOfReply) {
509 outStrForCallbackCheck = inStrOfReply;};
510 ProtocolChannel *protocolChannel = new ProtocolHandler(callback, ecmaVm);
511 auto runtimeImpl = std::make_unique<RuntimeImpl>(ecmaVm, protocolChannel);
512 auto debuggerImpl = std::make_unique<DebuggerImpl>(ecmaVm, protocolChannel, runtimeImpl.get());
513 auto dispatcherImpl = std::make_unique<DebuggerImpl::DispatcherImpl>(protocolChannel, std::move(debuggerImpl));
514
515 // DDebuggerImpl::DispatcherImpl::GetScriptSource -- params == nullptr
516 std::string msg = std::string() +
517 R"({
518 "id":0,
519 "method":"Debugger.pause"
520 })";
521 DispatchRequest request(msg);
522
523 dispatcherImpl->Dispatch(request);
524 EXPECT_STREQ(outStrForCallbackCheck.c_str(), R"({"id":0,"result":{}})");
525 if (protocolChannel) {
526 delete protocolChannel;
527 protocolChannel = nullptr;
528 }
529 }
530
HWTEST_F_L0(DebuggerImplTest,Dispatcher_Dispatch_RemoveBreakpoint__001)531 HWTEST_F_L0(DebuggerImplTest, Dispatcher_Dispatch_RemoveBreakpoint__001)
532 {
533 std::string outStrForCallbackCheck = "";
534 std::function<void(const void*, const std::string &)> callback =
535 [&outStrForCallbackCheck]([[maybe_unused]] const void *ptr, const std::string &inStrOfReply) {
536 outStrForCallbackCheck = inStrOfReply;};
537 ProtocolChannel *protocolChannel = new ProtocolHandler(callback, ecmaVm);
538 auto runtimeImpl = std::make_unique<RuntimeImpl>(ecmaVm, protocolChannel);
539 auto debuggerImpl = std::make_unique<DebuggerImpl>(ecmaVm, protocolChannel, runtimeImpl.get());
540 auto dispatcherImpl = std::make_unique<DebuggerImpl::DispatcherImpl>(protocolChannel, std::move(debuggerImpl));
541
542 // DDebuggerImpl::DispatcherImpl::RemoveBreakpoint -- params == nullptr
543 std::string msg = std::string() +
544 R"({
545 "id":0,
546 "method":"Debugger.removeBreakpoint",
547 "params":{}
548 })";
549 DispatchRequest request(msg);
550
551 dispatcherImpl->Dispatch(request);
552 EXPECT_STREQ(outStrForCallbackCheck.c_str(), R"({"id":0,"result":{"code":1,"message":"wrong params"}})");
553 if (protocolChannel) {
554 delete protocolChannel;
555 protocolChannel = nullptr;
556 }
557 }
558
HWTEST_F_L0(DebuggerImplTest,Dispatcher_Dispatch_RemoveBreakpoint__002)559 HWTEST_F_L0(DebuggerImplTest, Dispatcher_Dispatch_RemoveBreakpoint__002)
560 {
561 std::string outStrForCallbackCheck = "";
562 std::function<void(const void*, const std::string &)> callback =
563 [&outStrForCallbackCheck]([[maybe_unused]] const void *ptr, const std::string &inStrOfReply) {
564 outStrForCallbackCheck = inStrOfReply;};
565 ProtocolChannel *protocolChannel = new ProtocolHandler(callback, ecmaVm);
566 auto runtimeImpl = std::make_unique<RuntimeImpl>(ecmaVm, protocolChannel);
567 auto debuggerImpl = std::make_unique<DebuggerImpl>(ecmaVm, protocolChannel, runtimeImpl.get());
568 auto dispatcherImpl = std::make_unique<DebuggerImpl::DispatcherImpl>(protocolChannel, std::move(debuggerImpl));
569
570 // DDebuggerImpl::RemoveBreakpoint -- !BreakpointDetails::ParseBreakpointId(id, &metaData)
571 std::string msg = std::string() +
572 R"({
573 "id":0,
574 "method":"Debugger.removeBreakpoint",
575 "params":{
576 "breakpointId":"id:0:0"
577 }
578 })";
579 DispatchRequest request(msg);
580
581 dispatcherImpl->Dispatch(request);
582 EXPECT_STREQ(outStrForCallbackCheck.c_str(),
583 R"({"id":0,"result":{"code":1,"message":"Parse breakpoint id failed"}})");
584 if (protocolChannel) {
585 delete protocolChannel;
586 protocolChannel = nullptr;
587 }
588 }
589
HWTEST_F_L0(DebuggerImplTest,Dispatcher_Dispatch_RemoveBreakpoint__003)590 HWTEST_F_L0(DebuggerImplTest, Dispatcher_Dispatch_RemoveBreakpoint__003)
591 {
592 std::string outStrForCallbackCheck = "";
593 std::function<void(const void*, const std::string &)> callback =
594 [&outStrForCallbackCheck]([[maybe_unused]] const void *ptr, const std::string &inStrOfReply) {
595 outStrForCallbackCheck = inStrOfReply;};
596 ProtocolChannel *protocolChannel = new ProtocolHandler(callback, ecmaVm);
597 auto runtimeImpl = std::make_unique<RuntimeImpl>(ecmaVm, protocolChannel);
598 auto debuggerImpl = std::make_unique<DebuggerImpl>(ecmaVm, protocolChannel, runtimeImpl.get());
599 auto dispatcherImpl = std::make_unique<DebuggerImpl::DispatcherImpl>(protocolChannel, std::move(debuggerImpl));
600
601 // DDebuggerImpl::RemoveBreakpoint -- !MatchScripts(scriptFunc, metaData.url_, ScriptMatchType::URL)
602 std::string msg = std::string() +
603 R"({
604 "id":0,
605 "method":"Debugger.removeBreakpoint",
606 "params":{
607 "breakpointId":"id:0:0:url"
608 }
609 })";
610 DispatchRequest request(msg);
611
612 dispatcherImpl->Dispatch(request);
613 EXPECT_STREQ(outStrForCallbackCheck.c_str(),
614 R"({"id":0,"result":{"code":1,"message":"Unknown file name."}})");
615 if (protocolChannel) {
616 delete protocolChannel;
617 protocolChannel = nullptr;
618 }
619 }
620
HWTEST_F_L0(DebuggerImplTest,Dispatcher_Dispatch_RemoveBreakpointsByUrl__001)621 HWTEST_F_L0(DebuggerImplTest, Dispatcher_Dispatch_RemoveBreakpointsByUrl__001)
622 {
623 std::string outStrForCallbackCheck = "";
624 std::function<void(const void*, const std::string &)> callback =
625 [&outStrForCallbackCheck]([[maybe_unused]] const void *ptr, const std::string &inStrOfReply) {
626 outStrForCallbackCheck = inStrOfReply;};
627 ProtocolChannel *protocolChannel = new ProtocolHandler(callback, ecmaVm);
628 auto runtimeImpl = std::make_unique<RuntimeImpl>(ecmaVm, protocolChannel);
629 auto debuggerImpl = std::make_unique<DebuggerImpl>(ecmaVm, protocolChannel, runtimeImpl.get());
630 auto dispatcherImpl = std::make_unique<DebuggerImpl::DispatcherImpl>(protocolChannel, std::move(debuggerImpl));
631
632 std::string msg = std::string() +
633 R"({
634 "id":0,
635 "method":"Debugger.removeBreakpointsByUrl",
636 "params":{}
637 })";
638 DispatchRequest request(msg);
639
640 dispatcherImpl->Dispatch(request);
641 EXPECT_STREQ(outStrForCallbackCheck.c_str(), R"({"id":0,"result":{"code":1,"message":"wrong params"}})");
642 if (protocolChannel) {
643 delete protocolChannel;
644 protocolChannel = nullptr;
645 }
646 }
647
HWTEST_F_L0(DebuggerImplTest,Dispatcher_Dispatch_RemoveBreakpointsByUrl__002)648 HWTEST_F_L0(DebuggerImplTest, Dispatcher_Dispatch_RemoveBreakpointsByUrl__002)
649 {
650 std::string outStrForCallbackCheck = "";
651 std::function<void(const void*, const std::string &)> callback =
652 [&outStrForCallbackCheck]([[maybe_unused]] const void *ptr, const std::string &inStrOfReply) {
653 outStrForCallbackCheck = inStrOfReply;};
654 ProtocolChannel *protocolChannel = new ProtocolHandler(callback, ecmaVm);
655 auto runtimeImpl = std::make_unique<RuntimeImpl>(ecmaVm, protocolChannel);
656 auto debuggerImpl = std::make_unique<DebuggerImpl>(ecmaVm, protocolChannel, runtimeImpl.get());
657 auto dispatcherImpl = std::make_unique<DebuggerImpl::DispatcherImpl>(protocolChannel, std::move(debuggerImpl));
658
659 std::string msg = std::string() +
660 R"({
661 "id":0,
662 "method":"Debugger.removeBreakpointsByUrl",
663 "params":{
664 "url":"1"
665 }
666 })";
667 DispatchRequest request(msg);
668
669 dispatcherImpl->Dispatch(request);
670 EXPECT_STREQ(outStrForCallbackCheck.c_str(), R"({"id":0,"result":{"code":1,"message":"Unknown url"}})");
671 if (protocolChannel) {
672 delete protocolChannel;
673 protocolChannel = nullptr;
674 }
675 }
676
HWTEST_F_L0(DebuggerImplTest,Dispatcher_Dispatch_RemoveBreakpointsByUrl__003)677 HWTEST_F_L0(DebuggerImplTest, Dispatcher_Dispatch_RemoveBreakpointsByUrl__003)
678 {
679 ProtocolChannel *protocolChannel = new ProtocolHandler(nullptr, ecmaVm);
680 auto runtimeImpl = std::make_unique<RuntimeImpl>(ecmaVm, protocolChannel);
681 auto debuggerImpl = std::make_unique<DebuggerImpl>(ecmaVm, protocolChannel, runtimeImpl.get());
682 auto dispatcherImpl = std::make_unique<DebuggerImpl::DispatcherImpl>(protocolChannel, std::move(debuggerImpl));
683 int32_t callId = 0;
684 std::string msg = std::string() +
685 R"({
686 "id": 0,
687 "method": "Debugger.removeBreakpointsByUrl",
688 "params": {
689 "url": "entry|entry|1.0.0|src/main/ets/pages/Index.ts"
690 }
691 })";
692 std::unique_ptr<RemoveBreakpointsByUrlParams> params =
693 RemoveBreakpointsByUrlParams::Create(DispatchRequest(msg).GetParams());
694 std::string result = dispatcherImpl->RemoveBreakpointsByUrl(callId, std::move(params));
695 EXPECT_STREQ(result.c_str(), R"({"id":0,"result":{"code":1,"message":"Unknown url"}})");
696 if (protocolChannel) {
697 delete protocolChannel;
698 protocolChannel = nullptr;
699 }
700 }
701
HWTEST_F_L0(DebuggerImplTest,Dispatcher_Dispatch_SaveAllPossibleBreakpoints__001)702 HWTEST_F_L0(DebuggerImplTest, Dispatcher_Dispatch_SaveAllPossibleBreakpoints__001)
703 {
704 ProtocolChannel *protocolChannel = new ProtocolHandler(nullptr, ecmaVm);
705 auto runtimeImpl = std::make_unique<RuntimeImpl>(ecmaVm, protocolChannel);
706 auto debuggerImpl = std::make_unique<DebuggerImpl>(ecmaVm, protocolChannel, runtimeImpl.get());
707 auto dispatcherImpl = std::make_unique<DebuggerImpl::DispatcherImpl>(protocolChannel, std::move(debuggerImpl));
708 int32_t callId = 0;
709 std::string msg = std::string() +
710 R"({
711 "id": 0,
712 "method": "Debugger.saveAllPossibleBreakpoints",
713 "params": {
714 "locations": {
715 "entry|entry|1.0.0|src/main/ets/pages/Index.ts": [{
716 "lineNumber": 59,
717 "columnNumber": 16
718 }]
719 }
720 }
721 })";
722 std::unique_ptr<SaveAllPossibleBreakpointsParams> params =
723 SaveAllPossibleBreakpointsParams::Create(DispatchRequest(msg).GetParams());
724 std::string result = dispatcherImpl->SaveAllPossibleBreakpoints(callId, std::move(params));
725 EXPECT_STREQ(result.c_str(),
726 R"({"id":0,"result":{"code":1,"message":"SaveAllPossibleBreakpoints: debugger agent is not enabled"}})");
727 if (protocolChannel) {
728 delete protocolChannel;
729 protocolChannel = nullptr;
730 }
731 }
732
HWTEST_F_L0(DebuggerImplTest,Dispatcher_Dispatch_SetSymbolBreakpoints_001)733 HWTEST_F_L0(DebuggerImplTest, Dispatcher_Dispatch_SetSymbolBreakpoints_001)
734 {
735 std::string outStrForCallbackCheck = "";
736 std::function<void(const void*, const std::string &)> callback =
737 [&outStrForCallbackCheck]([[maybe_unused]] const void *ptr, const std::string &inStrOfReply) {
738 outStrForCallbackCheck = inStrOfReply;};
739 ProtocolChannel *protocolChannel = new ProtocolHandler(callback, ecmaVm);
740 auto runtimeImpl = std::make_unique<RuntimeImpl>(ecmaVm, protocolChannel);
741 auto debuggerImpl = std::make_unique<DebuggerImpl>(ecmaVm, protocolChannel, runtimeImpl.get());
742 auto dispatcherImpl = std::make_unique<DebuggerImpl::DispatcherImpl>(protocolChannel, std::move(debuggerImpl));
743
744 std::string msg = std::string() +
745 R"({
746 "id":0,
747 "method":"Debugger.setSymbolicBreakpoints",
748 "params":{}
749 })";
750 DispatchRequest request(msg);
751
752 dispatcherImpl->Dispatch(request);
753 EXPECT_STREQ(outStrForCallbackCheck.c_str(), R"({"id":0,"result":{"code":1,"message":"wrong params"}})");
754 if (protocolChannel) {
755 delete protocolChannel;
756 protocolChannel = nullptr;
757 }
758 }
759
HWTEST_F_L0(DebuggerImplTest,Dispatcher_Dispatch_SetSymbolBreakpoints_002)760 HWTEST_F_L0(DebuggerImplTest, Dispatcher_Dispatch_SetSymbolBreakpoints_002)
761 {
762 std::string outStrForCallbackCheck = "";
763 std::function<void(const void*, const std::string &)> callback =
764 [&outStrForCallbackCheck]([[maybe_unused]] const void *ptr, const std::string &inStrOfReply) {
765 outStrForCallbackCheck = inStrOfReply;};
766 ProtocolChannel *protocolChannel = new ProtocolHandler(callback, ecmaVm);
767 auto runtimeImpl = std::make_unique<RuntimeImpl>(ecmaVm, protocolChannel);
768 auto debuggerImpl = std::make_unique<DebuggerImpl>(ecmaVm, protocolChannel, runtimeImpl.get());
769 auto dispatcherImpl = std::make_unique<DebuggerImpl::DispatcherImpl>(protocolChannel, std::move(debuggerImpl));
770
771 std::string msg = std::string() +
772 R"({
773 "id":0,
774 "method":"Debugger.setSymbolicBreakpoints",
775 "params":{
776 "symbolicBreakpoints":[
777 {
778 "condition":"testDebug"
779 }
780 ]
781 }
782 })";
783 DispatchRequest request(msg);
784
785 dispatcherImpl->Dispatch(request);
786 EXPECT_STREQ(outStrForCallbackCheck.c_str(), R"({"id":0,"result":{"code":1,"message":"wrong params"}})");
787 if (protocolChannel) {
788 delete protocolChannel;
789 protocolChannel = nullptr;
790 }
791 }
792
HWTEST_F_L0(DebuggerImplTest,Dispatcher_Dispatch_Resume__001)793 HWTEST_F_L0(DebuggerImplTest, Dispatcher_Dispatch_Resume__001)
794 {
795 std::string outStrForCallbackCheck = "";
796 std::function<void(const void*, const std::string &)> callback =
797 [&outStrForCallbackCheck]([[maybe_unused]] const void *ptr, const std::string &inStrOfReply) {
798 outStrForCallbackCheck = inStrOfReply;};
799 ProtocolChannel *protocolChannel = new ProtocolHandler(callback, ecmaVm);
800 auto runtimeImpl = std::make_unique<RuntimeImpl>(ecmaVm, protocolChannel);
801 auto debuggerImpl = std::make_unique<DebuggerImpl>(ecmaVm, protocolChannel, runtimeImpl.get());
802 debuggerImpl->SetDebuggerState(DebuggerState::PAUSED);
803 auto dispatcherImpl = std::make_unique<DebuggerImpl::DispatcherImpl>(protocolChannel, std::move(debuggerImpl));
804
805 // DebuggerImpl::DispatcherImpl::Resume -- params == nullptr
806 std::string msg = std::string() +
807 R"({
808 "id":0,
809 "method":"Debugger.resume",
810 "params":{
811 "terminateOnResume":"NotBool"
812 }
813 })";
814 DispatchRequest request(msg);
815
816 dispatcherImpl->Dispatch(request);
817 EXPECT_STREQ(outStrForCallbackCheck.c_str(), R"({"id":0,"result":{"code":1,"message":"wrong params"}})");
818 if (protocolChannel) {
819 delete protocolChannel;
820 protocolChannel = nullptr;
821 }
822 }
823
HWTEST_F_L0(DebuggerImplTest,Dispatcher_Dispatch_Resume__002)824 HWTEST_F_L0(DebuggerImplTest, Dispatcher_Dispatch_Resume__002)
825 {
826 std::string outStrForCallbackCheck = "";
827 std::function<void(const void*, const std::string &)> callback =
828 [&outStrForCallbackCheck]([[maybe_unused]] const void *ptr, const std::string &inStrOfReply) {
829 outStrForCallbackCheck = inStrOfReply;};
830 ProtocolChannel *protocolChannel = new ProtocolHandler(callback, ecmaVm);
831 auto runtimeImpl = std::make_unique<RuntimeImpl>(ecmaVm, protocolChannel);
832 auto debuggerImpl = std::make_unique<DebuggerImpl>(ecmaVm, protocolChannel, runtimeImpl.get());
833 debuggerImpl->SetDebuggerState(DebuggerState::PAUSED);
834 auto dispatcherImpl = std::make_unique<DebuggerImpl::DispatcherImpl>(protocolChannel, std::move(debuggerImpl));
835
836 std::string msg = std::string() +
837 R"({
838 "id":0,
839 "method":"Debugger.resume",
840 "params":{
841 "terminateOnResume":true
842 }
843 })";
844 DispatchRequest request(msg);
845
846 dispatcherImpl->Dispatch(request);
847 EXPECT_STREQ(outStrForCallbackCheck.c_str(), R"({"id":0,"result":{}})");
848 if (protocolChannel) {
849 delete protocolChannel;
850 protocolChannel = nullptr;
851 }
852 }
853
HWTEST_F_L0(DebuggerImplTest,Dispatcher_Dispatch_SetAsyncCallStackDepth__001)854 HWTEST_F_L0(DebuggerImplTest, Dispatcher_Dispatch_SetAsyncCallStackDepth__001)
855 {
856 std::string outStrForCallbackCheck = "";
857 std::function<void(const void*, const std::string &)> callback =
858 [&outStrForCallbackCheck]([[maybe_unused]] const void *ptr, const std::string &inStrOfReply) {
859 outStrForCallbackCheck = inStrOfReply;};
860 ProtocolChannel *protocolChannel = new ProtocolHandler(callback, ecmaVm);
861 auto runtimeImpl = std::make_unique<RuntimeImpl>(ecmaVm, protocolChannel);
862 auto debuggerImpl = std::make_unique<DebuggerImpl>(ecmaVm, protocolChannel, runtimeImpl.get());
863 auto dispatcherImpl = std::make_unique<DebuggerImpl::DispatcherImpl>(protocolChannel, std::move(debuggerImpl));
864
865 std::string msg = std::string() +
866 R"({
867 "id":0,
868 "method":"Debugger.setAsyncCallStackDepth",
869 "params":{
870 "maxDepth":32
871 }
872 })";
873 DispatchRequest request(msg);
874
875 dispatcherImpl->Dispatch(request);
876 EXPECT_STREQ(outStrForCallbackCheck.c_str(),
877 R"({"id":0,"result":{}})");
878 if (protocolChannel) {
879 delete protocolChannel;
880 protocolChannel = nullptr;
881 }
882 }
883
HWTEST_F_L0(DebuggerImplTest,Dispatcher_Dispatch_SetBreakpointByUrl__001)884 HWTEST_F_L0(DebuggerImplTest, Dispatcher_Dispatch_SetBreakpointByUrl__001)
885 {
886 std::string outStrForCallbackCheck = "";
887 std::function<void(const void*, const std::string &)> callback =
888 [&outStrForCallbackCheck]([[maybe_unused]] const void *ptr, const std::string &inStrOfReply) {
889 outStrForCallbackCheck = inStrOfReply;};
890 ProtocolChannel *protocolChannel = new ProtocolHandler(callback, ecmaVm);
891 auto runtimeImpl = std::make_unique<RuntimeImpl>(ecmaVm, protocolChannel);
892 auto debuggerImpl = std::make_unique<DebuggerImpl>(ecmaVm, protocolChannel, runtimeImpl.get());
893 auto dispatcherImpl = std::make_unique<DebuggerImpl::DispatcherImpl>(protocolChannel, std::move(debuggerImpl));
894
895 // DebuggerImpl::DispatcherImpl::SetBreakpointByUrl -- params == nullptr
896 std::string msg = std::string() +
897 R"({
898 "id":0,
899 "method":"Debugger.setBreakpointByUrl",
900 "params":{}
901 })";
902 DispatchRequest request(msg);
903
904 dispatcherImpl->Dispatch(request);
905 EXPECT_STREQ(outStrForCallbackCheck.c_str(), R"({"id":0,"result":{"code":1,"message":"wrong params"}})");
906 if (protocolChannel) {
907 delete protocolChannel;
908 protocolChannel = nullptr;
909 }
910 }
911
HWTEST_F_L0(DebuggerImplTest,Dispatcher_Dispatch_SetBreakpointByUrl__002)912 HWTEST_F_L0(DebuggerImplTest, Dispatcher_Dispatch_SetBreakpointByUrl__002)
913 {
914 std::string outStrForCallbackCheck = "";
915 std::function<void(const void*, const std::string &)> callback =
916 [&outStrForCallbackCheck]([[maybe_unused]] const void *ptr, const std::string &inStrOfReply) {
917 outStrForCallbackCheck = inStrOfReply;};
918 ProtocolChannel *protocolChannel = new ProtocolHandler(callback, ecmaVm);
919 auto runtimeImpl = std::make_unique<RuntimeImpl>(ecmaVm, protocolChannel);
920 auto debuggerImpl = std::make_unique<DebuggerImpl>(ecmaVm, protocolChannel, runtimeImpl.get());
921 auto dispatcherImpl = std::make_unique<DebuggerImpl::DispatcherImpl>(protocolChannel, std::move(debuggerImpl));
922 ecmaVm->GetJsDebuggerManager()->SetDebugMode(true);
923
924 // DebuggerImpl::SetBreakpointByUrl -- extractor == nullptr
925 std::string msg = std::string() +
926 R"({
927 "id":0,
928 "method":"Debugger.setBreakpointByUrl",
929 "params":{
930 "lineNumber":0,
931 "url":"url_str",
932 "urlRegex":"urlRegex_str",
933 "scriptHash":"scriptHash_str",
934 "columnNumber":0,
935 "condition":"condition_str"
936 }
937 })";
938 DispatchRequest request(msg);
939
940 dispatcherImpl->Dispatch(request);
941 EXPECT_STREQ(outStrForCallbackCheck.c_str(), R"({"id":0,"result":{"code":1,"message":"Unknown file name."}})");
942 if (protocolChannel) {
943 delete protocolChannel;
944 protocolChannel = nullptr;
945 }
946 }
947
HWTEST_F_L0(DebuggerImplTest,Dispatcher_Dispatch_SetPauseOnExceptions__001)948 HWTEST_F_L0(DebuggerImplTest, Dispatcher_Dispatch_SetPauseOnExceptions__001)
949 {
950 std::string outStrForCallbackCheck = "";
951 std::function<void(const void*, const std::string &)> callback =
952 [&outStrForCallbackCheck]([[maybe_unused]] const void *ptr, const std::string &inStrOfReply) {
953 outStrForCallbackCheck = inStrOfReply;};
954 ProtocolChannel *protocolChannel = new ProtocolHandler(callback, ecmaVm);
955 auto runtimeImpl = std::make_unique<RuntimeImpl>(ecmaVm, protocolChannel);
956 auto debuggerImpl = std::make_unique<DebuggerImpl>(ecmaVm, protocolChannel, runtimeImpl.get());
957 auto dispatcherImpl = std::make_unique<DebuggerImpl::DispatcherImpl>(protocolChannel, std::move(debuggerImpl));
958
959 // DebuggerImpl::DispatcherImpl::SetPauseOnExceptions -- params == nullptr
960 std::string msg = std::string() +
961 R"({
962 "id":0,
963 "method":"Debugger.setPauseOnExceptions",
964 "params":{}
965 })";
966 DispatchRequest request(msg);
967
968 dispatcherImpl->Dispatch(request);
969 EXPECT_STREQ(outStrForCallbackCheck.c_str(), R"({"id":0,"result":{"code":1,"message":"wrong params"}})");
970 if (protocolChannel) {
971 delete protocolChannel;
972 protocolChannel = nullptr;
973 }
974 }
975
HWTEST_F_L0(DebuggerImplTest,Dispatcher_Dispatch_SetPauseOnExceptions__002)976 HWTEST_F_L0(DebuggerImplTest, Dispatcher_Dispatch_SetPauseOnExceptions__002)
977 {
978 std::string outStrForCallbackCheck = "";
979 std::function<void(const void*, const std::string &)> callback =
980 [&outStrForCallbackCheck]([[maybe_unused]] const void *ptr, const std::string &inStrOfReply) {
981 outStrForCallbackCheck = inStrOfReply;};
982 ProtocolChannel *protocolChannel = new ProtocolHandler(callback, ecmaVm);
983 auto runtimeImpl = std::make_unique<RuntimeImpl>(ecmaVm, protocolChannel);
984 auto debuggerImpl = std::make_unique<DebuggerImpl>(ecmaVm, protocolChannel, runtimeImpl.get());
985 auto dispatcherImpl = std::make_unique<DebuggerImpl::DispatcherImpl>(protocolChannel, std::move(debuggerImpl));
986
987 std::string msg = std::string() +
988 R"({
989 "id":0,
990 "method":"Debugger.setPauseOnExceptions",
991 "params":{
992 "state":"all"
993 }
994 })";
995 DispatchRequest request(msg);
996
997 dispatcherImpl->Dispatch(request);
998 EXPECT_STREQ(outStrForCallbackCheck.c_str(), R"({"id":0,"result":{}})");
999 if (protocolChannel) {
1000 delete protocolChannel;
1001 protocolChannel = nullptr;
1002 }
1003 }
1004
HWTEST_F_L0(DebuggerImplTest,Dispatcher_Dispatch_StepInto__001)1005 HWTEST_F_L0(DebuggerImplTest, Dispatcher_Dispatch_StepInto__001)
1006 {
1007 std::string outStrForCallbackCheck = "";
1008 std::function<void(const void*, const std::string &)> callback =
1009 [&outStrForCallbackCheck]([[maybe_unused]] const void *ptr, const std::string &inStrOfReply) {
1010 outStrForCallbackCheck = inStrOfReply;};
1011 ProtocolChannel *protocolChannel = new ProtocolHandler(callback, ecmaVm);
1012 auto runtimeImpl = std::make_unique<RuntimeImpl>(ecmaVm, protocolChannel);
1013 auto debuggerImpl = std::make_unique<DebuggerImpl>(ecmaVm, protocolChannel, runtimeImpl.get());
1014 auto dispatcherImpl = std::make_unique<DebuggerImpl::DispatcherImpl>(protocolChannel, std::move(debuggerImpl));
1015
1016 // DebuggerImpl::DispatcherImpl::StepInto -- params == nullptr
1017 std::string msg = std::string() +
1018 R"({
1019 "id":0,
1020 "method":"Debugger.stepInto",
1021 "params":{
1022 "breakOnAsyncCall":"Str"
1023 }
1024 })";
1025 DispatchRequest request(msg);
1026
1027 dispatcherImpl->Dispatch(request);
1028 EXPECT_STREQ(outStrForCallbackCheck.c_str(), R"({"id":0,"result":{"code":1,"message":"wrong params"}})");
1029 if (protocolChannel) {
1030 delete protocolChannel;
1031 protocolChannel = nullptr;
1032 }
1033 }
1034
HWTEST_F_L0(DebuggerImplTest,Dispatcher_Dispatch_SetMixedDebugEnabled__001)1035 HWTEST_F_L0(DebuggerImplTest, Dispatcher_Dispatch_SetMixedDebugEnabled__001)
1036 {
1037 std::string outStrForCallbackCheck = "";
1038 std::function<void(const void*, const std::string &)> callback =
1039 [&outStrForCallbackCheck]([[maybe_unused]] const void *ptr, const std::string &inStrOfReply) {
1040 outStrForCallbackCheck = inStrOfReply;};
1041 ProtocolChannel *protocolChannel = new ProtocolHandler(callback, ecmaVm);
1042 auto runtimeImpl = std::make_unique<RuntimeImpl>(ecmaVm, protocolChannel);
1043 auto debuggerImpl = std::make_unique<DebuggerImpl>(ecmaVm, protocolChannel, runtimeImpl.get());
1044 auto dispatcherImpl = std::make_unique<DebuggerImpl::DispatcherImpl>(protocolChannel, std::move(debuggerImpl));
1045
1046 // DebuggerImpl::DispatcherImpl::SetMixedDebugEnabled -- Params == nullptr
1047 std::string msg = std::string() +
1048 R"({
1049 "id":0,
1050 "method":"Debugger.setMixedDebugEnabled",
1051 "params":{
1052 "enabled":"NotBoolValue"
1053 }
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_SetMixedDebugEnabled__002)1065 HWTEST_F_L0(DebuggerImplTest, Dispatcher_Dispatch_SetMixedDebugEnabled__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 EXPECT_FALSE(ecmaVm->GetJsDebuggerManager()->IsMixedDebugEnabled());
1076
1077 std::string msg = std::string() +
1078 R"({
1079 "id":0,
1080 "method":"Debugger.setMixedDebugEnabled",
1081 "params":{
1082 "enabled":true,
1083 "mixedStackEnabled":true
1084 }
1085 })";
1086 DispatchRequest request(msg);
1087
1088 dispatcherImpl->Dispatch(request);
1089 EXPECT_TRUE(ecmaVm->GetJsDebuggerManager()->IsMixedDebugEnabled());
1090 EXPECT_STREQ(outStrForCallbackCheck.c_str(), R"({"id":0,"result":{}})");
1091 if (protocolChannel) {
1092 delete protocolChannel;
1093 protocolChannel = nullptr;
1094 }
1095 }
1096
HWTEST_F_L0(DebuggerImplTest,Dispatcher_Dispatch_SetBlackboxPatterns__001)1097 HWTEST_F_L0(DebuggerImplTest, Dispatcher_Dispatch_SetBlackboxPatterns__001)
1098 {
1099 std::string outStrForCallbackCheck = "";
1100 std::function<void(const void*, const std::string &)> callback =
1101 [&outStrForCallbackCheck]([[maybe_unused]] const void *ptr, const std::string &inStrOfReply) {
1102 outStrForCallbackCheck = inStrOfReply;};
1103 ProtocolChannel *protocolChannel = new ProtocolHandler(callback, ecmaVm);
1104 auto runtimeImpl = std::make_unique<RuntimeImpl>(ecmaVm, protocolChannel);
1105 auto debuggerImpl = std::make_unique<DebuggerImpl>(ecmaVm, protocolChannel, runtimeImpl.get());
1106 auto dispatcherImpl = std::make_unique<DebuggerImpl::DispatcherImpl>(protocolChannel, std::move(debuggerImpl));
1107
1108 std::string msg = std::string() +
1109 R"({
1110 "id":0,
1111 "method":"Debugger.setBlackboxPatterns"
1112 })";
1113 DispatchRequest request(msg);
1114
1115 dispatcherImpl->Dispatch(request);
1116 EXPECT_STREQ(outStrForCallbackCheck.c_str(),
1117 R"({"id":0,"result":{"code":1,"message":"SetBlackboxPatterns not support now"}})");
1118 if (protocolChannel) {
1119 delete protocolChannel;
1120 protocolChannel = nullptr;
1121 }
1122 }
1123
HWTEST_F_L0(DebuggerImplTest,Dispatcher_Dispatch_ReplyNativeCalling__001)1124 HWTEST_F_L0(DebuggerImplTest, Dispatcher_Dispatch_ReplyNativeCalling__001)
1125 {
1126 std::string outStrForCallbackCheck = "";
1127 std::function<void(const void*, const std::string &)> callback =
1128 [&outStrForCallbackCheck]([[maybe_unused]] const void *ptr, const std::string &inStrOfReply) {
1129 outStrForCallbackCheck = inStrOfReply;};
1130 ProtocolChannel *protocolChannel = new ProtocolHandler(callback, ecmaVm);
1131 auto runtimeImpl = std::make_unique<RuntimeImpl>(ecmaVm, protocolChannel);
1132 auto debuggerImpl = std::make_unique<DebuggerImpl>(ecmaVm, protocolChannel, runtimeImpl.get());
1133 auto dispatcherImpl = std::make_unique<DebuggerImpl::DispatcherImpl>(protocolChannel, std::move(debuggerImpl));
1134
1135 // DebuggerImpl::DispatcherImpl::ReplyNativeCalling -- params == nullptr
1136 std::string msg = std::string() +
1137 R"({
1138 "id":0,
1139 "method":"Debugger.replyNativeCalling",
1140 "params":{
1141 "userCode":"NotBoolValue"
1142 }
1143 })";
1144 DispatchRequest request(msg);
1145
1146 dispatcherImpl->Dispatch(request);
1147 EXPECT_STREQ(outStrForCallbackCheck.c_str(), R"({"id":0,"result":{"code":1,"message":"wrong params"}})");
1148 if (protocolChannel) {
1149 delete protocolChannel;
1150 protocolChannel = nullptr;
1151 }
1152 }
1153
HWTEST_F_L0(DebuggerImplTest,Dispatcher_Dispatch_ReplyNativeCalling__002)1154 HWTEST_F_L0(DebuggerImplTest, Dispatcher_Dispatch_ReplyNativeCalling__002)
1155 {
1156 std::string outStrForCallbackCheck = "";
1157 std::function<void(const void*, const std::string &)> callback =
1158 [&outStrForCallbackCheck]([[maybe_unused]] const void *ptr, const std::string &inStrOfReply) {
1159 outStrForCallbackCheck = inStrOfReply;};
1160 ProtocolChannel *protocolChannel = new ProtocolHandler(callback, ecmaVm);
1161 auto runtimeImpl = std::make_unique<RuntimeImpl>(ecmaVm, protocolChannel);
1162 auto debuggerImpl = std::make_unique<DebuggerImpl>(ecmaVm, protocolChannel, runtimeImpl.get());
1163 auto dispatcherImpl = std::make_unique<DebuggerImpl::DispatcherImpl>(protocolChannel, std::move(debuggerImpl));
1164
1165 std::string msg = std::string() +
1166 R"({
1167 "id":0,
1168 "method":"Debugger.replyNativeCalling",
1169 "params":{
1170 "userCode":true
1171 }
1172 })";
1173 DispatchRequest request(msg);
1174
1175 dispatcherImpl->Dispatch(request);
1176 EXPECT_STREQ(outStrForCallbackCheck.c_str(), R"({"id":0,"result":{}})");
1177 if (protocolChannel) {
1178 delete protocolChannel;
1179 protocolChannel = nullptr;
1180 }
1181 }
1182
HWTEST_F_L0(DebuggerImplTest,Dispatcher_Dispatch_ContinueToLocation__001)1183 HWTEST_F_L0(DebuggerImplTest, Dispatcher_Dispatch_ContinueToLocation__001)
1184 {
1185 std::string outStrForCallbackCheck = "";
1186 std::function<void(const void*, const std::string &)> callback =
1187 [&outStrForCallbackCheck]([[maybe_unused]] const void *ptr, const std::string &inStrOfReply) {
1188 outStrForCallbackCheck = inStrOfReply;};
1189 ProtocolChannel *protocolChannel = new ProtocolHandler(callback, ecmaVm);
1190 auto runtimeImpl = std::make_unique<RuntimeImpl>(ecmaVm, protocolChannel);
1191 auto debuggerImpl = std::make_unique<DebuggerImpl>(ecmaVm, protocolChannel, runtimeImpl.get());
1192 auto dispatcherImpl = std::make_unique<DebuggerImpl::DispatcherImpl>(protocolChannel, std::move(debuggerImpl));
1193
1194 std::string msg = std::string() +
1195 R"({
1196 "id":0,
1197 "method":"Debugger.continueToLocation",
1198 "params":{}
1199 })";
1200 DispatchRequest request(msg);
1201
1202 dispatcherImpl->Dispatch(request);
1203 EXPECT_STREQ(outStrForCallbackCheck.c_str(), R"({"id":0,"result":{"code":1,"message":"wrong params"}})");
1204 if (protocolChannel) {
1205 delete protocolChannel;
1206 protocolChannel = nullptr;
1207 }
1208 }
1209
HWTEST_F_L0(DebuggerImplTest,Dispatcher_Dispatch_ContinueToLocation__002)1210 HWTEST_F_L0(DebuggerImplTest, Dispatcher_Dispatch_ContinueToLocation__002)
1211 {
1212 std::string outStrForCallbackCheck = "";
1213 std::function<void(const void*, const std::string &)> callback =
1214 [&outStrForCallbackCheck]([[maybe_unused]] const void *ptr, const std::string &inStrOfReply) {
1215 outStrForCallbackCheck = inStrOfReply;};
1216 ProtocolChannel *protocolChannel = new ProtocolHandler(callback, ecmaVm);
1217 auto runtimeImpl = std::make_unique<RuntimeImpl>(ecmaVm, protocolChannel);
1218 auto debuggerImpl = std::make_unique<DebuggerImpl>(ecmaVm, protocolChannel, runtimeImpl.get());
1219 auto dispatcherImpl = std::make_unique<DebuggerImpl::DispatcherImpl>(protocolChannel, std::move(debuggerImpl));
1220
1221 std::string msg = std::string() +
1222 R"({
1223 "id":0,
1224 "method":"Debugger.continueToLocation",
1225 "params":{
1226 "location":{
1227 "scriptId":"2",
1228 "lineNumber":3,
1229 "columnNumber":20
1230 },
1231 "targetCallFrames":"testTargetCallFrames"
1232 }
1233 })";
1234 DispatchRequest request(msg);
1235
1236 dispatcherImpl->Dispatch(request);
1237 EXPECT_STREQ(outStrForCallbackCheck.c_str(), R"({"id":0,"result":{}})");
1238 if (protocolChannel) {
1239 delete protocolChannel;
1240 protocolChannel = nullptr;
1241 }
1242 }
1243
HWTEST_F_L0(DebuggerImplTest,Dispatcher_Dispatch_SetBreakpointsActive__001)1244 HWTEST_F_L0(DebuggerImplTest, Dispatcher_Dispatch_SetBreakpointsActive__001)
1245 {
1246 std::string outStrForCallbackCheck = "";
1247 std::function<void(const void*, const std::string &)> callback =
1248 [&outStrForCallbackCheck]([[maybe_unused]] const void *ptr, const std::string &inStrOfReply) {
1249 outStrForCallbackCheck = inStrOfReply;};
1250 ProtocolChannel *protocolChannel = new ProtocolHandler(callback, ecmaVm);
1251 auto runtimeImpl = std::make_unique<RuntimeImpl>(ecmaVm, protocolChannel);
1252 auto debuggerImpl = std::make_unique<DebuggerImpl>(ecmaVm, protocolChannel, runtimeImpl.get());
1253 auto dispatcherImpl = std::make_unique<DebuggerImpl::DispatcherImpl>(protocolChannel, std::move(debuggerImpl));
1254
1255 std::string msg = std::string() +
1256 R"({
1257 "id":0,
1258 "method":"Debugger.setBreakpointsActive",
1259 "params":{}
1260 })";
1261 DispatchRequest request(msg);
1262
1263 dispatcherImpl->Dispatch(request);
1264 EXPECT_STREQ(outStrForCallbackCheck.c_str(), R"({"id":0,"result":{"code":1,"message":"wrong params"}})");
1265 if (protocolChannel) {
1266 delete protocolChannel;
1267 protocolChannel = nullptr;
1268 }
1269 }
1270
HWTEST_F_L0(DebuggerImplTest,Dispatcher_Dispatch_SetBreakpointsActive__002)1271 HWTEST_F_L0(DebuggerImplTest, Dispatcher_Dispatch_SetBreakpointsActive__002)
1272 {
1273 std::string outStrForCallbackCheck = "";
1274 std::function<void(const void*, const std::string &)> callback =
1275 [&outStrForCallbackCheck]([[maybe_unused]] const void *ptr, const std::string &inStrOfReply) {
1276 outStrForCallbackCheck = inStrOfReply;};
1277 ProtocolChannel *protocolChannel = new ProtocolHandler(callback, ecmaVm);
1278 auto runtimeImpl = std::make_unique<RuntimeImpl>(ecmaVm, protocolChannel);
1279 auto debuggerImpl = std::make_unique<DebuggerImpl>(ecmaVm, protocolChannel, runtimeImpl.get());
1280 auto dispatcherImpl = std::make_unique<DebuggerImpl::DispatcherImpl>(protocolChannel, std::move(debuggerImpl));
1281
1282 std::string msg = std::string() +
1283 R"({
1284 "id":0,
1285 "method":"Debugger.setBreakpointsActive",
1286 "params":{
1287 "active":true
1288 }
1289 })";
1290 DispatchRequest request(msg);
1291
1292 dispatcherImpl->Dispatch(request);
1293 EXPECT_STREQ(outStrForCallbackCheck.c_str(), R"({"id":0,"result":{}})");
1294 if (protocolChannel) {
1295 delete protocolChannel;
1296 protocolChannel = nullptr;
1297 }
1298 }
1299
HWTEST_F_L0(DebuggerImplTest,Dispatcher_Dispatch_SetSkipAllPauses__001)1300 HWTEST_F_L0(DebuggerImplTest, Dispatcher_Dispatch_SetSkipAllPauses__001)
1301 {
1302 std::string outStrForCallbackCheck = "";
1303 std::function<void(const void*, const std::string &)> callback =
1304 [&outStrForCallbackCheck]([[maybe_unused]] const void *ptr, const std::string &inStrOfReply) {
1305 outStrForCallbackCheck = inStrOfReply;};
1306 ProtocolChannel *protocolChannel = new ProtocolHandler(callback, ecmaVm);
1307 auto runtimeImpl = std::make_unique<RuntimeImpl>(ecmaVm, protocolChannel);
1308 auto debuggerImpl = std::make_unique<DebuggerImpl>(ecmaVm, protocolChannel, runtimeImpl.get());
1309 auto dispatcherImpl = std::make_unique<DebuggerImpl::DispatcherImpl>(protocolChannel, std::move(debuggerImpl));
1310
1311 std::string msg = std::string() +
1312 R"({
1313 "id":0,
1314 "method":"Debugger.setSkipAllPauses",
1315 "params":{}
1316 })";
1317 DispatchRequest request(msg);
1318
1319 dispatcherImpl->Dispatch(request);
1320 EXPECT_STREQ(outStrForCallbackCheck.c_str(), R"({"id":0,"result":{"code":1,"message":"wrong params"}})");
1321 if (protocolChannel) {
1322 delete protocolChannel;
1323 protocolChannel = nullptr;
1324 }
1325 }
1326
HWTEST_F_L0(DebuggerImplTest,Dispatcher_Dispatch_SetSkipAllPauses__002)1327 HWTEST_F_L0(DebuggerImplTest, Dispatcher_Dispatch_SetSkipAllPauses__002)
1328 {
1329 std::string outStrForCallbackCheck = "";
1330 std::function<void(const void*, const std::string &)> callback =
1331 [&outStrForCallbackCheck]([[maybe_unused]] const void *ptr, const std::string &inStrOfReply) {
1332 outStrForCallbackCheck = inStrOfReply;};
1333 ProtocolChannel *protocolChannel = new ProtocolHandler(callback, ecmaVm);
1334 auto runtimeImpl = std::make_unique<RuntimeImpl>(ecmaVm, protocolChannel);
1335 auto debuggerImpl = std::make_unique<DebuggerImpl>(ecmaVm, protocolChannel, runtimeImpl.get());
1336 auto dispatcherImpl = std::make_unique<DebuggerImpl::DispatcherImpl>(protocolChannel, std::move(debuggerImpl));
1337
1338 std::string msg = std::string() +
1339 R"({
1340 "id":0,
1341 "method":"Debugger.setSkipAllPauses",
1342 "params":{
1343 "skip":true
1344 }
1345 })";
1346 DispatchRequest request(msg);
1347
1348 dispatcherImpl->Dispatch(request);
1349 EXPECT_STREQ(outStrForCallbackCheck.c_str(), R"({"id":0,"result":{}})");
1350 if (protocolChannel) {
1351 delete protocolChannel;
1352 protocolChannel = nullptr;
1353 }
1354 }
1355
HWTEST_F_L0(DebuggerImplTest,Dispatcher_Dispatch_GetPossibleAndSetBreakpoint__001)1356 HWTEST_F_L0(DebuggerImplTest, Dispatcher_Dispatch_GetPossibleAndSetBreakpoint__001)
1357 {
1358 std::string outStrForCallbackCheck = "";
1359 std::function<void(const void*, const std::string &)> callback =
1360 [&outStrForCallbackCheck]([[maybe_unused]] const void *ptr, const std::string &inStrOfReply) {
1361 outStrForCallbackCheck = inStrOfReply;};
1362 ProtocolChannel *protocolChannel = new ProtocolHandler(callback, ecmaVm);
1363 auto runtimeImpl = std::make_unique<RuntimeImpl>(ecmaVm, protocolChannel);
1364 auto debuggerImpl = std::make_unique<DebuggerImpl>(ecmaVm, protocolChannel, runtimeImpl.get());
1365 ecmaVm->GetJsDebuggerManager()->SetDebugMode(true);
1366 auto dispatcherImpl = std::make_unique<DebuggerImpl::DispatcherImpl>(protocolChannel, std::move(debuggerImpl));
1367
1368 std::string msg = std::string() +
1369 R"({
1370 "id":0,
1371 "method":"Debugger.getPossibleAndSetBreakpointByUrl",
1372 "params":{}
1373 })";
1374 DispatchRequest request(msg);
1375
1376 dispatcherImpl->Dispatch(request);
1377 EXPECT_STREQ(outStrForCallbackCheck.c_str(),
1378 R"({"id":0,"result":{"code":1,"message":"GetPossibleAndSetBreakpointByUrl: no pennding breakpoint exists"}})");
1379 if (protocolChannel) {
1380 delete protocolChannel;
1381 protocolChannel = nullptr;
1382 }
1383 }
1384
HWTEST_F_L0(DebuggerImplTest,Dispatcher_Dispatch_GetPossibleAndSetBreakpoint__002)1385 HWTEST_F_L0(DebuggerImplTest, Dispatcher_Dispatch_GetPossibleAndSetBreakpoint__002)
1386 {
1387 std::string outStrForCallbackCheck = "";
1388 std::function<void(const void*, const std::string &)> callback =
1389 [&outStrForCallbackCheck]([[maybe_unused]] const void *ptr, const std::string &inStrOfReply) {
1390 outStrForCallbackCheck = inStrOfReply;};
1391 ProtocolChannel *protocolChannel = new ProtocolHandler(callback, ecmaVm);
1392 auto runtimeImpl = std::make_unique<RuntimeImpl>(ecmaVm, protocolChannel);
1393 auto debuggerImpl = std::make_unique<DebuggerImpl>(ecmaVm, protocolChannel, runtimeImpl.get());
1394 ecmaVm->GetJsDebuggerManager()->SetDebugMode(true);
1395 auto dispatcherImpl = std::make_unique<DebuggerImpl::DispatcherImpl>(protocolChannel, std::move(debuggerImpl));
1396
1397 std::string msg = std::string() +
1398 R"({
1399 "id":0,
1400 "method":"Debugger.getPossibleAndSetBreakpointByUrl",
1401 "params":{
1402 "locations":[
1403 {
1404 "lineNumber":3,
1405 "columnNumber":20,
1406 "url":"Index.ets"
1407 }]
1408 }
1409 })";
1410 DispatchRequest request(msg);
1411
1412 dispatcherImpl->Dispatch(request);
1413 EXPECT_STREQ(outStrForCallbackCheck.c_str(),
1414 R"({"id":0,"result":{"locations":[{"lineNumber":3,"columnNumber":20,"id":"invalid","scriptId":0}]}})");
1415 if (protocolChannel) {
1416 delete protocolChannel;
1417 protocolChannel = nullptr;
1418 }
1419 }
1420
HWTEST_F_L0(DebuggerImplTest,Dispatcher_Dispatch_GetPossibleAndSetBreakpointByUrl__001)1421 HWTEST_F_L0(DebuggerImplTest, Dispatcher_Dispatch_GetPossibleAndSetBreakpointByUrl__001)
1422 {
1423 ProtocolChannel *protocolChannel = new ProtocolHandler(nullptr, ecmaVm);
1424 auto runtimeImpl = std::make_unique<RuntimeImpl>(ecmaVm, protocolChannel);
1425 auto debuggerImpl = std::make_unique<DebuggerImpl>(ecmaVm, protocolChannel, runtimeImpl.get());
1426 auto dispatcherImpl = std::make_unique<DebuggerImpl::DispatcherImpl>(protocolChannel, std::move(debuggerImpl));
1427 int32_t callId = 0;
1428 std::string msg = std::string() +
1429 R"({
1430 "id": 0,
1431 "method": "Debugger.getPossibleAndSetBreakpointByUrl",
1432 "params": {
1433 "locations": [{
1434 "url": "entry|entry|1.0.0|src/main/ets/pages/Index.ts",
1435 "lineNumber": 59,
1436 "columnNumber": 16
1437 }]
1438 }
1439 })";
1440 std::unique_ptr<GetPossibleAndSetBreakpointParams> params =
1441 GetPossibleAndSetBreakpointParams::Create(DispatchRequest(msg).GetParams());
1442 std::string result = dispatcherImpl->GetPossibleAndSetBreakpointByUrl(callId, std::move(params));
1443 EXPECT_STREQ(result.c_str(),
1444 R"({"id":0,"result":{"code":1,"message":"GetPossibleAndSetBreakpointByUrl: debugger agent is not enabled"}})");
1445 if (protocolChannel) {
1446 delete protocolChannel;
1447 protocolChannel = nullptr;
1448 }
1449 }
1450
HWTEST_F_L0(DebuggerImplTest,Dispatcher_Dispatch_DropFrame__001)1451 HWTEST_F_L0(DebuggerImplTest, Dispatcher_Dispatch_DropFrame__001)
1452 {
1453 std::string outStrForCallbackCheck = "";
1454 std::function<void(const void*, const std::string &)> callback =
1455 [&outStrForCallbackCheck]([[maybe_unused]] const void *ptr, const std::string &inStrOfReply) {
1456 outStrForCallbackCheck = inStrOfReply;};
1457 ProtocolChannel *protocolChannel = new ProtocolHandler(callback, ecmaVm);
1458 auto runtimeImpl = std::make_unique<RuntimeImpl>(ecmaVm, protocolChannel);
1459 auto debuggerImpl = std::make_unique<DebuggerImpl>(ecmaVm, protocolChannel, runtimeImpl.get());
1460 debuggerImpl->SetDebuggerState(DebuggerState::PAUSED);
1461 auto dispatcherImpl = std::make_unique<DebuggerImpl::DispatcherImpl>(protocolChannel, std::move(debuggerImpl));
1462
1463 std::string msg = std::string() +
1464 R"({
1465 "id":0,
1466 "method":"Debugger.dropFrame",
1467 "params":{
1468 "droppedDepth":3
1469 }
1470 })";
1471 DispatchRequest request(msg);
1472
1473 dispatcherImpl->Dispatch(request);
1474 EXPECT_STREQ(outStrForCallbackCheck.c_str(),
1475 R"({"id":0,"result":{"code":1,"message":"Not yet support dropping multiple frames"}})");
1476 if (protocolChannel) {
1477 delete protocolChannel;
1478 protocolChannel = nullptr;
1479 }
1480 }
1481
HWTEST_F_L0(DebuggerImplTest,DispatcherImplCallFunctionOn__001)1482 HWTEST_F_L0(DebuggerImplTest, DispatcherImplCallFunctionOn__001)
1483 {
1484 std::string outStrForCallbackCheck = "";
1485 std::function<void(const void*, const std::string &)> callback =
1486 [&outStrForCallbackCheck]([[maybe_unused]] const void *ptr, const std::string &inStrOfReply) {
1487 outStrForCallbackCheck = inStrOfReply;};
1488 ProtocolChannel *protocolChannel = new ProtocolHandler(callback, ecmaVm);
1489 auto runtimeImpl = std::make_unique<RuntimeImpl>(ecmaVm, protocolChannel);
1490 auto debuggerImpl = std::make_unique<DebuggerImpl>(ecmaVm, protocolChannel, runtimeImpl.get());
1491 auto dispatcherImpl = std::make_unique<DebuggerImpl::DispatcherImpl>(protocolChannel, std::move(debuggerImpl));
1492
1493 std::string msg = std::string() + R"({"id":0,"method":"Debugger.callFunctionOn","params":{
1494 "callFrameId":"0", "functionDeclaration":0}})";
1495 DispatchRequest request(msg);
1496 dispatcherImpl->CallFunctionOn(request);
1497 ASSERT_TRUE(outStrForCallbackCheck.find("wrong params") != std::string::npos);
1498
1499 msg = std::string() + R"({"id":0,"method":"Debugger.callFunctionOn","params":{
1500 "callFrameId":"0", "functionDeclaration":"test"}})";
1501 DispatchRequest request1(msg);
1502 dispatcherImpl->CallFunctionOn(request1);
1503 ASSERT_TRUE(outStrForCallbackCheck.find("Unsupport eval now") == std::string::npos);
1504 if (protocolChannel != nullptr) {
1505 delete protocolChannel;
1506 protocolChannel = nullptr;
1507 }
1508 }
1509
HWTEST_F_L0(DebuggerImplTest,DispatcherImplCallFunctionOn__002)1510 HWTEST_F_L0(DebuggerImplTest, DispatcherImplCallFunctionOn__002)
1511 {
1512 ProtocolChannel *protocolChannel = new ProtocolHandler(nullptr, ecmaVm);
1513 auto runtimeImpl = std::make_unique<RuntimeImpl>(ecmaVm, protocolChannel);
1514 auto debuggerImpl = std::make_unique<DebuggerImpl>(ecmaVm, protocolChannel, runtimeImpl.get());
1515 auto dispatcherImpl = std::make_unique<DebuggerImpl::DispatcherImpl>(protocolChannel, std::move(debuggerImpl));
1516 std::string msg = std::string() + R"({"id":0,"method":"Debugger.callFunctionOn","params":{
1517 "callFrameId":"0", "functionDeclaration":"test"}})";
1518 std::unique_ptr<CallFunctionOnParams> params = CallFunctionOnParams::Create(DispatchRequest(msg).GetParams());
1519 int32_t callId = 0;
1520 std::string result = dispatcherImpl->CallFunctionOn(callId, std::move(params));
1521 EXPECT_STREQ(result.c_str(), R"({"id":0,"result":{"code":1,"message":"Invalid callFrameId."}})");
1522 if (protocolChannel != nullptr) {
1523 delete protocolChannel;
1524 protocolChannel = nullptr;
1525 }
1526 }
1527
HWTEST_F_L0(DebuggerImplTest,Dispatcher_Dispatch_SmartStepInto__001)1528 HWTEST_F_L0(DebuggerImplTest, Dispatcher_Dispatch_SmartStepInto__001)
1529 {
1530 std::string outStrForCallbackCheck = "";
1531 std::function<void(const void*, const std::string &)> callback =
1532 [&outStrForCallbackCheck]([[maybe_unused]] const void *ptr, const std::string &inStrOfReply) {
1533 outStrForCallbackCheck = inStrOfReply;};
1534 ProtocolChannel *protocolChannel = new ProtocolHandler(callback, ecmaVm);
1535 auto runtimeImpl = std::make_unique<RuntimeImpl>(ecmaVm, protocolChannel);
1536 auto debuggerImpl = std::make_unique<DebuggerImpl>(ecmaVm, protocolChannel, runtimeImpl.get());
1537 auto dispatcherImpl = std::make_unique<DebuggerImpl::DispatcherImpl>(protocolChannel, std::move(debuggerImpl));
1538
1539 std::string msg = std::string() +
1540 R"({
1541 "id":0,
1542 "method":"Debugger.smartStepInto",
1543 "params":{}
1544 })";
1545 DispatchRequest request(msg);
1546
1547 dispatcherImpl->Dispatch(request);
1548 EXPECT_STREQ(outStrForCallbackCheck.c_str(),
1549 R"({"id":0,"result":{"code":1,"message":"wrong params"}})");
1550 if (protocolChannel) {
1551 delete protocolChannel;
1552 protocolChannel = nullptr;
1553 }
1554 }
1555
HWTEST_F_L0(DebuggerImplTest,Dispatcher_Dispatch_SmartStepInto__002)1556 HWTEST_F_L0(DebuggerImplTest, Dispatcher_Dispatch_SmartStepInto__002)
1557 {
1558 std::string outStrForCallbackCheck = "";
1559 std::function<void(const void*, const std::string &)> callback =
1560 [&outStrForCallbackCheck]([[maybe_unused]] const void *ptr, const std::string &inStrOfReply) {
1561 outStrForCallbackCheck = inStrOfReply;};
1562 ProtocolChannel *protocolChannel = new ProtocolHandler(callback, ecmaVm);
1563 auto runtimeImpl = std::make_unique<RuntimeImpl>(ecmaVm, protocolChannel);
1564 auto debuggerImpl = std::make_unique<DebuggerImpl>(ecmaVm, protocolChannel, runtimeImpl.get());
1565 auto dispatcherImpl = std::make_unique<DebuggerImpl::DispatcherImpl>(protocolChannel, std::move(debuggerImpl));
1566
1567 std::string msg = std::string() +
1568 R"({
1569 "id":0,
1570 "method":"Debugger.smartStepInto",
1571 "params":{
1572 "lineNumber":0,
1573 "url":"url_str",
1574 "urlRegex":"urlRegex_str",
1575 "scriptHash":"scriptHash_str",
1576 "columnNumber":0,
1577 "condition":"condition_str"
1578 }
1579 })";
1580 DispatchRequest request(msg);
1581
1582 dispatcherImpl->Dispatch(request);
1583 EXPECT_STREQ(outStrForCallbackCheck.c_str(),
1584 R"({"id":0,"result":{"code":1,"message":"Can only perform operation while paused"}})");
1585 if (protocolChannel) {
1586 delete protocolChannel;
1587 protocolChannel = nullptr;
1588 }
1589 }
1590
HWTEST_F_L0(DebuggerImplTest,Dispatcher_Dispatch_SmartStepInto__003)1591 HWTEST_F_L0(DebuggerImplTest, Dispatcher_Dispatch_SmartStepInto__003)
1592 {
1593 std::string outStrForCallbackCheck = "";
1594 std::function<void(const void*, const std::string &)> callback =
1595 [&outStrForCallbackCheck]([[maybe_unused]] const void *ptr, const std::string &inStrOfReply) {
1596 outStrForCallbackCheck = inStrOfReply;};
1597 ProtocolChannel *protocolChannel = new ProtocolHandler(callback, ecmaVm);
1598 auto runtimeImpl = std::make_unique<RuntimeImpl>(ecmaVm, protocolChannel);
1599 auto debuggerImpl = std::make_unique<DebuggerImpl>(ecmaVm, protocolChannel, runtimeImpl.get());
1600 debuggerImpl->SetDebuggerState(DebuggerState::PAUSED);
1601 auto dispatcherImpl = std::make_unique<DebuggerImpl::DispatcherImpl>(protocolChannel, std::move(debuggerImpl));
1602
1603 std::string msg = std::string() +
1604 R"({
1605 "id":0,
1606 "method":"Debugger.smartStepInto",
1607 "params":{
1608 "lineNumber":0,
1609 "url":"url_str",
1610 "urlRegex":"urlRegex_str",
1611 "scriptHash":"scriptHash_str",
1612 "columnNumber":0,
1613 "condition":"condition_str"
1614 }
1615 })";
1616 DispatchRequest request(msg);
1617
1618 dispatcherImpl->Dispatch(request);
1619 EXPECT_STREQ(outStrForCallbackCheck.c_str(),
1620 R"({"id":0,"result":{"code":1,"message":"SetBreakpointByUrl: debugger agent is not enabled"}})");
1621 if (protocolChannel) {
1622 delete protocolChannel;
1623 protocolChannel = nullptr;
1624 }
1625 }
1626
HWTEST_F_L0(DebuggerImplTest,Dispatcher_Dispatch_SetNativeRange__001)1627 HWTEST_F_L0(DebuggerImplTest, Dispatcher_Dispatch_SetNativeRange__001)
1628 {
1629 std::string outStrForCallbackCheck = "";
1630 std::function<void(const void*, const std::string &)> callback =
1631 [&outStrForCallbackCheck]([[maybe_unused]] const void *ptr, const std::string &inStrOfReply) {
1632 outStrForCallbackCheck = inStrOfReply;};
1633 ProtocolChannel *protocolChannel = new ProtocolHandler(callback, ecmaVm);
1634 auto runtimeImpl = std::make_unique<RuntimeImpl>(ecmaVm, protocolChannel);
1635 auto debuggerImpl = std::make_unique<DebuggerImpl>(ecmaVm, protocolChannel, runtimeImpl.get());
1636 auto dispatcherImpl = std::make_unique<DebuggerImpl::DispatcherImpl>(protocolChannel, std::move(debuggerImpl));
1637
1638 std::string msg = std::string() +
1639 R"({
1640 "id":0,
1641 "method":"Debugger.setNativeRange",
1642 "params":{
1643 "nativeRange":""
1644 }
1645 })";
1646 DispatchRequest request(msg);
1647
1648 dispatcherImpl->Dispatch(request);
1649 EXPECT_STREQ(outStrForCallbackCheck.c_str(),
1650 R"({"id":0,"result":{"code":1,"message":"wrong params"}})");
1651 if (protocolChannel) {
1652 delete protocolChannel;
1653 protocolChannel = nullptr;
1654 }
1655 }
1656
HWTEST_F_L0(DebuggerImplTest,Dispatcher_Dispatch_SetNativeRange__002)1657 HWTEST_F_L0(DebuggerImplTest, Dispatcher_Dispatch_SetNativeRange__002)
1658 {
1659 std::string outStrForCallbackCheck = "";
1660 std::function<void(const void*, const std::string &)> callback =
1661 [&outStrForCallbackCheck]([[maybe_unused]] const void *ptr, const std::string &inStrOfReply) {
1662 outStrForCallbackCheck = inStrOfReply;};
1663 ProtocolChannel *protocolChannel = new ProtocolHandler(callback, ecmaVm);
1664 auto runtimeImpl = std::make_unique<RuntimeImpl>(ecmaVm, protocolChannel);
1665 auto debuggerImpl = std::make_unique<DebuggerImpl>(ecmaVm, protocolChannel, runtimeImpl.get());
1666 auto dispatcherImpl = std::make_unique<DebuggerImpl::DispatcherImpl>(protocolChannel, std::move(debuggerImpl));
1667
1668 std::string msg = std::string() +
1669 R"({
1670 "id":0,
1671 "method":"Debugger.setNativeRange",
1672 "params":{}
1673 })";
1674 DispatchRequest request(msg);
1675
1676 dispatcherImpl->Dispatch(request);
1677 EXPECT_STREQ(outStrForCallbackCheck.c_str(),
1678 R"({"id":0,"result":{}})");
1679 if (protocolChannel) {
1680 delete protocolChannel;
1681 protocolChannel = nullptr;
1682 }
1683 }
1684
HWTEST_F_L0(DebuggerImplTest,Dispatcher_Dispatch_ResetSingleStepper__001)1685 HWTEST_F_L0(DebuggerImplTest, Dispatcher_Dispatch_ResetSingleStepper__001)
1686 {
1687 std::string outStrForCallbackCheck = "";
1688 std::function<void(const void*, const std::string &)> callback =
1689 [&outStrForCallbackCheck]([[maybe_unused]] const void *ptr, const std::string &inStrOfReply) {
1690 outStrForCallbackCheck = inStrOfReply;};
1691 ProtocolChannel *protocolChannel = new ProtocolHandler(callback, ecmaVm);
1692 auto runtimeImpl = std::make_unique<RuntimeImpl>(ecmaVm, protocolChannel);
1693 auto debuggerImpl = std::make_unique<DebuggerImpl>(ecmaVm, protocolChannel, runtimeImpl.get());
1694 auto dispatcherImpl = std::make_unique<DebuggerImpl::DispatcherImpl>(protocolChannel, std::move(debuggerImpl));
1695
1696 std::string msg = std::string() +
1697 R"({
1698 "id":0,
1699 "method":"Debugger.resetSingleStepper",
1700 "params":{
1701 "resetSingleStepper":"test"
1702 }
1703 })";
1704 DispatchRequest request(msg);
1705
1706 dispatcherImpl->Dispatch(request);
1707 EXPECT_STREQ(outStrForCallbackCheck.c_str(),
1708 R"({"id":0,"result":{"code":1,"message":"wrong params"}})");
1709 if (protocolChannel) {
1710 delete protocolChannel;
1711 protocolChannel = nullptr;
1712 }
1713 }
1714
HWTEST_F_L0(DebuggerImplTest,Dispatcher_Dispatch_ResetSingleStepper__002)1715 HWTEST_F_L0(DebuggerImplTest, Dispatcher_Dispatch_ResetSingleStepper__002)
1716 {
1717 std::string outStrForCallbackCheck = "";
1718 std::function<void(const void*, const std::string &)> callback =
1719 [&outStrForCallbackCheck]([[maybe_unused]] const void *ptr, const std::string &inStrOfReply) {
1720 outStrForCallbackCheck = inStrOfReply;};
1721 ProtocolChannel *protocolChannel = new ProtocolHandler(callback, ecmaVm);
1722 auto runtimeImpl = std::make_unique<RuntimeImpl>(ecmaVm, protocolChannel);
1723 auto debuggerImpl = std::make_unique<DebuggerImpl>(ecmaVm, protocolChannel, runtimeImpl.get());
1724 auto dispatcherImpl = std::make_unique<DebuggerImpl::DispatcherImpl>(protocolChannel, std::move(debuggerImpl));
1725
1726 std::string msg = std::string() +
1727 R"({
1728 "id":0,
1729 "method":"Debugger.resetSingleStepper",
1730 "params":{
1731 "resetSingleStepper":true
1732 }
1733 })";
1734 DispatchRequest request(msg);
1735
1736 dispatcherImpl->Dispatch(request);
1737 EXPECT_STREQ(outStrForCallbackCheck.c_str(),
1738 R"({"id":0,"result":{}})");
1739 if (protocolChannel) {
1740 delete protocolChannel;
1741 protocolChannel = nullptr;
1742 }
1743 }
1744
HWTEST_F_L0(DebuggerImplTest,Dispatcher_Dispatch_ClientDisconnect)1745 HWTEST_F_L0(DebuggerImplTest, Dispatcher_Dispatch_ClientDisconnect)
1746 {
1747 std::string outStrForCallbackCheck = "";
1748 std::function<void(const void*, const std::string &)> callback =
1749 [&outStrForCallbackCheck]([[maybe_unused]] const void *ptr, const std::string &inStrOfReply) {
1750 outStrForCallbackCheck = inStrOfReply;};
1751 ProtocolChannel *protocolChannel = new ProtocolHandler(callback, ecmaVm);
1752 auto runtimeImpl = std::make_unique<RuntimeImpl>(ecmaVm, protocolChannel);
1753 auto debuggerImpl = std::make_unique<DebuggerImpl>(ecmaVm, protocolChannel, runtimeImpl.get());
1754 auto dispatcherImpl = std::make_unique<DebuggerImpl::DispatcherImpl>(protocolChannel, std::move(debuggerImpl));
1755
1756 std::string msg = std::string() +
1757 R"({
1758 "id":0,
1759 "method":"Debugger.clientDisconnect",
1760 "params":{}
1761 })";
1762 DispatchRequest request(msg);
1763
1764 dispatcherImpl->Dispatch(request);
1765 EXPECT_STREQ(outStrForCallbackCheck.c_str(), R"()");
1766 if (protocolChannel) {
1767 delete protocolChannel;
1768 protocolChannel = nullptr;
1769 }
1770 }
1771
HWTEST_F_L0(DebuggerImplTest,Dispatcher_Dispatch_CallFunctionOn__001)1772 HWTEST_F_L0(DebuggerImplTest, Dispatcher_Dispatch_CallFunctionOn__001)
1773 {
1774 std::string outStrForCallbackCheck = "";
1775 std::function<void(const void*, const std::string &)> callback =
1776 [&outStrForCallbackCheck]([[maybe_unused]] const void *ptr, const std::string &inStrOfReply) {
1777 outStrForCallbackCheck = inStrOfReply;};
1778 ProtocolChannel *protocolChannel = new ProtocolHandler(callback, ecmaVm);
1779 auto runtimeImpl = std::make_unique<RuntimeImpl>(ecmaVm, protocolChannel);
1780 auto debuggerImpl = std::make_unique<DebuggerImpl>(ecmaVm, protocolChannel, runtimeImpl.get());
1781 auto dispatcherImpl = std::make_unique<DebuggerImpl::DispatcherImpl>(protocolChannel, std::move(debuggerImpl));
1782
1783 std::string msg = std::string() +
1784 R"({
1785 "id":0,
1786 "method":"Debugger.callFunctionOn",
1787 "params":{
1788 "callFrameId":"1",
1789 "functionDeclaration":"test"
1790 }
1791 })";
1792 DispatchRequest request(msg);
1793
1794 dispatcherImpl->Dispatch(request);
1795 EXPECT_STREQ(outStrForCallbackCheck.c_str(),
1796 R"({"id":0,"result":{"code":1,"message":"Invalid callFrameId."}})");
1797 if (protocolChannel) {
1798 delete protocolChannel;
1799 protocolChannel = nullptr;
1800 }
1801 }
1802
HWTEST_F_L0(DebuggerImplTest,Dispatcher_Dispatch_CallFunctionOn__002)1803 HWTEST_F_L0(DebuggerImplTest, Dispatcher_Dispatch_CallFunctionOn__002)
1804 {
1805 std::string outStrForCallbackCheck = "";
1806 std::function<void(const void*, const std::string &)> callback =
1807 [&outStrForCallbackCheck]([[maybe_unused]] const void *ptr, const std::string &inStrOfReply) {
1808 outStrForCallbackCheck = inStrOfReply;};
1809 ProtocolChannel *protocolChannel = new ProtocolHandler(callback, ecmaVm);
1810 auto runtimeImpl = std::make_unique<RuntimeImpl>(ecmaVm, protocolChannel);
1811 auto debuggerImpl = std::make_unique<DebuggerImpl>(ecmaVm, protocolChannel, runtimeImpl.get());
1812 auto dispatcherImpl = std::make_unique<DebuggerImpl::DispatcherImpl>(protocolChannel, std::move(debuggerImpl));
1813
1814 std::string msg = std::string() +
1815 R"({
1816 "id":0,
1817 "method":"Debugger.callFunctionOn",
1818 "params":{
1819 "callFrameId":"0",
1820 "functionDeclaration":0
1821 }
1822 })";
1823 DispatchRequest request(msg);
1824
1825 dispatcherImpl->Dispatch(request);
1826 EXPECT_STREQ(outStrForCallbackCheck.c_str(),
1827 R"({"id":0,"result":{"code":1,"message":"wrong params"}})");
1828 if (protocolChannel) {
1829 delete protocolChannel;
1830 protocolChannel = nullptr;
1831 }
1832 }
1833
HWTEST_F_L0(DebuggerImplTest,NativeOutTest)1834 HWTEST_F_L0(DebuggerImplTest, NativeOutTest)
1835 {
1836 std::string outStrForCallbackCheck = "";
1837 std::function<void(const void*, const std::string &)> callback =
1838 [&outStrForCallbackCheck]([[maybe_unused]] const void *ptr, const std::string &inStrOfReply) {
1839 outStrForCallbackCheck = inStrOfReply;};
1840 ProtocolChannel *protocolChannel = new ProtocolHandler(callback, ecmaVm);
1841 auto runtimeImpl = std::make_unique<RuntimeImpl>(ecmaVm, protocolChannel);
1842 auto debuggerImpl = std::make_unique<DebuggerImpl>(ecmaVm, protocolChannel, runtimeImpl.get());
1843 std::unique_ptr<JSPtHooks> jspthooks = std::make_unique<JSPtHooks>(debuggerImpl.get());
1844 bool result1 = jspthooks->NativeOut();
1845 ASSERT_TRUE(!result1);
1846 bool value = true;
1847 debuggerImpl->SetNativeOutPause(value);
1848 bool result2 = jspthooks->NativeOut();
1849 ASSERT_TRUE(result2);
1850 ASSERT_NE(jspthooks, nullptr);
1851 }
1852
HWTEST_F_L0(DebuggerImplTest,NotifyNativeReturn__001)1853 HWTEST_F_L0(DebuggerImplTest, NotifyNativeReturn__001)
1854 {
1855 std::string outStrForCallbackCheck = "";
1856 std::function<void(const void*, const std::string &)> callback =
1857 [&outStrForCallbackCheck]([[maybe_unused]] const void *ptr, const std::string &inStrOfReply) {
1858 outStrForCallbackCheck = inStrOfReply;};
1859 ProtocolChannel *protocolChannel = new ProtocolHandler(callback, ecmaVm);
1860
1861 auto runtimeImpl = std::make_unique<RuntimeImpl>(ecmaVm, protocolChannel);
1862 auto debuggerImpl = std::make_unique<DebuggerImpl>(ecmaVm, protocolChannel, runtimeImpl.get());
1863 std::unique_ptr<PtJson> json = PtJson::CreateObject();
1864 json->Add("enabled", false);
1865 json->Add("mixedStackEnabled", false);
1866 std::unique_ptr<SetMixedDebugParams> params = SetMixedDebugParams::Create(*json);
1867 debuggerImpl->SetMixedDebugEnabled(*params);
1868 debuggerImpl->NotifyNativeReturn(nullptr);
1869 auto debugger = std::make_unique<DebuggerImplFriendTest>(debuggerImpl);
1870 ASSERT_TRUE(!debugger->GetMixStackEnabled());
1871 if (protocolChannel) {
1872 delete protocolChannel;
1873 protocolChannel = nullptr;
1874 }
1875 }
1876
HWTEST_F_L0(DebuggerImplTest,NotifyNativeReturn__002)1877 HWTEST_F_L0(DebuggerImplTest, NotifyNativeReturn__002)
1878 {
1879 std::string outStrForCallbackCheck = "";
1880 std::function<void(const void*, const std::string &)> callback =
1881 [&outStrForCallbackCheck]([[maybe_unused]] const void *ptr, const std::string &inStrOfReply) {
1882 outStrForCallbackCheck = inStrOfReply;};
1883 ProtocolChannel *protocolChannel = new ProtocolHandler(callback, ecmaVm);
1884
1885 auto runtimeImpl = std::make_unique<RuntimeImpl>(ecmaVm, protocolChannel);
1886 auto debuggerImpl = std::make_unique<DebuggerImpl>(ecmaVm, protocolChannel, runtimeImpl.get());
1887 std::unique_ptr<PtJson> json = PtJson::CreateObject();
1888 json->Add("enabled", false);
1889 json->Add("mixedStackEnabled", true);
1890 std::unique_ptr<SetMixedDebugParams> params = SetMixedDebugParams::Create(*json);
1891 debuggerImpl->SetMixedDebugEnabled(*params);
1892 debuggerImpl->NotifyNativeReturn(nullptr);
1893 auto debugger = std::make_unique<DebuggerImplFriendTest>(debuggerImpl);
1894 ASSERT_TRUE(debugger->GetMixStackEnabled());
1895 if (protocolChannel) {
1896 delete protocolChannel;
1897 protocolChannel = nullptr;
1898 }
1899 }
1900
HWTEST_F_L0(DebuggerImplTest,NotifyReturnNative__001)1901 HWTEST_F_L0(DebuggerImplTest, NotifyReturnNative__001)
1902 {
1903 std::string outStrForCallbackCheck = "";
1904 std::function<void(const void*, const std::string &)> callback =
1905 [&outStrForCallbackCheck]([[maybe_unused]] const void *ptr, const std::string &inStrOfReply) {
1906 outStrForCallbackCheck = inStrOfReply;};
1907 ProtocolChannel *protocolChannel = new ProtocolHandler(callback, ecmaVm);
1908
1909 auto runtimeImpl = std::make_unique<RuntimeImpl>(ecmaVm, protocolChannel);
1910 auto debuggerImpl = std::make_unique<DebuggerImpl>(ecmaVm, protocolChannel, runtimeImpl.get());
1911 std::unique_ptr<PtJson> json = PtJson::CreateObject();
1912 json->Add("enabled", false);
1913 json->Add("mixedStackEnabled", true);
1914 std::unique_ptr<SetMixedDebugParams> params = SetMixedDebugParams::Create(*json);
1915 debuggerImpl->SetMixedDebugEnabled(*params);
1916 debuggerImpl->NotifyReturnNative();
1917 auto debugger = std::make_unique<DebuggerImplFriendTest>(debuggerImpl);
1918 ASSERT_TRUE(debugger->GetMixStackEnabled());
1919 if (protocolChannel) {
1920 delete protocolChannel;
1921 protocolChannel = nullptr;
1922 }
1923 }
1924
HWTEST_F_L0(DebuggerImplTest,NotifyReturnNative__002)1925 HWTEST_F_L0(DebuggerImplTest, NotifyReturnNative__002)
1926 {
1927 std::string outStrForCallbackCheck = "";
1928 std::function<void(const void*, const std::string &)> callback =
1929 [&outStrForCallbackCheck]([[maybe_unused]] const void *ptr, const std::string &inStrOfReply) {
1930 outStrForCallbackCheck = inStrOfReply;};
1931 ProtocolChannel *protocolChannel = new ProtocolHandler(callback, ecmaVm);
1932
1933 auto runtimeImpl = std::make_unique<RuntimeImpl>(ecmaVm, protocolChannel);
1934 auto debuggerImpl = std::make_unique<DebuggerImpl>(ecmaVm, protocolChannel, runtimeImpl.get());
1935 std::unique_ptr<PtJson> json = PtJson::CreateObject();
1936 json->Add("enabled", false);
1937 json->Add("mixedStackEnabled", false);
1938 std::unique_ptr<SetMixedDebugParams> params = SetMixedDebugParams::Create(*json);
1939 debuggerImpl->SetMixedDebugEnabled(*params);
1940 debuggerImpl->NotifyReturnNative();
1941 auto debugger = std::make_unique<DebuggerImplFriendTest>(debuggerImpl);
1942 ASSERT_TRUE(!debugger->GetMixStackEnabled());
1943 if (protocolChannel) {
1944 delete protocolChannel;
1945 protocolChannel = nullptr;
1946 }
1947 }
1948
HWTEST_F_L0(DebuggerImplTest,NotifyNativeCalling__001)1949 HWTEST_F_L0(DebuggerImplTest, NotifyNativeCalling__001)
1950 {
1951 std::string outStrForCallbackCheck = "";
1952 std::function<void(const void*, const std::string &)> callback =
1953 [&outStrForCallbackCheck]([[maybe_unused]] const void *ptr, const std::string &inStrOfReply) {
1954 outStrForCallbackCheck = inStrOfReply;};
1955 ProtocolChannel *protocolChannel = new ProtocolHandler(callback, ecmaVm);
1956
1957 auto runtimeImpl = std::make_unique<RuntimeImpl>(ecmaVm, protocolChannel);
1958 auto debuggerImpl = std::make_unique<DebuggerImpl>(ecmaVm, protocolChannel, runtimeImpl.get());
1959 std::unique_ptr<PtJson> json = PtJson::CreateObject();
1960 json->Add("enabled", false);
1961 json->Add("mixedStackEnabled", false);
1962 std::unique_ptr<SetMixedDebugParams> params = SetMixedDebugParams::Create(*json);
1963 debuggerImpl->SetMixedDebugEnabled(*params);
1964 debuggerImpl->NotifyNativeCalling(nullptr);
1965 auto debugger = std::make_unique<DebuggerImplFriendTest>(debuggerImpl);
1966 ASSERT_TRUE(!debugger->GetMixStackEnabled());
1967 if (protocolChannel) {
1968 delete protocolChannel;
1969 protocolChannel = nullptr;
1970 }
1971 }
1972
HWTEST_F_L0(DebuggerImplTest,NotifyNativeCalling__002)1973 HWTEST_F_L0(DebuggerImplTest, NotifyNativeCalling__002)
1974 {
1975 std::string outStrForCallbackCheck = "";
1976 std::function<void(const void*, const std::string &)> callback =
1977 [&outStrForCallbackCheck]([[maybe_unused]] const void *ptr, const std::string &inStrOfReply) {
1978 outStrForCallbackCheck = inStrOfReply;};
1979 ProtocolChannel *protocolChannel = new ProtocolHandler(callback, ecmaVm);
1980
1981 auto runtimeImpl = std::make_unique<RuntimeImpl>(ecmaVm, protocolChannel);
1982 auto debuggerImpl = std::make_unique<DebuggerImpl>(ecmaVm, protocolChannel, runtimeImpl.get());
1983 std::unique_ptr<PtJson> json = PtJson::CreateObject();
1984 json->Add("enabled", false);
1985 json->Add("mixedStackEnabled", true);
1986 std::unique_ptr<SetMixedDebugParams> params = SetMixedDebugParams::Create(*json);
1987 debuggerImpl->SetMixedDebugEnabled(*params);
1988 debuggerImpl->NotifyNativeCalling(nullptr);
1989 auto debugger = std::make_unique<DebuggerImplFriendTest>(debuggerImpl);
1990 ASSERT_TRUE(debugger->GetMixStackEnabled());
1991 if (protocolChannel) {
1992 delete protocolChannel;
1993 protocolChannel = nullptr;
1994 }
1995 }
1996
HWTEST_F_L0(DebuggerImplTest,CheckAndGenerateCondFunc__001)1997 HWTEST_F_L0(DebuggerImplTest, CheckAndGenerateCondFunc__001)
1998 {
1999 std::string outStrForCallbackCheck = "";
2000 std::function<void(const void*, const std::string &)> callback =
2001 [&outStrForCallbackCheck]([[maybe_unused]] const void *ptr, const std::string &inStrOfReply) {
2002 outStrForCallbackCheck = inStrOfReply;};
2003 ProtocolChannel *protocolChannel = new ProtocolHandler(callback, ecmaVm);
2004 auto runtimeImpl = std::make_unique<RuntimeImpl>(ecmaVm, protocolChannel);
2005 auto debuggerImpl = std::make_unique<DebuggerImpl>(ecmaVm, protocolChannel, runtimeImpl.get());
2006 auto debugger = std::make_unique<DebuggerImplFriendTest>(debuggerImpl);
2007 std::vector<uint8_t> dest;
2008 debugger->CheckAndGenerateCondFunc("");
2009 ASSERT_TRUE(!debugger->DecodeAndCheckBase64("", dest));
2010 std::string msg = "UEFOREEAAAAAAAAADAACAEgBAAAAAAAAAAAAAAIAAAA8AAAAAQAA";
2011 msg += "AEQBAAAAAAARAAAAAEAAABEAAAAkQAAAMQAAAB8AAAASAEAAAIAAABsAAAAAgAAAHQAAAD//////////";
2012 debugger->CheckAndGenerateCondFunc(msg);
2013 ASSERT_TRUE(debugger->DecodeAndCheckBase64(msg, dest));
2014 }
2015
HWTEST_F_L0(DebuggerImplTest,ConvertToLocal__001)2016 HWTEST_F_L0(DebuggerImplTest, ConvertToLocal__001)
2017 {
2018 std::string outStrForCallbackCheck = "";
2019 std::function<void(const void*, const std::string &)> callback =
2020 [&outStrForCallbackCheck]([[maybe_unused]] const void *ptr, const std::string &inStrOfReply) {
2021 outStrForCallbackCheck = inStrOfReply;};
2022 ProtocolChannel *protocolChannel = new ProtocolHandler(callback, ecmaVm);
2023 auto runtimeImpl = std::make_unique<RuntimeImpl>(ecmaVm, protocolChannel);
2024 auto debuggerImpl = std::make_unique<DebuggerImpl>(ecmaVm, protocolChannel, runtimeImpl.get());
2025 auto debugger = std::make_unique<DebuggerImplFriendTest>(debuggerImpl);
2026 Local<JSValueRef> taggedValue = debugger->ConvertToLocal("");
2027 ASSERT_TRUE(!taggedValue.IsEmpty());
2028 taggedValue = debugger->ConvertToLocal("false");
2029 ASSERT_TRUE(!taggedValue.IsEmpty());
2030 taggedValue = debugger->ConvertToLocal("true");
2031 ASSERT_TRUE(!taggedValue.IsEmpty());
2032 taggedValue = debugger->ConvertToLocal("undefined");
2033 ASSERT_TRUE(!taggedValue.IsEmpty());
2034 taggedValue = debugger->ConvertToLocal("\"test\"");
2035 ASSERT_TRUE(!taggedValue.IsEmpty());
2036 taggedValue = debugger->ConvertToLocal("test");
2037 ASSERT_TRUE(taggedValue.IsEmpty());
2038 taggedValue = debugger->ConvertToLocal("1");
2039 ASSERT_TRUE(!taggedValue.IsEmpty());
2040 }
2041 } // namespace panda::test
2042