-
Notifications
You must be signed in to change notification settings - Fork 1.9k
NullReferenceException throws on Windows when setting Cookies on .NET MAUI WebView #24846
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
18 commits
Select commit
Hold shift + click to select a range
327964d
Fixed the null exception on maui webview at load time.
NanthiniMahalingam 167e07a
Added the test cases for webview
NanthiniMahalingam 7893d3d
Removed unwanted code section.
NanthiniMahalingam 7ce8c7f
Added the output images for web view issue fix.
NanthiniMahalingam 0c42570
Invoked the SyncPlatformCookiesToVirtualView in OnCoreWebView2Initial…
NanthiniMahalingam 0fea22b
Change the source value in test case.
NanthiniMahalingam 7ad6fb4
Added the UI test cases and removed images.
NanthiniMahalingam 9df9990
Moved the SyncPlatformCookies under UpdateUserAgent method.
NanthiniMahalingam ed4eeb2
Invoked the SyncPlatformCookies after the UpdateUserAgent method.
NanthiniMahalingam 368f5b5
Updated UI test case.
NanthiniMahalingam e332f57
Removed unwanted condition in Webview test case.
NanthiniMahalingam ad0c0a1
Used the waitForElement instead of task delay.
NanthiniMahalingam 92407f2
Updated fix due to resolve failed case.
NanthiniMahalingam 4ab37e8
Added the fix for failed cases.
NanthiniMahalingam 37ad4e9
Removed unwanted code changes.
NanthiniMahalingam c62a7f2
Updated the source URL in test case.
NanthiniMahalingam a8a6a5a
Get the source property from sender instead of getting from the handl…
NanthiniMahalingam 25cd0be
Resolved the webview loaded without exception failed case in android …
NanthiniMahalingam File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.