-
Notifications
You must be signed in to change notification settings - Fork 64
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix Issue #161 - [Feature Request] Add rule to ensure the descendants…
… of off screen elements are also off screen. (#326) The evaluation strategy is to test each element against its parent. This avoids starting with a root element and testing all its descendants. The latter would be very inefficient because the test would be re-run for each descendant of the root. Also, the chosen strategy has the added benefit of failing while on the element with the mismatched IsOffscreen property value, which means it is easier to point users to the element with the problem. This would have been much more difficult if the non matching element were a deep descendant of the element being tested.
- Loading branch information
Showing
7 changed files
with
128 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -258,5 +258,6 @@ public enum RuleId | |
|
||
ClickablePointOnScreen, | ||
ClickablePointOffScreen, | ||
IsOffScreenChild, | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
// Copyright (c) Microsoft. All rights reserved. | ||
// Licensed under the MIT license. See LICENSE file in the project root for full license information. | ||
using Axe.Windows.Core.Bases; | ||
using Axe.Windows.Core.Enums; | ||
using Axe.Windows.Core.Types; | ||
using Axe.Windows.Rules.Resources; | ||
using System; | ||
using static Axe.Windows.Rules.PropertyConditions.BoolProperties; | ||
using static Axe.Windows.Rules.PropertyConditions.Relationships; | ||
|
||
namespace Axe.Windows.Rules.Library | ||
{ | ||
[RuleInfo(ID = RuleId.IsOffScreenChild)] | ||
class IsOffScreenChild : Rule | ||
{ | ||
public IsOffScreenChild() | ||
{ | ||
this.Info.Description = Descriptions.IsOffScreenChild; | ||
this.Info.HowToFix = HowToFix.IsOffScreenChild; | ||
this.Info.Standard = A11yCriteriaId.ObjectInformation; | ||
this.Info.PropertyID = PropertyType.UIA_IsOffscreenPropertyId; | ||
} | ||
|
||
public override EvaluationCode Evaluate(IA11yElement e) | ||
{ | ||
if (e == null) throw new ArgumentNullException(nameof(e)); | ||
|
||
return Parent(IsOffScreen).Matches(e) ? EvaluationCode.Error : EvaluationCode.Pass; | ||
} | ||
|
||
protected override Condition CreateCondition() | ||
{ | ||
return ~IsOffScreen; | ||
} | ||
} // class | ||
} // namespace |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
// Copyright (c) Microsoft. All rights reserved. | ||
// Licensed under the MIT license. See LICENSE file in the project root for full license information. | ||
using System; | ||
using Microsoft.VisualStudio.TestTools.UnitTesting; | ||
using EvaluationCode = Axe.Windows.Rules.EvaluationCode; | ||
|
||
namespace Axe.Windows.RulesTest.Library | ||
{ | ||
[TestClass] | ||
public class IsOffScreenChildTests | ||
{ | ||
private static Axe.Windows.Rules.IRule Rule = new Axe.Windows.Rules.Library.IsOffScreenChild(); | ||
|
||
[TestMethod] | ||
public void IsOffScreenChild_Condition_Matches() | ||
{ | ||
using (var e = new MockA11yElement()) | ||
{ | ||
e.IsOffScreen = false; | ||
Assert.IsTrue(Rule.Condition.Matches(e)); | ||
} // using | ||
} | ||
|
||
[TestMethod] | ||
public void IsOffScreenChild_Condition_NoMatch() | ||
{ | ||
using (var e = new MockA11yElement()) | ||
{ | ||
e.IsOffScreen = true; | ||
Assert.IsFalse(Rule.Condition.Matches(e)); | ||
} // using | ||
} | ||
|
||
[TestMethod] | ||
public void IsOffScreenChild_Evaluate_Error() | ||
{ | ||
using (var e = new MockA11yElement()) | ||
using (var parent = new MockA11yElement()) | ||
{ | ||
parent.IsOffScreen = true; | ||
e.Parent = parent; | ||
Assert.AreEqual(EvaluationCode.Error, Rule.Evaluate(e)); | ||
} // using | ||
} | ||
|
||
[TestMethod] | ||
public void IsOffScreenChild_Evaluate_Pass() | ||
{ | ||
using (var e = new MockA11yElement()) | ||
using (var parent = new MockA11yElement()) | ||
{ | ||
parent.IsOffScreen = false; | ||
e.Parent = parent; | ||
Assert.AreEqual(EvaluationCode.Pass, Rule.Evaluate(e)); | ||
} // using | ||
} | ||
|
||
[TestMethod] | ||
public void IsOffScreenChild_Evaluate_ThrowsArgumentNullException() | ||
{ | ||
var ex = Assert.ThrowsException<ArgumentNullException>(() => Rule.Evaluate(null)); | ||
Assert.AreEqual("e", ex.ParamName); | ||
} | ||
} // class | ||
} // namespace |