Fix semantics_tester (#34368)
This commit is contained in:
parent
72828d66cf
commit
ea6b758720
@ -438,6 +438,7 @@ class DayPicker extends StatelessWidget {
|
|||||||
// formatted full date.
|
// formatted full date.
|
||||||
label: '${localizations.formatDecimal(day)}, ${localizations.formatFullDate(dayToBuild)}',
|
label: '${localizations.formatDecimal(day)}, ${localizations.formatFullDate(dayToBuild)}',
|
||||||
selected: isSelectedDay,
|
selected: isSelectedDay,
|
||||||
|
sortKey: OrdinalSortKey(day.toDouble()),
|
||||||
child: ExcludeSemantics(
|
child: ExcludeSemantics(
|
||||||
child: Text(localizations.formatDecimal(day), style: itemStyle),
|
child: Text(localizations.formatDecimal(day), style: itemStyle),
|
||||||
),
|
),
|
||||||
|
@ -762,7 +762,7 @@ class RenderParagraph extends RenderBox
|
|||||||
TextDirection currentDirection = textDirection;
|
TextDirection currentDirection = textDirection;
|
||||||
Rect currentRect;
|
Rect currentRect;
|
||||||
|
|
||||||
SemanticsConfiguration buildSemanticsConfig(int start, int end, { bool includeText = true }) {
|
SemanticsConfiguration buildSemanticsConfig(int start, int end) {
|
||||||
final TextDirection initialDirection = currentDirection;
|
final TextDirection initialDirection = currentDirection;
|
||||||
final TextSelection selection = TextSelection(baseOffset: start, extentOffset: end);
|
final TextSelection selection = TextSelection(baseOffset: start, extentOffset: end);
|
||||||
final List<ui.TextBox> rects = getBoxesForSelection(selection);
|
final List<ui.TextBox> rects = getBoxesForSelection(selection);
|
||||||
@ -784,10 +784,8 @@ class RenderParagraph extends RenderBox
|
|||||||
order += 1;
|
order += 1;
|
||||||
final SemanticsConfiguration configuration = SemanticsConfiguration()
|
final SemanticsConfiguration configuration = SemanticsConfiguration()
|
||||||
..sortKey = OrdinalSortKey(order)
|
..sortKey = OrdinalSortKey(order)
|
||||||
..textDirection = initialDirection;
|
..textDirection = initialDirection
|
||||||
if (includeText) {
|
..label = rawLabel.substring(start, end);
|
||||||
configuration.label = rawLabel.substring(start, end);
|
|
||||||
}
|
|
||||||
return configuration;
|
return configuration;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -805,7 +803,7 @@ class RenderParagraph extends RenderBox
|
|||||||
newChildren.add(node);
|
newChildren.add(node);
|
||||||
}
|
}
|
||||||
final dynamic inlineElement = _inlineSemanticsElements[j];
|
final dynamic inlineElement = _inlineSemanticsElements[j];
|
||||||
final SemanticsConfiguration configuration = buildSemanticsConfig(start, end, includeText: false);
|
final SemanticsConfiguration configuration = buildSemanticsConfig(start, end);
|
||||||
if (inlineElement != null) {
|
if (inlineElement != null) {
|
||||||
// Add semantics for this recognizer.
|
// Add semantics for this recognizer.
|
||||||
final SemanticsNode node = SemanticsNode();
|
final SemanticsNode node = SemanticsNode();
|
||||||
@ -824,6 +822,9 @@ class RenderParagraph extends RenderBox
|
|||||||
} else if (childIndex < children.length) {
|
} else if (childIndex < children.length) {
|
||||||
// Add semantics for this placeholder. Semantics are precomputed in the children
|
// Add semantics for this placeholder. Semantics are precomputed in the children
|
||||||
// argument.
|
// argument.
|
||||||
|
// Placeholders should not get a label, which would come through as an
|
||||||
|
// object replacement character.
|
||||||
|
configuration.label = '';
|
||||||
final SemanticsNode childNode = children.elementAt(childIndex);
|
final SemanticsNode childNode = children.elementAt(childIndex);
|
||||||
final TextParentData parentData = child.parentData;
|
final TextParentData parentData = child.parentData;
|
||||||
childNode.rect = Rect.fromLTWH(
|
childNode.rect = Rect.fromLTWH(
|
||||||
|
@ -2098,7 +2098,7 @@ class SemanticsNode extends AbstractNode with DiagnosticableTreeMixin {
|
|||||||
properties.add(DoubleProperty('scrollPosition', scrollPosition, defaultValue: null));
|
properties.add(DoubleProperty('scrollPosition', scrollPosition, defaultValue: null));
|
||||||
properties.add(DoubleProperty('scrollExtentMax', scrollExtentMax, defaultValue: null));
|
properties.add(DoubleProperty('scrollExtentMax', scrollExtentMax, defaultValue: null));
|
||||||
properties.add(DoubleProperty('elevation', elevation, defaultValue: 0.0));
|
properties.add(DoubleProperty('elevation', elevation, defaultValue: 0.0));
|
||||||
properties.add(DoubleProperty('thicknes', thickness, defaultValue: 0.0));
|
properties.add(DoubleProperty('thickness', thickness, defaultValue: 0.0));
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Returns a string representation of this node and its descendants.
|
/// Returns a string representation of this node and its descendants.
|
||||||
|
@ -5,7 +5,7 @@ homepage: http://flutter.dev
|
|||||||
|
|
||||||
environment:
|
environment:
|
||||||
# The pub client defaults to an <2.0.0 sdk constraint which we need to explicitly overwrite.
|
# The pub client defaults to an <2.0.0 sdk constraint which we need to explicitly overwrite.
|
||||||
sdk: ">=2.2.0 <3.0.0"
|
sdk: ">=2.2.2 <3.0.0"
|
||||||
|
|
||||||
dependencies:
|
dependencies:
|
||||||
# To update these, use "flutter update-packages --force-upgrade".
|
# To update these, use "flutter update-packages --force-upgrade".
|
||||||
|
@ -449,6 +449,7 @@ void _tests() {
|
|||||||
TestSemantics(
|
TestSemantics(
|
||||||
children: <TestSemantics>[
|
children: <TestSemantics>[
|
||||||
TestSemantics(
|
TestSemantics(
|
||||||
|
id: 55,
|
||||||
actions: <SemanticsAction>[SemanticsAction.scrollLeft, SemanticsAction.scrollRight],
|
actions: <SemanticsAction>[SemanticsAction.scrollLeft, SemanticsAction.scrollRight],
|
||||||
children: <TestSemantics>[
|
children: <TestSemantics>[
|
||||||
TestSemantics(
|
TestSemantics(
|
||||||
@ -456,7 +457,22 @@ void _tests() {
|
|||||||
TestSemantics(
|
TestSemantics(
|
||||||
children: <TestSemantics>[
|
children: <TestSemantics>[
|
||||||
TestSemantics(
|
TestSemantics(
|
||||||
|
id: 11,
|
||||||
|
flags: <SemanticsFlag>[SemanticsFlag.hasImplicitScrolling],
|
||||||
children: <TestSemantics>[
|
children: <TestSemantics>[
|
||||||
|
// TODO(dnfield): These shouldn't be here. https://github.com/flutter/flutter/issues/34431
|
||||||
|
TestSemantics(),
|
||||||
|
TestSemantics(),
|
||||||
|
TestSemantics(),
|
||||||
|
TestSemantics(),
|
||||||
|
TestSemantics(),
|
||||||
|
TestSemantics(),
|
||||||
|
TestSemantics(),
|
||||||
|
TestSemantics(),
|
||||||
|
TestSemantics(),
|
||||||
|
TestSemantics(),
|
||||||
|
TestSemantics(),
|
||||||
|
TestSemantics(),
|
||||||
TestSemantics(
|
TestSemantics(
|
||||||
actions: <SemanticsAction>[SemanticsAction.tap],
|
actions: <SemanticsAction>[SemanticsAction.tap],
|
||||||
label: '1, Friday, January 1, 2016',
|
label: '1, Friday, January 1, 2016',
|
||||||
|
@ -530,7 +530,7 @@ void main() {
|
|||||||
SemanticsFlag.isTextField,
|
SemanticsFlag.isTextField,
|
||||||
SemanticsFlag.isFocused,
|
SemanticsFlag.isFocused,
|
||||||
SemanticsFlag.isHeader,
|
SemanticsFlag.isHeader,
|
||||||
SemanticsFlag.namesRoute,
|
if (debugDefaultTargetPlatformOverride != TargetPlatform.iOS) SemanticsFlag.namesRoute,
|
||||||
],
|
],
|
||||||
actions: <SemanticsAction>[
|
actions: <SemanticsAction>[
|
||||||
SemanticsAction.tap,
|
SemanticsAction.tap,
|
||||||
@ -539,6 +539,7 @@ void main() {
|
|||||||
],
|
],
|
||||||
label: 'Search',
|
label: 'Search',
|
||||||
textDirection: TextDirection.ltr,
|
textDirection: TextDirection.ltr,
|
||||||
|
textSelection: const TextSelection(baseOffset: 0, extentOffset: 0),
|
||||||
),
|
),
|
||||||
],
|
],
|
||||||
),
|
),
|
||||||
|
@ -353,7 +353,7 @@ void main() {
|
|||||||
' scrollPosition: null\n'
|
' scrollPosition: null\n'
|
||||||
' scrollExtentMax: null\n'
|
' scrollExtentMax: null\n'
|
||||||
' elevation: 0.0\n'
|
' elevation: 0.0\n'
|
||||||
' thicknes: 0.0\n',
|
' thickness: 0.0\n',
|
||||||
);
|
);
|
||||||
|
|
||||||
final SemanticsConfiguration config = SemanticsConfiguration()
|
final SemanticsConfiguration config = SemanticsConfiguration()
|
||||||
@ -448,7 +448,7 @@ void main() {
|
|||||||
' scrollPosition: null\n'
|
' scrollPosition: null\n'
|
||||||
' scrollExtentMax: null\n'
|
' scrollExtentMax: null\n'
|
||||||
' elevation: 0.0\n'
|
' elevation: 0.0\n'
|
||||||
' thicknes: 0.0\n',
|
' thickness: 0.0\n',
|
||||||
);
|
);
|
||||||
|
|
||||||
});
|
});
|
||||||
|
@ -335,7 +335,9 @@ class TestSemantics {
|
|||||||
result = false;
|
result = false;
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
return true;
|
}
|
||||||
|
if (it.moveNext()) {
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
@ -603,7 +605,6 @@ class SemanticsTester {
|
|||||||
buf.writeln(' hint: \'${node.hint}\',');
|
buf.writeln(' hint: \'${node.hint}\',');
|
||||||
if (node.textDirection != null)
|
if (node.textDirection != null)
|
||||||
buf.writeln(' textDirection: ${node.textDirection},');
|
buf.writeln(' textDirection: ${node.textDirection},');
|
||||||
|
|
||||||
if (node.hasChildren) {
|
if (node.hasChildren) {
|
||||||
buf.writeln(' children: <TestSemantics>[');
|
buf.writeln(' children: <TestSemantics>[');
|
||||||
for (final SemanticsNode child in node.debugListChildrenInOrder(childOrder)) {
|
for (final SemanticsNode child in node.debugListChildrenInOrder(childOrder)) {
|
||||||
|
44
packages/flutter/test/widgets/semantics_tester_test.dart
Normal file
44
packages/flutter/test/widgets/semantics_tester_test.dart
Normal file
@ -0,0 +1,44 @@
|
|||||||
|
// Copyright 2019 The Flutter 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/gestures.dart';
|
||||||
|
import 'package:flutter/widgets.dart';
|
||||||
|
import 'package:flutter_test/flutter_test.dart';
|
||||||
|
|
||||||
|
import 'semantics_tester.dart';
|
||||||
|
|
||||||
|
void main() {
|
||||||
|
testWidgets('Semantics tester visits last child', (WidgetTester tester) async {
|
||||||
|
final SemanticsTester semantics = SemanticsTester(tester);
|
||||||
|
const TextStyle textStyle = TextStyle(fontFamily: 'Ahem');
|
||||||
|
await tester.pumpWidget(
|
||||||
|
Text.rich(
|
||||||
|
TextSpan(
|
||||||
|
children: <TextSpan>[
|
||||||
|
const TextSpan(text: 'hello'),
|
||||||
|
TextSpan(text: 'world', recognizer: TapGestureRecognizer()..onTap = () { }),
|
||||||
|
],
|
||||||
|
style: textStyle,
|
||||||
|
),
|
||||||
|
textDirection: TextDirection.ltr,
|
||||||
|
maxLines: 1,
|
||||||
|
),
|
||||||
|
);
|
||||||
|
final TestSemantics expectedSemantics = TestSemantics.root(
|
||||||
|
children: <TestSemantics>[
|
||||||
|
TestSemantics.rootChild(
|
||||||
|
children: <TestSemantics>[
|
||||||
|
TestSemantics(
|
||||||
|
label: 'hello',
|
||||||
|
textDirection: TextDirection.ltr,
|
||||||
|
),
|
||||||
|
TestSemantics(),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
],
|
||||||
|
);
|
||||||
|
expect(semantics, isNot(hasSemantics(expectedSemantics, ignoreTransform: true, ignoreId: true, ignoreRect: true)));
|
||||||
|
semantics.dispose();
|
||||||
|
});
|
||||||
|
}
|
@ -152,11 +152,11 @@ void main() {
|
|||||||
// ┌─────────────────┘
|
// ┌─────────────────┘
|
||||||
// V
|
// V
|
||||||
// ┌───┐ ┌─────────┐ ┌───┐
|
// ┌───┐ ┌─────────┐ ┌───┐
|
||||||
// │ E │ │ │>│ H │
|
// │ E │>│ │>│ G │
|
||||||
// └───┘ │ G │ └───┘
|
// └───┘ │ F │ └───┘
|
||||||
// V │ │ V
|
// ┌───|─────────|───┘
|
||||||
// ┌───┐ │ │ ┌───┐
|
// ┌───┐ │ │ ┌───┐
|
||||||
// │ F │>│ │ │ I │
|
// │ H │─|─────────|>│ I │
|
||||||
// └───┘ └─────────┘ └───┘
|
// └───┘ └─────────┘ └───┘
|
||||||
// ┌─────────────────┘
|
// ┌─────────────────┘
|
||||||
// V
|
// V
|
||||||
@ -171,11 +171,11 @@ void main() {
|
|||||||
// └─────────────────┐
|
// └─────────────────┐
|
||||||
// V
|
// V
|
||||||
// ┌───┐ ┌─────────┐ ┌───┐
|
// ┌───┐ ┌─────────┐ ┌───┐
|
||||||
// │ E │<│ │ │ H │
|
// │ E │<│ │<│ G │
|
||||||
// └───┘ │ G │ └───┘
|
// └───┘ │ F │ └───┘
|
||||||
// V │ │ V
|
// └──|─────────|────┐
|
||||||
// ┌───┐ │ │ ┌───┐
|
// ┌───┐ │ │ ┌───┐
|
||||||
// │ F │ │ │<│ I │
|
// │ H │<|─────────|─│ I │
|
||||||
// └───┘ └─────────┘ └───┘
|
// └───┘ └─────────┘ └───┘
|
||||||
// └─────────────────┐
|
// └─────────────────┐
|
||||||
// V
|
// V
|
||||||
@ -189,9 +189,9 @@ void main() {
|
|||||||
'C': const Offset(40.0, 0.0) & tenByTen,
|
'C': const Offset(40.0, 0.0) & tenByTen,
|
||||||
'D': const Offset(60.0, 0.0) & tenByTen,
|
'D': const Offset(60.0, 0.0) & tenByTen,
|
||||||
'E': const Offset(0.0, 20.0) & tenByTen,
|
'E': const Offset(0.0, 20.0) & tenByTen,
|
||||||
'F': const Offset(0.0, 40.0) & tenByTen,
|
'F': const Offset(20.0, 20.0) & (tenByTen * 2.0),
|
||||||
'G': const Offset(20.0, 20.0) & (tenByTen * 2.0),
|
'G': const Offset(60.0, 20.0) & tenByTen,
|
||||||
'H': const Offset(60.0, 20.0) & tenByTen,
|
'H': const Offset(0.0, 40.0) & tenByTen,
|
||||||
'I': const Offset(60.0, 40.0) & tenByTen,
|
'I': const Offset(60.0, 40.0) & tenByTen,
|
||||||
'J': const Offset(0.0, 60.0) & tenByTen,
|
'J': const Offset(0.0, 60.0) & tenByTen,
|
||||||
'K': const Offset(20.0, 60.0) & tenByTen,
|
'K': const Offset(20.0, 60.0) & tenByTen,
|
||||||
@ -208,7 +208,7 @@ void main() {
|
|||||||
await tester.test(
|
await tester.test(
|
||||||
textDirection: TextDirection.rtl,
|
textDirection: TextDirection.rtl,
|
||||||
children: children,
|
children: children,
|
||||||
expectedTraversal: 'D C B A H I G E F M L K J',
|
expectedTraversal: 'D C B A G F E I H M L K J',
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -168,6 +168,7 @@ void _tests() {
|
|||||||
SemanticsAction.scrollUp,
|
SemanticsAction.scrollUp,
|
||||||
SemanticsAction.scrollDown,
|
SemanticsAction.scrollDown,
|
||||||
],
|
],
|
||||||
|
flags: <SemanticsFlag>[SemanticsFlag.hasImplicitScrolling],
|
||||||
children: <TestSemantics>[
|
children: <TestSemantics>[
|
||||||
TestSemantics(
|
TestSemantics(
|
||||||
id: 3,
|
id: 3,
|
||||||
@ -521,6 +522,7 @@ void _tests() {
|
|||||||
SemanticsAction.scrollUp,
|
SemanticsAction.scrollUp,
|
||||||
SemanticsAction.scrollDown,
|
SemanticsAction.scrollDown,
|
||||||
],
|
],
|
||||||
|
flags: <SemanticsFlag>[SemanticsFlag.hasImplicitScrolling],
|
||||||
children: <TestSemantics>[
|
children: <TestSemantics>[
|
||||||
TestSemantics(
|
TestSemantics(
|
||||||
flags: <SemanticsFlag>[SemanticsFlag.isHidden],
|
flags: <SemanticsFlag>[SemanticsFlag.isHidden],
|
||||||
@ -630,6 +632,7 @@ void _tests() {
|
|||||||
SemanticsAction.scrollUp,
|
SemanticsAction.scrollUp,
|
||||||
SemanticsAction.scrollDown,
|
SemanticsAction.scrollDown,
|
||||||
],
|
],
|
||||||
|
flags: <SemanticsFlag>[SemanticsFlag.hasImplicitScrolling],
|
||||||
children: <TestSemantics>[
|
children: <TestSemantics>[
|
||||||
TestSemantics(
|
TestSemantics(
|
||||||
flags: <SemanticsFlag>[SemanticsFlag.isHidden],
|
flags: <SemanticsFlag>[SemanticsFlag.isHidden],
|
||||||
@ -994,6 +997,7 @@ void _tests() {
|
|||||||
SemanticsAction.scrollUp,
|
SemanticsAction.scrollUp,
|
||||||
SemanticsAction.scrollDown,
|
SemanticsAction.scrollDown,
|
||||||
],
|
],
|
||||||
|
flags: <SemanticsFlag>[SemanticsFlag.hasImplicitScrolling],
|
||||||
children: <TestSemantics>[
|
children: <TestSemantics>[
|
||||||
TestSemantics(
|
TestSemantics(
|
||||||
flags: <SemanticsFlag>[SemanticsFlag.isHidden],
|
flags: <SemanticsFlag>[SemanticsFlag.isHidden],
|
||||||
|
@ -218,7 +218,7 @@ void main() {
|
|||||||
],
|
],
|
||||||
),
|
),
|
||||||
TestSemantics(
|
TestSemantics(
|
||||||
label: ' regrettable event',
|
label: ' this is a regrettable event',
|
||||||
textDirection: TextDirection.ltr,
|
textDirection: TextDirection.ltr,
|
||||||
),
|
),
|
||||||
],
|
],
|
||||||
@ -414,7 +414,7 @@ void main() {
|
|||||||
TestSemantics(
|
TestSemantics(
|
||||||
label: 'INTERRUPTION',
|
label: 'INTERRUPTION',
|
||||||
textDirection: TextDirection.rtl,
|
textDirection: TextDirection.rtl,
|
||||||
rect: const Rect.fromLTRB(448.0, 0.0, 488.0, 80.0),
|
rect: const Rect.fromLTRB(0.0, 0.0, 40.0, 80.0),
|
||||||
),
|
),
|
||||||
TestSemantics(
|
TestSemantics(
|
||||||
label: 'sky',
|
label: 'sky',
|
||||||
|
Loading…
x
Reference in New Issue
Block a user