View | Details | Raw Unified | Return to bug 428845
Collapse All | Expand All

(-)BaseColorControlProviderTest.cs (+120 lines)
Line 0 Link Here
1
// Permission is hereby granted, free of charge, to any person obtaining 
2
// a copy of this software and associated documentation files (the 
3
// "Software"), to deal in the Software without restriction, including 
4
// without limitation the rights to use, copy, modify, merge, publish, 
5
// distribute, sublicense, and/or sell copies of the Software, and to 
6
// permit persons to whom the Software is furnished to do so, subject to 
7
// the following conditions: 
8
//  
9
// The above copyright notice and this permission notice shall be 
10
// included in all copies or substantial portions of the Software. 
11
//  
12
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 
13
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 
14
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 
15
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE 
16
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION 
17
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION 
18
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 
19
// 
20
// Copyright (c) 2008 Novell, Inc. (http://www.novell.com) 
21
// 
22
// Authors: 
23
// 	Neville Gao <nevillegao@gmail.com>
24
// 
25
26
using System;
27
using System.Collections.Generic;
28
using System.Windows.Forms;
29
using System.Threading;
30
using System.Windows.Automation;
31
using System.Windows.Automation.Provider;
32
using Mono.UIAutomation.Winforms;
33
using NUnit.Framework;
34
35
namespace MonoTests.Mono.UIAutomation.Winforms
36
{
37
    	[TestFixture]
38
    	public class BaseColorControlProviderTest : BaseProviderTest
39
    	{
40
		#region Test
41
42
		[Test]
43
		public void BasicPropertiesTest ()
44
		{
45
			IRawElementProviderSimple provider = GetBaseColorControlProvider ();
46
			Assert.IsNotNull (provider, "We should have a BaseColorCotrol");
47
			
48
			TestProperty (provider,
49
			              AutomationElementIdentifiers.ControlTypeProperty,
50
			              ControlType.Pane.Id);
51
			
52
			TestProperty (provider,
53
			              AutomationElementIdentifiers.LocalizedControlTypeProperty,
54
			              "pane");
55
		}
56
57
		#endregion
58
59
		#region SmallColorControl IInvokePattern Test
60
61
		[Test]
62
		public void SmallColorControlInvokeTest ()
63
		{
64
			IRawElementProviderFragmentRoot provider =
65
				(IRawElementProviderFragmentRoot) GetBaseColorControlProvider ();
66
			IRawElementProviderFragment child =
67
				provider.Navigate (NavigateDirection.FirstChild);
68
69
			IInvokeProvider invokeProvider = (IInvokeProvider)
70
				child.GetPatternProvider (InvokePatternIdentifiers.Pattern.Id);
71
			Assert.IsNotNull (invokeProvider,
72
			                  "Not returning InvokePatternIdentifiers.");
73
			
74
			// TODO: we need to get ColorDialog.BaseColorControl.IsSelected to test this.
75
		}
76
77
		#endregion
78
		
79
		#region BaseProviderTest Overrides
80
		
81
		protected override Control GetControlInstance ()
82
		{
83
			return null;
84
		}
85
86
		protected override IRawElementProviderSimple GetProvider ()
87
		{
88
			ColorDialog colorDialog = new ColorDialog ();
89
			return ProviderFactory.GetProvider (colorDialog);
90
		}
91
92
		#endregion
93
94
		private IRawElementProviderSimple GetBaseColorControlProvider ()
95
		{
96
			ColorDialog colorDialog = new ColorDialog ();
97
			IRawElementProviderFragmentRoot rootProvider =
98
				(IRawElementProviderFragmentRoot) ProviderFactory.GetProvider (colorDialog);
99
100
			Thread t = new Thread (new ThreadStart (delegate {
101
				colorDialog.ShowDialog ();
102
				}));
103
			t.Start();
104
			
105
			// Wait for dialog appear
106
			Thread.Sleep (1000);
107
108
			// Destroy dialog
109
			t.Abort ();
110
			
111
			IRawElementProviderFragment provider =
112
				rootProvider.Navigate (NavigateDirection.FirstChild);
113
			while (provider != null && 
114
			       provider.Navigate (NavigateDirection.FirstChild) == null)
115
				provider = provider.Navigate (NavigateDirection.NextSibling);
116
117
			return provider;
118
		}
119
	}
120
}

Return to bug 428845