public void ComboBoxItemAccessibleObject_Get_Not_ThrowsException()
        {
            using (new NoAssertContext())
            {
                using ComboBox control = new ComboBox();

                HashNotImplementedObject item1 = new();
                HashNotImplementedObject item2 = new();
                HashNotImplementedObject item3 = new();

                control.Items.AddRange(new[] { item1, item2, item3 });

                ComboBox.ComboBoxAccessibleObject comboBoxAccessibleObject = (ComboBox.ComboBoxAccessibleObject)control.AccessibilityObject;

                bool exceptionThrown = false;

                try
                {
                    ComboBox.ComboBoxItemAccessibleObject item1AccessibleObject = comboBoxAccessibleObject.ItemAccessibleObjects.GetComboBoxItemAccessibleObject(control.Items.InnerList[0]);
                    ComboBox.ComboBoxItemAccessibleObject item2AccessibleObject = comboBoxAccessibleObject.ItemAccessibleObjects.GetComboBoxItemAccessibleObject(control.Items.InnerList[1]);
                    ComboBox.ComboBoxItemAccessibleObject item3AccessibleObject = comboBoxAccessibleObject.ItemAccessibleObjects.GetComboBoxItemAccessibleObject(control.Items.InnerList[2]);
                }
                catch
                {
                    exceptionThrown = true;
                }

                Assert.False(exceptionThrown, "Getting accessible object for ComboBox item has thrown an exception.");
            }
        }
        public void ComboBoxItemAccessibleObject_SeveralSameItems_FragmentNavigate_NextSibling_ReturnExpected(ComboBoxStyle comboBoxStyle)
        {
            using ComboBox comboBox = new ComboBox
                  {
                      DropDownStyle = comboBoxStyle
                  };

            comboBox.Items.AddRange(new[] { "aaa", "aaa", "aaa" });
            comboBox.CreateControl();

            ComboBoxItemAccessibleObjectCollection itemAccessibleObjects = ((ComboBox.ComboBoxAccessibleObject)comboBox.AccessibilityObject).ItemAccessibleObjects;

            ComboBox.ComboBoxItemAccessibleObject comboBoxItem1 = (ComboBox.ComboBoxItemAccessibleObject)comboBox
                                                                  .ChildListAccessibleObject.FragmentNavigate(Interop.UiaCore.NavigateDirection.FirstChild);
            Assert.Equal("aaa", comboBoxItem1.Name);
            Assert.Equal(comboBoxItem1, itemAccessibleObjects.GetComboBoxItemAccessibleObject(comboBox.Items.InnerList[0]));

            // FragmentNavigate(Interop.UiaCore.NavigateDirection.NextSibling) should return accessible object for second "aaa" item
            ComboBox.ComboBoxItemAccessibleObject comboBoxItem2 = (ComboBox.ComboBoxItemAccessibleObject)comboBoxItem1
                                                                  .FragmentNavigate(Interop.UiaCore.NavigateDirection.NextSibling);
            Assert.NotEqual(comboBoxItem1, comboBoxItem2);
            Assert.Equal("aaa", comboBoxItem2.Name);
            Assert.Equal(comboBoxItem2, itemAccessibleObjects.GetComboBoxItemAccessibleObject(comboBox.Items.InnerList[1]));

            // FragmentNavigate(Interop.UiaCore.NavigateDirection.NextSibling) should return accessible object for third "aaa" item
            ComboBox.ComboBoxItemAccessibleObject comboBoxItem3 = (ComboBox.ComboBoxItemAccessibleObject)comboBoxItem2
                                                                  .FragmentNavigate(Interop.UiaCore.NavigateDirection.NextSibling);
            Assert.NotEqual(comboBoxItem3, comboBoxItem2);
            Assert.NotEqual(comboBoxItem3, comboBoxItem1);
            Assert.Equal("aaa", comboBoxItem3.Name);
            Assert.Equal(comboBoxItem3, itemAccessibleObjects.GetComboBoxItemAccessibleObject(comboBox.Items.InnerList[2]));

            Assert.True(comboBox.IsHandleCreated);
        }
Example #3
0
        public void ComboBoxItemAccessibleObject_SeveralSameItems_FragmentNavigate_NextSibling_ReturnExpected()
        {
            using (new NoAssertContext())
            {
                using ComboBox comboBox = new ComboBox();
                comboBox.CreateControl();

                comboBox.Items.AddRange(new[] { "aaa", "aaa", "aaa" });
                ComboBox.ComboBoxItemAccessibleObject comboBoxItem1 = (ComboBox.ComboBoxItemAccessibleObject)comboBox
                                                                      .ChildListAccessibleObject.FragmentNavigate(Interop.UiaCore.NavigateDirection.FirstChild);
                Assert.Equal("aaa", comboBoxItem1.Name);

                // FragmentNavigate(Interop.UiaCore.NavigateDirection.NextSibling) should return accessible object for second "aaa" item
                ComboBox.ComboBoxItemAccessibleObject comboBoxItem2 = (ComboBox.ComboBoxItemAccessibleObject)comboBoxItem1
                                                                      .FragmentNavigate(Interop.UiaCore.NavigateDirection.NextSibling);
                Assert.NotEqual(comboBoxItem1, comboBoxItem2);
                Assert.Equal("aaa", comboBoxItem2.Name);

                // FragmentNavigate(Interop.UiaCore.NavigateDirection.NextSibling) should return accessible object for third "aaa" item
                ComboBox.ComboBoxItemAccessibleObject comboBoxItem3 = (ComboBox.ComboBoxItemAccessibleObject)comboBoxItem2
                                                                      .FragmentNavigate(Interop.UiaCore.NavigateDirection.NextSibling);
                Assert.NotEqual(comboBoxItem3, comboBoxItem2);
                Assert.NotEqual(comboBoxItem3, comboBoxItem1);
                Assert.Equal("aaa", comboBoxItem3.Name);

                Assert.True(comboBox.IsHandleCreated);
            }
        }
        public void ComboBoxItemAccessibleObject_DropDownCollapsed_GetOffScreenProperty_ReturnExpected(ComboBoxStyle comboBoxStyle)
        {
            using ComboBox comboBox = GetComboBox(comboBoxStyle);

            ComboBox.ComboBoxItemAccessibleObject comboBoxItem1 = (ComboBox.ComboBoxItemAccessibleObject)comboBox
                                                                  .ChildListAccessibleObject.FragmentNavigate(Interop.UiaCore.NavigateDirection.FirstChild);
            ComboBox.ComboBoxItemAccessibleObject comboBoxItem2 = (ComboBox.ComboBoxItemAccessibleObject)comboBoxItem1
                                                                  .FragmentNavigate(Interop.UiaCore.NavigateDirection.NextSibling);

            AssertExtensions.True(comboBoxItem1, UiaCore.UIA.IsOffscreenPropertyId);
            AssertExtensions.True(comboBoxItem2, UiaCore.UIA.IsOffscreenPropertyId);
        }
        public void ComboBoxItemAccessibleObject_DropDownCollapsed_State_ReturnExpected(ComboBoxStyle comboBoxStyle)
        {
            using ComboBox comboBox = GetComboBox(comboBoxStyle);

            ComboBox.ComboBoxItemAccessibleObject comboBoxItem1 = (ComboBox.ComboBoxItemAccessibleObject)comboBox
                                                                  .ChildListAccessibleObject.FragmentNavigate(Interop.UiaCore.NavigateDirection.FirstChild);
            ComboBox.ComboBoxItemAccessibleObject comboBoxItem2 = (ComboBox.ComboBoxItemAccessibleObject)comboBoxItem1
                                                                  .FragmentNavigate(Interop.UiaCore.NavigateDirection.NextSibling);

            Assert.Equal(comboBoxItem1.State, InvisibleItemState);
            Assert.Equal(comboBoxItem2.State, InvisibleItemState);
        }
        public void ComboBoxItemAccessibleObject_GetOffScreenProperty_ReturnExpected()
        {
            using ComboBox comboBox = GetComboBoxWithMaxSize(ComboBoxStyle.Simple);

            ComboBox.ComboBoxItemAccessibleObject comboBoxItem1 = (ComboBox.ComboBoxItemAccessibleObject)comboBox
                                                                  .ChildListAccessibleObject.FragmentNavigate(Interop.UiaCore.NavigateDirection.FirstChild);
            ComboBox.ComboBoxItemAccessibleObject comboBoxItem2 = (ComboBox.ComboBoxItemAccessibleObject)comboBoxItem1
                                                                  .FragmentNavigate(Interop.UiaCore.NavigateDirection.NextSibling);
            ComboBox.ComboBoxItemAccessibleObject comboBoxItem3 = (ComboBox.ComboBoxItemAccessibleObject)comboBoxItem2
                                                                  .FragmentNavigate(Interop.UiaCore.NavigateDirection.NextSibling);

            AssertExtensions.True(comboBoxItem1, UiaCore.UIA.IsOffscreenPropertyId);  // comboBoxItem1 above the visible area
            AssertExtensions.False(comboBoxItem2, UiaCore.UIA.IsOffscreenPropertyId); // comboBoxItem2 in the visible area
            AssertExtensions.True(comboBoxItem3, UiaCore.UIA.IsOffscreenPropertyId);  // comboBoxItem3 below the visible area
        }
        public void ComboBoxItemAccessibleObject_DropDownHeight_State_ReturnExpected(ComboBoxStyle comboBoxStyle)
        {
            using ComboBox comboBox = GetComboBoxWithMaxHeight(comboBoxStyle);

            ComboBox.ComboBoxItemAccessibleObject comboBoxItem1 = (ComboBox.ComboBoxItemAccessibleObject)comboBox
                                                                  .ChildListAccessibleObject.FragmentNavigate(Interop.UiaCore.NavigateDirection.FirstChild);
            ComboBox.ComboBoxItemAccessibleObject comboBoxItem2 = (ComboBox.ComboBoxItemAccessibleObject)comboBoxItem1
                                                                  .FragmentNavigate(Interop.UiaCore.NavigateDirection.NextSibling);
            ComboBox.ComboBoxItemAccessibleObject comboBoxItem3 = (ComboBox.ComboBoxItemAccessibleObject)comboBoxItem2
                                                                  .FragmentNavigate(Interop.UiaCore.NavigateDirection.NextSibling);

            Assert.Equal(comboBoxItem1.State, InvisibleItemState); // comboBoxItem1 above the visible area
            Assert.Equal(comboBoxItem2.State, VisibleItemState);   // comboBoxItem2 in the visible area
            Assert.Equal(comboBoxItem3.State, InvisibleItemState); // comboBoxItem3 below the visible area
        }
        public void ComboBoxItemAccessibleObject_State_ReturnExpected()
        {
            using ComboBox comboBox = GetComboBoxWithMaxSize(ComboBoxStyle.Simple);

            ComboBox.ComboBoxItemAccessibleObject comboBoxItem1 = (ComboBox.ComboBoxItemAccessibleObject)comboBox
                                                                  .ChildListAccessibleObject.FragmentNavigate(Interop.UiaCore.NavigateDirection.FirstChild);
            ComboBox.ComboBoxItemAccessibleObject comboBoxItem2 = (ComboBox.ComboBoxItemAccessibleObject)comboBoxItem1
                                                                  .FragmentNavigate(Interop.UiaCore.NavigateDirection.NextSibling);
            ComboBox.ComboBoxItemAccessibleObject comboBoxItem3 = (ComboBox.ComboBoxItemAccessibleObject)comboBoxItem2
                                                                  .FragmentNavigate(Interop.UiaCore.NavigateDirection.NextSibling);

            AccessibleStates itemState = AccessibleStates.Invisible | AccessibleStates.Selected | AccessibleStates.Focusable | AccessibleStates.Selectable;

            Assert.Equal(comboBoxItem1.State, InvisibleItemState); // comboBoxItem1 above the visible area
            Assert.Equal(comboBoxItem2.State, itemState);          // comboBoxItem2 in the visible area
            Assert.Equal(comboBoxItem3.State, InvisibleItemState); // comboBoxItem3 below the visible area
        }
        public void ComboBoxItemAccessibleObject_DataBoundAccessibleName()
        {
            using (new NoAssertContext())
            {
                // Regression test for https://github.com/dotnet/winforms/issues/3549
                using ComboBox control = new ComboBox()
                      {
                          DataSource    = TestDataSources.GetPersons(),
                          DisplayMember = TestDataSources.PersonDisplayMember
                      };

                ComboBox.ComboBoxAccessibleObject accessibleObject = Assert.IsType <ComboBox.ComboBoxAccessibleObject>(control.AccessibilityObject);

                foreach (Person person in TestDataSources.GetPersons())
                {
                    ComboBox.ComboBoxItemAccessibleObject item = accessibleObject.ItemAccessibleObjects.GetComboBoxItemAccessibleObject(new Entry(person));
                    AccessibleObject itemAccessibleObject      = Assert.IsType <ComboBox.ComboBoxItemAccessibleObject>(item);
                    Assert.Equal(person.Name, itemAccessibleObject.Name);
                }
            }
        }