RemoveStructureChangedEventHandler() public static method

public static RemoveStructureChangedEventHandler ( AutomationElement element, StructureChangedEventHandler eventHandler ) : void
element AutomationElement
eventHandler StructureChangedEventHandler
return void
Ejemplo n.º 1
0
        public void StructureEventTest()
        {
            List <AutomationElement>     elementEventSenders      = new List <AutomationElement> ();
            List <StructureChangeType>   elementEventChangeTypes  = new List <StructureChangeType> ();
            List <AutomationElement>     childrenEventSenders     = new List <AutomationElement> ();
            List <StructureChangeType>   childrenEventChangeTypes = new List <StructureChangeType> ();
            StructureChangedEventHandler elementHandler           = delegate(object sender, StructureChangedEventArgs args) {
                elementEventSenders.Add(sender as AutomationElement);
                elementEventChangeTypes.Add(args.StructureChangeType);
            };

            At.AddStructureChangedEventHandler(panel1Element, TreeScope.Element, elementHandler);
            StructureChangedEventHandler childrenHandler = delegate(object sender, StructureChangedEventArgs args) {
                childrenEventSenders.Add(sender as AutomationElement);
                childrenEventChangeTypes.Add(args.StructureChangeType);
            };

            At.AddStructureChangedEventHandler(panel1Element, TreeScope.Children, childrenHandler);
            InvokePattern addAction    = (InvokePattern)btnAddTextboxElement.GetCurrentPattern(InvokePattern.Pattern);
            InvokePattern removeAction = (InvokePattern)btnRemoveTextboxElement.GetCurrentPattern(InvokePattern.Pattern);

            addAction.Invoke();
            Thread.Sleep(1000);
            Assert.AreEqual(1, elementEventSenders.Count, "Check event count");
            Assert.AreEqual(panel1Element, elementEventSenders [0], "Check ChildrenInvalidated event sender");
            Assert.AreEqual(StructureChangeType.ChildrenInvalidated,
                            elementEventChangeTypes [0], "Check ChildrenInvalidated event type");
            Assert.AreEqual(1, childrenEventSenders.Count, "Check event count");
            Assert.AreEqual(StructureChangeType.ChildAdded,
                            childrenEventChangeTypes [0], "Check ChildAdded event type");
            removeAction.Invoke();
            Thread.Sleep(1000);
            Assert.AreEqual(3, elementEventSenders.Count, "Check event count");
            Assert.AreEqual(panel1Element, elementEventSenders [1], "Check event sender");
            Assert.AreEqual(panel1Element, elementEventSenders [2], "Check event sender");
            Assert.IsTrue((elementEventChangeTypes [1] == StructureChangeType.ChildRemoved &&
                           elementEventChangeTypes [2] == StructureChangeType.ChildrenInvalidated) ||
                          (elementEventChangeTypes [1] == StructureChangeType.ChildrenInvalidated &&
                           elementEventChangeTypes [2] == StructureChangeType.ChildRemoved),
                          "Check event type");
            addAction.Invoke();
            Thread.Sleep(1000);
            Assert.AreEqual(4, elementEventSenders.Count, "Check event count");
            Assert.AreEqual(panel1Element, elementEventSenders [3], "Check ChildrenInvalidated event sender");
            Assert.AreEqual(StructureChangeType.ChildrenInvalidated,
                            elementEventChangeTypes [3], "Check ChildrenInvalidated event type");
            Assert.AreEqual(2, childrenEventSenders.Count, "Check event count");
            Assert.AreEqual(StructureChangeType.ChildAdded,
                            childrenEventChangeTypes [1], "Check ChildAdded event type");

            At.RemoveStructureChangedEventHandler(panel1Element, elementHandler);
            At.RemoveStructureChangedEventHandler(panel1Element, childrenHandler);
            addAction.Invoke();
            Thread.Sleep(1000);
            Assert.AreEqual(4, elementEventSenders.Count, "Element event count didn't change");
            Assert.AreEqual(2, childrenEventSenders.Count, "Children event count didn't change");
        }
Ejemplo n.º 2
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"); });
        }