예제 #1
0
        public void InvokeProvider_Events()
        {
            if (!EventsManager.Instance.AutomationSingletonExists)
            {
                EnqueueTestComplete();
                return;
            }

            TestPanel.Children.Clear();
            datagrid = CreateDataGrid();
            IInvokeProvider      provider = null;
            AutomationEventTuple tuple    = null;
            AutomationPeer       peer     = null;

            CreateAsyncTest(datagrid,
                            () => {
                peer     = GetDataGridColumnHeader(datagrid);
                provider = (IInvokeProvider)peer.GetPattern(PatternInterface.Invoke);
                Assert.IsNotNull(provider, "GetPattern #0");
                EventsManager.Instance.Reset();
            },
                            () => {
                tuple = EventsManager.Instance.GetAutomationEventFrom(peer, AutomationEvents.InvokePatternOnInvoked);
                Assert.IsNull(tuple, "GetAutomationEventFrom #0");
                provider.Invoke();
            },
                            () => {
                tuple = EventsManager.Instance.GetAutomationEventFrom(peer, AutomationEvents.InvokePatternOnInvoked);
                Assert.IsNotNull(tuple, "GetAutomationEventFrom #1");
            });
        }
예제 #2
0
        public override void GetChildrenChanged()
        {
            if (!EventsManager.Instance.AutomationSingletonExists)
            {
                EnqueueTestComplete();
                return;
            }

            TestPanel.Children.Clear();
            datagrid = CreateDataGrid();

            ContentControl        control  = null;
            AutomationPeer        peer     = null;
            List <AutomationPeer> children = null;
            AutomationEventTuple  tuple    = null;
            object oldContent = null;

            CreateAsyncTest(datagrid,
                            () => {
                peer       = GetDataGridColumnHeader(datagrid);
                control    = ((FrameworkElementAutomationPeer)peer).Owner as ContentControl;
                oldContent = control.Content;
                Assert.IsNotNull(peer, "Peer");
                children = peer.GetChildren();
                Assert.IsNotNull(children, "GetChildren #0");
                Assert.AreEqual(1, children.Count, "GetChildren #1");
            },
                            () => {
                control.Content = "Hello";
            },
                            () => {
                children = peer.GetChildren();
                Assert.IsNotNull(children, "GetChildren #1");
                Assert.AreEqual(1, children.Count, "Children.Count #0");
                tuple = EventsManager.Instance.GetAutomationEventFrom(peer, AutomationEvents.StructureChanged);
                Assert.IsNotNull(tuple, "StructureChanged #0");
                EventsManager.Instance.Reset();
            },
                            () => control.Content = null,
                            () => {
                Assert.IsNotNull(peer.GetChildren(), "GetChildren #3");
                tuple = EventsManager.Instance.GetAutomationEventFrom(peer, AutomationEvents.StructureChanged);
                Assert.IsNotNull(tuple, "StructureChanged #1");
                EventsManager.Instance.Reset();

                control.Content = oldContent;
            },
                            () => {
                children = peer.GetChildren();
                Assert.IsNotNull(children, "GetChildren #4");
                Assert.AreEqual(1, children.Count, "Children.Count #1");
                tuple = EventsManager.Instance.GetAutomationEventFrom(peer, AutomationEvents.StructureChanged);
                Assert.IsNotNull(tuple, "StructureChanged #6");
            });
        }
예제 #3
0
        public virtual void StructureChanged_Events()
        {
            if (!EventsManager.Instance.AutomationSingletonExists)
            {
                EnqueueTestComplete();
                return;
            }

            bool         concreteLoaded = false;
            ItemsControl concrete       = CreateConcreteFrameworkElement() as ItemsControl;

            concrete.Loaded += (o, e) => concreteLoaded = true;
            TestPanel.Children.Add(concrete);

            EnqueueConditional(() => concreteLoaded, "ConcreteLoaded #0");
            Enqueue(() => concrete.ApplyTemplate());
            Enqueue(() => {
                AutomationPeer peer = FrameworkElementAutomationPeer.CreatePeerForElement(concrete);
                Assert.IsNotNull(peer, "FrameworkElementAutomationPeer.CreatePeerForElement #0");
                AutomationEventTuple tuple
                    = EventsManager.Instance.GetAutomationEventFrom(peer, AutomationEvents.StructureChanged);
                Assert.IsNull(tuple, "GetAutomationEventFrom #0");
            });
            Enqueue(() => {
                EventsManager.Instance.Reset();
                concrete.Items.Add(new ListBoxItem()
                {
                    Content = "Item 0"
                });
            });
            Enqueue(() => {
                AutomationPeer peer = FrameworkElementAutomationPeer.CreatePeerForElement(concrete);
                Assert.IsNotNull(peer, "FrameworkElementAutomationPeer.CreatePeerForElement #1");
                AutomationEventTuple tuple
                    = EventsManager.Instance.GetAutomationEventFrom(peer, AutomationEvents.StructureChanged);
                Assert.IsNotNull(tuple, "GetAutomationEventFrom #1");
            });
            Enqueue(() => {
                EventsManager.Instance.Reset();
                concrete.Items.RemoveAt(0);
            });
            Enqueue(() => {
                AutomationPeer peer = FrameworkElementAutomationPeer.CreatePeerForElement(concrete);
                Assert.IsNotNull(peer, "FrameworkElementAutomationPeer.CreatePeerForElement #2");
                AutomationEventTuple tuple
                    = EventsManager.Instance.GetAutomationEventFrom(peer, AutomationEvents.StructureChanged);
                Assert.IsNotNull(tuple, "GetAutomationEventFrom #2");
            });
            EnqueueTestComplete();
        }
예제 #4
0
        protected void Test_InvokeProvider_Events(ButtonBase element)
        {
            AutomationPeer peer = FrameworkElementAutomationPeer.CreatePeerForElement(element);

            IInvokeProvider provider
                = (IInvokeProvider)peer.GetPattern(PatternInterface.Invoke);

            Assert.IsNotNull(provider, "GetPattern #0");

            EventsManager.Instance.Reset();

            AutomationEventTuple tuple
                = EventsManager.Instance.GetAutomationEventFrom(peer, AutomationEvents.InvokePatternOnInvoked);

            Assert.IsNull(tuple, "GetAutomationEventFrom #0");

            provider.Invoke();
            tuple = EventsManager.Instance.GetAutomationEventFrom(peer, AutomationEvents.InvokePatternOnInvoked);
            Assert.IsNotNull(tuple, "GetAutomationEventFrom #1");
        }
예제 #5
0
        public void StructureChanged_Events()
        {
            if (!EventsManager.Instance.AutomationSingletonExists)
            {
                EnqueueTestComplete();
                return;
            }

            bool      scrollbarLoaded        = false;
            bool      scrollbarLayoutUpdated = false;
            ScrollBar scrollbar = new ScrollBar();

            scrollbar.Orientation = Orientation.Vertical;
            scrollbar.Loaded     += (o, e) => scrollbarLoaded = true;
            TestPanel.Children.Add(scrollbar);

            ScrollBarAutomationPeerPoker sbapp = new ScrollBarAutomationPeerPoker(scrollbar);

            EnqueueConditional(() => scrollbarLoaded, "ScrollBarLoaded #0");
            Enqueue(() => {
                AutomationPeer peer = FrameworkElementAutomationPeer.CreatePeerForElement(scrollbar);
                Assert.IsNotNull(peer, "FrameworkElementAutomationPeer.CreatePeerForElement");

                List <AutomationPeer> children = sbapp.GetChildren();
                Assert.IsNotNull(children, "GetChildren #0");
                Assert.AreEqual(5, children.Count, "GetChildren #1");
                scrollbar.LayoutUpdated += (o, e) => scrollbarLayoutUpdated = true;
                EventsManager.Instance.Reset();
                scrollbar.Orientation = Orientation.Horizontal;
            });
            EnqueueConditional(() => scrollbarLayoutUpdated, "ScrollBarLayoutUpdated #0");
            Enqueue(() => {
                AutomationPeer peer = FrameworkElementAutomationPeer.CreatePeerForElement(scrollbar);
                Assert.IsNotNull(peer, "FrameworkElementAutomationPeer.CreatePeerForElement");

                AutomationEventTuple tuple = EventsManager.Instance.GetAutomationEventFrom(peer, AutomationEvents.StructureChanged);
                Assert.IsNotNull(tuple, "AutomationEvents.StructureChanged #0");
            });
            EnqueueTestComplete();
        }
예제 #6
0
        public override void StructureChanged_Events()
        {
            if (!EventsManager.Instance.AutomationSingletonExists)
            {
                EnqueueTestComplete();
                return;
            }
            AutomationPeer peer       = null;
            TabControl     tabControl = CreateConcreteFrameworkElement() as TabControl;

            CreateAsyncTest(tabControl,
                            () => {
                peer = FrameworkElementAutomationPeer.CreatePeerForElement(tabControl);
                Assert.IsNotNull(peer, "FrameworkElementAutomationPeer.CreatePeerForElement #0");
                AutomationEventTuple tuple
                    = EventsManager.Instance.GetAutomationEventFrom(peer, AutomationEvents.StructureChanged);
                Assert.IsNull(tuple, "GetAutomationEventFrom #0");
            },
                            () => {
                EventsManager.Instance.Reset();
                tabControl.Items.Add(new TabItem()
                {
                    Header = "Item 0"
                });
            },
                            () => {
                AutomationEventTuple tuple
                    = EventsManager.Instance.GetAutomationEventFrom(peer, AutomationEvents.StructureChanged);
                Assert.IsNotNull(tuple, "GetAutomationEventFrom #1");
            },
                            () => {
                EventsManager.Instance.Reset();
                tabControl.Items.RemoveAt(0);
            },
                            () => {
                AutomationEventTuple tuple
                    = EventsManager.Instance.GetAutomationEventFrom(peer, AutomationEvents.StructureChanged);
                Assert.IsNotNull(tuple, "GetAutomationEventFrom #2");
            });
        }
예제 #7
0
        public override void GetChildrenChanged()
        {
            if (!EventsManager.Instance.AutomationSingletonExists)
            {
                EnqueueTestComplete();
                return;
            }

            TabControl tabControl = new TabControl();
            TabItem    tabItem    = new TabItem();

            tabControl.Items.Add(tabItem);
            AutomationPeer       peerTab = null;
            AutomationPeer       peer    = null;
            AutomationEventTuple tuple   = null;

            CreateAsyncTest(tabControl,
                            () => {
                peerTab = FrameworkElementAutomationPeer.CreatePeerForElement(tabControl);
                Assert.IsNotNull(peerTab, "#0");

                List <AutomationPeer> children = peerTab.GetChildren();
                Assert.IsNotNull(children, "GetChildren #0");
                Assert.AreEqual(1, children.Count, "GetChildren.Count #0");

                peer = FrameworkElementAutomationPeer.CreatePeerForElement(tabItem);
                Assert.IsNotNull(peer, "#0");
                children = peer.GetChildren();
                Assert.IsNull(children, "GetChildren #1");
            },
                            () => {
                StackPanel panel = new StackPanel();
                tabItem.Content  = panel;
                panel.Children.Add(new TextBlock()
                {
                    Text = "Content"
                });
            },
                            () => {
                tuple = EventsManager.Instance.GetAutomationEventFrom(peer, AutomationEvents.StructureChanged);
                Assert.IsNotNull(tuple, "StructureChanged #0");

                List <AutomationPeer> children = peer.GetChildren();
                Assert.IsNotNull(children, "GetChildren #2");
                Assert.AreEqual(1, children.Count, "GetChildren.Count #2");
            },
                            () => {
                StackPanel panel = (StackPanel)tabItem.Content;
                panel.Children.Add(new TextBlock()
                {
                    Text = "Content"
                });
            },
                            () => {
                tuple = EventsManager.Instance.GetAutomationEventFrom(peer, AutomationEvents.StructureChanged);
                Assert.IsNotNull(tuple, "StructureChanged #1");

                List <AutomationPeer> children = peer.GetChildren();
                Assert.IsNotNull(children, "GetChildren #3");
                Assert.AreEqual(2, children.Count, "GetChildren.Count #3");
            });
        }
        public virtual void ISelectionItemProvider_Events()
        {
            if (!EventsManager.Instance.AutomationSingletonExists)
            {
                EnqueueTestComplete();
                return;
            }

            ListBox     listbox      = new ListBox();
            ListBoxItem selectorItem = CreateConcreteFrameworkElement() as ListBoxItem;

            selectorItem.Content = "1";
            ListBoxItem secondSelectorItem = new ListBoxItem()
            {
                Content = "2"
            };

            listbox.Items.Add(selectorItem);
            listbox.Items.Add(secondSelectorItem);

            AutomationPeer               peer  = null;
            AutomationPeer               peer1 = null;
            AutomationPeer               peer2 = null;
            ISelectionItemProvider       selectionItemProvider1 = null;
            ISelectionItemProvider       selectionItemProvider2 = null;
            AutomationEventTuple         tuple         = null;
            AutomationPropertyEventTuple propertyTuple = null;

            CreateAsyncTest(listbox,
                            () => {
                peer  = FrameworkElementAutomationPeer.CreatePeerForElement(listbox);
                peer1 = FrameworkElementAutomationPeer.CreatePeerForElement(selectorItem);
                peer2 = FrameworkElementAutomationPeer.CreatePeerForElement(secondSelectorItem);

                selectionItemProvider1 = peer1.GetPattern(PatternInterface.SelectionItem) as ISelectionItemProvider;
                Assert.IsNotNull(selectionItemProvider1, "SelectionItem Provider #0");

                selectionItemProvider2 = peer2.GetPattern(PatternInterface.SelectionItem) as ISelectionItemProvider;
                Assert.IsNotNull(selectionItemProvider2, "SelectionItem Provider #1");

                // By default both are not selected
                Assert.IsFalse(selectionItemProvider1.IsSelected, "IsSelected #0");
                Assert.IsFalse(selectionItemProvider2.IsSelected, "IsSelected #1");
            },
                            () => {
                EventsManager.Instance.Reset();
                selectionItemProvider1.AddToSelection();
            },
                            () => {
                Assert.IsTrue(selectionItemProvider1.IsSelected, "IsSelected #2");
                Assert.IsFalse(selectionItemProvider2.IsSelected, "IsSelected #3");

                tuple = EventsManager.Instance.GetAutomationEventFrom(peer1, AutomationEvents.SelectionItemPatternOnElementSelected);
                Assert.IsNotNull(tuple, "GetAutomationEventFrom #0");

                propertyTuple = EventsManager.Instance.GetAutomationEventFrom(peer1, SelectionItemPatternIdentifiers.IsSelectedProperty);
                Assert.IsNotNull(propertyTuple, "GetPropertyAutomationEventFrom #0");
                Assert.IsFalse((bool)propertyTuple.OldValue, "GetPropertyAutomationEventFrom.OldValue #0");
                Assert.IsTrue((bool)propertyTuple.NewValue, "GetPropertyAutomationEventFrom.NewValue #0");

                EventsManager.Instance.Reset();
                selectionItemProvider1.Select();                  // Nothing really changes
            },
                            () => {
                tuple = EventsManager.Instance.GetAutomationEventFrom(peer1, AutomationEvents.SelectionItemPatternOnElementSelected);
                Assert.IsNull(tuple, "GetAutomationEventFrom #1");

                propertyTuple = EventsManager.Instance.GetAutomationEventFrom(peer1, SelectionItemPatternIdentifiers.IsSelectedProperty);
                Assert.IsNull(propertyTuple, "GetPropertyAutomationEventFrom #1");

                Assert.IsTrue(selectionItemProvider1.IsSelected, "IsSelected #4");
                Assert.IsFalse(selectionItemProvider2.IsSelected, "IsSelected #5");

                // Throws exception because an element is already selected
                Assert.Throws <InvalidOperationException>(delegate {
                    selectionItemProvider2.AddToSelection();
                }, "AddToSelection #0");

                Assert.IsTrue(selectionItemProvider1.IsSelected, "IsSelected #6");
                Assert.IsFalse(selectionItemProvider2.IsSelected, "IsSelected #7");
            },
                            () => {
                EventsManager.Instance.Reset();
                selectionItemProvider1.RemoveFromSelection();
            },
                            () => {
                tuple = EventsManager.Instance.GetAutomationEventFrom(peer1, AutomationEvents.SelectionItemPatternOnElementSelected);
                Assert.IsNull(tuple, "GetAutomationEventFrom #2");

                tuple = EventsManager.Instance.GetAutomationEventFrom(peer2, AutomationEvents.SelectionItemPatternOnElementSelected);
                Assert.IsNull(tuple, "GetAutomationEventFrom #3");

                propertyTuple = EventsManager.Instance.GetAutomationEventFrom(peer1, SelectionItemPatternIdentifiers.IsSelectedProperty);
                Assert.IsNotNull(propertyTuple, "GetPropertyAutomationEventFrom #2");
                Assert.IsTrue((bool)propertyTuple.OldValue, "GetPropertyAutomationEventFrom.OldValue #1");
                Assert.IsFalse((bool)propertyTuple.NewValue, "GetPropertyAutomationEventFrom.NewValue #1");

                Assert.IsFalse(selectionItemProvider1.IsSelected, "IsSelected #8");
                Assert.IsFalse(selectionItemProvider2.IsSelected, "IsSelected #9");
            },
                            () => {
                EventsManager.Instance.Reset();
                selectionItemProvider2.AddToSelection();
            },
                            () => {
                tuple = EventsManager.Instance.GetAutomationEventFrom(peer1, AutomationEvents.SelectionItemPatternOnElementSelected);
                Assert.IsNull(tuple, "GetAutomationEventFrom #4");

                tuple = EventsManager.Instance.GetAutomationEventFrom(peer2, AutomationEvents.SelectionItemPatternOnElementSelected);
                Assert.IsNotNull(tuple, "GetAutomationEventFrom #5");

                propertyTuple = EventsManager.Instance.GetAutomationEventFrom(peer2, SelectionItemPatternIdentifiers.IsSelectedProperty);
                Assert.IsNotNull(propertyTuple, "GetPropertyAutomationEventFrom #3");
                Assert.IsFalse((bool)propertyTuple.OldValue, "GetPropertyAutomationEventFrom.OldValue #2");
                Assert.IsTrue((bool)propertyTuple.NewValue, "GetPropertyAutomationEventFrom.NewValue #2");

                Assert.IsFalse(selectionItemProvider1.IsSelected, "IsSelected #10");
                Assert.IsTrue(selectionItemProvider2.IsSelected, "IsSelected #11");
            },
                            () => {
                EventsManager.Instance.Reset();
                selectionItemProvider2.Select();                  // Nothing really changes
            },
                            () => {
                tuple = EventsManager.Instance.GetAutomationEventFrom(peer2, AutomationEvents.SelectionItemPatternOnElementSelected);
                Assert.IsNull(tuple, "GetAutomationEventFrom #6");

                tuple = EventsManager.Instance.GetAutomationEventFrom(peer1, AutomationEvents.SelectionItemPatternOnElementSelected);
                Assert.IsNull(tuple, "GetAutomationEventFrom #7");

                propertyTuple = EventsManager.Instance.GetAutomationEventFrom(peer2, SelectionItemPatternIdentifiers.IsSelectedProperty);
                Assert.IsNull(propertyTuple, "GetPropertyAutomationEventFrom #4");

                Assert.IsFalse(selectionItemProvider1.IsSelected, "IsSelected #12");
                Assert.IsTrue(selectionItemProvider2.IsSelected, "IsSelected #13");
            },
                            () => {
                EventsManager.Instance.Reset();
                selectionItemProvider2.RemoveFromSelection();
            },
                            () => {
                tuple = EventsManager.Instance.GetAutomationEventFrom(peer2, AutomationEvents.SelectionItemPatternOnElementSelected);
                Assert.IsNull(tuple, "GetAutomationEventFrom #7");

                propertyTuple = EventsManager.Instance.GetAutomationEventFrom(peer2, SelectionItemPatternIdentifiers.IsSelectedProperty);
                Assert.IsNotNull(propertyTuple, "GetPropertyAutomationEventFrom #6");
                Assert.IsTrue((bool)propertyTuple.OldValue, "GetPropertyAutomationEventFrom.OldValue #4");
                Assert.IsFalse((bool)propertyTuple.NewValue, "GetPropertyAutomationEventFrom.NewValue #4");

                Assert.IsFalse(selectionItemProvider1.IsSelected, "IsSelected #14");
                Assert.IsFalse(selectionItemProvider2.IsSelected, "IsSelected #15");
            },
                            () => {
                EventsManager.Instance.Reset();
                selectionItemProvider1.Select();
            },
                            () => {
                tuple = EventsManager.Instance.GetAutomationEventFrom(peer1, AutomationEvents.SelectionItemPatternOnElementSelected);
                Assert.IsNotNull(tuple, "GetAutomationEventFrom #8");

                tuple = EventsManager.Instance.GetAutomationEventFrom(peer2, AutomationEvents.SelectionItemPatternOnElementSelected);
                Assert.IsNull(tuple, "GetAutomationEventFrom #9");

                propertyTuple = EventsManager.Instance.GetAutomationEventFrom(peer1, SelectionItemPatternIdentifiers.IsSelectedProperty);
                Assert.IsNotNull(propertyTuple, "GetPropertyAutomationEventFrom #7");
                Assert.IsFalse((bool)propertyTuple.OldValue, "GetPropertyAutomationEventFrom.OldValue #5");
                Assert.IsTrue((bool)propertyTuple.NewValue, "GetPropertyAutomationEventFrom.NewValue #5");

                Assert.IsTrue(selectionItemProvider1.IsSelected, "IsSelected #16");
                Assert.IsFalse(selectionItemProvider2.IsSelected, "IsSelected #17");
            },
                            () => {
                EventsManager.Instance.Reset();
                selectionItemProvider2.Select();
            },
                            () => {
                tuple = EventsManager.Instance.GetAutomationEventFrom(peer1, AutomationEvents.SelectionItemPatternOnElementSelected);
                Assert.IsNull(tuple, "GetAutomationEventFrom #10");

                tuple = EventsManager.Instance.GetAutomationEventFrom(peer2, AutomationEvents.SelectionItemPatternOnElementSelected);
                Assert.IsNotNull(tuple, "GetAutomationEventFrom #11");

                propertyTuple = EventsManager.Instance.GetAutomationEventFrom(peer2, SelectionItemPatternIdentifiers.IsSelectedProperty);
                Assert.IsNotNull(propertyTuple, "GetPropertyAutomationEventFrom #8");
                Assert.IsFalse((bool)propertyTuple.OldValue, "GetPropertyAutomationEventFrom.OldValue #6");
                Assert.IsTrue((bool)propertyTuple.NewValue, "GetPropertyAutomationEventFrom.NewValue #6");

                propertyTuple = EventsManager.Instance.GetAutomationEventFrom(peer1, SelectionItemPatternIdentifiers.IsSelectedProperty);
                Assert.IsNotNull(propertyTuple, "GetPropertyAutomationEventFrom #9");
                Assert.IsTrue((bool)propertyTuple.OldValue, "GetPropertyAutomationEventFrom.OldValue #7");
                Assert.IsFalse((bool)propertyTuple.NewValue, "GetPropertyAutomationEventFrom.NewValue #7");

                Assert.IsFalse(selectionItemProvider1.IsSelected, "IsSelected #18");
                Assert.IsTrue(selectionItemProvider2.IsSelected, "IsSelected #19");
            },
                            () => {
                EventsManager.Instance.Reset();
                listbox.Items.Remove(secondSelectorItem);
            },
                            () => {
                propertyTuple = EventsManager.Instance.GetAutomationEventFrom(peer2, SelectionItemPatternIdentifiers.SelectionContainerProperty);
                Assert.IsNotNull(tuple, "GetPropertyAutomationEventFrom #10");
                Assert.AreEqual(new PeerFromProvider().GetPeerFromProvider((IRawElementProviderSimple)propertyTuple.OldValue),
                                peer,
                                "GetPropertyAutomationEventFrom.OldValue #8");
                Assert.IsNull(propertyTuple.NewValue, "GetPropertyAutomationEventFrom.NewValue #8");

                tuple = EventsManager.Instance.GetAutomationEventFrom(peer, AutomationEvents.StructureChanged);
                Assert.IsNotNull(tuple, "GetAutomationEventFrom #12");
            },
                            () => {
                EventsManager.Instance.Reset();
                listbox.Items.Add(secondSelectorItem);
            },
                            () => {
                propertyTuple = EventsManager.Instance.GetAutomationEventFrom(peer2, SelectionItemPatternIdentifiers.SelectionContainerProperty);
                Assert.IsNotNull(tuple, "GetPropertyAutomationEventFrom #11");
                Assert.IsNull(propertyTuple.OldValue, "GetPropertyAutomationEventFrom.OldValue #9");
                Assert.AreEqual(new PeerFromProvider().GetPeerFromProvider((IRawElementProviderSimple)propertyTuple.NewValue),
                                peer,
                                "GetPropertyAutomationEventFrom.NewValue #9");

                tuple = EventsManager.Instance.GetAutomationEventFrom(peer, AutomationEvents.StructureChanged);
                Assert.IsNotNull(tuple, "GetAutomationEventFrom #13");
            });
        }
예제 #9
0
        public override void GetChildrenChanged()
        {
            if (!EventsManager.Instance.AutomationSingletonExists)
            {
                EnqueueTestComplete();
                return;
            }

            ContentControl        control  = null;
            AutomationPeer        peer     = null;
            List <AutomationPeer> children = null;
            Button button = null;
            AutomationEventTuple tuple           = null;
            object oldContent                    = null;
            List <AutomationPeer> buttonChildren = null;

            CreateAsyncTest(calendar,
                            () => {
                buttonChildren = GetButtonChildren();
                control        = ((FrameworkElementAutomationPeer)buttonChildren [0]).Owner as ContentControl;
                peer           = FrameworkElementAutomationPeer.CreatePeerForElement(control);
                oldContent     = control.Content;

                Assert.IsNotNull(peer, "Peer");
                children = peer.GetChildren();
                Assert.IsNotNull(children, "GetChildren #0");
                Assert.AreEqual(1, children.Count, "GetChildren #1");
            },
                            () => {
                button = new Button()
                {
                    Content = "Button0"
                };
                control.Content = button;
            },
                            () => {
                children = peer.GetChildren();
                Assert.IsNotNull(children, "GetChildren #1");
                Assert.AreEqual(1, children.Count, "Children.Count #0");
                Assert.AreEqual(FrameworkElementAutomationPeer.CreatePeerForElement(button),
                                children[0], "GetChildren #2");
                tuple = EventsManager.Instance.GetAutomationEventFrom(peer, AutomationEvents.StructureChanged);
                Assert.IsNotNull(tuple, "StructureChanged #0");
                EventsManager.Instance.Reset();
            },
                            () => control.Content = null,
                            () => {
                Assert.IsNull(peer.GetChildren(), "GetChildren #3");
                tuple = EventsManager.Instance.GetAutomationEventFrom(peer, AutomationEvents.StructureChanged);
                Assert.IsNotNull(tuple, "StructureChanged #1");
                EventsManager.Instance.Reset();

                control.Content = oldContent;
            },
                            () => {
                children = peer.GetChildren();
                Assert.IsNotNull(children, "GetChildren #4");
                Assert.AreEqual(1, children.Count, "Children.Count #1");
                tuple = EventsManager.Instance.GetAutomationEventFrom(peer, AutomationEvents.StructureChanged);
                Assert.IsNotNull(tuple, "StructureChanged #6");
            });
        }
예제 #10
0
        public override void GetChildrenChanged()
        {
            if (!IsContentPropertyElement() ||
                !EventsManager.Instance.AutomationSingletonExists)
            {
                EnqueueTestComplete();
                return;
            }

            ContentControl        control  = CreateConcreteFrameworkElement() as ContentControl;
            AutomationPeer        peer     = null;
            List <AutomationPeer> children = null;

            Assert.IsNotNull(control, "ContentControl");
            Button               button           = null;
            Canvas               canvas           = new Canvas();
            StackPanel           stackPanel       = new StackPanel();
            Button               stackPanelButton = new Button();
            CheckBox             checkbox         = new CheckBox();
            Grid                 grid             = new Grid();
            TextBlock            textblock        = new TextBlock();
            TextBox              textbox          = new TextBox();
            Button               gridButton       = new Button();
            AutomationEventTuple tuple            = null;

            CreateAsyncTest(control,
                            () => {
                peer = FrameworkElementAutomationPeer.CreatePeerForElement(control);
                Assert.IsNotNull(peer, "Peer");
                children = peer.GetChildren();
                Assert.IsNotNull(children, "GetChildren #0");
                Assert.AreEqual(2, children.Count, "Children.Count #0");
                // Control hierarchy: control { textblock, textblock }
                // UIA hierarchy: control { textblock, textblock }
            },
                            () => {
                button = new Button()
                {
                    Content = "Button0"
                };
                control.Content = button;
                // Control hierarchy: control { textblock, textblock, button }
                // UIA hierarchy: control { textblock, textblock, button }
            },
                            () => {
                children = peer.GetChildren();
                Assert.IsNotNull(children, "GetChildren #1");
                Assert.AreEqual(3, children.Count, "Children.Count #1");
                Assert.AreEqual(FrameworkElementAutomationPeer.CreatePeerForElement(button),
                                children [2], "GetChildren #2");

                tuple = EventsManager.Instance.GetAutomationEventFrom(peer, AutomationEvents.StructureChanged);
                Assert.IsNotNull(tuple, "StructureChanged #0");
                EventsManager.Instance.Reset();
            },
                            () => control.Content = null,
                            () => {
                children = peer.GetChildren();
                Assert.IsNotNull(children, "GetChildren #3");
                Assert.AreEqual(2, children.Count, "Children.Count #2");
                tuple = EventsManager.Instance.GetAutomationEventFrom(peer, AutomationEvents.StructureChanged);
                Assert.IsNotNull(tuple, "StructureChanged #1");
                EventsManager.Instance.Reset();

                // Panel subclasses don't expose any AutomationPeer but chidren's
                control.Content = canvas;
                // Control hierarchy: control { textblock, tetxblock, canvas { } }
                // UIA hierarchy: control { textblock, textblock }
            },
                            () => {
                children = peer.GetChildren();
                Assert.IsNotNull(children, "GetChildren #4");
                Assert.AreEqual(2, children.Count, "Children.Count #2");
                tuple = EventsManager.Instance.GetAutomationEventFrom(peer, AutomationEvents.StructureChanged);
                Assert.IsNull(tuple, "StructureChanged #2");
                EventsManager.Instance.Reset();
                canvas.Children.Add(stackPanel);
                // Control hierarchy: control { textblock, textblock, canvas { stackpanel { } } }
                // UIA hierarchy: control { textblock, textblock }
            },
                            () => {
                children = peer.GetChildren();
                Assert.IsNotNull(children, "GetChildren #5");
                Assert.AreEqual(2, children.Count, "Children.Count #3");
                canvas.Children.Add(button);
                // Control hierarchy: control { textblock, textblock, canvas { stackapanel, button } }
                // UIA hierarchy: control { textblock, textblock, button }
            },
                            () => {
                children = peer.GetChildren();
                Assert.IsNotNull(children, "GetChildren #6");
                Assert.AreEqual(3, children.Count, "Children.Count #4");
                Assert.IsTrue(children.Contains(FrameworkElementAutomationPeer.CreatePeerForElement(button)),
                              "GetChildren #7");
                tuple = EventsManager.Instance.GetAutomationEventFrom(peer, AutomationEvents.StructureChanged);
                Assert.IsNotNull(tuple, "StructureChanged #3");
                EventsManager.Instance.Reset();

                stackPanel.Children.Add(checkbox);
                // Control hierarchy: control { textblock, textblock, canvas { stackPanel { checkbox }, button } }
                // UIA hierarchy: control { textblock, textblock, checkbox, button }
            },
                            () => {
                children = peer.GetChildren();
                Assert.IsNotNull(children, "GetChildren #8");
                Assert.AreEqual(4, children.Count, "Children.Count #5");
                Assert.IsTrue(children.Contains(FrameworkElementAutomationPeer.CreatePeerForElement(checkbox)),
                              "GetChildren #9");
                Assert.IsTrue(children.Contains(FrameworkElementAutomationPeer.CreatePeerForElement(button)),
                              "GetChildren #10");
                tuple = EventsManager.Instance.GetAutomationEventFrom(peer, AutomationEvents.StructureChanged);
                Assert.IsNotNull(tuple, "StructureChanged #4");
                EventsManager.Instance.Reset();

                stackPanel.Children.Add(grid);
                // Control hierarchy: control { textblock, textblock, canvas { stackPanel { checkbox, grid }, button } }
                // UIA hierarchy: control { textblock, textblock, checkbox, button }
            },
                            () => {
                children = peer.GetChildren();
                Assert.IsNotNull(children, "GetChildren #11");
                Assert.AreEqual(4, children.Count, "Children.Count #6");
                Assert.IsTrue(children.Contains(FrameworkElementAutomationPeer.CreatePeerForElement(checkbox)),
                              "GetChildren #12");
                Assert.IsTrue(children.Contains(FrameworkElementAutomationPeer.CreatePeerForElement(button)),
                              "GetChildren #13");
                tuple = EventsManager.Instance.GetAutomationEventFrom(peer, AutomationEvents.StructureChanged);
                Assert.IsNull(tuple, "StructureChanged #5");
                EventsManager.Instance.Reset();

                grid.Children.Add(textblock);
                // Control hierarchy: control { textblock, textblock, canvas { stackPanel { checkbox, grid { textblock } }, button } }
                // UIA hierarchy: control { textblock, textblock, checkbox, textblock, button }
            },
                            () => {
                children = peer.GetChildren();
                Assert.IsNotNull(children, "GetChildren #14");
                Assert.AreEqual(5, children.Count, "Children.Count #7");
                Assert.IsTrue(children.Contains(FrameworkElementAutomationPeer.CreatePeerForElement(checkbox)),
                              "GetChildren #15");
                Assert.IsTrue(children.Contains(FrameworkElementAutomationPeer.CreatePeerForElement(button)),
                              "GetChildren #16");
                Assert.IsTrue(children.Contains(FrameworkElementAutomationPeer.CreatePeerForElement(textblock)),
                              "GetChildren #17");
                tuple = EventsManager.Instance.GetAutomationEventFrom(peer, AutomationEvents.StructureChanged);
                Assert.IsNotNull(tuple, "StructureChanged #6");
                EventsManager.Instance.Reset();

                canvas.Children.Add(textbox);
                // Control hierarchy: control { textblock, textblock, canvas { stackPanel { checkbox, grid { textblock } }, button, textbox } }
                // UIA hierarchy: control { textblock, textblock, checkbox, textblock, button, textbox }
            },
                            () => {
                children = peer.GetChildren();
                Assert.IsNotNull(children, "GetChildren #18");
                Assert.AreEqual(6, children.Count, "Children.Count #8");
                Assert.IsTrue(children.Contains(FrameworkElementAutomationPeer.CreatePeerForElement(checkbox)),
                              "GetChildren #19");
                Assert.IsTrue(children.Contains(FrameworkElementAutomationPeer.CreatePeerForElement(button)),
                              "GetChildren #20");
                Assert.IsTrue(children.Contains(FrameworkElementAutomationPeer.CreatePeerForElement(textblock)),
                              "GetChildren #21");
                Assert.IsTrue(children.Contains(FrameworkElementAutomationPeer.CreatePeerForElement(textbox)),
                              "GetChildren #22");
                tuple = EventsManager.Instance.GetAutomationEventFrom(peer, AutomationEvents.StructureChanged);
                Assert.IsNotNull(tuple, "StructureChanged #7");
                EventsManager.Instance.Reset();

                stackPanel.Children.Clear();
                // Control hierarchy: control { textblock, textblock, canvas { stackPanel { }, button, textbox } }
                // UIA hierarchy: control { textblock, textblock, button, textbox }
            },
                            () => {
                children = peer.GetChildren();
                Assert.IsNotNull(children, "GetChildren #23");
                Assert.AreEqual(4, children.Count, "Children.Count #9");
                Assert.IsTrue(children.Contains(FrameworkElementAutomationPeer.CreatePeerForElement(button)),
                              "GetChildren #24");
                Assert.IsTrue(children.Contains(FrameworkElementAutomationPeer.CreatePeerForElement(textbox)),
                              "GetChildren #25");
                tuple = EventsManager.Instance.GetAutomationEventFrom(peer, AutomationEvents.StructureChanged);
                Assert.IsNotNull(tuple, "StructureChanged #8");
                EventsManager.Instance.Reset();

                // If we modify 'grid' no event should be raised, since is not part of 'canvas' anymore
                grid.Children.Add(gridButton);
            },             // CONTINUE
                            () => {
                tuple = EventsManager.Instance.GetAutomationEventFrom(peer, AutomationEvents.StructureChanged);
                Assert.IsNull(tuple, "StructureChanged #9");
                EventsManager.Instance.Reset();
                canvas.Children.Clear();
                // Control hierarchy: control { textblock, textblock, canvas { } }
                // UIA hierarchy: control { }
            },
                            () => {
                children = peer.GetChildren();
                Assert.IsNotNull(children, "GetChildren #26");
                Assert.AreEqual(2, children.Count, "Children.Count #10");
                tuple = EventsManager.Instance.GetAutomationEventFrom(peer, AutomationEvents.StructureChanged);
                Assert.IsNotNull(tuple, "StructureChanged #10");
                EventsManager.Instance.Reset();

                // If we modify 'stackPanel' no event should be raised, since is not part of 'canvas' anymore
                stackPanel.Children.Add(stackPanelButton);
            },
                            () => {
                tuple = EventsManager.Instance.GetAutomationEventFrom(peer, AutomationEvents.StructureChanged);
                Assert.IsNull(tuple, "StructureChanged #11");
                EventsManager.Instance.Reset();

                stackPanel.Children.Add(grid);
                // We have now: stackpanel { stackPanelButton, grid { textblock, gridButton } }
            },
                            () => {
                tuple = EventsManager.Instance.GetAutomationEventFrom(peer, AutomationEvents.StructureChanged);
                Assert.IsNull(tuple, "StructureChanged #12");
                EventsManager.Instance.Reset();

                // Event should not be raised
                control.Content = null;
            },
                            () => {
                tuple = EventsManager.Instance.GetAutomationEventFrom(peer, AutomationEvents.StructureChanged);
                Assert.IsNull(tuple, "StructureChanged #13");
                EventsManager.Instance.Reset();

                control.Content = stackPanel;
                // Control hierarchy: canvas { stackpanel { stackPanelButton, grid { textblock, gridButton } } }
                // UIA hierarchy: control { stackPanelButton, textblock, gridButton }
            },
                            () => {
                children = peer.GetChildren();
                Assert.IsNotNull(children, "GetChildren #27");
                Assert.AreEqual(5, children.Count, "Children.Count #7");
                Assert.IsTrue(children.Contains(FrameworkElementAutomationPeer.CreatePeerForElement(stackPanelButton)),
                              "GetChildren #28");
                Assert.IsTrue(children.Contains(FrameworkElementAutomationPeer.CreatePeerForElement(textblock)),
                              "GetChildren #29");
                Assert.IsTrue(children.Contains(FrameworkElementAutomationPeer.CreatePeerForElement(gridButton)),
                              "GetChildren #30");
                tuple = EventsManager.Instance.GetAutomationEventFrom(peer, AutomationEvents.StructureChanged);
                Assert.IsNotNull(tuple, "StructureChanged #14");
                EventsManager.Instance.Reset();

                grid.Children.Add(checkbox);
                // Control hierarchy: canvas { stackpanel { stackPanelButton, grid { textblock, gridButton, checkbox } } }
                // UIA hierarchy: control { stackPanelButton, textblock, gridButton, checkbox }
            },
                            () => {
                children = peer.GetChildren();
                Assert.IsNotNull(children, "GetChildren #31");
                Assert.AreEqual(6, children.Count, "Children.Count #8");
                Assert.IsTrue(children.Contains(FrameworkElementAutomationPeer.CreatePeerForElement(stackPanelButton)),
                              "GetChildren #32");
                Assert.IsTrue(children.Contains(FrameworkElementAutomationPeer.CreatePeerForElement(textblock)),
                              "GetChildren #33");
                Assert.IsTrue(children.Contains(FrameworkElementAutomationPeer.CreatePeerForElement(gridButton)),
                              "GetChildren #34");
                Assert.IsTrue(children.Contains(FrameworkElementAutomationPeer.CreatePeerForElement(checkbox)),
                              "GetChildren #35");
                tuple = EventsManager.Instance.GetAutomationEventFrom(peer, AutomationEvents.StructureChanged);
                Assert.IsNotNull(tuple, "StructureChanged #15");
                EventsManager.Instance.Reset();
            });
        }