Ejemplo n.º 1
0
        public override void IsEnabledPropertyTest()
        {
            var provider = GetProvider();

            bridge.ResetEventLists();

            object initialVal =
                provider.GetPropertyValue(AutomationElementIdentifiers.IsEnabledProperty.Id);

            Assert.IsNotNull(initialVal, "Property returns null");
            Assert.IsTrue((bool)initialVal, "Should initialize to true");

            toolBarButton.Enabled = false;

            Assert.IsFalse((bool)provider.GetPropertyValue(AutomationElementIdentifiers.IsEnabledProperty.Id),
                           "Toggle to false");

            AutomationPropertyChangedEventTuple tuple
                = bridge.GetAutomationPropertyEventFrom(provider,
                                                        AutomationElementIdentifiers.IsEnabledProperty.Id);

            Assert.IsNotNull(tuple, "Tuple missing");
            Assert.AreEqual(initialVal,
                            tuple.e.OldValue,
                            string.Format("1st. Old value should be true: '{0}'", tuple.e.OldValue));
            Assert.AreEqual(false,
                            tuple.e.NewValue,
                            string.Format("1st. New value should be true: '{0}'", tuple.e.NewValue));

            bridge.ResetEventLists();

            toolBarButton.Enabled = true;
            Assert.IsTrue((bool)provider.GetPropertyValue(AutomationElementIdentifiers.IsEnabledProperty.Id),
                          "Toggle to true");

            tuple
                = bridge.GetAutomationPropertyEventFrom(provider,
                                                        AutomationElementIdentifiers.IsEnabledProperty.Id);
            Assert.IsNotNull(tuple, "Tuple missing");
            Assert.AreEqual(false,
                            tuple.e.OldValue,
                            string.Format("2nd. Old value should be false: '{0}'", tuple.e.OldValue));
            Assert.AreEqual(true,
                            tuple.e.NewValue,
                            string.Format("2nd. New value should be true: '{0}'", tuple.e.NewValue));

            //restore state
            toolBarButton.Enabled = true;
        }
Ejemplo n.º 2
0
        public new void IsEnabledPropertyTest()
        {
            MenuItem menuItem = new MenuItem();
            IRawElementProviderSimple provider = ProviderFactory.GetProvider(menuItem);

            bridge.ResetEventLists();

            object initialVal =
                provider.GetPropertyValue(AutomationElementIdentifiers.IsEnabledProperty.Id);

            Assert.IsNotNull(initialVal, "Property returns null");
            Assert.IsTrue((bool)initialVal, "Should initialize to true");

            menuItem.Enabled = false;

            Assert.IsFalse((bool)provider.GetPropertyValue(AutomationElementIdentifiers.IsEnabledProperty.Id),
                           "Toggle to false");

            AutomationPropertyChangedEventTuple tuple
                = bridge.GetAutomationPropertyEventFrom(provider,
                                                        AutomationElementIdentifiers.IsEnabledProperty.Id);

            Assert.IsNotNull(tuple, "Tuple missing");
            Assert.AreEqual(initialVal,
                            tuple.e.OldValue,
                            string.Format("1st. Old value should be true: '{0}'", tuple.e.OldValue));
            Assert.AreEqual(false,
                            tuple.e.NewValue,
                            string.Format("1st. New value should be true: '{0}'", tuple.e.NewValue));

            bridge.ResetEventLists();

            menuItem.Enabled = true;
            Assert.IsTrue((bool)provider.GetPropertyValue(AutomationElementIdentifiers.IsEnabledProperty.Id),
                          "Toggle to true");

            tuple
                = bridge.GetAutomationPropertyEventFrom(provider,
                                                        AutomationElementIdentifiers.IsEnabledProperty.Id);
            Assert.IsNotNull(tuple, "Tuple missing");
            Assert.AreEqual(false,
                            tuple.e.OldValue,
                            string.Format("2nd. Old value should be false: '{0}'", tuple.e.OldValue));
            Assert.AreEqual(true,
                            tuple.e.NewValue,
                            string.Format("2nd. New value should be true: '{0}'", tuple.e.NewValue));
        }
Ejemplo n.º 3
0
        public void NamePropertyEventTest()
        {
            bridge.ResetEventLists();

            object oldName = calendarProvider.GetPropertyValue(AutomationElementIdentifiers.NameProperty.Id);

            calendar.SelectionStart = new DateTime(2012, 2, 29);

            AutomationPropertyChangedEventTuple eventInfo = null;
            int eventCount = 0;

            foreach (AutomationPropertyChangedEventTuple evnt in bridge.AutomationPropertyChangedEvents)
            {
                if (evnt.e.Property.Id == AutomationElementIdentifiers.NameProperty.Id)
                {
                    eventCount++;
                    eventInfo = evnt;
                }
            }
            Assert.AreEqual(1, eventCount, "event count");

            Assert.AreEqual(oldName,
                            eventInfo.e.OldValue,
                            "event old value");

            TestProperty(calendarProvider,
                         AutomationElementIdentifiers.NameProperty,
                         eventInfo.e.NewValue);

            Assert.AreEqual(AutomationElementIdentifiers.AutomationPropertyChangedEvent.Id,
                            eventInfo.e.EventId.Id,
                            "event id");

            Assert.AreEqual(calendarProvider,
                            eventInfo.element,
                            "event element");
        }
Ejemplo n.º 4
0
        public void StatusBarPanelNamePropertyChangedEventTest()
        {
            StatusBar statusBar = new StatusBar();
            IRawElementProviderFragmentRoot rootProvider =
                (IRawElementProviderFragmentRoot)GetProviderFromControl(statusBar);

            string         panelName = "original panel name";
            StatusBarPanel panel     = new StatusBarPanel();

            panel.Text = panelName;

            statusBar.Panels.Add(panel);
            IRawElementProviderFragment childProvider =
                rootProvider.Navigate(NavigateDirection.FirstChild);

            TestProperty(childProvider,
                         AutomationElementIdentifiers.NameProperty,
                         panelName);

            bridge.ResetEventLists();

            string newPanelName = "new panel name";

            panel.Text = newPanelName;

            TestProperty(childProvider,
                         AutomationElementIdentifiers.NameProperty,
                         newPanelName);

            Assert.AreEqual(1,
                            bridge.AutomationPropertyChangedEvents.Count,
                            "Name property change event expected");
            AutomationPropertyChangedEventTuple eventTuple =
                bridge.AutomationPropertyChangedEvents [0];

            Assert.AreEqual(childProvider,
                            eventTuple.element,
                            "event sender");
            Assert.AreEqual(AutomationElementIdentifiers.NameProperty,
                            eventTuple.e.Property,
                            "event property");
            Assert.AreEqual(newPanelName,
                            eventTuple.e.NewValue,
                            "event new value");
            Assert.AreEqual(panelName,
                            eventTuple.e.OldValue,
                            "event old value");

            Assert.AreEqual(1,
                            bridge.AutomationEvents.Count,
                            "TextPattern text change event expected");
            AutomationEventTuple eventTuple2 =
                bridge.AutomationEvents [0];

            Assert.AreEqual(childProvider,
                            eventTuple2.provider,
                            "event sender");
            Assert.AreEqual(TextPatternIdentifiers.TextChangedEvent,
                            eventTuple2.eventId,
                            "event id");
            Assert.AreEqual(TextPatternIdentifiers.TextChangedEvent,
                            eventTuple2.e.EventId,
                            "event id");
        }
        public new void IsEnabledPropertyTest()          //and other properties...
        {
            // Set up initial menu item structure, with some sub-items
            T control = GetNewToolStripDropDownItem();

            control.Text = "My menu item";

            T subMenuItem1 = GetNewToolStripDropDownItem();

            subMenuItem1.Text = "sub1";
            T subMenuItem2 = GetNewToolStripDropDownItem();

            subMenuItem2.Text = "sub2";

            control.DropDownItems.Add(subMenuItem1);
            control.DropDownItems.Add(subMenuItem2);

            // Add item to parent strip, parent strip to form,
            // and initialize providers
            MenuStrip strip = new MenuStrip();

            strip.Items.Add(control);
            GetProviderFromControl(strip);

            //T control = GetNewToolStripDropDownItem ();
            Assert.IsNotNull(control, "control should not be null");

            IRawElementProviderSimple provider = ProviderFactory.GetProvider(control);

            bridge.ResetEventLists();

            object initialVal =
                provider.GetPropertyValue(AutomationElementIdentifiers.IsEnabledProperty.Id);

            Assert.IsNotNull(initialVal, "Property returns null");
            Assert.IsTrue((bool)initialVal, "Should initialize to true");

            control.Enabled = false;

            Assert.IsFalse((bool)provider.GetPropertyValue(AutomationElementIdentifiers.IsEnabledProperty.Id),
                           "Toggle to false");

            AutomationPropertyChangedEventTuple tuple
                = bridge.GetAutomationPropertyEventFrom(provider,
                                                        AutomationElementIdentifiers.IsEnabledProperty.Id);

            Assert.IsNotNull(tuple, "Tuple missing");
            Assert.AreEqual(initialVal,
                            tuple.e.OldValue,
                            string.Format("1st. Old value should be true: '{0}'", tuple.e.OldValue));
            Assert.AreEqual(false,
                            tuple.e.NewValue,
                            string.Format("1st. New value should be true: '{0}'", tuple.e.NewValue));

            bridge.ResetEventLists();

            control.Enabled = true;
            Assert.IsTrue((bool)provider.GetPropertyValue(AutomationElementIdentifiers.IsEnabledProperty.Id),
                          "Toggle to true");

            tuple
                = bridge.GetAutomationPropertyEventFrom(provider,
                                                        AutomationElementIdentifiers.IsEnabledProperty.Id);
            Assert.IsNotNull(tuple, "Tuple missing");
            Assert.AreEqual(false,
                            tuple.e.OldValue,
                            string.Format("2nd. Old value should be false: '{0}'", tuple.e.OldValue));
            Assert.AreEqual(true,
                            tuple.e.NewValue,
                            string.Format("2nd. New value should be true: '{0}'", tuple.e.NewValue));

            initialVal
                = provider.GetPropertyValue(AutomationElementIdentifiers.IsOffscreenProperty.Id);
            Assert.IsNotNull(initialVal, "val missing (offscreen)");
            Assert.IsFalse((bool)initialVal, "ToolStripMenuItem should not be offscreen");
        }