Skip to content

Commit 7211288

Browse files
E2E test apps for WinForms and WPF BlazorWebView (#31021)
1 parent e640e79 commit 7211288

File tree

16 files changed

+426
-2
lines changed

16 files changed

+426
-2
lines changed

AspNetCore.sln

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1618,6 +1618,14 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "BlazorWinFormsApp", "src\Co
16181618
EndProject
16191619
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Microsoft.AspNetCore.Http.Abstractions.Microbenchmarks", "src\Http\Http.Abstractions\perf\Microbenchmarks\Microsoft.AspNetCore.Http.Abstractions.Microbenchmarks.csproj", "{3F752B48-2936-4FCA-B0DC-4AB0F788F897}"
16201620
EndProject
1621+
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "testassets", "testassets", "{F0849E7E-61DB-4849-9368-9E7BC125DCB0}"
1622+
EndProject
1623+
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "WinFormsTestApp", "src\Components\WebView\Platforms\WindowsForms\testassets\WinFormsTestApp\WinFormsTestApp.csproj", "{99EE7769-3C81-477B-B947-0A5CBCD5B27D}"
1624+
EndProject
1625+
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "testassets", "testassets", "{94D0D6F3-8632-41DE-908B-47A787D570FF}"
1626+
EndProject
1627+
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "WpfTestApp", "src\Components\WebView\Platforms\Wpf\testassets\WpfTestApp\WpfTestApp.csproj", "{036C6BDA-7B69-4E8C-A921-822DA5972A56}"
1628+
EndProject
16211629
Global
16221630
GlobalSection(SolutionConfigurationPlatforms) = preSolution
16231631
Debug|Any CPU = Debug|Any CPU
@@ -7653,6 +7661,30 @@ Global
76537661
{3F752B48-2936-4FCA-B0DC-4AB0F788F897}.Release|x64.Build.0 = Release|Any CPU
76547662
{3F752B48-2936-4FCA-B0DC-4AB0F788F897}.Release|x86.ActiveCfg = Release|Any CPU
76557663
{3F752B48-2936-4FCA-B0DC-4AB0F788F897}.Release|x86.Build.0 = Release|Any CPU
7664+
{99EE7769-3C81-477B-B947-0A5CBCD5B27D}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
7665+
{99EE7769-3C81-477B-B947-0A5CBCD5B27D}.Debug|Any CPU.Build.0 = Debug|Any CPU
7666+
{99EE7769-3C81-477B-B947-0A5CBCD5B27D}.Debug|x64.ActiveCfg = Debug|Any CPU
7667+
{99EE7769-3C81-477B-B947-0A5CBCD5B27D}.Debug|x64.Build.0 = Debug|Any CPU
7668+
{99EE7769-3C81-477B-B947-0A5CBCD5B27D}.Debug|x86.ActiveCfg = Debug|Any CPU
7669+
{99EE7769-3C81-477B-B947-0A5CBCD5B27D}.Debug|x86.Build.0 = Debug|Any CPU
7670+
{99EE7769-3C81-477B-B947-0A5CBCD5B27D}.Release|Any CPU.ActiveCfg = Release|Any CPU
7671+
{99EE7769-3C81-477B-B947-0A5CBCD5B27D}.Release|Any CPU.Build.0 = Release|Any CPU
7672+
{99EE7769-3C81-477B-B947-0A5CBCD5B27D}.Release|x64.ActiveCfg = Release|Any CPU
7673+
{99EE7769-3C81-477B-B947-0A5CBCD5B27D}.Release|x64.Build.0 = Release|Any CPU
7674+
{99EE7769-3C81-477B-B947-0A5CBCD5B27D}.Release|x86.ActiveCfg = Release|Any CPU
7675+
{99EE7769-3C81-477B-B947-0A5CBCD5B27D}.Release|x86.Build.0 = Release|Any CPU
7676+
{036C6BDA-7B69-4E8C-A921-822DA5972A56}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
7677+
{036C6BDA-7B69-4E8C-A921-822DA5972A56}.Debug|Any CPU.Build.0 = Debug|Any CPU
7678+
{036C6BDA-7B69-4E8C-A921-822DA5972A56}.Debug|x64.ActiveCfg = Debug|Any CPU
7679+
{036C6BDA-7B69-4E8C-A921-822DA5972A56}.Debug|x64.Build.0 = Debug|Any CPU
7680+
{036C6BDA-7B69-4E8C-A921-822DA5972A56}.Debug|x86.ActiveCfg = Debug|Any CPU
7681+
{036C6BDA-7B69-4E8C-A921-822DA5972A56}.Debug|x86.Build.0 = Debug|Any CPU
7682+
{036C6BDA-7B69-4E8C-A921-822DA5972A56}.Release|Any CPU.ActiveCfg = Release|Any CPU
7683+
{036C6BDA-7B69-4E8C-A921-822DA5972A56}.Release|Any CPU.Build.0 = Release|Any CPU
7684+
{036C6BDA-7B69-4E8C-A921-822DA5972A56}.Release|x64.ActiveCfg = Release|Any CPU
7685+
{036C6BDA-7B69-4E8C-A921-822DA5972A56}.Release|x64.Build.0 = Release|Any CPU
7686+
{036C6BDA-7B69-4E8C-A921-822DA5972A56}.Release|x86.ActiveCfg = Release|Any CPU
7687+
{036C6BDA-7B69-4E8C-A921-822DA5972A56}.Release|x86.Build.0 = Release|Any CPU
76567688
EndGlobalSection
76577689
GlobalSection(SolutionProperties) = preSolution
76587690
HideSolutionNode = FALSE
@@ -8452,6 +8484,10 @@ Global
84528484
{3BA297F8-1CA1-492D-AE64-A60B825D8501} = {D4E9A2C5-0838-42DF-BC80-C829C4C9137E}
84538485
{CC740832-D268-47A3-9058-B9054F8397E2} = {D3B76F4E-A980-45BF-AEA1-EA3175B0B5A1}
84548486
{3F752B48-2936-4FCA-B0DC-4AB0F788F897} = {DCBBDB52-4A49-4141-8F4D-81C0FFFB7BD5}
8487+
{F0849E7E-61DB-4849-9368-9E7BC125DCB0} = {D4E9A2C5-0838-42DF-BC80-C829C4C9137E}
8488+
{99EE7769-3C81-477B-B947-0A5CBCD5B27D} = {F0849E7E-61DB-4849-9368-9E7BC125DCB0}
8489+
{94D0D6F3-8632-41DE-908B-47A787D570FF} = {5241CF68-66A0-4724-9BAA-36DB959A5B11}
8490+
{036C6BDA-7B69-4E8C-A921-822DA5972A56} = {94D0D6F3-8632-41DE-908B-47A787D570FF}
84558491
EndGlobalSection
84568492
GlobalSection(ExtensibilityGlobals) = postSolution
84578493
SolutionGuid = {3E8720B3-DBDD-498C-B383-2CC32A054E8F}

src/Components/ComponentsNoDeps.slnf

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,9 @@
3939
"src\\Components\\WebAssembly\\testassets\\WasmLinkerTest\\WasmLinkerTest.csproj",
4040
"src\\Components\\WebView\\Platforms\\WebView2\\src\\Microsoft.AspNetCore.Components.WebView.WebView2.csproj",
4141
"src\\Components\\WebView\\Platforms\\WindowsForms\\src\\Microsoft.AspNetCore.Components.WebView.WindowsForms.csproj",
42+
"src\\Components\\WebView\\Platforms\\WindowsForms\\testassets\\WinFormsTestApp\\WinFormsTestApp.csproj",
4243
"src\\Components\\WebView\\Platforms\\Wpf\\src\\Microsoft.AspNetCore.Components.WebView.Wpf.csproj",
44+
"src\\Components\\WebView\\Platforms\\Wpf\\testassets\\WpfTestApp\\WpfTestApp.csproj",
4345
"src\\Components\\WebView\\Samples\\BlazorWinFormsApp\\BlazorWinFormsApp.csproj",
4446
"src\\Components\\WebView\\Samples\\BlazorWpfApp\\BlazorWpfApp.csproj",
4547
"src\\Components\\WebView\\WebView\\src\\Microsoft.AspNetCore.Components.WebView.csproj",

src/Components/WebView/Platforms/WindowsForms/testassets/WinFormsTestApp/Form1.Designer.cs

Lines changed: 59 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
// Copyright (c) .NET Foundation. All rights reserved.
2+
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
3+
4+
using System.Windows.Forms;
5+
using System.Net.Http;
6+
using Microsoft.AspNetCore.Components.WebView.WindowsForms;
7+
using Microsoft.Extensions.DependencyInjection;
8+
9+
namespace WinFormsTestApp
10+
{
11+
public partial class Form1 : Form
12+
{
13+
public Form1()
14+
{
15+
var serviceCollection = new ServiceCollection();
16+
serviceCollection.AddBlazorWebView();
17+
serviceCollection.AddSingleton<HttpClient>();
18+
InitializeComponent();
19+
20+
blazorWebView1.HostPage = @"wwwroot\webviewhost.html";
21+
blazorWebView1.Services = serviceCollection.BuildServiceProvider();
22+
blazorWebView1.RootComponents.Add<BasicTestApp.Index>("root");
23+
}
24+
}
25+
}
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
// Copyright (c) .NET Foundation. All rights reserved.
2+
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
3+
4+
using System;
5+
using System.Windows.Forms;
6+
7+
namespace WinFormsTestApp
8+
{
9+
static class Program
10+
{
11+
/// <summary>
12+
/// The main entry point for the application.
13+
/// </summary>
14+
[STAThread]
15+
static void Main()
16+
{
17+
AppDomain.CurrentDomain.UnhandledException += (sender, error) =>
18+
{
19+
MessageBox.Show(text: error.ExceptionObject.ToString(), caption: "Error");
20+
};
21+
22+
Application.SetHighDpiMode(HighDpiMode.SystemAware);
23+
Application.EnableVisualStyles();
24+
Application.SetCompatibleTextRenderingDefault(false);
25+
Application.Run(new Form1());
26+
}
27+
}
28+
}
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
<Project Sdk="Microsoft.NET.Sdk.Razor">
2+
3+
<PropertyGroup>
4+
<TargetFramework>$(DefaultNetCoreTargetFramework)-windows</TargetFramework>
5+
<OutputType>WinExe</OutputType>
6+
<UseWindowsForms>true</UseWindowsForms>
7+
<IsShippingPackage>false</IsShippingPackage>
8+
</PropertyGroup>
9+
10+
<ItemGroup>
11+
<ProjectReference Include="..\..\..\..\..\test\testassets\BasicTestApp\BasicTestApp.csproj" />
12+
</ItemGroup>
13+
14+
<ItemGroup>
15+
<Reference Include="Microsoft.AspNetCore.Components.WebView.WindowsForms" />
16+
</ItemGroup>
17+
18+
<ItemGroup>
19+
<Content Update="wwwroot\**">
20+
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
21+
</Content>
22+
</ItemGroup>
23+
24+
</Project>
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
#blazor-error-ui {
2+
background: lightyellow;
3+
bottom: 0;
4+
box-shadow: 0 -1px 2px rgba(0, 0, 0, 0.2);
5+
display: none;
6+
left: 0;
7+
padding: 0.6rem 1.25rem 0.7rem 1.25rem;
8+
position: fixed;
9+
width: 100%;
10+
z-index: 1000;
11+
}
12+
13+
#blazor-error-ui .dismiss {
14+
cursor: pointer;
15+
position: absolute;
16+
right: 0.75rem;
17+
top: 0.5rem;
18+
}
19+
20+
.valid.modified:not([type=checkbox]) {
21+
outline: 1px solid #26b050;
22+
}
23+
24+
.invalid {
25+
outline: 1px solid red;
26+
}
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
<!DOCTYPE html>
2+
<html>
3+
4+
<head>
5+
<meta charset="utf-8" />
6+
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no" />
7+
<title>WinFormsTestApp</title>
8+
<base href="/" />
9+
<link href="css/app.css" rel="stylesheet" />
10+
</head>
11+
12+
<body>
13+
<!-- The content here is duplicated from index.html in BasicTestApp -->
14+
15+
<root>Loading...</root>
16+
17+
<!-- Explicit display:none required so StartupErrorNotificationTest can observe it change -->
18+
<div id="blazor-error-ui" style="display: none;">
19+
An unhandled error has occurred.
20+
<a href class='reload'>Reload</a>
21+
<a class='dismiss' style="cursor: pointer;">🗙</a>
22+
</div>
23+
24+
<!-- Used for specific test cases -->
25+
<script src="js/jsinteroptests.js"></script>
26+
<script src="js/renderattributestest.js"></script>
27+
<script src="js/webComponentPerformingJsInterop.js"></script>
28+
<script src="js/customLinkElement.js"></script>
29+
30+
<script>
31+
// Used by ElementRefComponent
32+
function setElementValue(element, newValue) {
33+
element.value = newValue;
34+
return element.value;
35+
}
36+
37+
function navigationManagerNavigate() {
38+
Blazor.navigateTo('/subdir/some-path');
39+
}
40+
41+
function getCurrentUrl() {
42+
return location.href;
43+
}
44+
</script>
45+
<script src="_framework/blazor.webview.js"></script>
46+
47+
<!-- Used by ExternalContentPackage -->
48+
<script src="_content/TestContentPackage/prompt.js"></script>
49+
</body>
50+
51+
</html>
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
<Application x:Class="WpfTestApp.App"
2+
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
3+
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
4+
xmlns:local="clr-namespace:WpfTestApp"
5+
StartupUri="MainWindow.xaml"
6+
Startup="Application_Startup">
7+
<Application.Resources>
8+
9+
</Application.Resources>
10+
</Application>
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
// Copyright (c) .NET Foundation. All rights reserved.
2+
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
3+
4+
using System;
5+
using System.Windows;
6+
7+
namespace WpfTestApp
8+
{
9+
/// <summary>
10+
/// Interaction logic for App.xaml
11+
/// </summary>
12+
public partial class App : Application
13+
{
14+
private void Application_Startup(object sender, StartupEventArgs e)
15+
{
16+
AppDomain.CurrentDomain.UnhandledException += (sender, error) =>
17+
{
18+
MessageBox.Show(error.ExceptionObject.ToString(), "Error", MessageBoxButton.OK, MessageBoxImage.Error);
19+
};
20+
}
21+
}
22+
}
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
<Window x:Class="WpfTestApp.MainWindow"
2+
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
3+
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
4+
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
5+
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
6+
xmlns:basictestapp="clr-namespace:BasicTestApp;assembly=BasicTestApp"
7+
xmlns:blazor="clr-namespace:Microsoft.AspNetCore.Components.WebView.Wpf;assembly=Microsoft.AspNetCore.Components.WebView.Wpf"
8+
mc:Ignorable="d"
9+
Title="MainWindow" Height="450" Width="800">
10+
<blazor:BlazorWebView HostPage="wwwroot\webviewhost.html" Services="{StaticResource services}">
11+
<blazor:BlazorWebView.RootComponents>
12+
<blazor:RootComponent Selector="root" ComponentType="{x:Type basictestapp:Index}" />
13+
</blazor:BlazorWebView.RootComponents>
14+
</blazor:BlazorWebView>
15+
</Window>
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
// Copyright (c) .NET Foundation. All rights reserved.
2+
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
3+
4+
using System.Net.Http;
5+
using System.Windows;
6+
using Microsoft.Extensions.DependencyInjection;
7+
8+
namespace WpfTestApp
9+
{
10+
/// <summary>
11+
/// Interaction logic for MainWindow.xaml
12+
/// </summary>
13+
public partial class MainWindow : Window
14+
{
15+
public MainWindow()
16+
{
17+
var serviceCollection = new ServiceCollection();
18+
serviceCollection.AddBlazorWebView();
19+
serviceCollection.AddSingleton<HttpClient>();
20+
Resources.Add("services", serviceCollection.BuildServiceProvider());
21+
22+
InitializeComponent();
23+
}
24+
}
25+
}
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
<Project Sdk="Microsoft.NET.Sdk.Razor">
2+
3+
<PropertyGroup>
4+
<TargetFramework>$(DefaultNetCoreTargetFramework)-windows</TargetFramework>
5+
<OutputType>WinExe</OutputType>
6+
<UseWPF>true</UseWPF>
7+
<IsShippingPackage>false</IsShippingPackage>
8+
</PropertyGroup>
9+
10+
<ItemGroup>
11+
<ProjectReference Include="..\..\..\..\..\test\testassets\BasicTestApp\BasicTestApp.csproj" />
12+
</ItemGroup>
13+
14+
<ItemGroup>
15+
<Reference Include="Microsoft.AspNetCore.Components.WebView.Wpf" />
16+
</ItemGroup>
17+
18+
<ItemGroup>
19+
<Content Update="wwwroot\**">
20+
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
21+
</Content>
22+
</ItemGroup>
23+
24+
</Project>

0 commit comments

Comments
 (0)