diff --git a/dev/integration_tests/android_views/.metadata b/dev/integration_tests/android_views/.metadata new file mode 100644 index 0000000000..eb51b7a8e3 --- /dev/null +++ b/dev/integration_tests/android_views/.metadata @@ -0,0 +1,8 @@ +# This file tracks properties of this Flutter project. +# Used by Flutter tool to assess capabilities and perform upgrades etc. +# +# This file should be version controlled and should not be manually edited. + +version: + revision: 19aa6f8de8c34af7e62f4791393a98d7decf1b65 + channel: unknown diff --git a/dev/integration_tests/android_views/README.md b/dev/integration_tests/android_views/README.md new file mode 100644 index 0000000000..11c0525670 --- /dev/null +++ b/dev/integration_tests/android_views/README.md @@ -0,0 +1,32 @@ +# Integration test for touch events on embedded Android views + +This test verifies that the synthesized motion events that get to embedded +Android view are equal to the motion events that originally hit the FlutterView. + +The test app's Android code listens to MotionEvents that get to FlutterView and +to an embedded Android view and sends them over a platform channel to the Dart +code, where the events are matched. + +This is what the app looks like: + +![android_views test app](https://flutter.github.io/assets-for-api-docs/assets/readme-assets/android_views_test.png) + +The blue part is the embedded Android view, because it is positioned at the top +left corner, the coordinate systems for FlutterView and for the embedded view's +virtual display has the same origin (this makes the MotionEvent comparison +easier as we don't need to translate the coordinates). + +The app includes the following control buttons: + * RECORD - Start listening for MotionEvents for 3 seconds, matched/unmatched events are + displayed in the listview as they arrive. + * CLEAR - Clears the events that were recorded so far. + * SAVE - Saves the events that hit FlutterView to a file. + * PLAY FILE - Send a list of events from a bundled asset file to FlutterView. + +A recorded touch events sequence is bundled as an asset in the +assets_for_android_view package which lives in the goldens repository. + +When running this test with `flutter drive` the record touch sequences is +replayed and the test asserts that the events that got to FlutterView are +equivalent to the ones that got to the embedded view. + diff --git a/dev/integration_tests/android_views/android/app/build.gradle b/dev/integration_tests/android_views/android/app/build.gradle new file mode 100644 index 0000000000..763b8b92f4 --- /dev/null +++ b/dev/integration_tests/android_views/android/app/build.gradle @@ -0,0 +1,61 @@ +def localProperties = new Properties() +def localPropertiesFile = rootProject.file('local.properties') +if (localPropertiesFile.exists()) { + localPropertiesFile.withReader('UTF-8') { reader -> + localProperties.load(reader) + } +} + +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.") +} + +def flutterVersionCode = localProperties.getProperty('flutter.versionCode') +if (flutterVersionCode == null) { + throw new GradleException("versionCode not found. Define flutter.versionCode in the local.properties file.") +} + +def flutterVersionName = localProperties.getProperty('flutter.versionName') +if (flutterVersionName == null) { + throw new GradleException("versionName not found. Define flutter.versionName 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 { + // TODO: Specify your own unique Application ID (https://developer.android.com/studio/build/application-id.html). + applicationId "io.flutter.integration.androidviews" + minSdkVersion 16 + targetSdkVersion 27 + versionCode flutterVersionCode.toInteger() + versionName flutterVersionName + testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner" + } + + buildTypes { + release { + // TODO: Add your own signing config for the release build. + // Signing with the debug keys for now, so `flutter run --release` works. + signingConfig signingConfigs.debug + } + } +} + +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' +} diff --git a/dev/integration_tests/android_views/android/app/src/main/AndroidManifest.xml b/dev/integration_tests/android_views/android/app/src/main/AndroidManifest.xml new file mode 100644 index 0000000000..a98823d2a6 --- /dev/null +++ b/dev/integration_tests/android_views/android/app/src/main/AndroidManifest.xml @@ -0,0 +1,25 @@ + + + + + + + + + + + + + + + diff --git a/dev/integration_tests/android_views/android/app/src/main/java/io/flutter/integration/androidviews/MainActivity.java b/dev/integration_tests/android_views/android/app/src/main/java/io/flutter/integration/androidviews/MainActivity.java new file mode 100644 index 0000000000..397dda9b1b --- /dev/null +++ b/dev/integration_tests/android_views/android/app/src/main/java/io/flutter/integration/androidviews/MainActivity.java @@ -0,0 +1,104 @@ +// Copyright 2018 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +package io.flutter.integration.androidviews; + +import android.Manifest; +import android.content.pm.PackageManager; +import android.os.Build; +import android.os.Bundle; +import android.view.MotionEvent; + +import java.util.HashMap; + +import io.flutter.app.FlutterActivity; +import io.flutter.plugin.common.MethodCall; +import io.flutter.plugin.common.MethodChannel; +import io.flutter.plugins.GeneratedPluginRegistrant; + +public class MainActivity extends FlutterActivity implements MethodChannel.MethodCallHandler { + final static int STORAGE_PERMISSION_CODE = 1; + + MethodChannel mMethodChannel; + TouchPipe mFlutterViewTouchPipe; + + // The method result to complete with the Android permission request result. + // This is null when not waiting for the Android permission request; + private MethodChannel.Result permissionResult; + + @Override + protected void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + GeneratedPluginRegistrant.registerWith(this); + getFlutterView().getPluginRegistry() + .registrarFor("io.flutter.integration.android_views").platformViewRegistry() + .registerViewFactory("simple_view", new SimpleViewFactory(getFlutterView())); + mMethodChannel = new MethodChannel(this.getFlutterView(), "android_views_integration"); + mMethodChannel.setMethodCallHandler(this); + mFlutterViewTouchPipe = new TouchPipe(mMethodChannel, getFlutterView()); + } + + @Override + public void onMethodCall(MethodCall methodCall, MethodChannel.Result result) { + switch(methodCall.method) { + case "pipeFlutterViewEvents": + mFlutterViewTouchPipe.enable(); + result.success(null); + return; + case "stopFlutterViewEvents": + mFlutterViewTouchPipe.disable(); + result.success(null); + return; + case "getStoragePermission": + if (permissionResult != null) { + result.error("error", "already waiting for permissions", null); + return; + } + permissionResult = result; + getExternalStoragePermissions(); + return; + case "synthesizeEvent": + synthesizeEvent(methodCall, result); + return; + } + result.notImplemented(); + } + + @SuppressWarnings("unchecked") + public void synthesizeEvent(MethodCall methodCall, MethodChannel.Result result) { + MotionEvent event = MotionEventCodec.decode((HashMap) methodCall.arguments()); + getFlutterView().dispatchTouchEvent(event); + result.success(null); + } + + @Override + public void onRequestPermissionsResult(int requestCode, String[] permissions, int[] grantResults) { + if (requestCode != STORAGE_PERMISSION_CODE || permissionResult == null) + return; + boolean permisisonGranted = grantResults.length > 0 && grantResults[0] == PackageManager.PERMISSION_GRANTED; + sendPermissionResult(permisisonGranted); + } + + + private void getExternalStoragePermissions() { + if (Build.VERSION.SDK_INT < Build.VERSION_CODES.M) + return; + + if (checkSelfPermission(Manifest.permission.WRITE_EXTERNAL_STORAGE) + == PackageManager.PERMISSION_GRANTED) { + sendPermissionResult(true); + return; + } + + requestPermissions(new String[]{Manifest.permission.WRITE_EXTERNAL_STORAGE}, STORAGE_PERMISSION_CODE); + } + + private void sendPermissionResult(boolean result) { + if (permissionResult == null) + return; + permissionResult.success(result); + permissionResult = null; + } +} + diff --git a/dev/integration_tests/android_views/android/app/src/main/java/io/flutter/integration/androidviews/MotionEventCodec.java b/dev/integration_tests/android_views/android/app/src/main/java/io/flutter/integration/androidviews/MotionEventCodec.java new file mode 100644 index 0000000000..1bd1f03a0d --- /dev/null +++ b/dev/integration_tests/android_views/android/app/src/main/java/io/flutter/integration/androidviews/MotionEventCodec.java @@ -0,0 +1,125 @@ +// Copyright 2018 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +package io.flutter.integration.androidviews; + +import android.annotation.TargetApi; +import android.os.Build; +import android.view.MotionEvent; + +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; + +import static android.view.MotionEvent.PointerCoords; +import static android.view.MotionEvent.PointerProperties; + +@TargetApi(Build.VERSION_CODES.ICE_CREAM_SANDWICH) +public class MotionEventCodec { + public static HashMap encode(MotionEvent event) { + ArrayList> pointerProperties = new ArrayList<>(); + ArrayList> pointerCoords = new ArrayList<>(); + + for (int i = 0; i < event.getPointerCount(); i++) { + MotionEvent.PointerProperties properties = new MotionEvent.PointerProperties(); + event.getPointerProperties(i, properties); + pointerProperties.add(encodePointerProperties(properties)); + + MotionEvent.PointerCoords coords = new MotionEvent.PointerCoords(); + event.getPointerCoords(i, coords); + pointerCoords.add(encodePointerCoords(coords)); + } + + HashMap eventMap = new HashMap<>(); + eventMap.put("downTime", event.getDownTime()); + eventMap.put("eventTime", event.getEventTime()); + eventMap.put("action", event.getAction()); + eventMap.put("pointerCount", event.getPointerCount()); + eventMap.put("pointerProperties", pointerProperties); + eventMap.put("pointerCoords", pointerCoords); + eventMap.put("metaState", event.getMetaState()); + eventMap.put("buttonState", event.getButtonState()); + eventMap.put("xPrecision", event.getXPrecision()); + eventMap.put("yPrecision", event.getYPrecision()); + eventMap.put("deviceId", event.getDeviceId()); + eventMap.put("edgeFlags", event.getEdgeFlags()); + eventMap.put("source", event.getSource()); + eventMap.put("flags", event.getFlags()); + + return eventMap; + } + + private static HashMap encodePointerProperties(PointerProperties properties) { + HashMap map = new HashMap<>(); + map.put("id", properties.id); + map.put("toolType", properties.toolType); + return map; + } + + private static HashMap encodePointerCoords(PointerCoords coords) { + HashMap map = new HashMap<>(); + map.put("orientation", coords.orientation); + map.put("pressure", coords.pressure); + map.put("size", coords.size); + map.put("toolMajor", coords.toolMajor); + map.put("toolMinor", coords.toolMinor); + map.put("touchMajor", coords.touchMajor); + map.put("touchMinor", coords.touchMinor); + map.put("x", coords.x); + map.put("y", coords.y); + return map; + } + + @SuppressWarnings("unchecked") + public static MotionEvent decode(HashMap data) { + List pointerProperties = new ArrayList<>(); + List pointerCoords = new ArrayList<>(); + + for (HashMap property : (List>) data.get("pointerProperties")) { + pointerProperties.add(decodePointerProperties(property)) ; + } + + for (HashMap coord : (List>) data.get("pointerCoords")) { + pointerCoords.add(decodePointerCoords(coord)) ; + } + + return MotionEvent.obtain( + (int) data.get("downTime"), + (int) data.get("eventTime"), + (int) data.get("action"), + (int) data.get("pointerCount"), + pointerProperties.toArray(new PointerProperties[pointerProperties.size()]), + pointerCoords.toArray(new PointerCoords[pointerCoords.size()]), + (int) data.get("metaState"), + (int) data.get("buttonState"), + (float) (double) data.get("xPrecision"), + (float) (double) data.get("yPrecision"), + (int) data.get("deviceId"), + (int) data.get("edgeFlags"), + (int) data.get("source"), + (int) data.get("flags") + ); + } + + private static PointerProperties decodePointerProperties(HashMap data) { + PointerProperties properties = new PointerProperties(); + properties.id = (int) data.get("id"); + properties.toolType = (int) data.get("toolType"); + return properties; + } + + private static PointerCoords decodePointerCoords(HashMap data) { + PointerCoords coords = new PointerCoords(); + coords.orientation = (float) (double) data.get("orientation"); + coords.pressure = (float) (double) data.get("pressure"); + coords.size = (float) (double) data.get("size"); + coords.toolMajor = (float) (double) data.get("toolMajor"); + coords.toolMinor = (float) (double) data.get("toolMinor"); + coords.touchMajor = (float) (double) data.get("touchMajor"); + coords.touchMinor = (float) (double) data.get("touchMinor"); + coords.x = (float) (double) data.get("x"); + coords.y = (float) (double) data.get("y"); + return coords; + } +} diff --git a/dev/integration_tests/android_views/android/app/src/main/java/io/flutter/integration/androidviews/SimplePlatformView.java b/dev/integration_tests/android_views/android/app/src/main/java/io/flutter/integration/androidviews/SimplePlatformView.java new file mode 100644 index 0000000000..28a7fd005e --- /dev/null +++ b/dev/integration_tests/android_views/android/app/src/main/java/io/flutter/integration/androidviews/SimplePlatformView.java @@ -0,0 +1,56 @@ +// Copyright 2018 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +package io.flutter.integration.androidviews; + +import android.content.Context; +import android.view.MotionEvent; +import android.view.View; + +import io.flutter.plugin.common.MethodCall; +import io.flutter.plugin.common.MethodChannel; +import io.flutter.plugin.platform.PlatformView; + +public class SimplePlatformView implements PlatformView, MethodChannel.MethodCallHandler { + private final View mView; + private final MethodChannel mMethodChannel; + private final TouchPipe mTouchPipe; + + SimplePlatformView(Context context, MethodChannel methodChannel) { + mMethodChannel = methodChannel; + mView = new View(context) { + @Override + public boolean onTouchEvent(MotionEvent event) { + return super.onTouchEvent(event); + } + }; + mView.setBackgroundColor(0xff0000ff); + mMethodChannel.setMethodCallHandler(this); + mTouchPipe = new TouchPipe(mMethodChannel, mView); + } + + @Override + public View getView() { + return mView; + } + + @Override + public void dispose() { + } + + @Override + public void onMethodCall(MethodCall methodCall, MethodChannel.Result result) { + switch(methodCall.method) { + case "pipeTouchEvents": + mTouchPipe.enable(); + result.success(null); + return; + case "stopTouchEvents": + mTouchPipe.disable(); + result.success(null); + return; + } + result.notImplemented(); + } +} diff --git a/dev/integration_tests/android_views/android/app/src/main/java/io/flutter/integration/androidviews/SimpleViewFactory.java b/dev/integration_tests/android_views/android/app/src/main/java/io/flutter/integration/androidviews/SimpleViewFactory.java new file mode 100644 index 0000000000..338e6fdd6c --- /dev/null +++ b/dev/integration_tests/android_views/android/app/src/main/java/io/flutter/integration/androidviews/SimpleViewFactory.java @@ -0,0 +1,26 @@ +// Copyright 2018 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +package io.flutter.integration.androidviews; + +import android.content.Context; + +import io.flutter.plugin.common.BinaryMessenger; +import io.flutter.plugin.common.MethodChannel; +import io.flutter.plugin.platform.PlatformView; +import io.flutter.plugin.platform.PlatformViewFactory; + +public class SimpleViewFactory implements PlatformViewFactory { + final BinaryMessenger messenger; + + public SimpleViewFactory(BinaryMessenger messenger) { + this.messenger = messenger; + } + + @Override + public PlatformView create(Context context, int id) { + MethodChannel methodChannel = new MethodChannel(messenger, "simple_view/" + id); + return new SimplePlatformView(context, methodChannel); + } +} diff --git a/dev/integration_tests/android_views/android/app/src/main/java/io/flutter/integration/androidviews/TouchPipe.java b/dev/integration_tests/android_views/android/app/src/main/java/io/flutter/integration/androidviews/TouchPipe.java new file mode 100644 index 0000000000..a9d7f3bf26 --- /dev/null +++ b/dev/integration_tests/android_views/android/app/src/main/java/io/flutter/integration/androidviews/TouchPipe.java @@ -0,0 +1,45 @@ +// Copyright 2018 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +package io.flutter.integration.androidviews; + +import android.annotation.TargetApi; +import android.os.Build; +import android.view.MotionEvent; +import android.view.View; + +import io.flutter.plugin.common.MethodChannel; + +@TargetApi(Build.VERSION_CODES.ICE_CREAM_SANDWICH) +class TouchPipe implements View.OnTouchListener { + private final MethodChannel mMethodChannel; + private final View mView; + + private boolean mEnabled; + + TouchPipe(MethodChannel methodChannel, View view) { + mMethodChannel = methodChannel; + mView = view; + } + + public void enable() { + if (mEnabled) + return; + mEnabled = true; + mView.setOnTouchListener(this); + } + + public void disable() { + if(!mEnabled) + return; + mEnabled = false; + mView.setOnTouchListener(null); + } + + @Override + public boolean onTouch(View v, MotionEvent event) { + mMethodChannel.invokeMethod("onTouch", MotionEventCodec.encode(event)); + return false; + } +} diff --git a/dev/integration_tests/android_views/android/build.gradle b/dev/integration_tests/android_views/android/build.gradle new file mode 100644 index 0000000000..d4225c7905 --- /dev/null +++ b/dev/integration_tests/android_views/android/build.gradle @@ -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 +} diff --git a/dev/integration_tests/android_views/android/gradle.properties b/dev/integration_tests/android_views/android/gradle.properties new file mode 100644 index 0000000000..8bd86f6805 --- /dev/null +++ b/dev/integration_tests/android_views/android/gradle.properties @@ -0,0 +1 @@ +org.gradle.jvmargs=-Xmx1536M diff --git a/dev/integration_tests/android_views/android/gradle/wrapper/gradle-wrapper.properties b/dev/integration_tests/android_views/android/gradle/wrapper/gradle-wrapper.properties new file mode 100644 index 0000000000..9372d0f3f4 --- /dev/null +++ b/dev/integration_tests/android_views/android/gradle/wrapper/gradle-wrapper.properties @@ -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 diff --git a/dev/integration_tests/android_views/android/settings.gradle b/dev/integration_tests/android_views/android/settings.gradle new file mode 100644 index 0000000000..5a2f14fb18 --- /dev/null +++ b/dev/integration_tests/android_views/android/settings.gradle @@ -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.withReader('UTF-8') { reader -> plugins.load(reader) } +} + +plugins.each { name, path -> + def pluginDirectory = flutterProjectRoot.resolve(path).resolve('android').toFile() + include ":$name" + project(":$name").projectDir = pluginDirectory +} diff --git a/dev/integration_tests/android_views/ios/.gitignore b/dev/integration_tests/android_views/ios/.gitignore new file mode 100644 index 0000000000..79cc4da802 --- /dev/null +++ b/dev/integration_tests/android_views/ios/.gitignore @@ -0,0 +1,45 @@ +.idea/ +.vagrant/ +.sconsign.dblite +.svn/ + +.DS_Store +*.swp +profile + +DerivedData/ +build/ +GeneratedPluginRegistrant.h +GeneratedPluginRegistrant.m + +.generated/ + +*.pbxuser +*.mode1v3 +*.mode2v3 +*.perspectivev3 + +!default.pbxuser +!default.mode1v3 +!default.mode2v3 +!default.perspectivev3 + +xcuserdata + +*.moved-aside + +*.pyc +*sync/ +Icon? +.tags* + +/Flutter/app.flx +/Flutter/app.zip +/Flutter/flutter_assets/ +/Flutter/App.framework +/Flutter/Flutter.framework +/Flutter/Generated.xcconfig +/ServiceDefinitions.json + +Pods/ +.symlinks/ diff --git a/dev/integration_tests/android_views/ios/Runner.xcodeproj/project.pbxproj b/dev/integration_tests/android_views/ios/Runner.xcodeproj/project.pbxproj new file mode 100644 index 0000000000..995fb36e5b --- /dev/null +++ b/dev/integration_tests/android_views/ios/Runner.xcodeproj/project.pbxproj @@ -0,0 +1,438 @@ +// !$*UTF8*$! +{ + archiveVersion = 1; + classes = { + }; + objectVersion = 46; + objects = { + +/* Begin PBXBuildFile section */ + 1498D2341E8E89220040F4C2 /* GeneratedPluginRegistrant.m in Sources */ = {isa = PBXBuildFile; fileRef = 1498D2331E8E89220040F4C2 /* GeneratedPluginRegistrant.m */; }; + 2D5378261FAA1A9400D5DBA9 /* flutter_assets in Resources */ = {isa = PBXBuildFile; fileRef = 2D5378251FAA1A9400D5DBA9 /* flutter_assets */; }; + 3B3967161E833CAA004F5970 /* AppFrameworkInfo.plist in Resources */ = {isa = PBXBuildFile; fileRef = 3B3967151E833CAA004F5970 /* AppFrameworkInfo.plist */; }; + 3B80C3941E831B6300D905FE /* App.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 3B80C3931E831B6300D905FE /* App.framework */; }; + 3B80C3951E831B6300D905FE /* App.framework in Embed Frameworks */ = {isa = PBXBuildFile; fileRef = 3B80C3931E831B6300D905FE /* App.framework */; settings = {ATTRIBUTES = (CodeSignOnCopy, RemoveHeadersOnCopy, ); }; }; + 9705A1C61CF904A100538489 /* Flutter.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 9740EEBA1CF902C7004384FC /* Flutter.framework */; }; + 9705A1C71CF904A300538489 /* Flutter.framework in Embed Frameworks */ = {isa = PBXBuildFile; fileRef = 9740EEBA1CF902C7004384FC /* Flutter.framework */; settings = {ATTRIBUTES = (CodeSignOnCopy, RemoveHeadersOnCopy, ); }; }; + 9740EEB41CF90195004384FC /* Debug.xcconfig in Resources */ = {isa = PBXBuildFile; fileRef = 9740EEB21CF90195004384FC /* Debug.xcconfig */; }; + 9740EEB51CF90195004384FC /* Generated.xcconfig in Resources */ = {isa = PBXBuildFile; fileRef = 9740EEB31CF90195004384FC /* Generated.xcconfig */; }; + 978B8F6F1D3862AE00F588F7 /* AppDelegate.m in Sources */ = {isa = PBXBuildFile; fileRef = 7AFFD8EE1D35381100E5BB4D /* AppDelegate.m */; }; + 97C146F31CF9000F007C117D /* main.m in Sources */ = {isa = PBXBuildFile; fileRef = 97C146F21CF9000F007C117D /* main.m */; }; + 97C146FC1CF9000F007C117D /* Main.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 97C146FA1CF9000F007C117D /* Main.storyboard */; }; + 97C146FE1CF9000F007C117D /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 97C146FD1CF9000F007C117D /* Assets.xcassets */; }; + 97C147011CF9000F007C117D /* LaunchScreen.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 97C146FF1CF9000F007C117D /* LaunchScreen.storyboard */; }; +/* End PBXBuildFile section */ + +/* Begin PBXCopyFilesBuildPhase section */ + 9705A1C41CF9048500538489 /* Embed Frameworks */ = { + isa = PBXCopyFilesBuildPhase; + buildActionMask = 2147483647; + dstPath = ""; + dstSubfolderSpec = 10; + files = ( + 3B80C3951E831B6300D905FE /* App.framework in Embed Frameworks */, + 9705A1C71CF904A300538489 /* Flutter.framework in Embed Frameworks */, + ); + name = "Embed Frameworks"; + runOnlyForDeploymentPostprocessing = 0; + }; +/* End PBXCopyFilesBuildPhase section */ + +/* Begin PBXFileReference section */ + 1498D2321E8E86230040F4C2 /* GeneratedPluginRegistrant.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = GeneratedPluginRegistrant.h; sourceTree = ""; }; + 1498D2331E8E89220040F4C2 /* GeneratedPluginRegistrant.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = GeneratedPluginRegistrant.m; sourceTree = ""; }; + 2D5378251FAA1A9400D5DBA9 /* flutter_assets */ = {isa = PBXFileReference; lastKnownFileType = folder; name = flutter_assets; path = Flutter/flutter_assets; sourceTree = SOURCE_ROOT; }; + 3B3967151E833CAA004F5970 /* AppFrameworkInfo.plist */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.xml; name = AppFrameworkInfo.plist; path = Flutter/AppFrameworkInfo.plist; sourceTree = ""; }; + 3B80C3931E831B6300D905FE /* App.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = App.framework; path = Flutter/App.framework; sourceTree = ""; }; + 7AFA3C8E1D35360C0083082E /* Release.xcconfig */ = {isa = PBXFileReference; lastKnownFileType = text.xcconfig; name = Release.xcconfig; path = Flutter/Release.xcconfig; sourceTree = ""; }; + 7AFFD8ED1D35381100E5BB4D /* AppDelegate.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = AppDelegate.h; sourceTree = ""; }; + 7AFFD8EE1D35381100E5BB4D /* AppDelegate.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = AppDelegate.m; sourceTree = ""; }; + 9740EEB21CF90195004384FC /* Debug.xcconfig */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.xcconfig; name = Debug.xcconfig; path = Flutter/Debug.xcconfig; sourceTree = ""; }; + 9740EEB31CF90195004384FC /* Generated.xcconfig */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.xcconfig; name = Generated.xcconfig; path = Flutter/Generated.xcconfig; sourceTree = ""; }; + 9740EEBA1CF902C7004384FC /* Flutter.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = Flutter.framework; path = Flutter/Flutter.framework; sourceTree = ""; }; + 97C146EE1CF9000F007C117D /* Runner.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = Runner.app; sourceTree = BUILT_PRODUCTS_DIR; }; + 97C146F21CF9000F007C117D /* main.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = main.m; sourceTree = ""; }; + 97C146FB1CF9000F007C117D /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/Main.storyboard; sourceTree = ""; }; + 97C146FD1CF9000F007C117D /* Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Assets.xcassets; sourceTree = ""; }; + 97C147001CF9000F007C117D /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/LaunchScreen.storyboard; sourceTree = ""; }; + 97C147021CF9000F007C117D /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; +/* End PBXFileReference section */ + +/* Begin PBXFrameworksBuildPhase section */ + 97C146EB1CF9000F007C117D /* Frameworks */ = { + isa = PBXFrameworksBuildPhase; + buildActionMask = 2147483647; + files = ( + 9705A1C61CF904A100538489 /* Flutter.framework in Frameworks */, + 3B80C3941E831B6300D905FE /* App.framework in Frameworks */, + ); + runOnlyForDeploymentPostprocessing = 0; + }; +/* End PBXFrameworksBuildPhase section */ + +/* Begin PBXGroup section */ + 9740EEB11CF90186004384FC /* Flutter */ = { + isa = PBXGroup; + children = ( + 2D5378251FAA1A9400D5DBA9 /* flutter_assets */, + 3B80C3931E831B6300D905FE /* App.framework */, + 3B3967151E833CAA004F5970 /* AppFrameworkInfo.plist */, + 9740EEBA1CF902C7004384FC /* Flutter.framework */, + 9740EEB21CF90195004384FC /* Debug.xcconfig */, + 7AFA3C8E1D35360C0083082E /* Release.xcconfig */, + 9740EEB31CF90195004384FC /* Generated.xcconfig */, + ); + name = Flutter; + sourceTree = ""; + }; + 97C146E51CF9000F007C117D = { + isa = PBXGroup; + children = ( + 9740EEB11CF90186004384FC /* Flutter */, + 97C146F01CF9000F007C117D /* Runner */, + 97C146EF1CF9000F007C117D /* Products */, + CF3B75C9A7D2FA2A4C99F110 /* Frameworks */, + ); + sourceTree = ""; + }; + 97C146EF1CF9000F007C117D /* Products */ = { + isa = PBXGroup; + children = ( + 97C146EE1CF9000F007C117D /* Runner.app */, + ); + name = Products; + sourceTree = ""; + }; + 97C146F01CF9000F007C117D /* Runner */ = { + isa = PBXGroup; + children = ( + 7AFFD8ED1D35381100E5BB4D /* AppDelegate.h */, + 7AFFD8EE1D35381100E5BB4D /* AppDelegate.m */, + 97C146FA1CF9000F007C117D /* Main.storyboard */, + 97C146FD1CF9000F007C117D /* Assets.xcassets */, + 97C146FF1CF9000F007C117D /* LaunchScreen.storyboard */, + 97C147021CF9000F007C117D /* Info.plist */, + 97C146F11CF9000F007C117D /* Supporting Files */, + 1498D2321E8E86230040F4C2 /* GeneratedPluginRegistrant.h */, + 1498D2331E8E89220040F4C2 /* GeneratedPluginRegistrant.m */, + ); + path = Runner; + sourceTree = ""; + }; + 97C146F11CF9000F007C117D /* Supporting Files */ = { + isa = PBXGroup; + children = ( + 97C146F21CF9000F007C117D /* main.m */, + ); + name = "Supporting Files"; + sourceTree = ""; + }; +/* End PBXGroup section */ + +/* Begin PBXNativeTarget section */ + 97C146ED1CF9000F007C117D /* Runner */ = { + isa = PBXNativeTarget; + buildConfigurationList = 97C147051CF9000F007C117D /* Build configuration list for PBXNativeTarget "Runner" */; + buildPhases = ( + 9740EEB61CF901F6004384FC /* Run Script */, + 97C146EA1CF9000F007C117D /* Sources */, + 97C146EB1CF9000F007C117D /* Frameworks */, + 97C146EC1CF9000F007C117D /* Resources */, + 9705A1C41CF9048500538489 /* Embed Frameworks */, + 3B06AD1E1E4923F5004D2608 /* Thin Binary */, + ); + buildRules = ( + ); + dependencies = ( + ); + name = Runner; + productName = Runner; + productReference = 97C146EE1CF9000F007C117D /* Runner.app */; + productType = "com.apple.product-type.application"; + }; +/* End PBXNativeTarget section */ + +/* Begin PBXProject section */ + 97C146E61CF9000F007C117D /* Project object */ = { + isa = PBXProject; + attributes = { + LastUpgradeCheck = 0910; + ORGANIZATIONNAME = "The Chromium Authors"; + TargetAttributes = { + 97C146ED1CF9000F007C117D = { + CreatedOnToolsVersion = 7.3.1; + }; + }; + }; + buildConfigurationList = 97C146E91CF9000F007C117D /* Build configuration list for PBXProject "Runner" */; + compatibilityVersion = "Xcode 3.2"; + developmentRegion = English; + hasScannedForEncodings = 0; + knownRegions = ( + en, + Base, + ); + mainGroup = 97C146E51CF9000F007C117D; + productRefGroup = 97C146EF1CF9000F007C117D /* Products */; + projectDirPath = ""; + projectRoot = ""; + targets = ( + 97C146ED1CF9000F007C117D /* Runner */, + ); + }; +/* End PBXProject section */ + +/* Begin PBXResourcesBuildPhase section */ + 97C146EC1CF9000F007C117D /* Resources */ = { + isa = PBXResourcesBuildPhase; + buildActionMask = 2147483647; + files = ( + 97C147011CF9000F007C117D /* LaunchScreen.storyboard in Resources */, + 9740EEB51CF90195004384FC /* Generated.xcconfig in Resources */, + 3B3967161E833CAA004F5970 /* AppFrameworkInfo.plist in Resources */, + 9740EEB41CF90195004384FC /* Debug.xcconfig in Resources */, + 97C146FE1CF9000F007C117D /* Assets.xcassets in Resources */, + 2D5378261FAA1A9400D5DBA9 /* flutter_assets in Resources */, + 97C146FC1CF9000F007C117D /* Main.storyboard in Resources */, + ); + runOnlyForDeploymentPostprocessing = 0; + }; +/* End PBXResourcesBuildPhase section */ + +/* Begin PBXShellScriptBuildPhase section */ + 3B06AD1E1E4923F5004D2608 /* Thin Binary */ = { + isa = PBXShellScriptBuildPhase; + buildActionMask = 2147483647; + files = ( + ); + inputPaths = ( + ); + name = "Thin Binary"; + outputPaths = ( + ); + runOnlyForDeploymentPostprocessing = 0; + shellPath = /bin/sh; + shellScript = "/bin/sh \"$FLUTTER_ROOT/packages/flutter_tools/bin/xcode_backend.sh\" thin"; + }; + 9740EEB61CF901F6004384FC /* Run Script */ = { + isa = PBXShellScriptBuildPhase; + buildActionMask = 2147483647; + files = ( + ); + inputPaths = ( + ); + name = "Run Script"; + outputPaths = ( + ); + runOnlyForDeploymentPostprocessing = 0; + shellPath = /bin/sh; + shellScript = "/bin/sh \"$FLUTTER_ROOT/packages/flutter_tools/bin/xcode_backend.sh\" build"; + }; +/* End PBXShellScriptBuildPhase section */ + +/* Begin PBXSourcesBuildPhase section */ + 97C146EA1CF9000F007C117D /* Sources */ = { + isa = PBXSourcesBuildPhase; + buildActionMask = 2147483647; + files = ( + 978B8F6F1D3862AE00F588F7 /* AppDelegate.m in Sources */, + 97C146F31CF9000F007C117D /* main.m in Sources */, + 1498D2341E8E89220040F4C2 /* GeneratedPluginRegistrant.m in Sources */, + ); + runOnlyForDeploymentPostprocessing = 0; + }; +/* End PBXSourcesBuildPhase section */ + +/* Begin PBXVariantGroup section */ + 97C146FA1CF9000F007C117D /* Main.storyboard */ = { + isa = PBXVariantGroup; + children = ( + 97C146FB1CF9000F007C117D /* Base */, + ); + name = Main.storyboard; + sourceTree = ""; + }; + 97C146FF1CF9000F007C117D /* LaunchScreen.storyboard */ = { + isa = PBXVariantGroup; + children = ( + 97C147001CF9000F007C117D /* Base */, + ); + name = LaunchScreen.storyboard; + sourceTree = ""; + }; +/* End PBXVariantGroup section */ + +/* Begin XCBuildConfiguration section */ + 97C147031CF9000F007C117D /* Debug */ = { + isa = XCBuildConfiguration; + baseConfigurationReference = 9740EEB21CF90195004384FC /* Debug.xcconfig */; + buildSettings = { + ALWAYS_SEARCH_USER_PATHS = NO; + CLANG_ANALYZER_NONNULL = YES; + CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x"; + CLANG_CXX_LIBRARY = "libc++"; + CLANG_ENABLE_MODULES = YES; + CLANG_ENABLE_OBJC_ARC = YES; + CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES; + CLANG_WARN_BOOL_CONVERSION = YES; + CLANG_WARN_COMMA = YES; + CLANG_WARN_CONSTANT_CONVERSION = YES; + CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; + CLANG_WARN_EMPTY_BODY = YES; + CLANG_WARN_ENUM_CONVERSION = YES; + CLANG_WARN_INFINITE_RECURSION = YES; + CLANG_WARN_INT_CONVERSION = YES; + CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES; + CLANG_WARN_OBJC_LITERAL_CONVERSION = YES; + CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; + CLANG_WARN_RANGE_LOOP_ANALYSIS = YES; + CLANG_WARN_STRICT_PROTOTYPES = YES; + CLANG_WARN_SUSPICIOUS_MOVE = YES; + CLANG_WARN_UNREACHABLE_CODE = YES; + CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; + "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; + COPY_PHASE_STRIP = NO; + DEBUG_INFORMATION_FORMAT = dwarf; + ENABLE_STRICT_OBJC_MSGSEND = YES; + ENABLE_TESTABILITY = YES; + GCC_C_LANGUAGE_STANDARD = gnu99; + GCC_DYNAMIC_NO_PIC = NO; + GCC_NO_COMMON_BLOCKS = YES; + GCC_OPTIMIZATION_LEVEL = 0; + GCC_PREPROCESSOR_DEFINITIONS = ( + "DEBUG=1", + "$(inherited)", + ); + GCC_WARN_64_TO_32_BIT_CONVERSION = YES; + GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; + GCC_WARN_UNDECLARED_SELECTOR = YES; + GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; + GCC_WARN_UNUSED_FUNCTION = YES; + GCC_WARN_UNUSED_VARIABLE = YES; + IPHONEOS_DEPLOYMENT_TARGET = 8.0; + MTL_ENABLE_DEBUG_INFO = YES; + ONLY_ACTIVE_ARCH = YES; + SDKROOT = iphoneos; + TARGETED_DEVICE_FAMILY = "1,2"; + }; + name = Debug; + }; + 97C147041CF9000F007C117D /* Release */ = { + isa = XCBuildConfiguration; + baseConfigurationReference = 7AFA3C8E1D35360C0083082E /* Release.xcconfig */; + buildSettings = { + ALWAYS_SEARCH_USER_PATHS = NO; + CLANG_ANALYZER_NONNULL = YES; + CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x"; + CLANG_CXX_LIBRARY = "libc++"; + CLANG_ENABLE_MODULES = YES; + CLANG_ENABLE_OBJC_ARC = YES; + CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES; + CLANG_WARN_BOOL_CONVERSION = YES; + CLANG_WARN_COMMA = YES; + CLANG_WARN_CONSTANT_CONVERSION = YES; + CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; + CLANG_WARN_EMPTY_BODY = YES; + CLANG_WARN_ENUM_CONVERSION = YES; + CLANG_WARN_INFINITE_RECURSION = YES; + CLANG_WARN_INT_CONVERSION = YES; + CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES; + CLANG_WARN_OBJC_LITERAL_CONVERSION = YES; + CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; + CLANG_WARN_RANGE_LOOP_ANALYSIS = YES; + CLANG_WARN_STRICT_PROTOTYPES = YES; + CLANG_WARN_SUSPICIOUS_MOVE = YES; + CLANG_WARN_UNREACHABLE_CODE = YES; + CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; + "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; + COPY_PHASE_STRIP = NO; + DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym"; + ENABLE_NS_ASSERTIONS = NO; + ENABLE_STRICT_OBJC_MSGSEND = YES; + GCC_C_LANGUAGE_STANDARD = gnu99; + GCC_NO_COMMON_BLOCKS = YES; + GCC_WARN_64_TO_32_BIT_CONVERSION = YES; + GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; + GCC_WARN_UNDECLARED_SELECTOR = YES; + GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; + GCC_WARN_UNUSED_FUNCTION = YES; + GCC_WARN_UNUSED_VARIABLE = YES; + IPHONEOS_DEPLOYMENT_TARGET = 8.0; + MTL_ENABLE_DEBUG_INFO = NO; + SDKROOT = iphoneos; + TARGETED_DEVICE_FAMILY = "1,2"; + VALIDATE_PRODUCT = YES; + }; + name = Release; + }; + 97C147061CF9000F007C117D /* Debug */ = { + isa = XCBuildConfiguration; + baseConfigurationReference = 9740EEB21CF90195004384FC /* Debug.xcconfig */; + buildSettings = { + ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; + CURRENT_PROJECT_VERSION = "$(FLUTTER_BUILD_NUMBER)"; + ENABLE_BITCODE = NO; + FRAMEWORK_SEARCH_PATHS = ( + "$(inherited)", + "$(PROJECT_DIR)/Flutter", + ); + INFOPLIST_FILE = Runner/Info.plist; + LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; + LIBRARY_SEARCH_PATHS = ( + "$(inherited)", + "$(PROJECT_DIR)/Flutter", + ); + PRODUCT_BUNDLE_IDENTIFIER = io.flutter.integration.platformViews; + PRODUCT_NAME = "$(TARGET_NAME)"; + VERSIONING_SYSTEM = "apple-generic"; + }; + name = Debug; + }; + 97C147071CF9000F007C117D /* Release */ = { + isa = XCBuildConfiguration; + baseConfigurationReference = 7AFA3C8E1D35360C0083082E /* Release.xcconfig */; + buildSettings = { + ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; + CURRENT_PROJECT_VERSION = "$(FLUTTER_BUILD_NUMBER)"; + ENABLE_BITCODE = NO; + FRAMEWORK_SEARCH_PATHS = ( + "$(inherited)", + "$(PROJECT_DIR)/Flutter", + ); + INFOPLIST_FILE = Runner/Info.plist; + LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; + LIBRARY_SEARCH_PATHS = ( + "$(inherited)", + "$(PROJECT_DIR)/Flutter", + ); + PRODUCT_BUNDLE_IDENTIFIER = io.flutter.integration.platformViews; + PRODUCT_NAME = "$(TARGET_NAME)"; + VERSIONING_SYSTEM = "apple-generic"; + }; + name = Release; + }; +/* End XCBuildConfiguration section */ + +/* Begin XCConfigurationList section */ + 97C146E91CF9000F007C117D /* Build configuration list for PBXProject "Runner" */ = { + isa = XCConfigurationList; + buildConfigurations = ( + 97C147031CF9000F007C117D /* Debug */, + 97C147041CF9000F007C117D /* Release */, + ); + defaultConfigurationIsVisible = 0; + defaultConfigurationName = Release; + }; + 97C147051CF9000F007C117D /* Build configuration list for PBXNativeTarget "Runner" */ = { + isa = XCConfigurationList; + buildConfigurations = ( + 97C147061CF9000F007C117D /* Debug */, + 97C147071CF9000F007C117D /* Release */, + ); + defaultConfigurationIsVisible = 0; + defaultConfigurationName = Release; + }; +/* End XCConfigurationList section */ + }; + rootObject = 97C146E61CF9000F007C117D /* Project object */; +} diff --git a/dev/integration_tests/android_views/ios/Runner.xcodeproj/project.xcworkspace/contents.xcworkspacedata b/dev/integration_tests/android_views/ios/Runner.xcodeproj/project.xcworkspace/contents.xcworkspacedata new file mode 100644 index 0000000000..1d526a16ed --- /dev/null +++ b/dev/integration_tests/android_views/ios/Runner.xcodeproj/project.xcworkspace/contents.xcworkspacedata @@ -0,0 +1,7 @@ + + + + + diff --git a/dev/integration_tests/android_views/ios/Runner.xcodeproj/xcshareddata/xcschemes/Runner.xcscheme b/dev/integration_tests/android_views/ios/Runner.xcodeproj/xcshareddata/xcschemes/Runner.xcscheme new file mode 100644 index 0000000000..1263ac84b1 --- /dev/null +++ b/dev/integration_tests/android_views/ios/Runner.xcodeproj/xcshareddata/xcschemes/Runner.xcscheme @@ -0,0 +1,93 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/dev/integration_tests/android_views/lib/main.dart b/dev/integration_tests/android_views/lib/main.dart new file mode 100644 index 0000000000..d1b03e689d --- /dev/null +++ b/dev/integration_tests/android_views/lib/main.dart @@ -0,0 +1,298 @@ +// Copyright 2018 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +import 'dart:async'; +import 'dart:io'; +import 'dart:typed_data'; + +import 'package:flutter/material.dart'; +import 'package:flutter/services.dart'; +import 'package:flutter_driver/driver_extension.dart'; +import 'package:path_provider/path_provider.dart'; + +import 'motion_event_diff.dart'; + +MethodChannel channel = const MethodChannel('android_views_integration'); + +const String kEventsFileName = 'touchEvents'; + +/// Wraps a flutter driver [DataHandler] with one that waits until a delegate is set. +/// +/// This allows the driver test to call [FlutterDriver.requestData] before the handler was +/// set by the app in which case the requestData call will only complete once the app is ready +/// for it. +class FutureDataHandler { + final Completer handlerCompleter = new Completer(); + + Future handleMessage(String message) async { + final DataHandler handler = await handlerCompleter.future; + return handler(message); + } +} + +FutureDataHandler driverDataHandler = new FutureDataHandler(); + +void main() { + enableFlutterDriverExtension(handler: driverDataHandler.handleMessage); + runApp(new MyApp()); +} + +class MyApp extends StatelessWidget { + @override + Widget build(BuildContext context) { + return new MaterialApp( + title: 'Android Views Integration Test', + home: new Scaffold( + body: new PlatformViewPage(), + ), + ); + } +} + +class PlatformViewPage extends StatefulWidget { + @override + State createState() => new PlatformViewState(); +} + +class PlatformViewState extends State { + static const int kEventsBufferSize = 1000; + + MethodChannel viewChannel; + + /// The list of motion events that were passed to the FlutterView. + List> flutterViewEvents = >[]; + + /// The list of motion events that were passed to the embedded view. + List> embeddedViewEvents = >[]; + + @override + Widget build(BuildContext context) { + return new Column( + children: [ + new SizedBox( + height: 300.0, + child: new AndroidView( + viewType: 'simple_view', + onPlatformViewCreated: onPlatformViewCreated), + ), + new Expanded( + child: new ListView.builder( + itemBuilder: buildEventTile, + itemCount: flutterViewEvents.length, + ), + ), + new Row( + children: [ + new RaisedButton( + child: const Text('RECORD'), + onPressed: listenToFlutterViewEvents, + ), + new RaisedButton( + child: const Text('CLEAR'), + onPressed: () { + setState(() { + flutterViewEvents.clear(); + embeddedViewEvents.clear(); + }); + }, + ), + new RaisedButton( + child: const Text('SAVE'), + onPressed: () { + const StandardMessageCodec codec = StandardMessageCodec(); + saveRecordedEvents( + codec.encodeMessage(flutterViewEvents), context); + }, + ), + new RaisedButton( + key: const ValueKey('play'), + child: const Text('PLAY FILE'), + onPressed: () { playEventsFile(); }, + ) + ], + ) + ], + ); + } + + Future playEventsFile() async { + const StandardMessageCodec codec = StandardMessageCodec(); + try { + final ByteData data = await rootBundle.load('packages/assets_for_android_views/assets/touchEvents'); + final List unTypedRecordedEvents = codec.decodeMessage(data); + final List> recordedEvents = unTypedRecordedEvents + .cast>() + .map((Map e) =>e.cast()) + .toList(); + await channel.invokeMethod('pipeFlutterViewEvents'); + await viewChannel.invokeMethod('pipeTouchEvents'); + print('replaying ${recordedEvents.length} motion events'); + for (Map event in recordedEvents.reversed) { + await channel.invokeMethod('synthesizeEvent', event); + } + + await channel.invokeMethod('stopFlutterViewEvents'); + await viewChannel.invokeMethod('stopTouchEvents'); + + if (flutterViewEvents.length != embeddedViewEvents.length) + return 'Synthesized ${flutterViewEvents.length} events but the embedded view received ${embeddedViewEvents.length} events'; + + final StringBuffer diff = new StringBuffer(); + for (int i = 0; i < flutterViewEvents.length; ++i) { + final String currentDiff = diffMotionEvents(flutterViewEvents[i], embeddedViewEvents[i]); + if (currentDiff.isEmpty) + continue; + if (diff.isNotEmpty) + diff.write(', '); + diff.write(currentDiff); + } + return diff.toString(); + } catch(e) { + return e.toString(); + } + } + + @override + void initState() { + super.initState(); + channel.setMethodCallHandler(onMethodChannelCall); + } + + Future saveRecordedEvents(ByteData data, BuildContext context) async { + if (!await channel.invokeMethod('getStoragePermission')) { + showMessage( + context, 'External storage permissions are required to save events'); + return; + } + try { + final Directory outDir = await getExternalStorageDirectory(); + // This test only runs on Android so we can assume path separator is '/'. + final File file = new File('${outDir.path}/$kEventsFileName'); + await file.writeAsBytes(data.buffer.asUint8List(0, data.lengthInBytes), flush: true); + showMessage(context, 'Saved original events to ${file.path}'); + } catch (e) { + showMessage(context, 'Failed saving ${e.toString()}'); + } + } + + void showMessage(BuildContext context, String message) { + Scaffold.of(context).showSnackBar(new SnackBar( + content: new Text(message), + duration: const Duration(seconds: 3), + )); + } + + void onPlatformViewCreated(int id) { + viewChannel = new MethodChannel('simple_view/$id'); + viewChannel.setMethodCallHandler(onViewMethodChannelCall); + driverDataHandler.handlerCompleter.complete(handleDriverMessage); + } + + void listenToFlutterViewEvents() { + channel.invokeMethod('pipeFlutterViewEvents'); + viewChannel.invokeMethod('pipeTouchEvents'); + new Timer(const Duration(seconds: 3), () { + channel.invokeMethod('stopFlutterViewEvents'); + viewChannel.invokeMethod('stopTouchEvents'); + }); + } + + Future handleDriverMessage(String message) async { + switch (message) { + case 'run test': + return playEventsFile(); + } + return 'unknown message: "$message"'; + } + + Future onMethodChannelCall(MethodCall call) { + switch (call.method) { + case 'onTouch': + final Map map = call.arguments; + flutterViewEvents.insert(0, map.cast()); + if (flutterViewEvents.length > kEventsBufferSize) + flutterViewEvents.removeLast(); + setState(() {}); + break; + } + return new Future.sync(null); + } + + Future onViewMethodChannelCall(MethodCall call) { + switch (call.method) { + case 'onTouch': + final Map map = call.arguments; + embeddedViewEvents.insert(0, map.cast()); + if (embeddedViewEvents.length > kEventsBufferSize) + embeddedViewEvents.removeLast(); + setState(() {}); + break; + } + return new Future.sync(null); + } + + Widget buildEventTile(BuildContext context, int index) { + if (embeddedViewEvents.length > index) + return new TouchEventDiff( + flutterViewEvents[index], embeddedViewEvents[index]); + return new Text( + 'Unmatched event, action: ${flutterViewEvents[index]['action']}'); + } +} + +class TouchEventDiff extends StatelessWidget { + const TouchEventDiff(this.originalEvent, this.synthesizedEvent); + + final Map originalEvent; + final Map synthesizedEvent; + + @override + Widget build(BuildContext context) { + + Color color; + final String diff = diffMotionEvents(originalEvent, synthesizedEvent); + String msg; + final int action = synthesizedEvent['action']; + final String actionName = getActionName(getActionMasked(action), action); + if (diff.isEmpty) { + color = Colors.green; + msg = 'Matched event (action $actionName)'; + } else { + color = Colors.red; + msg = '[$actionName] $diff'; + } + return new GestureDetector( + onLongPress: () { + print('expected:'); + prettyPrintEvent(originalEvent); + print('\nactual:'); + prettyPrintEvent(synthesizedEvent); + }, + child: new Container( + color: color, + margin: const EdgeInsets.only(bottom: 2.0), + child: new Text(msg), + ), + ); + } + + void prettyPrintEvent(Map event) { + final StringBuffer buffer = new StringBuffer(); + final int action = event['action']; + final int maskedAction = getActionMasked(action); + final String actionName = getActionName(maskedAction, action); + + buffer.write('$actionName '); + if (maskedAction == 5 || maskedAction == 6) { + buffer.write('pointer: ${getPointerIdx(action)} '); + } + + final List> coords = event['pointerCoords'].cast>(); + for (int i = 0; i < coords.length; i++) { + buffer.write('p$i x: ${coords[i]['x']} y: ${coords[i]['y']}, pressure: ${coords[i]['pressure']} '); + } + print(buffer.toString()); + } +} + diff --git a/dev/integration_tests/android_views/lib/motion_event_diff.dart b/dev/integration_tests/android_views/lib/motion_event_diff.dart new file mode 100644 index 0000000000..ecd2c5238a --- /dev/null +++ b/dev/integration_tests/android_views/lib/motion_event_diff.dart @@ -0,0 +1,191 @@ +// Copyright 2018 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +import 'package:collection/collection.dart'; + +// Android MotionEvent actions for which a pointer index is encoded in the +// unmasked action code. +const List kPointerActions = [ + 0, // DOWN + 1, // UP + 5, // POINTER_DOWN + 6 // POINTER_UP +]; + +const double kDoubleErrorMargin = 0.0001; + +String diffMotionEvents( + Map originalEvent, + Map synthesizedEvent, +) { + final StringBuffer diff = new StringBuffer(); + + diffMaps(originalEvent, synthesizedEvent, diff, excludeKeys: const [ + 'pointerProperties', // Compared separately. + 'pointerCoords', // Compared separately. + 'source', // Unused by Flutter. + 'deviceId', // Android documentation says that's an arbitrary number that shouldn't be depended on. + 'action', // Compared separately. + ]); + + diffActions(diff, originalEvent, synthesizedEvent); + diffPointerProperties(diff, originalEvent, synthesizedEvent); + diffPointerCoordsList(diff, originalEvent, synthesizedEvent); + + return diff.toString(); +} + +void diffActions(StringBuffer diffBuffer, Map originalEvent, + Map synthesizedEvent) { + final int synthesizedActionMasked = + getActionMasked(synthesizedEvent['action']); + final int originalActionMasked = getActionMasked(originalEvent['action']); + final String synthesizedActionName = + getActionName(synthesizedActionMasked, synthesizedEvent['action']); + final String originalActionName = + getActionName(originalActionMasked, originalEvent['action']); + + if (synthesizedActionMasked != originalActionMasked) + diffBuffer.write( + 'action (expected: $originalActionName actual: $synthesizedActionName) '); + + if (kPointerActions.contains(originalActionMasked) && + originalActionMasked == synthesizedActionMasked) { + final int originalPointer = getPointerIdx(originalEvent['action']); + final int synthesizedPointer = getPointerIdx(synthesizedEvent['action']); + if (originalPointer != synthesizedPointer) + diffBuffer.write( + 'pointerIdx (expected: $originalPointer actual: $synthesizedPointer action: $originalActionName '); + } +} + +void diffPointerProperties(StringBuffer diffBuffer, + Map originalEvent, Map synthesizedEvent) { + final List> expectedList = + originalEvent['pointerProperties'].cast>(); + final List> actualList = + synthesizedEvent['pointerProperties'].cast>(); + + if (expectedList.length != actualList.length) { + diffBuffer.write( + 'pointerProperties (actual length: ${actualList.length}, expected length: ${expectedList.length} '); + return; + } + + for (int i = 0; i < expectedList.length; i++) { + final Map expected = + expectedList[i].cast(); + final Map actual = actualList[i].cast(); + diffMaps(expected, actual, diffBuffer, + messagePrefix: '[pointerProperty $i] '); + } +} + +void diffPointerCoordsList(StringBuffer diffBuffer, + Map originalEvent, Map synthesizedEvent) { + final List> expectedList = + originalEvent['pointerCoords'].cast>(); + final List> actualList = + synthesizedEvent['pointerCoords'].cast>(); + + if (expectedList.length != actualList.length) { + diffBuffer.write( + 'pointerCoords (actual length: ${actualList.length}, expected length: ${expectedList.length} '); + return; + } + + if (isSinglePointerAction(originalEvent['action'])) { + final int idx = getPointerIdx(originalEvent['action']); + final Map expected = + expectedList[idx].cast(); + final Map actual = actualList[idx].cast(); + diffPointerCoords(expected, actual, idx, diffBuffer); + // For POINTER_UP and POINTER_DOWN events the engine drops the data for all pointers + // but for the pointer that was taken up/down. + // See: https://github.com/flutter/flutter/issues/19882 + // + // Until that issue is resolved, we only compare the pointer for which the action + // applies to here. + // + // TODO(amirh): Compare all pointers once the issue mentioned above is resolved. + return; + } + + for (int i = 0; i < expectedList.length; i++) { + final Map expected = + expectedList[i].cast(); + final Map actual = actualList[i].cast(); + diffPointerCoords(expected, actual, i, diffBuffer); + } +} + +void diffPointerCoords(Map expected, + Map actual, int pointerIdx, StringBuffer diffBuffer) { + diffMaps(expected, actual, diffBuffer, + messagePrefix: '[pointerCoord $pointerIdx] ', + excludeKeys: [ + 'size', // Currently the framework doesn't get the size from the engine. + ]); +} + +void diffMaps( + Map expected, + Map actual, + StringBuffer diffBuffer, { + List excludeKeys = const [], + String messagePrefix = '', +}) { + const IterableEquality eq = IterableEquality(); + if (!eq.equals(expected.keys, actual.keys)) { + diffBuffer.write( + '${messagePrefix}keys (expected: ${expected.keys} actual: ${actual.keys} '); + return; + } + for (String key in expected.keys) { + if (excludeKeys.contains(key)) + continue; + if (doublesApproximatelyMatch(expected[key], actual[key])) + continue; + + if (expected[key] != actual[key]) { + diffBuffer.write( + '$messagePrefix$key (expected: ${expected[key]} actual: ${actual[key]}) '); + } + } +} + +bool isSinglePointerAction(int action) { + final int actionMasked = getActionMasked(action); + return actionMasked == 5 || // POINTER_DOWN + actionMasked == 6; // POINTER_UP +} + +int getActionMasked(int action) => action & 0xff; + +int getPointerIdx(int action) => (action >> 8) & 0xff; + +String getActionName(int actionMasked, int action) { + const List actionNames = [ + 'DOWN', + 'UP', + 'MOVE', + 'CANCEL', + 'OUTSIDE', + 'POINTER_DOWN', + 'POINTER_UP', + 'HOVER_MOVE', + 'SCROLL', + 'HOVER_ENTER', + 'HOVER_EXIT', + 'BUTTON_PRESS', + 'BUTTON_RELEASE' + ]; + if (actionMasked < actionNames.length) + return '${actionNames[actionMasked]}($action)'; + else + return 'ACTION_$actionMasked'; +} + +bool doublesApproximatelyMatch(dynamic a, dynamic b) => + a is double && b is double && (a - b).abs() < kDoubleErrorMargin; diff --git a/dev/integration_tests/android_views/pubspec.yaml b/dev/integration_tests/android_views/pubspec.yaml new file mode 100644 index 0000000000..7c03b28f33 --- /dev/null +++ b/dev/integration_tests/android_views/pubspec.yaml @@ -0,0 +1,22 @@ +name: android_views +description: An integration test for embedded Android views +version: 1.0.0+1 + +dependencies: + flutter: + sdk: flutter + flutter_driver: + sdk: flutter + path_provider: ^0.4.1 + collection: ^1.14.6 + assets_for_android_views: + path: ../../../bin/cache/pkg/goldens/dev/integration_tests/assets_for_android_views + +dev_dependencies: + flutter_test: + sdk: flutter + flutter_goldens: + sdk: flutter + +flutter: + uses-material-design: true diff --git a/dev/integration_tests/android_views/test_driver/main_test.dart b/dev/integration_tests/android_views/test_driver/main_test.dart new file mode 100644 index 0000000000..25f4096803 --- /dev/null +++ b/dev/integration_tests/android_views/test_driver/main_test.dart @@ -0,0 +1,27 @@ +// Copyright 2018 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +import 'dart:async'; + +import 'package:flutter_driver/flutter_driver.dart'; +import 'package:flutter_goldens_client/client.dart'; +import 'package:test/test.dart' hide TypeMatcher, isInstanceOf; + +Future main() async { + + setUpAll(() async { + print('Cloning goldens repository...'); + final GoldensClient goldensClient = new GoldensClient(); + await goldensClient.prepare(); + }); + + test('MotionEvents recomposition', () async { + final FlutterDriver driver = await FlutterDriver.connect(); + final String errorMessage = await driver.requestData('run test'); + + expect(errorMessage, ''); + driver?.close(); + }); +} +