Skip to content

Commit

Permalink
[Testing] Split off HandlerDoesNotLeak.DatePicker into its own UI test (
Browse files Browse the repository at this point in the history
#24585)

* Split off DatePicker.HandlerDoesNotLeak into its own UI test.

* Changed RunMemoryTest to take in INavigation instead of NavigationPage, renamed Issue24147 to MemoryTests and changed it to take in Text from Entry to determine which Handler to use, Removed Issue22072 as that's now in MemoryTests

* Renamed Issue24147 in Tests.Shared to MemoryTests, added methods to check DatePicker and WebView. Added automationids in HostApp MemoryTests
  • Loading branch information
dustin-wojciechowski authored Sep 9, 2024
1 parent 760cbb2 commit 9d965cc
Show file tree
Hide file tree
Showing 6 changed files with 108 additions and 45 deletions.
4 changes: 2 additions & 2 deletions src/Controls/tests/DeviceTests/Memory/MemoryTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ await CreateHandlerAndAddToWindow(new Window(navPage), async () =>
[InlineData(typeof(CarouselView))]
[InlineData(typeof(ContentView))]
[InlineData(typeof(CheckBox))]
[InlineData(typeof(DatePicker))]
// [InlineData(typeof(DatePicker))] - This test was moved to MemoryTests.cs inside Appium
[InlineData(typeof(Ellipse))]
[InlineData(typeof(Entry))]
[InlineData(typeof(Editor))]
Expand Down Expand Up @@ -162,7 +162,7 @@ await CreateHandlerAndAddToWindow(new Window(navPage), async () =>
[InlineData(typeof(Switch))]
[InlineData(typeof(TimePicker))]
[InlineData(typeof(TableView))]
[InlineData(typeof(WebView))]
//[InlineData(typeof(WebView))] - This test was moved to MemoryTests.cs inside Appium
[InlineData(typeof(CollectionView))]
public async Task HandlerDoesNotLeak(Type type)
{
Expand Down
20 changes: 0 additions & 20 deletions src/Controls/tests/TestCases.HostApp/Issues/Issue22972.cs

This file was deleted.

69 changes: 69 additions & 0 deletions src/Controls/tests/TestCases.HostApp/Issues/MemoryTests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
namespace Maui.Controls.Sample.Issues
{
[Issue(IssueTracker.None, 24147, "Test Handlers for Memory Leaks", PlatformAffected.All)]
public class MemoryTests : NavigationPage
{
public class MemoryTestPage : ContentPage
{
Entry entryText;
public MemoryTestPage()
{
entryText = new Entry
{
AutomationId = "DataTypeEntry",
Placeholder = "Enter the data type of the Handler you want to test",
};

var runMemoryTestButton = new Button
{
AutomationId = "RunMemoryTestButton",
Text = "Run Memory Test"
};
runMemoryTestButton.Clicked += OnRunMemoryTestClicked;

var stackLayout = new StackLayout
{
Padding = 10,
Children = { entryText, runMemoryTestButton }
};

Content = stackLayout;
}

private void OnRunMemoryTestClicked(object sender, EventArgs e)
{
string dataType = entryText.Text;
RunMemoryTest(dataType);
}

private void RunMemoryTest(String dataType)
{
switch(dataType) {
case "DatePicker":
this.Navigation.RunMemoryTest(() =>
{
return new DatePicker
{
AutomationId = "DatePicker",
Date = new DateTime(2021, 1, 1)
};
});
break;
case "WebView": // 22972: Win platform WebView cannot be release after its parent window get closed
this.Navigation.RunMemoryTest(() =>
{
return new WebView
{
HeightRequest = 500, // NOTE: non-zero size required for Windows
Source = new HtmlWebViewSource { Html = "<p>hi</p>" },
};
});
break;
default:
break;
}
}
}
public MemoryTests(): base(new MemoryTestPage()) {}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ public static async Task AssertEventually(this Func<bool> assertion, int timeout
}
}

public static void RunMemoryTest(this NavigationPage navigationPage, Func<VisualElement> elementToTest)
public static void RunMemoryTest(this INavigation navigationPage, Func<VisualElement> elementToTest)
{
ContentPage rootPage = new ContentPage { Title = "Page 1" };
navigationPage.PushAsync(rootPage);
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
using NUnit.Framework;
using UITest.Appium;
using UITest.Core;

namespace Microsoft.Maui.TestCases.Tests.Issues
{
public class MemoryTests : _IssuesUITest
{
public MemoryTests(TestDevice device) : base(device)
{
}

protected override bool ResetAfterEachTest => true;
public override string Issue => "Test Handlers for Memory Leaks";

[Test]
[Category(UITestCategories.DatePicker)]
public void DatePickerDoesNotLeak()
{
App.WaitForElement("DataTypeEntry");
App.EnterText("DataTypeEntry", "DatePicker");
App.Tap("RunMemoryTestButton");
App.AssertMemoryTest();
}

[Test]
[Category(UITestCategories.WebView)]
public void WebViewDoesNotLeak()
{
App.WaitForElement("DataTypeEntry");
App.EnterText("DataTypeEntry", "WebView");
App.Tap("RunMemoryTestButton");
App.AssertMemoryTest();
}
}
}

0 comments on commit 9d965cc

Please sign in to comment.