This repository was archived by the owner on Feb 25, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 6k
[web] Fix multi-reply on message channel. Add test #17591
Merged
Merged
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
c7cac19
Fix multi-reply on message channel. Add test
ferhatb 3268207
fix formatting in cirrus.yml
ferhatb edf2bf8
Add comment on HomePageState text field
ferhatb 8822398
Fix test title
ferhatb 31e4a90
Add check for viewInstanceCount
ferhatb 5ed9251
skip no-headless test
ferhatb 8b0a070
testCI fail
ferhatb 37b5396
Merge remote-tracking branch 'upstream/master' into platform_msg
ferhatb File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
64 changes: 64 additions & 0 deletions
64
e2etests/web/regular_integration_tests/lib/platform_messages_main.dart
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,64 @@ | ||
| // Copyright 2013 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/material.dart'; | ||
| import 'package:flutter/services.dart'; | ||
|
|
||
| void main() => runApp(MyApp()); | ||
|
|
||
| Future<ClipboardData> dataFuture; | ||
|
|
||
| class MyApp extends StatelessWidget { | ||
| @override | ||
| Widget build(BuildContext context) { | ||
| return MaterialApp( | ||
| key: const Key('mainapp'), | ||
| title: 'Integration Test App For Platform Messages', | ||
| home: MyHomePage(title: 'Integration Test App For Platform Messages'), | ||
| ); | ||
| } | ||
| } | ||
|
|
||
| class MyHomePage extends StatefulWidget { | ||
| MyHomePage({Key key, this.title}) : super(key: key); | ||
|
|
||
| final String title; | ||
|
|
||
| @override | ||
| _MyHomePageState createState() => _MyHomePageState(); | ||
| } | ||
|
|
||
| class _MyHomePageState extends State<MyHomePage> { | ||
| final TextEditingController _controller = | ||
| TextEditingController(text: 'Text1'); | ||
|
|
||
| @override | ||
| Widget build(BuildContext context) { | ||
| return Scaffold( | ||
| appBar: AppBar( | ||
| title: Text(widget.title), | ||
| ), | ||
| body: Center( | ||
| child: Column( | ||
| mainAxisAlignment: MainAxisAlignment.center, | ||
| children: <Widget>[ | ||
| const Text('Hello World', | ||
| ), | ||
| // Create a text form field since we can't test clipboard unless | ||
| // html document has focus. | ||
| TextFormField( | ||
| key: const Key('input'), | ||
| enabled: true, | ||
| controller: _controller, | ||
| //initialValue: 'Text1', | ||
| decoration: const InputDecoration( | ||
| labelText: 'Text Input Field:', | ||
| ), | ||
| ), | ||
| ], | ||
| ), | ||
| ), | ||
| ); | ||
| } | ||
| } | ||
59 changes: 59 additions & 0 deletions
59
e2etests/web/regular_integration_tests/test_driver/platform_messages_e2e.dart
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,59 @@ | ||
| // Copyright 2013 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 'dart:html' as html; | ||
| // ignore: undefined_shown_name | ||
| import 'dart:ui' as ui show platformViewRegistry; | ||
| import 'package:flutter/material.dart'; | ||
| import 'package:flutter/services.dart'; | ||
| import 'package:flutter_test/flutter_test.dart'; | ||
| import 'package:regular_integration_tests/platform_messages_main.dart' as app; | ||
|
|
||
| import 'package:e2e/e2e.dart'; | ||
|
|
||
| void main() async { | ||
| E2EWidgetsFlutterBinding.ensureInitialized() as E2EWidgetsFlutterBinding; | ||
|
|
||
| testWidgets('platform message for Clipboard.setData reply with future', | ||
| (WidgetTester tester) async { | ||
| app.main(); | ||
| await tester.pumpAndSettle(); | ||
|
|
||
| // TODO(nurhan): https://github.com/flutter/flutter/issues/51885 | ||
| SystemChannels.textInput.setMockMethodCallHandler(null); | ||
| // Focus on a TextFormField. | ||
| final Finder finder = find.byKey(const Key('input')); | ||
| expect(finder, findsOneWidget); | ||
| await tester.tap(find.byKey(const Key('input'))); | ||
| // Focus in input, otherwise clipboard will fail with | ||
| // 'document is not focused' platform exception. | ||
| html.document.querySelector('input').focus(); | ||
| await Clipboard.setData(const ClipboardData(text: 'sample text')); | ||
| }, skip: true); // https://github.com/flutter/flutter/issues/54296 | ||
|
|
||
| testWidgets('Should create and dispose view embedder', | ||
| (WidgetTester tester) async { | ||
| int viewInstanceCount = 0; | ||
|
|
||
| final int currentViewId = platformViewsRegistry.getNextPlatformViewId(); | ||
| // ignore: undefined_prefixed_name | ||
| ui.platformViewRegistry.registerViewFactory('MyView', (int viewId) { | ||
| ++viewInstanceCount; | ||
ditman marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| return html.DivElement(); | ||
| }); | ||
|
|
||
| app.main(); | ||
| await tester.pumpAndSettle(); | ||
| final Map<String, dynamic> createArgs = <String, dynamic>{ | ||
| 'id': '567', | ||
| 'viewType': 'MyView', | ||
| }; | ||
| await SystemChannels.platform_views.invokeMethod<void>('create', createArgs); | ||
| final Map<String, dynamic> disposeArgs = <String, dynamic>{ | ||
| 'id': '567', | ||
| }; | ||
| await SystemChannels.platform_views.invokeMethod<void>('dispose', disposeArgs); | ||
| expect(viewInstanceCount, 1); | ||
| }); | ||
| } | ||
7 changes: 7 additions & 0 deletions
7
e2etests/web/regular_integration_tests/test_driver/platform_messages_e2e_test.dart
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,7 @@ | ||
| // Copyright 2013 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:e2e/e2e_driver.dart' as e2e; | ||
|
|
||
| Future<void> main() async => e2e.main(); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -18,6 +18,7 @@ class ClipboardMessageHandler { | |
| void setDataMethodCall( | ||
| MethodCall methodCall, ui.PlatformMessageResponseCallback callback) { | ||
| const MethodCodec codec = JSONMethodCodec(); | ||
| bool errorEnvelopeEncoded = false; | ||
| _copyToClipboardStrategy | ||
| .setData(methodCall.arguments['text']) | ||
| .then((bool success) { | ||
|
|
@@ -26,10 +27,15 @@ class ClipboardMessageHandler { | |
| } else { | ||
| callback(codec.encodeErrorEnvelope( | ||
| code: 'copy_fail', message: 'Clipboard.setData failed')); | ||
| errorEnvelopeEncoded = true; | ||
|
Comment on lines
28
to
+30
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There's no error thrown here. Why would the
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. When you do the error reply, the code that handles it could/did crash, then that is caught and instead of stack trace of error handling code that failed, you get the multi-reply failure. |
||
| } | ||
| }).catchError((dynamic _) { | ||
| callback(codec.encodeErrorEnvelope( | ||
| code: 'copy_fail', message: 'Clipboard.setData failed')); | ||
| // Don't encode a duplicate reply if we already failed and an error | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. thanks! |
||
| // was already encoded. | ||
| if (!errorEnvelopeEncoded) { | ||
| callback(codec.encodeErrorEnvelope( | ||
| code: 'copy_fail', message: 'Clipboard.setData failed')); | ||
| } | ||
| }); | ||
| } | ||
|
|
||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this is a leftover from my code. I also saw it yesterday. Can you remove this line :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Clarified why we need text field with comment.