Migrates android semanitcs integration to integration test (#127128)
I think the flake is due to setclipboard or semantics update race condition. I migrated the test to use integration test package which relies less on timing fixes https://github.com/flutter/flutter/issues/124636
This commit is contained in:
@@ -2,13 +2,7 @@
|
||||
// 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 'package:flutter/material.dart';
|
||||
import 'package:flutter/scheduler.dart';
|
||||
import 'package:flutter/services.dart';
|
||||
import 'package:flutter_driver/driver_extension.dart';
|
||||
|
||||
import 'src/tests/controls_page.dart';
|
||||
import 'src/tests/headings_page.dart';
|
||||
@@ -16,49 +10,9 @@ import 'src/tests/popup_page.dart';
|
||||
import 'src/tests/text_field_page.dart';
|
||||
|
||||
void main() {
|
||||
timeDilation = 0.05; // remove animations.
|
||||
enableFlutterDriverExtension(handler: dataHandler);
|
||||
runApp(const TestApp());
|
||||
}
|
||||
|
||||
const MethodChannel kSemanticsChannel = MethodChannel('semantics');
|
||||
|
||||
Future<String> dataHandler(String? message) async {
|
||||
if (message != null && message.contains('getSemanticsNode')) {
|
||||
final Completer<String> completer = Completer<String>();
|
||||
final int id = int.tryParse(message.split('#')[1]) ?? 0;
|
||||
Future<void> completeSemantics([Object? _]) async {
|
||||
final dynamic result = await kSemanticsChannel.invokeMethod<dynamic>('getSemanticsNode', <String, dynamic>{
|
||||
'id': id,
|
||||
});
|
||||
completer.complete(json.encode(result));
|
||||
}
|
||||
if (SchedulerBinding.instance.hasScheduledFrame) {
|
||||
SchedulerBinding.instance.addPostFrameCallback(completeSemantics);
|
||||
} else {
|
||||
completeSemantics();
|
||||
}
|
||||
return completer.future;
|
||||
}
|
||||
if (message != null && message.contains('setClipboard')) {
|
||||
final Completer<String> completer = Completer<String>();
|
||||
final String str = message.split('#')[1];
|
||||
Future<void> completeSetClipboard([Object? _]) async {
|
||||
await kSemanticsChannel.invokeMethod<dynamic>('setClipboard', <String, dynamic>{
|
||||
'message': str,
|
||||
});
|
||||
completer.complete('');
|
||||
}
|
||||
if (SchedulerBinding.instance.hasScheduledFrame) {
|
||||
SchedulerBinding.instance.addPostFrameCallback(completeSetClipboard);
|
||||
} else {
|
||||
completeSetClipboard();
|
||||
}
|
||||
return completer.future;
|
||||
}
|
||||
throw UnimplementedError();
|
||||
}
|
||||
|
||||
Map<String, WidgetBuilder> routes = <String, WidgetBuilder>{
|
||||
selectionControlsRoute : (BuildContext context) => const SelectionControlsPage(),
|
||||
popupControlsRoute : (BuildContext context) => const PopupControlsPage(),
|
||||
|
||||
@@ -98,6 +98,7 @@ enum AndroidSemanticsAction {
|
||||
/// The Android id of the action.
|
||||
final int id;
|
||||
|
||||
// These indices need to be in sync with android_semantics_testing/android/app/src/main/java/com/yourcompany/platforminteraction/MainActivity.java
|
||||
static const int _kFocusIndex = 1 << 0;
|
||||
static const int _kClearFocusIndex = 1 << 1;
|
||||
static const int _kSelectIndex = 1 << 2;
|
||||
|
||||
@@ -77,7 +77,8 @@ class _AndroidSemanticsMatcher extends Matcher {
|
||||
this.isHeading,
|
||||
this.isPassword,
|
||||
this.isLongClickable,
|
||||
});
|
||||
}) : assert(ignoredActions == null || actions != null, 'actions must not be null if ignoredActions is not null'),
|
||||
assert(ignoredActions == null || !actions!.any(ignoredActions.contains));
|
||||
|
||||
final String? text;
|
||||
final String? className;
|
||||
@@ -115,6 +116,9 @@ class _AndroidSemanticsMatcher extends Matcher {
|
||||
if (actions != null) {
|
||||
description.add(' with actions: $actions');
|
||||
}
|
||||
if (ignoredActions != null) {
|
||||
description.add(' with ignoredActions: $ignoredActions');
|
||||
}
|
||||
if (rect != null) {
|
||||
description.add(' with rect: $rect');
|
||||
}
|
||||
@@ -170,13 +174,15 @@ class _AndroidSemanticsMatcher extends Matcher {
|
||||
}
|
||||
if (actions != null) {
|
||||
final List<AndroidSemanticsAction> itemActions = item.getActions();
|
||||
if (ignoredActions != null) {
|
||||
itemActions.removeWhere(ignoredActions!.contains);
|
||||
}
|
||||
if (!unorderedEquals(actions!).matches(itemActions, matchState)) {
|
||||
final List<String> actionsString = actions!.map<String>((AndroidSemanticsAction action) => action.toString()).toList()..sort();
|
||||
final List<String> itemActionsString = itemActions.map<String>((AndroidSemanticsAction action) => action.toString()).toList()..sort();
|
||||
final Set<AndroidSemanticsAction> unexpected = itemActions.toSet().difference(actions!.toSet());
|
||||
final Set<String> unexpectedInString = itemActionsString.toSet().difference(actionsString.toSet());
|
||||
final Set<String> missingInString = actionsString.toSet().difference(itemActionsString.toSet());
|
||||
if (missingInString.isEmpty && ignoredActions != null && unexpected.every(ignoredActions!.contains)) {
|
||||
if (missingInString.isEmpty && unexpectedInString.isEmpty) {
|
||||
return true;
|
||||
}
|
||||
return _failWithMessage('Expected actions: $actionsString\nActual actions: $itemActionsString\nUnexpected: $unexpectedInString\nMissing: $missingInString', matchState);
|
||||
|
||||
Reference in New Issue
Block a user