blob: dfcc6024c2c1f1b8e22c78dfd088fe081a6ba39e [file] [log] [blame]
Ian Hickson449f4a62019-11-27 15:04:02 -08001// Copyright 2014 The Flutter Authors. All rights reserved.
matthew-carroll2a655052018-07-02 06:58:35 +00002// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
5import 'package:flutter/material.dart';
6import 'package:flutter/services.dart';
7import 'package:flutter_test/flutter_test.dart';
8
9void main() {
Alexandre Ardhuin440ce8f2019-03-07 21:09:28 +010010 testWidgets('receiveAction() forwards exception when exception occurs during action processing', (WidgetTester tester) async {
matthew-carroll2a655052018-07-02 06:58:35 +000011 // Setup a widget that can receive focus so that we can open the keyboard.
Dan Fieldea5435c2018-09-25 13:57:12 -040012 const Widget widget = MaterialApp(
13 home: Material(
Alexandre Ardhuineda03e22018-08-02 12:02:32 +020014 child: TextField(),
matthew-carroll2a655052018-07-02 06:58:35 +000015 ),
16 );
17 await tester.pumpWidget(widget);
18
19 // Keyboard must be shown for receiveAction() to function.
20 await tester.showKeyboard(find.byType(TextField));
21
22 // Register a handler for the text input channel that throws an error. This
23 // error should be reported within a PlatformException by TestTextInput.
24 SystemChannels.textInput.setMethodCallHandler((MethodCall call) {
Alexandre Ardhuind927c932018-09-12 08:29:29 +020025 throw FlutterError('A fake error occurred during action processing.');
matthew-carroll2a655052018-07-02 06:58:35 +000026 });
27
28 try {
29 await tester.testTextInput.receiveAction(TextInputAction.done);
30 fail('Expected a PlatformException, but it was not thrown.');
31 } catch (e) {
Dan Field8b299332020-01-27 14:36:02 -080032 expect(e, isA<PlatformException>());
matthew-carroll2a655052018-07-02 06:58:35 +000033 }
34 });
Todd Volkert00aac682018-07-27 08:44:39 -070035}