|
| 1 | +// Copyright 2013 The Flutter Authors. All rights reserved. |
| 2 | +// Use of this source code is governed by a BSD-style license that can be |
| 3 | +// found in the LICENSE file. |
| 4 | + |
| 5 | +import 'package:test/bootstrap/browser.dart'; |
| 6 | +import 'package:test/test.dart'; |
| 7 | +import 'package:ui/src/engine.dart'; |
| 8 | +import 'package:ui/ui.dart'; |
| 9 | + |
| 10 | +// TODO(yjbanov): https://github.com/flutter/flutter/issues/76885 |
| 11 | +const bool issue76885Exists = true; |
| 12 | + |
| 13 | +void main() { |
| 14 | + internalBootstrapBrowserTest(() => testMain); |
| 15 | +} |
| 16 | + |
| 17 | +void testMain() { |
| 18 | + test('PathRef.getRRect with radius', () { |
| 19 | + final SurfacePath path = SurfacePath(); |
| 20 | + final RRect rrect = RRect.fromLTRBR(0, 0, 10, 10, const Radius.circular(2)); |
| 21 | + path.addRRect(rrect); |
| 22 | + expect(path.toRoundedRect(), rrect); |
| 23 | + }); |
| 24 | + |
| 25 | + test('PathRef.getRRect with radius larger than rect', () { |
| 26 | + final SurfacePath path = SurfacePath(); |
| 27 | + final RRect rrect = RRect.fromLTRBR(0, 0, 10, 10, const Radius.circular(20)); |
| 28 | + path.addRRect(rrect); |
| 29 | + expect( |
| 30 | + path.toRoundedRect(), |
| 31 | + // Path.addRRect will correct the radius to fit the dimensions, so when |
| 32 | + // extracting the rrect out of the path we don't get the original. |
| 33 | + RRect.fromLTRBR(0, 0, 10, 10, const Radius.circular(5)), |
| 34 | + ); |
| 35 | + }); |
| 36 | + |
| 37 | + test('PathRef.getRRect with zero radius', () { |
| 38 | + final SurfacePath path = SurfacePath(); |
| 39 | + final RRect rrect = RRect.fromLTRBR(0, 0, 10, 10, const Radius.circular(0)); |
| 40 | + path.addRRect(rrect); |
| 41 | + expect(path.toRoundedRect(), isNull); |
| 42 | + expect(path.toRect(), rrect.outerRect); |
| 43 | + }); |
| 44 | + |
| 45 | + test('PathRef.getRRect elliptical', () { |
| 46 | + final SurfacePath path = SurfacePath(); |
| 47 | + final RRect rrect = RRect.fromLTRBR(0, 0, 10, 10, const Radius.elliptical(2, 4)); |
| 48 | + path.addRRect(rrect); |
| 49 | + expect(path.toRoundedRect(), rrect); |
| 50 | + }); |
| 51 | + |
| 52 | + test('PathRef.getRRect elliptical zero x', () { |
| 53 | + final SurfacePath path = SurfacePath(); |
| 54 | + final RRect rrect = RRect.fromLTRBR(0, 0, 10, 10, const Radius.elliptical(0, 3)); |
| 55 | + path.addRRect(rrect); |
| 56 | + expect(path.toRoundedRect(), isNull); |
| 57 | + expect(path.toRect(), rrect.outerRect); |
| 58 | + }); |
| 59 | + |
| 60 | + test('PathRef.getRRect elliptical zero y', () { |
| 61 | + final SurfacePath path = SurfacePath(); |
| 62 | + final RRect rrect = RRect.fromLTRBR(0, 0, 10, 10, const Radius.elliptical(3, 0)); |
| 63 | + path.addRRect(rrect); |
| 64 | + expect(path.toRoundedRect(), isNull); |
| 65 | + expect(path.toRect(), rrect.outerRect); |
| 66 | + }); |
| 67 | + |
| 68 | + // This test demonstrates the issue with attempting to reconstruct an RRect |
| 69 | + // with imprecision introduced by comparing double values. We should fix this |
| 70 | + // by removing the need to reconstruct rrects: |
| 71 | + // https://github.com/flutter/flutter/issues/76885 |
| 72 | + test('PathRef.getRRect with nearly zero corner', () { |
| 73 | + final SurfacePath path = SurfacePath(); |
| 74 | + final RRect original = RRect.fromLTRBR(0, 0, 10, 10, const Radius.elliptical(0.00000001, 5)); |
| 75 | + path.addRRect(original); |
| 76 | + expect(path.toRoundedRect(), original); |
| 77 | + }, skip: issue76885Exists); |
| 78 | +} |
0 commit comments