semantics_perf_test.dart 1.65 KB
Newer Older
Ian Hickson's avatar
Ian Hickson committed
1
// Copyright 2014 The Flutter Authors. All rights reserved.
2 3 4 5 6 7 8 9 10
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

import 'dart:async';
import 'dart:convert';
import 'dart:io';

import 'package:flutter_driver/flutter_driver.dart';
import 'package:path/path.dart' as p;
11
import 'package:test/test.dart' hide TypeMatcher, isInstanceOf;
12 13 14

void main() {
  group('semantics performance test', () {
15
    late FlutterDriver driver;
16 17 18 19 20 21 22 23 24 25

    setUpAll(() async {
      driver = await FlutterDriver.connect(printCommunication: true);
    });

    tearDownAll(() async {
      if (driver != null)
        driver.close();
    });

26
    test('initial tree creation', () async {
27
      // Let app become fully idle.
28
      await Future<void>.delayed(const Duration(seconds: 2));
29

30 31
      await driver.forceGC();

32 33 34 35
      final Timeline timeline = await driver.traceAction(() async {
        expect(await driver.setSemantics(true), isTrue);
      });

36
      final Iterable<TimelineEvent>? semanticsEvents = timeline.events?.where((TimelineEvent event) => event.name == 'SEMANTICS');
37
      if (semanticsEvents?.length != 2)
38
        fail('Expected exactly two "SEMANTICS" events, got ${semanticsEvents?.length}:\n$semanticsEvents');
39
      final Duration semanticsTreeCreation = Duration(microseconds: semanticsEvents!.last.timestampMicros! - semanticsEvents.first.timestampMicros!);
40

41
      final String jsonEncoded = json.encode(<String, dynamic>{'initialSemanticsTreeCreation': semanticsTreeCreation.inMilliseconds});
42
      File(p.join(testOutputsDirectory, 'complex_layout_semantics_perf.json')).writeAsStringSync(jsonEncoded);
43
    }, timeout: Timeout.none);
44 45
  });
}