Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
6332b84
Fix code and test case commit
praveenkumarkarunanithi Jan 8, 2025
36b0e6e
test case code updated
praveenkumarkarunanithi Jan 8, 2025
9d1e5c0
removed ui tests as it used user name included url
praveenkumarkarunanithi Jan 12, 2025
f86e728
updated unit test case
praveenkumarkarunanithi Jan 17, 2025
a5f3de8
updated fix and unit test case
praveenkumarkarunanithi Jan 21, 2025
1a1ec99
updated the new class access specifier.
praveenkumarkarunanithi Jan 22, 2025
7a1d98a
Removed unit test descriptions
praveenkumarkarunanithi Jan 22, 2025
9886753
Fix updated
praveenkumarkarunanithi Jan 22, 2025
44203e7
updated the unit test case
praveenkumarkarunanithi Jan 22, 2025
47778eb
Reverted unit test and added UI test case
praveenkumarkarunanithi Jan 28, 2025
55cbb10
updated test case description
praveenkumarkarunanithi Jan 28, 2025
5dd8b04
updating ui test case with ignore windows comment
praveenkumarkarunanithi Jan 29, 2025
c6db857
updated windows issue url
praveenkumarkarunanithi Jan 29, 2025
348cfa7
updating test case with comments.
praveenkumarkarunanithi Jan 29, 2025
0315473
updated the test case as device test
praveenkumarkarunanithi Feb 21, 2025
c728787
removed ui test
praveenkumarkarunanithi Feb 21, 2025
656a162
Fix build error
jfversluis Feb 26, 2025
9a3b6eb
Merge branch 'dotnet:main' into 26843-fix
praveenkumarkarunanithi Feb 26, 2025
7c67151
updated device test with conditional skip code
praveenkumarkarunanithi Mar 3, 2025
09e67b5
Merge branch 'dotnet:main' into 26843-fix
praveenkumarkarunanithi Mar 18, 2025
06905a0
updating test case with internet connectivity checks.
praveenkumarkarunanithi Mar 18, 2025
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
2 changes: 1 addition & 1 deletion src/Core/src/Platform/Android/MauiWebView.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ void IWebViewDelegate.LoadUrl(string? url)
_handler.CurrentNavigationEvent = WebNavigationEvent.NewPage;
}

if (url != null && !url.StartsWith('/') && !Uri.IsWellFormedUriString(url, UriKind.Absolute))
if (url is not null && !url.StartsWith('/') && !Uri.TryCreate(url, UriKind.Absolute, out _))
{
// URLs like "index.html" can't possibly load, so try "file:///android_asset/index.html"
url = AssetBaseUrl + url;
Expand Down
35 changes: 35 additions & 0 deletions src/Core/tests/DeviceTests/Handlers/WebView/WebViewHandlerTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -113,5 +113,40 @@ await img.AssertContainsColor(expectedColorInPlayingVideo, imageRect =>
});
});
}

[Theory(DisplayName = "WebView loads non-Western character encoded URLs correctly"
#if WINDOWS
, Skip = "Skipping this test on Windows due to WebView's OnNavigated event returning WebNavigationResult.Failure for URLs with non-Western characters. More information: https://github.com/dotnet/maui/issues/27425"
#endif
)]
[InlineData("https://example.com/test-Ağ-Sistem%20Bilgi%20Güvenliği%20Md/Guide.pdf")] // Non-ASCII character + space (%20) (Outside IRI range)
[InlineData("https://google.com/[]")] // Reserved set (`;/?:@&=+$,#[]!'()*%`)
[InlineData("https://example.com/test/%3Cvalue%3E")] // Escaped character from " <>`^{|} set (e.g., < >)
[InlineData("https://example.com/path/%09text")] // Escaped character from [0, 1F] range (e.g., tab %09)
[InlineData("https://example.com/test?query=%26value")] // Another escaped character from reserved set (e.g., & as %26)
public async Task WebViewShouldLoadEncodedUrl(string encodedUrl)
{
if (await AssertionExtensions.SkipTestIfNoInternetConnection())
{
return;
}
var webView = new WebView();
var tcs = new TaskCompletionSource<WebNavigationResult>();

webView.Navigated += (sender, args) =>
{
tcs.TrySetResult(args.Result);
};

await InvokeOnMainThreadAsync(() =>
{
var handler = CreateHandler<WebViewHandler>(webView);
(handler.PlatformView as IWebViewDelegate)?.LoadUrl(encodedUrl);
});

var navigationResult = await tcs.Task.WaitAsync(TimeSpan.FromSeconds(5));

Assert.Equal(WebNavigationResult.Success, navigationResult);
}
}
}
35 changes: 35 additions & 0 deletions src/TestUtils/src/DeviceTests/AssertionExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using System.Net.Http;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Maui.Dispatching;
using Microsoft.Maui.Platform;
Expand Down Expand Up @@ -266,5 +267,39 @@ public static async Task AssertEventually(this Func<bool> assertion, int timeout
throw new XunitException(message);
}
}
// Add these methods to AssertionExtensions class
/// <summary>
/// Checks if internet connection is available by making an HTTP request
/// </summary>
/// <returns>True if internet connection is available</returns>
public static async Task<bool> HasInternetConnection()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this necessary? Can't you use the VerifyInternetConnectivity(); existing method?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@jsuarezruiz , The existing method (VerifyInternetConnectivity) is added in the UITest project, but since this is a different project (Device Test), I have added the method separately here.

{
try
{
using var httpClient = new HttpClient();
httpClient.Timeout = TimeSpan.FromSeconds(5);
using var response = await httpClient.GetAsync("https://1.1.1.1");
return response.IsSuccessStatusCode;
}
catch
{
return false;
}
}

/// <summary>
/// Skips the current test if no internet connection is available
/// </summary>
/// <param name="message">Custom message to display when skipping the test</param>
/// <returns>True if test should be skipped (no internet), false if test can continue</returns>
public static async Task<bool> SkipTestIfNoInternetConnection(string message = "Test requires internet connection")
{
if (!await HasInternetConnection())
{
Assert.True(true, $"TEST SKIPPED: {message}");
return true; // Test should be skipped
}
return false; // Test can proceed
}
}
}
Loading