OLD | NEW |
(Empty) | |
| 1 // Copyright 2017 the V8 project authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. |
| 4 |
| 5 InspectorTest.log('Tests how multiple sessions interact while pausing, stepping,
setting breakpoints and blackboxing.'); |
| 6 |
| 7 var contextGroup = new InspectorTest.ContextGroup(); |
| 8 |
| 9 contextGroup.addScript(` |
| 10 function foo() { |
| 11 return 1; |
| 12 } |
| 13 function baz() { |
| 14 return 2; |
| 15 } |
| 16 function stepping() { |
| 17 debugger; |
| 18 var a = 1; |
| 19 var b = 1; |
| 20 } |
| 21 //# sourceURL=test.js`, 9, 25); |
| 22 |
| 23 contextGroup.addScript(` |
| 24 function bar() { |
| 25 debugger; |
| 26 } |
| 27 //# sourceURL=test2.js`, 23, 25); |
| 28 |
| 29 (async function test() { |
| 30 var session1 = contextGroup.connect(); |
| 31 await session1.Protocol.Debugger.enable(); |
| 32 var session2 = contextGroup.connect(); |
| 33 await session2.Protocol.Debugger.enable(); |
| 34 |
| 35 InspectorTest.log('Setting breakpoints in 1'); |
| 36 await session1.Protocol.Debugger.setBreakpointByUrl({url: 'test.js', lineNumbe
r: 11}); |
| 37 await session1.Protocol.Debugger.setBreakpointByUrl({url: 'test.js', lineNumbe
r: 14}); |
| 38 InspectorTest.log('Setting breakpoints in 2'); |
| 39 await session2.Protocol.Debugger.setBreakpointByUrl({url: 'test.js', lineNumbe
r: 11}); |
| 40 |
| 41 InspectorTest.log('Evaluating common breakpoint in 1'); |
| 42 session1.Protocol.Runtime.evaluate({expression: 'foo();'}); |
| 43 await waitForBothPaused(); |
| 44 InspectorTest.log('Resuming in 1'); |
| 45 session1.Protocol.Debugger.resume(); |
| 46 await waitForBothResumed(); |
| 47 |
| 48 InspectorTest.log('Evaluating debugger in 1'); |
| 49 session1.Protocol.Runtime.evaluate({expression: 'bar();'}); |
| 50 await waitForBothPaused(); |
| 51 InspectorTest.log('Resuming in 2'); |
| 52 session2.Protocol.Debugger.resume(); |
| 53 await waitForBothResumed(); |
| 54 |
| 55 InspectorTest.log('Evaluating exclusive breakpoint in 1'); |
| 56 session1.Protocol.Runtime.evaluate({expression: 'baz();'}); |
| 57 await waitForBothPaused(); |
| 58 InspectorTest.log('Resuming in 1'); |
| 59 session1.Protocol.Debugger.resume(); |
| 60 await waitForBothResumed(); |
| 61 |
| 62 InspectorTest.log('Evaluating common breakpoint in 2'); |
| 63 session2.Protocol.Runtime.evaluate({expression: 'foo();'}); |
| 64 await waitForBothPaused(); |
| 65 InspectorTest.log('Resuming in 2'); |
| 66 session2.Protocol.Debugger.resume(); |
| 67 await waitForBothResumed(); |
| 68 |
| 69 InspectorTest.log('Evaluating debugger in 2'); |
| 70 session2.Protocol.Runtime.evaluate({expression: 'bar();'}); |
| 71 await waitForBothPaused(); |
| 72 InspectorTest.log('Resuming in 2'); |
| 73 session2.Protocol.Debugger.resume(); |
| 74 await waitForBothResumed(); |
| 75 |
| 76 InspectorTest.log('Evaluating exclusive breakpoint in 2'); |
| 77 session2.Protocol.Runtime.evaluate({expression: 'baz();'}); |
| 78 await waitForBothPaused(); |
| 79 InspectorTest.log('Resuming in 1'); |
| 80 session1.Protocol.Debugger.resume(); |
| 81 await waitForBothResumed(); |
| 82 |
| 83 InspectorTest.log('Evaluating stepping in 1'); |
| 84 session1.Protocol.Runtime.evaluate({expression: 'stepping();'}); |
| 85 await waitForBothPaused(); |
| 86 InspectorTest.log('Stepping into in 2'); |
| 87 session2.Protocol.Debugger.stepInto(); |
| 88 await waitForBothResumed(); |
| 89 await waitForBothPaused(); |
| 90 InspectorTest.log('Stepping over in 1'); |
| 91 session1.Protocol.Debugger.stepOver(); |
| 92 await waitForBothResumed(); |
| 93 await waitForBothPaused(); |
| 94 InspectorTest.log('Stepping out in 2'); |
| 95 session2.Protocol.Debugger.stepOut(); |
| 96 await waitForBothResumed(); |
| 97 await waitForBothPaused(); |
| 98 InspectorTest.log('Resuming in 1'); |
| 99 session1.Protocol.Debugger.resume(); |
| 100 await waitForBothResumed(); |
| 101 |
| 102 InspectorTest.log('Pausing in next statement'); |
| 103 contextGroup.schedulePauseOnNextStatement('some-reason', JSON.stringify({a: 42
})); |
| 104 session2.Protocol.Runtime.evaluate({expression: 'var a = 1;'}); |
| 105 await waitForBothPaused(); |
| 106 InspectorTest.log('Resuming in 1'); |
| 107 session1.Protocol.Debugger.resume(); |
| 108 await waitForBothResumed(); |
| 109 |
| 110 InspectorTest.log('Pausing in next statement'); |
| 111 contextGroup.schedulePauseOnNextStatement('some-reason', JSON.stringify({a: 42
})); |
| 112 session2.Protocol.Runtime.evaluate({expression: 'var a = 1;'}); |
| 113 await waitForBothPaused(); |
| 114 InspectorTest.log('Resuming in 2'); |
| 115 session2.Protocol.Debugger.resume(); |
| 116 await waitForBothResumed(); |
| 117 |
| 118 InspectorTest.log('Blackboxing bar() in 2'); |
| 119 await session2.Protocol.Debugger.setBlackboxPatterns({patterns: ['test2.js']})
; |
| 120 InspectorTest.log('Evaluating bar() in 2'); |
| 121 session2.Protocol.Runtime.evaluate({expression: 'bar();'}); |
| 122 await waitForPaused(session1, 1); |
| 123 InspectorTest.log('Resuming in 1'); |
| 124 session1.Protocol.Debugger.resume(); |
| 125 await waitForResumed(session1, 1); |
| 126 |
| 127 InspectorTest.log('Blackboxing bar() in 1'); |
| 128 await session1.Protocol.Debugger.setBlackboxPatterns({patterns: ['test2.js']})
; |
| 129 InspectorTest.log('Evaluating bar() in 2'); |
| 130 await session2.Protocol.Runtime.evaluate({expression: 'bar();'}); |
| 131 |
| 132 InspectorTest.log('Skipping pauses in 1'); |
| 133 await session1.Protocol.Debugger.setSkipAllPauses({skip: true}); |
| 134 InspectorTest.log('Evaluating common breakpoint in 1'); |
| 135 session1.Protocol.Runtime.evaluate({expression: 'foo();'}); |
| 136 await waitForPaused(session2, 2); |
| 137 InspectorTest.log('Resuming in 2'); |
| 138 session2.Protocol.Debugger.resume(); |
| 139 await waitForResumed(session2, 2); |
| 140 |
| 141 InspectorTest.log('Skipping pauses in 2'); |
| 142 await session2.Protocol.Debugger.setSkipAllPauses({skip: true}); |
| 143 InspectorTest.log('Evaluating common breakpoint in 1'); |
| 144 await session1.Protocol.Runtime.evaluate({expression: 'foo();'}); |
| 145 |
| 146 InspectorTest.completeTest(); |
| 147 |
| 148 function waitForBothPaused() { |
| 149 return Promise.all([waitForPaused(session1, 1), waitForPaused(session2, 2)])
; |
| 150 } |
| 151 |
| 152 function waitForBothResumed() { |
| 153 return Promise.all([waitForResumed(session1, 1), waitForResumed(session2, 2)
]); |
| 154 } |
| 155 })(); |
| 156 |
| 157 function waitForPaused(session, num) { |
| 158 return session.Protocol.Debugger.oncePaused().then(message => { |
| 159 InspectorTest.log(`Paused in ${num}:`); |
| 160 InspectorTest.log(` reason: ${message.params.reason}`); |
| 161 InspectorTest.log(` hit breakpoints: ${(message.params.hitBreakpoints || []
).join(';')}`); |
| 162 var callFrame = message.params.callFrames[0]; |
| 163 InspectorTest.log(` location: ${callFrame.functionName || '<anonymous>'}@${
callFrame.location.lineNumber}`); |
| 164 InspectorTest.log(` data: ${JSON.stringify(message.params.data || null)}`); |
| 165 }); |
| 166 } |
| 167 |
| 168 function waitForResumed(session, num) { |
| 169 return session.Protocol.Debugger.onceResumed().then(message => { |
| 170 InspectorTest.log(`Resumed in ${num}`); |
| 171 }); |
| 172 } |
OLD | NEW |