Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Sign in
Toggle navigation
F
Front-End
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
abdullh.alsoleman
Front-End
Commits
1152fd60
Commit
1152fd60
authored
Sep 01, 2016
by
Ian Hickson
Committed by
GitHub
Sep 01, 2016
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Adds tester.pumpUntilNoTransientCallbacks (#5696)
Fixes
https://github.com/flutter/flutter/issues/5234
parent
ae565547
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
75 additions
and
5 deletions
+75
-5
widget_tester.dart
packages/flutter_test/lib/src/widget_tester.dart
+44
-5
widget_tester_test.dart
packages/flutter_test/test/widget_tester_test.dart
+31
-0
No files found.
packages/flutter_test/lib/src/widget_tester.dart
View file @
1152fd60
...
...
@@ -7,6 +7,7 @@ import 'dart:async';
import
'package:flutter/gestures.dart'
;
import
'package:flutter/rendering.dart'
;
import
'package:flutter/widgets.dart'
;
import
'package:meta/meta.dart'
;
import
'package:test/test.dart'
as
test_package
;
import
'all_elements.dart'
;
...
...
@@ -154,10 +155,10 @@ class WidgetTester extends WidgetController implements HitTestDispatcher {
/// Renders the UI from the given [widget].
///
/// Calls [runApp] with the given widget, then triggers a frame
sequence and
///
flushes microtasks, by calling [pump] with the same duration (if any).
///
The supplied [EnginePhase] is the final phase reached during the pump pass;
///
if
not supplied, the whole pass is executed.
/// Calls [runApp] with the given widget, then triggers a frame
and flushes
///
microtasks, by calling [pump] with the same `duration` (if any). The
///
supplied [EnginePhase] is the final phase reached during the pump pass; if
/// not supplied, the whole pass is executed.
Future
<
Null
>
pumpWidget
(
Widget
widget
,
[
Duration
duration
,
EnginePhase
phase
=
EnginePhase
.
sendSemanticsTree
...
...
@@ -168,7 +169,11 @@ class WidgetTester extends WidgetController implements HitTestDispatcher {
});
}
/// Triggers a sequence of frames for [duration] amount of time.
/// Triggers a frame after `duration` amount of time.
///
/// This makes the framework act as if the application had janked (missed
/// frames) for `duration` amount of time, and then received a v-sync signal
/// to paint the application.
///
/// This is a convenience function that just calls
/// [TestWidgetsFlutterBinding.pump].
...
...
@@ -180,6 +185,40 @@ class WidgetTester extends WidgetController implements HitTestDispatcher {
return
TestAsyncUtils
.
guard
(()
=>
binding
.
pump
(
duration
,
phase
));
}
/// Repeatedly calls [pump] with the given `duration` until there are no
/// longer any transient callbacks scheduled. If no transient callbacks are
/// scheduled when the function is called, it returns without calling [pump].
///
/// This essentially waits for all animations to have completed.
///
/// This function will never return (and the test will hang and eventually
/// time out and fail) if there is an infinite animation in progress (for
/// example, if there is an indeterminate progress indicator spinning).
///
/// If the function returns, it returns the number of pumps that it performed.
///
/// In general, it is better practice to figure out exactly why each frame is
/// needed, and then to [pump] exactly as many frames as necessary. This will
/// help catch regressions where, for instance, an animation is being started
/// one frame later than it should.
///
/// Alternatively, one can check that the return value from this function
/// matches the expected number of pumps.
Future
<
int
>
pumpUntilNoTransientCallbacks
([
@required
Duration
duration
,
EnginePhase
phase
=
EnginePhase
.
sendSemanticsTree
])
{
assert
(
duration
!=
null
);
assert
(
duration
>
Duration
.
ZERO
);
int
count
=
0
;
return
TestAsyncUtils
.
guard
(()
async
{
while
(
binding
.
transientCallbackCount
>
0
)
{
await
binding
.
pump
(
duration
,
phase
);
count
+=
1
;
}
}).
then
/*<int>*/
((
Null
_
)
=>
count
);
}
@override
HitTestResult
hitTestOnBinding
(
Point
location
)
{
location
=
binding
.
localToGlobal
(
location
);
...
...
packages/flutter_test/test/widget_tester_test.dart
View file @
1152fd60
...
...
@@ -68,6 +68,37 @@ void main() {
expect
(
message
,
contains
(
'Actual: ?:<exactly one widget with text "foo" (ignoring offstage widgets): Text("foo")>
\n
'
));
expect
(
message
,
contains
(
'Which: means one was found but none were expected
\n
'
));
});
testWidgets
(
'pumping'
,
(
WidgetTester
tester
)
async
{
await
tester
.
pumpWidget
(
new
Text
(
'foo'
));
int
count
;
AnimationController
test
=
new
AnimationController
(
duration:
const
Duration
(
milliseconds:
5100
));
count
=
await
tester
.
pumpUntilNoTransientCallbacks
(
const
Duration
(
seconds:
1
));
expect
(
count
,
0
);
test
.
forward
(
from:
0.0
);
count
=
await
tester
.
pumpUntilNoTransientCallbacks
(
const
Duration
(
seconds:
1
));
// 1 frame at t=0, starting the animation
// 1 frame at t=1
// 1 frame at t=2
// 1 frame at t=3
// 1 frame at t=4
// 1 frame at t=5
// 1 frame at t=6, ending the animation
expect
(
count
,
7
);
test
.
forward
(
from:
0.0
);
await
tester
.
pump
();
// starts the animation
count
=
await
tester
.
pumpUntilNoTransientCallbacks
(
const
Duration
(
seconds:
1
));
expect
(
count
,
6
);
test
.
forward
(
from:
0.0
);
await
tester
.
pump
();
// starts the animation
await
tester
.
pump
();
// has no effect
count
=
await
tester
.
pumpUntilNoTransientCallbacks
(
const
Duration
(
seconds:
1
));
expect
(
count
,
6
);
});
});
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment