-
Notifications
You must be signed in to change notification settings - Fork 1.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
NullReferenceException throws on Windows when setting Cookies on .NET…
… MAUI WebView (#24846) * Fixed the null exception on maui webview at load time. * Added the test cases for webview * Removed unwanted code section. * Added the output images for web view issue fix. * Invoked the SyncPlatformCookiesToVirtualView in OnCoreWebView2Initialized method. * Change the source value in test case. * Added the UI test cases and removed images. * Moved the SyncPlatformCookies under UpdateUserAgent method. * Invoked the SyncPlatformCookies after the UpdateUserAgent method. * Updated UI test case. * Removed unwanted condition in Webview test case. * Used the waitForElement instead of task delay. * Updated fix due to resolve failed case. * Added the fix for failed cases. * Removed unwanted code changes. * Updated the source URL in test case. * Get the source property from sender instead of getting from the handler platform view. * Resolved the webview loaded without exception failed case in android platform.
- Loading branch information
1 parent
d160357
commit f115e57
Showing
3 changed files
with
93 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
using System.Net; | ||
|
||
namespace Maui.Controls.Sample.Issues | ||
{ | ||
[Issue(IssueTracker.Github, 18452, "NullReferenceException throws on Windows when setting Cookies on .NET MAUI WebView", PlatformAffected.UWP)] | ||
public class Issue18452 : TestContentPage | ||
{ | ||
protected override void Init() | ||
{ | ||
Grid grid = new Grid(); | ||
grid.RowDefinitions.Add(new RowDefinition { Height = new GridLength(0.8, GridUnitType.Star) }); | ||
grid.RowDefinitions.Add(new RowDefinition { Height = new GridLength(0.2, GridUnitType.Star) }); | ||
WebView webView = new WebView(); | ||
|
||
Label label = new Label(); | ||
label.AutomationId = "Label"; | ||
|
||
const string url = "https://learn.microsoft.com/en-us/dotnet/"; | ||
|
||
CookieContainer cookieContainer = new(); | ||
Uri uri = new(url, UriKind.RelativeOrAbsolute); | ||
|
||
Cookie cookie = new() | ||
{ | ||
Name = "DotNetMAUICookie", | ||
Expires = DateTime.Now.AddDays(1), | ||
Value = "My cookie", | ||
Domain = uri.Host, | ||
Path = "/" | ||
}; | ||
|
||
cookieContainer.Add(uri, cookie); | ||
webView.Cookies = cookieContainer; | ||
webView.AutomationId = "WebView"; | ||
webView.Source = new UrlWebViewSource { Url = uri.ToString() }; | ||
|
||
grid.Children.Add(webView); | ||
|
||
webView.Navigated += (s, e) => | ||
{ | ||
var cookies = webView.Cookies.GetCookies(uri); | ||
foreach (Cookie c in cookies) | ||
{ | ||
if (c.Name == "DotNetMAUICookie") | ||
{ | ||
if (!grid.Contains(label)) | ||
{ | ||
grid.Children.Add(label); | ||
label.Text = "Success"; | ||
break; | ||
} | ||
} | ||
} | ||
}; | ||
|
||
Content = grid; | ||
} | ||
} | ||
} |
24 changes: 24 additions & 0 deletions
24
src/Controls/tests/TestCases.Shared.Tests/Tests/Issues/Issue18452.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
using NUnit.Framework; | ||
using UITest.Appium; | ||
using UITest.Core; | ||
|
||
namespace Microsoft.Maui.TestCases.Tests.Issues; | ||
|
||
[Category(UITestCategories.WebView)] | ||
public class Issue18452 : _IssuesUITest | ||
{ | ||
public override string Issue => "NullReferenceException throws on Windows when setting Cookies on .NET MAUI WebView"; | ||
string? expected = "Success"; | ||
|
||
public Issue18452(TestDevice device) : base(device) | ||
{ | ||
} | ||
|
||
[Test] | ||
public void WebViewLoadedWithoutException() | ||
{ | ||
App.WaitForElement("Label"); | ||
string? label = App.FindElement("Label").GetText(); | ||
Assert.That(label, Is.EqualTo(expected)); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters