diff --git a/src/Controls/tests/TestCases.HostApp/Issues/Issue3262.cs b/src/Controls/tests/TestCases.HostApp/Issues/Issue3262.cs index 76fad6a092b8..f8856f7eb6ef 100644 --- a/src/Controls/tests/TestCases.HostApp/Issues/Issue3262.cs +++ b/src/Controls/tests/TestCases.HostApp/Issues/Issue3262.cs @@ -1,5 +1,6 @@ using System.Net; using System.Text.RegularExpressions; +using Microsoft.Maui.Controls.PlatformConfiguration; using Microsoft.Maui.Controls.PlatformConfiguration.WindowsSpecific; using Label = Microsoft.Maui.Controls.Label; using WebView = Microsoft.Maui.Controls.WebView; @@ -13,19 +14,16 @@ public class Issue3262 : TestContentPage // or TestFlyoutPage, etc ... protected override void Init() { -#pragma warning disable CS0612 // Type or member is obsolete Label header = new Label { Text = "Cookies...", - FontSize = Device.GetNamedSize(NamedSize.Medium, typeof(Label)), HorizontalOptions = LayoutOptions.Center }; -#pragma warning restore CS0612 // Type or member is obsolete try { CookieContainer cookieContainer = new CookieContainer(); - string url = "https://dotnet.microsoft.com/apps/xamarin"; + string url = "https://dotnet.microsoft.com/apps/maui"; Uri uri = new Uri(url, UriKind.RelativeOrAbsolute); Cookie cookie = new Cookie @@ -39,35 +37,39 @@ protected override void Init() cookieContainer.Add(uri, cookie); -#pragma warning disable CS0618 // Type or member is obsolete WebView webView = new WebView { Source = url, - HorizontalOptions = LayoutOptions.FillAndExpand, - VerticalOptions = LayoutOptions.FillAndExpand, + HeightRequest = 200, + WidthRequest = 300, Cookies = cookieContainer }; -#pragma warning restore CS0618 // Type or member is obsolete - webView.On().SetIsJavaScriptAlertEnabled(true); + + webView.On().SetIsJavaScriptAlertEnabled(true); Action cookieExpectation = null; var cookieResult = new Label() { Text = "Loading", - AutomationId = "CookieResult" }; - webView.Navigating += (_, __) => + var successfullPageLoadLabel = new Label() { - if (cookieExpectation != null) - cookieResult.Text = "Navigating"; + IsVisible = false, + Text = "Page was loaded", + AutomationId = "SuccessfullPageLoadLabel" }; - webView.Navigated += async (_, __) => + var successCookiesLabel = new Label() { - if (cookieResult.Text == "Loading") - cookieResult.Text = "Loaded"; + IsVisible = false, + Text = "Success", + AutomationId = "SuccessCookiesLabel" + }; + webView.Navigated += async (_, __) => + { + successfullPageLoadLabel.IsVisible = true; _currentCookieValue = await webView.EvaluateJavaScriptAsync("document.cookie"); cookieExpectation?.Invoke(_currentCookieValue); cookieExpectation = null; @@ -84,7 +86,12 @@ protected override void Init() { Text = "Modify the Cookie Container" }, - cookieResult, + new HorizontalStackLayout() + { + cookieResult, + successfullPageLoadLabel, + successCookiesLabel + }, new StackLayout() { Orientation = StackOrientation.Horizontal, @@ -97,7 +104,8 @@ protected override void Init() Command = new Command(() => { webView.Cookies = cookieContainer; - cookieResult.Text = String.Empty; + cookieResult.Text = string.Empty; + successCookiesLabel.IsVisible = false; cookieExpectation = (cookieValue) => { if(cookieValue.Contains("TestCookie", StringComparison.OrdinalIgnoreCase)) @@ -106,7 +114,7 @@ protected override void Init() } else { - cookieResult.Text = "Success"; + successCookiesLabel.IsVisible = true; } }; @@ -134,7 +142,7 @@ protected override void Init() } else { - cookieResult.Text = "Success"; + successCookiesLabel.IsVisible = true; } }; @@ -149,6 +157,7 @@ protected override void Init() Command = new Command(() => { cookieResult.Text = String.Empty; + successCookiesLabel.IsVisible = false; cookieExpectation = (cookieValue) => { if(Regex.Matches(cookieValue, "TestCookie").Count > 1) @@ -157,7 +166,7 @@ protected override void Init() } else { - cookieResult.Text = "Success"; + successCookiesLabel.IsVisible = true; } }; @@ -190,6 +199,7 @@ protected override void Init() { webView.Cookies = cookieContainer; cookieResult.Text = String.Empty; + successCookiesLabel.IsVisible = false; cookieContainer.Add(new Cookie { Name = $"TestCookie{cookieContainer.Count}", @@ -212,7 +222,7 @@ protected override void Init() } else { - cookieResult.Text = "Success"; + successCookiesLabel.IsVisible = true; } }; @@ -242,6 +252,7 @@ protected override void Init() }; cookieResult.Text = String.Empty; + successCookiesLabel.IsVisible = false; cookieExpectation = (cookieValue) => { if(cookieValue.Contains(cookieToAdd.Name, StringComparison.OrdinalIgnoreCase)) @@ -250,7 +261,7 @@ protected override void Init() } else { - cookieResult.Text = "Success"; + successCookiesLabel.IsVisible = true; } }; @@ -275,8 +286,13 @@ protected override void Init() AutomationId = "PageWithoutCookies", Command = new Command(() => { + var previousCookies = webView.Cookies; webView.Cookies = null; webView.Source = "file:///android_asset/googlemapsearch.html"; + + //Restore to the previous state + webView.Cookies = previousCookies; + webView.Source = url; }) } } diff --git a/src/Controls/tests/TestCases.Shared.Tests/Tests/Issues/Issue3262.cs b/src/Controls/tests/TestCases.Shared.Tests/Tests/Issues/Issue3262.cs index 26088e804e95..58073167991f 100644 --- a/src/Controls/tests/TestCases.Shared.Tests/Tests/Issues/Issue3262.cs +++ b/src/Controls/tests/TestCases.Shared.Tests/Tests/Issues/Issue3262.cs @@ -4,6 +4,7 @@ namespace Microsoft.Maui.TestCases.Tests.Issues { + [Category(UITestCategories.WebView)] public class Issue3262 : _IssuesUITest { public Issue3262(TestDevice testDevice) : base(testDevice) @@ -13,21 +14,22 @@ public Issue3262(TestDevice testDevice) : base(testDevice) public override string Issue => "Adding Cookies ability to a WebView..."; [Test] - [Category(UITestCategories.WebView)] - [FailsOnAllPlatformsWhenRunningOnXamarinUITest] + [FailsOnMacWhenRunningOnXamarinUITest] + [FailsOnWindowsWhenRunningOnXamarinUITest] public void LoadingPageWithoutCookiesSpecifiedDoesntCrash() { + App.WaitForElement("SuccessfullPageLoadLabel"); App.Tap("PageWithoutCookies"); App.WaitForElement("PageWithoutCookies"); } [Test] - [Category(UITestCategories.WebView)] [Category(UITestCategories.Compatibility)] - [FailsOnAllPlatformsWhenRunningOnXamarinUITest] + [FailsOnMacWhenRunningOnXamarinUITest] + [FailsOnWindowsWhenRunningOnXamarinUITest] public void ChangeDuringNavigating() { - App.WaitForElement("Loaded"); + App.WaitForElement("SuccessfullPageLoadLabel"); // add a couple cookies App.Tap("ChangeDuringNavigating"); ValidateSuccess(); @@ -36,12 +38,12 @@ public void ChangeDuringNavigating() } [Test] - [Category(UITestCategories.WebView)] [Category(UITestCategories.Compatibility)] - [FailsOnAllPlatformsWhenRunningOnXamarinUITest] + [FailsOnMacWhenRunningOnXamarinUITest] + [FailsOnWindowsWhenRunningOnXamarinUITest] public void AddAdditionalCookieToWebView() { - App.WaitForElement("Loaded"); + App.WaitForElement("SuccessfullPageLoadLabel"); // add a couple cookies App.Tap("AdditionalCookie"); ValidateSuccess(); @@ -50,23 +52,23 @@ public void AddAdditionalCookieToWebView() } [Test] - [Category(UITestCategories.WebView)] [Category(UITestCategories.Compatibility)] - [FailsOnAllPlatformsWhenRunningOnXamarinUITest] + [FailsOnMacWhenRunningOnXamarinUITest] + [FailsOnWindowsWhenRunningOnXamarinUITest] public void SetToOneCookie() { - App.WaitForElement("Loaded"); + App.WaitForElement("SuccessfullPageLoadLabel"); App.Tap("OneCookie"); ValidateSuccess(); } [Test] - [Category(UITestCategories.WebView)] [Category(UITestCategories.Compatibility)] - [FailsOnAllPlatformsWhenRunningOnXamarinUITest] + [FailsOnMacWhenRunningOnXamarinUITest] + [FailsOnWindowsWhenRunningOnXamarinUITest] public void SetCookieContainerToNullDisablesCookieManagement() { - App.WaitForElement("Loaded"); + App.WaitForElement("SuccessfullPageLoadLabel"); // add a cookie to verify said cookie remains App.Tap("AdditionalCookie"); ValidateSuccess(); @@ -75,12 +77,12 @@ public void SetCookieContainerToNullDisablesCookieManagement() } [Test] - [Category(UITestCategories.WebView)] [Category(UITestCategories.Compatibility)] - [FailsOnAllPlatformsWhenRunningOnXamarinUITest] + [FailsOnMacWhenRunningOnXamarinUITest] + [FailsOnWindowsWhenRunningOnXamarinUITest] public void RemoveAllTheCookiesIAdded() { - App.WaitForElement("Loaded"); + App.WaitForElement("SuccessfullPageLoadLabel"); // add a cookie so you can remove a cookie App.Tap("AdditionalCookie"); ValidateSuccess(); @@ -92,7 +94,7 @@ void ValidateSuccess() { try { - App.WaitForElement("Success"); + App.WaitForElement("SuccessCookiesLabel"); } catch {