debug_test.dart 3.45 KB
Newer Older
1 2 3 4 5 6 7 8
// Copyright 2015 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.

import 'package:flutter/rendering.dart';
import 'package:test/test.dart';
import 'package:vector_math/vector_math_64.dart';

9
import 'mock_canvas.dart';
10
import 'rendering_tester.dart';
11

12
void main() {
13
  test('Describe transform control test', () {
14 15
    final Matrix4 identity = new Matrix4.identity();
    final List<String> description = debugDescribeTransform(identity);
16 17 18 19 20 21 22
    expect(description, equals(<String>[
      '  [0] 1.0,0.0,0.0,0.0',
      '  [1] 0.0,1.0,0.0,0.0',
      '  [2] 0.0,0.0,1.0,0.0',
      '  [3] 0.0,0.0,0.0,1.0',
    ]));
  });
23 24 25 26 27 28 29 30 31 32 33 34

  test('debugPaintPadding', () {
    expect((Canvas canvas) {
      debugPaintPadding(canvas, new Rect.fromLTRB(10.0, 10.0, 20.0, 20.0), null);
    }, paints..rect(color: debugPaintSpacingColor));
    expect((Canvas canvas) {
      debugPaintPadding(canvas, new Rect.fromLTRB(10.0, 10.0, 20.0, 20.0), new Rect.fromLTRB(11.0, 11.0, 19.0, 19.0));
    }, paints..path(color: debugPaintPaddingColor)..path(color: debugPaintPaddingInnerEdgeColor));
    expect((Canvas canvas) {
      debugPaintPadding(canvas, new Rect.fromLTRB(10.0, 10.0, 20.0, 20.0), new Rect.fromLTRB(15.0, 15.0, 15.0, 15.0));
    }, paints..rect(rect: new Rect.fromLTRB(10.0, 10.0, 20.0, 20.0), color: debugPaintSpacingColor));
  });
Ian Hickson's avatar
Ian Hickson committed
35 36 37 38 39

  test('debugPaintPadding from render objects', () {
    debugPaintSizeEnabled = true;
    RenderSliver s;
    RenderBox b;
40
    final RenderViewport root = new RenderViewport(
Ian Hickson's avatar
Ian Hickson committed
41 42 43
      offset: new ViewportOffset.zero(),
      children: <RenderSliver>[
        s = new RenderSliverPadding(
44
          padding: const EdgeInsets.all(10.0),
Ian Hickson's avatar
Ian Hickson committed
45 46
          child: new RenderSliverToBoxAdapter(
            child: b = new RenderPadding(
47
              padding: const EdgeInsets.all(10.0),
Ian Hickson's avatar
Ian Hickson committed
48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64
            ),
          ),
        ),
      ],
    );
    layout(root);
    expect(b.debugPaint, paints..rect(color: debugPaintSizeColor)..rect(color: debugPaintSpacingColor));
    expect(b.debugPaint, isNot(paints..path()));
    expect(s.debugPaint, paints..circle(hasMaskFilter: true)..line(hasMaskFilter: true)..path(hasMaskFilter: true)..path(hasMaskFilter: true)
                               ..path(color: debugPaintPaddingColor)..path(color: debugPaintPaddingInnerEdgeColor));
    expect(s.debugPaint, isNot(paints..rect()));
    debugPaintSizeEnabled = false;
  });

  test('debugPaintPadding from render objects', () {
    debugPaintSizeEnabled = true;
    RenderSliver s;
65
    final RenderBox b = new RenderPadding(
66
      padding: const EdgeInsets.all(10.0),
Adam Barth's avatar
Adam Barth committed
67
      child: new RenderViewport(
Ian Hickson's avatar
Ian Hickson committed
68 69 70
        offset: new ViewportOffset.zero(),
        children: <RenderSliver>[
          s = new RenderSliverPadding(
71
            padding: const EdgeInsets.all(10.0),
Ian Hickson's avatar
Ian Hickson committed
72 73 74 75 76 77 78 79 80 81 82 83
          ),
        ],
      ),
    );
    layout(b);
    expect(s.debugPaint, paints..rect(color: debugPaintSpacingColor));
    expect(s.debugPaint, isNot(paints..circle(hasMaskFilter: true)..line(hasMaskFilter: true)..path(hasMaskFilter: true)..path(hasMaskFilter: true)
                                     ..path(color: debugPaintPaddingColor)..path(color: debugPaintPaddingInnerEdgeColor)));
    expect(b.debugPaint, paints..rect(color: debugPaintSizeColor)..path(color: debugPaintPaddingColor)..path(color: debugPaintPaddingInnerEdgeColor));
    expect(b.debugPaint, isNot(paints..rect(color: debugPaintSpacingColor)));
    debugPaintSizeEnabled = false;
  });
84
}