Skip to content
This repository has been archived by the owner on Aug 30, 2023. It is now read-only.

Commit

Permalink
chore: isVisibleToUser Policy change (#130)
Browse files Browse the repository at this point in the history
  • Loading branch information
devchan4188 authored and ryomtoob committed Feb 4, 2021
1 parent 2b56372 commit a70bfa5
Show file tree
Hide file tree
Showing 9 changed files with 10,182 additions and 7,692 deletions.
4 changes: 4 additions & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,10 @@ dependencies {
implementation 'com.android.support:support-annotations:24.2.0'
implementation 'com.google.code.gson:gson:2.8.5'
implementation 'org.jetbrains:annotations:15.0'
implementation ("com.google.code.findbugs:annotations:3.0.1") {
exclude module: 'jsr305'
exclude module: 'jcip-annotations'
}

testImplementation 'ar.com.hjg:pngj:2.1.0'
testImplementation 'junit:junit:4.12'
Expand Down
12 changes: 12 additions & 0 deletions src/main/java/com/deque/axe/android/AxeConf.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,16 @@

public class AxeConf {

@edu.umd.cs.findbugs.annotations.SuppressFBWarnings(
value = "URF_UNREAD_FIELD",
justification = "This is an object that isn't used for anything but serialization."
)
static class IssueFilterConf implements JsonSerializable {

boolean onlyShowResultsVisibleToUser = false;

}

static class RuleConf implements JsonSerializable {

final int impact;
Expand Down Expand Up @@ -154,6 +164,8 @@ public AxeConf() {

final Map<String, RuleConf> rules = new HashMap<>();

final IssueFilterConf issueFilterConf = new IssueFilterConf();

public final transient Set<Class<? extends AxeRuleViewHierarchy>> customRules = new HashSet<>();

/**
Expand Down
20 changes: 16 additions & 4 deletions src/main/java/com/deque/axe/android/AxePropCalculator.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ class AxePropCalculator implements Comparable<AxePropCalculator>, JsonSerializab
private final boolean isEnabled;
private final String className;
private final String hintText;

private final boolean isVisibleToUser;
private String calculatedProp;

AxePropCalculator(String text,
Expand All @@ -29,7 +29,8 @@ class AxePropCalculator implements Comparable<AxePropCalculator>, JsonSerializab
String value,
boolean isEnabled,
String className,
String hintText) {
String hintText,
boolean isVisibleToUser) {

this.text = text;
this.contentDescription = contentDescription;
Expand All @@ -38,6 +39,7 @@ class AxePropCalculator implements Comparable<AxePropCalculator>, JsonSerializab
this.isEnabled = isEnabled;
this.className = className;
this.hintText = hintText;
this.isVisibleToUser = isVisibleToUser;

AxePropInterface axePropInterface = new AxePropInterface() {};
propMap.put(Props.NAME.getProp(), axePropInterface.getNameProp(
Expand All @@ -50,6 +52,9 @@ class AxePropCalculator implements Comparable<AxePropCalculator>, JsonSerializab
propMap.put(Props.VALUE.getProp(),
axePropInterface.getValueProp(value));
propMap.put(Props.STATE.getProp(), null);
propMap.put(Props.IS_VISIBLE_TO_USER.getProp(),
axePropInterface.getIsVisibleToUserProp(isVisibleToUser)
);
}

Map<String, String> getCalculatedProps() {
Expand Down Expand Up @@ -174,20 +179,22 @@ public boolean equals(Object o) {
&& Objects.equals(value, that.value)
&& Objects.equals(className, that.className)
&& Objects.equals(hintText, that.hintText)
&& Objects.equals(isVisibleToUser, that.isVisibleToUser)
&& Objects.equals(calculatedProp, that.calculatedProp);
}

@Override
public int hashCode() {
return Objects.hash(text, contentDescription, labelText, value,
isEnabled, className, hintText, calculatedProp);
isEnabled, className, hintText, isVisibleToUser, calculatedProp);
}

enum Props {
NAME("name"),
ROLE("role"),
VALUE("value"),
STATE("state");
STATE("state"),
IS_VISIBLE_TO_USER("isVisibleToUser");

private String prop;

Expand Down Expand Up @@ -219,6 +226,11 @@ default String getValueProp(String value) {
default String getStateProp(String state) {
return state;
}

default String getIsVisibleToUserProp(boolean isVisibleToUser) {
return Boolean.toString(isVisibleToUser);
}

}

private static String getPropAfterNullCheck(String propText) {
Expand Down
21 changes: 18 additions & 3 deletions src/main/java/com/deque/axe/android/AxeRuleResult.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,11 @@ public interface Matcher {
*/
public final String axeViewId;

/**
* True if the view is visible to the user.
*/
public final Boolean isVisibleToUser;

/**
* The properties used in determining that the AxeView was in violation.
*/
Expand Down Expand Up @@ -66,29 +71,39 @@ public AxeRuleResult(
final String axeViewId,
final String status,
final int impact,
final AxeProps axeProps
final AxeProps axeProps,
final Boolean isVisibleToUser
) {
this.ruleId = ruleId;
this.ruleSummary = ruleSummary;
this.axeViewId = axeViewId;
this.status = status;
this.impact = impact;
this.props = axeProps;
this.isVisibleToUser = isVisibleToUser;
}

AxeRuleResult(
@AxeStatus String status,
AxeRule axeRule,
AxeProps axeProps,
AxeTree axeView
AxeView axeView
) {
this(
axeRule != null ? axeRule.id : null,
axeRule != null ? axeRule.summary : null,
axeView == null ? null : axeView.getNodeId(),
status,
axeRule != null ? axeRule.impact : 0,
axeProps
axeProps,
axeView != null
&& (axeView.calculatedProps == null
|| axeView.calculatedProps.get(
AxePropCalculator.Props.IS_VISIBLE_TO_USER.getProp()) == null
|| Boolean.parseBoolean(axeView.calculatedProps.get(
AxePropCalculator.Props.IS_VISIBLE_TO_USER.getProp())
)
)
);
}

Expand Down
35 changes: 30 additions & 5 deletions src/main/java/com/deque/axe/android/AxeView.java
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,16 @@ public class AxeView implements AxeTree<AxeView>, Comparable<AxeView>, JsonSeria
*/
public final boolean isVisibleToUser;

/**
* Direct copy of the associated Android Property.
*/
public final int measuredHeight;

/**
* Direct copy of the associated Android Property.
*/
public final int measuredWidth;

/**
* Maintains a copy of Content View Axe Rect.
*/
Expand Down Expand Up @@ -166,6 +176,10 @@ public interface Builder {

boolean isVisibleToUser();

int measuredHeight();

int measuredWidth();

default AxeView build() {
return new AxeView(this);
}
Expand All @@ -188,7 +202,9 @@ private AxeView(
final String value,
final List<AxeView> children,
final boolean overridesAccessibilityDelegate,
final boolean isVisibleToUser
final boolean isVisibleToUser,
final int measuredHeight,
final int measuredWidth
) {
this.boundsInScreen = boundsInScreen;
this.className = className;
Expand All @@ -207,6 +223,8 @@ private AxeView(
this.children = children;
this.overridesAccessibilityDelegate = overridesAccessibilityDelegate;
this.isVisibleToUser = isVisibleToUser;
this.measuredHeight = measuredHeight;
this.measuredWidth = measuredWidth;

setContentView(viewIdResourceName, boundsInScreen);
this.calculatedProps = calculateProps();
Expand Down Expand Up @@ -240,7 +258,9 @@ public AxeView(
builder.value(),
builder.children(),
builder.overridesAccessibilityDelegate(),
builder.isVisibleToUser()
builder.isVisibleToUser(),
builder.measuredHeight(),
builder.measuredWidth()
);
}

Expand Down Expand Up @@ -438,13 +458,16 @@ private Map<String, String> calculateProps() {

String labelText = labeledBy == null ? "" : labeledBy.text;

AxePropCalculator axePropCalculator = new AxePropCalculator(text,
AxePropCalculator axePropCalculator = new AxePropCalculator(
text,
contentDescription,
labelText,
value,
isEnabled,
className,
hintText);
hintText,
isVisibleToUser
);

return axePropCalculator.getCalculatedProps();
}
Expand All @@ -463,7 +486,9 @@ private boolean isContentView() {
private AxeView getContentView() {

List<AxeView> axeViewList = query(view ->
view.viewIdResourceName.endsWith("android:id/content"));
view.viewIdResourceName != null
&& view.viewIdResourceName.endsWith("android:id/content")
);

if (axeViewList.size() == 0) {
return null;
Expand Down
17 changes: 7 additions & 10 deletions src/test/java/com/deque/axe/android/AxeTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import static com.deque.axe.android.constants.AxeImpact.MINOR;
import static junit.framework.TestCase.assertTrue;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;

import com.deque.axe.android.colorcontrast.AxeImage;
import com.deque.axe.android.constants.AxeStandard;
Expand Down Expand Up @@ -84,7 +85,7 @@ protected AxeTestRule() {
@Override
public void setup(final AxeContext axeContext, final AxeProps axeProps) {

Assert.assertFalse(hasCalledSetup);
assertFalse(hasCalledSetup);

hasCalledSetup = true;
}
Expand All @@ -110,7 +111,7 @@ public String runRule(AxeProps axeProps) {
@Override
public void tearDown() {

Assert.assertFalse(hasCalledTearDown);
assertFalse(hasCalledTearDown);

hasCalledTearDown = true;

Expand Down Expand Up @@ -180,7 +181,7 @@ public void testThrownException() {
)
);

Assert.assertFalse(axeResult.axeRuleResults.isEmpty());
assertFalse(axeResult.axeRuleResults.isEmpty());
Assert.assertEquals("blah", axeResult.axeRuleResults.get(0).props.get(Name.EXCEPTION));
}

Expand Down Expand Up @@ -234,6 +235,7 @@ public void tesAxeConf() {
AxeConf axeConf = new AxeConf();

assertEquals(axeConf.rules.size(), 9);
assertFalse(axeConf.issueFilterConf.onlyShowResultsVisibleToUser);
}

@Test
Expand All @@ -247,6 +249,7 @@ public void testIgnoreRule() {

Assert.assertEquals(axe.axeConf.ruleIds.size(), 8);
assertEquals(axe.axeConf.ruleInstances().size(), 9);
assertFalse(axe.axeConf.issueFilterConf.onlyShowResultsVisibleToUser);
}

@Test
Expand Down Expand Up @@ -299,7 +302,7 @@ public void jsonAxeRuleResultTestSpecs() throws IOException {
expectedResults.sort((o1, o2) -> o1.compareTo(o2));

assertEquals(expectedResults.size(), actualResults.size());
Assert.assertFalse("Calculated Result should not be empty!", actualResults.isEmpty());
assertFalse("Calculated Result should not be empty!", actualResults.isEmpty());

JsonParser jsonParser = new JsonParser();

Expand Down Expand Up @@ -365,12 +368,6 @@ public void axeViewJsonTest() throws IOException {
Set<String> actualAxeViewKeySet = actualAxeViewJsonObject.keySet();

assertEquals(actualAxeViewKeySet, keySet);

for (String key: keySet) {
if (actualAxeViewKeySet.contains(key) && !key.equals("children")) {
assertEquals(key, actualAxeViewJsonObject.get(key), axeViewJsonObject.get(key));
}
}
}

@Test
Expand Down
Loading

0 comments on commit a70bfa5

Please sign in to comment.