image_rtl_test.dart 24.1 KB
Newer Older
Ian Hickson's avatar
Ian Hickson committed
1 2 3 4 5
// Copyright 2017 The Chromium 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 'dart:async';
6
import 'dart:typed_data';
7
import 'dart:ui' as ui show Image, ImageByteFormat;
Ian Hickson's avatar
Ian Hickson committed
8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28

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> {
  @override
  Future<TestImageProvider> obtainKey(ImageConfiguration configuration) {
    return new SynchronousFuture<TestImageProvider>(this);
  }

  @override
  ImageStreamCompleter load(TestImageProvider key) {
    return new OneFrameImageStreamCompleter(
      new SynchronousFuture<ImageInfo>(new ImageInfo(image: new TestImage()))
    );
  }
}

29
class TestImage implements ui.Image {
Ian Hickson's avatar
Ian Hickson committed
30 31 32 33 34 35
  @override
  int get width => 16;

  @override
  int get height => 9;

36 37
  @override
  void dispose() { }
38 39

  @override
40
  Future<ByteData> toByteData({ui.ImageByteFormat format}) async {
41 42
    throw new UnsupportedError('Cannot encode test image');
  }
Ian Hickson's avatar
Ian Hickson committed
43 44 45 46 47 48 49 50 51 52 53 54 55 56
}

void main() {
  testWidgets('DecorationImage RTL with alignment topEnd and match', (WidgetTester tester) async {
    await tester.pumpWidget(
      new Directionality(
        textDirection: TextDirection.rtl,
        child: new Center(
          child: new Container(
            width: 100.0,
            height: 50.0,
            decoration: new BoxDecoration(
              image: new DecorationImage(
                image: new TestImageProvider(),
57
                alignment: AlignmentDirectional.topEnd,
Ian Hickson's avatar
Ian Hickson committed
58 59 60 61 62 63 64
                repeat: ImageRepeat.repeatX,
                matchTextDirection: true,
              ),
            ),
          ),
        ),
      ),
65
      Duration.zero,
Ian Hickson's avatar
Ian Hickson committed
66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95
      EnginePhase.layout, // so that we don't try to paint the fake images
    );
    expect(find.byType(Container), paints
      ..clipRect(rect: new Rect.fromLTRB(0.0, 0.0, 100.0, 50.0))
      ..translate(x: 50.0, y: 0.0)
      ..scale(x: -1.0, y: 1.0)
      ..translate(x: -50.0, y: 0.0)
      ..drawImageRect(source: new Rect.fromLTRB(0.0, 0.0, 16.0, 9.0), destination: new Rect.fromLTRB(-12.0, 0.0, 4.0, 9.0))
      ..drawImageRect(source: new Rect.fromLTRB(0.0, 0.0, 16.0, 9.0), destination: new Rect.fromLTRB(4.0, 0.0, 20.0, 9.0))
      ..drawImageRect(source: new Rect.fromLTRB(0.0, 0.0, 16.0, 9.0), destination: new Rect.fromLTRB(20.0, 0.0, 36.0, 9.0))
      ..drawImageRect(source: new Rect.fromLTRB(0.0, 0.0, 16.0, 9.0), destination: new Rect.fromLTRB(36.0, 0.0, 52.0, 9.0))
      ..drawImageRect(source: new Rect.fromLTRB(0.0, 0.0, 16.0, 9.0), destination: new Rect.fromLTRB(52.0, 0.0, 68.0, 9.0))
      ..drawImageRect(source: new Rect.fromLTRB(0.0, 0.0, 16.0, 9.0), destination: new Rect.fromLTRB(68.0, 0.0, 84.0, 9.0))
      ..drawImageRect(source: new Rect.fromLTRB(0.0, 0.0, 16.0, 9.0), destination: new Rect.fromLTRB(84.0, 0.0, 100.0, 9.0))
      ..restore()
    );
    expect(find.byType(Container), isNot(paints..scale()..scale()));
  });

  testWidgets('DecorationImage LTR with alignment topEnd (and pointless match)', (WidgetTester tester) async {
    await tester.pumpWidget(
      new Directionality(
        textDirection: TextDirection.ltr,
        child: new Center(
          child: new Container(
            width: 100.0,
            height: 50.0,
            decoration: new BoxDecoration(
              image: new DecorationImage(
                image: new TestImageProvider(),
96
                alignment: AlignmentDirectional.topEnd,
Ian Hickson's avatar
Ian Hickson committed
97 98 99 100 101 102 103
                repeat: ImageRepeat.repeatX,
                matchTextDirection: true,
              ),
            ),
          ),
        ),
      ),
104
      Duration.zero,
Ian Hickson's avatar
Ian Hickson committed
105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131
      EnginePhase.layout, // so that we don't try to paint the fake images
    );
    expect(find.byType(Container), paints
      ..clipRect(rect: new Rect.fromLTRB(0.0, 0.0, 100.0, 50.0))
      ..drawImageRect(source: new Rect.fromLTRB(0.0, 0.0, 16.0, 9.0), destination: new Rect.fromLTRB(-12.0, 0.0, 4.0, 9.0))
      ..drawImageRect(source: new Rect.fromLTRB(0.0, 0.0, 16.0, 9.0), destination: new Rect.fromLTRB(4.0, 0.0, 20.0, 9.0))
      ..drawImageRect(source: new Rect.fromLTRB(0.0, 0.0, 16.0, 9.0), destination: new Rect.fromLTRB(20.0, 0.0, 36.0, 9.0))
      ..drawImageRect(source: new Rect.fromLTRB(0.0, 0.0, 16.0, 9.0), destination: new Rect.fromLTRB(36.0, 0.0, 52.0, 9.0))
      ..drawImageRect(source: new Rect.fromLTRB(0.0, 0.0, 16.0, 9.0), destination: new Rect.fromLTRB(52.0, 0.0, 68.0, 9.0))
      ..drawImageRect(source: new Rect.fromLTRB(0.0, 0.0, 16.0, 9.0), destination: new Rect.fromLTRB(68.0, 0.0, 84.0, 9.0))
      ..drawImageRect(source: new Rect.fromLTRB(0.0, 0.0, 16.0, 9.0), destination: new Rect.fromLTRB(84.0, 0.0, 100.0, 9.0))
      ..restore()
    );
    expect(find.byType(Container), isNot(paints..scale()));
  });

  testWidgets('DecorationImage RTL with alignment topEnd', (WidgetTester tester) async {
    await tester.pumpWidget(
      new Directionality(
        textDirection: TextDirection.rtl,
        child: new Center(
          child: new Container(
            width: 100.0,
            height: 50.0,
            decoration: new BoxDecoration(
              image: new DecorationImage(
                image: new TestImageProvider(),
132
                alignment: AlignmentDirectional.topEnd,
Ian Hickson's avatar
Ian Hickson committed
133 134 135 136 137 138
                repeat: ImageRepeat.repeatX,
              ),
            ),
          ),
        ),
      ),
139
      Duration.zero,
Ian Hickson's avatar
Ian Hickson committed
140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166
      EnginePhase.layout, // so that we don't try to paint the fake images
    );
    expect(find.byType(Container), paints
      ..clipRect(rect: new Rect.fromLTRB(0.0, 0.0, 100.0, 50.0))
      ..drawImageRect(source: new Rect.fromLTRB(0.0, 0.0, 16.0, 9.0), destination: new Rect.fromLTRB(0.0, 0.0, 16.0, 9.0))
      ..drawImageRect(source: new Rect.fromLTRB(0.0, 0.0, 16.0, 9.0), destination: new Rect.fromLTRB(16.0, 0.0, 32.0, 9.0))
      ..drawImageRect(source: new Rect.fromLTRB(0.0, 0.0, 16.0, 9.0), destination: new Rect.fromLTRB(32.0, 0.0, 48.0, 9.0))
      ..drawImageRect(source: new Rect.fromLTRB(0.0, 0.0, 16.0, 9.0), destination: new Rect.fromLTRB(48.0, 0.0, 64.0, 9.0))
      ..drawImageRect(source: new Rect.fromLTRB(0.0, 0.0, 16.0, 9.0), destination: new Rect.fromLTRB(64.0, 0.0, 80.0, 9.0))
      ..drawImageRect(source: new Rect.fromLTRB(0.0, 0.0, 16.0, 9.0), destination: new Rect.fromLTRB(80.0, 0.0, 96.0, 9.0))
      ..drawImageRect(source: new Rect.fromLTRB(0.0, 0.0, 16.0, 9.0), destination: new Rect.fromLTRB(96.0, 0.0, 112.0, 9.0))
      ..restore()
    );
    expect(find.byType(Container), isNot(paints..scale()));
  });

  testWidgets('DecorationImage LTR with alignment topEnd', (WidgetTester tester) async {
    await tester.pumpWidget(
      new Directionality(
        textDirection: TextDirection.ltr,
        child: new Center(
          child: new Container(
            width: 100.0,
            height: 50.0,
            decoration: new BoxDecoration(
              image: new DecorationImage(
                image: new TestImageProvider(),
167
                alignment: AlignmentDirectional.topEnd,
Ian Hickson's avatar
Ian Hickson committed
168 169 170 171 172 173
                repeat: ImageRepeat.repeatX,
              ),
            ),
          ),
        ),
      ),
174
      Duration.zero,
Ian Hickson's avatar
Ian Hickson committed
175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201
      EnginePhase.layout, // so that we don't try to paint the fake images
    );
    expect(find.byType(Container), paints
      ..clipRect(rect: new Rect.fromLTRB(0.0, 0.0, 100.0, 50.0))
      ..drawImageRect(source: new Rect.fromLTRB(0.0, 0.0, 16.0, 9.0), destination: new Rect.fromLTRB(-12.0, 0.0, 4.0, 9.0))
      ..drawImageRect(source: new Rect.fromLTRB(0.0, 0.0, 16.0, 9.0), destination: new Rect.fromLTRB(4.0, 0.0, 20.0, 9.0))
      ..drawImageRect(source: new Rect.fromLTRB(0.0, 0.0, 16.0, 9.0), destination: new Rect.fromLTRB(20.0, 0.0, 36.0, 9.0))
      ..drawImageRect(source: new Rect.fromLTRB(0.0, 0.0, 16.0, 9.0), destination: new Rect.fromLTRB(36.0, 0.0, 52.0, 9.0))
      ..drawImageRect(source: new Rect.fromLTRB(0.0, 0.0, 16.0, 9.0), destination: new Rect.fromLTRB(52.0, 0.0, 68.0, 9.0))
      ..drawImageRect(source: new Rect.fromLTRB(0.0, 0.0, 16.0, 9.0), destination: new Rect.fromLTRB(68.0, 0.0, 84.0, 9.0))
      ..drawImageRect(source: new Rect.fromLTRB(0.0, 0.0, 16.0, 9.0), destination: new Rect.fromLTRB(84.0, 0.0, 100.0, 9.0))
      ..restore()
    );
    expect(find.byType(Container), isNot(paints..scale()));
  });

  testWidgets('DecorationImage RTL with alignment center-right and match', (WidgetTester tester) async {
    await tester.pumpWidget(
      new Directionality(
        textDirection: TextDirection.rtl,
        child: new Center(
          child: new Container(
            width: 100.0,
            height: 50.0,
            decoration: new BoxDecoration(
              image: new DecorationImage(
                image: new TestImageProvider(),
202
                alignment: Alignment.centerRight,
Ian Hickson's avatar
Ian Hickson committed
203 204 205 206 207 208
                matchTextDirection: true,
              ),
            ),
          ),
        ),
      ),
209
      Duration.zero,
Ian Hickson's avatar
Ian Hickson committed
210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233
      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)
      ..drawImageRect(source: new Rect.fromLTRB(0.0, 0.0, 16.0, 9.0), destination: new Rect.fromLTRB(0.0, 20.5, 16.0, 29.5))
      ..restore()
    );
    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(
      new Directionality(
        textDirection: TextDirection.rtl,
        child: new Center(
          child: new Container(
            width: 100.0,
            height: 50.0,
            decoration: new BoxDecoration(
              image: new DecorationImage(
                image: new TestImageProvider(),
234
                alignment: Alignment.centerRight,
Ian Hickson's avatar
Ian Hickson committed
235 236 237 238 239
              ),
            ),
          ),
        ),
      ),
240
      Duration.zero,
Ian Hickson's avatar
Ian Hickson committed
241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260
      EnginePhase.layout, // so that we don't try to paint the fake images
    );
    expect(find.byType(Container), paints
      ..drawImageRect(source: new Rect.fromLTRB(0.0, 0.0, 16.0, 9.0), destination: new Rect.fromLTRB(84.0, 20.5, 100.0, 29.5))
    );
    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(
      new Directionality(
        textDirection: TextDirection.ltr,
        child: new Center(
          child: new Container(
            width: 100.0,
            height: 50.0,
            decoration: new BoxDecoration(
              image: new DecorationImage(
                image: new TestImageProvider(),
261
                alignment: Alignment.centerRight,
Ian Hickson's avatar
Ian Hickson committed
262 263 264 265 266 267
                matchTextDirection: true
              ),
            ),
          ),
        ),
      ),
268
      Duration.zero,
Ian Hickson's avatar
Ian Hickson committed
269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288
      EnginePhase.layout, // so that we don't try to paint the fake images
    );
    expect(find.byType(Container), paints
      ..drawImageRect(source: new Rect.fromLTRB(0.0, 0.0, 16.0, 9.0), destination: new Rect.fromLTRB(84.0, 20.5, 100.0, 29.5))
    );
    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(
      new Directionality(
        textDirection: TextDirection.ltr,
        child: new Center(
          child: new Container(
            width: 100.0,
            height: 50.0,
            decoration: new BoxDecoration(
              image: new DecorationImage(
                image: new TestImageProvider(),
289
                alignment: Alignment.centerRight,
Ian Hickson's avatar
Ian Hickson committed
290 291 292 293 294 295
                matchTextDirection: true
              ),
            ),
          ),
        ),
      ),
296
      Duration.zero,
Ian Hickson's avatar
Ian Hickson committed
297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315
      EnginePhase.layout, // so that we don't try to paint the fake images
    );
    expect(find.byType(Container), paints
      ..drawImageRect(source: new Rect.fromLTRB(0.0, 0.0, 16.0, 9.0), destination: new Rect.fromLTRB(84.0, 20.5, 100.0, 29.5))
    );
    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(
      new Directionality(
        textDirection: TextDirection.rtl,
        child: new Center(
          child: new Container(
            width: 100.0,
            height: 50.0,
            child: new Image(
              image: new TestImageProvider(),
316
              alignment: AlignmentDirectional.topEnd,
Ian Hickson's avatar
Ian Hickson committed
317 318 319 320 321 322
              repeat: ImageRepeat.repeatX,
              matchTextDirection: true,
            ),
          ),
        ),
      ),
323
      Duration.zero,
Ian Hickson's avatar
Ian Hickson committed
324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352
      EnginePhase.layout, // so that we don't try to paint the fake images
    );
    expect(find.byType(Container), paints
      ..clipRect(rect: new Rect.fromLTRB(0.0, 0.0, 100.0, 50.0))
      ..translate(x: 50.0, y: 0.0)
      ..scale(x: -1.0, y: 1.0)
      ..translate(x: -50.0, y: 0.0)
      ..drawImageRect(source: new Rect.fromLTRB(0.0, 0.0, 16.0, 9.0), destination: new Rect.fromLTRB(-12.0, 0.0, 4.0, 9.0))
      ..drawImageRect(source: new Rect.fromLTRB(0.0, 0.0, 16.0, 9.0), destination: new Rect.fromLTRB(4.0, 0.0, 20.0, 9.0))
      ..drawImageRect(source: new Rect.fromLTRB(0.0, 0.0, 16.0, 9.0), destination: new Rect.fromLTRB(20.0, 0.0, 36.0, 9.0))
      ..drawImageRect(source: new Rect.fromLTRB(0.0, 0.0, 16.0, 9.0), destination: new Rect.fromLTRB(36.0, 0.0, 52.0, 9.0))
      ..drawImageRect(source: new Rect.fromLTRB(0.0, 0.0, 16.0, 9.0), destination: new Rect.fromLTRB(52.0, 0.0, 68.0, 9.0))
      ..drawImageRect(source: new Rect.fromLTRB(0.0, 0.0, 16.0, 9.0), destination: new Rect.fromLTRB(68.0, 0.0, 84.0, 9.0))
      ..drawImageRect(source: new Rect.fromLTRB(0.0, 0.0, 16.0, 9.0), destination: new Rect.fromLTRB(84.0, 0.0, 100.0, 9.0))
      ..restore()
    );
    expect(find.byType(Container), isNot(paints..scale()..scale()));
  });

  testWidgets('Image LTR with alignment topEnd (and pointless match)', (WidgetTester tester) async {
    await tester.pumpWidget(
      new Directionality(
        textDirection: TextDirection.ltr,
        child: new Center(
          child: new Container(
            width: 100.0,
            height: 50.0,
            child: new Image(
              image: new TestImageProvider(),
353
              alignment: AlignmentDirectional.topEnd,
Ian Hickson's avatar
Ian Hickson committed
354 355 356 357 358 359
              repeat: ImageRepeat.repeatX,
              matchTextDirection: true,
            ),
          ),
        ),
      ),
360
      Duration.zero,
Ian Hickson's avatar
Ian Hickson committed
361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386
      EnginePhase.layout, // so that we don't try to paint the fake images
    );
    expect(find.byType(Container), paints
      ..clipRect(rect: new Rect.fromLTRB(0.0, 0.0, 100.0, 50.0))
      ..drawImageRect(source: new Rect.fromLTRB(0.0, 0.0, 16.0, 9.0), destination: new Rect.fromLTRB(-12.0, 0.0, 4.0, 9.0))
      ..drawImageRect(source: new Rect.fromLTRB(0.0, 0.0, 16.0, 9.0), destination: new Rect.fromLTRB(4.0, 0.0, 20.0, 9.0))
      ..drawImageRect(source: new Rect.fromLTRB(0.0, 0.0, 16.0, 9.0), destination: new Rect.fromLTRB(20.0, 0.0, 36.0, 9.0))
      ..drawImageRect(source: new Rect.fromLTRB(0.0, 0.0, 16.0, 9.0), destination: new Rect.fromLTRB(36.0, 0.0, 52.0, 9.0))
      ..drawImageRect(source: new Rect.fromLTRB(0.0, 0.0, 16.0, 9.0), destination: new Rect.fromLTRB(52.0, 0.0, 68.0, 9.0))
      ..drawImageRect(source: new Rect.fromLTRB(0.0, 0.0, 16.0, 9.0), destination: new Rect.fromLTRB(68.0, 0.0, 84.0, 9.0))
      ..drawImageRect(source: new Rect.fromLTRB(0.0, 0.0, 16.0, 9.0), destination: new Rect.fromLTRB(84.0, 0.0, 100.0, 9.0))
      ..restore()
    );
    expect(find.byType(Container), isNot(paints..scale()));
  });

  testWidgets('Image RTL with alignment topEnd', (WidgetTester tester) async {
    await tester.pumpWidget(
      new Directionality(
        textDirection: TextDirection.rtl,
        child: new Center(
          child: new Container(
            width: 100.0,
            height: 50.0,
            child: new Image(
              image: new TestImageProvider(),
387
              alignment: AlignmentDirectional.topEnd,
Ian Hickson's avatar
Ian Hickson committed
388 389 390 391 392
              repeat: ImageRepeat.repeatX,
            ),
          ),
        ),
      ),
393
      Duration.zero,
Ian Hickson's avatar
Ian Hickson committed
394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419
      EnginePhase.layout, // so that we don't try to paint the fake images
    );
    expect(find.byType(Container), paints
      ..clipRect(rect: new Rect.fromLTRB(0.0, 0.0, 100.0, 50.0))
      ..drawImageRect(source: new Rect.fromLTRB(0.0, 0.0, 16.0, 9.0), destination: new Rect.fromLTRB(0.0, 0.0, 16.0, 9.0))
      ..drawImageRect(source: new Rect.fromLTRB(0.0, 0.0, 16.0, 9.0), destination: new Rect.fromLTRB(16.0, 0.0, 32.0, 9.0))
      ..drawImageRect(source: new Rect.fromLTRB(0.0, 0.0, 16.0, 9.0), destination: new Rect.fromLTRB(32.0, 0.0, 48.0, 9.0))
      ..drawImageRect(source: new Rect.fromLTRB(0.0, 0.0, 16.0, 9.0), destination: new Rect.fromLTRB(48.0, 0.0, 64.0, 9.0))
      ..drawImageRect(source: new Rect.fromLTRB(0.0, 0.0, 16.0, 9.0), destination: new Rect.fromLTRB(64.0, 0.0, 80.0, 9.0))
      ..drawImageRect(source: new Rect.fromLTRB(0.0, 0.0, 16.0, 9.0), destination: new Rect.fromLTRB(80.0, 0.0, 96.0, 9.0))
      ..drawImageRect(source: new Rect.fromLTRB(0.0, 0.0, 16.0, 9.0), destination: new Rect.fromLTRB(96.0, 0.0, 112.0, 9.0))
      ..restore()
    );
    expect(find.byType(Container), isNot(paints..scale()));
  });

  testWidgets('Image LTR with alignment topEnd', (WidgetTester tester) async {
    await tester.pumpWidget(
      new Directionality(
        textDirection: TextDirection.ltr,
        child: new Center(
          child: new Container(
            width: 100.0,
            height: 50.0,
            child: new Image(
              image: new TestImageProvider(),
420
              alignment: AlignmentDirectional.topEnd,
Ian Hickson's avatar
Ian Hickson committed
421 422 423 424 425
              repeat: ImageRepeat.repeatX,
            ),
          ),
        ),
      ),
426
      Duration.zero,
Ian Hickson's avatar
Ian Hickson committed
427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452
      EnginePhase.layout, // so that we don't try to paint the fake images
    );
    expect(find.byType(Container), paints
      ..clipRect(rect: new Rect.fromLTRB(0.0, 0.0, 100.0, 50.0))
      ..drawImageRect(source: new Rect.fromLTRB(0.0, 0.0, 16.0, 9.0), destination: new Rect.fromLTRB(-12.0, 0.0, 4.0, 9.0))
      ..drawImageRect(source: new Rect.fromLTRB(0.0, 0.0, 16.0, 9.0), destination: new Rect.fromLTRB(4.0, 0.0, 20.0, 9.0))
      ..drawImageRect(source: new Rect.fromLTRB(0.0, 0.0, 16.0, 9.0), destination: new Rect.fromLTRB(20.0, 0.0, 36.0, 9.0))
      ..drawImageRect(source: new Rect.fromLTRB(0.0, 0.0, 16.0, 9.0), destination: new Rect.fromLTRB(36.0, 0.0, 52.0, 9.0))
      ..drawImageRect(source: new Rect.fromLTRB(0.0, 0.0, 16.0, 9.0), destination: new Rect.fromLTRB(52.0, 0.0, 68.0, 9.0))
      ..drawImageRect(source: new Rect.fromLTRB(0.0, 0.0, 16.0, 9.0), destination: new Rect.fromLTRB(68.0, 0.0, 84.0, 9.0))
      ..drawImageRect(source: new Rect.fromLTRB(0.0, 0.0, 16.0, 9.0), destination: new Rect.fromLTRB(84.0, 0.0, 100.0, 9.0))
      ..restore()
    );
    expect(find.byType(Container), isNot(paints..scale()));
  });

  testWidgets('Image RTL with alignment center-right and match', (WidgetTester tester) async {
    await tester.pumpWidget(
      new Directionality(
        textDirection: TextDirection.rtl,
        child: new Center(
          child: new Container(
            width: 100.0,
            height: 50.0,
            child: new Image(
              image: new TestImageProvider(),
453
              alignment: Alignment.centerRight,
Ian Hickson's avatar
Ian Hickson committed
454 455 456 457 458
              matchTextDirection: true,
            ),
          ),
        ),
      ),
459
      Duration.zero,
Ian Hickson's avatar
Ian Hickson committed
460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482
      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)
      ..drawImageRect(source: new Rect.fromLTRB(0.0, 0.0, 16.0, 9.0), destination: new Rect.fromLTRB(0.0, 20.5, 16.0, 29.5))
      ..restore()
    );
    expect(find.byType(Container), isNot(paints..scale()..scale()));
    expect(find.byType(Container), isNot(paints..drawImageRect()..drawImageRect()));
  });

  testWidgets('Image RTL with alignment center-right and no match', (WidgetTester tester) async {
    await tester.pumpWidget(
      new Directionality(
        textDirection: TextDirection.rtl,
        child: new Center(
          child: new Container(
            width: 100.0,
            height: 50.0,
            child: new Image(
              image: new TestImageProvider(),
483
              alignment: Alignment.centerRight,
Ian Hickson's avatar
Ian Hickson committed
484 485 486 487
            ),
          ),
        ),
      ),
488
      Duration.zero,
Ian Hickson's avatar
Ian Hickson committed
489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507
      EnginePhase.layout, // so that we don't try to paint the fake images
    );
    expect(find.byType(Container), paints
      ..drawImageRect(source: new Rect.fromLTRB(0.0, 0.0, 16.0, 9.0), destination: new Rect.fromLTRB(84.0, 20.5, 100.0, 29.5))
    );
    expect(find.byType(Container), isNot(paints..scale()));
    expect(find.byType(Container), isNot(paints..drawImageRect()..drawImageRect()));
  });

  testWidgets('Image LTR with alignment center-right and match', (WidgetTester tester) async {
    await tester.pumpWidget(
      new Directionality(
        textDirection: TextDirection.ltr,
        child: new Center(
          child: new Container(
            width: 100.0,
            height: 50.0,
            child: new Image(
              image: new TestImageProvider(),
508
              alignment: Alignment.centerRight,
Ian Hickson's avatar
Ian Hickson committed
509 510 511 512 513
              matchTextDirection: true
            ),
          ),
        ),
      ),
514
      Duration.zero,
Ian Hickson's avatar
Ian Hickson committed
515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533
      EnginePhase.layout, // so that we don't try to paint the fake images
    );
    expect(find.byType(Container), paints
      ..drawImageRect(source: new Rect.fromLTRB(0.0, 0.0, 16.0, 9.0), destination: new Rect.fromLTRB(84.0, 20.5, 100.0, 29.5))
    );
    expect(find.byType(Container), isNot(paints..scale()));
    expect(find.byType(Container), isNot(paints..drawImageRect()..drawImageRect()));
  });

  testWidgets('Image LTR with alignment center-right and no match', (WidgetTester tester) async {
    await tester.pumpWidget(
      new Directionality(
        textDirection: TextDirection.ltr,
        child: new Center(
          child: new Container(
            width: 100.0,
            height: 50.0,
            child: new Image(
              image: new TestImageProvider(),
534
              alignment: Alignment.centerRight,
Ian Hickson's avatar
Ian Hickson committed
535 536 537 538 539
              matchTextDirection: true
            ),
          ),
        ),
      ),
540
      Duration.zero,
Ian Hickson's avatar
Ian Hickson committed
541 542 543 544 545 546 547 548 549 550 551 552 553 554 555
      EnginePhase.layout, // so that we don't try to paint the fake images
    );
    expect(find.byType(Container), paints
      ..drawImageRect(source: new Rect.fromLTRB(0.0, 0.0, 16.0, 9.0), destination: new Rect.fromLTRB(84.0, 20.5, 100.0, 29.5))
    );
    expect(find.byType(Container), isNot(paints..scale()));
    expect(find.byType(Container), isNot(paints..drawImageRect()..drawImageRect()));
  });

  testWidgets('Image - Switch needing direction', (WidgetTester tester) async {
    await tester.pumpWidget(
      new Directionality(
        textDirection: TextDirection.ltr,
        child: new Image(
          image: new TestImageProvider(),
556
          alignment: Alignment.centerRight,
Ian Hickson's avatar
Ian Hickson committed
557 558 559
          matchTextDirection: false,
        ),
      ),
560
      Duration.zero,
Ian Hickson's avatar
Ian Hickson committed
561 562 563 564 565 566 567
      EnginePhase.layout, // so that we don't try to paint the fake images
    );
    await tester.pumpWidget(
      new Directionality(
        textDirection: TextDirection.ltr,
        child: new Image(
          image: new TestImageProvider(),
568
          alignment: AlignmentDirectional.centerEnd,
Ian Hickson's avatar
Ian Hickson committed
569 570 571
          matchTextDirection: true,
        ),
      ),
572
      Duration.zero,
Ian Hickson's avatar
Ian Hickson committed
573 574 575 576 577 578 579
      EnginePhase.layout, // so that we don't try to paint the fake images
    );
    await tester.pumpWidget(
      new Directionality(
        textDirection: TextDirection.ltr,
        child: new Image(
          image: new TestImageProvider(),
580
          alignment: Alignment.centerRight,
Ian Hickson's avatar
Ian Hickson committed
581 582 583
          matchTextDirection: false,
        ),
      ),
584
      Duration.zero,
Ian Hickson's avatar
Ian Hickson committed
585 586 587
      EnginePhase.layout, // so that we don't try to paint the fake images
    );
  });
588
}