Merge branch 'loaded-branch'
[moon.git] / test / 2.0 / moon-unit / System.Windows.Automation.Peers / ButtonAutomationPeerTest.cs
blobd37a509db197d54d09201fe906fd385d3cd99ac0
1 //
2 // Unit tests for ButtonAutomationPeer
3 //
4 // Contact:
5 // Moonlight List (moonlight-list@lists.ximian.com)
6 //
7 // Copyright (C) 2009 Novell, Inc (http://www.novell.com)
8 //
9 // Permission is hereby granted, free of charge, to any person obtaining
10 // a copy of this software and associated documentation files (the
11 // "Software"), to deal in the Software without restriction, including
12 // without limitation the rights to use, copy, modify, merge, publish,
13 // distribute, sublicense, and/or sell copies of the Software, and to
14 // permit persons to whom the Software is furnished to do so, subject to
15 // the following conditions:
17 // The above copyright notice and this permission notice shall be
18 // included in all copies or substantial portions of the Software.
20 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
21 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
22 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
23 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
24 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
25 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
26 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
29 using System;
30 using System.Windows;
31 using System.Windows.Controls;
32 using System.Windows.Automation;
33 using System.Windows.Automation.Peers;
34 using System.Windows.Automation.Provider;
35 using System.Windows.Controls.Primitives;
37 using Mono.Moonlight.UnitTesting;
38 using Microsoft.VisualStudio.TestTools.UnitTesting;
39 using Microsoft.Silverlight.Testing;
41 namespace MoonTest.System.Windows.Automation.Peers {
43 [TestClass]
44 public class ButtonAutomationPeerTest : ButtonBaseAutomationPeerTest {
46 public class ButtonConcrete : Button {
47 public ButtonConcrete ()
48 : base ()
52 protected override AutomationPeer OnCreateAutomationPeer ()
54 return new ButtonAutomationPeerPoker (this);
58 public class ButtonAutomationPeerPoker : ButtonAutomationPeer, FrameworkElementAutomationPeerContract {
60 public ButtonAutomationPeerPoker (Button owner)
61 : base (owner)
65 #region Overridden Methods
67 public AutomationControlType GetAutomationControlTypeCore_ ()
69 return base.GetAutomationControlTypeCore ();
72 public string GetClassNameCore_ ()
74 return base.GetClassNameCore ();
77 #endregion
79 #region Wrapper Methods
81 public AutomationPeer GetLabeledByCore_ ()
83 return base.GetLabeledByCore ();
86 public string GetNameCore_ ()
88 return base.GetNameCore ();
91 public bool IsContentElementCore_ ()
93 return base.IsContentElementCore ();
96 public bool IsControlElementCore_ ()
98 return base.IsControlElementCore ();
101 public string GetAcceleratorKeyCore_ ()
103 return base.GetAcceleratorKeyCore ();
106 public string GetAccessKeyCore_ ()
108 return base.GetAccessKeyCore ();
111 public string GetAutomationIdCore_ ()
113 return base.GetAutomationIdCore ();
116 public global::System.Windows.Rect GetBoundingRectangleCore_ ()
118 return base.GetBoundingRectangleCore ();
121 public global::System.Collections.Generic.List<AutomationPeer> GetChildrenCore_ ()
123 return base.GetChildrenCore ();
126 public global::System.Windows.Point GetClickablePointCore_ ()
128 return base.GetClickablePointCore ();
131 public string GetHelpTextCore_ ()
133 return base.GetHelpTextCore ();
136 public string GetItemStatusCore_ ()
138 return base.GetItemStatusCore ();
141 public string GetItemTypeCore_ ()
143 return base.GetItemTypeCore ();
146 public string GetLocalizedControlTypeCore_ ()
148 return base.GetLocalizedControlTypeCore ();
151 public AutomationOrientation GetOrientationCore_ ()
153 return base.GetOrientationCore ();
156 public bool HasKeyboardFocusCore_ ()
158 return base.HasKeyboardFocusCore ();
161 public bool IsEnabledCore_ ()
163 return base.IsEnabledCore ();
166 public bool IsKeyboardFocusableCore_ ()
168 return base.IsKeyboardFocusableCore ();
171 public bool IsOffscreenCore_ ()
173 return base.IsOffscreenCore ();
176 public bool IsPasswordCore_ ()
178 return base.IsPasswordCore ();
181 public bool IsRequiredForFormCore_ ()
183 return base.IsRequiredForFormCore ();
186 #endregion
189 [TestMethod]
190 public override void GetAutomationControlType ()
192 ButtonAutomationPeerPoker bapp = new ButtonAutomationPeerPoker (new Button ());
193 Assert.AreEqual (AutomationControlType.Button, bapp.GetAutomationControlType (), "GetAutomationControlType");
194 Assert.AreEqual (AutomationControlType.Button, bapp.GetAutomationControlTypeCore_ (), "GetAutomationControlTypeCore");
197 [TestMethod]
198 public override void GetClassName ()
200 FrameworkElementAutomationPeerContract feap
201 = CreateConcreteFrameworkElementAutomationPeer (CreateConcreteFrameworkElement ());
202 Assert.AreEqual ("Button", feap.GetClassName (), "GetClassNameCore");
203 Assert.AreEqual ("Button", feap.GetClassNameCore_ (), "GetClassNameCoreCore");
206 [TestMethod]
207 public override void GetPattern ()
209 ButtonAutomationPeerPoker bap = new ButtonAutomationPeerPoker (new Button ());
211 Assert.IsNull (bap.GetPattern (PatternInterface.Dock), "Dock");
212 Assert.IsNull (bap.GetPattern (PatternInterface.ExpandCollapse), "ExpandCollapse");
213 Assert.IsNull (bap.GetPattern (PatternInterface.Grid), "Grid");
214 Assert.IsNull (bap.GetPattern (PatternInterface.GridItem), "GridItem");
215 Assert.IsNull (bap.GetPattern (PatternInterface.MultipleView), "MultipleView");
216 Assert.IsNull (bap.GetPattern (PatternInterface.RangeValue), "RangeValue");
217 Assert.IsNull (bap.GetPattern (PatternInterface.Scroll), "Scroll");
218 Assert.IsNull (bap.GetPattern (PatternInterface.ScrollItem), "ScrollItem");
219 Assert.IsNull (bap.GetPattern (PatternInterface.Selection), "Selection");
220 Assert.IsNull (bap.GetPattern (PatternInterface.SelectionItem), "SelectionItem");
221 Assert.IsNull (bap.GetPattern (PatternInterface.Table), "Table");
222 Assert.IsNull (bap.GetPattern (PatternInterface.TableItem), "TableItem");
223 Assert.IsNull (bap.GetPattern (PatternInterface.Toggle), "Toggle");
224 Assert.IsNull (bap.GetPattern (PatternInterface.Transform), "Transform");
225 Assert.IsNull (bap.GetPattern (PatternInterface.Value), "Value");
226 Assert.IsNull (bap.GetPattern (PatternInterface.Window), "Window");
228 Assert.IsNotNull (bap.GetPattern (PatternInterface.Invoke), "Invoke");
231 [TestMethod]
232 public void IInvokeProvider_Invoke ()
234 Test_InvokeProvider_Invoke (CreateConcreteFrameworkElement () as ButtonBase);
237 [TestMethod]
238 [Asynchronous]
239 public override void ContentTest ()
241 ContentTest ((Button)CreateConcreteFrameworkElement ());
244 [TestMethod]
245 [Asynchronous]
246 public override void GetBoundingRectangle ()
248 base.GetBoundingRectangle ();
250 TestLocationAndSize ();
253 [TestMethod]
254 public override void GetName ()
256 base.GetName ();
258 // LAMESPEC: MSDN: A string that contains the name, minus the accelerator key.
260 ButtonConcrete button = CreateConcreteFrameworkElement () as ButtonConcrete;
261 AutomationPeer peer = FrameworkElementAutomationPeer.CreatePeerForElement (button);
262 Assert.IsNotNull (peer, "IsNotNull #0");
264 Assert.AreEqual (string.Empty, peer.GetName (), "GetName #0");
266 button.Content = "Hello I'm button";
267 Assert.AreEqual ("Hello I'm button", peer.GetName (), "GetName #1");
269 button.Content = "Hello I'm &button";
270 Assert.AreEqual ("Hello I'm &button", peer.GetName (), "GetName #2");
272 button.Content = "Hello I'm &&button";
273 Assert.AreEqual ("Hello I'm &&button", peer.GetName (), "GetName #3");
275 button.Content = null;
276 Assert.AreEqual (string.Empty, peer.GetName (), "GetName #4");
278 TextBox textbox = new TextBox ();
279 textbox.Text = "I'm textbox";
280 button.Content = textbox;
282 Assert.AreEqual (string.Empty, peer.GetName (), "GetName #5");
284 TextBlock textblock = new TextBlock ();
285 textblock.Text = "I'm textblock";
286 button.Content = textblock;
288 Assert.AreEqual ("I'm textblock", peer.GetName (), "GetName #6");
290 button.Content = "I'm a button";
291 Assert.AreEqual ("I'm a button", peer.GetName (), "GetName #7");
293 // Now usin a stack panel with a textblock
294 StackPanel panel = new StackPanel ();
295 panel.Children.Add (new TextBlock () { Text = "Textblock in Stackpanel1" });
297 button.Content = panel;
298 Assert.AreEqual (string.Empty, peer.GetName (), "GetName #8");
300 panel.Children.Add (new TextBlock () { Text = "Textblock in Stackpanel2" });
301 Assert.AreEqual (string.Empty, peer.GetName (), "GetName #9");
303 button.Content = "What's up?";
304 Assert.AreEqual ("What's up?", peer.GetName (), "GetName #10");
307 [TestMethod]
308 public virtual void InvokeProvider_Events ()
310 if (!EventsManager.Instance.AutomationSingletonExists)
311 return;
313 Test_InvokeProvider_Events ((ButtonBase)CreateConcreteFrameworkElement ());
316 protected override FrameworkElement CreateConcreteFrameworkElement ()
318 return new ButtonConcrete ();
321 protected override FrameworkElementAutomationPeerContract CreateConcreteFrameworkElementAutomationPeer (FrameworkElement element)
323 return new ButtonAutomationPeerPoker (element as ButtonConcrete);