forked from firka/flutter
Trigger display_cutout_rotation flutter driver test in ci. (#162641)
Fixes https://github.com/flutter/flutter/issues/162615 Can test 2 different ways. On a mac (or linux machine) with adb on the path (or android sdk set in ANDROID_HOME) and an emulator running (or physical device attached) that is api 30 or higher. ``` cd dev/devicelab dart bin/test_runner.dart test -t android_display_cutout ``` OR ``` dev/integration_tests/display_cutout_rotation flutter drive integration_test/display_cutout_test.dart ``` Proof the test ran successfully ``` [2025-02-12 08:08:22.069817] [STDOUT] Removing Synthetic notch... [2025-02-12 08:08:22.071147] [STDOUT] Executing "/b/s/w/ir/cache/android/sdk/platform-tools/adb -s emulator-5554 shell cmd overlay disable com.android.internal.display.cutout.emulation.tall" in "/b/s/w/ir/x/w/rc/tmpk3k3yhhp/flutter sdk/dev/integration_tests/display_cutout_rotation/" with environment {BOT: true, LANG: en_US.UTF-8} [2025-02-12 08:08:22.862219] [STDOUT] Checking for reboot [android_defines_test] Process terminated with exit code 0. Task result: { "success": true, "data": null, "detailFiles": [], "benchmarkScoreKeys": [], "reason": "success" } ``` https://logs.chromium.org/logs/flutter/buildbucket/cr-buildbucket/8723125792202374961/+/u/run_android_defines_test/stdout All checks passed https://github.com/flutter/flutter/pull/162641/checks?check_run_id=36991537539 ## Pre-launch Checklist - [x] I read the [Contributor Guide] and followed the process outlined there for submitting PRs. - [x] I read the [Tree Hygiene] wiki page, which explains my responsibilities. - [x] I read and followed the [Flutter Style Guide], including [Features we expect every widget to implement]. - [x] I signed the [CLA]. - [x] I listed at least one issue that this PR fixes in the description above. - [x] I updated/added relevant documentation (doc comments with `///`). - [x] I added new tests to check the change I am making, or this PR is [test-exempt]. - [x] I followed the [breaking change policy] and added [Data Driven Fixes] where supported. - [x] All existing and new tests are passing.
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
# display_cutout_rotation
|
||||
|
||||
To run test locally use `flutter drive integration_test/display_cutout_test.dart` from this folder.
|
||||
To run test locally use `flutter test integration_test/display_cutout_test.dart` from this folder.
|
||||
|
||||
OR from `flutter/dev/devicelab` run `dart bin/test_runner.dart test -t android_display_cutout`.
|
||||
|
||||
@@ -14,7 +14,7 @@ void main() {
|
||||
IntegrationTestWidgetsFlutterBinding.ensureInitialized();
|
||||
|
||||
group('end-to-end test', () {
|
||||
// Test assumes a custom driver that enables
|
||||
// Test assumes that the device already has enabled
|
||||
// "com.android.internal.display.cutout.emulation.tall".
|
||||
testWidgets('cutout should be on top in portrait mode', (WidgetTester tester) async {
|
||||
// Force rotation
|
||||
|
||||
@@ -1,104 +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:async';
|
||||
import 'dart:convert';
|
||||
import 'dart:io';
|
||||
|
||||
import 'package:flutter_driver/flutter_driver.dart';
|
||||
|
||||
// display_cutout needs a custom driver becuase cutout manipulations needs to be
|
||||
// done to a device/emulator in order for the tests to pass.
|
||||
Future<void> main() async {
|
||||
if (!(Platform.isLinux || Platform.isMacOS)) {
|
||||
// Not a fundemental limitation, developer shortcut.
|
||||
print('This test must be run on a POSIX host. Skipping...');
|
||||
return;
|
||||
}
|
||||
final bool adbExists = Process.runSync('which', <String>['adb']).exitCode == 0;
|
||||
if (!adbExists) {
|
||||
print(r'This test needs ADB to exist on the $PATH.');
|
||||
exitCode = 1;
|
||||
return;
|
||||
}
|
||||
// Test requires developer settings added in 28 and behavior added in 30
|
||||
final ProcessResult checkApiLevel = Process.runSync('adb', <String>[
|
||||
'shell',
|
||||
'getprop',
|
||||
'ro.build.version.sdk',
|
||||
]);
|
||||
final String apiStdout = checkApiLevel.stdout.toString();
|
||||
// Api level 30 or higher.
|
||||
if (apiStdout.startsWith('2') || apiStdout.startsWith('1') || apiStdout.length == 1) {
|
||||
print('This test must be run on api 30 or higher. Skipping...');
|
||||
return;
|
||||
}
|
||||
// Developer settings are required on target device for cutout manipulation.
|
||||
bool shouldResetDevSettings = false;
|
||||
final ProcessResult checkDevSettingsResult = Process.runSync('adb', <String>[
|
||||
'shell',
|
||||
'settings',
|
||||
'get',
|
||||
'global',
|
||||
'development_settings_enabled',
|
||||
]);
|
||||
if (checkDevSettingsResult.stdout.toString().startsWith('0')) {
|
||||
print('Enabling developer settings...');
|
||||
// Developer settings not enabled, enable them and mark that the origional
|
||||
// state should be restored after.
|
||||
shouldResetDevSettings = true;
|
||||
Process.runSync('adb', <String>[
|
||||
'shell',
|
||||
'settings',
|
||||
'put',
|
||||
'global',
|
||||
'development_settings_enabled',
|
||||
'1',
|
||||
]);
|
||||
}
|
||||
// Assumption of diplay_cutout_test.dart is that there is a "tall" notch.
|
||||
print('Adding Synthetic notch...');
|
||||
Process.runSync('adb', <String>[
|
||||
'shell',
|
||||
'cmd',
|
||||
'overlay',
|
||||
'enable',
|
||||
'com.android.internal.display.cutout.emulation.tall',
|
||||
]);
|
||||
print('Starting test.');
|
||||
try {
|
||||
final FlutterDriver driver = await FlutterDriver.connect();
|
||||
final String data = await driver.requestData(null, timeout: const Duration(minutes: 1));
|
||||
await driver.close();
|
||||
final Map<String, dynamic> result = jsonDecode(data) as Map<String, dynamic>;
|
||||
print('Test finished!');
|
||||
print(result);
|
||||
exitCode = result['result'] == 'true' ? 0 : 1;
|
||||
} catch (e) {
|
||||
print(e);
|
||||
exitCode = 1;
|
||||
} finally {
|
||||
print('Removing Synthetic notch...');
|
||||
Process.runSync('adb', <String>[
|
||||
'shell',
|
||||
'cmd',
|
||||
'overlay',
|
||||
'disable',
|
||||
'com.android.internal.display.cutout.emulation.tall',
|
||||
]);
|
||||
print('Reverting Adb changes...');
|
||||
if (shouldResetDevSettings) {
|
||||
print('Disabling developer settings...');
|
||||
Process.runSync('adb', <String>[
|
||||
'shell',
|
||||
'settings',
|
||||
'put',
|
||||
'global',
|
||||
'development_settings_enabled',
|
||||
'0',
|
||||
]);
|
||||
}
|
||||
}
|
||||
return;
|
||||
}
|
||||
Reference in New Issue
Block a user