RemoveAllEventHandlers() публичный статический Метод

public static RemoveAllEventHandlers ( ) : void
Результат void
Пример #1
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");
        }
Пример #2
0
        public void StructureEventTest()
        //this test also tested WindowPattern.WindowOpenedEvent (i.e. AddAutomationEventHandler)
        {
            int                    automationEventCount = 0;
            int                    structureEventCount  = 0;
            AutomationEvent        eventId = null;
            AutomationEventHandler automationEventHandler = (o, e) =>
            {
                automationEventCount++;
                eventId = e.EventId;
            };

            At.AddAutomationEventHandler(
                WindowPattern.WindowOpenedEvent,
                AutomationElement.RootElement, TreeScope.Children,
                automationEventHandler);
            StructureChangedEventHandler structureEventHandler = (o, e) =>
            {
                if (e.StructureChangeType == StructureChangeType.ChildAdded)
                {
                    structureEventCount++;
                }
            };

            At.AddStructureChangedEventHandler(
                AutomationElement.RootElement, TreeScope.Children, structureEventHandler);
            int pid = OpenForm();

            Thread.Sleep(3000);
            Assert.AreEqual(1, structureEventCount, "[OpenForm] count of StructureChangedEvent");
            Assert.AreEqual(1, automationEventCount, "[OpenForm] count of WindowOpenedEvent");
            Assert.AreEqual(WindowPattern.WindowOpenedEvent, eventId);

            automationEventCount = 0;
            structureEventCount  = 0;
            At.RemoveAllEventHandlers();
            int pid2 = OpenForm();

            Thread.Sleep(3000);
            Assert.AreEqual(0, structureEventCount);
            Assert.AreEqual(0, automationEventCount);

            structureEventHandler = (o, e) =>
            {
                structureEventCount++;
            };
            At.AddStructureChangedEventHandler(
                AutomationElement.RootElement, TreeScope.Children, structureEventHandler);
            CloseForm(pid);
            CloseForm(pid2);
            Thread.Sleep(3000);
            // Note: I expect 2 events here (whose StructureChangeType are both ChildRemoved)
            // But as tested on Win 7, we'll actually get no event,
            // And with our current implementation, we'll get 4 events (i.e. besides the 2 expected events, we
            // get other 2 ChildRemoved events, whose sender is the "testFormElement")
            Assert.AreEqual(0, structureEventCount, "[CloseForm] count of StructureChangedEvent");
        }
Пример #3
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);
            }
        }