22// Use of this source code is governed by a BSD-style license that can be
33// found in the LICENSE file.
44
5+ import 'dart:async' ;
6+
57import 'package:flutter/gestures.dart' ;
68import 'package:flutter/rendering.dart' ;
79import 'package:flutter/widgets.dart' ;
@@ -10,6 +12,158 @@ import 'package:flutter_test/flutter_test.dart';
1012// This file is for testings that require a `LiveTestWidgetsFlutterBinding`
1113void main () {
1214 final binding = LiveTestWidgetsFlutterBinding ();
15+ testWidgets ('Widgets are built within the current test zone (test 1 of 2)' , (
16+ WidgetTester tester,
17+ ) async {
18+ // Regression test for https://github.com/flutter/flutter/issues/113885
19+ Zone ? buildZone;
20+ final Zone bodyZone = Zone .current;
21+ await tester.pumpWidget (
22+ TestWidgetsApp (
23+ home: Builder (
24+ builder: (BuildContext context) {
25+ buildZone = Zone .current;
26+ return const Text ('Test 1' );
27+ },
28+ ),
29+ ),
30+ );
31+ expect (buildZone, equals (bodyZone));
32+ });
33+
34+ testWidgets ('Widgets are built within the current test zone (test 2 of 2)' , (
35+ WidgetTester tester,
36+ ) async {
37+ // Regression test for https://github.com/flutter/flutter/issues/113885
38+ Zone ? buildZone;
39+ final Zone bodyZone = Zone .current;
40+ await tester.pumpWidget (
41+ TestWidgetsApp (
42+ home: Builder (
43+ builder: (BuildContext context) {
44+ buildZone = Zone .current;
45+ return const Text ('Test 2' );
46+ },
47+ ),
48+ ),
49+ );
50+ expect (buildZone, equals (bodyZone));
51+ });
52+
53+ testWidgets ('Frame callbacks and pointer events run in current test zone (test 1 of 2)' , (
54+ WidgetTester tester,
55+ ) async {
56+ // Regression test for https://github.com/flutter/flutter/issues/113885
57+ Zone ? frameCallbackZone;
58+ Zone ? postFrameCallbackZone;
59+ Zone ? gestureZone;
60+ final Zone bodyZone = Zone .current;
61+
62+ tester.binding.scheduleFrameCallback ((Duration timeStamp) {
63+ frameCallbackZone = Zone .current;
64+ });
65+ tester.binding.addPostFrameCallback ((Duration timeStamp) {
66+ postFrameCallbackZone = Zone .current;
67+ });
68+
69+ await tester.pumpWidget (
70+ TestWidgetsApp (
71+ home: GestureDetector (
72+ onTap: () {
73+ gestureZone = Zone .current;
74+ },
75+ child: const Text ('Tap target 1' ),
76+ ),
77+ ),
78+ );
79+
80+ await tester.tap (find.text ('Tap target 1' ));
81+ await tester.pump ();
82+
83+ expect (frameCallbackZone, equals (bodyZone));
84+ expect (postFrameCallbackZone, equals (bodyZone));
85+ expect (gestureZone, equals (bodyZone));
86+ });
87+
88+ testWidgets ('Frame callbacks and pointer events run in current test zone (test 2 of 2)' , (
89+ WidgetTester tester,
90+ ) async {
91+ // Regression test for https://github.com/flutter/flutter/issues/113885
92+ Zone ? frameCallbackZone;
93+ Zone ? postFrameCallbackZone;
94+ Zone ? gestureZone;
95+ final Zone bodyZone = Zone .current;
96+
97+ tester.binding.scheduleFrameCallback ((Duration timeStamp) {
98+ frameCallbackZone = Zone .current;
99+ });
100+ tester.binding.addPostFrameCallback ((Duration timeStamp) {
101+ postFrameCallbackZone = Zone .current;
102+ });
103+
104+ await tester.pumpWidget (
105+ TestWidgetsApp (
106+ home: GestureDetector (
107+ onTap: () {
108+ gestureZone = Zone .current;
109+ },
110+ child: const Text ('Tap target 2' ),
111+ ),
112+ ),
113+ );
114+
115+ await tester.tap (find.text ('Tap target 2' ));
116+ await tester.pump ();
117+
118+ expect (frameCallbackZone, equals (bodyZone));
119+ expect (postFrameCallbackZone, equals (bodyZone));
120+ expect (gestureZone, equals (bodyZone));
121+ });
122+
123+ testWidgets (
124+ 'Teardown callbacks and frame callbacks in teardown run in current test zone (test 1 of 2)' ,
125+ (WidgetTester tester) async {
126+ // Regression test for https://github.com/flutter/flutter/issues/113885
127+ final Zone bodyZone = Zone .current;
128+ addTearDown (() async {
129+ Zone ? teardownBuildZone;
130+ await tester.pumpWidget (
131+ TestWidgetsApp (
132+ home: Builder (
133+ builder: (BuildContext context) {
134+ teardownBuildZone = Zone .current;
135+ return const Text ('Teardown 1' );
136+ },
137+ ),
138+ ),
139+ );
140+ expect (teardownBuildZone, equals (bodyZone));
141+ });
142+ },
143+ );
144+
145+ testWidgets (
146+ 'Teardown callbacks and frame callbacks in teardown run in current test zone (test 2 of 2)' ,
147+ (WidgetTester tester) async {
148+ // Regression test for https://github.com/flutter/flutter/issues/113885
149+ final Zone bodyZone = Zone .current;
150+ addTearDown (() async {
151+ Zone ? teardownBuildZone;
152+ await tester.pumpWidget (
153+ TestWidgetsApp (
154+ home: Builder (
155+ builder: (BuildContext context) {
156+ teardownBuildZone = Zone .current;
157+ return const Text ('Teardown 2' );
158+ },
159+ ),
160+ ),
161+ );
162+ expect (teardownBuildZone, equals (bodyZone));
163+ });
164+ },
165+ );
166+
13167 testWidgets ('Input PointerAddedEvent' , (WidgetTester tester) async {
14168 await tester.pumpWidget (const TestWidgetsApp (home: Text ('Test' )));
15169 await tester.pump ();
0 commit comments