Skip to content

Commit 7f783e3

Browse files
author
Jonah Williams
authored
[Android] fix hcpp tapping, again, and add test. (flutter#163035)
I didn't actually fix it. lets add a test this time.
1 parent 2376fa0 commit 7f783e3

File tree

3 files changed

+140
-1
lines changed

3 files changed

+140
-1
lines changed
Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
// Copyright 2014 The Flutter Authors. All rights reserved.
2+
// Use of this source code is governed by a BSD-style license that can be
3+
// found in the LICENSE file.
4+
5+
import 'dart:convert';
6+
7+
import 'package:android_driver_extensions/extension.dart';
8+
import 'package:flutter/foundation.dart';
9+
import 'package:flutter/gestures.dart';
10+
import 'package:flutter/material.dart';
11+
import 'package:flutter/rendering.dart';
12+
import 'package:flutter/services.dart';
13+
import 'package:flutter_driver/driver_extension.dart';
14+
15+
import '../src/allow_list_devices.dart';
16+
17+
void main() async {
18+
ensureAndroidDevice();
19+
enableFlutterDriverExtension(
20+
handler: (String? command) async {
21+
return json.encode(<String, Object?>{
22+
'supported': await HybridAndroidViewController.checkIfSupported(),
23+
});
24+
},
25+
commands: <CommandExtension>[nativeDriverCommands],
26+
);
27+
28+
// Run on full screen.
29+
await SystemChrome.setEnabledSystemUIMode(SystemUiMode.immersive);
30+
runApp(const MainApp());
31+
}
32+
33+
final class MainApp extends StatelessWidget {
34+
const MainApp({super.key});
35+
36+
@override
37+
Widget build(BuildContext context) {
38+
return const MaterialApp(
39+
debugShowCheckedModeBanner: false,
40+
home: _HybridCompositionAndroidPlatformView(viewType: 'changing_color_button_platform_view'),
41+
);
42+
}
43+
}
44+
45+
final class _HybridCompositionAndroidPlatformView extends StatelessWidget {
46+
const _HybridCompositionAndroidPlatformView({required this.viewType});
47+
48+
final String viewType;
49+
50+
@override
51+
Widget build(BuildContext context) {
52+
return PlatformViewLink(
53+
viewType: viewType,
54+
surfaceFactory: (BuildContext context, PlatformViewController controller) {
55+
return AndroidViewSurface(
56+
controller: controller as AndroidViewController,
57+
gestureRecognizers: const <Factory<OneSequenceGestureRecognizer>>{},
58+
hitTestBehavior: PlatformViewHitTestBehavior.opaque,
59+
);
60+
},
61+
onCreatePlatformView: (PlatformViewCreationParams params) {
62+
return PlatformViewsService.initHybridAndroidView(
63+
id: params.id,
64+
viewType: viewType,
65+
layoutDirection: TextDirection.ltr,
66+
creationParamsCodec: const StandardMessageCodec(),
67+
)
68+
..addOnPlatformViewCreatedListener(params.onPlatformViewCreated)
69+
..create();
70+
},
71+
);
72+
}
73+
}
Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
// Copyright 2014 The Flutter Authors. All rights reserved.
2+
// Use of this source code is governed by a BSD-style license that can be
3+
// found in the LICENSE file.
4+
5+
import 'dart:convert';
6+
7+
import 'package:android_driver_extensions/native_driver.dart';
8+
import 'package:android_driver_extensions/skia_gold.dart';
9+
import 'package:flutter_driver/flutter_driver.dart';
10+
import 'package:test/test.dart';
11+
12+
import '../_luci_skia_gold_prelude.dart';
13+
14+
/// For local debugging, a (local) golden-file is required as a baseline:
15+
///
16+
/// ```sh
17+
/// # Checkout HEAD, i.e. *before* changes you want to test.
18+
/// UPDATE_GOLDENS=1 flutter drive lib/platform_view_tap_color_change_main.dart
19+
///
20+
/// # Make your changes.
21+
///
22+
/// # Run the test against baseline.
23+
/// flutter drive lib/platform_view_tap_color_change_main.dart
24+
/// ```
25+
///
26+
/// For a convenient way to deflake a test, see `tool/deflake.dart`.
27+
void main() async {
28+
const String goldenPrefix = 'hybrid_composition_pp_platform_view';
29+
30+
late final FlutterDriver flutterDriver;
31+
late final NativeDriver nativeDriver;
32+
33+
setUpAll(() async {
34+
if (isLuci) {
35+
await enableSkiaGoldComparator(namePrefix: 'android_engine_test$goldenVariant');
36+
}
37+
flutterDriver = await FlutterDriver.connect();
38+
nativeDriver = await AndroidNativeDriver.connect(flutterDriver);
39+
await nativeDriver.configureForScreenshotTesting();
40+
});
41+
42+
tearDownAll(() async {
43+
await nativeDriver.close();
44+
await flutterDriver.close();
45+
});
46+
47+
test('verify that HCPP is supported and enabled', () async {
48+
final Map<String, Object?> response =
49+
json.decode(await flutterDriver.requestData('')) as Map<String, Object?>;
50+
51+
expect(response['supported'], true);
52+
}, timeout: Timeout.none);
53+
54+
test('should screenshot a rectangle that becomes blue after a tap with hcpp', () async {
55+
await expectLater(
56+
nativeDriver.screenshot(),
57+
matchesGoldenFile('$goldenPrefix.tap_color_change_initial.png'),
58+
);
59+
60+
await nativeDriver.tap(const ByNativeAccessibilityLabel('Change color'));
61+
await expectLater(
62+
nativeDriver.screenshot(),
63+
matchesGoldenFile('$goldenPrefix.tap_color_change_tapped.png'),
64+
);
65+
}, timeout: Timeout.none);
66+
}

packages/flutter/lib/src/services/platform_views.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1205,7 +1205,7 @@ class HybridAndroidViewController extends AndroidViewController {
12051205

12061206
@override
12071207
Future<void> sendMotionEvent(AndroidMotionEvent event) async {
1208-
await SystemChannels.platform_views.invokeMethod<dynamic>('touch', event._asList(viewId));
1208+
await SystemChannels.platform_views_2.invokeMethod<dynamic>('touch', event._asList(viewId));
12091209
}
12101210
}
12111211

0 commit comments

Comments
 (0)