Commit bf1d8221 authored by Greg Spencer's avatar Greg Spencer Committed by Flutter GitHub Bot

Add TargetPlatform.macOS tests to cupertino, foundation, rendering, and...

Add TargetPlatform.macOS tests to cupertino, foundation, rendering, and services libraries. (#45644)
parent 59004bea
...@@ -153,7 +153,6 @@ void main() { ...@@ -153,7 +153,6 @@ void main() {
testWidgets( testWidgets(
'scrolling calls onSelectedItemChanged and triggers haptic feedback', 'scrolling calls onSelectedItemChanged and triggers haptic feedback',
(WidgetTester tester) async { (WidgetTester tester) async {
debugDefaultTargetPlatformOverride = TargetPlatform.iOS;
final List<int> selectedItems = <int>[]; final List<int> selectedItems = <int>[];
final List<MethodCall> systemCalls = <MethodCall>[]; final List<MethodCall> systemCalls = <MethodCall>[];
...@@ -200,15 +199,11 @@ void main() { ...@@ -200,15 +199,11 @@ void main() {
arguments: 'HapticFeedbackType.selectionClick', arguments: 'HapticFeedbackType.selectionClick',
), ),
); );
}, variant: TargetPlatformVariant.only(TargetPlatform.iOS));
debugDefaultTargetPlatformOverride = null;
},
);
testWidgets( testWidgets(
'do not trigger haptic effects on non-iOS devices', 'do not trigger haptic effects on non-iOS devices',
(WidgetTester tester) async { (WidgetTester tester) async {
debugDefaultTargetPlatformOverride = TargetPlatform.android;
final List<int> selectedItems = <int>[]; final List<int> selectedItems = <int>[];
final List<MethodCall> systemCalls = <MethodCall>[]; final List<MethodCall> systemCalls = <MethodCall>[];
...@@ -238,13 +233,9 @@ void main() { ...@@ -238,13 +233,9 @@ void main() {
await tester.drag(find.text('0'), const Offset(0.0, -100.0)); await tester.drag(find.text('0'), const Offset(0.0, -100.0));
expect(selectedItems, <int>[1]); expect(selectedItems, <int>[1]);
expect(systemCalls, isEmpty); expect(systemCalls, isEmpty);
}, variant: TargetPlatformVariant(TargetPlatform.values.where((TargetPlatform platform) => platform != TargetPlatform.iOS).toSet()));
debugDefaultTargetPlatformOverride = null;
},
);
testWidgets('a drag in between items settles back', (WidgetTester tester) async { testWidgets('a drag in between items settles back', (WidgetTester tester) async {
debugDefaultTargetPlatformOverride = TargetPlatform.iOS;
final FixedExtentScrollController controller = final FixedExtentScrollController controller =
FixedExtentScrollController(initialItem: 10); FixedExtentScrollController(initialItem: 10);
final List<int> selectedItems = <int>[]; final List<int> selectedItems = <int>[];
...@@ -297,11 +288,9 @@ void main() { ...@@ -297,11 +288,9 @@ void main() {
moreOrLessEquals(350.0, epsilon: 0.5), moreOrLessEquals(350.0, epsilon: 0.5),
); );
expect(selectedItems, <int>[9]); expect(selectedItems, <int>[9]);
debugDefaultTargetPlatformOverride = null; }, variant: const TargetPlatformVariant(<TargetPlatform>{ TargetPlatform.iOS, TargetPlatform.macOS }));
});
testWidgets('a big fling that overscrolls springs back', (WidgetTester tester) async { testWidgets('a big fling that overscrolls springs back', (WidgetTester tester) async {
debugDefaultTargetPlatformOverride = TargetPlatform.iOS;
final FixedExtentScrollController controller = final FixedExtentScrollController controller =
FixedExtentScrollController(initialItem: 10); FixedExtentScrollController(initialItem: 10);
final List<int> selectedItems = <int>[]; final List<int> selectedItems = <int>[];
...@@ -357,8 +346,6 @@ void main() { ...@@ -357,8 +346,6 @@ void main() {
// Falling back to 0 shouldn't produce more callbacks. // Falling back to 0 shouldn't produce more callbacks.
<int>[8, 6, 4, 2, 0], <int>[8, 6, 4, 2, 0],
); );
}, variant: const TargetPlatformVariant(<TargetPlatform>{ TargetPlatform.iOS, TargetPlatform.macOS }));
debugDefaultTargetPlatformOverride = null;
});
}); });
} }
...@@ -43,7 +43,6 @@ void main() { ...@@ -43,7 +43,6 @@ void main() {
}); });
testWidgets('Switch emits light haptic vibration on tap', (WidgetTester tester) async { testWidgets('Switch emits light haptic vibration on tap', (WidgetTester tester) async {
debugDefaultTargetPlatformOverride = TargetPlatform.iOS;
final Key switchKey = UniqueKey(); final Key switchKey = UniqueKey();
bool value = false; bool value = false;
...@@ -80,11 +79,9 @@ void main() { ...@@ -80,11 +79,9 @@ void main() {
expect(log, hasLength(1)); expect(log, hasLength(1));
expect(log.single, isMethodCall('HapticFeedback.vibrate', arguments: 'HapticFeedbackType.lightImpact')); expect(log.single, isMethodCall('HapticFeedback.vibrate', arguments: 'HapticFeedbackType.lightImpact'));
debugDefaultTargetPlatformOverride = null; }, variant: TargetPlatformVariant.only(TargetPlatform.iOS));
});
testWidgets('Using other widgets that rebuild the switch will not cause vibrations', (WidgetTester tester) async { testWidgets('Using other widgets that rebuild the switch will not cause vibrations', (WidgetTester tester) async {
debugDefaultTargetPlatformOverride = TargetPlatform.iOS;
final Key switchKey = UniqueKey(); final Key switchKey = UniqueKey();
final Key switchKey2 = UniqueKey(); final Key switchKey2 = UniqueKey();
bool value = false; bool value = false;
...@@ -152,11 +149,9 @@ void main() { ...@@ -152,11 +149,9 @@ void main() {
expect(log, hasLength(4)); expect(log, hasLength(4));
expect(log[3], isMethodCall('HapticFeedback.vibrate', arguments: 'HapticFeedbackType.lightImpact')); expect(log[3], isMethodCall('HapticFeedback.vibrate', arguments: 'HapticFeedbackType.lightImpact'));
debugDefaultTargetPlatformOverride = null; }, variant: TargetPlatformVariant.only(TargetPlatform.iOS));
});
testWidgets('Haptic vibration triggers on drag', (WidgetTester tester) async { testWidgets('Haptic vibration triggers on drag', (WidgetTester tester) async {
debugDefaultTargetPlatformOverride = TargetPlatform.iOS;
bool value = false; bool value = false;
final List<MethodCall> log = <MethodCall>[]; final List<MethodCall> log = <MethodCall>[];
...@@ -191,11 +186,9 @@ void main() { ...@@ -191,11 +186,9 @@ void main() {
expect(log, hasLength(1)); expect(log, hasLength(1));
expect(log[0], isMethodCall('HapticFeedback.vibrate', arguments: 'HapticFeedbackType.lightImpact')); expect(log[0], isMethodCall('HapticFeedback.vibrate', arguments: 'HapticFeedbackType.lightImpact'));
debugDefaultTargetPlatformOverride = null; }, variant: TargetPlatformVariant.only(TargetPlatform.iOS));
});
testWidgets('No haptic vibration triggers from a programmatic value change', (WidgetTester tester) async { testWidgets('No haptic vibration triggers from a programmatic value change', (WidgetTester tester) async {
debugDefaultTargetPlatformOverride = TargetPlatform.iOS;
final Key switchKey = UniqueKey(); final Key switchKey = UniqueKey();
bool value = false; bool value = false;
...@@ -244,8 +237,7 @@ void main() { ...@@ -244,8 +237,7 @@ void main() {
await tester.pump(); await tester.pump();
expect(log, hasLength(0)); expect(log, hasLength(0));
debugDefaultTargetPlatformOverride = null; }, variant: TargetPlatformVariant.only(TargetPlatform.iOS));
});
testWidgets('Switch can drag (LTR)', (WidgetTester tester) async { testWidgets('Switch can drag (LTR)', (WidgetTester tester) async {
bool value = false; bool value = false;
......
...@@ -425,9 +425,7 @@ void main() { ...@@ -425,9 +425,7 @@ void main() {
expect(editableText.cursorOffset, const Offset(-2.0 / 3.0, 0)); expect(editableText.cursorOffset, const Offset(-2.0 / 3.0, 0));
}); });
testWidgets('Cursor animates on iOS', (WidgetTester tester) async { testWidgets('Cursor animates', (WidgetTester tester) async {
debugDefaultTargetPlatformOverride = TargetPlatform.iOS;
await tester.pumpWidget( await tester.pumpWidget(
const CupertinoApp( const CupertinoApp(
home: CupertinoTextField(), home: CupertinoTextField(),
...@@ -459,13 +457,9 @@ void main() { ...@@ -459,13 +457,9 @@ void main() {
await tester.pump(const Duration(milliseconds: 50)); await tester.pump(const Duration(milliseconds: 50));
expect(renderEditable.cursorColor.alpha, 0); expect(renderEditable.cursorColor.alpha, 0);
}, variant: const TargetPlatformVariant(<TargetPlatform>{ TargetPlatform.iOS, TargetPlatform.macOS }));
debugDefaultTargetPlatformOverride = null; testWidgets('Cursor radius is 2.0', (WidgetTester tester) async {
});
testWidgets('Cursor radius is 2.0 on iOS', (WidgetTester tester) async {
debugDefaultTargetPlatformOverride = TargetPlatform.iOS;
await tester.pumpWidget( await tester.pumpWidget(
const CupertinoApp( const CupertinoApp(
home: CupertinoTextField(), home: CupertinoTextField(),
...@@ -476,9 +470,7 @@ void main() { ...@@ -476,9 +470,7 @@ void main() {
final RenderEditable renderEditable = editableTextState.renderEditable; final RenderEditable renderEditable = editableTextState.renderEditable;
expect(renderEditable.cursorRadius, const Radius.circular(2.0)); expect(renderEditable.cursorRadius, const Radius.circular(2.0));
}, variant: const TargetPlatformVariant(<TargetPlatform>{ TargetPlatform.iOS, TargetPlatform.macOS }));
debugDefaultTargetPlatformOverride = null;
});
testWidgets('Cupertino cursor android golden', (WidgetTester tester) async { testWidgets('Cupertino cursor android golden', (WidgetTester tester) async {
final Widget widget = CupertinoApp( final Widget widget = CupertinoApp(
...@@ -507,9 +499,7 @@ void main() { ...@@ -507,9 +499,7 @@ void main() {
); );
}); });
testWidgets('Cupertino cursor iOS golden', (WidgetTester tester) async { testWidgets('Cupertino cursor golden', (WidgetTester tester) async {
debugDefaultTargetPlatformOverride = TargetPlatform.iOS;
final Widget widget = CupertinoApp( final Widget widget = CupertinoApp(
home: Center( home: Center(
child: RepaintBoundary( child: RepaintBoundary(
...@@ -530,12 +520,13 @@ void main() { ...@@ -530,12 +520,13 @@ void main() {
await tester.tapAt(textOffsetToPosition(tester, testValue.length)); await tester.tapAt(textOffsetToPosition(tester, testValue.length));
await tester.pumpAndSettle(); await tester.pumpAndSettle();
debugDefaultTargetPlatformOverride = null;
await expectLater( await expectLater(
find.byKey(const ValueKey<int>(1)), find.byKey(const ValueKey<int>(1)),
matchesGoldenFile('text_field_cursor_test.cupertino.1.png'), matchesGoldenFile(
'text_field_cursor_test.cupertino_${describeEnum(debugDefaultTargetPlatformOverride).toLowerCase()}.1.png',
),
); );
}); }, variant: const TargetPlatformVariant(<TargetPlatform>{ TargetPlatform.iOS, TargetPlatform.macOS }));
testWidgets( testWidgets(
'can control text content via controller', 'can control text content via controller',
...@@ -2946,8 +2937,7 @@ void main() { ...@@ -2946,8 +2937,7 @@ void main() {
expect(editableText.cursorColor.value, 0x87654321); expect(editableText.cursorColor.value, 0x87654321);
}); });
testWidgets('iOS shows selection handles', (WidgetTester tester) async { testWidgets('shows selection handles', (WidgetTester tester) async {
debugDefaultTargetPlatformOverride = TargetPlatform.iOS;
const String testText = 'lorem ipsum'; const String testText = 'lorem ipsum';
final TextEditingController controller = TextEditingController(text: testText); final TextEditingController controller = TextEditingController(text: testText);
...@@ -2977,9 +2967,7 @@ void main() { ...@@ -2977,9 +2967,7 @@ void main() {
expect(left.opacity.value, equals(1.0)); expect(left.opacity.value, equals(1.0));
expect(right.opacity.value, equals(1.0)); expect(right.opacity.value, equals(1.0));
}, variant: const TargetPlatformVariant(<TargetPlatform>{ TargetPlatform.iOS, TargetPlatform.macOS }));
debugDefaultTargetPlatformOverride = null;
});
testWidgets('when CupertinoTextField would be blocked by keyboard, it is shown with enough space for the selection handle', (WidgetTester tester) async { testWidgets('when CupertinoTextField would be blocked by keyboard, it is shown with enough space for the selection handle', (WidgetTester tester) async {
final ScrollController scrollController = ScrollController(); final ScrollController scrollController = ScrollController();
......
...@@ -489,43 +489,51 @@ void main() { ...@@ -489,43 +489,51 @@ void main() {
extensionChangedEvent = extensionChangedEvents.last; extensionChangedEvent = extensionChangedEvents.last;
expect(extensionChangedEvent['extension'], 'ext.flutter.platformOverride'); expect(extensionChangedEvent['extension'], 'ext.flutter.platformOverride');
expect(extensionChangedEvent['value'], 'iOS'); expect(extensionChangedEvent['value'], 'iOS');
result = await hasReassemble(binding.testExtension('platformOverride', <String, String>{'value': 'macOS'}));
expect(result, <String, String>{'value': 'macOS'});
expect(binding.reassembled, 2);
expect(defaultTargetPlatform, TargetPlatform.macOS);
expect(extensionChangedEvents.length, 2);
extensionChangedEvent = extensionChangedEvents.last;
expect(extensionChangedEvent['extension'], 'ext.flutter.platformOverride');
expect(extensionChangedEvent['value'], 'macOS');
result = await hasReassemble(binding.testExtension('platformOverride', <String, String>{'value': 'android'})); result = await hasReassemble(binding.testExtension('platformOverride', <String, String>{'value': 'android'}));
expect(result, <String, String>{'value': 'android'}); expect(result, <String, String>{'value': 'android'});
expect(binding.reassembled, 2); expect(binding.reassembled, 3);
expect(defaultTargetPlatform, TargetPlatform.android); expect(defaultTargetPlatform, TargetPlatform.android);
expect(extensionChangedEvents.length, 2); expect(extensionChangedEvents.length, 3);
extensionChangedEvent = extensionChangedEvents.last; extensionChangedEvent = extensionChangedEvents.last;
expect(extensionChangedEvent['extension'], 'ext.flutter.platformOverride'); expect(extensionChangedEvent['extension'], 'ext.flutter.platformOverride');
expect(extensionChangedEvent['value'], 'android'); expect(extensionChangedEvent['value'], 'android');
result = await hasReassemble(binding.testExtension('platformOverride', <String, String>{'value': 'fuchsia'})); result = await hasReassemble(binding.testExtension('platformOverride', <String, String>{'value': 'fuchsia'}));
expect(result, <String, String>{'value': 'fuchsia'}); expect(result, <String, String>{'value': 'fuchsia'});
expect(binding.reassembled, 3); expect(binding.reassembled, 4);
expect(defaultTargetPlatform, TargetPlatform.fuchsia); expect(defaultTargetPlatform, TargetPlatform.fuchsia);
expect(extensionChangedEvents.length, 3); expect(extensionChangedEvents.length, 4);
extensionChangedEvent = extensionChangedEvents.last; extensionChangedEvent = extensionChangedEvents.last;
expect(extensionChangedEvent['extension'], 'ext.flutter.platformOverride'); expect(extensionChangedEvent['extension'], 'ext.flutter.platformOverride');
expect(extensionChangedEvent['value'], 'fuchsia'); expect(extensionChangedEvent['value'], 'fuchsia');
result = await hasReassemble(binding.testExtension('platformOverride', <String, String>{'value': 'default'})); result = await hasReassemble(binding.testExtension('platformOverride', <String, String>{'value': 'default'}));
expect(result, <String, String>{'value': 'android'}); expect(result, <String, String>{'value': 'android'});
expect(binding.reassembled, 4); expect(binding.reassembled, 5);
expect(defaultTargetPlatform, TargetPlatform.android); expect(defaultTargetPlatform, TargetPlatform.android);
expect(extensionChangedEvents.length, 4); expect(extensionChangedEvents.length, 5);
extensionChangedEvent = extensionChangedEvents.last; extensionChangedEvent = extensionChangedEvents.last;
expect(extensionChangedEvent['extension'], 'ext.flutter.platformOverride'); expect(extensionChangedEvent['extension'], 'ext.flutter.platformOverride');
expect(extensionChangedEvent['value'], 'android'); expect(extensionChangedEvent['value'], 'android');
result = await hasReassemble(binding.testExtension('platformOverride', <String, String>{'value': 'iOS'})); result = await hasReassemble(binding.testExtension('platformOverride', <String, String>{'value': 'iOS'}));
expect(result, <String, String>{'value': 'iOS'}); expect(result, <String, String>{'value': 'iOS'});
expect(binding.reassembled, 5); expect(binding.reassembled, 6);
expect(defaultTargetPlatform, TargetPlatform.iOS); expect(defaultTargetPlatform, TargetPlatform.iOS);
expect(extensionChangedEvents.length, 5); expect(extensionChangedEvents.length, 6);
extensionChangedEvent = extensionChangedEvents.last; extensionChangedEvent = extensionChangedEvents.last;
expect(extensionChangedEvent['extension'], 'ext.flutter.platformOverride'); expect(extensionChangedEvent['extension'], 'ext.flutter.platformOverride');
expect(extensionChangedEvent['value'], 'iOS'); expect(extensionChangedEvent['value'], 'iOS');
result = await hasReassemble(binding.testExtension('platformOverride', <String, String>{'value': 'bogus'})); result = await hasReassemble(binding.testExtension('platformOverride', <String, String>{'value': 'bogus'}));
expect(result, <String, String>{'value': 'android'}); expect(result, <String, String>{'value': 'android'});
expect(binding.reassembled, 6); expect(binding.reassembled, 7);
expect(defaultTargetPlatform, TargetPlatform.android); expect(defaultTargetPlatform, TargetPlatform.android);
expect(extensionChangedEvents.length, 6); expect(extensionChangedEvents.length, 7);
extensionChangedEvent = extensionChangedEvents.last; extensionChangedEvent = extensionChangedEvents.last;
expect(extensionChangedEvent['extension'], 'ext.flutter.platformOverride'); expect(extensionChangedEvent['extension'], 'ext.flutter.platformOverride');
expect(extensionChangedEvent['value'], 'android'); expect(extensionChangedEvent['value'], 'android');
......
...@@ -81,7 +81,11 @@ void main() { ...@@ -81,7 +81,11 @@ void main() {
}); });
test('RenderPhysicalModel compositing on non-Fuchsia', () { test('RenderPhysicalModel compositing on non-Fuchsia', () {
debugDefaultTargetPlatformOverride = TargetPlatform.iOS; for (final TargetPlatform platform in TargetPlatform.values) {
if (platform == TargetPlatform.fuchsia) {
continue;
}
debugDefaultTargetPlatformOverride = platform;
final RenderPhysicalModel root = RenderPhysicalModel(color: const Color(0xffff00ff)); final RenderPhysicalModel root = RenderPhysicalModel(color: const Color(0xffff00ff));
layout(root, phase: EnginePhase.composite); layout(root, phase: EnginePhase.composite);
...@@ -95,7 +99,7 @@ void main() { ...@@ -95,7 +99,7 @@ void main() {
root.elevation = 0.0; root.elevation = 0.0;
pumpFrame(phase: EnginePhase.composite); pumpFrame(phase: EnginePhase.composite);
expect(root.needsCompositing, isTrue); expect(root.needsCompositing, isTrue);
}
debugDefaultTargetPlatformOverride = null; debugDefaultTargetPlatformOverride = null;
}); });
...@@ -121,11 +125,13 @@ void main() { ...@@ -121,11 +125,13 @@ void main() {
}); });
group('RenderPhysicalShape', () { group('RenderPhysicalShape', () {
setUp(() {
debugDefaultTargetPlatformOverride = TargetPlatform.iOS;
});
test('shape change triggers repaint', () { test('shape change triggers repaint', () {
for (final TargetPlatform platform in TargetPlatform.values) {
if (platform == TargetPlatform.fuchsia) {
continue;
}
debugDefaultTargetPlatformOverride = platform;
final RenderPhysicalShape root = RenderPhysicalShape( final RenderPhysicalShape root = RenderPhysicalShape(
color: const Color(0xffff00ff), color: const Color(0xffff00ff),
clipper: const ShapeBorderClipper(shape: CircleBorder()), clipper: const ShapeBorderClipper(shape: CircleBorder()),
...@@ -140,9 +146,16 @@ void main() { ...@@ -140,9 +146,16 @@ void main() {
// Different shape triggers repaint. // Different shape triggers repaint.
root.clipper = const ShapeBorderClipper(shape: StadiumBorder()); root.clipper = const ShapeBorderClipper(shape: StadiumBorder());
expect(root.debugNeedsPaint, isTrue); expect(root.debugNeedsPaint, isTrue);
}
debugDefaultTargetPlatformOverride = null;
}); });
test('compositing on non-Fuchsia', () { test('compositing on non-Fuchsia', () {
for (final TargetPlatform platform in TargetPlatform.values) {
if (platform == TargetPlatform.fuchsia) {
continue;
}
debugDefaultTargetPlatformOverride = platform;
final RenderPhysicalShape root = RenderPhysicalShape( final RenderPhysicalShape root = RenderPhysicalShape(
color: const Color(0xffff00ff), color: const Color(0xffff00ff),
clipper: const ShapeBorderClipper(shape: CircleBorder()), clipper: const ShapeBorderClipper(shape: CircleBorder()),
...@@ -158,7 +171,7 @@ void main() { ...@@ -158,7 +171,7 @@ void main() {
root.elevation = 0.0; root.elevation = 0.0;
pumpFrame(phase: EnginePhase.composite); pumpFrame(phase: EnginePhase.composite);
expect(root.needsCompositing, isTrue); expect(root.needsCompositing, isTrue);
}
debugDefaultTargetPlatformOverride = null; debugDefaultTargetPlatformOverride = null;
}); });
}); });
......
...@@ -1145,10 +1145,8 @@ void main() { ...@@ -1145,10 +1145,8 @@ void main() {
); );
}); });
testWidgets('Handles infinite constraints when TargetPlatform is iOS', (WidgetTester tester) async { testWidgets('Handles infinite constraints when TargetPlatform is iOS or macOS', (WidgetTester tester) async {
// regression test for https://github.com/flutter/flutter/issues/45866 // regression test for https://github.com/flutter/flutter/issues/45866
final TargetPlatform oldTargetPlatform = debugDefaultTargetPlatformOverride;
debugDefaultTargetPlatformOverride = TargetPlatform.iOS;
await tester.pumpWidget( await tester.pumpWidget(
Directionality( Directionality(
textDirection: TextDirection.ltr, textDirection: TextDirection.ltr,
...@@ -1177,6 +1175,5 @@ void main() { ...@@ -1177,6 +1175,5 @@ void main() {
expect(find.text('b'), findsOneWidget); expect(find.text('b'), findsOneWidget);
await tester.drag(find.text('b'), const Offset(0, 200)); await tester.drag(find.text('b'), const Offset(0, 200));
await tester.pumpAndSettle(); await tester.pumpAndSettle();
debugDefaultTargetPlatformOverride = oldTargetPlatform; }, variant: const TargetPlatformVariant(<TargetPlatform>{ TargetPlatform.iOS, TargetPlatform.macOS }));
});
} }
...@@ -744,7 +744,6 @@ void main() { ...@@ -744,7 +744,6 @@ void main() {
} }
}, variant: TargetPlatformVariant.all()); }, variant: TargetPlatformVariant.all());
}); });
} }
class FakeMatcher extends AsyncMatcher { class FakeMatcher extends AsyncMatcher {
......
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