/// <summary> /// Adds the value of the ClickablePoint property to the A11yElement's Properties dictionary /// </summary> /// <remarks> /// Requesting the clickable point property in Edge can cause a crash, /// so the clickable point property is not initially populated by <see cref="DesktopElementExtensionMethods.PopulatePropertiesAndPatternsFromCache(A11yElement)"/>. /// </remarks> private static void InitClickablePointProperty(this A11yElement a11yElement, IUIAutomationElement uiaElement) { if (a11yElement.IsEdgeElement()) { return; } int id = PropertyType.UIA_ClickablePointPropertyId; double[] clickablePoint = uiaElement.GetCurrentPropertyValue(id); if (clickablePoint == null) { return; } string name = A11yAutomation.UIAutomationObject.GetPropertyProgrammaticName(id); var prop = new A11yProperty { Id = id, Name = name, Value = new Point((int)clickablePoint[0], (int)clickablePoint[1]) }; a11yElement.Properties.Add(id, prop); }
public void BoundingRectangleCompletelyObscuresContainer_IsDialog_NotApplicable() { var e = new MockA11yElement(); var parent = new MockA11yElement(); e.BoundingRectangle = TestRect; parent.BoundingRectangle = TestRect; e.Parent = parent; Assert.IsTrue(Rule.Condition.Matches(e)); var a11yProperty = new A11yProperty(PropertyType.UIA_IsDialogPropertyId, true); e.Properties.Add(PropertyType.UIA_IsDialogPropertyId, a11yProperty); Assert.IsTrue(Rule.Condition.Matches(e)); e.ControlTypeId = ControlType.Pane; Assert.IsFalse(Rule.Condition.Matches(e)); e.Properties.Remove(PropertyType.UIA_IsDialogPropertyId); Assert.IsTrue(Rule.Condition.Matches(e)); }
public void TestBoundingRectangleDataFormatCorrectArrayTypeFaile() { using (var e = new MockA11yElement()) { var p = new A11yProperty(PropertyType.UIA_BoundingRectanglePropertyId, new int[] { 1, 2, 3, 4 }); e.Properties.Add(PropertyType.UIA_BoundingRectanglePropertyId, p); Assert.AreNotEqual(Rule.Evaluate(e), EvaluationCode.Pass); } // using }
public void TestBoundingRectangleDataFormatCorrectArrayTypeFaile() { using (var e = new MockA11yElement()) { var p = new A11yProperty(PropertyType.UIA_BoundingRectanglePropertyId, new int[] { 1, 2, 3, 4 }); e.Properties.Add(PropertyType.UIA_BoundingRectanglePropertyId, p); Assert.IsFalse(Rule.PassesTest(e)); } // using }
public void TestBoundingRectangleDataFormatCorrectPass() { using (var e = new MockA11yElement()) { var p = new A11yProperty(PropertyType.UIA_BoundingRectanglePropertyId, new double[] { 1, 2, 3, 4 }); e.Properties.Add(PropertyType.UIA_BoundingRectanglePropertyId, p); Assert.AreEqual(EvaluationCode.Pass, Rule.Evaluate(e)); } // using }
public void TestBoundingRectangleNotCorrectDataFormatFalse() { using (var e = new MockA11yElement()) { var proeprty = new A11yProperty(PropertyType.UIA_BoundingRectanglePropertyId, new double[] { 1, 2, 3, 4 }); e.Properties.Add(PropertyType.UIA_BoundingRectanglePropertyId, proeprty); Assert.IsFalse(BoundingRectangle.NotCorrectDataFormat.Matches(e)); } // using }
public void TestBoundingRectangleNotCorrectDataFormatTypeTrue() { using (var e = new MockA11yElement()) { var property = new A11yProperty(PropertyType.UIA_BoundingRectanglePropertyId, true); e.Properties.Add(PropertyType.UIA_BoundingRectanglePropertyId, property); Assert.IsTrue(BoundingRectangle.NotCorrectDataFormat.Matches(e)); } // using }
public void CreateScrubbedCopyWithoutRelationships_InputHasAllProperties_ResultHasFilteredProperties() { const int propertiesTypesBase = 30000; const int inputProperties = 200; HashSet <int> allowedProperties = new HashSet <int> { PropertyType.UIA_AcceleratorKeyPropertyId, PropertyType.UIA_AccessKeyPropertyId, PropertyType.UIA_AutomationIdPropertyId, PropertyType.UIA_BoundingRectanglePropertyId, PropertyType.UIA_ClassNamePropertyId, PropertyType.UIA_ControlTypePropertyId, PropertyType.UIA_FrameworkIdPropertyId, PropertyType.UIA_IsContentElementPropertyId, PropertyType.UIA_IsControlElementPropertyId, PropertyType.UIA_IsKeyboardFocusablePropertyId, PropertyType.UIA_LocalizedControlTypePropertyId, PropertyType.UIA_NamePropertyId, }; Dictionary <int, A11yProperty> properties = new Dictionary <int, A11yProperty>(); // This gives us a superset of all const values in the PropertyTypes class for (int loop = 0; loop < inputProperties; loop++) { int type = propertiesTypesBase + loop; properties.Add(type, new A11yProperty(type, type.ToString())); } A11yElement input = new A11yElement { Properties = properties, }; A11yElement copy = input.CreateScrubbedCopyWithoutRelationships(); Assert.AreEqual(inputProperties, input.Properties.Count); // Confirm the allowed properties foreach (KeyValuePair <int, A11yProperty> pair in copy.Properties) { A11yProperty inputProperty = input.Properties[pair.Key]; A11yProperty copyProperty = pair.Value; if (pair.Key == PropertyType.UIA_NamePropertyId) // Name is special cased and makes a copy { Assert.AreNotSame(inputProperty, copyProperty); } else { Assert.AreSame(inputProperty, copyProperty); } Assert.AreEqual(inputProperty.Id, copyProperty.Id); Assert.IsTrue(allowedProperties.Contains(pair.Key), pair.Key.ToString() + " is not allowed"); allowedProperties.Remove(pair.Key); } Assert.IsFalse(allowedProperties.Any(), allowedProperties.Count + " unexpected elements"); }
public void TestIsNotDesktopFalse() { using (var e = new MockA11yElement()) { var property = new A11yProperty(PropertyType.UIA_RuntimeIdPropertyId, new int[] { 0x2A, 0x10010 }); e.Properties.Add(property.Id, property); Assert.IsFalse(IsNotDesktop.Matches(e)); } // using }
/// <summary> /// Convert Element Value to formated string /// </summary> /// <param name="p"></param> /// <returns></returns> public static string ConvertIntArrayToString(this A11yProperty p) { if (p == null) { throw new ArgumentNullException(nameof(p)); } return(p.Value != null?ConvertIntArrayToString(p.Value) : null); }
public void IsDialog_False() { using (var e = new MockA11yElement()) { var a11yProperty = new A11yProperty(PropertyType.UIA_IsDialogPropertyId, false); e.Properties.Add(PropertyType.UIA_IsDialogPropertyId, a11yProperty); Assert.IsFalse(IsDialog.Matches(e)); } // using }
public void SimpleStyleTrue() { using (var e = new MockA11yElement()) { var p = new A11yProperty(PlatformPropertyType.Platform_WindowsStylePropertyId, 1); e.PlatformProperties.Add(PlatformPropertyType.Platform_WindowsStylePropertyId, p); Assert.IsTrue(PlatformProperties.SimpleStyle.Matches(e)); } // using }
public void SimpleCustomPropertyTest() { const int testId = 42; dynamic testValue = 1; const string expectedRendering = "1"; A11yProperty.RegisterCustomProperty(testId, new IntTypeConverter()); A11yProperty kp = new A11yProperty(testId, testValue); Assert.AreEqual(expectedRendering, kp.ToString()); }
public void RegisterTwiceCustomPropertyTest() { const int testId = 42; dynamic testValue = 1; const string expectedRendering = "1"; A11yProperty.RegisterCustomProperty(testId, new PointTypeConverter()); // First registration, should be dropped. A11yProperty.RegisterCustomProperty(testId, new IntTypeConverter()); // Second registration, last one wins. A11yProperty kp = new A11yProperty(testId, testValue); Assert.AreEqual(expectedRendering, kp.ToString()); }
/// <summary> /// Convert Element Property value to Rectangle /// </summary> /// <param name="ep"></param> /// <returns></returns> public static Rectangle ToRectangle(this A11yProperty property) { if (property == null) { return(Rectangle.Empty); } switch (property.Value) { case double[] rectangle: { if (rectangle.Length != 4) { return(Rectangle.Empty); } return(new Rectangle( x: (int)rectangle[0], y: (int)rectangle[1], width: rectangle[2] > 0 ? (int)rectangle[2] : 0, height: rectangle[3] > 0 ? (int)rectangle[3] : 0)); } case Newtonsoft.Json.Linq.JArray jArray: { if (jArray.Count != 4) { return(Rectangle.Empty); } foreach (var token in jArray) { if (token.Type != Newtonsoft.Json.Linq.JTokenType.Float) { return(Rectangle.Empty); } } int width = jArray[2].ToObject <int>(); int height = jArray[3].ToObject <int>(); return(new Rectangle( x: jArray[0].ToObject <int>(), y: jArray[1].ToObject <int>(), width: width > 0 ? width : 0, height: height > 0 ? height : 0)); } } // switch return(Rectangle.Empty); }
private void SetProperty(int id, dynamic value) { if (this.Properties.ContainsKey(id)) { this.Properties[id].Value = value; return; } var property = new A11yProperty { Id = id, Value = value }; this.Properties[id] = property; }
public void TestTextWithDisallowedPlatformProperties() { const uint WS_EX_STATICEDGE = 0x00020000; using (var e = new MockA11yElement()) { e.ControlTypeId = Text; e.Framework = FrameworkId.WinForm; Assert.IsTrue(Misc.NameRequired.Matches(e)); var prop = new A11yProperty(PlatformPropertyType.Platform_WindowsExtendedStylePropertyId, WS_EX_STATICEDGE); e.PlatformProperties.Add(PlatformPropertyType.Platform_WindowsExtendedStylePropertyId, prop); Assert.IsFalse(Misc.NameRequired.Matches(e)); e.Framework = null; Assert.IsTrue(Misc.NameRequired.Matches(e)); } // using }
/// <summary> /// Given the input element, create a scrubbed copy that has no parent or children /// </summary> /// <param name="element">The element to clone</param> /// <returns>A new element that has been scrubbed of key information and properties</returns> internal static A11yElement CreateScrubbedCopyWithoutRelationships(this A11yElement element) { A11yElement clone = new A11yElement { BugId = element.BugId, ScanResults = element.ScanResults, TreeWalkerMode = element.TreeWalkerMode, UniqueId = element.UniqueId, Children = element.Children == null ? null : new List <A11yElement>() }; if (element.Properties != null) { clone.Properties = new Dictionary <int, A11yProperty>(); foreach (var pair in element.Properties) { if (PropertiesToInclude.Contains(pair.Key)) { if (pair.Key == PropertyType.UIA_NamePropertyId) { A11yProperty scrubbedProperty = new A11yProperty(pair.Key, pair.Value.ToString().Substring(0, MaxScrubbedNameLength)); clone.Properties.Add(pair.Key, scrubbedProperty); } else { clone.Properties.Add(pair.Key, pair.Value); } } } } if (element.Glimpse != null) { clone.UpdateGlimpse(); } return(clone); }
public PropertyListViewItemModel(A11yProperty p) { this.Property = p; }
/// <summary> /// Convert Element Value to formated string /// </summary> /// <param name="p"></param> /// <returns></returns> public static string ConvertIntArrayToString(this A11yProperty p) { return(p.Value != null?ConvertIntArrayToString(p.Value) : null); }