Skip to content
This repository has been archived by the owner on May 1, 2024. It is now read-only.

Fix failing UI tests for Android FormsApplicationActivity #1141

Merged
merged 10 commits into from
Sep 15, 2017
16 changes: 14 additions & 2 deletions Xamarin.Forms.ControlGallery.Android/CustomRenderers.cs
Original file line number Diff line number Diff line change
Expand Up @@ -533,15 +533,27 @@ protected override NumberKeyListener GetDigitsKeyListener(InputTypes inputTypes)
// }
// }

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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -133,13 +133,25 @@ protected override void Init()
[Test]
public void Bugzilla32830Test()
{
IgnoreFormsApplicationActivity();

RunningApp.WaitForElement(q => q.Marked(BottomLabel));
RunningApp.WaitForElement(q => q.Marked(Button1));
RunningApp.Tap(q => q.Marked(Button1));
RunningApp.WaitForElement(q => q.Marked(Button2));
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
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using System;
using System.Threading;
using System.Threading.Tasks;
using Xamarin.Forms.CustomAttributes;
using Xamarin.Forms.Internals;

Expand Down Expand Up @@ -66,9 +67,12 @@ public void Issue45926Test ()
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"));

Expand All @@ -81,6 +85,10 @@ public void Issue45926Test ()
[Preserve(AllMembers = true)]
public class _45926IntermediatePage : ContentPage
{
public _45926IntermediatePage()
{
Content = new Label { Text = "Intermediate Page" };
}
}

[Preserve(AllMembers = true)]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,8 @@ public AppearingPage (int id)
protected override void OnAppearing ()
{
base.OnAppearing ();
Device.StartTimer (new TimeSpan (200), () => {

Device.StartTimer (TimeSpan.FromMilliseconds(750), () => {
_listMessages.ItemsSource = App.AppearingMessages;
return false;
});
Expand Down
11 changes: 11 additions & 0 deletions Xamarin.Forms.Platform.Android/Renderers/FrameRenderer.cs
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -10,6 +11,7 @@ namespace Xamarin.Forms.Platform.Android
public class FrameRenderer : VisualElementRenderer<Frame>
{
bool _disposed;
readonly MotionEventHelper _motionEventHelper = new MotionEventHelper();

protected override void Dispose(bool disposing)
{
Expand All @@ -22,6 +24,14 @@ protected override void Dispose(bool disposing)
}
}

public override bool OnTouchEvent(MotionEvent e)
{
if (base.OnTouchEvent(e))
return true;

return _motionEventHelper.HandleMotionEvent(Parent, e);
}

protected override void OnElementChanged(ElementChangedEventArgs<Frame> e)
{
base.OnElementChanged(e);
Expand All @@ -30,6 +40,7 @@ protected override void OnElementChanged(ElementChangedEventArgs<Frame> e)
{
UpdateBackground();
UpdateCornerRadius();
_motionEventHelper.UpdateElement(e.NewElement);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -287,7 +287,10 @@ Task<bool> SwitchContentAsync(Page view, bool animated, bool removed = false)
}
s_currentAnimation = null;
tcs.TrySetResult(true);
((Platform)Element.Platform).NavAnimationInProgress = false;
if (Element?.Platform != null)
{
((Platform)Element.Platform).NavAnimationInProgress = false;
}
} });
}
}
Expand Down