Skip to content
This repository was archived by the owner on Feb 25, 2025. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .cirrus.yml
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,7 @@ task:
- $FRAMEWORK_PATH/flutter/bin/flutter config --local-engine=host_debug_unopt --no-analytics --enable-web
- $FRAMEWORK_PATH/flutter/bin/flutter pub get --local-engine=host_debug_unopt
- $FRAMEWORK_PATH/flutter/bin/flutter drive -v --target=test_driver/text_editing_e2e.dart -d web-server --release --browser-name=chrome --local-engine=host_debug_unopt
- $FRAMEWORK_PATH/flutter/bin/flutter drive -v --target=test_driver/platform_messages_e2e.dart -d web-server --release --browser-name=chrome --local-engine=host_debug_unopt
- $FRAMEWORK_PATH/flutter/bin/flutter drive -v --target=test_driver/treeshaking_e2e.dart -d web-server --profile --browser-name=chrome --local-engine=host_debug_unopt
- $FRAMEWORK_PATH/flutter/bin/flutter drive -v --target=test_driver/image_loading_e2e.dart -d web-server --release --browser-name=chrome --local-engine=host_debug_unopt

Expand Down
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',
Copy link
Contributor

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 :)

Copy link
Contributor Author

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.

decoration: const InputDecoration(
labelText: 'Text Input Field:',
),
),
],
),
),
);
}
}
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;
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);
});
}
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();
10 changes: 8 additions & 2 deletions lib/web_ui/lib/src/engine/clipboard.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There's no error thrown here. Why would the catchError callback be invoked after this?

Copy link
Contributor Author

@ferhatb ferhatb Apr 8, 2020

Choose a reason for hiding this comment

The 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
Copy link
Contributor

Choose a reason for hiding this comment

The 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'));
}
});
}

Expand Down
2 changes: 0 additions & 2 deletions lib/web_ui/lib/src/engine/compositor/embedded_views.dart
Original file line number Diff line number Diff line change
Expand Up @@ -69,11 +69,9 @@ class HtmlViewEmbedder {
switch (decoded.method) {
case 'create':
_create(decoded, callback);
window._replyToPlatformMessage(callback, codec.encodeSuccessEnvelope(true));
return;
case 'dispose':
_dispose(decoded, callback);
window._replyToPlatformMessage(callback, codec.encodeSuccessEnvelope(true));
return;
}
callback(null);
Expand Down
2 changes: 0 additions & 2 deletions lib/web_ui/lib/src/engine/platform_views.dart
Original file line number Diff line number Diff line change
Expand Up @@ -50,11 +50,9 @@ void handlePlatformViewCall(
switch (decoded.method) {
case 'create':
_createPlatformView(decoded, callback);
window._replyToPlatformMessage(callback, codec.encodeSuccessEnvelope(true));
return;
case 'dispose':
_disposePlatformView(decoded, callback);
window._replyToPlatformMessage(callback, codec.encodeSuccessEnvelope(true));
return;
}
callback(null);
Expand Down