RemoveAutomationPropertyChangedEventHandler() public static method

public static RemoveAutomationPropertyChangedEventHandler ( AutomationElement element, AutomationPropertyChangedEventHandler eventHandler ) : void
element AutomationElement
eventHandler AutomationPropertyChangedEventHandler
return void
Ejemplo n.º 1
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);
        }
Ejemplo n.º 2
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");
        }
Ejemplo n.º 3
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();
        }
Ejemplo n.º 4
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");
        }
Ejemplo n.º 5
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);
        }
Ejemplo n.º 6
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");
        }
Ejemplo n.º 7
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"); });
        }