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

Commit

Permalink
Merge branch '4.6.0'
Browse files Browse the repository at this point in the history
  • Loading branch information
rmarinho committed Mar 16, 2020
2 parents 1532d46 + 3a82750 commit 954cc8b
Show file tree
Hide file tree
Showing 115 changed files with 2,172 additions and 671 deletions.
11 changes: 5 additions & 6 deletions Xamarin.Forms.ControlGallery.Android/FormsAppCompatActivity.cs
Original file line number Diff line number Diff line change
Expand Up @@ -96,12 +96,11 @@ protected override void OnCreate(Bundle bundle)
});

LoadApplication(_app);
if (Forms.Flags.Contains("FastRenderers_Experimental"))
{
var masterPage = ((_app.MainPage as MasterDetailPage)?.Master as ContentPage);
if (masterPage != null)
masterPage.Content = new Label { Text = "Fast Renderers" };
}

#if !TEST_EXPERIMENTAL_RENDERERS
// Show a purple status bar if we're looking at legacy renderers
Window.SetStatusBarColor(Color.MediumPurple.ToAndroid());
#endif
}

protected override void OnResume()
Expand Down
5 changes: 5 additions & 0 deletions Xamarin.Forms.ControlGallery.Android/LinkDescription.xml
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,9 @@
<namespace fullname="Xamarin.Forms.Controls.Tests" />
</assembly>
<assembly fullname="nunit.framework"/>
<assembly fullname="mscorlib">
<!-- If we don't preserve these, we can't run async unit tests on the platform -->
<type fullname="System.Runtime.CompilerServices.INotifyCompletion" />
<type fullname="System.Runtime.CompilerServices.TaskAwaiter" />
</assembly>
</linker>
55 changes: 19 additions & 36 deletions Xamarin.Forms.ControlGallery.Android/Tests/BackgroundColorTests.cs
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
using System;
using System.Collections;
using System.Collections.Generic;
using System.IO;
using System.Collections;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Android.Graphics.Drawables;
using NUnit.Framework;
using NUnit.Framework.Internal;
Expand Down Expand Up @@ -31,7 +28,7 @@ static IEnumerable TestCases

[Test, Category("BackgroundColor"), Category("Button")]
[Description("Button background color should match renderer background color")]
public void ButtonBackgroundColorConsistent()
public async Task ButtonBackgroundColorConsistent()
{
var button = new Button
{
Expand All @@ -40,17 +37,14 @@ public void ButtonBackgroundColorConsistent()
BackgroundColor = Color.AliceBlue
};

using (var nativeButton = GetNativeControl(button))
{
var expectedColor = button.BackgroundColor.ToAndroid();
Layout(button, nativeButton);
nativeButton.AssertColorAtCenter(expectedColor);
}
var expectedColor = button.BackgroundColor.ToAndroid();
var screenshot = await GetControlProperty(button, abutton => abutton.ToBitmap(), requiresLayout: true);
screenshot.AssertColorAtCenter(expectedColor);
}

[Test, Category("BackgroundColor"), Category("Button")]
[Description("ImageButton background color should match renderer background color")]
public void ImageButtonBackgroundColorConsistent()
public async Task ImageButtonBackgroundColorConsistent()
{
var button = new ImageButton
{
Expand All @@ -59,17 +53,14 @@ public void ImageButtonBackgroundColorConsistent()
BackgroundColor = Color.AliceBlue
};

using (var nativeButton = GetNativeControl(button))
{
var expectedColor = button.BackgroundColor.ToAndroid();
Layout(button, nativeButton);
nativeButton.AssertColorAtCenter(expectedColor);
}
var expectedColor = button.BackgroundColor.ToAndroid();
var screenshot = await GetControlProperty(button, abutton => abutton.ToBitmap(), requiresLayout: true);
screenshot.AssertColorAtCenter(expectedColor);
}

[Test, Category("BackgroundColor")]
[Description("Frame background color should match renderer background color")]
public void FrameBackgroundColorConsistent()
public async Task FrameBackgroundColorConsistent()
{
var frame = new Frame
{
Expand All @@ -78,27 +69,19 @@ public void FrameBackgroundColorConsistent()
BackgroundColor = Color.AliceBlue
};

using (var renderer = GetRenderer(frame))
{
var expectedColor = frame.BackgroundColor.ToAndroid();
var view = renderer.View;
Layout(frame, view);
view.AssertColorAtCenter(expectedColor);
}
var expectedColor = frame.BackgroundColor.ToAndroid();

var screenshot = await GetRendererProperty(frame, ver => ver.View.ToBitmap(), requiresLayout: true);
screenshot.AssertColorAtCenter(expectedColor);
}

[Test, Category("BackgroundColor"), TestCaseSource(nameof(TestCases))]
[Description("VisualElement background color should match renderer background color")]
public void BackgroundColorConsistent(VisualElement element)
public async Task BackgroundColorConsistent(VisualElement element)
{
using (var renderer = GetRenderer(element))
{
var expectedColor = element.BackgroundColor.ToAndroid();
var view = renderer.View;
var colorDrawable = view.Background as ColorDrawable;
var nativeColor = colorDrawable.Color;
Assert.That(nativeColor, Is.EqualTo(expectedColor));
}
var expectedColor = element.BackgroundColor.ToAndroid();
var nativeColor = await GetRendererProperty(element, ver => (ver.View.Background as ColorDrawable)?.Color);
Assert.That(nativeColor, Is.EqualTo(expectedColor));
}
}
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using NUnit.Framework;
using System.Threading.Tasks;
using NUnit.Framework;
using NUnit.Framework.Internal;
using Xamarin.Forms.CustomAttributes;

Expand All @@ -8,7 +9,7 @@ public class CollectionViewTests : PlatformTestFixture
{
[Issue(IssueTracker.Github, 9030, "[Bug] ClassNotFoundException when using snap points on API < 23")]
[Test(Description = "CollectionView with SnapPointsType set should not crash")]
public void SnapPointsDoNotCrashOnOlderAPIs()
public async Task SnapPointsDoNotCrashOnOlderAPIs()
{
var cv = new CollectionView();

Expand All @@ -19,7 +20,7 @@ public void SnapPointsDoNotCrashOnOlderAPIs()
cv.ItemsLayout = itemsLayout;

// Creating the renderer is enough to cause the ClassNotFoundException on older APIs
GetRenderer(cv).Dispose();
await Device.InvokeOnMainThreadAsync(() => { GetRenderer(cv).Dispose(); });
}
}
}
56 changes: 31 additions & 25 deletions Xamarin.Forms.ControlGallery.Android/Tests/CornerRadiusTests.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using NUnit.Framework;
using System.Threading.Tasks;
using NUnit.Framework;
using NUnit.Framework.Internal;
using Xamarin.Forms.CustomAttributes;
using Xamarin.Forms.Platform.Android;
Expand All @@ -9,7 +10,7 @@ namespace Xamarin.Forms.ControlGallery.Android.Tests
public class CornerRadiusTests : PlatformTestFixture
{
[Test, Category("CornerRadius"), Category("BoxView")]
public void BoxviewCornerRadius()
public async Task BoxviewCornerRadius()
{
var boxView = new BoxView
{
Expand All @@ -19,11 +20,11 @@ public void BoxviewCornerRadius()
BackgroundColor = Color.Red
};

CheckCornerRadius(boxView);
await CheckCornerRadius(boxView);
}

[Test, Category("CornerRadius"), Category("Button")]
public void ButtonCornerRadius()
public async Task ButtonCornerRadius()
{
var backgroundColor = Color.Red;

Expand All @@ -35,11 +36,11 @@ public void ButtonCornerRadius()
BackgroundColor = backgroundColor
};

CheckCornerRadius(button);
await CheckCornerRadius(button);
}

[Test, Category("CornerRadius"), Category("Frame")]
public void FrameCornerRadius()
public async Task FrameCornerRadius()
{
var backgroundColor = Color.Red;

Expand All @@ -51,11 +52,11 @@ public void FrameCornerRadius()
BackgroundColor = backgroundColor
};

CheckCornerRadius(frame);
await CheckCornerRadius(frame);
}

[Test, Category("CornerRadius"), Category("ImageButton")]
public void ImageButtonCornerRadius()
public async Task ImageButtonCornerRadius()
{
var backgroundColor = Color.Red;

Expand All @@ -69,28 +70,33 @@ public void ImageButtonCornerRadius()
BorderWidth = 2
};

CheckCornerRadius(button);
await CheckCornerRadius(button);
}

public void CheckCornerRadius(VisualElement visualElement)
public async Task CheckCornerRadius(VisualElement visualElement)
{
using (var renderer = GetRenderer(visualElement))
{
var view = renderer.View;
Layout(visualElement, view);
var screenshot = await Device.InvokeOnMainThreadAsync(() => {
using (var renderer = GetRenderer(visualElement))
{
var view = renderer.View;
Layout(visualElement, view);
// Need to parent the Frame for it to work on lower APIs (below Marshmallow)
ParentView(view);
// Need to parent the Frame for it to work on lower APIs (below Marshmallow)
ParentView(view);
var image = view.ToBitmap();
UnparentView(view);
// The corners should show the background color
view.AssertColorAtTopLeft(EmptyBackground)
.AssertColorAtTopRight(EmptyBackground)
.AssertColorAtBottomLeft(EmptyBackground)
.AssertColorAtBottomRight(EmptyBackground)
.AssertColorAtCenter(visualElement.BackgroundColor.ToAndroid());
return image;
}
});

UnparentView(view);
}
// The corners should show the background color
screenshot.AssertColorAtTopLeft(EmptyBackground)
.AssertColorAtTopRight(EmptyBackground)
.AssertColorAtBottomLeft(EmptyBackground)
.AssertColorAtBottomRight(EmptyBackground)
.AssertColorAtCenter(visualElement.BackgroundColor.ToAndroid());
}
}
}
29 changes: 16 additions & 13 deletions Xamarin.Forms.ControlGallery.Android/Tests/IsEnabledTests.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System.Collections;
using System.Threading.Tasks;
using NUnit.Framework;
using NUnit.Framework.Internal;
using Xamarin.Forms.CustomAttributes;
Expand Down Expand Up @@ -32,24 +33,26 @@ static IEnumerable TestCases

[Test, Category("IsEnabled"), TestCaseSource(nameof(TestCases))]
[Description("VisualElement enabled should match renderer enabled")]
public void EnabledConsistent(VisualElement element)
public async Task EnabledConsistent(VisualElement element)
{
using (var renderer = GetRenderer(element))
{
var expected = element.IsEnabled;
var nativeView = renderer.View;
await Device.InvokeOnMainThreadAsync(() => {
using (var renderer = GetRenderer(element))
{
var expected = element.IsEnabled;
var nativeView = renderer.View;
ParentView(nativeView);
ParentView(nativeView);
// Check the container control
Assert.That(renderer.View.Enabled, Is.EqualTo(expected));
// Check the container control
Assert.That(renderer.View.Enabled, Is.EqualTo(expected));
// Check the actual control
var control = GetNativeControl(element);
Assert.That(control.Enabled, Is.EqualTo(expected));
// Check the actual control
var control = GetNativeControl(element);
Assert.That(control.Enabled, Is.EqualTo(expected));
UnparentView(nativeView);
}
UnparentView(nativeView);
}
});
}
}
}
21 changes: 7 additions & 14 deletions Xamarin.Forms.ControlGallery.Android/Tests/IsVisibleTests.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System.Collections;
using System.Threading.Tasks;
using NUnit.Framework;
using NUnit.Framework.Internal;
using Xamarin.Forms.CustomAttributes;
Expand Down Expand Up @@ -32,22 +33,14 @@ static IEnumerable TestCases

[Test, Category("IsVisible"), TestCaseSource(nameof(TestCases))]
[Description("VisualElement visibility should match renderer visibility")]
public void VisibleConsistent(VisualElement element)
public async Task VisibleConsistent(VisualElement element)
{
using (var renderer = GetRenderer(element))
{
var expected = element.IsVisible
? global::Android.Views.ViewStates.Visible
: global::Android.Views.ViewStates.Invisible;

var nativeView = renderer.View;

ParentView(nativeView);
var expected = element.IsVisible
? global::Android.Views.ViewStates.Visible
: global::Android.Views.ViewStates.Invisible;

Assert.That(renderer.View.Visibility, Is.EqualTo(expected));

UnparentView(nativeView);
}
var actual = await GetRendererProperty(element, ver => ver.View.Visibility, requiresParent: true);
Assert.That(actual, Is.EqualTo(expected));
}
}
}
Loading

0 comments on commit 954cc8b

Please sign in to comment.