Added tests for the new Android heading semantic flag to android_semantics_testing (#44031)

Added tests for the new Android heading semantic flag to android_semantics_testing.
This commit is contained in:
Darren Austin
2019-11-04 16:35:04 -08:00
committed by GitHub
parent bbb2a0f837
commit b815f76293
8 changed files with 98 additions and 1 deletions

View File

@@ -33,6 +33,7 @@ class AndroidSemanticsNode {
/// "isEnabled": bool,
/// "isFocusable": bool,
/// "isFocused": bool,
/// "isHeading": bool,
/// "isPassword": bool,
/// "isLongClickable": bool,
/// },
@@ -115,6 +116,9 @@ class AndroidSemanticsNode {
/// Whether the node is focused.
bool get isFocused => _flags['isFocused'];
/// Whether the node is considered a heading.
bool get isHeading => _flags['isHeading'];
/// Whether the node represents a password field.
///
/// Equivalent to [SemanticsFlag.isObscured].

View File

@@ -8,7 +8,10 @@ import 'flutter_test_alternative.dart';
/// Matches an [AndroidSemanticsNode].
///
/// Any properties which aren't supplied are ignored during the comparison.
/// Any properties which aren't supplied are ignored during the comparison,
/// with the exception of `isHeading`. The heading property is not available
/// on all versions of Android. If it is not available on the tested version,
/// it will be match whatever it is compared against.
///
/// This matcher is intended to compare the accessibility values generated by
/// the Android accessibility bridge, and not the semantics object created by
@@ -28,6 +31,7 @@ Matcher hasAndroidSemantics({
bool isEnabled,
bool isFocusable,
bool isFocused,
bool isHeading,
bool isPassword,
bool isLongClickable,
}) {
@@ -45,6 +49,7 @@ Matcher hasAndroidSemantics({
isEnabled: isEnabled,
isFocusable: isFocusable,
isFocused: isFocused,
isHeading: isHeading,
isPassword: isPassword,
isLongClickable: isLongClickable,
);
@@ -65,6 +70,7 @@ class _AndroidSemanticsMatcher extends Matcher {
this.isEditable,
this.isFocusable,
this.isFocused,
this.isHeading,
this.isPassword,
this.isLongClickable,
});
@@ -82,6 +88,7 @@ class _AndroidSemanticsMatcher extends Matcher {
final bool isEnabled;
final bool isFocusable;
final bool isFocused;
final bool isHeading;
final bool isPassword;
final bool isLongClickable;
@@ -112,6 +119,8 @@ class _AndroidSemanticsMatcher extends Matcher {
description.add(' with flag isFocusable: $isFocusable');
if (isFocused != null)
description.add(' with flag isFocused: $isFocused');
if (isHeading != null)
description.add(' with flag isHeading: $isHeading');
if (isPassword != null)
description.add(' with flag isPassword: $isPassword');
if (isLongClickable != null)
@@ -155,6 +164,9 @@ class _AndroidSemanticsMatcher extends Matcher {
return _failWithMessage('Expected isFocusable: $isFocusable', matchState);
if (isFocused != null && isFocused != item.isFocused)
return _failWithMessage('Expected isFocused: $isFocused', matchState);
// Heading is not available in all Android versions, so match anything if it is not set by the platform
if (isHeading != null && isHeading != item.isHeading && item.isHeading != null)
return _failWithMessage('Expected isHeading: $isHeading', matchState);
if (isPassword != null && isPassword != item.isPassword)
return _failWithMessage('Expected isPassword: $isPassword', matchState);
if (isLongClickable != null && isLongClickable != item.isLongClickable)

View File

@@ -0,0 +1,12 @@
// Copyright 2019 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
/// The name of the route containing the test suite.
const String headingsRoute = 'headings';
/// The string supplied to the [ValueKey] for the app bar title widget.
const String appBarTitleKeyValue = 'Headings#AppBarTitle';
/// The string supplied to the [ValueKey] for the body text widget.
const String bodyTextKeyValue = 'Headings#BodyText';

View File

@@ -0,0 +1,28 @@
// Copyright 2019 The Chromium 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 'package:flutter/material.dart';
import 'package:flutter/widgets.dart';
import 'headings_constants.dart';
export 'headings_constants.dart';
/// A test page with an app bar and some body text for testing heading flags.
class HeadingsPage extends StatelessWidget {
static const ValueKey<String> _appBarTitleKey = ValueKey<String>(appBarTitleKeyValue);
static const ValueKey<String> _bodyTextKey = ValueKey<String>(bodyTextKeyValue);
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
leading: const BackButton(key: ValueKey<String>('back')),
title: const Text('Heading', key: _appBarTitleKey),
),
body: const Center(
child: Text('Body text', key: _bodyTextKey),
),
);
}
}