Merge branch 'loaded-branch'
[moon.git] / test / 2.0 / moon-unit / System.Windows.Automation.Peers / HyperlinkButtonAutomationPeerTest.cs
blob2d1562af2a690726b1665e39a84ebfa0666a4311
1 using System;
2 using System.Collections.Generic;
3 using System.Net;
4 using System.Windows;
5 using System.Windows.Controls;
6 using System.Windows.Documents;
7 using System.Windows.Ink;
8 using System.Windows.Input;
9 using System.Windows.Media;
10 using System.Windows.Media.Animation;
11 using System.Windows.Shapes;
12 using System.Windows.Automation.Peers;
13 using System.Windows.Controls.Primitives;
15 using Microsoft.VisualStudio.TestTools.UnitTesting;
16 using Mono.Moonlight.UnitTesting;
17 using Microsoft.Silverlight.Testing;
20 namespace MoonTest.System.Windows.Automation.Peers {
22 [TestClass]
23 public class HyperlinkButtonAutomationPeerTest : ButtonBaseAutomationPeerTest {
25 public class HyperlinkButtonAutomationPeerPoker : HyperlinkButtonAutomationPeer, FrameworkElementAutomationPeerContract {
27 public HyperlinkButtonAutomationPeerPoker (HyperlinkButton owner) : base (owner)
31 #region FrameworkElementAutomationPeerContract Members
33 public AutomationPeer GetLabeledByCore_ ()
35 return base.GetLabeledByCore ();
38 public string GetNameCore_ ()
40 return base.GetNameCore ();
43 public bool IsContentElementCore_ ()
45 return base.IsContentElementCore ();
48 public bool IsControlElementCore_ ()
50 return base.IsControlElementCore ();
53 public string GetAcceleratorKeyCore_ ()
55 return base.GetAcceleratorKeyCore ();
58 public string GetAccessKeyCore_ ()
60 return base.GetAccessKeyCore ();
63 public AutomationControlType GetAutomationControlTypeCore_ ()
65 return base.GetAutomationControlTypeCore ();
68 public string GetAutomationIdCore_ ()
70 return base.GetAutomationIdCore ();
73 public Rect GetBoundingRectangleCore_ ()
75 return base.GetBoundingRectangle ();
78 public List<AutomationPeer> GetChildrenCore_ ()
80 return base.GetChildrenCore ();
83 public Point GetClickablePointCore_ ()
85 return base.GetClickablePointCore ();
88 public string GetHelpTextCore_ ()
90 return base.GetHelpTextCore ();
93 public string GetItemStatusCore_ ()
95 return base.GetItemStatusCore ();
98 public string GetItemTypeCore_ ()
100 return base.GetItemTypeCore ();
103 public string GetLocalizedControlTypeCore_ ()
105 return base.GetLocalizedControlType ();
108 public AutomationOrientation GetOrientationCore_ ()
110 return base.GetOrientationCore ();
113 public bool HasKeyboardFocusCore_ ()
115 return base.HasKeyboardFocus ();
118 public bool IsEnabledCore_ ()
120 return base.IsEnabledCore ();
123 public bool IsKeyboardFocusableCore_ ()
125 return base.IsKeyboardFocusableCore ();
128 public bool IsOffscreenCore_ ()
130 return base.IsOffscreenCore ();
133 public bool IsPasswordCore_ ()
135 return base.IsPasswordCore ();
138 public bool IsRequiredForFormCore_ ()
140 return base.IsRequiredForFormCore ();
143 public string GetClassNameCore_ ()
145 return base.GetClassNameCore ();
148 #endregion
151 [TestMethod]
152 public override void GetClassName ()
154 FrameworkElementAutomationPeerContract feap
155 = CreateConcreteFrameworkElementAutomationPeer (CreateConcreteFrameworkElement ());
156 Assert.AreEqual("Hyperlink", feap.GetClassName (), "GetClassNameCore");
157 Assert.AreEqual("Hyperlink", feap.GetClassNameCore_ (), "GetClassNameCoreCore");
160 [TestMethod]
161 public override void GetAutomationControlType ()
163 FrameworkElementAutomationPeerContract feap
164 = CreateConcreteFrameworkElementAutomationPeer (CreateConcreteFrameworkElement ());
165 Assert.AreEqual(AutomationControlType.Hyperlink, feap.GetAutomationControlType (), "GetAutomationControlType");
166 Assert.AreEqual(AutomationControlType.Hyperlink, feap.GetAutomationControlTypeCore_ (), "GetAutomationControlTypeCore");
169 [TestMethod]
170 public override void GetPattern ()
172 FrameworkElementAutomationPeer peer
173 = CreateConcreteFrameworkElementAutomationPeer (CreateConcreteFrameworkElement())
174 as FrameworkElementAutomationPeer;
176 Assert.IsNull (peer.GetPattern (PatternInterface.Dock), "Dock");
177 Assert.IsNull (peer.GetPattern (PatternInterface.ExpandCollapse), "ExpandCollapse");
178 Assert.IsNull (peer.GetPattern (PatternInterface.Grid), "Grid");
179 Assert.IsNull (peer.GetPattern (PatternInterface.GridItem), "GridItem");
180 Assert.IsNull (peer.GetPattern (PatternInterface.MultipleView), "MultipleView");
181 Assert.IsNull (peer.GetPattern (PatternInterface.RangeValue), "RangeValue");
182 Assert.IsNull (peer.GetPattern (PatternInterface.Scroll), "Scroll");
183 Assert.IsNull (peer.GetPattern (PatternInterface.ScrollItem), "ScrollItem");
184 Assert.IsNull (peer.GetPattern (PatternInterface.Selection), "Selection");
185 Assert.IsNull (peer.GetPattern (PatternInterface.SelectionItem), "SelectionItem");
186 Assert.IsNull (peer.GetPattern (PatternInterface.Table), "Table");
187 Assert.IsNull (peer.GetPattern (PatternInterface.TableItem), "TableItem");
188 Assert.IsNull (peer.GetPattern (PatternInterface.Toggle), "Toggle");
189 Assert.IsNull (peer.GetPattern (PatternInterface.Transform), "Transform");
190 Assert.IsNull (peer.GetPattern (PatternInterface.Window), "Window");
191 Assert.IsNull (peer.GetPattern (PatternInterface.Value), "Value");
193 Assert.IsNotNull (peer.GetPattern (PatternInterface.Invoke), "Invoke");
196 [TestMethod]
197 [Asynchronous]
198 public override void ContentTest()
200 ButtonBase button = (ButtonBase)CreateConcreteFrameworkElement ();
201 Assert.IsTrue (IsContentPropertyElement (), "ButtonElement ContentElement.");
203 bool buttonLoaded = false;
204 button.Loaded += (o, e) => buttonLoaded = true;
205 TestPanel.Children.Add (button);
207 // StackPanel and two TextBlocks
208 bool stackPanelLoaded = false;
209 StackPanel stackPanel = new StackPanel ();
210 stackPanel.Children.Add (new TextBlock () { Text = "Text0" });
211 stackPanel.Children.Add (new TextBlock () { Text = "Text1" });
212 stackPanel.Loaded += (o, e) => stackPanelLoaded = true;
214 int INITIAL_CHILDREN_COUNT = 2;
216 EnqueueConditional (() => buttonLoaded, "ButtonLoaded #0");
217 Enqueue (() =>
219 AutomationPeer peer = FrameworkElementAutomationPeer.CreatePeerForElement (button);
220 Assert.IsNotNull (peer, "FrameworkElementAutomationPeer.CreatePeerForElement");
222 Assert.IsNotNull (peer.GetChildren (), "GetChildren#0");
223 Assert.AreEqual (INITIAL_CHILDREN_COUNT, peer.GetChildren ().Count, "GetChildren #0, count");
225 Assert.AreEqual(typeof (TextBlockAutomationPeer), peer.GetChildren () [0].GetType (), "GetChildren #0, type#1");
226 Assert.AreEqual(typeof (TextBlockAutomationPeer), peer.GetChildren () [1].GetType (), "GetChildren #0, type#2");
227 button.Content = stackPanel;
229 EnqueueConditional (() => buttonLoaded && stackPanelLoaded, "ButtonLoaded #1");
230 Enqueue (() =>
232 AutomationPeer peer = FrameworkElementAutomationPeer.CreatePeerForElement (button);
233 Assert.IsNotNull (peer.GetChildren(), "GetChildren #1");
234 Assert.AreEqual (INITIAL_CHILDREN_COUNT + 2, peer.GetChildren ().Count, "GetChildren.Count #1");
235 // We add one TextBlock
236 stackPanel.Children.Add (new TextBlock () { Text = "Text2" });
237 Assert.IsNotNull (peer.GetChildren (), "GetChildren #2");
238 Assert.AreEqual (INITIAL_CHILDREN_COUNT + 3, peer.GetChildren ().Count, "GetChildren.Count #2");
240 EnqueueTestComplete ();
244 [TestMethod]
245 [Asynchronous]
246 public override void GetBoundingRectangle ()
248 base.GetBoundingRectangle ();
250 TestLocationAndSize ();
253 [TestMethod]
254 public virtual void InvokeProvider_Events ()
256 if (!EventsManager.Instance.AutomationSingletonExists)
257 return;
259 Test_InvokeProvider_Events ((ButtonBase)CreateConcreteFrameworkElement ());
262 [TestMethod]
263 public void IInvokeProvider_Invoke ()
265 Test_InvokeProvider_Invoke (CreateConcreteFrameworkElement () as ButtonBase);
268 protected override FrameworkElement CreateConcreteFrameworkElement ()
270 return new HyperlinkButton ();
273 protected override FrameworkElementAutomationPeerContract CreateConcreteFrameworkElementAutomationPeer (FrameworkElement element)
275 return new HyperlinkButtonAutomationPeerPoker (element as HyperlinkButton);