RemoveAutomationEventHandler() public static method

public static RemoveAutomationEventHandler ( AutomationEvent eventId, AutomationElement element, AutomationEventHandler eventHandler ) : void
eventId AutomationEvent
element AutomationElement
eventHandler AutomationEventHandler
return void
Beispiel #1
0
        public void Z_AutomationEventTest()
        {
            var automationEventsArray = new [] {
                new { Sender = (object)null, Args = (AutomationEventArgs)null }
            };
            var automationEvents = automationEventsArray.ToList();

            automationEvents.Clear();

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

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

            item1.Select();

            AutomationEvent eventId = SelectionItemPattern.ElementSelectedEvent;

            At.AddAutomationEventHandler(eventId,
                                         treeView1Element, TreeScope.Descendants, handler);

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

            item2.Select();
            Thread.Sleep(500);
            At.RemoveAutomationEventHandler(eventId, treeView1Element, handler);
            Assert.AreEqual(1, automationEvents.Count, "event count");
            Assert.AreEqual(child2Element, automationEvents [0].Sender, "event sender");
            Assert.AreEqual(SelectionItemPattern.ElementSelectedEvent, automationEvents [0].Args.EventId, "EventId");
            automationEvents.Clear();

            item1.Select();
            Thread.Sleep(500);
            Assert.AreEqual(0, automationEvents.Count, "event count");
        }
Beispiel #2
0
        public void InvokeEventTest()
        {
            int eventCount = 0;
            AutomationEventHandler handler = (o, e) => eventCount++;

            At.AddAutomationEventHandler(InvokePattern.InvokedEvent, button1Element,
                                         TreeScope.Element, handler);

            AssertRaises <ArgumentException> (
                () => At.RemoveAutomationEventHandler(AutomationElementIdentifiers.AutomationPropertyChangedEvent, button1Element, handler),
                "AutomationPropertyChangedEvent is not valid");

            //Shall have no effect.
            At.RemoveAutomationEventHandler(InvokePattern.InvokedEvent, testFormElement, handler);
            RunCommand("click button1");
            Assert.AreEqual(1, eventCount, "Invoke event fired");

            eventCount = 0;
            At.RemoveAutomationEventHandler(InvokePattern.InvokedEvent, button1Element, handler);
            RunCommand("click button1");
            Assert.AreEqual(0, eventCount, "Invoke event not fired");
            eventCount = 0;
            //Test for add the same handler again.
            At.AddAutomationEventHandler(InvokePattern.InvokedEvent, button1Element,
                                         TreeScope.Element, handler);
            At.AddAutomationEventHandler(InvokePattern.InvokedEvent, button1Element,
                                         TreeScope.Element, handler);
            RunCommand("click button1");
            Assert.AreEqual(2, eventCount, "Invoke event fired");

            eventCount = 0;
            At.RemoveAllEventHandlers();
            RunCommand("click button1");
            Assert.AreEqual(0, eventCount, "Invoke event not fired");
        }
Beispiel #3
0
        public void TextSelectionChangedEvent()
        {
            int eventCount = 0;
            AutomationEventHandler handler = (o, e) => eventCount++;

            At.AddAutomationEventHandler(TextPattern.TextSelectionChangedEvent, textbox3Element,
                                         TreeScope.Element, handler);
            RunCommand("select textbox3");
            Assert.AreEqual(1, eventCount, "TextSelectionChangedEvent fired");

            At.RemoveAutomationEventHandler(TextPattern.TextSelectionChangedEvent, textbox3Element, handler);
        }
Beispiel #4
0
        //todo this test will fail since we won't even fire the TextChangedEvent at
        //provider/bridge side
        public void TextChangedEvent()
        {
            int eventCount = 0;
            AutomationEventHandler handler = (o, e) => eventCount++;

            At.AddAutomationEventHandler(TextPattern.TextChangedEvent, textbox3Element,
                                         TreeScope.Element, handler);
            RunCommand("set textbox3 text");
            Thread.Sleep(500);
            // Ideally we should only receive one event, but at-spi
            // generates a text-changed::delete followed by a
            // text-changed::insert.
            int expectedEventCount = (Atspi? 2: 1);

            Assert.AreEqual(expectedEventCount, eventCount, "TextChangedEvent fired");

            At.RemoveAutomationEventHandler(TextPattern.TextChangedEvent, textbox3Element, handler);
        }
        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"); });
        }