AddAutomationPropertyChangedEventHandler() public static method

public static AddAutomationPropertyChangedEventHandler ( AutomationElement element, TreeScope scope, AutomationPropertyChangedEventHandler eventHandler ) : void
element AutomationElement
scope TreeScope
eventHandler AutomationPropertyChangedEventHandler
return void
Beispiel #1
0
        //The "Z1_" prefix ensures the test case's execution sequence
        public void Z1_DynamicTest()
        {
            var automationEventsArray = new [] {
                new { Sender = (object)null, Args = (AutomationPropertyChangedEventArgs)null }
            };
            var automationEvents = automationEventsArray.ToList();

            automationEvents.Clear();

            AutomationPropertyChangedEventHandler handler =
                (o, e) => automationEvents.Add(new { Sender = o, Args = e });

            At.AddAutomationPropertyChangedEventHandler(listView1Element,
                                                        TreeScope.Element, handler,
                                                        MultipleViewPattern.CurrentViewProperty,
                                                        MultipleViewPattern.SupportedViewsProperty);

            RunCommand("change list view mode list");

            //var currentView = pattern.Current.CurrentView;

            // We should expect an AutomationPropertyChangedEvent here,
            // But since on Windows Winforms didn't fire such a event, then we also assert no event fired.
            Assert.AreEqual(0, automationEvents.Count, "event count");

            /*
             * Assert.AreEqual (1, automationEvents.Count, "event count");
             * Assert.AreEqual (listView1Element, automationEvents [0].Sender, "event sender");
             * Assert.AreEqual (MultipleViewPattern.CurrentViewProperty, automationEvents [0].Args.Property, "property");
             * Assert.AreEqual (3, automationEvents [0].Args.NewValue, "new value");
             * Assert.AreEqual (1, automationEvents [0].Args.OldValue, "old value");
             * Assert.AreEqual ("List", pattern.GetViewName (currentView), "Current view name" );*/
        }
Beispiel #2
0
        public void PropertyEventTest()
        {
            int eventCount = 0;
            AutomationProperty changedProperty            = null;
            object             newValue                   = null;
            object             sender                     = null;
            AutomationPropertyChangedEventHandler handler = (o, e) =>
            {
                eventCount++;
                changedProperty = e.Property;
                newValue        = e.NewValue;
                sender          = o;
            };

            At.AddAutomationPropertyChangedEventHandler(
                AutomationElement.RootElement, TreeScope.Children,
                handler, AutomationElement.NameProperty);
            RunCommand("change title:title 1");
            Assert.AreEqual(1, eventCount, "count of AutomationPropertyChangedEvent");
            Assert.AreEqual(AutomationElement.NameProperty, changedProperty);
            Assert.AreEqual("title 1", newValue);
            Assert.AreEqual(testFormElement, sender);
            At.RemoveAutomationPropertyChangedEventHandler(
                AutomationElement.RootElement, handler);
            RunCommand("change title:title 2");
            Assert.AreEqual(1, eventCount);
        }
Beispiel #3
0
        //The "Z_" prefix ensures this test runs last, since it will change the column/row count of the data grid
        //todo Currently This test case fails, see #bug 549112
        public void Z_DynamicTest()
        {
            var automationEventsArray = new [] {
                new { Sender = (object)null, Args = (AutomationPropertyChangedEventArgs)null }
            };
            var automationEvents = automationEventsArray.ToList();

            automationEvents.Clear();

            AutomationPropertyChangedEventHandler handler =
                (o, e) => automationEvents.Add(new { Sender = o, Args = e });

            At.AddAutomationPropertyChangedEventHandler(table1Element,
                                                        TreeScope.Element, handler,
                                                        GridPattern.RowCountProperty,
                                                        GridPattern.ColumnCountProperty);

            RunCommand("add table row");
            Assert.AreEqual(1, automationEvents.Count, "event count");
            Assert.AreEqual(table1Element, automationEvents [0].Sender, "event sender");
            Assert.AreEqual(GridPattern.RowCountProperty, automationEvents [0].Args.Property, "property");
            int oldValue = (Atspi? 2: 3);

            Assert.AreEqual(oldValue, automationEvents [0].Args.OldValue, "old value");
            Assert.AreEqual(oldValue + 1, automationEvents [0].Args.NewValue, "new value");
            automationEvents.Clear();

            RunCommand("add table column");
            Assert.AreEqual(1, automationEvents.Count, "event count");
            Assert.AreEqual(table1Element, automationEvents [0].Sender, "event sender");
            Assert.AreEqual(GridPattern.ColumnCountProperty, automationEvents [0].Args.Property, "property");
            Assert.AreEqual(3, automationEvents [0].Args.OldValue, "old value");
            Assert.AreEqual(4, automationEvents [0].Args.NewValue, "new value");
        }
Beispiel #4
0
        public void Z_PropertyEventTest()
        {
            var automationEventsArray = new [] {
                new { Sender = (object)null, Args = (AutomationPropertyChangedEventArgs)null }
            };
            var automationEvents = automationEventsArray.ToList();

            automationEvents.Clear();

            AutomationPropertyChangedEventHandler handler =
                (o, e) => automationEvents.Add(new { Sender = o, Args = e });

            SelectionItemPattern item1 = (SelectionItemPattern)child1Element.GetCurrentPattern(SelectionItemPatternIdentifiers.Pattern);

            item1.Select();
            At.AddAutomationPropertyChangedEventHandler(treeView1Element,
                                                        TreeScope.Subtree, handler,
                                                        SelectionItemPattern.IsSelectedProperty);

            SelectionItemPattern item2 = (SelectionItemPattern)child2Element.GetCurrentPattern(SelectionItemPatternIdentifiers.Pattern);

            item2.Select();
            Thread.Sleep(500);
            At.RemoveAutomationPropertyChangedEventHandler(treeView1Element, handler);
            if (Atspi)
            {
                Assert.AreEqual(2, automationEvents.Count, "event count");
                Assert.AreEqual(child1Element, automationEvents [0].Sender, "event sender");
                Assert.AreEqual(false, automationEvents [0].Args.NewValue, "new Value");
                Assert.AreEqual(true, automationEvents [0].Args.OldValue, "old Value");
                Assert.AreEqual(child2Element, automationEvents [1].Sender, "event sender");
                Assert.AreEqual(true, automationEvents [1].Args.NewValue, "new Value");
                Assert.AreEqual(false, automationEvents [1].Args.OldValue, "old Value");
            }
            else
            {
                // TODO: This all seems wrong; test again with Windows 7
                Assert.AreEqual(1, automationEvents.Count, "event count");
                Assert.AreEqual(child2Element, automationEvents [0].Sender, "event sender");
                Assert.AreEqual(true, automationEvents [0].Args.NewValue, "new Value");
                Assert.IsNull(automationEvents [0].Args.OldValue, "old Value");
            }
            automationEvents.Clear();

            item1.Select();
            Thread.Sleep(500);
            Assert.AreEqual(0, automationEvents.Count, "event count");
        }
        public void ControlTypePropertyChangedEventTest()
        {
            int eventCount = 0;
            AutomationPropertyChangedEventHandler propertyHandler =
                (o, e) => { eventCount++; };

            // textBox3's ControlType will change from "Document" to "Edit" if we set Multiline = false
            // but on Windows we don't have corresponding property changed event.
            At.AddAutomationPropertyChangedEventHandler(textbox3Element, TreeScope.Element,
                                                        propertyHandler, AEIds.ControlTypeProperty);
            var ct = textbox3Element.Current.ControlType;

            Assert.AreEqual(ControlType.Document, ct, ct.ProgrammaticName);

            RunCommand("textBox3 singleline");
            Thread.Sleep(500);

            ct = textbox3Element.Current.ControlType;
            Assert.AreEqual(ControlType.Document, ct, ct.ProgrammaticName);
            textbox3Element = testFormElement.FindFirst(TreeScope.Children,
                                                        new PropertyCondition(AEIds.NameProperty, "textBox3"));

            ct = textbox3Element.Current.ControlType;
            Assert.AreEqual(ControlType.Edit, ct, ct.ProgrammaticName);
            Assert.AreEqual(0, eventCount);

            // listView1's ControlType will change from "DataGrid" to "List" if we set View = View.Tile
            // but on Windows we don't have corresponding property changed event.
            At.AddAutomationPropertyChangedEventHandler(listView1Element, TreeScope.Element,
                                                        propertyHandler, AEIds.ControlTypeProperty);
            ct = listView1Element.Current.ControlType;
            Assert.AreEqual(ControlType.DataGrid, ct, ct.ProgrammaticName);

            RunCommand("change list view mode tile");
            Thread.Sleep(500);

            ct = listView1Element.Current.ControlType;
            Assert.AreEqual(ControlType.DataGrid, ct, ct.ProgrammaticName);
            listView1Element = testFormElement.FindFirst(TreeScope.Descendants,
                                                         new PropertyCondition(AEIds.NameProperty, "listView1"));

            ct = listView1Element.Current.ControlType;
            Assert.AreEqual(ControlType.List, ct, ct.ProgrammaticName);
            Assert.AreEqual(0, eventCount);
        }
Beispiel #6
0
        public void Z_EventTest()
        {
            int eventCount = 0;
            AutomationPropertyChangedEventHandler handler = (o, e) => eventCount++;

            At.AddAutomationPropertyChangedEventHandler(checkBox1Element, TreeScope.Element, handler,
                                                        TogglePattern.ToggleStateProperty);

            TogglePattern pattern = (TogglePattern)checkBox1Element.GetCurrentPattern(TogglePattern.Pattern);

            pattern.Toggle();
            //We should expect an AutomationPropertyChangedEvent here,
            //But since no such event fired on Windows Winforms,
            //then we assert no event fired here
            int expectedEventCount = (Atspi? 1: 0);

            Assert.AreEqual(expectedEventCount, eventCount, "ToggleState changed event");
        }
        public void BoundingRectanglePropertyChangedEventTest()
        {
            int    eventCount = 0;
            object newValue   = null;
            AutomationPropertyChangedEventHandler propertyHandler = (o, e) => {
                eventCount++;
                newValue = e.NewValue;
            };

            At.AddAutomationPropertyChangedEventHandler(testFormElement, TreeScope.Element,
                                                        propertyHandler, AEIds.BoundingRectangleProperty);
            RunCommand("change form size 800x600");
            Thread.Sleep(1000);
            Assert.AreEqual(1, eventCount);
            SW.Rect rect = (SW.Rect)newValue;
            Assert.AreEqual(800, rect.Width, "rect.Width");
            Assert.AreEqual(600, rect.Height, "rect.Height");
        }
Beispiel #8
0
        public void Z_EventTest()
        {
            AutomationElement element = (Atspi
                                ? numericUpDown1Element : hScrollBarElement);
            RangeValuePattern pattern;

            pattern = (RangeValuePattern)element.GetCurrentPattern(RangeValuePatternIdentifiers.Pattern);
            var automationEventsArray = new [] {
                new { Sender = (object)null, Args = (AutomationPropertyChangedEventArgs)null }
            };
            var automationEvents = automationEventsArray.ToList();

            automationEvents.Clear();

            AutomationPropertyChangedEventHandler handler =
                (o, e) => automationEvents.Add(new { Sender = o, Args = e });

            pattern.SetValue(20);

            At.AddAutomationPropertyChangedEventHandler(element,
                                                        TreeScope.Element, handler,
                                                        RangeValuePatternIdentifiers.ValueProperty);
            pattern.SetValue(25);
            if (Atspi)
            {
                Assert.AreEqual(1, automationEvents.Count, "event count");
                Assert.AreEqual(element, automationEvents [0].Sender, "event sender");
                Assert.AreEqual(RangeValuePattern.ValueProperty, automationEvents [0].Args.Property, "property");
                Assert.AreEqual(20, automationEvents [0].Args.OldValue, "old value");
                Assert.AreEqual(25, automationEvents [0].Args.NewValue, "new value");
            }
            else
            {
                Assert.AreEqual(0, automationEvents.Count, "event count");
            }

            At.RemoveAutomationPropertyChangedEventHandler(element,
                                                           handler);
            automationEvents.Clear();
        }
Beispiel #9
0
        public void PropertyEventTest()
        {
            var automationEventsArray = new [] {
                new { Sender = (object)null, Args = (AutomationPropertyChangedEventArgs)null }
            };
            var automationEvents = automationEventsArray.ToList();

            automationEvents.Clear();

            string       magicStr1 = "ValuePatternTest.PropertyEventTest.m1";
            string       magicStr2 = "ValuePatternTest.PropertyEventTest.m2";
            ValuePattern pattern   = (ValuePattern)textbox1Element.GetCurrentPattern(ValuePatternIdentifiers.Pattern);

            pattern.SetValue(magicStr1);
            Thread.Sleep(500);

            AutomationPropertyChangedEventHandler handler =
                (o, e) => automationEvents.Add(new { Sender = o, Args = e });

            At.AddAutomationPropertyChangedEventHandler(textbox1Element,
                                                        TreeScope.Element, handler,
                                                        ValuePattern.ValueProperty,
                                                        ValuePattern.IsReadOnlyProperty);

            pattern.SetValue(magicStr2);
            Thread.Sleep(500);
            Assert.AreEqual(1, automationEvents.Count, "event count");
            Assert.AreEqual(textbox1Element, automationEvents [0].Sender, "event sender");
            Assert.AreEqual(magicStr2, automationEvents [0].Args.NewValue, "new Value");
            // LAMESPEC: The value should be equal to "magicStr1" but is returning null instead
            Assert.IsNull(automationEvents [0].Args.OldValue, "old Value");
            automationEvents.Clear();

            At.RemoveAutomationPropertyChangedEventHandler(textbox1Element, handler);
            pattern.SetValue(magicStr1);
            Thread.Sleep(500);
            Assert.AreEqual(0, automationEvents.Count, "event count");
        }
Beispiel #10
0
        public void SelectionPropertyChangedEventTest()
        {
            int propertyEventCount  = 0;
            int selectionEventCount = 0;
            AutomationPropertyChangedEventHandler propertyHandler =
                (o, e) => { propertyEventCount++; };
            AutomationEventHandler selectionEventHandler =
                (o, e) => { selectionEventCount++; };

            var childElement = treeView1Element.FindFirst(TreeScope.Children,
                                                          new PropertyCondition(AEIds.ControlTypeProperty,
                                                                                ControlType.TreeItem));

            At.AddAutomationPropertyChangedEventHandler(treeView1Element, TreeScope.Subtree,
                                                        propertyHandler, SelectionPattern.SelectionProperty);
            At.AddAutomationEventHandler(SelectionItemPattern.ElementSelectedEvent,
                                         childElement, TreeScope.Element, selectionEventHandler);

            var pattern = (SelectionPattern)
                          treeView1Element.GetCurrentPattern(SelectionPatternIdentifiers.Pattern);

            Assert.IsNotNull(pattern, "selectionPattern should not be null");
            var current = pattern.Current;

            AutomationElement [] selection = current.GetSelection();
            Assert.AreEqual(0, selection.Length, "Selection length");

            var selectionItemPattern = (SelectionItemPattern)
                                       childElement.GetCurrentPattern(SelectionItemPatternIdentifiers.Pattern);

            selectionItemPattern.Select();
            Thread.Sleep(1000);

            selection = current.GetSelection();
            Assert.AreEqual(1, selection.Length, "Selection length");
            Assert.AreEqual(0, propertyEventCount, "# of SelectionProperty changed event");
            Assert.AreEqual(1, selectionEventCount, "# of selection event");
        }
Beispiel #11
0
        public void Z2_EventTest()
        {
            var automationEventsArray = new [] {
                new { Sender = (object)null, Args = (AutomationPropertyChangedEventArgs)null }
            };
            var automationEvents = automationEventsArray.ToList();

            automationEvents.Clear();
            AutomationPropertyChangedEventHandler handler =
                (o, e) => automationEvents.Add(new { Sender = o, Args = e });

            ResetPosition();
            At.AddAutomationPropertyChangedEventHandler(listView1Element,
                                                        TreeScope.Element, handler,
                                                        ScrollPattern.VerticalScrollPercentProperty,
                                                        ScrollPattern.HorizontalScrollPercentProperty,
                                                        ScrollPattern.VerticallyScrollableProperty,
                                                        ScrollPattern.HorizontallyScrollableProperty,
                                                        ScrollPattern.VerticalViewSizeProperty,
                                                        ScrollPattern.HorizontalViewSizeProperty);

            scrollPattern.Scroll(ScrollAmount.LargeIncrement,
                                 ScrollAmount.LargeIncrement);
            UpdatePosition();
            Assert.Greater(vertOffset, 0, "vert scrolled");
            Assert.Greater(horiOffset, 0, "hori scrolled");
            Thread.Sleep(500);
            bool vertChanged = false;
            bool horiChanged = false;

            foreach (var evt in automationEvents)
            {
                var args = evt.Args;
                Assert.AreEqual(listView1Element, evt.Sender, "event sender");
                //On Windows, args.OldValue is always null
                Assert.IsNull(args.OldValue, "event.OldValue");
                if (args.Property == ScrollPattern.VerticalScrollPercentProperty)
                {
                    Assert.Greater((double)args.NewValue, 0.0, "vert scrolled, event.NewValue");
                    vertChanged = true;
                }
                else if (args.Property == ScrollPattern.HorizontalScrollPercentProperty)
                {
                    Assert.Greater((double)args.NewValue, 0.0, "hori scrolled, event.NewValue");
                    horiChanged = true;
                }
            }
            Assert.IsTrue(vertChanged, "vert position event fired");
            Assert.IsTrue(horiChanged, "hori position event fired");

            automationEvents.Clear();
            var oldVertViewSize = scrollPattern.Current.VerticalViewSize;

            RunCommand("add listView1 item");
            var newVertViewSize = scrollPattern.Current.VerticalViewSize;

            Assert.Greater(oldVertViewSize, newVertViewSize, "size expanded, so view shrinked");
            vertChanged = false;
            bool viewSizeChanged = false;

            Thread.Sleep(500);
            foreach (var evt in automationEvents)
            {
                var args = evt.Args;
                Assert.AreEqual(listView1Element, evt.Sender, "event sender");
                //On Windows, args.OldValue is always null
                Assert.IsNull(args.OldValue, "event.OldValue");
                if (args.Property == ScrollPattern.VerticalViewSizeProperty)
                {
                    viewSizeChanged = true;
                }
                else if (args.Property == ScrollPattern.VerticalScrollPercentProperty)
                {
                    vertChanged = true;
                }
            }
            //On Windows, though viewSize changes, no event is fired
            Assert.IsFalse(viewSizeChanged, "viewSize changed event fired");
            Assert.IsTrue(vertChanged, "vert position event fired");

            automationEvents.Clear();
            Assert.IsTrue(scrollPattern.Current.VerticallyScrollable);
            RunCommand("make listView1 higher");
            Assert.IsFalse(scrollPattern.Current.VerticallyScrollable);
            vertChanged     = false;
            viewSizeChanged = false;
            bool scrollableChanged = false;

            Thread.Sleep(500);
            foreach (var evt in automationEvents)
            {
                var args = evt.Args;
                Assert.AreEqual(listView1Element, evt.Sender, "event sender");
                //On Windows, args.OldValue is always null
                Assert.IsNull(args.OldValue, "event.OldValue");
                if (args.Property == ScrollPattern.VerticalViewSizeProperty)
                {
                    viewSizeChanged = true;
                }
                else if (args.Property == ScrollPattern.VerticalScrollPercentProperty)
                {
                    vertChanged = true;
                }
                else if (args.Property == ScrollPattern.VerticallyScrollableProperty)
                {
                    scrollableChanged = true;
                }
            }
            //On Windows, though all Vertical*Property changes, no event is fired
            Assert.IsFalse(viewSizeChanged, "viewSize changed event fired");
            Assert.IsFalse(scrollableChanged, "viewSize changed event fired");
            Assert.IsFalse(vertChanged, "vert position event fired");

            At.RemoveAutomationPropertyChangedEventHandler(listView1Element, handler);
        }
Beispiel #12
0
        public void PropertySelectionEventTest()
        {
            var automationEventsArray = new[] {
                new { Sender = (object)null, Args = (AutomationPropertyChangedEventArgs)null }
            };
            var automationEvents = automationEventsArray.ToList();

            automationEvents.Clear();

            AutomationPropertyChangedEventHandler handler =
                (o, e) => automationEvents.Add(new { Sender = o, Args = e });

            SelectionItemPattern item1
                = (SelectionItemPattern)child3Element.GetCurrentPattern(SelectionItemPatternIdentifiers.Pattern);
            SelectionItemPattern item2
                = (SelectionItemPattern)child4Element.GetCurrentPattern(SelectionItemPatternIdentifiers.Pattern);

            At.AddAutomationPropertyChangedEventHandler(listView1Element,
                                                        TreeScope.Element,
                                                        handler,
                                                        SelectionPattern.SelectionProperty);
            // FIXME: Isolate this conditional
            if (Atspi)
            {
                item1.Select();
                Thread.Sleep(500);
                Assert.AreEqual(1, automationEvents.Count, "#0");
                Assert.AreEqual(listView1Element, automationEvents [0].Sender, "#1");

                AutomationElement[] oldValue = automationEvents [0].Args.OldValue as AutomationElement[];

                Assert.IsNotNull(oldValue, "#2");
                Assert.AreEqual(0, oldValue.Length, "#3");
                AutomationElement[] newValue = automationEvents [0].Args.NewValue as AutomationElement[];
                Assert.IsNotNull(newValue, "#4");
                Assert.AreEqual(1, newValue.Length, "#5");
                Assert.AreEqual(child3Element, newValue [0], "#6");
                automationEvents.Clear();

                item2.Select();
                Thread.Sleep(500);

                // We have 2 events bacause Select firs deselects all elements and then selects the item
                Assert.AreEqual(2, automationEvents.Count, "#7");
                Assert.AreEqual(listView1Element, automationEvents [0].Sender, "#8");

                // First event: deselected-element event
                oldValue = automationEvents [0].Args.OldValue as AutomationElement[];
                Assert.IsNotNull(oldValue, "#9");
                Assert.AreEqual(1, oldValue.Length, "#10");
                Assert.AreEqual(child3Element, newValue [0], "#11");

                newValue = automationEvents [0].Args.NewValue as AutomationElement[];
                Assert.IsNotNull(newValue, "#12");
                Assert.AreEqual(0, newValue.Length, "#13");

                // Second event: selected-element event
                oldValue = automationEvents [1].Args.OldValue as AutomationElement[];
                Assert.IsNotNull(oldValue, "#14");
                Assert.AreEqual(0, oldValue.Length, "#15");

                newValue = automationEvents [1].Args.NewValue as AutomationElement[];
                Assert.IsNotNull(newValue, "#16");
                Assert.AreEqual(1, newValue.Length, "#17");
                Assert.AreEqual(child4Element, newValue [0], "#18");
            }
            else
            {
                item1.Select();
                Thread.Sleep(500);
                // LAMESPEC: SelectionProperty not raised
                Assert.AreEqual(0, automationEvents.Count, "event count #0");

                item2.Select();
                Thread.Sleep(500);
                // LAMESPEC: SelectionProperty not raised
                Assert.AreEqual(0, automationEvents.Count, "event count #1");
            }

            At.RemoveAutomationPropertyChangedEventHandler(listView1Element, handler);
            automationEvents.Clear();

            item1.Select();
            Thread.Sleep(500);
            Assert.AreEqual(0, automationEvents.Count, "event count");
        }
        public void Z_EventTest()
        {
            AutomationElement parentElement;

            parentElement = treeView1Element.FindFirst(TreeScope.Children,
                                                       new PropertyCondition(AEIds.ControlTypeProperty,
                                                                             ControlType.TreeItem));
            ExpandCollapsePattern pattern = (ExpandCollapsePattern)parentElement.GetCurrentPattern(ExpandCollapsePatternIdentifiers.Pattern);

            pattern.Collapse();
            var propertyEventsArray = new [] {
                new { Sender = (object)null, Args = (AutomationPropertyChangedEventArgs)null }
            };
            var propertyEvents = propertyEventsArray.ToList();

            propertyEvents.Clear();

            AutomationPropertyChangedEventHandler propertyHandler =
                (o, e) => propertyEvents.Add(new { Sender = o, Args = e });

            At.AddAutomationPropertyChangedEventHandler(parentElement,
                                                        TreeScope.Element, propertyHandler,
                                                        ExpandCollapsePattern.ExpandCollapseStateProperty);

            pattern.Expand();
            Thread.Sleep(100);
            Assert.AreEqual(1, propertyEvents.Count, "event count");
            Assert.AreEqual(parentElement, propertyEvents [0].Sender, "event sender");
            Assert.AreEqual(ExpandCollapsePattern.ExpandCollapseStateProperty, propertyEvents [0].Args.Property, "property");
            if (Atspi)
            {
                Assert.AreEqual(ExpandCollapseState.Collapsed, propertyEvents [0].Args.OldValue, "old value");
                Assert.AreEqual(ExpandCollapseState.Expanded, propertyEvents [0].Args.NewValue, "new value");
            }
            else
            {
                Assert.AreEqual(null, propertyEvents [0].Args.OldValue, "old value");
                Assert.AreEqual(1, propertyEvents [0].Args.NewValue, "new value");
            }

            propertyEvents.Clear();
            pattern.Collapse();
            Thread.Sleep(100);
            Assert.AreEqual(1, propertyEvents.Count, "event count");
            Assert.AreEqual(parentElement, propertyEvents [0].Sender, "event sender");
            Assert.AreEqual(ExpandCollapsePattern.ExpandCollapseStateProperty, propertyEvents [0].Args.Property, "property");
            if (Atspi)
            {
                Assert.AreEqual(ExpandCollapseState.Expanded, propertyEvents [0].Args.OldValue, "old value");
                Assert.AreEqual(ExpandCollapseState.Collapsed, propertyEvents [0].Args.NewValue, "new value");
            }
            else
            {
                Assert.AreEqual(null, propertyEvents [0].Args.OldValue, "old value");
                Assert.AreEqual(0, propertyEvents [0].Args.NewValue, "new value");
            }

            propertyEvents.Clear();
            pattern.Collapse();
            Thread.Sleep(100);
            Assert.AreEqual(0, propertyEvents.Count, "event count when collapsing but already collapsed");
        }
Beispiel #14
0
        public void ArgumentExceptionTest()
        {
            Action action = () => {
                At.AddAutomationEventHandler(InvokePattern.InvokedEvent,
                                             null, TreeScope.Element, (o, e) => {});
            };

            AssertRaises <ArgumentNullException>(action,
                                                 "Pass null as element to AddAutomationEventHandler");

            action = () => {
                At.AddAutomationPropertyChangedEventHandler(
                    null, TreeScope.Element, (o, e) => {}, AEIds.NameProperty);
            };
            AssertRaises <ArgumentNullException>(action,
                                                 "Pass null as element to AddAutomationPropertyChangedEventHandler");

            action = () => {
                At.AddStructureChangedEventHandler(
                    null, TreeScope.Element, (o, e) => {});
            };
            AssertRaises <ArgumentNullException>(action,
                                                 "Pass null as element to AddStructureChangedEventHandler");

            action = () => {
                At.AddAutomationEventHandler(InvokePattern.InvokedEvent,
                                             button1Element, TreeScope.Element, null);
            };
            AssertRaises <ArgumentNullException>(action,
                                                 "Pass null as handler to AddAutomationEventHandler");

            action = () => {
                At.AddAutomationPropertyChangedEventHandler(
                    button1Element, TreeScope.Element, null, AEIds.NameProperty);
            };
            AssertRaises <ArgumentNullException>(action,
                                                 "Pass null as handler to AddAutomationPropertyChangedEventHandler");

            action = () => {
                At.AddStructureChangedEventHandler(
                    button1Element, TreeScope.Element, null);
            };
            AssertRaises <ArgumentNullException>(action,
                                                 "Pass null as handler to AddStructureChangedEventHandler");

            action = () => {
                At.AddAutomationFocusChangedEventHandler(null);
            };
            AssertRaises <ArgumentNullException>(action,
                                                 "Pass null as handler to AddAutomationFocusChangedEventHandler");

            action = () => {
                At.RemoveAutomationEventHandler(InvokePattern.InvokedEvent,
                                                null, (o, e) => {});
            };
            AssertRaises <ArgumentNullException>(action,
                                                 "Pass null as element to RemoveAutomationEventHandler");

            action = () => {
                At.RemoveAutomationPropertyChangedEventHandler(
                    null, (o, e) => {});
            };
            AssertRaises <ArgumentNullException>(action,
                                                 "Pass null as element to RemoveAutomationPropertyChangedEventHandler");

            action = () => {
                At.RemoveStructureChangedEventHandler(
                    null, (o, e) => {});
            };
            AssertRaises <ArgumentNullException>(action,
                                                 "Pass null as element to RemoveStructureChangedEventHandler");

            action = () => {
                At.RemoveAutomationEventHandler(InvokePattern.InvokedEvent,
                                                button1Element, null);
            };
            AssertRaises <ArgumentNullException>(action,
                                                 "Pass null as handler to RemoveAutomationEventHandler");

            action = () => {
                At.RemoveAutomationPropertyChangedEventHandler(
                    button1Element, null);
            };
            AssertRaises <ArgumentNullException>(action,
                                                 "Pass null as handler to RemoveAutomationPropertyChangedEventHandler");

            action = () => {
                At.RemoveStructureChangedEventHandler(
                    button1Element, null);
            };
            AssertRaises <ArgumentNullException>(action,
                                                 "Pass null as handler to RemoveStructureChangedEventHandler");

            action = () => {
                At.RemoveAutomationFocusChangedEventHandler(null);
            };
            AssertRaises <ArgumentNullException>(action,
                                                 "Pass null as handler to RemoveAutomationFocusChangedEventHandler");

            //Assert removing a non-existent handler won't fire any exception
            At.RemoveAutomationEventHandler(InvokePattern.InvokedEvent,
                                            button1Element, (o, e) => { Console.Write("nop"); });
            At.RemoveAutomationPropertyChangedEventHandler(
                button1Element, (o, e) => { Console.Write("nop"); });
            At.RemoveStructureChangedEventHandler(
                button1Element, (o, e) => { Console.Write("nop"); });
            At.RemoveAutomationFocusChangedEventHandler(
                (o, e) => { Console.Write("nop"); });
        }