public void TestButtonClientSideProvider() { // Create the provider ClientSideProviderDescription provider = new ClientSideProviderDescription( new ClientSideProviderFactoryCallback(SampleButtonProvider.ButtonFactory), "Shell_TrayWnd"); ClientSideProviderDescription[] providers = new ClientSideProviderDescription[1] { provider }; try { // Register it ClientSettings.RegisterClientSideProviders(providers); // Get the overridden element AutomationElement startButton = AutomationElement.FromHandle(this.startButtonHwnd); // Validate that it is ours Assert.AreEqual(SampleButtonProvider.ButtonName, startButton.Current.Name); // Unregister it ClientSettings.RegisterClientSideProviders(new ClientSideProviderDescription[0]); // Get the overridden element startButton = AutomationElement.FromHandle(this.startButtonHwnd); // Validate that it is not ours Assert.AreNotEqual(SampleButtonProvider.ButtonName, startButton.Current.Name); } finally { // Restore the status quo ante ClientSettings.RegisterClientSideProviders(new ClientSideProviderDescription[0]); } }
public void TestImageMatch() { // Create the provider ClientSideProviderDescription provider = new ClientSideProviderDescription( new ClientSideProviderFactoryCallback( SampleButtonProvider.ButtonFactory), "BUTTON", "EXPLORER.EXE", ClientSideProviderMatchIndicator.None); ClientSideProviderDescription[] providers = new ClientSideProviderDescription[1] { provider }; try { // Register it ClientSettings.RegisterClientSideProviders(providers); // Get the overridden element AutomationElement startButton = AutomationElement.FromHandle(this.startButtonHwnd); // Validate that it is ours Assert.AreEqual(SampleButtonProvider.ButtonName, startButton.Current.Name); } finally { // Restore the status quo ante ClientSettings.RegisterClientSideProviders(new ClientSideProviderDescription[0]); } }
public void TestPartialMatchNotPermitted() { // Create the provider ClientSideProviderDescription provider = new ClientSideProviderDescription( new ClientSideProviderFactoryCallback( SampleButtonProvider.ButtonFactory), "Shell_", null /* image name */, ClientSideProviderMatchIndicator.None); ClientSideProviderDescription[] providers = new ClientSideProviderDescription[1] { provider }; try { // Register it ClientSettings.RegisterClientSideProviders(providers); // Get the overridden element AutomationElement startButton = AutomationElement.FromHandle(this.startButtonHwnd); // Validate that it is not ours Assert.AreNotEqual(SampleButtonProvider.ButtonName, startButton.Current.Name); } finally { // Restore the status quo ante ClientSettings.RegisterClientSideProviders(new ClientSideProviderDescription[0]); } }
private static void AddToProxyDescriptionTable(ClientSideProviderDescription[] proxyInfo) { ClientSideProviderDescription pi; // the array that is passed in may have the same className occuring more than once in the table. // The way this works it the first occurence in the array is giver the first chance to return a valid // proxy. In order to make that work we go through the array backwards so the the entries first // in the table get inserted in front of the ones that came later. This also works if // RegisterWindowHandlers is called more than once. for( int i = proxyInfo.Length - 1; i >= 0; i-- ) { pi = proxyInfo[i]; // Check for pseudo-proxy names... if( pi.ClassName != null && pi.ClassName.Length > 0 && pi.ClassName[ 0 ] == '#' ) { for( int j = 0 ; j < _pseudoProxyClassNames.Length ; j++ ) { if( pi.ClassName.Equals( _pseudoProxyClassNames[ j ] ) ) { if( pi.ImageName != null || pi.Flags != 0 ) { throw new ArgumentException(SR.Get(SRID.NonclientClassnameCannotBeUsedWithFlagsOrImagename)); } _pseudoProxies[j] = pi.ClientSideProviderFactoryCallback; break; } } // fall through to add to table as usual, that ensures that it appears in a 'get' operation. } if( pi.ClassName == null && pi.ImageName == null ) { _fallbackHandlers.Insert(0, pi.ClientSideProviderFactoryCallback); } else if ( pi.ClassName == null ) { AddToHashTable(_imageOnlyHandlers, pi.ImageName, pi.ClientSideProviderFactoryCallback); } else if ((pi.Flags & ClientSideProviderMatchIndicator.AllowSubstringMatch) != 0) { _partialClassHandlers.Insert( 0, pi ); } else { AddToHashTable( _classHandlers, pi.ClassName, pi ); } } }
// register specified proxies internal static void RegisterWindowHandlers(ClientSideProviderDescription[] proxyInfo) { // If a client registers a proxy before the defaults proxies are loaded because of use, // we should load the defaults first. LoadDefaultProxies(); lock (_lockObj) { AddToProxyDescriptionTable( proxyInfo ); } }
// set proxy table to specified array, clearing any previously registered proxies internal static void SetProxyDescriptionTable(ClientSideProviderDescription[] proxyInfo) { lock (_lockObj) { // This method replaces the entire table. So clear all the collections for( int i = 0 ; i < _pseudoProxies.Length ; i++ ) { _pseudoProxies[ i ] = null; } _classHandlers.Clear(); _partialClassHandlers.Clear(); _imageOnlyHandlers.Clear(); _fallbackHandlers.Clear(); AddToProxyDescriptionTable( proxyInfo ); // if someone calls this method before the default proxies are // loaded assume they don't want us to add the defaults on top // of the ones they just put into affect here _defaultProxiesNeeded = false; } }
// return an array representing the currently registered proxies internal static ClientSideProviderDescription[] GetProxyDescriptionTable() { // the ClientSideProviderDescription table is split into four different collections. Bundle them all back // together to let them be manipulated // If a client gets the table before the defaults proxies are loaded because of use, it should return the default proxies LoadDefaultProxies(); lock (_lockObj) { int count = 0; IEnumerable [ ] sourceProxyDescription = {_classHandlers, _partialClassHandlers, _imageOnlyHandlers, _fallbackHandlers}; // figure out how many there are foreach ( IEnumerable e in sourceProxyDescription ) { foreach ( Object item in e ) { Object o = item; if( o is DictionaryEntry ) o = ((DictionaryEntry)o).Value; if (o is ClientSideProviderDescription) { count++; } else if (o is ClientSideProviderFactoryCallback) { count++; } else { count += ((ArrayList)o).Count; } } } ClientSideProviderDescription[] proxyDescriptions = new ClientSideProviderDescription[count]; count = 0; // Because the four collections have a simular stucture in common we can treat like they are the same // and build the array in the correct order from each one. foreach ( IEnumerable e in sourceProxyDescription ) { foreach ( Object item in e ) { Object o = item; if( o is DictionaryEntry ) o = ((DictionaryEntry)o).Value; if (o is ClientSideProviderDescription) { proxyDescriptions[count++] = (ClientSideProviderDescription)o; } else if (o is ClientSideProviderFactoryCallback) { ClientSideProviderFactoryCallback pfc = (ClientSideProviderFactoryCallback)o; proxyDescriptions[count++] = new ClientSideProviderDescription(pfc, null); } else { foreach( Object o1 in (ArrayList) o ) { proxyDescriptions[count++] = (ClientSideProviderDescription)o1; } } } } return proxyDescriptions; } }
internal AdapterProxyFactory(ClientSideProviderDescription proxyDescription) { this._proxyDescription = proxyDescription; }
public void MyTestInitialize() { // Find the taskbar, which will be our target AutomationElement taskBar = AutomationElementTest.GetTaskbar(); this.targetHwnd = (IntPtr)taskBar.Current.NativeWindowHandle; // Register a client side provider ClientSideProviderDescription provider = new ClientSideProviderDescription( new ClientSideProviderFactoryCallback(MockPatternProvider.MockPatternFactory), "Shell_TrayWnd"); ClientSideProviderDescription[] providers = new ClientSideProviderDescription[1] { provider }; ClientSettings.RegisterClientSideProviders(providers); // Get the overridden element this.mockObject = AutomationElement.FromHandle(this.targetHwnd); Assert.IsNotNull(this.mockObject); }
public static void RegisterClientSideProviders(ClientSideProviderDescription[] clientSideProviderDescription) { Utility.ValidateArgumentNonNull(clientSideProviderDescription, "clientSideProviderDescription "); // Convert providers to native code representation List<UIAutomationClient.IUIAutomationProxyFactoryEntry> entriesList = new List<UIAutomationClient.IUIAutomationProxyFactoryEntry>(); foreach (ClientSideProviderDescription provider in clientSideProviderDescription) { // Construct a wrapper for the proxy factory callback Utility.ValidateArgumentNonNull(provider.ClientSideProviderFactoryCallback, "provider.ClientSideProviderFactoryCallback"); ProxyFactoryCallbackWrapper wrapper = new ProxyFactoryCallbackWrapper(provider.ClientSideProviderFactoryCallback); // Construct a factory entry UIAutomationClient.IUIAutomationProxyFactoryEntry factoryEntry = Automation.Factory.CreateProxyFactoryEntry(wrapper); factoryEntry.AllowSubstringMatch = ((provider.Flags & ClientSideProviderMatchIndicator.AllowSubstringMatch) != 0) ? 1 : 0; factoryEntry.CanCheckBaseClass = ((provider.Flags & ClientSideProviderMatchIndicator.DisallowBaseClassNameMatch) != 0) ? 0 : 1; factoryEntry.ClassName = provider.ClassName; factoryEntry.ImageName = provider.ImageName; // Add it to the list entriesList.Add(factoryEntry); } // Get the proxy map from Automation and restore the default table UIAutomationClient.IUIAutomationProxyFactoryMapping map = Automation.Factory.ProxyFactoryMapping; map.RestoreDefaultTable(); // Decide where to insert // MSDN recommends inserting after non-control and container proxies uint insertBefore; uint count = (uint)map.count; for (insertBefore = 0; insertBefore < count; ++insertBefore) { string proxyFactoryId = map.GetEntry(insertBefore).ProxyFactory.ProxyFactoryId; if (!proxyFactoryId.Contains("Non-Control") && !proxyFactoryId.Contains("Container")) { break; } } // Insert our new entries map.InsertEntries(insertBefore, entriesList.ToArray()); }
/// <summary> /// Register client-side providers to use on HWND-based controls. /// </summary> /// <param name="clientSideProviderDescription">Array of ClientSideProviderDescription structs that specify window class names and factory delegate</param> public static void RegisterClientSideProviders(ClientSideProviderDescription[] clientSideProviderDescription) { Misc.ValidateArgumentNonNull(clientSideProviderDescription, "clientSideProviderDescription "); ProxyManager.RegisterWindowHandlers(clientSideProviderDescription); }
public static void RegisterClientSideProviders ( ClientSideProviderDescription [] clientSideProviderDescription) { throw new NotImplementedException (); }