Unverified Commit 2f3f5f09 authored by Yegor's avatar Yegor Committed by GitHub

FlutterDriver: deprecate enableAccessibility; redirect it to setSemantics; add...

FlutterDriver: deprecate enableAccessibility; redirect it to setSemantics; add setSemantics tests (#82939)

* deprecate enableAccessibility; redirect it to setSemantics
Co-authored-by: 's avatarDavid Iglesias <ditman@gmail.com>
parent 843083c9
...@@ -31,7 +31,7 @@ void main() { ...@@ -31,7 +31,7 @@ void main() {
}); });
test('enable accessibility', () async { test('enable accessibility', () async {
await driver.enableAccessibility(); await driver.setSemantics(true);
await Future<void>.delayed(const Duration(seconds: 2)); await Future<void>.delayed(const Duration(seconds: 2));
......
...@@ -174,8 +174,12 @@ abstract class FlutterDriver { ...@@ -174,8 +174,12 @@ abstract class FlutterDriver {
async_io.WebDriver get webDriver => throw UnimplementedError(); async_io.WebDriver get webDriver => throw UnimplementedError();
/// Enables accessibility feature. /// Enables accessibility feature.
@Deprecated(
'Call setSemantics(true) instead. '
'This feature was deprecated after v2.3.0-12.1.pre.'
)
Future<void> enableAccessibility() async { Future<void> enableAccessibility() async {
throw UnimplementedError(); await setSemantics(true);
} }
/// Sends [command] to the Flutter Driver extensions. /// Sends [command] to the Flutter Driver extensions.
...@@ -522,6 +526,13 @@ abstract class FlutterDriver { ...@@ -522,6 +526,13 @@ abstract class FlutterDriver {
/// ///
/// Returns true when the call actually changed the state from on to off or /// Returns true when the call actually changed the state from on to off or
/// vice versa. /// vice versa.
///
/// Does not enable or disable the assistive technology installed on the
/// device. For example, this does not enable VoiceOver on iOS, TalkBack on
/// Android, or NVDA on Windows.
///
/// Enabling semantics on the web causes the engine to render ARIA-annotated
/// HTML.
Future<bool> setSemantics(bool enabled, { Duration? timeout }) async { Future<bool> setSemantics(bool enabled, { Duration? timeout }) async {
final SetSemanticsResult result = SetSemanticsResult.fromJson(await sendCommand(SetSemantics(enabled, timeout: timeout))); final SetSemanticsResult result = SetSemanticsResult.fromJson(await sendCommand(SetSemantics(enabled, timeout: timeout)));
return result.changedState; return result.changedState;
......
...@@ -287,10 +287,6 @@ class VMServiceFlutterDriver extends FlutterDriver { ...@@ -287,10 +287,6 @@ class VMServiceFlutterDriver extends FlutterDriver {
/// Whether to log communication between host and app to `flutter_driver_commands.log`. /// Whether to log communication between host and app to `flutter_driver_commands.log`.
final bool _logCommunicationToFile; final bool _logCommunicationToFile;
@override
Future<void> enableAccessibility() async {
throw UnsupportedError('VMServiceFlutterDriver does not support enableAccessibility');
}
@override @override
Future<Map<String, dynamic>> sendCommand(Command command) async { Future<Map<String, dynamic>> sendCommand(Command command) async {
......
...@@ -39,7 +39,6 @@ class WebFlutterDriver extends FlutterDriver { ...@@ -39,7 +39,6 @@ class WebFlutterDriver extends FlutterDriver {
final FlutterWebConnection _connection; final FlutterWebConnection _connection;
DateTime _startTime; DateTime _startTime;
bool _accessibilityEnabled = false;
static int _nextDriverId = 0; static int _nextDriverId = 0;
/// The unique ID of this driver instance. /// The unique ID of this driver instance.
...@@ -96,22 +95,6 @@ class WebFlutterDriver extends FlutterDriver { ...@@ -96,22 +95,6 @@ class WebFlutterDriver extends FlutterDriver {
); );
} }
@override
Future<void> enableAccessibility() async {
if (!_accessibilityEnabled) {
// Clicks the button to enable accessibility via Javascript for Desktop Web.
//
// The tag used in the script is based on
// https://github.com/flutter/engine/blob/master/lib/web_ui/lib/src/engine/semantics/semantics_helper.dart#L193
//
// TODO(angjieli): Support Mobile Web. (https://github.com/flutter/flutter/issues/65192)
await webDriver.execute(
"document.querySelector('flt-semantics-placeholder').click();",
<String>[]);
_accessibilityEnabled = true;
}
}
@override @override
Future<Map<String, dynamic>> sendCommand(Command command) async { Future<Map<String, dynamic>> sendCommand(Command command) async {
Map<String, dynamic> response; Map<String, dynamic> response;
......
...@@ -630,15 +630,31 @@ void main() { ...@@ -630,15 +630,31 @@ void main() {
}); });
}); });
group('VMServiceFlutterDriver Unsupported error', () { group('setSemantics', () {
test('enableAccessibility', () async { test('can be enabled', () async {
expect(driver.enableAccessibility(), throwsUnsupportedError); fakeClient.responses['set_semantics'] = makeFakeResponse(<String, Object>{
'changedState': true,
});
await driver.setSemantics(true, timeout: _kTestTimeout);
expect(fakeClient.commandLog, <String>[
'ext.flutter.driver {command: set_semantics, timeout: $_kSerializedTestTimeout, enabled: true}',
]);
}); });
test('webDriver', () async { test('can be disabled', () async {
expect(() => driver.webDriver, throwsUnsupportedError); fakeClient.responses['set_semantics'] = makeFakeResponse(<String, Object>{
'changedState': false,
});
await driver.setSemantics(false, timeout: _kTestTimeout);
expect(fakeClient.commandLog, <String>[
'ext.flutter.driver {command: set_semantics, timeout: $_kSerializedTestTimeout, enabled: false}',
]);
}); });
}); });
test('VMServiceFlutterDriver does not support webDriver', () async {
expect(() => driver.webDriver, throwsUnsupportedError);
});
}); });
group('VMServiceFlutterDriver with custom timeout', () { group('VMServiceFlutterDriver with custom timeout', () {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment