-
Notifications
You must be signed in to change notification settings - Fork 29.8k
[WIP] Semantics integration test for Android #19005
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Closed
Closed
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
1d69291
initial work on android integration testing and new finders for seman…
jonahwilliams 93e9952
update semantics data matcher to only require boolean fields, update …
jonahwilliams 60da7f9
add missing licenses and more semantics test cases, clean up matcher
jonahwilliams c8825f9
Merge branch 'master' of https://github.com/flutter/flutter into andr…
jonahwilliams 40e25aa
merge with upstream
10737e1
undo accidental merge change
b17d12a
undo accidental merge change
47f8445
merge with upstream
jonahwilliams c73f4fb
more merging
jonahwilliams 41aba47
merge with origin
jonahwilliams File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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,3 @@ | ||
| # semantics | ||
|
|
||
| Integration test of platform semantics. |
This file contains hidden or 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 @@ | ||
| def localProperties = new Properties() | ||
| def localPropertiesFile = rootProject.file('local.properties') | ||
| if (localPropertiesFile.exists()) { | ||
| localPropertiesFile.withInputStream { stream -> | ||
| localProperties.load(stream) | ||
| } | ||
| } | ||
|
|
||
| def flutterRoot = localProperties.getProperty('flutter.sdk') | ||
| if (flutterRoot == null) { | ||
| throw new GradleException("Flutter SDK not found. Define location with flutter.sdk in the local.properties file.") | ||
| } | ||
|
|
||
| apply plugin: 'com.android.application' | ||
| apply from: "$flutterRoot/packages/flutter_tools/gradle/flutter.gradle" | ||
|
|
||
| android { | ||
| compileSdkVersion 27 | ||
|
|
||
| lintOptions { | ||
| disable 'InvalidPackage' | ||
| } | ||
|
|
||
| defaultConfig { | ||
| applicationId "com.yourcompany.semantics" | ||
| minSdkVersion 16 | ||
| targetSdkVersion 27 | ||
| versionCode 1 | ||
| versionName "1.0" | ||
| testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner" | ||
| } | ||
|
|
||
| buildTypes { | ||
| release { | ||
| signingConfig signingConfigs.debug | ||
| } | ||
| } | ||
|
|
||
| aaptOptions { | ||
| // TODO(goderbauer): remove when https://github.com/flutter/flutter/issues/8986 is resolved. | ||
| if(System.getenv("FLUTTER_CI_WIN")) { | ||
| println "AAPT cruncher disabled when running on Win CI." | ||
| cruncherEnabled false | ||
| } | ||
| } | ||
| } | ||
|
|
||
| flutter { | ||
| source '../..' | ||
| } | ||
|
|
||
| dependencies { | ||
| testImplementation 'junit:junit:4.12' | ||
| androidTestImplementation 'com.android.support.test:runner:1.0.2' | ||
| androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2' | ||
| } |
21 changes: 21 additions & 0 deletions
21
dev/integration_tests/semantics/android/app/src/main/AndroidManifest.xml
This file contains hidden or 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 @@ | ||
| <manifest xmlns:android="http://schemas.android.com/apk/res/android" | ||
| package="com.yourcompany.semantics"> | ||
|
|
||
| <uses-permission android:name="android.permission.INTERNET"/> | ||
|
|
||
| <application | ||
| android:name="io.flutter.app.FlutterApplication" | ||
| android:label="SemanticsIntegrationTest"> | ||
| <activity | ||
| android:name=".MainActivity" | ||
| android:launchMode="singleTop" | ||
| android:configChanges="orientation|keyboardHidden|keyboard|screenSize|locale|layoutDirection|fontScale|screenLayout|density" | ||
| android:hardwareAccelerated="true" | ||
| android:windowSoftInputMode="adjustResize"> | ||
| <intent-filter> | ||
| <action android:name="android.intent.action.MAIN"/> | ||
| <category android:name="android.intent.category.LAUNCHER"/> | ||
| </intent-filter> | ||
| </activity> | ||
| </application> | ||
| </manifest> |
108 changes: 108 additions & 0 deletions
108
...ion_tests/semantics/android/app/src/main/java/com/yourcompany/semantics/MainActivity.java
This file contains hidden or 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,108 @@ | ||
| package com.yourcompany.semantics; | ||
|
|
||
| import java.util.HashMap; | ||
| import java.util.Map; | ||
| import java.util.List; | ||
| import java.util.ArrayList; | ||
| import java.lang.StringBuilder; | ||
| import android.graphics.Rect; | ||
| import android.os.Bundle; | ||
| import android.util.DisplayMetrics; | ||
| import android.view.WindowManager; | ||
| import android.content.Context; | ||
|
|
||
| import io.flutter.app.FlutterActivity; | ||
| import io.flutter.plugin.common.MethodCall; | ||
| import io.flutter.plugin.common.MethodChannel; | ||
| import io.flutter.plugin.common.MethodChannel.MethodCallHandler; | ||
| import io.flutter.plugins.GeneratedPluginRegistrant; | ||
| import io.flutter.view.FlutterView; | ||
|
|
||
| import android.view.accessibility.AccessibilityManager; | ||
| import android.view.accessibility.AccessibilityNodeProvider; | ||
| import android.view.accessibility.AccessibilityNodeInfo; | ||
|
|
||
| public class MainActivity extends FlutterActivity { | ||
|
|
||
| @Override | ||
| protected void onCreate(Bundle savedInstanceState) { | ||
| super.onCreate(savedInstanceState); | ||
| GeneratedPluginRegistrant.registerWith(this); | ||
| new MethodChannel(getFlutterView(), "semantics").setMethodCallHandler(new SemanticsTesterMethodHandler()); | ||
| } | ||
|
|
||
|
|
||
| class SemanticsTesterMethodHandler implements MethodCallHandler { | ||
| Float mScreenDensity = 1.0f; | ||
|
|
||
| @Override | ||
| public void onMethodCall(MethodCall methodCall, MethodChannel.Result result) { | ||
| FlutterView flutterView = getFlutterView(); | ||
| AccessibilityNodeProvider provider = flutterView.getAccessibilityNodeProvider(); | ||
| DisplayMetrics displayMetrics = new DisplayMetrics(); | ||
| WindowManager wm = (WindowManager) getApplicationContext().getSystemService(Context.WINDOW_SERVICE); | ||
| wm.getDefaultDisplay().getMetrics(displayMetrics); | ||
| mScreenDensity = displayMetrics.density; | ||
|
|
||
| if (methodCall.method.equals("getSemanticsNode")) { | ||
| Map<String, Object> data = methodCall.arguments(); | ||
| @SuppressWarnings("unchecked") | ||
| Integer id = (Integer) data.get("id"); | ||
| if (id == null) { | ||
| result.error("No ID provided", "", null); | ||
| return; | ||
| } | ||
| if (provider == null) { | ||
| result.error("Semantics not enabled", "", null); | ||
| return; | ||
| } | ||
| AccessibilityNodeInfo node = provider.createAccessibilityNodeInfo(id); | ||
| result.success(convertSemantics(node, id)); | ||
| return; | ||
| } | ||
| result.notImplemented(); | ||
| } | ||
|
|
||
| @SuppressWarnings("unchecked") | ||
| private Map<String, Object> convertSemantics(AccessibilityNodeInfo node, int id) { | ||
| if (node == null) | ||
| return null; | ||
| Map<String, Object> result = new HashMap<>(); | ||
| Map<String, Object> flags = new HashMap<>(); | ||
| Map<String, Object> rect = new HashMap<>(); | ||
| result.put("id", id); | ||
| result.put("text", node.getText()); | ||
| flags.put("isChecked", node.isChecked()); | ||
| flags.put("isCheckable", node.isCheckable()); | ||
| flags.put("isDismissable", node.isDismissable()); | ||
| flags.put("isEditable", node.isEditable()); | ||
| flags.put("isEnabled", node.isEnabled()); | ||
| flags.put("isFocusable", node.isFocusable()); | ||
| flags.put("isFocused", node.isFocused()); | ||
| flags.put("isPassword", node.isPassword()); | ||
| flags.put("isLongClickable", node.isLongClickable()); | ||
| result.put("flags", flags); | ||
| Rect nodeRect = new Rect(); | ||
| node.getBoundsInScreen(nodeRect); | ||
| rect.put("left", nodeRect.left / mScreenDensity); | ||
| rect.put("top", nodeRect.top/ mScreenDensity); | ||
| rect.put("right", nodeRect.right / mScreenDensity); | ||
| rect.put("bottom", nodeRect.bottom/ mScreenDensity); | ||
| rect.put("width", nodeRect.width()); | ||
| rect.put("height", nodeRect.height()); | ||
| result.put("rect", rect); | ||
| result.put("className", node.getClassName()); | ||
| result.put("contentDescription", node.getContentDescription()); | ||
| result.put("liveRegion", node.getLiveRegion()); | ||
| List<AccessibilityNodeInfo.AccessibilityAction> actionList = node.getActionList(); | ||
| if (actionList.size() > 0) { | ||
| ArrayList<Integer> actions = new ArrayList<>(); | ||
| for (AccessibilityNodeInfo.AccessibilityAction action : actionList) { | ||
| actions.add(action.getId()); | ||
| } | ||
| result.put("actions", actions); | ||
| } | ||
| return result; | ||
| } | ||
| } | ||
| } | ||
This file contains hidden or 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,29 @@ | ||
| buildscript { | ||
| repositories { | ||
| google() | ||
| jcenter() | ||
| } | ||
|
|
||
| dependencies { | ||
| classpath 'com.android.tools.build:gradle:3.1.2' | ||
| } | ||
| } | ||
|
|
||
| allprojects { | ||
| repositories { | ||
| google() | ||
| jcenter() | ||
| } | ||
| } | ||
|
|
||
| rootProject.buildDir = '../build' | ||
| subprojects { | ||
| project.buildDir = "${rootProject.buildDir}/${project.name}" | ||
| } | ||
| subprojects { | ||
| project.evaluationDependsOn(':app') | ||
| } | ||
|
|
||
| task clean(type: Delete) { | ||
| delete rootProject.buildDir | ||
| } |
This file contains hidden or 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 @@ | ||
| org.gradle.jvmargs=-Xmx1536M |
6 changes: 6 additions & 0 deletions
6
dev/integration_tests/semantics/android/gradle/wrapper/gradle-wrapper.properties
This file contains hidden or 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,6 @@ | ||
| #Fri Jun 23 08:50:38 CEST 2017 | ||
| distributionBase=GRADLE_USER_HOME | ||
| distributionPath=wrapper/dists | ||
| zipStoreBase=GRADLE_USER_HOME | ||
| zipStorePath=wrapper/dists | ||
| distributionUrl=https\://services.gradle.org/distributions/gradle-4.4-all.zip |
This file contains hidden or 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,15 @@ | ||
| include ':app' | ||
|
|
||
| def flutterProjectRoot = rootProject.projectDir.parentFile.toPath() | ||
|
|
||
| def plugins = new Properties() | ||
| def pluginsFile = new File(flutterProjectRoot.toFile(), '.flutter-plugins') | ||
| if (pluginsFile.exists()) { | ||
| pluginsFile.withInputStream { stream -> plugins.load(stream) } | ||
| } | ||
|
|
||
| plugins.each { name, path -> | ||
| def pluginDirectory = flutterProjectRoot.resolve(path).resolve('android').toFile() | ||
| include ":$name" | ||
| project(":$name").projectDir = pluginDirectory | ||
| } |
26 changes: 26 additions & 0 deletions
26
dev/integration_tests/semantics/ios/Flutter/AppFrameworkInfo.plist
This file contains hidden or 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,26 @@ | ||
| <?xml version="1.0" encoding="UTF-8"?> | ||
| <!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd"> | ||
| <plist version="1.0"> | ||
| <dict> | ||
| <key>CFBundleDevelopmentRegion</key> | ||
| <string>en</string> | ||
| <key>CFBundleExecutable</key> | ||
| <string>App</string> | ||
| <key>CFBundleIdentifier</key> | ||
| <string>io.flutter.flutter.app</string> | ||
| <key>CFBundleInfoDictionaryVersion</key> | ||
| <string>6.0</string> | ||
| <key>CFBundleName</key> | ||
| <string>App</string> | ||
| <key>CFBundlePackageType</key> | ||
| <string>FMWK</string> | ||
| <key>CFBundleShortVersionString</key> | ||
| <string>1.0</string> | ||
| <key>CFBundleSignature</key> | ||
| <string>????</string> | ||
| <key>CFBundleVersion</key> | ||
| <string>1.0</string> | ||
| <key>MinimumOSVersion</key> | ||
| <string>8.0</string> | ||
| </dict> | ||
| </plist> |
This file contains hidden or 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 @@ | ||
| #include "Generated.xcconfig" |
This file contains hidden or 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 @@ | ||
| #include "Generated.xcconfig" |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why do we need to correct these values with the density?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is just so the rects will be in the same space as the rects on the SemanticsData. So you could check that a checkbox is 48 by 48