Ian Hickson | 449f4a6 | 2019-11-27 15:04:02 -0800 | [diff] [blame] | 1 | // Copyright 2014 The Flutter Authors. All rights reserved. |
matthew-carroll | 2a65505 | 2018-07-02 06:58:35 +0000 | [diff] [blame] | 2 | // Use of this source code is governed by a BSD-style license that can be |
| 3 | // found in the LICENSE file. |
| 4 | |
| 5 | import 'package:flutter/material.dart'; |
| 6 | import 'package:flutter/services.dart'; |
| 7 | import 'package:flutter_test/flutter_test.dart'; |
| 8 | |
| 9 | void main() { |
Alexandre Ardhuin | 440ce8f | 2019-03-07 21:09:28 +0100 | [diff] [blame] | 10 | testWidgets('receiveAction() forwards exception when exception occurs during action processing', (WidgetTester tester) async { |
matthew-carroll | 2a65505 | 2018-07-02 06:58:35 +0000 | [diff] [blame] | 11 | // Setup a widget that can receive focus so that we can open the keyboard. |
Dan Field | ea5435c | 2018-09-25 13:57:12 -0400 | [diff] [blame] | 12 | const Widget widget = MaterialApp( |
| 13 | home: Material( |
Alexandre Ardhuin | eda03e2 | 2018-08-02 12:02:32 +0200 | [diff] [blame] | 14 | child: TextField(), |
matthew-carroll | 2a65505 | 2018-07-02 06:58:35 +0000 | [diff] [blame] | 15 | ), |
| 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 Ardhuin | d927c93 | 2018-09-12 08:29:29 +0200 | [diff] [blame] | 25 | throw FlutterError('A fake error occurred during action processing.'); |
matthew-carroll | 2a65505 | 2018-07-02 06:58:35 +0000 | [diff] [blame] | 26 | }); |
| 27 | |
| 28 | try { |
| 29 | await tester.testTextInput.receiveAction(TextInputAction.done); |
| 30 | fail('Expected a PlatformException, but it was not thrown.'); |
| 31 | } catch (e) { |
Dan Field | 8b29933 | 2020-01-27 14:36:02 -0800 | [diff] [blame] | 32 | expect(e, isA<PlatformException>()); |
matthew-carroll | 2a65505 | 2018-07-02 06:58:35 +0000 | [diff] [blame] | 33 | } |
| 34 | }); |
Todd Volkert | 00aac68 | 2018-07-27 08:44:39 -0700 | [diff] [blame] | 35 | } |