-
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.
feat(chrome-scans): Add
ChromiumComponentsShouldUseWebScanner
rule (#…
…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
Showing
20 changed files
with
262 additions
and
21 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
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
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
31 changes: 31 additions & 0 deletions
31
src/Rules/Library/ChromiumComponentsShouldUseWebScanner.cs
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,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 |
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
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
56 changes: 56 additions & 0 deletions
56
src/RulesTest/Library/ChromiumComponentsShouldUseWebScannerTests.cs
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,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)); | ||
} | ||
} | ||
} |
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
Binary file not shown.
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,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> |
Oops, something went wrong.