transitions_perf.dart 1.94 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 6
import 'dart:convert' show JsonEncoder;

7
import 'package:flutter_driver/driver_extension.dart';
8
import 'package:flutter_gallery/gallery/demos.dart';
9
import 'package:flutter_gallery/demo_lists.dart';
10
import 'package:flutter_gallery/gallery/app.dart' show GalleryApp;
11
import 'package:flutter_test/flutter_test.dart';
12
import 'package:flutter/material.dart';
13

14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45
import 'run_demos.dart';

// All of the gallery demos, identified as "title@category".
//
// These names are reported by the test app, see _handleMessages()
// in transitions_perf.dart.
List<String> _allDemos = kAllGalleryDemos.map(
  (GalleryDemo demo) => '${demo.title}@${demo.category.name}',
).toList();

Set<String> _unTestedDemos = Set<String>.from(_allDemos);

class _MessageHandler {
  static LiveWidgetController controller;
  Future<String> call(String message) async {
    switch(message) {
      case 'demoNames':
        return const JsonEncoder.withIndent('  ').convert(_allDemos);
      case 'profileDemos':
        controller ??= LiveWidgetController(WidgetsBinding.instance);
        await runDemos(kProfiledDemos, controller);
        _unTestedDemos.removeAll(kProfiledDemos);
        return const JsonEncoder.withIndent('  ').convert(kProfiledDemos);
      case 'restDemos':
        controller ??= LiveWidgetController(WidgetsBinding.instance);
        final List<String> restDemos =  _unTestedDemos.toList();
        await runDemos(restDemos, controller);
        return const JsonEncoder.withIndent('  ').convert(restDemos);
      default:
        throw ArgumentError;
    }
  }
46 47
}

48
void main() {
49
  enableFlutterDriverExtension(handler: _MessageHandler());
50 51 52
  // As in lib/main.dart: overriding https://github.com/flutter/flutter/issues/13736
  // for better visual effect at the cost of performance.
  runApp(const GalleryApp(testMode: true));
53
}