Unverified Commit 12016e41 authored by xubaolin's avatar xubaolin Committed by GitHub

Reland "Update PopupMenuButton to match Material Design spec" (#74620)

parent 76be5581
...@@ -409,8 +409,14 @@ void main() { ...@@ -409,8 +409,14 @@ void main() {
}); });
test('Popup Menu has correct Android semantics', () async { test('Popup Menu has correct Android semantics', () async {
final SerializableFinder button = find.descendant(
of: find.byValueKey(popupButtonKeyValue),
matching: find.byType('Semantics'),
firstMatchOnly: true,
);
expect( expect(
await getSemantics(find.byValueKey(popupButtonKeyValue)), await getSemantics(button),
hasAndroidSemantics( hasAndroidSemantics(
className: AndroidClassName.button, className: AndroidClassName.button,
isChecked: false, isChecked: false,
...@@ -432,20 +438,21 @@ void main() { ...@@ -432,20 +438,21 @@ void main() {
for (final String item in popupItems) { for (final String item in popupItems) {
expect( expect(
await getSemantics(find.byValueKey('$popupKeyValue.$item')), await getSemantics(find.byValueKey('$popupKeyValue.$item')),
hasAndroidSemantics( hasAndroidSemantics(
className: AndroidClassName.button, className: AndroidClassName.button,
isChecked: false, isChecked: false,
isCheckable: false, isCheckable: false,
isEnabled: true, isEnabled: true,
isFocusable: true, isFocusable: true,
actions: <AndroidSemanticsAction>[ actions: <AndroidSemanticsAction>[
if (item == popupItems.first) AndroidSemanticsAction.clearAccessibilityFocus, if (item == popupItems.first) AndroidSemanticsAction.clearAccessibilityFocus,
if (item != popupItems.first) AndroidSemanticsAction.accessibilityFocus, if (item != popupItems.first) AndroidSemanticsAction.accessibilityFocus,
AndroidSemanticsAction.click, AndroidSemanticsAction.click,
], ],
), ),
reason: "Popup $item doesn't have the right semantics"); reason: "Popup $item doesn't have the right semantics",
);
} }
await driver.tap(find.byValueKey('$popupKeyValue.${popupItems.first}')); await driver.tap(find.byValueKey('$popupKeyValue.${popupItems.first}'));
......
...@@ -38,6 +38,7 @@ void main() { ...@@ -38,6 +38,7 @@ void main() {
key: targetKey, key: targetKey,
builder: (BuildContext context) { builder: (BuildContext context) {
return PopupMenuButton<int>( return PopupMenuButton<int>(
placement: PopupMenuPlacement.belowButton,
onSelected: (int value) { onSelected: (int value) {
Navigator.pushNamed(context, '/next'); Navigator.pushNamed(context, '/next');
}, },
...@@ -78,20 +79,20 @@ void main() { ...@@ -78,20 +79,20 @@ void main() {
Offset bottomLeft = tester.getBottomLeft(find.text('hello, world')); Offset bottomLeft = tester.getBottomLeft(find.text('hello, world'));
Offset bottomRight = tester.getBottomRight(find.text('hello, world')); Offset bottomRight = tester.getBottomRight(find.text('hello, world'));
expect(topLeft, const Offset(392.0, 299.5)); expect(topLeft, const Offset(392.0, 347.5));
expect(topRight, const Offset(596.0, 299.5)); expect(topRight, const Offset(596.0, 347.5));
expect(bottomLeft, const Offset(392.0, 316.5)); expect(bottomLeft, const Offset(392.0, 364.5));
expect(bottomRight, const Offset(596.0, 316.5)); expect(bottomRight, const Offset(596.0, 364.5));
topLeft = tester.getTopLeft(find.text('你好,世界')); topLeft = tester.getTopLeft(find.text('你好,世界'));
topRight = tester.getTopRight(find.text('你好,世界')); topRight = tester.getTopRight(find.text('你好,世界'));
bottomLeft = tester.getBottomLeft(find.text('你好,世界')); bottomLeft = tester.getBottomLeft(find.text('你好,世界'));
bottomRight = tester.getBottomRight(find.text('你好,世界')); bottomRight = tester.getBottomRight(find.text('你好,世界'));
expect(topLeft, const Offset(392.0, 347.5)); expect(topLeft, const Offset(392.0, 395.5));
expect(topRight, const Offset(477.0, 347.5)); expect(topRight, const Offset(477.0, 395.5));
expect(bottomLeft, const Offset(392.0, 364.5)); expect(bottomLeft, const Offset(392.0, 412.5));
expect(bottomRight, const Offset(477.0, 364.5)); expect(bottomRight, const Offset(477.0, 412.5));
}); });
testWidgets('Text baseline with EN locale', (WidgetTester tester) async { testWidgets('Text baseline with EN locale', (WidgetTester tester) async {
...@@ -124,6 +125,7 @@ void main() { ...@@ -124,6 +125,7 @@ void main() {
key: targetKey, key: targetKey,
builder: (BuildContext context) { builder: (BuildContext context) {
return PopupMenuButton<int>( return PopupMenuButton<int>(
placement: PopupMenuPlacement.belowButton,
onSelected: (int value) { onSelected: (int value) {
Navigator.pushNamed(context, '/next'); Navigator.pushNamed(context, '/next');
}, },
...@@ -164,19 +166,19 @@ void main() { ...@@ -164,19 +166,19 @@ void main() {
Offset bottomLeft = tester.getBottomLeft(find.text('hello, world')); Offset bottomLeft = tester.getBottomLeft(find.text('hello, world'));
Offset bottomRight = tester.getBottomRight(find.text('hello, world')); Offset bottomRight = tester.getBottomRight(find.text('hello, world'));
expect(topLeft, const Offset(392.0, 300.0)); expect(topLeft, const Offset(392.0, 348.0));
expect(topRight, const Offset(584.0, 300.0)); expect(topRight, const Offset(584.0, 348.0));
expect(bottomLeft, const Offset(392.0, 316)); expect(bottomLeft, const Offset(392.0, 364));
expect(bottomRight, const Offset(584.0, 316)); expect(bottomRight, const Offset(584.0, 364));
topLeft = tester.getTopLeft(find.text('你好,世界')); topLeft = tester.getTopLeft(find.text('你好,世界'));
topRight = tester.getTopRight(find.text('你好,世界')); topRight = tester.getTopRight(find.text('你好,世界'));
bottomLeft = tester.getBottomLeft(find.text('你好,世界')); bottomLeft = tester.getBottomLeft(find.text('你好,世界'));
bottomRight = tester.getBottomRight(find.text('你好,世界')); bottomRight = tester.getBottomRight(find.text('你好,世界'));
expect(topLeft, const Offset(392.0, 348.0)); expect(topLeft, const Offset(392.0, 396.0));
expect(topRight, const Offset(472.0, 348.0)); expect(topRight, const Offset(472.0, 396.0));
expect(bottomLeft, const Offset(392.0, 364.0)); expect(bottomLeft, const Offset(392.0, 412.0));
expect(bottomRight, const Offset(472.0, 364.0)); expect(bottomRight, const Offset(472.0, 412.0));
}); });
} }
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