Unverified Commit 76d6d36b authored by Victoria Ashworth's avatar Victoria Ashworth Committed by GitHub

Revert "FocusNode and FocusManager should dispatch creation in constructor." (#133474)

Reverts flutter/flutter#133352

Tree is failing on Mac and Linux customer_testing on this PR.
https://ci.chromium.org/ui/p/flutter/builders/prod/Mac%20customer_testing/14646/overview
https://ci.chromium.org/ui/p/flutter/builders/prod/Linux%20customer_testing/14974/overview
parent ec387a46
......@@ -471,7 +471,6 @@ class DrawerControllerState extends State<DrawerController> with SingleTickerPro
void dispose() {
_historyEntry?.remove();
_controller.dispose();
_focusScopeNode.dispose();
super.dispose();
}
......
......@@ -437,10 +437,6 @@ class FocusNode with DiagnosticableTreeMixin, ChangeNotifier {
_descendantsAreTraversable = descendantsAreTraversable {
// Set it via the setter so that it does nothing on release builds.
this.debugLabel = debugLabel;
if (kFlutterMemoryAllocationsEnabled) {
maybeDispatchObjectCreation();
}
}
/// If true, tells the focus traversal policy to skip over this node for
......@@ -1467,9 +1463,6 @@ class FocusManager with DiagnosticableTreeMixin, ChangeNotifier {
/// handlers, callers must call [registerGlobalHandlers]. See the
/// documentation in that method for caveats to watch out for.
FocusManager() {
if (kFlutterMemoryAllocationsEnabled) {
maybeDispatchObjectCreation();
}
rootScope._manager = this;
}
......
......@@ -1609,41 +1609,6 @@ void main() {
tester.binding.focusManager.removeListener(handleFocusChange);
});
test('$FocusManager dispatches object creation in constructor', () {
final List<ObjectEvent> events = <ObjectEvent>[];
void listener(ObjectEvent event) {
if (event.object.runtimeType == FocusManager) {
events.add(event);
}
}
MemoryAllocations.instance.addListener(listener);
final FocusManager focusManager = FocusManager();
expect(events, hasLength(1));
focusManager.dispose();
MemoryAllocations.instance.removeListener(listener);
});
test('$FocusNode dispatches object creation in constructor', () {
final List<ObjectEvent> events = <ObjectEvent>[];
void listener(ObjectEvent event) {
if (event.object.runtimeType == FocusNode) {
events.add(event);
}
}
MemoryAllocations.instance.addListener(listener);
final FocusNode focusManager = FocusNode();
expect(events, hasLength(1));
focusManager.dispose();
MemoryAllocations.instance.removeListener(listener);
});
testWidgets('FocusManager notifies listeners when a widget loses focus because it was removed.', (WidgetTester tester) async {
final FocusNode nodeA = FocusNode(debugLabel: 'a');
final FocusNode nodeB = FocusNode(debugLabel: 'b');
......
......@@ -6,26 +6,20 @@ import 'package:flutter/foundation.dart';
import 'package:flutter/widgets.dart';
import 'package:flutter_test/flutter_test.dart';
int _creations = 0;
int _disposals = 0;
void main() {
final MemoryAllocations ma = MemoryAllocations.instance;
setUp(() {
assert(!ma.hasListeners);
});
test('Publishers dispatch events in debug mode', () async {
void listener(ObjectEvent event) {
if (event is ObjectDisposed) {
_disposals++;
}
if (event is ObjectCreated) {
_creations++;
}
}
int eventCount = 0;
void listener(ObjectEvent event) => eventCount++;
ma.addListener(listener);
final _EventStats actual = await _activateFlutterObjectsAndReturnCountOfEvents();
expect(actual.creations, _creations);
expect(actual.disposals, _disposals);
final int expectedEventCount = await _activateFlutterObjectsAndReturnCountOfEvents();
expect(eventCount, expectedEventCount);
ma.removeListener(listener);
expect(ma.hasListeners, isFalse);
......@@ -35,8 +29,6 @@ void main() {
bool stateCreated = false;
bool stateDisposed = false;
expect(ma.hasListeners, false);
void listener(ObjectEvent event) {
if (event is ObjectCreated && event.object is State) {
stateCreated = true;
......@@ -55,7 +47,7 @@ void main() {
expect(stateCreated, isTrue);
expect(stateDisposed, isTrue);
ma.removeListener(listener);
expect(ma.hasListeners, false);
expect(ma.hasListeners, isFalse);
});
}
......@@ -70,8 +62,7 @@ class _TestElement extends RenderObjectElement with RootElementMixin {
_TestElement(): super(_TestLeafRenderObjectWidget());
void makeInactive() {
final FocusManager newFocusManager = FocusManager();
assignOwner(BuildOwner(focusManager: newFocusManager));
assignOwner(BuildOwner(focusManager: FocusManager()));
mount(null, null);
deactivate();
}
......@@ -118,22 +109,15 @@ class _TestStatefulWidgetState extends State<_TestStatefulWidget> {
}
}
class _EventStats {
int creations = 0;
int disposals = 0;
}
/// Create and dispose Flutter objects to fire memory allocation events.
Future<_EventStats> _activateFlutterObjectsAndReturnCountOfEvents() async {
final _EventStats result = _EventStats();
Future<int> _activateFlutterObjectsAndReturnCountOfEvents() async {
int count = 0;
final _TestElement element = _TestElement(); result.creations++;
final RenderObject renderObject = _TestRenderObject(); result.creations++;
final _TestElement element = _TestElement(); count++;
final RenderObject renderObject = _TestRenderObject(); count++;
element.makeInactive(); result.creations += 3; // 1 for the new BuildOwner, 1 for the new FocusManager, 1 for the new FocusScopeNode
element.unmount(); result.disposals += 2; // 1 for the old BuildOwner, 1 for the element
renderObject.dispose(); result.disposals += 1;
element.makeInactive(); element.unmount(); count += 3;
renderObject.dispose(); count++;
return result;
return count;
}
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