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

import 'package:flutter/painting.dart';
import 'package:flutter_test/flutter_test.dart';

class TestCanvas implements Canvas {
9
  TestCanvas();
10

11
  final List<Invocation> invocations = <Invocation>[];
12 13 14

  @override
  void noSuchMethod(Invocation invocation) {
15
    invocations.add(invocation);
16 17 18 19 20
  }
}

void main() {
  test('DefaultShaderWarmUp has expected canvas invocations', () {
21
    final TestCanvas canvas = TestCanvas();
22 23 24 25
    const DefaultShaderWarmUp s = DefaultShaderWarmUp();
    s.warmUpOnCanvas(canvas);

    bool hasDrawRectAfterClipRRect = false;
26 27
    for (int i = 0; i < canvas.invocations.length - 1; i += 1) {
      if (canvas.invocations[i].memberName == #clipRRect && canvas.invocations[i + 1].memberName == #drawRect) {
28 29 30 31 32 33 34 35
        hasDrawRectAfterClipRRect = true;
        break;
      }
    }

    expect(hasDrawRectAfterClipRRect, true);
  });
}