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

5
import 'package:flutter_devicelab/framework/devices.dart';
6
import 'package:flutter_devicelab/framework/framework.dart';
7
import 'package:flutter_devicelab/framework/task_result.dart';
8
import 'package:flutter_devicelab/tasks/gallery.dart';
9

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

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

40
    return TaskResult.success(data, benchmarkScoreKeys: benchmarkScoreKeys);
41 42
  });
}