Esempio n. 1
0
        //The "Z1_" prefix ensures the test case's execution sequence
        public void Z1_DynamicTest()
        {
            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 });

            At.AddAutomationPropertyChangedEventHandler(listView1Element,
                                                        TreeScope.Element, handler,
                                                        MultipleViewPattern.CurrentViewProperty,
                                                        MultipleViewPattern.SupportedViewsProperty);

            RunCommand("change list view mode list");

            //var currentView = pattern.Current.CurrentView;

            // We should expect an AutomationPropertyChangedEvent here,
            // But since on Windows Winforms didn't fire such a event, then we also assert no event fired.
            Assert.AreEqual(0, automationEvents.Count, "event count");

            /*
             * Assert.AreEqual (1, automationEvents.Count, "event count");
             * Assert.AreEqual (listView1Element, automationEvents [0].Sender, "event sender");
             * Assert.AreEqual (MultipleViewPattern.CurrentViewProperty, automationEvents [0].Args.Property, "property");
             * Assert.AreEqual (3, automationEvents [0].Args.NewValue, "new value");
             * Assert.AreEqual (1, automationEvents [0].Args.OldValue, "old value");
             * Assert.AreEqual ("List", pattern.GetViewName (currentView), "Current view name" );*/
        }
Esempio n. 2
0
        public void InvokeTest()
        {
            int eventCount = 0;
            AutomationEventHandler handler = (o, e) => eventCount++;

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

            InvokePattern pattern = (InvokePattern)button1Element.GetCurrentPattern(InvokePattern.Pattern);

            pattern.Invoke();
            if (Atspi)
            {
                Thread.Sleep(200);
            }
            Assert.AreEqual("button1_click",
                            textbox1Element.GetCurrentPropertyValue(ValuePatternIdentifiers.ValueProperty),
                            "textBox1's text is modified after button1 is clicked");
            Assert.AreEqual("button1_click",
                            label1Element.GetCurrentPropertyValue(AutomationElementIdentifiers.NameProperty),
                            "label1's text is modified after button1 is clicked");
            if (Atspi)
            {
                Assert.AreEqual(1, eventCount, "Invoke event fired");
            }
        }
Esempio n. 3
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);
        }
Esempio n. 4
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);
            }
        }
Esempio n. 5
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");
        }
Esempio n. 6
0
        //The "Z_" prefix ensures this test runs last, since it will change the column/row count of the data grid
        //todo Currently This test case fails, see #bug 549112
        public void Z_DynamicTest()
        {
            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 });

            At.AddAutomationPropertyChangedEventHandler(table1Element,
                                                        TreeScope.Element, handler,
                                                        GridPattern.RowCountProperty,
                                                        GridPattern.ColumnCountProperty);

            RunCommand("add table row");
            Assert.AreEqual(1, automationEvents.Count, "event count");
            Assert.AreEqual(table1Element, automationEvents [0].Sender, "event sender");
            Assert.AreEqual(GridPattern.RowCountProperty, automationEvents [0].Args.Property, "property");
            int oldValue = (Atspi? 2: 3);

            Assert.AreEqual(oldValue, automationEvents [0].Args.OldValue, "old value");
            Assert.AreEqual(oldValue + 1, automationEvents [0].Args.NewValue, "new value");
            automationEvents.Clear();

            RunCommand("add table column");
            Assert.AreEqual(1, automationEvents.Count, "event count");
            Assert.AreEqual(table1Element, automationEvents [0].Sender, "event sender");
            Assert.AreEqual(GridPattern.ColumnCountProperty, automationEvents [0].Args.Property, "property");
            Assert.AreEqual(3, automationEvents [0].Args.OldValue, "old value");
            Assert.AreEqual(4, automationEvents [0].Args.NewValue, "new value");
        }
Esempio n. 7
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");
        }
Esempio n. 8
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");
        }
Esempio n. 9
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");
        }
Esempio n. 10
0
        public void EventTest()
        {
            int eventCount = 0;
            AutomationEventHandler handler = (o, e) => eventCount++;

            At.AddAutomationEventHandler(InvokePattern.InvokedEvent,
                                         child, TreeScope.Element, handler);
            childProvider.PerformInvoke();
            Thread.Sleep(500);
            Assert.AreEqual(1, eventCount);
        }
Esempio n. 11
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);
        }
Esempio n. 12
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");
        }
Esempio n. 13
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);
            }
        }
Esempio n. 14
0
        public void ControlTypePropertyChangedEventTest()
        {
            int eventCount = 0;
            AutomationPropertyChangedEventHandler propertyHandler =
                (o, e) => { eventCount++; };

            // textBox3's ControlType will change from "Document" to "Edit" if we set Multiline = false
            // but on Windows we don't have corresponding property changed event.
            At.AddAutomationPropertyChangedEventHandler(textbox3Element, TreeScope.Element,
                                                        propertyHandler, AEIds.ControlTypeProperty);
            var ct = textbox3Element.Current.ControlType;

            Assert.AreEqual(ControlType.Document, ct, ct.ProgrammaticName);

            RunCommand("textBox3 singleline");
            Thread.Sleep(500);

            ct = textbox3Element.Current.ControlType;
            Assert.AreEqual(ControlType.Document, ct, ct.ProgrammaticName);
            textbox3Element = testFormElement.FindFirst(TreeScope.Children,
                                                        new PropertyCondition(AEIds.NameProperty, "textBox3"));

            ct = textbox3Element.Current.ControlType;
            Assert.AreEqual(ControlType.Edit, ct, ct.ProgrammaticName);
            Assert.AreEqual(0, eventCount);

            // listView1's ControlType will change from "DataGrid" to "List" if we set View = View.Tile
            // but on Windows we don't have corresponding property changed event.
            At.AddAutomationPropertyChangedEventHandler(listView1Element, TreeScope.Element,
                                                        propertyHandler, AEIds.ControlTypeProperty);
            ct = listView1Element.Current.ControlType;
            Assert.AreEqual(ControlType.DataGrid, ct, ct.ProgrammaticName);

            RunCommand("change list view mode tile");
            Thread.Sleep(500);

            ct = listView1Element.Current.ControlType;
            Assert.AreEqual(ControlType.DataGrid, ct, ct.ProgrammaticName);
            listView1Element = testFormElement.FindFirst(TreeScope.Descendants,
                                                         new PropertyCondition(AEIds.NameProperty, "listView1"));

            ct = listView1Element.Current.ControlType;
            Assert.AreEqual(ControlType.List, ct, ct.ProgrammaticName);
            Assert.AreEqual(0, eventCount);
        }
Esempio n. 15
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);
        }
Esempio n. 16
0
        public void Z_EventTest()
        {
            int eventCount = 0;
            AutomationPropertyChangedEventHandler handler = (o, e) => eventCount++;

            At.AddAutomationPropertyChangedEventHandler(checkBox1Element, TreeScope.Element, handler,
                                                        TogglePattern.ToggleStateProperty);

            TogglePattern pattern = (TogglePattern)checkBox1Element.GetCurrentPattern(TogglePattern.Pattern);

            pattern.Toggle();
            //We should expect an AutomationPropertyChangedEvent here,
            //But since no such event fired on Windows Winforms,
            //then we assert no event fired here
            int expectedEventCount = (Atspi? 1: 0);

            Assert.AreEqual(expectedEventCount, eventCount, "ToggleState changed event");
        }
Esempio n. 17
0
        public void BoundingRectanglePropertyChangedEventTest()
        {
            int    eventCount = 0;
            object newValue   = null;
            AutomationPropertyChangedEventHandler propertyHandler = (o, e) => {
                eventCount++;
                newValue = e.NewValue;
            };

            At.AddAutomationPropertyChangedEventHandler(testFormElement, TreeScope.Element,
                                                        propertyHandler, AEIds.BoundingRectangleProperty);
            RunCommand("change form size 800x600");
            Thread.Sleep(1000);
            Assert.AreEqual(1, eventCount);
            SW.Rect rect = (SW.Rect)newValue;
            Assert.AreEqual(800, rect.Width, "rect.Width");
            Assert.AreEqual(600, rect.Height, "rect.Height");
        }
Esempio n. 18
0
        public static AutomationProperty [] GetPatternProperties(AutomationPattern pattern)
        {
            List <AutomationProperty> props = new List <AutomationProperty> ();
            var patternName = string.Format(
                "System.Windows.Automation.{0}Pattern",
                At.PatternName(pattern));
            Type t = typeof(DockPattern).Assembly.GetType(patternName);

            Assert.IsNotNull(t, "Unknown pattern type");
            foreach (FieldInfo info in t.GetFields(
                         BindingFlags.Public | BindingFlags.Static))
            {
                if (info.Name.EndsWith("Property"))
                {
                    props.Add((AutomationProperty)info.GetValue(null));
                }
            }
            return(props.ToArray());
        }
Esempio n. 19
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();
        }
Esempio n. 20
0
        public void SelectionPropertyChangedEventTest()
        {
            int propertyEventCount  = 0;
            int selectionEventCount = 0;
            AutomationPropertyChangedEventHandler propertyHandler =
                (o, e) => { propertyEventCount++; };
            AutomationEventHandler selectionEventHandler =
                (o, e) => { selectionEventCount++; };

            var childElement = treeView1Element.FindFirst(TreeScope.Children,
                                                          new PropertyCondition(AEIds.ControlTypeProperty,
                                                                                ControlType.TreeItem));

            At.AddAutomationPropertyChangedEventHandler(treeView1Element, TreeScope.Subtree,
                                                        propertyHandler, SelectionPattern.SelectionProperty);
            At.AddAutomationEventHandler(SelectionItemPattern.ElementSelectedEvent,
                                         childElement, TreeScope.Element, selectionEventHandler);

            var pattern = (SelectionPattern)
                          treeView1Element.GetCurrentPattern(SelectionPatternIdentifiers.Pattern);

            Assert.IsNotNull(pattern, "selectionPattern should not be null");
            var current = pattern.Current;

            AutomationElement [] selection = current.GetSelection();
            Assert.AreEqual(0, selection.Length, "Selection length");

            var selectionItemPattern = (SelectionItemPattern)
                                       childElement.GetCurrentPattern(SelectionItemPatternIdentifiers.Pattern);

            selectionItemPattern.Select();
            Thread.Sleep(1000);

            selection = current.GetSelection();
            Assert.AreEqual(1, selection.Length, "Selection length");
            Assert.AreEqual(0, propertyEventCount, "# of SelectionProperty changed event");
            Assert.AreEqual(1, selectionEventCount, "# of selection event");
        }
Esempio n. 21
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");
        }
Esempio n. 22
0
        public override bool Equals(object obj)
        {
            var el2 = obj as AutomationElement;

            return(obj != null && !(el2 == null) && Automation.Compare(el1: this, el2: el2));
        }
Esempio n. 23
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);
        }
Esempio n. 24
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"); });
        }
Esempio n. 25
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");
        }
        public void Z_EventTest()
        {
            AutomationElement parentElement;

            parentElement = treeView1Element.FindFirst(TreeScope.Children,
                                                       new PropertyCondition(AEIds.ControlTypeProperty,
                                                                             ControlType.TreeItem));
            ExpandCollapsePattern pattern = (ExpandCollapsePattern)parentElement.GetCurrentPattern(ExpandCollapsePatternIdentifiers.Pattern);

            pattern.Collapse();
            var propertyEventsArray = new [] {
                new { Sender = (object)null, Args = (AutomationPropertyChangedEventArgs)null }
            };
            var propertyEvents = propertyEventsArray.ToList();

            propertyEvents.Clear();

            AutomationPropertyChangedEventHandler propertyHandler =
                (o, e) => propertyEvents.Add(new { Sender = o, Args = e });

            At.AddAutomationPropertyChangedEventHandler(parentElement,
                                                        TreeScope.Element, propertyHandler,
                                                        ExpandCollapsePattern.ExpandCollapseStateProperty);

            pattern.Expand();
            Thread.Sleep(100);
            Assert.AreEqual(1, propertyEvents.Count, "event count");
            Assert.AreEqual(parentElement, propertyEvents [0].Sender, "event sender");
            Assert.AreEqual(ExpandCollapsePattern.ExpandCollapseStateProperty, propertyEvents [0].Args.Property, "property");
            if (Atspi)
            {
                Assert.AreEqual(ExpandCollapseState.Collapsed, propertyEvents [0].Args.OldValue, "old value");
                Assert.AreEqual(ExpandCollapseState.Expanded, propertyEvents [0].Args.NewValue, "new value");
            }
            else
            {
                Assert.AreEqual(null, propertyEvents [0].Args.OldValue, "old value");
                Assert.AreEqual(1, propertyEvents [0].Args.NewValue, "new value");
            }

            propertyEvents.Clear();
            pattern.Collapse();
            Thread.Sleep(100);
            Assert.AreEqual(1, propertyEvents.Count, "event count");
            Assert.AreEqual(parentElement, propertyEvents [0].Sender, "event sender");
            Assert.AreEqual(ExpandCollapsePattern.ExpandCollapseStateProperty, propertyEvents [0].Args.Property, "property");
            if (Atspi)
            {
                Assert.AreEqual(ExpandCollapseState.Expanded, propertyEvents [0].Args.OldValue, "old value");
                Assert.AreEqual(ExpandCollapseState.Collapsed, propertyEvents [0].Args.NewValue, "new value");
            }
            else
            {
                Assert.AreEqual(null, propertyEvents [0].Args.OldValue, "old value");
                Assert.AreEqual(0, propertyEvents [0].Args.NewValue, "new value");
            }

            propertyEvents.Clear();
            pattern.Collapse();
            Thread.Sleep(100);
            Assert.AreEqual(0, propertyEvents.Count, "event count when collapsing but already collapsed");
        }