texture_test.dart 4.82 KB
Newer Older
1 2 3 4 5 6
// Copyright 2014 The Flutter 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:flutter/widgets.dart';
7
import 'package:flutter_test/flutter_test.dart';
8 9

void main() {
10 11
  testWidgets('Texture with freeze set to true', (WidgetTester tester) async {
    await tester.pumpWidget(
12
        const Center(child: Texture(textureId: 1, freeze: true)),
13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37
    );

    final Texture texture = tester.firstWidget(find.byType(Texture));
    expect(texture, isNotNull);
    expect(texture.textureId, 1);
    expect(texture.freeze, true);

    final RenderObject renderObject = tester.firstRenderObject(find.byType(Texture));
    expect(renderObject, isNotNull);
    final TextureBox textureBox = renderObject as TextureBox;
    expect(textureBox, isNotNull);
    expect(textureBox.textureId, 1);
    expect(textureBox.freeze, true);

    final ContainerLayer containerLayer = ContainerLayer();
    final PaintingContext paintingContext = PaintingContext(containerLayer, Rect.zero);
    textureBox.paint(paintingContext, Offset.zero);
    final Layer layer = containerLayer.lastChild!;
    expect(layer, isNotNull);
    final TextureLayer textureLayer = layer as TextureLayer;
    expect(textureLayer, isNotNull);
    expect(textureLayer.textureId, 1);
    expect(textureLayer.freeze, true);
  });

38 39
  testWidgets('Texture with default FilterQuality', (WidgetTester tester) async {
    await tester.pumpWidget(
40
        const Center(child: Texture(textureId: 1)),
41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57
    );

    final Texture texture = tester.firstWidget(find.byType(Texture));
    expect(texture, isNotNull);
    expect(texture.textureId, 1);
    expect(texture.filterQuality, FilterQuality.low);

    final RenderObject renderObject = tester.firstRenderObject(find.byType(Texture));
    expect(renderObject, isNotNull);
    final TextureBox textureBox = renderObject as TextureBox;
    expect(textureBox, isNotNull);
    expect(textureBox.textureId, 1);
    expect(textureBox.filterQuality, FilterQuality.low);

    final ContainerLayer containerLayer = ContainerLayer();
    final PaintingContext paintingContext = PaintingContext(containerLayer, Rect.zero);
    textureBox.paint(paintingContext, Offset.zero);
58
    final Layer layer = containerLayer.lastChild!;
59 60 61 62 63 64 65 66 67 68
    expect(layer, isNotNull);
    final TextureLayer textureLayer = layer as TextureLayer;
    expect(textureLayer, isNotNull);
    expect(textureLayer.textureId, 1);
    expect(textureLayer.filterQuality, FilterQuality.low);
  });


  testWidgets('Texture with FilterQuality.none', (WidgetTester tester) async {
    await tester.pumpWidget(
69
        const Center(child: Texture(textureId: 1, filterQuality: FilterQuality.none)),
70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86
    );

    final Texture texture = tester.firstWidget(find.byType(Texture));
    expect(texture, isNotNull);
    expect(texture.textureId, 1);
    expect(texture.filterQuality, FilterQuality.none);

    final RenderObject renderObject = tester.firstRenderObject(find.byType(Texture));
    expect(renderObject, isNotNull);
    final TextureBox textureBox = renderObject as TextureBox;
    expect(textureBox, isNotNull);
    expect(textureBox.textureId, 1);
    expect(textureBox.filterQuality, FilterQuality.none);

    final ContainerLayer containerLayer = ContainerLayer();
    final PaintingContext paintingContext = PaintingContext(containerLayer, Rect.zero);
    textureBox.paint(paintingContext, Offset.zero);
87
    final Layer layer = containerLayer.lastChild!;
88 89 90 91 92 93 94 95 96
    expect(layer, isNotNull);
    final TextureLayer textureLayer = layer as TextureLayer;
    expect(textureLayer, isNotNull);
    expect(textureLayer.textureId, 1);
    expect(textureLayer.filterQuality, FilterQuality.none);
  });

  testWidgets('Texture with FilterQuality.low', (WidgetTester tester) async {
    await tester.pumpWidget(
97
        const Center(child: Texture(textureId: 1)),
98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114
    );

    final Texture texture = tester.firstWidget(find.byType(Texture));
    expect(texture, isNotNull);
    expect(texture.textureId, 1);
    expect(texture.filterQuality, FilterQuality.low);

    final RenderObject renderObject = tester.firstRenderObject(find.byType(Texture));
    expect(renderObject, isNotNull);
    final TextureBox textureBox = renderObject as TextureBox;
    expect(textureBox, isNotNull);
    expect(textureBox.textureId, 1);
    expect(textureBox.filterQuality, FilterQuality.low);

    final ContainerLayer containerLayer = ContainerLayer();
    final PaintingContext paintingContext = PaintingContext(containerLayer, Rect.zero);
    textureBox.paint(paintingContext, Offset.zero);
115
    final Layer layer = containerLayer.lastChild!;
116 117 118 119 120 121 122
    expect(layer, isNotNull);
    final TextureLayer textureLayer = layer as TextureLayer;
    expect(textureLayer, isNotNull);
    expect(textureLayer.textureId, 1);
    expect(textureLayer.filterQuality, FilterQuality.low);
  });
}