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

import 'dart:typed_data';
import 'dart:ui' as ui show Image;

import 'package:flutter/material.dart';
import 'package:flutter/rendering.dart';
import 'package:flutter_test/flutter_test.dart';
11
import 'package:leak_tracker_flutter_testing/leak_tracker_flutter_testing.dart';
12

13
import '../image_data.dart';
14 15
import '../painting/fake_codec.dart';
import '../painting/fake_image_provider.dart';
16

17
Future<void> main() async {
18 19
  final FakeCodec fakeCodec = await FakeCodec.fromData(Uint8List.fromList(kAnimatedGif));
  final FakeImageProvider fakeImageProvider = FakeImageProvider(fakeCodec);
20

21
  testWidgetsWithLeakTracking('Obscured image does not animate', (WidgetTester tester) async {
22
    final GlobalKey imageKey = GlobalKey();
23
    await tester.pumpWidget(
24 25
      MaterialApp(
        home: Image(image: fakeImageProvider, excludeFromSemantics: true, key: imageKey),
26
        routes: <String, WidgetBuilder>{
27 28
          '/page': (BuildContext context) => Container(),
        },
29
      ),
30 31
    );
    final RenderImage renderImage = tester.renderObject(find.byType(Image));
32
    final ui.Image? image1 = renderImage.image;
33
    await tester.pump(const Duration(milliseconds: 100));
34
    final ui.Image? image2 = renderImage.image;
35 36
    expect(image1, isNot(same(image2)));

37
    Navigator.pushNamed(imageKey.currentContext!, '/page');
38 39 40 41 42
    await tester.pump(); // Starts the page animation.
    await tester.pump(const Duration(seconds: 1)); // Let the page animation complete.

    // The image is now obscured by another page, it should not be changing
    // frames.
43
    final ui.Image? image3 = renderImage.image;
44
    await tester.pump(const Duration(milliseconds: 100));
45
    final ui.Image? image4 = renderImage.image;
46 47 48
    expect(image3, same(image4));
  });
}