Add android semantics integration test to device lab (#20971)
This commit is contained in:
@@ -37,6 +37,7 @@ class AndroidSemanticsNode {
|
||||
/// "isLongClickable": bool,
|
||||
/// },
|
||||
/// "text": String,
|
||||
/// "contentDescription": String,
|
||||
/// "className": String,
|
||||
/// "id": int,
|
||||
/// "rect": {
|
||||
@@ -64,6 +65,16 @@ class AndroidSemanticsNode {
|
||||
/// the Flutter [SemanticsNode].
|
||||
String get text => _values['text'];
|
||||
|
||||
/// The contentDescription of the semantics node.
|
||||
///
|
||||
/// This field is used for the Switch, Radio, and Checkbox widgets
|
||||
/// instead of [text]. If the text property is used for these, TalkBack
|
||||
/// will not read out the "checked" or "not checked" label by default.
|
||||
///
|
||||
/// This is produced by combining the value, label, and hint fields from
|
||||
/// the Flutter [SemanticsNode].
|
||||
String get contentDescription => _values['contentDescription'];
|
||||
|
||||
/// The className of the semantics node.
|
||||
///
|
||||
/// Certain kinds of Flutter semantics are mapped to Android classes to
|
||||
|
||||
@@ -21,6 +21,9 @@ class AndroidClassName {
|
||||
|
||||
/// The class name used for read only text fields.
|
||||
static const String textView = 'android.widget.TextView';
|
||||
|
||||
/// The class name used for toggle switches.
|
||||
static const String toggleSwitch = 'android.widget.Switch';
|
||||
}
|
||||
|
||||
/// Action constants which correspond to `AccessibilityAction` in Android.
|
||||
|
||||
@@ -0,0 +1,14 @@
|
||||
// Copyright 2018 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.
|
||||
|
||||
// Defines a 'package:test' shim.
|
||||
// TODO(ianh): Remove this file once https://github.com/dart-lang/matcher/issues/98 is fixed
|
||||
|
||||
import 'package:test/test.dart' hide TypeMatcher, isInstanceOf;
|
||||
import 'package:test/test.dart' as test_package show TypeMatcher;
|
||||
|
||||
export 'package:test/test.dart' hide TypeMatcher, isInstanceOf;
|
||||
|
||||
/// A matcher that compares the type of the actual value to the type argument T.
|
||||
Matcher isInstanceOf<T>() => new test_package.TypeMatcher<T>(); // ignore: prefer_const_constructors, https://github.com/dart-lang/sdk/issues/32544
|
||||
@@ -2,10 +2,9 @@
|
||||
// Use of this source code is governed by a BSD-style license that can be
|
||||
// found in the LICENSE file.
|
||||
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
|
||||
import 'common.dart';
|
||||
import 'constants.dart';
|
||||
import 'flutter_test_alternative.dart';
|
||||
|
||||
/// Matches an [AndroidSemanticsNode].
|
||||
///
|
||||
@@ -16,6 +15,7 @@ import 'constants.dart';
|
||||
/// the Flutter framework.
|
||||
Matcher hasAndroidSemantics({
|
||||
String text,
|
||||
String contentDescription,
|
||||
String className,
|
||||
int id,
|
||||
Rect rect,
|
||||
@@ -33,6 +33,7 @@ Matcher hasAndroidSemantics({
|
||||
}) {
|
||||
return new _AndroidSemanticsMatcher(
|
||||
text: text,
|
||||
contentDescription: contentDescription,
|
||||
className: className,
|
||||
rect: rect,
|
||||
size: size,
|
||||
@@ -52,6 +53,7 @@ Matcher hasAndroidSemantics({
|
||||
class _AndroidSemanticsMatcher extends Matcher {
|
||||
_AndroidSemanticsMatcher({
|
||||
this.text,
|
||||
this.contentDescription,
|
||||
this.className,
|
||||
this.id,
|
||||
this.actions,
|
||||
@@ -69,6 +71,7 @@ class _AndroidSemanticsMatcher extends Matcher {
|
||||
|
||||
final String text;
|
||||
final String className;
|
||||
final String contentDescription;
|
||||
final int id;
|
||||
final List<AndroidSemanticsAction> actions;
|
||||
final Rect rect;
|
||||
@@ -87,6 +90,8 @@ class _AndroidSemanticsMatcher extends Matcher {
|
||||
description.add('AndroidSemanticsNode');
|
||||
if (text != null)
|
||||
description.add(' with text: $text');
|
||||
if (contentDescription != null)
|
||||
description.add( 'with contentDescription $contentDescription');
|
||||
if (className != null)
|
||||
description.add(' with className: $className');
|
||||
if (id != null)
|
||||
@@ -118,6 +123,8 @@ class _AndroidSemanticsMatcher extends Matcher {
|
||||
bool matches(covariant AndroidSemanticsNode item, Map<Object, Object> matchState) {
|
||||
if (text != null && text != item.text)
|
||||
return _failWithMessage('Expected text: $text', matchState);
|
||||
if (contentDescription != null && contentDescription != item.contentDescription)
|
||||
return _failWithMessage('Expected contentDescription: $contentDescription', matchState);
|
||||
if (className != null && className != item.className)
|
||||
return _failWithMessage('Expected className: $className', matchState);
|
||||
if (id != null && id != item.id)
|
||||
|
||||
@@ -0,0 +1,30 @@
|
||||
// Copyright 2018 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 selectionControlsRoute = 'controls';
|
||||
|
||||
/// The string supplied to the [ValueKey] for the enabled checkbox.
|
||||
const String checkboxKeyValue = 'SelectionControls#Checkbox1';
|
||||
|
||||
/// The string supplied to the [ValueKey] for the disabled checkbox.
|
||||
const String disabledCheckboxKeyValue = 'SelectionControls#Checkbox2';
|
||||
|
||||
/// The string supplied to the [ValueKey] for the radio button with value 1.
|
||||
const String radio1KeyValue = 'SelectionControls#Radio1';
|
||||
|
||||
/// The string supplied to the [ValueKey] for the radio button with value 2.
|
||||
const String radio2KeyValue = 'SelectionControls#Radio2';
|
||||
|
||||
/// The string supplied to the [ValueKey] for the radio button with value 3.
|
||||
const String radio3KeyValue = 'SelectionControls#Radio3';
|
||||
|
||||
/// The string supplied to the [ValueKey] for the switch.
|
||||
const String switchKeyValue = 'SelectionControls#Switch1';
|
||||
|
||||
/// The string supplied to the [ValueKey] for the labeled switch.
|
||||
const String labeledSwitchKeyValue = 'SelectionControls#Switch2';
|
||||
|
||||
/// The label of the labeled switch.
|
||||
const String switchLabel = 'Label';
|
||||
@@ -0,0 +1,103 @@
|
||||
// Copyright 2018 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 'controls_constants.dart';
|
||||
export 'controls_constants.dart';
|
||||
|
||||
/// A test page with a checkbox, three radio buttons, and a switch.
|
||||
class SelectionControlsPage extends StatefulWidget {
|
||||
@override
|
||||
State<StatefulWidget> createState() => new _SelectionControlsPageState();
|
||||
}
|
||||
|
||||
class _SelectionControlsPageState extends State<SelectionControlsPage> {
|
||||
static const ValueKey<String> checkbox1Key = ValueKey<String>(checkboxKeyValue);
|
||||
static const ValueKey<String> checkbox2Key = ValueKey<String>(disabledCheckboxKeyValue);
|
||||
static const ValueKey<String> radio1Key = ValueKey<String>(radio1KeyValue);
|
||||
static const ValueKey<String> radio2Key = ValueKey<String>(radio2KeyValue);
|
||||
static const ValueKey<String> radio3Key = ValueKey<String>(radio3KeyValue);
|
||||
static const ValueKey<String> switchKey = ValueKey<String>(switchKeyValue);
|
||||
static const ValueKey<String> labeledSwitchKey = ValueKey<String>(labeledSwitchKeyValue);
|
||||
bool _isChecked = false;
|
||||
bool _isOn = false;
|
||||
bool _isLabeledOn = false;
|
||||
int _radio = 0;
|
||||
|
||||
void _updateCheckbox(bool newValue) {
|
||||
setState(() {
|
||||
_isChecked = newValue;
|
||||
});
|
||||
}
|
||||
|
||||
void _updateRadio(int newValue) {
|
||||
setState(() {
|
||||
_radio = newValue;
|
||||
});
|
||||
}
|
||||
|
||||
void _updateSwitch(bool newValue) {
|
||||
setState(() {
|
||||
_isOn = newValue;
|
||||
});
|
||||
}
|
||||
|
||||
void _updateLabeledSwitch(bool newValue) {
|
||||
setState(() {
|
||||
_isLabeledOn = newValue;
|
||||
});
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return new Scaffold(
|
||||
appBar: new AppBar(leading: const BackButton(key: ValueKey<String>('back'))),
|
||||
body: new Material(
|
||||
child: new Column(children: <Widget>[
|
||||
new Row(
|
||||
children: <Widget>[
|
||||
new Checkbox(
|
||||
key: checkbox1Key,
|
||||
value: _isChecked,
|
||||
onChanged: _updateCheckbox,
|
||||
),
|
||||
const Checkbox(
|
||||
key: checkbox2Key,
|
||||
value: false,
|
||||
onChanged: null,
|
||||
),
|
||||
],
|
||||
),
|
||||
const Spacer(),
|
||||
new Row(children: <Widget>[
|
||||
new Radio<int>(key: radio1Key, value: 0, groupValue: _radio, onChanged: _updateRadio),
|
||||
new Radio<int>(key: radio2Key, value: 1, groupValue: _radio, onChanged: _updateRadio),
|
||||
new Radio<int>(key: radio3Key, value: 2, groupValue: _radio, onChanged: _updateRadio),
|
||||
]),
|
||||
const Spacer(),
|
||||
new Switch(
|
||||
key: switchKey,
|
||||
value: _isOn,
|
||||
onChanged: _updateSwitch,
|
||||
),
|
||||
const Spacer(),
|
||||
new MergeSemantics(
|
||||
child: new Row(
|
||||
children: <Widget>[
|
||||
const Text(switchLabel),
|
||||
new Switch(
|
||||
key: labeledSwitchKey,
|
||||
value: _isLabeledOn,
|
||||
onChanged: _updateLabeledSwitch,
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
]),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user