inflate_widget_tracing_test.dart 2.06 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
// 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.

import 'package:flutter/scheduler.dart';
import 'package:flutter/widgets.dart';
import 'package:flutter_test/flutter_test.dart';

import 'common.dart';

final Set<String> interestingLabels = <String>{
  '$Row',
  '$TestRoot',
  '$TestChildWidget',
  '$Container',
};

void main() {
19
  ZoneIgnoringTestBinding.ensureInitialized();
20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42
  initTimelineTests();
  test('Children of MultiChildRenderObjectElement show up in tracing', () async {
    // We don't have expectations around the first frame because there's a race around
    // the warm-up frame that we don't want to get involved in here.
    await runFrame(() { runApp(const TestRoot()); });
    await SchedulerBinding.instance.endOfFrame;
    await fetchInterestingEvents(interestingLabels);

    debugProfileBuildsEnabled = true;

    await runFrame(() {
      TestRoot.state.showRow();
    });
    expect(
      await fetchInterestingEventNames(interestingLabels),
      <String>['TestRoot', 'Row', 'TestChildWidget', 'Container', 'TestChildWidget', 'Container'],
    );

    debugProfileBuildsEnabled = false;
  }, skip: isBrowser); // [intended] uses dart:isolate and io.
}

class TestRoot extends StatefulWidget {
43
  const TestRoot({super.key});
44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67

  static late TestRootState state;

  @override
  State<TestRoot> createState() => TestRootState();
}

class TestRootState extends State<TestRoot> {
  @override
  void initState() {
    super.initState();
    TestRoot.state = this;
  }

  bool _showRow = false;
  void showRow() {
    setState(() {
      _showRow = true;
    });
  }

  @override
  Widget build(BuildContext context) {
    return _showRow
68 69
      ? const Row(
          children: <Widget>[
70 71 72 73 74 75 76 77 78
            TestChildWidget(),
            TestChildWidget(),
          ],
        )
      : Container();
  }
}

class TestChildWidget extends StatelessWidget {
79
  const TestChildWidget({super.key});
80 81 82 83 84 85

  @override
  Widget build(BuildContext context) {
    return Container();
  }
}