From 813b953360c5dde98b0de0fc03fce849cd6c7edc Mon Sep 17 00:00:00 2001 From: "E.Z. Hart" Date: Fri, 15 Sep 2017 08:37:09 -0600 Subject: [PATCH] Fix failing UI tests for Android FormsApplicationActivity (#1141) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * Fix broken test for 57910 when using FormsApplicationActivity * Fix NRE when removing a page during OnAppearing using FormsApplicationActivity * Update 45926 test to work correctly with FormsApplicationActivity * Update 32830 test so it doesn't crash on FormsApplicationActivity * Longer wait before refreshing appearing messages (to work with FormsApplicationActivity) * Fix input transparency issue with old FrameRenderer * Remove extraneous using directive * Just ignore test 32830 on FormsApplicationActivity * [Controls] Add missing directive --- .../CustomRenderers.cs | 16 ++++++++++++++-- .../Bugzilla32830.cs | 12 ++++++++++++ .../Bugzilla45926.cs | 8 ++++++++ .../ControlGalleryPages/AppearingGalleryPage.cs | 3 ++- .../Renderers/FrameRenderer.cs | 11 +++++++++++ .../Renderers/NavigationRenderer.cs | 5 ++++- 6 files changed, 51 insertions(+), 4 deletions(-) diff --git a/Xamarin.Forms.ControlGallery.Android/CustomRenderers.cs b/Xamarin.Forms.ControlGallery.Android/CustomRenderers.cs index e219b82ce..d8c5b9c09 100644 --- a/Xamarin.Forms.ControlGallery.Android/CustomRenderers.cs +++ b/Xamarin.Forms.ControlGallery.Android/CustomRenderers.cs @@ -533,15 +533,27 @@ namespace Xamarin.Forms.ControlGallery.Android // } // } - public class NoFlashTestNavigationPage : Xamarin.Forms.Platform.Android.AppCompat.NavigationPageRenderer + public class NoFlashTestNavigationPage +#if FORMS_APPLICATION_ACTIVITY + : Xamarin.Forms.Platform.Android.NavigationRenderer +#else + : Xamarin.Forms.Platform.Android.AppCompat.NavigationPageRenderer +#endif { +#if !FORMS_APPLICATION_ACTIVITY protected override void SetupPageTransition(global::Android.Support.V4.App.FragmentTransaction transaction, bool isPush) { transaction.SetTransition((int)FragmentTransit.None); } +#endif } - public class QuickCollectNavigationPage : Xamarin.Forms.Platform.Android.AppCompat.NavigationPageRenderer + public class QuickCollectNavigationPage +#if FORMS_APPLICATION_ACTIVITY + : Xamarin.Forms.Platform.Android.NavigationRenderer +#else + : Xamarin.Forms.Platform.Android.AppCompat.NavigationPageRenderer +#endif { bool _disposed; NavigationPage _page; diff --git a/Xamarin.Forms.Controls.Issues/Xamarin.Forms.Controls.Issues.Shared/Bugzilla32830.cs b/Xamarin.Forms.Controls.Issues/Xamarin.Forms.Controls.Issues.Shared/Bugzilla32830.cs index 0e97a33d2..96aa5e8aa 100644 --- a/Xamarin.Forms.Controls.Issues/Xamarin.Forms.Controls.Issues.Shared/Bugzilla32830.cs +++ b/Xamarin.Forms.Controls.Issues/Xamarin.Forms.Controls.Issues.Shared/Bugzilla32830.cs @@ -133,6 +133,8 @@ namespace Xamarin.Forms.Controls.Issues [Test] public void Bugzilla32830Test() { + IgnoreFormsApplicationActivity(); + RunningApp.WaitForElement(q => q.Marked(BottomLabel)); RunningApp.WaitForElement(q => q.Marked(Button1)); RunningApp.Tap(q => q.Marked(Button1)); @@ -140,6 +142,16 @@ namespace Xamarin.Forms.Controls.Issues RunningApp.Tap(q => q.Marked(Button2)); RunningApp.WaitForElement(q => q.Marked(BottomLabel)); } + + static void IgnoreFormsApplicationActivity() + { +#if __ANDROID__ + if (AppSetup.IsFormsApplicationActivity) + { + Assert.Ignore("This test only applies to FormsAppCompatActivity."); + } +#endif + } #endif } } \ No newline at end of file diff --git a/Xamarin.Forms.Controls.Issues/Xamarin.Forms.Controls.Issues.Shared/Bugzilla45926.cs b/Xamarin.Forms.Controls.Issues/Xamarin.Forms.Controls.Issues.Shared/Bugzilla45926.cs index 152d94ad2..4427f3909 100644 --- a/Xamarin.Forms.Controls.Issues/Xamarin.Forms.Controls.Issues.Shared/Bugzilla45926.cs +++ b/Xamarin.Forms.Controls.Issues/Xamarin.Forms.Controls.Issues.Shared/Bugzilla45926.cs @@ -1,5 +1,6 @@ using System; using System.Threading; +using System.Threading.Tasks; using Xamarin.Forms.CustomAttributes; using Xamarin.Forms.Internals; @@ -66,9 +67,12 @@ namespace Xamarin.Forms.Controls.Issues RunningApp.WaitForElement (q => q.Marked ("New Page")); RunningApp.Tap (q => q.Marked ("New Page")); + RunningApp.WaitForElement (q => q.Marked ("Second Page #1")); RunningApp.Back(); + RunningApp.WaitForElement (q => q.Marked ("Intermediate Page")); RunningApp.Back(); RunningApp.Tap(q => q.Marked("Do GC")); + RunningApp.Tap(q => q.Marked("Do GC")); RunningApp.Tap(q => q.Marked("Send Message")); RunningApp.Tap(q => q.Marked("Do GC")); @@ -81,6 +85,10 @@ namespace Xamarin.Forms.Controls.Issues [Preserve(AllMembers = true)] public class _45926IntermediatePage : ContentPage { + public _45926IntermediatePage() + { + Content = new Label { Text = "Intermediate Page" }; + } } [Preserve(AllMembers = true)] diff --git a/Xamarin.Forms.Controls/ControlGalleryPages/AppearingGalleryPage.cs b/Xamarin.Forms.Controls/ControlGalleryPages/AppearingGalleryPage.cs index 21d91906e..548ec96b4 100644 --- a/Xamarin.Forms.Controls/ControlGalleryPages/AppearingGalleryPage.cs +++ b/Xamarin.Forms.Controls/ControlGalleryPages/AppearingGalleryPage.cs @@ -109,7 +109,8 @@ namespace Xamarin.Forms.Controls protected override void OnAppearing () { base.OnAppearing (); - Device.StartTimer (new TimeSpan (200), () => { + + Device.StartTimer (TimeSpan.FromMilliseconds(750), () => { _listMessages.ItemsSource = App.AppearingMessages; return false; }); diff --git a/Xamarin.Forms.Platform.Android/Renderers/FrameRenderer.cs b/Xamarin.Forms.Platform.Android/Renderers/FrameRenderer.cs index 68c7fbc66..4d232e582 100644 --- a/Xamarin.Forms.Platform.Android/Renderers/FrameRenderer.cs +++ b/Xamarin.Forms.Platform.Android/Renderers/FrameRenderer.cs @@ -1,6 +1,7 @@ using System.ComponentModel; using Android.Graphics; using Android.Graphics.Drawables; +using Android.Views; using AButton = Android.Widget.Button; using ACanvas = Android.Graphics.Canvas; using GlobalResource = Android.Resource; @@ -10,6 +11,7 @@ namespace Xamarin.Forms.Platform.Android public class FrameRenderer : VisualElementRenderer { bool _disposed; + readonly MotionEventHelper _motionEventHelper = new MotionEventHelper(); protected override void Dispose(bool disposing) { @@ -22,6 +24,14 @@ namespace Xamarin.Forms.Platform.Android } } + public override bool OnTouchEvent(MotionEvent e) + { + if (base.OnTouchEvent(e)) + return true; + + return _motionEventHelper.HandleMotionEvent(Parent, e); + } + protected override void OnElementChanged(ElementChangedEventArgs e) { base.OnElementChanged(e); @@ -30,6 +40,7 @@ namespace Xamarin.Forms.Platform.Android { UpdateBackground(); UpdateCornerRadius(); + _motionEventHelper.UpdateElement(e.NewElement); } } diff --git a/Xamarin.Forms.Platform.Android/Renderers/NavigationRenderer.cs b/Xamarin.Forms.Platform.Android/Renderers/NavigationRenderer.cs index 109bb6911..ebe542725 100644 --- a/Xamarin.Forms.Platform.Android/Renderers/NavigationRenderer.cs +++ b/Xamarin.Forms.Platform.Android/Renderers/NavigationRenderer.cs @@ -287,7 +287,10 @@ namespace Xamarin.Forms.Platform.Android } s_currentAnimation = null; tcs.TrySetResult(true); - ((Platform)Element.Platform).NavAnimationInProgress = false; + if (Element?.Platform != null) + { + ((Platform)Element.Platform).NavAnimationInProgress = false; + } } }); } }