debug_test.dart 6.54 KB
Newer Older
1 2 3 4
// 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.

5
import 'package:flutter/foundation.dart';
6 7 8
import 'package:flutter/rendering.dart';
import 'package:vector_math/vector_math_64.dart';

9
import '../flutter_test_alternative.dart';
10
import 'mock_canvas.dart';
11
import 'rendering_tester.dart';
12

13
void main() {
14
  test('Describe transform control test', () {
15
    final Matrix4 identity = Matrix4.identity();
16
    final List<String> description = debugDescribeTransform(identity);
17
    expect(description, <String>[
18 19 20 21
      '[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',
22
    ]);
23
  });
24

25
  test('transform property test', () {
26 27
    final Matrix4 transform = Matrix4.diagonal3(Vector3.all(2.0));
    final TransformProperty simple = TransformProperty(
28 29 30 31
      'transform',
      transform,
    );
    expect(simple.name, equals('transform'));
32
    expect(simple.value, same(transform));
33
    expect(
34
      simple.toString(parentConfiguration: sparseTextConfiguration),
35 36
      equals(
        'transform:\n'
37 38 39 40
        '  [0] 2.0,0.0,0.0,0.0\n'
        '  [1] 0.0,2.0,0.0,0.0\n'
        '  [2] 0.0,0.0,2.0,0.0\n'
        '  [3] 0.0,0.0,0.0,1.0',
41 42
      ),
    );
43 44 45 46
    expect(
      simple.toString(parentConfiguration: singleLineTextConfiguration),
      equals('transform: [2.0,0.0,0.0,0.0; 0.0,2.0,0.0,0.0; 0.0,0.0,2.0,0.0; 0.0,0.0,0.0,1.0]'),
    );
47

48
    final TransformProperty nullProperty = TransformProperty(
49 50 51 52
      'transform',
      null,
    );
    expect(nullProperty.name, equals('transform'));
53
    expect(nullProperty.value, isNull);
54 55
    expect(nullProperty.toString(), equals('transform: null'));

56
    final TransformProperty hideNull = TransformProperty(
57 58 59 60
      'transform',
      null,
      defaultValue: null,
    );
61
    expect(hideNull.value, isNull);
62 63 64
    expect(hideNull.toString(), equals('transform: null'));
  });

65 66
  test('debugPaintPadding', () {
    expect((Canvas canvas) {
Dan Field's avatar
Dan Field committed
67
      debugPaintPadding(canvas, const Rect.fromLTRB(10.0, 10.0, 20.0, 20.0), null);
68
    }, paints..rect(color: const Color(0x90909090)));
69
    expect((Canvas canvas) {
Dan Field's avatar
Dan Field committed
70
      debugPaintPadding(canvas, const Rect.fromLTRB(10.0, 10.0, 20.0, 20.0), const Rect.fromLTRB(11.0, 11.0, 19.0, 19.0));
71
    }, paints..path(color: const Color(0x900090FF))..path(color: const Color(0xFF0090FF)));
72
    expect((Canvas canvas) {
Dan Field's avatar
Dan Field committed
73 74
      debugPaintPadding(canvas, const Rect.fromLTRB(10.0, 10.0, 20.0, 20.0), const Rect.fromLTRB(15.0, 15.0, 15.0, 15.0));
    }, paints..rect(rect: const Rect.fromLTRB(10.0, 10.0, 20.0, 20.0), color: const Color(0x90909090)));
75
  });
Ian Hickson's avatar
Ian Hickson committed
76 77 78 79 80

  test('debugPaintPadding from render objects', () {
    debugPaintSizeEnabled = true;
    RenderSliver s;
    RenderBox b;
81
    final RenderViewport root = RenderViewport(
82
      crossAxisDirection: AxisDirection.right,
83
      offset: ViewportOffset.zero(),
Ian Hickson's avatar
Ian Hickson committed
84
      children: <RenderSliver>[
85
        s = RenderSliverPadding(
86
          padding: const EdgeInsets.all(10.0),
87 88
          child: RenderSliverToBoxAdapter(
            child: b = RenderPadding(
89
              padding: const EdgeInsets.all(10.0),
Ian Hickson's avatar
Ian Hickson committed
90 91 92 93 94 95
            ),
          ),
        ),
      ],
    );
    layout(root);
96
    expect(b.debugPaint, paints..rect(color: const Color(0xFF00FFFF))..rect(color: const Color(0x90909090)));
Ian Hickson's avatar
Ian Hickson committed
97 98
    expect(b.debugPaint, isNot(paints..path()));
    expect(s.debugPaint, paints..circle(hasMaskFilter: true)..line(hasMaskFilter: true)..path(hasMaskFilter: true)..path(hasMaskFilter: true)
99
                               ..path(color: const Color(0x900090FF))..path(color: const Color(0xFF0090FF)));
Ian Hickson's avatar
Ian Hickson committed
100 101 102 103 104 105 106
    expect(s.debugPaint, isNot(paints..rect()));
    debugPaintSizeEnabled = false;
  });

  test('debugPaintPadding from render objects', () {
    debugPaintSizeEnabled = true;
    RenderSliver s;
107
    final RenderBox b = RenderPadding(
108
      padding: const EdgeInsets.all(10.0),
109
      child: RenderViewport(
110
        crossAxisDirection: AxisDirection.right,
111
        offset: ViewportOffset.zero(),
Ian Hickson's avatar
Ian Hickson committed
112
        children: <RenderSliver>[
113
          s = RenderSliverPadding(
114
            padding: const EdgeInsets.all(10.0),
Ian Hickson's avatar
Ian Hickson committed
115 116 117 118 119
          ),
        ],
      ),
    );
    layout(b);
120
    expect(s.debugPaint, paints..rect(color: const Color(0x90909090)));
Ian Hickson's avatar
Ian Hickson committed
121
    expect(s.debugPaint, isNot(paints..circle(hasMaskFilter: true)..line(hasMaskFilter: true)..path(hasMaskFilter: true)..path(hasMaskFilter: true)
122 123 124
                                     ..path(color: const Color(0x900090FF))..path(color: const Color(0xFF0090FF))));
    expect(b.debugPaint, paints..rect(color: const Color(0xFF00FFFF))..path(color: const Color(0x900090FF))..path(color: const Color(0xFF0090FF)));
    expect(b.debugPaint, isNot(paints..rect(color: const Color(0x90909090))));
Ian Hickson's avatar
Ian Hickson committed
125 126
    debugPaintSizeEnabled = false;
  });
127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192

  test('debugPaintPadding from render objects with inverted direction vertical', () {
    debugPaintSizeEnabled = true;
    RenderSliver s;
    final RenderViewport root = RenderViewport(
      axisDirection: AxisDirection.up,
      crossAxisDirection: AxisDirection.right,
      offset: ViewportOffset.zero(),
      children: <RenderSliver>[
        s = RenderSliverPadding(
          padding: const EdgeInsets.all(10.0),
          child: RenderSliverToBoxAdapter(
            child: RenderPadding(
              padding: const EdgeInsets.all(10.0),
            ),
          ),
        ),
      ],
    );
    layout(root);
    dynamic error;
    try {
      s.debugPaint(
        PaintingContext(
          ContainerLayer(), const Rect.fromLTRB(0.0, 0.0, 800.0, 600.0)),
        const Offset(0.0, 500)
      );
    } catch(e) {
      error = e;
    }
    expect(error, isNull);
    debugPaintSizeEnabled = false;
  });

  test('debugPaintPadding from render objects with inverted direction horizontal', () {
    debugPaintSizeEnabled = true;
    RenderSliver s;
    final RenderViewport root = RenderViewport(
      axisDirection: AxisDirection.left,
      crossAxisDirection: AxisDirection.down,
      offset: ViewportOffset.zero(),
      children: <RenderSliver>[
        s = RenderSliverPadding(
          padding: const EdgeInsets.all(10.0),
          child: RenderSliverToBoxAdapter(
            child: RenderPadding(
              padding: const EdgeInsets.all(10.0),
            ),
          ),
        ),
      ],
    );
    layout(root);
    dynamic error;
    try {
      s.debugPaint(
        PaintingContext(
          ContainerLayer(), const Rect.fromLTRB(0.0, 0.0, 800.0, 600.0)),
        const Offset(0.0, 500)
      );
    } catch(e) {
      error = e;
    }
    expect(error, isNull);
    debugPaintSizeEnabled = false;
  });
193
}