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

only include foundation changes (#111146)

parent 46998c4a
...@@ -41,6 +41,7 @@ export 'src/foundation/persistent_hash_map.dart'; ...@@ -41,6 +41,7 @@ export 'src/foundation/persistent_hash_map.dart';
export 'src/foundation/platform.dart'; export 'src/foundation/platform.dart';
export 'src/foundation/print.dart'; export 'src/foundation/print.dart';
export 'src/foundation/serialization.dart'; export 'src/foundation/serialization.dart';
export 'src/foundation/service_extensions.dart';
export 'src/foundation/stack_frame.dart'; export 'src/foundation/stack_frame.dart';
export 'src/foundation/synchronous_future.dart'; export 'src/foundation/synchronous_future.dart';
export 'src/foundation/unicode.dart'; export 'src/foundation/unicode.dart';
...@@ -18,6 +18,7 @@ import 'debug.dart'; ...@@ -18,6 +18,7 @@ import 'debug.dart';
import 'object.dart'; import 'object.dart';
import 'platform.dart'; import 'platform.dart';
import 'print.dart'; import 'print.dart';
import 'service_extensions.dart';
export 'dart:ui' show PlatformDispatcher, SingletonFlutterWindow; export 'dart:ui' show PlatformDispatcher, SingletonFlutterWindow;
...@@ -424,7 +425,7 @@ abstract class BindingBase { ...@@ -424,7 +425,7 @@ abstract class BindingBase {
assert(() { assert(() {
registerSignalServiceExtension( registerSignalServiceExtension(
name: 'reassemble', name: FoundationServiceExtensions.reassemble.name,
callback: reassembleApplication, callback: reassembleApplication,
); );
return true; return true;
...@@ -433,20 +434,20 @@ abstract class BindingBase { ...@@ -433,20 +434,20 @@ abstract class BindingBase {
if (!kReleaseMode) { if (!kReleaseMode) {
if (!kIsWeb) { if (!kIsWeb) {
registerSignalServiceExtension( registerSignalServiceExtension(
name: 'exit', name: FoundationServiceExtensions.exit.name,
callback: _exitApplication, callback: _exitApplication,
); );
} }
// These service extensions are used in profile mode applications. // These service extensions are used in profile mode applications.
registerStringServiceExtension( registerStringServiceExtension(
name: 'connectedVmServiceUri', name: FoundationServiceExtensions.connectedVmServiceUri.name,
getter: () async => connectedVmServiceUri ?? '', getter: () async => connectedVmServiceUri ?? '',
setter: (String uri) async { setter: (String uri) async {
connectedVmServiceUri = uri; connectedVmServiceUri = uri;
}, },
); );
registerStringServiceExtension( registerStringServiceExtension(
name: 'activeDevToolsServerAddress', name: FoundationServiceExtensions.activeDevToolsServerAddress.name,
getter: () async => activeDevToolsServerAddress ?? '', getter: () async => activeDevToolsServerAddress ?? '',
setter: (String serverAddress) async { setter: (String serverAddress) async {
activeDevToolsServerAddress = serverAddress; activeDevToolsServerAddress = serverAddress;
...@@ -455,9 +456,8 @@ abstract class BindingBase { ...@@ -455,9 +456,8 @@ abstract class BindingBase {
} }
assert(() { assert(() {
const String platformOverrideExtensionName = 'platformOverride';
registerServiceExtension( registerServiceExtension(
name: platformOverrideExtensionName, name: FoundationServiceExtensions.platformOverride.name,
callback: (Map<String, String> parameters) async { callback: (Map<String, String> parameters) async {
if (parameters.containsKey('value')) { if (parameters.containsKey('value')) {
switch (parameters['value']) { switch (parameters['value']) {
...@@ -484,7 +484,7 @@ abstract class BindingBase { ...@@ -484,7 +484,7 @@ abstract class BindingBase {
debugDefaultTargetPlatformOverride = null; debugDefaultTargetPlatformOverride = null;
} }
_postExtensionStateChangedEvent( _postExtensionStateChangedEvent(
platformOverrideExtensionName, FoundationServiceExtensions.platformOverride.name,
defaultTargetPlatform.toString().substring('$TargetPlatform.'.length), defaultTargetPlatform.toString().substring('$TargetPlatform.'.length),
); );
await reassembleApplication(); await reassembleApplication();
...@@ -497,9 +497,8 @@ abstract class BindingBase { ...@@ -497,9 +497,8 @@ abstract class BindingBase {
}, },
); );
const String brightnessOverrideExtensionName = 'brightnessOverride';
registerServiceExtension( registerServiceExtension(
name: brightnessOverrideExtensionName, name: FoundationServiceExtensions.brightnessOverride.name,
callback: (Map<String, String> parameters) async { callback: (Map<String, String> parameters) async {
if (parameters.containsKey('value')) { if (parameters.containsKey('value')) {
switch (parameters['value']) { switch (parameters['value']) {
...@@ -513,7 +512,7 @@ abstract class BindingBase { ...@@ -513,7 +512,7 @@ abstract class BindingBase {
debugBrightnessOverride = null; debugBrightnessOverride = null;
} }
_postExtensionStateChangedEvent( _postExtensionStateChangedEvent(
brightnessOverrideExtensionName, FoundationServiceExtensions.brightnessOverride.name,
(debugBrightnessOverride ?? platformDispatcher.platformBrightness).toString(), (debugBrightnessOverride ?? platformDispatcher.platformBrightness).toString(),
); );
await reassembleApplication(); await reassembleApplication();
......
// 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 foundation 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 FoundationServiceExtensions {
/// Name of service extension that, when called, will cause the entire
/// application to redraw.
///
/// See also:
///
/// * [BindingBase.initServiceExtensions], where the service extension is
/// registered.
reassemble,
/// Name of service extension that, when called, will terminate the Flutter
/// application.
///
/// See also:
///
/// * [BindingBase.initServiceExtensions], where the service extension is
/// registered.
exit,
/// Name of service extension that, when called, will get or set the value of
/// [connectedVmServiceUri].
///
/// See also:
///
/// * [connectedVmServiceUri], which stores the uri for the connected vm service
/// protocol.
/// * [BindingBase.initServiceExtensions], where the service extension is
/// registered.
connectedVmServiceUri,
/// Name of service extension that, when called, will get or set the value of
/// [activeDevToolsServerAddress].
///
/// See also:
///
/// * [activeDevToolsServerAddress], which stores the address for the active
/// DevTools server used for debugging this application.
/// * [BindingBase.initServiceExtensions], where the service extension is
/// registered.
activeDevToolsServerAddress,
/// Name of service extension that, when called, will change the value of
/// [defaultTargetPlatform], which controls which [TargetPlatform] that the
/// framework will execute for.
///
/// See also:
///
/// * [debugDefaultTargetPlatformOverride], which is the flag that this service
/// extension exposes.
/// * [BindingBase.initServiceExtensions], where the service extension is
/// registered.
platformOverride,
/// Name of service extension that, when called, will override the platform
/// [Brightness].
///
/// See also:
///
/// * [debugBrightnessOverride], which is the flag that this service
/// extension exposes.
/// * [BindingBase.initServiceExtensions], where the service extension is
/// registered.
brightnessOverride,
}
...@@ -578,7 +578,7 @@ void main() { ...@@ -578,7 +578,7 @@ void main() {
test('Service extensions - exit', () async { test('Service extensions - exit', () async {
// no test for _calling_ 'exit', because that should terminate the process! // no test for _calling_ 'exit', because that should terminate the process!
// Not expecting extension to be available for web platform. // Not expecting extension to be available for web platform.
expect(binding.extensions.containsKey('exit'), !isBrowser); expect(binding.extensions.containsKey(FoundationServiceExtensions.exit.name), !isBrowser);
}); });
test('Service extensions - platformOverride', () async { test('Service extensions - platformOverride', () async {
...@@ -588,11 +588,11 @@ void main() { ...@@ -588,11 +588,11 @@ void main() {
expect(binding.reassembled, 0); expect(binding.reassembled, 0);
expect(defaultTargetPlatform, TargetPlatform.android); expect(defaultTargetPlatform, TargetPlatform.android);
result = await binding.testExtension('platformOverride', <String, String>{}); result = await binding.testExtension(FoundationServiceExtensions.platformOverride.name, <String, String>{});
expect(result, <String, String>{'value': 'android'}); expect(result, <String, String>{'value': 'android'});
expect(defaultTargetPlatform, TargetPlatform.android); expect(defaultTargetPlatform, TargetPlatform.android);
expect(extensionChangedEvents, isEmpty); expect(extensionChangedEvents, isEmpty);
result = await hasReassemble(binding.testExtension('platformOverride', <String, String>{'value': 'iOS'})); result = await hasReassemble(binding.testExtension(FoundationServiceExtensions.platformOverride.name, <String, String>{'value': 'iOS'}));
expect(result, <String, String>{'value': 'iOS'}); expect(result, <String, String>{'value': 'iOS'});
expect(binding.reassembled, 1); expect(binding.reassembled, 1);
expect(defaultTargetPlatform, TargetPlatform.iOS); expect(defaultTargetPlatform, TargetPlatform.iOS);
...@@ -600,7 +600,7 @@ void main() { ...@@ -600,7 +600,7 @@ void main() {
extensionChangedEvent = extensionChangedEvents.last; extensionChangedEvent = extensionChangedEvents.last;
expect(extensionChangedEvent['extension'], 'ext.flutter.platformOverride'); expect(extensionChangedEvent['extension'], 'ext.flutter.platformOverride');
expect(extensionChangedEvent['value'], 'iOS'); expect(extensionChangedEvent['value'], 'iOS');
result = await hasReassemble(binding.testExtension('platformOverride', <String, String>{'value': 'macOS'})); result = await hasReassemble(binding.testExtension(FoundationServiceExtensions.platformOverride.name, <String, String>{'value': 'macOS'}));
expect(result, <String, String>{'value': 'macOS'}); expect(result, <String, String>{'value': 'macOS'});
expect(binding.reassembled, 2); expect(binding.reassembled, 2);
expect(defaultTargetPlatform, TargetPlatform.macOS); expect(defaultTargetPlatform, TargetPlatform.macOS);
...@@ -608,7 +608,7 @@ void main() { ...@@ -608,7 +608,7 @@ void main() {
extensionChangedEvent = extensionChangedEvents.last; extensionChangedEvent = extensionChangedEvents.last;
expect(extensionChangedEvent['extension'], 'ext.flutter.platformOverride'); expect(extensionChangedEvent['extension'], 'ext.flutter.platformOverride');
expect(extensionChangedEvent['value'], 'macOS'); expect(extensionChangedEvent['value'], 'macOS');
result = await hasReassemble(binding.testExtension('platformOverride', <String, String>{'value': 'android'})); result = await hasReassemble(binding.testExtension(FoundationServiceExtensions.platformOverride.name, <String, String>{'value': 'android'}));
expect(result, <String, String>{'value': 'android'}); expect(result, <String, String>{'value': 'android'});
expect(binding.reassembled, 3); expect(binding.reassembled, 3);
expect(defaultTargetPlatform, TargetPlatform.android); expect(defaultTargetPlatform, TargetPlatform.android);
...@@ -616,7 +616,7 @@ void main() { ...@@ -616,7 +616,7 @@ void main() {
extensionChangedEvent = extensionChangedEvents.last; extensionChangedEvent = extensionChangedEvents.last;
expect(extensionChangedEvent['extension'], 'ext.flutter.platformOverride'); expect(extensionChangedEvent['extension'], 'ext.flutter.platformOverride');
expect(extensionChangedEvent['value'], 'android'); expect(extensionChangedEvent['value'], 'android');
result = await hasReassemble(binding.testExtension('platformOverride', <String, String>{'value': 'fuchsia'})); result = await hasReassemble(binding.testExtension(FoundationServiceExtensions.platformOverride.name, <String, String>{'value': 'fuchsia'}));
expect(result, <String, String>{'value': 'fuchsia'}); expect(result, <String, String>{'value': 'fuchsia'});
expect(binding.reassembled, 4); expect(binding.reassembled, 4);
expect(defaultTargetPlatform, TargetPlatform.fuchsia); expect(defaultTargetPlatform, TargetPlatform.fuchsia);
...@@ -624,7 +624,7 @@ void main() { ...@@ -624,7 +624,7 @@ void main() {
extensionChangedEvent = extensionChangedEvents.last; extensionChangedEvent = extensionChangedEvents.last;
expect(extensionChangedEvent['extension'], 'ext.flutter.platformOverride'); expect(extensionChangedEvent['extension'], 'ext.flutter.platformOverride');
expect(extensionChangedEvent['value'], 'fuchsia'); expect(extensionChangedEvent['value'], 'fuchsia');
result = await hasReassemble(binding.testExtension('platformOverride', <String, String>{'value': 'default'})); result = await hasReassemble(binding.testExtension(FoundationServiceExtensions.platformOverride.name, <String, String>{'value': 'default'}));
expect(result, <String, String>{'value': 'android'}); expect(result, <String, String>{'value': 'android'});
expect(binding.reassembled, 5); expect(binding.reassembled, 5);
expect(defaultTargetPlatform, TargetPlatform.android); expect(defaultTargetPlatform, TargetPlatform.android);
...@@ -632,7 +632,7 @@ void main() { ...@@ -632,7 +632,7 @@ void main() {
extensionChangedEvent = extensionChangedEvents.last; extensionChangedEvent = extensionChangedEvents.last;
expect(extensionChangedEvent['extension'], 'ext.flutter.platformOverride'); expect(extensionChangedEvent['extension'], 'ext.flutter.platformOverride');
expect(extensionChangedEvent['value'], 'android'); expect(extensionChangedEvent['value'], 'android');
result = await hasReassemble(binding.testExtension('platformOverride', <String, String>{'value': 'iOS'})); result = await hasReassemble(binding.testExtension(FoundationServiceExtensions.platformOverride.name, <String, String>{'value': 'iOS'}));
expect(result, <String, String>{'value': 'iOS'}); expect(result, <String, String>{'value': 'iOS'});
expect(binding.reassembled, 6); expect(binding.reassembled, 6);
expect(defaultTargetPlatform, TargetPlatform.iOS); expect(defaultTargetPlatform, TargetPlatform.iOS);
...@@ -640,7 +640,7 @@ void main() { ...@@ -640,7 +640,7 @@ void main() {
extensionChangedEvent = extensionChangedEvents.last; extensionChangedEvent = extensionChangedEvents.last;
expect(extensionChangedEvent['extension'], 'ext.flutter.platformOverride'); expect(extensionChangedEvent['extension'], 'ext.flutter.platformOverride');
expect(extensionChangedEvent['value'], 'iOS'); expect(extensionChangedEvent['value'], 'iOS');
result = await hasReassemble(binding.testExtension('platformOverride', <String, String>{'value': 'linux'})); result = await hasReassemble(binding.testExtension(FoundationServiceExtensions.platformOverride.name, <String, String>{'value': 'linux'}));
expect(result, <String, String>{'value': 'linux'}); expect(result, <String, String>{'value': 'linux'});
expect(binding.reassembled, 7); expect(binding.reassembled, 7);
expect(defaultTargetPlatform, TargetPlatform.linux); expect(defaultTargetPlatform, TargetPlatform.linux);
...@@ -648,7 +648,7 @@ void main() { ...@@ -648,7 +648,7 @@ void main() {
extensionChangedEvent = extensionChangedEvents.last; extensionChangedEvent = extensionChangedEvents.last;
expect(extensionChangedEvent['extension'], 'ext.flutter.platformOverride'); expect(extensionChangedEvent['extension'], 'ext.flutter.platformOverride');
expect(extensionChangedEvent['value'], 'linux'); expect(extensionChangedEvent['value'], 'linux');
result = await hasReassemble(binding.testExtension('platformOverride', <String, String>{'value': 'windows'})); result = await hasReassemble(binding.testExtension(FoundationServiceExtensions.platformOverride.name, <String, String>{'value': 'windows'}));
expect(result, <String, String>{'value': 'windows'}); expect(result, <String, String>{'value': 'windows'});
expect(binding.reassembled, 8); expect(binding.reassembled, 8);
expect(defaultTargetPlatform, TargetPlatform.windows); expect(defaultTargetPlatform, TargetPlatform.windows);
...@@ -656,7 +656,7 @@ void main() { ...@@ -656,7 +656,7 @@ void main() {
extensionChangedEvent = extensionChangedEvents.last; extensionChangedEvent = extensionChangedEvents.last;
expect(extensionChangedEvent['extension'], 'ext.flutter.platformOverride'); expect(extensionChangedEvent['extension'], 'ext.flutter.platformOverride');
expect(extensionChangedEvent['value'], 'windows'); expect(extensionChangedEvent['value'], 'windows');
result = await hasReassemble(binding.testExtension('platformOverride', <String, String>{'value': 'bogus'})); result = await hasReassemble(binding.testExtension(FoundationServiceExtensions.platformOverride.name, <String, String>{'value': 'bogus'}));
expect(result, <String, String>{'value': 'android'}); expect(result, <String, String>{'value': 'android'});
expect(binding.reassembled, 9); expect(binding.reassembled, 9);
expect(defaultTargetPlatform, TargetPlatform.android); expect(defaultTargetPlatform, TargetPlatform.android);
...@@ -843,7 +843,7 @@ void main() { ...@@ -843,7 +843,7 @@ void main() {
completed = false; completed = false;
expect(binding.reassembled, 0); expect(binding.reassembled, 0);
pendingResult = binding.testExtension('reassemble', <String, String>{}); pendingResult = binding.testExtension(FoundationServiceExtensions.reassemble.name, <String, String>{});
pendingResult.whenComplete(() { completed = true; }); pendingResult.whenComplete(() { completed = true; });
await binding.flushMicrotasks(); await binding.flushMicrotasks();
expect(binding.frameScheduled, isTrue); expect(binding.frameScheduled, isTrue);
...@@ -925,7 +925,7 @@ void main() { ...@@ -925,7 +925,7 @@ void main() {
test('Service extensions - brightnessOverride', () async { test('Service extensions - brightnessOverride', () async {
Map<String, dynamic> result; Map<String, dynamic> result;
result = await binding.testExtension('brightnessOverride', <String, String>{}); result = await binding.testExtension(FoundationServiceExtensions.brightnessOverride.name, <String, String>{});
final String brightnessValue = result['value'] as String; final String brightnessValue = result['value'] as String;
expect(brightnessValue, 'Brightness.light'); expect(brightnessValue, 'Brightness.light');
...@@ -933,26 +933,26 @@ void main() { ...@@ -933,26 +933,26 @@ void main() {
test('Service extensions - activeDevToolsServerAddress', () async { test('Service extensions - activeDevToolsServerAddress', () async {
Map<String, dynamic> result; Map<String, dynamic> result;
result = await binding.testExtension('activeDevToolsServerAddress', <String, String>{}); result = await binding.testExtension(FoundationServiceExtensions.activeDevToolsServerAddress.name, <String, String>{});
String serverAddress = result['value'] as String; String serverAddress = result['value'] as String;
expect(serverAddress, ''); expect(serverAddress, '');
result = await binding.testExtension('activeDevToolsServerAddress', <String, String>{'value': 'http://127.0.0.1:9101'}); result = await binding.testExtension(FoundationServiceExtensions.activeDevToolsServerAddress.name, <String, String>{'value': 'http://127.0.0.1:9101'});
serverAddress = result['value'] as String; serverAddress = result['value'] as String;
expect(serverAddress, 'http://127.0.0.1:9101'); expect(serverAddress, 'http://127.0.0.1:9101');
result = await binding.testExtension('activeDevToolsServerAddress', <String, String>{'value': 'http://127.0.0.1:9102'}); result = await binding.testExtension(FoundationServiceExtensions.activeDevToolsServerAddress.name, <String, String>{'value': 'http://127.0.0.1:9102'});
serverAddress = result['value'] as String; serverAddress = result['value'] as String;
expect(serverAddress, 'http://127.0.0.1:9102'); expect(serverAddress, 'http://127.0.0.1:9102');
}); });
test('Service extensions - connectedVmServiceUri', () async { test('Service extensions - connectedVmServiceUri', () async {
Map<String, dynamic> result; Map<String, dynamic> result;
result = await binding.testExtension('connectedVmServiceUri', <String, String>{}); result = await binding.testExtension(FoundationServiceExtensions.connectedVmServiceUri.name, <String, String>{});
String serverAddress = result['value'] as String; String serverAddress = result['value'] as String;
expect(serverAddress, ''); expect(serverAddress, '');
result = await binding.testExtension('connectedVmServiceUri', <String, String>{'value': 'http://127.0.0.1:54669/kMUMseKAnog=/'}); result = await binding.testExtension(FoundationServiceExtensions.connectedVmServiceUri.name, <String, String>{'value': 'http://127.0.0.1:54669/kMUMseKAnog=/'});
serverAddress = result['value'] as String; serverAddress = result['value'] as String;
expect(serverAddress, 'http://127.0.0.1:54669/kMUMseKAnog=/'); expect(serverAddress, 'http://127.0.0.1:54669/kMUMseKAnog=/');
result = await binding.testExtension('connectedVmServiceUri', <String, String>{'value': 'http://127.0.0.1:54000/kMUMseKAnog=/'}); result = await binding.testExtension(FoundationServiceExtensions.connectedVmServiceUri.name, <String, String>{'value': 'http://127.0.0.1:54000/kMUMseKAnog=/'});
serverAddress = result['value'] as String; serverAddress = result['value'] as String;
expect(serverAddress, 'http://127.0.0.1:54000/kMUMseKAnog=/'); expect(serverAddress, 'http://127.0.0.1:54000/kMUMseKAnog=/');
}); });
......
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