Inheritance: BasePattern
Ejemplo n.º 1
0
        internal TextWrapper(AutomationElement element, string testSuite, TestPriorities priority, TypeOfControl typeOfControl, TypeOfPattern typeOfPattern, string dirResults, bool testEvents, IApplicationCommands commands)
            :
            base(element, testSuite, priority, typeOfControl, typeOfPattern, dirResults, testEvents, commands)
        {
            if (m_le == null)
                throw new ArgumentException("m_le cannot be null");

            _pattern = (TextPattern)m_le.GetCurrentPattern(TextPattern.Pattern);
            _frameworkId = ((string)m_le.GetCurrentPropertyValue(AutomationElement.FrameworkIdProperty)).ToLower(CultureInfo.InvariantCulture);
            _testPriority = TestPriorities.BuildVerificationTest; // default value

            // Determine if tests currently running on Windows Vista
            NativeMethods.OSVERSIONINFOEX ver = new NativeMethods.OSVERSIONINFOEX();
            UnsafeNativeMethods.GetVersionEx(ver);
            if (ver.majorVersion >= 6) // This should account for Windows Vista + Service Packs
                _windowsVista = true;   // It may also occur for Vienna, but the expectation is things
            else                        // could change so much post-Vista, that TextPattern tests will
                _windowsVista = false;  // have to be revisited anyway ((i.e. we will likely be moving to un-managed client)

            Comment("Operating System Version = " + ver.majorVersion + "." + ver.minorVersion + "." + ver.buildNumber);
        }
Ejemplo n.º 2
0
        private static TextPatternRange GetRandomTestPatternRange(TextPattern pattern)
        {
            int count = _rnd.Next(-10, 10);
            
            TextUnit textUnit = GetRandomTextUnit();
            pattern.DocumentRange.Move(textUnit, count);

            count = _rnd.Next(-10, 10);
            textUnit = GetRandomTextUnit();
            pattern.DocumentRange.MoveEndpointByUnit(TextPatternRangeEndpoint.End, textUnit, count);
            
            return pattern.DocumentRange;
        }
Ejemplo n.º 3
0
        // -------------------------------------------------------------------
        // Determine if the application we are hitting supports knowledge about the control's text implementation
        // -------------------------------------------------------------------
        private void TS_ScenarioPreConditions(bool requireTextPattern, CheckType checkType)
        {
            string className;
            string localizedControlType;

            // This is hard-coded as a critical failure
            if (m_le == null)
            {
                ThrowMe( CheckType.Verification, "Unable to get AutomationElement for control with focus");
            }

            // Give info about control 
            TextLibrary.GetClassName(m_le, out className, out localizedControlType);
            Comment("Automation ID = " + m_le.Current.AutomationId.ToString() +
                    "           (" + className + " / " + localizedControlType + ")");

            try
            {
                _pattern = m_le.GetCurrentPattern(TextPattern.Pattern) as TextPattern;
            }
            catch (Exception exception)
            {
                if (Library.IsCriticalException(exception))
                    throw;

                Comment("Acquiring TextPattern for automation element with focus raised exception");
                Comment("  Message = " + exception.Message);
                Comment("  Type    = " + exception.GetType().ToString());
                ThrowMe(checkType, "Unable to proceed with test, should not have received exception acquiring TextPattern");  // hard-coded... on purpose
            }

            m_TestStep++;
        }
Ejemplo n.º 4
0
 // compare two text patterns and return true if they are from the same logical element.
 static internal bool Compare(TextPattern t1, TextPattern t2)
 {
     return Misc.Compare(t1._element, t2._element);
 }
Ejemplo n.º 5
0
        // -------------------------------------------------------------------
        // Determine if the application we are hitting supports knowledge about the control's text implementation
        // -------------------------------------------------------------------
        private void TS_ScenarioPreConditions(bool requireTextPattern, CheckType checkType)
        {
            string className;
            string localizedControlType;

            // This is hard-coded as a critical failure
            if (m_le == null)
            {
                ThrowMe(
                    CheckType.Verification, "Unable to get AutomationElement for control with focus");
            }

            // Give info about control
            GetClassName(m_le, out className, out localizedControlType);
            Comment("Automation ID = " + m_le.Current.AutomationId.ToString() +
                    "           (" + className + " / " + localizedControlType + ")");

            try
            {
                _pattern = m_le.GetCurrentPattern(TextPattern.Pattern) as TextPattern;
            }
            catch (InvalidOperationException)
            {
                Comment("Unable to get a _textPattern for this control (likely a disabled control)");
                supportsText = false;
            }
            catch (Exception exception)
            {
                if (Library.IsCriticalException(exception))
                    throw;

                Comment("Acquiring TextPattern for automation element with focus raised exception");
                Comment("  Message = " + exception.Message);
                Comment("  Type    = " + exception.GetType().ToString());
                ThrowMe(CheckType.Verification, "Unable to proceed with test, should not have received exception acquiring TextPattern");  // hard-coded... on purpose
            }

            // Do we have a valid text pattern?    
            if ((_pattern == null) && (requireTextPattern == true ))
            {
                ThrowMe(CheckType.Verification, "Unable to proceed with test, should not have received exception acquiring TextPattern");  // hard-coded... on purpose
            }

            // Would be nice to have this information.            
            if (m_le.Current.AutomationId.ToString().Length == 0)
            {
                ThrowMe(checkType, "Unable to determine automation id of control");
            }

            m_TestStep++;
        }
Ejemplo n.º 6
0
        /// --------------------------------------------------------------------
        /// <summary>
        ///     Finds the text control in our target.
        /// </summary>
        /// <param name="src">The object that raised the event.</param>
        /// <param name="e">Event arguments.</param>
        /// <remarks>
        ///     Initializes the TextPattern object and event handlers.
        /// </remarks>
        /// --------------------------------------------------------------------
        private void FindTextProvider_Click(object src, RoutedEventArgs e)
        {
            // Set up the conditions for finding the text control.
            var documentControl = new PropertyCondition(
                AutomationElement.ControlTypeProperty,
                ControlType.Document);
            var textPatternAvailable = new PropertyCondition(
                AutomationElement.IsTextPatternAvailableProperty, true);
            var findControl =
                new AndCondition(documentControl, textPatternAvailable);

            // Get the Automation Element for the first text control found.
            // For the purposes of this sample it is sufficient to find the 
            // first text control. In other cases there may be multiple text
            // controls to sort through.
            _targetDocument =
                _targetWindow.FindFirst(TreeScope.Descendants, findControl);

            // Didn't find a text control.
            if (_targetDocument == null)
            {
                _targetResult.Content =
                    _wpfTarget +
                    " does not contain a Document control type.";
                _targetResult.Background = Brushes.Salmon;
                _startWpfTargetButton.IsEnabled = false;
                return;
            }

            // Get required control patterns 
            _targetTextPattern =
                _targetDocument.GetCurrentPattern(
                    TextPattern.Pattern) as TextPattern;

            // Didn't find a text control that supports TextPattern.
            if (_targetTextPattern == null)
            {
                _targetResult.Content =
                    _wpfTarget +
                    " does not contain an element that supports TextPattern.";
                _targetResult.Background = Brushes.Salmon;
                _startWpfTargetButton.IsEnabled = false;
                return;
            }

            // Text control is available so display the client controls.
            _infoGrid.Visibility = Visibility.Visible;

            _targetResult.Content =
                "Text provider found.";
            _targetResult.Background = Brushes.LightGreen;

            // Initialize the document range for the text of the document.
            _documentRange = _targetTextPattern.DocumentRange;

            // Initialize the client's search buttons.
            if (_targetTextPattern.DocumentRange.GetText(1).Length > 0)
            {
                _searchForwardButton.IsEnabled = true;
            }
            // Initialize the client's search TextBox.
            _searchString.IsEnabled = true;

            // Check if the text control supports text selection
            if (_targetTextPattern.SupportedTextSelection ==
                SupportedTextSelection.None)
            {
                _targetResult.Content = "Unable to select text.";
                _targetResult.Background = Brushes.Salmon;
                return;
            }

            // Edit control found so remove the find button from the client.
            _findEditButton.Visibility = Visibility.Collapsed;

            // Initialize the client with the current target selection, if any.
            NotifySelectionChanged();

            // Search starts at beginning of doc and goes forward
            _searchBackward = false;

            // Initialize a text changed listener.
            // An instance of TextPatternRange will become invalid if 
            // one of the following occurs:
            // 1) The text in the provider changes via some user activity.
            // 2) ValuePattern.SetValue is used to programatically change 
            // the value of the text in the provider.
            // The only way the client application can detect if the text 
            // has changed (to ensure that the ranges are still valid), 
            // is by setting a listener for the TextChanged event of 
            // the TextPattern. If this event is raised, the client needs 
            // to update the targetDocumentRange member data to ensure the 
            // user is working with the updated text. 
            // Clients must always anticipate the possibility that the text 
            // can change underneath them.
            Automation.AddAutomationEventHandler(
                TextPattern.TextChangedEvent,
                _targetDocument,
                TreeScope.Element,
                TextChanged);

            // Initialize a selection changed listener.
            // The target selection is reflected in the client.
            Automation.AddAutomationEventHandler(
                TextPattern.TextSelectionChangedEvent,
                _targetDocument,
                TreeScope.Element,
                OnTextSelectionChange);
        }
Ejemplo n.º 7
0
 //---------------------------------------------------------------------------
 // TestStep for TextPatternRange.TextPattern property
 //---------------------------------------------------------------------------
 static internal void TS_IsMatchingTextPattern(TextPattern _pattern, TextPattern newPattern, CheckType checkType)
 {
     if (ReferenceEquals(_pattern, newPattern) == true)
         Comment("TextPattern property matches expected instance of TextPattern class");
     else
         ThrowMe(
                 checkType, "TextPattern property does not match expected instance of TextPattern class");
     m_TestStep++;
 }
Ejemplo n.º 8
0
        //---------------------------------------------------------------------------
        // TestStep for TextPatternRange.TextPattern Property
        //---------------------------------------------------------------------------
        static internal void TS_TextPattern(TextPatternRange range, ref TextPattern pattern, CheckType checkType)
        {
            Range_TextPattern(range, ref pattern);

            if (pattern == null)
                ThrowMe(checkType, "TextPatternRange.TextPattern property should not return NULL");

            m_TestStep++;
        }
Ejemplo n.º 9
0
        //---------------------------------------------------------------------------
        // Wrapper for TextPatternRange.TextPattern Property
        //---------------------------------------------------------------------------
        static internal void Range_TextPattern(TextPatternRange callingRange, ref TextPattern pattern)
        {
            string call = "TextPatternRange.TextPattern";
            Comment("---Getting value of " + call);

            if (callingRange == null)
                throw new ArgumentNullException(call + " requires non-NULL TextPatterncallingRange");

            pattern = callingRange.TextPattern;
        }
Ejemplo n.º 10
0
        //---------------------------------------------------------------------------
        // Wrapper for TextPattern.GetVisibleRanges Method
        //---------------------------------------------------------------------------
        internal void Pattern_GetVisibleRanges(TextPattern textPattern, ref TextPatternRange[] returnedRanges, Type expectedException, CheckType checkType)
        {
            string call = "TextPattern.GetVisibleRanges()";
            Comment("---Calling " + call);

            try
            {
                returnedRanges = textPattern.GetVisibleRanges();
            }
            catch (Exception actualException)
            {
                if (Library.IsCriticalException(actualException))
                    throw;

                TestException(expectedException, actualException, call, checkType);
                return;
            }

            if (returnedRanges == null)
                ThrowMe(checkType, call + " should not give a null TextPatternRange");

            TestNoExceptionQuiet(expectedException, call, checkType);
        }
Ejemplo n.º 11
0
        //---------------------------------------------------------------------------
        // Wrapper for TextPattern.RangeFromChild Method
        //---------------------------------------------------------------------------
        internal void Pattern_RangeFromChild(TextPattern textPattern, ref TextPatternRange returnedRange, AutomationElement childElem, Type expectedException, CheckType checkType)
        {
            string call = "TextPattern.RangeFromChild(" + childElem + ")";
            Comment("---Calling " + call);

            try
            {
                returnedRange = textPattern.RangeFromChild(childElem);
            }
            catch (Exception actualException)
            {
                if (Library.IsCriticalException(actualException))
                    throw;

                if( (actualException is ArgumentException) || (actualException is InvalidOperationException))
                {
                    // Win32 Edit Controls don't support children. InvalidOperationException here is expected
                    if ((TextLibrary.typeOfProvider == "win32") || (TextLibrary.typeOfProvider == "winform"))
                    {
                        if ((childElem != null) && (TextLibrary.IsRichEdit(childElem) == false))
                        {
                            // Yes, this is a hard-coded CheckType. This is by-design/a good thing
                            ThrowMe(CheckType.IncorrectElementConfiguration, "Win32 Edit controls do not support children");
                        }
                    }
                }

                TestException(expectedException, actualException, call, checkType);
                return;
            }

            if (returnedRange == null)
                ThrowMe(checkType, call + " should not give a null TextPatternRange");

            TestNoExceptionQuiet(expectedException, call, checkType);
        }
Ejemplo n.º 12
0
        //---------------------------------------------------------------------------
        // Wrapper for TextPattern.RangeFromPoint Method
        //---------------------------------------------------------------------------
        internal void Pattern_RangeFromPoint(TextPattern textPattern, ref TextPatternRange returnedRange, Point screenLocation, Type expectedException, CheckType checkType)
        {
            string call = "TextPattern.RangeFromPoint(" + screenLocation + ")";
            Comment("---Calling " + call);

            try
            {
                returnedRange = textPattern.RangeFromPoint(screenLocation);
            }
            catch (Exception actualException)
            {
                if (Library.IsCriticalException(actualException))
                    throw;

                TestException(expectedException, actualException, call, checkType);
                return;
            }

            if (returnedRange == null)
                throw new ArgumentNullException(call + " should not give a null TextPatternRange");

            TestNoExceptionQuiet(expectedException, call, checkType);
        }
 // compare two text patterns and return true if they are from the same logical element.
 static internal bool Compare(TextPattern t1, TextPattern t2)
 {
     return(Misc.Compare(t1._element, t2._element));
 }