diff options
Diffstat (limited to 'Xamarin.Forms.Controls.Issues')
2 files changed, 164 insertions, 1 deletions
diff --git a/Xamarin.Forms.Controls.Issues/Xamarin.Forms.Controls.Issues.Shared/Issue1023.cs b/Xamarin.Forms.Controls.Issues/Xamarin.Forms.Controls.Issues.Shared/Issue1023.cs new file mode 100644 index 00000000..a09a49a0 --- /dev/null +++ b/Xamarin.Forms.Controls.Issues/Xamarin.Forms.Controls.Issues.Shared/Issue1023.cs @@ -0,0 +1,162 @@ +using System; +using System.Collections.Generic; +using Xamarin.Forms.CustomAttributes; +using Xamarin.Forms.Internals; +using System.Threading; + +#if UITEST +using Xamarin.UITest; +using NUnit.Framework; +#endif + +namespace Xamarin.Forms.Controls.Issues +{ + [Preserve(AllMembers = true)] + [Issue(IssueTracker.None, 1023, "Automate GC checks of picker disposals", PlatformAffected.iOS)] + public class Bugzilla1023 : TestNavigationPage + { + protected override void Init() + { + PushAsync(new LandingPage1023()); + } + +#if UITEST && __IOS__ + [Test] + public void Bugzilla1023Test() + { + for (var n = 0; n < 10; n++) + { + RunningApp.WaitForElement(q => q.Marked("Push")); + RunningApp.Tap(q => q.Marked("Push")); + + RunningApp.WaitForElement(q => q.Marked("ListView")); + RunningApp.Back(); + } + + // At this point, the counter can be any value, but it's most likely not zero. + // Invoking GC once is enough to clean up all garbage data and set counter to zero + RunningApp.WaitForElement(q => q.Marked("GC")); + RunningApp.Tap(q => q.Marked("GC")); + + RunningApp.WaitForElement(q => q.Marked("Counter: 0")); + } +#endif + } + + [Preserve(AllMembers = true)] + public class LandingPage1023 : ContentPage + { + public static int Counter; + public Label Label; + + public LandingPage1023() + { + Label = new Label + { + Text = "Counter: " + Counter, + HorizontalTextAlignment = TextAlignment.Center, + VerticalTextAlignment = TextAlignment.Center + }; + + Content = new StackLayout + { + Orientation = StackOrientation.Vertical, + HorizontalOptions = LayoutOptions.Center, + VerticalOptions = LayoutOptions.Center, + Spacing = 15, + Children = + { + new Label + { + Text = "Click Push to show a ListView. When you hit the Back button, Counter will show the number of pages that have not been finalized yet." + + " If you click GC, the counter should be 0." + }, + Label, + new Button + { + Text = "GC", + AutomationId = "GC", + Command = new Command(o => + { + GC.Collect(); + GC.WaitForPendingFinalizers(); + GC.Collect(); + Label.Text = "Counter: " + Counter; + }) + }, + new Button + { + Text = "Push", + AutomationId = "Push", + Command = new Command(async o => + { + await Navigation.PushAsync(new ContentPage1023()); + }) + } + } + }; + } + + protected override void OnAppearing() + { + base.OnAppearing(); + + if (Label != null) + Label.Text = "Counter: " + Counter; + } + } + + [Preserve(AllMembers = true)] + public class ContentPage1023 : ContentPage + { + public ContentPage1023() + { + Interlocked.Increment(ref LandingPage1023.Counter); + System.Diagnostics.Debug.WriteLine("Page: " + LandingPage1023.Counter); + + Content = new ListView + { + HasUnevenRows = true, + ItemsSource = new List<string> { "DatePicker", "Picker", "TimePicker" }, + ItemTemplate = new DataTemplateSelector1023(), + AutomationId = "ListView" + }; + } + + ~ContentPage1023() + { + Interlocked.Decrement(ref LandingPage1023.Counter); + System.Diagnostics.Debug.WriteLine("Page: " + LandingPage1023.Counter); + } + } + + [Preserve(AllMembers = true)] + public class DataTemplateSelector1023 : DataTemplateSelector + { + public DataTemplate DatePickerTemplate { get; set; } + public DataTemplate PickerTemplate { get; set; } + public DataTemplate TimePickerTemplate { get; set; } + + public DataTemplateSelector1023() + { + DatePickerTemplate = new DataTemplate(() => new ViewCell { View = new DatePicker() }); + PickerTemplate = new DataTemplate(() => new ViewCell { View = new Picker() }); + TimePickerTemplate = new DataTemplate(() => new ViewCell { View = new TimePicker() }); + } + + protected override DataTemplate OnSelectTemplate(object item, BindableObject container) + { + switch (item as string) + { + case "DatePicker": + return DatePickerTemplate; + case "Picker": + return PickerTemplate; + case "TimePicker": + return TimePickerTemplate; + } + + return null; + } + } +}
\ No newline at end of file diff --git a/Xamarin.Forms.Controls.Issues/Xamarin.Forms.Controls.Issues.Shared/Xamarin.Forms.Controls.Issues.Shared.projitems b/Xamarin.Forms.Controls.Issues/Xamarin.Forms.Controls.Issues.Shared/Xamarin.Forms.Controls.Issues.Shared.projitems index c69e1a31..754133de 100644 --- a/Xamarin.Forms.Controls.Issues/Xamarin.Forms.Controls.Issues.Shared/Xamarin.Forms.Controls.Issues.Shared.projitems +++ b/Xamarin.Forms.Controls.Issues/Xamarin.Forms.Controls.Issues.Shared/Xamarin.Forms.Controls.Issues.Shared.projitems @@ -177,6 +177,7 @@ <Compile Include="$(MSBuildThisFileDirectory)InputTransparentIssue.cs" /> <Compile Include="$(MSBuildThisFileDirectory)IsInvokeRequiredRaceCondition.cs" /> <Compile Include="$(MSBuildThisFileDirectory)IsPasswordToggleTest.cs" /> + <Compile Include="$(MSBuildThisFileDirectory)Issue1023.cs" /> <Compile Include="$(MSBuildThisFileDirectory)Issue1024.cs" /> <Compile Include="$(MSBuildThisFileDirectory)Issue1025.cs" /> <Compile Include="$(MSBuildThisFileDirectory)Issue1026.cs" /> @@ -634,4 +635,4 @@ <Generator>MSBuild:UpdateDesignTimeXaml</Generator> </EmbeddedResource> </ItemGroup> -</Project>
\ No newline at end of file +</Project> |