Skip to content

Commit

Permalink
feat(chrome-scans): Add ChromiumComponentsShouldUseWebScanner rule (#…
Browse files Browse the repository at this point in the history
…871)

#### Details

This PR is 1/2 of addressing
#836. It includes the
following commits/changes, which can be reviewed separately:

-
27295d6
adds a new sample project to the tools repo that uses a minimal
webview2.
-
b007694
adds the `ChromiumComponentsShouldUseWebScanner` rule and a new e2e test
leveraging the new web view sample added in this PR.

##### Motivation

Addresses issue #836

##### Context

This PR only adds the new rule logic but does not do the work to
suppress any further errors in descendants of the root "Chrome" element
(hence why there are 35 expected errors in the end to end test instead
of just 1). A future PR will add the suppression logic separately.

#### Pull request checklist
<!-- If a checklist item is not applicable to this change, write "n/a"
in the checkbox -->
- [x] Addresses an existing issue:
[#0000](#836)
  • Loading branch information
sfoslund committed Jan 27, 2023
1 parent 7bbff33 commit f83d5e7
Show file tree
Hide file tree
Showing 20 changed files with 262 additions and 21 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -329,3 +329,6 @@ ASALocalRun/

# MFractors (Xamarin productivity tool) working folder
.mfractor/

# Tools webview run output
tools/WebViewSample/WebViewSample.exe.WebView2
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
15 changes: 14 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,15 @@ public class AutomationIntegrationTests
const int WindowsFormsControlSamplerKnownErrorCount = 6;
const int WpfControlSamplerKnownErrorCount = 7;
const int WindowsFormsMultiWindowSamplerAppAllErrorCount = 12;
// Note: This will be reduced to 1 when we add logic to ignore all but the top level chrome element
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 +128,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
Binary file added tools/WebViewSample/WebViewSample.exe
Binary file not shown.
12 changes: 12 additions & 0 deletions tools/WebViewSample/src/App.xaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<!-- Copyright (c) Microsoft. All rights reserved.
Licensed under the MIT license. See LICENSE file in the project root for full license information.-->

<Application x:Class="WebViewSample.App"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="clr-namespace:WebViewSample"
StartupUri="MainWindow.xaml">
<Application.Resources>

</Application.Resources>
</Application>

0 comments on commit f83d5e7

Please sign in to comment.