Unverified Commit ea6b7587 authored by Dan Field's avatar Dan Field Committed by GitHub

Fix semantics_tester (#34368)

parent 72828d66
......@@ -438,6 +438,7 @@ class DayPicker extends StatelessWidget {
// formatted full date.
label: '${localizations.formatDecimal(day)}, ${localizations.formatFullDate(dayToBuild)}',
selected: isSelectedDay,
sortKey: OrdinalSortKey(day.toDouble()),
child: ExcludeSemantics(
child: Text(localizations.formatDecimal(day), style: itemStyle),
),
......
......@@ -762,7 +762,7 @@ class RenderParagraph extends RenderBox
TextDirection currentDirection = textDirection;
Rect currentRect;
SemanticsConfiguration buildSemanticsConfig(int start, int end, { bool includeText = true }) {
SemanticsConfiguration buildSemanticsConfig(int start, int end) {
final TextDirection initialDirection = currentDirection;
final TextSelection selection = TextSelection(baseOffset: start, extentOffset: end);
final List<ui.TextBox> rects = getBoxesForSelection(selection);
......@@ -784,10 +784,8 @@ class RenderParagraph extends RenderBox
order += 1;
final SemanticsConfiguration configuration = SemanticsConfiguration()
..sortKey = OrdinalSortKey(order)
..textDirection = initialDirection;
if (includeText) {
configuration.label = rawLabel.substring(start, end);
}
..textDirection = initialDirection
..label = rawLabel.substring(start, end);
return configuration;
}
......@@ -805,7 +803,7 @@ class RenderParagraph extends RenderBox
newChildren.add(node);
}
final dynamic inlineElement = _inlineSemanticsElements[j];
final SemanticsConfiguration configuration = buildSemanticsConfig(start, end, includeText: false);
final SemanticsConfiguration configuration = buildSemanticsConfig(start, end);
if (inlineElement != null) {
// Add semantics for this recognizer.
final SemanticsNode node = SemanticsNode();
......@@ -824,6 +822,9 @@ class RenderParagraph extends RenderBox
} else if (childIndex < children.length) {
// Add semantics for this placeholder. Semantics are precomputed in the children
// 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 TextParentData parentData = child.parentData;
childNode.rect = Rect.fromLTWH(
......
......@@ -2098,7 +2098,7 @@ class SemanticsNode extends AbstractNode with DiagnosticableTreeMixin {
properties.add(DoubleProperty('scrollPosition', scrollPosition, defaultValue: null));
properties.add(DoubleProperty('scrollExtentMax', scrollExtentMax, defaultValue: null));
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.
......
......@@ -5,7 +5,7 @@ homepage: http://flutter.dev
environment:
# 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:
# To update these, use "flutter update-packages --force-upgrade".
......
......@@ -449,6 +449,7 @@ void _tests() {
TestSemantics(
children: <TestSemantics>[
TestSemantics(
id: 55,
actions: <SemanticsAction>[SemanticsAction.scrollLeft, SemanticsAction.scrollRight],
children: <TestSemantics>[
TestSemantics(
......@@ -456,7 +457,22 @@ void _tests() {
TestSemantics(
children: <TestSemantics>[
TestSemantics(
id: 11,
flags: <SemanticsFlag>[SemanticsFlag.hasImplicitScrolling],
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(
actions: <SemanticsAction>[SemanticsAction.tap],
label: '1, Friday, January 1, 2016',
......
......@@ -530,7 +530,7 @@ void main() {
SemanticsFlag.isTextField,
SemanticsFlag.isFocused,
SemanticsFlag.isHeader,
SemanticsFlag.namesRoute,
if (debugDefaultTargetPlatformOverride != TargetPlatform.iOS) SemanticsFlag.namesRoute,
],
actions: <SemanticsAction>[
SemanticsAction.tap,
......@@ -539,6 +539,7 @@ void main() {
],
label: 'Search',
textDirection: TextDirection.ltr,
textSelection: const TextSelection(baseOffset: 0, extentOffset: 0),
),
],
),
......
......@@ -353,7 +353,7 @@ void main() {
' scrollPosition: null\n'
' scrollExtentMax: null\n'
' elevation: 0.0\n'
' thicknes: 0.0\n',
' thickness: 0.0\n',
);
final SemanticsConfiguration config = SemanticsConfiguration()
......@@ -448,7 +448,7 @@ void main() {
' scrollPosition: null\n'
' scrollExtentMax: null\n'
' elevation: 0.0\n'
' thicknes: 0.0\n',
' thickness: 0.0\n',
);
});
......
......@@ -335,7 +335,9 @@ class TestSemantics {
result = false;
return false;
}
return true;
}
if (it.moveNext()) {
return false;
}
return result;
}
......@@ -603,7 +605,6 @@ class SemanticsTester {
buf.writeln(' hint: \'${node.hint}\',');
if (node.textDirection != null)
buf.writeln(' textDirection: ${node.textDirection},');
if (node.hasChildren) {
buf.writeln(' children: <TestSemantics>[');
for (final SemanticsNode child in node.debugListChildrenInOrder(childOrder)) {
......
// 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
// ┌───┐ ┌─────────┐ ┌───┐
// │ E │ │ │>│ H
// └───┘ │ G │ └───┘
// V │ │ V
// │ E │>│ │>│ G
// └───┘ │ F │ └───┘
// ┌───|─────────|───┘
// ┌───┐ │ │ ┌───┐
// │ F │>│ │ │ I │
// │ H │─|─────────|>│ I │
// └───┘ └─────────┘ └───┘
// ┌─────────────────┘
// V
......@@ -171,11 +171,11 @@ void main() {
// └─────────────────┐
// V
// ┌───┐ ┌─────────┐ ┌───┐
// │ E │<│ │ │ H
// └───┘ │ G │ └───┘
// V │ │ V
// │ E │<│ │<│ G
// └───┘ │ F │ └───┘
// └──|─────────|────┐
// ┌───┐ │ │ ┌───┐
// │ F │ │ │<│ I │
// │ H │<|─────────|─│ I │
// └───┘ └─────────┘ └───┘
// └─────────────────┐
// V
......@@ -189,9 +189,9 @@ void main() {
'C': const Offset(40.0, 0.0) & tenByTen,
'D': const Offset(60.0, 0.0) & tenByTen,
'E': const Offset(0.0, 20.0) & tenByTen,
'F': const Offset(0.0, 40.0) & tenByTen,
'G': const Offset(20.0, 20.0) & (tenByTen * 2.0),
'H': const Offset(60.0, 20.0) & tenByTen,
'F': const Offset(20.0, 20.0) & (tenByTen * 2.0),
'G': const Offset(60.0, 20.0) & tenByTen,
'H': const Offset(0.0, 40.0) & tenByTen,
'I': const Offset(60.0, 40.0) & tenByTen,
'J': const Offset(0.0, 60.0) & tenByTen,
'K': const Offset(20.0, 60.0) & tenByTen,
......@@ -208,7 +208,7 @@ void main() {
await tester.test(
textDirection: TextDirection.rtl,
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.scrollDown,
],
flags: <SemanticsFlag>[SemanticsFlag.hasImplicitScrolling],
children: <TestSemantics>[
TestSemantics(
id: 3,
......@@ -521,6 +522,7 @@ void _tests() {
SemanticsAction.scrollUp,
SemanticsAction.scrollDown,
],
flags: <SemanticsFlag>[SemanticsFlag.hasImplicitScrolling],
children: <TestSemantics>[
TestSemantics(
flags: <SemanticsFlag>[SemanticsFlag.isHidden],
......@@ -630,6 +632,7 @@ void _tests() {
SemanticsAction.scrollUp,
SemanticsAction.scrollDown,
],
flags: <SemanticsFlag>[SemanticsFlag.hasImplicitScrolling],
children: <TestSemantics>[
TestSemantics(
flags: <SemanticsFlag>[SemanticsFlag.isHidden],
......@@ -994,6 +997,7 @@ void _tests() {
SemanticsAction.scrollUp,
SemanticsAction.scrollDown,
],
flags: <SemanticsFlag>[SemanticsFlag.hasImplicitScrolling],
children: <TestSemantics>[
TestSemantics(
flags: <SemanticsFlag>[SemanticsFlag.isHidden],
......
......@@ -218,7 +218,7 @@ void main() {
],
),
TestSemantics(
label: ' regrettable event',
label: ' this is a regrettable event',
textDirection: TextDirection.ltr,
),
],
......@@ -414,7 +414,7 @@ void main() {
TestSemantics(
label: 'INTERRUPTION',
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(
label: 'sky',
......
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