public async Task When_Mask_All() { using (ScreenHelper.OverrideVisibleBounds(new Thickness(0, 34, 0, 65))) { var inner = new Border { Background = new SolidColorBrush(Colors.AliceBlue), Child = new Ellipse { Fill = new SolidColorBrush(Colors.DarkOrange) } }; var container = new Grid { Children = { inner } }; VisibleBoundsPadding.SetPaddingMask(container, VisibleBoundsPadding.PaddingMask.All); WindowHelper.WindowContent = container; await WindowHelper.WaitForLoaded(inner); var visibleBounds = ApplicationView.GetForCurrentView().VisibleBounds; var windowBounds = Window.Current.Bounds; RectAssert.AreNotEqual(windowBounds, visibleBounds); var containerBounds = container.GetOnScreenBounds(); var childBounds = inner.GetOnScreenBounds(); RectAssert.AreEqual(windowBounds, containerBounds); RectAssert.AreEqual(visibleBounds, childBounds); } }
public async Task When_Nested_In_Native_View() { var page = new Native_View_Page(); WindowHelper.WindowContent = page; await WindowHelper.WaitForLoaded(page); var pageBounds = page.GetOnScreenBounds(); var statusBarHeight = pageBounds.Y; // Non-zero on Android var sut = page.SUT; var bounds = sut.GetOnScreenBounds(); bounds.Y -= statusBarHeight; // Status bar height is included in TransformToVisual on Android, but shouldn't be included in VisualTreeHelper.HitTest call var expected = new Rect(25, 205, 80, 40); RectAssert.AreEqual(expected, bounds); GetHitTestability getHitTestability = null; getHitTestability = element => (element as FrameworkElement)?.Background != null ? (element.GetHitTestVisibility(), getHitTestability) : (HitTestability.Invisible, getHitTestability); foreach (var point in GetPointsInside(bounds, perimeterOffset: 5)) { var hitTest = VisualTreeHelper.HitTest(point, getHitTestability); Assert.AreEqual(sut, hitTest.element); } foreach (var point in GetPointsOutside(bounds, perimeterOffset: 5)) { var hitTest = VisualTreeHelper.HitTest(point); Assert.IsNotNull(hitTest.element); Assert.AreNotEqual(sut, hitTest.element); } }
public async Task When_GridViewItems_LayoutSlots() { var gridView = new GridView { ItemContainerStyle = TestsResourceHelper.GetResource <Style>("MyGridViewItemStyle") }; var gvi = new GridViewItem(); var gvi2 = new GridViewItem(); gridView.ItemsSource = new[] { gvi, gvi2 }; WindowHelper.WindowContent = gridView; await WindowHelper.WaitForLoaded(gridView); await WindowHelper.WaitForIdle(); RectAssert.AreEqual(new Rect { X = 0d, Y = 0d, Width = 104d, Height = 104d, }, gvi.LayoutSlot); RectAssert.AreEqual(new Rect { X = 0d, Y = 0d, Width = 100d, Height = 100d, }, gvi.LayoutSlotWithMarginsAndAlignments); RectAssert.AreEqual(new Rect { X = 104d, Y = 0d, Width = 104d, Height = 104d, }, gvi2.LayoutSlot); RectAssert.AreEqual(new Rect { X = 104d, Y = 0d, Width = 100d, Height = 100d, }, gvi2.LayoutSlotWithMarginsAndAlignments); }
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(); } } }