Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

3. Add the test framework for CDP #499

Merged
merged 11 commits into from
Mar 15, 2022
8 changes: 5 additions & 3 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -249,16 +249,18 @@ Passes if `text` is not included in the last debugger log.

Passes if `text` is included in the debuggee log.

### Tests for DAP
### Tests for DAP and CDP

Currently, there are 2 kinds of test frameworks for DAP.
Currently, there are 2 kinds of test frameworks for DAP and CDP.

1. Protocol-based tests

If you want to write protocol-based tests, you should use the test generator.
After running `$ bin/gentest target.rb --open=vscode` in the terminal, VSCode will be executed.
To run the test generator, you can enter `$ bin/gentest target.rb --open=vscode` in the terminal, VSCode will be executed.
Also, if you enter ``$ bin/gentest target.rb --open=chrome` there, Chrome will be executed.
If you need to modify existing tests, it is basically a good idea to regenerate them by the test generator instead of rewriting them directly.
Please refer to [the Microsoft "Debug Adapter Protocol" article](https://microsoft.github.io/debug-adapter-protocol/specification) to learn more about DAP formats.
Please refer to [Procol viewer for "Chrome DevTools Protocol"](https://chromedevtools.github.io/devtools-protocol/) to learn more about CDP formats.

2. High-level tests

Expand Down
14 changes: 10 additions & 4 deletions bin/gentest
Original file line number Diff line number Diff line change
Expand Up @@ -14,17 +14,23 @@ OptionParser.new do |opt|
opt.on('-c CLASS', 'Class name in the test file') do |c|
options[:class] = c
end
opt.on('-f FILENAME', 'File name of the test file') do |name|
options[:file_name] = name
end
opt.on('--open=FRONTEND', 'Start remote debugging with opening the network port.',
'Currently, only vscode is supported.') do |f|
'Prepare for the given FRONTEND.') do |f|
options[:open] = f.downcase
end
opt.parse!(ARGV)
end

exit if ARGV.empty?

if options[:open] == 'vscode'
DEBUGGER__::DAPTestBuilder.new(ARGV, options[:method], options[:class]).start
case options[:open]
when 'vscode'
DEBUGGER__::DAPTestBuilder.new(ARGV, options[:method], options[:class], options[:file_name]).start
when 'chrome'
DEBUGGER__::CDPTestBuilder.new(ARGV, options[:method], options[:class], options[:file_name]).start
else
DEBUGGER__::LocalTestBuilder.new(ARGV, options[:method], options[:class]).start
DEBUGGER__::LocalTestBuilder.new(ARGV, options[:method], options[:class], options[:file_name]).start
end
29 changes: 16 additions & 13 deletions lib/debug/server_cdp.rb
Original file line number Diff line number Diff line change
Expand Up @@ -358,21 +358,21 @@ def process
exit
when 'Page.startScreencast', 'Emulation.setTouchEmulationEnabled', 'Emulation.setEmitTouchEventsForMouse',
'Runtime.compileScript', 'Page.getResourceContent', 'Overlay.setPausedInDebuggerMessage',
'Runtime.releaseObjectGroup', 'Runtime.discardConsoleEntries', 'Log.clear'
'Runtime.releaseObjectGroup', 'Runtime.discardConsoleEntries', 'Log.clear', 'Runtime.runIfWaitingForDebugger'
send_response req

## control
when 'Debugger.resume'
@q_msg << 'c'
@q_msg << req
send_response req
send_event 'Debugger.resumed'
@q_msg << 'c'
@q_msg << req
when 'Debugger.stepOver'
begin
@session.check_postmortem
@q_msg << 'n'
send_response req
send_event 'Debugger.resumed'
@q_msg << 'n'
rescue PostmortemError
send_fail_response req,
code: INVALID_REQUEST,
Expand All @@ -383,9 +383,9 @@ def process
when 'Debugger.stepInto'
begin
@session.check_postmortem
@q_msg << 's'
send_response req
send_event 'Debugger.resumed'
@q_msg << 's'
rescue PostmortemError
send_fail_response req,
code: INVALID_REQUEST,
Expand All @@ -396,9 +396,9 @@ def process
when 'Debugger.stepOut'
begin
@session.check_postmortem
@q_msg << 'fin'
send_response req
send_event 'Debugger.resumed'
@q_msg << 'fin'
rescue PostmortemError
send_fail_response req,
code: INVALID_REQUEST,
Expand Down Expand Up @@ -576,9 +576,10 @@ def process_protocol_request req
@tc << [:cdp, :backtrace, req]
when 'Debugger.evaluateOnCallFrame'
frame_id = req.dig('params', 'callFrameId')
group = req.dig('params', 'objectGroup')
if fid = @frame_map[frame_id]
expr = req.dig('params', 'expression')
@tc << [:cdp, :evaluate, req, fid, expr]
@tc << [:cdp, :evaluate, req, fid, expr, group]
else
fail_response req,
code: INVALID_PARAMS,
Expand All @@ -596,7 +597,7 @@ def process_protocol_request req
@tc << [:cdp, :properties, req, oid]
when 'script', 'global'
# TODO: Support script and global types
@ui.respond req
@ui.respond req, result: []
return :retry
else
raise "Unknown type: #{ref.inspect}"
Expand Down Expand Up @@ -685,7 +686,7 @@ def cdp_event args
endLine: lineno,
endColumn: 0,
executionContextId: 1,
hash: src.hash
hash: src.hash.inspect

frame[:scopeChain].each {|s|
oid = s.dig(:object, :objectId)
Expand Down Expand Up @@ -716,7 +717,7 @@ def cdp_event args
endLine: lineno,
endColumn: 0,
executionContextId: 1,
hash: src.hash
hash: src.hash.inspect
if exc = result.dig(:response, :exceptionDetails)
exc[:stackTrace][:callFrames].each{|frame|
if frame[:url].empty?
Expand Down Expand Up @@ -841,7 +842,7 @@ def process_cdp args
event! :cdp_result, :backtrace, req, result
when :evaluate
res = {}
fid, expr = args
fid, expr, group = args
frame = @target_frames[fid]
message = nil

Expand All @@ -853,7 +854,7 @@ def process_cdp args

result = nil

case req.dig('params', 'objectGroup')
case group
when 'popover'
case expr
# Chrome doesn't read instance variables
Expand Down Expand Up @@ -882,7 +883,7 @@ def process_cdp args
end
end
end
else
when 'console', 'watch-group'
begin
orig_stdout = $stdout
$stdout = StringIO.new
Expand Down Expand Up @@ -922,6 +923,8 @@ def process_cdp args
output = $stdout.string
$stdout = orig_stdout
end
else
message = "Error: unknown objectGroup: #{group}"
end
else
result = Exception.new("Error: Can not evaluate on this frame")
Expand Down
Loading