obscured_animated_image_test.dart 1.78 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
// 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';

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

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

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

36
    Navigator.pushNamed(imageKey.currentContext!, '/page');
37 38 39 40 41
    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.
42
    final ui.Image? image3 = renderImage.image;
43
    await tester.pump(const Duration(milliseconds: 100));
44
    final ui.Image? image4 = renderImage.image;
45 46 47
    expect(image3, same(image4));
  });
}