public async Task When_Native_AppBarButton_And_Managed_Popups() { using (StyleHelper.UseNativeFrameNavigation()) { var page = new Native_AppBarButton_Page(); WindowHelper.WindowContent = page; await WindowHelper.WaitForLoaded(page); var flyout = page.SUT.Flyout as MenuFlyout; try { await ControlHelper.DoClickUsingAP(page.SUT); #if !NETFX_CORE Assert.AreEqual(false, flyout.UseNativePopup); #endif var flyoutItem = page.FirstFlyoutItem; await WindowHelper.WaitForLoaded(flyoutItem); var pageBounds = page.GetOnScreenBounds(); var flyoutItemBounds = flyoutItem.GetOnScreenBounds(); Assert.AreEqual(pageBounds.Right, flyoutItemBounds.Right, delta: 1); NumberAssert.Less(flyoutItemBounds.Top, pageBounds.Height / 4); // Exact command bar height may vary between platforms, but the flyout should at least be in the ~top 1/4th of screen } finally { flyout.Hide(); } } }
private static void VerifyRelativeContentPosition(HorizontalPosition horizontalPosition, VerticalPosition verticalPosition, FrameworkElement content, double minimumTargetOffset, Border target) { var contentScreenBounds = content.GetOnScreenBounds(); var contentCenter = contentScreenBounds.GetCenter(); var targetScreenBounds = target.GetOnScreenBounds(); var targetCenter = targetScreenBounds.GetCenter(); Assert.IsTrue(targetCenter.X > minimumTargetOffset); Assert.IsTrue(targetCenter.Y > minimumTargetOffset); switch (horizontalPosition) { case HorizontalPosition.BeyondLeft: NumberAssert.Less(contentScreenBounds.Right, targetScreenBounds.Left); break; case HorizontalPosition.LeftFlush: Assert.AreEqual(targetScreenBounds.Left, contentScreenBounds.Left, delta: 2); break; case HorizontalPosition.Center: Assert.AreEqual(targetCenter.X, contentCenter.X, delta: 2); break; case HorizontalPosition.RightFlush: Assert.AreEqual(targetScreenBounds.Right, contentScreenBounds.Right, delta: 2); break; case HorizontalPosition.BeyondRight: NumberAssert.Greater(contentScreenBounds.Left, targetScreenBounds.Right); break; } switch (verticalPosition) { case VerticalPosition.BeyondTop: NumberAssert.Less(contentScreenBounds.Bottom, targetScreenBounds.Top); break; case VerticalPosition.TopFlush: Assert.AreEqual(targetScreenBounds.Top, contentScreenBounds.Top, delta: 2); break; case VerticalPosition.Center: Assert.AreEqual(targetCenter.Y, contentCenter.Y, delta: 2); break; case VerticalPosition.BottomFlush: Assert.AreEqual(targetScreenBounds.Bottom, contentScreenBounds.Bottom, delta: 2); break; case VerticalPosition.BeyondBottom: NumberAssert.Greater(contentScreenBounds.Top, targetScreenBounds.Bottom); break; } }
public async Task Check_Dropdown_Measure_Count() { var source = Enumerable.Range(0, 500).ToArray(); var SUT = new ComboBox { ItemsSource = source, ItemsPanel = MeasureCountCarouselPanelTemplate }; try { WindowHelper.WindowContent = SUT; await WindowHelper.WaitForLoaded(SUT); Assert.AreEqual(0, MeasureCountCarouselPanel.MeasureCount); Assert.AreEqual(0, MeasureCountCarouselPanel.ArrangeCount); SUT.IsDropDownOpen = true; ComboBoxItem cbi = null; await WindowHelper.WaitFor(() => source.Any(i => (cbi = SUT.ContainerFromItem(i) as ComboBoxItem) != null)); // Windows loads up CarouselPanel with no selected item around the middle, other platforms may not await WindowHelper.WaitForLoaded(cbi); // Required on Android NumberAssert.Greater(MeasureCountCarouselPanel.MeasureCount, 0); NumberAssert.Greater(MeasureCountCarouselPanel.ArrangeCount, 0); #if __IOS__ const int MaxAllowedCount = 15; // TODO: figure out why iOS measures more times #else const int MaxAllowedCount = 5; #endif NumberAssert.Less(MeasureCountCarouselPanel.MeasureCount, MaxAllowedCount); NumberAssert.Less(MeasureCountCarouselPanel.ArrangeCount, MaxAllowedCount); } finally { SUT.IsDropDownOpen = false; WindowHelper.WindowContent = null; } }
[Ignore("ComboBox is currently not virtualized on iOS and Android - #556")] // https://github.com/unoplatform/uno/issues/556 #endif public async Task Check_Creation_Count_Many_Items() { var source = Enumerable.Range(0, 500).ToArray(); var SUT = new ComboBox { ItemsSource = source, ItemContainerStyle = CounterComboBoxContainerStyle, ItemTemplate = CounterItemTemplate }; try { WindowHelper.WindowContent = SUT; await WindowHelper.WaitForLoaded(SUT); Assert.AreEqual(0, CounterGrid.CreationCount); Assert.AreEqual(0, CounterGrid2.CreationCount); SUT.IsDropDownOpen = true; ComboBoxItem cbi = null; await WindowHelper.WaitFor(() => source.Any(i => (cbi = SUT.ContainerFromItem(i) as ComboBoxItem) != null)); // Windows loads up CarouselPanel with no selected item around the middle, other platforms may not //await WindowHelper.WaitFor(() => (cbi = SUT.ContainerFromItem(source[0]) as ComboBoxItem) != null); await WindowHelper.WaitForLoaded(cbi); // Required on Android const int maxCount = 30; NumberAssert.Less(CounterGrid.CreationCount, maxCount); NumberAssert.Less(CounterGrid2.CreationCount, maxCount); } finally { SUT.IsDropDownOpen = false; WindowHelper.WindowContent = null; } }
public async Task When_Soft_Keyboard_And_VisibleBounds() { var nativeUnsafeArea = ScreenHelper.GetUnsafeArea(); using (ScreenHelper.OverrideVisibleBounds(new Thickness(0, 38, 0, 72), skipIfHasNativeUnsafeArea: (nativeUnsafeArea.Top + nativeUnsafeArea.Bottom) > 50)) { var tb = new TextBox { Height = 1200 }; var dummyButton = new Button { Content = "Dummy" }; var SUT = new MyContentDialog { Title = "Dialog title", Content = new ScrollViewer { Content = new StackPanel { Children = { dummyButton, tb } } }, PrimaryButtonText = "Accept", SecondaryButtonText = "Nope" }; try { await ShowDialog(SUT); dummyButton.Focus(FocusState.Pointer); // Ensure keyboard is dismissed in case it is initially visible var inputPane = InputPane.GetForCurrentView(); await WindowHelper.WaitFor(() => inputPane.OccludedRect.Height == 0); var originalButtonBounds = SUT.PrimaryButton.GetOnScreenBounds(); var originalBackgroundBounds = SUT.BackgroundElement.GetOnScreenBounds(); var visibleBounds = ApplicationView.GetForCurrentView().VisibleBounds; RectAssert.Contains(visibleBounds, originalButtonBounds); await FocusTextBoxWithSoftKeyboard(tb); var occludedRect = inputPane.OccludedRect; var shiftedButtonBounds = SUT.PrimaryButton.GetOnScreenBounds(); var shiftedBackgroundBounds = SUT.BackgroundElement.GetOnScreenBounds(); NumberAssert.Greater(originalButtonBounds.Bottom, occludedRect.Top); // Button's original position should be occluded, otherwise test is pointless NumberAssert.Greater(originalBackgroundBounds.Bottom, occludedRect.Top); // ditto background NumberAssert.Less(shiftedButtonBounds.Bottom, occludedRect.Top); // Button should be shifted to be visible (along with rest of dialog) while keyboard is open NumberAssert.Less(shiftedBackgroundBounds.Bottom, occludedRect.Top); // ditto background ; } finally { SUT.Hide(); } } }