Skip to content
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -7,20 +7,20 @@
using Microsoft.Extensions.DependencyInjection;
using PhotinoNET;

namespace Microsoft.AspNetCore.Components.WebViewE2E.Test;

public class BasicBlazorHybridTest
public class BasicTest : IExecutionMode
{
private string _latestControlDivValue;
const int MaxWaitTimes = 30;
const int WaitTimeInMS = 250;

public void Run()
{
// Note: This test produces *a lot* of debug output to aid when debugging failures. The only output
// that is necessary for the functioning of this test is the "Test passed" at the end of this method.

Console.WriteLine($"Current directory: {Environment.CurrentDirectory}");
Console.WriteLine($"Current assembly: {typeof(Program).Assembly.Location}");
var thisProgramDir = Path.GetDirectoryName(typeof(Program).Assembly.Location);
Console.WriteLine($"Current assembly: {typeof(BasicTest).Assembly.Location}");
var thisProgramDir = Path.GetDirectoryName(typeof(BasicTest).Assembly.Location);

// Add correct runtime sub-folder to PATH to ensure native files are discovered (this is supposed to happen automatically, but somehow it doesn't...)
var newNativePath = Path.Combine(thisProgramDir, "runtimes", RuntimeInformation.RuntimeIdentifier, "native");
Expand Down Expand Up @@ -66,7 +66,7 @@ public void Run()
};

Console.WriteLine($"Setting up root components...");
mainWindow.RootComponents.Add<Pages.TestPage>("root");
mainWindow.RootComponents.Add<PhotinoTestApp.Pages.TestPage>("root");

Console.WriteLine($"Running window...");

Expand Down Expand Up @@ -161,10 +161,7 @@ public void Run()
Console.WriteLine($"Test passed? {testPassed}");
}

const int MaxWaitTimes = 30;
const int WaitTimeInMS = 250;

public async Task<bool> WaitForControlDiv(PhotinoWindow photinoWindow, string controlValueToWaitFor)
private async Task<bool> WaitForControlDiv(PhotinoWindow photinoWindow, string controlValueToWaitFor)
{

for (var i = 0; i < MaxWaitTimes; i++)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.

public interface IExecutionMode
{
void Run();
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.

using System.Net.Http;
using Microsoft.AspNetCore.Components.Web;
using Microsoft.AspNetCore.Components.WebView.Photino;
using Microsoft.Extensions.DependencyInjection;

public class LaunchSample : IExecutionMode
{
public void Run()
{
var serviceCollection = new ServiceCollection();
serviceCollection.AddBlazorWebView();
serviceCollection.AddSingleton<HttpClient>();

var mainWindow = new BlazorWindow(
title: "Hello, world!",
hostPage: "wwwroot/webviewhost.html",
services: serviceCollection.BuildServiceProvider(),
pathBase: "/subdir"); // The content in BasicTestApp assumes this

AppDomain.CurrentDomain.UnhandledException += (sender, error) =>
{
Console.Write(
"Fatal exception" + Environment.NewLine +
error.ExceptionObject.ToString() + Environment.NewLine);
};

mainWindow.RootComponents.Add<BasicTestApp.Index>("root");
mainWindow.RootComponents.RegisterForJavaScript<BasicTestApp.DynamicallyAddedRootComponent>("my-dynamic-root-component");
mainWindow.RootComponents.RegisterForJavaScript<BasicTestApp.JavaScriptRootComponentParameterTypes>(
"component-with-many-parameters",
javaScriptInitializer: "myJsRootComponentInitializers.testInitializer");

mainWindow.Run();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<OutputType>Exe</OutputType>
<IsShippingPackage>false</IsShippingPackage>
<SignAssembly>false</SignAssembly>
<_WebViewAssetsBasePath>..\..\..\..\..\Web.JS\dist\Release\</_WebViewAssetsBasePath>
<_WebViewAssetsBasePath>..\..\..\..\..\Web.JS\dist\$(Configuration)\</_WebViewAssetsBasePath>
<_BlazorModulesFilePath>..\..\..\..\WebView\src\blazor.modules.json</_BlazorModulesFilePath>
</PropertyGroup>

Expand Down
Original file line number Diff line number Diff line change
@@ -1,41 +1,28 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.

using System.Net.Http;
using Microsoft.AspNetCore.Components.Web;
using Microsoft.AspNetCore.Components.WebView.Photino;
using Microsoft.Extensions.DependencyInjection;

namespace PhotinoTestApp;

class Program
{
[STAThread]
static void Main(string[] args)
{
var serviceCollection = new ServiceCollection();
serviceCollection.AddBlazorWebView();
serviceCollection.AddSingleton<HttpClient>();

var mainWindow = new BlazorWindow(
title: "Hello, world!",
hostPage: "wwwroot/webviewhost.html",
services: serviceCollection.BuildServiceProvider(),
pathBase: "/subdir"); // The content in BasicTestApp assumes this

AppDomain.CurrentDomain.UnhandledException += (sender, error) =>
if (args.Length < 1)
{
Console.Write(
"Fatal exception" + Environment.NewLine +
error.ExceptionObject.ToString() + Environment.NewLine);
};

mainWindow.RootComponents.Add<BasicTestApp.Index>("root");
mainWindow.RootComponents.RegisterForJavaScript<BasicTestApp.DynamicallyAddedRootComponent>("my-dynamic-root-component");
mainWindow.RootComponents.RegisterForJavaScript<BasicTestApp.JavaScriptRootComponentParameterTypes>(
"component-with-many-parameters",
javaScriptInitializer: "myJsRootComponentInitializers.testInitializer");

mainWindow.Run();
var sample = new LaunchSample();
sample.Run();
return;
}
var testScenario = args[0];
if (testScenario == "--basic-test")
{
var basic = new BasicTest();
basic.Run();
}
else
{
throw new Exception($"Scenario {testScenario} is unknown.");
}
}
}
Original file line number Diff line number Diff line change
@@ -1,22 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk.Razor">
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>$(DefaultNetCoreTargetFramework)</TargetFramework>
<OutputType>Exe</OutputType>
<!-- Suppress CS8002 because Photino assemblies are not signed -->
<NoWarn>@(NoWarn);CS8002</NoWarn>
<!-- See code comment in Program.cs/Main in this project regarding this -->
<StartupObject>Microsoft.AspNetCore.Components.WebViewE2E.Test.Program</StartupObject>
</PropertyGroup>

<ItemGroup>
<ProjectReference Include="..\..\Samples\PhotinoPlatform\src\Microsoft.AspNetCore.Components.WebView.Photino.csproj" />
</ItemGroup>

<ItemGroup>
<Content Update="wwwroot\**">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
</ItemGroup>

</Project>
30 changes: 0 additions & 30 deletions src/Components/WebView/test/E2ETest/Program.cs

This file was deleted.

33 changes: 22 additions & 11 deletions src/Components/WebView/test/E2ETest/WebViewManagerE2ETests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,22 +18,33 @@ public class WebViewManagerE2ETests
[ConditionalFact]
[OSSkipCondition(OperatingSystems.Linux | OperatingSystems.MacOSX,
SkipReason = "On Helix/Ubuntu the native Photino assemblies can't be found, and on macOS it can't detect when the WebView is ready")]
[QuarantinedTest("https://github.com/dotnet/aspnetcore/issues/50802")]
public async Task CanLaunchPhotinoWebViewAndClickButton()
{
var photinoTestProgramExePath = typeof(WebViewManagerE2ETests).Assembly.Location;
// Get the path to the PhotinoTestApp instead of the current test assembly
var currentAssemblyPath = typeof(WebViewManagerE2ETests).Assembly.Location;

// This test launches this very test assembly as an executable so that the Photino UI window
// can launch and be automated. See the comment in Program.Main() for more info.
// Extract the current assembly name from the path (without .dll extension)
var currentAssemblyName = Path.GetFileNameWithoutExtension(currentAssemblyPath);

// Replace the current assembly name with "PhotinoTestApp" in the entire path
var photinoTestAppPath = currentAssemblyPath.Replace(currentAssemblyName, "PhotinoTestApp");

if (!File.Exists(photinoTestAppPath))
{
throw new FileNotFoundException($"Could not find PhotinoTestApp.dll at: {photinoTestAppPath}");
}

// This test launches the PhotinoTestApp sample as an executable so that the Photino UI window
// can launch and be automated.
var photinoProcess = new Process()
{
StartInfo = new ProcessStartInfo
{
WorkingDirectory = Path.GetDirectoryName(photinoTestProgramExePath),
FileName = "dotnet",
Arguments = $"\"{photinoTestProgramExePath}\"",
RedirectStandardOutput = true,
},
StartInfo = new ProcessStartInfo
{
WorkingDirectory = Path.GetDirectoryName(photinoTestAppPath),
FileName = "dotnet",
Arguments = $"\"{photinoTestAppPath}\" --basic-test",
RedirectStandardOutput = true,
},
};

photinoProcess.Start();
Expand Down
7 changes: 0 additions & 7 deletions src/Components/WebView/test/E2ETest/_Imports.razor

This file was deleted.

23 changes: 0 additions & 23 deletions src/Components/WebView/test/E2ETest/wwwroot/css/app.css

This file was deleted.

Loading