Skip to content

Commit 83acf53

Browse files
authored
Merge branch 'main' into FullScreenEvents
2 parents 779d8d9 + c3c79ba commit 83acf53

37 files changed

+346
-205
lines changed

src/CommunityToolkit.Maui.Analyzers.UnitTests/CommunityToolkit.Maui.Analyzers.UnitTests.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
<!--Fix vulnerabilities-->
2929
<PackageReference Include="System.Formats.Asn1" Version="9.0.5" />
3030
<PackageReference Include="System.Net.Http" Version="4.3.4" />
31+
<PackageReference Include="System.Private.Uri" Version="4.3.2" />
3132
<PackageReference Include="System.Text.RegularExpressions" Version="4.3.1" />
3233
</ItemGroup>
3334

src/CommunityToolkit.Maui.Camera/Primitives/CameraViewDefaults.shared.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,4 +61,4 @@ internal static ICommand CreateStopCameraPreviewCommand(BindableObject bindable)
6161
var cameraView = (CameraView)bindable;
6262
return new Command(_ => cameraView.StopCameraPreview());
6363
}
64-
}
64+
}

src/CommunityToolkit.Maui.MediaElement/Views/MauiMediaElement.android.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -176,8 +176,8 @@ void SetSystemBarsVisibility()
176176
| SystemUiFlags.Fullscreen
177177
| SystemUiFlags.Immersive;
178178
}
179-
180-
if(windowInsetsControllerCompat is not null)
179+
180+
if (windowInsetsControllerCompat is not null)
181181
{
182182
windowInsetsControllerCompat.Hide(barTypes);
183183
windowInsetsControllerCompat.SystemBarsBehavior = WindowInsetsControllerCompat.BehaviorShowTransientBarsBySwipe;
@@ -198,12 +198,12 @@ void SetSystemBarsVisibility()
198198
currentWindow.DecorView.SystemUiFlags = (SystemUiFlags)defaultSystemUiVisibility;
199199
}
200200

201-
if(windowInsetsControllerCompat is not null)
201+
if (windowInsetsControllerCompat is not null)
202202
{
203203
windowInsetsControllerCompat.Show(barTypes);
204204
windowInsetsControllerCompat.SystemBarsBehavior = WindowInsetsControllerCompat.BehaviorDefault;
205205
}
206-
206+
207207
WindowCompat.SetDecorFitsSystemWindows(currentWindow, true);
208208
}
209209
}

src/CommunityToolkit.Maui.UnitTests/BaseHandlerTest.cs renamed to src/CommunityToolkit.Maui.UnitTests/BaseViewTest.cs

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,13 @@
11
using CommunityToolkit.Maui.Core;
2-
using CommunityToolkit.Maui.Services;
32
using CommunityToolkit.Maui.UnitTests.Mocks;
43
using CommunityToolkit.Maui.UnitTests.Services;
54
using FluentAssertions;
6-
using Xunit;
75

86
namespace CommunityToolkit.Maui.UnitTests;
97

10-
public abstract class BaseHandlerTest : BaseTest
8+
public abstract class BaseViewTest : BaseTest
119
{
12-
protected BaseHandlerTest()
10+
protected BaseViewTest()
1311
{
1412
InitializeServicesAndSetMockApplication(out var serviceProvider);
1513
ServiceProvider = serviceProvider;
@@ -77,10 +75,10 @@ static void InitializeServicesAndSetMockApplication(out IServiceProvider service
7775

7876
#region Register Services for PopupServiceTests
7977

80-
var mockPageViewModel = new MockPageViewModel();
81-
var mockPopup = new MockSelfClosingPopup(mockPageViewModel, new());
78+
appBuilder.Services.AddTransientPopup<LongLivedSelfClosingPopup, LongLivedMockPageViewModel>();
79+
appBuilder.Services.AddTransientPopup<ShortLivedSelfClosingPopup, ShortLivedMockPageViewModel>();
80+
appBuilder.Services.AddTransientPopup<GarbageCollectionHeavySelfClosingPopup, MockPageViewModel>();
8281

83-
PopupService.AddPopup(mockPopup, mockPageViewModel, appBuilder.Services, ServiceLifetime.Transient);
8482
appBuilder.Services.AddTransientPopup<MockPopup>();
8583
#endregion
8684

src/CommunityToolkit.Maui.UnitTests/Converters/BaseConverterTest.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ public void InvalidConvertBackValue_ShouldSuppressExceptionsInConverters_ShouldR
4545
}
4646
}
4747

48-
public abstract class ConverterTest<TConverter> : BaseHandlerTest where TConverter : ICommunityToolkitValueConverter, new()
48+
public abstract class ConverterTest<TConverter> : BaseViewTest where TConverter : ICommunityToolkitValueConverter, new()
4949
{
5050
[Fact]
5151
public void InvalidConvertValue_ShouldThrowException()

src/CommunityToolkit.Maui.UnitTests/Essentials/AppThemeTests.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66
namespace CommunityToolkit.Maui.UnitTests.Essentials;
77

8-
public class AppThemeTests : BaseHandlerTest
8+
public class AppThemeTests : BaseViewTest
99
{
1010
readonly Label label = new();
1111
readonly Window window;

src/CommunityToolkit.Maui.UnitTests/Extensions/PopupExtensionsTests.cs

Lines changed: 50 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99

1010
namespace CommunityToolkit.Maui.UnitTests.Extensions;
1111

12-
public class PopupExtensionsTests : BaseHandlerTest
12+
public class PopupExtensionsTests : BaseViewTest
1313
{
1414
const string shellParameterViewModelTextValue = "Hello World";
1515
static readonly Color shellParameterBackgroundColorValue = Colors.Green;
@@ -124,7 +124,7 @@ public async Task ClosePopupT_NullNavigation_ShouldThrowArgumentNullException()
124124
public async Task ShowPopupAsync_WithPopupType_ShowsPopupAndClosesPopup()
125125
{
126126
// Arrange
127-
var selfClosingPopup = ServiceProvider.GetRequiredService<MockSelfClosingPopup>() ?? throw new InvalidOperationException();
127+
var selfClosingPopup = ServiceProvider.GetRequiredService<ShortLivedSelfClosingPopup>() ?? throw new InvalidOperationException();
128128

129129
// Act
130130
navigation.ShowPopup(selfClosingPopup);
@@ -228,7 +228,7 @@ public void ShowPopupAsync_Shell_WithViewType_ShowsPopup()
228228
public async Task ShowPopupAsync_AwaitingShowPopupAsync_EnsurePreviousPopupClosed()
229229
{
230230
// Arrange
231-
var selfClosingPopup = ServiceProvider.GetRequiredService<MockSelfClosingPopup>() ?? throw new InvalidOperationException();
231+
var selfClosingPopup = ServiceProvider.GetRequiredService<ShortLivedSelfClosingPopup>() ?? throw new InvalidOperationException();
232232

233233
// Act
234234
await navigation.ShowPopupAsync<object?>(selfClosingPopup, PopupOptions.Empty, TestContext.Current.CancellationToken);
@@ -249,7 +249,7 @@ public async Task ShowPopupAsync_Shell_AwaitingShowPopupAsync_EnsurePreviousPopu
249249
Application.Current.Windows[0].Page = shell;
250250

251251
var shellNavigation = Shell.Current.Navigation;
252-
var selfClosingPopup = ServiceProvider.GetRequiredService<MockSelfClosingPopup>() ?? throw new InvalidOperationException();
252+
var selfClosingPopup = ServiceProvider.GetRequiredService<ShortLivedSelfClosingPopup>() ?? throw new InvalidOperationException();
253253

254254
// Act
255255
await shell.ShowPopupAsync<object?>(selfClosingPopup, PopupOptions.Empty, shellParameters, TestContext.Current.CancellationToken);
@@ -264,7 +264,7 @@ public async Task ShowPopupAsync_Shell_AwaitingShowPopupAsync_EnsurePreviousPopu
264264
public void ShowPopup_NavigationModalStackCountIncreases()
265265
{
266266
// Arrange
267-
var selfClosingPopup = ServiceProvider.GetRequiredService<MockSelfClosingPopup>() ?? throw new InvalidOperationException();
267+
var selfClosingPopup = ServiceProvider.GetRequiredService<ShortLivedSelfClosingPopup>() ?? throw new InvalidOperationException();
268268
Assert.Empty(navigation.ModalStack);
269269

270270
// Act
@@ -345,7 +345,7 @@ public void ShowPopupWithView_Shell_NavigationModalStackCountIncreases()
345345
public void ShowPopup_MultiplePopupsDisplayed()
346346
{
347347
// Arrange
348-
var selfClosingPopup = ServiceProvider.GetRequiredService<MockSelfClosingPopup>() ?? throw new InvalidOperationException();
348+
var selfClosingPopup = ServiceProvider.GetRequiredService<ShortLivedSelfClosingPopup>() ?? throw new InvalidOperationException();
349349

350350
// Act
351351
navigation.ShowPopup(selfClosingPopup, PopupOptions.Empty);
@@ -359,7 +359,7 @@ public void ShowPopup_MultiplePopupsDisplayed()
359359
public void ShowPopup_Shell_MultiplePopupsDisplayed()
360360
{
361361
// Arrange
362-
var selfClosingPopup = ServiceProvider.GetRequiredService<MockSelfClosingPopup>() ?? throw new InvalidOperationException();
362+
var selfClosingPopup = ServiceProvider.GetRequiredService<ShortLivedSelfClosingPopup>() ?? throw new InvalidOperationException();
363363
var shell = new Shell();
364364
shell.Items.Add(new MockPage(new MockPageViewModel()));
365365

@@ -421,7 +421,7 @@ public void ShowPopupAsync_WithCustomOptions_AppliesOptions()
421421
// Arrange
422422
var onTappingOutsideOfPopup = () => { };
423423

424-
var selfClosingPopup = ServiceProvider.GetRequiredService<MockSelfClosingPopup>() ?? throw new InvalidOperationException();
424+
var selfClosingPopup = ServiceProvider.GetRequiredService<ShortLivedSelfClosingPopup>() ?? throw new InvalidOperationException();
425425
var options = new PopupOptions
426426
{
427427
PageOverlayColor = Colors.Red,
@@ -493,7 +493,7 @@ public void ShowPopupAsync_Shell_WithCustomOptions_AppliesOptions()
493493
var shellNavigation = Shell.Current.Navigation;
494494
var onTappingOutsideOfPopup = () => { };
495495

496-
var selfClosingPopup = ServiceProvider.GetRequiredService<MockSelfClosingPopup>() ?? throw new InvalidOperationException();
496+
var selfClosingPopup = ServiceProvider.GetRequiredService<ShortLivedSelfClosingPopup>() ?? throw new InvalidOperationException();
497497
var options = new PopupOptions
498498
{
499499
PageOverlayColor = Colors.Red,
@@ -713,7 +713,7 @@ public void ShowPopupAsyncWithView_Shell_WithCustomOptions_AppliesOptions()
713713
public async Task ShowPopupAsync_CancellationTokenExpired()
714714
{
715715
// Arrange
716-
var selfClosingPopup = ServiceProvider.GetRequiredService<MockSelfClosingPopup>() ?? throw new InvalidOperationException();
716+
var selfClosingPopup = ServiceProvider.GetRequiredService<ShortLivedSelfClosingPopup>() ?? throw new InvalidOperationException();
717717
var cts = new CancellationTokenSource(TimeSpan.FromMilliseconds(1));
718718

719719
// Act
@@ -734,7 +734,7 @@ public async Task ShowPopupAsync_Shell_CancellationTokenExpired()
734734
Application.Current.Windows[0].Page = shell;
735735

736736
var shellNavigation = Shell.Current.Navigation;
737-
var selfClosingPopup = ServiceProvider.GetRequiredService<MockSelfClosingPopup>() ?? throw new InvalidOperationException();
737+
var selfClosingPopup = ServiceProvider.GetRequiredService<ShortLivedSelfClosingPopup>() ?? throw new InvalidOperationException();
738738

739739
var cts = new CancellationTokenSource(TimeSpan.FromMilliseconds(1));
740740

@@ -788,7 +788,7 @@ public async Task ShowPopupAsyncWithView_Shell_CancellationTokenExpired()
788788
public async Task ShowPopupAsync_CancellationTokenCanceled()
789789
{
790790
// Arrange
791-
var selfClosingPopup = ServiceProvider.GetRequiredService<MockSelfClosingPopup>() ?? throw new InvalidOperationException();
791+
var selfClosingPopup = ServiceProvider.GetRequiredService<ShortLivedSelfClosingPopup>() ?? throw new InvalidOperationException();
792792
var cts = new CancellationTokenSource(TimeSpan.FromMilliseconds(1));
793793

794794
// Act
@@ -809,7 +809,7 @@ public async Task ShowPopupAsync_Shell_CancellationTokenCanceled()
809809
Application.Current.Windows[0].Page = shell;
810810

811811
var shellNavigation = Shell.Current.Navigation;
812-
var selfClosingPopup = ServiceProvider.GetRequiredService<MockSelfClosingPopup>() ?? throw new InvalidOperationException();
812+
var selfClosingPopup = ServiceProvider.GetRequiredService<ShortLivedSelfClosingPopup>() ?? throw new InvalidOperationException();
813813

814814
var cts = new CancellationTokenSource(TimeSpan.FromMilliseconds(1));
815815

@@ -863,15 +863,15 @@ public async Task ShowPopupAsyncWithView_Shell_CancellationTokenCanceled()
863863
public async Task ShowPopupAsync_ShouldValidateProperBindingContext()
864864
{
865865
// Arrange
866-
var selfClosingPopup = ServiceProvider.GetRequiredService<MockSelfClosingPopup>() ?? throw new InvalidOperationException();
867-
var popupInstance = ServiceProvider.GetRequiredService<MockSelfClosingPopup>();
868-
var popupViewModel = ServiceProvider.GetRequiredService<MockPageViewModel>();
866+
var selfClosingPopup = ServiceProvider.GetRequiredService<ShortLivedSelfClosingPopup>() ?? throw new InvalidOperationException();
867+
var popupInstance = ServiceProvider.GetRequiredService<ShortLivedSelfClosingPopup>();
869868

870869
// Act
871870
await navigation.ShowPopupAsync<object?>(selfClosingPopup, PopupOptions.Empty, TestContext.Current.CancellationToken);
872871

873872
// Assert
874-
Assert.Same(popupInstance.BindingContext, popupViewModel);
873+
Assert.NotNull(popupInstance.BindingContext);
874+
Assert.IsType<ShortLivedMockPageViewModel>(popupInstance.BindingContext);
875875
}
876876

877877
[Fact(Timeout = (int)TestDuration.Medium)]
@@ -885,15 +885,15 @@ public async Task ShowPopupAsync_Shell_ShouldValidateProperBindingContext()
885885
Application.Current.Windows[0].Page = shell;
886886

887887
var shellNavigation = Shell.Current.Navigation;
888-
var selfClosingPopup = ServiceProvider.GetRequiredService<MockSelfClosingPopup>() ?? throw new InvalidOperationException();
889-
var popupInstance = ServiceProvider.GetRequiredService<MockSelfClosingPopup>();
890-
var popupViewModel = ServiceProvider.GetRequiredService<MockPageViewModel>();
888+
var selfClosingPopup = ServiceProvider.GetRequiredService<ShortLivedSelfClosingPopup>() ?? throw new InvalidOperationException();
889+
var popupInstance = ServiceProvider.GetRequiredService<ShortLivedSelfClosingPopup>();
891890

892891
// Act
893892
await shell.ShowPopupAsync<object?>(selfClosingPopup, PopupOptions.Empty, shellParameters, TestContext.Current.CancellationToken);
894893

895894
// Assert
896-
Assert.Same(popupInstance.BindingContext, popupViewModel);
895+
Assert.NotNull(popupInstance.BindingContext);
896+
Assert.IsType<ShortLivedMockPageViewModel>(popupInstance.BindingContext);
897897
Assert.Equal(shellParameterBackgroundColorValue, selfClosingPopup.BackgroundColor);
898898
}
899899

@@ -902,8 +902,7 @@ public async Task ShowPopupAsyncWithView_ShouldValidateProperBindingContext()
902902
{
903903
// Arrange
904904
var view = new Grid();
905-
var popupInstance = ServiceProvider.GetRequiredService<MockSelfClosingPopup>();
906-
var popupViewModel = ServiceProvider.GetRequiredService<MockPageViewModel>();
905+
var popupInstance = ServiceProvider.GetRequiredService<ShortLivedSelfClosingPopup>();
907906

908907
// Act
909908
var showPopupTask = navigation.ShowPopupAsync<object?>(view, PopupOptions.Empty, TestContext.Current.CancellationToken);
@@ -914,7 +913,8 @@ public async Task ShowPopupAsyncWithView_ShouldValidateProperBindingContext()
914913
await showPopupTask;
915914

916915
// Assert
917-
Assert.Same(popupInstance.BindingContext, popupViewModel);
916+
Assert.NotNull(popupInstance.BindingContext);
917+
Assert.IsType<ShortLivedMockPageViewModel>(popupInstance.BindingContext);
918918
}
919919

920920
[Fact(Timeout = (int)TestDuration.Medium)]
@@ -929,8 +929,7 @@ public async Task ShowPopupAsyncWithView_Shell_ShouldValidateProperBindingContex
929929

930930
var shellNavigation = Shell.Current.Navigation;
931931
var view = new ViewWithIQueryAttributable(new ViewModelWithIQueryAttributable());
932-
var popupInstance = ServiceProvider.GetRequiredService<MockSelfClosingPopup>();
933-
var popupViewModel = ServiceProvider.GetRequiredService<MockPageViewModel>();
932+
var popupInstance = ServiceProvider.GetRequiredService<ShortLivedSelfClosingPopup>();
934933

935934
// Act
936935
var showPopupTask = shell.ShowPopupAsync<object?>(view, PopupOptions.Empty, shellParameters, TestContext.Current.CancellationToken);
@@ -941,17 +940,33 @@ public async Task ShowPopupAsyncWithView_Shell_ShouldValidateProperBindingContex
941940
await showPopupTask;
942941

943942
// Assert
944-
Assert.Same(popupInstance.BindingContext, popupViewModel);
943+
Assert.NotNull(popupInstance.BindingContext);
944+
Assert.IsType<ShortLivedMockPageViewModel>(popupInstance.BindingContext);
945945
Assert.Equal(shellParameterBackgroundColorValue, view.BackgroundColor);
946946
Assert.Equal(shellParameterViewModelTextValue, view.BindingContext.Text);
947947
}
948948

949+
[Fact(Timeout = (int)TestDuration.Medium)]
950+
public async Task ShowPopupAsync_ShouldSuccessfullyCompleteAndReturnResultUnderHeavyGarbageCollection()
951+
{
952+
// Arrange
953+
var mockPopup = ServiceProvider.GetRequiredService<GarbageCollectionHeavySelfClosingPopup>();
954+
var selfClosingPopup = ServiceProvider.GetRequiredService<GarbageCollectionHeavySelfClosingPopup>() ?? throw new InvalidOperationException();
955+
956+
// Act
957+
var result = await navigation.ShowPopupAsync<object?>(selfClosingPopup, PopupOptions.Empty, TestContext.Current.CancellationToken);
958+
959+
// Assert
960+
Assert.Same(mockPopup.Result, result.Result);
961+
Assert.False(result.WasDismissedByTappingOutsideOfPopup);
962+
}
963+
949964
[Fact(Timeout = (int)TestDuration.Medium)]
950965
public async Task ShowPopupAsync_ShouldReturnResultOnceClosed()
951966
{
952967
// Arrange
953-
var mockPopup = ServiceProvider.GetRequiredService<MockSelfClosingPopup>();
954-
var selfClosingPopup = ServiceProvider.GetRequiredService<MockSelfClosingPopup>() ?? throw new InvalidOperationException();
968+
var mockPopup = ServiceProvider.GetRequiredService<ShortLivedSelfClosingPopup>();
969+
var selfClosingPopup = ServiceProvider.GetRequiredService<ShortLivedSelfClosingPopup>() ?? throw new InvalidOperationException();
955970

956971
// Act
957972
var result = await navigation.ShowPopupAsync<object?>(selfClosingPopup, PopupOptions.Empty, TestContext.Current.CancellationToken);
@@ -972,8 +987,8 @@ public async Task ShowPopupAsync_Shell_ShouldReturnResultOnceClosed()
972987
Application.Current.Windows[0].Page = shell;
973988

974989
var shellNavigation = Shell.Current.Navigation;
975-
var mockPopup = ServiceProvider.GetRequiredService<MockSelfClosingPopup>();
976-
var selfClosingPopup = ServiceProvider.GetRequiredService<MockSelfClosingPopup>() ?? throw new InvalidOperationException();
990+
var mockPopup = ServiceProvider.GetRequiredService<ShortLivedSelfClosingPopup>();
991+
var selfClosingPopup = ServiceProvider.GetRequiredService<ShortLivedSelfClosingPopup>() ?? throw new InvalidOperationException();
977992

978993
// Act
979994
var result = await shell.ShowPopupAsync<object?>(selfClosingPopup, PopupOptions.Empty, shellParameters, TestContext.Current.CancellationToken);
@@ -1070,7 +1085,7 @@ public async Task ShowPopupAsync_Shell_ShouldThrowArgumentNullException_WhenView
10701085
public async Task ShowPopupAsync_ShouldThrowArgumentNullException_WhenNavigationIsNull()
10711086
{
10721087
// Arrange
1073-
var selfClosingPopup = ServiceProvider.GetRequiredService<MockSelfClosingPopup>() ?? throw new InvalidOperationException();
1088+
var selfClosingPopup = ServiceProvider.GetRequiredService<ShortLivedSelfClosingPopup>() ?? throw new InvalidOperationException();
10741089

10751090
// Act / Assert
10761091
#pragma warning disable CS8625 // Cannot convert null literal to non-nullable reference type.
@@ -1089,7 +1104,7 @@ public async Task ShowPopupAsync_Shell_ShouldThrowArgumentNullException_WhenNavi
10891104
Application.Current.Windows[0].Page = shell;
10901105

10911106
var shellNavigation = Shell.Current.Navigation;
1092-
var selfClosingPopup = ServiceProvider.GetRequiredService<MockSelfClosingPopup>() ?? throw new InvalidOperationException();
1107+
var selfClosingPopup = ServiceProvider.GetRequiredService<ShortLivedSelfClosingPopup>() ?? throw new InvalidOperationException();
10931108

10941109
// Act/Assert
10951110
#pragma warning disable CS8625 // Cannot convert null literal to non-nullable reference type.
@@ -1430,7 +1445,7 @@ public async Task ClosePopupAsyncT_ShouldClosePopupUsingPageAndReturnResult()
14301445
Assert.Equal(expectedResult, popupResult.Result);
14311446
Assert.False(popupResult.WasDismissedByTappingOutsideOfPopup);
14321447
}
1433-
1448+
14341449
[Fact(Timeout = (int)TestDuration.Short)]
14351450
public async Task ShowPopupAsync_TaskShouldCompleteWhenCloseAsyncIsCalled()
14361451
{
@@ -1460,7 +1475,7 @@ public async Task ShowPopupAsync_TaskShouldCompleteWhenCloseAsyncIsCalled()
14601475
Assert.False(popupResult.WasDismissedByTappingOutsideOfPopup);
14611476
}
14621477

1463-
static TapGestureRecognizer GetTapOutsideGestureRecognizer(PopupPage popupPage) =>
1478+
static TapGestureRecognizer GetTapOutsideGestureRecognizer(PopupPage popupPage) =>
14641479
(TapGestureRecognizer)popupPage.Content.Children.OfType<BoxView>().Single().GestureRecognizers[0];
14651480
}
14661481

0 commit comments

Comments
 (0)