semantics_perf_test.dart 1.59 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 15 16 17 18 19 20 21 22 23 24 25 26 27

void main() {
  group('semantics performance test', () {
    FlutterDriver driver;

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

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

    test('inital tree creation', () async {
      // 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 38 39
      if (semanticsEvents.length != 2)
        fail('Expected exactly two semantics events, got ${semanticsEvents.length}');
      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 44 45
    });
  });
}