shader_warm_up_test.dart 1.05 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 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36
// 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 {
  TestCanvas([this.invocations]);

  final List<Invocation> invocations;

  @override
  void noSuchMethod(Invocation invocation) {
    invocations?.add(invocation);
  }
}

void main() {
  test('DefaultShaderWarmUp has expected canvas invocations', () {
    final List<Invocation> invocations = <Invocation>[];
    final TestCanvas canvas = TestCanvas(invocations);
    const DefaultShaderWarmUp s = DefaultShaderWarmUp();
    s.warmUpOnCanvas(canvas);

    bool hasDrawRectAfterClipRRect = false;
    for (int i = 0; i < invocations.length - 1; i += 1) {
      if (invocations[i].memberName == #clipRRect && invocations[i + 1].memberName == #drawRect) {
        hasDrawRectAfterClipRRect = true;
        break;
      }
    }

    expect(hasDrawRectAfterClipRRect, true);
  });
}