AddAutomationFocusChangedEventHandler() public static method

public static AddAutomationFocusChangedEventHandler ( AutomationFocusChangedEventHandler eventHandler ) : void
eventHandler AutomationFocusChangedEventHandler
return void
Exemplo n.º 1
0
        public void SetFocusTest()
        {
            AutomationElement [] expectedFocusedElements = new AutomationElement [] {
                textbox3Element, button2Element
            };

            button2Element.SetFocus();
            AutomationFocusChangedEventHandler handler = (s, e) => actualFocusedElements.Add((AutomationElement)s);

            At.AddAutomationFocusChangedEventHandler(handler);
            actualFocusedElements.Clear();
            textbox3Element.SetFocus();
            Thread.Sleep(100);
            Assert.AreEqual(textbox3Element, AutomationElement.FocusedElement, "FocusedElement");
            button2Element.SetFocus();
            Thread.Sleep(100);
            Assert.AreEqual(button2Element, AutomationElement.FocusedElement, "FocusedElement");
            Thread.Sleep(1000);
            At.RemoveAutomationFocusChangedEventHandler(handler);
            Assert.AreEqual(expectedFocusedElements.Length, actualFocusedElements.Count, "Event handler count");
            for (int i = 0; i < actualFocusedElements.Count; i++)
            {
                Assert.AreEqual(expectedFocusedElements [i], actualFocusedElements [i], "Event handler sender #" + i);
            }
        }
Exemplo n.º 2
0
        public void BasicFocusTest()
        {
            // TODO:
            //Currently FocusTest.BasicFocusTest can pass on Windows, but can't on Linux. The failure reason is that:
            //on Windows, call InvokePattern.Invoke will make corresponding button focused, so we also assert this behavior in the test,
            //however our implementation will not make the button focused after InvokePattern.Invoke.

            AutomationElement [] expectedFocusedElements;
            if (Atspi)
            {
                expectedFocusedElements = new AutomationElement [] {
                    btnRunElement, textbox3Element,
                    btnRunElement, button2Element,
                }
            }
            ;
            else
            {
                expectedFocusedElements = new AutomationElement [] {
                    txtCommandElement, textbox3Element,
                    txtCommandElement, button2Element,
                }
            };

            AutomationFocusChangedEventHandler handler = (s, e) => actualFocusedElements.Add((AutomationElement)s);

            At.AddAutomationFocusChangedEventHandler(handler);
            RunCommand("focus textBox3");
            Assert.AreEqual(textbox3Element, AutomationElement.FocusedElement, "FocusedElement");
            RunCommand("focus button2");
            Assert.AreEqual(button2Element, AutomationElement.FocusedElement, "FocusedElement");
            At.RemoveAutomationFocusChangedEventHandler(handler);
            RunCommand("focus textBox3");
            Assert.AreEqual(textbox3Element, AutomationElement.FocusedElement, "FocusedElement");

            At.AddAutomationFocusChangedEventHandler(handler);
            At.RemoveAllEventHandlers();
            RunCommand("focus button2");
            Assert.AreEqual(button2Element, AutomationElement.FocusedElement, "FocusedElement");

            Assert.AreEqual(expectedFocusedElements.Length, actualFocusedElements.Count, "Event handler count");
            for (int i = 0; i < actualFocusedElements.Count; i++)
            {
                Assert.AreEqual(expectedFocusedElements [i], actualFocusedElements [i], "Event handler sender #" + i);
            }
        }
Exemplo n.º 3
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"); });
        }