-
Notifications
You must be signed in to change notification settings - Fork 3.8k
[cupertino_ui] Re-enable tab_scaffold_test.dart
#12064
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,121 @@ | ||
| // Copyright 2013 The Flutter Authors | ||
| // Use of this source code is governed by a BSD-style license that can be | ||
| // found in the LICENSE file. | ||
|
|
||
| import 'dart:convert'; | ||
|
|
||
| import 'package:cupertino_ui/cupertino_ui.dart'; | ||
| import 'package:flutter/foundation.dart'; | ||
| import 'package:flutter_test/flutter_test.dart'; | ||
|
|
||
| /// Tuple-like test class for storing a [stream] and [eventKind]. | ||
| /// | ||
| /// Used to store the [stream] and [eventKind] that a dispatched event would be | ||
| /// sent on. | ||
| @immutable | ||
| class DispatchedEventKey { | ||
| const DispatchedEventKey({required this.stream, required this.eventKind}); | ||
|
|
||
| final String stream; | ||
| final String eventKind; | ||
|
|
||
| @override | ||
| String toString() { | ||
| return '[DispatchedEventKey]($stream, $eventKind)'; | ||
| } | ||
|
|
||
| @override | ||
| bool operator ==(Object other) { | ||
| return other is DispatchedEventKey && stream == other.stream && eventKind == other.eventKind; | ||
| } | ||
|
|
||
| @override | ||
| int get hashCode => Object.hash(stream, eventKind); | ||
| } | ||
|
|
||
| class TestWidgetInspectorService extends Object with WidgetInspectorService { | ||
| TestWidgetInspectorService() { | ||
| selection.addListener(() => selectionChangedCallback?.call()); | ||
| } | ||
|
|
||
| final Map<String, ServiceExtensionCallback> extensions = <String, ServiceExtensionCallback>{}; | ||
|
|
||
| final Map<DispatchedEventKey, List<Map<Object, Object?>>> eventsDispatched = | ||
| <DispatchedEventKey, List<Map<Object, Object?>>>{}; | ||
|
|
||
| final List<Object?> objectsInspected = <Object?>[]; | ||
|
|
||
| @override | ||
| void registerServiceExtension({ | ||
| required String name, | ||
| required ServiceExtensionCallback callback, | ||
| required RegisterServiceExtensionCallback registerExtension, | ||
| }) { | ||
| assert(!extensions.containsKey(name)); | ||
| extensions[name] = callback; | ||
| } | ||
|
|
||
| @override | ||
| void postEvent(String eventKind, Map<Object, Object?> eventData, {String stream = 'Extension'}) { | ||
| dispatchedEvents(eventKind, stream: stream).add(eventData); | ||
| } | ||
|
|
||
| @override | ||
| void inspect(Object? object) { | ||
| objectsInspected.add(object); | ||
| } | ||
|
|
||
| List<Map<Object, Object?>> dispatchedEvents(String eventKind, {String stream = 'Extension'}) { | ||
| return eventsDispatched.putIfAbsent( | ||
| DispatchedEventKey(stream: stream, eventKind: eventKind), | ||
| () => <Map<Object, Object?>>[], | ||
| ); | ||
| } | ||
|
|
||
| List<Object?> inspectedObjects() { | ||
| return objectsInspected; | ||
| } | ||
|
|
||
| Iterable<Map<Object, Object?>> getServiceExtensionStateChangedEvents(String extensionName) { | ||
| return dispatchedEvents( | ||
| 'Flutter.ServiceExtensionStateChanged', | ||
| ).where((Map<Object, Object?> event) => event['extension'] == extensionName); | ||
| } | ||
|
|
||
| Future<Object?> testExtension(String name, Map<String, String> arguments) async { | ||
| expect(extensions, contains(name)); | ||
| // Encode and decode to JSON to match behavior using a real service | ||
| // extension where only JSON is allowed. | ||
| return (json.decode(json.encode(await extensions[name]!(arguments))) | ||
| as Map<String, dynamic>)['result']; | ||
| } | ||
|
|
||
| Future<String> testBoolExtension(String name, Map<String, String> arguments) async { | ||
| expect(extensions, contains(name)); | ||
| // Encode and decode to JSON to match behavior using a real service | ||
| // extension where only JSON is allowed. | ||
| return (json.decode(json.encode(await extensions[name]!(arguments))) | ||
| as Map<String, dynamic>)['enabled'] | ||
| .toString(); | ||
| } | ||
|
Comment on lines
+93
to
+100
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The Future<String> testBoolExtension(String name, Map<String, String> arguments) async {
expect(extensions, contains(name));
// Encode and decode to JSON to match behavior using a real service
// extension where only JSON is allowed.
final Map<String, dynamic> result = json.decode(json.encode(await extensions[name]!(arguments))) as Map<String, dynamic>;
return result['enabled']?.toString() ?? 'false';
}
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Sounds reasonable, though I know you just copied this code, so it's fine either way. |
||
|
|
||
| int rebuildCount = 0; | ||
|
|
||
| @override | ||
| Future<void> forceRebuild() async { | ||
| rebuildCount++; | ||
| final WidgetsBinding binding = WidgetsBinding.instance; | ||
|
|
||
| if (binding.rootElement != null) { | ||
| binding.buildOwner!.reassemble(binding.rootElement!); | ||
| } | ||
| } | ||
|
|
||
| @override | ||
| void resetAllState() { | ||
| super.resetAllState(); | ||
| eventsDispatched.clear(); | ||
| objectsInspected.clear(); | ||
| rebuildCount = 0; | ||
| } | ||
| } | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The import of
package:cupertino_ui/cupertino_ui.dartis unused in this test utility file. To avoid unnecessary coupling and keep the test utilities clean, importpackage:flutter/widgets.dartinstead, which providesWidgetInspectorServiceandWidgetsBinding.References
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is it really unused?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No it's definitely used.