-
Notifications
You must be signed in to change notification settings - Fork 1.9k
[Testing] Add Validation Test For Issue28051 On Android #30026
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
PureWeen
merged 3 commits into
dotnet:inflight/candidate
from
prakashKannanSf3972:28051-TestCase
Jun 26, 2025
Merged
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
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
152 changes: 152 additions & 0 deletions
152
src/Controls/tests/TestCases.HostApp/Issues/Issue28051.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,152 @@ | ||
| using System.Collections.ObjectModel; | ||
| using System.ComponentModel; | ||
| using System.Runtime.CompilerServices; | ||
|
|
||
| namespace Maui.Controls.Sample.Issues; | ||
|
|
||
| [Issue(IssueTracker.Github, 28051, "ObjectDisposedException Occurs During View Recycling When PlatformBehavior Is Attached on Android", PlatformAffected.Android)] | ||
| public class Issue28051 : TestContentPage, INotifyPropertyChanged | ||
| { | ||
| ObservableCollection<string> items; | ||
|
|
||
| public ObservableCollection<string> Items | ||
| { | ||
| get => items; | ||
| set | ||
| { | ||
| if (items != value) | ||
| { | ||
| items = value; | ||
| OnPropertyChanged(); | ||
| } | ||
| } | ||
| } | ||
|
|
||
| protected override void Init() | ||
| { | ||
| BindingContext = this; | ||
| LoadItems(); | ||
|
|
||
| Button refreshItemsButton = new Button | ||
| { | ||
| AutomationId = "RefreshItemsButton", | ||
| Text = "Refresh" | ||
| }; | ||
| refreshItemsButton.Clicked += OnReproClicked; | ||
|
|
||
| StackLayout contentLayout = new StackLayout() { Spacing = 10 }; | ||
|
|
||
| StackLayout itemContainer = new StackLayout(); | ||
| itemContainer.SetBinding(BindableLayout.ItemsSourceProperty, new Binding("Items")); | ||
|
|
||
| BindableLayout.SetItemTemplate(itemContainer, CreateItemTemplate()); | ||
|
|
||
| RefreshView refreshView = new RefreshView | ||
| { | ||
| Content = itemContainer | ||
| }; | ||
|
|
||
| contentLayout.Children.Add(refreshItemsButton); | ||
| contentLayout.Children.Add(refreshView); | ||
|
|
||
| this.Content = contentLayout; | ||
| } | ||
|
|
||
| DataTemplate CreateItemTemplate() | ||
| { | ||
| DataTemplate itemTemplate = new DataTemplate(() => | ||
| { | ||
| Button button = new Button | ||
| { | ||
| BackgroundColor = Colors.DarkGreen, | ||
| TextColor = Colors.White | ||
| }; | ||
| button.SetBinding(Button.TextProperty, new Binding(".")); | ||
| LongPressBehavior longPressBehavior = new LongPressBehavior(); | ||
| button.Behaviors.Add(longPressBehavior); | ||
| return button; | ||
| }); | ||
|
|
||
| return itemTemplate; | ||
| } | ||
|
|
||
| void OnReproClicked(object sender, EventArgs e) | ||
| { | ||
| Items = null; | ||
| Items = new ObservableCollection<string> | ||
| { | ||
| "Item A", | ||
| "Item B", | ||
| "Item C" | ||
| }; | ||
| } | ||
|
|
||
| void LoadItems() | ||
| { | ||
| Items = new ObservableCollection<string> | ||
| { | ||
| "Item 1", | ||
| "Item 2", | ||
| "Item 3" | ||
| }; | ||
| } | ||
|
|
||
| public new event PropertyChangedEventHandler PropertyChanged; | ||
| protected new void OnPropertyChanged([CallerMemberName] string propertyName = null) | ||
| => PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName)); | ||
| } | ||
|
|
||
| #if ANDROID | ||
| public class LongPressBehavior : PlatformBehavior<Element, Android.Views.View> | ||
| { | ||
| protected override void OnAttachedTo(Element bindable, Android.Views.View platformView) | ||
| { | ||
| BindingContext = bindable.BindingContext; | ||
| } | ||
|
|
||
| protected override void OnDetachedFrom(Element bindable, Android.Views.View platformView) | ||
| { | ||
| BindingContext = null; | ||
| } | ||
| } | ||
| #elif IOS || MACCATALYST | ||
| public class LongPressBehavior : PlatformBehavior<Element, UIKit.UIView> | ||
| { | ||
| protected override void OnAttachedTo(Element bindable, UIKit.UIView platformView) | ||
| { | ||
| BindingContext = bindable.BindingContext; | ||
| } | ||
|
|
||
| protected override void OnDetachedFrom(Element bindable, UIKit.UIView platformView) | ||
| { | ||
| BindingContext = null; | ||
|
|
||
| } | ||
| } | ||
| #elif WINDOWS | ||
| public class LongPressBehavior : PlatformBehavior<Element, Microsoft.UI.Xaml.FrameworkElement> | ||
| { | ||
| protected override void OnAttachedTo(Element bindable, Microsoft.UI.Xaml.FrameworkElement platformView) | ||
| { | ||
| BindingContext = bindable.BindingContext; | ||
| } | ||
|
|
||
| protected override void OnDetachedFrom(Element bindable, Microsoft.UI.Xaml.FrameworkElement platformView) | ||
| { | ||
| BindingContext = null; | ||
| } | ||
| } | ||
| #else | ||
| public class LongPressBehavior : PlatformBehavior<Element, object> | ||
| { | ||
| protected override void OnAttachedTo(Element bindable, object platformView) | ||
| { | ||
| BindingContext = bindable.BindingContext; | ||
| } | ||
|
|
||
| protected override void OnDetachedFrom(Element bindable, object platformView) | ||
| { | ||
| BindingContext = null; | ||
| } | ||
| } | ||
| #endif |
26 changes: 26 additions & 0 deletions
26
src/Controls/tests/TestCases.Shared.Tests/Tests/Issues/Issue28051.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,26 @@ | ||
| using NUnit.Framework; | ||
| using UITest.Appium; | ||
| using UITest.Core; | ||
|
|
||
| namespace Microsoft.Maui.TestCases.Tests.Issues; | ||
|
|
||
| public class Issue28051 : _IssuesUITest | ||
| { | ||
| public Issue28051(TestDevice testDevice) : base(testDevice) { } | ||
|
|
||
| public override string Issue => "ObjectDisposedException Occurs During View Recycling When PlatformBehavior Is Attached on Android"; | ||
|
|
||
| const string Refresh = "Refresh"; | ||
|
|
||
| [Test] | ||
| [Category(UITestCategories.Performance)] | ||
| public void RefreshItemsShouldNotCrash() | ||
| { | ||
| App.WaitForElement(Refresh); | ||
| for (int i = 0; i < 10; i++) | ||
| { | ||
| App.Tap("RefreshItemsButton"); | ||
| } | ||
| App.WaitForElement(Refresh); | ||
| } | ||
| } | ||
Oops, something went wrong.
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.