Skip to content

Commit

Permalink
Adding more unit tests and fixing review points
Browse files Browse the repository at this point in the history
  • Loading branch information
Ryuugamine committed Aug 12, 2020
1 parent db3678c commit 85330c4
Show file tree
Hide file tree
Showing 22 changed files with 58 additions and 103 deletions.
3 changes: 0 additions & 3 deletions src/System.Windows.Forms/src/Resources/SR.resx
Original file line number Diff line number Diff line change
Expand Up @@ -6722,7 +6722,4 @@ Stack trace where the illegal operation occurred was:
<data name="AccessibleActionDoubleClick" xml:space="preserve">
<value>Double Click</value>
</data>
<data name="ListViewFocusedGroupDescription" xml:space="preserve">
<value>The ListView group that currently has the user focus.</value>
</data>
</root>
5 changes: 0 additions & 5 deletions src/System.Windows.Forms/src/Resources/xlf/SR.cs.xlf

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 0 additions & 5 deletions src/System.Windows.Forms/src/Resources/xlf/SR.de.xlf

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 0 additions & 5 deletions src/System.Windows.Forms/src/Resources/xlf/SR.es.xlf

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 0 additions & 5 deletions src/System.Windows.Forms/src/Resources/xlf/SR.fr.xlf

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 0 additions & 5 deletions src/System.Windows.Forms/src/Resources/xlf/SR.it.xlf

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 0 additions & 5 deletions src/System.Windows.Forms/src/Resources/xlf/SR.ja.xlf

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 0 additions & 5 deletions src/System.Windows.Forms/src/Resources/xlf/SR.ko.xlf

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 0 additions & 5 deletions src/System.Windows.Forms/src/Resources/xlf/SR.pl.xlf

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 0 additions & 5 deletions src/System.Windows.Forms/src/Resources/xlf/SR.pt-BR.xlf

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 0 additions & 5 deletions src/System.Windows.Forms/src/Resources/xlf/SR.ru.xlf

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 0 additions & 5 deletions src/System.Windows.Forms/src/Resources/xlf/SR.tr.xlf

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 0 additions & 5 deletions src/System.Windows.Forms/src/Resources/xlf/SR.zh-Hans.xlf

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 0 additions & 5 deletions src/System.Windows.Forms/src/Resources/xlf/SR.zh-Hant.xlf

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -266,14 +266,13 @@ internal override UiaCore.IRawElementProviderSimple[] GetSelection()
return Array.Empty<UiaCore.IRawElementProviderSimple>();
}

List<UiaCore.IRawElementProviderSimple> selectedItemProviders = new List<UiaCore.IRawElementProviderSimple>();
SelectedListViewItemCollection selectedItems = _owningListView.SelectedItems;
foreach (ListViewItem selectedItem in selectedItems)
UiaCore.IRawElementProviderSimple[] selectedItemProviders = new UiaCore.IRawElementProviderSimple[_owningListView.SelectedItems.Count];
for (int i = 0; i < selectedItemProviders.Length; i++)
{
selectedItemProviders.Add(selectedItem.AccessibilityObject);
selectedItemProviders[i] = _owningListView.SelectedItems[i].AccessibilityObject;
}

return selectedItemProviders.ToArray();
return selectedItemProviders;
}

public override AccessibleObject? HitTest(int x, int y)
Expand Down
8 changes: 2 additions & 6 deletions src/System.Windows.Forms/src/System/Windows/Forms/ListView.cs
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ public partial class ListView : Control
private CheckedIndexCollection checkedIndexCollection;
private CheckedListViewItemCollection checkedListViewItemCollection;
private SelectedListViewItemCollection selectedListViewItemCollection;
internal SelectedIndexCollection selectedIndexCollection;
private SelectedIndexCollection selectedIndexCollection;
private ListViewGroupCollection groups;
private ListViewInsertionMark insertionMark;
private LabelEditEventHandler onAfterLabelEdit;
Expand Down Expand Up @@ -824,10 +824,6 @@ internal bool ExpectingMouseUp
/// group that's drawn with the dotted focus rectangle around it.
/// Returns null if no group is currently focused.
/// </summary>
[SRCategory(nameof(SR.CatAppearance))]
[Browsable(false)]
[DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
[SRDescription(nameof(SR.ListViewFocusedGroupDescription))]
internal ListViewGroup FocusedGroup
{
get => IsHandleCreated ? focusedGroup : null;
Expand Down Expand Up @@ -5908,7 +5904,7 @@ private void WmMouseDown(ref Message m, MouseButtons button, int clicks)
}

Point screenPoint = PointToScreen(new Point(x, y));
AccessibleObject accessibilityObject = (AccessibilityObject as ListViewAccessibleObject).HitTest(screenPoint.X, screenPoint.Y);
AccessibleObject accessibilityObject = AccessibilityObject.HitTest(screenPoint.X, screenPoint.Y);
accessibilityObject?.RaiseAutomationEvent(UiaCore.UIA.AutomationFocusChangedEventId);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ internal AccessibleObject? AccessibilityObject
{
if (_accessibilityObject is null)
{
_accessibilityObject = new ListViewGroupAccessibleObject(this, IsDefault);
_accessibilityObject = new ListViewGroupAccessibleObject(this, ListView?.Groups.Contains(this) == false);
}

return _accessibilityObject;
Expand Down Expand Up @@ -188,19 +188,6 @@ public HorizontalAlignment FooterAlignment

internal bool Focused { get; set; }

private bool IsDefault
{
get
{
if (ListView is null || ListView.Groups.Contains(this))
{
return false;
}

return true;
}
}

/// <summary>
/// Controls which <see cref="ListViewGroupCollapsedState"/> the group will appear as.
/// </summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -282,9 +282,9 @@ internal override void ScrollIntoView()

internal unsafe override void SelectItem()
{
if (_owningListView.IsHandleCreated && _owningListView.selectedIndexCollection != null)
if (_owningListView.IsHandleCreated)
{
_owningListView.selectedIndexCollection.Add(CurrentIndex);
_owningListView.SelectedIndices.Add(CurrentIndex);
User32.InvalidateRect(new HandleRef(this, _owningListView.Handle), null, BOOL.FALSE);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,25 @@ internal override UiaCore.IRawElementProviderFragmentRoot FragmentRoot
=> _owningListView.AccessibilityObject;

public override Rectangle Bounds
=> new Rectangle(
{
get
{
// Previously bounds was provided using MSAA,
// but using UIA we found out that SendMessageW work incorrectly.
// When we need to get bounds for first sub item it will return width of all item.
int width = _owningSubItem.Bounds.Width;

if (Column == 0 && _owningItem.SubItems.Count > 1)
{
width = _owningItem.SubItems[Column + 1].Bounds.X - _owningSubItem.Bounds.X;
}

return new Rectangle(
_owningListView.AccessibilityObject.Bounds.X + _owningSubItem.Bounds.X,
_owningListView.AccessibilityObject.Bounds.Y + _owningSubItem.Bounds.Y,
_owningSubItem.Bounds.Width,
_owningSubItem.Bounds.Height);
width, _owningSubItem.Bounds.Height);
}
}

internal override UiaCore.IRawElementProviderFragment? FragmentNavigate(UiaCore.NavigateDirection direction)
{
Expand Down Expand Up @@ -65,7 +79,7 @@ public override Rectangle Bounds
/// </summary>
public override string? Name
{
get => _owningSubItem.Text;
get => base.Name ?? _owningSubItem.Text;
set => base.Name = value;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,34 @@ public void ListViewAccessibleObject_EmptyList_GetChildCount_ReturnsCorrectValue
Assert.Equal(0, accessibleObject.GetChildCount()); // listView doesn't have items
}

[WinFormsFact]
public void ListViewAccessibleObject_GetMultiViewProviderCurrentView_ReturnsCorrectValue()
{
using ListView listView = new ListView();
AccessibleObject accessibleObject = listView.AccessibilityObject;
Assert.True(listView.IsHandleCreated);
Assert.Equal((int)listView.View, accessibleObject.GetMultiViewProviderCurrentView());
}

[WinFormsFact]
public void ListViewAccessibleObject_GetMultiViewProviderSupportedViews_ReturnsExpected()
{
using ListView listView = new ListView();
AccessibleObject accessibleObject = listView.AccessibilityObject;
Assert.True(listView.IsHandleCreated);
Assert.Equal(new int[] { (int)View.Details }, accessibleObject.GetMultiViewProviderSupportedViews());
}

[WinFormsFact]
public void ListViewAccessibleObject_GetMultiViewProviderViewName_ReturnsCorrectValue()
{
using ListView listView = new ListView();
listView.View = View.Details;
AccessibleObject accessibleObject = listView.AccessibilityObject;
Assert.True(listView.IsHandleCreated);
Assert.Equal(((int)(listView.View)).ToString(), accessibleObject.GetMultiViewProviderViewName((int)View.Details));
}

[WinFormsFact]
public void ListViewAccessibleObject_ListWithOneItem_GetChildCount_ReturnsCorrectValue()
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ public void ListViewGroupAccessibleObject_ListWithTwoGroups_FragmentNavigateWork
Assert.Equal(firstChild, listItem3.AccessibilityObject);
}

[WinFormsFact(Skip = "Crash with AbandonedMutexException. See: https://github.com/dotnet/arcade/issues/5325")]
[WinFormsFact]
public void ListViewGroupAccessibleObject_Bounds_ReturnsCorrectValue()
{
using RemoteInvokeHandle invokerHandle = RemoteExecutor.Invoke(() =>
Expand All @@ -143,7 +143,6 @@ public void ListViewGroupAccessibleObject_Bounds_ReturnsCorrectValue()
list.CreateControl();
form.Controls.Add(list);
form.Show();
Thread.Sleep(40000);

AccessibleObject accessibleObject = list.AccessibilityObject;
AccessibleObject group1AccObj = listGroup.AccessibilityObject;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ public void ListViewSubItemAccessibleObject_Bounds_ReturnCorrectValue()
Assert.True(list.IsHandleCreated);

int actualWidth = accessibleObject.Bounds.Width;
int expectedWidth = subItem.Bounds.Width;
int expectedWidth = listViewItem1.SubItems[1].Bounds.X - subItem.Bounds.X;
Assert.Equal(expectedWidth, actualWidth);

int actualHeight = accessibleObject.Bounds.Height;
Expand All @@ -163,7 +163,7 @@ public void ListViewSubItemAccessibleObject_Bounds_ReturnCorrectValue()

Rectangle actualBounds = accessibleObject.Bounds;
actualBounds.Location = new Point(0, 0);
Rectangle expectedBounds = subItem.Bounds;
Rectangle expectedBounds = new Rectangle(subItem.Bounds.X, subItem.Bounds.Y, expectedWidth, expectedHeight);
expectedBounds.Location = new Point(0, 0);
Assert.Equal(expectedBounds, actualBounds);
}
Expand Down

0 comments on commit 85330c4

Please sign in to comment.