Skip to content

Commit 5566e8d

Browse files
bhavanesh2001PureWeen
authored andcommitted
[Android] Fix WebView Navigated is fired when source is null (#29234)
* Don't LoadUrl call when source is null * Add UI Test * remove space * Update UI Test
1 parent 4380089 commit 5566e8d

File tree

4 files changed

+59
-2
lines changed

4 files changed

+59
-2
lines changed
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
<?xml version="1.0" encoding="utf-8" ?>
2+
<ContentPage xmlns="http://schemas.microsoft.com/dotnet/2021/maui"
3+
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
4+
x:Class="Controls.TestCases.HostApp.Issues.Issue29233"
5+
Title="Issue29233">
6+
<VerticalStackLayout VerticalOptions="Center">
7+
<Label AutomationId="WaitLabel" x:Name="waitLabel" />
8+
<Label IsVisible="false" AutomationId="MauiLabel" x:Name="label" />
9+
<WebView Navigated="WebView_Navigated"/>
10+
</VerticalStackLayout>
11+
</ContentPage>
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
using System.Threading.Tasks;
2+
3+
namespace Controls.TestCases.HostApp.Issues;
4+
5+
[Issue(IssueTracker.Github, 29233, "Android WebView Navigated is fired without setting source", PlatformAffected.Android)]
6+
public partial class Issue29233 : ContentPage
7+
{
8+
public Issue29233()
9+
{
10+
InitializeComponent();
11+
}
12+
13+
private void WebView_Navigated(object sender, WebNavigatedEventArgs e)
14+
{
15+
label.IsVisible = true;
16+
label.Text= "Failed";
17+
}
18+
19+
protected override async void OnAppearing()
20+
{
21+
base.OnAppearing();
22+
await Task.Delay(2000);
23+
waitLabel.Text = "Hello";
24+
}
25+
}
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
using System;
2+
using NUnit.Framework;
3+
using UITest.Appium;
4+
using UITest.Core;
5+
6+
namespace Microsoft.Maui.TestCases.Tests.Tests.Issues;
7+
8+
public class Issue29233 : _IssuesUITest
9+
{
10+
public Issue29233(TestDevice device) : base(device)
11+
{
12+
}
13+
14+
public override string Issue => "Android WebView Navigated is fired without setting source";
15+
16+
[Test]
17+
[Category(UITestCategories.WebView)]
18+
public void NavigatedShouldNotFireWithNullSource()
19+
{
20+
App.WaitForElement("WaitLabel",timeout: TimeSpan.FromSeconds(5));
21+
App.WaitForNoElement("MauiLabel");
22+
}
23+
}

src/Core/src/Platform/Android/WebViewExtensions.cs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,6 @@ public static void UpdateSource(this AWebView platformWebView, IWebView webView,
2525
platformWebView.UpdateCanGoBackForward(webView);
2626
}
2727
}
28-
else
29-
platformWebView.LoadUrl("about:blank");
3028
}
3129

3230
public static void UpdateSettings(this AWebView platformWebView, IWebView webView, bool javaScriptEnabled, bool domStorageEnabled)

0 commit comments

Comments
 (0)