timeline_test.dart 1.85 KB
Newer Older
1 2 3 4
// Copyright 2016 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

5
import 'package:flutter_driver/src/driver/timeline.dart';
6

7 8
import '../common.dart';

9 10 11
void main() {
  group('Timeline', () {
    test('parses JSON', () {
12
      final Timeline timeline = Timeline.fromJson(<String, dynamic>{
pq's avatar
pq committed
13 14
        'traceEvents': <Map<String, dynamic>>[
          <String, dynamic>{
15 16 17 18 19 20
            'name': 'test event',
            'cat': 'test category',
            'ph': 'B',
            'pid': 123,
            'tid': 234,
            'dur': 345,
21
            'tdur': 245,
22 23
            'ts': 456,
            'tts': 567,
pq's avatar
pq committed
24
            'args': <String, dynamic>{
25
              'arg1': true,
26
            },
27 28
          },
          // Tests that we don't choke on missing data
29 30
          <String, dynamic>{},
        ],
31 32 33 34
      });

      expect(timeline.events, hasLength(2));

35
      final TimelineEvent e1 = timeline.events[0];
36 37 38 39 40 41
      expect(e1.name, 'test event');
      expect(e1.category, 'test category');
      expect(e1.phase, 'B');
      expect(e1.processId, 123);
      expect(e1.threadId, 234);
      expect(e1.duration, const Duration(microseconds: 345));
42
      expect(e1.threadDuration, const Duration(microseconds: 245));
43 44
      expect(e1.timestampMicros, 456);
      expect(e1.threadTimestampMicros, 567);
45
      expect(e1.arguments, <String, dynamic>{'arg1': true});
46

47
      final TimelineEvent e2 = timeline.events[1];
48 49 50 51 52 53
      expect(e2.name, isNull);
      expect(e2.category, isNull);
      expect(e2.phase, isNull);
      expect(e2.processId, isNull);
      expect(e2.threadId, isNull);
      expect(e2.duration, isNull);
54
      expect(e2.threadDuration, isNull);
55 56 57 58 59 60
      expect(e2.timestampMicros, isNull);
      expect(e2.threadTimestampMicros, isNull);
      expect(e2.arguments, isNull);
    });
  });
}