diff --git a/dev/bots/suite_runners/run_flutter_driver_android_tests.dart b/dev/bots/suite_runners/run_flutter_driver_android_tests.dart index c6c7e7b0dc..e2f97f6e15 100644 --- a/dev/bots/suite_runners/run_flutter_driver_android_tests.dart +++ b/dev/bots/suite_runners/run_flutter_driver_android_tests.dart @@ -2,9 +2,6 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -import 'dart:convert'; -import 'dart:io' as io; - import 'package:path/path.dart' as path; import '../run_command.dart'; import '../utils.dart'; @@ -19,32 +16,15 @@ import '../utils.dart'; /// ``` /// /// For debugging, it is recommended to instead just run and launch these tests -/// individually _in_ the `dev/integration_tests/android_driver_test` directory. +/// individually _in_ the `dev/integration_tests/native_driver_test` directory. Future runFlutterDriverAndroidTests() async { print('Running Flutter Driver Android tests...'); - // Print out the results of `adb devices`, for uh, science: - print('Listing devices...'); - final io.ProcessResult devices = await _adb( - [ - 'devices', - ], - ); - print(devices.stdout); - print(devices.stderr); - - // We need to configure the emulator to disable confirmations before the - // application starts. Some of these configuration options won't work once - // the application is running. - print('Configuring device...'); - await _configureForScreenshotTesting(); - - // TODO(matanlurey): Should we be using another instrumentation method? await runCommand( 'flutter', [ 'drive', - 'lib/blue_rectangle_main.dart', + 'lib/flutter_rendered_blue_rectangle_main.dart', // There are no reason to enable development flags for this test. // Disable them to work around flakiness issues, and in general just // make less things start up unnecessarily. @@ -56,7 +36,7 @@ Future runFlutterDriverAndroidTests() async { workingDirectory: path.join( 'dev', 'integration_tests', - 'android_driver_test', + 'native_driver_test', ), ); @@ -64,7 +44,7 @@ Future runFlutterDriverAndroidTests() async { 'flutter', [ 'drive', - 'lib/blue_orange_gradient_platform_view_main.dart', + 'lib/platform_view_blue_orange_gradient_main.dart', // There are no reason to enable development flags for this test. // Disable them to work around flakiness issues, and in general just // make less things start up unnecessarily. @@ -76,64 +56,27 @@ Future runFlutterDriverAndroidTests() async { workingDirectory: path.join( 'dev', 'integration_tests', - 'android_driver_test', + 'native_driver_test', + ), + ); + + await runCommand( + 'flutter', + [ + 'drive', + 'lib/external_texture_smiley_face_main.dart', + // There are no reason to enable development flags for this test. + // Disable them to work around flakiness issues, and in general just + // make less things start up unnecessarily. + '--no-dds', + '--no-enable-dart-profiling', + '--test-arguments=test', + '--test-arguments=--reporter=expanded', + ], + workingDirectory: path.join( + 'dev', + 'integration_tests', + 'native_driver_test', ), ); } - -// TODO(matanlurey): Move this code into flutter_driver instead of here. -Future _configureForScreenshotTesting() async { - // Disable confirmation for immersive mode. - final io.ProcessResult immersive = await _adb( - [ - 'shell', - 'settings', - 'put', - 'secure', - 'immersive_mode_confirmations', - 'confirmed', - ], - ); - - if (immersive.exitCode != 0) { - throw StateError('Failed to configure device: ${immersive.stderr}'); - } - - const Map settings = { - 'show_surface_updates': '1', - 'transition_animation_scale': '0', - 'window_animation_scale': '0', - 'animator_duration_scale': '0', - }; - - for (final MapEntry entry in settings.entries) { - final io.ProcessResult result = await _adb( - [ - 'shell', - 'settings', - 'put', - 'global', - entry.key, - entry.value, - ], - ); - - if (result.exitCode != 0) { - throw StateError('Failed to configure device: ${result.stderr}'); - } - } -} - -Future _adb( - List args, { - Encoding? stdoutEncoding = io.systemEncoding, -}) { - // TODO(matanlurey): Ideally we should specify the device target here. - return io.Process.run( - 'adb', - [ - ...args, - ], - stdoutEncoding: stdoutEncoding, - ); -} diff --git a/dev/integration_tests/android_driver_test/README.md b/dev/integration_tests/android_driver_test/README.md deleted file mode 100644 index f3ae358a3a..0000000000 --- a/dev/integration_tests/android_driver_test/README.md +++ /dev/null @@ -1,6 +0,0 @@ -# Flutter Driver Android Integration Tests - -This directory contains a sample app and tests that demonstrate how to use the -(experimental) _native_ Flutter Driver API to drive Flutter apps that run on -Android devices or emulators, interact with and capture screenshots of the app, -and compare the screenshots against golden images. diff --git a/dev/integration_tests/android_driver_test/android/build.gradle b/dev/integration_tests/android_driver_test/android/build.gradle deleted file mode 100644 index bedac9d2d4..0000000000 --- a/dev/integration_tests/android_driver_test/android/build.gradle +++ /dev/null @@ -1,34 +0,0 @@ -// Copyright 2014 The Flutter Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -// This file is auto generated. -// To update all the build.gradle files in the Flutter repo, -// See dev/tools/bin/generate_gradle_lockfiles.dart. - -allprojects { - repositories { - google() - mavenCentral() - } -} - -rootProject.buildDir = '../build' - -subprojects { - project.buildDir = "${rootProject.buildDir}/${project.name}" -} -subprojects { - project.evaluationDependsOn(':app') - dependencyLocking { - ignoredDependencies.add('io.flutter:*') - lockFile = file("${rootProject.projectDir}/project-${project.name}.lockfile") - if (!project.hasProperty('local-engine-repo')) { - lockAllConfigurations() - } - } -} - -tasks.register("clean", Delete) { - delete rootProject.buildDir -} diff --git a/dev/integration_tests/android_driver_test/test_driver/blue_orange_gradient_platform_view_main_test.dart b/dev/integration_tests/android_driver_test/test_driver/blue_orange_gradient_platform_view_main_test.dart deleted file mode 100644 index 3284547a54..0000000000 --- a/dev/integration_tests/android_driver_test/test_driver/blue_orange_gradient_platform_view_main_test.dart +++ /dev/null @@ -1,47 +0,0 @@ -// Copyright 2014 The Flutter 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:flutter_driver/flutter_driver.dart'; -import 'package:flutter_driver/src/native_driver.dart'; -import 'package:test/test.dart'; - -import '_flutter_goldens_fork.dart'; - -// TODO(matanlurey): This is done automatically by 'flutter test' but not by -// 'flutter drive'. If we get closer to shipping the native 'flutter drive' -// command, we should look into if 'flutter_test_config.dart', or a similar -// mechanism, can be used to configure this automatically. -void main() async { - await testExecutable(_main); -} - -Future _main() async { - // To generate golden files locally, uncomment the following line. - // autoUpdateGoldenFiles = true; - - late FlutterDriver flutterDriver; - late NativeDriver nativeDriver; - - setUpAll(() async { - flutterDriver = await FlutterDriver.connect(); - nativeDriver = await AndroidNativeDriver.connect(); - }); - - tearDownAll(() async { - await nativeDriver.close(); - await flutterDriver.close(); - }); - - test( - 'should screenshot and match a blue (top left) -> orange (bottom right) gradient', - () async { - await flutterDriver.waitFor(find.byType('AndroidView')); - await expectLater( - nativeDriver.screenshot(), - matchesGoldenFile('android_driver_test.BlueOrangeGradient.png'), - ); - }, - timeout: Timeout.none, - ); -} diff --git a/dev/integration_tests/android_driver_test/.metadata b/dev/integration_tests/native_driver_test/.metadata similarity index 59% rename from dev/integration_tests/android_driver_test/.metadata rename to dev/integration_tests/native_driver_test/.metadata index 4cff445185..1f1b3329b1 100644 --- a/dev/integration_tests/android_driver_test/.metadata +++ b/dev/integration_tests/native_driver_test/.metadata @@ -4,7 +4,7 @@ # This file should be version controlled and should not be manually edited. version: - revision: "6a346df51b97840ff2c06805e5482be28c6dd7c4" + revision: "6c380ffb86ea5048f0650629fe4f0e904afd50e1" channel: "[user-branch]" project_type: app @@ -13,11 +13,14 @@ project_type: app migration: platforms: - platform: root - create_revision: 6a346df51b97840ff2c06805e5482be28c6dd7c4 - base_revision: 6a346df51b97840ff2c06805e5482be28c6dd7c4 + create_revision: 6c380ffb86ea5048f0650629fe4f0e904afd50e1 + base_revision: 6c380ffb86ea5048f0650629fe4f0e904afd50e1 - platform: android - create_revision: 6a346df51b97840ff2c06805e5482be28c6dd7c4 - base_revision: 6a346df51b97840ff2c06805e5482be28c6dd7c4 + create_revision: 6c380ffb86ea5048f0650629fe4f0e904afd50e1 + base_revision: 6c380ffb86ea5048f0650629fe4f0e904afd50e1 + - platform: ios + create_revision: 6c380ffb86ea5048f0650629fe4f0e904afd50e1 + base_revision: 6c380ffb86ea5048f0650629fe4f0e904afd50e1 # User provided section diff --git a/dev/integration_tests/native_driver_test/README.md b/dev/integration_tests/native_driver_test/README.md new file mode 100644 index 0000000000..09c03721d5 --- /dev/null +++ b/dev/integration_tests/native_driver_test/README.md @@ -0,0 +1,37 @@ +# native_driver_test + +This directory contains a sample app and tests that demonstrate how to use the +(experimental) _native_ Flutter Driver API to drive Flutter apps that run on +Android or iOS devices or emulators, interact with and capture screenshots of +the app, and compare the screenshots against golden images. + +## Running the apps and tests + +Each `lib/{prefix}_main.dart` file is a standalone Flutter app that you can run +on an Android or iOS device or emulator: + +### `flutter_rendered_blue_rectangle` + +This app displays a full screen blue rectangle. It mostly serves as a test that +Flutter can run at all on the target device, and that the Flutter (native) +driver can take a screenshot and compare it to a golden image. If this app or +test fails, it's likely none of the other apps or tests will work either. + +```sh +# Run the app +$ flutter run lib/flutter_rendered_blue_rectangle_main.dart + +# Run the test +$ flutter drive lib/flutter_rendered_blue_rectangle_main.dart +``` + +Files of significance: + +- [Entrypoint](lib/flutter_rendered_blue_rectangle_main.dart) +- [Test](test_driver/flutter_rendered_blue_rectangle_main_test.dart) + +## Debugging tips + +- Use `flutter drive --keep-app-running` to keep the app running after the test. +- USe `flutter run` followed by `flutter drive --use-existing-app` for faster + test iterations. diff --git a/dev/integration_tests/android_driver_test/android/.gitignore b/dev/integration_tests/native_driver_test/android/.gitignore similarity index 100% rename from dev/integration_tests/android_driver_test/android/.gitignore rename to dev/integration_tests/native_driver_test/android/.gitignore diff --git a/dev/integration_tests/android_driver_test/android/app/build.gradle b/dev/integration_tests/native_driver_test/android/app/build.gradle similarity index 93% rename from dev/integration_tests/android_driver_test/android/app/build.gradle rename to dev/integration_tests/native_driver_test/android/app/build.gradle index 0f5328b878..c5b106e0c9 100644 --- a/dev/integration_tests/android_driver_test/android/app/build.gradle +++ b/dev/integration_tests/native_driver_test/android/app/build.gradle @@ -10,7 +10,7 @@ plugins { } android { - namespace = "com.example.android_driver_test" + namespace = "com.example.native_driver_test" compileSdk = flutter.compileSdkVersion ndkVersion = flutter.ndkVersion @@ -25,7 +25,7 @@ android { defaultConfig { // TODO: Specify your own unique Application ID (https://developer.android.com/studio/build/application-id.html). - applicationId = "com.example.android_driver_test" + applicationId = "com.example.native_driver_test" // You can update the following values to match your application needs. // For more information, see: https://flutter.dev/to/review-gradle-config. minSdk = flutter.minSdkVersion diff --git a/dev/integration_tests/android_driver_test/android/app/src/debug/AndroidManifest.xml b/dev/integration_tests/native_driver_test/android/app/src/debug/AndroidManifest.xml similarity index 100% rename from dev/integration_tests/android_driver_test/android/app/src/debug/AndroidManifest.xml rename to dev/integration_tests/native_driver_test/android/app/src/debug/AndroidManifest.xml diff --git a/dev/integration_tests/android_driver_test/android/app/src/main/AndroidManifest.xml b/dev/integration_tests/native_driver_test/android/app/src/main/AndroidManifest.xml similarity index 98% rename from dev/integration_tests/android_driver_test/android/app/src/main/AndroidManifest.xml rename to dev/integration_tests/native_driver_test/android/app/src/main/AndroidManifest.xml index bd4d55b4c8..c66599875d 100644 --- a/dev/integration_tests/android_driver_test/android/app/src/main/AndroidManifest.xml +++ b/dev/integration_tests/native_driver_test/android/app/src/main/AndroidManifest.xml @@ -4,7 +4,7 @@ found in the LICENSE file. --> { + result.success(null) + } + "tap_view" -> { + // Decode the selector. + val kind = call.argument("kind") + lateinit var selector: NativeSelector + when (kind) { + "byNativeAccessibilityLabel" -> { + selector = NativeSelector.ByContentDescription(call.argument("label")!!) + } + "byNativeIntegerId" -> { + selector = NativeSelector.ByViewId(call.argument("id")!!) + } + else -> { + result.error("INVALID_SELECTOR", "Not supported", kind) + return + } + } + + // Fail if not found. + val found = selector.find(activity.window.decorView.rootView) + if (found == null) { + result.error("VIEW_NOT_FOUND", "No view was found", call.arguments()) + return + } + + // Send tap event. + val x = found.x + found.width / 2 + val y = found.y + found.height / 2 + val downTime = SystemClock.uptimeMillis() + + val pressDown = MotionEvent.obtain(downTime, downTime, MotionEvent.ACTION_DOWN, x, y, 0) + found.dispatchTouchEvent(pressDown) + pressDown.recycle() + + val pressUp = MotionEvent.obtain(downTime, downTime, MotionEvent.ACTION_UP, x, y, 0) + found.dispatchTouchEvent(pressUp) + pressUp.recycle() + result.success(null) + } + else -> { + result.notImplemented() + } + } + } + + override fun onAttachedToActivity(binding: ActivityPluginBinding) { + activity = binding.activity + } + + override fun onDetachedFromActivityForConfigChanges() { + activity = null + } + + override fun onReattachedToActivityForConfigChanges(binding: ActivityPluginBinding) { + activity = binding.activity + } + + override fun onDetachedFromActivity() { + activity = null + } +} diff --git a/dev/integration_tests/native_driver_test/android/app/src/main/kotlin/com/example/native_driver_test/extensions/NativeSelector.kt b/dev/integration_tests/native_driver_test/android/app/src/main/kotlin/com/example/native_driver_test/extensions/NativeSelector.kt new file mode 100644 index 0000000000..1b4acb9daf --- /dev/null +++ b/dev/integration_tests/native_driver_test/android/app/src/main/kotlin/com/example/native_driver_test/extensions/NativeSelector.kt @@ -0,0 +1,57 @@ +// Copyright 2014 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +@file:Suppress("PackageName") + +package com.example.native_driver_test.extensions + +import android.view.View +import android.view.ViewGroup +import androidx.core.view.children + +// / Finds a native view using serialized data provided by a driver script. +sealed class NativeSelector { + // / Finds a native view by a {@code contentDescription} attribute. + data class ByContentDescription( + val contentDescription: String + ) : NativeSelector() { + override fun find(root: View): View? { + val found = ArrayList() + findRecursive(root, found) + if (found.isEmpty()) { + return null + } + if (found.size > 1) { + throw IllegalStateException("Expected a single matching view, got ${found.size}") + } + return found[0] + } + + private fun findRecursive( + parent: View, + found: ArrayList + ) { + if (contentDescription == parent.contentDescription) { + found.add(parent) + } + if (parent is ViewGroup) { + for (child in parent.children) { + findRecursive(child, found) + } + } + } + } + + // / Finds a native view by a {@code id} attribute. + data class ByViewId( + val id: Int + ) : NativeSelector() { + override fun find(root: View): View? = root.findViewById(id) + } + + // / Given a root view, returns the only view that matches this selector. + // / + // / If no view is found, returns null. + abstract fun find(root: View): View? +} diff --git a/dev/integration_tests/android_driver_test/android/app/src/main/kotlin/com/example/android_driver_test/BlueOrangeGradientPlatformViewFactory.kt b/dev/integration_tests/native_driver_test/android/app/src/main/kotlin/com/example/native_driver_test/fixtures/BlueOrangeGradientPlatformViewFactory.kt similarity index 97% rename from dev/integration_tests/android_driver_test/android/app/src/main/kotlin/com/example/android_driver_test/BlueOrangeGradientPlatformViewFactory.kt rename to dev/integration_tests/native_driver_test/android/app/src/main/kotlin/com/example/native_driver_test/fixtures/BlueOrangeGradientPlatformViewFactory.kt index 1e81046d55..a63095f77a 100644 --- a/dev/integration_tests/android_driver_test/android/app/src/main/kotlin/com/example/android_driver_test/BlueOrangeGradientPlatformViewFactory.kt +++ b/dev/integration_tests/native_driver_test/android/app/src/main/kotlin/com/example/native_driver_test/fixtures/BlueOrangeGradientPlatformViewFactory.kt @@ -4,7 +4,7 @@ @file:Suppress("PackageName") -package com.example.android_driver_test +package com.example.native_driver_test.fixtures import android.content.Context import android.graphics.Canvas diff --git a/dev/integration_tests/native_driver_test/android/app/src/main/kotlin/com/example/native_driver_test/fixtures/ChangingColorButtonPlatformViewFactory.kt b/dev/integration_tests/native_driver_test/android/app/src/main/kotlin/com/example/native_driver_test/fixtures/ChangingColorButtonPlatformViewFactory.kt new file mode 100644 index 0000000000..2121cb94f5 --- /dev/null +++ b/dev/integration_tests/native_driver_test/android/app/src/main/kotlin/com/example/native_driver_test/fixtures/ChangingColorButtonPlatformViewFactory.kt @@ -0,0 +1,68 @@ +// Copyright 2014 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +@file:Suppress("PackageName") + +package com.example.native_driver_test.fixtures + +import android.content.Context +import android.graphics.Canvas +import android.graphics.Color +import android.graphics.Paint +import android.view.View +import android.view.ViewGroup +import io.flutter.plugin.platform.PlatformView +import io.flutter.plugin.platform.PlatformViewFactory + +class ChangingColorButtonPlatformViewFactory : PlatformViewFactory(null) { + override fun create( + context: Context, + viewId: Int, + args: Any? + ): PlatformView = ChangingColorButtonPlatformView(context) +} + +private class ChangingColorButtonPlatformView( + context: Context +) : View(context), + PlatformView { + private val paintRed = + Paint().apply { + color = Color.RED + style = Paint.Style.FILL + } + private val paintBlue = + Paint().apply { + color = Color.BLUE + style = Paint.Style.FILL + } + + private var isBlue = false + + init { + layoutParams = + ViewGroup.LayoutParams( + ViewGroup.LayoutParams.MATCH_PARENT, + ViewGroup.LayoutParams.MATCH_PARENT + ) + + contentDescription = "Change color" + + setOnClickListener { + run { + isBlue = !isBlue + invalidate() // Force a redraw + } + } + } + + override fun getView(): View = this + + override fun dispose() {} + + override fun onDraw(canvas: Canvas) { + super.onDraw(canvas) + canvas.drawRect(0f, 0f, width.toFloat(), height.toFloat(), if (isBlue) paintBlue else paintRed) + } +} diff --git a/dev/integration_tests/native_driver_test/android/app/src/main/kotlin/com/example/native_driver_test/fixtures/SmileyFaceTexturePlugin.kt b/dev/integration_tests/native_driver_test/android/app/src/main/kotlin/com/example/native_driver_test/fixtures/SmileyFaceTexturePlugin.kt new file mode 100644 index 0000000000..d44c8b06c1 --- /dev/null +++ b/dev/integration_tests/native_driver_test/android/app/src/main/kotlin/com/example/native_driver_test/fixtures/SmileyFaceTexturePlugin.kt @@ -0,0 +1,105 @@ +// Copyright 2014 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +@file:Suppress("PackageName") + +package com.example.native_driver_test.fixtures + +import android.graphics.Color +import android.graphics.Paint +import android.os.Build +import android.view.Surface +import io.flutter.Log +import io.flutter.embedding.engine.plugins.FlutterPlugin +import io.flutter.embedding.engine.plugins.FlutterPlugin.FlutterPluginBinding +import io.flutter.plugin.common.MethodCall +import io.flutter.plugin.common.MethodChannel +import io.flutter.plugin.common.MethodChannel.MethodCallHandler +import io.flutter.view.TextureRegistry.SurfaceProducer + +class SmileyFaceTexturePlugin : + FlutterPlugin, + MethodCallHandler, + SurfaceProducer.Callback { + private val tag = "SmileyFaceTexturePlugin" + private lateinit var channel: MethodChannel + private lateinit var binding: FlutterPluginBinding + private lateinit var producer: SurfaceProducer + + private var surface: Surface? = null + + override fun onAttachedToEngine(binding: FlutterPluginBinding) { + this.binding = binding + channel = MethodChannel(binding.binaryMessenger, "smiley_face_texture") + channel.setMethodCallHandler(this) + producer = binding.textureRegistry.createSurfaceProducer() + producer.setCallback(this) + } + + override fun onDetachedFromEngine(binding: FlutterPluginBinding) { + channel.setMethodCallHandler(null) + producer.release() + } + + override fun onMethodCall( + call: MethodCall, + result: MethodChannel.Result + ) { + if (call.method == "initTexture") { + val height = call.argument("height") ?: 1 + val width = call.argument("width") ?: 1 + producer.setSize(width, height) + result.success(updateTexture()) + } else { + result.notImplemented() + } + } + + private fun updateTexture(): Long { + var surface = this.surface + if (surface == null) { + surface = producer.surface + this.surface = surface + } + drawOnSurface(producer.surface) + return producer.id() + } + + private fun drawOnSurface(surface: Surface) { + val canvas = + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) { + surface.lockHardwareCanvas() + } else { + surface.lockCanvas(null) + } + + // Yellow background + canvas.drawRGB(255, 230, 15) + + val paint = Paint() + paint.style = Paint.Style.FILL + + // Black eyes + paint.color = Color.BLACK + canvas.drawRect(200f, 200f, 250f, 250f, paint) // Left eye + canvas.drawRect(400f, 200f, 450f, 250f, paint) // Right eye + + // Black mouth + paint.color = Color.BLACK + canvas.drawRect(250f, 400f, 400f, 420f, paint) // Simple mouth + + surface.unlockCanvasAndPost(canvas) + } + + override fun onSurfaceCreated() { + Log.i(tag, "onSurfaceCreated()") + updateTexture() + } + + override fun onSurfaceDestroyed() { + Log.i(tag, "onSurfaceDestroyed()") + surface?.release() + surface = null + } +} diff --git a/dev/integration_tests/android_driver_test/android/app/src/main/res/drawable-v21/launch_background.xml b/dev/integration_tests/native_driver_test/android/app/src/main/res/drawable-v21/launch_background.xml similarity index 64% rename from dev/integration_tests/android_driver_test/android/app/src/main/res/drawable-v21/launch_background.xml rename to dev/integration_tests/native_driver_test/android/app/src/main/res/drawable-v21/launch_background.xml index 841324cf37..d633f6d97c 100644 --- a/dev/integration_tests/android_driver_test/android/app/src/main/res/drawable-v21/launch_background.xml +++ b/dev/integration_tests/native_driver_test/android/app/src/main/res/drawable-v21/launch_background.xml @@ -5,11 +5,4 @@ found in the LICENSE file. --> - - - diff --git a/dev/integration_tests/android_driver_test/android/app/src/main/res/drawable/launch_background.xml b/dev/integration_tests/native_driver_test/android/app/src/main/res/drawable/launch_background.xml similarity index 64% rename from dev/integration_tests/android_driver_test/android/app/src/main/res/drawable/launch_background.xml rename to dev/integration_tests/native_driver_test/android/app/src/main/res/drawable/launch_background.xml index 8703894be7..8a4bf7693f 100644 --- a/dev/integration_tests/android_driver_test/android/app/src/main/res/drawable/launch_background.xml +++ b/dev/integration_tests/native_driver_test/android/app/src/main/res/drawable/launch_background.xml @@ -5,11 +5,4 @@ found in the LICENSE file. --> - - - diff --git a/dev/integration_tests/android_driver_test/android/app/src/main/res/mipmap-hdpi/ic_launcher.png b/dev/integration_tests/native_driver_test/android/app/src/main/res/mipmap-hdpi/ic_launcher.png similarity index 100% rename from dev/integration_tests/android_driver_test/android/app/src/main/res/mipmap-hdpi/ic_launcher.png rename to dev/integration_tests/native_driver_test/android/app/src/main/res/mipmap-hdpi/ic_launcher.png diff --git a/dev/integration_tests/android_driver_test/android/app/src/main/res/mipmap-mdpi/ic_launcher.png b/dev/integration_tests/native_driver_test/android/app/src/main/res/mipmap-mdpi/ic_launcher.png similarity index 100% rename from dev/integration_tests/android_driver_test/android/app/src/main/res/mipmap-mdpi/ic_launcher.png rename to dev/integration_tests/native_driver_test/android/app/src/main/res/mipmap-mdpi/ic_launcher.png diff --git a/dev/integration_tests/android_driver_test/android/app/src/main/res/mipmap-xhdpi/ic_launcher.png b/dev/integration_tests/native_driver_test/android/app/src/main/res/mipmap-xhdpi/ic_launcher.png similarity index 100% rename from dev/integration_tests/android_driver_test/android/app/src/main/res/mipmap-xhdpi/ic_launcher.png rename to dev/integration_tests/native_driver_test/android/app/src/main/res/mipmap-xhdpi/ic_launcher.png diff --git a/dev/integration_tests/android_driver_test/android/app/src/main/res/mipmap-xxhdpi/ic_launcher.png b/dev/integration_tests/native_driver_test/android/app/src/main/res/mipmap-xxhdpi/ic_launcher.png similarity index 100% rename from dev/integration_tests/android_driver_test/android/app/src/main/res/mipmap-xxhdpi/ic_launcher.png rename to dev/integration_tests/native_driver_test/android/app/src/main/res/mipmap-xxhdpi/ic_launcher.png diff --git a/dev/integration_tests/android_driver_test/android/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png b/dev/integration_tests/native_driver_test/android/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png similarity index 100% rename from dev/integration_tests/android_driver_test/android/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png rename to dev/integration_tests/native_driver_test/android/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png diff --git a/dev/integration_tests/android_driver_test/android/app/src/main/res/values-night/styles.xml b/dev/integration_tests/native_driver_test/android/app/src/main/res/values-night/styles.xml similarity index 100% rename from dev/integration_tests/android_driver_test/android/app/src/main/res/values-night/styles.xml rename to dev/integration_tests/native_driver_test/android/app/src/main/res/values-night/styles.xml diff --git a/dev/integration_tests/android_driver_test/android/app/src/main/res/values/styles.xml b/dev/integration_tests/native_driver_test/android/app/src/main/res/values/styles.xml similarity index 100% rename from dev/integration_tests/android_driver_test/android/app/src/main/res/values/styles.xml rename to dev/integration_tests/native_driver_test/android/app/src/main/res/values/styles.xml diff --git a/dev/integration_tests/android_driver_test/android/app/src/profile/AndroidManifest.xml b/dev/integration_tests/native_driver_test/android/app/src/profile/AndroidManifest.xml similarity index 100% rename from dev/integration_tests/android_driver_test/android/app/src/profile/AndroidManifest.xml rename to dev/integration_tests/native_driver_test/android/app/src/profile/AndroidManifest.xml diff --git a/dev/integration_tests/native_driver_test/android/build.gradle b/dev/integration_tests/native_driver_test/android/build.gradle new file mode 100644 index 0000000000..96ac13cda7 --- /dev/null +++ b/dev/integration_tests/native_driver_test/android/build.gradle @@ -0,0 +1,22 @@ +// Copyright 2014 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +allprojects { + repositories { + google() + mavenCentral() + } +} + +rootProject.buildDir = "../build" +subprojects { + project.buildDir = "${rootProject.buildDir}/${project.name}" +} +subprojects { + project.evaluationDependsOn(":app") +} + +tasks.register("clean", Delete) { + delete rootProject.buildDir +} diff --git a/dev/integration_tests/android_driver_test/android/gradle.properties b/dev/integration_tests/native_driver_test/android/gradle.properties similarity index 100% rename from dev/integration_tests/android_driver_test/android/gradle.properties rename to dev/integration_tests/native_driver_test/android/gradle.properties diff --git a/dev/integration_tests/android_driver_test/android/gradle/wrapper/gradle-wrapper.properties b/dev/integration_tests/native_driver_test/android/gradle/wrapper/gradle-wrapper.properties similarity index 100% rename from dev/integration_tests/android_driver_test/android/gradle/wrapper/gradle-wrapper.properties rename to dev/integration_tests/native_driver_test/android/gradle/wrapper/gradle-wrapper.properties diff --git a/dev/integration_tests/android_driver_test/android/settings.gradle b/dev/integration_tests/native_driver_test/android/settings.gradle similarity index 59% rename from dev/integration_tests/android_driver_test/android/settings.gradle rename to dev/integration_tests/native_driver_test/android/settings.gradle index 73a4cf75b6..9f47aeeecb 100644 --- a/dev/integration_tests/android_driver_test/android/settings.gradle +++ b/dev/integration_tests/native_driver_test/android/settings.gradle @@ -2,10 +2,6 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -// This file is auto generated. -// To update all the settings.gradle files in the Flutter repo, -// See dev/tools/bin/generate_gradle_lockfiles.dart. - pluginManagement { def flutterSdkPath = { def properties = new Properties() @@ -13,10 +9,9 @@ pluginManagement { def flutterSdkPath = properties.getProperty("flutter.sdk") assert flutterSdkPath != null, "flutter.sdk not set in local.properties" return flutterSdkPath - } - settings.ext.flutterSdkPath = flutterSdkPath() + }() - includeBuild("${settings.ext.flutterSdkPath}/packages/flutter_tools/gradle") + includeBuild("$flutterSdkPath/packages/flutter_tools/gradle") repositories { google() @@ -25,17 +20,10 @@ pluginManagement { } } -buildscript { - dependencyLocking { - lockFile = file("${rootProject.projectDir}/buildscript-gradle.lockfile") - lockAllConfigurations() - } -} - plugins { id "dev.flutter.flutter-plugin-loader" version "1.0.0" id "com.android.application" version "8.1.0" apply false - id "org.jetbrains.kotlin.android" version "1.7.10" apply false + id "org.jetbrains.kotlin.android" version "1.8.22" apply false } include ":app" diff --git a/dev/integration_tests/native_driver_test/ios/.gitignore b/dev/integration_tests/native_driver_test/ios/.gitignore new file mode 100644 index 0000000000..7a7f9873ad --- /dev/null +++ b/dev/integration_tests/native_driver_test/ios/.gitignore @@ -0,0 +1,34 @@ +**/dgph +*.mode1v3 +*.mode2v3 +*.moved-aside +*.pbxuser +*.perspectivev3 +**/*sync/ +.sconsign.dblite +.tags* +**/.vagrant/ +**/DerivedData/ +Icon? +**/Pods/ +**/.symlinks/ +profile +xcuserdata +**/.generated/ +Flutter/App.framework +Flutter/Flutter.framework +Flutter/Flutter.podspec +Flutter/Generated.xcconfig +Flutter/ephemeral/ +Flutter/app.flx +Flutter/app.zip +Flutter/flutter_assets/ +Flutter/flutter_export_environment.sh +ServiceDefinitions.json +Runner/GeneratedPluginRegistrant.* + +# Exceptions to above rules. +!default.mode1v3 +!default.mode2v3 +!default.pbxuser +!default.perspectivev3 diff --git a/dev/integration_tests/native_driver_test/ios/Flutter/AppFrameworkInfo.plist b/dev/integration_tests/native_driver_test/ios/Flutter/AppFrameworkInfo.plist new file mode 100644 index 0000000000..7c56964006 --- /dev/null +++ b/dev/integration_tests/native_driver_test/ios/Flutter/AppFrameworkInfo.plist @@ -0,0 +1,26 @@ + + + + + CFBundleDevelopmentRegion + en + CFBundleExecutable + App + CFBundleIdentifier + io.flutter.flutter.app + CFBundleInfoDictionaryVersion + 6.0 + CFBundleName + App + CFBundlePackageType + FMWK + CFBundleShortVersionString + 1.0 + CFBundleSignature + ???? + CFBundleVersion + 1.0 + MinimumOSVersion + 12.0 + + diff --git a/dev/integration_tests/native_driver_test/ios/Flutter/Debug.xcconfig b/dev/integration_tests/native_driver_test/ios/Flutter/Debug.xcconfig new file mode 100644 index 0000000000..592ceee85b --- /dev/null +++ b/dev/integration_tests/native_driver_test/ios/Flutter/Debug.xcconfig @@ -0,0 +1 @@ +#include "Generated.xcconfig" diff --git a/dev/integration_tests/native_driver_test/ios/Flutter/Release.xcconfig b/dev/integration_tests/native_driver_test/ios/Flutter/Release.xcconfig new file mode 100644 index 0000000000..592ceee85b --- /dev/null +++ b/dev/integration_tests/native_driver_test/ios/Flutter/Release.xcconfig @@ -0,0 +1 @@ +#include "Generated.xcconfig" diff --git a/dev/integration_tests/native_driver_test/ios/Runner.xcodeproj/project.pbxproj b/dev/integration_tests/native_driver_test/ios/Runner.xcodeproj/project.pbxproj new file mode 100644 index 0000000000..8ca05f97f7 --- /dev/null +++ b/dev/integration_tests/native_driver_test/ios/Runner.xcodeproj/project.pbxproj @@ -0,0 +1,619 @@ +// !$*UTF8*$! +{ + archiveVersion = 1; + classes = { + }; + objectVersion = 54; + objects = { + +/* Begin PBXBuildFile section */ + 1498D2341E8E89220040F4C2 /* GeneratedPluginRegistrant.m in Sources */ = {isa = PBXBuildFile; fileRef = 1498D2331E8E89220040F4C2 /* GeneratedPluginRegistrant.m */; }; + 331C808B294A63AB00263BE5 /* RunnerTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 331C807B294A618700263BE5 /* RunnerTests.swift */; }; + 3B3967161E833CAA004F5970 /* AppFrameworkInfo.plist in Resources */ = {isa = PBXBuildFile; fileRef = 3B3967151E833CAA004F5970 /* AppFrameworkInfo.plist */; }; + 74858FAF1ED2DC5600515810 /* AppDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = 74858FAE1ED2DC5600515810 /* AppDelegate.swift */; }; + 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 PBXContainerItemProxy section */ + 331C8085294A63A400263BE5 /* PBXContainerItemProxy */ = { + isa = PBXContainerItemProxy; + containerPortal = 97C146E61CF9000F007C117D /* Project object */; + proxyType = 1; + remoteGlobalIDString = 97C146ED1CF9000F007C117D; + remoteInfo = Runner; + }; +/* End PBXContainerItemProxy section */ + +/* Begin PBXCopyFilesBuildPhase section */ + 9705A1C41CF9048500538489 /* Embed Frameworks */ = { + isa = PBXCopyFilesBuildPhase; + buildActionMask = 2147483647; + dstPath = ""; + dstSubfolderSpec = 10; + files = ( + ); + 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 = ""; }; + 331C807B294A618700263BE5 /* RunnerTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = RunnerTests.swift; sourceTree = ""; }; + 331C8081294A63A400263BE5 /* RunnerTests.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = RunnerTests.xctest; sourceTree = BUILT_PRODUCTS_DIR; }; + 3B3967151E833CAA004F5970 /* AppFrameworkInfo.plist */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.xml; name = AppFrameworkInfo.plist; path = Flutter/AppFrameworkInfo.plist; sourceTree = ""; }; + 74858FAD1ED2DC5600515810 /* Runner-Bridging-Header.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = "Runner-Bridging-Header.h"; sourceTree = ""; }; + 74858FAE1ED2DC5600515810 /* AppDelegate.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = AppDelegate.swift; sourceTree = ""; }; + 7AFA3C8E1D35360C0083082E /* Release.xcconfig */ = {isa = PBXFileReference; lastKnownFileType = text.xcconfig; name = Release.xcconfig; path = Flutter/Release.xcconfig; 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 = ""; }; + 97C146EE1CF9000F007C117D /* Runner.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = Runner.app; sourceTree = BUILT_PRODUCTS_DIR; }; + 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 = ( + ); + runOnlyForDeploymentPostprocessing = 0; + }; +/* End PBXFrameworksBuildPhase section */ + +/* Begin PBXGroup section */ + 331C8082294A63A400263BE5 /* RunnerTests */ = { + isa = PBXGroup; + children = ( + 331C807B294A618700263BE5 /* RunnerTests.swift */, + ); + path = RunnerTests; + sourceTree = ""; + }; + 9740EEB11CF90186004384FC /* Flutter */ = { + isa = PBXGroup; + children = ( + 3B3967151E833CAA004F5970 /* AppFrameworkInfo.plist */, + 9740EEB21CF90195004384FC /* Debug.xcconfig */, + 7AFA3C8E1D35360C0083082E /* Release.xcconfig */, + 9740EEB31CF90195004384FC /* Generated.xcconfig */, + ); + name = Flutter; + sourceTree = ""; + }; + 97C146E51CF9000F007C117D = { + isa = PBXGroup; + children = ( + 9740EEB11CF90186004384FC /* Flutter */, + 97C146F01CF9000F007C117D /* Runner */, + 97C146EF1CF9000F007C117D /* Products */, + 331C8082294A63A400263BE5 /* RunnerTests */, + ); + sourceTree = ""; + }; + 97C146EF1CF9000F007C117D /* Products */ = { + isa = PBXGroup; + children = ( + 97C146EE1CF9000F007C117D /* Runner.app */, + 331C8081294A63A400263BE5 /* RunnerTests.xctest */, + ); + name = Products; + sourceTree = ""; + }; + 97C146F01CF9000F007C117D /* Runner */ = { + isa = PBXGroup; + children = ( + 97C146FA1CF9000F007C117D /* Main.storyboard */, + 97C146FD1CF9000F007C117D /* Assets.xcassets */, + 97C146FF1CF9000F007C117D /* LaunchScreen.storyboard */, + 97C147021CF9000F007C117D /* Info.plist */, + 1498D2321E8E86230040F4C2 /* GeneratedPluginRegistrant.h */, + 1498D2331E8E89220040F4C2 /* GeneratedPluginRegistrant.m */, + 74858FAE1ED2DC5600515810 /* AppDelegate.swift */, + 74858FAD1ED2DC5600515810 /* Runner-Bridging-Header.h */, + ); + path = Runner; + sourceTree = ""; + }; +/* End PBXGroup section */ + +/* Begin PBXNativeTarget section */ + 331C8080294A63A400263BE5 /* RunnerTests */ = { + isa = PBXNativeTarget; + buildConfigurationList = 331C8087294A63A400263BE5 /* Build configuration list for PBXNativeTarget "RunnerTests" */; + buildPhases = ( + 331C807D294A63A400263BE5 /* Sources */, + 331C807F294A63A400263BE5 /* Resources */, + ); + buildRules = ( + ); + dependencies = ( + 331C8086294A63A400263BE5 /* PBXTargetDependency */, + ); + name = RunnerTests; + productName = RunnerTests; + productReference = 331C8081294A63A400263BE5 /* RunnerTests.xctest */; + productType = "com.apple.product-type.bundle.unit-test"; + }; + 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 = { + BuildIndependentTargetsInParallel = YES; + LastUpgradeCheck = 1510; + ORGANIZATIONNAME = ""; + TargetAttributes = { + 331C8080294A63A400263BE5 = { + CreatedOnToolsVersion = 14.0; + TestTargetID = 97C146ED1CF9000F007C117D; + }; + 97C146ED1CF9000F007C117D = { + CreatedOnToolsVersion = 7.3.1; + LastSwiftMigration = 1100; + }; + }; + }; + buildConfigurationList = 97C146E91CF9000F007C117D /* Build configuration list for PBXProject "Runner" */; + compatibilityVersion = "Xcode 9.3"; + developmentRegion = en; + hasScannedForEncodings = 0; + knownRegions = ( + en, + Base, + ); + mainGroup = 97C146E51CF9000F007C117D; + productRefGroup = 97C146EF1CF9000F007C117D /* Products */; + projectDirPath = ""; + projectRoot = ""; + targets = ( + 97C146ED1CF9000F007C117D /* Runner */, + 331C8080294A63A400263BE5 /* RunnerTests */, + ); + }; +/* End PBXProject section */ + +/* Begin PBXResourcesBuildPhase section */ + 331C807F294A63A400263BE5 /* Resources */ = { + isa = PBXResourcesBuildPhase; + buildActionMask = 2147483647; + files = ( + ); + runOnlyForDeploymentPostprocessing = 0; + }; + 97C146EC1CF9000F007C117D /* Resources */ = { + isa = PBXResourcesBuildPhase; + buildActionMask = 2147483647; + files = ( + 97C147011CF9000F007C117D /* LaunchScreen.storyboard in Resources */, + 3B3967161E833CAA004F5970 /* AppFrameworkInfo.plist in Resources */, + 97C146FE1CF9000F007C117D /* Assets.xcassets in Resources */, + 97C146FC1CF9000F007C117D /* Main.storyboard in Resources */, + ); + runOnlyForDeploymentPostprocessing = 0; + }; +/* End PBXResourcesBuildPhase section */ + +/* Begin PBXShellScriptBuildPhase section */ + 3B06AD1E1E4923F5004D2608 /* Thin Binary */ = { + isa = PBXShellScriptBuildPhase; + alwaysOutOfDate = 1; + buildActionMask = 2147483647; + files = ( + ); + inputPaths = ( + "${TARGET_BUILD_DIR}/${INFOPLIST_PATH}", + ); + name = "Thin Binary"; + outputPaths = ( + ); + runOnlyForDeploymentPostprocessing = 0; + shellPath = /bin/sh; + shellScript = "/bin/sh \"$FLUTTER_ROOT/packages/flutter_tools/bin/xcode_backend.sh\" embed_and_thin"; + }; + 9740EEB61CF901F6004384FC /* Run Script */ = { + isa = PBXShellScriptBuildPhase; + alwaysOutOfDate = 1; + 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 */ + 331C807D294A63A400263BE5 /* Sources */ = { + isa = PBXSourcesBuildPhase; + buildActionMask = 2147483647; + files = ( + 331C808B294A63AB00263BE5 /* RunnerTests.swift in Sources */, + ); + runOnlyForDeploymentPostprocessing = 0; + }; + 97C146EA1CF9000F007C117D /* Sources */ = { + isa = PBXSourcesBuildPhase; + buildActionMask = 2147483647; + files = ( + 74858FAF1ED2DC5600515810 /* AppDelegate.swift in Sources */, + 1498D2341E8E89220040F4C2 /* GeneratedPluginRegistrant.m in Sources */, + ); + runOnlyForDeploymentPostprocessing = 0; + }; +/* End PBXSourcesBuildPhase section */ + +/* Begin PBXTargetDependency section */ + 331C8086294A63A400263BE5 /* PBXTargetDependency */ = { + isa = PBXTargetDependency; + target = 97C146ED1CF9000F007C117D /* Runner */; + targetProxy = 331C8085294A63A400263BE5 /* PBXContainerItemProxy */; + }; +/* End PBXTargetDependency 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 */ + 249021D3217E4FDB00AE95B9 /* Profile */ = { + isa = XCBuildConfiguration; + buildSettings = { + ALWAYS_SEARCH_USER_PATHS = NO; + ASSETCATALOG_COMPILER_GENERATE_SWIFT_ASSET_SYMBOL_EXTENSIONS = YES; + 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_DEPRECATED_OBJC_IMPLEMENTATIONS = 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_IMPLICIT_RETAIN_SELF = 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; + ENABLE_USER_SCRIPT_SANDBOXING = NO; + 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 = 12.0; + MTL_ENABLE_DEBUG_INFO = NO; + SDKROOT = iphoneos; + SUPPORTED_PLATFORMS = iphoneos; + TARGETED_DEVICE_FAMILY = "1,2"; + VALIDATE_PRODUCT = YES; + }; + name = Profile; + }; + 249021D4217E4FDB00AE95B9 /* Profile */ = { + isa = XCBuildConfiguration; + baseConfigurationReference = 7AFA3C8E1D35360C0083082E /* Release.xcconfig */; + buildSettings = { + ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; + CLANG_ENABLE_MODULES = YES; + CURRENT_PROJECT_VERSION = "$(FLUTTER_BUILD_NUMBER)"; + DEVELOPMENT_TEAM = QA3N6G4XTH; + ENABLE_BITCODE = NO; + INFOPLIST_FILE = Runner/Info.plist; + LD_RUNPATH_SEARCH_PATHS = ( + "$(inherited)", + "@executable_path/Frameworks", + ); + PRODUCT_BUNDLE_IDENTIFIER = com.example.nativeDriverTest; + PRODUCT_NAME = "$(TARGET_NAME)"; + SWIFT_OBJC_BRIDGING_HEADER = "Runner/Runner-Bridging-Header.h"; + SWIFT_VERSION = 5.0; + VERSIONING_SYSTEM = "apple-generic"; + }; + name = Profile; + }; + 331C8088294A63A400263BE5 /* Debug */ = { + isa = XCBuildConfiguration; + buildSettings = { + BUNDLE_LOADER = "$(TEST_HOST)"; + CODE_SIGN_STYLE = Automatic; + CURRENT_PROJECT_VERSION = 1; + GENERATE_INFOPLIST_FILE = YES; + MARKETING_VERSION = 1.0; + PRODUCT_BUNDLE_IDENTIFIER = com.example.nativeDriverTest.RunnerTests; + PRODUCT_NAME = "$(TARGET_NAME)"; + SWIFT_ACTIVE_COMPILATION_CONDITIONS = DEBUG; + SWIFT_OPTIMIZATION_LEVEL = "-Onone"; + SWIFT_VERSION = 5.0; + TEST_HOST = "$(BUILT_PRODUCTS_DIR)/Runner.app/$(BUNDLE_EXECUTABLE_FOLDER_PATH)/Runner"; + }; + name = Debug; + }; + 331C8089294A63A400263BE5 /* Release */ = { + isa = XCBuildConfiguration; + buildSettings = { + BUNDLE_LOADER = "$(TEST_HOST)"; + CODE_SIGN_STYLE = Automatic; + CURRENT_PROJECT_VERSION = 1; + GENERATE_INFOPLIST_FILE = YES; + MARKETING_VERSION = 1.0; + PRODUCT_BUNDLE_IDENTIFIER = com.example.nativeDriverTest.RunnerTests; + PRODUCT_NAME = "$(TARGET_NAME)"; + SWIFT_VERSION = 5.0; + TEST_HOST = "$(BUILT_PRODUCTS_DIR)/Runner.app/$(BUNDLE_EXECUTABLE_FOLDER_PATH)/Runner"; + }; + name = Release; + }; + 331C808A294A63A400263BE5 /* Profile */ = { + isa = XCBuildConfiguration; + buildSettings = { + BUNDLE_LOADER = "$(TEST_HOST)"; + CODE_SIGN_STYLE = Automatic; + CURRENT_PROJECT_VERSION = 1; + GENERATE_INFOPLIST_FILE = YES; + MARKETING_VERSION = 1.0; + PRODUCT_BUNDLE_IDENTIFIER = com.example.nativeDriverTest.RunnerTests; + PRODUCT_NAME = "$(TARGET_NAME)"; + SWIFT_VERSION = 5.0; + TEST_HOST = "$(BUILT_PRODUCTS_DIR)/Runner.app/$(BUNDLE_EXECUTABLE_FOLDER_PATH)/Runner"; + }; + name = Profile; + }; + 97C147031CF9000F007C117D /* Debug */ = { + isa = XCBuildConfiguration; + buildSettings = { + ALWAYS_SEARCH_USER_PATHS = NO; + ASSETCATALOG_COMPILER_GENERATE_SWIFT_ASSET_SYMBOL_EXTENSIONS = YES; + 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_DEPRECATED_OBJC_IMPLEMENTATIONS = 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_IMPLICIT_RETAIN_SELF = 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; + ENABLE_USER_SCRIPT_SANDBOXING = NO; + 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 = 12.0; + MTL_ENABLE_DEBUG_INFO = YES; + ONLY_ACTIVE_ARCH = YES; + SDKROOT = iphoneos; + TARGETED_DEVICE_FAMILY = "1,2"; + }; + name = Debug; + }; + 97C147041CF9000F007C117D /* Release */ = { + isa = XCBuildConfiguration; + buildSettings = { + ALWAYS_SEARCH_USER_PATHS = NO; + ASSETCATALOG_COMPILER_GENERATE_SWIFT_ASSET_SYMBOL_EXTENSIONS = YES; + 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_DEPRECATED_OBJC_IMPLEMENTATIONS = 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_IMPLICIT_RETAIN_SELF = 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; + ENABLE_USER_SCRIPT_SANDBOXING = NO; + 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 = 12.0; + MTL_ENABLE_DEBUG_INFO = NO; + SDKROOT = iphoneos; + SUPPORTED_PLATFORMS = iphoneos; + SWIFT_COMPILATION_MODE = wholemodule; + SWIFT_OPTIMIZATION_LEVEL = "-O"; + TARGETED_DEVICE_FAMILY = "1,2"; + VALIDATE_PRODUCT = YES; + }; + name = Release; + }; + 97C147061CF9000F007C117D /* Debug */ = { + isa = XCBuildConfiguration; + baseConfigurationReference = 9740EEB21CF90195004384FC /* Debug.xcconfig */; + buildSettings = { + ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; + CLANG_ENABLE_MODULES = YES; + CURRENT_PROJECT_VERSION = "$(FLUTTER_BUILD_NUMBER)"; + DEVELOPMENT_TEAM = QA3N6G4XTH; + ENABLE_BITCODE = NO; + INFOPLIST_FILE = Runner/Info.plist; + LD_RUNPATH_SEARCH_PATHS = ( + "$(inherited)", + "@executable_path/Frameworks", + ); + PRODUCT_BUNDLE_IDENTIFIER = com.example.nativeDriverTest; + PRODUCT_NAME = "$(TARGET_NAME)"; + SWIFT_OBJC_BRIDGING_HEADER = "Runner/Runner-Bridging-Header.h"; + SWIFT_OPTIMIZATION_LEVEL = "-Onone"; + SWIFT_VERSION = 5.0; + VERSIONING_SYSTEM = "apple-generic"; + }; + name = Debug; + }; + 97C147071CF9000F007C117D /* Release */ = { + isa = XCBuildConfiguration; + baseConfigurationReference = 7AFA3C8E1D35360C0083082E /* Release.xcconfig */; + buildSettings = { + ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; + CLANG_ENABLE_MODULES = YES; + CURRENT_PROJECT_VERSION = "$(FLUTTER_BUILD_NUMBER)"; + DEVELOPMENT_TEAM = QA3N6G4XTH; + ENABLE_BITCODE = NO; + INFOPLIST_FILE = Runner/Info.plist; + LD_RUNPATH_SEARCH_PATHS = ( + "$(inherited)", + "@executable_path/Frameworks", + ); + PRODUCT_BUNDLE_IDENTIFIER = com.example.nativeDriverTest; + PRODUCT_NAME = "$(TARGET_NAME)"; + SWIFT_OBJC_BRIDGING_HEADER = "Runner/Runner-Bridging-Header.h"; + SWIFT_VERSION = 5.0; + VERSIONING_SYSTEM = "apple-generic"; + }; + name = Release; + }; +/* End XCBuildConfiguration section */ + +/* Begin XCConfigurationList section */ + 331C8087294A63A400263BE5 /* Build configuration list for PBXNativeTarget "RunnerTests" */ = { + isa = XCConfigurationList; + buildConfigurations = ( + 331C8088294A63A400263BE5 /* Debug */, + 331C8089294A63A400263BE5 /* Release */, + 331C808A294A63A400263BE5 /* Profile */, + ); + defaultConfigurationIsVisible = 0; + defaultConfigurationName = Release; + }; + 97C146E91CF9000F007C117D /* Build configuration list for PBXProject "Runner" */ = { + isa = XCConfigurationList; + buildConfigurations = ( + 97C147031CF9000F007C117D /* Debug */, + 97C147041CF9000F007C117D /* Release */, + 249021D3217E4FDB00AE95B9 /* Profile */, + ); + defaultConfigurationIsVisible = 0; + defaultConfigurationName = Release; + }; + 97C147051CF9000F007C117D /* Build configuration list for PBXNativeTarget "Runner" */ = { + isa = XCConfigurationList; + buildConfigurations = ( + 97C147061CF9000F007C117D /* Debug */, + 97C147071CF9000F007C117D /* Release */, + 249021D4217E4FDB00AE95B9 /* Profile */, + ); + defaultConfigurationIsVisible = 0; + defaultConfigurationName = Release; + }; +/* End XCConfigurationList section */ + }; + rootObject = 97C146E61CF9000F007C117D /* Project object */; +} diff --git a/dev/integration_tests/native_driver_test/ios/Runner.xcodeproj/project.xcworkspace/contents.xcworkspacedata b/dev/integration_tests/native_driver_test/ios/Runner.xcodeproj/project.xcworkspace/contents.xcworkspacedata new file mode 100644 index 0000000000..919434a625 --- /dev/null +++ b/dev/integration_tests/native_driver_test/ios/Runner.xcodeproj/project.xcworkspace/contents.xcworkspacedata @@ -0,0 +1,7 @@ + + + + + diff --git a/dev/integration_tests/native_driver_test/ios/Runner.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist b/dev/integration_tests/native_driver_test/ios/Runner.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist new file mode 100644 index 0000000000..18d981003d --- /dev/null +++ b/dev/integration_tests/native_driver_test/ios/Runner.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist @@ -0,0 +1,8 @@ + + + + + IDEDidComputeMac32BitWarning + + + diff --git a/dev/integration_tests/native_driver_test/ios/Runner.xcodeproj/project.xcworkspace/xcshareddata/WorkspaceSettings.xcsettings b/dev/integration_tests/native_driver_test/ios/Runner.xcodeproj/project.xcworkspace/xcshareddata/WorkspaceSettings.xcsettings new file mode 100644 index 0000000000..f9b0d7c5ea --- /dev/null +++ b/dev/integration_tests/native_driver_test/ios/Runner.xcodeproj/project.xcworkspace/xcshareddata/WorkspaceSettings.xcsettings @@ -0,0 +1,8 @@ + + + + + PreviewsEnabled + + + diff --git a/dev/integration_tests/native_driver_test/ios/Runner.xcodeproj/xcshareddata/xcschemes/Runner.xcscheme b/dev/integration_tests/native_driver_test/ios/Runner.xcodeproj/xcshareddata/xcschemes/Runner.xcscheme new file mode 100644 index 0000000000..8e3ca5dfe1 --- /dev/null +++ b/dev/integration_tests/native_driver_test/ios/Runner.xcodeproj/xcshareddata/xcschemes/Runner.xcscheme @@ -0,0 +1,98 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/dev/integration_tests/native_driver_test/ios/Runner.xcworkspace/contents.xcworkspacedata b/dev/integration_tests/native_driver_test/ios/Runner.xcworkspace/contents.xcworkspacedata new file mode 100644 index 0000000000..1d526a16ed --- /dev/null +++ b/dev/integration_tests/native_driver_test/ios/Runner.xcworkspace/contents.xcworkspacedata @@ -0,0 +1,7 @@ + + + + + diff --git a/dev/integration_tests/native_driver_test/ios/Runner.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist b/dev/integration_tests/native_driver_test/ios/Runner.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist new file mode 100644 index 0000000000..18d981003d --- /dev/null +++ b/dev/integration_tests/native_driver_test/ios/Runner.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist @@ -0,0 +1,8 @@ + + + + + IDEDidComputeMac32BitWarning + + + diff --git a/dev/integration_tests/native_driver_test/ios/Runner.xcworkspace/xcshareddata/WorkspaceSettings.xcsettings b/dev/integration_tests/native_driver_test/ios/Runner.xcworkspace/xcshareddata/WorkspaceSettings.xcsettings new file mode 100644 index 0000000000..f9b0d7c5ea --- /dev/null +++ b/dev/integration_tests/native_driver_test/ios/Runner.xcworkspace/xcshareddata/WorkspaceSettings.xcsettings @@ -0,0 +1,8 @@ + + + + + PreviewsEnabled + + + diff --git a/dev/integration_tests/native_driver_test/ios/Runner/AppDelegate.swift b/dev/integration_tests/native_driver_test/ios/Runner/AppDelegate.swift new file mode 100644 index 0000000000..58f3ea9b92 --- /dev/null +++ b/dev/integration_tests/native_driver_test/ios/Runner/AppDelegate.swift @@ -0,0 +1,17 @@ +// Copyright 2014 The Flutter 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 Flutter +import UIKit + +@main +@objc class AppDelegate: FlutterAppDelegate { + override func application( + _ application: UIApplication, + didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]? + ) -> Bool { + GeneratedPluginRegistrant.register(with: self) + return super.application(application, didFinishLaunchingWithOptions: launchOptions) + } +} diff --git a/dev/integration_tests/native_driver_test/ios/Runner/Assets.xcassets/AppIcon.appiconset/Contents.json b/dev/integration_tests/native_driver_test/ios/Runner/Assets.xcassets/AppIcon.appiconset/Contents.json new file mode 100644 index 0000000000..94bc3d9f63 --- /dev/null +++ b/dev/integration_tests/native_driver_test/ios/Runner/Assets.xcassets/AppIcon.appiconset/Contents.json @@ -0,0 +1,7 @@ +{ + "images" : [], + "info" : { + "version" : 1, + "author" : "xcode" + } +} diff --git a/dev/integration_tests/native_driver_test/ios/Runner/Assets.xcassets/LaunchImage.imageset/Contents.json b/dev/integration_tests/native_driver_test/ios/Runner/Assets.xcassets/LaunchImage.imageset/Contents.json new file mode 100644 index 0000000000..94bc3d9f63 --- /dev/null +++ b/dev/integration_tests/native_driver_test/ios/Runner/Assets.xcassets/LaunchImage.imageset/Contents.json @@ -0,0 +1,7 @@ +{ + "images" : [], + "info" : { + "version" : 1, + "author" : "xcode" + } +} diff --git a/dev/integration_tests/native_driver_test/ios/Runner/Base.lproj/LaunchScreen.storyboard b/dev/integration_tests/native_driver_test/ios/Runner/Base.lproj/LaunchScreen.storyboard new file mode 100644 index 0000000000..f2e259c7c9 --- /dev/null +++ b/dev/integration_tests/native_driver_test/ios/Runner/Base.lproj/LaunchScreen.storyboard @@ -0,0 +1,37 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/dev/integration_tests/native_driver_test/ios/Runner/Base.lproj/Main.storyboard b/dev/integration_tests/native_driver_test/ios/Runner/Base.lproj/Main.storyboard new file mode 100644 index 0000000000..f3c28516fb --- /dev/null +++ b/dev/integration_tests/native_driver_test/ios/Runner/Base.lproj/Main.storyboard @@ -0,0 +1,26 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/dev/integration_tests/native_driver_test/ios/Runner/Info.plist b/dev/integration_tests/native_driver_test/ios/Runner/Info.plist new file mode 100644 index 0000000000..240bbf6750 --- /dev/null +++ b/dev/integration_tests/native_driver_test/ios/Runner/Info.plist @@ -0,0 +1,49 @@ + + + + + CFBundleDevelopmentRegion + $(DEVELOPMENT_LANGUAGE) + CFBundleDisplayName + Native Driver Test + CFBundleExecutable + $(EXECUTABLE_NAME) + CFBundleIdentifier + $(PRODUCT_BUNDLE_IDENTIFIER) + CFBundleInfoDictionaryVersion + 6.0 + CFBundleName + native_driver_test + CFBundlePackageType + APPL + CFBundleShortVersionString + $(FLUTTER_BUILD_NAME) + CFBundleSignature + ???? + CFBundleVersion + $(FLUTTER_BUILD_NUMBER) + LSRequiresIPhoneOS + + UILaunchStoryboardName + LaunchScreen + UIMainStoryboardFile + Main + UISupportedInterfaceOrientations + + UIInterfaceOrientationPortrait + UIInterfaceOrientationLandscapeLeft + UIInterfaceOrientationLandscapeRight + + UISupportedInterfaceOrientations~ipad + + UIInterfaceOrientationPortrait + UIInterfaceOrientationPortraitUpsideDown + UIInterfaceOrientationLandscapeLeft + UIInterfaceOrientationLandscapeRight + + CADisableMinimumFrameDurationOnPhone + + UIApplicationSupportsIndirectInputEvents + + + diff --git a/dev/integration_tests/native_driver_test/ios/Runner/Runner-Bridging-Header.h b/dev/integration_tests/native_driver_test/ios/Runner/Runner-Bridging-Header.h new file mode 100644 index 0000000000..95b7baf386 --- /dev/null +++ b/dev/integration_tests/native_driver_test/ios/Runner/Runner-Bridging-Header.h @@ -0,0 +1,5 @@ +// Copyright 2014 The Flutter 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 "GeneratedPluginRegistrant.h" diff --git a/dev/integration_tests/native_driver_test/lib/external_texture_smiley_face_main.dart b/dev/integration_tests/native_driver_test/lib/external_texture_smiley_face_main.dart new file mode 100644 index 0000000000..9a215346cd --- /dev/null +++ b/dev/integration_tests/native_driver_test/lib/external_texture_smiley_face_main.dart @@ -0,0 +1,59 @@ +// Copyright 2014 The Flutter 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/material.dart'; +import 'package:flutter/services.dart'; +import 'package:flutter_driver/driver_extension.dart'; +import 'package:native_driver/extension.dart'; + +import 'src/allow_list_devices.dart'; + +const MethodChannel _channel = MethodChannel('smiley_face_texture'); +Future _fetchTexture(int width, int height) async { + final int? result = await _channel.invokeMethod( + 'initTexture', + { + 'width': width, + 'height': height, + }, + ); + return result!; +} + +void main() async { + ensureAndroidOrIosDevice(); + enableFlutterDriverExtension(commands: [ + nativeDriverCommands, + ]); + + // Run on full screen. + SystemChrome.setEnabledSystemUIMode(SystemUiMode.immersive); + + // Fetch the texture ID. + final Future textureId = _fetchTexture(512, 512); + runApp(MainApp(textureId)); +} + +final class MainApp extends StatelessWidget { + const MainApp(this.textureId, {super.key}); + final Future textureId; + + @override + Widget build(BuildContext context) { + return MaterialApp( + debugShowCheckedModeBanner: false, + home: FutureBuilder( + future: textureId, + builder: (BuildContext context, AsyncSnapshot snapshot) { + if (snapshot.hasData) { + return Texture(textureId: snapshot.data!); + } + return const CircularProgressIndicator(); + }, + ), + ); + } +} diff --git a/dev/integration_tests/android_driver_test/lib/blue_rectangle_main.dart b/dev/integration_tests/native_driver_test/lib/flutter_rendered_blue_rectangle_main.dart similarity index 62% rename from dev/integration_tests/android_driver_test/lib/blue_rectangle_main.dart rename to dev/integration_tests/native_driver_test/lib/flutter_rendered_blue_rectangle_main.dart index 261f79498d..e111a7b835 100644 --- a/dev/integration_tests/android_driver_test/lib/blue_rectangle_main.dart +++ b/dev/integration_tests/native_driver_test/lib/flutter_rendered_blue_rectangle_main.dart @@ -2,18 +2,21 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -import 'dart:io' as io; - -import 'package:flutter/foundation.dart'; import 'package:flutter/material.dart'; +import 'package:flutter/services.dart'; import 'package:flutter_driver/driver_extension.dart'; +import 'package:native_driver/extension.dart'; + +import 'src/allow_list_devices.dart'; void main() { - enableFlutterDriverExtension(); + ensureAndroidOrIosDevice(); + enableFlutterDriverExtension(commands: [ + nativeDriverCommands, + ]); - if (kIsWeb || !io.Platform.isAndroid) { - throw UnsupportedError('This app should only run on Android devices.'); - } + // Run on full screen. + SystemChrome.setEnabledSystemUIMode(SystemUiMode.immersive); runApp(const MainApp()); } diff --git a/dev/integration_tests/android_driver_test/lib/blue_orange_gradient_platform_view_main.dart b/dev/integration_tests/native_driver_test/lib/platform_view_blue_orange_gradient_main.dart similarity index 61% rename from dev/integration_tests/android_driver_test/lib/blue_orange_gradient_platform_view_main.dart rename to dev/integration_tests/native_driver_test/lib/platform_view_blue_orange_gradient_main.dart index 75829c782d..bc933dce84 100644 --- a/dev/integration_tests/android_driver_test/lib/blue_orange_gradient_platform_view_main.dart +++ b/dev/integration_tests/native_driver_test/lib/platform_view_blue_orange_gradient_main.dart @@ -2,19 +2,21 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -import 'dart:io' as io; - -import 'package:flutter/foundation.dart'; import 'package:flutter/material.dart'; +import 'package:flutter/services.dart'; import 'package:flutter_driver/driver_extension.dart'; +import 'package:native_driver/extension.dart'; -void main() { - enableFlutterDriverExtension(); +import 'src/allow_list_devices.dart'; - if (kIsWeb || !io.Platform.isAndroid) { - throw UnsupportedError('This app should only run on Android devices.'); - } +void main() async { + ensureAndroidOrIosDevice(); + enableFlutterDriverExtension(commands: [ + nativeDriverCommands, + ]); + // Run on full screen. + await SystemChrome.setEnabledSystemUIMode(SystemUiMode.immersive); runApp(const MainApp()); } diff --git a/dev/integration_tests/native_driver_test/lib/platform_view_tap_color_change_main.dart b/dev/integration_tests/native_driver_test/lib/platform_view_tap_color_change_main.dart new file mode 100644 index 0000000000..2f03cc6fed --- /dev/null +++ b/dev/integration_tests/native_driver_test/lib/platform_view_tap_color_change_main.dart @@ -0,0 +1,33 @@ +// Copyright 2014 The Flutter 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:flutter/material.dart'; +import 'package:flutter/services.dart'; +import 'package:flutter_driver/driver_extension.dart'; +import 'package:native_driver/extension.dart'; + +import 'src/allow_list_devices.dart'; + +void main() async { + ensureAndroidOrIosDevice(); + enableFlutterDriverExtension(commands: [ + nativeDriverCommands, + ]); + + // Run on full screen. + await SystemChrome.setEnabledSystemUIMode(SystemUiMode.immersive); + runApp(const MainApp()); +} + +final class MainApp extends StatelessWidget { + const MainApp({super.key}); + + @override + Widget build(BuildContext context) { + return const MaterialApp( + debugShowCheckedModeBanner: false, + home: AndroidView(viewType: 'changing_color_button_platform_view'), + ); + } +} diff --git a/dev/integration_tests/native_driver_test/lib/src/allow_list_devices.dart b/dev/integration_tests/native_driver_test/lib/src/allow_list_devices.dart new file mode 100644 index 0000000000..b1f11353ad --- /dev/null +++ b/dev/integration_tests/native_driver_test/lib/src/allow_list_devices.dart @@ -0,0 +1,18 @@ +// Copyright 2014 The Flutter 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:io' as io; + +import 'package:flutter/foundation.dart'; + +/// Throws an [UnsupportedError] if the current platform is not Android or iOS. +void ensureAndroidOrIosDevice() { + if (kIsWeb || (!io.Platform.isAndroid && !io.Platform.isIOS)) { + throw UnsupportedError( + 'This app should only run on Android or iOS devices. It uses native ' + 'plugins that are not developed for other platforms, and would need to ' + 'be adapted to run on other platforms. See the README.md for details.', + ); + } +} diff --git a/dev/integration_tests/android_driver_test/pubspec.yaml b/dev/integration_tests/native_driver_test/pubspec.yaml similarity index 94% rename from dev/integration_tests/android_driver_test/pubspec.yaml rename to dev/integration_tests/native_driver_test/pubspec.yaml index 18d6dc4e29..0dfc45e9bd 100644 --- a/dev/integration_tests/android_driver_test/pubspec.yaml +++ b/dev/integration_tests/native_driver_test/pubspec.yaml @@ -1,10 +1,12 @@ -name: android_driver_test +name: native_driver_test publish_to: none environment: - sdk: ^3.6.0-77.0.dev + sdk: ^3.6.0-216.0.dev dependencies: + native_driver: + path: ../../tools/native_driver flutter: sdk: flutter flutter_driver: @@ -19,6 +21,8 @@ dependencies: material_color_utilities: 0.11.1 # THIS LINE IS AUTOGENERATED - TO UPDATE USE "flutter update-packages --force-upgrade" meta: 1.15.0 # THIS LINE IS AUTOGENERATED - TO UPDATE USE "flutter update-packages --force-upgrade" path: 1.9.0 # THIS LINE IS AUTOGENERATED - TO UPDATE USE "flutter update-packages --force-upgrade" + platform: 3.1.5 # THIS LINE IS AUTOGENERATED - TO UPDATE USE "flutter update-packages --force-upgrade" + process: 5.0.2 # THIS LINE IS AUTOGENERATED - TO UPDATE USE "flutter update-packages --force-upgrade" source_span: 1.10.0 # THIS LINE IS AUTOGENERATED - TO UPDATE USE "flutter update-packages --force-upgrade" stack_trace: 1.11.1 # THIS LINE IS AUTOGENERATED - TO UPDATE USE "flutter update-packages --force-upgrade" stream_channel: 2.1.2 # THIS LINE IS AUTOGENERATED - TO UPDATE USE "flutter update-packages --force-upgrade" @@ -31,10 +35,6 @@ dependencies: webdriver: 3.0.3 # THIS LINE IS AUTOGENERATED - TO UPDATE USE "flutter update-packages --force-upgrade" dev_dependencies: - flutter_goldens: - sdk: flutter - platform: 3.1.5 - process: 5.0.2 test: 1.25.8 _fe_analyzer_shared: 74.0.0 # THIS LINE IS AUTOGENERATED - TO UPDATE USE "flutter update-packages --force-upgrade" diff --git a/dev/integration_tests/android_driver_test/test_driver/.gitignore b/dev/integration_tests/native_driver_test/test_driver/.gitignore similarity index 100% rename from dev/integration_tests/android_driver_test/test_driver/.gitignore rename to dev/integration_tests/native_driver_test/test_driver/.gitignore diff --git a/packages/flutter_driver/lib/src/native_driver.dart b/dev/integration_tests/native_driver_test/test_driver/_luci_skia_gold_prelude.dart similarity index 53% rename from packages/flutter_driver/lib/src/native_driver.dart rename to dev/integration_tests/native_driver_test/test_driver/_luci_skia_gold_prelude.dart index 01442610ab..2485438509 100644 --- a/packages/flutter_driver/lib/src/native_driver.dart +++ b/dev/integration_tests/native_driver_test/test_driver/_luci_skia_gold_prelude.dart @@ -2,11 +2,7 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -@experimental -library; +import 'dart:io' as io; -import 'package:meta/meta.dart'; - -export 'native/android.dart'; -export 'native/driver.dart'; -export 'native/goldens.dart'; +/// Whether the current environment is LUCI. +bool get isLuci => io.Platform.environment['LUCI_CI'] == 'True'; diff --git a/dev/integration_tests/native_driver_test/test_driver/external_texture_smiley_face_main_test.dart b/dev/integration_tests/native_driver_test/test_driver/external_texture_smiley_face_main_test.dart new file mode 100644 index 0000000000..e1ca7f7ca7 --- /dev/null +++ b/dev/integration_tests/native_driver_test/test_driver/external_texture_smiley_face_main_test.dart @@ -0,0 +1,54 @@ +// Copyright 2014 The Flutter 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:flutter_driver/flutter_driver.dart'; +import 'package:native_driver/native_driver.dart'; +import 'package:native_driver/skia_gold.dart'; +import 'package:test/test.dart'; + +import '_luci_skia_gold_prelude.dart'; + +void main() async { + // To test the golden file generation locally, comment out the following line. + // autoUpdateGoldenFiles = true; + + const String appName = 'com.example.native_driver_test'; + late final FlutterDriver flutterDriver; + late final NativeDriver nativeDriver; + + setUpAll(() async { + if (isLuci) { + await enableSkiaGoldComparator(); + } + flutterDriver = await FlutterDriver.connect(); + nativeDriver = await AndroidNativeDriver.connect(flutterDriver); + await nativeDriver.configureForScreenshotTesting(); + }); + + tearDownAll(() async { + await nativeDriver.close(); + await flutterDriver.close(); + }); + + test('should screenshot and match an external smiley face texture', () async { + await flutterDriver.waitFor(find.byType('Texture')); + + // On Android: Background the app, trim memory, and restore the app. + if (nativeDriver case final AndroidNativeDriver nativeDriver) { + print('Backgrounding the app, trimming memory, and resuming the app.'); + await nativeDriver.backgroundApp(); + + print('Trimming memory.'); + await nativeDriver.simulateLowMemory(appName: appName); + + print('Resuming the app.'); + await nativeDriver.resumeApp(appName: appName); + } + + await expectLater( + nativeDriver.screenshot(), + matchesGoldenFile('external_texture_smiley_face.android.png'), + ); + }, timeout: Timeout.none); +} diff --git a/dev/integration_tests/android_driver_test/test_driver/blue_rectangle_main_test.dart b/dev/integration_tests/native_driver_test/test_driver/flutter_rendered_blue_rectangle_main_test.dart similarity index 50% rename from dev/integration_tests/android_driver_test/test_driver/blue_rectangle_main_test.dart rename to dev/integration_tests/native_driver_test/test_driver/flutter_rendered_blue_rectangle_main_test.dart index 49e681368e..a820d44116 100644 --- a/dev/integration_tests/android_driver_test/test_driver/blue_rectangle_main_test.dart +++ b/dev/integration_tests/native_driver_test/test_driver/flutter_rendered_blue_rectangle_main_test.dart @@ -3,29 +3,26 @@ // found in the LICENSE file. import 'package:flutter_driver/flutter_driver.dart'; -import 'package:flutter_driver/src/native_driver.dart'; +import 'package:native_driver/native_driver.dart'; +import 'package:native_driver/skia_gold.dart'; import 'package:test/test.dart'; -import '_flutter_goldens_fork.dart'; +import '_luci_skia_gold_prelude.dart'; -// TODO(matanlurey): This is done automatically by 'flutter test' but not by -// 'flutter drive'. If we get closer to shipping the native 'flutter drive' -// command, we should look into if 'flutter_test_config.dart', or a similar -// mechanism, can be used to configure this automatically. void main() async { - await testExecutable(_main); -} - -Future _main() async { - // To generate golden files locally, uncomment the following line. + // To test the golden file generation locally, comment out the following line. // autoUpdateGoldenFiles = true; - late FlutterDriver flutterDriver; - late NativeDriver nativeDriver; + late final FlutterDriver flutterDriver; + late final NativeDriver nativeDriver; setUpAll(() async { + if (isLuci) { + await enableSkiaGoldComparator(); + } flutterDriver = await FlutterDriver.connect(); - nativeDriver = await AndroidNativeDriver.connect(); + nativeDriver = await AndroidNativeDriver.connect(flutterDriver); + await nativeDriver.configureForScreenshotTesting(); }); tearDownAll(() async { @@ -37,7 +34,7 @@ Future _main() async { await flutterDriver.waitFor(find.byType('DecoratedBox')); await expectLater( nativeDriver.screenshot(), - matchesGoldenFile('android_driver_test.BlueRectangle.png'), + matchesGoldenFile('fluttered_rendered_blue_rectangle.android.png'), ); }, timeout: Timeout.none); } diff --git a/dev/integration_tests/native_driver_test/test_driver/platform_view_blue_orange_gradient_main_test.dart b/dev/integration_tests/native_driver_test/test_driver/platform_view_blue_orange_gradient_main_test.dart new file mode 100644 index 0000000000..52e4239905 --- /dev/null +++ b/dev/integration_tests/native_driver_test/test_driver/platform_view_blue_orange_gradient_main_test.dart @@ -0,0 +1,61 @@ +// Copyright 2014 The Flutter 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:flutter_driver/flutter_driver.dart'; +import 'package:native_driver/native_driver.dart'; +import 'package:native_driver/skia_gold.dart'; +import 'package:test/test.dart'; + +import '_luci_skia_gold_prelude.dart'; + +void main() async { + // To test the golden file generation locally, comment out the following line. + // autoUpdateGoldenFiles = true; + + late final FlutterDriver flutterDriver; + late final NativeDriver nativeDriver; + + setUpAll(() async { + if (isLuci) { + await enableSkiaGoldComparator(); + } + flutterDriver = await FlutterDriver.connect(); + nativeDriver = await AndroidNativeDriver.connect(flutterDriver); + await nativeDriver.configureForScreenshotTesting(); + }); + + tearDownAll(() async { + await nativeDriver.close(); + await flutterDriver.close(); + }); + + test('should screenshot and match a blue -> orange gradient', () async { + await flutterDriver.waitFor(find.byType('AndroidView')); + await expectLater( + nativeDriver.screenshot(), + matchesGoldenFile( + 'platform_view_blue_orange_gradient_portrait.android.png', + ), + ); + }, timeout: Timeout.none); + + test('should rotate landscape and screenshot the gradient', () async { + await flutterDriver.waitFor(find.byType('AndroidView')); + await nativeDriver.rotateToLandscape(); + await expectLater( + nativeDriver.screenshot(), + matchesGoldenFile( + 'platform_view_blue_orange_gradient_landscape.android.png', + ), + ); + + await nativeDriver.rotateResetDefault(); + await expectLater( + nativeDriver.screenshot(), + matchesGoldenFile( + 'platform_view_blue_orange_gradient_portrait_post_rotation.android.png', + ), + ); + }, timeout: Timeout.none); +} diff --git a/dev/integration_tests/native_driver_test/test_driver/platform_view_tap_color_change_main_test.dart b/dev/integration_tests/native_driver_test/test_driver/platform_view_tap_color_change_main_test.dart new file mode 100644 index 0000000000..fcbc964adf --- /dev/null +++ b/dev/integration_tests/native_driver_test/test_driver/platform_view_tap_color_change_main_test.dart @@ -0,0 +1,50 @@ +// Copyright 2014 The Flutter 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:flutter_driver/flutter_driver.dart'; +import 'package:native_driver/native_driver.dart'; +import 'package:native_driver/skia_gold.dart'; +import 'package:test/test.dart'; + +import '_luci_skia_gold_prelude.dart'; + +void main() async { + // To test the golden file generation locally, comment out the following line. + // autoUpdateGoldenFiles = true; + + late final FlutterDriver flutterDriver; + late final NativeDriver nativeDriver; + + setUpAll(() async { + if (isLuci) { + await enableSkiaGoldComparator(); + } + flutterDriver = await FlutterDriver.connect(); + nativeDriver = await AndroidNativeDriver.connect(flutterDriver); + await nativeDriver.configureForScreenshotTesting(); + }); + + tearDownAll(() async { + await nativeDriver.close(); + await flutterDriver.close(); + }); + + test('should screenshot a rectangle that becomes blue after a tap', () async { + await flutterDriver.waitFor(find.byType('AndroidView')); + await expectLater( + nativeDriver.screenshot(), + matchesGoldenFile( + 'platform_view_tap_color_change_initial.android.png', + ), + ); + + await nativeDriver.tap(const ByNativeAccessibilityLabel('Change color')); + await expectLater( + nativeDriver.screenshot(), + matchesGoldenFile( + 'platform_view_tap_color_change_tapped.android.png', + ), + ); + }, timeout: Timeout.none); +} diff --git a/dev/tools/native_driver/README.md b/dev/tools/native_driver/README.md new file mode 100644 index 0000000000..d604596e86 --- /dev/null +++ b/dev/tools/native_driver/README.md @@ -0,0 +1,21 @@ +# Flutter Native Driver + +This a minimal library on top of `flutter_driver` that provides extensions for +interacting with the native platform, to otherwise perform actions that are not +possible purely through Flutter Driver, and would want to run as an _external_ +test (run on the host, not on the device): + +- Take a screenshot, including of _native_ widgets (platform views, textures) +- Tap on a native widget +- Rotate the device +- (Android Only) Background an app and send a "trim memory" signal to the device + +> [!NOTE] +> +> While this library runs on Flutter's own CI, and is used to test Flutter's +> Platform Views, it is not officially supported as an external API, and may +> change or be removed at any time. We recommend you use existing testing +> infrastructure, such as: +> +> - [Integration Test](https://docs.flutter.dev/testing/integration-tests) +> - [Patrol](https://github.com/leancodepl/patrol) diff --git a/dev/tools/native_driver/lib/extension.dart b/dev/tools/native_driver/lib/extension.dart new file mode 100644 index 0000000000..c5aa409a6c --- /dev/null +++ b/dev/tools/native_driver/lib/extension.dart @@ -0,0 +1,123 @@ +// Copyright 2014 The Flutter 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:convert'; + +import 'package:flutter/services.dart' as flt; +import 'package:flutter_driver/driver_extension.dart'; +import 'package:flutter_driver/flutter_driver.dart'; +import 'package:flutter_test/flutter_test.dart'; + +import 'src/common.dart'; + +/// An extension that forwards [NativeCommand]s to a registered plugin. +const CommandExtension nativeDriverCommands = NativeDriverCommandExtension( + flt.MethodChannel('native_driver'), +); + +/// An extension that forwards [NativeCommand]s to a registered plugin. +/// +/// This extension is used to communicate with a platform plugin, and relays +/// [NativeCommand]s to the platform plugin, and resolves the result as a +/// [NativeResult], both thin wrappers around a `Map` (JSON +/// compatible object). +/// +/// A singleton default instance of this class is [nativeDriverCommands]. +final class NativeDriverCommandExtension implements CommandExtension { + /// Creates a new [NativeDriverCommandExtension] with the given [channel]. + /// + /// Can be used in exceptional cases where a custom [MethodChannel] is needed; + /// otherwise, use the singleton [nativeDriverCommands]. + const NativeDriverCommandExtension(this._channel); + final flt.MethodChannel _channel; + + @override + Future call( + Command command, + WidgetController prober, + CreateFinderFactory finderFactory, + CommandHandlerFactory handlerFactory, + ) async { + if (command is! NativeCommand) { + throw ArgumentError.value(command, 'command', 'Expected a NativeCommand'); + } + if (await _builtInCall(command.method) case final Result result) { + return result; + } + final Object? result = await _channel.invokeMethod( + command.method, + command.arguments, + ); + if (result == null) { + return const _MethodChannelResult({}); + } + if (result is! Map) { + throw ArgumentError.value( + result, + 'result', + 'Expected a Map', + ); + } + return _MethodChannelResult(result); + } + + // While these could have been implemented in native code, they are already + // available as engine-bundled platform plugins, so using them directly + // reduces the amount of code to be written and maintained. + Future _builtInCall(String method) async { + switch (method) { + case 'rotate_landscape': + await flt.SystemChrome.setPreferredOrientations( + const [flt.DeviceOrientation.landscapeLeft], + ); + return Result.empty; + case 'rotate_default': + await flt.SystemChrome.setPreferredOrientations( + const [], + ); + return Result.empty; + default: + return null; + } + } + + @override + String get commandKind => 'native_driver'; + + @override + NativeCommand deserialize( + Map params, + DeserializeFinderFactory finderFactory, + DeserializeCommandFactory commandFactory, + ) { + final String? method = params['method']; + if (method == null) { + throw ArgumentError.value(params, 'params', 'Missing method'); + } + final String? arguments = params['arguments']; + final Map? decoded; + if (arguments == null) { + decoded = null; + } else { + final Object? intermediate = json.decode(arguments); + if (intermediate is! Map) { + throw ArgumentError.value( + arguments, + 'arguments', + 'Expected a Map', + ); + } + decoded = intermediate; + } + return NativeCommand(method, arguments: decoded); + } +} + +final class _MethodChannelResult implements Result { + const _MethodChannelResult(this._json); + final Map _json; + + @override + Map toJson() => _json; +} diff --git a/dev/tools/native_driver/lib/native_driver.dart b/dev/tools/native_driver/lib/native_driver.dart new file mode 100644 index 0000000000..eae0297c99 --- /dev/null +++ b/dev/tools/native_driver/lib/native_driver.dart @@ -0,0 +1,27 @@ +// Copyright 2014 The Flutter 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' as io; +import 'dart:typed_data'; + +import 'package:flutter_driver/flutter_driver.dart'; + +import 'package:matcher/matcher.dart'; + +// Similar to `flutter_test`, we ignore the implementation import. +// ignore: implementation_imports +import 'package:matcher/src/expect/async_matcher.dart'; + +import 'package:path/path.dart' as path; +import 'package:test_api/test_api.dart'; + +import 'src/common.dart'; + +export 'src/backend/android.dart' show AndroidDeviceTarget, AndroidNativeDriver; +export 'src/common.dart' + show ByNativeAccessibilityLabel, ByNativeIntegerId, NativeFinder; + +part 'src/driver.dart'; +part 'src/goldens.dart'; diff --git a/dev/integration_tests/android_driver_test/test_driver/_flutter_goldens_fork.dart b/dev/tools/native_driver/lib/skia_gold.dart similarity index 84% rename from dev/integration_tests/android_driver_test/test_driver/_flutter_goldens_fork.dart rename to dev/tools/native_driver/lib/skia_gold.dart index e453ba3eae..95a072db0c 100644 --- a/dev/integration_tests/android_driver_test/test_driver/_flutter_goldens_fork.dart +++ b/dev/tools/native_driver/lib/skia_gold.dart @@ -12,21 +12,28 @@ import 'dart:io' as io; import 'dart:typed_data'; import 'package:file/local.dart'; -import 'package:flutter_driver/src/native_driver.dart'; import 'package:flutter_goldens/skia_client.dart'; import 'package:path/path.dart' as path; import 'package:platform/platform.dart'; import 'package:process/process.dart'; +import 'native_driver.dart'; + const LocalFileSystem _localFs = LocalFileSystem(); const String _kGoldctlKey = 'GOLDCTL'; const String _kGoldctlPresubmitKey = 'GOLD_TRYJOB'; -// TODO(matanlurey): Refactor flutter_goldens to just re-use that code instead. -Future testExecutable( - FutureOr Function() testMain, { - String? namePrefix, -}) async { +/// Configures [goldenFileComparator] to use Skia Gold (i.e. on CI). +/// +/// Requires that the `GOLDCTL` environment variable is set. +/// +/// If the `GOLD_TRYJOB` environment variable is set, the test will be run in +/// presubmit mode; that is, the test will not fail if the comparison fails. +/// See +/// for more information. +/// +/// May optionally provide a [namePrefix] to be used when uploading images. +Future enableSkiaGoldComparator({String? namePrefix}) async { assert( goldenFileComparator is NaiveLocalFileComparator, 'The flutter_goldens_fork library should be used from a *_test.dart file ' @@ -34,11 +41,10 @@ Future testExecutable( 'that the correct comparator is used for the current test environment.', ); if (!io.Platform.environment.containsKey(_kGoldctlKey)) { - io.stderr.writeln( - 'Environment variable $_kGoldctlKey is not set. Assuming this is a local ' - 'test run and will not upload results to Skia Gold.', + throw StateError( + 'Environment variable $_kGoldctlKey is not set. ' + 'Set it to use Skia Gold.', ); - return testMain(); } final io.Directory tmpDir = io.Directory.systemTemp.createTempSync( 'android_driver_test', @@ -67,7 +73,6 @@ Future testExecutable( namePrefix: namePrefix, isPresubmit: isPresubmit, ); - return testMain(); } final class _GoldenFileComparator extends GoldenFileComparator { diff --git a/dev/tools/native_driver/lib/src/backend/android.dart b/dev/tools/native_driver/lib/src/backend/android.dart new file mode 100644 index 0000000000..7a4cab1dc2 --- /dev/null +++ b/dev/tools/native_driver/lib/src/backend/android.dart @@ -0,0 +1,6 @@ +// Copyright 2014 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +export 'android/adb.dart'; +export 'android/driver.dart'; diff --git a/dev/tools/native_driver/lib/src/backend/android/adb.dart b/dev/tools/native_driver/lib/src/backend/android/adb.dart new file mode 100644 index 0000000000..34740481ad --- /dev/null +++ b/dev/tools/native_driver/lib/src/backend/android/adb.dart @@ -0,0 +1,318 @@ +// Copyright 2014 The Flutter 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:io' as io; +import 'dart:typed_data'; + +import 'package:meta/meta.dart'; +import 'package:process/process.dart'; + +/// A minimal wrapper around the `adb` command-line tool. +@internal +class Adb { + const Adb._(this._prefixArgs, this._proccess); + + /// Creates a new `adb` command runner that uses the `adb` command-line tool. + /// + /// If [adbPath] is not provided, the `adb` command is assumed to be in the + /// system's PATH. + /// + /// If [target] is not provided, the target is assumed to be the only running + /// emulator or connected device. + /// + /// For testing, [processManager] can be provided to mock the process manager. + static Future create({ + String? adbPath, + AndroidDeviceTarget? target, + @visibleForTesting ProcessManager? processManager, + }) async { + target ??= const AndroidDeviceTarget.onlyEmulatorOrDevice(); + final String tool = adbPath ?? 'adb'; + final Adb adb = Adb._( + [tool, ...target._toAdbArgs()], + processManager ?? const LocalProcessManager(), + ); + final (bool connected, String? error) = await adb.isDeviceConnected(); + if (!connected) { + throw StateError('No device connected: $error'); + } + return adb; + } + + Future _runString(List args) async { + final io.ProcessResult result = await _proccess.run( + [ + ..._prefixArgs, + ...args, + ], + ); + return AdbStringResult( + result.stdout as String, + exitCode: result.exitCode, + stderr: result.stderr as String, + ); + } + + Future _runBinary(List args) async { + final io.ProcessResult result = await _proccess.run( + [ + ..._prefixArgs, + ...args, + ], + stdoutEncoding: null, + ); + return AdbBinaryResult( + result.stdout as Uint8List, + exitCode: result.exitCode, + stderr: result.stderr as String, + ); + } + + final List _prefixArgs; + final ProcessManager _proccess; + + /// Returns whether the device is currently connected. + /// + /// Returns a tuple of a boolean indicating whether the device is connected + /// and an error message if the device is not connected. If the device is + /// connected, the error message is `null`. + Future<(bool connected, String? error)> isDeviceConnected() async { + final AdbStringResult result = await _runString([ + 'shell', + 'echo', + 'connected', + ]); + if (result.exitCode != 0) { + return (false, result.stderr); + } else { + return (true, null); + } + } + + /// Takes a screenshot of the device. + Future screencap() async { + final AdbBinaryResult result = await _runBinary([ + 'exec-out', + 'screencap', + '-p', + ]); + if (result.exitCode != 0) { + throw StateError('Failed to take screenshot: ${result.stderr}'); + } + return result.stdout; + } + + /// Taps on the screen at the given [x] and [y] coordinates. + Future tap(int x, int y) async { + final AdbStringResult result = await _runString([ + 'shell', + 'input', + 'tap', + '$x', + '$y', + ]); + if (result.exitCode != 0) { + throw StateError('Failed to tap at $x, $y: ${result.stderr}'); + } + } + + /// Sends the device to the home screen. + Future sendToHome() async { + final AdbStringResult result = await _runString([ + 'shell', + 'input', + 'keyevent', + 'KEYCODE_HOME', + ]); + if (result.exitCode != 0) { + throw StateError('Failed to send to home: ${result.stderr}'); + } + } + + /// Simulate low memory conditions on the device. + Future trimMemory({required String appName}) async { + final AdbStringResult result = await _runString([ + 'shell', + 'am', + 'send-trim-memory', + appName, + 'MODERATE', + ]); + if (result.exitCode != 0) { + throw StateError('Failed to simulate low memory: ${result.stderr}'); + } + } + + /// Resume a backgrounded app (i.e. after [sendToHome]). + Future resumeApp({ + required String appName, + String activityName = '.MainActivity', + }) async { + final AdbStringResult result = await _runString([ + 'shell', + 'am', + 'start', + '-n', + '$appName/$activityName', + ]); + if (result.exitCode != 0) { + throw StateError('Failed to resume app: ${result.stderr}'); + } + } + + /// Disable confirnations for immersive mode. + Future disableImmersiveModeConfirmations() async { + final AdbStringResult result = await _runString([ + 'shell', + 'settings', + 'put', + 'secure', + 'immersive_mode_confirmations', + 'confirmed', + ]); + if (result.exitCode != 0) { + throw StateError( + 'Failed to disable immersive mode confirmations: ${result.stderr}', + ); + } + } + + /// Disable animations on the device. + Future disableAnimations() async { + const Map settings = { + 'show_surface_updates': '1', + 'transition_animation_scale': '0', + 'window_animation_scale': '0', + 'animator_duration_scale': '0', + }; + for (final MapEntry entry in settings.entries) { + final AdbStringResult result = await _runString([ + 'shell', + 'settings', + 'put', + 'global', + entry.key, + entry.value, + ]); + if (result.exitCode != 0) { + throw StateError('Failed to disable animations: ${result.stderr}'); + } + } + } +} + +/// Possible results of an `adb` command. +@internal +sealed class AdbResult { + /// Creates a new `adb` result. + const AdbResult._({this.exitCode = 0, this.stderr = ''}); + + /// The exit code of the `adb` command. + final int exitCode; + + /// The standard error output of the `adb` command. + final String stderr; +} + +@internal +final class AdbStringResult extends AdbResult { + AdbStringResult(this.stdout, {super.stderr, super.exitCode}) : super._(); + + /// The standard output of the `adb` command. + final String stdout; +} + +@internal +final class AdbBinaryResult extends AdbResult { + AdbBinaryResult(this.stdout, {super.stderr, super.exitCode}) : super._(); + + /// The standard output of the `adb` command. + final Uint8List stdout; +} + +/// Represents a target device running Android. +sealed class AndroidDeviceTarget { + /// Represents a device with the given [serialNumber]. + /// + /// This is the recommended way to target a specific device, and uses the + /// device's serial number, as reported by `adb devices`, to identify the + /// device: + /// + /// ```sh + /// $ adb devices + /// List of devices attached + /// emulator-5554 device + /// ``` + /// + /// In this example, the serial number is `emulator-5554`: + /// + /// ```dart + /// const AndroidDeviceTarget target = AndroidDeviceTarget.bySerial('emulator-5554'); + /// ``` + const factory AndroidDeviceTarget.bySerial( + String serialNumber, + ) = _SerialDeviceTarget; + + /// Represents the only running emulator _or_ connected device. + /// + /// This is equivalent to using `adb` without `-e`, `-d`, or `-s`. + const factory AndroidDeviceTarget.onlyEmulatorOrDevice() = _SingleAnyTarget; + + /// Represents the only running emulator on the host machine. + /// + /// This is equivalent to using `adb -e`, a _single_ emulator must be running. + const factory AndroidDeviceTarget.onlyEmulator() = _SingleEmulatorTarget; + + /// Represents the only connected device on the host machine. + /// + /// This is equivalent to using `adb -d`, a _single_ device must be connected. + const factory AndroidDeviceTarget.onlyDevice() = _SingleDeviceTarget; + + /// Returns the arguments to pass to `adb` to target this device. + List _toAdbArgs(); +} + +final class _SerialDeviceTarget implements AndroidDeviceTarget { + const _SerialDeviceTarget(this.serialNumber); + final String serialNumber; + + @override + List _toAdbArgs() => ['-s', serialNumber]; +} + +final class _SingleEmulatorTarget implements AndroidDeviceTarget { + const _SingleEmulatorTarget(); + + @override + List _toAdbArgs() => const ['-e']; +} + +final class _SingleDeviceTarget implements AndroidDeviceTarget { + const _SingleDeviceTarget(); + + @override + List _toAdbArgs() => const ['-d']; +} + +final class _SingleAnyTarget implements AndroidDeviceTarget { + const _SingleAnyTarget(); + + @override + List _toAdbArgs() => const []; +} + +/// Represents the possible screen orientations on Android. +enum AdbUserRotation { + /// Portrait orientation. + portrait, + + /// Landscape orientation. + landscape, + + /// Reverse portrait orientation, i.e., portrait upside down. + reversePortrait, + + /// Reverse landscape orientation, i.e., landscape upside down. + reverseLandscape; +} diff --git a/dev/tools/native_driver/lib/src/backend/android/driver.dart b/dev/tools/native_driver/lib/src/backend/android/driver.dart new file mode 100644 index 0000000000..263959fcca --- /dev/null +++ b/dev/tools/native_driver/lib/src/backend/android/driver.dart @@ -0,0 +1,151 @@ +// Copyright 2014 The Flutter 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:io' as io; +import 'dart:typed_data'; + +import 'package:flutter_driver/flutter_driver.dart'; +import 'package:meta/meta.dart'; +import 'package:path/path.dart' as p; + +import '../../../native_driver.dart'; +import '../../common.dart'; +import 'adb.dart'; + +/// Drives an Android device or emulator that is running a Flutter application. +final class AndroidNativeDriver implements NativeDriver { + /// Assumes a connected device or emulator via [adb]. + /// + /// This constructor is intended for testing purposes only. + @visibleForTesting + AndroidNativeDriver.forTesting({ + required Adb adb, + required FlutterDriver driver, + required io.Directory tempDirectory, + }) : this._(adb, driver, tempDirectory); + + AndroidNativeDriver._(this._adb, this._driver, this._tmpDir); + final Adb _adb; + final FlutterDriver _driver; + final io.Directory _tmpDir; + + /// Connects to a device or emulator identified by [target], which defaults to + /// the only running emulator or connected device. + /// + /// If [adbPath] is not provided, the `adb` command is assumed to be in the + /// system's PATH. + /// + /// If [tempDirectory] is not provided, a temporary directory will be created + /// in the system's temporary directory. + static Future connect( + FlutterDriver driver, { + AndroidDeviceTarget? target, + String? adbPath, + io.Directory? tempDirectory, + }) async { + final Adb adb = await Adb.create( + adbPath: adbPath, + target: target, + ); + tempDirectory ??= io.Directory.systemTemp.createTempSync('native_driver.'); + final AndroidNativeDriver nativeDriver = AndroidNativeDriver.forTesting( + adb: adb, + driver: driver, + tempDirectory: tempDirectory, + ); + await nativeDriver.ping(); + return nativeDriver; + } + + @override + Future close() async { + await _tmpDir.delete(recursive: true); + } + + @override + Future configureForScreenshotTesting() async { + await _adb.disableImmersiveModeConfirmations(); + await _adb.disableAnimations(); + } + + @override + Future tap(NativeFinder finder) async { + await _driver.sendCommand(NativeCommand.tap(finder)); + } + + /// Waits for 2 seconds before completing. + /// + /// There is no perfect way, outside of polling, to know when the device is + /// "stable" or has "stabilized" after a state change. The way that commands + /// such as [FlutterDriver.screenshot] handle this is to wait for 2 seconds + /// as a baseline, and then proceed with the command. + static Future _waitFor2s() async { + await Future.delayed(const Duration(seconds: 2)); + } + + @override + Future screenshot() async { + // Indentical wait to what `FlutterDriver.screenshot` does. + await _waitFor2s(); + return _AdbScreencap(await _adb.screencap(), _tmpDir); + } + + @override + Future ping() async { + final Stopwatch stopwatch = Stopwatch()..start(); + await _driver.sendCommand(NativeCommand.ping); + return stopwatch.elapsed; + } + + @override + Future rotateToLandscape() async { + _driver.sendCommand(NativeCommand.rotateLandscape); + } + + @override + Future rotateResetDefault() async { + _driver.sendCommand(NativeCommand.rotateDefault); + } + + /// Background the app by pressing the home button. + Future backgroundApp() async { + await _adb.sendToHome(); + await _waitFor2s(); + } + + /// Resumes the app by selecting it from the recent apps list. + Future resumeApp({required String appName}) async { + await _adb.resumeApp(appName: appName); + await _waitFor2s(); + } + + /// Send a trim memory signal to the app to force it to release memory. + Future simulateLowMemory({required String appName}) async { + await _adb.trimMemory(appName: appName); + await _waitFor2s(); + } +} + +final class _AdbScreencap implements NativeScreenshot { + const _AdbScreencap(this._bytes, this._tmpDir); + + /// Raw bytes of the screenshot in PNG format. + final Uint8List _bytes; + + /// Temporary directory to use as a default location for saving. + final io.Directory _tmpDir; + + static int _lastScreenshotId = 0; + + @override + Future saveAs([String? path]) async { + final int id = _lastScreenshotId++; + path ??= p.join(_tmpDir.path, 'screenshot_$id.png'); + await io.File(path).writeAsBytes(_bytes); + return path; + } + + @override + Future readAsBytes() async => _bytes; +} diff --git a/dev/tools/native_driver/lib/src/common.dart b/dev/tools/native_driver/lib/src/common.dart new file mode 100644 index 0000000000..3f3635c951 --- /dev/null +++ b/dev/tools/native_driver/lib/src/common.dart @@ -0,0 +1,131 @@ +// Copyright 2014 The Flutter 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:convert'; + +// This code has to be available in both the Flutter app and Dart VM test. +// ignore: implementation_imports +import 'package:flutter_driver/src/common/message.dart'; + +/// A command that is forwarded to a registered plugin. +final class NativeCommand extends Command { + /// Creates a new [NativeCommand] with the given [method]. + const NativeCommand(this.method, {this.arguments, super.timeout}); + + /// Tries to tap a native view by a selector. + factory NativeCommand.tap(NativeFinder finder) { + return NativeCommand('tap_view', arguments: finder); + } + + /// Requests that the device be rotated to landscape mode. + static const NativeCommand rotateLandscape = NativeCommand( + 'rotate_landscape', + ); + + /// Requests that the device reset its rotation to the default orientation. + static const NativeCommand rotateDefault = NativeCommand( + 'rotate_default', + ); + + /// Pings the device to ensure it is responsive. + static const NativeCommand ping = NativeCommand( + 'ping', + ); + + /// The method to call on the plugin. + final String method; + + /// What arguments to pass when invoking the [method]. + final Object? arguments; + + @override + String get kind => 'native_driver'; + + @override + Map serialize() { + final Map serialized = super.serialize(); + serialized['method'] = method; + if (arguments != null) { + serialized['arguments'] = jsonEncode(arguments); + } + return serialized; + } +} + +/// A result from a [NativeCommand]. +final class NativeResult extends Result { + /// Creates a new [NativeResult]. + const NativeResult(); + + @override + Map toJson() => const {}; +} + +/// An object that descrbes searching for _native_ elements. +sealed class NativeFinder { + const NativeFinder(); + + /// Serializes to JSON. + Map toJson() => const {}; +} + +/// Finds a native element by its native accessibility label. +final class ByNativeAccessibilityLabel extends NativeFinder { + /// Creates a new [ByNativeSemanticsLabel] finder. + const ByNativeAccessibilityLabel(this.label); + + /// The label to search for. + /// + /// ## Android + /// + /// On Android, this label is the `contentDescription` of the view: + /// + /// ```java + /// view.setContentDescription("My Label"); + /// ``` + final String label; + + @override + Map toJson() { + return { + 'kind': 'byNativeAccessibilityLabel', + 'label': label, + }; + } + + /// Deserializes this finder from the value generated by [serialize]. + static ByNativeAccessibilityLabel deserialize(Map params) { + return ByNativeAccessibilityLabel(params['label']!); + } +} + +/// Finds a native element by its native integer-based ID. +final class ByNativeIntegerId extends NativeFinder { + /// Creates a new [ByNativeIntegerId] finder. + const ByNativeIntegerId(this.id); + + /// The integer ID to search for. + /// + /// ## Android + /// + /// On Android, this ID is the `View.getId()` of the view: + /// + /// ```java + /// view.setId(42); + /// ``` + final int id; + + @override + Map toJson() { + return { + 'kind': 'byNativeIntegerId', + 'id': id.toString(), + }; + } + + /// Deserializes this finder from the value generated by [serialize]. + static ByNativeIntegerId deserialize(Map params) { + return ByNativeIntegerId(int.parse(params['id']!)); + } +} diff --git a/packages/flutter_driver/lib/src/native/driver.dart b/dev/tools/native_driver/lib/src/driver.dart similarity index 56% rename from packages/flutter_driver/lib/src/native/driver.dart rename to dev/tools/native_driver/lib/src/driver.dart index fd7025abd4..1bf3ff192c 100644 --- a/packages/flutter_driver/lib/src/native/driver.dart +++ b/dev/tools/native_driver/lib/src/driver.dart @@ -2,18 +2,14 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -/// @docImport 'package:flutter_driver/flutter_driver.dart'; -library; - -import 'dart:typed_data'; +part of '../native_driver.dart'; /// Drives a native device or emulator that is running a Flutter application. /// /// Unlike [FlutterDriver], a [NativeDriver] is backed by a platform specific /// implementation that might interact with out-of-process services, such as -/// `adb` for Android or `ios-deploy` for iOS, and might require additional -/// setup (e.g., adding test-only plugins to the application under test) for -/// full functionality. +/// `adb` for Android and might require additional setup (e.g., adding test-only +/// plugins to the application under test) for full functionality. /// /// API that is available directly on [NativeDriver] is considered _lowest /// common denominator_ and is guaranteed to work on all platforms supported by @@ -26,6 +22,29 @@ abstract interface class NativeDriver { /// After calling this method, the driver is no longer usable. Future close(); + /// Configures the device for (more) deterministic screenshots if possible. + /// + /// This method should be called during `setUpAll` if tests are going to + /// compare screenshots to golden files. + /// + /// Not all platforms support this method, and it is a no-op on platforms that + /// do not. + Future configureForScreenshotTesting(); + + /// Pings the device to ensure it is responsive. + /// + /// The implementation should return a future that completes when a command + /// is passed to the device (from the driver script), and to the native driver + /// plugin (if applicable), and back to the driver script. + /// + /// The duration of the round trip is returned, typically calculated as: + /// ```dart + /// final Stopwatch stopwatch = Stopwatch()..start(); + /// await doPing(); + /// return stopwatch.elapsed; + /// ``` + Future ping(); + /// Take a screenshot using a platform-specific mechanism. /// /// The image is returned as an opaque handle that can be used to retrieve @@ -33,6 +52,19 @@ abstract interface class NativeDriver { /// include platform-specific system UI elements, such as the status bar or /// navigation bar. Future screenshot(); + + /// Rotates the device to landscape orientation. + Future rotateToLandscape(); + + /// Returns the device to its default orientation. + Future rotateResetDefault(); + + /// Taps on a native view found by a selector. + /// + /// The [finder] is a platform-specific object that describes how to search + /// for a view to tap on. The method completes when the tap is complete, + /// or throws if a view cannot be found or tapped. + Future tap(NativeFinder finder); } /// An opaque handle to a screenshot taken on a native device. diff --git a/packages/flutter_driver/lib/src/native/goldens.dart b/dev/tools/native_driver/lib/src/goldens.dart similarity index 82% rename from packages/flutter_driver/lib/src/native/goldens.dart rename to dev/tools/native_driver/lib/src/goldens.dart index 1c4e72bd9a..bd0e180757 100644 --- a/packages/flutter_driver/lib/src/native/goldens.dart +++ b/dev/tools/native_driver/lib/src/goldens.dart @@ -2,47 +2,14 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -/// A partial copy of [flutter_test.matchesGoldenFile] and supporting code. -/// -/// Flutter driver runs in the standalone Dart VM, which does not have access to -/// the Flutter test library or `dart:ui`. This file provides a subset of the -/// functionality of `flutter_test`'s `matchesGoldenFile` function, and we can -/// consider refactoring this code to be shared between the two libraries -/// (https://github.com/flutter/flutter/issues/152257). -/// -/// ## TODOs -/// -/// - [ ] Figure out a code-sharing strategy with `flutter_test`. -/// -/// The basics, such as the matcher and APIs, could definitely be shared. -/// -/// - [ ] Consider how local image diffing could be shared, if at all. -/// -/// The `flutter_test` implementation uses `dart:ui`, which is not available -/// today in a Flutter driver script. We could either (a) provide a different -/// implementation for Flutter driver, or (b) provide a way, such as using -/// `flutter_tester` to run the tests in a Flutter context, to use the same -/// implementation. -/// -/// - [ ] Teach `flutter drive` to use and provide `--update-goldens` flag. -/// -/// @docImport 'package:flutter_test/flutter_test.dart' as flutter_test; -library; - -import 'dart:async'; -import 'dart:io' as io; -import 'dart:typed_data'; - -import 'package:matcher/matcher.dart'; - -// Similar to `flutter_test`, we ignore the implementation import. -// ignore: implementation_imports -import 'package:matcher/src/expect/async_matcher.dart'; - -import 'package:path/path.dart' as path; -import 'package:test_api/test_api.dart'; - -import 'driver.dart'; +// A partial copy of [flutter_test.matchesGoldenFile] and supporting code. +// +// Flutter driver runs in the standalone Dart VM, which does not have access to +// the Flutter test library or `dart:ui`. This file provides a subset of the +// functionality of `flutter_test`'s `matchesGoldenFile` function, and we can +// consider refactoring this code to be shared between the two libraries +// (https://github.com/flutter/flutter/issues/152257). +part of '../native_driver.dart'; /// Whether golden files should be automatically updated during tests rather /// than compared to the image bytes recorded by the tests. @@ -62,7 +29,10 @@ GoldenFileComparator goldenFileComparator = const NaiveLocalFileComparator._(); /// /// Instances of this comparator will be used as the backend for /// [matchesGoldenFile]. -abstract mixin class GoldenFileComparator { +abstract class GoldenFileComparator { + /// @nodoc + const GoldenFileComparator(); + /// Compares the pixels of decoded png [imageBytes] against the golden file /// identified by [golden]. /// @@ -114,7 +84,7 @@ abstract mixin class GoldenFileComparator { /// returning true only if there's an exact match. In cases where the captured /// test image does not match the golden file, this comparator will provide a /// fairly unhelpful error message, which could be improved in the future. -final class NaiveLocalFileComparator with GoldenFileComparator { +final class NaiveLocalFileComparator extends GoldenFileComparator { const NaiveLocalFileComparator._(); @override diff --git a/dev/tools/native_driver/pubspec.yaml b/dev/tools/native_driver/pubspec.yaml new file mode 100644 index 0000000000..86a7514376 --- /dev/null +++ b/dev/tools/native_driver/pubspec.yaml @@ -0,0 +1,79 @@ +name: native_driver + +environment: + sdk: ^3.5.0 + +dependencies: + flutter: + sdk: flutter + flutter_driver: + sdk: flutter + flutter_goldens: + sdk: flutter + flutter_test: + sdk: flutter + matcher: 0.12.16+1 + meta: 1.15.0 + path: 1.9.0 + platform: 3.1.5 + process: 5.0.2 + test_api: 0.7.3 + + async: 2.11.0 # THIS LINE IS AUTOGENERATED - TO UPDATE USE "flutter update-packages --force-upgrade" + boolean_selector: 2.1.1 # THIS LINE IS AUTOGENERATED - TO UPDATE USE "flutter update-packages --force-upgrade" + characters: 1.3.0 # THIS LINE IS AUTOGENERATED - TO UPDATE USE "flutter update-packages --force-upgrade" + clock: 1.1.1 # THIS LINE IS AUTOGENERATED - TO UPDATE USE "flutter update-packages --force-upgrade" + collection: 1.19.0 # THIS LINE IS AUTOGENERATED - TO UPDATE USE "flutter update-packages --force-upgrade" + crypto: 3.0.5 # THIS LINE IS AUTOGENERATED - TO UPDATE USE "flutter update-packages --force-upgrade" + fake_async: 1.3.1 # THIS LINE IS AUTOGENERATED - TO UPDATE USE "flutter update-packages --force-upgrade" + file: 7.0.0 # THIS LINE IS AUTOGENERATED - TO UPDATE USE "flutter update-packages --force-upgrade" + leak_tracker: 10.0.7 # THIS LINE IS AUTOGENERATED - TO UPDATE USE "flutter update-packages --force-upgrade" + leak_tracker_flutter_testing: 3.0.8 # THIS LINE IS AUTOGENERATED - TO UPDATE USE "flutter update-packages --force-upgrade" + leak_tracker_testing: 3.0.1 # THIS LINE IS AUTOGENERATED - TO UPDATE USE "flutter update-packages --force-upgrade" + material_color_utilities: 0.11.1 # THIS LINE IS AUTOGENERATED - TO UPDATE USE "flutter update-packages --force-upgrade" + source_span: 1.10.0 # THIS LINE IS AUTOGENERATED - TO UPDATE USE "flutter update-packages --force-upgrade" + stack_trace: 1.11.1 # THIS LINE IS AUTOGENERATED - TO UPDATE USE "flutter update-packages --force-upgrade" + stream_channel: 2.1.2 # THIS LINE IS AUTOGENERATED - TO UPDATE USE "flutter update-packages --force-upgrade" + string_scanner: 1.3.0 # THIS LINE IS AUTOGENERATED - TO UPDATE USE "flutter update-packages --force-upgrade" + sync_http: 0.3.1 # THIS LINE IS AUTOGENERATED - TO UPDATE USE "flutter update-packages --force-upgrade" + term_glyph: 1.2.1 # THIS LINE IS AUTOGENERATED - TO UPDATE USE "flutter update-packages --force-upgrade" + typed_data: 1.3.2 # THIS LINE IS AUTOGENERATED - TO UPDATE USE "flutter update-packages --force-upgrade" + vector_math: 2.1.4 # THIS LINE IS AUTOGENERATED - TO UPDATE USE "flutter update-packages --force-upgrade" + vm_service: 14.2.5 # THIS LINE IS AUTOGENERATED - TO UPDATE USE "flutter update-packages --force-upgrade" + webdriver: 3.0.3 # THIS LINE IS AUTOGENERATED - TO UPDATE USE "flutter update-packages --force-upgrade" + +dev_dependencies: + test: 1.25.8 + + _fe_analyzer_shared: 74.0.0 # THIS LINE IS AUTOGENERATED - TO UPDATE USE "flutter update-packages --force-upgrade" + analyzer: 6.9.0 # THIS LINE IS AUTOGENERATED - TO UPDATE USE "flutter update-packages --force-upgrade" + args: 2.5.0 # THIS LINE IS AUTOGENERATED - TO UPDATE USE "flutter update-packages --force-upgrade" + convert: 3.1.1 # THIS LINE IS AUTOGENERATED - TO UPDATE USE "flutter update-packages --force-upgrade" + coverage: 1.9.2 # THIS LINE IS AUTOGENERATED - TO UPDATE USE "flutter update-packages --force-upgrade" + frontend_server_client: 4.0.0 # THIS LINE IS AUTOGENERATED - TO UPDATE USE "flutter update-packages --force-upgrade" + glob: 2.1.2 # THIS LINE IS AUTOGENERATED - TO UPDATE USE "flutter update-packages --force-upgrade" + http_multi_server: 3.2.1 # THIS LINE IS AUTOGENERATED - TO UPDATE USE "flutter update-packages --force-upgrade" + http_parser: 4.1.0 # THIS LINE IS AUTOGENERATED - TO UPDATE USE "flutter update-packages --force-upgrade" + io: 1.0.4 # THIS LINE IS AUTOGENERATED - TO UPDATE USE "flutter update-packages --force-upgrade" + js: 0.7.1 # THIS LINE IS AUTOGENERATED - TO UPDATE USE "flutter update-packages --force-upgrade" + logging: 1.2.0 # THIS LINE IS AUTOGENERATED - TO UPDATE USE "flutter update-packages --force-upgrade" + mime: 1.0.6 # THIS LINE IS AUTOGENERATED - TO UPDATE USE "flutter update-packages --force-upgrade" + node_preamble: 2.0.2 # THIS LINE IS AUTOGENERATED - TO UPDATE USE "flutter update-packages --force-upgrade" + package_config: 2.1.0 # THIS LINE IS AUTOGENERATED - TO UPDATE USE "flutter update-packages --force-upgrade" + pool: 1.5.1 # THIS LINE IS AUTOGENERATED - TO UPDATE USE "flutter update-packages --force-upgrade" + pub_semver: 2.1.4 # THIS LINE IS AUTOGENERATED - TO UPDATE USE "flutter update-packages --force-upgrade" + shelf: 1.4.2 # THIS LINE IS AUTOGENERATED - TO UPDATE USE "flutter update-packages --force-upgrade" + shelf_packages_handler: 3.0.2 # THIS LINE IS AUTOGENERATED - TO UPDATE USE "flutter update-packages --force-upgrade" + shelf_static: 1.1.3 # THIS LINE IS AUTOGENERATED - TO UPDATE USE "flutter update-packages --force-upgrade" + shelf_web_socket: 2.0.0 # THIS LINE IS AUTOGENERATED - TO UPDATE USE "flutter update-packages --force-upgrade" + source_map_stack_trace: 2.1.2 # THIS LINE IS AUTOGENERATED - TO UPDATE USE "flutter update-packages --force-upgrade" + source_maps: 0.10.12 # THIS LINE IS AUTOGENERATED - TO UPDATE USE "flutter update-packages --force-upgrade" + test_core: 0.6.5 # THIS LINE IS AUTOGENERATED - TO UPDATE USE "flutter update-packages --force-upgrade" + watcher: 1.1.0 # THIS LINE IS AUTOGENERATED - TO UPDATE USE "flutter update-packages --force-upgrade" + web: 1.0.0 # THIS LINE IS AUTOGENERATED - TO UPDATE USE "flutter update-packages --force-upgrade" + web_socket: 0.1.6 # THIS LINE IS AUTOGENERATED - TO UPDATE USE "flutter update-packages --force-upgrade" + web_socket_channel: 3.0.1 # THIS LINE IS AUTOGENERATED - TO UPDATE USE "flutter update-packages --force-upgrade" + webkit_inspection_protocol: 1.2.1 # THIS LINE IS AUTOGENERATED - TO UPDATE USE "flutter update-packages --force-upgrade" + yaml: 3.1.2 # THIS LINE IS AUTOGENERATED - TO UPDATE USE "flutter update-packages --force-upgrade" + +# PUBSPEC CHECKSUM: 65e8 diff --git a/dev/tools/native_driver/test/adb_fake_io_test.dart b/dev/tools/native_driver/test/adb_fake_io_test.dart new file mode 100644 index 0000000000..3382965206 --- /dev/null +++ b/dev/tools/native_driver/test/adb_fake_io_test.dart @@ -0,0 +1,132 @@ +// Copyright 2014 The Flutter 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:typed_data'; + +import 'package:native_driver/src/backend/android/adb.dart'; +import 'package:process/process.dart'; +import 'package:test/test.dart'; + +import 'src/fake_process_manager.dart'; + +// These tests are fake IO tests, so they don't actually run any commands. +void main() { + group('AndroidDeviceTarget', () { + late List caughtArgs; + late FakeProcessManager processManager; + + setUp(() { + caughtArgs = []; + processManager = FakeProcessManager(( + String exec, + List args, + ) async { + assert(caughtArgs.isEmpty, 'Should only catch one call to run'); + caughtArgs = args; + return FakeProcessManager.ok(); + }); + }); + + test('bySerial emits "-s "', () async { + await Adb.create( + target: const AndroidDeviceTarget.bySerial('1234'), + processManager: processManager, + ); + + expect(caughtArgs.take(2), ['-s', '1234']); + }); + + test('onlyEmulatorOrDevice emits no arguments', () async { + await Adb.create( + target: const AndroidDeviceTarget.onlyEmulatorOrDevice(), + processManager: processManager, + ); + + expect(caughtArgs, ['shell', 'echo', 'connected']); + }); + + test('onlyEmulator emits "-e"', () async { + await Adb.create( + target: const AndroidDeviceTarget.onlyEmulator(), + processManager: processManager, + ); + + expect(caughtArgs.take(1), ['-e']); + }); + + test('onlyDevice emits "-d"', () async { + await Adb.create( + target: const AndroidDeviceTarget.onlyDevice(), + processManager: processManager, + ); + + expect(caughtArgs.take(1), ['-d']); + }); + }); + + test('if isDeviceConnected fails, bootstrap fails', () async { + final ProcessManager processManager = FakeProcessManager(( + String exec, + List args, + ) async { + return FakeProcessManager.error('error'); + }); + + expect( + Adb.create( + processManager: processManager, + ), + throwsA(isA().having( + (StateError e) => e.message, + 'message', + 'No device connected: error', + )), + ); + }); + + test('screencap invokes "exec-out screencap -p"', () async { + final FakeProcessManager processManager = FakeProcessManager(( + String exec, + List args, + ) async { + switch (args) { + case ['shell', 'echo', 'connected']: + return FakeProcessManager.ok('connected'); + case ['exec-out', 'screencap', '-p']: + return FakeProcessManager.okBinary([0, 1, 2, 3]); + default: + throw UnsupportedError('Unknown command: $args'); + } + }); + + final Adb adb = await Adb.create( + processManager: processManager, + ); + + final Uint8List result = await adb.screencap(); + expect(result, [0, 1, 2, 3]); + }); + + test('tap invokes "shell input tap"', () async { + final FakeProcessManager processManager = FakeProcessManager(( + String exec, + List args, + ) async { + switch (args) { + case ['shell', 'echo', 'connected']: + return FakeProcessManager.ok('connected'); + case ['shell', 'input', 'tap', '1', '2']: + return FakeProcessManager.ok(); + default: + throw UnsupportedError('Unknown command: $args'); + } + }); + + final Adb adb = await Adb.create( + processManager: processManager, + ); + + await adb.tap(1, 2); + }); +} diff --git a/dev/tools/native_driver/test/android_driver_fake_test.dart b/dev/tools/native_driver/test/android_driver_fake_test.dart new file mode 100644 index 0000000000..792cdd9cdf --- /dev/null +++ b/dev/tools/native_driver/test/android_driver_fake_test.dart @@ -0,0 +1,49 @@ +// Copyright 2014 The Flutter 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:io' as io; +import 'dart:typed_data'; + +import 'package:native_driver/native_driver.dart'; +import 'package:test/test.dart'; + +import 'src/fake_adb.dart'; +import 'src/fake_driver.dart'; + +void main() async { + test('screenshot calls ADB screencap', () async { + final FakeAdb adb = FakeAdb( + screencap: () async => Uint8List.fromList([1, 2, 3, 4]), + ); + final io.Directory tmpDir = io.Directory.systemTemp.createTempSync(); + final AndroidNativeDriver driver = AndroidNativeDriver.forTesting( + adb: adb, + driver: const NullFlutterDriver(), + tempDirectory: tmpDir, + ); + + final NativeScreenshot screenshot = await driver.screenshot(); + await expectLater(screenshot.readAsBytes(), completion([1, 2, 3, 4])); + + final String path = await screenshot.saveAs(); + final io.File file = io.File(path); + expect(file.readAsBytes(), completion([1, 2, 3, 4])); + + await driver.close(); + }); + + test('closes deletes the temporary directory', () async { + final FakeAdb adb = FakeAdb(); + final io.Directory tmpDir = io.Directory.systemTemp.createTempSync(); + final AndroidNativeDriver driver = AndroidNativeDriver.forTesting( + adb: adb, + driver: const NullFlutterDriver(), + tempDirectory: tmpDir, + ); + + expect(tmpDir.existsSync(), isTrue); + await driver.close(); + expect(tmpDir.existsSync(), isFalse); + }); +} diff --git a/dev/tools/native_driver/test/src/fake_adb.dart b/dev/tools/native_driver/test/src/fake_adb.dart new file mode 100644 index 0000000000..9fd91d7184 --- /dev/null +++ b/dev/tools/native_driver/test/src/fake_adb.dart @@ -0,0 +1,89 @@ +// Copyright 2014 The Flutter 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:typed_data'; + +import 'package:native_driver/src/backend/android.dart'; + +/// A stub of [Adb] that allows overriding its methods. +/// +/// The default implementation of each method is a simple success case. +final class FakeAdb implements Adb { + FakeAdb({ + Future<(bool, String?)> Function()? isDeviceConnected, + Future Function()? screencap, + Future Function(int x, int y)? tap, + Future Function()? disableImmersiveModeConfirmations, + Future Function()? disableAnimations, + Future Function()? sendToHome, + Future Function(String appName, [String? activityName])? resumeApp, + Future Function(String appName)? trimMemory, + }) : _isDeviceConnected = isDeviceConnected, + _screencap = screencap, + _tap = tap, + _disableImmersiveModeConfirmations = disableImmersiveModeConfirmations, + _disableAnimations = disableAnimations, + _sendToHome = sendToHome, + _resumeApp = resumeApp, + _trimMemory = trimMemory; + + @override + Future<(bool, String?)> isDeviceConnected() async { + return _isDeviceConnected?.call() ?? (true, null); + } + + final Future<(bool, String?)> Function()? _isDeviceConnected; + + @override + Future screencap() { + return _screencap?.call() ?? Future.value(Uint8List(0)); + } + + final Future Function()? _screencap; + + @override + Future tap(int x, int y) async { + return _tap?.call(x, y) ?? Future.value(); + } + + final Future Function(int x, int y)? _tap; + + @override + Future disableImmersiveModeConfirmations() { + return _disableImmersiveModeConfirmations?.call() ?? Future.value(); + } + + final Future Function()? _disableImmersiveModeConfirmations; + + @override + Future disableAnimations() { + return _disableAnimations?.call() ?? Future.value(); + } + + final Future Function()? _disableAnimations; + + @override + Future sendToHome() { + return _sendToHome?.call() ?? Future.value(); + } + + final Future Function()? _sendToHome; + + @override + Future resumeApp({required String appName, String? activityName}) { + return _resumeApp?.call(appName, activityName) ?? Future.value(); + } + + final Future Function( + String appName, [ + String? activityName, + ])? _resumeApp; + + @override + Future trimMemory({required String appName}) { + return _trimMemory?.call(appName) ?? Future.value(); + } + + final Future Function(String appName)? _trimMemory; +} diff --git a/dev/tools/native_driver/test/src/fake_driver.dart b/dev/tools/native_driver/test/src/fake_driver.dart new file mode 100644 index 0000000000..0c6398a0a2 --- /dev/null +++ b/dev/tools/native_driver/test/src/fake_driver.dart @@ -0,0 +1,13 @@ +// Copyright 2014 The Flutter 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:flutter_driver/flutter_driver.dart'; + +/// A fake [FlutterDriver] that throws [UnimplementedError] for all methods. +final class NullFlutterDriver implements FlutterDriver { + const NullFlutterDriver(); + + @override + Never noSuchMethod(Invocation invocation) => throw UnimplementedError(); +} diff --git a/dev/tools/native_driver/test/src/fake_process_manager.dart b/dev/tools/native_driver/test/src/fake_process_manager.dart new file mode 100644 index 0000000000..078f70e7c5 --- /dev/null +++ b/dev/tools/native_driver/test/src/fake_process_manager.dart @@ -0,0 +1,53 @@ +// Copyright 2014 The Flutter 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:convert'; + +import 'dart:io'; +import 'dart:typed_data'; + +import 'package:process/process.dart'; + +/// A stub of [ProcessManager] that allows mocking the [run] method only. +final class FakeProcessManager extends ProcessManager { + /// Creates a new [FakeProcessManager] with the given delegate callback. + FakeProcessManager(this._runDelegate); + final Future Function( + String executable, + List arguments, + ) _runDelegate; + + @override + Never noSuchMethod(_) => throw UnimplementedError(); + + @override + Future run( + List command, { + String? workingDirectory, + Map? environment, + bool includeParentEnvironment = true, + bool runInShell = false, + Encoding? stdoutEncoding = systemEncoding, + Encoding? stderrEncoding = systemEncoding, + }) { + final List strings = command.map((Object e) => '$e').toList(); + final [String executable, ...List arguments] = strings; + return _runDelegate(executable, arguments); + } + + /// Returns a [ProcessResult] with the given [stdout]. + static ProcessResult ok([String stdout = '']) { + return ProcessResult(0, 0, stdout, ''); + } + + /// Returns a [ProcessResult] with the given [stderr]. + static ProcessResult error([String stderr = '']) { + return ProcessResult(0, 1, '', stderr); + } + + /// Returns a [ProcessResult] with the given [stdout] binary data. + static ProcessResult okBinary(List stdout) { + return ProcessResult(0, 0, Uint8List.fromList(stdout), ''); + } +} diff --git a/packages/flutter_driver/lib/src/native/README.md b/packages/flutter_driver/lib/src/native/README.md deleted file mode 100644 index 347988b066..0000000000 --- a/packages/flutter_driver/lib/src/native/README.md +++ /dev/null @@ -1,24 +0,0 @@ -# Flutter Native Driver - -An experiment in adding platform-aware functionality to `flutter_driver`. - -Project tracking: . - -We'd like to be able to test, within `flutter/flutter` (and friends): - -- Does a web-view load and render the expected content? -- Unexpected changes with the native OS, i.e. Android edge-to-edge -- Impeller rendering on Android using a real GPU (not swift_shader or Skia) -- Does an app correctly respond to application backgrounding and resume? -- Interact with native UI elements (not rendered by Flutter) and observe output -- Native text/keyboard input (IMEs, virtual keyboards, anything a11y related) - -This project is tracking augmenting `flutter_driver` towards these goals. - -If the project is not successful, the experiment will be turned-down and the -code removed or repurposed. - ---- - -_Questions?_ Ask in the `#hackers-tests` channel on the Flutter Discord or -`@matanlurey` or `@johnmccutchan` on GitHub. diff --git a/packages/flutter_driver/lib/src/native/android.dart b/packages/flutter_driver/lib/src/native/android.dart deleted file mode 100644 index 84db15de62..0000000000 --- a/packages/flutter_driver/lib/src/native/android.dart +++ /dev/null @@ -1,202 +0,0 @@ -// Copyright 2014 The Flutter Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -// Examples can assume: -// import 'package:flutter_driver/src/native/android.dart'; - -import 'dart:convert'; -import 'dart:io' as io; -import 'dart:typed_data'; - -import 'package:meta/meta.dart'; -import 'package:path/path.dart' as p; - -import 'driver.dart'; - -/// Drives an Android device or emulator that is running a Flutter application. -final class AndroidNativeDriver implements NativeDriver { - /// Creates a new Android native driver with the provided configuration. - /// - /// The [tempDirectory] argument can be used to specify a custom directory - /// where the driver will store temporary files. If not provided, a temporary - /// directory will be created in the system's temporary directory. - /// - /// @nodoc - @visibleForTesting - AndroidNativeDriver({ - required AndroidDeviceTarget target, - String? adbPath, - io.Directory? tempDirectory, - }) : _adbPath = adbPath ?? 'adb', - _target = target, - _tmpDir = tempDirectory ?? - io.Directory.systemTemp.createTempSync('flutter_driver.'); - - /// Connects to a device or emulator identified by [target]. - static Future connect({ - AndroidDeviceTarget? target, - }) async { - target ??= const AndroidDeviceTarget.onlyEmulatorOrDevice(); - final AndroidNativeDriver driver = AndroidNativeDriver(target: target); - await driver._smokeTest(); - return driver; - } - - Future _adb( - List args, { - Encoding? stdoutEncoding = io.systemEncoding, - }) { - return io.Process.run( - _adbPath, - [ - ..._target._toAdbArgs(), - ...args, - ], - stdoutEncoding: stdoutEncoding, - ); - } - - Future _smokeTest() async { - final io.ProcessResult version = await _adb(['version']); - if (version.exitCode != 0) { - throw StateError('Failed to run `$_adbPath version`: ${version.stderr}'); - } - - final io.ProcessResult echo = await _adb( - [ - 'shell', - 'echo', - 'connected', - ], - ); - if (echo.exitCode != 0) { - throw StateError('Failed to connect to target: ${echo.stderr}'); - } - } - - final String _adbPath; - final AndroidDeviceTarget _target; - final io.Directory _tmpDir; - - @override - Future close() async { - await _tmpDir.delete(recursive: true); - } - - @override - Future screenshot() async { - // Similar pause to the one in `.screenshot()`. - await Future.delayed(const Duration(seconds: 2)); - final io.ProcessResult result = await _adb( - [ - ..._target._toAdbArgs(), - 'exec-out', - 'screencap', - '-p', - ], - stdoutEncoding: null, - ); - - if (result.exitCode != 0) { - throw StateError('Failed to take screenshot: ${result.stderr}'); - } - - final Uint8List bytes = result.stdout as Uint8List; - return _AdbScreencap(bytes, _tmpDir); - } -} - -final class _AdbScreencap implements NativeScreenshot { - const _AdbScreencap(this._bytes, this._tmpDir); - - /// Raw bytes of the screenshot in PNG format. - final Uint8List _bytes; - - /// Temporary directory to default to when saving the screenshot. - final io.Directory _tmpDir; - - static int _lastScreenshotId = 0; - - @override - Future saveAs([String? path]) async { - final int id = _lastScreenshotId++; - path ??= p.join(_tmpDir.path, '$id.png'); - await io.File(path).writeAsBytes(_bytes); - return path; - } - - @override - Future readAsBytes() async => _bytes; -} - -/// Represents a target device running Android. -sealed class AndroidDeviceTarget { - /// Represents a device with the given [serialNumber]. - /// - /// This is the recommended way to target a specific device, and uses the - /// device's serial number, as reported by `adb devices`, to identify the - /// device: - /// - /// ```sh - /// $ adb devices - /// List of devices attached - /// emulator-5554 device - /// ``` - /// - /// In this example, the serial number is `emulator-5554`: - /// - /// ```dart - /// const AndroidDeviceTarget target = AndroidDeviceTarget.bySerial('emulator-5554'); - /// ``` - const factory AndroidDeviceTarget.bySerial(String serialNumber) = - _SerialDeviceTarget; - - /// Represents the only running emulator _or_ connected device. - /// - /// This is equivalent to using `adb` without `-e`, `-d`, or `-s`. - const factory AndroidDeviceTarget.onlyEmulatorOrDevice() = _SingleAnyTarget; - - /// Represents the only running emulator on the host machine. - /// - /// This is equivalent to using `adb -e`, a _single_ emulator must be running. - const factory AndroidDeviceTarget.onlyRunningEmulator() = - _SingleEmulatorTarget; - - /// Represents the only connected device on the host machine. - /// - /// This is equivalent to using `adb -d`, a _single_ device must be connected. - const factory AndroidDeviceTarget.onlyConnectedDevice() = _SingleDeviceTarget; - - /// Returns the arguments to pass to `adb` to target this device. - List _toAdbArgs(); -} - -final class _SerialDeviceTarget implements AndroidDeviceTarget { - const _SerialDeviceTarget(this.serialNumber); - final String serialNumber; - - @override - List _toAdbArgs() => ['-s', serialNumber]; -} - -final class _SingleEmulatorTarget implements AndroidDeviceTarget { - const _SingleEmulatorTarget(); - - @override - List _toAdbArgs() => const ['-e']; -} - -final class _SingleDeviceTarget implements AndroidDeviceTarget { - const _SingleDeviceTarget(); - - @override - List _toAdbArgs() => const ['-d']; -} - -final class _SingleAnyTarget implements AndroidDeviceTarget { - const _SingleAnyTarget(); - - @override - List _toAdbArgs() => const []; -} diff --git a/packages/flutter_driver/test/src/native_tests/android/README.md b/packages/flutter_driver/test/src/native_tests/android/README.md deleted file mode 100644 index a79e1e8df5..0000000000 --- a/packages/flutter_driver/test/src/native_tests/android/README.md +++ /dev/null @@ -1,15 +0,0 @@ -# `AndroidNativeDriver` Tests - -This directory are tests that require an Android device or emulator to run. - -To run locally, connect an Android device or start an emulator and run: - -```bash -# Assumuing your current working directory is `packages/flutter_driver`.\ - -$ flutter test test/src/native_tests/android -``` - -On CI, these tests are run via [`run_flutter_driver_android_tests.dart`][ci]. - -[ci]: ../../../../../../dev/bots/suite_runners/run_flutter_driver_android_tests.dart diff --git a/packages/flutter_driver/test/src/native_tests/android/screenshot_test.dart b/packages/flutter_driver/test/src/native_tests/android/screenshot_test.dart deleted file mode 100644 index d41d477941..0000000000 --- a/packages/flutter_driver/test/src/native_tests/android/screenshot_test.dart +++ /dev/null @@ -1,25 +0,0 @@ -// Copyright 2014 The Flutter 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:io' as io; -import 'dart:typed_data'; - -import 'package:flutter_driver/src/native/android.dart'; -import 'package:flutter_driver/src/native/driver.dart'; -import 'package:test/test.dart'; - -void main() async { - test('should connect to an Android device and take a screenshot', () async { - final NativeDriver driver = await AndroidNativeDriver.connect(); - final NativeScreenshot screenshot = await driver.screenshot(); - - final Uint8List bytes = await screenshot.readAsBytes(); - expect(bytes.length, greaterThan(0)); - - final String path = await screenshot.saveAs(); - expect(io.File(path).readAsBytesSync(), bytes); - - await driver.close(); - }); -}