-
Notifications
You must be signed in to change notification settings - Fork 38
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Separate roborazzi-accessibility-check module
- Loading branch information
Showing
14 changed files
with
216 additions
and
83 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 |
---|---|---|
@@ -0,0 +1 @@ | ||
/build |
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,44 @@ | ||
plugins { | ||
id 'com.android.library' | ||
id 'org.jetbrains.kotlin.android' | ||
} | ||
if (System.getenv("INTEGRATION_TEST") != "true") { | ||
pluginManager.apply("com.vanniktech.maven.publish") | ||
} | ||
|
||
|
||
android { | ||
namespace 'com.github.takahirom.roborazzi.accessibility.check' | ||
compileSdk 34 | ||
|
||
defaultConfig { | ||
minSdk 21 | ||
targetSdk 32 | ||
|
||
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner" | ||
} | ||
|
||
buildTypes { | ||
release { | ||
minifyEnabled false | ||
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro' | ||
} | ||
} | ||
buildFeatures { | ||
} | ||
testOptions { | ||
unitTests { | ||
includeAndroidResources = true | ||
} | ||
} | ||
} | ||
|
||
dependencies { | ||
implementation project(':roborazzi-junit-rule') | ||
implementation project(':roborazzi') | ||
implementation libs.androidx.test.ext.junit.ktx | ||
compileOnly libs.robolectric | ||
compileOnly libs.androidx.compose.ui.test | ||
compileOnly libs.androidx.compose.ui.test.junit4 | ||
api libs.accessibility.test.framework | ||
} |
Empty file.
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,21 @@ | ||
# Add project specific ProGuard rules here. | ||
# You can control the set of applied configuration files using the | ||
# proguardFiles setting in build.gradle. | ||
# | ||
# For more details, see | ||
# http://developer.android.com/guide/developing/tools/proguard.html | ||
|
||
# If your project uses WebView with JS, uncomment the following | ||
# and specify the fully qualified class name to the JavaScript interface | ||
# class: | ||
#-keepclassmembers class fqcn.of.javascript.interface.for.webview { | ||
# public *; | ||
#} | ||
|
||
# Uncomment this to preserve the line number information for | ||
# debugging stack traces. | ||
#-keepattributes SourceFile,LineNumberTable | ||
|
||
# If you keep the line number information, uncomment this to | ||
# hide the original source file name. | ||
#-renamesourcefileattribute SourceFile |
22 changes: 22 additions & 0 deletions
22
...lity-check/src/androidTest/java/com/github/takahirom/roborazzi/ExampleInstrumentedTest.kt
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,22 @@ | ||
package com.github.takahirom.roborazzi | ||
|
||
import androidx.test.ext.junit.runners.AndroidJUnit4 | ||
import androidx.test.platform.app.InstrumentationRegistry | ||
import org.junit.Assert.* | ||
import org.junit.Test | ||
import org.junit.runner.RunWith | ||
|
||
/** | ||
* Instrumented test, which will execute on an Android device. | ||
* | ||
* See [testing documentation](http://d.android.com/tools/testing). | ||
*/ | ||
@RunWith(AndroidJUnit4::class) | ||
class ExampleInstrumentedTest { | ||
@Test | ||
fun useAppContext() { | ||
// Context of the app under test. | ||
val appContext = InstrumentationRegistry.getInstrumentation().targetContext | ||
assertEquals("com.github.takahirom.roborazzi.test", appContext.packageName) | ||
} | ||
} |
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,4 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<manifest> | ||
|
||
</manifest> |
47 changes: 0 additions & 47 deletions
47
...ava/com/github/takahirom/roborazzi/ATF.kt → ...ava/com/github/takahirom/roborazzi/ATF.kt
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
81 changes: 81 additions & 0 deletions
81
...cessibility-check/src/main/java/com/github/takahirom/roborazzi/ATFAccessibilityChecker.kt
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,81 @@ | ||
package com.github.takahirom.roborazzi | ||
|
||
import android.annotation.SuppressLint | ||
import android.os.Build | ||
import androidx.compose.ui.platform.ViewRootForTest | ||
import com.github.takahirom.roborazzi.RoborazziRule.CaptureRoot | ||
import com.google.android.apps.common.testing.accessibility.framework.AccessibilityCheckResult.AccessibilityCheckResultType | ||
import com.google.android.apps.common.testing.accessibility.framework.AccessibilityHierarchyCheck | ||
import com.google.android.apps.common.testing.accessibility.framework.AccessibilityViewCheckResult | ||
import com.google.android.apps.common.testing.accessibility.framework.integrations.espresso.AccessibilityViewCheckException | ||
import org.hamcrest.Matcher | ||
import org.robolectric.shadows.ShadowBuild | ||
|
||
@ExperimentalRoborazziApi | ||
data class ATFAccessibilityChecker( | ||
val checks: Set<AccessibilityHierarchyCheck>, | ||
val suppressions: Matcher<in AccessibilityViewCheckResult>, | ||
val failureLevel: AccessibilityCheckResultType, | ||
) { | ||
@SuppressLint("VisibleForTests") | ||
fun runAccessibilityChecks( | ||
captureRoot: CaptureRoot, | ||
roborazziOptions: RoborazziOptions, | ||
) { | ||
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.UPSIDE_DOWN_CAKE) { | ||
roborazziErrorLog("Skipping accessibilityChecks on API " + Build.VERSION.SDK_INT + "(< ${Build.VERSION_CODES.UPSIDE_DOWN_CAKE})") | ||
return | ||
} | ||
// TODO remove this once ATF doesn't bail out | ||
// https://github.com/google/Accessibility-Test-Framework-for-Android/blob/c65cab02b2a845c29c3da100d6adefd345a144e3/src/main/java/com/google/android/apps/common/testing/accessibility/framework/uielement/AccessibilityHierarchyAndroid.java#L667 | ||
ShadowBuild.setFingerprint("roborazzi") | ||
|
||
if (captureRoot is CaptureRoot.Compose) { | ||
val view = | ||
(captureRoot.semanticsNodeInteraction.fetchSemanticsNode().root as ViewRootForTest).view.rootView | ||
|
||
// Will throw based on configuration | ||
val results = runAllChecks(roborazziOptions, view, captureRoot) | ||
|
||
// Report on any warnings in the log output if not failing | ||
results.forEach { check -> | ||
when (check.type) { | ||
AccessibilityCheckResultType.ERROR -> roborazziErrorLog("Error: $check") | ||
AccessibilityCheckResultType.WARNING -> roborazziErrorLog( | ||
"Warning: $check" | ||
) | ||
|
||
AccessibilityCheckResultType.INFO -> roborazziReportLog( | ||
"Info: $check" | ||
) | ||
|
||
else -> {} | ||
} | ||
} | ||
|
||
val failures = results.filter { it.type.ordinal <= failureLevel.ordinal } | ||
if (failures.isNotEmpty()) { | ||
throw AccessibilityViewCheckException(failures.toMutableList()) | ||
} | ||
|
||
// TODO handle View cases | ||
// } else if (captureRoot is CaptureRoot.View) { | ||
} | ||
} | ||
|
||
companion object | ||
} | ||
|
||
data class AccessibilityChecksValidate( | ||
val checker: ATFAccessibilityChecker | ||
) : RoborazziRule.AccessibilityChecks { | ||
override fun runAccessibilityChecks( | ||
captureRoot: CaptureRoot, | ||
roborazziOptions: RoborazziOptions | ||
) { | ||
checker.runAccessibilityChecks( | ||
captureRoot = captureRoot, | ||
roborazziOptions = roborazziOptions, | ||
) | ||
} | ||
} |
16 changes: 16 additions & 0 deletions
16
...razzi-accessibility-check/src/test/java/com/github/takahirom/roborazzi/ExampleUnitTest.kt
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,16 @@ | ||
package com.github.takahirom.roborazzi | ||
|
||
import org.junit.Assert.assertEquals | ||
import org.junit.Test | ||
|
||
/** | ||
* Example local unit test, which will execute on the development machine (host). | ||
* | ||
* See [testing documentation](http://d.android.com/tools/testing). | ||
*/ | ||
class ExampleUnitTest { | ||
@Test | ||
fun addition_isCorrect() { | ||
assertEquals(4, 2 + 2) | ||
} | ||
} |
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
Oops, something went wrong.