Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
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
135 changes: 135 additions & 0 deletions src/Controls/tests/TestCases.HostApp/Issues/Issue30515.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,135 @@
namespace Maui.Controls.Sample.Issues;

[Issue(IssueTracker.Github, 30515, "[iOS] WebView.Reload() with HtmlWebViewSource returns WebNavigationResult.Failure in Navigated event", PlatformAffected.iOS)]
public class Issue30515 : ContentPage
{
WebView webView;
Label statusTextLabel;
Label statusValueLabel;

public Issue30515()
{
Title = "Issue 30515";

// Create the navigation status labels - split into static text and dynamic value
statusTextLabel = new Label
{
Text = "Status:",
FontSize = 14,
TextColor = Colors.Gray,
VerticalOptions = LayoutOptions.Center
};

statusValueLabel = new Label
{
Text = "Ready",
AutomationId = "NavigationStatusLabel",
FontSize = 14,
TextColor = Colors.Blue,
VerticalOptions = LayoutOptions.Center
};

// Create a horizontal stack for the status display
var statusContainer = new StackLayout
{
Orientation = StackOrientation.Horizontal,
Spacing = 5,
HorizontalOptions = LayoutOptions.Center,
Children = { statusTextLabel, statusValueLabel }
};

// Create the WebView
webView = new WebView
{
HeightRequest = 300,
WidthRequest = 400,
Source = new HtmlWebViewSource
{
Html = @"
<html>
<head>
<title>HTML WebView Source</title>
</head>
<body style='font-family:sans-serif; padding:20px;'>
<h1>WebView Feature Matrix</h1>
<p>This page demonstrates various capabilities of the .NET MAUI WebView control, such as:</p>
<ul>
<li>Rendering HTML content</li>
<li>Executing JavaScript</li>
<li>Cookie management</li>
<li>Back/Forward navigation</li>
</ul>
<h2>Test Content</h2>
<p>
This is a longer body paragraph to help test the <strong>EvaluateJavaScript</strong> functionality
and how it extracts body text. You can use this text to verify substring operations and test scrolling
or formatting in the WebView.

</p>
<p>
Try interacting with navigation buttons, loading multiple pages, or checking cookie behavior.
</p>

<h2>Navigation Test Links</h2>
<p>Click these links to test URL navigation:</p>
<ul>
<li><a href='https://www.google.com'>Google</a></li>
<li><a href='https://www.microsoft.com'>Microsoft</a></li>
<li><a href='https://github.com'>GitHub</a></li>
<li><a href='https://docs.microsoft.com/dotnet/maui/'>MAUI Documentation</a></li>
<li><a href='https://httpbin.org/html'>HTTPBin HTML Test</a></li>
</ul>

<footer style='margin-top:40px; font-size:0.9em; color:gray;'>Generated for testing WebView features.</footer>
</body>
</html>"
}
};

// Set up event handlers
webView.Navigated += OnWebViewNavigated;

// Create the reload button
var reloadButton = new Button
{
Text = "Reload",
AutomationId = "ReloadButton",
HorizontalOptions = LayoutOptions.Center
};
reloadButton.Clicked += OnReloadClicked;

// Add all elements to the page
Content = new StackLayout
{
Padding = new Thickness(10),
Spacing = 10,
Children =
{
statusContainer,
webView,
new StackLayout
{
Orientation = StackOrientation.Horizontal,
Spacing = 10,
HorizontalOptions = LayoutOptions.Center,
Children =
{
reloadButton
}
}
}
};
}

void OnReloadClicked(object sender, EventArgs e)
{
statusValueLabel.Text = "Reloading...";
webView.Reload();
}

void OnWebViewNavigated(object sender, WebNavigatedEventArgs e)
{
statusValueLabel.Text = e.Result.ToString();
statusValueLabel.TextColor = Colors.Green;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
using NUnit.Framework;
using UITest.Appium;
using UITest.Core;

namespace Microsoft.Maui.TestCases.Tests.Issues;

public class Issue30515 : _IssuesUITest
{
public override string Issue => "[iOS] WebView.Reload() with HtmlWebViewSource returns WebNavigationResult.Failure in Navigated event";

public Issue30515(TestDevice device)
: base(device)
{ }

[Test]
[Category(UITestCategories.WebView)]
public void VerifyWebViewHTMLSourceReloadStatus()
{
App.WaitForElement("NavigationStatusLabel");
App.Tap("ReloadButton");
Assert.That(App.FindElement("NavigationStatusLabel").GetText(), Is.EqualTo("Success"));
}
}
27 changes: 26 additions & 1 deletion src/Core/src/Platform/iOS/WebViewExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,32 @@ public static void UpdateGoForward(this WKWebView platformWebView, IWebView webV

public static void UpdateReload(this WKWebView platformWebView, IWebView webView)
{
platformWebView?.Reload();
if (platformWebView == null)
{
return;
}

// Check if we have a source and platformWebView implements IWebViewDelegate
if (webView.Source != null && platformWebView is IWebViewDelegate webViewDelegate)
{
// If the source is an HTML source, we need to reload from the source
// since WKWebView.Reload() doesn't work properly with LoadHtmlString
var sourceType = webView.Source.GetType().Name;
if (string.Equals(sourceType, "HtmlWebViewSource", StringComparison.Ordinal))
{
// For HTML sources, always reload from the source
webView.Source.Load(webViewDelegate);
}
else
{
// For URL sources, use the standard reload
platformWebView.Reload();
}
}
else
{
platformWebView.Reload();
}
}

internal static void UpdateCanGoBackForward(this WKWebView platformWebView, IWebView webView)
Expand Down
Loading