image_rtl_test.dart 23.8 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 10 11 12 13

import 'package:flutter/foundation.dart';
import 'package:flutter/widgets.dart';
import 'package:flutter_test/flutter_test.dart';

import '../rendering/mock_canvas.dart';

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

  final ui.Image image;

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

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

void main() {
32
  late ui.Image testImage;
33 34 35
  setUpAll(() async {
    testImage = await createTestImage(width: 16, height: 9);
  });
Ian Hickson's avatar
Ian Hickson committed
36 37
  testWidgets('DecorationImage RTL with alignment topEnd and match', (WidgetTester tester) async {
    await tester.pumpWidget(
38
      Directionality(
Ian Hickson's avatar
Ian Hickson committed
39
        textDirection: TextDirection.rtl,
40 41
        child: Center(
          child: Container(
Ian Hickson's avatar
Ian Hickson committed
42 43
            width: 100.0,
            height: 50.0,
44 45
            decoration: BoxDecoration(
              image: DecorationImage(
46
                image: TestImageProvider(testImage),
47
                alignment: AlignmentDirectional.topEnd,
Ian Hickson's avatar
Ian Hickson committed
48 49 50 51 52 53 54
                repeat: ImageRepeat.repeatX,
                matchTextDirection: true,
              ),
            ),
          ),
        ),
      ),
55
      Duration.zero,
Ian Hickson's avatar
Ian Hickson committed
56 57 58
      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
59
      ..clipRect(rect: const Rect.fromLTRB(0.0, 0.0, 100.0, 50.0))
Ian Hickson's avatar
Ian Hickson committed
60 61 62
      ..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
63 64 65 66 67 68 69
      ..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))
70
      ..restore(),
Ian Hickson's avatar
Ian Hickson committed
71 72 73 74 75 76
    );
    expect(find.byType(Container), isNot(paints..scale()..scale()));
  });

  testWidgets('DecorationImage LTR with alignment topEnd (and pointless match)', (WidgetTester tester) async {
    await tester.pumpWidget(
77
      Directionality(
Ian Hickson's avatar
Ian Hickson committed
78
        textDirection: TextDirection.ltr,
79 80
        child: Center(
          child: Container(
Ian Hickson's avatar
Ian Hickson committed
81 82
            width: 100.0,
            height: 50.0,
83 84
            decoration: BoxDecoration(
              image: DecorationImage(
85
                image: TestImageProvider(testImage),
86
                alignment: AlignmentDirectional.topEnd,
Ian Hickson's avatar
Ian Hickson committed
87 88 89 90 91 92 93
                repeat: ImageRepeat.repeatX,
                matchTextDirection: true,
              ),
            ),
          ),
        ),
      ),
94
      Duration.zero,
Ian Hickson's avatar
Ian Hickson committed
95 96 97
      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
98 99 100 101 102 103 104 105
      ..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))
106
      ..restore(),
Ian Hickson's avatar
Ian Hickson committed
107 108 109 110 111 112
    );
    expect(find.byType(Container), isNot(paints..scale()));
  });

  testWidgets('DecorationImage RTL with alignment topEnd', (WidgetTester tester) async {
    await tester.pumpWidget(
113
      Directionality(
Ian Hickson's avatar
Ian Hickson committed
114
        textDirection: TextDirection.rtl,
115 116
        child: Center(
          child: Container(
Ian Hickson's avatar
Ian Hickson committed
117 118
            width: 100.0,
            height: 50.0,
119 120
            decoration: BoxDecoration(
              image: DecorationImage(
121
                image: TestImageProvider(testImage),
122
                alignment: AlignmentDirectional.topEnd,
Ian Hickson's avatar
Ian Hickson committed
123 124 125 126 127 128
                repeat: ImageRepeat.repeatX,
              ),
            ),
          ),
        ),
      ),
129
      Duration.zero,
Ian Hickson's avatar
Ian Hickson committed
130 131 132
      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
133 134 135 136 137 138 139 140
      ..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))
141
      ..restore(),
Ian Hickson's avatar
Ian Hickson committed
142 143 144 145 146 147
    );
    expect(find.byType(Container), isNot(paints..scale()));
  });

  testWidgets('DecorationImage LTR with alignment topEnd', (WidgetTester tester) async {
    await tester.pumpWidget(
148
      Directionality(
Ian Hickson's avatar
Ian Hickson committed
149
        textDirection: TextDirection.ltr,
150 151
        child: Center(
          child: Container(
Ian Hickson's avatar
Ian Hickson committed
152 153
            width: 100.0,
            height: 50.0,
154 155
            decoration: BoxDecoration(
              image: DecorationImage(
156
                image: TestImageProvider(testImage),
157
                alignment: AlignmentDirectional.topEnd,
Ian Hickson's avatar
Ian Hickson committed
158 159 160 161 162 163
                repeat: ImageRepeat.repeatX,
              ),
            ),
          ),
        ),
      ),
164
      Duration.zero,
Ian Hickson's avatar
Ian Hickson committed
165 166 167
      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
168 169 170 171 172 173 174 175
      ..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))
176
      ..restore(),
Ian Hickson's avatar
Ian Hickson committed
177 178 179 180 181 182
    );
    expect(find.byType(Container), isNot(paints..scale()));
  });

  testWidgets('DecorationImage RTL with alignment center-right and match', (WidgetTester tester) async {
    await tester.pumpWidget(
183
      Directionality(
Ian Hickson's avatar
Ian Hickson committed
184
        textDirection: TextDirection.rtl,
185 186
        child: Center(
          child: Container(
Ian Hickson's avatar
Ian Hickson committed
187 188
            width: 100.0,
            height: 50.0,
189 190
            decoration: BoxDecoration(
              image: DecorationImage(
191
                image: TestImageProvider(testImage),
192
                alignment: Alignment.centerRight,
Ian Hickson's avatar
Ian Hickson committed
193 194 195 196 197 198
                matchTextDirection: true,
              ),
            ),
          ),
        ),
      ),
199
      Duration.zero,
Ian Hickson's avatar
Ian Hickson committed
200 201 202 203 204 205
      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
206
      ..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))
207
      ..restore(),
Ian Hickson's avatar
Ian Hickson committed
208 209 210 211 212 213 214
    );
    expect(find.byType(Container), isNot(paints..scale()..scale()));
    expect(find.byType(Container), isNot(paints..drawImageRect()..drawImageRect()));
  });

  testWidgets('DecorationImage RTL with alignment center-right and no match', (WidgetTester tester) async {
    await tester.pumpWidget(
215
      Directionality(
Ian Hickson's avatar
Ian Hickson committed
216
        textDirection: TextDirection.rtl,
217 218
        child: Center(
          child: Container(
Ian Hickson's avatar
Ian Hickson committed
219 220
            width: 100.0,
            height: 50.0,
221 222
            decoration: BoxDecoration(
              image: DecorationImage(
223
                image: TestImageProvider(testImage),
224
                alignment: Alignment.centerRight,
Ian Hickson's avatar
Ian Hickson committed
225 226 227 228 229
              ),
            ),
          ),
        ),
      ),
230
      Duration.zero,
Ian Hickson's avatar
Ian Hickson committed
231 232 233
      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
234
      ..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
235 236 237 238 239 240 241
    );
    expect(find.byType(Container), isNot(paints..scale()));
    expect(find.byType(Container), isNot(paints..drawImageRect()..drawImageRect()));
  });

  testWidgets('DecorationImage LTR with alignment center-right and match', (WidgetTester tester) async {
    await tester.pumpWidget(
242
      Directionality(
Ian Hickson's avatar
Ian Hickson committed
243
        textDirection: TextDirection.ltr,
244 245
        child: Center(
          child: Container(
Ian Hickson's avatar
Ian Hickson committed
246 247
            width: 100.0,
            height: 50.0,
248 249
            decoration: BoxDecoration(
              image: DecorationImage(
250
                image: TestImageProvider(testImage),
251
                alignment: Alignment.centerRight,
252
                matchTextDirection: true,
Ian Hickson's avatar
Ian Hickson committed
253 254 255 256 257
              ),
            ),
          ),
        ),
      ),
258
      Duration.zero,
Ian Hickson's avatar
Ian Hickson committed
259 260 261
      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
262
      ..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
263 264 265 266 267 268 269
    );
    expect(find.byType(Container), isNot(paints..scale()));
    expect(find.byType(Container), isNot(paints..drawImageRect()..drawImageRect()));
  });

  testWidgets('DecorationImage LTR with alignment center-right and no match', (WidgetTester tester) async {
    await tester.pumpWidget(
270
      Directionality(
Ian Hickson's avatar
Ian Hickson committed
271
        textDirection: TextDirection.ltr,
272 273
        child: Center(
          child: Container(
Ian Hickson's avatar
Ian Hickson committed
274 275
            width: 100.0,
            height: 50.0,
276 277
            decoration: BoxDecoration(
              image: DecorationImage(
278
                image: TestImageProvider(testImage),
279
                alignment: Alignment.centerRight,
280
                matchTextDirection: true,
Ian Hickson's avatar
Ian Hickson committed
281 282 283 284 285
              ),
            ),
          ),
        ),
      ),
286
      Duration.zero,
Ian Hickson's avatar
Ian Hickson committed
287 288 289
      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
290
      ..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
291 292 293 294 295 296 297
    );
    expect(find.byType(Container), isNot(paints..scale()));
    expect(find.byType(Container), isNot(paints..drawImageRect()..drawImageRect()));
  });

  testWidgets('Image RTL with alignment topEnd and match', (WidgetTester tester) async {
    await tester.pumpWidget(
298
      Directionality(
Ian Hickson's avatar
Ian Hickson committed
299
        textDirection: TextDirection.rtl,
300
        child: Center(
301
          child: SizedBox(
Ian Hickson's avatar
Ian Hickson committed
302 303
            width: 100.0,
            height: 50.0,
304
            child: Image(
305
              image: TestImageProvider(testImage),
306
              alignment: AlignmentDirectional.topEnd,
Ian Hickson's avatar
Ian Hickson committed
307 308 309 310 311 312
              repeat: ImageRepeat.repeatX,
              matchTextDirection: true,
            ),
          ),
        ),
      ),
313
      Duration.zero,
Ian Hickson's avatar
Ian Hickson committed
314 315
      EnginePhase.layout, // so that we don't try to paint the fake images
    );
316
    expect(find.byType(SizedBox), paints
Dan Field's avatar
Dan Field committed
317
      ..clipRect(rect: const Rect.fromLTRB(0.0, 0.0, 100.0, 50.0))
Ian Hickson's avatar
Ian Hickson committed
318 319 320
      ..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
321 322 323 324 325 326 327
      ..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))
328
      ..restore(),
Ian Hickson's avatar
Ian Hickson committed
329
    );
330
    expect(find.byType(SizedBox), isNot(paints..scale()..scale()));
Ian Hickson's avatar
Ian Hickson committed
331 332 333 334
  });

  testWidgets('Image LTR with alignment topEnd (and pointless match)', (WidgetTester tester) async {
    await tester.pumpWidget(
335
      Directionality(
Ian Hickson's avatar
Ian Hickson committed
336
        textDirection: TextDirection.ltr,
337
        child: Center(
338
          child: SizedBox(
Ian Hickson's avatar
Ian Hickson committed
339 340
            width: 100.0,
            height: 50.0,
341
            child: Image(
342
              image: TestImageProvider(testImage),
343
              alignment: AlignmentDirectional.topEnd,
Ian Hickson's avatar
Ian Hickson committed
344 345 346 347 348 349
              repeat: ImageRepeat.repeatX,
              matchTextDirection: true,
            ),
          ),
        ),
      ),
350
      Duration.zero,
Ian Hickson's avatar
Ian Hickson committed
351 352
      EnginePhase.layout, // so that we don't try to paint the fake images
    );
353
    expect(find.byType(SizedBox), paints
Dan Field's avatar
Dan Field committed
354 355 356 357 358 359 360 361
      ..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))
362
      ..restore(),
Ian Hickson's avatar
Ian Hickson committed
363
    );
364
    expect(find.byType(SizedBox), isNot(paints..scale()));
Ian Hickson's avatar
Ian Hickson committed
365 366 367 368
  });

  testWidgets('Image RTL with alignment topEnd', (WidgetTester tester) async {
    await tester.pumpWidget(
369
      Directionality(
Ian Hickson's avatar
Ian Hickson committed
370
        textDirection: TextDirection.rtl,
371
        child: Center(
372
          child: SizedBox(
Ian Hickson's avatar
Ian Hickson committed
373 374
            width: 100.0,
            height: 50.0,
375
            child: Image(
376
              image: TestImageProvider(testImage),
377
              alignment: AlignmentDirectional.topEnd,
Ian Hickson's avatar
Ian Hickson committed
378 379 380 381 382
              repeat: ImageRepeat.repeatX,
            ),
          ),
        ),
      ),
383
      Duration.zero,
Ian Hickson's avatar
Ian Hickson committed
384 385
      EnginePhase.layout, // so that we don't try to paint the fake images
    );
386
    expect(find.byType(SizedBox), paints
Dan Field's avatar
Dan Field committed
387 388 389 390 391 392 393 394
      ..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))
395
      ..restore(),
Ian Hickson's avatar
Ian Hickson committed
396
    );
397
    expect(find.byType(SizedBox), isNot(paints..scale()));
Ian Hickson's avatar
Ian Hickson committed
398 399 400 401
  });

  testWidgets('Image LTR with alignment topEnd', (WidgetTester tester) async {
    await tester.pumpWidget(
402
      Directionality(
Ian Hickson's avatar
Ian Hickson committed
403
        textDirection: TextDirection.ltr,
404
        child: Center(
405
          child: SizedBox(
Ian Hickson's avatar
Ian Hickson committed
406 407
            width: 100.0,
            height: 50.0,
408
            child: Image(
409
              image: TestImageProvider(testImage),
410
              alignment: AlignmentDirectional.topEnd,
Ian Hickson's avatar
Ian Hickson committed
411 412 413 414 415
              repeat: ImageRepeat.repeatX,
            ),
          ),
        ),
      ),
416
      Duration.zero,
Ian Hickson's avatar
Ian Hickson committed
417 418
      EnginePhase.layout, // so that we don't try to paint the fake images
    );
419
    expect(find.byType(SizedBox), paints
Dan Field's avatar
Dan Field committed
420 421 422 423 424 425 426 427
      ..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))
428
      ..restore(),
Ian Hickson's avatar
Ian Hickson committed
429
    );
430
    expect(find.byType(SizedBox), isNot(paints..scale()));
Ian Hickson's avatar
Ian Hickson committed
431 432 433 434
  });

  testWidgets('Image RTL with alignment center-right and match', (WidgetTester tester) async {
    await tester.pumpWidget(
435
      Directionality(
Ian Hickson's avatar
Ian Hickson committed
436
        textDirection: TextDirection.rtl,
437
        child: Center(
438
          child: SizedBox(
Ian Hickson's avatar
Ian Hickson committed
439 440
            width: 100.0,
            height: 50.0,
441
            child: Image(
442
              image: TestImageProvider(testImage),
443
              alignment: Alignment.centerRight,
Ian Hickson's avatar
Ian Hickson committed
444 445 446 447 448 449
              matchTextDirection: true,
            ),
          ),
        ),
      ),
    );
450
    expect(find.byType(SizedBox), paints
Ian Hickson's avatar
Ian Hickson committed
451 452 453
      ..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
454
      ..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))
455
      ..restore(),
Ian Hickson's avatar
Ian Hickson committed
456
    );
457 458
    expect(find.byType(SizedBox), isNot(paints..scale()..scale()));
    expect(find.byType(SizedBox), isNot(paints..drawImageRect()..drawImageRect()));
Ian Hickson's avatar
Ian Hickson committed
459 460 461 462
  });

  testWidgets('Image RTL with alignment center-right and no match', (WidgetTester tester) async {
    await tester.pumpWidget(
463
      Directionality(
Ian Hickson's avatar
Ian Hickson committed
464
        textDirection: TextDirection.rtl,
465
        child: Center(
466
          child: SizedBox(
Ian Hickson's avatar
Ian Hickson committed
467 468
            width: 100.0,
            height: 50.0,
469
            child: Image(
470
              image: TestImageProvider(testImage),
471
              alignment: Alignment.centerRight,
Ian Hickson's avatar
Ian Hickson committed
472 473 474 475
            ),
          ),
        ),
      ),
476
      Duration.zero,
Ian Hickson's avatar
Ian Hickson committed
477 478
      EnginePhase.layout, // so that we don't try to paint the fake images
    );
479
    expect(find.byType(SizedBox), paints
Dan Field's avatar
Dan Field committed
480
      ..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
481
    );
482 483
    expect(find.byType(SizedBox), isNot(paints..scale()));
    expect(find.byType(SizedBox), isNot(paints..drawImageRect()..drawImageRect()));
Ian Hickson's avatar
Ian Hickson committed
484 485 486 487
  });

  testWidgets('Image LTR with alignment center-right and match', (WidgetTester tester) async {
    await tester.pumpWidget(
488
      Directionality(
Ian Hickson's avatar
Ian Hickson committed
489
        textDirection: TextDirection.ltr,
490
        child: Center(
491
          child: SizedBox(
Ian Hickson's avatar
Ian Hickson committed
492 493
            width: 100.0,
            height: 50.0,
494
            child: Image(
495
              image: TestImageProvider(testImage),
496
              alignment: Alignment.centerRight,
497
              matchTextDirection: true,
Ian Hickson's avatar
Ian Hickson committed
498 499 500 501
            ),
          ),
        ),
      ),
502
      Duration.zero,
Ian Hickson's avatar
Ian Hickson committed
503 504
      EnginePhase.layout, // so that we don't try to paint the fake images
    );
505
    expect(find.byType(SizedBox), paints
Dan Field's avatar
Dan Field committed
506
      ..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
507
    );
508 509
    expect(find.byType(SizedBox), isNot(paints..scale()));
    expect(find.byType(SizedBox), isNot(paints..drawImageRect()..drawImageRect()));
Ian Hickson's avatar
Ian Hickson committed
510 511 512 513
  });

  testWidgets('Image LTR with alignment center-right and no match', (WidgetTester tester) async {
    await tester.pumpWidget(
514
      Directionality(
Ian Hickson's avatar
Ian Hickson committed
515
        textDirection: TextDirection.ltr,
516
        child: Center(
517
          child: SizedBox(
Ian Hickson's avatar
Ian Hickson committed
518 519
            width: 100.0,
            height: 50.0,
520
            child: Image(
521
              image: TestImageProvider(testImage),
522
              alignment: Alignment.centerRight,
523
              matchTextDirection: true,
Ian Hickson's avatar
Ian Hickson committed
524 525 526 527
            ),
          ),
        ),
      ),
528
      Duration.zero,
Ian Hickson's avatar
Ian Hickson committed
529 530
      EnginePhase.layout, // so that we don't try to paint the fake images
    );
531
    expect(find.byType(SizedBox), paints
Dan Field's avatar
Dan Field committed
532
      ..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
533
    );
534 535
    expect(find.byType(SizedBox), isNot(paints..scale()));
    expect(find.byType(SizedBox), isNot(paints..drawImageRect()..drawImageRect()));
Ian Hickson's avatar
Ian Hickson committed
536 537 538 539
  });

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