flutter_gallery__transition_perf_with_semantics.dart 1.66 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
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

import 'package:flutter_devicelab/tasks/gallery.dart';
import 'package:flutter_devicelab/framework/adb.dart';
import 'package:flutter_devicelab/framework/framework.dart';
8
import 'package:flutter_devicelab/framework/task_result.dart';
9

10
Future<void> main() async {
11 12 13 14
  deviceOperatingSystem = DeviceOperatingSystem.android;
  await task(() async {
    final TaskResult withoutSemantics = await createGalleryTransitionTest()();
    final TaskResult withSemantics = await createGalleryTransitionTest(semanticsEnabled: true)();
15 16 17 18 19 20 21 22 23 24 25 26
    if (withSemantics.benchmarkScoreKeys.isEmpty || withoutSemantics.benchmarkScoreKeys.isEmpty) {
      String message = 'Lack of data';
      if (withSemantics.benchmarkScoreKeys.isEmpty) {
        message += ' for test with semantics';
        if (withoutSemantics.benchmarkScoreKeys.isEmpty) {
          message += ' and without semantics';
        }
      } else {
        message += 'for test without semantics';
      }
      return TaskResult.failure(message);
    }
27 28 29

    final List<String> benchmarkScoreKeys = <String>[];
    final Map<String, dynamic> data = <String, dynamic>{};
30
    for (final String key in withSemantics.benchmarkScoreKeys) {
31 32 33 34 35 36 37
      final String deltaKey = 'delta_$key';
      data[deltaKey] = withSemantics.data[key] - withoutSemantics.data[key];
      data['semantics_$key'] = withSemantics.data[key];
      data[key] = withoutSemantics.data[key];
      benchmarkScoreKeys.add(deltaKey);
    }

38
    return TaskResult.success(data, benchmarkScoreKeys: benchmarkScoreKeys);
39 40
  });
}