diff --git a/tooling/test/debugger_impl_test.cpp b/tooling/test/debugger_impl_test.cpp index 0fbb8811b5ee33985daac5e220e97c2c9c4305b3..04e7eb6862fcaec8bb509b6c84b85ad99cf8581d 100644 --- a/tooling/test/debugger_impl_test.cpp +++ b/tooling/test/debugger_impl_test.cpp @@ -1805,7 +1805,702 @@ HWTEST_F_L0(DebuggerImplTest, ConvertToLocal__001) ASSERT_TRUE(!taggedValue.IsEmpty()); taggedValue = debugger->ConvertToLocal("test"); ASSERT_TRUE(taggedValue.IsEmpty()); - taggedValue = debugger->ConvertToLocal("1"); + taggedValue = debugger->ConvertToLocal("1"); ASSERT_TRUE(!taggedValue.IsEmpty()); } + +HWTEST_F_L0(DebuggerImplTest, Dispatcher_Dispatch_Enable__002) +{ + std::string outStrForCallbackCheck = ""; + std::function callback = + [&outStrForCallbackCheck]([[maybe_unused]] const void *ptr, const std::string &inStrOfReply) { + outStrForCallbackCheck = inStrOfReply;}; + ProtocolChannel *protocolChannel = new ProtocolHandler(callback, ecmaVm); + auto runtimeImpl = std::make_unique(ecmaVm, protocolChannel); + auto debuggerImpl = std::make_unique(ecmaVm, protocolChannel, runtimeImpl.get()); + auto dispatcherImpl = std::make_unique(protocolChannel, std::move(debuggerImpl)); + EXPECT_FALSE(ecmaVm->GetJsDebuggerManager()->IsDebugMode()); + + std::string msg = std::string() + + R"({ + "id":0, + "method":"Debugger.enable", + "params":{ + "maxScriptsCacheSize":1024 + } + })"; + DispatchRequest request(msg); + dispatcherImpl->Dispatch(request); + + bool condition = outStrForCallbackCheck.find("protocols") != std::string::npos && + outStrForCallbackCheck.find("debuggerId") != std::string::npos; + EXPECT_TRUE(condition); + EXPECT_TRUE(ecmaVm->GetJsDebuggerManager()->IsDebugMode()); + if (protocolChannel) { + delete protocolChannel; + protocolChannel = nullptr; + } +} + +HWTEST_F_L0(DebuggerImplTest, Dispatcher_Dispatch_Disable__001) +{ + std::string outStrForCallbackCheck = ""; + std::function callback = + [&outStrForCallbackCheck]([[maybe_unused]] const void *ptr, const std::string &inStrOfReply) { + outStrForCallbackCheck = inStrOfReply;}; + ProtocolChannel *protocolChannel = new ProtocolHandler(callback, ecmaVm); + auto runtimeImpl = std::make_unique(ecmaVm, protocolChannel); + auto debuggerImpl = std::make_unique(ecmaVm, protocolChannel, runtimeImpl.get()); + auto dispatcherImpl = std::make_unique(protocolChannel, std::move(debuggerImpl)); + ecmaVm->GetJsDebuggerManager()->SetDebugMode(true); + + std::string msg = std::string() + + R"({ + "id":0, + "method":"Debugger.disable" + })"; + DispatchRequest request(msg); + + dispatcherImpl->Dispatch(request); + EXPECT_STREQ(outStrForCallbackCheck.c_str(), R"({"id":0,"result":{}})"); + EXPECT_FALSE(ecmaVm->GetJsDebuggerManager()->IsDebugMode()); + if (protocolChannel) { + delete protocolChannel; + protocolChannel = nullptr; + } +} + +HWTEST_F_L0(DebuggerImplTest, Dispatcher_Dispatch_EvaluateOnCallFrame__001) +{ + std::string outStrForCallbackCheck = ""; + std::function callback = + [&outStrForCallbackCheck]([[maybe_unused]] const void *ptr, const std::string &inStrOfReply) { + outStrForCallbackCheck = inStrOfReply;}; + ProtocolChannel *protocolChannel = new ProtocolHandler(callback, ecmaVm); + auto runtimeImpl = std::make_unique(ecmaVm, protocolChannel); + auto debuggerImpl = std::make_unique(ecmaVm, protocolChannel, runtimeImpl.get()); + auto dispatcherImpl = std::make_unique(protocolChannel, std::move(debuggerImpl)); + + // DebuggerImpl::DispatcherImpl::EvaluateOnCallFrame -- params == nullptr + std::string msg = std::string() + + R"({ + "id":0, + "method":"Debugger.evaluateOnCallFrame", + "params":{} + })"; + DispatchRequest request(msg); + + dispatcherImpl->Dispatch(request); + EXPECT_STREQ(outStrForCallbackCheck.c_str(), R"({"id":0,"result":{"code":1,"message":"wrong params"}})"); + if (protocolChannel) { + delete protocolChannel; + protocolChannel = nullptr; + } +} + +HWTEST_F_L0(DebuggerImplTest, Dispatcher_Dispatch_EvaluateOnCallFrame__002) +{ + std::string outStrForCallbackCheck = ""; + std::function callback = + [&outStrForCallbackCheck]([[maybe_unused]] const void *ptr, const std::string &inStrOfReply) { + outStrForCallbackCheck = inStrOfReply;}; + ProtocolChannel *protocolChannel = new ProtocolHandler(callback, ecmaVm); + auto runtimeImpl = std::make_unique(ecmaVm, protocolChannel); + auto debuggerImpl = std::make_unique(ecmaVm, protocolChannel, runtimeImpl.get()); + auto dispatcherImpl = std::make_unique(protocolChannel, std::move(debuggerImpl)); + + // DebuggerImpl::EvaluateOnCallFrame -- callFrameId < 0 + std::string msg = std::string() + + R"({ + "id":0, + "method":"Debugger.evaluateOnCallFrame", + "params":{ + "callFrameId":"-1", + "expression":"the expression" + } + })"; + DispatchRequest request(msg); + + dispatcherImpl->Dispatch(request); + EXPECT_STREQ(outStrForCallbackCheck.c_str(), R"({"id":0,"result":{"code":1,"message":"Invalid callFrameId."}})"); + if (protocolChannel) { + delete protocolChannel; + protocolChannel = nullptr; + } +} + +HWTEST_F_L0(DebuggerImplTest, Dispatcher_Dispatch_EvaluateOnCallFrame__003) +{ + std::string outStrForCallbackCheck = ""; + std::function callback = + [&outStrForCallbackCheck]([[maybe_unused]] const void *ptr, const std::string &inStrOfReply) { + outStrForCallbackCheck = inStrOfReply;}; + ProtocolChannel *protocolChannel = new ProtocolHandler(callback, ecmaVm); + auto runtimeImpl = std::make_unique(ecmaVm, protocolChannel); + auto debuggerImpl = std::make_unique(ecmaVm, protocolChannel, runtimeImpl.get()); + auto dispatcherImpl = std::make_unique(protocolChannel, std::move(debuggerImpl)); + + // DebuggerImpl::EvaluateOnCallFrame -- callFrameId >= static_cast(callFrameHandlers_.size()) + std::string msg = std::string() + + R"({ + "id":0, + "method":"Debugger.evaluateOnCallFrame", + "params":{ + "callFrameId":"0", + "expression":"the expression" + } + })"; + DispatchRequest request(msg); + + dispatcherImpl->Dispatch(request); + EXPECT_STREQ(outStrForCallbackCheck.c_str(), R"({"id":0,"result":{"code":1,"message":"Invalid callFrameId."}})"); + if (protocolChannel) { + delete protocolChannel; + protocolChannel = nullptr; + } +} + +HWTEST_F_L0(DebuggerImplTest, Dispatcher_Dispatch_GetPossibleBreakpoints__001) +{ + std::string outStrForCallbackCheck = ""; + std::function callback = + [&outStrForCallbackCheck]([[maybe_unused]] const void *ptr, const std::string &inStrOfReply) { + outStrForCallbackCheck = inStrOfReply;}; + ProtocolChannel *protocolChannel = new ProtocolHandler(callback, ecmaVm); + auto runtimeImpl = std::make_unique(ecmaVm, protocolChannel); + auto debuggerImpl = std::make_unique(ecmaVm, protocolChannel, runtimeImpl.get()); + auto dispatcherImpl = std::make_unique(protocolChannel, std::move(debuggerImpl)); + + // DebuggerImpl::DispatcherImpl::GetPossibleBreakpoints -- params == nullptr + std::string msg = std::string() + + R"({ + "id":0, + "method":"Debugger.getPossibleBreakpoints", + "params":{} + })"; + DispatchRequest request(msg); + + dispatcherImpl->Dispatch(request); + EXPECT_STREQ(outStrForCallbackCheck.c_str(), R"({"id":0,"result":{"code":1,"message":"wrong params"}})"); + if (protocolChannel) { + delete protocolChannel; + protocolChannel = nullptr; + } +} + +HWTEST_F_L0(DebuggerImplTest, Dispatcher_Dispatch_GetPossibleBreakpoints__002) +{ + std::string outStrForCallbackCheck = ""; + std::function callback = + [&outStrForCallbackCheck]([[maybe_unused]] const void *ptr, const std::string &inStrOfReply) { + outStrForCallbackCheck = inStrOfReply;}; + ProtocolChannel *protocolChannel = new ProtocolHandler(callback, ecmaVm); + auto runtimeImpl = std::make_unique(ecmaVm, protocolChannel); + auto debuggerImpl = std::make_unique(ecmaVm, protocolChannel, runtimeImpl.get()); + auto dispatcherImpl = std::make_unique(protocolChannel, std::move(debuggerImpl)); + + // DebuggerImpl::GetPossibleBreakpoints -- iter == scripts_.end() + std::string msg = std::string() + + R"({ + "id":0, + "method":"Debugger.getPossibleBreakpoints", + "params":{ + "start":{ + "scriptId":"0", + "lineNumber":1, + "columnNumber":0 + }, + "end":{ + "scriptId":"0", + "lineNumber":1, + "columnNumber":0 + }, + "restrictToFunction":true + } + })"; + DispatchRequest request(msg); + + dispatcherImpl->Dispatch(request); + EXPECT_STREQ(outStrForCallbackCheck.c_str(), R"({"id":0,"result":{"code":1,"message":"Unknown file name."}})"); + if (protocolChannel) { + delete protocolChannel; + protocolChannel = nullptr; + } +} + +HWTEST_F_L0(DebuggerImplTest, Dispatcher_Dispatch_GetScriptSource__001) +{ + std::string outStrForCallbackCheck = ""; + std::function callback = + [&outStrForCallbackCheck]([[maybe_unused]] const void *ptr, const std::string &inStrOfReply) { + outStrForCallbackCheck = inStrOfReply;}; + ProtocolChannel *protocolChannel = new ProtocolHandler(callback, ecmaVm); + auto runtimeImpl = std::make_unique(ecmaVm, protocolChannel); + auto debuggerImpl = std::make_unique(ecmaVm, protocolChannel, runtimeImpl.get()); + auto dispatcherImpl = std::make_unique(protocolChannel, std::move(debuggerImpl)); + + // DebuggerImpl::DispatcherImpl::GetScriptSource -- params == nullptr + std::string msg = std::string() + + R"({ + "id":0, + "method":"Debugger.getScriptSource", + "params":{} + })"; + DispatchRequest request(msg); + + dispatcherImpl->Dispatch(request); + EXPECT_STREQ(outStrForCallbackCheck.c_str(), R"({"id":0,"result":{"code":1,"message":"wrong params"}})"); + if (protocolChannel) { + delete protocolChannel; + protocolChannel = nullptr; + } +} + +HWTEST_F_L0(DebuggerImplTest, Dispatcher_Dispatch_GetScriptSource__002) +{ + std::string outStrForCallbackCheck = ""; + std::function callback = + [&outStrForCallbackCheck]([[maybe_unused]] const void *ptr, const std::string &inStrOfReply) { + outStrForCallbackCheck = inStrOfReply;}; + ProtocolChannel *protocolChannel = new ProtocolHandler(callback, ecmaVm); + auto runtimeImpl = std::make_unique(ecmaVm, protocolChannel); + auto debuggerImpl = std::make_unique(ecmaVm, protocolChannel, runtimeImpl.get()); + auto dispatcherImpl = std::make_unique(protocolChannel, std::move(debuggerImpl)); + + // DebuggerImpl::GetScriptSource -- iter == scripts_.end() + std::string msg = std::string() + + R"({ + "id":0, + "method":"Debugger.getScriptSource", + "params":{ + "scriptId":"0" + } + })"; + DispatchRequest request(msg); + + dispatcherImpl->Dispatch(request); + EXPECT_STREQ(outStrForCallbackCheck.c_str(), R"({"id":0,"result":{"code":1,"message":"unknown script id: 0"}})"); + if (protocolChannel) { + delete protocolChannel; + protocolChannel = nullptr; + } +} + +HWTEST_F_L0(DebuggerImplTest, Dispatcher_Dispatch_Pause__001) +{ + std::string outStrForCallbackCheck = ""; + std::function callback = + [&outStrForCallbackCheck]([[maybe_unused]] const void *ptr, const std::string &inStrOfReply) { + outStrForCallbackCheck = inStrOfReply;}; + ProtocolChannel *protocolChannel = new ProtocolHandler(callback, ecmaVm); + auto runtimeImpl = std::make_unique(ecmaVm, protocolChannel); + auto debuggerImpl = std::make_unique(ecmaVm, protocolChannel, runtimeImpl.get()); + auto dispatcherImpl = std::make_unique(protocolChannel, std::move(debuggerImpl)); + + // DDebuggerImpl::DispatcherImpl::GetScriptSource -- params == nullptr + std::string msg = std::string() + + R"({ + "id":0, + "method":"Debugger.pause" + })"; + DispatchRequest request(msg); + + dispatcherImpl->Dispatch(request); + EXPECT_STREQ(outStrForCallbackCheck.c_str(), R"({"id":0,"result":{}})"); + if (protocolChannel) { + delete protocolChannel; + protocolChannel = nullptr; + } +} + +HWTEST_F_L0(DebuggerImplTest, Dispatcher_Dispatch_RemoveBreakpoint__001) +{ + std::string outStrForCallbackCheck = ""; + std::function callback = + [&outStrForCallbackCheck]([[maybe_unused]] const void *ptr, const std::string &inStrOfReply) { + outStrForCallbackCheck = inStrOfReply;}; + ProtocolChannel *protocolChannel = new ProtocolHandler(callback, ecmaVm); + auto runtimeImpl = std::make_unique(ecmaVm, protocolChannel); + auto debuggerImpl = std::make_unique(ecmaVm, protocolChannel, runtimeImpl.get()); + auto dispatcherImpl = std::make_unique(protocolChannel, std::move(debuggerImpl)); + + // DDebuggerImpl::DispatcherImpl::RemoveBreakpoint -- params == nullptr + std::string msg = std::string() + + R"({ + "id":0, + "method":"Debugger.removeBreakpoint", + "params":{} + })"; + DispatchRequest request(msg); + + dispatcherImpl->Dispatch(request); + EXPECT_STREQ(outStrForCallbackCheck.c_str(), R"({"id":0,"result":{"code":1,"message":"wrong params"}})"); + if (protocolChannel) { + delete protocolChannel; + protocolChannel = nullptr; + } +} + +HWTEST_F_L0(DebuggerImplTest, Dispatcher_Dispatch_RemoveBreakpoint__002) +{ + std::string outStrForCallbackCheck = ""; + std::function callback = + [&outStrForCallbackCheck]([[maybe_unused]] const void *ptr, const std::string &inStrOfReply) { + outStrForCallbackCheck = inStrOfReply;}; + ProtocolChannel *protocolChannel = new ProtocolHandler(callback, ecmaVm); + auto runtimeImpl = std::make_unique(ecmaVm, protocolChannel); + auto debuggerImpl = std::make_unique(ecmaVm, protocolChannel, runtimeImpl.get()); + auto dispatcherImpl = std::make_unique(protocolChannel, std::move(debuggerImpl)); + + // DDebuggerImpl::RemoveBreakpoint -- !BreakpointDetails::ParseBreakpointId(id, &metaData) + std::string msg = std::string() + + R"({ + "id":0, + "method":"Debugger.removeBreakpoint", + "params":{ + "breakpointId":"id:0:0" + } + })"; + DispatchRequest request(msg); + + dispatcherImpl->Dispatch(request); + EXPECT_STREQ(outStrForCallbackCheck.c_str(), + R"({"id":0,"result":{"code":1,"message":"Parse breakpoint id failed"}})"); + if (protocolChannel) { + delete protocolChannel; + protocolChannel = nullptr; + } +} + +HWTEST_F_L0(DebuggerImplTest, Dispatcher_Dispatch_RemoveBreakpoint__003) +{ + std::string outStrForCallbackCheck = ""; + std::function callback = + [&outStrForCallbackCheck]([[maybe_unused]] const void *ptr, const std::string &inStrOfReply) { + outStrForCallbackCheck = inStrOfReply;}; + ProtocolChannel *protocolChannel = new ProtocolHandler(callback, ecmaVm); + auto runtimeImpl = std::make_unique(ecmaVm, protocolChannel); + auto debuggerImpl = std::make_unique(ecmaVm, protocolChannel, runtimeImpl.get()); + auto dispatcherImpl = std::make_unique(protocolChannel, std::move(debuggerImpl)); + + // DDebuggerImpl::RemoveBreakpoint -- !MatchScripts(scriptFunc, metaData.url_, ScriptMatchType::URL) + std::string msg = std::string() + + R"({ + "id":0, + "method":"Debugger.removeBreakpoint", + "params":{ + "breakpointId":"id:0:0:url" + } + })"; + DispatchRequest request(msg); + + dispatcherImpl->Dispatch(request); + EXPECT_STREQ(outStrForCallbackCheck.c_str(), + R"({"id":0,"result":{"code":1,"message":"Unknown file name."}})"); + if (protocolChannel) { + delete protocolChannel; + protocolChannel = nullptr; + } +} + +HWTEST_F_L0(DebuggerImplTest, Dispatcher_Dispatch_RemoveBreakpointsByUrl__001) +{ + std::string outStrForCallbackCheck = ""; + std::function callback = + [&outStrForCallbackCheck]([[maybe_unused]] const void *ptr, const std::string &inStrOfReply) { + outStrForCallbackCheck = inStrOfReply;}; + ProtocolChannel *protocolChannel = new ProtocolHandler(callback, ecmaVm); + auto runtimeImpl = std::make_unique(ecmaVm, protocolChannel); + auto debuggerImpl = std::make_unique(ecmaVm, protocolChannel, runtimeImpl.get()); + auto dispatcherImpl = std::make_unique(protocolChannel, std::move(debuggerImpl)); + + std::string msg = std::string() + + R"({ + "id":0, + "method":"Debugger.removeBreakpointsByUrl", + "params":{} + })"; + DispatchRequest request(msg); + + dispatcherImpl->Dispatch(request); + EXPECT_STREQ(outStrForCallbackCheck.c_str(), R"({"id":0,"result":{"code":1,"message":"wrong params"}})"); + if (protocolChannel) { + delete protocolChannel; + protocolChannel = nullptr; + } +} + +HWTEST_F_L0(DebuggerImplTest, Dispatcher_Dispatch_RemoveBreakpointsByUrl__002) +{ + std::string outStrForCallbackCheck = ""; + std::function callback = + [&outStrForCallbackCheck]([[maybe_unused]] const void *ptr, const std::string &inStrOfReply) { + outStrForCallbackCheck = inStrOfReply;}; + ProtocolChannel *protocolChannel = new ProtocolHandler(callback, ecmaVm); + auto runtimeImpl = std::make_unique(ecmaVm, protocolChannel); + auto debuggerImpl = std::make_unique(ecmaVm, protocolChannel, runtimeImpl.get()); + auto dispatcherImpl = std::make_unique(protocolChannel, std::move(debuggerImpl)); + + std::string msg = std::string() + + R"({ + "id":0, + "method":"Debugger.removeBreakpointsByUrl", + "params":{ + "url":"1" + } + })"; + DispatchRequest request(msg); + + dispatcherImpl->Dispatch(request); + EXPECT_STREQ(outStrForCallbackCheck.c_str(), R"({"id":0,"result":{"code":1,"message":"Unknown url"}})"); + if (protocolChannel) { + delete protocolChannel; + protocolChannel = nullptr; + } +} + +HWTEST_F_L0(DebuggerImplTest, Dispatcher_Dispatch_Resume__001) +{ + std::string outStrForCallbackCheck = ""; + std::function callback = + [&outStrForCallbackCheck]([[maybe_unused]] const void *ptr, const std::string &inStrOfReply) { + outStrForCallbackCheck = inStrOfReply;}; + ProtocolChannel *protocolChannel = new ProtocolHandler(callback, ecmaVm); + auto runtimeImpl = std::make_unique(ecmaVm, protocolChannel); + auto debuggerImpl = std::make_unique(ecmaVm, protocolChannel, runtimeImpl.get()); + debuggerImpl->SetDebuggerState(DebuggerState::PAUSED); + auto dispatcherImpl = std::make_unique(protocolChannel, std::move(debuggerImpl)); + + // DebuggerImpl::DispatcherImpl::Resume -- params == nullptr + std::string msg = std::string() + + R"({ + "id":0, + "method":"Debugger.resume", + "params":{ + "terminateOnResume":"NotBool" + } + })"; + DispatchRequest request(msg); + + dispatcherImpl->Dispatch(request); + EXPECT_STREQ(outStrForCallbackCheck.c_str(), R"({"id":0,"result":{"code":1,"message":"wrong params"}})"); + if (protocolChannel) { + delete protocolChannel; + protocolChannel = nullptr; + } +} + +HWTEST_F_L0(DebuggerImplTest, Dispatcher_Dispatch_Resume__002) +{ + std::string outStrForCallbackCheck = ""; + std::function callback = + [&outStrForCallbackCheck]([[maybe_unused]] const void *ptr, const std::string &inStrOfReply) { + outStrForCallbackCheck = inStrOfReply;}; + ProtocolChannel *protocolChannel = new ProtocolHandler(callback, ecmaVm); + auto runtimeImpl = std::make_unique(ecmaVm, protocolChannel); + auto debuggerImpl = std::make_unique(ecmaVm, protocolChannel, runtimeImpl.get()); + debuggerImpl->SetDebuggerState(DebuggerState::PAUSED); + auto dispatcherImpl = std::make_unique(protocolChannel, std::move(debuggerImpl)); + + std::string msg = std::string() + + R"({ + "id":0, + "method":"Debugger.resume", + "params":{ + "terminateOnResume":true + } + })"; + DispatchRequest request(msg); + + dispatcherImpl->Dispatch(request); + EXPECT_STREQ(outStrForCallbackCheck.c_str(), R"({"id":0,"result":{}})"); + if (protocolChannel) { + delete protocolChannel; + protocolChannel = nullptr; + } +} + +HWTEST_F_L0(DebuggerImplTest, Dispatcher_Dispatch_SetAsyncCallStackDepth__001) +{ + std::string outStrForCallbackCheck = ""; + std::function callback = + [&outStrForCallbackCheck]([[maybe_unused]] const void *ptr, const std::string &inStrOfReply) { + outStrForCallbackCheck = inStrOfReply;}; + ProtocolChannel *protocolChannel = new ProtocolHandler(callback, ecmaVm); + auto runtimeImpl = std::make_unique(ecmaVm, protocolChannel); + auto debuggerImpl = std::make_unique(ecmaVm, protocolChannel, runtimeImpl.get()); + auto dispatcherImpl = std::make_unique(protocolChannel, std::move(debuggerImpl)); + + std::string msg = std::string() + + R"({ + "id":0, + "method":"Debugger.setAsyncCallStackDepth" + })"; + DispatchRequest request(msg); + + dispatcherImpl->Dispatch(request); + EXPECT_STREQ(outStrForCallbackCheck.c_str(), + R"({"id":0,"result":{"code":1,"message":"SetAsyncCallStackDepth not support now"}})"); + if (protocolChannel) { + delete protocolChannel; + protocolChannel = nullptr; + } +} + +HWTEST_F_L0(DebuggerImplTest, Dispatcher_Dispatch_SetBreakpointByUrl__001) +{ + std::string outStrForCallbackCheck = ""; + std::function callback = + [&outStrForCallbackCheck]([[maybe_unused]] const void *ptr, const std::string &inStrOfReply) { + outStrForCallbackCheck = inStrOfReply;}; + ProtocolChannel *protocolChannel = new ProtocolHandler(callback, ecmaVm); + auto runtimeImpl = std::make_unique(ecmaVm, protocolChannel); + auto debuggerImpl = std::make_unique(ecmaVm, protocolChannel, runtimeImpl.get()); + auto dispatcherImpl = std::make_unique(protocolChannel, std::move(debuggerImpl)); + + // DebuggerImpl::DispatcherImpl::SetBreakpointByUrl -- params == nullptr + std::string msg = std::string() + + R"({ + "id":0, + "method":"Debugger.setBreakpointByUrl", + "params":{} + })"; + DispatchRequest request(msg); + + dispatcherImpl->Dispatch(request); + EXPECT_STREQ(outStrForCallbackCheck.c_str(), R"({"id":0,"result":{"code":1,"message":"wrong params"}})"); + if (protocolChannel) { + delete protocolChannel; + protocolChannel = nullptr; + } +} + +HWTEST_F_L0(DebuggerImplTest, Dispatcher_Dispatch_SetBreakpointByUrl__002) +{ + std::string outStrForCallbackCheck = ""; + std::function callback = + [&outStrForCallbackCheck]([[maybe_unused]] const void *ptr, const std::string &inStrOfReply) { + outStrForCallbackCheck = inStrOfReply;}; + ProtocolChannel *protocolChannel = new ProtocolHandler(callback, ecmaVm); + auto runtimeImpl = std::make_unique(ecmaVm, protocolChannel); + auto debuggerImpl = std::make_unique(ecmaVm, protocolChannel, runtimeImpl.get()); + auto dispatcherImpl = std::make_unique(protocolChannel, std::move(debuggerImpl)); + ecmaVm->GetJsDebuggerManager()->SetDebugMode(true); + + // DebuggerImpl::SetBreakpointByUrl -- extractor == nullptr + std::string msg = std::string() + + R"({ + "id":0, + "method":"Debugger.setBreakpointByUrl", + "params":{ + "lineNumber":0, + "url":"url_str", + "urlRegex":"urlRegex_str", + "scriptHash":"scriptHash_str", + "columnNumber":0, + "condition":"condition_str" + } + })"; + DispatchRequest request(msg); + + dispatcherImpl->Dispatch(request); + EXPECT_STREQ(outStrForCallbackCheck.c_str(), R"({"id":0,"result":{"code":1,"message":"Unknown file name."}})"); + if (protocolChannel) { + delete protocolChannel; + protocolChannel = nullptr; + } +} + +HWTEST_F_L0(DebuggerImplTest, Dispatcher_Dispatch_SetPauseOnExceptions__001) +{ + std::string outStrForCallbackCheck = ""; + std::function callback = + [&outStrForCallbackCheck]([[maybe_unused]] const void *ptr, const std::string &inStrOfReply) { + outStrForCallbackCheck = inStrOfReply;}; + ProtocolChannel *protocolChannel = new ProtocolHandler(callback, ecmaVm); + auto runtimeImpl = std::make_unique(ecmaVm, protocolChannel); + auto debuggerImpl = std::make_unique(ecmaVm, protocolChannel, runtimeImpl.get()); + auto dispatcherImpl = std::make_unique(protocolChannel, std::move(debuggerImpl)); + + // DebuggerImpl::DispatcherImpl::SetPauseOnExceptions -- params == nullptr + std::string msg = std::string() + + R"({ + "id":0, + "method":"Debugger.setPauseOnExceptions", + "params":{} + })"; + DispatchRequest request(msg); + + dispatcherImpl->Dispatch(request); + EXPECT_STREQ(outStrForCallbackCheck.c_str(), R"({"id":0,"result":{"code":1,"message":"wrong params"}})"); + if (protocolChannel) { + delete protocolChannel; + protocolChannel = nullptr; + } +} + +HWTEST_F_L0(DebuggerImplTest, Dispatcher_Dispatch_SetBreakpointByUrl__002) +{ + std::string outStrForCallbackCheck = ""; + std::function callback = + [&outStrForCallbackCheck]([[maybe_unused]] const void *ptr, const std::string &inStrOfReply) { + outStrForCallbackCheck = inStrOfReply;}; + ProtocolChannel *protocolChannel = new ProtocolHandler(callback, ecmaVm); + auto runtimeImpl = std::make_unique(ecmaVm, protocolChannel); + auto debuggerImpl = std::make_unique(ecmaVm, protocolChannel, runtimeImpl.get()); + auto dispatcherImpl = std::make_unique(protocolChannel, std::move(debuggerImpl)); + ecmaVm->GetJsDebuggerManager()->SetDebugMode(true); + + // DebuggerImpl::SetBreakpointByUrl -- extractor == nullptr + std::string msg = std::string() + + R"({ + "id":0, + "method":"Debugger.setBreakpointByUrl", + "params":{ + "lineNumber":0, + "url":"url_str", + "urlRegex":"urlRegex_str", + "scriptHash":"scriptHash_str", + "columnNumber":0, + "condition":"condition_str" + } + })"; + DispatchRequest request(msg); + + dispatcherImpl->Dispatch(request); + EXPECT_STREQ(outStrForCallbackCheck.c_str(), R"({"id":0,"result":{"code":1,"message":"Unknown file name."}})"); + if (protocolChannel) { + delete protocolChannel; + protocolChannel = nullptr; + } +} + +HWTEST_F_L0(DebuggerImplTest, Dispatcher_Dispatch_SetPauseOnExceptions__001) +{ + std::string outStrForCallbackCheck = ""; + std::function callback = + [&outStrForCallbackCheck]([[maybe_unused]] const void *ptr, const std::string &inStrOfReply) { + outStrForCallbackCheck = inStrOfReply;}; + ProtocolChannel *protocolChannel = new ProtocolHandler(callback, ecmaVm); + auto runtimeImpl = std::make_unique(ecmaVm, protocolChannel); + auto debuggerImpl = std::make_unique(ecmaVm, protocolChannel, runtimeImpl.get()); + auto dispatcherImpl = std::make_unique(protocolChannel, std::move(debuggerImpl)); + + // DebuggerImpl::DispatcherImpl::SetPauseOnExceptions -- params == nullptr + std::string msg = std::string() + + R"({ + "id":0, + "method":"Debugger.setPauseOnExceptions", + "params":{} + })"; + DispatchRequest request(msg); + + dispatcherImpl->Dispatch(request); + EXPECT_STREQ(outStrForCallbackCheck.c_str(), R"({"id":0,"result":{"code":1,"message":"wrong params"}})"); + if (protocolChannel) { + delete protocolChannel; + protocolChannel = nullptr; + } +} } // namespace panda::test +