Skip to content

Commit

Permalink
Add chrome rule
Browse files Browse the repository at this point in the history
  • Loading branch information
sfoslund committed Jan 25, 2023
1 parent 27295d6 commit b007694
Show file tree
Hide file tree
Showing 12 changed files with 149 additions and 21 deletions.
1 change: 1 addition & 0 deletions docs/RulesDescription.md
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,7 @@ ClickablePointOnScreenWPF | Error | An element's IsOffScreen property must be fa
ClickablePointOffScreen | Warning | An element's IsOffScreen property must be true when its clickable point is off-screen. | Section 508 502.3.1 ObjectInformation
FrameworkDoesNotSupportUIAutomation | Error | The framework used to build this application does not support. | Section 508 502.3.1 ObjectInformation
EdgeBrowserHasBeenDeprecated | Error | The non-Chromium version of Microsoft Edge has been deprecated. | Section 508 502.3.1 ObjectInformation
ChromiumComponentsShouldUseWebScanner | Error | Chromium components should be scanned with a web-based scanner. | Not applicable

## Severity descriptions

Expand Down
14 changes: 13 additions & 1 deletion src/AutomationTests/AutomationIntegrationTests.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright (c) Microsoft. All rights reserved.
// 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.Automation;
Expand Down Expand Up @@ -26,12 +26,14 @@ public class AutomationIntegrationTests
const int WindowsFormsControlSamplerKnownErrorCount = 6;
const int WpfControlSamplerKnownErrorCount = 7;
const int WindowsFormsMultiWindowSamplerAppAllErrorCount = 12;
const int WebViewSampleKnownErrorCount = 35;

readonly string _wildlifeManagerAppPath = Path.GetFullPath("../../../../../tools/WildlifeManager/WildlifeManager.exe");
readonly string _win32ControlSamplerAppPath = Path.GetFullPath("../../../../../tools/Win32ControlSampler/Win32ControlSampler.exe");
readonly string _windowsFormsControlSamplerAppPath = Path.GetFullPath("../../../../../tools/WindowsFormsControlSampler/WindowsFormsControlSampler.exe");
readonly string _windowsFormsMultiWindowSamplerAppPath = Path.GetFullPath("../../../../../tools/WindowsFormsMultiWindowSample/WindowsFormsMultiWindowSample.exe");
readonly string _wpfControlSamplerAppPath = Path.GetFullPath("../../../../../tools/WpfControlSampler/WpfControlSampler.exe");
readonly string _webViewSampleAppPath = Path.GetFullPath("../../../../../tools/WebViewSample/WebViewSample.exe");

readonly string _outputDir = Path.GetFullPath("./TestOutput");
readonly string _validationAppFolder;
Expand Down Expand Up @@ -125,6 +127,16 @@ public void Scan_Integration_WpfControlSampler(bool sync)
ScanIntegrationCore(sync, _wpfControlSamplerAppPath, WpfControlSamplerKnownErrorCount);
}


[DataTestMethod]
[DataRow(true)]
[DataRow(false)]
[Timeout(60000)]
public void Scan_Integration_WebViewSample(bool sync)
{
ScanIntegrationCore(sync, _webViewSampleAppPath, WebViewSampleKnownErrorCount);
}

[TestMethod]
[Timeout(30000)]
public void ScanAsync_WindowsFormsSampler_TaskIsCancelled_ThrowsCancellationException()
Expand Down
4 changes: 2 additions & 2 deletions src/Core/Enums/FrameworkId.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@

// Copyright (c) Microsoft. All rights reserved.
// Copyright (c) Microsoft. All rights reserved.
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
namespace Axe.Windows.Core.Enums
{
Expand All @@ -8,6 +7,7 @@ public static class FrameworkId
public const string DirectUI = "DirectUI";
public const string Edge = "MicrosoftEdge";
public const string InternetExplorer = "InternetExplorer";
public const string Chrome = "Chrome";
public const string WPF = "WPF";
public const string WinForm = "WinForm";
public const string Win32 = "Win32";
Expand Down
3 changes: 2 additions & 1 deletion src/Core/Enums/RuleId.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright (c) Microsoft. All rights reserved.
// Copyright (c) Microsoft. All rights reserved.
// Licensed under the MIT license. See LICENSE file in the project root for full license information.

namespace Axe.Windows.Core.Enums
Expand Down Expand Up @@ -202,5 +202,6 @@ public enum RuleId

FrameworkDoesNotSupportUIAutomation,
EdgeBrowserHasBeenDeprecated,
ChromiumComponentsShouldUseWebScanner
}
}
31 changes: 31 additions & 0 deletions src/Rules/Library/ChromiumComponentsShouldUseWebScanner.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
// 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.Rules.Resources;
using static Axe.Windows.Rules.PropertyConditions.Framework;

namespace Axe.Windows.Rules.Library
{
[RuleInfo(ID = RuleId.ChromiumComponentsShouldUseWebScanner)]
class ChromiumComponentsShouldUseWebScanner : Rule
{
public ChromiumComponentsShouldUseWebScanner()
{
Info.Description = Descriptions.ChromiumComponentsShouldUseWebScanner;
Info.HowToFix = HowToFix.ChromiumComponentsShouldUseWebScanner;
Info.ErrorCode = EvaluationCode.Error;
}

public override bool PassesTest(IA11yElement e)
{
return false;
}

protected override Condition CreateCondition()
{
return Chrome;
}
} // class
} // namespace
1 change: 1 addition & 0 deletions src/Rules/PropertyConditions/Framework.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ static class Framework
{
public static readonly Condition DirectUI = StringProperties.Framework.Is(FrameworkId.DirectUI);
public static readonly Condition Edge = StringProperties.Framework.Is(FrameworkId.Edge);
public static readonly Condition Chrome = StringProperties.Framework.Is(FrameworkId.Chrome);
// The following name includes "Framework" to avoid clashing with the Win32 namespace
public static readonly Condition Win32Framework = StringProperties.Framework.Is(FrameworkId.Win32);
public static readonly Condition WinForms = StringProperties.Framework.Is(FrameworkId.WinForm);
Expand Down
9 changes: 9 additions & 0 deletions src/Rules/Resources/Descriptions.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 4 additions & 0 deletions src/Rules/Resources/Descriptions.resx
Original file line number Diff line number Diff line change
Expand Up @@ -520,4 +520,8 @@ HowToFix: {2}
Condition: {3}</value>
<comment>{0} is id, {1} is description, {2} is how to fix, and {3} is condition</comment>
</data>
<data name="ChromiumComponentsShouldUseWebScanner" xml:space="preserve">
<value>Chromium components should be scanned with a web-based scanner.</value>
<comment>The description of a problem with an element currently under inspection.</comment>
</data>
</root>
41 changes: 25 additions & 16 deletions src/Rules/Resources/HowToFix.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 4 additions & 0 deletions src/Rules/Resources/HowToFix.resx
Original file line number Diff line number Diff line change
Expand Up @@ -634,4 +634,8 @@ If the element's ClickablePoint property is incorrect, please ensure it returns
<value>The non-Chromium version of Edge has reached its end of life and should not be used for current product development. Please migrate your application to a supported browser.</value>
<comment>Brief guidance on how to fix an accessibility problem.</comment>
</data>
<data name="ChromiumComponentsShouldUseWebScanner" xml:space="preserve">
<value>Use a web-based scanner (for example, Accessibility Insights for Web) to scan this component.</value>
<comment>Brief guidance on how to fix a scan problem.</comment>
</data>
</root>
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
// 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 Microsoft.VisualStudio.TestTools.UnitTesting;
using Moq;

namespace Axe.Windows.RulesTests.Library
{
[TestClass]
public class ChromiumComponentsShouldUseWebScannerTests
{
private static readonly Rules.IRule Rule = new Rules.Library.ChromiumComponentsShouldUseWebScanner();
private Mock<IA11yElement> _elementMock;

[TestInitialize]
public void BeforeEach()
{
_elementMock = new Mock<IA11yElement>(MockBehavior.Strict);
}

[TestMethod]
public void Condition_FrameworkIsNotChrome_ReturnsFalse()
{
string[] nonChromeValues = { FrameworkId.DirectUI, FrameworkId.InternetExplorer, FrameworkId.WinForm, FrameworkId.WPF, FrameworkId.XAML, FrameworkId.Win32, FrameworkId.Edge, "NotChrome" };

foreach (string nonChromeValue in nonChromeValues)
{
_elementMock.Setup(m => m.Framework)
.Returns(nonChromeValue)
.Verifiable();

Assert.IsFalse(Rule.Condition.Matches(_elementMock.Object));
}

_elementMock.Verify(m => m.Framework, Times.Exactly(nonChromeValues.Length));
}

[TestMethod]
public void Condition_FrameworkIsChrome_ReturnsTrue()
{
_elementMock.Setup(m => m.Framework).Returns(FrameworkId.Chrome).Verifiable();

Assert.IsTrue(Rule.Condition.Matches(_elementMock.Object));

_elementMock.Verify(m => m.Framework, Times.Once());
}

[TestMethod]
public void PassesTest_ReturnsFalse()
{
Assert.IsFalse(Rule.PassesTest(_elementMock.Object));
}
}
}
2 changes: 1 addition & 1 deletion src/RulesTest/Library/EdgeBrowserHasBeenDeprecatedTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ public void FrameworkIssueLink_IsNotNull()
[TestMethod]
public void Condition_FrameworkIsNotEdge_ReturnsFalse()
{
string[] nonWin32Values = { FrameworkId.DirectUI, FrameworkId.InternetExplorer, FrameworkId.WinForm, FrameworkId.WPF, FrameworkId.XAML, FrameworkId.Win32, "NotEdge" };
string[] nonWin32Values = { FrameworkId.DirectUI, FrameworkId.InternetExplorer, FrameworkId.WinForm, FrameworkId.WPF, FrameworkId.XAML, FrameworkId.Win32, FrameworkId.Chrome, "NotEdge" };

foreach (string nonWin32Value in nonWin32Values)
{
Expand Down

0 comments on commit b007694

Please sign in to comment.