[go: nahoru, domu]

Skip to content

Commit

Permalink
Remove single window assumption from testing/dart (flutter#40160)
Browse files Browse the repository at this point in the history
  • Loading branch information
goderbauer committed Mar 9, 2023
1 parent 8a9bf0e commit 7893f10
Show file tree
Hide file tree
Showing 9 changed files with 16 additions and 19 deletions.
2 changes: 1 addition & 1 deletion testing/dart/assets_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ void main() {
/// Manually load font asset through dart.
final Uint8List encoded = utf8.encoder.convert(Uri(path: Uri.encodeFull('Roboto-Medium.ttf')).path);
final Completer<Uint8List> result = Completer<Uint8List>();
window.sendPlatformMessage('flutter/assets', encoded.buffer.asByteData(), (ByteData? data) {
PlatformDispatcher.instance.sendPlatformMessage('flutter/assets', encoded.buffer.asByteData(), (ByteData? data) {
result.complete(data!.buffer.asUint8List());
});

Expand Down
2 changes: 1 addition & 1 deletion testing/dart/color_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import 'dart:ui';
import 'package:litetest/litetest.dart';

class NotAColor extends Color {
const NotAColor(int value) : super(value);
const NotAColor(super.value);
}

void main() {
Expand Down
11 changes: 4 additions & 7 deletions testing/dart/observatory/skp_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ void main() {
);

final Completer<void> completer = Completer<void>();
window.onBeginFrame = (Duration timeStamp) {
PlatformDispatcher.instance.onBeginFrame = (Duration timeStamp) {
final PictureRecorder recorder = PictureRecorder();
final Canvas canvas = Canvas(recorder);
canvas.drawRect(const Rect.fromLTRB(10, 10, 20, 20), Paint());
Expand All @@ -35,14 +35,11 @@ void main() {
builder.addPicture(Offset.zero, picture);
final Scene scene = builder.build();

window.render(scene);
PlatformDispatcher.instance.implicitView!.render(scene);
scene.dispose();
// window. timeStamp) {
completer.complete();
// };
// window.scheduleFrame();
completer.complete();
};
window.scheduleFrame();
PlatformDispatcher.instance.scheduleFrame();
await completer.future;

final vms.Response response = await vmService.callServiceExtension('_flutter.screenshotSkp');
Expand Down
4 changes: 2 additions & 2 deletions testing/dart/observatory/tracing_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ void main() {
);

final Completer<void> completer = Completer<void>();
window.onBeginFrame = (Duration timeStamp) async {
PlatformDispatcher.instance.onBeginFrame = (Duration timeStamp) async {
final PictureRecorder recorder = PictureRecorder();
final Canvas canvas = Canvas(recorder);
canvas.drawColor(const Color(0xff0000ff), BlendMode.srcOut);
Expand All @@ -45,7 +45,7 @@ void main() {
scene.dispose();
completer.complete();
};
window.scheduleFrame();
PlatformDispatcher.instance.scheduleFrame();
await completer.future;

final vms.Timeline timeline = await vmService.getVMTimeline();
Expand Down
2 changes: 1 addition & 1 deletion testing/dart/observatory/vmservice_methods_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ void main() {
}

final Completer<PlatformResponse> completer = Completer<PlatformResponse>();
ui.window.onPlatformMessage = (String name, ByteData? data, ui.PlatformMessageResponseCallback? callback) {
ui.PlatformDispatcher.instance.onPlatformMessage = (String name, ByteData? data, ui.PlatformMessageResponseCallback? callback) {
final ByteBuffer buffer = data!.buffer;
final Uint8List list = buffer.asUint8List(data.offsetInBytes, data.lengthInBytes);
completer.complete(PlatformResponse(name: name, contents: utf8.decode(list)));
Expand Down
2 changes: 1 addition & 1 deletion testing/dart/platform_view_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ void main() {
builder.addPlatformView(1);
final Scene scene = builder.build();

window.render(scene);
PlatformDispatcher.instance.implicitView!.render(scene);
scene.dispose();
// Test harness asserts that this does not emit an error from the shell logs.
});
Expand Down
2 changes: 1 addition & 1 deletion testing/dart/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ publish_to: none
# relative to this directory into //third_party/dart

environment:
sdk: '>=2.12.0 <3.0.0'
sdk: '>=2.17.0 <3.0.0'

dependencies:
litetest: any
Expand Down
6 changes: 3 additions & 3 deletions testing/dart/text_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -195,18 +195,18 @@ void testTextRange() {

void testLoadFontFromList() {
test('loadFontFromList will send platform message after font is loaded', () async {
final PlatformMessageCallback? oldHandler = window.onPlatformMessage;
final PlatformMessageCallback? oldHandler = PlatformDispatcher.instance.onPlatformMessage;
late String actualName;
late String message;
window.onPlatformMessage = (String name, ByteData? data, PlatformMessageResponseCallback? callback) {
PlatformDispatcher.instance.onPlatformMessage = (String name, ByteData? data, PlatformMessageResponseCallback? callback) {
assert(data != null);
actualName = name;
final Uint8List list = data!.buffer.asUint8List(data.offsetInBytes, data.lengthInBytes);
message = utf8.decode(list);
};
final Uint8List fontData = Uint8List(0);
await loadFontFromList(fontData, fontFamily: 'fake');
window.onPlatformMessage = oldHandler;
PlatformDispatcher.instance.onPlatformMessage = oldHandler;
expect(actualName, 'flutter/system');
expect(message, '{"type":"fontsChange"}');
});
Expand Down
4 changes: 2 additions & 2 deletions testing/dart/window_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ void main() {
test('window.sendPlatformMessage preserves callback zone', () {
runZoned(() {
final Zone innerZone = Zone.current;
window.sendPlatformMessage('test', ByteData.view(Uint8List(0).buffer), expectAsync1((ByteData? data) {
PlatformDispatcher.instance.sendPlatformMessage('test', ByteData.view(Uint8List(0).buffer), expectAsync1((ByteData? data) {
final Zone runZone = Zone.current;
expect(runZone, isNotNull);
expect(runZone, same(innerZone));
Expand Down Expand Up @@ -76,7 +76,7 @@ void main() {
const Locale.fromSubtags(languageCode: 'en'),
];
// The default implementation returns null due to lack of a real platform.
final Locale? result = window.computePlatformResolvedLocale(supportedLocales);
final Locale? result = PlatformDispatcher.instance.computePlatformResolvedLocale(supportedLocales);
expect(result, null);
});
}

0 comments on commit 7893f10

Please sign in to comment.