From 21f7afeb8b275412101043a97f217940928607dc Mon Sep 17 00:00:00 2001 From: Dan Field Date: Mon, 22 Apr 2019 15:46:51 -0700 Subject: [PATCH 1/3] Add tests from framework --- testing/dart/dart_test.dart | 26 +++++++++++++ testing/dart/paragraph_test.dart | 62 +++++++++++++++++++++++++++++++ testing/dart/rrect_test.dart | 47 +++++++++++++++++++++++ testing/dart/task_order_test.dart | 49 ++++++++++++++++++++++++ 4 files changed, 184 insertions(+) create mode 100644 testing/dart/dart_test.dart create mode 100644 testing/dart/paragraph_test.dart create mode 100644 testing/dart/rrect_test.dart create mode 100644 testing/dart/task_order_test.dart diff --git a/testing/dart/dart_test.dart b/testing/dart/dart_test.dart new file mode 100644 index 0000000000000..28b5618f7787f --- /dev/null +++ b/testing/dart/dart_test.dart @@ -0,0 +1,26 @@ +// Copyright 2013 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'; + +import 'package:test/test.dart' hide TypeMatcher, isInstanceOf; + +/// Verifies Dart semantics governed by flags set by Flutter tooling. +void main() { + group('Async', () { + String greeting = 'hello'; + Future changeGreeting() async { + greeting += ' 1'; + await Future.value(null); + greeting += ' 2'; + } + test('execution of async method starts synchronously', () async { + expect(greeting, 'hello'); + final Future future = changeGreeting(); + expect(greeting, 'hello 1'); + await future; + expect(greeting, 'hello 1 2'); + }); + }); +} diff --git a/testing/dart/paragraph_test.dart b/testing/dart/paragraph_test.dart new file mode 100644 index 0000000000000..06c62382af6e8 --- /dev/null +++ b/testing/dart/paragraph_test.dart @@ -0,0 +1,62 @@ +// Copyright 2018 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:ui'; + +import 'package:flutter_test/flutter_test.dart'; + +void main() { + // Ahem font uses a constant ideographic/alphabetic baseline ratio. + const double kAhemBaselineRatio = 1.25; + + test('predictably lays out a single-line paragraph', () { + for (double fontSize in [10.0, 20.0, 30.0, 40.0]) { + final ParagraphBuilder builder = ParagraphBuilder(ParagraphStyle( + fontFamily: 'Ahem', + fontStyle: FontStyle.normal, + fontWeight: FontWeight.normal, + fontSize: fontSize, + )); + builder.addText('Test'); + final Paragraph paragraph = builder.build(); + paragraph.layout(const ParagraphConstraints(width: 400.0)); + + expect(paragraph.height, closeTo(fontSize, 0.001)); + expect(paragraph.width, closeTo(400.0, 0.001)); + expect(paragraph.minIntrinsicWidth, closeTo(fontSize * 4.0, 0.001)); + expect(paragraph.maxIntrinsicWidth, closeTo(fontSize * 4.0, 0.001)); + expect(paragraph.alphabeticBaseline, closeTo(fontSize * .8, 0.001)); + expect( + paragraph.ideographicBaseline, + closeTo(paragraph.alphabeticBaseline * kAhemBaselineRatio, 0.001), + ); + } + }); + + test('predictably lays out a multi-line paragraph', () { + for (double fontSize in [10.0, 20.0, 30.0, 40.0]) { + final ParagraphBuilder builder = ParagraphBuilder(ParagraphStyle( + fontFamily: 'Ahem', + fontStyle: FontStyle.normal, + fontWeight: FontWeight.normal, + fontSize: fontSize, + )); + builder.addText('Test Ahem'); + final Paragraph paragraph = builder.build(); + paragraph.layout(ParagraphConstraints(width: fontSize * 5.0)); + + expect(paragraph.height, closeTo(fontSize * 2.0, 0.001)); // because it wraps + expect(paragraph.width, closeTo(fontSize * 5.0, 0.001)); + expect(paragraph.minIntrinsicWidth, closeTo(fontSize * 4.0, 0.001)); + + // TODO(yjbanov): see https://github.com/flutter/flutter/issues/21965 + expect(paragraph.maxIntrinsicWidth, closeTo(fontSize * 9.0, 0.001)); + expect(paragraph.alphabeticBaseline, closeTo(fontSize * .8, 0.001)); + expect( + paragraph.ideographicBaseline, + closeTo(paragraph.alphabeticBaseline * kAhemBaselineRatio, 0.001), + ); + } + }); +} diff --git a/testing/dart/rrect_test.dart b/testing/dart/rrect_test.dart new file mode 100644 index 0000000000000..b86c48e23dcac --- /dev/null +++ b/testing/dart/rrect_test.dart @@ -0,0 +1,47 @@ +// Copyright 2013 The Flutter 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:ui'; + +import 'package:test/test.dart'; + +void main() { + test('RRect.contains()', () { + final RRect rrect = RRect.fromRectAndCorners( + Rect.fromLTRB(1.0, 1.0, 2.0, 2.0), + topLeft: const Radius.circular(0.5), + topRight: const Radius.circular(0.25), + bottomRight: const Radius.elliptical(0.25, 0.75), + bottomLeft: Radius.zero, + ); + + expect(rrect.contains(const Offset(1.0, 1.0)), isFalse); + expect(rrect.contains(const Offset(1.1, 1.1)), isFalse); + expect(rrect.contains(const Offset(1.15, 1.15)), isTrue); + expect(rrect.contains(const Offset(2.0, 1.0)), isFalse); + expect(rrect.contains(const Offset(1.93, 1.07)), isFalse); + expect(rrect.contains(const Offset(1.97, 1.7)), isFalse); + expect(rrect.contains(const Offset(1.7, 1.97)), isTrue); + expect(rrect.contains(const Offset(1.0, 1.99)), isTrue); + }); + + test('RRect.contains() large radii', () { + final RRect rrect = RRect.fromRectAndCorners( + Rect.fromLTRB(1.0, 1.0, 2.0, 2.0), + topLeft: const Radius.circular(5000.0), + topRight: const Radius.circular(2500.0), + bottomRight: const Radius.elliptical(2500.0, 7500.0), + bottomLeft: Radius.zero, + ); + + expect(rrect.contains(const Offset(1.0, 1.0)), isFalse); + expect(rrect.contains(const Offset(1.1, 1.1)), isFalse); + expect(rrect.contains(const Offset(1.15, 1.15)), isTrue); + expect(rrect.contains(const Offset(2.0, 1.0)), isFalse); + expect(rrect.contains(const Offset(1.93, 1.07)), isFalse); + expect(rrect.contains(const Offset(1.97, 1.7)), isFalse); + expect(rrect.contains(const Offset(1.7, 1.97)), isTrue); + expect(rrect.contains(const Offset(1.0, 1.99)), isTrue); + }); +} diff --git a/testing/dart/task_order_test.dart b/testing/dart/task_order_test.dart new file mode 100644 index 0000000000000..74b5d805ad1d1 --- /dev/null +++ b/testing/dart/task_order_test.dart @@ -0,0 +1,49 @@ +// Copyright 2013 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'; + +import 'package:test/test.dart' hide TypeMatcher, isInstanceOf; + +void main() { + test('Message loop flushes microtasks between iterations', () async { + final List tasks = []; + + tasks.add(1); + + // Flush 0 microtasks. + await Future.delayed(Duration.zero); + + scheduleMicrotask(() { + tasks.add(3); + }); + scheduleMicrotask(() { + tasks.add(4); + }); + + tasks.add(2); + + // Flush 2 microtasks. + await Future.delayed(Duration.zero); + + scheduleMicrotask(() { + tasks.add(6); + }); + scheduleMicrotask(() { + tasks.add(7); + }); + scheduleMicrotask(() { + tasks.add(8); + }); + + tasks.add(5); + + // Flush 3 microtasks. + await Future.delayed(Duration.zero); + + tasks.add(9); + + expect(tasks, [1, 2, 3, 4, 5, 6, 7, 8, 9]); + }); +} From 91146cac10fe0c99f67051deaea92857f805ef39 Mon Sep 17 00:00:00 2001 From: Dan Field Date: Mon, 22 Apr 2019 16:12:03 -0700 Subject: [PATCH 2/3] update paragarph test --- testing/dart/paragraph_test.dart | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/testing/dart/paragraph_test.dart b/testing/dart/paragraph_test.dart index 06c62382af6e8..54c4046d19085 100644 --- a/testing/dart/paragraph_test.dart +++ b/testing/dart/paragraph_test.dart @@ -4,7 +4,7 @@ import 'dart:ui'; -import 'package:flutter_test/flutter_test.dart'; +import 'package:test/test.dart'; void main() { // Ahem font uses a constant ideographic/alphabetic baseline ratio. From deaad2e7a1f4efcbfd5ab07b758847a5c6d804f4 Mon Sep 17 00:00:00 2001 From: Dan Field Date: Mon, 22 Apr 2019 16:12:55 -0700 Subject: [PATCH 3/3] ++ --- testing/dart/paragraph_test.dart | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/testing/dart/paragraph_test.dart b/testing/dart/paragraph_test.dart index 54c4046d19085..3f5638d9c02f0 100644 --- a/testing/dart/paragraph_test.dart +++ b/testing/dart/paragraph_test.dart @@ -1,4 +1,4 @@ -// Copyright 2018 The Chromium Authors. All rights reserved. +// Copyright 2013 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.