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

Commit efb4779

Browse files
authored
Add more platform tests (#9011)
* Add a platform test to check for Bugzilla 35738 * Delete the Bugzilla35738 UI test * Bold the start of fixtures Fix typo * Add some background color tests for iOS * Add test for iOS Button BackgroundColor * Remove changes to PerformanceTrackerRenderer * Split classes into files * Add UWP testing platform * Cache default font size * Run UWP tests on main thread * Use GetOrCreateRenderer * Split Test and Description attributes; clean up iOS background color tests * Opacity tests on iOS * Some background color tests for UWP * BackgroundColorTests for UWP for most controls * Shortcut key to get to platform tests on UWP * Button background color test for Android * BackgroundColor tests for Android controls * Opacity tests for Android * Ignore Opacity tests for iOS/Android (replaced by platform tests) * Remove unused empty BackgroundColor test * IsEnabled tests for Android * Consolidate basic VisualElement list * Apply categories for generate test cases * Consolidate element list * IsEnabled tests for iOS * Ignore tests covered by platform tests * Fix incorrect overrides * Rotation tests for Android * Rotation tests for iOS * Set UI test versions to Ignore * Rotation tests for UWP * Scale tests for iOS * ScaleX and ScaleY tests for Android * Android TranslationX and TranslationY tests * Ignore TranslationX/Y for manual review on Android * Ignore tests covered by platform tests * Add Sliders to the Android/iOS tests * Add Slider to UWP tests * Ignore tests for Slider that're already covered * Add ImageButton to the platform tests * Ignore duplicate tests for ImageButton * Add IsVisible tests for Android/iOS * Ignore IsVisible tests covered by platform tests * Fix usings for AndroidX * BoxView tests for Android * Add test counter to platform test console * BoxView tests for iOS * Ignore duplicate tests for BoxView * Frame tests for Android * Add Frame tests on iOS * Ignore duplicate tests * Add Button and Label text tests for Android/iOS * Ignore duplicate text test for Button * Add more controls to UWP tests; add IsEnabled tests for UWP * Add scale tests for UWP * Ignore UWP tests covered by platform tests * Mark Issue968 test as manual review * Replace 8269 UI test with platform test * Move 8682 from UI test to platform test * Mark Issue8004 test for manual review * Adding manual review attribute for Bugzilla29128 * Show bitmaps for failed color tests on Android; create BoxView CornerRadius test * Functional color-at-point tests * Clean up Android pixel checking code; add more CornerRadius tests * Fix NRE in FrameRenderer * Ignore Frame * Fix cross-thread dispose issues with StepperRenderer and SliderRenderer * Add tolerance for color comparisons * Parent Frame for older API versions * Remove assertion not supported before iOS 12 * Address fast label renderer, changes in BoxView, and a bug in Android fast button
1 parent 0eade95 commit efb4779

File tree

83 files changed

+3294
-294
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

83 files changed

+3294
-294
lines changed

Xamarin.Forms.ControlGallery.Android/Activity1.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@
2121
[assembly: Dependency (typeof (TestCloudService))]
2222
[assembly: ExportRenderer (typeof (DisposePage), typeof (DisposePageRenderer))]
2323
[assembly: ExportRenderer (typeof (DisposeLabel), typeof (DisposeLabelRenderer))]
24-
[assembly: ExportRenderer (typeof (CustomButton), typeof (CustomButtonRenderer))]
2524
[assembly: ExportEffect (typeof (BorderEffect), "BorderEffect")]
2625

2726
namespace Xamarin.Forms.ControlGallery.Android

Xamarin.Forms.ControlGallery.Android/CustomRenderers.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@
5757
[assembly: ExportRenderer(typeof(Issue7249Switch), typeof(Issue7249SwitchRenderer))]
5858
[assembly: ExportRenderer(typeof(Issue9360.Issue9360NavigationPage), typeof(Issue9360NavigationPageRenderer))]
5959
[assembly: ExportRenderer(typeof(Xamarin.Forms.Controls.GalleryPages.TwoPaneViewGalleries.HingeAngleLabel), typeof(HingeAngleLabelRenderer))]
60+
[assembly: ExportRenderer(typeof(Xamarin.Forms.Controls.Tests.TestClasses.CustomButton), typeof(CustomButtonRenderer))]
6061

6162
#if PRE_APPLICATION_CLASS
6263
#elif FORMS_APPLICATION_ACTIVITY
Lines changed: 122 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,122 @@
1+
using AView = Android.Views.View;
2+
using AColor = Android.Graphics.Color;
3+
using Android.Graphics;
4+
using System;
5+
using NUnit.Framework;
6+
using System.IO;
7+
8+
#if __ANDROID_29__
9+
#else
10+
using Android.Support.V7.Widget;
11+
#endif
12+
13+
namespace Xamarin.Forms.ControlGallery.Android.Tests
14+
{
15+
internal static class AssertionExtensions
16+
{
17+
public static string CreateColorAtPointError(this Bitmap bitmap, AColor expectedColor, int x, int y)
18+
{
19+
using (var ms = new MemoryStream())
20+
{
21+
bitmap.Compress(Bitmap.CompressFormat.Png, 0, ms);
22+
var imageAsString = Convert.ToBase64String(ms.ToArray());
23+
return $"Expected {expectedColor} at point {x},{y} in renderered view. This is what it looked like:<img>{imageAsString}</img>";
24+
}
25+
}
26+
27+
public static AColor ColorAtPoint(this Bitmap bitmap, int x, int y)
28+
{
29+
int pixel = bitmap.GetPixel(x, y);
30+
31+
int red = AColor.GetRedComponent(pixel);
32+
int blue = AColor.GetBlueComponent(pixel);
33+
int green = AColor.GetGreenComponent(pixel);
34+
35+
return AColor.Rgb(red, green, blue);
36+
}
37+
38+
public static Bitmap ToBitmap(this AView view)
39+
{
40+
var bitmap = Bitmap.CreateBitmap(view.Width, view.Height, Bitmap.Config.Argb8888);
41+
var canvas = new Canvas(bitmap);
42+
canvas.Save();
43+
canvas.Translate(0, 0);
44+
view.Draw(canvas);
45+
canvas.Restore();
46+
47+
return bitmap;
48+
}
49+
50+
public static Bitmap AssertColorAtPoint(this Bitmap bitmap, AColor expectedColor, int x, int y)
51+
{
52+
Assert.That(bitmap.ColorAtPoint(x, y), Is.EqualTo(expectedColor),
53+
() => bitmap.CreateColorAtPointError(expectedColor, x, y));
54+
55+
return bitmap;
56+
}
57+
58+
public static Bitmap AssertColorAtCenter(this Bitmap bitmap, AColor expectedColor)
59+
{
60+
return bitmap.AssertColorAtPoint(expectedColor, bitmap.Width / 2, bitmap.Height / 2);
61+
}
62+
63+
public static Bitmap AssertColorAtBottomLeft(this Bitmap bitmap, AColor expectedColor)
64+
{
65+
return bitmap.AssertColorAtPoint(expectedColor, 0, 0);
66+
}
67+
68+
public static Bitmap AssertColorAtBottomRight(this Bitmap bitmap, AColor expectedColor)
69+
{
70+
return bitmap.AssertColorAtPoint(expectedColor, bitmap.Width - 1, 0);
71+
}
72+
73+
public static Bitmap AssertColorAtTopLeft(this Bitmap bitmap, AColor expectedColor)
74+
{
75+
return bitmap.AssertColorAtPoint(expectedColor, 0, bitmap.Height - 1);
76+
}
77+
78+
public static Bitmap AssertColorAtTopRight(this Bitmap bitmap, AColor expectedColor)
79+
{
80+
return bitmap.AssertColorAtPoint(expectedColor, bitmap.Width - 1, bitmap.Height - 1);
81+
}
82+
83+
public static Bitmap AssertColorAtPoint(this AView view, AColor expectedColor, int x, int y)
84+
{
85+
var bitmap = view.ToBitmap();
86+
Assert.That(bitmap.ColorAtPoint(x, y), Is.EqualTo(expectedColor),
87+
() => bitmap.CreateColorAtPointError(expectedColor, x, y));
88+
89+
return bitmap;
90+
}
91+
92+
public static Bitmap AssertColorAtCenter(this AView view, AColor expectedColor)
93+
{
94+
var bitmap = view.ToBitmap();
95+
return bitmap.AssertColorAtCenter(expectedColor);
96+
}
97+
98+
public static Bitmap AssertColorAtBottomLeft(this AView view, AColor expectedColor)
99+
{
100+
var bitmap = view.ToBitmap();
101+
return bitmap.AssertColorAtBottomLeft(expectedColor);
102+
}
103+
104+
public static Bitmap AssertColorAtBottomRight(this AView view, AColor expectedColor)
105+
{
106+
var bitmap = view.ToBitmap();
107+
return bitmap.AssertColorAtBottomRight(expectedColor);
108+
}
109+
110+
public static Bitmap AssertColorAtTopLeft(this AView view, AColor expectedColor)
111+
{
112+
var bitmap = view.ToBitmap();
113+
return bitmap.AssertColorAtTopLeft(expectedColor);
114+
}
115+
116+
public static Bitmap AssertColorAtTopRight(this AView view, AColor expectedColor)
117+
{
118+
var bitmap = view.ToBitmap();
119+
return bitmap.AssertColorAtTopRight(expectedColor);
120+
}
121+
}
122+
}
Lines changed: 104 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,104 @@
1+
using System;
2+
using System.Collections;
3+
using System.Collections.Generic;
4+
using System.IO;
5+
using System.Linq;
6+
using System.Text;
7+
using Android.Graphics.Drawables;
8+
using NUnit.Framework;
9+
using NUnit.Framework.Internal;
10+
using Xamarin.Forms.CustomAttributes;
11+
using Xamarin.Forms.Platform.Android;
12+
13+
namespace Xamarin.Forms.ControlGallery.Android.Tests
14+
{
15+
[TestFixture]
16+
public class BackgroundColorTests : PlatformTestFixture
17+
{
18+
static IEnumerable TestCases
19+
{
20+
get
21+
{
22+
foreach (var element in BasicElements
23+
.Where(e => !(e is Button) && !(e is ImageButton) && !(e is Frame)))
24+
{
25+
element.BackgroundColor = Color.AliceBlue;
26+
yield return new TestCaseData(element)
27+
.SetCategory(element.GetType().Name);
28+
}
29+
}
30+
}
31+
32+
[Test, Category("BackgroundColor"), Category("Button")]
33+
[Description("Button background color should match renderer background color")]
34+
public void ButtonBackgroundColorConsistent()
35+
{
36+
var button = new Button
37+
{
38+
Text = " ",
39+
HeightRequest = 100, WidthRequest = 100,
40+
BackgroundColor = Color.AliceBlue
41+
};
42+
43+
using (var nativeButton = GetNativeControl(button))
44+
{
45+
var expectedColor = button.BackgroundColor.ToAndroid();
46+
Layout(button, nativeButton);
47+
nativeButton.AssertColorAtCenter(expectedColor);
48+
}
49+
}
50+
51+
[Test, Category("BackgroundColor"), Category("Button")]
52+
[Description("ImageButton background color should match renderer background color")]
53+
public void ImageButtonBackgroundColorConsistent()
54+
{
55+
var button = new ImageButton
56+
{
57+
HeightRequest = 100,
58+
WidthRequest = 100,
59+
BackgroundColor = Color.AliceBlue
60+
};
61+
62+
using (var nativeButton = GetNativeControl(button))
63+
{
64+
var expectedColor = button.BackgroundColor.ToAndroid();
65+
Layout(button, nativeButton);
66+
nativeButton.AssertColorAtCenter(expectedColor);
67+
}
68+
}
69+
70+
[Test, Category("BackgroundColor")]
71+
[Description("Frame background color should match renderer background color")]
72+
public void FrameBackgroundColorConsistent()
73+
{
74+
var frame = new Frame
75+
{
76+
HeightRequest = 100,
77+
WidthRequest = 100,
78+
BackgroundColor = Color.AliceBlue
79+
};
80+
81+
using (var renderer = GetRenderer(frame))
82+
{
83+
var expectedColor = frame.BackgroundColor.ToAndroid();
84+
var view = renderer.View;
85+
Layout(frame, view);
86+
view.AssertColorAtCenter(expectedColor);
87+
}
88+
}
89+
90+
[Test, Category("BackgroundColor"), TestCaseSource(nameof(TestCases))]
91+
[Description("VisualElement background color should match renderer background color")]
92+
public void BackgroundColorConsistent(VisualElement element)
93+
{
94+
using (var renderer = GetRenderer(element))
95+
{
96+
var expectedColor = element.BackgroundColor.ToAndroid();
97+
var view = renderer.View;
98+
var colorDrawable = view.Background as ColorDrawable;
99+
var nativeColor = colorDrawable.Color;
100+
Assert.That(nativeColor, Is.EqualTo(expectedColor));
101+
}
102+
}
103+
}
104+
}
Lines changed: 96 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,96 @@
1+
using NUnit.Framework;
2+
using NUnit.Framework.Internal;
3+
using Xamarin.Forms.CustomAttributes;
4+
using Xamarin.Forms.Platform.Android;
5+
6+
namespace Xamarin.Forms.ControlGallery.Android.Tests
7+
{
8+
[TestFixture]
9+
public class CornerRadiusTests : PlatformTestFixture
10+
{
11+
[Test, Category("CornerRadius"), Category("BoxView")]
12+
public void BoxviewCornerRadius()
13+
{
14+
var boxView = new BoxView
15+
{
16+
HeightRequest = 100,
17+
WidthRequest = 200,
18+
CornerRadius = 15,
19+
BackgroundColor = Color.Red
20+
};
21+
22+
CheckCornerRadius(boxView);
23+
}
24+
25+
[Test, Category("CornerRadius"), Category("Button")]
26+
public void ButtonCornerRadius()
27+
{
28+
var backgroundColor = Color.Red;
29+
30+
var button = new Button
31+
{
32+
HeightRequest = 100,
33+
WidthRequest = 200,
34+
CornerRadius = 15,
35+
BackgroundColor = backgroundColor
36+
};
37+
38+
CheckCornerRadius(button);
39+
}
40+
41+
[Test, Category("CornerRadius"), Category("Frame")]
42+
public void FrameCornerRadius()
43+
{
44+
var backgroundColor = Color.Red;
45+
46+
var frame = new Frame
47+
{
48+
HeightRequest = 100,
49+
WidthRequest = 200,
50+
CornerRadius = 15,
51+
BackgroundColor = backgroundColor
52+
};
53+
54+
CheckCornerRadius(frame);
55+
}
56+
57+
[Test, Category("CornerRadius"), Category("ImageButton")]
58+
public void ImageButtonCornerRadius()
59+
{
60+
var backgroundColor = Color.Red;
61+
62+
var button = new ImageButton
63+
{
64+
HeightRequest = 100,
65+
WidthRequest = 200,
66+
CornerRadius = 15,
67+
BackgroundColor = backgroundColor,
68+
BorderColor = Color.Black,
69+
BorderWidth = 2
70+
};
71+
72+
CheckCornerRadius(button);
73+
}
74+
75+
public void CheckCornerRadius(VisualElement visualElement)
76+
{
77+
using (var renderer = GetRenderer(visualElement))
78+
{
79+
var view = renderer.View;
80+
Layout(visualElement, view);
81+
82+
// Need to parent the Frame for it to work on lower APIs (below Marshmallow)
83+
ParentView(view);
84+
85+
// The corners should show the background color
86+
view.AssertColorAtTopLeft(EmptyBackground)
87+
.AssertColorAtTopRight(EmptyBackground)
88+
.AssertColorAtBottomLeft(EmptyBackground)
89+
.AssertColorAtBottomRight(EmptyBackground)
90+
.AssertColorAtCenter(visualElement.BackgroundColor.ToAndroid());
91+
92+
UnparentView(view);
93+
}
94+
}
95+
}
96+
}

0 commit comments

Comments
 (0)