Unverified Commit 87084933 authored by Kenzie Davisson's avatar Kenzie Davisson Committed by GitHub

Create enum for scheduler service extension names so they can be accessed from tooling (#111222)

* Create enum for scheduler service extension names so they can be accessed from tooling

* fix two more strings
parent 12d1fc0d
...@@ -16,4 +16,5 @@ library scheduler; ...@@ -16,4 +16,5 @@ library scheduler;
export 'src/scheduler/binding.dart'; export 'src/scheduler/binding.dart';
export 'src/scheduler/debug.dart'; export 'src/scheduler/debug.dart';
export 'src/scheduler/priority.dart'; export 'src/scheduler/priority.dart';
export 'src/scheduler/service_extensions.dart';
export 'src/scheduler/ticker.dart'; export 'src/scheduler/ticker.dart';
...@@ -12,6 +12,7 @@ import 'package:flutter/foundation.dart'; ...@@ -12,6 +12,7 @@ import 'package:flutter/foundation.dart';
import 'debug.dart'; import 'debug.dart';
import 'priority.dart'; import 'priority.dart';
import 'service_extensions.dart';
export 'dart:developer' show Flow; export 'dart:developer' show Flow;
export 'dart:ui' show AppLifecycleState, FrameTiming, TimingsCallback; export 'dart:ui' show AppLifecycleState, FrameTiming, TimingsCallback;
...@@ -355,7 +356,7 @@ mixin SchedulerBinding on BindingBase { ...@@ -355,7 +356,7 @@ mixin SchedulerBinding on BindingBase {
if (!kReleaseMode) { if (!kReleaseMode) {
registerNumericServiceExtension( registerNumericServiceExtension(
name: 'timeDilation', name: SchedulerServiceExtensions.timeDilation.name,
getter: () async => timeDilation, getter: () async => timeDilation,
setter: (double value) async { setter: (double value) async {
timeDilation = value; timeDilation = value;
......
// Copyright 2014 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.
/// Service extension constants for the scheduler library.
///
/// These constants will be used when registering service extensions in the
/// framework, and they will also be used by tools and services that call these
/// service extensions.
///
/// The String value for each of these extension names should be accessed by
/// calling the `.name` property on the enum value.
enum SchedulerServiceExtensions {
/// Name of service extension that, when called, will change the value of
/// [timeDilation], which determines the factor by which to slow down
/// animations for help in development.
///
/// See also:
///
/// * [timeDilation], which is the field that this service extension exposes.
/// * [SchedulerBinding.initServiceExtensions], where the service extension is
/// registered.
timeDilation,
}
...@@ -894,30 +894,30 @@ void main() { ...@@ -894,30 +894,30 @@ void main() {
expect(binding.frameScheduled, isFalse); expect(binding.frameScheduled, isFalse);
expect(timeDilation, 1.0); expect(timeDilation, 1.0);
result = await binding.testExtension('timeDilation', <String, String>{}); result = await binding.testExtension(SchedulerServiceExtensions.timeDilation.name, <String, String>{});
expect(result, <String, String>{'timeDilation': 1.0.toString()}); expect(result, <String, String>{SchedulerServiceExtensions.timeDilation.name: 1.0.toString()});
expect(timeDilation, 1.0); expect(timeDilation, 1.0);
expect(extensionChangedEvents, isEmpty); expect(extensionChangedEvents, isEmpty);
result = await binding.testExtension('timeDilation', <String, String>{'timeDilation': '100.0'}); result = await binding.testExtension(SchedulerServiceExtensions.timeDilation.name, <String, String>{SchedulerServiceExtensions.timeDilation.name: '100.0'});
expect(result, <String, String>{'timeDilation': 100.0.toString()}); expect(result, <String, String>{SchedulerServiceExtensions.timeDilation.name: 100.0.toString()});
expect(timeDilation, 100.0); expect(timeDilation, 100.0);
expect(extensionChangedEvents.length, 1); expect(extensionChangedEvents.length, 1);
extensionChangedEvent = extensionChangedEvents.last; extensionChangedEvent = extensionChangedEvents.last;
expect(extensionChangedEvent['extension'], 'ext.flutter.timeDilation'); expect(extensionChangedEvent['extension'], 'ext.flutter.${SchedulerServiceExtensions.timeDilation.name}');
expect(extensionChangedEvent['value'], 100.0.toString()); expect(extensionChangedEvent['value'], 100.0.toString());
result = await binding.testExtension('timeDilation', <String, String>{}); result = await binding.testExtension(SchedulerServiceExtensions.timeDilation.name, <String, String>{});
expect(result, <String, String>{'timeDilation': 100.0.toString()}); expect(result, <String, String>{SchedulerServiceExtensions.timeDilation.name: 100.0.toString()});
expect(timeDilation, 100.0); expect(timeDilation, 100.0);
expect(extensionChangedEvents.length, 1); expect(extensionChangedEvents.length, 1);
result = await binding.testExtension('timeDilation', <String, String>{'timeDilation': '1.0'}); result = await binding.testExtension(SchedulerServiceExtensions.timeDilation.name, <String, String>{SchedulerServiceExtensions.timeDilation.name: '1.0'});
expect(result, <String, String>{'timeDilation': 1.0.toString()}); expect(result, <String, String>{SchedulerServiceExtensions.timeDilation.name: 1.0.toString()});
expect(timeDilation, 1.0); expect(timeDilation, 1.0);
expect(extensionChangedEvents.length, 2); expect(extensionChangedEvents.length, 2);
extensionChangedEvent = extensionChangedEvents.last; extensionChangedEvent = extensionChangedEvents.last;
expect(extensionChangedEvent['extension'], 'ext.flutter.timeDilation'); expect(extensionChangedEvent['extension'], 'ext.flutter.${SchedulerServiceExtensions.timeDilation.name}');
expect(extensionChangedEvent['value'], 1.0.toString()); expect(extensionChangedEvent['value'], 1.0.toString());
result = await binding.testExtension('timeDilation', <String, String>{}); result = await binding.testExtension(SchedulerServiceExtensions.timeDilation.name, <String, String>{});
expect(result, <String, String>{'timeDilation': 1.0.toString()}); expect(result, <String, String>{SchedulerServiceExtensions.timeDilation.name: 1.0.toString()});
expect(timeDilation, 1.0); expect(timeDilation, 1.0);
expect(extensionChangedEvents.length, 2); expect(extensionChangedEvents.length, 2);
expect(binding.frameScheduled, isFalse); expect(binding.frameScheduled, isFalse);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment