From d51858c2e16e87e2c581e56187b01e19b2a088c3 Mon Sep 17 00:00:00 2001 From: godofredoc Date: Wed, 24 Jan 2024 15:11:12 -0800 Subject: [PATCH] Migrate android views to devicelab. (#142081) Migrate android view out of recipes. --- dev/devicelab/bin/tasks/android_views.dart | 10 ++++ .../lib/tasks/android_views_test.dart | 56 +++++++++++++++++++ 2 files changed, 66 insertions(+) create mode 100644 dev/devicelab/bin/tasks/android_views.dart create mode 100644 dev/devicelab/lib/tasks/android_views_test.dart diff --git a/dev/devicelab/bin/tasks/android_views.dart b/dev/devicelab/bin/tasks/android_views.dart new file mode 100644 index 0000000000..70aa800abb --- /dev/null +++ b/dev/devicelab/bin/tasks/android_views.dart @@ -0,0 +1,10 @@ +// 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_devicelab/framework/framework.dart'; +import 'package:flutter_devicelab/tasks/android_views_test.dart'; + +Future main() async { + await task(androidViewsTest()); +} diff --git a/dev/devicelab/lib/tasks/android_views_test.dart b/dev/devicelab/lib/tasks/android_views_test.dart new file mode 100644 index 0000000000..8900f2c411 --- /dev/null +++ b/dev/devicelab/lib/tasks/android_views_test.dart @@ -0,0 +1,56 @@ +// 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 '../framework/framework.dart'; +import '../framework/task_result.dart'; +import '../framework/utils.dart'; + + +/// Tests the following Android lifecycles: Activity#onStop(), Activity#onResume(), Activity#onPause(), +/// and Activity#onDestroy() from Dart perspective in debug, profile, and release modes. +TaskFunction androidViewsTest({ + Map? environment, +}){ + return () async { + section('Build APK'); + await flutter( + 'build', + options: [ + 'apk', + '--config-only', + ], + environment: environment, + workingDirectory: '${flutterDirectory.path}/dev/integration_tests/android_views' + ); + + /// Any gradle command downloads gradle if not already present in the cache. + /// ./gradlew dependencies downloads any gradle defined dependencies to the cache. + /// https://docs.gradle.org/current/userguide/viewing_debugging_dependencies.html + /// Downloading gradle and downloading dependencies are a common source of flakes + /// and moving those to an infra step that can be retried shifts the blame + /// individual tests to the infra itself. + section('Download android dependencies'); + final int exitCode = await exec( + './gradlew', + ['-q', 'dependencies'], + workingDirectory: + '${flutterDirectory.path}/dev/integration_tests/android_views/android' + ); + if (exitCode != 0) { + return TaskResult.failure('Failed to download gradle dependencies'); + } + section('Run flutter drive on android views'); + await flutter( + 'drive', + options: [ + '--browser-name=android-chrome', + '--android-emulator', '--no-start-paused', + '--purge-persistent-cache', '--device-timeout=30', + ], + environment: environment, + workingDirectory: '${flutterDirectory.path}/dev/integration_tests/android_views' + ); + return TaskResult.success(null); + }; +}