Skip to content
This repository was archived by the owner on Feb 25, 2025. It is now read-only.

Commit 4addb6a

Browse files
authored
Actually use Impeller in scenario_app tests (#50977)
Right now, the scenario_app tests that claim to use Impeller are not actually using Impeller. This is for a few reasons: - The arguments passed via instrumentation do not end up by default on the `Intent` for the `Activity` that is under test. - The arguments passed via instrumentation were in the wrong order and not getting sent to instrumentation at all. This patch updates existing tests to use a new `@Rule` that reads the arguments from the instrumentation's argument `Bundle` and injects them into the `Intent` that we actually pass to the `Activity` under test. It also updates the argument order in the script and adds a verification that Impeller prints that it is being used at least once.
1 parent 0bc21ea commit 4addb6a

File tree

5 files changed

+35
-97
lines changed

5 files changed

+35
-97
lines changed

testing/scenario_app/android/BUILD.gn

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ import("//flutter/testing/rules/android.gni")
77
_android_sources = [
88
"app/build.gradle",
99
"app/src/androidTest/java/dev/flutter/TestRunner.java",
10-
"app/src/androidTest/java/dev/flutter/scenarios/EngineLaunchE2ETest.java",
1110
"app/src/androidTest/java/dev/flutter/scenarios/ExampleInstrumentedTest.java",
1211
"app/src/androidTest/java/dev/flutter/scenariosui/DrawSolidBlueScreenTest.java",
1312
"app/src/androidTest/java/dev/flutter/scenariosui/ExternalTextureTests.java",

testing/scenario_app/android/app/src/androidTest/java/dev/flutter/TestRunner.java

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,21 @@
88
import androidx.annotation.Nullable;
99
import androidx.test.runner.AndroidJUnitRunner;
1010
import dev.flutter.scenariosui.ScreenshotUtil;
11+
import io.flutter.FlutterInjector;
1112

1213
public class TestRunner extends AndroidJUnitRunner {
1314
@Override
1415
public void onCreate(@Nullable Bundle arguments) {
16+
String[] engineArguments = null;
17+
if ("true".equals(arguments.getString("enable-impeller"))) {
18+
// Set up the global settings object so that Impeller is enabled for all tests.
19+
engineArguments = new String[] {"--enable-impeller=true"};
20+
}
21+
// For consistency, just always initilaize FlutterJNI etc.
22+
FlutterInjector.instance().flutterLoader().startInitialization(getTargetContext());
23+
FlutterInjector.instance()
24+
.flutterLoader()
25+
.ensureInitializationComplete(getTargetContext(), engineArguments);
1526
ScreenshotUtil.onCreate();
1627
super.onCreate(arguments);
1728
}

testing/scenario_app/android/app/src/androidTest/java/dev/flutter/scenarios/EngineLaunchE2ETest.java

Lines changed: 0 additions & 83 deletions
This file was deleted.

testing/scenario_app/bin/run_android_tests.dart

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -199,6 +199,7 @@ Future<void> _run({
199199

200200
late Process logcatProcess;
201201
late Future<int> logcatProcessExitCode;
202+
bool seenImpeller = false;
202203

203204
final IOSink logcat = File(logcatPath).openWrite();
204205
try {
@@ -221,6 +222,9 @@ Future<void> _run({
221222
logcatOutput.listen((String line) {
222223
// Always write to the full log.
223224
logcat.writeln(line);
225+
if (enableImpeller && !seenImpeller) {
226+
seenImpeller = line.contains('Using the Impeller rendering backend');
227+
}
224228

225229
// Conditionally parse and write to stderr.
226230
final AdbLogLine? adbLogLine = AdbLogLine.tryParse(line);
@@ -325,11 +329,13 @@ Future<void> _run({
325329
'am',
326330
'instrument',
327331
'-w',
328-
if (smokeTestFullPath != null) '-e class $smokeTestFullPath',
329-
'dev.flutter.scenarios.test/dev.flutter.TestRunner',
330-
if (enableImpeller) '-e enable-impeller',
332+
if (smokeTestFullPath != null)
333+
'-e class $smokeTestFullPath',
334+
if (enableImpeller)
335+
'-e enable-impeller true',
331336
if (impellerBackend != null)
332337
'-e impeller-backend ${impellerBackend.name}',
338+
'dev.flutter.scenarios.test/dev.flutter.TestRunner',
333339
]);
334340
if (exitCode != 0) {
335341
panic(<String>['instrumented tests failed to run']);
@@ -367,6 +373,16 @@ Future<void> _run({
367373
log('wrote logcat to $logcatPath');
368374
});
369375

376+
if (enableImpeller) {
377+
await step('Validating Impeller...', () async {
378+
if (!seenImpeller) {
379+
panic(<String>[
380+
'--enable-impeller was specified, but Impeller was not used.',
381+
]);
382+
}
383+
});
384+
}
385+
370386
await step('Symbolize stack traces', () async {
371387
final ProcessResult result = await pm.run(
372388
<String>[

testing/scenario_app/lib/main.dart

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -25,19 +25,14 @@ void main() {
2525
channelBuffers.setListener('driver', _handleDriverMessage);
2626
channelBuffers.setListener('write_timeline', _handleWriteTimelineMessage);
2727

28-
// TODO(matanlurey): https://github.com/flutter/flutter/issues/142746.
29-
// This Dart program is used for every test, but there is at least one test
30-
// (EngineLaunchE2ETest.java) that does not create a FlutterView, so the
31-
// implicit view's size is not initialized (and the assert would be tripped).
32-
//
33-
// final FlutterView view = PlatformDispatcher.instance.implicitView!;
28+
final FlutterView view = PlatformDispatcher.instance.implicitView!;
3429
// Asserting that this is greater than zero since this app runs on different
3530
// platforms with different sizes. If it is greater than zero, it has been
3631
// initialized to some meaningful value at least.
37-
// assert(
38-
// view.display.size > Offset.zero,
39-
// 'Expected ${view.display} to be initialized.',
40-
// );
32+
assert(
33+
view.display.size > Offset.zero,
34+
'Expected ${view.display} to be initialized.',
35+
);
4136

4237
final ByteData data = ByteData(1);
4338
data.setUint8(0, 1);

0 commit comments

Comments
 (0)