-
Notifications
You must be signed in to change notification settings - Fork 717
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #17792 from unoplatform/dev/mazi/iseditable
- Loading branch information
Showing
81 changed files
with
12,188 additions
and
2,336 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
187 changes: 187 additions & 0 deletions
187
src/Uno.UI.RuntimeTests/IntegrationTests/common/ComboBoxHelper.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,187 @@ | ||
// Copyright (c) Microsoft Corporation. All rights reserved. | ||
// Licensed under the MIT License. See LICENSE in the project root for license information. | ||
|
||
using System; | ||
using System.Threading.Tasks; | ||
using Microsoft.UI.Xaml.Controls; | ||
using Microsoft.UI.Xaml.Tests.Enterprise; | ||
using Private.Infrastructure; | ||
using Uno.UI.RuntimeTests.MUX.Helpers; | ||
using Windows.Foundation; | ||
using static Private.Infrastructure.TestServices; | ||
|
||
namespace Microsoft.UI.Xaml.Tests.Common; | ||
|
||
internal static class ComboBoxHelper | ||
{ | ||
public enum OpenMethod | ||
{ | ||
Mouse, | ||
Touch, | ||
Keyboard, | ||
Gamepad, | ||
Programmatic | ||
}; | ||
|
||
public enum CloseMethod | ||
{ | ||
Mouse, | ||
Touch, | ||
Keyboard, | ||
Gamepad, | ||
Programmatic | ||
}; | ||
|
||
public static async Task FocusComboBoxIfNecessary(ComboBox comboBox) | ||
{ | ||
var comboBoxGotFocusEvent = new Event(); | ||
var gotFocusRegistration = CreateSafeEventRegistration<ComboBox, RoutedEventHandler>("GotFocus"); | ||
gotFocusRegistration.Attach(comboBox, (s, e) => | ||
{ | ||
LOG_OUTPUT("[ComboBox]: Got Focus Event Fired."); | ||
comboBoxGotFocusEvent.Set(); | ||
}); | ||
|
||
bool alreadyHasFocus = false; | ||
await RunOnUIThread(() => | ||
{ | ||
alreadyHasFocus = comboBox.FocusState != FocusState.Unfocused; | ||
comboBox.Focus(FocusState.Keyboard); | ||
}); | ||
|
||
if (!alreadyHasFocus) | ||
{ | ||
await comboBoxGotFocusEvent.WaitForDefault(); | ||
} | ||
} | ||
|
||
public static async Task OpenComboBox(ComboBox comboBox, OpenMethod openMethod) | ||
{ | ||
var comboBoxOpenedEvent = new Event(); | ||
var openedRegistration = CreateSafeEventRegistration<ComboBox, EventHandler<object>>("DropDownOpened"); | ||
openedRegistration.Attach(comboBox, (s, e) => { comboBoxOpenedEvent.Set(); }); | ||
|
||
if (openMethod == OpenMethod.Mouse) | ||
{ | ||
TestServices.InputHelper.LeftMouseClick(comboBox); | ||
} | ||
else if (openMethod == OpenMethod.Touch) | ||
{ | ||
TestServices.InputHelper.Tap(comboBox); | ||
} | ||
else if (openMethod == OpenMethod.Keyboard) | ||
{ | ||
await FocusComboBoxIfNecessary(comboBox); | ||
await TestServices.KeyboardHelper.PressKeySequence(" "); | ||
} | ||
else if (openMethod == OpenMethod.Gamepad) | ||
{ | ||
await FocusComboBoxIfNecessary(comboBox); | ||
await CommonInputHelper.Accept(InputDevice.Gamepad); | ||
} | ||
else if (openMethod == OpenMethod.Programmatic) | ||
{ | ||
await RunOnUIThread(() => | ||
{ | ||
comboBox.IsDropDownOpen = true; | ||
}); | ||
} | ||
await TestServices.WindowHelper.WaitForIdle(); | ||
|
||
await comboBoxOpenedEvent.WaitForDefault(); | ||
} | ||
|
||
public static async Task CloseComboBox(ComboBox comboBox) | ||
{ | ||
await CloseComboBox(comboBox, CloseMethod.Programmatic); | ||
} | ||
|
||
public static async Task CloseComboBox(ComboBox comboBox, CloseMethod closeMethod) | ||
{ | ||
var dropDownClosedEvent = new Event(); | ||
var dropDownClosedRegistration = CreateSafeEventRegistration<ComboBox, EventHandler<object>>("DropDownClosed"); | ||
dropDownClosedRegistration.Attach(comboBox, (s, e) => { dropDownClosedEvent.Set(); }); | ||
|
||
if (closeMethod == CloseMethod.Touch || closeMethod == CloseMethod.Mouse) | ||
{ | ||
Rect dropdownBounds = await GetBoundsOfOpenDropdown(comboBox); | ||
int outsideBuffer = 10; // Tap at least this far away from the dropdown in order to ensure that it closes. | ||
var closeTapPoint = new Point(dropdownBounds.X + dropdownBounds.Width + outsideBuffer, dropdownBounds.Y + dropdownBounds.Height + outsideBuffer); | ||
|
||
if (closeMethod == CloseMethod.Touch) | ||
{ | ||
TestServices.InputHelper.Tap(closeTapPoint); | ||
} | ||
else | ||
{ | ||
TestServices.InputHelper.LeftMouseClick(closeTapPoint); | ||
} | ||
} | ||
else if (closeMethod == CloseMethod.Keyboard) | ||
{ | ||
await CommonInputHelper.Cancel(InputDevice.Keyboard); | ||
} | ||
else if (closeMethod == CloseMethod.Gamepad) | ||
{ | ||
await CommonInputHelper.Cancel(InputDevice.Gamepad); | ||
} | ||
else if (closeMethod == CloseMethod.Programmatic) | ||
{ | ||
await RunOnUIThread(() => | ||
{ | ||
comboBox.IsDropDownOpen = false; | ||
}); | ||
} | ||
|
||
await dropDownClosedEvent.WaitForDefault(); | ||
await TestServices.WindowHelper.WaitForIdle(); | ||
|
||
dropDownClosedRegistration.Detach(); | ||
} | ||
|
||
private static async Task<Rect> GetBoundsOfOpenDropdown(DependencyObject element) | ||
{ | ||
Rect dropdownBounds = new(); | ||
|
||
await RunOnUIThread(async () => | ||
{ | ||
var dropdownScrollViewer = (ScrollViewer)(TreeHelper.GetVisualChildByNameFromOpenPopups("ScrollViewer", element)); | ||
Assert.IsNotNull(dropdownScrollViewer, "DropDown not found."); | ||
dropdownBounds = await ControlHelper.GetBounds(dropdownScrollViewer); | ||
LOG_OUTPUT("dropdownBounds: (%f, %f, %f, %f)", dropdownBounds.X, dropdownBounds.Y, dropdownBounds.Width, dropdownBounds.Height); | ||
}); | ||
await TestServices.WindowHelper.WaitForIdle(); | ||
|
||
return dropdownBounds; | ||
} | ||
|
||
// Verify the selected Index on the ComboBox. | ||
public static async Task VerifySelectedIndex(ComboBox comboBox, int expected) | ||
{ | ||
await SelectorHelper.VerifySelectedIndex(comboBox, expected); | ||
} | ||
|
||
// Uses touch to select the ComboBoxItem with the specified index. | ||
// Note: The function does not currently scroll the popup, so it won't work if the item to be selected | ||
// is not immediately visible. | ||
public static async Task SelectItemWithTap(ComboBox comboBox, int index) | ||
{ | ||
await OpenComboBox(comboBox, OpenMethod.Touch); | ||
await TestServices.WindowHelper.WaitForIdle(); | ||
|
||
Event selectionChangedEvent = new(); | ||
var selectionChangedRegistration = CreateSafeEventRegistration<ComboBox, SelectionChangedEventHandler>("SelectionChanged"); | ||
selectionChangedRegistration.Attach(comboBox, (s, e) => selectionChangedEvent.Set()); | ||
|
||
ComboBoxItem comboBoxItemToSelect = null; | ||
await RunOnUIThread(() => | ||
{ | ||
comboBoxItemToSelect = (ComboBoxItem)comboBox.ContainerFromIndex(index); | ||
THROW_IF_NULL(comboBoxItemToSelect); | ||
}); | ||
|
||
TestServices.InputHelper.Tap(comboBoxItemToSelect); | ||
await selectionChangedEvent.WaitForDefault(); | ||
} | ||
} |
68 changes: 68 additions & 0 deletions
68
src/Uno.UI.RuntimeTests/IntegrationTests/common/FocusTestHelper.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
using System.Threading.Tasks; | ||
using Microsoft.UI.Xaml.Input; | ||
using Microsoft.UI.Xaml.Tests.Enterprise; | ||
using static Private.Infrastructure.TestServices; | ||
|
||
namespace Microsoft.UI.Xaml.Tests.Common; | ||
|
||
internal static class FocusTestHelper | ||
{ | ||
public static async Task EnsureFocus(UIElement element, FocusState focusState, int Attempts = 1) | ||
{ | ||
bool gotFocus = false; | ||
|
||
while (Attempts > 0 && !gotFocus) | ||
{ | ||
Attempts--; | ||
|
||
// On desktop, check if there is any other window currently having the window focus | ||
// If so, try to bring the test app to foreground before attempting focus on the element | ||
//if (!Private.Infrastructure.TestServices.Utilities.IsOneCore && | ||
// !Private.Infrastructure.TestServices.Utilities.IsXBox) | ||
//{ | ||
// if (!Private.Infrastructure.TestServices.WindowHelper.IsFocusedWindow) | ||
// { | ||
// LOG_OUTPUT("Test app does not have window focus, bring it to foreground and try again!"); | ||
// Private.Infrastructure.TestServices.WindowHelper.RestoreForegroundWindow(); | ||
// Private.Infrastructure.TestServices.WindowHelper.WaitForIdle(); | ||
// } | ||
//} | ||
|
||
var gotFocusEvent = new Event(); | ||
// gotFocusEvent MUST be declared before gotFocusRegistration | ||
// Otherwise the event handler could execute after gotFocusEvent has been destroyed. | ||
var gotFocusRegistration = CreateSafeEventRegistration<UIElement, RoutedEventHandler>("GotFocus"); | ||
|
||
await RunOnUIThread(() => | ||
{ | ||
gotFocusRegistration.Attach(element, (s, e) => | ||
{ | ||
LOG_OUTPUT("Element has received focus."); | ||
gotFocusEvent.Set(); | ||
}); | ||
if (element.FocusState != FocusState.Unfocused && FocusManager.GetFocusedElement(WindowHelper.WindowContent.XamlRoot).Equals(element)) | ||
{ | ||
// The element is already focused | ||
LOG_OUTPUT("Focus was already set on this element"); | ||
gotFocusEvent.Set(); | ||
} | ||
else | ||
{ | ||
LOG_OUTPUT("Setting focus to the element..."); | ||
element.Focus(focusState); | ||
} | ||
}); | ||
|
||
await gotFocusEvent.WaitForNoThrow(4000); | ||
gotFocus = gotFocusEvent.HasFired(); | ||
} | ||
|
||
if (!gotFocus) | ||
{ | ||
//Private.Infrastructure.TestServices.Utilities.CaptureScreen("FocusTestHelper"); | ||
} | ||
VERIFY_IS_TRUE(gotFocus); | ||
} | ||
} |
21 changes: 21 additions & 0 deletions
21
src/Uno.UI.RuntimeTests/IntegrationTests/common/SelectorHelper.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Text; | ||
using System.Threading.Tasks; | ||
using Microsoft.UI.Xaml.Controls.Primitives; | ||
using static Private.Infrastructure.TestServices; | ||
|
||
namespace Microsoft.UI.Xaml.Tests.Common; | ||
|
||
internal static class SelectorHelper | ||
{ | ||
public static async Task VerifySelectedIndex(Selector selector, int expected) | ||
{ | ||
await RunOnUIThread(() => | ||
{ | ||
LOG_OUTPUT("Selected Index = %d", selector.SelectedIndex); | ||
VERIFY_ARE_EQUAL(selector.SelectedIndex, expected); | ||
}); | ||
} | ||
} |
Oops, something went wrong.