|
6 | 6 | using System.Threading.Tasks;
|
7 | 7 | using Microsoft.WebAssembly.Diagnostics;
|
8 | 8 | using Newtonsoft.Json.Linq;
|
| 9 | +using System.Threading; |
9 | 10 | using Xunit;
|
10 | 11 |
|
11 | 12 | namespace DebuggerTests
|
@@ -191,6 +192,110 @@ await CheckValue(pause_location["data"], JObject.FromObject(new
|
191 | 192 | CheckString(exception_members, "message", exception_message);
|
192 | 193 | }
|
193 | 194 |
|
| 195 | + [Fact] |
| 196 | + public async Task ExceptionTestUncaughtWithReload() |
| 197 | + { |
| 198 | + string entry_method_name = "[debugger-test] DebuggerTests.ExceptionTestsClass:TestExceptions"; |
| 199 | + var debugger_test_loc = "dotnet://debugger-test.dll/debugger-exception-test.cs"; |
| 200 | + |
| 201 | + await SetPauseOnException("uncaught"); |
| 202 | + |
| 203 | + await SendCommand("Page.enable", null); |
| 204 | + await SendCommand("Page.reload", JObject.FromObject(new |
| 205 | + { |
| 206 | + ignoreCache = true |
| 207 | + })); |
| 208 | + Thread.Sleep(1000); |
| 209 | + |
| 210 | + var eval_expr = "window.setTimeout(function() { invoke_static_method (" + |
| 211 | + $"'{entry_method_name}'" + |
| 212 | + "); }, 1);"; |
| 213 | + |
| 214 | + var pause_location = await EvaluateAndCheck(eval_expr, null, 0, 0, null); |
| 215 | + //stop in the managed caught exception |
| 216 | + pause_location = await WaitForManagedException(pause_location); |
| 217 | + |
| 218 | + AssertEqual("run", pause_location["callFrames"]?[0]?["functionName"]?.Value<string>(), "pause1"); |
| 219 | + |
| 220 | + //stop in the uncaught exception |
| 221 | + CheckLocation(debugger_test_loc, 28, 16, scripts, pause_location["callFrames"][0]["location"]); |
| 222 | + |
| 223 | + await CheckValue(pause_location["data"], JObject.FromObject(new |
| 224 | + { |
| 225 | + type = "object", |
| 226 | + subtype = "error", |
| 227 | + className = "DebuggerTests.CustomException", |
| 228 | + uncaught = true |
| 229 | + }), "exception1.data"); |
| 230 | + |
| 231 | + var exception_members = await GetProperties(pause_location["data"]["objectId"]?.Value<string>()); |
| 232 | + CheckString(exception_members, "message", "not implemented uncaught"); |
| 233 | + } |
| 234 | + |
| 235 | + [Fact] |
| 236 | + public async Task ExceptionTestAllWithReload() |
| 237 | + { |
| 238 | + string entry_method_name = "[debugger-test] DebuggerTests.ExceptionTestsClass:TestExceptions"; |
| 239 | + var debugger_test_loc = "dotnet://debugger-test.dll/debugger-exception-test.cs"; |
| 240 | + |
| 241 | + await SetPauseOnException("all"); |
| 242 | + |
| 243 | + await SendCommand("Page.enable", null); |
| 244 | + var pause_location = await SendCommandAndCheck(JObject.FromObject(new |
| 245 | + { |
| 246 | + ignoreCache = true |
| 247 | + }), "Page.reload",null, 0, 0, null); |
| 248 | + Thread.Sleep(1000); |
| 249 | + |
| 250 | + //send a lot of resumes to "skip" all the pauses on caught exception and completely reload the page |
| 251 | + int i = 0; |
| 252 | + while (i < 100) |
| 253 | + { |
| 254 | + Result res = await cli.SendCommand("Debugger.resume", null, token); |
| 255 | + i++; |
| 256 | + } |
| 257 | + |
| 258 | + |
| 259 | + var eval_expr = "window.setTimeout(function() { invoke_static_method (" + |
| 260 | + $"'{entry_method_name}'" + |
| 261 | + "); }, 1);"; |
| 262 | + |
| 263 | + pause_location = await EvaluateAndCheck(eval_expr, null, 0, 0, null); |
| 264 | + //stop in the managed caught exception |
| 265 | + pause_location = await WaitForManagedException(pause_location); |
| 266 | + |
| 267 | + AssertEqual("run", pause_location["callFrames"]?[0]?["functionName"]?.Value<string>(), "pause0"); |
| 268 | + |
| 269 | + await CheckValue(pause_location["data"], JObject.FromObject(new |
| 270 | + { |
| 271 | + type = "object", |
| 272 | + subtype = "error", |
| 273 | + className = "DebuggerTests.CustomException", |
| 274 | + uncaught = false |
| 275 | + }), "exception0.data"); |
| 276 | + |
| 277 | + var exception_members = await GetProperties(pause_location["data"]["objectId"]?.Value<string>()); |
| 278 | + CheckString(exception_members, "message", "not implemented caught"); |
| 279 | + |
| 280 | + pause_location = await WaitForManagedException(null); |
| 281 | + AssertEqual("run", pause_location["callFrames"]?[0]?["functionName"]?.Value<string>(), "pause1"); |
| 282 | + |
| 283 | + //stop in the uncaught exception |
| 284 | + CheckLocation(debugger_test_loc, 28, 16, scripts, pause_location["callFrames"][0]["location"]); |
| 285 | + |
| 286 | + await CheckValue(pause_location["data"], JObject.FromObject(new |
| 287 | + { |
| 288 | + type = "object", |
| 289 | + subtype = "error", |
| 290 | + className = "DebuggerTests.CustomException", |
| 291 | + uncaught = true |
| 292 | + }), "exception1.data"); |
| 293 | + |
| 294 | + exception_members = await GetProperties(pause_location["data"]["objectId"]?.Value<string>()); |
| 295 | + CheckString(exception_members, "message", "not implemented uncaught"); |
| 296 | + } |
| 297 | + |
| 298 | + |
194 | 299 | async Task<JObject> WaitForManagedException(JObject pause_location)
|
195 | 300 | {
|
196 | 301 | while (true)
|
|
0 commit comments