public virtual void RatingPeerGetSelectionChanged() { Rating acc = new Rating(); acc.ItemsSource = null; RatingItem first = new RatingItem(); RatingItem second = new RatingItem(); acc.Items.Add(first); acc.Items.Add(second); ISelectionProvider provider = null; IRawElementProviderSimple[] selection = null; TestAsync( acc, () => acc.Value = 1.0, () => provider = FrameworkElementAutomationPeer.CreatePeerForElement(acc) as ISelectionProvider, () => FrameworkElementAutomationPeer.CreatePeerForElement(second), () => selection = provider.GetSelection(), () => Assert.AreEqual(1, selection.Length, "Expected a selection!"), () => acc.Value = 0.0, () => selection = provider.GetSelection(), () => Assert.IsNotNull(selection, "An empty selection was expected!"), () => Assert.AreEqual(0, selection.Length, "No items should be selected!")); }
public virtual void TreeViewPeerGetSelectionChanged() { TreeView view = new TreeView(); TreeViewItem first = new TreeViewItem { Header = "First" }; TreeViewItem second = new TreeViewItem { Header = "Second" }; view.Items.Add(first); view.Items.Add(second); ISelectionProvider provider = null; IRawElementProviderSimple[] selection = null; TestAsync( view, () => first.IsSelected = true, () => provider = FrameworkElementAutomationPeer.CreatePeerForElement(view) as ISelectionProvider, () => FrameworkElementAutomationPeer.CreatePeerForElement(first), () => selection = provider.GetSelection(), () => Assert.AreEqual(1, selection.Length, "Expected a selection!"), () => first.IsSelected = false, () => selection = provider.GetSelection(), () => Assert.IsNotNull(selection, "An empty selection was expected!"), () => Assert.AreEqual(0, selection.Length, "No items should be selected!")); }
public virtual void AccordionPeerGetSelectionChanged() { Accordion acc = new Accordion(); acc.SelectionMode = AccordionSelectionMode.ZeroOrMore; AccordionItem first = new AccordionItem { Header = "First", Content = "a" }; AccordionItem second = new AccordionItem { Header = "Second", Content = "b" }; acc.Items.Add(first); acc.Items.Add(second); ISelectionProvider provider = null; IRawElementProviderSimple[] selection = null; TestAsync( acc, () => second.IsSelected = true, () => provider = FrameworkElementAutomationPeer.CreatePeerForElement(acc) as ISelectionProvider, () => FrameworkElementAutomationPeer.CreatePeerForElement(second), () => selection = provider.GetSelection(), () => Assert.AreEqual(1, selection.Length, "Expected a selection!"), () => second.IsSelected = false, () => selection = provider.GetSelection(), () => Assert.IsNotNull(selection, "An empty selection was expected!"), () => Assert.AreEqual(0, selection.Length, "No items should be selected!")); }
public virtual void ISelectionProvider_Methods() { bool concreteLoaded = false; Selector selector = CreateConcreteFrameworkElement() as Selector; selector.Width = 300; selector.Height = 400; selector.Loaded += (o, e) => concreteLoaded = true; selector.Items.Add(new TextBlock() { Text = "Item0" }); selector.Items.Add(new TextBlock() { Text = "Item1" }); TestPanel.Children.Add(selector); EnqueueConditional(() => concreteLoaded, "ConcreteLoaded #0"); Enqueue(() => { AutomationPeer peer = FrameworkElementAutomationPeer.CreatePeerForElement(selector); ISelectionProvider selectionProvider = peer.GetPattern(PatternInterface.Selection) as ISelectionProvider; Assert.IsNotNull(selectionProvider, "Selection Provider"); Assert.IsFalse(selectionProvider.CanSelectMultiple, "CanSelectMultiple #0"); Assert.IsFalse(selectionProvider.IsSelectionRequired, "IsSelectionRequired #0"); IRawElementProviderSimple[] selection = selectionProvider.GetSelection(); Assert.IsNull(selection, "GetSelection #0"); selector.SelectedIndex = 1; selection = selectionProvider.GetSelection(); Assert.IsNotNull(selection, "GetSelection #1"); Assert.AreEqual(1, selector.SelectedIndex, "SelectedIndex #0"); selectionProvider = peer.GetPattern(PatternInterface.Selection) as ISelectionProvider; Assert.AreEqual(1, selection.Length, "GetSelection #2"); selector.Items.Add(new TextBlock() { Text = "Item1" }); selector.SelectedIndex = 0; selection = selectionProvider.GetSelection(); Assert.IsNotNull(selection, "GetSelection #3"); Assert.AreEqual(1, selection.Length, "GetSelection #4"); selector.SelectedIndex = 1; selection = selectionProvider.GetSelection(); Assert.IsNotNull(selection, "GetSelection #5"); Assert.AreEqual(1, selection.Length, "GetSelection #6"); }); EnqueueTestComplete(); }
public virtual void ShouldFillSelectionWithAPeer() { ListTimePickerPopup ltp = new ListTimePickerPopup(); ISelectionProvider provider = null; ItemSelectionHelper <KeyValuePair <string, DateTime?> > helper = null; TestAsync( ltp, () => provider = (ISelectionProvider)FrameworkElementAutomationPeer.CreatePeerForElement(ltp), () => helper = ltp.TimeItemsSelection, () => Assert.IsTrue(provider.GetSelection().Length == 0), () => helper.SelectedItem = helper.Items[3], () => Assert.IsNotNull(provider.GetSelection(), "There have been intermittent Automation problems where the ListBoxAutomationPeer reports null children."), () => Assert.IsTrue(provider.GetSelection().Length == 1)); }
public ComboBox(IRawElementProviderSimple provider) : base(provider) { if (!(provider is IRawElementProviderFragment)) { throw new ArgumentException("Provider should be IRawElementProviderFragment"); } this.Role = Atk.Role.ComboBox; selProvider = (ISelectionProvider)provider.GetPatternProvider(SelectionPatternIdentifiers.Pattern.Id); if (selProvider == null) { throw new ArgumentException("ComboBoxProvider should always implement ISelectionProvider"); } selectionHelper = new SelectionProviderUserHelper((IRawElementProviderFragment)Provider, selProvider, true); var providersSelected = selProvider.GetSelection(); if (providersSelected != null && providersSelected.Length == 1) { Name = (string)providersSelected [0].GetPropertyValue(AEIds.NameProperty.Id); } }
public void AddToSelection() { if (nodeProvider.TreeNode.TreeView != null && !nodeProvider.TreeNode.TreeView.Enabled) { throw new ElementNotEnabledException(); } IRawElementProviderSimple treeProvider = ProviderFactory.FindProvider(nodeProvider.TreeNode.TreeView); if (treeProvider == null) { return; } ISelectionProvider treeSelectionProvider = (ISelectionProvider) treeProvider.GetPatternProvider(SelectionPatternIdentifiers.Pattern.Id); if (treeSelectionProvider == null) { return; } if (!treeSelectionProvider.CanSelectMultiple && treeSelectionProvider.GetSelection().Length > 0) { throw new InvalidOperationException("Cannot select multiple nodes."); } Select(); }
public virtual void TreeViewPeerGetSelectionNoPeer() { TreeView view = new TreeView(); TreeViewItem first = new TreeViewItem { Header = "First" }; TreeViewItem second = new TreeViewItem { Header = "Second" }; view.Items.Add(first); view.Items.Add(second); ISelectionProvider provider = null; IRawElementProviderSimple[] selection = null; bool peersAutomaticallyCreated = false; TestAsync( view, () => first.IsSelected = true, () => peersAutomaticallyCreated = (FrameworkElementAutomationPeer.FromElement(first) as TreeViewItemAutomationPeer) != null, () => provider = FrameworkElementAutomationPeer.CreatePeerForElement(view) as ISelectionProvider, () => selection = provider.GetSelection(), () => Assert.AreEqual(peersAutomaticallyCreated ? 1 : 0, selection.Length, "No items should be selected (unless peers are automatically being created!")); }
public void RemoveFromSelection() { if (!IsSelected) { return; } ISelectionProvider selectionProvider = SelectionProvider; int selectedItemsCount = selectionProvider.GetSelection().Length; if (!selectionProvider.CanSelectMultiple && selectionProvider.IsSelectionRequired && selectedItemsCount > 0) { throw new InvalidOperationException(); } else if (selectionProvider.CanSelectMultiple && selectionProvider.IsSelectionRequired && selectedItemsCount == 1) { throw new InvalidOperationException(); } else { PerformUnselect(); } }
void ISelectionItemProvider.AddToSelection() { if (!IsEnabled()) { throw new ElementNotEnabledException(); } ISelectionProvider selectionProvider = SelectionProvider; if (selectionProvider == null) { return; } ISelectionItemProvider selectionItemProvider = (ISelectionItemProvider)this; if (!selectionProvider.CanSelectMultiple) { IRawElementProviderSimple[] selection = selectionProvider.GetSelection(); if (selection == null || selection.Length == 0) { selectionItemProvider.Select(); } else { throw new InvalidOperationException(); } } else { selectionItemProvider.Select(); } }
IRawElementProviderSimple [] GetSelection() { var elements = selectionProvider.GetSelection(); if (elements == null) { return(new IRawElementProviderSimple [0]); } int controlTypeId = (int)provider.GetPropertyValue(AutomationElementIdentifiers.ControlTypeProperty.Id); if (elements.Length == 0 || controlTypeId != ControlType.Group.Id) { return(elements); } IRawElementProviderSimple [] ret = new IRawElementProviderSimple [elements.Length]; int count = 0; for (int i = 0; i < elements.Length; i++) { var parent = ((IRawElementProviderFragment)elements [i]).Navigate(NavigateDirection.Parent); if (parent == ChildrenHolder) { ret [count++] = elements [i]; } } Array.Resize <IRawElementProviderSimple> (ref ret, count); return(ret); }
public int GetSelectedRows(out int [] selected) { ISelectionProvider selection = (ISelectionProvider)resource.Provider.GetPatternProvider(SelectionPatternIdentifiers.Pattern.Id); if (selection == null) { selected = new int [0]; return(0); } IRawElementProviderSimple [] items = selection.GetSelection(); List <int> selectedItems = new List <int> (); foreach (IRawElementProviderSimple item in items) { ISelectionItemProvider selectionItem = (ISelectionItemProvider)item.GetPatternProvider(SelectionItemPatternIdentifiers.Pattern.Id); IGridItemProvider gridItem = (IGridItemProvider)item.GetPatternProvider(GridItemPatternIdentifiers.Pattern.Id); if (selectionItem != null && gridItem != null) { if (selectionItem.IsSelected) { selectedItems.Add(gridItem.Row); } } } selected = selectedItems.ToArray(); return(selectedItems.Count); }
public void AddToSelection() { if (IsSelected) { return; } ISelectionProvider selectionProvider = SelectionProvider; if (!selectionProvider.CanSelectMultiple) { if (selectionProvider.GetSelection().Length > 0) { throw new InvalidOperationException(); } else { Select(); } } else { Select(); } }
public void ISelectionProvider_Methods() { Calendar calendar = CreateConcreteFrameworkElement() as Calendar; AutomationPeer peer = FrameworkElementAutomationPeer.CreatePeerForElement(calendar); ISelectionProvider selectionProvider = null; CreateAsyncTest(calendar, () => { Assert.IsNotNull(peer, "#0"); selectionProvider = peer.GetPattern(PatternInterface.Selection) as ISelectionProvider; Assert.IsNotNull(selectionProvider, "#1"); // ISelectionProvider.IsSelectionRequired calendar.SelectionMode = CalendarSelectionMode.None; Assert.IsFalse(selectionProvider.IsSelectionRequired, "IsSelectionRequired #0"); calendar.SelectionMode = CalendarSelectionMode.SingleDate; Assert.IsFalse(selectionProvider.IsSelectionRequired, "IsSelectionRequired #1"); calendar.SelectionMode = CalendarSelectionMode.SingleRange; Assert.IsFalse(selectionProvider.IsSelectionRequired, "IsSelectionRequired #2"); calendar.SelectionMode = CalendarSelectionMode.MultipleRange; Assert.IsFalse(selectionProvider.IsSelectionRequired, "IsSelectionRequired #3"); // ISelectionProvider.CanSelectMultiple calendar.SelectionMode = CalendarSelectionMode.None; Assert.IsFalse(selectionProvider.CanSelectMultiple, "CanSelectMultiple #0"); calendar.SelectionMode = CalendarSelectionMode.SingleDate; Assert.IsFalse(selectionProvider.CanSelectMultiple, "CanSelectMultiple #1"); calendar.SelectionMode = CalendarSelectionMode.SingleRange; Assert.IsTrue(selectionProvider.CanSelectMultiple, "CanSelectMultiple #2"); calendar.SelectionMode = CalendarSelectionMode.MultipleRange; Assert.IsTrue(selectionProvider.CanSelectMultiple, "CanSelectMultiple #3"); // ISelectionProvider.GetSelection Assert.IsNull(calendar.SelectedDate); Assert.IsTrue(selectionProvider.CanSelectMultiple, "GetSelection #0"); calendar.DisplayMode = CalendarMode.Year; calendar.SelectedDates.AddRange(new DateTime(2000, 2, 10), new DateTime(2000, 3, 30)); IRawElementProviderSimple[] selection = selectionProvider.GetSelection(); Assert.IsNull(selection, "GetSelection #1"); calendar.DisplayMode = CalendarMode.Month; selection = selectionProvider.GetSelection(); Assert.IsNotNull(selection, "GetSelection #4"); Assert.AreEqual(selection.Length, 31, "GetSelection #5"); AutomationPeer cellPeer = new PeerFromProvider().GetPeerFromProvider(selection [0]); Assert.AreEqual(cellPeer.GetClassName(), typeof(CalendarDayButton).Name, "GetSelection #6"); }); }
public void ISelectionProvider_Methods() { TabControl tabControl = new TabControl(); ISelectionProvider selectionProvider = null; AutomationPeer peer = null; CreateAsyncTest(tabControl, () => { peer = FrameworkElementAutomationPeer.CreatePeerForElement(tabControl); Assert.IsNotNull(peer, "#0"); selectionProvider = (ISelectionProvider)peer.GetPattern(PatternInterface.Selection) as ISelectionProvider; Assert.IsNotNull(selectionProvider); Assert.IsNull(peer.GetChildren(), "#1"); }, () => { Assert.IsFalse(selectionProvider.CanSelectMultiple, "#2"); Assert.IsTrue(selectionProvider.IsSelectionRequired, "#3"); Assert.IsNull(selectionProvider.GetSelection(), "#4"); tabControl.Items.Add(new TabItem() { Header = "Item0" }); tabControl.Items.Add(new TabItem() { Header = "Item1" }); }, () => { List <AutomationPeer> children = peer.GetChildren(); Assert.IsNotNull(children, "#5"); Assert.AreEqual(2, children.Count, "#6"); IRawElementProviderSimple[] selection = selectionProvider.GetSelection(); Assert.IsNotNull(selection, "#7"); Assert.AreEqual(1, selection.Length, "#8"); Assert.AreEqual("Item0", new PeerFromProvider().GetPeerFromProvider(selection [0]).GetName(), "#9"); }, () => tabControl.SelectedIndex = 1, () => { IRawElementProviderSimple[] selection = selectionProvider.GetSelection(); Assert.IsNotNull(selection, "#10"); Assert.AreEqual(1, selection.Length, "#11"); Assert.AreEqual("Item1", new PeerFromProvider().GetPeerFromProvider(selection [0]).GetName(), "#12"); }); }
public void ISelectionProviderEventTest() { TabControl tc = new TabControl(); TabPage tp1 = new TabPage(); TabPage tp2 = new TabPage(); tc.Controls.Add(tp1); tc.Controls.Add(tp2); Form.Controls.Add(tc); IRawElementProviderSimple provider = ProviderFactory.GetProvider(tc); ISelectionProvider selectionProvider = provider.GetPatternProvider( SelectionPatternIdentifiers.Pattern.Id) as ISelectionProvider; Assert.IsNotNull(selectionProvider, "Not returning SelectionPatternIdentifiers."); tc.SelectTab(0); // Case 1: Select currently selected tab bridge.ResetEventLists(); tc.SelectTab(0); Assert.AreEqual(0, bridge.AutomationEvents.Count, "EventCount after selecting selected tab"); // Case 2: Select different tab bridge.ResetEventLists(); tc.SelectTab(1); Assert.AreEqual(1, bridge.GetAutomationPropertyEventCount(SelectionPatternIdentifiers.SelectionProperty), "EventCount after selecting new tab"); IRawElementProviderSimple[] pageProviders = selectionProvider.GetSelection(); Assert.IsNotNull(pageProviders, "Null selection returned"); Assert.AreEqual(1, pageProviders.Length, "Less/More than one selected page returned"); IRawElementProviderSimple child = ((IRawElementProviderFragmentRoot)provider) .Navigate(NavigateDirection.FirstChild); Assert.IsNotNull(child, "First child is null"); child = ((IRawElementProviderFragment)child) .Navigate(NavigateDirection.NextSibling); Assert.IsNotNull(child, "Second child is null"); Assert.AreEqual(child, pageProviders[0], "Selected child and second child aren't equal"); IRawElementProviderSimple pageProvider = pageProviders[0]; // TODO: flesh this out when we implement TabPageProvider Assert.IsNotNull(pageProvider); }
public void TabControlAutomationPeerTest() { TabControl tabControl = new TabControl(); TabItem tabItem = new TabItem(); TabControlAutomationPeer peer = ((TabControlAutomationPeer)TabControlAutomationPeer.CreatePeerForElement(tabControl)); ISelectionProvider selector = (ISelectionProvider)peer.GetPattern(PatternInterface.Selection); CreateAsyncTask(tabControl, () => Assert.IsFalse(selector.CanSelectMultiple), () => Assert.IsTrue(selector.IsSelectionRequired), () => Assert.IsNull(selector.GetSelection()), () => tabControl.Items.Add(tabItem), () => Assert.IsNotNull(selector.GetSelection()) ); EnqueueTestComplete(); }
public void ISelectionPatternTest() { DomainUpDown domainUpDown = new DomainUpDown(); domainUpDown.Items.Add("First"); domainUpDown.Items.Add("Second"); domainUpDown.Items.Add("Third"); domainUpDown.Items.Add("Fourth"); Form.Controls.Add(domainUpDown); IRawElementProviderSimple provider = ProviderFactory.GetProvider(domainUpDown); ISelectionProvider prov = (ISelectionProvider)provider.GetPatternProvider( SelectionPatternIdentifiers.Pattern.Id); Assert.IsNotNull(prov); IRawElementProviderSimple[] items; // Test initial no selection Assert.AreEqual(-1, domainUpDown.SelectedIndex); items = prov.GetSelection(); Assert.IsNotNull(items, "Should never return null"); Assert.AreEqual(0, items.Length, "Too many items returned"); // Test first item selection domainUpDown.SelectedIndex = 0; Assert.AreEqual(0, domainUpDown.SelectedIndex); items = prov.GetSelection(); Assert.IsNotNull(items, "Should never return null"); Assert.AreEqual(1, items.Length, "Too many or too few items returned"); IValueProvider item_val_prov = (IValueProvider)items[0].GetPatternProvider( ValuePatternIdentifiers.Pattern.Id); Assert.AreEqual("First", item_val_prov.Value); }
public virtual void AccordionPeerGetSelectionEmpty() { Accordion acc = new Accordion(); ISelectionProvider provider = null; IRawElementProviderSimple[] selection = null; TestAsync( acc, () => provider = FrameworkElementAutomationPeer.CreatePeerForElement(acc) as ISelectionProvider, () => selection = provider.GetSelection(), () => Assert.IsNotNull(selection, "An empty selection was expected!"), () => Assert.AreEqual(0, selection.Length, "No items should be selected!")); }
public string [] GetSelectionPaths() { var selection = provider.GetSelection(); List <string> selectionPaths = new List <string> (selection.Length); foreach (var section in selection) { string elementPath = AutomationBridge.Instance.FindWrapperByProvider(section).Path; selectionPaths.Add(elementPath); } return(selectionPaths.ToArray()); }
public ComboBox (IRawElementProviderSimple provider) : base (provider) { if (!(provider is IRawElementProviderFragment)) throw new ArgumentException ("Provider should be IRawElementProviderFragment"); this.Role = Atk.Role.ComboBox; selProvider = (ISelectionProvider)provider.GetPatternProvider (SelectionPatternIdentifiers.Pattern.Id); if (selProvider == null) throw new ArgumentException ("ComboBoxProvider should always implement ISelectionProvider"); selectionHelper = new SelectionProviderUserHelper ((IRawElementProviderFragment)Provider, selProvider, true); var providersSelected = selProvider.GetSelection (); if (providersSelected != null && providersSelected.Length == 1) Name = (string)providersSelected [0].GetPropertyValue (AEIds.NameProperty.Id); }
public virtual void RatingPeerGetSelectionNoPeer() { Rating acc = new Rating(); acc.ItemsSource = null; acc.SelectionMode = RatingSelectionMode.Individual; RatingItem first = new RatingItem(); RatingItem second = new RatingItem(); acc.Items.Add(first); acc.Items.Add(second); ISelectionProvider provider = null; IRawElementProviderSimple[] selection = null; TestAsync( acc, () => acc.Value = 0.0, () => provider = FrameworkElementAutomationPeer.CreatePeerForElement(acc) as ISelectionProvider, () => selection = provider.GetSelection(), () => Assert.AreEqual(0, selection.Length, "No items should be selected!")); }
public override void ISelectionProvider_Events() { if (!EventsManager.Instance.AutomationSingletonExists) { EnqueueTestComplete(); return; } bool expanded = false; bool concreteLoaded = false; ComboBox combobox = CreateConcreteFrameworkElement() as ComboBox; combobox.Width = 300; combobox.Height = 400; combobox.Loaded += (o, e) => concreteLoaded = true; combobox.DropDownOpened += (o, e) => expanded = true; combobox.Items.Add(new TextBlock() { Text = "Item0" }); combobox.Items.Add(new TextBlock() { Text = "Item1" }); AutomationPeer peer = null; AutomationPeer childPeer = null; IRawElementProviderSimple[] selection = null; AutomationPropertyEventTuple propertyTuple = null; ISelectionProvider selectionProvider = null; TestPanel.Children.Add(combobox); EnqueueConditional(() => concreteLoaded, "ConcreteLoaded #0"); Enqueue(() => combobox.ApplyTemplate()); Enqueue(() => combobox.IsDropDownOpen = true); EnqueueConditional(() => expanded, "Expanded #0"); Enqueue(() => combobox.IsDropDownOpen = false); Enqueue(() => { peer = FrameworkElementAutomationPeer.CreatePeerForElement(combobox); selectionProvider = peer.GetPattern(PatternInterface.Selection) as ISelectionProvider; Assert.IsNotNull(selectionProvider, "Selection Provider"); Assert.IsFalse(selectionProvider.CanSelectMultiple, "CanSelectMultiple #0"); Assert.IsFalse(selectionProvider.IsSelectionRequired, "IsSelectionRequired #0"); selection = selectionProvider.GetSelection(); Assert.IsNull(selection, "GetSelection #0"); }); Enqueue(() => { EventsManager.Instance.Reset(); combobox.SelectedIndex = 1; }); Enqueue(() => { selection = selectionProvider.GetSelection(); Assert.IsNotNull(selection, "GetSelection #1"); Assert.AreEqual(1, selection.Length, "GetSelection #2"); propertyTuple = EventsManager.Instance.GetAutomationEventFrom(peer, SelectionPatternIdentifiers.SelectionProperty); Assert.IsNotNull(propertyTuple, "GetAutomationPropertyEventFrom #0"); Assert.IsNull(propertyTuple.OldValue, "GetPropertyAutomationEventFrom.OldValue #0"); Assert.IsNotNull(propertyTuple.NewValue, "GetPropertyAutomationEventFrom.NewValue #0"); childPeer = new PeerFromProvider().GetPeerFromProvider(selection [0]); }); Enqueue(() => { EventsManager.Instance.Reset(); combobox.Items.Add(new TextBlock() { Text = "Item1" }); combobox.SelectedIndex = 0; }); Enqueue(() => { selection = selectionProvider.GetSelection(); Assert.IsNotNull(selection, "GetSelection #3"); Assert.AreEqual(1, selection.Length, "GetSelection #4"); propertyTuple = EventsManager.Instance.GetAutomationEventFrom(peer, SelectionPatternIdentifiers.SelectionProperty); Assert.IsNotNull(propertyTuple, "GetAutomationPropertyEventFrom #1"); Assert.IsNotNull(propertyTuple.OldValue, "GetPropertyAutomationEventFrom.OldValue #1"); Assert.IsNotNull(propertyTuple.NewValue, "GetPropertyAutomationEventFrom.NewValue #1"); Assert.AreNotEqual(selection [0], childPeer, "GetSelection #5"); }); Enqueue(() => { EventsManager.Instance.Reset(); combobox.SelectedIndex = -1; }); Enqueue(() => { selection = selectionProvider.GetSelection(); Assert.IsNull(selection, "GetSelection #6"); propertyTuple = EventsManager.Instance.GetAutomationEventFrom(peer, SelectionPatternIdentifiers.SelectionProperty); Assert.IsNotNull(propertyTuple, "GetAutomationPropertyEventFrom #2"); Assert.IsNotNull(propertyTuple.OldValue, "GetPropertyAutomationEventFrom.OldValue #2"); Assert.IsNull(propertyTuple.NewValue, "GetPropertyAutomationEventFrom.NewValue #2"); }); EnqueueTestComplete(); }
public void ISelectionProviderTest() { IRawElementProviderFragmentRoot dataGridProvider; IRawElementProviderFragment listItem; GetDataGridAndFirstListItem(out dataGridProvider, out listItem); ISelectionProvider selectionProvider = dataGridProvider.GetPatternProvider(SelectionPatternIdentifiers.Pattern.Id) as ISelectionProvider; Assert.IsNotNull(selectionProvider, "Does not implement ISelectionProvider"); // Test CanSelectMultiple calendar.MaxSelectionCount = 1; Assert.IsFalse(selectionProvider.CanSelectMultiple, "CanSelectMultiple returns true when MaxSelectionCount is 1"); bridge.ResetEventLists(); calendar.MaxSelectionCount = 5; Assert.IsTrue(selectionProvider.CanSelectMultiple, "CanSelectMultiple returns false when MaxSelectionCount is 5"); Assert.AreEqual(1, bridge.GetAutomationPropertyEventCount(SelectionPatternIdentifiers.CanSelectMultipleProperty), "Event count"); // Test IsSelectionRequired calendar.MaxSelectionCount = 5; Assert.IsTrue(selectionProvider.IsSelectionRequired, "IsSelectionRequired returns false when MaxSelectionCount is 5"); // Test GetSelection and Selection event DateTime sel_start = new DateTime(2000, 12, 4); DateTime sel_end = new DateTime(2000, 12, 6); calendar.MinDate = new DateTime(2000, 12, 1); calendar.MaxSelectionCount = 5; bridge.ResetEventLists(); calendar.SelectionStart = sel_start; calendar.SelectionEnd = sel_end; Assert.AreEqual(2, bridge.GetAutomationPropertyEventCount(SelectionPatternIdentifiers.SelectionProperty), "Event count"); IRawElementProviderSimple[] selectedItems = selectionProvider.GetSelection(); Assert.IsNotNull(selectedItems, "GetSelection returning null"); Assert.AreEqual((sel_end - sel_start).Days + 1, selectedItems.Length, "GetSelection Not returning the right number of items"); int i = 0; DateTime date = sel_start; while (date <= sel_end) { TestProperty(selectedItems[i], AutomationElementIdentifiers.ControlTypeProperty, ControlType.ListItem.Id); TestProperty(selectedItems[i], AutomationElementIdentifiers.NameProperty, date.Day.ToString()); date = date.AddDays(1); i++; } }
/// <summary> /// Get the currently selected elements /// </summary> /// <returns>An AutomationElement array containing the currently selected elements</returns> object[]? ISelectionProvider.GetSelection() => publicISelectionProvider.GetSelection();
public void ListTest() { // This format should have 8 parts picker.Format = DateTimePickerFormat.Long; picker.ShowUpDown = false; picker.Value = awesome; IRawElementProviderSimple child = ((IRawElementProviderFragmentRoot)pickerProvider) .Navigate(NavigateDirection.FirstChild); int i = 0; do { if (long_pattern_part_type[i] == PartType.List) { TestProperty(child, AutomationElementIdentifiers.ControlTypeProperty, ControlType.List.Id); ISelectionProvider prov = (ISelectionProvider)child.GetPatternProvider( SelectionPatternIdentifiers.Pattern.Id); Assert.IsNotNull(prov); IRawElementProviderSimple[] items; string name = (string)child.GetPropertyValue( AutomationElementIdentifiers.NameProperty.Id); if (name == "Tuesday") { items = prov.GetSelection(); Assert.IsNotNull(items, "Should never return null"); Assert.AreEqual(1, items.Length, "Too many or too few items returned"); name = (string)items[0].GetPropertyValue( AutomationElementIdentifiers.NameProperty.Id); Assert.AreEqual("Tuesday", name, "GetSelection () isn't returning Tuesday"); bridge.ResetEventLists(); picker.Value = awesome.AddDays(3); Assert.AreEqual(1, bridge.GetAutomationPropertyEventCount( SelectionPatternIdentifiers.SelectionProperty), "SelectionProperty Event count"); items = prov.GetSelection(); Assert.IsNotNull(items, "Should never return null"); Assert.AreEqual(1, items.Length, "Too many or too few items returned"); name = (string)items[0].GetPropertyValue( AutomationElementIdentifiers.NameProperty.Id); Assert.AreEqual("Friday", name, "GetSelection () isn't returning Friday"); } else if (name == "January") { items = prov.GetSelection(); Assert.IsNotNull(items, "Should never return null"); Assert.AreEqual(1, items.Length, "Too many or too few items returned"); name = (string)items[0].GetPropertyValue( AutomationElementIdentifiers.NameProperty.Id); Assert.AreEqual("January", name, "GetSelection () isn't returning January"); bridge.ResetEventLists(); picker.Value = awesome.AddMonths(3); // Month will change, so will the day Assert.AreEqual(2, bridge.GetAutomationPropertyEventCount( SelectionPatternIdentifiers.SelectionProperty), "SelectionProperty Event count"); // Focus shouldn't change when we alter the value Assert.AreEqual(0, bridge.GetAutomationPropertyEventCount( AutomationElementIdentifiers.HasKeyboardFocusProperty), "HasKeyboardFocusProperty Event count"); items = prov.GetSelection(); Assert.IsNotNull(items, "Should never return null"); Assert.AreEqual(1, items.Length, "Too many or too few items returned"); name = (string)items[0].GetPropertyValue( AutomationElementIdentifiers.NameProperty.Id); Assert.AreEqual("April", name, "GetSelection () isn't returning April"); } } i++; child = ((IRawElementProviderFragment)child) .Navigate(NavigateDirection.NextSibling); } while (child != null && i < long_pattern_num_parts); }
public virtual void ISelectionProvider_Events() { if (!EventsManager.Instance.AutomationSingletonExists) { EnqueueTestComplete(); return; } Selector selector = CreateConcreteFrameworkElement() as Selector; selector.Width = 300; selector.Height = 400; selector.Items.Add(new TextBlock() { Text = "Item0" }); selector.Items.Add(new TextBlock() { Text = "Item1" }); AutomationPeer peer = null; AutomationPeer childPeer = null; IRawElementProviderSimple[] selection = null; AutomationPropertyEventTuple propertyTuple = null; ISelectionProvider selectionProvider = null; CreateAsyncTest(selector, () => { peer = FrameworkElementAutomationPeer.CreatePeerForElement(selector); selectionProvider = peer.GetPattern(PatternInterface.Selection) as ISelectionProvider; Assert.IsNotNull(selectionProvider, "Selection Provider"); Assert.IsFalse(selectionProvider.CanSelectMultiple, "CanSelectMultiple #0"); Assert.IsFalse(selectionProvider.IsSelectionRequired, "IsSelectionRequired #0"); selection = selectionProvider.GetSelection(); Assert.IsNull(selection, "GetSelection #0"); }, () => { EventsManager.Instance.Reset(); selector.SelectedIndex = 1; }, () => { selection = selectionProvider.GetSelection(); Assert.IsNotNull(selection, "GetSelection #1"); Assert.AreEqual(1, selection.Length, "GetSelection #2"); propertyTuple = EventsManager.Instance.GetAutomationEventFrom(peer, SelectionPatternIdentifiers.SelectionProperty); Assert.IsNotNull(propertyTuple, "GetAutomationPropertyEventFrom #0"); Assert.IsNull(propertyTuple.OldValue, "GetPropertyAutomationEventFrom.OldValue #0"); Assert.IsNotNull(propertyTuple.NewValue, "GetPropertyAutomationEventFrom.NewValue #0"); childPeer = new PeerFromProvider().GetPeerFromProvider(selection [0]); }, () => { EventsManager.Instance.Reset(); selector.Items.Add(new TextBlock() { Text = "Item1" }); selector.SelectedIndex = 0; }, () => { selection = selectionProvider.GetSelection(); Assert.IsNotNull(selection, "GetSelection #3"); Assert.AreEqual(1, selection.Length, "GetSelection #4"); propertyTuple = EventsManager.Instance.GetAutomationEventFrom(peer, SelectionPatternIdentifiers.SelectionProperty); Assert.IsNotNull(propertyTuple, "GetAutomationPropertyEventFrom #1"); Assert.IsNotNull(propertyTuple.OldValue, "GetPropertyAutomationEventFrom.OldValue #1"); Assert.IsNotNull(propertyTuple.NewValue, "GetPropertyAutomationEventFrom.NewValue #1"); Assert.AreNotEqual(selection [0], childPeer, "GetSelection #5"); }, () => { EventsManager.Instance.Reset(); selector.SelectedIndex = -1; }, () => { selection = selectionProvider.GetSelection(); Assert.IsNull(selection, "GetSelection #6"); propertyTuple = EventsManager.Instance.GetAutomationEventFrom(peer, SelectionPatternIdentifiers.SelectionProperty); Assert.IsNotNull(propertyTuple, "GetAutomationPropertyEventFrom #2"); Assert.IsNotNull(propertyTuple.OldValue, "GetPropertyAutomationEventFrom.OldValue #2"); Assert.IsNull(propertyTuple.NewValue, "GetPropertyAutomationEventFrom.NewValue #2"); }); }
public void SelectionPatternTest() { IRawElementProviderSimple formProvider = FormProvider; RadioButton r1 = new RadioButton(); r1.Checked = false; RadioButton r2 = new RadioButton(); r2.Checked = false; Form.Controls.Add(r1); Form.Controls.Add(r2); // A form with RadioButtons should provide SelectionPattern ISelectionProvider formSelectionProvider = formProvider.GetPatternProvider( SelectionPatternIdentifiers.Pattern.Id) as ISelectionProvider; Assert.IsNotNull(formSelectionProvider, "Parent provider should provide Selection Pattern if it has RadioButtons"); IRawElementProviderSimple provider1 = ProviderFactory.GetProvider(r1); IRawElementProviderSimple provider2 = ProviderFactory.GetProvider(r2); // Test SelectionPattern properties, which don't change // for a control containing RadioButtons Assert.IsFalse(formSelectionProvider.CanSelectMultiple, "Always false"); Assert.IsTrue(formSelectionProvider.IsSelectionRequired, "Always true"); // Test GetSelection method IRawElementProviderSimple [] selectedProviders = formSelectionProvider.GetSelection(); Assert.AreEqual(0, selectedProviders.Length, "No selection initially"); r1.Checked = true; selectedProviders = formSelectionProvider.GetSelection(); Assert.AreEqual(1, selectedProviders.Length); Assert.AreEqual(provider1, selectedProviders [0]); r2.Checked = true; selectedProviders = formSelectionProvider.GetSelection(); Assert.AreEqual(1, selectedProviders.Length); Assert.AreEqual(provider2, selectedProviders [0]); // Test adding RadioButtons RadioButton r3 = new RadioButton(); Form.Controls.Add(r3); IRawElementProviderSimple provider3 = ProviderFactory.GetProvider(r3); r3.Checked = true; selectedProviders = formSelectionProvider.GetSelection(); Assert.AreEqual(1, selectedProviders.Length); Assert.AreEqual(provider3, selectedProviders [0]); // Test removing RadioButtons Form.Controls.Remove(r3); selectedProviders = formSelectionProvider.GetSelection(); Assert.IsNotNull(selectedProviders); Assert.AreEqual(0, selectedProviders.Length, "No selection when selected RadioButton is removed from Form"); // Test that when all RadioButtons are removed, the form // no longer provides SelectionPattern Form.Controls.Remove(r1); Form.Controls.Remove(r2); formSelectionProvider = formProvider.GetPatternProvider( SelectionPatternIdentifiers.Pattern.Id) as ISelectionProvider; Assert.IsNull(formSelectionProvider, "Parent provider should not provide Selection Pattern if it has no RadioButtons"); }
public void ComboBoxTest() { SWF.DataGridViewComboBoxColumn column = new SWF.DataGridViewComboBoxColumn(); column.HeaderText = "CheckBox Column"; column.Items.AddRange("1", "2", "3", "4", "5"); SWF.DataGridViewComboBoxCell cell = new SWF.DataGridViewComboBoxCell(); SWF.DataGridViewComboBoxCell newCell = new SWF.DataGridViewComboBoxCell(); IRawElementProviderFragmentRoot provider = ColumnCellTest(column, cell, true, newCell); // Lets test navigation. IRawElementProviderFragment child = provider.Navigate(NavigateDirection.FirstChild); while (child != null) { if ((int)child.GetPropertyValue(AutomationElementIdentifiers.ControlTypeProperty.Id) == ControlType.DataItem.Id) { break; } child = child.Navigate(NavigateDirection.NextSibling); } // Lets search our ComboBox child = child.Navigate(NavigateDirection.FirstChild); while (child != null) { if ((int)child.GetPropertyValue(AutomationElementIdentifiers.ControlTypeProperty.Id) == ControlType.ComboBox.Id) { break; } child = child.Navigate(NavigateDirection.NextSibling); } // ComboBox should have 2 children. Button and ListBox int children = 0; IRawElementProviderFragmentRoot comboboxProvider = child as IRawElementProviderFragmentRoot; child = child.Navigate(NavigateDirection.FirstChild); while (child != null) { children++; child = child.Navigate(NavigateDirection.NextSibling); } Assert.AreEqual(2, children, "ComboBox.Children"); // Exposes #493520 // cell should be the first combobox cell.Value = "1"; ISelectionProvider selectionProvider = (ISelectionProvider)comboboxProvider.GetPatternProvider(SelectionPatternIdentifiers.Pattern.Id); Assert.IsNotNull(selectionProvider, "Selection Provider missing"); IRawElementProviderSimple [] selection = selectionProvider.GetSelection(); Assert.IsNotNull(selection, "Selection is null"); foreach (IRawElementProviderSimple selected in selection) { Assert.IsNotNull(selected, "Selected is null"); } cell.Value = null; selection = selectionProvider.GetSelection(); Assert.IsNotNull(selection, "Selection is null"); foreach (IRawElementProviderSimple selected in selection) { Assert.IsNotNull(selected, "Selected is null"); } }
public override void ISelectionProvider_Methods() { bool concreteLoaded = false; bool expanded = false; ComboBox combobox = CreateConcreteFrameworkElement() as ComboBox; combobox.Width = 300; combobox.Loaded += (o, e) => concreteLoaded = true; combobox.DropDownOpened += (o, e) => expanded = true; combobox.Items.Add("Item0"); combobox.Items.Add("Item1"); TestPanel.Children.Add(combobox); AutomationPeer peer = null; ISelectionProvider selectionProvider = null; IRawElementProviderSimple[] selection = null; EnqueueConditional(() => concreteLoaded, "ConcreteLoaded #0"); Enqueue(() => combobox.ApplyTemplate()); Enqueue(() => combobox.IsDropDownOpen = true); EnqueueConditional(() => expanded, "Expanded #0"); Enqueue(() => combobox.IsDropDownOpen = false); Enqueue(() => { peer = FrameworkElementAutomationPeer.CreatePeerForElement(combobox); selectionProvider = peer.GetPattern(PatternInterface.Selection) as ISelectionProvider; Assert.IsNotNull(selectionProvider, "Selection Provider"); Assert.IsFalse(selectionProvider.CanSelectMultiple, "CanSelectMultiple #0"); Assert.IsFalse(selectionProvider.IsSelectionRequired, "IsSelectionRequired #0"); selection = selectionProvider.GetSelection(); Assert.IsNull(selection, "GetSelection #0"); }); Enqueue(() => combobox.SelectedIndex = 1); Enqueue(() => { selection = selectionProvider.GetSelection(); Assert.IsNotNull(selection, "GetSelection #1"); Assert.AreEqual("Item1", new PeerFromProvider().GetPeerFromProvider(selection [0]).GetName(), "Name #0"); selectionProvider = peer.GetPattern(PatternInterface.Selection) as ISelectionProvider; Assert.AreEqual(1, selection.Length, "GetSelection #2"); }); Enqueue(() => { combobox.Items.Add("Item2"); combobox.SelectedIndex = 0; }); Enqueue(() => { selection = selectionProvider.GetSelection(); Assert.IsNotNull(selection, "GetSelection #3"); Assert.AreEqual(1, selection.Length, "GetSelection #4"); Assert.AreEqual("Item0", new PeerFromProvider().GetPeerFromProvider(selection [0]).GetName(), "Name #2"); }); Enqueue(() => combobox.SelectedIndex = 1); Enqueue(() => { selection = selectionProvider.GetSelection(); Assert.IsNotNull(selection, "GetSelection #5"); Assert.AreEqual(1, selection.Length, "GetSelection #6"); Assert.AreEqual("Item1", new PeerFromProvider().GetPeerFromProvider(selection [0]).GetName(), "Name #3"); }); Enqueue(() => combobox.SelectedIndex = 2); Enqueue(() => { selection = selectionProvider.GetSelection(); Assert.IsNotNull(selection, "GetSelection #7"); Assert.AreEqual(1, selection.Length, "GetSelection #8"); Assert.AreEqual("Item2", new PeerFromProvider().GetPeerFromProvider(selection [0]).GetName(), "Name #4"); }); EnqueueTestComplete(); }
public void ItemsNavigationTest() { DomainUpDown domainUpDown = (DomainUpDown)GetControlInstance(); domainUpDown.Items.Add("First"); domainUpDown.Items.Add("Second"); domainUpDown.Items.Add("Third"); domainUpDown.Items.Add("Fourth"); Form.Controls.Add(domainUpDown); IRawElementProviderFragmentRoot rootProvider; IRawElementProviderFragment childProvider; rootProvider = (IRawElementProviderFragmentRoot)GetProviderFromControl(domainUpDown); // Skip over the Forward and Backward buttons childProvider = rootProvider.Navigate(NavigateDirection.FirstChild); childProvider = childProvider.Navigate(NavigateDirection.NextSibling); childProvider = childProvider.Navigate(NavigateDirection.NextSibling); IValueProvider item_val_prov = (IValueProvider)childProvider.GetPatternProvider( ValuePatternIdentifiers.Pattern.Id); Assert.AreEqual("First", item_val_prov.Value); // Ensure the parent is set correctly Assert.AreEqual(childProvider.Navigate(NavigateDirection.Parent), rootProvider); childProvider = childProvider.Navigate(NavigateDirection.NextSibling); item_val_prov = (IValueProvider)childProvider.GetPatternProvider( ValuePatternIdentifiers.Pattern.Id); Assert.AreEqual("Second", item_val_prov.Value); // Try to select the Second item ISelectionItemProvider sel_item_prov = (ISelectionItemProvider)childProvider.GetPatternProvider( SelectionItemPatternIdentifiers.Pattern.Id); Assert.IsNotNull(sel_item_prov); sel_item_prov.Select(); Assert.AreEqual(1, domainUpDown.SelectedIndex); // Verify that the SelectionProvider reflects the new // selection ISelectionProvider sel_prov = (ISelectionProvider)rootProvider.GetPatternProvider( SelectionPatternIdentifiers.Pattern.Id); Assert.IsNotNull(sel_prov); IRawElementProviderSimple[] children = sel_prov.GetSelection(); Assert.IsNotNull(children); Assert.AreEqual(1, children.Length); IValueProvider val_prov = (IValueProvider)children[0].GetPatternProvider( ValuePatternIdentifiers.Pattern.Id); Assert.AreEqual("Second", val_prov.Value); }