private static bool HasSameTypeAsReferenceElement(IA11yElement e) { if (e == null) { throw new ArgumentNullException(nameof(e)); } if (!Condition.Context.IsValueCreated) { throw new AxeWindowsException(ErrorMessages.ExpectedValidConditionContext); } var referenceElement = Condition.Context.Value.ReferenceElements.Peek(); return(ControlTypeMatches(e, referenceElement)); }
public override EvaluationCode Evaluate(IA11yElement e) { if (e == null) { throw new ArgumentNullException(nameof(e)); } if (e.Name == null) { throw new ArgumentException(ErrorMessages.ElementNameNullOrWhiteSpace, nameof(e)); } var condition = Name.Length <= ReasonableLength; return(condition.Matches(e) ? EvaluationCode.Pass : EvaluationCode.Error); }
public void Ctor_ElementHasOneLevelOfAncestry_FingerprintRemovesTopParentName() { const string elementName = "NameOfElement"; const string parentName = "NameOfParent"; const string desktopName = "NameOfDesktop"; IA11yElement element = BuildTestElement(controlTypeId: 50033, name: elementName, parent: BuildTestElement(controlTypeId: 50031, name: parentName, parent: BuildTestElement(name: desktopName))); IFingerprint fingerprint = new ScanResultFingerprint(element, DefaultRule, DefaultScanStatus); ValidateFingerprint(fingerprint, nameValue: elementName, controlTypeValue: "Pane(50033)|SplitButton(50031)"); }
private static bool HasSameTypeAsReferenceElement(IA11yElement e) { if (e == null) { throw new ArgumentException(nameof(e)); } if (!Condition.Context.IsValueCreated) { throw new Exception("Expected Condition.Context to be valid"); } var referenceElement = Condition.Context.Value.ReferenceElements.Peek(); return(ControlTypeMatches(e, referenceElement)); }
public override EvaluationCode Evaluate(IA11yElement e) { if (e == null) { throw new ArgumentNullException(nameof(e)); } if (e.Parent == null) { throw new ArgumentException(ErrorMessages.ElementParentNull, nameof(e)); } var siblings = SiblingCount(EligibleHyperlink & Name.Is(e.Name)) <= 1; return(siblings.Matches(e) ? EvaluationCode.Pass : EvaluationCode.Warning); }
private static IA11yElement FindScrollableAncestor(IA11yElement e) { if (e == null) { return(null); } if (e.IsRootElement()) { return(null); } var pattern = e.GetPattern(PatternType.UIA_ScrollPatternId); return(pattern != null ? e : FindScrollableAncestor(e.Parent)); }
private static bool GetIsSelected(IA11yElement e) { if (e == null) { throw new ArgumentNullException(nameof(e)); } var pattern = e.GetPattern(PatternType.UIA_SelectionItemPatternId); if (pattern == null) { return(false); } return(pattern.GetValue <bool>(IsSelectedProperty)); }
private static bool GetCanSelectMultiple(IA11yElement e) { if (e == null) { throw new ArgumentNullException(nameof(e)); } var selectionPattern = e.GetPattern(PatternType.UIA_SelectionPatternId); if (selectionPattern == null) { return(false); } return(selectionPattern.GetValue <bool>(CanSelectMultipleProperty)); }
private static bool IsSelectionRequired(IA11yElement e) { if (e == null) { throw new ArgumentNullException(nameof(e)); } var selection = e.GetPattern(PatternType.UIA_SelectionPatternId); if (selection == null) { return(false); } return(selection.GetValue <bool>("IsSelectionRequired")); }
public override bool PassesTest(IA11yElement e) { if (e == null) { throw new ArgumentNullException(nameof(e)); } if (!IsBoundingRectangleContained(e.Parent, e)) { // if the element is not contained in the parent element, go further var container = e.FindContainerElement(); return(IsBoundingRectangleContained(container, e)); } return(true); }
private static bool MatchOrderInSiblings(IA11yElement e, int index) { if (e == null) { throw new ArgumentNullException(nameof(e)); } if (e.Parent == null || e.Parent.Children == null) { return(false); } if (index < 1 || index > e.Parent.Children.Count()) { return(false); } return(e.Parent.Children.ElementAt(index - 1).RuntimeId == e.RuntimeId); }
private static bool MatchParent(Condition c, IA11yElement e) { if (c == null) { throw new ArgumentNullException(nameof(c)); } if (e == null) { throw new ArgumentNullException(nameof(e)); } if (e.Parent == null) { return(false); } return(c.Matches(e.Parent)); }
public static RunResult RunRuleByID(RuleId id, IA11yElement element) { var rule = Provider.GetRule(id); if (rule == null) { return(new RunResult { EvaluationCode = EvaluationCode.RuleExecutionError, ErrorMessage = Invariant($"No rule matching the ID '{id}' was found.") }); } var retVal = Rules.RunRule(rule, element); return(retVal); }
public override EvaluationCode Evaluate(IA11yElement e) { if (e == null) { throw new ArgumentException(nameof(e)); } if (!IsBoundingRectangleContained(e.Parent, e)) { // if the element is not contained in the parent element, go further var container = e.FindContainerElement(); return(IsBoundingRectangleContained(container, e) ? EvaluationCode.Pass : EvaluationCode.Warning); } return(EvaluationCode.Pass); }
public override EvaluationCode Evaluate(IA11yElement e) { if (e == null) { throw new ArgumentNullException(nameof(e)); } if (PositionInSet.Exists.Matches(e) & SizeOfSet.Exists.Matches(e)) { return(EvaluationCode.Pass); } else if (PropertyConditions.StringProperties.Framework.Is(Core.Enums.Framework.WPF).Matches(e)) { return(EvaluationCode.Warning); } return(EvaluationCode.Error); }
/// <summary> /// Returns true if the given element is a tab item /// and is in the WPF or XAML frameworks. /// These frameworks are very similar. /// </summary> /// <param name="e"></param> /// <returns></returns> public static bool IsWPFTabItem(this IA11yElement e) { if (e == null) { return(false); } if (e.ControlTypeId != Axe.Windows.Core.Types.ControlType.UIA_TabItemControlTypeId) { return(false); } var framework = e.GetUIFramework(); return(framework == Framework.WPF || framework == Framework.XAML); }
private static bool AreMinMaxValuesCorrect(IA11yElement e) { if (e == null) { throw new ArgumentNullException(nameof(e)); } var rangeValue = e.GetPattern(PatternType.UIA_RangeValuePatternId); if (rangeValue == null) { throw new Exception($"Expected {nameof(rangeValue)} not to be null"); } return(PropertyValueMatches(rangeValue, "Minimum", 0.0) && PropertyValueMatches(rangeValue, "Maximum", 100.0) && PropertyValueMatches(rangeValue, "IsReadOnly", true)); }
public override bool PassesTest(IA11yElement e) { string[] stringsToExclude = { @"^\s*Microsoft(\.(\w|\d)+)+\s*$", @"^\s*Windows(\.(\w|\d)+)+\s*$" }; foreach (var s in stringsToExclude) { if (Regex.IsMatch(e.Name, s, RegexOptions.IgnoreCase)) { return(false); } } return(true); }
public override EvaluationCode Evaluate(IA11yElement e) { string[] stringsToExclude = { @"^\s*Microsoft(\.(\w|\d)+)+\s*$", @"^\s*Windows(\.(\w|\d)+)+\s*$" }; foreach (var s in stringsToExclude) { if (Regex.IsMatch(e.Name, s, RegexOptions.IgnoreCase)) { return(EvaluationCode.Error); } } return(EvaluationCode.Pass); }
private static RunResult RunRuleWorker(IRule rule, IA11yElement element) { var result = new RunResult { RuleInfo = rule.Info, element = element, EvaluationCode = EvaluationCode.NotApplicable }; if (!ShouldRun(rule.Condition, element)) { return(result); } result.EvaluationCode = rule.Evaluate(element); return(result); }
private static bool IsTextSelectionSupported(IA11yElement e) { if (e == null) { throw new ArgumentNullException(nameof(e)); } var textPattern = e.GetPattern(PatternType.UIA_TextPatternId); if (textPattern == null) { return(false); } var supportsSelection = textPattern.GetValue <UIAutomationClient.SupportedTextSelection>("SupportedTextSelection"); return(supportsSelection != UIAutomationClient.SupportedTextSelection.SupportedTextSelection_None); }
private static bool IsLargeChangeValueNull(IA11yElement e) { if (e == null) { throw new ArgumentNullException(nameof(e)); } var rangeValue = e.GetPattern(PatternType.UIA_RangeValuePatternId); if (rangeValue == null) { return(true); } var largeChange = rangeValue.GetValue <double>("LargeChange"); return(largeChange == default(double)); }
public override bool PassesTest(IA11yElement e) { if (e == null) { throw new ArgumentNullException(nameof(e)); } if (e.Name == null) { throw new ArgumentException(ErrorMessages.ElementNameNullOrWhiteSpace, nameof(e)); } if (e.LocalizedControlType == null) { throw new ArgumentException(ErrorMessages.ElementLocalizedControlTypeNullOrWhiteSpace, nameof(e)); } var r = new Regex($@"\b{e.LocalizedControlType}\b", RegexOptions.IgnoreCase); return(!r.IsMatch(e.Name)); }
public void DictionaryTest_FingerprintsAreDifferent_TreatsItemsCorrectly() { Dictionary <IFingerprint, int> store = new Dictionary <IFingerprint, int>(); IA11yElement element1 = BuildTestElement(name: _specialNameValue1); IA11yElement element2 = BuildTestElement(name: _specialNameValue2); IFingerprint fingerprint1 = new ScanResultFingerprint(element1, DefaultRule, DefaultScanStatus); IFingerprint fingerprint2 = new ScanResultFingerprint(element2, DefaultRule, DefaultScanStatus); store.Add(fingerprint1, 1); Assert.AreEqual(1, store.Count); Assert.IsTrue(store.TryGetValue(fingerprint1, out int value)); Assert.AreEqual(1, value); Assert.IsFalse(store.TryGetValue(fingerprint2, out value)); store.Add(fingerprint2, 2); Assert.AreEqual(2, store.Count); Assert.IsTrue(store.TryGetValue(fingerprint2, out value)); Assert.AreEqual(2, value); }
public override bool PassesTest(IA11yElement e) { if (e == null) { throw new ArgumentNullException(nameof(e)); } if (String.IsNullOrWhiteSpace(e.Name)) { throw new ArgumentException(ErrorMessages.ElementNameNullOrWhiteSpace, nameof(e)); } if (!ControlTypeStrings.Dictionary.TryGetValue(e.ControlTypeId, out string controlTypeString)) { throw new InvalidOperationException(ErrorMessages.NoControlTypeEntryFound); } var r = new Regex($@"\b{controlTypeString}\b", RegexOptions.IgnoreCase); return(!r.IsMatch(e.Name)); }
public override EvaluationCode Evaluate(IA11yElement e) { if (e == null) { throw new ArgumentException(nameof(e)); } if (e.Name == null) { throw new ArgumentException(nameof(e.Name)); } if (e.LocalizedControlType == null) { throw new ArgumentException(nameof(e.LocalizedControlType)); } var r = new Regex($@"\b{e.LocalizedControlType}\b", RegexOptions.IgnoreCase); return(r.IsMatch(e.Name) ? EvaluationCode.Error : EvaluationCode.Pass); }
private static bool IsVerticallyScrollable(IA11yElement e) { if (e == null) { throw new ArgumentException(nameof(e)); } var scrollPattern = e.GetPattern(PatternType.UIA_ScrollPatternId); if (scrollPattern == null) { return(false); } var verticalScrollPercent = scrollPattern.GetValue <double>(VerticalScrollPercentProperty); // DirectUI framework returns "NaN" instead of setting IsXXXScrollable to false in case it is not scrollable. return(scrollPattern.GetValue <bool>(VerticallyScrollableProperty) && !double.IsNaN(verticalScrollPercent)); }
private static RunResult RunRule(IRule rule, IA11yElement element) { try { return(RunRuleWorker(rule, element)); } catch (Exception ex) { if (System.Diagnostics.Debugger.IsLogging()) { System.Diagnostics.Debug.WriteLine(ex.ToString()); } return(new RunResult { RuleInfo = rule.Info, EvaluationCode = EvaluationCode.RuleExecutionError, ErrorMessage = ex.ToString() }); } // catch }
private static bool MatchExactlyOne(IA11yElement e, params Condition[] conditions) { int count = 0; foreach (var c in conditions) { if (!c.Matches(e)) { continue; } ++count; if (count > 1) { return(false); } } return(count == 1); }
public void Equals_OtherHasSameContributionCountAndHashButDifferentContent_ReturnsFalse() { FingerprintContribution fc1 = new FingerprintContribution("Name", _specialNameValue1); FingerprintContribution fc2 = new FingerprintContribution("Name", _specialNameValue2); Assert.AreEqual(fc1.GetHashCode(), fc2.GetHashCode()); IA11yElement element1 = BuildTestElement(_specialNameValue1); IA11yElement element2 = BuildTestElement(_specialNameValue2); IFingerprint fingerprint1 = new ScanResultFingerprint(element1, DefaultRule, DefaultScanStatus); IFingerprint fingerprint2 = new ScanResultFingerprint(element2, DefaultRule, DefaultScanStatus); Assert.AreEqual(fingerprint1.GetHashCode(), fingerprint2.GetHashCode()); // Ensure that these differ only in specific content Assert.AreEqual(0, fingerprint1.CompareTo(fingerprint2)); Assert.AreEqual(0, fingerprint2.CompareTo(fingerprint1)); Assert.IsFalse(fingerprint1.Equals(fingerprint2)); Assert.IsFalse(fingerprint2.Equals(fingerprint1)); }