Skip to content

Commit

Permalink
Merge branch 'main' into uitest-lifecycle-actions
Browse files Browse the repository at this point in the history
  • Loading branch information
jsuarezruiz committed Nov 30, 2023
2 parents a5a24ac + 1269d81 commit e26a20e
Show file tree
Hide file tree
Showing 19 changed files with 216 additions and 62 deletions.
7 changes: 4 additions & 3 deletions eng/devices/ios.cake
Expand Up @@ -158,8 +158,8 @@ Task("uitest-build")
{
args
.Append("/p:BuildIpa=true")
.Append("/p:RuntimeIdentifier=ios-arm64")
.Append("/bl:" + binlog);
.Append("/bl:" + binlog)
.Append("/tl");
// if we building for a device
if(TEST_DEVICE.ToLower().Contains("device"))
Expand Down Expand Up @@ -419,6 +419,7 @@ void InstallIpa(string testApp, string testAppPackageName, string testDevice, st

Information("The platform version to run tests: {0}", iosVersionToRun);
SetEnvironmentVariable("DEVICE_UDID", deviceToRun);
SetEnvironmentVariable("DEVICE_NAME", DEVICE_NAME);
SetEnvironmentVariable("PLATFORM_VERSION", iosVersionToRun);
}
}
Expand Down Expand Up @@ -498,4 +499,4 @@ void GetDevices(string version)
break;
}
}
}
}
44 changes: 44 additions & 0 deletions src/Controls/samples/Controls.Sample.UITests/Issues/Issue18457.cs
@@ -0,0 +1,44 @@
using System;
using System.Threading.Tasks;
using Microsoft.Maui;
using Microsoft.Maui.Controls;
using Microsoft.Maui.Graphics;

namespace Maui.Controls.Sample.Issues;

[Issue(IssueTracker.Github, 18457, "Adding/Removing Pages From Removed TabbedPage Causes Crash")]
public class Issue18457 : TestContentPage
{
bool pagePushed = false;
TabbedPage _tabbedPage = new TabbedPage();
protected override void Init()
{
_tabbedPage.Children.Add(new ContentPage() { Title = "tab 1"});
_tabbedPage.Children.Add(new ContentPage() { Title = "tab 2"});
_tabbedPage.Children.Add(new ContentPage() { Title = "tab 3"});
}

protected override async void OnNavigatedTo(NavigatedToEventArgs args)
{
base.OnNavigatedTo(args);

if (!pagePushed)
{
pagePushed = true;
await Navigation.PushAsync(_tabbedPage);
await Navigation.PopAsync();
_tabbedPage.Children.Add(new ContentPage());
_tabbedPage.Children[0].Background = SolidColorBrush.Purple;
_tabbedPage.Children[0].Title = "update title";
_tabbedPage.Children[0].IconImageSource = "dotnet_bot.png";
await Task.Yield();
Content = new VerticalStackLayout(){
Children =
{
new Label() { Text = "This test pushes and pops a TabbedPage, and then modifies the Children on the popped page."},
new Label() { Text = "If the app doesn't crash, this test has passed.", AutomationId = "Success" }
}
};
}
}
}
Expand Up @@ -242,7 +242,7 @@ void InvalidateMeasureIfContentSizeChanged()

internal Size? GetSize()
{
if (_emptyViewDisplayed)
if (_emptyViewDisplayed)
{
return _emptyUIView.Frame.Size.ToSize();
}
Expand Down
Expand Up @@ -564,7 +564,7 @@ static void ForceScrollToLastItem(UICollectionView collectionView, ItemsLayout i

public override bool ShouldInvalidateLayoutForBoundsChange(CGRect newBounds)
{
if(newBounds.Size == _currentSize)
if (newBounds.Size == _currentSize)
{
return base.ShouldInvalidateLayoutForBoundsChange(newBounds);
}
Expand Down
4 changes: 2 additions & 2 deletions src/Controls/src/Core/Handlers/Items/iOS/SizeExtensions.cs
Expand Up @@ -5,11 +5,11 @@

namespace Microsoft.Maui.Controls.Handlers.Items
{
internal static class SizeExtensions
internal static class SizeExtensions
{
const double Tolerance = 0.001;

public static bool IsCloseTo(this CGSize sizeA, CGSize sizeB)
public static bool IsCloseTo(this CGSize sizeA, CGSize sizeB)
{
if (Math.Abs(sizeA.Height - sizeB.Height) > Tolerance)
{
Expand Down
5 changes: 3 additions & 2 deletions src/Controls/src/Core/Platform/Android/TabbedPageManager.cs
Expand Up @@ -114,8 +114,9 @@ internal void SetElement(TabbedPage tabbedPage)
var activity = _context.GetActivity();
var themeContext = activity;

if (Element != null)
if (Element is not null)
{
Element.InternalChildren.ForEach(page => TeardownPage(page as Page));
((IPageController)Element).InternalChildren.CollectionChanged -= OnChildrenCollectionChanged;
Element.Appearing -= OnTabbedPageAppearing;
Element.Disappearing -= OnTabbedPageDisappearing;
Expand All @@ -124,7 +125,7 @@ internal void SetElement(TabbedPage tabbedPage)
}

Element = tabbedPage;
if (Element != null)
if (Element is not null)
{
_viewPager.LayoutChange += OnLayoutChanged;
Element.Appearing += OnTabbedPageAppearing;
Expand Down
Expand Up @@ -65,7 +65,7 @@ public override CGSize GetSizeForItem(UICollectionView collectionView, UICollect
// code changes don't break the cache again, and the only observable outside consequence is that the scrolling
// for the CollectionView becomes "janky". We don't want to rely entirely on human perception of "jankiness" to
// catch this problem.

// If the size comes back as EstimatedItemSize, we'll know that the actual value was not found in the cache.

if (_trackCacheMisses && itemSize == flowLayout.EstimatedItemSize)
Expand Down Expand Up @@ -96,7 +96,8 @@ public async Task EnsureCellSizesAreCached()
HeightRequest = 654.66666
};

var template = new DataTemplate(() => {
var template = new DataTemplate(() =>
{
var content = new Label() { Text = "Howdy" };
content.SetBinding(VisualElement.HeightRequestProperty, new Binding(nameof(VisualElement.HeightRequest)));
return content;
Expand Down Expand Up @@ -128,7 +129,7 @@ public async Task EnsureCellSizesAreCached()
collectionView.ScrollTo(0);
await Task.Delay(1000);
if (handler.Controller is CacheTestItemsViewController controller
if (handler.Controller is CacheTestItemsViewController controller
&& controller.DelegateFlowLayout is CacheMissCountingDelegate cacheMissCounter)
{
// Different screen sizes and timings mean this isn't 100% predictable. But we can work out some conditions
Expand Down
12 changes: 8 additions & 4 deletions src/Controls/tests/DeviceTests/Elements/Shape/ShapeTests.cs
Expand Up @@ -46,7 +46,8 @@ public async Task ShapeUpdatesBrushCorrectly(uint color)
Y2 = 100,
HeightRequest = 100,
WidthRequest = 100,
Stroke = Colors.Black
Stroke = Colors.Black,
StrokeThickness = 4
};

var button = new Button()
Expand All @@ -73,8 +74,13 @@ public async Task ShapeUpdatesBrushCorrectly(uint color)

await InvokeOnMainThreadAsync(async () =>
{
await CreateHandlerAndAddToWindow<LineHandler>(line, (handler) =>
await CreateHandlerAndAddToWindow<LineHandler>(line, async (handler) =>
{
await AssertionExtensions.Wait(
() =>
handler.PlatformView is not null &&
handler.PlatformView.Drawable is not null);
var mauiShapeView = handler.PlatformView;
Assert.NotNull(mauiShapeView);
var shapeDrawable = mauiShapeView.Drawable as ShapeDrawable;
Expand All @@ -84,8 +90,6 @@ public async Task ShapeUpdatesBrushCorrectly(uint color)
var shapeStroke = shape.Stroke as SolidColorBrush;
Assert.Equal(expected, shapeStroke?.Color);
return Task.CompletedTask;
});
});
}
Expand Down
6 changes: 6 additions & 0 deletions src/Controls/tests/DeviceTests/Memory/MemoryTests.cs
Expand Up @@ -91,6 +91,12 @@ public async Task HandlerDoesNotLeak(Type type)
return;
#endif

#if IOS
// NOTE: skip certain controls on older iOS devices
if (type == typeof (WebView) && !OperatingSystem.IsIOSVersionAtLeast(16))
return;
#endif

WeakReference viewReference = null;
WeakReference platformViewReference = null;
WeakReference handlerReference = null;
Expand Down
Expand Up @@ -22,15 +22,15 @@ protected override void NavigateToGallery()
[Test]
public void Simple([Values] Test.InputTransparency test) => RunTest(test.ToString());

[Test]
[Combinatorial]
public void Matrix([Values] bool rootTrans, [Values] bool rootCascade, [Values] bool nestedTrans, [Values] bool nestedCascade, [Values] bool trans)
{
var (clickable, passthru) = Test.InputTransparencyMatrix.States[(rootTrans, rootCascade, nestedTrans, nestedCascade, trans)];
var key = Test.InputTransparencyMatrix.GetKey(rootTrans, rootCascade, nestedTrans, nestedCascade, trans, clickable, passthru);
// [Test]
// [Combinatorial]
// public void Matrix([Values] bool rootTrans, [Values] bool rootCascade, [Values] bool nestedTrans, [Values] bool nestedCascade, [Values] bool trans)
// {
// var (clickable, passthru) = Test.InputTransparencyMatrix.States[(rootTrans, rootCascade, nestedTrans, nestedCascade, trans)];
// var key = Test.InputTransparencyMatrix.GetKey(rootTrans, rootCascade, nestedTrans, nestedCascade, trans, clickable, passthru);

RunTest(key, clickable, passthru);
}
// RunTest(key, clickable, passthru);
// }

void RunTest(string test, bool? clickable = null, bool? passthru = null)
{
Expand Down
4 changes: 2 additions & 2 deletions src/Core/src/Platform/iOS/MauiUIContextMenuInteraction.cs
Expand Up @@ -19,13 +19,13 @@ class MauiUIContextMenuInteraction : UIContextMenuInteraction
readonly IUIContextMenuInteractionDelegate? _uiContextMenuInteractionDelegate;

public MauiUIContextMenuInteraction(IElementHandler handler)
: base(CreateDelegate (out var del))
: base(CreateDelegate(out var del))
{
_uiContextMenuInteractionDelegate = del;
_handler = new WeakReference<IElementHandler>(handler);
}

static IUIContextMenuInteractionDelegate CreateDelegate (out IUIContextMenuInteractionDelegate del) =>
static IUIContextMenuInteractionDelegate CreateDelegate(out IUIContextMenuInteractionDelegate del) =>
del = new FlyoutUIContextMenuInteractionDelegate();

public UIContextMenuConfiguration? GetConfigurationForMenu()
Expand Down
39 changes: 11 additions & 28 deletions src/Core/src/Platform/iOS/MauiWebViewNavigationDelegate.cs
Expand Up @@ -26,7 +26,9 @@ public MauiWebViewNavigationDelegate(IWebViewHandler handler)
public void DidFinishNavigation(WKWebView webView, WKNavigation navigation)
{
var handler = Handler;
if (handler == null)
var virtualView = handler?.VirtualView;

if (handler == null || virtualView == null)
return;

handler.PlatformView?.UpdateCanGoBackForward(handler.VirtualView);
Expand All @@ -39,11 +41,6 @@ public void DidFinishNavigation(WKWebView webView, WKNavigation navigation)
if (url == $"file://{NSBundle.MainBundle.BundlePath}/")
return;

var virtualView = handler.VirtualView;

if (virtualView == null)
return;

virtualView.Navigated(_lastEvent, url, WebNavigationResult.Success);

handler.PlatformView?.UpdateCanGoBackForward(virtualView);
Expand All @@ -53,16 +50,13 @@ public void DidFinishNavigation(WKWebView webView, WKNavigation navigation)
public void DidFailNavigation(WKWebView webView, WKNavigation navigation, NSError error)
{
var handler = Handler;
if (handler == null)
var virtualView = handler?.VirtualView;

if (handler == null || virtualView == null)
return;

var url = GetCurrentUrl();

var virtualView = handler.VirtualView;

if (virtualView == null)
return;

virtualView.Navigated(_lastEvent, url, WebNavigationResult.Failure);

handler.PlatformView?.UpdateCanGoBackForward(virtualView);
Expand All @@ -72,29 +66,26 @@ public void DidFailNavigation(WKWebView webView, WKNavigation navigation, NSErro
public void DidFailProvisionalNavigation(WKWebView webView, WKNavigation navigation, NSError error)
{
var handler = Handler;
if (handler == null)
var virtualView = handler?.VirtualView;

if (handler == null || virtualView == null)
return;

var url = GetCurrentUrl();

var virtualView = handler.VirtualView;

if (virtualView == null)
return;

virtualView.Navigated(_lastEvent, url, WebNavigationResult.Failure);

handler.PlatformView?.UpdateCanGoBackForward(virtualView);

}

// https://stackoverflow.com/questions/37509990/migrating-from-uiwebview-to-wkwebview
[Export("webView:decidePolicyForNavigationAction:decisionHandler:")]
public void DecidePolicy(WKWebView webView, WKNavigationAction navigationAction, Action<WKNavigationActionPolicy> decisionHandler)
{
var handler = Handler;
var virtualView = handler?.VirtualView;

if (handler == null)
if (handler == null || virtualView == null)
{
decisionHandler.Invoke(WKNavigationActionPolicy.Cancel);
return;
Expand Down Expand Up @@ -131,14 +122,6 @@ public void DecidePolicy(WKWebView webView, WKNavigationAction navigationAction,

_lastEvent = navEvent;

var virtualView = handler.VirtualView;

if (virtualView == null)
{
decisionHandler.Invoke(WKNavigationActionPolicy.Cancel);
return;
}

var request = navigationAction.Request;
var lastUrl = request.Url.ToString();

Expand Down
Expand Up @@ -58,5 +58,11 @@
<array>
<string>mailto</string>
</array>
<key>NSCalendarsFullAccessUsageDescription</key>
<string>Full access to the Calendar is needed to sign you up for parties!</string>
<key>NSCalendarsWriteOnlyAccessUsageDescription</key>
<string>Just writing events to the Calendar, nothing to see here.</string>
<key>NSRemindersFullAccessUsageDescription</key>
<string>Just so you will remember</string>
</dict>
</plist>
8 changes: 7 additions & 1 deletion src/Essentials/samples/Samples/Platforms/iOS/Info.plist
Expand Up @@ -45,7 +45,7 @@
<key>NSLocationAlwaysUsageDescription</key>
<string>Get Location</string>
<key>NSPhotoLibraryAddUsageDescription</key>
<string>Add Photos</string>
<string>Add Photos</string>
<key>NSPhotoLibraryUsageDescription</key>
<string>Pick Photos</string>
<key>NSMicrophoneUsageDescription</key>
Expand All @@ -58,5 +58,11 @@
<array>
<string>mailto</string>
</array>
<key>NSCalendarsFullAccessUsageDescription</key>
<string>Full access to the Calendar is needed to sign you up for parties!</string>
<key>NSCalendarsWriteOnlyAccessUsageDescription</key>
<string>Just writing events to the Calendar, nothing to see here.</string>
<key>NSRemindersFullAccessUsageDescription</key>
<string>Just so you will remember</string>
</dict>
</plist>

0 comments on commit e26a20e

Please sign in to comment.