Skip to content

Conversation

@dkwingsmt
Copy link
Contributor

@dkwingsmt dkwingsmt commented May 25, 2021

This PR adds tests to the following behaviors, which have existed without tests:

  • When tapping during live testing, a message is printed with widgets that contain the tap location.
  • When tapping during live testing, a mark is displayed on screen on the tap location.

API change to TestWidgetsFlutterBinding

TestWidgetsFlutterBinding.handlePointerEvent no longer shadows GestureBinding.handlePointerEvent with a different signature. Its source-specified version is renamed to handlePointerEventForSource. This allows subclasses to redefine only how pointer events are handled (for each source) without having to change the source storing process.

New feature of AnimationSheetBuilder

AnimationSheetBuilder now supports a new option at construction: allLayers. The current behavior is allLayers: false. If allLayers is true, the recorder records the resulting image composited by the entire tree, clipped by the region of this recorder. This is useful when it is impossible for the recorder to include the target image in its subtree, which is needed for the test of this PR.

New way to use AnimationSheetBuilder and deprecation

AnimationSheetBuilder's output step used to require two calls: display and surfaceSize. This PR introduced a new way: collate.

The collate function directly puts the images together and asynchronously returns an image. It requires less boilerplate, and outputs smaller images (1/3 the width & height) without any compromise to quality.

The current APIs (display and surfaceSize) are thus deprecated. A migration guide is provided (although these APIs are probably not used by customer tests or g3): flutter/website#5862.

Pre-launch Checklist

  • I read the Contributor Guide and followed the process outlined there for submitting PRs.
  • I read the Tree Hygiene wiki page, which explains my responsibilities.
  • I read and followed the Flutter Style Guide, including Features we expect every widget to implement.
  • I signed the CLA.
  • I listed at least one issue that this PR fixes in the description above.
  • I updated/added relevant documentation (doc comments with ///).
  • I added new tests to check the change I am making or feature I am adding, or Hixie said the PR is test-exempt.
  • All existing and new tests are passing.

If you need help, consider asking for advice on the #hackers-new channel on Discord.

@flutter-dashboard flutter-dashboard bot added a: tests "flutter test", flutter_test, or one of our tests framework flutter/packages/flutter repository. See also f: labels. c: contributor-productivity Team-specific productivity, code health, technical debt. labels May 25, 2021
@google-cla google-cla bot added the cla: yes label May 25, 2021
@skia-gold
Copy link

Gold has detected about 1 untriaged digest(s) on patchset 9.
View them at https://flutter-gold.skia.org/cl/github/83337

@flutter-dashboard flutter-dashboard bot added the f: material design flutter/packages/flutter/material repository. label May 28, 2021
@skia-gold
Copy link

Gold has detected about 3 new digest(s) on patchset 11.
View them at https://flutter-gold.skia.org/cl/github/83337

@skia-gold
Copy link

Gold has detected about 3 new digest(s) on patchset 12.
View them at https://flutter-gold.skia.org/cl/github/83337

@skia-gold
Copy link

Gold has detected about 3 new digest(s) on patchset 14.
View them at https://flutter-gold.skia.org/cl/github/83337

@skia-gold
Copy link

Gold has detected about 3 new digest(s) on patchset 15.
View them at https://flutter-gold.skia.org/cl/github/83337

@skia-gold
Copy link

Gold has detected about 3 new digest(s) on patchset 16.
View them at https://flutter-gold.skia.org/cl/github/83337

@dkwingsmt dkwingsmt requested a review from goderbauer June 1, 2021 20:46
Copy link
Member

@goderbauer goderbauer left a comment

Choose a reason for hiding this comment

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

LGTM


final Widget display = await builder.display();
await tester.binding.setSurfaceSize(builder.sheetSize());
final Widget display = await builder.display(); // ignore: deprecated_member_use
Copy link
Member

Choose a reason for hiding this comment

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

Can these just be migrated to the new API? If not, maybe leave a comment explaining the ignore?

Copy link
Contributor Author

@dkwingsmt dkwingsmt Jun 2, 2021

Choose a reason for hiding this comment

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

This is to test the deprecated APIs are still working. I'll add a comment.

await tester.pumpWidget(display);

final ui.Image image = await animationSheet.collate(20);
// The deprecated `sheetSize` is used only for the migration from
Copy link
Member

Choose a reason for hiding this comment

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

What does this comment mean? Should these be migrated to the new API?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I plan to submit a new PR for the migration because the migration will break golden tests (because they'll be 1/3 in size), and in this way we're more sure what exactly caused the golden tests. It does look a bit redundant. Should I do them in the same PR?

*/

LiveTestWidgetsFlutterBinding();
testWidgets('Should show event indicator for pointer events', (WidgetTester tester) async {
Copy link
Member

Choose a reason for hiding this comment

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

nit: add a blank line before this one to help readability.

import 'package:flutter/material.dart';
import 'package:flutter/rendering.dart';
import 'package:flutter_test/flutter_test.dart';

Copy link
Member

Choose a reason for hiding this comment

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

nit: remove extra blank line?

Comment on lines 74 to 76
return _storeDebugPrints == null ?
super.debugPrintOverride :
((String? message, { int? wrapWidth }) => _storeDebugPrints!.add(message));
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
return _storeDebugPrints == null ?
super.debugPrintOverride :
((String? message, { int? wrapWidth }) => _storeDebugPrints!.add(message));
return _storeDebugPrints == null
? super.debugPrintOverride
: ((String? message, { int? wrapWidth }) => _storeDebugPrints!.add(message));

await tester.pump();
expect(invocations, 0);

expect(printedMessages, equals('''
Copy link
Member

Choose a reason for hiding this comment

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

Maybe to verify that it doesn't just list all possibilities also check what it prints when the tap misses the Text widget?

@skia-gold
Copy link

Gold has detected about 5 new digest(s) on patchset 18.
View them at https://flutter-gold.skia.org/cl/github/83337

@skia-gold
Copy link

Gold has detected about 6 new digest(s) on patchset 19.
View them at https://flutter-gold.skia.org/cl/github/83337

@dkwingsmt dkwingsmt removed f: material design flutter/packages/flutter/material repository. c: contributor-productivity Team-specific productivity, code health, technical debt. labels Jun 2, 2021
@dkwingsmt dkwingsmt merged commit e3da1bd into flutter:master Jun 2, 2021
@dkwingsmt dkwingsmt deleted the test-widget-tester-debug branch June 2, 2021 18:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

a: tests "flutter test", flutter_test, or one of our tests framework flutter/packages/flutter repository. See also f: labels.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants