[wasm][debugger][tests] Allow overriding which browser to use (#19769)
[mono-project.git] / sdks / wasm / ProxyDriver / Program.cs
blobfaaa4960c586d1bb94f27aac544f0acacb858e40
1 using System;
2 using System.IO;
3 using System.Threading;
4 using System.Threading.Tasks;
5 using Microsoft.AspNetCore;
6 using Microsoft.AspNetCore.Hosting;
7 using Microsoft.Extensions.Configuration;
8 using Microsoft.AspNetCore.Builder;
9 using Microsoft.Extensions.DependencyInjection;
11 namespace WebAssembly.Net.Debugging
13 public class ProxyOptions {
14 public Uri DevToolsUrl { get; set; } = new Uri ("http://localhost:9222");
17 public class TestHarnessOptions : ProxyOptions {
18 public string ChromePath { get; set; }
19 public string AppPath { get; set; }
20 public string PagePath { get; set; }
21 public string NodeApp { get; set; }
24 public class Program {
25 public static void Main(string[] args)
27 var host = new WebHostBuilder()
28 .UseSetting ("UseIISIntegration", false.ToString ())
29 .UseKestrel ()
30 .UseContentRoot (Directory.GetCurrentDirectory())
31 .UseStartup<Startup> ()
32 .ConfigureAppConfiguration ((hostingContext, config) =>
34 config.AddCommandLine(args);
36 .UseUrls ("http://localhost:9300")
37 .Build ();
39 host.Run ();
43 public class TestHarnessProxy {
44 static IWebHost host;
45 static Task hostTask;
46 static CancellationTokenSource cts = new CancellationTokenSource ();
47 static object proxyLock = new object ();
49 public static readonly Uri Endpoint = new Uri ("http://localhost:9400");
51 public static Task Start (string chromePath, string appPath, string pagePath)
53 lock (proxyLock) {
54 if (host != null)
55 return hostTask;
57 host = WebHost.CreateDefaultBuilder ()
58 .UseSetting ("UseIISIntegration", false.ToString ())
59 .ConfigureAppConfiguration ((hostingContext, config) => {
60 config.AddEnvironmentVariables (prefix: "WASM_TESTS_");
62 .ConfigureServices ((ctx, services) => {
63 services.Configure<TestHarnessOptions> (ctx.Configuration);
64 services.Configure<TestHarnessOptions> (options => {
65 options.ChromePath = options.ChromePath ?? chromePath;
66 options.AppPath = appPath;
67 options.PagePath = pagePath;
68 options.DevToolsUrl = new Uri ("http://localhost:0");
69 });
71 .UseStartup<TestHarnessStartup> ()
72 .UseUrls (Endpoint.ToString ())
73 .Build();
74 hostTask = host.StartAsync (cts.Token);
77 Console.WriteLine ("WebServer Ready!");
78 return hostTask;