Skip to content

Commit

Permalink
Register a service extension for profileUserWidgetBuilds (flutter#1…
Browse files Browse the repository at this point in the history
  • Loading branch information
kenzieschmoll authored Apr 15, 2022
1 parent 3ce2931 commit 0d08756
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 3 deletions.
8 changes: 8 additions & 0 deletions packages/flutter/lib/src/widgets/binding.dart
Original file line number Diff line number Diff line change
Expand Up @@ -435,6 +435,14 @@ mixin WidgetsBinding on BindingBase, ServicesBinding, SchedulerBinding, GestureB
debugProfileBuildsEnabled = value;
},
);
registerBoolServiceExtension(
name: 'profileUserWidgetBuilds',
getter: () async => debugProfileBuildsEnabledUserWidgets,
setter: (bool value) async {
if (debugProfileBuildsEnabledUserWidgets != value)
debugProfileBuildsEnabledUserWidgets = value;
},
);
}

assert(() {
Expand Down
40 changes: 37 additions & 3 deletions packages/flutter/test/foundation/service_extensions_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -171,9 +171,14 @@ void main() {
// 1. exit
// 2. showPerformanceOverlay
const int disabledExtensions = kIsWeb ? 2 : 0;
// If you add a service extension... TEST IT! :-)
// ...then increment this number.
expect(binding.extensions.length, 35 + widgetInspectorExtensionCount - disabledExtensions);

// The expected number of registered service extensions in the Flutter
// framework, excluding any that are for the widget inspector
// (see widget_inspector_test.dart for tests of the ext.flutter.inspector
// service extensions).
const int serviceExtensionCount = 36;

expect(binding.extensions.length, serviceExtensionCount + widgetInspectorExtensionCount - disabledExtensions);

expect(console, isEmpty);
debugPrint = debugPrintThrottled;
Expand Down Expand Up @@ -442,6 +447,35 @@ void main() {
expect(binding.frameScheduled, isFalse);
});

test('Service extensions - profileUserWidgetBuilds', () async {
Map<String, dynamic> result;

expect(binding.frameScheduled, isFalse);
expect(debugProfileBuildsEnabledUserWidgets, false);

result = await binding.testExtension('profileUserWidgetBuilds', <String, String>{});
expect(result, <String, String>{'enabled': 'false'});
expect(debugProfileBuildsEnabledUserWidgets, false);

result = await binding.testExtension('profileUserWidgetBuilds', <String, String>{'enabled': 'true'});
expect(result, <String, String>{'enabled': 'true'});
expect(debugProfileBuildsEnabledUserWidgets, true);

result = await binding.testExtension('profileUserWidgetBuilds', <String, String>{});
expect(result, <String, String>{'enabled': 'true'});
expect(debugProfileBuildsEnabledUserWidgets, true);

result = await binding.testExtension('profileUserWidgetBuilds', <String, String>{'enabled': 'false'});
expect(result, <String, String>{'enabled': 'false'});
expect(debugProfileBuildsEnabledUserWidgets, false);

result = await binding.testExtension('profileUserWidgetBuilds', <String, String>{});
expect(result, <String, String>{'enabled': 'false'});
expect(debugProfileBuildsEnabledUserWidgets, false);

expect(binding.frameScheduled, isFalse);
});

test('Service extensions - profileRenderObjectPaints', () async {
Map<String, dynamic> result;

Expand Down

0 comments on commit 0d08756

Please sign in to comment.