image_rtl_test.dart 24.2 KB
Newer Older
Ian Hickson's avatar
Ian Hickson committed
1
// Copyright 2014 The Flutter Authors. All rights reserved.
Ian Hickson's avatar
Ian Hickson committed
2 3 4
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

5
import 'dart:ui' as ui show Image;
Ian Hickson's avatar
Ian Hickson committed
6 7 8 9

import 'package:flutter/foundation.dart';
import 'package:flutter/widgets.dart';
import 'package:flutter_test/flutter_test.dart';
10
import 'package:leak_tracker_flutter_testing/leak_tracker_flutter_testing.dart';
Ian Hickson's avatar
Ian Hickson committed
11 12

class TestImageProvider extends ImageProvider<TestImageProvider> {
13 14 15 16
  const TestImageProvider(this.image);

  final ui.Image image;

Ian Hickson's avatar
Ian Hickson committed
17 18
  @override
  Future<TestImageProvider> obtainKey(ImageConfiguration configuration) {
19
    return SynchronousFuture<TestImageProvider>(this);
Ian Hickson's avatar
Ian Hickson committed
20 21 22
  }

  @override
23
  ImageStreamCompleter loadImage(TestImageProvider key, ImageDecoderCallback decode) {
24
    return OneFrameImageStreamCompleter(
25
      SynchronousFuture<ImageInfo>(ImageInfo(image: image)),
Ian Hickson's avatar
Ian Hickson committed
26 27 28 29 30
    );
  }
}

void main() {
31
  late ui.Image testImage;
32

33 34 35
  setUpAll(() async {
    testImage = await createTestImage(width: 16, height: 9);
  });
36 37 38 39 40 41

  tearDownAll(() {
    testImage.dispose();
  });

  testWidgetsWithLeakTracking('DecorationImage RTL with alignment topEnd and match', (WidgetTester tester) async {
Ian Hickson's avatar
Ian Hickson committed
42
    await tester.pumpWidget(
43
      Directionality(
Ian Hickson's avatar
Ian Hickson committed
44
        textDirection: TextDirection.rtl,
45 46
        child: Center(
          child: Container(
Ian Hickson's avatar
Ian Hickson committed
47 48
            width: 100.0,
            height: 50.0,
49 50
            decoration: BoxDecoration(
              image: DecorationImage(
51
                image: TestImageProvider(testImage),
52
                alignment: AlignmentDirectional.topEnd,
Ian Hickson's avatar
Ian Hickson committed
53 54 55 56 57 58 59
                repeat: ImageRepeat.repeatX,
                matchTextDirection: true,
              ),
            ),
          ),
        ),
      ),
60
      Duration.zero,
Ian Hickson's avatar
Ian Hickson committed
61 62 63
      EnginePhase.layout, // so that we don't try to paint the fake images
    );
    expect(find.byType(Container), paints
64
      ..clipRect(rect: const Rect.fromLTRB(0.0, 0.0, 100.0, 50.0))
Ian Hickson's avatar
Ian Hickson committed
65 66 67
      ..translate(x: 50.0, y: 0.0)
      ..scale(x: -1.0, y: 1.0)
      ..translate(x: -50.0, y: 0.0)
68 69 70 71 72 73 74
      ..drawImageRect(source: const Rect.fromLTRB(0.0, 0.0, 16.0, 9.0), destination: const Rect.fromLTRB(-12.0, 0.0, 4.0, 9.0))
      ..drawImageRect(source: const Rect.fromLTRB(0.0, 0.0, 16.0, 9.0), destination: const Rect.fromLTRB(4.0, 0.0, 20.0, 9.0))
      ..drawImageRect(source: const Rect.fromLTRB(0.0, 0.0, 16.0, 9.0), destination: const Rect.fromLTRB(20.0, 0.0, 36.0, 9.0))
      ..drawImageRect(source: const Rect.fromLTRB(0.0, 0.0, 16.0, 9.0), destination: const Rect.fromLTRB(36.0, 0.0, 52.0, 9.0))
      ..drawImageRect(source: const Rect.fromLTRB(0.0, 0.0, 16.0, 9.0), destination: const Rect.fromLTRB(52.0, 0.0, 68.0, 9.0))
      ..drawImageRect(source: const Rect.fromLTRB(0.0, 0.0, 16.0, 9.0), destination: const Rect.fromLTRB(68.0, 0.0, 84.0, 9.0))
      ..drawImageRect(source: const Rect.fromLTRB(0.0, 0.0, 16.0, 9.0), destination: const Rect.fromLTRB(84.0, 0.0, 100.0, 9.0))
75
      ..restore(),
Ian Hickson's avatar
Ian Hickson committed
76 77 78 79
    );
    expect(find.byType(Container), isNot(paints..scale()..scale()));
  });

80
  testWidgetsWithLeakTracking('DecorationImage LTR with alignment topEnd (and pointless match)', (WidgetTester tester) async {
Ian Hickson's avatar
Ian Hickson committed
81
    await tester.pumpWidget(
82
      Directionality(
Ian Hickson's avatar
Ian Hickson committed
83
        textDirection: TextDirection.ltr,
84 85
        child: Center(
          child: Container(
Ian Hickson's avatar
Ian Hickson committed
86 87
            width: 100.0,
            height: 50.0,
88 89
            decoration: BoxDecoration(
              image: DecorationImage(
90
                image: TestImageProvider(testImage),
91
                alignment: AlignmentDirectional.topEnd,
Ian Hickson's avatar
Ian Hickson committed
92 93 94 95 96 97 98
                repeat: ImageRepeat.repeatX,
                matchTextDirection: true,
              ),
            ),
          ),
        ),
      ),
99
      Duration.zero,
Ian Hickson's avatar
Ian Hickson committed
100 101 102
      EnginePhase.layout, // so that we don't try to paint the fake images
    );
    expect(find.byType(Container), paints
103 104 105 106 107 108 109 110
      ..clipRect(rect: const Rect.fromLTRB(0.0, 0.0, 100.0, 50.0))
      ..drawImageRect(source: const Rect.fromLTRB(0.0, 0.0, 16.0, 9.0), destination: const Rect.fromLTRB(-12.0, 0.0, 4.0, 9.0))
      ..drawImageRect(source: const Rect.fromLTRB(0.0, 0.0, 16.0, 9.0), destination: const Rect.fromLTRB(4.0, 0.0, 20.0, 9.0))
      ..drawImageRect(source: const Rect.fromLTRB(0.0, 0.0, 16.0, 9.0), destination: const Rect.fromLTRB(20.0, 0.0, 36.0, 9.0))
      ..drawImageRect(source: const Rect.fromLTRB(0.0, 0.0, 16.0, 9.0), destination: const Rect.fromLTRB(36.0, 0.0, 52.0, 9.0))
      ..drawImageRect(source: const Rect.fromLTRB(0.0, 0.0, 16.0, 9.0), destination: const Rect.fromLTRB(52.0, 0.0, 68.0, 9.0))
      ..drawImageRect(source: const Rect.fromLTRB(0.0, 0.0, 16.0, 9.0), destination: const Rect.fromLTRB(68.0, 0.0, 84.0, 9.0))
      ..drawImageRect(source: const Rect.fromLTRB(0.0, 0.0, 16.0, 9.0), destination: const Rect.fromLTRB(84.0, 0.0, 100.0, 9.0))
111
      ..restore(),
Ian Hickson's avatar
Ian Hickson committed
112 113 114 115
    );
    expect(find.byType(Container), isNot(paints..scale()));
  });

116
  testWidgetsWithLeakTracking('DecorationImage RTL with alignment topEnd', (WidgetTester tester) async {
Ian Hickson's avatar
Ian Hickson committed
117
    await tester.pumpWidget(
118
      Directionality(
Ian Hickson's avatar
Ian Hickson committed
119
        textDirection: TextDirection.rtl,
120 121
        child: Center(
          child: Container(
Ian Hickson's avatar
Ian Hickson committed
122 123
            width: 100.0,
            height: 50.0,
124 125
            decoration: BoxDecoration(
              image: DecorationImage(
126
                image: TestImageProvider(testImage),
127
                alignment: AlignmentDirectional.topEnd,
Ian Hickson's avatar
Ian Hickson committed
128 129 130 131 132 133
                repeat: ImageRepeat.repeatX,
              ),
            ),
          ),
        ),
      ),
134
      Duration.zero,
Ian Hickson's avatar
Ian Hickson committed
135 136 137
      EnginePhase.layout, // so that we don't try to paint the fake images
    );
    expect(find.byType(Container), paints
138 139 140 141 142 143 144 145
      ..clipRect(rect: const Rect.fromLTRB(0.0, 0.0, 100.0, 50.0))
      ..drawImageRect(source: const Rect.fromLTRB(0.0, 0.0, 16.0, 9.0), destination: const Rect.fromLTRB(0.0, 0.0, 16.0, 9.0))
      ..drawImageRect(source: const Rect.fromLTRB(0.0, 0.0, 16.0, 9.0), destination: const Rect.fromLTRB(16.0, 0.0, 32.0, 9.0))
      ..drawImageRect(source: const Rect.fromLTRB(0.0, 0.0, 16.0, 9.0), destination: const Rect.fromLTRB(32.0, 0.0, 48.0, 9.0))
      ..drawImageRect(source: const Rect.fromLTRB(0.0, 0.0, 16.0, 9.0), destination: const Rect.fromLTRB(48.0, 0.0, 64.0, 9.0))
      ..drawImageRect(source: const Rect.fromLTRB(0.0, 0.0, 16.0, 9.0), destination: const Rect.fromLTRB(64.0, 0.0, 80.0, 9.0))
      ..drawImageRect(source: const Rect.fromLTRB(0.0, 0.0, 16.0, 9.0), destination: const Rect.fromLTRB(80.0, 0.0, 96.0, 9.0))
      ..drawImageRect(source: const Rect.fromLTRB(0.0, 0.0, 16.0, 9.0), destination: const Rect.fromLTRB(96.0, 0.0, 112.0, 9.0))
146
      ..restore(),
Ian Hickson's avatar
Ian Hickson committed
147 148 149 150
    );
    expect(find.byType(Container), isNot(paints..scale()));
  });

151
  testWidgetsWithLeakTracking('DecorationImage LTR with alignment topEnd', (WidgetTester tester) async {
Ian Hickson's avatar
Ian Hickson committed
152
    await tester.pumpWidget(
153
      Directionality(
Ian Hickson's avatar
Ian Hickson committed
154
        textDirection: TextDirection.ltr,
155 156
        child: Center(
          child: Container(
Ian Hickson's avatar
Ian Hickson committed
157 158
            width: 100.0,
            height: 50.0,
159 160
            decoration: BoxDecoration(
              image: DecorationImage(
161
                image: TestImageProvider(testImage),
162
                alignment: AlignmentDirectional.topEnd,
Ian Hickson's avatar
Ian Hickson committed
163 164 165 166 167 168
                repeat: ImageRepeat.repeatX,
              ),
            ),
          ),
        ),
      ),
169
      Duration.zero,
Ian Hickson's avatar
Ian Hickson committed
170 171 172
      EnginePhase.layout, // so that we don't try to paint the fake images
    );
    expect(find.byType(Container), paints
173 174 175 176 177 178 179 180
      ..clipRect(rect: const Rect.fromLTRB(0.0, 0.0, 100.0, 50.0))
      ..drawImageRect(source: const Rect.fromLTRB(0.0, 0.0, 16.0, 9.0), destination: const Rect.fromLTRB(-12.0, 0.0, 4.0, 9.0))
      ..drawImageRect(source: const Rect.fromLTRB(0.0, 0.0, 16.0, 9.0), destination: const Rect.fromLTRB(4.0, 0.0, 20.0, 9.0))
      ..drawImageRect(source: const Rect.fromLTRB(0.0, 0.0, 16.0, 9.0), destination: const Rect.fromLTRB(20.0, 0.0, 36.0, 9.0))
      ..drawImageRect(source: const Rect.fromLTRB(0.0, 0.0, 16.0, 9.0), destination: const Rect.fromLTRB(36.0, 0.0, 52.0, 9.0))
      ..drawImageRect(source: const Rect.fromLTRB(0.0, 0.0, 16.0, 9.0), destination: const Rect.fromLTRB(52.0, 0.0, 68.0, 9.0))
      ..drawImageRect(source: const Rect.fromLTRB(0.0, 0.0, 16.0, 9.0), destination: const Rect.fromLTRB(68.0, 0.0, 84.0, 9.0))
      ..drawImageRect(source: const Rect.fromLTRB(0.0, 0.0, 16.0, 9.0), destination: const Rect.fromLTRB(84.0, 0.0, 100.0, 9.0))
181
      ..restore(),
Ian Hickson's avatar
Ian Hickson committed
182 183 184 185
    );
    expect(find.byType(Container), isNot(paints..scale()));
  });

186
  testWidgetsWithLeakTracking('DecorationImage RTL with alignment center-right and match', (WidgetTester tester) async {
Ian Hickson's avatar
Ian Hickson committed
187
    await tester.pumpWidget(
188
      Directionality(
Ian Hickson's avatar
Ian Hickson committed
189
        textDirection: TextDirection.rtl,
190 191
        child: Center(
          child: Container(
Ian Hickson's avatar
Ian Hickson committed
192 193
            width: 100.0,
            height: 50.0,
194 195
            decoration: BoxDecoration(
              image: DecorationImage(
196
                image: TestImageProvider(testImage),
197
                alignment: Alignment.centerRight,
Ian Hickson's avatar
Ian Hickson committed
198 199 200 201 202 203
                matchTextDirection: true,
              ),
            ),
          ),
        ),
      ),
204
      Duration.zero,
Ian Hickson's avatar
Ian Hickson committed
205 206 207 208 209 210
      EnginePhase.layout, // so that we don't try to paint the fake images
    );
    expect(find.byType(Container), paints
      ..translate(x: 50.0, y: 0.0)
      ..scale(x: -1.0, y: 1.0)
      ..translate(x: -50.0, y: 0.0)
Dan Field's avatar
Dan Field committed
211
      ..drawImageRect(source: const Rect.fromLTRB(0.0, 0.0, 16.0, 9.0), destination: const Rect.fromLTRB(0.0, 20.5, 16.0, 29.5))
212
      ..restore(),
Ian Hickson's avatar
Ian Hickson committed
213 214 215 216 217
    );
    expect(find.byType(Container), isNot(paints..scale()..scale()));
    expect(find.byType(Container), isNot(paints..drawImageRect()..drawImageRect()));
  });

218
  testWidgetsWithLeakTracking('DecorationImage RTL with alignment center-right and no match', (WidgetTester tester) async {
Ian Hickson's avatar
Ian Hickson committed
219
    await tester.pumpWidget(
220
      Directionality(
Ian Hickson's avatar
Ian Hickson committed
221
        textDirection: TextDirection.rtl,
222 223
        child: Center(
          child: Container(
Ian Hickson's avatar
Ian Hickson committed
224 225
            width: 100.0,
            height: 50.0,
226 227
            decoration: BoxDecoration(
              image: DecorationImage(
228
                image: TestImageProvider(testImage),
229
                alignment: Alignment.centerRight,
Ian Hickson's avatar
Ian Hickson committed
230 231 232 233 234
              ),
            ),
          ),
        ),
      ),
235
      Duration.zero,
Ian Hickson's avatar
Ian Hickson committed
236 237 238
      EnginePhase.layout, // so that we don't try to paint the fake images
    );
    expect(find.byType(Container), paints
Dan Field's avatar
Dan Field committed
239
      ..drawImageRect(source: const Rect.fromLTRB(0.0, 0.0, 16.0, 9.0), destination: const Rect.fromLTRB(84.0, 20.5, 100.0, 29.5)),
Ian Hickson's avatar
Ian Hickson committed
240 241 242 243 244
    );
    expect(find.byType(Container), isNot(paints..scale()));
    expect(find.byType(Container), isNot(paints..drawImageRect()..drawImageRect()));
  });

245
  testWidgetsWithLeakTracking('DecorationImage LTR with alignment center-right and match', (WidgetTester tester) async {
Ian Hickson's avatar
Ian Hickson committed
246
    await tester.pumpWidget(
247
      Directionality(
Ian Hickson's avatar
Ian Hickson committed
248
        textDirection: TextDirection.ltr,
249 250
        child: Center(
          child: Container(
Ian Hickson's avatar
Ian Hickson committed
251 252
            width: 100.0,
            height: 50.0,
253 254
            decoration: BoxDecoration(
              image: DecorationImage(
255
                image: TestImageProvider(testImage),
256
                alignment: Alignment.centerRight,
257
                matchTextDirection: true,
Ian Hickson's avatar
Ian Hickson committed
258 259 260 261 262
              ),
            ),
          ),
        ),
      ),
263
      Duration.zero,
Ian Hickson's avatar
Ian Hickson committed
264 265 266
      EnginePhase.layout, // so that we don't try to paint the fake images
    );
    expect(find.byType(Container), paints
Dan Field's avatar
Dan Field committed
267
      ..drawImageRect(source: const Rect.fromLTRB(0.0, 0.0, 16.0, 9.0), destination: const Rect.fromLTRB(84.0, 20.5, 100.0, 29.5)),
Ian Hickson's avatar
Ian Hickson committed
268 269 270 271 272
    );
    expect(find.byType(Container), isNot(paints..scale()));
    expect(find.byType(Container), isNot(paints..drawImageRect()..drawImageRect()));
  });

273
  testWidgetsWithLeakTracking('DecorationImage LTR with alignment center-right and no match', (WidgetTester tester) async {
Ian Hickson's avatar
Ian Hickson committed
274
    await tester.pumpWidget(
275
      Directionality(
Ian Hickson's avatar
Ian Hickson committed
276
        textDirection: TextDirection.ltr,
277 278
        child: Center(
          child: Container(
Ian Hickson's avatar
Ian Hickson committed
279 280
            width: 100.0,
            height: 50.0,
281 282
            decoration: BoxDecoration(
              image: DecorationImage(
283
                image: TestImageProvider(testImage),
284
                alignment: Alignment.centerRight,
285
                matchTextDirection: true,
Ian Hickson's avatar
Ian Hickson committed
286 287 288 289 290
              ),
            ),
          ),
        ),
      ),
291
      Duration.zero,
Ian Hickson's avatar
Ian Hickson committed
292 293 294
      EnginePhase.layout, // so that we don't try to paint the fake images
    );
    expect(find.byType(Container), paints
Dan Field's avatar
Dan Field committed
295
      ..drawImageRect(source: const Rect.fromLTRB(0.0, 0.0, 16.0, 9.0), destination: const Rect.fromLTRB(84.0, 20.5, 100.0, 29.5)),
Ian Hickson's avatar
Ian Hickson committed
296 297 298 299 300
    );
    expect(find.byType(Container), isNot(paints..scale()));
    expect(find.byType(Container), isNot(paints..drawImageRect()..drawImageRect()));
  });

301
  testWidgetsWithLeakTracking('Image RTL with alignment topEnd and match', (WidgetTester tester) async {
Ian Hickson's avatar
Ian Hickson committed
302
    await tester.pumpWidget(
303
      Directionality(
Ian Hickson's avatar
Ian Hickson committed
304
        textDirection: TextDirection.rtl,
305
        child: Center(
306
          child: SizedBox(
Ian Hickson's avatar
Ian Hickson committed
307 308
            width: 100.0,
            height: 50.0,
309
            child: Image(
310
              image: TestImageProvider(testImage),
311
              alignment: AlignmentDirectional.topEnd,
Ian Hickson's avatar
Ian Hickson committed
312 313 314 315 316 317
              repeat: ImageRepeat.repeatX,
              matchTextDirection: true,
            ),
          ),
        ),
      ),
318
      Duration.zero,
Ian Hickson's avatar
Ian Hickson committed
319 320
      EnginePhase.layout, // so that we don't try to paint the fake images
    );
321
    expect(find.byType(SizedBox), paints
322
      ..clipRect(rect: const Rect.fromLTRB(0.0, 0.0, 100.0, 50.0))
Ian Hickson's avatar
Ian Hickson committed
323 324 325
      ..translate(x: 50.0, y: 0.0)
      ..scale(x: -1.0, y: 1.0)
      ..translate(x: -50.0, y: 0.0)
326 327 328 329 330 331 332
      ..drawImageRect(source: const Rect.fromLTRB(0.0, 0.0, 16.0, 9.0), destination: const Rect.fromLTRB(-12.0, 0.0, 4.0, 9.0))
      ..drawImageRect(source: const Rect.fromLTRB(0.0, 0.0, 16.0, 9.0), destination: const Rect.fromLTRB(4.0, 0.0, 20.0, 9.0))
      ..drawImageRect(source: const Rect.fromLTRB(0.0, 0.0, 16.0, 9.0), destination: const Rect.fromLTRB(20.0, 0.0, 36.0, 9.0))
      ..drawImageRect(source: const Rect.fromLTRB(0.0, 0.0, 16.0, 9.0), destination: const Rect.fromLTRB(36.0, 0.0, 52.0, 9.0))
      ..drawImageRect(source: const Rect.fromLTRB(0.0, 0.0, 16.0, 9.0), destination: const Rect.fromLTRB(52.0, 0.0, 68.0, 9.0))
      ..drawImageRect(source: const Rect.fromLTRB(0.0, 0.0, 16.0, 9.0), destination: const Rect.fromLTRB(68.0, 0.0, 84.0, 9.0))
      ..drawImageRect(source: const Rect.fromLTRB(0.0, 0.0, 16.0, 9.0), destination: const Rect.fromLTRB(84.0, 0.0, 100.0, 9.0))
333
      ..restore(),
Ian Hickson's avatar
Ian Hickson committed
334
    );
335
    expect(find.byType(SizedBox), isNot(paints..scale()..scale()));
Ian Hickson's avatar
Ian Hickson committed
336 337
  });

338
  testWidgetsWithLeakTracking('Image LTR with alignment topEnd (and pointless match)', (WidgetTester tester) async {
Ian Hickson's avatar
Ian Hickson committed
339
    await tester.pumpWidget(
340
      Directionality(
Ian Hickson's avatar
Ian Hickson committed
341
        textDirection: TextDirection.ltr,
342
        child: Center(
343
          child: SizedBox(
Ian Hickson's avatar
Ian Hickson committed
344 345
            width: 100.0,
            height: 50.0,
346
            child: Image(
347
              image: TestImageProvider(testImage),
348
              alignment: AlignmentDirectional.topEnd,
Ian Hickson's avatar
Ian Hickson committed
349 350 351 352 353 354
              repeat: ImageRepeat.repeatX,
              matchTextDirection: true,
            ),
          ),
        ),
      ),
355
      Duration.zero,
Ian Hickson's avatar
Ian Hickson committed
356 357
      EnginePhase.layout, // so that we don't try to paint the fake images
    );
358
    expect(find.byType(SizedBox), paints
359 360 361 362 363 364 365 366
      ..clipRect(rect: const Rect.fromLTRB(0.0, 0.0, 100.0, 50.0))
      ..drawImageRect(source: const Rect.fromLTRB(0.0, 0.0, 16.0, 9.0), destination: const Rect.fromLTRB(-12.0, 0.0, 4.0, 9.0))
      ..drawImageRect(source: const Rect.fromLTRB(0.0, 0.0, 16.0, 9.0), destination: const Rect.fromLTRB(4.0, 0.0, 20.0, 9.0))
      ..drawImageRect(source: const Rect.fromLTRB(0.0, 0.0, 16.0, 9.0), destination: const Rect.fromLTRB(20.0, 0.0, 36.0, 9.0))
      ..drawImageRect(source: const Rect.fromLTRB(0.0, 0.0, 16.0, 9.0), destination: const Rect.fromLTRB(36.0, 0.0, 52.0, 9.0))
      ..drawImageRect(source: const Rect.fromLTRB(0.0, 0.0, 16.0, 9.0), destination: const Rect.fromLTRB(52.0, 0.0, 68.0, 9.0))
      ..drawImageRect(source: const Rect.fromLTRB(0.0, 0.0, 16.0, 9.0), destination: const Rect.fromLTRB(68.0, 0.0, 84.0, 9.0))
      ..drawImageRect(source: const Rect.fromLTRB(0.0, 0.0, 16.0, 9.0), destination: const Rect.fromLTRB(84.0, 0.0, 100.0, 9.0))
367
      ..restore(),
Ian Hickson's avatar
Ian Hickson committed
368
    );
369
    expect(find.byType(SizedBox), isNot(paints..scale()));
Ian Hickson's avatar
Ian Hickson committed
370 371
  });

372
  testWidgetsWithLeakTracking('Image RTL with alignment topEnd', (WidgetTester tester) async {
Ian Hickson's avatar
Ian Hickson committed
373
    await tester.pumpWidget(
374
      Directionality(
Ian Hickson's avatar
Ian Hickson committed
375
        textDirection: TextDirection.rtl,
376
        child: Center(
377
          child: SizedBox(
Ian Hickson's avatar
Ian Hickson committed
378 379
            width: 100.0,
            height: 50.0,
380
            child: Image(
381
              image: TestImageProvider(testImage),
382
              alignment: AlignmentDirectional.topEnd,
Ian Hickson's avatar
Ian Hickson committed
383 384 385 386 387
              repeat: ImageRepeat.repeatX,
            ),
          ),
        ),
      ),
388
      Duration.zero,
Ian Hickson's avatar
Ian Hickson committed
389 390
      EnginePhase.layout, // so that we don't try to paint the fake images
    );
391
    expect(find.byType(SizedBox), paints
392 393 394 395 396 397 398 399
      ..clipRect(rect: const Rect.fromLTRB(0.0, 0.0, 100.0, 50.0))
      ..drawImageRect(source: const Rect.fromLTRB(0.0, 0.0, 16.0, 9.0), destination: const Rect.fromLTRB(0.0, 0.0, 16.0, 9.0))
      ..drawImageRect(source: const Rect.fromLTRB(0.0, 0.0, 16.0, 9.0), destination: const Rect.fromLTRB(16.0, 0.0, 32.0, 9.0))
      ..drawImageRect(source: const Rect.fromLTRB(0.0, 0.0, 16.0, 9.0), destination: const Rect.fromLTRB(32.0, 0.0, 48.0, 9.0))
      ..drawImageRect(source: const Rect.fromLTRB(0.0, 0.0, 16.0, 9.0), destination: const Rect.fromLTRB(48.0, 0.0, 64.0, 9.0))
      ..drawImageRect(source: const Rect.fromLTRB(0.0, 0.0, 16.0, 9.0), destination: const Rect.fromLTRB(64.0, 0.0, 80.0, 9.0))
      ..drawImageRect(source: const Rect.fromLTRB(0.0, 0.0, 16.0, 9.0), destination: const Rect.fromLTRB(80.0, 0.0, 96.0, 9.0))
      ..drawImageRect(source: const Rect.fromLTRB(0.0, 0.0, 16.0, 9.0), destination: const Rect.fromLTRB(96.0, 0.0, 112.0, 9.0))
400
      ..restore(),
Ian Hickson's avatar
Ian Hickson committed
401
    );
402
    expect(find.byType(SizedBox), isNot(paints..scale()));
Ian Hickson's avatar
Ian Hickson committed
403 404
  });

405
  testWidgetsWithLeakTracking('Image LTR with alignment topEnd', (WidgetTester tester) async {
Ian Hickson's avatar
Ian Hickson committed
406
    await tester.pumpWidget(
407
      Directionality(
Ian Hickson's avatar
Ian Hickson committed
408
        textDirection: TextDirection.ltr,
409
        child: Center(
410
          child: SizedBox(
Ian Hickson's avatar
Ian Hickson committed
411 412
            width: 100.0,
            height: 50.0,
413
            child: Image(
414
              image: TestImageProvider(testImage),
415
              alignment: AlignmentDirectional.topEnd,
Ian Hickson's avatar
Ian Hickson committed
416 417 418 419 420
              repeat: ImageRepeat.repeatX,
            ),
          ),
        ),
      ),
421
      Duration.zero,
Ian Hickson's avatar
Ian Hickson committed
422 423
      EnginePhase.layout, // so that we don't try to paint the fake images
    );
424
    expect(find.byType(SizedBox), paints
425 426 427 428 429 430 431 432
      ..clipRect(rect: const Rect.fromLTRB(0.0, 0.0, 100.0, 50.0))
      ..drawImageRect(source: const Rect.fromLTRB(0.0, 0.0, 16.0, 9.0), destination: const Rect.fromLTRB(-12.0, 0.0, 4.0, 9.0))
      ..drawImageRect(source: const Rect.fromLTRB(0.0, 0.0, 16.0, 9.0), destination: const Rect.fromLTRB(4.0, 0.0, 20.0, 9.0))
      ..drawImageRect(source: const Rect.fromLTRB(0.0, 0.0, 16.0, 9.0), destination: const Rect.fromLTRB(20.0, 0.0, 36.0, 9.0))
      ..drawImageRect(source: const Rect.fromLTRB(0.0, 0.0, 16.0, 9.0), destination: const Rect.fromLTRB(36.0, 0.0, 52.0, 9.0))
      ..drawImageRect(source: const Rect.fromLTRB(0.0, 0.0, 16.0, 9.0), destination: const Rect.fromLTRB(52.0, 0.0, 68.0, 9.0))
      ..drawImageRect(source: const Rect.fromLTRB(0.0, 0.0, 16.0, 9.0), destination: const Rect.fromLTRB(68.0, 0.0, 84.0, 9.0))
      ..drawImageRect(source: const Rect.fromLTRB(0.0, 0.0, 16.0, 9.0), destination: const Rect.fromLTRB(84.0, 0.0, 100.0, 9.0))
433
      ..restore(),
Ian Hickson's avatar
Ian Hickson committed
434
    );
435
    expect(find.byType(SizedBox), isNot(paints..scale()));
Ian Hickson's avatar
Ian Hickson committed
436 437
  });

438
  testWidgetsWithLeakTracking('Image RTL with alignment center-right and match', (WidgetTester tester) async {
Ian Hickson's avatar
Ian Hickson committed
439
    await tester.pumpWidget(
440
      Directionality(
Ian Hickson's avatar
Ian Hickson committed
441
        textDirection: TextDirection.rtl,
442
        child: Center(
443
          child: SizedBox(
Ian Hickson's avatar
Ian Hickson committed
444 445
            width: 100.0,
            height: 50.0,
446
            child: Image(
447
              image: TestImageProvider(testImage),
448
              alignment: Alignment.centerRight,
Ian Hickson's avatar
Ian Hickson committed
449 450 451 452 453 454
              matchTextDirection: true,
            ),
          ),
        ),
      ),
    );
455
    expect(find.byType(SizedBox), paints
Ian Hickson's avatar
Ian Hickson committed
456 457 458
      ..translate(x: 50.0, y: 0.0)
      ..scale(x: -1.0, y: 1.0)
      ..translate(x: -50.0, y: 0.0)
Dan Field's avatar
Dan Field committed
459
      ..drawImageRect(source: const Rect.fromLTRB(0.0, 0.0, 16.0, 9.0), destination: const Rect.fromLTRB(0.0, 20.5, 16.0, 29.5))
460
      ..restore(),
Ian Hickson's avatar
Ian Hickson committed
461
    );
462 463
    expect(find.byType(SizedBox), isNot(paints..scale()..scale()));
    expect(find.byType(SizedBox), isNot(paints..drawImageRect()..drawImageRect()));
Ian Hickson's avatar
Ian Hickson committed
464 465
  });

466
  testWidgetsWithLeakTracking('Image RTL with alignment center-right and no match', (WidgetTester tester) async {
Ian Hickson's avatar
Ian Hickson committed
467
    await tester.pumpWidget(
468
      Directionality(
Ian Hickson's avatar
Ian Hickson committed
469
        textDirection: TextDirection.rtl,
470
        child: Center(
471
          child: SizedBox(
Ian Hickson's avatar
Ian Hickson committed
472 473
            width: 100.0,
            height: 50.0,
474
            child: Image(
475
              image: TestImageProvider(testImage),
476
              alignment: Alignment.centerRight,
Ian Hickson's avatar
Ian Hickson committed
477 478 479 480
            ),
          ),
        ),
      ),
481
      Duration.zero,
Ian Hickson's avatar
Ian Hickson committed
482 483
      EnginePhase.layout, // so that we don't try to paint the fake images
    );
484
    expect(find.byType(SizedBox), paints
Dan Field's avatar
Dan Field committed
485
      ..drawImageRect(source: const Rect.fromLTRB(0.0, 0.0, 16.0, 9.0), destination: const Rect.fromLTRB(84.0, 20.5, 100.0, 29.5)),
Ian Hickson's avatar
Ian Hickson committed
486
    );
487 488
    expect(find.byType(SizedBox), isNot(paints..scale()));
    expect(find.byType(SizedBox), isNot(paints..drawImageRect()..drawImageRect()));
Ian Hickson's avatar
Ian Hickson committed
489 490
  });

491
  testWidgetsWithLeakTracking('Image LTR with alignment center-right and match', (WidgetTester tester) async {
Ian Hickson's avatar
Ian Hickson committed
492
    await tester.pumpWidget(
493
      Directionality(
Ian Hickson's avatar
Ian Hickson committed
494
        textDirection: TextDirection.ltr,
495
        child: Center(
496
          child: SizedBox(
Ian Hickson's avatar
Ian Hickson committed
497 498
            width: 100.0,
            height: 50.0,
499
            child: Image(
500
              image: TestImageProvider(testImage),
501
              alignment: Alignment.centerRight,
502
              matchTextDirection: true,
Ian Hickson's avatar
Ian Hickson committed
503 504 505 506
            ),
          ),
        ),
      ),
507
      Duration.zero,
Ian Hickson's avatar
Ian Hickson committed
508 509
      EnginePhase.layout, // so that we don't try to paint the fake images
    );
510
    expect(find.byType(SizedBox), paints
Dan Field's avatar
Dan Field committed
511
      ..drawImageRect(source: const Rect.fromLTRB(0.0, 0.0, 16.0, 9.0), destination: const Rect.fromLTRB(84.0, 20.5, 100.0, 29.5)),
Ian Hickson's avatar
Ian Hickson committed
512
    );
513 514
    expect(find.byType(SizedBox), isNot(paints..scale()));
    expect(find.byType(SizedBox), isNot(paints..drawImageRect()..drawImageRect()));
Ian Hickson's avatar
Ian Hickson committed
515 516
  });

517
  testWidgetsWithLeakTracking('Image LTR with alignment center-right and no match', (WidgetTester tester) async {
Ian Hickson's avatar
Ian Hickson committed
518
    await tester.pumpWidget(
519
      Directionality(
Ian Hickson's avatar
Ian Hickson committed
520
        textDirection: TextDirection.ltr,
521
        child: Center(
522
          child: SizedBox(
Ian Hickson's avatar
Ian Hickson committed
523 524
            width: 100.0,
            height: 50.0,
525
            child: Image(
526
              image: TestImageProvider(testImage),
527
              alignment: Alignment.centerRight,
528
              matchTextDirection: true,
Ian Hickson's avatar
Ian Hickson committed
529 530 531 532
            ),
          ),
        ),
      ),
533
      Duration.zero,
Ian Hickson's avatar
Ian Hickson committed
534 535
      EnginePhase.layout, // so that we don't try to paint the fake images
    );
536
    expect(find.byType(SizedBox), paints
Dan Field's avatar
Dan Field committed
537
      ..drawImageRect(source: const Rect.fromLTRB(0.0, 0.0, 16.0, 9.0), destination: const Rect.fromLTRB(84.0, 20.5, 100.0, 29.5)),
Ian Hickson's avatar
Ian Hickson committed
538
    );
539 540
    expect(find.byType(SizedBox), isNot(paints..scale()));
    expect(find.byType(SizedBox), isNot(paints..drawImageRect()..drawImageRect()));
Ian Hickson's avatar
Ian Hickson committed
541 542
  });

543
  testWidgetsWithLeakTracking('Image - Switch needing direction', (WidgetTester tester) async {
Ian Hickson's avatar
Ian Hickson committed
544
    await tester.pumpWidget(
545
      Directionality(
Ian Hickson's avatar
Ian Hickson committed
546
        textDirection: TextDirection.ltr,
547
        child: Image(
548
          image: TestImageProvider(testImage),
549
          alignment: Alignment.centerRight,
Ian Hickson's avatar
Ian Hickson committed
550 551
        ),
      ),
552
      Duration.zero,
Ian Hickson's avatar
Ian Hickson committed
553 554 555
      EnginePhase.layout, // so that we don't try to paint the fake images
    );
    await tester.pumpWidget(
556
      Directionality(
Ian Hickson's avatar
Ian Hickson committed
557
        textDirection: TextDirection.ltr,
558
        child: Image(
559
          image: TestImageProvider(testImage),
560
          alignment: AlignmentDirectional.centerEnd,
Ian Hickson's avatar
Ian Hickson committed
561 562 563
          matchTextDirection: true,
        ),
      ),
564
      Duration.zero,
Ian Hickson's avatar
Ian Hickson committed
565 566 567
      EnginePhase.layout, // so that we don't try to paint the fake images
    );
    await tester.pumpWidget(
568
      Directionality(
Ian Hickson's avatar
Ian Hickson committed
569
        textDirection: TextDirection.ltr,
570
        child: Image(
571
          image: TestImageProvider(testImage),
572
          alignment: Alignment.centerRight,
Ian Hickson's avatar
Ian Hickson committed
573 574
        ),
      ),
575
      Duration.zero,
Ian Hickson's avatar
Ian Hickson committed
576 577 578
      EnginePhase.layout, // so that we don't try to paint the fake images
    );
  });
579
}