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
f3a4f722
Commit
f3a4f722
authored
Apr 14, 2016
by
Yegor
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
[flutter_test] new WidgetTester API based on finder objects (#3288)
parent
a5a34d97
Changes
67
Hide whitespace changes
Inline
Side-by-side
Showing
67 changed files
with
1670 additions
and
1121 deletions
+1670
-1121
card_collection_test.dart
dev/manual_tests/test/card_collection_test.dart
+6
-6
hello_test.dart
examples/hello_world/test/hello_test.dart
+1
-1
smoke_test.dart
examples/material_gallery/test/smoke_test.dart
+8
-8
icon_color_test.dart
examples/stocks/test/icon_color_test.dart
+14
-14
locale_test.dart
examples/stocks/test/locale_test.dart
+3
-6
build_bench.dart
packages/flutter/benchmark/stocks/build_bench.dart
+1
-1
slider_test.dart
packages/flutter/test/material/slider_test.dart
+4
-4
snack_bar_test.dart
packages/flutter/test/material/snack_bar_test.dart
+93
-93
tabs_test.dart
packages/flutter/test/material/tabs_test.dart
+28
-39
animated_container_test.dart
packages/flutter/test/widget/animated_container_test.dart
+1
-1
aspect_ratio_test.dart
packages/flutter/test/widget/aspect_ratio_test.dart
+3
-3
asset_vendor_test.dart
packages/flutter/test/widget/asset_vendor_test.dart
+10
-10
block_test.dart
packages/flutter/test/widget/block_test.dart
+6
-6
bottom_sheet_test.dart
packages/flutter/test/widget/bottom_sheet_test.dart
+14
-14
box_decoration_test.dart
packages/flutter/test/widget/box_decoration_test.dart
+1
-1
coordinates_test.dart
packages/flutter/test/widget/coordinates_test.dart
+1
-1
custom_multi_child_layout_test.dart
...s/flutter/test/widget/custom_multi_child_layout_test.dart
+1
-1
date_picker_test_disabled.dart
packages/flutter/test/widget/date_picker_test_disabled.dart
+3
-3
dismissable_test.dart
packages/flutter/test/widget/dismissable_test.dart
+38
-41
draggable_test.dart
packages/flutter/test/widget/draggable_test.dart
+133
-133
drawer_test.dart
packages/flutter/test/widget/drawer_test.dart
+17
-17
duplicate_key_test.dart
packages/flutter/test/widget/duplicate_key_test.dart
+1
-1
flex_test.dart
packages/flutter/test/widget/flex_test.dart
+7
-7
focus_test.dart
packages/flutter/test/widget/focus_test.dart
+40
-40
form_test.dart
packages/flutter/test/widget/form_test.dart
+2
-4
heroes_test.dart
packages/flutter/test/widget/heroes_test.dart
+37
-37
hyperlink_test.dart
packages/flutter/test/widget/hyperlink_test.dart
+1
-2
icon_test.dart
packages/flutter/test/widget/icon_test.dart
+1
-1
image_test.dart
packages/flutter/test/widget/image_test.dart
+8
-8
input_test.dart
packages/flutter/test/widget/input_test.dart
+6
-5
lazy_block_viewport_test.dart
packages/flutter/test/widget/lazy_block_viewport_test.dart
+7
-9
listener_test.dart
packages/flutter/test/widget/listener_test.dart
+1
-1
modal_barrier_test.dart
packages/flutter/test/widget/modal_barrier_test.dart
+6
-6
multichild_test.dart
packages/flutter/test/widget/multichild_test.dart
+1
-1
navigator_test.dart
packages/flutter/test/widget/navigator_test.dart
+9
-9
page_forward_transitions_test.dart
...es/flutter/test/widget/page_forward_transitions_test.dart
+7
-7
page_transitions_test.dart
packages/flutter/test/widget/page_transitions_test.dart
+30
-30
pageable_list_test.dart
packages/flutter/test/widget/pageable_list_test.dart
+61
-61
parent_data_test.dart
packages/flutter/test/widget/parent_data_test.dart
+1
-1
progress_indicator_test.dart
packages/flutter/test/widget/progress_indicator_test.dart
+1
-1
remember_scroll_position_test.dart
...es/flutter/test/widget/remember_scroll_position_test.dart
+41
-43
render_object_widget_test.dart
packages/flutter/test/widget/render_object_widget_test.dart
+4
-4
reparent_state_test.dart
packages/flutter/test/widget/reparent_state_test.dart
+4
-4
rotated_box_test.dart
packages/flutter/test/widget/rotated_box_test.dart
+1
-1
scrollable_lazy_list_test.dart
packages/flutter/test/widget/scrollable_lazy_list_test.dart
+1
-2
scrollable_list_hit_testing_test.dart
...flutter/test/widget/scrollable_list_hit_testing_test.dart
+17
-17
scrollable_list_horizontal_test.dart
.../flutter/test/widget/scrollable_list_horizontal_test.dart
+102
-102
scrollable_list_vertical_test.dart
...es/flutter/test/widget/scrollable_list_vertical_test.dart
+34
-34
scrollable_list_with_inherited_test.dart
...tter/test/widget/scrollable_list_with_inherited_test.dart
+8
-8
set_state_2_test.dart
packages/flutter/test/widget/set_state_2_test.dart
+1
-1
set_state_test.dart
packages/flutter/test/widget/set_state_test.dart
+1
-1
stack_test.dart
packages/flutter/test/widget/stack_test.dart
+9
-9
stateful_component_test.dart
packages/flutter/test/widget/stateful_component_test.dart
+1
-1
stateful_components_test.dart
packages/flutter/test/widget/stateful_components_test.dart
+1
-1
syncing_test.dart
packages/flutter/test/widget/syncing_test.dart
+4
-4
table_test.dart
packages/flutter/test/widget/table_test.dart
+7
-7
test_matchers.dart
packages/flutter/test/widget/test_matchers.dart
+24
-15
test_widgets.dart
packages/flutter/test/widget/test_widgets.dart
+1
-6
tooltip_test.dart
packages/flutter/test/widget/tooltip_test.dart
+7
-7
two_level_list_test.dart
packages/flutter/test/widget/two_level_list_test.dart
+11
-11
flutter_markdown_test.dart
packages/flutter_markdown/test/flutter_markdown_test.dart
+24
-38
flutter_test.dart
packages/flutter_test/lib/flutter_test.dart
+1
-0
element_tree_tester.dart
packages/flutter_test/lib/src/element_tree_tester.dart
+207
-0
instrumentation.dart
packages/flutter_test/lib/src/instrumentation.dart
+55
-0
widget_tester.dart
packages/flutter_test/lib/src/widget_tester.dart
+428
-171
widget_tester_test.dart
packages/flutter_test/test/widget_tester_test.dart
+62
-0
test.sh
travis/test.sh
+1
-0
No files found.
dev/manual_tests/test/card_collection_test.dart
View file @
f3a4f722
...
...
@@ -15,27 +15,27 @@ void main() {
tester
.
pump
();
// see https://github.com/flutter/flutter/issues/1865
tester
.
pump
();
// triggers a frame
Element
navigationMenu
=
tester
.
find
Element
((
Element
element
)
{
Finder
navigationMenu
=
find
.
by
Element
((
Element
element
)
{
Widget
widget
=
element
.
widget
;
if
(
widget
is
Tooltip
)
return
widget
.
message
==
'Open navigation menu'
;
return
false
;
});
expect
(
navigationMenu
,
isNotNull
);
expect
(
tester
,
hasWidget
(
navigationMenu
)
);
tester
.
tap
(
navigationMenu
);
tester
.
pump
();
// start opening menu
tester
.
pump
(
const
Duration
(
seconds:
1
));
// wait til it's really opened
// smoke test for various checkboxes
tester
.
tap
(
tester
.
findT
ext
(
'Make card labels editable'
));
tester
.
tap
(
find
.
t
ext
(
'Make card labels editable'
));
tester
.
pump
();
tester
.
tap
(
tester
.
findT
ext
(
'Let the sun shine'
));
tester
.
tap
(
find
.
t
ext
(
'Let the sun shine'
));
tester
.
pump
();
tester
.
tap
(
tester
.
findT
ext
(
'Make card labels editable'
));
tester
.
tap
(
find
.
t
ext
(
'Make card labels editable'
));
tester
.
pump
();
tester
.
tap
(
tester
.
findT
ext
(
'Vary font sizes'
));
tester
.
tap
(
find
.
t
ext
(
'Vary font sizes'
));
tester
.
pump
();
});
});
...
...
examples/hello_world/test/hello_test.dart
View file @
f3a4f722
...
...
@@ -13,7 +13,7 @@ void main() {
hello_world
.
main
();
// builds the app and schedules a frame but doesn't trigger one
tester
.
pump
();
// triggers a frame
expect
(
tester
.
findText
(
'Hello, world!'
),
isNotNull
);
expect
(
tester
,
hasWidget
(
find
.
text
(
'Hello, world!'
))
);
});
});
}
examples/material_gallery/test/smoke_test.dart
View file @
f3a4f722
...
...
@@ -16,45 +16,45 @@ void main() {
tester
.
pump
();
// triggers a frame
// Try loading Weather demo
tester
.
tap
(
tester
.
findT
ext
(
'Demos'
));
tester
.
tap
(
find
.
t
ext
(
'Demos'
));
tester
.
pump
();
tester
.
pump
(
const
Duration
(
seconds:
1
));
// wait til it's really opened
tester
.
tap
(
tester
.
findT
ext
(
'Weather'
));
tester
.
tap
(
find
.
t
ext
(
'Weather'
));
tester
.
pump
();
tester
.
pump
(
const
Duration
(
seconds:
1
));
// wait til it's really opened
// Go back
Element
backButton
=
tester
.
find
Element
((
Element
element
)
{
Finder
backButton
=
find
.
by
Element
((
Element
element
)
{
Widget
widget
=
element
.
widget
;
if
(
widget
is
Tooltip
)
return
widget
.
message
==
'Back'
;
return
false
;
});
expect
(
backButton
,
isNotNull
);
expect
(
tester
,
hasWidget
(
backButton
)
);
tester
.
tap
(
backButton
);
tester
.
pump
();
// start going back
tester
.
pump
(
const
Duration
(
seconds:
1
));
// wait til it's finished
// Open menu
Element
navigationMenu
=
tester
.
find
Element
((
Element
element
)
{
Finder
navigationMenu
=
find
.
by
Element
((
Element
element
)
{
Widget
widget
=
element
.
widget
;
if
(
widget
is
Tooltip
)
return
widget
.
message
==
'Open navigation menu'
;
return
false
;
});
expect
(
navigationMenu
,
isNotNull
);
expect
(
tester
,
hasWidget
(
navigationMenu
)
);
tester
.
tap
(
navigationMenu
);
tester
.
pump
();
// start opening menu
tester
.
pump
(
const
Duration
(
seconds:
1
));
// wait til it's really opened
// switch theme
tester
.
tap
(
tester
.
findT
ext
(
'Dark'
));
tester
.
tap
(
find
.
t
ext
(
'Dark'
));
tester
.
pump
();
tester
.
pump
(
const
Duration
(
seconds:
1
));
// wait til it's changed
// switch theme
tester
.
tap
(
tester
.
findT
ext
(
'Light'
));
tester
.
tap
(
find
.
t
ext
(
'Light'
));
tester
.
pump
();
tester
.
pump
(
const
Duration
(
seconds:
1
));
// wait til it's changed
});
...
...
examples/stocks/test/icon_color_test.dart
View file @
f3a4f722
...
...
@@ -38,7 +38,7 @@ Element findElementOfExactWidgetTypeGoingUp(Element node, Type targetType) {
final
RegExp
materialIconAssetNameColorExtractor
=
new
RegExp
(
r'[^/]+/ic_.+_(white|black)_[0-9]+dp\.png'
);
void
checkIconColor
(
Widget
Tester
tester
,
String
label
,
Color
color
)
{
void
checkIconColor
(
ElementTree
Tester
tester
,
String
label
,
Color
color
)
{
// The icon is going to be in the same merged semantics box as the text
// regardless of how the menu item is represented, so this is a good
// way to find the menu item. I hope.
...
...
@@ -59,11 +59,11 @@ void main() {
tester
.
pump
();
// triggers a frame
// sanity check
expect
(
tester
.
findText
(
'MARKET'
),
isNotNull
);
expect
(
tester
.
findText
(
'Help & Feedback'
),
isNull
);
expect
(
tester
,
hasWidget
(
find
.
text
(
'MARKET'
))
);
expect
(
tester
,
doesNotHaveWidget
(
find
.
text
(
'Help & Feedback'
))
);
tester
.
pump
(
new
Duration
(
seconds:
2
));
expect
(
tester
.
findText
(
'MARKET'
),
isNotNull
);
expect
(
tester
.
findText
(
'Help & Feedback'
),
isNull
);
expect
(
tester
,
hasWidget
(
find
.
text
(
'MARKET'
))
);
expect
(
tester
,
doesNotHaveWidget
(
find
.
text
(
'Help & Feedback'
))
);
// drag the drawer out
Point
left
=
new
Point
(
0.0
,
ui
.
window
.
size
.
height
/
2.0
);
...
...
@@ -74,24 +74,24 @@ void main() {
tester
.
pump
();
gesture
.
up
();
tester
.
pump
();
expect
(
tester
.
findText
(
'MARKET'
),
isNotNull
);
expect
(
tester
.
findText
(
'Help & Feedback'
),
isNotNull
);
expect
(
tester
,
hasWidget
(
find
.
text
(
'MARKET'
))
);
expect
(
tester
,
hasWidget
(
find
.
text
(
'Help & Feedback'
))
);
// check the colour of the icon - light mode
checkIconColor
(
tester
,
'Stock List'
,
Colors
.
purple
[
500
]);
// theme primary color
checkIconColor
(
tester
,
'Account Balance'
,
Colors
.
black45
);
// enabled
checkIconColor
(
tester
,
'Help & Feedback'
,
Colors
.
black26
);
// disabled
checkIconColor
(
tester
.
elementTreeTester
,
'Stock List'
,
Colors
.
purple
[
500
]);
// theme primary color
checkIconColor
(
tester
.
elementTreeTester
,
'Account Balance'
,
Colors
.
black45
);
// enabled
checkIconColor
(
tester
.
elementTreeTester
,
'Help & Feedback'
,
Colors
.
black26
);
// disabled
// switch to dark mode
tester
.
tap
(
tester
.
findT
ext
(
'Pessimistic'
));
tester
.
tap
(
find
.
t
ext
(
'Pessimistic'
));
tester
.
pump
();
// get the tap and send the notification that the theme has changed
tester
.
pump
();
// start the theme transition
tester
.
pump
(
const
Duration
(
seconds:
5
));
// end the transition
// check the colour of the icon - dark mode
checkIconColor
(
tester
,
'Stock List'
,
Colors
.
redAccent
[
200
]);
// theme accent color
checkIconColor
(
tester
,
'Account Balance'
,
Colors
.
white
);
// enabled
checkIconColor
(
tester
,
'Help & Feedback'
,
Colors
.
white30
);
// disabled
checkIconColor
(
tester
.
elementTreeTester
,
'Stock List'
,
Colors
.
redAccent
[
200
]);
// theme accent color
checkIconColor
(
tester
.
elementTreeTester
,
'Account Balance'
,
Colors
.
white
);
// enabled
checkIconColor
(
tester
.
elementTreeTester
,
'Help & Feedback'
,
Colors
.
white30
);
// disabled
});
});
...
...
examples/stocks/test/locale_test.dart
View file @
f3a4f722
...
...
@@ -2,7 +2,6 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
import
'package:flutter/material.dart'
;
import
'package:flutter_test/flutter_test.dart'
;
import
'package:stocks/main.dart'
as
stocks
;
import
'package:stocks/stock_data.dart'
as
stock_data
;
...
...
@@ -14,15 +13,13 @@ void main() {
test
(
"Test changing locale"
,
()
{
testWidgets
((
WidgetTester
tester
)
{
stocks
.
main
();
tester
.
async
.
flushMicrotasks
();
// see https://github.com/flutter/flutter/issues/1865
tester
.
flushMicrotasks
();
// see https://github.com/flutter/flutter/issues/1865
tester
.
pump
();
Element
tab
=
tester
.
findText
(
'MARKET'
);
expect
(
tab
,
isNotNull
);
expect
(
tester
,
hasWidget
(
find
.
text
(
'MARKET'
)));
tester
.
setLocale
(
"es"
,
"US"
);
tester
.
pump
();
Text
text
=
tab
.
widget
;
expect
(
text
.
data
,
equals
(
"MERCADO"
));
expect
(
tester
,
hasWidget
(
find
.
text
(
'MERCADO'
)));
// TODO(abarth): We're leaking an animation. We should track down the leak
// and plug it rather than waiting for the animation to end here.
...
...
packages/flutter/benchmark/stocks/build_bench.dart
View file @
f3a4f722
...
...
@@ -24,7 +24,7 @@ void main() {
tester
.
tapAt
(
new
Point
(
20.0
,
20.0
));
// Open drawer
tester
.
pump
();
// Start drawer animation
tester
.
pump
(
const
Duration
(
seconds:
1
));
// Complete drawer animation
appState
=
tester
.
findStateOfType
(
stocks
.
StocksAppState
);
appState
=
tester
.
stateOf
(
find
.
byType
(
stocks
.
StocksApp
)
);
});
WidgetFlutterBinding
binding
=
WidgetFlutterBinding
.
instance
;
...
...
packages/flutter/test/material/slider_test.dart
View file @
f3a4f722
...
...
@@ -34,7 +34,7 @@ void main() {
);
expect
(
value
,
equals
(
0.0
));
tester
.
tap
(
tester
.
findElementB
yKey
(
sliderKey
));
tester
.
tap
(
find
.
b
yKey
(
sliderKey
));
expect
(
value
,
equals
(
0.5
));
tester
.
pump
();
// No animation should start.
expect
(
Scheduler
.
instance
.
transientCallbackCount
,
equals
(
0
));
...
...
@@ -70,11 +70,11 @@ void main() {
);
expect
(
value
,
equals
(
0.0
));
tester
.
tap
(
tester
.
findElementB
yKey
(
sliderKey
));
tester
.
tap
(
find
.
b
yKey
(
sliderKey
));
expect
(
value
,
equals
(
50.0
));
tester
.
scroll
(
tester
.
findElementB
yKey
(
sliderKey
),
const
Offset
(
5.0
,
0.0
));
tester
.
scroll
(
find
.
b
yKey
(
sliderKey
),
const
Offset
(
5.0
,
0.0
));
expect
(
value
,
equals
(
50.0
));
tester
.
scroll
(
tester
.
findElementB
yKey
(
sliderKey
),
const
Offset
(
40.0
,
0.0
));
tester
.
scroll
(
find
.
b
yKey
(
sliderKey
),
const
Offset
(
40.0
,
0.0
));
expect
(
value
,
equals
(
80.0
));
tester
.
pump
();
// Starts animation.
...
...
packages/flutter/test/material/snack_bar_test.dart
View file @
f3a4f722
...
...
@@ -37,24 +37,24 @@ void main() {
}
}
));
expect
(
tester
.
findText
(
helloSnackBar
),
isNull
);
tester
.
tap
(
tester
.
findElementB
yKey
(
tapTarget
));
expect
(
tester
.
findText
(
helloSnackBar
),
isNull
);
expect
(
tester
,
doesNotHaveWidget
(
find
.
text
(
helloSnackBar
))
);
tester
.
tap
(
find
.
b
yKey
(
tapTarget
));
expect
(
tester
,
doesNotHaveWidget
(
find
.
text
(
helloSnackBar
))
);
tester
.
pump
();
// schedule animation
expect
(
tester
.
findText
(
helloSnackBar
),
isNotNull
);
expect
(
tester
,
hasWidget
(
find
.
text
(
helloSnackBar
))
);
tester
.
pump
();
// begin animation
expect
(
tester
.
findText
(
helloSnackBar
),
isNotNull
);
expect
(
tester
,
hasWidget
(
find
.
text
(
helloSnackBar
))
);
tester
.
pump
(
new
Duration
(
milliseconds:
750
));
// 0.75s // animation last frame; two second timer starts here
expect
(
tester
.
findText
(
helloSnackBar
),
isNotNull
);
expect
(
tester
,
hasWidget
(
find
.
text
(
helloSnackBar
))
);
tester
.
pump
(
new
Duration
(
milliseconds:
750
));
// 1.50s
expect
(
tester
.
findText
(
helloSnackBar
),
isNotNull
);
expect
(
tester
,
hasWidget
(
find
.
text
(
helloSnackBar
))
);
tester
.
pump
(
new
Duration
(
milliseconds:
750
));
// 2.25s
expect
(
tester
.
findText
(
helloSnackBar
),
isNotNull
);
expect
(
tester
,
hasWidget
(
find
.
text
(
helloSnackBar
))
);
tester
.
pump
(
new
Duration
(
milliseconds:
750
));
// 3.00s // timer triggers to dismiss snackbar, reverse animation is scheduled
tester
.
pump
();
// begin animation
expect
(
tester
.
findText
(
helloSnackBar
),
isNotNull
);
// frame 0 of dismiss animation
expect
(
tester
,
hasWidget
(
find
.
text
(
helloSnackBar
))
);
// frame 0 of dismiss animation
tester
.
pump
(
new
Duration
(
milliseconds:
750
));
// 3.75s // last frame of animation, snackbar removed from build
expect
(
tester
.
findText
(
helloSnackBar
),
isNull
);
expect
(
tester
,
doesNotHaveWidget
(
find
.
text
(
helloSnackBar
))
);
});
});
...
...
@@ -89,53 +89,53 @@ void main() {
}
}
));
expect
(
tester
.
findText
(
'bar1'
),
isNull
);
expect
(
tester
.
findText
(
'bar2'
),
isNull
);
tester
.
tap
(
tester
.
findElementB
yKey
(
tapTarget
));
// queue bar1
tester
.
tap
(
tester
.
findElementB
yKey
(
tapTarget
));
// queue bar2
expect
(
tester
.
findText
(
'bar1'
),
isNull
);
expect
(
tester
.
findText
(
'bar2'
),
isNull
);
expect
(
tester
,
doesNotHaveWidget
(
find
.
text
(
'bar1'
))
);
expect
(
tester
,
doesNotHaveWidget
(
find
.
text
(
'bar2'
))
);
tester
.
tap
(
find
.
b
yKey
(
tapTarget
));
// queue bar1
tester
.
tap
(
find
.
b
yKey
(
tapTarget
));
// queue bar2
expect
(
tester
,
doesNotHaveWidget
(
find
.
text
(
'bar1'
))
);
expect
(
tester
,
doesNotHaveWidget
(
find
.
text
(
'bar2'
))
);
tester
.
pump
();
// schedule animation for bar1
expect
(
tester
.
findText
(
'bar1'
),
isNotNull
);
expect
(
tester
.
findText
(
'bar2'
),
isNull
);
expect
(
tester
,
hasWidget
(
find
.
text
(
'bar1'
))
);
expect
(
tester
,
doesNotHaveWidget
(
find
.
text
(
'bar2'
))
);
tester
.
pump
();
// begin animation
expect
(
tester
.
findText
(
'bar1'
),
isNotNull
);
expect
(
tester
.
findText
(
'bar2'
),
isNull
);
expect
(
tester
,
hasWidget
(
find
.
text
(
'bar1'
))
);
expect
(
tester
,
doesNotHaveWidget
(
find
.
text
(
'bar2'
))
);
tester
.
pump
(
new
Duration
(
milliseconds:
750
));
// 0.75s // animation last frame; two second timer starts here
expect
(
tester
.
findText
(
'bar1'
),
isNotNull
);
expect
(
tester
.
findText
(
'bar2'
),
isNull
);
expect
(
tester
,
hasWidget
(
find
.
text
(
'bar1'
))
);
expect
(
tester
,
doesNotHaveWidget
(
find
.
text
(
'bar2'
))
);
tester
.
pump
(
new
Duration
(
milliseconds:
750
));
// 1.50s
expect
(
tester
.
findText
(
'bar1'
),
isNotNull
);
expect
(
tester
.
findText
(
'bar2'
),
isNull
);
expect
(
tester
,
hasWidget
(
find
.
text
(
'bar1'
))
);
expect
(
tester
,
doesNotHaveWidget
(
find
.
text
(
'bar2'
))
);
tester
.
pump
(
new
Duration
(
milliseconds:
750
));
// 2.25s
expect
(
tester
.
findText
(
'bar1'
),
isNotNull
);
expect
(
tester
.
findText
(
'bar2'
),
isNull
);
expect
(
tester
,
hasWidget
(
find
.
text
(
'bar1'
))
);
expect
(
tester
,
doesNotHaveWidget
(
find
.
text
(
'bar2'
))
);
tester
.
pump
(
new
Duration
(
milliseconds:
750
));
// 3.00s // timer triggers to dismiss snackbar, reverse animation is scheduled
tester
.
pump
();
// begin animation
expect
(
tester
.
findText
(
'bar1'
),
isNotNull
);
expect
(
tester
.
findText
(
'bar2'
),
isNull
);
expect
(
tester
,
hasWidget
(
find
.
text
(
'bar1'
))
);
expect
(
tester
,
doesNotHaveWidget
(
find
.
text
(
'bar2'
))
);
tester
.
pump
(
new
Duration
(
milliseconds:
750
));
// 3.75s // last frame of animation, snackbar removed from build, new snack bar put in its place
expect
(
tester
.
findText
(
'bar1'
),
isNull
);
expect
(
tester
.
findText
(
'bar2'
),
isNotNull
);
expect
(
tester
,
doesNotHaveWidget
(
find
.
text
(
'bar1'
))
);
expect
(
tester
,
hasWidget
(
find
.
text
(
'bar2'
))
);
tester
.
pump
();
// begin animation
expect
(
tester
.
findText
(
'bar1'
),
isNull
);
expect
(
tester
.
findText
(
'bar2'
),
isNotNull
);
expect
(
tester
,
doesNotHaveWidget
(
find
.
text
(
'bar1'
))
);
expect
(
tester
,
hasWidget
(
find
.
text
(
'bar2'
))
);
tester
.
pump
(
new
Duration
(
milliseconds:
750
));
// 4.50s // animation last frame; two second timer starts here
expect
(
tester
.
findText
(
'bar1'
),
isNull
);
expect
(
tester
.
findText
(
'bar2'
),
isNotNull
);
expect
(
tester
,
doesNotHaveWidget
(
find
.
text
(
'bar1'
))
);
expect
(
tester
,
hasWidget
(
find
.
text
(
'bar2'
))
);
tester
.
pump
(
new
Duration
(
milliseconds:
750
));
// 5.25s
expect
(
tester
.
findText
(
'bar1'
),
isNull
);
expect
(
tester
.
findText
(
'bar2'
),
isNotNull
);
expect
(
tester
,
doesNotHaveWidget
(
find
.
text
(
'bar1'
))
);
expect
(
tester
,
hasWidget
(
find
.
text
(
'bar2'
))
);
tester
.
pump
(
new
Duration
(
milliseconds:
750
));
// 6.00s
expect
(
tester
.
findText
(
'bar1'
),
isNull
);
expect
(
tester
.
findText
(
'bar2'
),
isNotNull
);
expect
(
tester
,
doesNotHaveWidget
(
find
.
text
(
'bar1'
))
);
expect
(
tester
,
hasWidget
(
find
.
text
(
'bar2'
))
);
tester
.
pump
(
new
Duration
(
milliseconds:
750
));
// 6.75s // timer triggers to dismiss snackbar, reverse animation is scheduled
tester
.
pump
();
// begin animation
expect
(
tester
.
findText
(
'bar1'
),
isNull
);
expect
(
tester
.
findText
(
'bar2'
),
isNotNull
);
expect
(
tester
,
doesNotHaveWidget
(
find
.
text
(
'bar1'
))
);
expect
(
tester
,
hasWidget
(
find
.
text
(
'bar2'
))
);
tester
.
pump
(
new
Duration
(
milliseconds:
750
));
// 7.50s // last frame of animation, snackbar removed from build, new snack bar put in its place
expect
(
tester
.
findText
(
'bar1'
),
isNull
);
expect
(
tester
.
findText
(
'bar2'
),
isNull
);
expect
(
tester
,
doesNotHaveWidget
(
find
.
text
(
'bar1'
))
);
expect
(
tester
,
doesNotHaveWidget
(
find
.
text
(
'bar2'
))
);
});
});
...
...
@@ -172,62 +172,62 @@ void main() {
}
}
));
expect
(
tester
.
findText
(
'bar1'
),
isNull
);
expect
(
tester
.
findText
(
'bar2'
),
isNull
);
expect
(
tester
,
doesNotHaveWidget
(
find
.
text
(
'bar1'
))
);
expect
(
tester
,
doesNotHaveWidget
(
find
.
text
(
'bar2'
))
);
time
=
1000
;
tester
.
tap
(
tester
.
findElementB
yKey
(
tapTarget
));
// queue bar1
tester
.
tap
(
find
.
b
yKey
(
tapTarget
));
// queue bar1
ScaffoldFeatureController
<
SnackBar
,
Null
>
firstController
=
lastController
;
time
=
2
;
tester
.
tap
(
tester
.
findElementB
yKey
(
tapTarget
));
// queue bar2
expect
(
tester
.
findText
(
'bar1'
),
isNull
);
expect
(
tester
.
findText
(
'bar2'
),
isNull
);
tester
.
tap
(
find
.
b
yKey
(
tapTarget
));
// queue bar2
expect
(
tester
,
doesNotHaveWidget
(
find
.
text
(
'bar1'
))
);
expect
(
tester
,
doesNotHaveWidget
(
find
.
text
(
'bar2'
))
);
tester
.
pump
();
// schedule animation for bar1
expect
(
tester
.
findText
(
'bar1'
),
isNotNull
);
expect
(
tester
.
findText
(
'bar2'
),
isNull
);
expect
(
tester
,
hasWidget
(
find
.
text
(
'bar1'
))
);
expect
(
tester
,
doesNotHaveWidget
(
find
.
text
(
'bar2'
))
);
tester
.
pump
();
// begin animation
expect
(
tester
.
findText
(
'bar1'
),
isNotNull
);
expect
(
tester
.
findText
(
'bar2'
),
isNull
);
expect
(
tester
,
hasWidget
(
find
.
text
(
'bar1'
))
);
expect
(
tester
,
doesNotHaveWidget
(
find
.
text
(
'bar2'
))
);
tester
.
pump
(
new
Duration
(
milliseconds:
750
));
// 0.75s // animation last frame; two second timer starts here
expect
(
tester
.
findText
(
'bar1'
),
isNotNull
);
expect
(
tester
.
findText
(
'bar2'
),
isNull
);
expect
(
tester
,
hasWidget
(
find
.
text
(
'bar1'
))
);
expect
(
tester
,
doesNotHaveWidget
(
find
.
text
(
'bar2'
))
);
tester
.
pump
(
new
Duration
(
milliseconds:
750
));
// 1.50s
expect
(
tester
.
findText
(
'bar1'
),
isNotNull
);
expect
(
tester
.
findText
(
'bar2'
),
isNull
);
expect
(
tester
,
hasWidget
(
find
.
text
(
'bar1'
))
);
expect
(
tester
,
doesNotHaveWidget
(
find
.
text
(
'bar2'
))
);
tester
.
pump
(
new
Duration
(
milliseconds:
750
));
// 2.25s
expect
(
tester
.
findText
(
'bar1'
),
isNotNull
);
expect
(
tester
.
findText
(
'bar2'
),
isNull
);
expect
(
tester
,
hasWidget
(
find
.
text
(
'bar1'
))
);
expect
(
tester
,
doesNotHaveWidget
(
find
.
text
(
'bar2'
))
);
tester
.
pump
(
new
Duration
(
milliseconds:
10000
));
// 12.25s
expect
(
tester
.
findText
(
'bar1'
),
isNotNull
);
expect
(
tester
.
findText
(
'bar2'
),
isNull
);
expect
(
tester
,
hasWidget
(
find
.
text
(
'bar1'
))
);
expect
(
tester
,
doesNotHaveWidget
(
find
.
text
(
'bar2'
))
);
firstController
.
close
();
// snackbar is manually dismissed
tester
.
pump
(
new
Duration
(
milliseconds:
750
));
// 13.00s // reverse animation is scheduled
tester
.
pump
();
// begin animation
expect
(
tester
.
findText
(
'bar1'
),
isNotNull
);
expect
(
tester
.
findText
(
'bar2'
),
isNull
);
expect
(
tester
,
hasWidget
(
find
.
text
(
'bar1'
))
);
expect
(
tester
,
doesNotHaveWidget
(
find
.
text
(
'bar2'
))
);
tester
.
pump
(
new
Duration
(
milliseconds:
750
));
// 13.75s // last frame of animation, snackbar removed from build, new snack bar put in its place
expect
(
tester
.
findText
(
'bar1'
),
isNull
);
expect
(
tester
.
findText
(
'bar2'
),
isNotNull
);
expect
(
tester
,
doesNotHaveWidget
(
find
.
text
(
'bar1'
))
);
expect
(
tester
,
hasWidget
(
find
.
text
(
'bar2'
))
);
tester
.
pump
();
// begin animation
expect
(
tester
.
findText
(
'bar1'
),
isNull
);
expect
(
tester
.
findText
(
'bar2'
),
isNotNull
);
expect
(
tester
,
doesNotHaveWidget
(
find
.
text
(
'bar1'
))
);
expect
(
tester
,
hasWidget
(
find
.
text
(
'bar2'
))
);
tester
.
pump
(
new
Duration
(
milliseconds:
750
));
// 14.50s // animation last frame; two second timer starts here
expect
(
tester
.
findText
(
'bar1'
),
isNull
);
expect
(
tester
.
findText
(
'bar2'
),
isNotNull
);
expect
(
tester
,
doesNotHaveWidget
(
find
.
text
(
'bar1'
))
);
expect
(
tester
,
hasWidget
(
find
.
text
(
'bar2'
))
);
tester
.
pump
(
new
Duration
(
milliseconds:
750
));
// 15.25s
expect
(
tester
.
findText
(
'bar1'
),
isNull
);
expect
(
tester
.
findText
(
'bar2'
),
isNotNull
);
expect
(
tester
,
doesNotHaveWidget
(
find
.
text
(
'bar1'
))
);
expect
(
tester
,
hasWidget
(
find
.
text
(
'bar2'
))
);
tester
.
pump
(
new
Duration
(
milliseconds:
750
));
// 16.00s
expect
(
tester
.
findText
(
'bar1'
),
isNull
);
expect
(
tester
.
findText
(
'bar2'
),
isNotNull
);
expect
(
tester
,
doesNotHaveWidget
(
find
.
text
(
'bar1'
))
);
expect
(
tester
,
hasWidget
(
find
.
text
(
'bar2'
))
);
tester
.
pump
(
new
Duration
(
milliseconds:
750
));
// 16.75s // timer triggers to dismiss snackbar, reverse animation is scheduled
tester
.
pump
();
// begin animation
expect
(
tester
.
findText
(
'bar1'
),
isNull
);
expect
(
tester
.
findText
(
'bar2'
),
isNotNull
);
expect
(
tester
,
doesNotHaveWidget
(
find
.
text
(
'bar1'
))
);
expect
(
tester
,
hasWidget
(
find
.
text
(
'bar2'
))
);
tester
.
pump
(
new
Duration
(
milliseconds:
750
));
// 17.50s // last frame of animation, snackbar removed from build, new snack bar put in its place
expect
(
tester
.
findText
(
'bar1'
),
isNull
);
expect
(
tester
.
findText
(
'bar2'
),
isNull
);
expect
(
tester
,
doesNotHaveWidget
(
find
.
text
(
'bar1'
))
);
expect
(
tester
,
doesNotHaveWidget
(
find
.
text
(
'bar2'
))
);
});
});
...
...
@@ -262,23 +262,23 @@ void main() {
}
}
));
expect
(
tester
.
findText
(
'bar1'
),
isNull
);
expect
(
tester
.
findText
(
'bar2'
),
isNull
);
tester
.
tap
(
tester
.
findElementB
yKey
(
tapTarget
));
// queue bar1
tester
.
tap
(
tester
.
findElementB
yKey
(
tapTarget
));
// queue bar2
expect
(
tester
.
findText
(
'bar1'
),
isNull
);
expect
(
tester
.
findText
(
'bar2'
),
isNull
);
expect
(
tester
,
doesNotHaveWidget
(
find
.
text
(
'bar1'
))
);
expect
(
tester
,
doesNotHaveWidget
(
find
.
text
(
'bar2'
))
);
tester
.
tap
(
find
.
b
yKey
(
tapTarget
));
// queue bar1
tester
.
tap
(
find
.
b
yKey
(
tapTarget
));
// queue bar2
expect
(
tester
,
doesNotHaveWidget
(
find
.
text
(
'bar1'
))
);
expect
(
tester
,
doesNotHaveWidget
(
find
.
text
(
'bar2'
))
);
tester
.
pump
();
// schedule animation for bar1
expect
(
tester
.
findText
(
'bar1'
),
isNotNull
);
expect
(
tester
.
findText
(
'bar2'
),
isNull
);
expect
(
tester
,
hasWidget
(
find
.
text
(
'bar1'
))
);
expect
(
tester
,
doesNotHaveWidget
(
find
.
text
(
'bar2'
))
);
tester
.
pump
();
// begin animation
expect
(
tester
.
findText
(
'bar1'
),
isNotNull
);
expect
(
tester
.
findText
(
'bar2'
),
isNull
);
expect
(
tester
,
hasWidget
(
find
.
text
(
'bar1'
))
);
expect
(
tester
,
doesNotHaveWidget
(
find
.
text
(
'bar2'
))
);
tester
.
pump
(
new
Duration
(
milliseconds:
750
));
// 0.75s // animation last frame; two second timer starts here
tester
.
scroll
(
tester
.
findT
ext
(
'bar1'
),
new
Offset
(
0.0
,
50.0
));
tester
.
scroll
(
find
.
t
ext
(
'bar1'
),
new
Offset
(
0.0
,
50.0
));
tester
.
pump
();
// bar1 dismissed, bar2 begins animating
expect
(
tester
.
findText
(
'bar1'
),
isNull
);
expect
(
tester
.
findText
(
'bar2'
),
isNotNull
);
expect
(
tester
,
doesNotHaveWidget
(
find
.
text
(
'bar1'
))
);
expect
(
tester
,
hasWidget
(
find
.
text
(
'bar2'
))
);
});
});
...
...
@@ -312,17 +312,17 @@ void main() {
}
}
));
tester
.
tap
(
tester
.
findT
ext
(
'X'
));
tester
.
tap
(
find
.
t
ext
(
'X'
));
tester
.
pump
();
// start animation
tester
.
pump
(
const
Duration
(
milliseconds:
750
));
expect
(
tapCount
,
equals
(
0
));
tester
.
tap
(
tester
.
findT
ext
(
'ACTION'
));
tester
.
tap
(
find
.
t
ext
(
'ACTION'
));
expect
(
tapCount
,
equals
(
1
));
tester
.
tap
(
tester
.
findT
ext
(
'ACTION'
));
tester
.
tap
(
find
.
t
ext
(
'ACTION'
));
expect
(
tapCount
,
equals
(
1
));
tester
.
pump
();
tester
.
tap
(
tester
.
findT
ext
(
'ACTION'
));
tester
.
tap
(
find
.
t
ext
(
'ACTION'
));
expect
(
tapCount
,
equals
(
1
));
});
});
...
...
packages/flutter/test/material/tabs_test.dart
View file @
f3a4f722
...
...
@@ -47,21 +47,21 @@ void main() {
List
<
String
>
tabs
=
<
String
>[
'A'
,
'B'
,
'C'
];
tester
.
pumpWidget
(
buildFrame
(
tabs:
tabs
,
value:
'C'
,
isScrollable:
false
));
TabBarSelectionState
<
String
>
selection
=
TabBarSelection
.
of
(
tester
.
findText
(
'A'
));
TabBarSelectionState
<
String
>
selection
=
TabBarSelection
.
of
(
tester
.
elementTreeTester
.
findText
(
'A'
));
expect
(
selection
,
isNotNull
);
expect
(
selection
.
indexOf
(
'A'
),
equals
(
0
));
expect
(
selection
.
indexOf
(
'B'
),
equals
(
1
));
expect
(
selection
.
indexOf
(
'C'
),
equals
(
2
));
expect
(
tester
.
findText
(
'A'
),
isNotNull
);
expect
(
tester
.
findText
(
'B'
),
isNotNull
);
expect
(
tester
.
findText
(
'C'
),
isNotNull
);
expect
(
tester
,
hasWidget
(
find
.
text
(
'A'
))
);
expect
(
tester
,
hasWidget
(
find
.
text
(
'B'
))
);
expect
(
tester
,
hasWidget
(
find
.
text
(
'C'
))
);
expect
(
selection
.
index
,
equals
(
2
));
expect
(
selection
.
previousIndex
,
equals
(
2
));
expect
(
selection
.
value
,
equals
(
'C'
));
expect
(
selection
.
previousValue
,
equals
(
'C'
));
tester
.
pumpWidget
(
buildFrame
(
tabs:
tabs
,
value:
'C'
,
isScrollable:
false
));
tester
.
tap
(
tester
.
findT
ext
(
'B'
));
tester
.
tap
(
find
.
t
ext
(
'B'
));
tester
.
pump
();
expect
(
selection
.
valueIsChanging
,
true
);
tester
.
pump
(
const
Duration
(
seconds:
1
));
// finish the animation
...
...
@@ -72,7 +72,7 @@ void main() {
expect
(
selection
.
previousIndex
,
equals
(
2
));
tester
.
pumpWidget
(
buildFrame
(
tabs:
tabs
,
value:
'C'
,
isScrollable:
false
));
tester
.
tap
(
tester
.
findT
ext
(
'C'
));
tester
.
tap
(
find
.
t
ext
(
'C'
));
tester
.
pump
();
tester
.
pump
(
const
Duration
(
seconds:
1
));
expect
(
selection
.
value
,
equals
(
'C'
));
...
...
@@ -81,7 +81,7 @@ void main() {
expect
(
selection
.
previousIndex
,
equals
(
1
));
tester
.
pumpWidget
(
buildFrame
(
tabs:
tabs
,
value:
'C'
,
isScrollable:
false
));
tester
.
tap
(
tester
.
findT
ext
(
'A'
));
tester
.
tap
(
find
.
t
ext
(
'A'
));
tester
.
pump
();
tester
.
pump
(
const
Duration
(
seconds:
1
));
expect
(
selection
.
value
,
equals
(
'A'
));
...
...
@@ -96,25 +96,25 @@ void main() {
List
<
String
>
tabs
=
<
String
>[
'A'
,
'B'
,
'C'
];
tester
.
pumpWidget
(
buildFrame
(
tabs:
tabs
,
value:
'C'
,
isScrollable:
true
));
TabBarSelectionState
<
String
>
selection
=
TabBarSelection
.
of
(
tester
.
findText
(
'A'
));
TabBarSelectionState
<
String
>
selection
=
TabBarSelection
.
of
(
tester
.
elementTreeTester
.
findText
(
'A'
));
expect
(
selection
,
isNotNull
);
expect
(
tester
.
findText
(
'A'
),
isNotNull
);
expect
(
tester
.
findText
(
'B'
),
isNotNull
);
expect
(
tester
.
findText
(
'C'
),
isNotNull
);
expect
(
tester
,
hasWidget
(
find
.
text
(
'A'
))
);
expect
(
tester
,
hasWidget
(
find
.
text
(
'B'
))
);
expect
(
tester
,
hasWidget
(
find
.
text
(
'C'
))
);
expect
(
selection
.
value
,
equals
(
'C'
));
tester
.
pumpWidget
(
buildFrame
(
tabs:
tabs
,
value:
'C'
,
isScrollable:
true
));
tester
.
tap
(
tester
.
findT
ext
(
'B'
));
tester
.
tap
(
find
.
t
ext
(
'B'
));
tester
.
pump
();
expect
(
selection
.
value
,
equals
(
'B'
));
tester
.
pumpWidget
(
buildFrame
(
tabs:
tabs
,
value:
'C'
,
isScrollable:
true
));
tester
.
tap
(
tester
.
findT
ext
(
'C'
));
tester
.
tap
(
find
.
t
ext
(
'C'
));
tester
.
pump
();
expect
(
selection
.
value
,
equals
(
'C'
));
tester
.
pumpWidget
(
buildFrame
(
tabs:
tabs
,
value:
'C'
,
isScrollable:
true
));
tester
.
tap
(
tester
.
findT
ext
(
'A'
));
tester
.
tap
(
find
.
t
ext
(
'A'
));
tester
.
pump
();
expect
(
selection
.
value
,
equals
(
'A'
));
});
...
...
@@ -125,20 +125,20 @@ void main() {
List
<
String
>
tabs
=
<
String
>[
'AAAAAA'
,
'BBBBBB'
,
'CCCCCC'
,
'DDDDDD'
,
'EEEEEE'
,
'FFFFFF'
,
'GGGGGG'
,
'HHHHHH'
,
'IIIIII'
,
'JJJJJJ'
,
'KKKKKK'
,
'LLLLLL'
];
Key
tabBarKey
=
new
Key
(
'TabBar'
);
tester
.
pumpWidget
(
buildFrame
(
tabs:
tabs
,
value:
'AAAAAA'
,
isScrollable:
true
,
tabBarKey:
tabBarKey
));
TabBarSelectionState
<
String
>
selection
=
TabBarSelection
.
of
(
tester
.
findText
(
'AAAAAA'
));
TabBarSelectionState
<
String
>
selection
=
TabBarSelection
.
of
(
tester
.
elementTreeTester
.
findText
(
'AAAAAA'
));
expect
(
selection
,
isNotNull
);
expect
(
selection
.
value
,
equals
(
'AAAAAA'
));
expect
(
tester
.
getSize
(
tester
.
findElementB
yKey
(
tabBarKey
)).
width
,
equals
(
800.0
));
expect
(
tester
.
getSize
(
find
.
b
yKey
(
tabBarKey
)).
width
,
equals
(
800.0
));
// The center of the FFFFFF item is to the right of the TabBar's center
expect
(
tester
.
getCenter
(
tester
.
findT
ext
(
'FFFFFF'
)).
x
,
greaterThan
(
401.0
));
expect
(
tester
.
getCenter
(
find
.
t
ext
(
'FFFFFF'
)).
x
,
greaterThan
(
401.0
));
tester
.
tap
(
tester
.
findT
ext
(
'FFFFFF'
));
tester
.
tap
(
find
.
t
ext
(
'FFFFFF'
));
tester
.
pump
();
tester
.
pump
(
const
Duration
(
seconds:
1
));
// finish the scroll animation
expect
(
selection
.
value
,
equals
(
'FFFFFF'
));
// The center of the FFFFFF item is now at the TabBar's center
expect
(
tester
.
getCenter
(
tester
.
findT
ext
(
'FFFFFF'
)).
x
,
closeTo
(
400.0
,
1.0
));
expect
(
tester
.
getCenter
(
find
.
t
ext
(
'FFFFFF'
)).
x
,
closeTo
(
400.0
,
1.0
));
});
});
...
...
@@ -148,16 +148,16 @@ void main() {
List
<
String
>
tabs
=
<
String
>[
'AAAAAA'
,
'BBBBBB'
,
'CCCCCC'
,
'DDDDDD'
,
'EEEEEE'
,
'FFFFFF'
,
'GGGGGG'
,
'HHHHHH'
,
'IIIIII'
,
'JJJJJJ'
,
'KKKKKK'
,
'LLLLLL'
];
Key
tabBarKey
=
new
Key
(
'TabBar'
);
tester
.
pumpWidget
(
buildFrame
(
tabs:
tabs
,
value:
'AAAAAA'
,
isScrollable:
true
,
tabBarKey:
tabBarKey
));
TabBarSelectionState
<
String
>
selection
=
TabBarSelection
.
of
(
tester
.
findText
(
'AAAAAA'
));
TabBarSelectionState
<
String
>
selection
=
TabBarSelection
.
of
(
tester
.
elementTreeTester
.
findText
(
'AAAAAA'
));
expect
(
selection
,
isNotNull
);
expect
(
selection
.
value
,
equals
(
'AAAAAA'
));
// Fling-scroll the TabBar to the left
expect
(
tester
.
getCenter
(
tester
.
findT
ext
(
'HHHHHH'
)).
x
,
lessThan
(
700.0
));
tester
.
fling
(
tester
.
findElementB
yKey
(
tabBarKey
),
const
Offset
(-
20.0
,
0.0
),
1000.0
);
expect
(
tester
.
getCenter
(
find
.
t
ext
(
'HHHHHH'
)).
x
,
lessThan
(
700.0
));
tester
.
fling
(
find
.
b
yKey
(
tabBarKey
),
const
Offset
(-
20.0
,
0.0
),
1000.0
);
tester
.
pump
();
tester
.
pump
(
const
Duration
(
seconds:
1
));
// finish the scroll animation
expect
(
tester
.
getCenter
(
tester
.
findT
ext
(
'HHHHHH'
)).
x
,
lessThan
(
500.0
));
expect
(
tester
.
getCenter
(
find
.
t
ext
(
'HHHHHH'
)).
x
,
lessThan
(
500.0
));
// Scrolling the TabBar doesn't change the selection
expect
(
selection
.
value
,
equals
(
'AAAAAA'
));
...
...
@@ -191,22 +191,11 @@ void main() {
}
StateMarkerState
findStateMarkerState
(
String
name
)
{
Element
secondLabel
=
tester
.
findText
(
name
);
expect
(
secondLabel
,
isNotNull
);
StatefulElement
secondMarker
;
secondLabel
.
visitAncestorElements
((
Element
element
)
{
if
(
element
.
widget
is
StateMarker
)
{
secondMarker
=
element
;
return
false
;
}
return
true
;
});
expect
(
secondMarker
,
isNotNull
);
return
secondMarker
.
state
;
return
tester
.
stateOf
(
find
.
widgetWithText
(
StateMarker
,
name
));
}
tester
.
pumpWidget
(
builder
());
TestGesture
gesture
=
tester
.
startGesture
(
tester
.
getCenter
(
tester
.
findT
ext
(
tabs
[
0
])));
TestGesture
gesture
=
tester
.
startGesture
(
tester
.
getCenter
(
find
.
t
ext
(
tabs
[
0
])));
gesture
.
moveBy
(
new
Offset
(-
600.0
,
0.0
));
tester
.
pump
();
expect
(
value
,
equals
(
tabs
[
0
]));
...
...
@@ -220,7 +209,7 @@ void main() {
// Move to the third tab.
gesture
=
tester
.
startGesture
(
tester
.
getCenter
(
tester
.
findT
ext
(
tabs
[
1
])));
gesture
=
tester
.
startGesture
(
tester
.
getCenter
(
find
.
t
ext
(
tabs
[
1
])));
gesture
.
moveBy
(
new
Offset
(-
600.0
,
0.0
));
gesture
.
up
();
tester
.
pump
();
...
...
@@ -231,11 +220,11 @@ void main() {
// The state is now gone.
expect
(
tester
.
findText
(
tabs
[
1
]),
isNull
);
expect
(
tester
,
doesNotHaveWidget
(
find
.
text
(
tabs
[
1
]))
);
// Move back to the second tab.
gesture
=
tester
.
startGesture
(
tester
.
getCenter
(
tester
.
findT
ext
(
tabs
[
2
])));
gesture
=
tester
.
startGesture
(
tester
.
getCenter
(
find
.
t
ext
(
tabs
[
2
])));
gesture
.
moveBy
(
new
Offset
(
600.0
,
0.0
));
tester
.
pump
();
StateMarkerState
markerState
=
findStateMarkerState
(
tabs
[
1
]);
...
...
packages/flutter/test/widget/animated_container_test.dart
View file @
f3a4f722
...
...
@@ -102,7 +102,7 @@ void main() {
});
test
(
'Animation rerun'
,
()
{
test
Widgets
((
Widget
Tester
tester
)
{
test
ElementTree
((
ElementTree
Tester
tester
)
{
tester
.
pumpWidget
(
new
Center
(
child:
new
AnimatedContainer
(
...
...
packages/flutter/test/widget/aspect_ratio_test.dart
View file @
f3a4f722
...
...
@@ -7,7 +7,7 @@ import 'package:flutter/rendering.dart';
import
'package:flutter/widgets.dart'
;
import
'package:test/test.dart'
;
Size
_getSize
(
Widget
Tester
tester
,
BoxConstraints
constraints
,
double
aspectRatio
)
{
Size
_getSize
(
ElementTree
Tester
tester
,
BoxConstraints
constraints
,
double
aspectRatio
)
{
Key
childKey
=
new
UniqueKey
();
tester
.
pumpWidget
(
new
Center
(
...
...
@@ -28,14 +28,14 @@ Size _getSize(WidgetTester tester, BoxConstraints constraints, double aspectRati
void
main
(
)
{
test
(
'Aspect ratio control test'
,
()
{
test
Widgets
((
Widget
Tester
tester
)
{
test
ElementTree
((
ElementTree
Tester
tester
)
{
expect
(
_getSize
(
tester
,
new
BoxConstraints
.
loose
(
new
Size
(
500.0
,
500.0
)),
2.0
),
equals
(
new
Size
(
500.0
,
250.0
)));
expect
(
_getSize
(
tester
,
new
BoxConstraints
.
loose
(
new
Size
(
500.0
,
500.0
)),
0.5
),
equals
(
new
Size
(
250.0
,
500.0
)));
});
});
test
(
'Aspect ratio infinite width'
,
()
{
test
Widgets
((
Widget
Tester
tester
)
{
test
ElementTree
((
ElementTree
Tester
tester
)
{
Key
childKey
=
new
UniqueKey
();
tester
.
pumpWidget
(
new
Center
(
...
...
packages/flutter/test/widget/asset_vendor_test.dart
View file @
f3a4f722
...
...
@@ -120,15 +120,15 @@ Widget buildImageAtRatio(String image, Key key, double ratio, bool inferSize) {
);
}
RenderImage
getRenderImage
(
Widget
Tester
tester
,
Key
key
)
{
RenderImage
getRenderImage
(
ElementTree
Tester
tester
,
Key
key
)
{
return
tester
.
findElementByKey
(
key
).
renderObject
;
}
TestImage
getTestImage
(
Widget
Tester
tester
,
Key
key
)
{
TestImage
getTestImage
(
ElementTree
Tester
tester
,
Key
key
)
{
return
getRenderImage
(
tester
,
key
).
image
;
}
void
pumpTreeToLayout
(
Widget
Tester
tester
,
Widget
widget
)
{
void
pumpTreeToLayout
(
ElementTree
Tester
tester
,
Widget
widget
)
{
Duration
pumpDuration
=
const
Duration
(
milliseconds:
0
);
EnginePhase
pumpPhase
=
EnginePhase
.
layout
;
tester
.
pumpWidget
(
widget
,
pumpDuration
,
pumpPhase
);
...
...
@@ -139,7 +139,7 @@ void main() {
test
(
'Image for device pixel ratio 1.0'
,
()
{
const
double
ratio
=
1.0
;
test
Widgets
((
Widget
Tester
tester
)
{
test
ElementTree
((
ElementTree
Tester
tester
)
{
Key
key
=
new
GlobalKey
();
pumpTreeToLayout
(
tester
,
buildImageAtRatio
(
image
,
key
,
ratio
,
false
));
expect
(
getRenderImage
(
tester
,
key
).
size
,
const
Size
(
200.0
,
200.0
));
...
...
@@ -153,7 +153,7 @@ void main() {
test
(
'Image for device pixel ratio 0.5'
,
()
{
const
double
ratio
=
0.5
;
test
Widgets
((
Widget
Tester
tester
)
{
test
ElementTree
((
ElementTree
Tester
tester
)
{
Key
key
=
new
GlobalKey
();
pumpTreeToLayout
(
tester
,
buildImageAtRatio
(
image
,
key
,
ratio
,
false
));
expect
(
getRenderImage
(
tester
,
key
).
size
,
const
Size
(
200.0
,
200.0
));
...
...
@@ -167,7 +167,7 @@ void main() {
test
(
'Image for device pixel ratio 1.5'
,
()
{
const
double
ratio
=
1.5
;
test
Widgets
((
Widget
Tester
tester
)
{
test
ElementTree
((
ElementTree
Tester
tester
)
{
Key
key
=
new
GlobalKey
();
pumpTreeToLayout
(
tester
,
buildImageAtRatio
(
image
,
key
,
ratio
,
false
));
expect
(
getRenderImage
(
tester
,
key
).
size
,
const
Size
(
200.0
,
200.0
));
...
...
@@ -181,7 +181,7 @@ void main() {
test
(
'Image for device pixel ratio 1.75'
,
()
{
const
double
ratio
=
1.75
;
test
Widgets
((
Widget
Tester
tester
)
{
test
ElementTree
((
ElementTree
Tester
tester
)
{
Key
key
=
new
GlobalKey
();
pumpTreeToLayout
(
tester
,
buildImageAtRatio
(
image
,
key
,
ratio
,
false
));
expect
(
getRenderImage
(
tester
,
key
).
size
,
const
Size
(
200.0
,
200.0
));
...
...
@@ -195,7 +195,7 @@ void main() {
test
(
'Image for device pixel ratio 2.3'
,
()
{
const
double
ratio
=
2.3
;
test
Widgets
((
Widget
Tester
tester
)
{
test
ElementTree
((
ElementTree
Tester
tester
)
{
Key
key
=
new
GlobalKey
();
pumpTreeToLayout
(
tester
,
buildImageAtRatio
(
image
,
key
,
ratio
,
false
));
expect
(
getRenderImage
(
tester
,
key
).
size
,
const
Size
(
200.0
,
200.0
));
...
...
@@ -209,7 +209,7 @@ void main() {
test
(
'Image for device pixel ratio 3.7'
,
()
{
const
double
ratio
=
3.7
;
test
Widgets
((
Widget
Tester
tester
)
{
test
ElementTree
((
ElementTree
Tester
tester
)
{
Key
key
=
new
GlobalKey
();
pumpTreeToLayout
(
tester
,
buildImageAtRatio
(
image
,
key
,
ratio
,
false
));
expect
(
getRenderImage
(
tester
,
key
).
size
,
const
Size
(
200.0
,
200.0
));
...
...
@@ -223,7 +223,7 @@ void main() {
test
(
'Image for device pixel ratio 5.1'
,
()
{
const
double
ratio
=
5.1
;
test
Widgets
((
Widget
Tester
tester
)
{
test
ElementTree
((
ElementTree
Tester
tester
)
{
Key
key
=
new
GlobalKey
();
pumpTreeToLayout
(
tester
,
buildImageAtRatio
(
image
,
key
,
ratio
,
false
));
expect
(
getRenderImage
(
tester
,
key
).
size
,
const
Size
(
200.0
,
200.0
));
...
...
packages/flutter/test/widget/block_test.dart
View file @
f3a4f722
...
...
@@ -23,14 +23,14 @@ void main() {
)
);
Point
middleOfContainer
=
tester
.
getCenter
(
tester
.
findT
ext
(
'Hello'
));
Point
target
=
tester
.
getCenter
(
tester
.
findElementB
yKey
(
blockKey
));
Point
middleOfContainer
=
tester
.
getCenter
(
find
.
t
ext
(
'Hello'
));
Point
target
=
tester
.
getCenter
(
find
.
b
yKey
(
blockKey
));
TestGesture
gesture
=
tester
.
startGesture
(
target
);
gesture
.
moveBy
(
const
Offset
(
0.0
,
-
10.0
));
tester
.
pump
(
const
Duration
(
milliseconds:
1
));
expect
(
tester
.
getCenter
(
tester
.
findT
ext
(
'Hello'
))
==
middleOfContainer
,
isTrue
);
expect
(
tester
.
getCenter
(
find
.
t
ext
(
'Hello'
))
==
middleOfContainer
,
isTrue
);
gesture
.
up
();
});
...
...
@@ -50,17 +50,17 @@ void main() {
)
);
Point
middleOfContainer
=
tester
.
getCenter
(
tester
.
findT
ext
(
'Hello'
));
Point
middleOfContainer
=
tester
.
getCenter
(
find
.
t
ext
(
'Hello'
));
expect
(
middleOfContainer
.
x
,
equals
(
400.0
));
expect
(
middleOfContainer
.
y
,
equals
(
1000.0
));
Point
target
=
tester
.
getCenter
(
tester
.
findElementB
yKey
(
blockKey
));
Point
target
=
tester
.
getCenter
(
find
.
b
yKey
(
blockKey
));
TestGesture
gesture
=
tester
.
startGesture
(
target
);
gesture
.
moveBy
(
const
Offset
(
0.0
,
-
10.0
));
tester
.
pump
();
// redo layout
expect
(
tester
.
getCenter
(
tester
.
findT
ext
(
'Hello'
)),
isNot
(
equals
(
middleOfContainer
)));
expect
(
tester
.
getCenter
(
find
.
t
ext
(
'Hello'
)),
isNot
(
equals
(
middleOfContainer
)));
gesture
.
up
();
});
...
...
packages/flutter/test/widget/bottom_sheet_test.dart
View file @
f3a4f722
...
...
@@ -23,7 +23,7 @@ void main() {
));
tester
.
pump
();
expect
(
tester
.
findText
(
'BottomSheet'
),
isNull
);
expect
(
tester
,
doesNotHaveWidget
(
find
.
text
(
'BottomSheet'
))
);
showModalBottomSheet
/*<Null>*/
(
context:
context
,
...
...
@@ -35,28 +35,28 @@ void main() {
tester
.
pump
();
// bottom sheet show animation starts
tester
.
pump
(
new
Duration
(
seconds:
1
));
// animation done
expect
(
tester
.
findText
(
'BottomSheet'
),
isNotNull
);
expect
(
tester
,
hasWidget
(
find
.
text
(
'BottomSheet'
))
);
expect
(
showBottomSheetThenCalled
,
isFalse
);
// Tap on the the bottom sheet itself to dismiss it
tester
.
tap
(
tester
.
findT
ext
(
'BottomSheet'
));
tester
.
tap
(
find
.
t
ext
(
'BottomSheet'
));
tester
.
pump
();
// bottom sheet dismiss animation starts
expect
(
showBottomSheetThenCalled
,
isTrue
);
tester
.
pump
(
new
Duration
(
seconds:
1
));
// last frame of animation (sheet is entirely off-screen, but still present)
tester
.
pump
(
new
Duration
(
seconds:
1
));
// frame after the animation (sheet has been removed)
expect
(
tester
.
findText
(
'BottomSheet'
),
isNull
);
expect
(
tester
,
doesNotHaveWidget
(
find
.
text
(
'BottomSheet'
))
);
showModalBottomSheet
/*<Null>*/
(
context:
context
,
builder:
(
BuildContext
context
)
=>
new
Text
(
'BottomSheet'
));
tester
.
pump
();
// bottom sheet show animation starts
tester
.
pump
(
new
Duration
(
seconds:
1
));
// animation done
expect
(
tester
.
findText
(
'BottomSheet'
),
isNotNull
);
expect
(
tester
,
hasWidget
(
find
.
text
(
'BottomSheet'
))
);
// Tap above the the bottom sheet to dismiss it
tester
.
tapAt
(
new
Point
(
20.0
,
20.0
));
tester
.
pump
();
// bottom sheet dismiss animation starts
tester
.
pump
(
new
Duration
(
seconds:
1
));
// animation done
tester
.
pump
(
new
Duration
(
seconds:
1
));
// rebuild frame
expect
(
tester
.
findText
(
'BottomSheet'
),
isNull
);
expect
(
tester
,
doesNotHaveWidget
(
find
.
text
(
'BottomSheet'
))
);
});
});
...
...
@@ -77,7 +77,7 @@ void main() {
));
expect
(
showBottomSheetThenCalled
,
isFalse
);
expect
(
tester
.
findText
(
'BottomSheet'
),
isNull
);
expect
(
tester
,
doesNotHaveWidget
(
find
.
text
(
'BottomSheet'
))
);
scaffoldKey
.
currentState
.
showBottomSheet
((
BuildContext
context
)
{
return
new
Container
(
...
...
@@ -89,33 +89,33 @@ void main() {
});
expect
(
showBottomSheetThenCalled
,
isFalse
);
expect
(
tester
.
findText
(
'BottomSheet'
),
isNull
);
expect
(
tester
,
doesNotHaveWidget
(
find
.
text
(
'BottomSheet'
))
);
tester
.
pump
();
// bottom sheet show animation starts
expect
(
showBottomSheetThenCalled
,
isFalse
);
expect
(
tester
.
findText
(
'BottomSheet'
),
isNotNull
);
expect
(
tester
,
hasWidget
(
find
.
text
(
'BottomSheet'
))
);
tester
.
pump
(
new
Duration
(
seconds:
1
));
// animation done
expect
(
showBottomSheetThenCalled
,
isFalse
);
expect
(
tester
.
findText
(
'BottomSheet'
),
isNotNull
);
expect
(
tester
,
hasWidget
(
find
.
text
(
'BottomSheet'
))
);
tester
.
fling
(
tester
.
findT
ext
(
'BottomSheet'
),
const
Offset
(
0.0
,
20.0
),
1000.0
);
tester
.
fling
(
find
.
t
ext
(
'BottomSheet'
),
const
Offset
(
0.0
,
20.0
),
1000.0
);
tester
.
pump
();
// drain the microtask queue (Future completion callback)
expect
(
showBottomSheetThenCalled
,
isTrue
);
expect
(
tester
.
findText
(
'BottomSheet'
),
isNotNull
);
expect
(
tester
,
hasWidget
(
find
.
text
(
'BottomSheet'
))
);
tester
.
pump
();
// bottom sheet dismiss animation starts
expect
(
showBottomSheetThenCalled
,
isTrue
);
expect
(
tester
.
findText
(
'BottomSheet'
),
isNotNull
);
expect
(
tester
,
hasWidget
(
find
.
text
(
'BottomSheet'
))
);
tester
.
pump
(
new
Duration
(
seconds:
1
));
// animation done
expect
(
showBottomSheetThenCalled
,
isTrue
);
expect
(
tester
.
findText
(
'BottomSheet'
),
isNull
);
expect
(
tester
,
doesNotHaveWidget
(
find
.
text
(
'BottomSheet'
))
);
});
});
...
...
packages/flutter/test/widget/box_decoration_test.dart
View file @
f3a4f722
...
...
@@ -38,7 +38,7 @@ void main() {
)
)
);
expect
(
tester
.
getSize
(
tester
.
findElementB
yKey
(
key
)),
equals
(
const
Size
(
45.0
,
45.0
)));
expect
(
tester
.
getSize
(
find
.
b
yKey
(
key
)),
equals
(
const
Size
(
45.0
,
45.0
)));
});
});
}
packages/flutter/test/widget/coordinates_test.dart
View file @
f3a4f722
...
...
@@ -9,7 +9,7 @@ import 'package:test/test.dart';
void
main
(
)
{
test
(
'Comparing coordinates'
,
()
{
test
Widgets
((
Widget
Tester
tester
)
{
test
ElementTree
((
ElementTree
Tester
tester
)
{
Key
keyA
=
new
GlobalKey
();
Key
keyB
=
new
GlobalKey
();
...
...
packages/flutter/test/widget/custom_multi_child_layout_test.dart
View file @
f3a4f722
...
...
@@ -146,7 +146,7 @@ void main() {
});
test
(
'Loose constraints'
,
()
{
test
Widgets
((
Widget
Tester
tester
)
{
test
ElementTree
((
ElementTree
Tester
tester
)
{
Key
key
=
new
UniqueKey
();
tester
.
pumpWidget
(
new
Center
(
child:
new
CustomMultiChildLayout
(
...
...
packages/flutter/test/widget/date_picker_test_disabled.dart
View file @
f3a4f722
...
...
@@ -29,12 +29,12 @@ void main() {
tester
.
pumpWidget
(
widget
);
expect
(
currentValue
,
isNull
);
tester
.
tap
(
tester
.
findT
ext
(
'2015'
));
tester
.
tap
(
find
.
t
ext
(
'2015'
));
tester
.
pumpWidget
(
widget
);
tester
.
tap
(
tester
.
findT
ext
(
'2014'
));
tester
.
tap
(
find
.
t
ext
(
'2014'
));
tester
.
pumpWidget
(
widget
);
expect
(
currentValue
,
equals
(
new
DateTime
(
2014
,
6
,
9
)));
tester
.
tap
(
tester
.
findT
ext
(
'30'
));
tester
.
tap
(
find
.
t
ext
(
'30'
));
expect
(
currentValue
,
equals
(
new
DateTime
(
2013
,
1
,
30
)));
});
});
...
...
packages/flutter/test/widget/dismissable_test.dart
View file @
f3a4f722
...
...
@@ -52,8 +52,8 @@ Widget widgetBuilder() {
);
}
void
dismissElement
(
WidgetTester
tester
,
Element
itemElement
,
{
DismissDirection
gestureDirection
})
{
assert
(
itemElement
!=
null
);
void
dismissElement
(
WidgetTester
tester
,
Finder
finder
,
{
DismissDirection
gestureDirection
})
{
assert
(
tester
.
exists
(
finder
)
);
assert
(
gestureDirection
!=
DismissDirection
.
horizontal
);
assert
(
gestureDirection
!=
DismissDirection
.
vertical
);
...
...
@@ -63,24 +63,24 @@ void dismissElement(WidgetTester tester, Element itemElement, { DismissDirection
case
DismissDirection
.
endToStart
:
// getTopRight() returns a point that's just beyond itemWidget's right
// edge and outside the Dismissable event listener's bounds.
downLocation
=
tester
.
getTopRight
(
itemElement
)
+
const
Offset
(-
0.1
,
0.0
);
upLocation
=
tester
.
getTopLeft
(
itemElement
);
downLocation
=
tester
.
getTopRight
(
finder
)
+
const
Offset
(-
0.1
,
0.0
);
upLocation
=
tester
.
getTopLeft
(
finder
);
break
;
case
DismissDirection
.
startToEnd
:
// we do the same thing here to keep the test symmetric
downLocation
=
tester
.
getTopLeft
(
itemElement
)
+
const
Offset
(
0.1
,
0.0
);
upLocation
=
tester
.
getTopRight
(
itemElement
);
downLocation
=
tester
.
getTopLeft
(
finder
)
+
const
Offset
(
0.1
,
0.0
);
upLocation
=
tester
.
getTopRight
(
finder
);
break
;
case
DismissDirection
.
up
:
// getBottomLeft() returns a point that's just below itemWidget's bottom
// edge and outside the Dismissable event listener's bounds.
downLocation
=
tester
.
getBottomLeft
(
itemElement
)
+
const
Offset
(
0.0
,
-
0.1
);
upLocation
=
tester
.
getTopLeft
(
itemElement
);
downLocation
=
tester
.
getBottomLeft
(
finder
)
+
const
Offset
(
0.0
,
-
0.1
);
upLocation
=
tester
.
getTopLeft
(
finder
);
break
;
case
DismissDirection
.
down
:
// again with doing the same here for symmetry
downLocation
=
tester
.
getTopLeft
(
itemElement
)
+
const
Offset
(
0.1
,
0.0
);
upLocation
=
tester
.
getBottomLeft
(
itemElement
);
downLocation
=
tester
.
getTopLeft
(
finder
)
+
const
Offset
(
0.1
,
0.0
);
upLocation
=
tester
.
getBottomLeft
(
finder
);
break
;
default
:
fail
(
"unsupported gestureDirection"
);
...
...
@@ -95,10 +95,10 @@ void dismissItem(WidgetTester tester, int item, { DismissDirection gestureDirect
assert
(
gestureDirection
!=
DismissDirection
.
horizontal
);
assert
(
gestureDirection
!=
DismissDirection
.
vertical
);
Element
itemElement
=
tester
.
findT
ext
(
item
.
toString
());
expect
(
itemElement
,
isNotNull
);
Finder
itemFinder
=
find
.
t
ext
(
item
.
toString
());
expect
(
tester
,
hasWidget
(
itemFinder
)
);
dismissElement
(
tester
,
item
Element
,
gestureDirection:
gestureDirection
);
dismissElement
(
tester
,
item
Finder
,
gestureDirection:
gestureDirection
);
tester
.
pumpWidget
(
widgetBuilder
());
// start the slide
tester
.
pumpWidget
(
widgetBuilder
(),
const
Duration
(
seconds:
1
));
// finish the slide and start shrinking...
...
...
@@ -139,12 +139,12 @@ void main() {
expect
(
dismissedItems
,
isEmpty
);
dismissItem
(
tester
,
0
,
gestureDirection:
DismissDirection
.
startToEnd
);
expect
(
tester
.
findText
(
'0'
),
isNull
);
expect
(
tester
,
doesNotHaveWidget
(
find
.
text
(
'0'
))
);
expect
(
dismissedItems
,
equals
([
0
]));
expect
(
reportedDismissDirection
,
DismissDirection
.
startToEnd
);
dismissItem
(
tester
,
1
,
gestureDirection:
DismissDirection
.
endToStart
);
expect
(
tester
.
findText
(
'1'
),
isNull
);
expect
(
tester
,
doesNotHaveWidget
(
find
.
text
(
'1'
))
);
expect
(
dismissedItems
,
equals
([
0
,
1
]));
expect
(
reportedDismissDirection
,
DismissDirection
.
endToStart
);
});
...
...
@@ -159,12 +159,12 @@ void main() {
expect
(
dismissedItems
,
isEmpty
);
dismissItem
(
tester
,
0
,
gestureDirection:
DismissDirection
.
up
);
expect
(
tester
.
findText
(
'0'
),
isNull
);
expect
(
tester
,
doesNotHaveWidget
(
find
.
text
(
'0'
))
);
expect
(
dismissedItems
,
equals
([
0
]));
expect
(
reportedDismissDirection
,
DismissDirection
.
up
);
dismissItem
(
tester
,
1
,
gestureDirection:
DismissDirection
.
down
);
expect
(
tester
.
findText
(
'1'
),
isNull
);
expect
(
tester
,
doesNotHaveWidget
(
find
.
text
(
'1'
))
);
expect
(
dismissedItems
,
equals
([
0
,
1
]));
expect
(
reportedDismissDirection
,
DismissDirection
.
down
);
});
...
...
@@ -179,12 +179,12 @@ void main() {
expect
(
dismissedItems
,
isEmpty
);
dismissItem
(
tester
,
0
,
gestureDirection:
DismissDirection
.
startToEnd
);
expect
(
tester
.
findText
(
'0'
),
isNotNull
);
expect
(
tester
,
hasWidget
(
find
.
text
(
'0'
))
);
expect
(
dismissedItems
,
isEmpty
);
dismissItem
(
tester
,
1
,
gestureDirection:
DismissDirection
.
startToEnd
);
dismissItem
(
tester
,
0
,
gestureDirection:
DismissDirection
.
endToStart
);
expect
(
tester
.
findText
(
'0'
),
isNull
);
expect
(
tester
,
doesNotHaveWidget
(
find
.
text
(
'0'
))
);
expect
(
dismissedItems
,
equals
([
0
]));
dismissItem
(
tester
,
1
,
gestureDirection:
DismissDirection
.
endToStart
);
});
...
...
@@ -199,11 +199,11 @@ void main() {
expect
(
dismissedItems
,
isEmpty
);
dismissItem
(
tester
,
0
,
gestureDirection:
DismissDirection
.
endToStart
);
expect
(
tester
.
findText
(
'0'
),
isNotNull
);
expect
(
tester
,
hasWidget
(
find
.
text
(
'0'
))
);
expect
(
dismissedItems
,
isEmpty
);
dismissItem
(
tester
,
0
,
gestureDirection:
DismissDirection
.
startToEnd
);
expect
(
tester
.
findText
(
'0'
),
isNull
);
expect
(
tester
,
doesNotHaveWidget
(
find
.
text
(
'0'
))
);
expect
(
dismissedItems
,
equals
([
0
]));
});
});
...
...
@@ -217,11 +217,11 @@ void main() {
expect
(
dismissedItems
,
isEmpty
);
dismissItem
(
tester
,
0
,
gestureDirection:
DismissDirection
.
down
);
expect
(
tester
.
findText
(
'0'
),
isNotNull
);
expect
(
tester
,
hasWidget
(
find
.
text
(
'0'
))
);
expect
(
dismissedItems
,
isEmpty
);
dismissItem
(
tester
,
0
,
gestureDirection:
DismissDirection
.
up
);
expect
(
tester
.
findText
(
'0'
),
isNull
);
expect
(
tester
,
doesNotHaveWidget
(
find
.
text
(
'0'
))
);
expect
(
dismissedItems
,
equals
([
0
]));
});
});
...
...
@@ -235,11 +235,11 @@ void main() {
expect
(
dismissedItems
,
isEmpty
);
dismissItem
(
tester
,
0
,
gestureDirection:
DismissDirection
.
up
);
expect
(
tester
.
findText
(
'0'
),
isNotNull
);
expect
(
tester
,
hasWidget
(
find
.
text
(
'0'
))
);
expect
(
dismissedItems
,
isEmpty
);
dismissItem
(
tester
,
0
,
gestureDirection:
DismissDirection
.
down
);
expect
(
tester
.
findText
(
'0'
),
isNull
);
expect
(
tester
,
doesNotHaveWidget
(
find
.
text
(
'0'
))
);
expect
(
dismissedItems
,
equals
([
0
]));
});
});
...
...
@@ -256,9 +256,7 @@ void main() {
dismissDirection
=
DismissDirection
.
down
;
tester
.
pumpWidget
(
widgetBuilder
());
Element
itemElement
=
tester
.
findText
(
'0'
);
Point
location
=
tester
.
getTopLeft
(
itemElement
);
Point
location
=
tester
.
getTopLeft
(
find
.
text
(
'0'
));
Offset
offset
=
new
Offset
(
0.0
,
5.0
);
TestGesture
gesture
=
tester
.
startGesture
(
location
,
pointer:
5
);
gesture
.
moveBy
(
offset
);
...
...
@@ -293,18 +291,18 @@ void main() {
)
)
));
expect
(
tester
.
findText
(
'1'
),
isNotNull
);
expect
(
tester
.
findText
(
'2'
),
isNotNull
);
dismissElement
(
tester
,
tester
.
findT
ext
(
'2'
),
gestureDirection:
DismissDirection
.
startToEnd
);
expect
(
tester
,
hasWidget
(
find
.
text
(
'1'
))
);
expect
(
tester
,
hasWidget
(
find
.
text
(
'2'
))
);
dismissElement
(
tester
,
find
.
t
ext
(
'2'
),
gestureDirection:
DismissDirection
.
startToEnd
);
tester
.
pump
();
// start the slide away
tester
.
pump
(
new
Duration
(
seconds:
1
));
// finish the slide away
expect
(
tester
.
findText
(
'1'
),
isNotNull
);
expect
(
tester
.
findText
(
'2'
),
isNull
);
dismissElement
(
tester
,
tester
.
findT
ext
(
'1'
),
gestureDirection:
DismissDirection
.
startToEnd
);
expect
(
tester
,
hasWidget
(
find
.
text
(
'1'
))
);
expect
(
tester
,
doesNotHaveWidget
(
find
.
text
(
'2'
))
);
dismissElement
(
tester
,
find
.
t
ext
(
'1'
),
gestureDirection:
DismissDirection
.
startToEnd
);
tester
.
pump
();
// start the slide away
tester
.
pump
(
new
Duration
(
seconds:
1
));
// finish the slide away (at which point the child is no longer included in the tree)
expect
(
tester
.
findText
(
'1'
),
isNull
);
expect
(
tester
.
findText
(
'2'
),
isNull
);
expect
(
tester
,
doesNotHaveWidget
(
find
.
text
(
'1'
))
);
expect
(
tester
,
doesNotHaveWidget
(
find
.
text
(
'2'
))
);
});
});
...
...
@@ -317,13 +315,12 @@ void main() {
tester
.
pumpWidget
(
widgetBuilder
());
expect
(
dismissedItems
,
isEmpty
);
Element
itemElement
=
tester
.
findText
(
0
.
toString
()
);
expect
(
itemElement
,
isNotNull
);
dismissElement
(
tester
,
item
Element
,
gestureDirection:
DismissDirection
.
startToEnd
);
Finder
itemFinder
=
find
.
text
(
'0'
);
expect
(
tester
,
hasWidget
(
itemFinder
)
);
dismissElement
(
tester
,
item
Finder
,
gestureDirection:
DismissDirection
.
startToEnd
);
tester
.
pump
();
Element
backgroundElement
=
tester
.
findText
(
'background'
);
RenderBox
backgroundBox
=
backgroundElement
.
findRenderObject
();
RenderBox
backgroundBox
=
tester
.
renderObjectOf
(
find
.
text
(
'background'
));
expect
(
backgroundBox
.
size
.
height
,
equals
(
100.0
));
});
});
...
...
packages/flutter/test/widget/draggable_test.dart
View file @
f3a4f722
...
...
@@ -29,35 +29,35 @@ void main() {
}));
expect
(
accepted
,
isEmpty
);
expect
(
tester
.
findText
(
'Source'
),
isNotNull
);
expect
(
tester
.
findText
(
'Dragging'
),
isNull
);
expect
(
tester
.
findText
(
'Target'
),
isNotNull
);
expect
(
tester
,
hasWidget
(
find
.
text
(
'Source'
))
);
expect
(
tester
,
doesNotHaveWidget
(
find
.
text
(
'Dragging'
))
);
expect
(
tester
,
hasWidget
(
find
.
text
(
'Target'
))
);
Point
firstLocation
=
tester
.
getCenter
(
tester
.
findT
ext
(
'Source'
));
Point
firstLocation
=
tester
.
getCenter
(
find
.
t
ext
(
'Source'
));
TestGesture
gesture
=
tester
.
startGesture
(
firstLocation
,
pointer:
7
);
tester
.
pump
();
expect
(
accepted
,
isEmpty
);
expect
(
tester
.
findText
(
'Source'
),
isNotNull
);
expect
(
tester
.
findText
(
'Dragging'
),
isNotNull
);
expect
(
tester
.
findText
(
'Target'
),
isNotNull
);
expect
(
tester
,
hasWidget
(
find
.
text
(
'Source'
))
);
expect
(
tester
,
hasWidget
(
find
.
text
(
'Dragging'
))
);
expect
(
tester
,
hasWidget
(
find
.
text
(
'Target'
))
);
Point
secondLocation
=
tester
.
getCenter
(
tester
.
findT
ext
(
'Target'
));
Point
secondLocation
=
tester
.
getCenter
(
find
.
t
ext
(
'Target'
));
gesture
.
moveTo
(
secondLocation
);
tester
.
pump
();
expect
(
accepted
,
isEmpty
);
expect
(
tester
.
findText
(
'Source'
),
isNotNull
);
expect
(
tester
.
findText
(
'Dragging'
),
isNotNull
);
expect
(
tester
.
findText
(
'Target'
),
isNotNull
);
expect
(
tester
,
hasWidget
(
find
.
text
(
'Source'
))
);
expect
(
tester
,
hasWidget
(
find
.
text
(
'Dragging'
))
);
expect
(
tester
,
hasWidget
(
find
.
text
(
'Target'
))
);
gesture
.
up
();
tester
.
pump
();
expect
(
accepted
,
equals
(<
int
>[
1
]));
expect
(
tester
.
findText
(
'Source'
),
isNotNull
);
expect
(
tester
.
findText
(
'Dragging'
),
isNull
);
expect
(
tester
.
findText
(
'Target'
),
isNotNull
);
expect
(
tester
,
hasWidget
(
find
.
text
(
'Source'
))
);
expect
(
tester
,
doesNotHaveWidget
(
find
.
text
(
'Dragging'
))
);
expect
(
tester
,
hasWidget
(
find
.
text
(
'Target'
))
);
});
});
...
...
@@ -93,30 +93,30 @@ void main() {
}));
expect
(
events
,
isEmpty
);
expect
(
tester
.
findText
(
'Source'
),
isNotNull
);
expect
(
tester
.
findText
(
'Dragging'
),
isNull
);
expect
(
tester
.
findText
(
'Target'
),
isNotNull
);
expect
(
tester
.
findText
(
'Button'
),
isNotNull
);
expect
(
tester
,
hasWidget
(
find
.
text
(
'Source'
))
);
expect
(
tester
,
doesNotHaveWidget
(
find
.
text
(
'Dragging'
))
);
expect
(
tester
,
hasWidget
(
find
.
text
(
'Target'
))
);
expect
(
tester
,
hasWidget
(
find
.
text
(
'Button'
))
);
// taps (we check both to make sure the test is consistent)
expect
(
events
,
isEmpty
);
tester
.
tap
(
tester
.
findT
ext
(
'Button'
));
tester
.
tap
(
find
.
t
ext
(
'Button'
));
expect
(
events
,
equals
(<
String
>[
'tap'
]));
events
.
clear
();
expect
(
events
,
isEmpty
);
tester
.
tap
(
tester
.
findT
ext
(
'Target'
));
tester
.
tap
(
find
.
t
ext
(
'Target'
));
expect
(
events
,
equals
(<
String
>[
'tap'
]));
events
.
clear
();
// drag and drop
firstLocation
=
tester
.
getCenter
(
tester
.
findT
ext
(
'Source'
));
firstLocation
=
tester
.
getCenter
(
find
.
t
ext
(
'Source'
));
TestGesture
gesture
=
tester
.
startGesture
(
firstLocation
,
pointer:
7
);
tester
.
pump
();
secondLocation
=
tester
.
getCenter
(
tester
.
findT
ext
(
'Target'
));
secondLocation
=
tester
.
getCenter
(
find
.
t
ext
(
'Target'
));
gesture
.
moveTo
(
secondLocation
);
tester
.
pump
();
...
...
@@ -128,17 +128,17 @@ void main() {
// drag and tap and drop
firstLocation
=
tester
.
getCenter
(
tester
.
findT
ext
(
'Source'
));
firstLocation
=
tester
.
getCenter
(
find
.
t
ext
(
'Source'
));
gesture
=
tester
.
startGesture
(
firstLocation
,
pointer:
7
);
tester
.
pump
();
secondLocation
=
tester
.
getCenter
(
tester
.
findT
ext
(
'Target'
));
secondLocation
=
tester
.
getCenter
(
find
.
t
ext
(
'Target'
));
gesture
.
moveTo
(
secondLocation
);
tester
.
pump
();
expect
(
events
,
isEmpty
);
tester
.
tap
(
tester
.
findT
ext
(
'Button'
));
tester
.
tap
(
tester
.
findT
ext
(
'Target'
));
tester
.
tap
(
find
.
t
ext
(
'Button'
));
tester
.
tap
(
find
.
t
ext
(
'Target'
));
gesture
.
up
();
tester
.
pump
();
expect
(
events
,
equals
(<
String
>[
'tap'
,
'tap'
,
'drop'
]));
...
...
@@ -174,19 +174,19 @@ void main() {
}));
expect
(
events
,
isEmpty
);
expect
(
tester
.
findText
(
'Button'
),
isNotNull
);
expect
(
tester
.
findText
(
'Target'
),
isNotNull
);
expect
(
tester
,
hasWidget
(
find
.
text
(
'Button'
))
);
expect
(
tester
,
hasWidget
(
find
.
text
(
'Target'
))
);
expect
(
events
,
isEmpty
);
tester
.
tap
(
tester
.
findT
ext
(
'Button'
));
tester
.
tap
(
find
.
t
ext
(
'Button'
));
expect
(
events
,
equals
(<
String
>[
'tap'
]));
events
.
clear
();
firstLocation
=
tester
.
getCenter
(
tester
.
findT
ext
(
'Button'
));
firstLocation
=
tester
.
getCenter
(
find
.
t
ext
(
'Button'
));
TestGesture
gesture
=
tester
.
startGesture
(
firstLocation
,
pointer:
7
);
tester
.
pump
();
secondLocation
=
tester
.
getCenter
(
tester
.
findT
ext
(
'Target'
));
secondLocation
=
tester
.
getCenter
(
find
.
t
ext
(
'Target'
));
gesture
.
moveTo
(
secondLocation
);
tester
.
pump
();
...
...
@@ -221,18 +221,18 @@ void main() {
}));
expect
(
events
,
isEmpty
);
expect
(
tester
.
findText
(
'Source'
),
isNotNull
);
expect
(
tester
.
findText
(
'Target'
),
isNotNull
);
expect
(
tester
,
hasWidget
(
find
.
text
(
'Source'
))
);
expect
(
tester
,
hasWidget
(
find
.
text
(
'Target'
))
);
expect
(
events
,
isEmpty
);
tester
.
tap
(
tester
.
findT
ext
(
'Source'
));
tester
.
tap
(
find
.
t
ext
(
'Source'
));
expect
(
events
,
isEmpty
);
firstLocation
=
tester
.
getCenter
(
tester
.
findT
ext
(
'Source'
));
firstLocation
=
tester
.
getCenter
(
find
.
t
ext
(
'Source'
));
TestGesture
gesture
=
tester
.
startGesture
(
firstLocation
,
pointer:
7
);
tester
.
pump
();
secondLocation
=
tester
.
getCenter
(
tester
.
findT
ext
(
'Target'
));
secondLocation
=
tester
.
getCenter
(
find
.
t
ext
(
'Target'
));
gesture
.
moveTo
(
secondLocation
);
tester
.
pump
();
...
...
@@ -266,20 +266,20 @@ void main() {
}));
expect
(
events
,
isEmpty
);
expect
(
tester
.
findText
(
'Source'
),
isNotNull
);
expect
(
tester
.
findText
(
'Target'
),
isNotNull
);
expect
(
tester
,
hasWidget
(
find
.
text
(
'Source'
))
);
expect
(
tester
,
hasWidget
(
find
.
text
(
'Target'
))
);
expect
(
events
,
isEmpty
);
tester
.
tap
(
tester
.
findT
ext
(
'Source'
));
tester
.
tap
(
find
.
t
ext
(
'Source'
));
expect
(
events
,
isEmpty
);
firstLocation
=
tester
.
getCenter
(
tester
.
findT
ext
(
'Source'
));
firstLocation
=
tester
.
getCenter
(
find
.
t
ext
(
'Source'
));
TestGesture
gesture
=
tester
.
startGesture
(
firstLocation
,
pointer:
7
);
tester
.
pump
();
tester
.
pump
(
const
Duration
(
seconds:
20
));
secondLocation
=
tester
.
getCenter
(
tester
.
findT
ext
(
'Target'
));
secondLocation
=
tester
.
getCenter
(
find
.
t
ext
(
'Target'
));
gesture
.
moveTo
(
secondLocation
);
tester
.
pump
();
...
...
@@ -319,14 +319,14 @@ void main() {
}));
expect
(
events
,
isEmpty
);
expect
(
tester
.
findText
(
'Target'
),
isNotNull
);
expect
(
tester
.
findText
(
'H'
),
isNotNull
);
expect
(
tester
.
findText
(
'V'
),
isNotNull
);
expect
(
tester
,
hasWidget
(
find
.
text
(
'Target'
))
);
expect
(
tester
,
hasWidget
(
find
.
text
(
'H'
))
);
expect
(
tester
,
hasWidget
(
find
.
text
(
'V'
))
);
// vertical draggable drags vertically
expect
(
events
,
isEmpty
);
firstLocation
=
tester
.
getCenter
(
tester
.
findT
ext
(
'V'
));
secondLocation
=
tester
.
getCenter
(
tester
.
findT
ext
(
'Target'
));
firstLocation
=
tester
.
getCenter
(
find
.
t
ext
(
'V'
));
secondLocation
=
tester
.
getCenter
(
find
.
t
ext
(
'Target'
));
TestGesture
gesture
=
tester
.
startGesture
(
firstLocation
,
pointer:
7
);
tester
.
pump
();
gesture
.
moveTo
(
secondLocation
);
...
...
@@ -334,14 +334,14 @@ void main() {
gesture
.
up
();
tester
.
pump
();
expect
(
events
,
equals
(<
String
>[
'drop 2'
]));
expect
(
tester
.
getCenter
(
tester
.
findT
ext
(
'Target'
)).
y
,
greaterThan
(
0.0
));
expect
(
tester
.
getCenter
(
find
.
t
ext
(
'Target'
)).
y
,
greaterThan
(
0.0
));
events
.
clear
();
// horizontal draggable drags horizontally
expect
(
events
,
isEmpty
);
firstLocation
=
tester
.
getTopLeft
(
tester
.
findT
ext
(
'H'
));
secondLocation
=
tester
.
getTopRight
(
tester
.
findT
ext
(
'H'
));
thirdLocation
=
tester
.
getCenter
(
tester
.
findT
ext
(
'Target'
));
firstLocation
=
tester
.
getTopLeft
(
find
.
t
ext
(
'H'
));
secondLocation
=
tester
.
getTopRight
(
find
.
t
ext
(
'H'
));
thirdLocation
=
tester
.
getCenter
(
find
.
t
ext
(
'Target'
));
gesture
=
tester
.
startGesture
(
firstLocation
,
pointer:
7
);
tester
.
pump
();
gesture
.
moveTo
(
secondLocation
);
...
...
@@ -351,15 +351,15 @@ void main() {
gesture
.
up
();
tester
.
pump
();
expect
(
events
,
equals
(<
String
>[
'drop 1'
]));
expect
(
tester
.
getCenter
(
tester
.
findT
ext
(
'Target'
)).
y
,
greaterThan
(
0.0
));
expect
(
tester
.
getCenter
(
find
.
t
ext
(
'Target'
)).
y
,
greaterThan
(
0.0
));
events
.
clear
();
// vertical draggable drags horizontally when there's no competition
// from other gesture detectors
expect
(
events
,
isEmpty
);
firstLocation
=
tester
.
getTopLeft
(
tester
.
findT
ext
(
'V'
));
secondLocation
=
tester
.
getTopRight
(
tester
.
findT
ext
(
'V'
));
thirdLocation
=
tester
.
getCenter
(
tester
.
findT
ext
(
'Target'
));
firstLocation
=
tester
.
getTopLeft
(
find
.
t
ext
(
'V'
));
secondLocation
=
tester
.
getTopRight
(
find
.
t
ext
(
'V'
));
thirdLocation
=
tester
.
getCenter
(
find
.
t
ext
(
'Target'
));
gesture
=
tester
.
startGesture
(
firstLocation
,
pointer:
7
);
tester
.
pump
();
gesture
.
moveTo
(
secondLocation
);
...
...
@@ -369,14 +369,14 @@ void main() {
gesture
.
up
();
tester
.
pump
();
expect
(
events
,
equals
(<
String
>[
'drop 2'
]));
expect
(
tester
.
getCenter
(
tester
.
findT
ext
(
'Target'
)).
y
,
greaterThan
(
0.0
));
expect
(
tester
.
getCenter
(
find
.
t
ext
(
'Target'
)).
y
,
greaterThan
(
0.0
));
events
.
clear
();
// horizontal draggable doesn't drag vertically when there is competition
// for vertical gestures
expect
(
events
,
isEmpty
);
firstLocation
=
tester
.
getCenter
(
tester
.
findT
ext
(
'H'
));
secondLocation
=
tester
.
getCenter
(
tester
.
findT
ext
(
'Target'
));
firstLocation
=
tester
.
getCenter
(
find
.
t
ext
(
'H'
));
secondLocation
=
tester
.
getCenter
(
find
.
t
ext
(
'Target'
));
gesture
=
tester
.
startGesture
(
firstLocation
,
pointer:
7
);
tester
.
pump
();
gesture
.
moveTo
(
secondLocation
);
...
...
@@ -384,7 +384,7 @@ void main() {
gesture
.
up
();
tester
.
pump
();
expect
(
events
,
equals
(<
String
>[]));
expect
(
tester
.
getCenter
(
tester
.
findT
ext
(
'Target'
)).
y
,
lessThan
(
0.0
));
expect
(
tester
.
getCenter
(
find
.
t
ext
(
'Target'
)).
y
,
lessThan
(
0.0
));
events
.
clear
();
});
});
...
...
@@ -418,14 +418,14 @@ void main() {
}));
expect
(
events
,
isEmpty
);
expect
(
tester
.
findText
(
'Target'
),
isNotNull
);
expect
(
tester
.
findText
(
'H'
),
isNotNull
);
expect
(
tester
.
findText
(
'V'
),
isNotNull
);
expect
(
tester
,
hasWidget
(
find
.
text
(
'Target'
))
);
expect
(
tester
,
hasWidget
(
find
.
text
(
'H'
))
);
expect
(
tester
,
hasWidget
(
find
.
text
(
'V'
))
);
// horizontal draggable drags horizontally
expect
(
events
,
isEmpty
);
firstLocation
=
tester
.
getCenter
(
tester
.
findT
ext
(
'H'
));
secondLocation
=
tester
.
getCenter
(
tester
.
findT
ext
(
'Target'
));
firstLocation
=
tester
.
getCenter
(
find
.
t
ext
(
'H'
));
secondLocation
=
tester
.
getCenter
(
find
.
t
ext
(
'Target'
));
TestGesture
gesture
=
tester
.
startGesture
(
firstLocation
,
pointer:
7
);
tester
.
pump
();
gesture
.
moveTo
(
secondLocation
);
...
...
@@ -433,14 +433,14 @@ void main() {
gesture
.
up
();
tester
.
pump
();
expect
(
events
,
equals
(<
String
>[
'drop 1'
]));
expect
(
tester
.
getCenter
(
tester
.
findT
ext
(
'Target'
)).
x
,
greaterThan
(
0.0
));
expect
(
tester
.
getCenter
(
find
.
t
ext
(
'Target'
)).
x
,
greaterThan
(
0.0
));
events
.
clear
();
// vertical draggable drags vertically
expect
(
events
,
isEmpty
);
firstLocation
=
tester
.
getTopLeft
(
tester
.
findT
ext
(
'V'
));
secondLocation
=
tester
.
getBottomLeft
(
tester
.
findT
ext
(
'V'
));
thirdLocation
=
tester
.
getCenter
(
tester
.
findT
ext
(
'Target'
));
firstLocation
=
tester
.
getTopLeft
(
find
.
t
ext
(
'V'
));
secondLocation
=
tester
.
getBottomLeft
(
find
.
t
ext
(
'V'
));
thirdLocation
=
tester
.
getCenter
(
find
.
t
ext
(
'Target'
));
gesture
=
tester
.
startGesture
(
firstLocation
,
pointer:
7
);
tester
.
pump
();
gesture
.
moveTo
(
secondLocation
);
...
...
@@ -450,15 +450,15 @@ void main() {
gesture
.
up
();
tester
.
pump
();
expect
(
events
,
equals
(<
String
>[
'drop 2'
]));
expect
(
tester
.
getCenter
(
tester
.
findT
ext
(
'Target'
)).
x
,
greaterThan
(
0.0
));
expect
(
tester
.
getCenter
(
find
.
t
ext
(
'Target'
)).
x
,
greaterThan
(
0.0
));
events
.
clear
();
// horizontal draggable drags vertically when there's no competition
// from other gesture detectors
expect
(
events
,
isEmpty
);
firstLocation
=
tester
.
getTopLeft
(
tester
.
findT
ext
(
'H'
));
secondLocation
=
tester
.
getBottomLeft
(
tester
.
findT
ext
(
'H'
));
thirdLocation
=
tester
.
getCenter
(
tester
.
findT
ext
(
'Target'
));
firstLocation
=
tester
.
getTopLeft
(
find
.
t
ext
(
'H'
));
secondLocation
=
tester
.
getBottomLeft
(
find
.
t
ext
(
'H'
));
thirdLocation
=
tester
.
getCenter
(
find
.
t
ext
(
'Target'
));
gesture
=
tester
.
startGesture
(
firstLocation
,
pointer:
7
);
tester
.
pump
();
gesture
.
moveTo
(
secondLocation
);
...
...
@@ -468,14 +468,14 @@ void main() {
gesture
.
up
();
tester
.
pump
();
expect
(
events
,
equals
(<
String
>[
'drop 1'
]));
expect
(
tester
.
getCenter
(
tester
.
findT
ext
(
'Target'
)).
x
,
greaterThan
(
0.0
));
expect
(
tester
.
getCenter
(
find
.
t
ext
(
'Target'
)).
x
,
greaterThan
(
0.0
));
events
.
clear
();
// vertical draggable doesn't drag horizontally when there is competition
// for horizontal gestures
expect
(
events
,
isEmpty
);
firstLocation
=
tester
.
getCenter
(
tester
.
findT
ext
(
'V'
));
secondLocation
=
tester
.
getCenter
(
tester
.
findT
ext
(
'Target'
));
firstLocation
=
tester
.
getCenter
(
find
.
t
ext
(
'V'
));
secondLocation
=
tester
.
getCenter
(
find
.
t
ext
(
'Target'
));
gesture
=
tester
.
startGesture
(
firstLocation
,
pointer:
7
);
tester
.
pump
();
gesture
.
moveTo
(
secondLocation
);
...
...
@@ -483,7 +483,7 @@ void main() {
gesture
.
up
();
tester
.
pump
();
expect
(
events
,
equals
(<
String
>[]));
expect
(
tester
.
getCenter
(
tester
.
findT
ext
(
'Target'
)).
x
,
lessThan
(
0.0
));
expect
(
tester
.
getCenter
(
find
.
t
ext
(
'Target'
)).
x
,
lessThan
(
0.0
));
events
.
clear
();
});
});
...
...
@@ -516,38 +516,38 @@ void main() {
}));
expect
(
accepted
,
isEmpty
);
expect
(
tester
.
findText
(
'Source'
),
isNotNull
);
expect
(
tester
.
findText
(
'Dragging'
),
isNull
);
expect
(
tester
.
findText
(
'Target'
),
isNotNull
);
expect
(
tester
,
hasWidget
(
find
.
text
(
'Source'
))
);
expect
(
tester
,
doesNotHaveWidget
(
find
.
text
(
'Dragging'
))
);
expect
(
tester
,
hasWidget
(
find
.
text
(
'Target'
))
);
expect
(
onDraggableCanceledCalled
,
isFalse
);
Point
firstLocation
=
tester
.
getCenter
(
tester
.
findT
ext
(
'Source'
));
Point
firstLocation
=
tester
.
getCenter
(
find
.
t
ext
(
'Source'
));
TestGesture
gesture
=
tester
.
startGesture
(
firstLocation
,
pointer:
7
);
tester
.
pump
();
expect
(
accepted
,
isEmpty
);
expect
(
tester
.
findText
(
'Source'
),
isNotNull
);
expect
(
tester
.
findText
(
'Dragging'
),
isNotNull
);
expect
(
tester
.
findText
(
'Target'
),
isNotNull
);
expect
(
tester
,
hasWidget
(
find
.
text
(
'Source'
))
);
expect
(
tester
,
hasWidget
(
find
.
text
(
'Dragging'
))
);
expect
(
tester
,
hasWidget
(
find
.
text
(
'Target'
))
);
expect
(
onDraggableCanceledCalled
,
isFalse
);
Point
secondLocation
=
tester
.
getCenter
(
tester
.
findT
ext
(
'Target'
));
Point
secondLocation
=
tester
.
getCenter
(
find
.
t
ext
(
'Target'
));
gesture
.
moveTo
(
secondLocation
);
tester
.
pump
();
expect
(
accepted
,
isEmpty
);
expect
(
tester
.
findText
(
'Source'
),
isNotNull
);
expect
(
tester
.
findText
(
'Dragging'
),
isNotNull
);
expect
(
tester
.
findText
(
'Target'
),
isNotNull
);
expect
(
tester
,
hasWidget
(
find
.
text
(
'Source'
))
);
expect
(
tester
,
hasWidget
(
find
.
text
(
'Dragging'
))
);
expect
(
tester
,
hasWidget
(
find
.
text
(
'Target'
))
);
expect
(
onDraggableCanceledCalled
,
isFalse
);
gesture
.
up
();
tester
.
pump
();
expect
(
accepted
,
equals
(<
int
>[
1
]));
expect
(
tester
.
findText
(
'Source'
),
isNotNull
);
expect
(
tester
.
findText
(
'Dragging'
),
isNull
);
expect
(
tester
.
findText
(
'Target'
),
isNotNull
);
expect
(
tester
,
hasWidget
(
find
.
text
(
'Source'
))
);
expect
(
tester
,
doesNotHaveWidget
(
find
.
text
(
'Dragging'
))
);
expect
(
tester
,
hasWidget
(
find
.
text
(
'Target'
))
);
expect
(
onDraggableCanceledCalled
,
isFalse
);
});
});
...
...
@@ -585,38 +585,38 @@ void main() {
}));
expect
(
accepted
,
isEmpty
);
expect
(
tester
.
findText
(
'Source'
),
isNotNull
);
expect
(
tester
.
findText
(
'Dragging'
),
isNull
);
expect
(
tester
.
findText
(
'Target'
),
isNotNull
);
expect
(
tester
,
hasWidget
(
find
.
text
(
'Source'
))
);
expect
(
tester
,
doesNotHaveWidget
(
find
.
text
(
'Dragging'
))
);
expect
(
tester
,
hasWidget
(
find
.
text
(
'Target'
))
);
expect
(
onDraggableCanceledCalled
,
isFalse
);
Point
firstLocation
=
tester
.
getTopLeft
(
tester
.
findT
ext
(
'Source'
));
Point
firstLocation
=
tester
.
getTopLeft
(
find
.
t
ext
(
'Source'
));
TestGesture
gesture
=
tester
.
startGesture
(
firstLocation
,
pointer:
7
);
tester
.
pump
();
expect
(
accepted
,
isEmpty
);
expect
(
tester
.
findText
(
'Source'
),
isNotNull
);
expect
(
tester
.
findText
(
'Dragging'
),
isNotNull
);
expect
(
tester
.
findText
(
'Target'
),
isNotNull
);
expect
(
tester
,
hasWidget
(
find
.
text
(
'Source'
))
);
expect
(
tester
,
hasWidget
(
find
.
text
(
'Dragging'
))
);
expect
(
tester
,
hasWidget
(
find
.
text
(
'Target'
))
);
expect
(
onDraggableCanceledCalled
,
isFalse
);
Point
secondLocation
=
tester
.
getCenter
(
tester
.
findT
ext
(
'Target'
));
Point
secondLocation
=
tester
.
getCenter
(
find
.
t
ext
(
'Target'
));
gesture
.
moveTo
(
secondLocation
);
tester
.
pump
();
expect
(
accepted
,
isEmpty
);
expect
(
tester
.
findText
(
'Source'
),
isNotNull
);
expect
(
tester
.
findText
(
'Dragging'
),
isNotNull
);
expect
(
tester
.
findText
(
'Target'
),
isNotNull
);
expect
(
tester
,
hasWidget
(
find
.
text
(
'Source'
))
);
expect
(
tester
,
hasWidget
(
find
.
text
(
'Dragging'
))
);
expect
(
tester
,
hasWidget
(
find
.
text
(
'Target'
))
);
expect
(
onDraggableCanceledCalled
,
isFalse
);
gesture
.
up
();
tester
.
pump
();
expect
(
accepted
,
isEmpty
);
expect
(
tester
.
findText
(
'Source'
),
isNotNull
);
expect
(
tester
.
findText
(
'Dragging'
),
isNull
);
expect
(
tester
.
findText
(
'Target'
),
isNotNull
);
expect
(
tester
,
hasWidget
(
find
.
text
(
'Source'
))
);
expect
(
tester
,
doesNotHaveWidget
(
find
.
text
(
'Dragging'
))
);
expect
(
tester
,
hasWidget
(
find
.
text
(
'Target'
))
);
expect
(
onDraggableCanceledCalled
,
isTrue
);
expect
(
onDraggableCanceledVelocity
,
equals
(
Velocity
.
zero
));
expect
(
onDraggableCanceledOffset
,
...
...
@@ -657,19 +657,19 @@ void main() {
}));
expect
(
accepted
,
isEmpty
);
expect
(
tester
.
findText
(
'Source'
),
isNotNull
);
expect
(
tester
.
findText
(
'Dragging'
),
isNull
);
expect
(
tester
.
findText
(
'Target'
),
isNotNull
);
expect
(
tester
,
hasWidget
(
find
.
text
(
'Source'
))
);
expect
(
tester
,
doesNotHaveWidget
(
find
.
text
(
'Dragging'
))
);
expect
(
tester
,
hasWidget
(
find
.
text
(
'Target'
))
);
expect
(
onDraggableCanceledCalled
,
isFalse
);
Point
flingStart
=
tester
.
getTopLeft
(
tester
.
findT
ext
(
'Source'
));
Point
flingStart
=
tester
.
getTopLeft
(
find
.
t
ext
(
'Source'
));
tester
.
flingFrom
(
flingStart
,
new
Offset
(
0.0
,
100.0
),
1000.0
);
tester
.
pump
();
expect
(
accepted
,
isEmpty
);
expect
(
tester
.
findText
(
'Source'
),
isNotNull
);
expect
(
tester
.
findText
(
'Dragging'
),
isNull
);
expect
(
tester
.
findText
(
'Target'
),
isNotNull
);
expect
(
tester
,
hasWidget
(
find
.
text
(
'Source'
))
);
expect
(
tester
,
doesNotHaveWidget
(
find
.
text
(
'Dragging'
))
);
expect
(
tester
,
hasWidget
(
find
.
text
(
'Target'
))
);
expect
(
onDraggableCanceledCalled
,
isTrue
);
expect
(
onDraggableCanceledVelocity
.
pixelsPerSecond
.
dx
.
abs
(),
lessThan
(
0.0000001
));
...
...
@@ -720,16 +720,16 @@ void main() {
expect
(
acceptedInts
,
isEmpty
);
expect
(
acceptedDoubles
,
isEmpty
);
expect
(
tester
.
findText
(
'IntSource'
),
isNotNull
);
expect
(
tester
.
findText
(
'IntDragging'
),
isNull
);
expect
(
tester
.
findText
(
'DoubleSource'
),
isNotNull
);
expect
(
tester
.
findText
(
'DoubleDragging'
),
isNull
);
expect
(
tester
.
findText
(
'Target1'
),
isNotNull
);
expect
(
tester
.
findText
(
'Target2'
),
isNotNull
);
expect
(
tester
,
hasWidget
(
find
.
text
(
'IntSource'
))
);
expect
(
tester
,
doesNotHaveWidget
(
find
.
text
(
'IntDragging'
))
);
expect
(
tester
,
hasWidget
(
find
.
text
(
'DoubleSource'
))
);
expect
(
tester
,
doesNotHaveWidget
(
find
.
text
(
'DoubleDragging'
))
);
expect
(
tester
,
hasWidget
(
find
.
text
(
'Target1'
))
);
expect
(
tester
,
hasWidget
(
find
.
text
(
'Target2'
))
);
Point
intLocation
=
tester
.
getCenter
(
tester
.
findT
ext
(
'IntSource'
));
Point
doubleLocation
=
tester
.
getCenter
(
tester
.
findT
ext
(
'DoubleSource'
));
Point
targetLocation
=
tester
.
getCenter
(
tester
.
findT
ext
(
'Target1'
));
Point
intLocation
=
tester
.
getCenter
(
find
.
t
ext
(
'IntSource'
));
Point
doubleLocation
=
tester
.
getCenter
(
find
.
t
ext
(
'DoubleSource'
));
Point
targetLocation
=
tester
.
getCenter
(
find
.
t
ext
(
'Target1'
));
// Drag the double draggable.
TestGesture
doubleGesture
=
...
...
@@ -738,24 +738,24 @@ void main() {
expect
(
acceptedInts
,
isEmpty
);
expect
(
acceptedDoubles
,
isEmpty
);
expect
(
tester
.
findText
(
'IntDragging'
),
isNull
);
expect
(
tester
.
findText
(
'DoubleDragging'
),
isNotNull
);
expect
(
tester
,
doesNotHaveWidget
(
find
.
text
(
'IntDragging'
))
);
expect
(
tester
,
hasWidget
(
find
.
text
(
'DoubleDragging'
))
);
doubleGesture
.
moveTo
(
targetLocation
);
tester
.
pump
();
expect
(
acceptedInts
,
isEmpty
);
expect
(
acceptedDoubles
,
isEmpty
);
expect
(
tester
.
findText
(
'IntDragging'
),
isNull
);
expect
(
tester
.
findText
(
'DoubleDragging'
),
isNotNull
);
expect
(
tester
,
doesNotHaveWidget
(
find
.
text
(
'IntDragging'
))
);
expect
(
tester
,
hasWidget
(
find
.
text
(
'DoubleDragging'
))
);
doubleGesture
.
up
();
tester
.
pump
();
expect
(
acceptedInts
,
isEmpty
);
expect
(
acceptedDoubles
,
equals
(<
double
>[
1.0
]));
expect
(
tester
.
findText
(
'IntDragging'
),
isNull
);
expect
(
tester
.
findText
(
'DoubleDragging'
),
isNull
);
expect
(
tester
,
doesNotHaveWidget
(
find
.
text
(
'IntDragging'
))
);
expect
(
tester
,
doesNotHaveWidget
(
find
.
text
(
'DoubleDragging'
))
);
acceptedDoubles
.
clear
();
...
...
@@ -765,24 +765,24 @@ void main() {
expect
(
acceptedInts
,
isEmpty
);
expect
(
acceptedDoubles
,
isEmpty
);
expect
(
tester
.
findText
(
'IntDragging'
),
isNotNull
);
expect
(
tester
.
findText
(
'DoubleDragging'
),
isNull
);
expect
(
tester
,
hasWidget
(
find
.
text
(
'IntDragging'
))
);
expect
(
tester
,
doesNotHaveWidget
(
find
.
text
(
'DoubleDragging'
))
);
intGesture
.
moveTo
(
targetLocation
);
tester
.
pump
();
expect
(
acceptedInts
,
isEmpty
);
expect
(
acceptedDoubles
,
isEmpty
);
expect
(
tester
.
findText
(
'IntDragging'
),
isNotNull
);
expect
(
tester
.
findText
(
'DoubleDragging'
),
isNull
);
expect
(
tester
,
hasWidget
(
find
.
text
(
'IntDragging'
))
);
expect
(
tester
,
doesNotHaveWidget
(
find
.
text
(
'DoubleDragging'
))
);
intGesture
.
up
();
tester
.
pump
();
expect
(
acceptedInts
,
equals
(<
int
>[
1
]));
expect
(
acceptedDoubles
,
isEmpty
);
expect
(
tester
.
findText
(
'IntDragging'
),
isNull
);
expect
(
tester
.
findText
(
'DoubleDragging'
),
isNull
);
expect
(
tester
,
doesNotHaveWidget
(
find
.
text
(
'IntDragging'
))
);
expect
(
tester
,
doesNotHaveWidget
(
find
.
text
(
'DoubleDragging'
))
);
});
});
...
...
@@ -818,8 +818,8 @@ void main() {
},
}));
Point
dragTargetLocation
=
tester
.
getCenter
(
tester
.
findT
ext
(
'Source'
));
Point
targetLocation
=
tester
.
getCenter
(
tester
.
findT
ext
(
'Target1'
));
Point
dragTargetLocation
=
tester
.
getCenter
(
find
.
t
ext
(
'Source'
));
Point
targetLocation
=
tester
.
getCenter
(
find
.
t
ext
(
'Target1'
));
for
(
int
i
=
0
;
i
<
2
;
i
+=
1
)
{
TestGesture
gesture
=
tester
.
startGesture
(
dragTargetLocation
);
...
...
packages/flutter/test/widget/drawer_test.dart
View file @
f3a4f722
...
...
@@ -28,17 +28,17 @@ void main() {
)
);
tester
.
pump
();
// no effect
expect
(
tester
.
findText
(
'drawer'
),
isNull
);
expect
(
tester
,
doesNotHaveWidget
(
find
.
text
(
'drawer'
))
);
scaffoldKey
.
currentState
.
openDrawer
();
tester
.
pump
();
// drawer should be starting to animate in
expect
(
tester
.
findText
(
'drawer'
),
isNotNull
);
expect
(
tester
,
hasWidget
(
find
.
text
(
'drawer'
))
);
tester
.
pump
(
new
Duration
(
seconds:
1
));
// animation done
expect
(
tester
.
findText
(
'drawer'
),
isNotNull
);
expect
(
tester
,
hasWidget
(
find
.
text
(
'drawer'
))
);
Navigator
.
pop
(
context
);
tester
.
pump
();
// drawer should be starting to animate away
expect
(
tester
.
findText
(
'drawer'
),
isNotNull
);
expect
(
tester
,
hasWidget
(
find
.
text
(
'drawer'
))
);
tester
.
pump
(
new
Duration
(
seconds:
1
));
// animation done
expect
(
tester
.
findText
(
'drawer'
),
isNull
);
expect
(
tester
,
doesNotHaveWidget
(
find
.
text
(
'drawer'
))
);
});
});
...
...
@@ -59,24 +59,24 @@ void main() {
)
);
tester
.
pump
();
// no effect
expect
(
tester
.
findText
(
'drawer'
),
isNull
);
expect
(
tester
,
doesNotHaveWidget
(
find
.
text
(
'drawer'
))
);
scaffoldKey
.
currentState
.
openDrawer
();
tester
.
pump
();
// drawer should be starting to animate in
expect
(
tester
.
findText
(
'drawer'
),
isNotNull
);
expect
(
tester
,
hasWidget
(
find
.
text
(
'drawer'
))
);
tester
.
pump
(
new
Duration
(
seconds:
1
));
// animation done
expect
(
tester
.
findText
(
'drawer'
),
isNotNull
);
tester
.
tap
(
tester
.
findT
ext
(
'drawer'
));
expect
(
tester
,
hasWidget
(
find
.
text
(
'drawer'
))
);
tester
.
tap
(
find
.
t
ext
(
'drawer'
));
tester
.
pump
();
// nothing should have happened
expect
(
tester
.
findText
(
'drawer'
),
isNotNull
);
expect
(
tester
,
hasWidget
(
find
.
text
(
'drawer'
))
);
tester
.
pump
(
new
Duration
(
seconds:
1
));
// ditto
expect
(
tester
.
findText
(
'drawer'
),
isNotNull
);
expect
(
tester
,
hasWidget
(
find
.
text
(
'drawer'
))
);
tester
.
tapAt
(
const
Point
(
750.0
,
100.0
));
// on the mask
tester
.
pump
();
tester
.
pump
(
new
Duration
(
milliseconds:
10
));
// drawer should be starting to animate away
expect
(
tester
.
findText
(
'drawer'
),
isNotNull
);
expect
(
tester
,
hasWidget
(
find
.
text
(
'drawer'
))
);
tester
.
pump
(
new
Duration
(
seconds:
1
));
// animation done
expect
(
tester
.
findText
(
'drawer'
),
isNull
);
expect
(
tester
,
doesNotHaveWidget
(
find
.
text
(
'drawer'
))
);
});
});
...
...
@@ -108,18 +108,18 @@ void main() {
}
)
);
expect
(
tester
.
findText
(
'drawer'
),
isNull
);
expect
(
tester
,
doesNotHaveWidget
(
find
.
text
(
'drawer'
))
);
scaffoldKey
.
currentState
.
openDrawer
();
tester
.
pump
();
// drawer should be starting to animate in
expect
(
tester
.
findText
(
'drawer'
),
isNotNull
);
expect
(
tester
,
hasWidget
(
find
.
text
(
'drawer'
))
);
tester
.
pump
(
new
Duration
(
seconds:
1
));
// animation done
expect
(
tester
.
findText
(
'drawer'
),
isNotNull
);
expect
(
tester
,
hasWidget
(
find
.
text
(
'drawer'
))
);
tester
.
tapAt
(
const
Point
(
750.0
,
100.0
));
// on the mask
tester
.
pump
();
tester
.
pump
(
new
Duration
(
milliseconds:
10
));
// drawer should be starting to animate away
RenderBox
textBox
=
tester
.
findText
(
'drawer'
).
renderObject
;
RenderBox
textBox
=
tester
.
renderObjectOf
(
find
.
text
(
'drawer'
))
;
double
textLeft
=
textBox
.
localToGlobal
(
Point
.
origin
).
x
;
expect
(
textLeft
,
lessThan
(
0.0
));
...
...
packages/flutter/test/widget/duplicate_key_test.dart
View file @
f3a4f722
...
...
@@ -58,7 +58,7 @@ void main() {
test
(
'duplicate key smoke test'
,
()
{
testWidgets
((
WidgetTester
tester
)
{
tester
.
pumpWidget
(
builder
());
StatefulLeafState
leaf
=
tester
.
findStateOfType
(
StatefulLeafState
);
StatefulLeafState
leaf
=
tester
.
stateOf
(
find
.
byType
(
StatefulLeaf
)
);
leaf
.
test
();
tester
.
pump
();
Item
lastItem
=
items
[
1
];
...
...
packages/flutter/test/widget/flex_test.dart
View file @
f3a4f722
...
...
@@ -46,7 +46,7 @@ void main() {
)
);
tester
.
tap
(
tester
.
findT
ext
(
'X'
));
tester
.
tap
(
find
.
t
ext
(
'X'
));
expect
(
didReceiveTap
,
isTrue
);
});
});
...
...
@@ -65,7 +65,7 @@ void main() {
key:
flexKey
)
));
RenderBox
renderBox
=
tester
.
findElementByKey
(
flexKey
).
renderObject
;
RenderBox
renderBox
=
tester
.
renderObjectOf
(
find
.
byKey
(
flexKey
))
;
expect
(
renderBox
.
size
.
width
,
equals
(
800.0
));
expect
(
renderBox
.
size
.
height
,
equals
(
100.0
));
...
...
@@ -80,7 +80,7 @@ void main() {
mainAxisAlignment:
MainAxisAlignment
.
collapse
)
));
renderBox
=
tester
.
findElementByKey
(
flexKey
).
renderObject
;
renderBox
=
tester
.
renderObjectOf
(
find
.
byKey
(
flexKey
))
;
expect
(
renderBox
.
size
.
width
,
equals
(
40.0
));
expect
(
renderBox
.
size
.
height
,
equals
(
100.0
));
});
...
...
@@ -96,7 +96,7 @@ void main() {
key:
flexKey
)
));
RenderBox
renderBox
=
tester
.
findElementByKey
(
flexKey
).
renderObject
;
RenderBox
renderBox
=
tester
.
renderObjectOf
(
find
.
byKey
(
flexKey
))
;
expect
(
renderBox
.
size
.
width
,
equals
(
100.0
));
expect
(
renderBox
.
size
.
height
,
equals
(
600.0
));
...
...
@@ -111,7 +111,7 @@ void main() {
mainAxisAlignment:
MainAxisAlignment
.
collapse
)
));
renderBox
=
tester
.
findElementByKey
(
flexKey
).
renderObject
;
renderBox
=
tester
.
renderObjectOf
(
find
.
byKey
(
flexKey
))
;
expect
(
renderBox
.
size
.
width
,
equals
(
100.0
));
expect
(
renderBox
.
size
.
height
,
equals
(
250.0
));
});
...
...
@@ -138,7 +138,7 @@ void main() {
)
));
RenderBox
renderBox
=
tester
.
findElementByKey
(
childKey
).
renderObject
;
RenderBox
renderBox
=
tester
.
renderObjectOf
(
find
.
byKey
(
childKey
))
;
expect
(
renderBox
.
size
.
width
,
equals
(
0.0
));
expect
(
renderBox
.
size
.
height
,
equals
(
100.0
));
...
...
@@ -159,7 +159,7 @@ void main() {
)
));
renderBox
=
tester
.
findElementByKey
(
childKey
).
renderObject
;
renderBox
=
tester
.
renderObjectOf
(
find
.
byKey
(
childKey
))
;
expect
(
renderBox
.
size
.
width
,
equals
(
100.0
));
expect
(
renderBox
.
size
.
height
,
equals
(
0.0
));
});
...
...
packages/flutter/test/widget/focus_test.dart
View file @
f3a4f722
...
...
@@ -53,34 +53,34 @@ void main() {
)
)
);
expect
(
tester
.
findText
(
'a'
),
isNull
);
expect
(
tester
.
findText
(
'A FOCUSED'
),
isNotNull
);
expect
(
tester
.
findText
(
'b'
),
isNotNull
);
expect
(
tester
.
findText
(
'B FOCUSED'
),
isNull
);
tester
.
tap
(
tester
.
findT
ext
(
'A FOCUSED'
));
expect
(
tester
,
doesNotHaveWidget
(
find
.
text
(
'a'
))
);
expect
(
tester
,
hasWidget
(
find
.
text
(
'A FOCUSED'
))
);
expect
(
tester
,
hasWidget
(
find
.
text
(
'b'
))
);
expect
(
tester
,
doesNotHaveWidget
(
find
.
text
(
'B FOCUSED'
))
);
tester
.
tap
(
find
.
t
ext
(
'A FOCUSED'
));
tester
.
pump
();
expect
(
tester
.
findText
(
'a'
),
isNull
);
expect
(
tester
.
findText
(
'A FOCUSED'
),
isNotNull
);
expect
(
tester
.
findText
(
'b'
),
isNotNull
);
expect
(
tester
.
findText
(
'B FOCUSED'
),
isNull
);
tester
.
tap
(
tester
.
findT
ext
(
'A FOCUSED'
));
expect
(
tester
,
doesNotHaveWidget
(
find
.
text
(
'a'
))
);
expect
(
tester
,
hasWidget
(
find
.
text
(
'A FOCUSED'
))
);
expect
(
tester
,
hasWidget
(
find
.
text
(
'b'
))
);
expect
(
tester
,
doesNotHaveWidget
(
find
.
text
(
'B FOCUSED'
))
);
tester
.
tap
(
find
.
t
ext
(
'A FOCUSED'
));
tester
.
pump
();
expect
(
tester
.
findText
(
'a'
),
isNull
);
expect
(
tester
.
findText
(
'A FOCUSED'
),
isNotNull
);
expect
(
tester
.
findText
(
'b'
),
isNotNull
);
expect
(
tester
.
findText
(
'B FOCUSED'
),
isNull
);
tester
.
tap
(
tester
.
findT
ext
(
'b'
));
expect
(
tester
,
doesNotHaveWidget
(
find
.
text
(
'a'
))
);
expect
(
tester
,
hasWidget
(
find
.
text
(
'A FOCUSED'
))
);
expect
(
tester
,
hasWidget
(
find
.
text
(
'b'
))
);
expect
(
tester
,
doesNotHaveWidget
(
find
.
text
(
'B FOCUSED'
))
);
tester
.
tap
(
find
.
t
ext
(
'b'
));
tester
.
pump
();
expect
(
tester
.
findText
(
'a'
),
isNotNull
);
expect
(
tester
.
findText
(
'A FOCUSED'
),
isNull
);
expect
(
tester
.
findText
(
'b'
),
isNull
);
expect
(
tester
.
findText
(
'B FOCUSED'
),
isNotNull
);
tester
.
tap
(
tester
.
findT
ext
(
'a'
));
expect
(
tester
,
hasWidget
(
find
.
text
(
'a'
))
);
expect
(
tester
,
doesNotHaveWidget
(
find
.
text
(
'A FOCUSED'
))
);
expect
(
tester
,
doesNotHaveWidget
(
find
.
text
(
'b'
))
);
expect
(
tester
,
hasWidget
(
find
.
text
(
'B FOCUSED'
))
);
tester
.
tap
(
find
.
t
ext
(
'a'
));
tester
.
pump
();
expect
(
tester
.
findText
(
'a'
),
isNull
);
expect
(
tester
.
findText
(
'A FOCUSED'
),
isNotNull
);
expect
(
tester
.
findText
(
'b'
),
isNotNull
);
expect
(
tester
.
findText
(
'B FOCUSED'
),
isNull
);
expect
(
tester
,
doesNotHaveWidget
(
find
.
text
(
'a'
))
);
expect
(
tester
,
hasWidget
(
find
.
text
(
'A FOCUSED'
))
);
expect
(
tester
,
hasWidget
(
find
.
text
(
'b'
))
);
expect
(
tester
,
doesNotHaveWidget
(
find
.
text
(
'B FOCUSED'
))
);
});
});
...
...
@@ -100,20 +100,20 @@ void main() {
)
);
expect
(
tester
.
findText
(
'a'
),
isNotNull
);
expect
(
tester
.
findText
(
'A FOCUSED'
),
isNull
);
expect
(
tester
,
hasWidget
(
find
.
text
(
'a'
))
);
expect
(
tester
,
doesNotHaveWidget
(
find
.
text
(
'A FOCUSED'
))
);
Focus
.
moveTo
(
keyA
);
tester
.
pump
();
expect
(
tester
.
findText
(
'a'
),
isNull
);
expect
(
tester
.
findText
(
'A FOCUSED'
),
isNotNull
);
expect
(
tester
,
doesNotHaveWidget
(
find
.
text
(
'a'
))
);
expect
(
tester
,
hasWidget
(
find
.
text
(
'A FOCUSED'
))
);
Focus
.
clear
(
keyA
.
currentContext
);
tester
.
pump
();
expect
(
tester
.
findText
(
'a'
),
isNotNull
);
expect
(
tester
.
findText
(
'A FOCUSED'
),
isNull
);
expect
(
tester
,
hasWidget
(
find
.
text
(
'a'
))
);
expect
(
tester
,
doesNotHaveWidget
(
find
.
text
(
'A FOCUSED'
))
);
});
});
...
...
@@ -138,14 +138,14 @@ void main() {
)
);
expect
(
tester
.
findText
(
'a'
),
isNotNull
);
expect
(
tester
.
findText
(
'A FOCUSED'
),
isNull
);
expect
(
tester
,
hasWidget
(
find
.
text
(
'a'
))
);
expect
(
tester
,
doesNotHaveWidget
(
find
.
text
(
'A FOCUSED'
))
);
Focus
.
moveTo
(
keyA
);
tester
.
pump
();
expect
(
tester
.
findText
(
'a'
),
isNull
);
expect
(
tester
.
findText
(
'A FOCUSED'
),
isNotNull
);
expect
(
tester
,
doesNotHaveWidget
(
find
.
text
(
'a'
))
);
expect
(
tester
,
hasWidget
(
find
.
text
(
'A FOCUSED'
))
);
Focus
.
moveScopeTo
(
keyChildFocus
,
context:
keyA
.
currentContext
);
...
...
@@ -172,8 +172,8 @@ void main() {
)
);
expect
(
tester
.
findText
(
'a'
),
isNotNull
);
expect
(
tester
.
findText
(
'A FOCUSED'
),
isNull
);
expect
(
tester
,
hasWidget
(
find
.
text
(
'a'
))
);
expect
(
tester
,
doesNotHaveWidget
(
find
.
text
(
'A FOCUSED'
))
);
tester
.
pumpWidget
(
new
Focus
(
...
...
@@ -192,13 +192,13 @@ void main() {
);
// Focus has received the removal notification but we haven't rebuilt yet.
expect
(
tester
.
findText
(
'a'
),
isNotNull
);
expect
(
tester
.
findText
(
'A FOCUSED'
),
isNull
);
expect
(
tester
,
hasWidget
(
find
.
text
(
'a'
))
);
expect
(
tester
,
doesNotHaveWidget
(
find
.
text
(
'A FOCUSED'
))
);
tester
.
pump
();
expect
(
tester
.
findText
(
'a'
),
isNull
);
expect
(
tester
.
findText
(
'A FOCUSED'
),
isNotNull
);
expect
(
tester
,
doesNotHaveWidget
(
find
.
text
(
'a'
))
);
expect
(
tester
,
hasWidget
(
find
.
text
(
'A FOCUSED'
))
);
});
});
}
packages/flutter/test/widget/form_test.dart
View file @
f3a4f722
...
...
@@ -101,8 +101,7 @@ void main() {
tester
.
pumpWidget
(
builder
());
// Check for a new Text widget with our error text.
Element
errorElement
=
tester
.
findText
(
errorText
(
testValue
));
expect
(
errorElement
,
isNotNull
);
expect
(
tester
,
hasWidget
(
find
.
text
(
errorText
(
testValue
))));
}
checkErrorText
(
'Test'
);
...
...
@@ -157,8 +156,7 @@ void main() {
expect
(
fieldValue
,
equals
(
testValue
));
// Check for a new Text widget with our error text.
Element
errorElement
=
tester
.
findText
(
errorText
(
testValue
));
expect
(
errorElement
,
isNotNull
);
expect
(
tester
,
hasWidget
(
find
.
text
(
errorText
(
testValue
))));
}
checkErrorText
(
'Test'
);
...
...
packages/flutter/test/widget/heroes_test.dart
View file @
f3a4f722
...
...
@@ -51,101 +51,101 @@ void main() {
// the initial setup.
expect
(
tester
.
findElementByKey
(
firstKey
),
isOnStage
);
expect
(
tester
.
findElementByKey
(
firstKey
),
isInCard
);
expect
(
tester
.
findElementByKey
(
secondKey
),
isNull
);
expect
(
find
.
byKey
(
firstKey
),
isOnStage
(
tester
)
);
expect
(
find
.
byKey
(
firstKey
),
isInCard
(
tester
)
);
expect
(
tester
,
doesNotHaveWidget
(
find
.
byKey
(
secondKey
))
);
tester
.
tap
(
tester
.
findT
ext
(
'two'
));
tester
.
tap
(
find
.
t
ext
(
'two'
));
tester
.
pump
();
// begin navigation
// at this stage, the second route is off-stage, so that we can form the
// hero party.
expect
(
tester
.
findElementByKey
(
firstKey
),
isOnStage
);
expect
(
tester
.
findElementByKey
(
firstKey
),
isInCard
);
expect
(
tester
.
findElementByKey
(
secondKey
),
isOffStage
);
expect
(
tester
.
findElementByKey
(
secondKey
),
isInCard
);
expect
(
find
.
byKey
(
firstKey
),
isOnStage
(
tester
)
);
expect
(
find
.
byKey
(
firstKey
),
isInCard
(
tester
)
);
expect
(
find
.
byKey
(
secondKey
),
isOffStage
(
tester
)
);
expect
(
find
.
byKey
(
secondKey
),
isInCard
(
tester
)
);
tester
.
pump
();
// at this stage, the heroes have just gone on their journey, we are
// seeing them at t=16ms. The original page no longer contains the hero.
expect
(
tester
.
findElementByKey
(
firstKey
),
isNull
);
expect
(
tester
.
findElementByKey
(
secondKey
),
isOnStage
);
expect
(
tester
.
findElementByKey
(
secondKey
),
isNotInCard
);
expect
(
tester
,
doesNotHaveWidget
(
find
.
byKey
(
firstKey
))
);
expect
(
find
.
byKey
(
secondKey
),
isOnStage
(
tester
)
);
expect
(
find
.
byKey
(
secondKey
),
isNotInCard
(
tester
)
);
tester
.
pump
();
// t=32ms for the journey. Surely they are still at it.
expect
(
tester
.
findElementByKey
(
firstKey
),
isNull
);
expect
(
tester
.
findElementByKey
(
secondKey
),
isOnStage
);
expect
(
tester
.
findElementByKey
(
secondKey
),
isNotInCard
);
expect
(
tester
,
doesNotHaveWidget
(
find
.
byKey
(
firstKey
))
);
expect
(
find
.
byKey
(
secondKey
),
isOnStage
(
tester
)
);
expect
(
find
.
byKey
(
secondKey
),
isNotInCard
(
tester
)
);
tester
.
pump
(
new
Duration
(
seconds:
1
));
// t=1.032s for the journey. The journey has ended (it ends this frame, in
// fact). The hero should now be in the new page, on-stage.
expect
(
tester
.
findElementByKey
(
firstKey
),
isNull
);
expect
(
tester
.
findElementByKey
(
secondKey
),
isOnStage
);
expect
(
tester
.
findElementByKey
(
secondKey
),
isInCard
);
expect
(
tester
,
doesNotHaveWidget
(
find
.
byKey
(
firstKey
))
);
expect
(
find
.
byKey
(
secondKey
),
isOnStage
(
tester
)
);
expect
(
find
.
byKey
(
secondKey
),
isInCard
(
tester
)
);
tester
.
pump
();
// Should not change anything.
expect
(
tester
.
findElementByKey
(
firstKey
),
isNull
);
expect
(
tester
.
findElementByKey
(
secondKey
),
isOnStage
);
expect
(
tester
.
findElementByKey
(
secondKey
),
isInCard
);
expect
(
tester
,
doesNotHaveWidget
(
find
.
byKey
(
firstKey
))
);
expect
(
find
.
byKey
(
secondKey
),
isOnStage
(
tester
)
);
expect
(
find
.
byKey
(
secondKey
),
isInCard
(
tester
)
);
// Now move on to view 3
tester
.
tap
(
tester
.
findT
ext
(
'three'
));
tester
.
tap
(
find
.
t
ext
(
'three'
));
tester
.
pump
();
// begin navigation
// at this stage, the second route is off-stage, so that we can form the
// hero party.
expect
(
tester
.
findElementByKey
(
secondKey
),
isOnStage
);
expect
(
tester
.
findElementByKey
(
secondKey
),
isInCard
);
expect
(
tester
.
findElementByKey
(
thirdKey
),
isOffStage
);
expect
(
tester
.
findElementByKey
(
thirdKey
),
isInCard
);
expect
(
find
.
byKey
(
secondKey
),
isOnStage
(
tester
)
);
expect
(
find
.
byKey
(
secondKey
),
isInCard
(
tester
)
);
expect
(
find
.
byKey
(
thirdKey
),
isOffStage
(
tester
)
);
expect
(
find
.
byKey
(
thirdKey
),
isInCard
(
tester
)
);
tester
.
pump
();
// at this stage, the heroes have just gone on their journey, we are
// seeing them at t=16ms. The original page no longer contains the hero.
expect
(
tester
.
findElementByKey
(
secondKey
),
isNull
);
expect
(
tester
.
findElementByKey
(
thirdKey
),
isOnStage
);
expect
(
tester
.
findElementByKey
(
thirdKey
),
isNotInCard
);
expect
(
tester
,
doesNotHaveWidget
(
find
.
byKey
(
secondKey
))
);
expect
(
find
.
byKey
(
thirdKey
),
isOnStage
(
tester
)
);
expect
(
find
.
byKey
(
thirdKey
),
isNotInCard
(
tester
)
);
tester
.
pump
();
// t=32ms for the journey. Surely they are still at it.
expect
(
tester
.
findElementByKey
(
secondKey
),
isNull
);
expect
(
tester
.
findElementByKey
(
thirdKey
),
isOnStage
);
expect
(
tester
.
findElementByKey
(
thirdKey
),
isNotInCard
);
expect
(
tester
,
doesNotHaveWidget
(
find
.
byKey
(
secondKey
))
);
expect
(
find
.
byKey
(
thirdKey
),
isOnStage
(
tester
)
);
expect
(
find
.
byKey
(
thirdKey
),
isNotInCard
(
tester
)
);
tester
.
pump
(
new
Duration
(
seconds:
1
));
// t=1.032s for the journey. The journey has ended (it ends this frame, in
// fact). The hero should now be in the new page, on-stage.
expect
(
tester
.
findElementByKey
(
secondKey
),
isNull
);
expect
(
tester
.
findElementByKey
(
thirdKey
),
isOnStage
);
expect
(
tester
.
findElementByKey
(
thirdKey
),
isInCard
);
expect
(
tester
,
doesNotHaveWidget
(
find
.
byKey
(
secondKey
))
);
expect
(
find
.
byKey
(
thirdKey
),
isOnStage
(
tester
)
);
expect
(
find
.
byKey
(
thirdKey
),
isInCard
(
tester
)
);
tester
.
pump
();
// Should not change anything.
expect
(
tester
.
findElementByKey
(
secondKey
),
isNull
);
expect
(
tester
.
findElementByKey
(
thirdKey
),
isOnStage
);
expect
(
tester
.
findElementByKey
(
thirdKey
),
isInCard
);
expect
(
tester
,
doesNotHaveWidget
(
find
.
byKey
(
secondKey
))
);
expect
(
find
.
byKey
(
thirdKey
),
isOnStage
(
tester
)
);
expect
(
find
.
byKey
(
thirdKey
),
isInCard
(
tester
)
);
});
});
}
packages/flutter/test/widget/hyperlink_test.dart
View file @
f3a4f722
...
...
@@ -45,8 +45,7 @@ void main() {
)
);
Element
element
=
tester
.
findElementByKey
(
textKey
);
RenderBox
box
=
element
.
renderObject
;
RenderBox
box
=
tester
.
renderObjectOf
(
find
.
byKey
(
textKey
));
expect
(
didTapLeft
,
isFalse
);
expect
(
didTapRight
,
isFalse
);
...
...
packages/flutter/test/widget/icon_test.dart
View file @
f3a4f722
...
...
@@ -18,7 +18,7 @@ void main() {
child:
new
Icon
(
icon:
Icons
.
add
)
)
);
Text
text
=
tester
.
findWidgetOfType
(
Text
);
Text
text
=
tester
.
widget
(
find
.
byType
(
Text
)
);
expect
(
text
.
style
.
color
,
equals
(
Colors
.
green
[
500
].
withOpacity
(
0.5
)));
});
});
...
...
packages/flutter/test/widget/image_test.dart
View file @
f3a4f722
...
...
@@ -24,7 +24,7 @@ void main() {
);
ImageResource
imageResource
=
imageCache
.
load
(
testUrl
,
scale:
1.0
);
expect
(
tester
.
findElementByKey
(
new
ObjectKey
(
imageResource
)),
isNotNull
);
expect
(
tester
,
hasWidget
(
find
.
byKey
(
new
ObjectKey
(
imageResource
)))
);
});
});
...
...
@@ -40,7 +40,7 @@ void main() {
);
ImageResource
imageResource
=
imageCache
.
load
(
testUrl
,
scale:
1.0
);
expect
(
tester
.
findElementByKey
(
new
ObjectKey
(
imageResource
)),
isNull
);
expect
(
tester
,
doesNotHaveWidget
(
find
.
byKey
(
new
ObjectKey
(
imageResource
)))
);
});
});
...
...
@@ -50,7 +50,7 @@ void main() {
tester
.
pumpWidget
(
new
AsyncImage
(
provider:
imageProvider
));
ImageResource
imageResource
=
imageCache
.
loadProvider
(
imageProvider
);
expect
(
tester
.
findElementByKey
(
new
ObjectKey
(
imageResource
)),
isNotNull
);
expect
(
tester
,
hasWidget
(
find
.
byKey
(
new
ObjectKey
(
imageResource
)))
);
});
});
...
...
@@ -65,7 +65,7 @@ void main() {
);
ImageResource
imageResource
=
imageCache
.
loadProvider
(
imageProvider
);
expect
(
tester
.
findElementByKey
(
new
ObjectKey
(
imageResource
)),
isNull
);
expect
(
tester
,
doesNotHaveWidget
(
find
.
byKey
(
new
ObjectKey
(
imageResource
)))
);
});
});
...
...
@@ -81,7 +81,7 @@ void main() {
);
ImageResource
imageResource
=
assetBundle
.
loadImage
(
name
);
expect
(
tester
.
findElementByKey
(
new
ObjectKey
(
imageResource
)),
isNotNull
);
expect
(
tester
,
hasWidget
(
find
.
byKey
(
new
ObjectKey
(
imageResource
)))
);
});
});
...
...
@@ -98,7 +98,7 @@ void main() {
);
ImageResource
imageResource
=
assetBundle
.
loadImage
(
name
);
expect
(
tester
.
findElementByKey
(
new
ObjectKey
(
imageResource
)),
isNull
);
expect
(
tester
,
doesNotHaveWidget
(
find
.
byKey
(
new
ObjectKey
(
imageResource
)))
);
});
});
...
...
@@ -120,7 +120,7 @@ void main() {
expect
(
renderImage
.
image
,
isNull
);
imageProvider1
.
complete
();
tester
.
async
.
flushMicrotasks
();
// resolve the future from the image provider
tester
.
flushMicrotasks
();
// resolve the future from the image provider
tester
.
pump
(
null
,
EnginePhase
.
layout
);
renderImage
=
key
.
currentContext
.
findRenderObject
();
...
...
@@ -160,7 +160,7 @@ void main() {
expect
(
renderImage
.
image
,
isNull
);
imageProvider1
.
complete
();
tester
.
async
.
flushMicrotasks
();
// resolve the future from the image provider
tester
.
flushMicrotasks
();
// resolve the future from the image provider
tester
.
pump
(
null
,
EnginePhase
.
layout
);
renderImage
=
key
.
currentContext
.
findRenderObject
();
...
...
packages/flutter/test/widget/input_test.dart
View file @
f3a4f722
...
...
@@ -51,8 +51,9 @@ void main() {
tester
.
pumpWidget
(
builder
());
Element
input
=
tester
.
findElementByKey
(
inputKey
);
RenderBox
inputBox
=
input
.
renderObject
;
RenderBox
findInputBox
()
=>
tester
.
renderObjectOf
(
find
.
byKey
(
inputKey
));
RenderBox
inputBox
=
findInputBox
();
Size
emptyInputSize
=
inputBox
.
size
;
void
enterText
(
String
testValue
)
{
...
...
@@ -70,11 +71,11 @@ void main() {
}
enterText
(
' '
);
expect
(
input
.
renderObject
,
equals
(
inputBox
));
expect
(
findInputBox
()
,
equals
(
inputBox
));
expect
(
inputBox
.
size
,
equals
(
emptyInputSize
));
enterText
(
'Test'
);
expect
(
input
.
renderObject
,
equals
(
inputBox
));
expect
(
findInputBox
()
,
equals
(
inputBox
));
expect
(
inputBox
.
size
,
equals
(
emptyInputSize
));
});
});
...
...
@@ -96,7 +97,7 @@ void main() {
tester
.
pumpWidget
(
builder
());
RawInputLineState
editableText
=
tester
.
findStateOfType
(
RawInputLineState
);
RawInputLineState
editableText
=
tester
.
stateOf
(
find
.
byType
(
RawInputLine
)
);
// Check that the cursor visibility toggles after each blink interval.
void
checkCursorToggle
()
{
...
...
packages/flutter/test/widget/lazy_block_viewport_test.dart
View file @
f3a4f722
...
...
@@ -36,8 +36,7 @@ void main() {
tester
.
pumpWidget
(
builder
());
StatefulElement
element
=
tester
.
findElement
((
Element
element
)
=>
element
.
widget
is
FlipWidget
);
FlipWidgetState
testWidget
=
element
.
state
;
FlipWidgetState
testWidget
=
tester
.
stateOf
(
find
.
byType
(
FlipWidget
));
expect
(
callbackTracker
,
equals
([
0
,
1
,
2
,
3
,
4
,
5
]));
...
...
@@ -176,8 +175,7 @@ void main() {
);
};
ElementVisitor
collectText
=
(
Element
element
)
{
final
Widget
widget
=
element
.
widget
;
void
collectText
(
Widget
widget
)
{
if
(
widget
is
Text
)
text
.
add
(
widget
.
data
);
};
...
...
@@ -193,7 +191,7 @@ void main() {
expect
(
callbackTracker
,
equals
([
0
,
1
,
2
]));
callbackTracker
.
clear
();
tester
.
w
alkElements
(
collectText
);
tester
.
w
idgets
.
forEach
(
collectText
);
expect
(
text
,
equals
([
'0'
,
'1'
,
'2'
]));
text
.
clear
();
...
...
@@ -201,7 +199,7 @@ void main() {
expect
(
callbackTracker
,
equals
([
0
,
1
,
2
]));
callbackTracker
.
clear
();
tester
.
w
alkElements
(
collectText
);
tester
.
w
idgets
.
forEach
(
collectText
);
expect
(
text
,
equals
([
'0'
,
'1'
,
'2'
]));
text
.
clear
();
});
...
...
@@ -237,7 +235,7 @@ void main() {
)
);
DecoratedBox
widget
=
tester
.
findWidgetOfType
(
DecoratedBox
);
DecoratedBox
widget
=
tester
.
widget
(
find
.
byType
(
DecoratedBox
)
);
BoxDecoration
decoraton
=
widget
.
decoration
;
expect
(
decoraton
.
backgroundColor
,
equals
(
Colors
.
blue
[
500
]));
...
...
@@ -247,7 +245,7 @@ void main() {
tester
.
pump
();
widget
=
tester
.
findWidgetOfType
(
DecoratedBox
);
widget
=
tester
.
widget
(
find
.
byType
(
DecoratedBox
)
);
decoraton
=
widget
.
decoration
;
expect
(
decoraton
.
backgroundColor
,
equals
(
Colors
.
green
[
500
]));
});
...
...
@@ -274,7 +272,7 @@ void main() {
)
);
RenderBox
firstBox
=
tester
.
findText
(
'0'
).
findRenderObject
(
);
RenderBox
firstBox
=
tester
.
renderObjectOf
(
find
.
text
(
'0'
)
);
Point
upperLeft
=
firstBox
.
localToGlobal
(
Point
.
origin
);
expect
(
upperLeft
,
equals
(
new
Point
(
7.0
,
3.0
)));
expect
(
firstBox
.
size
.
width
,
equals
(
800.0
-
12.0
));
...
...
packages/flutter/test/widget/listener_test.dart
View file @
f3a4f722
...
...
@@ -33,7 +33,7 @@ void main() {
)
);
tester
.
tap
(
tester
.
findT
ext
(
'X'
));
tester
.
tap
(
find
.
t
ext
(
'X'
));
expect
(
log
,
equals
([
'bottom'
,
...
...
packages/flutter/test/widget/modal_barrier_test.dart
View file @
f3a4f722
...
...
@@ -35,7 +35,7 @@ void main() {
);
tester
.
pumpWidget
(
subject
);
tester
.
tap
(
tester
.
findT
ext
(
'target'
));
tester
.
tap
(
find
.
t
ext
(
'target'
));
tester
.
pumpWidget
(
subject
);
expect
(
tapped
,
isFalse
,
reason:
'because the tap is prevented by ModalBarrier'
);
...
...
@@ -52,7 +52,7 @@ void main() {
);
tester
.
pumpWidget
(
subject
);
tester
.
tap
(
tester
.
findT
ext
(
'target'
));
tester
.
tap
(
find
.
t
ext
(
'target'
));
tester
.
pumpWidget
(
subject
);
expect
(
tapped
,
isTrue
,
reason:
'because the tap is not prevented by ModalBarrier'
);
...
...
@@ -69,19 +69,19 @@ void main() {
tester
.
pumpWidget
(
new
MaterialApp
(
routes:
routes
));
// Initially the barrier is not visible
expect
(
tester
.
findElementByKey
(
const
ValueKey
<
String
>(
'barrier'
)),
isNull
);
expect
(
tester
,
doesNotHaveWidget
(
find
.
byKey
(
const
ValueKey
<
String
>(
'barrier'
)))
);
// Tapping on X routes to the barrier
tester
.
tap
(
tester
.
findT
ext
(
'X'
));
tester
.
tap
(
find
.
t
ext
(
'X'
));
tester
.
pump
();
// begin transition
tester
.
pump
(
const
Duration
(
seconds:
1
));
// end transition
// Tap on the barrier to dismiss it
tester
.
tap
(
tester
.
findElementB
yKey
(
const
ValueKey
<
String
>(
'barrier'
)));
tester
.
tap
(
find
.
b
yKey
(
const
ValueKey
<
String
>(
'barrier'
)));
tester
.
pump
();
// begin transition
tester
.
pump
(
const
Duration
(
seconds:
1
));
// end transition
expect
(
tester
.
findElementByKey
(
const
ValueKey
<
String
>(
'barrier'
)),
isNull
,
expect
(
tester
,
doesNotHaveWidget
(
find
.
byKey
(
const
ValueKey
<
String
>(
'barrier'
)))
,
reason:
'because the barrier was dismissed'
);
});
});
...
...
packages/flutter/test/widget/multichild_test.dart
View file @
f3a4f722
...
...
@@ -11,7 +11,7 @@ import 'test_widgets.dart';
void
checkTree
(
WidgetTester
tester
,
List
<
BoxDecoration
>
expectedDecorations
)
{
MultiChildRenderObjectElement
element
=
tester
.
findElement
((
Element
element
)
=>
element
is
MultiChildRenderObjectElement
);
tester
.
elementOf
(
find
.
byElement
((
Element
element
)
=>
element
is
MultiChildRenderObjectElement
)
);
expect
(
element
,
isNotNull
);
expect
(
element
.
renderObject
is
RenderStack
,
isTrue
);
RenderStack
renderObject
=
element
.
renderObject
;
...
...
packages/flutter/test/widget/navigator_test.dart
View file @
f3a4f722
...
...
@@ -77,27 +77,27 @@ void main() {
tester
.
pumpWidget
(
new
MaterialApp
(
routes:
routes
));
expect
(
tester
.
findText
(
'X'
),
isNotNull
);
expect
(
tester
.
findText
(
'Y'
),
isNull
);
expect
(
tester
,
hasWidget
(
find
.
text
(
'X'
))
);
expect
(
tester
,
doesNotHaveWidget
(
find
.
text
(
'Y'
))
);
tester
.
tap
(
tester
.
findT
ext
(
'X'
));
tester
.
tap
(
find
.
t
ext
(
'X'
));
tester
.
pump
(
const
Duration
(
milliseconds:
10
));
expect
(
tester
.
findText
(
'X'
),
isNotNull
);
expect
(
tester
.
findText
(
'Y'
),
isNotNull
);
expect
(
tester
,
hasWidget
(
find
.
text
(
'X'
))
);
expect
(
tester
,
hasWidget
(
find
.
text
(
'Y'
))
);
tester
.
pump
(
const
Duration
(
milliseconds:
10
));
tester
.
pump
(
const
Duration
(
milliseconds:
10
));
tester
.
pump
(
const
Duration
(
seconds:
1
));
tester
.
tap
(
tester
.
findT
ext
(
'Y'
));
tester
.
tap
(
find
.
t
ext
(
'Y'
));
tester
.
pump
(
const
Duration
(
milliseconds:
10
));
tester
.
pump
(
const
Duration
(
milliseconds:
10
));
tester
.
pump
(
const
Duration
(
milliseconds:
10
));
tester
.
pump
(
const
Duration
(
seconds:
1
));
expect
(
tester
.
findText
(
'X'
),
isNotNull
);
expect
(
tester
.
findText
(
'Y'
),
isNull
);
expect
(
tester
,
hasWidget
(
find
.
text
(
'X'
))
);
expect
(
tester
,
doesNotHaveWidget
(
find
.
text
(
'Y'
))
);
});
});
...
...
@@ -112,7 +112,7 @@ void main() {
}
);
tester
.
pumpWidget
(
widget
);
tester
.
tap
(
tester
.
findElementB
yKey
(
targetKey
));
tester
.
tap
(
find
.
b
yKey
(
targetKey
));
expect
(
exception
,
new
isInstanceOf
<
FlutterError
>());
expect
(
'
$exception
'
,
startsWith
(
'openTransaction called with a context'
));
});
...
...
packages/flutter/test/widget/page_forward_transitions_test.dart
View file @
f3a4f722
...
...
@@ -56,19 +56,19 @@ void main() {
String
state
()
{
String
result
=
''
;
if
(
tester
.
findText
(
'A'
)
!=
null
)
if
(
tester
.
exists
(
find
.
text
(
'A'
))
)
result
+=
'A'
;
if
(
tester
.
findText
(
'B'
)
!=
null
)
if
(
tester
.
exists
(
find
.
text
(
'B'
))
)
result
+=
'B'
;
if
(
tester
.
findText
(
'C'
)
!=
null
)
if
(
tester
.
exists
(
find
.
text
(
'C'
))
)
result
+=
'C'
;
if
(
tester
.
findText
(
'D'
)
!=
null
)
if
(
tester
.
exists
(
find
.
text
(
'D'
))
)
result
+=
'D'
;
if
(
tester
.
findText
(
'E'
)
!=
null
)
if
(
tester
.
exists
(
find
.
text
(
'E'
))
)
result
+=
'E'
;
if
(
tester
.
findText
(
'F'
)
!=
null
)
if
(
tester
.
exists
(
find
.
text
(
'F'
))
)
result
+=
'F'
;
if
(
tester
.
findText
(
'G'
)
!=
null
)
if
(
tester
.
exists
(
find
.
text
(
'G'
))
)
result
+=
'G'
;
return
result
;
}
...
...
packages/flutter/test/widget/page_transitions_test.dart
View file @
f3a4f722
...
...
@@ -26,9 +26,9 @@ void main() {
tester
.
pumpWidget
(
new
MaterialApp
(
routes:
routes
));
expect
(
tester
.
findText
(
'Home'
),
isOnStage
);
expect
(
tester
.
findText
(
'Settings'
),
isNull
);
expect
(
tester
.
findText
(
'Overlay'
),
isNull
);
expect
(
find
.
text
(
'Home'
),
isOnStage
(
tester
)
);
expect
(
tester
,
doesNotHaveWidget
(
find
.
text
(
'Settings'
))
);
expect
(
tester
,
doesNotHaveWidget
(
find
.
text
(
'Overlay'
))
);
expect
(
Navigator
.
canPop
(
containerKey1
.
currentContext
),
isFalse
);
Navigator
.
pushNamed
(
containerKey1
.
currentContext
,
'/settings'
);
...
...
@@ -36,63 +36,63 @@ void main() {
tester
.
pump
();
expect
(
tester
.
findText
(
'Home'
),
isOnStage
);
expect
(
tester
.
findText
(
'Settings'
),
isOffStage
);
expect
(
tester
.
findText
(
'Overlay'
),
isNull
);
expect
(
find
.
text
(
'Home'
),
isOnStage
(
tester
)
);
expect
(
find
.
text
(
'Settings'
),
isOffStage
(
tester
)
);
expect
(
tester
,
doesNotHaveWidget
(
find
.
text
(
'Overlay'
))
);
tester
.
pump
(
const
Duration
(
milliseconds:
16
));
expect
(
tester
.
findText
(
'Home'
),
isOnStage
);
expect
(
tester
.
findText
(
'Settings'
),
isOnStage
);
expect
(
tester
.
findText
(
'Overlay'
),
isNull
);
expect
(
find
.
text
(
'Home'
),
isOnStage
(
tester
)
);
expect
(
find
.
text
(
'Settings'
),
isOnStage
(
tester
)
);
expect
(
tester
,
doesNotHaveWidget
(
find
.
text
(
'Overlay'
))
);
tester
.
pump
(
const
Duration
(
seconds:
1
));
expect
(
tester
.
findText
(
'Home'
),
isNull
);
expect
(
tester
.
findText
(
'Settings'
),
isOnStage
);
expect
(
tester
.
findText
(
'Overlay'
),
isNull
);
expect
(
tester
,
doesNotHaveWidget
(
find
.
text
(
'Home'
))
);
expect
(
find
.
text
(
'Settings'
),
isOnStage
(
tester
)
);
expect
(
tester
,
doesNotHaveWidget
(
find
.
text
(
'Overlay'
))
);
Navigator
.
push
(
containerKey2
.
currentContext
,
new
TestOverlayRoute
());
tester
.
pump
();
expect
(
tester
.
findText
(
'Home'
),
isNull
);
expect
(
tester
.
findText
(
'Settings'
),
isOnStage
);
expect
(
tester
.
findText
(
'Overlay'
),
isOnStage
);
expect
(
tester
,
doesNotHaveWidget
(
find
.
text
(
'Home'
))
);
expect
(
find
.
text
(
'Settings'
),
isOnStage
(
tester
)
);
expect
(
find
.
text
(
'Overlay'
),
isOnStage
(
tester
)
);
tester
.
pump
(
const
Duration
(
seconds:
1
));
expect
(
tester
.
findText
(
'Home'
),
isNull
);
expect
(
tester
.
findText
(
'Settings'
),
isOnStage
);
expect
(
tester
.
findText
(
'Overlay'
),
isOnStage
);
expect
(
tester
,
doesNotHaveWidget
(
find
.
text
(
'Home'
))
);
expect
(
find
.
text
(
'Settings'
),
isOnStage
(
tester
)
);
expect
(
find
.
text
(
'Overlay'
),
isOnStage
(
tester
)
);
expect
(
Navigator
.
canPop
(
containerKey2
.
currentContext
),
isTrue
);
Navigator
.
pop
(
containerKey2
.
currentContext
);
tester
.
pump
();
expect
(
tester
.
findText
(
'Home'
),
isNull
);
expect
(
tester
.
findText
(
'Settings'
),
isOnStage
);
expect
(
tester
.
findText
(
'Overlay'
),
isNull
);
expect
(
tester
,
doesNotHaveWidget
(
find
.
text
(
'Home'
))
);
expect
(
find
.
text
(
'Settings'
),
isOnStage
(
tester
)
);
expect
(
tester
,
doesNotHaveWidget
(
find
.
text
(
'Overlay'
))
);
tester
.
pump
(
const
Duration
(
seconds:
1
));
expect
(
tester
.
findText
(
'Home'
),
isNull
);
expect
(
tester
.
findText
(
'Settings'
),
isOnStage
);
expect
(
tester
.
findText
(
'Overlay'
),
isNull
);
expect
(
tester
,
doesNotHaveWidget
(
find
.
text
(
'Home'
))
);
expect
(
find
.
text
(
'Settings'
),
isOnStage
(
tester
)
);
expect
(
tester
,
doesNotHaveWidget
(
find
.
text
(
'Overlay'
))
);
expect
(
Navigator
.
canPop
(
containerKey2
.
currentContext
),
isTrue
);
Navigator
.
pop
(
containerKey2
.
currentContext
);
tester
.
pump
();
expect
(
tester
.
findText
(
'Home'
),
isOnStage
);
expect
(
tester
.
findText
(
'Settings'
),
isOnStage
);
expect
(
tester
.
findText
(
'Overlay'
),
isNull
);
expect
(
find
.
text
(
'Home'
),
isOnStage
(
tester
)
);
expect
(
find
.
text
(
'Settings'
),
isOnStage
(
tester
)
);
expect
(
tester
,
doesNotHaveWidget
(
find
.
text
(
'Overlay'
))
);
tester
.
pump
(
const
Duration
(
seconds:
1
));
expect
(
tester
.
findText
(
'Home'
),
isOnStage
);
expect
(
tester
.
findText
(
'Settings'
),
isNull
);
expect
(
tester
.
findText
(
'Overlay'
),
isNull
);
expect
(
find
.
text
(
'Home'
),
isOnStage
(
tester
)
);
expect
(
tester
,
doesNotHaveWidget
(
find
.
text
(
'Settings'
))
);
expect
(
tester
,
doesNotHaveWidget
(
find
.
text
(
'Overlay'
))
);
expect
(
Navigator
.
canPop
(
containerKey1
.
currentContext
),
isFalse
);
...
...
packages/flutter/test/widget/pageable_list_test.dart
View file @
f3a4f722
...
...
@@ -44,7 +44,7 @@ Widget buildFrame({
void
page
(
WidgetTester
tester
,
Offset
offset
)
{
String
itemText
=
currentPage
!=
null
?
currentPage
.
toString
()
:
'0'
;
tester
.
scroll
(
tester
.
findT
ext
(
itemText
),
offset
);
tester
.
scroll
(
find
.
t
ext
(
itemText
),
offset
);
// One frame to start the animation, a second to complete it.
tester
.
pump
();
tester
.
pump
(
const
Duration
(
seconds:
1
));
...
...
@@ -67,22 +67,22 @@ void main() {
pageLeft
(
tester
);
expect
(
currentPage
,
equals
(
1
));
expect
(
tester
.
findText
(
'0'
),
isNull
);
expect
(
tester
.
findText
(
'1'
),
isNotNull
);
expect
(
tester
.
findText
(
'2'
),
isNull
);
expect
(
tester
.
findText
(
'3'
),
isNull
);
expect
(
tester
.
findText
(
'4'
),
isNull
);
expect
(
tester
.
findText
(
'5'
),
isNull
);
expect
(
tester
,
doesNotHaveWidget
(
find
.
text
(
'0'
))
);
expect
(
tester
,
hasWidget
(
find
.
text
(
'1'
))
);
expect
(
tester
,
doesNotHaveWidget
(
find
.
text
(
'2'
))
);
expect
(
tester
,
doesNotHaveWidget
(
find
.
text
(
'3'
))
);
expect
(
tester
,
doesNotHaveWidget
(
find
.
text
(
'4'
))
);
expect
(
tester
,
doesNotHaveWidget
(
find
.
text
(
'5'
))
);
pageRight
(
tester
);
expect
(
currentPage
,
equals
(
0
));
expect
(
tester
.
findText
(
'0'
),
isNotNull
);
expect
(
tester
.
findText
(
'1'
),
isNull
);
expect
(
tester
.
findText
(
'2'
),
isNull
);
expect
(
tester
.
findText
(
'3'
),
isNull
);
expect
(
tester
.
findText
(
'4'
),
isNull
);
expect
(
tester
.
findText
(
'5'
),
isNull
);
expect
(
tester
,
hasWidget
(
find
.
text
(
'0'
))
);
expect
(
tester
,
doesNotHaveWidget
(
find
.
text
(
'1'
))
);
expect
(
tester
,
doesNotHaveWidget
(
find
.
text
(
'2'
))
);
expect
(
tester
,
doesNotHaveWidget
(
find
.
text
(
'3'
))
);
expect
(
tester
,
doesNotHaveWidget
(
find
.
text
(
'4'
))
);
expect
(
tester
,
doesNotHaveWidget
(
find
.
text
(
'5'
))
);
pageRight
(
tester
);
expect
(
currentPage
,
equals
(
0
));
...
...
@@ -96,32 +96,32 @@ void main() {
pageRight
(
tester
);
expect
(
currentPage
,
equals
(
4
));
expect
(
tester
.
findText
(
'0'
),
isNull
);
expect
(
tester
.
findText
(
'1'
),
isNull
);
expect
(
tester
.
findText
(
'2'
),
isNull
);
expect
(
tester
.
findText
(
'3'
),
isNull
);
expect
(
tester
.
findText
(
'4'
),
isNotNull
);
expect
(
tester
.
findText
(
'5'
),
isNull
);
expect
(
tester
,
doesNotHaveWidget
(
find
.
text
(
'0'
))
);
expect
(
tester
,
doesNotHaveWidget
(
find
.
text
(
'1'
))
);
expect
(
tester
,
doesNotHaveWidget
(
find
.
text
(
'2'
))
);
expect
(
tester
,
doesNotHaveWidget
(
find
.
text
(
'3'
))
);
expect
(
tester
,
hasWidget
(
find
.
text
(
'4'
))
);
expect
(
tester
,
doesNotHaveWidget
(
find
.
text
(
'5'
))
);
pageLeft
(
tester
);
expect
(
currentPage
,
equals
(
5
));
expect
(
tester
.
findText
(
'0'
),
isNull
);
expect
(
tester
.
findText
(
'1'
),
isNull
);
expect
(
tester
.
findText
(
'2'
),
isNull
);
expect
(
tester
.
findText
(
'3'
),
isNull
);
expect
(
tester
.
findText
(
'4'
),
isNull
);
expect
(
tester
.
findText
(
'5'
),
isNotNull
);
expect
(
tester
,
doesNotHaveWidget
(
find
.
text
(
'0'
))
);
expect
(
tester
,
doesNotHaveWidget
(
find
.
text
(
'1'
))
);
expect
(
tester
,
doesNotHaveWidget
(
find
.
text
(
'2'
))
);
expect
(
tester
,
doesNotHaveWidget
(
find
.
text
(
'3'
))
);
expect
(
tester
,
doesNotHaveWidget
(
find
.
text
(
'4'
))
);
expect
(
tester
,
hasWidget
(
find
.
text
(
'5'
))
);
pageLeft
(
tester
);
expect
(
currentPage
,
equals
(
5
));
expect
(
tester
.
findText
(
'0'
),
isNull
);
expect
(
tester
.
findText
(
'1'
),
isNull
);
expect
(
tester
.
findText
(
'2'
),
isNull
);
expect
(
tester
.
findText
(
'3'
),
isNull
);
expect
(
tester
.
findText
(
'4'
),
isNull
);
expect
(
tester
.
findText
(
'5'
),
isNotNull
);
expect
(
tester
,
doesNotHaveWidget
(
find
.
text
(
'0'
))
);
expect
(
tester
,
doesNotHaveWidget
(
find
.
text
(
'1'
))
);
expect
(
tester
,
doesNotHaveWidget
(
find
.
text
(
'2'
))
);
expect
(
tester
,
doesNotHaveWidget
(
find
.
text
(
'3'
))
);
expect
(
tester
,
doesNotHaveWidget
(
find
.
text
(
'4'
))
);
expect
(
tester
,
hasWidget
(
find
.
text
(
'5'
))
);
});
});
...
...
@@ -146,42 +146,42 @@ void main() {
pageRight
(
tester
);
expect
(
currentPage
,
equals
(
4
));
expect
(
tester
.
findText
(
'0'
),
isNull
);
expect
(
tester
.
findText
(
'1'
),
isNull
);
expect
(
tester
.
findText
(
'2'
),
isNull
);
expect
(
tester
.
findText
(
'3'
),
isNull
);
expect
(
tester
.
findText
(
'4'
),
isNotNull
);
expect
(
tester
.
findText
(
'5'
),
isNull
);
expect
(
tester
,
doesNotHaveWidget
(
find
.
text
(
'0'
))
);
expect
(
tester
,
doesNotHaveWidget
(
find
.
text
(
'1'
))
);
expect
(
tester
,
doesNotHaveWidget
(
find
.
text
(
'2'
))
);
expect
(
tester
,
doesNotHaveWidget
(
find
.
text
(
'3'
))
);
expect
(
tester
,
hasWidget
(
find
.
text
(
'4'
))
);
expect
(
tester
,
doesNotHaveWidget
(
find
.
text
(
'5'
))
);
pageLeft
(
tester
);
expect
(
currentPage
,
equals
(
5
));
expect
(
tester
.
findText
(
'0'
),
isNull
);
expect
(
tester
.
findText
(
'1'
),
isNull
);
expect
(
tester
.
findText
(
'2'
),
isNull
);
expect
(
tester
.
findText
(
'3'
),
isNull
);
expect
(
tester
.
findText
(
'4'
),
isNull
);
expect
(
tester
.
findText
(
'5'
),
isNotNull
);
expect
(
tester
,
doesNotHaveWidget
(
find
.
text
(
'0'
))
);
expect
(
tester
,
doesNotHaveWidget
(
find
.
text
(
'1'
))
);
expect
(
tester
,
doesNotHaveWidget
(
find
.
text
(
'2'
))
);
expect
(
tester
,
doesNotHaveWidget
(
find
.
text
(
'3'
))
);
expect
(
tester
,
doesNotHaveWidget
(
find
.
text
(
'4'
))
);
expect
(
tester
,
hasWidget
(
find
.
text
(
'5'
))
);
pageLeft
(
tester
);
expect
(
currentPage
,
equals
(
0
));
expect
(
tester
.
findText
(
'0'
),
isNotNull
);
expect
(
tester
.
findText
(
'1'
),
isNull
);
expect
(
tester
.
findText
(
'2'
),
isNull
);
expect
(
tester
.
findText
(
'3'
),
isNull
);
expect
(
tester
.
findText
(
'4'
),
isNull
);
expect
(
tester
.
findText
(
'5'
),
isNull
);
expect
(
tester
,
hasWidget
(
find
.
text
(
'0'
))
);
expect
(
tester
,
doesNotHaveWidget
(
find
.
text
(
'1'
))
);
expect
(
tester
,
doesNotHaveWidget
(
find
.
text
(
'2'
))
);
expect
(
tester
,
doesNotHaveWidget
(
find
.
text
(
'3'
))
);
expect
(
tester
,
doesNotHaveWidget
(
find
.
text
(
'4'
))
);
expect
(
tester
,
doesNotHaveWidget
(
find
.
text
(
'5'
))
);
pageLeft
(
tester
);
expect
(
currentPage
,
equals
(
1
));
expect
(
tester
.
findText
(
'0'
),
isNull
);
expect
(
tester
.
findText
(
'1'
),
isNotNull
);
expect
(
tester
.
findText
(
'2'
),
isNull
);
expect
(
tester
.
findText
(
'3'
),
isNull
);
expect
(
tester
.
findText
(
'4'
),
isNull
);
expect
(
tester
.
findText
(
'5'
),
isNull
);
expect
(
tester
,
doesNotHaveWidget
(
find
.
text
(
'0'
))
);
expect
(
tester
,
hasWidget
(
find
.
text
(
'1'
))
);
expect
(
tester
,
doesNotHaveWidget
(
find
.
text
(
'2'
))
);
expect
(
tester
,
doesNotHaveWidget
(
find
.
text
(
'3'
))
);
expect
(
tester
,
doesNotHaveWidget
(
find
.
text
(
'4'
))
);
expect
(
tester
,
doesNotHaveWidget
(
find
.
text
(
'5'
))
);
});
});
...
...
@@ -238,12 +238,12 @@ void main() {
pageSize
=
new
Size
(
pageSize
.
height
,
pageSize
.
width
);
tester
.
pumpWidget
(
buildFrame
(
itemsWrap:
true
));
expect
(
tester
.
findText
(
'0'
),
isNull
);
expect
(
tester
.
findText
(
'1'
),
isNull
);
expect
(
tester
.
findText
(
'2'
),
isNull
);
expect
(
tester
.
findText
(
'3'
),
isNull
);
expect
(
tester
.
findText
(
'4'
),
isNull
);
expect
(
tester
.
findText
(
'5'
),
isNotNull
);
expect
(
tester
,
doesNotHaveWidget
(
find
.
text
(
'0'
))
);
expect
(
tester
,
doesNotHaveWidget
(
find
.
text
(
'1'
))
);
expect
(
tester
,
doesNotHaveWidget
(
find
.
text
(
'2'
))
);
expect
(
tester
,
doesNotHaveWidget
(
find
.
text
(
'3'
))
);
expect
(
tester
,
doesNotHaveWidget
(
find
.
text
(
'4'
))
);
expect
(
tester
,
hasWidget
(
find
.
text
(
'5'
))
);
box
=
globalKeys
[
5
].
currentContext
.
findRenderObject
();
expect
(
box
.
size
.
width
,
equals
(
pageSize
.
width
));
...
...
packages/flutter/test/widget/parent_data_test.dart
View file @
f3a4f722
...
...
@@ -20,7 +20,7 @@ class TestParentData {
void
checkTree
(
WidgetTester
tester
,
List
<
TestParentData
>
expectedParentData
)
{
MultiChildRenderObjectElement
element
=
tester
.
findElement
((
Element
element
)
=>
element
is
MultiChildRenderObjectElement
);
tester
.
elementOf
(
find
.
byElement
((
Element
element
)
=>
element
is
MultiChildRenderObjectElement
)
);
expect
(
element
,
isNotNull
);
expect
(
element
.
renderObject
is
RenderStack
,
isTrue
);
RenderStack
renderObject
=
element
.
renderObject
;
...
...
packages/flutter/test/widget/progress_indicator_test.dart
View file @
f3a4f722
...
...
@@ -9,7 +9,7 @@ import 'package:test/test.dart';
void
main
(
)
{
test
(
'LinearProgressIndicator changes when its value changes'
,
()
{
test
Widgets
((
Widget
Tester
tester
)
{
test
ElementTree
((
ElementTree
Tester
tester
)
{
tester
.
pumpWidget
(
new
Block
(
children:
<
Widget
>[
new
LinearProgressIndicator
(
value:
0.0
)]));
List
<
Layer
>
layers1
=
tester
.
layers
;
...
...
packages/flutter/test/widget/remember_scroll_position_test.dart
View file @
f3a4f722
...
...
@@ -38,36 +38,34 @@ void main() {
// we're 600 pixels high, each item is 100 pixels high, scroll position is
// zero, so we should have exactly 6 items, 0..5.
expect
(
tester
.
findText
(
'0'
),
isNotNull
);
expect
(
tester
.
findText
(
'1'
),
isNotNull
);
expect
(
tester
.
findText
(
'2'
),
isNotNull
);
expect
(
tester
.
findText
(
'3'
),
isNotNull
);
expect
(
tester
.
findText
(
'4'
),
isNotNull
);
expect
(
tester
.
findText
(
'5'
),
isNotNull
);
expect
(
tester
.
findText
(
'6'
),
isNull
);
expect
(
tester
.
findText
(
'10'
),
isNull
);
expect
(
tester
.
findText
(
'100'
),
isNull
);
expect
(
tester
,
hasWidget
(
find
.
text
(
'0'
))
);
expect
(
tester
,
hasWidget
(
find
.
text
(
'1'
))
);
expect
(
tester
,
hasWidget
(
find
.
text
(
'2'
))
);
expect
(
tester
,
hasWidget
(
find
.
text
(
'3'
))
);
expect
(
tester
,
hasWidget
(
find
.
text
(
'4'
))
);
expect
(
tester
,
hasWidget
(
find
.
text
(
'5'
))
);
expect
(
tester
,
doesNotHaveWidget
(
find
.
text
(
'6'
))
);
expect
(
tester
,
doesNotHaveWidget
(
find
.
text
(
'10'
))
);
expect
(
tester
,
doesNotHaveWidget
(
find
.
text
(
'100'
))
);
StatefulElement
target
=
tester
.
findElement
((
Element
element
)
=>
element
.
widget
is
ScrollableLazyList
);
ScrollableState
targetState
=
target
.
state
;
ScrollableState
targetState
=
tester
.
stateOf
(
find
.
byType
(
ScrollableLazyList
));
targetState
.
scrollTo
(
1000.0
);
tester
.
pump
(
new
Duration
(
seconds:
1
));
// we're 600 pixels high, each item is 100 pixels high, scroll position is
// 1000, so we should have exactly 6 items, 10..15.
expect
(
tester
.
findText
(
'0'
),
isNull
);
expect
(
tester
.
findText
(
'8'
),
isNull
);
expect
(
tester
.
findText
(
'9'
),
isNull
);
expect
(
tester
.
findText
(
'10'
),
isNotNull
);
expect
(
tester
.
findText
(
'11'
),
isNotNull
);
expect
(
tester
.
findText
(
'12'
),
isNotNull
);
expect
(
tester
.
findText
(
'13'
),
isNotNull
);
expect
(
tester
.
findText
(
'14'
),
isNotNull
);
expect
(
tester
.
findText
(
'15'
),
isNotNull
);
expect
(
tester
.
findText
(
'16'
),
isNull
);
expect
(
tester
.
findText
(
'100'
),
isNull
);
expect
(
tester
,
doesNotHaveWidget
(
find
.
text
(
'0'
))
);
expect
(
tester
,
doesNotHaveWidget
(
find
.
text
(
'8'
))
);
expect
(
tester
,
doesNotHaveWidget
(
find
.
text
(
'9'
))
);
expect
(
tester
,
hasWidget
(
find
.
text
(
'10'
))
);
expect
(
tester
,
hasWidget
(
find
.
text
(
'11'
))
);
expect
(
tester
,
hasWidget
(
find
.
text
(
'12'
))
);
expect
(
tester
,
hasWidget
(
find
.
text
(
'13'
))
);
expect
(
tester
,
hasWidget
(
find
.
text
(
'14'
))
);
expect
(
tester
,
hasWidget
(
find
.
text
(
'15'
))
);
expect
(
tester
,
doesNotHaveWidget
(
find
.
text
(
'16'
))
);
expect
(
tester
,
doesNotHaveWidget
(
find
.
text
(
'100'
))
);
navigatorKey
.
currentState
.
openTransaction
(
(
NavigatorTransaction
transaction
)
=>
transaction
.
pushNamed
(
'/second'
)
...
...
@@ -76,15 +74,15 @@ void main() {
tester
.
pump
(
new
Duration
(
seconds:
1
));
// same as the first list again
expect
(
tester
.
findText
(
'0'
),
isNotNull
);
expect
(
tester
.
findText
(
'1'
),
isNotNull
);
expect
(
tester
.
findText
(
'2'
),
isNotNull
);
expect
(
tester
.
findText
(
'3'
),
isNotNull
);
expect
(
tester
.
findText
(
'4'
),
isNotNull
);
expect
(
tester
.
findText
(
'5'
),
isNotNull
);
expect
(
tester
.
findText
(
'6'
),
isNull
);
expect
(
tester
.
findText
(
'10'
),
isNull
);
expect
(
tester
.
findText
(
'100'
),
isNull
);
expect
(
tester
,
hasWidget
(
find
.
text
(
'0'
))
);
expect
(
tester
,
hasWidget
(
find
.
text
(
'1'
))
);
expect
(
tester
,
hasWidget
(
find
.
text
(
'2'
))
);
expect
(
tester
,
hasWidget
(
find
.
text
(
'3'
))
);
expect
(
tester
,
hasWidget
(
find
.
text
(
'4'
))
);
expect
(
tester
,
hasWidget
(
find
.
text
(
'5'
))
);
expect
(
tester
,
doesNotHaveWidget
(
find
.
text
(
'6'
))
);
expect
(
tester
,
doesNotHaveWidget
(
find
.
text
(
'10'
))
);
expect
(
tester
,
doesNotHaveWidget
(
find
.
text
(
'100'
))
);
navigatorKey
.
currentState
.
openTransaction
(
(
NavigatorTransaction
transaction
)
=>
transaction
.
pop
()
...
...
@@ -95,17 +93,17 @@ void main() {
// we're 600 pixels high, each item is 100 pixels high, scroll position is
// 1000, so we should have exactly 6 items, 10..15.
expect
(
tester
.
findText
(
'0'
),
isNull
);
expect
(
tester
.
findText
(
'8'
),
isNull
);
expect
(
tester
.
findText
(
'9'
),
isNull
);
expect
(
tester
.
findText
(
'10'
),
isNotNull
);
expect
(
tester
.
findText
(
'11'
),
isNotNull
);
expect
(
tester
.
findText
(
'12'
),
isNotNull
);
expect
(
tester
.
findText
(
'13'
),
isNotNull
);
expect
(
tester
.
findText
(
'14'
),
isNotNull
);
expect
(
tester
.
findText
(
'15'
),
isNotNull
);
expect
(
tester
.
findText
(
'16'
),
isNull
);
expect
(
tester
.
findText
(
'100'
),
isNull
);
expect
(
tester
,
doesNotHaveWidget
(
find
.
text
(
'0'
))
);
expect
(
tester
,
doesNotHaveWidget
(
find
.
text
(
'8'
))
);
expect
(
tester
,
doesNotHaveWidget
(
find
.
text
(
'9'
))
);
expect
(
tester
,
hasWidget
(
find
.
text
(
'10'
))
);
expect
(
tester
,
hasWidget
(
find
.
text
(
'11'
))
);
expect
(
tester
,
hasWidget
(
find
.
text
(
'12'
))
);
expect
(
tester
,
hasWidget
(
find
.
text
(
'13'
))
);
expect
(
tester
,
hasWidget
(
find
.
text
(
'14'
))
);
expect
(
tester
,
hasWidget
(
find
.
text
(
'15'
))
);
expect
(
tester
,
doesNotHaveWidget
(
find
.
text
(
'16'
))
);
expect
(
tester
,
doesNotHaveWidget
(
find
.
text
(
'100'
))
);
});
});
...
...
packages/flutter/test/widget/render_object_widget_test.dart
View file @
f3a4f722
...
...
@@ -43,7 +43,7 @@ class TestOrientedBox extends SingleChildRenderObjectWidget {
void
main
(
)
{
test
(
'RenderObjectWidget smoke test'
,
()
{
test
Widgets
((
Widget
Tester
tester
)
{
test
ElementTree
((
ElementTree
Tester
tester
)
{
tester
.
pumpWidget
(
new
DecoratedBox
(
decoration:
kBoxDecorationA
));
SingleChildRenderObjectElement
element
=
tester
.
findElement
((
Element
element
)
=>
element
is
SingleChildRenderObjectElement
);
...
...
@@ -64,7 +64,7 @@ void main() {
});
test
(
'RenderObjectWidget can add and remove children'
,
()
{
test
Widgets
((
Widget
Tester
tester
)
{
test
ElementTree
((
ElementTree
Tester
tester
)
{
void
checkFullTree
()
{
SingleChildRenderObjectElement
element
=
...
...
@@ -150,7 +150,7 @@ void main() {
});
test
(
'Detached render tree is intact'
,
()
{
test
Widgets
((
Widget
Tester
tester
)
{
test
ElementTree
((
ElementTree
Tester
tester
)
{
tester
.
pumpWidget
(
new
DecoratedBox
(
decoration:
kBoxDecorationA
,
...
...
@@ -194,7 +194,7 @@ void main() {
});
test
(
'Can watch inherited widgets'
,
()
{
test
Widgets
((
Widget
Tester
tester
)
{
test
ElementTree
((
ElementTree
Tester
tester
)
{
Key
boxKey
=
new
UniqueKey
();
TestOrientedBox
box
=
new
TestOrientedBox
(
key:
boxKey
);
...
...
packages/flutter/test/widget/reparent_state_test.dart
View file @
f3a4f722
...
...
@@ -77,7 +77,7 @@ void main() {
StateMarkerState
rightState
=
right
.
currentState
;
rightState
.
marker
=
"right"
;
StateMarkerState
grandchildState
=
tester
.
findStateByConfig
(
grandchild
);
StateMarkerState
grandchildState
=
tester
.
stateOf
(
find
.
byConfig
(
grandchild
)
);
expect
(
grandchildState
,
isNotNull
);
grandchildState
.
marker
=
"grandchild"
;
...
...
@@ -103,7 +103,7 @@ void main() {
expect
(
right
.
currentState
,
equals
(
rightState
));
expect
(
rightState
.
marker
,
equals
(
"right"
));
StateMarkerState
newGrandchildState
=
tester
.
findStateByConfig
(
newGrandchild
);
StateMarkerState
newGrandchildState
=
tester
.
stateOf
(
find
.
byConfig
(
newGrandchild
)
);
expect
(
newGrandchildState
,
isNotNull
);
expect
(
newGrandchildState
,
equals
(
grandchildState
));
expect
(
newGrandchildState
.
marker
,
equals
(
"grandchild"
));
...
...
@@ -148,7 +148,7 @@ void main() {
StateMarkerState
rightState
=
right
.
currentState
;
rightState
.
marker
=
"right"
;
StateMarkerState
grandchildState
=
tester
.
findStateByConfig
(
grandchild
);
StateMarkerState
grandchildState
=
tester
.
stateOf
(
find
.
byConfig
(
grandchild
)
);
expect
(
grandchildState
,
isNotNull
);
grandchildState
.
marker
=
"grandchild"
;
...
...
@@ -170,7 +170,7 @@ void main() {
expect
(
right
.
currentState
,
equals
(
rightState
));
expect
(
rightState
.
marker
,
equals
(
"right"
));
StateMarkerState
newGrandchildState
=
tester
.
findStateByConfig
(
newGrandchild
);
StateMarkerState
newGrandchildState
=
tester
.
stateOf
(
find
.
byConfig
(
newGrandchild
)
);
expect
(
newGrandchildState
,
isNotNull
);
expect
(
newGrandchildState
,
equals
(
grandchildState
));
expect
(
newGrandchildState
.
marker
,
equals
(
"grandchild"
));
...
...
packages/flutter/test/widget/rotated_box_test.dart
View file @
f3a4f722
...
...
@@ -42,7 +42,7 @@ void main() {
)
);
RenderBox
box
=
tester
.
findElementByKey
(
rotatedBoxKey
).
renderObject
;
RenderBox
box
=
tester
.
elementTreeTester
.
findElementByKey
(
rotatedBoxKey
).
renderObject
;
expect
(
box
.
size
.
width
,
equals
(
65.0
));
expect
(
box
.
size
.
height
,
equals
(
175.0
));
...
...
packages/flutter/test/widget/scrollable_lazy_list_test.dart
View file @
f3a4f722
...
...
@@ -39,8 +39,7 @@ void main() {
tester
.
pumpWidget
(
builder
());
StatefulElement
element
=
tester
.
findElement
((
Element
element
)
=>
element
.
widget
is
FlipWidget
);
FlipWidgetState
testWidget
=
element
.
state
;
FlipWidgetState
testWidget
=
tester
.
stateOf
(
find
.
byType
(
FlipWidget
));
expect
(
callbackTracker
,
equals
([
0
,
1
,
2
,
3
,
4
,
5
]));
...
...
packages/flutter/test/widget/scrollable_list_hit_testing_test.dart
View file @
f3a4f722
...
...
@@ -31,21 +31,21 @@ void main() {
)
)
));
tester
.
scroll
(
tester
.
findT
ext
(
'2'
),
const
Offset
(-
280.0
,
0.0
));
tester
.
scroll
(
find
.
t
ext
(
'2'
),
const
Offset
(-
280.0
,
0.0
));
tester
.
pump
(
const
Duration
(
seconds:
1
));
// screen is 800px wide, and has the following items:
// -280..10 = 0
// 10..300 = 1
// 300..590 = 2
// 590..880 = 3
expect
(
tester
.
findText
(
'0'
),
isNotNull
);
expect
(
tester
.
findText
(
'1'
),
isNotNull
);
expect
(
tester
.
findText
(
'2'
),
isNotNull
);
expect
(
tester
.
findText
(
'3'
),
isNotNull
);
expect
(
tester
.
findText
(
'4'
),
isNull
);
expect
(
tester
.
findText
(
'5'
),
isNull
);
expect
(
tester
,
hasWidget
(
find
.
text
(
'0'
))
);
expect
(
tester
,
hasWidget
(
find
.
text
(
'1'
))
);
expect
(
tester
,
hasWidget
(
find
.
text
(
'2'
))
);
expect
(
tester
,
hasWidget
(
find
.
text
(
'3'
))
);
expect
(
tester
,
doesNotHaveWidget
(
find
.
text
(
'4'
))
);
expect
(
tester
,
doesNotHaveWidget
(
find
.
text
(
'5'
))
);
expect
(
tapped
,
equals
([]));
tester
.
tap
(
tester
.
findT
ext
(
'2'
));
tester
.
tap
(
find
.
t
ext
(
'2'
));
expect
(
tapped
,
equals
([
2
]));
});
});
...
...
@@ -71,23 +71,23 @@ void main() {
)
)
));
tester
.
scroll
(
tester
.
findT
ext
(
'1'
),
const
Offset
(
0.0
,
-
280.0
));
tester
.
scroll
(
find
.
t
ext
(
'1'
),
const
Offset
(
0.0
,
-
280.0
));
tester
.
pump
(
const
Duration
(
seconds:
1
));
// screen is 600px tall, and has the following items:
// -280..10 = 0
// 10..300 = 1
// 300..590 = 2
// 590..880 = 3
expect
(
tester
.
findText
(
'0'
),
isNotNull
);
expect
(
tester
.
findText
(
'1'
),
isNotNull
);
expect
(
tester
.
findText
(
'2'
),
isNotNull
);
expect
(
tester
.
findText
(
'3'
),
isNotNull
);
expect
(
tester
.
findText
(
'4'
),
isNull
);
expect
(
tester
.
findText
(
'5'
),
isNull
);
expect
(
tester
,
hasWidget
(
find
.
text
(
'0'
))
);
expect
(
tester
,
hasWidget
(
find
.
text
(
'1'
))
);
expect
(
tester
,
hasWidget
(
find
.
text
(
'2'
))
);
expect
(
tester
,
hasWidget
(
find
.
text
(
'3'
))
);
expect
(
tester
,
doesNotHaveWidget
(
find
.
text
(
'4'
))
);
expect
(
tester
,
doesNotHaveWidget
(
find
.
text
(
'5'
))
);
expect
(
tapped
,
equals
([]));
tester
.
tap
(
tester
.
findT
ext
(
'1'
));
tester
.
tap
(
find
.
t
ext
(
'1'
));
expect
(
tapped
,
equals
([
1
]));
tester
.
tap
(
tester
.
findT
ext
(
'3'
));
tester
.
tap
(
find
.
t
ext
(
'3'
));
expect
(
tapped
,
equals
([
1
]));
// the center of the third item is off-screen so it shouldn't get hit
});
});
...
...
packages/flutter/test/widget/scrollable_list_horizontal_test.dart
View file @
f3a4f722
...
...
@@ -33,60 +33,60 @@ void main() {
tester
.
pumpWidget
(
buildFrame
(
ViewportAnchor
.
start
));
tester
.
pump
(
const
Duration
(
seconds:
1
));
tester
.
scroll
(
tester
.
findT
ext
(
'1'
),
const
Offset
(-
300.0
,
0.0
));
tester
.
scroll
(
find
.
t
ext
(
'1'
),
const
Offset
(-
300.0
,
0.0
));
tester
.
pump
(
const
Duration
(
seconds:
1
));
// screen is 800px wide, and has the following items:
// -10..280 = 1
// 280..570 = 2
// 570..860 = 3
expect
(
tester
.
findText
(
'0'
),
isNull
);
expect
(
tester
.
findText
(
'1'
),
isNotNull
);
expect
(
tester
.
findText
(
'2'
),
isNotNull
);
expect
(
tester
.
findText
(
'3'
),
isNotNull
);
expect
(
tester
.
findText
(
'4'
),
isNull
);
expect
(
tester
.
findText
(
'5'
),
isNull
);
expect
(
tester
,
doesNotHaveWidget
(
find
.
text
(
'0'
))
);
expect
(
tester
,
hasWidget
(
find
.
text
(
'1'
))
);
expect
(
tester
,
hasWidget
(
find
.
text
(
'2'
))
);
expect
(
tester
,
hasWidget
(
find
.
text
(
'3'
))
);
expect
(
tester
,
doesNotHaveWidget
(
find
.
text
(
'4'
))
);
expect
(
tester
,
doesNotHaveWidget
(
find
.
text
(
'5'
))
);
// the center of item 3 is visible, so this works;
// if item 3 was a bit wider, such that its center was past the 800px mark, this would fail,
// because it wouldn't be hit tested when scrolling from its center, as scroll() does.
tester
.
pump
(
const
Duration
(
seconds:
1
));
tester
.
scroll
(
tester
.
findT
ext
(
'3'
),
const
Offset
(-
290.0
,
0.0
));
tester
.
scroll
(
find
.
t
ext
(
'3'
),
const
Offset
(-
290.0
,
0.0
));
tester
.
pump
(
const
Duration
(
seconds:
1
));
// screen is 800px wide, and has the following items:
// -10..280 = 2
// 280..570 = 3
// 570..860 = 4
expect
(
tester
.
findText
(
'0'
),
isNull
);
expect
(
tester
.
findText
(
'1'
),
isNull
);
expect
(
tester
.
findText
(
'2'
),
isNotNull
);
expect
(
tester
.
findText
(
'3'
),
isNotNull
);
expect
(
tester
.
findText
(
'4'
),
isNotNull
);
expect
(
tester
.
findText
(
'5'
),
isNull
);
expect
(
tester
,
doesNotHaveWidget
(
find
.
text
(
'0'
))
);
expect
(
tester
,
doesNotHaveWidget
(
find
.
text
(
'1'
))
);
expect
(
tester
,
hasWidget
(
find
.
text
(
'2'
))
);
expect
(
tester
,
hasWidget
(
find
.
text
(
'3'
))
);
expect
(
tester
,
hasWidget
(
find
.
text
(
'4'
))
);
expect
(
tester
,
doesNotHaveWidget
(
find
.
text
(
'5'
))
);
tester
.
pump
(
const
Duration
(
seconds:
1
));
tester
.
scroll
(
tester
.
findT
ext
(
'3'
),
const
Offset
(
0.0
,
-
290.0
));
tester
.
scroll
(
find
.
t
ext
(
'3'
),
const
Offset
(
0.0
,
-
290.0
));
tester
.
pump
(
const
Duration
(
seconds:
1
));
// unchanged
expect
(
tester
.
findText
(
'0'
),
isNull
);
expect
(
tester
.
findText
(
'1'
),
isNull
);
expect
(
tester
.
findText
(
'2'
),
isNotNull
);
expect
(
tester
.
findText
(
'3'
),
isNotNull
);
expect
(
tester
.
findText
(
'4'
),
isNotNull
);
expect
(
tester
.
findText
(
'5'
),
isNull
);
expect
(
tester
,
doesNotHaveWidget
(
find
.
text
(
'0'
))
);
expect
(
tester
,
doesNotHaveWidget
(
find
.
text
(
'1'
))
);
expect
(
tester
,
hasWidget
(
find
.
text
(
'2'
))
);
expect
(
tester
,
hasWidget
(
find
.
text
(
'3'
))
);
expect
(
tester
,
hasWidget
(
find
.
text
(
'4'
))
);
expect
(
tester
,
doesNotHaveWidget
(
find
.
text
(
'5'
))
);
tester
.
pump
(
const
Duration
(
seconds:
1
));
tester
.
scroll
(
tester
.
findT
ext
(
'3'
),
const
Offset
(-
290.0
,
0.0
));
tester
.
scroll
(
find
.
t
ext
(
'3'
),
const
Offset
(-
290.0
,
0.0
));
tester
.
pump
(
const
Duration
(
seconds:
1
));
// screen is 800px wide, and has the following items:
// -10..280 = 3
// 280..570 = 4
// 570..860 = 5
expect
(
tester
.
findText
(
'0'
),
isNull
);
expect
(
tester
.
findText
(
'1'
),
isNull
);
expect
(
tester
.
findText
(
'2'
),
isNull
);
expect
(
tester
.
findText
(
'3'
),
isNotNull
);
expect
(
tester
.
findText
(
'4'
),
isNotNull
);
expect
(
tester
.
findText
(
'5'
),
isNotNull
);
expect
(
tester
,
doesNotHaveWidget
(
find
.
text
(
'0'
))
);
expect
(
tester
,
doesNotHaveWidget
(
find
.
text
(
'1'
))
);
expect
(
tester
,
doesNotHaveWidget
(
find
.
text
(
'2'
))
);
expect
(
tester
,
hasWidget
(
find
.
text
(
'3'
))
);
expect
(
tester
,
hasWidget
(
find
.
text
(
'4'
))
);
expect
(
tester
,
hasWidget
(
find
.
text
(
'5'
))
);
tester
.
pump
(
const
Duration
(
seconds:
1
));
// at this point we can drag 60 pixels further before we hit the friction zone
...
...
@@ -94,58 +94,58 @@ void main() {
// to move item 3 entirely off screen therefore takes:
// 60 + (290-60)*2 = 520 pixels
// plus a couple more to be sure
tester
.
scroll
(
tester
.
findT
ext
(
'3'
),
const
Offset
(-
522.0
,
0.0
));
tester
.
scroll
(
find
.
t
ext
(
'3'
),
const
Offset
(-
522.0
,
0.0
));
tester
.
pump
();
// just after release
// screen is 800px wide, and has the following items:
// -11..279 = 4
// 279..569 = 5
expect
(
tester
.
findText
(
'0'
),
isNull
);
expect
(
tester
.
findText
(
'1'
),
isNull
);
expect
(
tester
.
findText
(
'2'
),
isNull
);
expect
(
tester
.
findText
(
'3'
),
isNull
);
expect
(
tester
.
findText
(
'4'
),
isNotNull
);
expect
(
tester
.
findText
(
'5'
),
isNotNull
);
expect
(
tester
,
doesNotHaveWidget
(
find
.
text
(
'0'
))
);
expect
(
tester
,
doesNotHaveWidget
(
find
.
text
(
'1'
))
);
expect
(
tester
,
doesNotHaveWidget
(
find
.
text
(
'2'
))
);
expect
(
tester
,
doesNotHaveWidget
(
find
.
text
(
'3'
))
);
expect
(
tester
,
hasWidget
(
find
.
text
(
'4'
))
);
expect
(
tester
,
hasWidget
(
find
.
text
(
'5'
))
);
tester
.
pump
(
const
Duration
(
seconds:
1
));
// a second after release
// screen is 800px wide, and has the following items:
// -70..220 = 3
// 220..510 = 4
// 510..800 = 5
expect
(
tester
.
findText
(
'0'
),
isNull
);
expect
(
tester
.
findText
(
'1'
),
isNull
);
expect
(
tester
.
findText
(
'2'
),
isNull
);
expect
(
tester
.
findText
(
'3'
),
isNotNull
);
expect
(
tester
.
findText
(
'4'
),
isNotNull
);
expect
(
tester
.
findText
(
'5'
),
isNotNull
);
expect
(
tester
,
doesNotHaveWidget
(
find
.
text
(
'0'
))
);
expect
(
tester
,
doesNotHaveWidget
(
find
.
text
(
'1'
))
);
expect
(
tester
,
doesNotHaveWidget
(
find
.
text
(
'2'
))
);
expect
(
tester
,
hasWidget
(
find
.
text
(
'3'
))
);
expect
(
tester
,
hasWidget
(
find
.
text
(
'4'
))
);
expect
(
tester
,
hasWidget
(
find
.
text
(
'5'
))
);
tester
.
pumpWidget
(
new
Container
());
tester
.
pumpWidget
(
buildFrame
(
ViewportAnchor
.
start
),
const
Duration
(
seconds:
1
));
tester
.
scroll
(
tester
.
findT
ext
(
'2'
),
const
Offset
(-
280.0
,
0.0
));
tester
.
scroll
(
find
.
t
ext
(
'2'
),
const
Offset
(-
280.0
,
0.0
));
tester
.
pump
(
const
Duration
(
seconds:
1
));
// screen is 800px wide, and has the following items:
// -280..10 = 0
// 10..300 = 1
// 300..590 = 2
// 590..880 = 3
expect
(
tester
.
findText
(
'0'
),
isNotNull
);
expect
(
tester
.
findText
(
'1'
),
isNotNull
);
expect
(
tester
.
findText
(
'2'
),
isNotNull
);
expect
(
tester
.
findText
(
'3'
),
isNotNull
);
expect
(
tester
.
findText
(
'4'
),
isNull
);
expect
(
tester
.
findText
(
'5'
),
isNull
);
expect
(
tester
,
hasWidget
(
find
.
text
(
'0'
))
);
expect
(
tester
,
hasWidget
(
find
.
text
(
'1'
))
);
expect
(
tester
,
hasWidget
(
find
.
text
(
'2'
))
);
expect
(
tester
,
hasWidget
(
find
.
text
(
'3'
))
);
expect
(
tester
,
doesNotHaveWidget
(
find
.
text
(
'4'
))
);
expect
(
tester
,
doesNotHaveWidget
(
find
.
text
(
'5'
))
);
tester
.
pump
(
const
Duration
(
seconds:
1
));
tester
.
scroll
(
tester
.
findT
ext
(
'2'
),
const
Offset
(-
290.0
,
0.0
));
tester
.
scroll
(
find
.
t
ext
(
'2'
),
const
Offset
(-
290.0
,
0.0
));
tester
.
pump
(
const
Duration
(
seconds:
1
));
// screen is 800px wide, and has the following items:
// -280..10 = 1
// 10..300 = 2
// 300..590 = 3
// 590..880 = 4
expect
(
tester
.
findText
(
'0'
),
isNull
);
expect
(
tester
.
findText
(
'1'
),
isNotNull
);
expect
(
tester
.
findText
(
'2'
),
isNotNull
);
expect
(
tester
.
findText
(
'3'
),
isNotNull
);
expect
(
tester
.
findText
(
'4'
),
isNotNull
);
expect
(
tester
.
findText
(
'5'
),
isNull
);
expect
(
tester
,
doesNotHaveWidget
(
find
.
text
(
'0'
))
);
expect
(
tester
,
hasWidget
(
find
.
text
(
'1'
))
);
expect
(
tester
,
hasWidget
(
find
.
text
(
'2'
))
);
expect
(
tester
,
hasWidget
(
find
.
text
(
'3'
))
);
expect
(
tester
,
hasWidget
(
find
.
text
(
'4'
))
);
expect
(
tester
,
doesNotHaveWidget
(
find
.
text
(
'5'
))
);
});
});
...
...
@@ -158,67 +158,67 @@ void main() {
// -70..220 = 3
// 220..510 = 4
// 510..800 = 5
expect
(
tester
.
findText
(
'0'
),
isNull
);
expect
(
tester
.
findText
(
'1'
),
isNull
);
expect
(
tester
.
findText
(
'2'
),
isNull
);
expect
(
tester
.
findText
(
'3'
),
isNotNull
);
expect
(
tester
.
findText
(
'4'
),
isNotNull
);
expect
(
tester
.
findText
(
'5'
),
isNotNull
);
expect
(
tester
,
doesNotHaveWidget
(
find
.
text
(
'0'
))
);
expect
(
tester
,
doesNotHaveWidget
(
find
.
text
(
'1'
))
);
expect
(
tester
,
doesNotHaveWidget
(
find
.
text
(
'2'
))
);
expect
(
tester
,
hasWidget
(
find
.
text
(
'3'
))
);
expect
(
tester
,
hasWidget
(
find
.
text
(
'4'
))
);
expect
(
tester
,
hasWidget
(
find
.
text
(
'5'
))
);
tester
.
scroll
(
tester
.
findT
ext
(
'5'
),
const
Offset
(
300.0
,
0.0
));
tester
.
scroll
(
find
.
t
ext
(
'5'
),
const
Offset
(
300.0
,
0.0
));
tester
.
pump
(
const
Duration
(
seconds:
1
));
// screen is 800px wide, and has the following items:
// -80..210 = 2
// 230..520 = 3
// 520..810 = 4
expect
(
tester
.
findText
(
'0'
),
isNull
);
expect
(
tester
.
findText
(
'1'
),
isNull
);
expect
(
tester
.
findText
(
'2'
),
isNotNull
);
expect
(
tester
.
findText
(
'3'
),
isNotNull
);
expect
(
tester
.
findText
(
'4'
),
isNotNull
);
expect
(
tester
.
findText
(
'5'
),
isNull
);
expect
(
tester
,
doesNotHaveWidget
(
find
.
text
(
'0'
))
);
expect
(
tester
,
doesNotHaveWidget
(
find
.
text
(
'1'
))
);
expect
(
tester
,
hasWidget
(
find
.
text
(
'2'
))
);
expect
(
tester
,
hasWidget
(
find
.
text
(
'3'
))
);
expect
(
tester
,
hasWidget
(
find
.
text
(
'4'
))
);
expect
(
tester
,
doesNotHaveWidget
(
find
.
text
(
'5'
))
);
// the center of item 3 is visible, so this works;
// if item 3 was a bit wider, such that its center was past the 800px mark, this would fail,
// because it wouldn't be hit tested when scrolling from its center, as scroll() does.
tester
.
pump
(
const
Duration
(
seconds:
1
));
tester
.
scroll
(
tester
.
findT
ext
(
'3'
),
const
Offset
(
290.0
,
0.0
));
tester
.
scroll
(
find
.
t
ext
(
'3'
),
const
Offset
(
290.0
,
0.0
));
tester
.
pump
(
const
Duration
(
seconds:
1
));
// screen is 800px wide, and has the following items:
// -10..280 = 1
// 280..570 = 2
// 570..860 = 3
expect
(
tester
.
findText
(
'0'
),
isNull
);
expect
(
tester
.
findText
(
'1'
),
isNotNull
);
expect
(
tester
.
findText
(
'2'
),
isNotNull
);
expect
(
tester
.
findText
(
'3'
),
isNotNull
);
expect
(
tester
.
findText
(
'4'
),
isNull
);
expect
(
tester
.
findText
(
'5'
),
isNull
);
expect
(
tester
,
doesNotHaveWidget
(
find
.
text
(
'0'
))
);
expect
(
tester
,
hasWidget
(
find
.
text
(
'1'
))
);
expect
(
tester
,
hasWidget
(
find
.
text
(
'2'
))
);
expect
(
tester
,
hasWidget
(
find
.
text
(
'3'
))
);
expect
(
tester
,
doesNotHaveWidget
(
find
.
text
(
'4'
))
);
expect
(
tester
,
doesNotHaveWidget
(
find
.
text
(
'5'
))
);
tester
.
pump
(
const
Duration
(
seconds:
1
));
tester
.
scroll
(
tester
.
findT
ext
(
'3'
),
const
Offset
(
0.0
,
290.0
));
tester
.
scroll
(
find
.
t
ext
(
'3'
),
const
Offset
(
0.0
,
290.0
));
tester
.
pump
(
const
Duration
(
seconds:
1
));
// unchanged
expect
(
tester
.
findText
(
'0'
),
isNull
);
expect
(
tester
.
findText
(
'1'
),
isNotNull
);
expect
(
tester
.
findText
(
'2'
),
isNotNull
);
expect
(
tester
.
findText
(
'3'
),
isNotNull
);
expect
(
tester
.
findText
(
'4'
),
isNull
);
expect
(
tester
.
findText
(
'5'
),
isNull
);
expect
(
tester
,
doesNotHaveWidget
(
find
.
text
(
'0'
))
);
expect
(
tester
,
hasWidget
(
find
.
text
(
'1'
))
);
expect
(
tester
,
hasWidget
(
find
.
text
(
'2'
))
);
expect
(
tester
,
hasWidget
(
find
.
text
(
'3'
))
);
expect
(
tester
,
doesNotHaveWidget
(
find
.
text
(
'4'
))
);
expect
(
tester
,
doesNotHaveWidget
(
find
.
text
(
'5'
))
);
tester
.
pump
(
const
Duration
(
seconds:
1
));
tester
.
scroll
(
tester
.
findT
ext
(
'2'
),
const
Offset
(
290.0
,
0.0
));
tester
.
scroll
(
find
.
t
ext
(
'2'
),
const
Offset
(
290.0
,
0.0
));
tester
.
pump
(
const
Duration
(
seconds:
1
));
// screen is 800px wide, and has the following items:
// -10..280 = 0
// 280..570 = 1
// 570..860 = 2
expect
(
tester
.
findText
(
'0'
),
isNotNull
);
expect
(
tester
.
findText
(
'1'
),
isNotNull
);
expect
(
tester
.
findText
(
'2'
),
isNotNull
);
expect
(
tester
.
findText
(
'3'
),
isNull
);
expect
(
tester
.
findText
(
'4'
),
isNull
);
expect
(
tester
.
findText
(
'5'
),
isNull
);
expect
(
tester
,
hasWidget
(
find
.
text
(
'0'
))
);
expect
(
tester
,
hasWidget
(
find
.
text
(
'1'
))
);
expect
(
tester
,
hasWidget
(
find
.
text
(
'2'
))
);
expect
(
tester
,
doesNotHaveWidget
(
find
.
text
(
'3'
))
);
expect
(
tester
,
doesNotHaveWidget
(
find
.
text
(
'4'
))
);
expect
(
tester
,
doesNotHaveWidget
(
find
.
text
(
'5'
))
);
tester
.
pump
(
const
Duration
(
seconds:
1
));
// at this point we can drag 60 pixels further before we hit the friction zone
...
...
@@ -226,28 +226,28 @@ void main() {
// to move item 3 entirely off screen therefore takes:
// 60 + (290-60)*2 = 520 pixels
// plus a couple more to be sure
tester
.
scroll
(
tester
.
findT
ext
(
'1'
),
const
Offset
(
522.0
,
0.0
));
tester
.
scroll
(
find
.
t
ext
(
'1'
),
const
Offset
(
522.0
,
0.0
));
tester
.
pump
();
// just after release
// screen is 800px wide, and has the following items:
// 280..570 = 0
// 570..860 = 1
expect
(
tester
.
findText
(
'0'
),
isNotNull
);
expect
(
tester
.
findText
(
'1'
),
isNotNull
);
expect
(
tester
.
findText
(
'2'
),
isNull
);
expect
(
tester
.
findText
(
'3'
),
isNull
);
expect
(
tester
.
findText
(
'4'
),
isNull
);
expect
(
tester
.
findText
(
'5'
),
isNull
);
expect
(
tester
,
hasWidget
(
find
.
text
(
'0'
))
);
expect
(
tester
,
hasWidget
(
find
.
text
(
'1'
))
);
expect
(
tester
,
doesNotHaveWidget
(
find
.
text
(
'2'
))
);
expect
(
tester
,
doesNotHaveWidget
(
find
.
text
(
'3'
))
);
expect
(
tester
,
doesNotHaveWidget
(
find
.
text
(
'4'
))
);
expect
(
tester
,
doesNotHaveWidget
(
find
.
text
(
'5'
))
);
tester
.
pump
(
const
Duration
(
seconds:
1
));
// a second after release
// screen is 800px wide, and has the following items:
// 0..290 = 0
// 290..580 = 1
// 580..870 = 2
expect
(
tester
.
findText
(
'0'
),
isNotNull
);
expect
(
tester
.
findText
(
'1'
),
isNotNull
);
expect
(
tester
.
findText
(
'2'
),
isNotNull
);
expect
(
tester
.
findText
(
'3'
),
isNull
);
expect
(
tester
.
findText
(
'4'
),
isNull
);
expect
(
tester
.
findText
(
'5'
),
isNull
);
expect
(
tester
,
hasWidget
(
find
.
text
(
'0'
))
);
expect
(
tester
,
hasWidget
(
find
.
text
(
'1'
))
);
expect
(
tester
,
hasWidget
(
find
.
text
(
'2'
))
);
expect
(
tester
,
doesNotHaveWidget
(
find
.
text
(
'3'
))
);
expect
(
tester
,
doesNotHaveWidget
(
find
.
text
(
'4'
))
);
expect
(
tester
,
doesNotHaveWidget
(
find
.
text
(
'5'
))
);
});
});
}
packages/flutter/test/widget/scrollable_list_vertical_test.dart
View file @
f3a4f722
...
...
@@ -26,43 +26,43 @@ void main() {
tester
.
pumpWidget
(
buildFrame
());
tester
.
pump
();
tester
.
scroll
(
tester
.
findT
ext
(
'1'
),
const
Offset
(
0.0
,
-
300.0
));
tester
.
scroll
(
find
.
t
ext
(
'1'
),
const
Offset
(
0.0
,
-
300.0
));
tester
.
pump
();
// screen is 600px high, and has the following items:
// -10..280 = 1
// 280..570 = 2
// 570..860 = 3
expect
(
tester
.
findText
(
'0'
),
isNull
);
expect
(
tester
.
findText
(
'1'
),
isNotNull
);
expect
(
tester
.
findText
(
'2'
),
isNotNull
);
expect
(
tester
.
findText
(
'3'
),
isNotNull
);
expect
(
tester
.
findText
(
'4'
),
isNull
);
expect
(
tester
.
findText
(
'5'
),
isNull
);
expect
(
tester
,
doesNotHaveWidget
(
find
.
text
(
'0'
))
);
expect
(
tester
,
hasWidget
(
find
.
text
(
'1'
))
);
expect
(
tester
,
hasWidget
(
find
.
text
(
'2'
))
);
expect
(
tester
,
hasWidget
(
find
.
text
(
'3'
))
);
expect
(
tester
,
doesNotHaveWidget
(
find
.
text
(
'4'
))
);
expect
(
tester
,
doesNotHaveWidget
(
find
.
text
(
'5'
))
);
tester
.
pump
();
tester
.
scroll
(
tester
.
findT
ext
(
'2'
),
const
Offset
(
0.0
,
-
290.0
));
tester
.
scroll
(
find
.
t
ext
(
'2'
),
const
Offset
(
0.0
,
-
290.0
));
tester
.
pump
();
// screen is 600px high, and has the following items:
// -10..280 = 2
// 280..570 = 3
// 570..860 = 4
expect
(
tester
.
findText
(
'0'
),
isNull
);
expect
(
tester
.
findText
(
'1'
),
isNull
);
expect
(
tester
.
findText
(
'2'
),
isNotNull
);
expect
(
tester
.
findText
(
'3'
),
isNotNull
);
expect
(
tester
.
findText
(
'4'
),
isNotNull
);
expect
(
tester
.
findText
(
'5'
),
isNull
);
expect
(
tester
,
doesNotHaveWidget
(
find
.
text
(
'0'
))
);
expect
(
tester
,
doesNotHaveWidget
(
find
.
text
(
'1'
))
);
expect
(
tester
,
hasWidget
(
find
.
text
(
'2'
))
);
expect
(
tester
,
hasWidget
(
find
.
text
(
'3'
))
);
expect
(
tester
,
hasWidget
(
find
.
text
(
'4'
))
);
expect
(
tester
,
doesNotHaveWidget
(
find
.
text
(
'5'
))
);
tester
.
pump
();
tester
.
scroll
(
tester
.
findT
ext
(
'3'
),
const
Offset
(-
300.0
,
0.0
));
tester
.
scroll
(
find
.
t
ext
(
'3'
),
const
Offset
(-
300.0
,
0.0
));
tester
.
pump
();
// nothing should have changed
expect
(
tester
.
findText
(
'0'
),
isNull
);
expect
(
tester
.
findText
(
'1'
),
isNull
);
expect
(
tester
.
findText
(
'2'
),
isNotNull
);
expect
(
tester
.
findText
(
'3'
),
isNotNull
);
expect
(
tester
.
findText
(
'4'
),
isNotNull
);
expect
(
tester
.
findText
(
'5'
),
isNull
);
expect
(
tester
,
doesNotHaveWidget
(
find
.
text
(
'0'
))
);
expect
(
tester
,
doesNotHaveWidget
(
find
.
text
(
'1'
))
);
expect
(
tester
,
hasWidget
(
find
.
text
(
'2'
))
);
expect
(
tester
,
hasWidget
(
find
.
text
(
'3'
))
);
expect
(
tester
,
hasWidget
(
find
.
text
(
'4'
))
);
expect
(
tester
,
doesNotHaveWidget
(
find
.
text
(
'5'
))
);
});
});
...
...
@@ -85,25 +85,25 @@ void main() {
// screen is 600px high, and has the following items:
// 250..540 = 0
// 540..830 = 1
expect
(
tester
.
findText
(
'0'
),
isNotNull
);
expect
(
tester
.
findText
(
'1'
),
isNotNull
);
expect
(
tester
.
findText
(
'2'
),
isNull
);
expect
(
tester
.
findText
(
'3'
),
isNull
);
expect
(
tester
.
findText
(
'4'
),
isNull
);
expect
(
tester
.
findText
(
'5'
),
isNull
);
expect
(
tester
,
hasWidget
(
find
.
text
(
'0'
))
);
expect
(
tester
,
hasWidget
(
find
.
text
(
'1'
))
);
expect
(
tester
,
doesNotHaveWidget
(
find
.
text
(
'2'
))
);
expect
(
tester
,
doesNotHaveWidget
(
find
.
text
(
'3'
))
);
expect
(
tester
,
doesNotHaveWidget
(
find
.
text
(
'4'
))
);
expect
(
tester
,
doesNotHaveWidget
(
find
.
text
(
'5'
))
);
tester
.
scroll
(
tester
.
findT
ext
(
'0'
),
const
Offset
(
0.0
,
-
300.0
));
tester
.
scroll
(
find
.
t
ext
(
'0'
),
const
Offset
(
0.0
,
-
300.0
));
tester
.
pump
();
// screen is 600px high, and has the following items:
// -50..240 = 0
// 240..530 = 1
// 530..820 = 2
expect
(
tester
.
findText
(
'0'
),
isNotNull
);
expect
(
tester
.
findText
(
'1'
),
isNotNull
);
expect
(
tester
.
findText
(
'2'
),
isNotNull
);
expect
(
tester
.
findText
(
'3'
),
isNull
);
expect
(
tester
.
findText
(
'4'
),
isNull
);
expect
(
tester
.
findText
(
'5'
),
isNull
);
expect
(
tester
,
hasWidget
(
find
.
text
(
'0'
))
);
expect
(
tester
,
hasWidget
(
find
.
text
(
'1'
))
);
expect
(
tester
,
hasWidget
(
find
.
text
(
'2'
))
);
expect
(
tester
,
doesNotHaveWidget
(
find
.
text
(
'3'
))
);
expect
(
tester
,
doesNotHaveWidget
(
find
.
text
(
'4'
))
);
expect
(
tester
,
doesNotHaveWidget
(
find
.
text
(
'5'
))
);
});
});
}
packages/flutter/test/widget/scrollable_list_with_inherited_test.dart
View file @
f3a4f722
...
...
@@ -31,16 +31,16 @@ void main() {
test
(
'LazyBlock is a build function (smoketest)'
,
()
{
testWidgets
((
WidgetTester
tester
)
{
tester
.
pumpWidget
(
buildFrame
());
expect
(
tester
.
findText
(
'0'
),
isNotNull
);
expect
(
tester
.
findText
(
'1'
),
isNotNull
);
expect
(
tester
.
findText
(
'2'
),
isNotNull
);
expect
(
tester
.
findText
(
'3'
),
isNotNull
);
expect
(
tester
,
hasWidget
(
find
.
text
(
'0'
))
);
expect
(
tester
,
hasWidget
(
find
.
text
(
'1'
))
);
expect
(
tester
,
hasWidget
(
find
.
text
(
'2'
))
);
expect
(
tester
,
hasWidget
(
find
.
text
(
'3'
))
);
items
.
removeAt
(
2
);
tester
.
pumpWidget
(
buildFrame
());
expect
(
tester
.
findText
(
'0'
),
isNotNull
);
expect
(
tester
.
findText
(
'1'
),
isNotNull
);
expect
(
tester
.
findText
(
'2'
),
isNull
);
expect
(
tester
.
findText
(
'3'
),
isNotNull
);
expect
(
tester
,
hasWidget
(
find
.
text
(
'0'
))
);
expect
(
tester
,
hasWidget
(
find
.
text
(
'1'
))
);
expect
(
tester
,
doesNotHaveWidget
(
find
.
text
(
'2'
))
);
expect
(
tester
,
hasWidget
(
find
.
text
(
'3'
))
);
});
});
}
packages/flutter/test/widget/set_state_2_test.dart
View file @
f3a4f722
...
...
@@ -41,7 +41,7 @@ void main() {
}
));
log
.
add
(
'---'
);
tester
.
tap
(
tester
.
findT
ext
(
'inner'
));;
tester
.
tap
(
find
.
t
ext
(
'inner'
));;
tester
.
pump
();
log
.
add
(
'---'
);
expect
(
log
,
equals
(<
String
>[
...
...
packages/flutter/test/widget/set_state_test.dart
View file @
f3a4f722
...
...
@@ -64,7 +64,7 @@ void main() {
test
(
'setState() smoke test'
,
()
{
testWidgets
((
WidgetTester
tester
)
{
tester
.
pumpWidget
(
new
Outside
());
Point
location
=
tester
.
getCenter
(
tester
.
findT
ext
(
'INSIDE'
));
Point
location
=
tester
.
getCenter
(
find
.
t
ext
(
'INSIDE'
));
TestGesture
gesture
=
tester
.
startGesture
(
location
);
tester
.
pump
();
gesture
.
up
();
...
...
packages/flutter/test/widget/stack_test.dart
View file @
f3a4f722
...
...
@@ -23,7 +23,7 @@ void main() {
});
test
(
'Can change position data'
,
()
{
test
Widgets
((
Widget
Tester
tester
)
{
test
ElementTree
((
ElementTree
Tester
tester
)
{
Key
key
=
new
Key
(
'container'
);
tester
.
pumpWidget
(
...
...
@@ -80,7 +80,7 @@ void main() {
});
test
(
'Can remove parent data'
,
()
{
test
Widgets
((
Widget
Tester
tester
)
{
test
ElementTree
((
ElementTree
Tester
tester
)
{
Key
key
=
new
Key
(
'container'
);
Container
container
=
new
Container
(
key:
key
,
width:
10.0
,
height:
10.0
);
...
...
@@ -110,7 +110,7 @@ void main() {
});
test
(
'Can align non-positioned children'
,
()
{
test
Widgets
((
Widget
Tester
tester
)
{
test
ElementTree
((
ElementTree
Tester
tester
)
{
Key
child0Key
=
new
Key
(
'child0'
);
Key
child1Key
=
new
Key
(
'child1'
);
...
...
@@ -167,9 +167,9 @@ void main() {
}
tester
.
pumpWidget
(
buildFrame
(
0
));
expect
(
tester
.
findText
(
'0'
),
isNotNull
);
expect
(
tester
.
findText
(
'1'
),
isNotNull
);
expect
(
tester
.
findText
(
'2'
),
isNotNull
);
expect
(
tester
,
hasWidget
(
find
.
text
(
'0'
))
);
expect
(
tester
,
hasWidget
(
find
.
text
(
'1'
))
);
expect
(
tester
,
hasWidget
(
find
.
text
(
'2'
))
);
expect
(
itemsPainted
,
equals
([
0
]));
tester
.
pumpWidget
(
buildFrame
(
1
));
...
...
@@ -196,18 +196,18 @@ void main() {
tester
.
pumpWidget
(
buildFrame
(
0
));
expect
(
itemsTapped
,
isEmpty
);
tester
.
tap
(
tester
.
findElementB
yKey
(
key
));
tester
.
tap
(
find
.
b
yKey
(
key
));
expect
(
itemsTapped
,
[
0
]);
tester
.
pumpWidget
(
buildFrame
(
2
));
expect
(
itemsTapped
,
isEmpty
);
tester
.
tap
(
tester
.
findElementB
yKey
(
key
));
tester
.
tap
(
find
.
b
yKey
(
key
));
expect
(
itemsTapped
,
[
2
]);
});
});
test
(
'Can set width and height'
,
()
{
test
Widgets
((
Widget
Tester
tester
)
{
test
ElementTree
((
ElementTree
Tester
tester
)
{
Key
key
=
new
Key
(
'container'
);
BoxDecoration
kBoxDecoration
=
new
BoxDecoration
(
...
...
packages/flutter/test/widget/stateful_component_test.dart
View file @
f3a4f722
...
...
@@ -15,7 +15,7 @@ void main() {
void
checkTree
(
BoxDecoration
expectedDecoration
)
{
SingleChildRenderObjectElement
element
=
tester
.
findElement
((
Element
element
)
=>
element
is
SingleChildRenderObjectElement
);
tester
.
elementOf
(
find
.
byElement
((
Element
element
)
=>
element
is
SingleChildRenderObjectElement
)
);
expect
(
element
,
isNotNull
);
expect
(
element
.
renderObject
is
RenderDecoratedBox
,
isTrue
);
RenderDecoratedBox
renderObject
=
element
.
renderObject
;
...
...
packages/flutter/test/widget/stateful_components_test.dart
View file @
f3a4f722
...
...
@@ -46,7 +46,7 @@ class OuterContainerState extends State<OuterContainer> {
void
main
(
)
{
test
(
'resync stateful widget'
,
()
{
test
Widgets
((
Widget
Tester
tester
)
{
test
ElementTree
((
ElementTree
Tester
tester
)
{
Key
innerKey
=
new
Key
(
'inner'
);
Key
outerKey
=
new
Key
(
'outer'
);
...
...
packages/flutter/test/widget/syncing_test.dart
View file @
f3a4f722
...
...
@@ -56,7 +56,7 @@ void main() {
)
);
TestWidgetState
state
=
tester
.
findStateOfType
(
TestWidgetState
);
TestWidgetState
state
=
tester
.
stateOf
(
find
.
byType
(
TestWidget
)
);
expect
(
state
.
persistentState
,
equals
(
1
));
expect
(
state
.
updates
,
equals
(
0
));
...
...
@@ -92,7 +92,7 @@ void main() {
)
);
TestWidgetState
state
=
tester
.
findStateOfType
(
TestWidgetState
);
TestWidgetState
state
=
tester
.
stateOf
(
find
.
byType
(
TestWidget
)
);
expect
(
state
.
persistentState
,
equals
(
10
));
expect
(
state
.
updates
,
equals
(
0
));
...
...
@@ -106,7 +106,7 @@ void main() {
)
);
state
=
tester
.
findStateOfType
(
TestWidgetState
);
state
=
tester
.
stateOf
(
find
.
byType
(
TestWidget
)
);
expect
(
state
.
persistentState
,
equals
(
11
));
expect
(
state
.
updates
,
equals
(
0
));
...
...
@@ -116,7 +116,7 @@ void main() {
});
test
(
'swap instances around'
,
()
{
test
Widgets
((
Widget
Tester
tester
)
{
test
ElementTree
((
ElementTree
Tester
tester
)
{
Widget
a
=
new
TestWidget
(
persistentState:
0x61
,
syncedState:
0x41
,
child:
new
Text
(
'apple'
));
Widget
b
=
new
TestWidget
(
persistentState:
0x62
,
syncedState:
0x42
,
child:
new
Text
(
'banana'
));
tester
.
pumpWidget
(
new
Column
());
...
...
packages/flutter/test/widget/table_test.dart
View file @
f3a4f722
...
...
@@ -9,7 +9,7 @@ import 'package:test/test.dart';
void
main
(
)
{
test
(
'Table widget - control test'
,
()
{
test
Widgets
((
Widget
Tester
tester
)
{
test
ElementTree
((
ElementTree
Tester
tester
)
{
tester
.
pumpWidget
(
new
Table
(
children:
<
TableRow
>[
...
...
@@ -41,7 +41,7 @@ void main() {
});
});
test
(
'Table widget - changing table dimensions'
,
()
{
test
Widgets
((
Widget
Tester
tester
)
{
test
ElementTree
((
ElementTree
Tester
tester
)
{
tester
.
pumpWidget
(
new
Table
(
children:
<
TableRow
>[
...
...
@@ -92,7 +92,7 @@ void main() {
});
});
test
(
'Table widget - repump test'
,
()
{
test
Widgets
((
Widget
Tester
tester
)
{
test
ElementTree
((
ElementTree
Tester
tester
)
{
tester
.
pumpWidget
(
new
Table
(
children:
<
TableRow
>[
...
...
@@ -145,7 +145,7 @@ void main() {
});
});
test
(
'Table widget - intrinsic sizing test'
,
()
{
test
Widgets
((
Widget
Tester
tester
)
{
test
ElementTree
((
ElementTree
Tester
tester
)
{
tester
.
pumpWidget
(
new
Table
(
defaultColumnWidth:
const
IntrinsicColumnWidth
(),
...
...
@@ -179,7 +179,7 @@ void main() {
});
});
test
(
'Table widget - intrinsic sizing test, resizing'
,
()
{
test
Widgets
((
Widget
Tester
tester
)
{
test
ElementTree
((
ElementTree
Tester
tester
)
{
tester
.
pumpWidget
(
new
Table
(
defaultColumnWidth:
const
IntrinsicColumnWidth
(),
...
...
@@ -235,7 +235,7 @@ void main() {
});
});
test
(
'Table widget - intrinsic sizing test, changing column widths'
,
()
{
test
Widgets
((
Widget
Tester
tester
)
{
test
ElementTree
((
ElementTree
Tester
tester
)
{
tester
.
pumpWidget
(
new
Table
(
children:
<
TableRow
>[
...
...
@@ -290,7 +290,7 @@ void main() {
});
});
test
(
'Table widget - moving test'
,
()
{
test
Widgets
((
Widget
Tester
tester
)
{
test
ElementTree
((
ElementTree
Tester
tester
)
{
List
<
BuildContext
>
contexts
=
<
BuildContext
>[];
tester
.
pumpWidget
(
new
Table
(
...
...
packages/flutter/test/widget/test_matchers.dart
View file @
f3a4f722
...
...
@@ -3,12 +3,13 @@
// found in the LICENSE file.
import
'package:flutter/material.dart'
;
import
'package:flutter_test/flutter_test.dart'
;
import
'package:test/test.dart'
;
bool
_hasAncestorOfType
(
Element
element
,
Type
targetType
)
{
expect
(
element
,
isNotNull
);
bool
_hasAncestorOfType
(
WidgetTester
tester
,
Finder
finder
,
Type
targetType
)
{
expect
(
tester
,
hasWidget
(
finder
)
);
bool
result
=
false
;
element
.
visitAncestorElements
((
Element
ancestor
)
{
finder
.
findFirst
(
tester
)
.
visitAncestorElements
((
Element
ancestor
)
{
if
(
ancestor
.
widget
.
runtimeType
==
targetType
)
{
result
=
true
;
return
false
;
...
...
@@ -19,46 +20,54 @@ bool _hasAncestorOfType(Element element, Type targetType) {
}
class
_IsOnStage
extends
Matcher
{
const
_IsOnStage
();
const
_IsOnStage
(
this
.
tester
);
final
WidgetTester
tester
;
@override
bool
matches
(
Element
item
,
Map
<
dynamic
,
dynamic
>
matchState
)
=>
!
_hasAncestorOfType
(
item
,
OffStage
);
bool
matches
(
Finder
finder
,
Map
<
dynamic
,
dynamic
>
matchState
)
=>
!
_hasAncestorOfType
(
tester
,
finder
,
OffStage
);
@override
Description
describe
(
Description
description
)
=>
description
.
add
(
'onstage'
);
}
class
_IsOffStage
extends
Matcher
{
const
_IsOffStage
();
const
_IsOffStage
(
this
.
tester
);
final
WidgetTester
tester
;
@override
bool
matches
(
Element
item
,
Map
<
dynamic
,
dynamic
>
matchState
)
=>
_hasAncestorOfType
(
item
,
OffStage
);
bool
matches
(
Finder
finder
,
Map
<
dynamic
,
dynamic
>
matchState
)
=>
_hasAncestorOfType
(
tester
,
finder
,
OffStage
);
@override
Description
describe
(
Description
description
)
=>
description
.
add
(
'offstage'
);
}
class
_IsInCard
extends
Matcher
{
const
_IsInCard
();
const
_IsInCard
(
this
.
tester
);
final
WidgetTester
tester
;
@override
bool
matches
(
Element
item
,
Map
<
dynamic
,
dynamic
>
matchState
)
=>
_hasAncestorOfType
(
item
,
Card
);
bool
matches
(
Finder
finder
,
Map
<
dynamic
,
dynamic
>
matchState
)
=>
_hasAncestorOfType
(
tester
,
finder
,
Card
);
@override
Description
describe
(
Description
description
)
=>
description
.
add
(
'in card'
);
}
class
_IsNotInCard
extends
Matcher
{
const
_IsNotInCard
();
const
_IsNotInCard
(
this
.
tester
);
final
WidgetTester
tester
;
@override
bool
matches
(
Element
item
,
Map
<
dynamic
,
dynamic
>
matchState
)
=>
!
_hasAncestorOfType
(
item
,
Card
);
bool
matches
(
Finder
finder
,
Map
<
dynamic
,
dynamic
>
matchState
)
=>
!
_hasAncestorOfType
(
tester
,
finder
,
Card
);
@override
Description
describe
(
Description
description
)
=>
description
.
add
(
'not in card'
);
}
const
Matcher
isOnStage
=
const
_IsOnStage
(
);
const
Matcher
isOffStage
=
const
_IsOffStage
(
);
const
Matcher
isInCard
=
const
_IsInCard
(
);
const
Matcher
isNotInCard
=
const
_IsNotInCard
(
);
Matcher
isOnStage
(
WidgetTester
tester
)
=>
new
_IsOnStage
(
tester
);
Matcher
isOffStage
(
WidgetTester
tester
)
=>
new
_IsOffStage
(
tester
);
Matcher
isInCard
(
WidgetTester
tester
)
=>
new
_IsInCard
(
tester
);
Matcher
isNotInCard
(
WidgetTester
tester
)
=>
new
_IsNotInCard
(
tester
);
packages/flutter/test/widget/test_widgets.dart
View file @
f3a4f722
...
...
@@ -4,7 +4,6 @@
import
'package:flutter_test/flutter_test.dart'
;
import
'package:flutter/widgets.dart'
;
import
'package:test/test.dart'
;
final
BoxDecoration
kBoxDecorationA
=
new
BoxDecoration
(
backgroundColor:
const
Color
(
0xFFFF0000
)
...
...
@@ -55,10 +54,6 @@ class FlipWidgetState extends State<FlipWidget> {
}
void
flipStatefulWidget
(
WidgetTester
tester
)
{
StatefulElement
stateElement
=
tester
.
findElement
((
Element
element
)
=>
element
is
StatefulElement
);
expect
(
stateElement
,
isNotNull
);
expect
(
stateElement
.
state
is
FlipWidgetState
,
isTrue
);
FlipWidgetState
state
=
stateElement
.
state
;
FlipWidgetState
state
=
tester
.
stateOf
(
find
.
byType
(
FlipWidget
));
state
.
flip
();
}
packages/flutter/test/widget/tooltip_test.dart
View file @
f3a4f722
...
...
@@ -27,7 +27,7 @@ import 'test_semantics.dart';
void
main
(
)
{
test
(
'Does tooltip end up in the right place - top left'
,
()
{
test
Widgets
((
Widget
Tester
tester
)
{
test
ElementTree
((
ElementTree
Tester
tester
)
{
GlobalKey
key
=
new
GlobalKey
();
tester
.
pumpWidget
(
new
Overlay
(
...
...
@@ -81,7 +81,7 @@ void main() {
});
test
(
'Does tooltip end up in the right place - center prefer above fits'
,
()
{
test
Widgets
((
Widget
Tester
tester
)
{
test
ElementTree
((
ElementTree
Tester
tester
)
{
GlobalKey
key
=
new
GlobalKey
();
tester
.
pumpWidget
(
new
Overlay
(
...
...
@@ -137,7 +137,7 @@ void main() {
});
test
(
'Does tooltip end up in the right place - center prefer above does not fit'
,
()
{
test
Widgets
((
Widget
Tester
tester
)
{
test
ElementTree
((
ElementTree
Tester
tester
)
{
GlobalKey
key
=
new
GlobalKey
();
tester
.
pumpWidget
(
new
Overlay
(
...
...
@@ -204,7 +204,7 @@ void main() {
});
test
(
'Does tooltip end up in the right place - center prefer below fits'
,
()
{
test
Widgets
((
Widget
Tester
tester
)
{
test
ElementTree
((
ElementTree
Tester
tester
)
{
GlobalKey
key
=
new
GlobalKey
();
tester
.
pumpWidget
(
new
Overlay
(
...
...
@@ -259,7 +259,7 @@ void main() {
});
test
(
'Does tooltip end up in the right place - way off to the right'
,
()
{
test
Widgets
((
Widget
Tester
tester
)
{
test
ElementTree
((
ElementTree
Tester
tester
)
{
GlobalKey
key
=
new
GlobalKey
();
tester
.
pumpWidget
(
new
Overlay
(
...
...
@@ -316,7 +316,7 @@ void main() {
});
test
(
'Does tooltip end up in the right place - near the edge'
,
()
{
test
Widgets
((
Widget
Tester
tester
)
{
test
ElementTree
((
ElementTree
Tester
tester
)
{
GlobalKey
key
=
new
GlobalKey
();
tester
.
pumpWidget
(
new
Overlay
(
...
...
@@ -373,7 +373,7 @@ void main() {
});
test
(
'Does tooltip contribute semantics'
,
()
{
test
Widgets
((
Widget
Tester
tester
)
{
test
ElementTree
((
ElementTree
Tester
tester
)
{
TestSemanticsListener
client
=
new
TestSemanticsListener
();
GlobalKey
key
=
new
GlobalKey
();
tester
.
pumpWidget
(
...
...
packages/flutter/test/widget/two_level_list_test.dart
View file @
f3a4f722
...
...
@@ -39,12 +39,12 @@ void main() {
testWidgets
((
WidgetTester
tester
)
{
tester
.
pumpWidget
(
new
MaterialApp
(
routes:
routes
));
expect
(
tester
.
findText
(
'Top'
),
isNotNull
);
expect
(
tester
.
findText
(
'Sublist'
),
isNotNull
);
expect
(
tester
.
findText
(
'Bottom'
),
isNotNull
);
expect
(
tester
,
hasWidget
(
find
.
text
(
'Top'
))
);
expect
(
tester
,
hasWidget
(
find
.
text
(
'Sublist'
))
);
expect
(
tester
,
hasWidget
(
find
.
text
(
'Bottom'
))
);
double
getY
(
Key
key
)
=>
tester
.
getTopLeft
(
tester
.
findElementB
yKey
(
key
)).
y
;
double
getHeight
(
Key
key
)
=>
tester
.
getSize
(
tester
.
findElementB
yKey
(
key
)).
height
;
double
getY
(
Key
key
)
=>
tester
.
getTopLeft
(
find
.
b
yKey
(
key
)).
y
;
double
getHeight
(
Key
key
)
=>
tester
.
getSize
(
find
.
b
yKey
(
key
)).
height
;
expect
(
getY
(
topKey
),
lessThan
(
getY
(
sublistKey
)));
expect
(
getY
(
sublistKey
),
lessThan
(
getY
(
bottomKey
)));
...
...
@@ -53,15 +53,15 @@ void main() {
expect
(
getHeight
(
topKey
),
equals
(
getHeight
(
sublistKey
)
-
2.0
));
expect
(
getHeight
(
bottomKey
),
equals
(
getHeight
(
sublistKey
)
-
2.0
));
tester
.
tap
(
tester
.
findT
ext
(
'Sublist'
));
tester
.
tap
(
find
.
t
ext
(
'Sublist'
));
tester
.
pump
(
const
Duration
(
seconds:
1
));
tester
.
pump
(
const
Duration
(
seconds:
1
));
expect
(
tester
.
findText
(
'Top'
),
isNotNull
);
expect
(
tester
.
findText
(
'Sublist'
),
isNotNull
);
expect
(
tester
.
findText
(
'0'
),
isNotNull
);
expect
(
tester
.
findText
(
'1'
),
isNotNull
);
expect
(
tester
.
findText
(
'Bottom'
),
isNotNull
);
expect
(
tester
,
hasWidget
(
find
.
text
(
'Top'
))
);
expect
(
tester
,
hasWidget
(
find
.
text
(
'Sublist'
))
);
expect
(
tester
,
hasWidget
(
find
.
text
(
'0'
))
);
expect
(
tester
,
hasWidget
(
find
.
text
(
'1'
))
);
expect
(
tester
,
hasWidget
(
find
.
text
(
'Bottom'
))
);
expect
(
getY
(
topKey
),
lessThan
(
getY
(
sublistKey
)));
expect
(
getY
(
sublistKey
),
lessThan
(
getY
(
bottomKey
)));
...
...
packages/flutter_markdown/test/flutter_markdown_test.dart
View file @
f3a4f722
...
...
@@ -10,9 +10,9 @@ void main() {
testWidgets
((
WidgetTester
tester
)
{
tester
.
pumpWidget
(
new
MarkdownBody
(
data:
"Hello"
));
List
<
Element
>
elements
=
_listElements
(
tester
)
;
_expectWidgetTypes
(
elemen
ts
,
<
Type
>[
MarkdownBody
,
Column
,
Container
,
Padding
,
RichText
]);
_expectTextStrings
(
elemen
ts
,
<
String
>[
"Hello"
]);
Iterable
<
Widget
>
widgets
=
tester
.
widgets
;
_expectWidgetTypes
(
widge
ts
,
<
Type
>[
MarkdownBody
,
Column
,
Container
,
Padding
,
RichText
]);
_expectTextStrings
(
widge
ts
,
<
String
>[
"Hello"
]);
});
});
...
...
@@ -20,9 +20,9 @@ void main() {
testWidgets
((
WidgetTester
tester
)
{
tester
.
pumpWidget
(
new
MarkdownBody
(
data:
"# Header"
));
List
<
Element
>
elements
=
_listElements
(
tester
)
;
_expectWidgetTypes
(
elemen
ts
,
<
Type
>[
MarkdownBody
,
Column
,
Container
,
Padding
,
RichText
]);
_expectTextStrings
(
elemen
ts
,
<
String
>[
"Header"
]);
Iterable
<
Widget
>
widgets
=
tester
.
widgets
;
_expectWidgetTypes
(
widge
ts
,
<
Type
>[
MarkdownBody
,
Column
,
Container
,
Padding
,
RichText
]);
_expectTextStrings
(
widge
ts
,
<
String
>[
"Header"
]);
});
});
...
...
@@ -30,8 +30,8 @@ void main() {
testWidgets
((
WidgetTester
tester
)
{
tester
.
pumpWidget
(
new
MarkdownBody
(
data:
""
));
List
<
Element
>
elements
=
_listElements
(
tester
)
;
_expectWidgetTypes
(
elemen
ts
,
<
Type
>[
MarkdownBody
,
Column
]);
Iterable
<
Widget
>
widgets
=
tester
.
widgets
;
_expectWidgetTypes
(
widge
ts
,
<
Type
>[
MarkdownBody
,
Column
]);
});
});
...
...
@@ -39,8 +39,8 @@ void main() {
testWidgets
((
WidgetTester
tester
)
{
tester
.
pumpWidget
(
new
MarkdownBody
(
data:
"1. Item 1
\n
1. Item 2
\n
2. Item 3"
));
List
<
Element
>
elements
=
_listElements
(
tester
)
;
_expectTextStrings
(
elemen
ts
,
<
String
>[
Iterable
<
Widget
>
widgets
=
tester
.
widgets
;
_expectTextStrings
(
widge
ts
,
<
String
>[
"1."
,
"Item 1"
,
"2."
,
...
...
@@ -55,8 +55,8 @@ void main() {
testWidgets
((
WidgetTester
tester
)
{
tester
.
pumpWidget
(
new
MarkdownBody
(
data:
"- Item 1
\n
- Item 2
\n
- Item 3"
));
List
<
Element
>
elements
=
_listElements
(
tester
)
;
_expectTextStrings
(
elemen
ts
,
<
String
>[
Iterable
<
Widget
>
widgets
=
tester
.
widgets
;
_expectTextStrings
(
widge
ts
,
<
String
>[
"•"
,
"Item 1"
,
"•"
,
...
...
@@ -71,11 +71,12 @@ void main() {
testWidgets
((
WidgetTester
tester
)
{
tester
.
pumpWidget
(
new
Markdown
(
data:
""
));
List
<
Element
>
elements
=
_listElements
(
tester
);
_expectWidgetTypes
(
elements
,
<
Type
>[
List
<
Widget
>
widgets
=
tester
.
widgets
.
toList
(
);
_expectWidgetTypes
(
widgets
.
take
(
2
)
,
<
Type
>[
Markdown
,
ScrollableViewport
,
null
,
null
,
null
,
null
,
null
,
// ScrollableViewport internals
]);
_expectWidgetTypes
(
widgets
.
reversed
.
take
(
3
).
toList
().
reversed
,
<
Type
>[
Padding
,
MarkdownBody
,
Column
...
...
@@ -87,8 +88,7 @@ void main() {
testWidgets
((
WidgetTester
tester
)
{
tester
.
pumpWidget
(
new
Markdown
(
data:
"[Link Text](href)"
));
Element
textElement
=
tester
.
findElement
((
Element
element
)
=>
element
.
widget
is
RichText
);
RichText
textWidget
=
textElement
.
widget
;
RichText
textWidget
=
tester
.
widgets
.
firstWhere
((
Widget
widget
)
=>
widget
is
RichText
);
TextSpan
span
=
textWidget
.
text
;
expect
(
span
.
children
[
0
].
recognizer
.
runtimeType
,
equals
(
TapGestureRecognizer
));
...
...
@@ -98,7 +98,7 @@ void main() {
test
(
"Changing config - data"
,
()
{
testWidgets
((
WidgetTester
tester
)
{
tester
.
pumpWidget
(
new
Markdown
(
data:
"Data1"
));
_expectTextStrings
(
_listElements
(
tester
)
,
<
String
>[
"Data1"
]);
_expectTextStrings
(
tester
.
widgets
,
<
String
>[
"Data1"
]);
String
stateBefore
=
WidgetFlutterBinding
.
instance
.
renderViewElement
.
toStringDeep
();
tester
.
pumpWidget
(
new
Markdown
(
data:
"Data1"
));
...
...
@@ -106,7 +106,7 @@ void main() {
expect
(
stateBefore
,
equals
(
stateAfter
));
tester
.
pumpWidget
(
new
Markdown
(
data:
"Data2"
));
_expectTextStrings
(
_listElements
(
tester
)
,
<
String
>[
"Data2"
]);
_expectTextStrings
(
tester
.
widgets
,
<
String
>[
"Data2"
]);
});
});
...
...
@@ -127,28 +127,14 @@ void main() {
});
}
List
<
Element
>
_listElements
(
WidgetTester
tester
)
{
List
<
Element
>
elements
=
<
Element
>[];
tester
.
walkElements
((
Element
element
)
{
elements
.
add
(
element
);
});
return
elements
;
}
void
_expectWidgetTypes
(
List
<
Element
>
elements
,
List
<
Type
>
types
)
{
expect
(
elements
.
length
,
equals
(
types
.
length
));
for
(
int
i
=
0
;
i
<
elements
.
length
;
i
+=
1
)
{
Element
element
=
elements
[
i
];
Type
type
=
types
[
i
];
if
(
type
==
null
)
continue
;
expect
(
element
.
widget
.
runtimeType
,
equals
(
type
));
}
void
_expectWidgetTypes
(
Iterable
<
Widget
>
widgets
,
List
<
Type
>
expected
)
{
List
<
Type
>
actual
=
widgets
.
map
((
Widget
w
)
=>
w
.
runtimeType
).
toList
();
expect
(
actual
,
expected
);
}
void
_expectTextStrings
(
List
<
Element
>
elemen
ts
,
List
<
String
>
strings
)
{
void
_expectTextStrings
(
Iterable
<
Widget
>
widge
ts
,
List
<
String
>
strings
)
{
int
currentString
=
0
;
for
(
Element
element
in
elements
)
{
Widget
widget
=
element
.
widget
;
for
(
Widget
widget
in
widgets
)
{
if
(
widget
is
RichText
)
{
TextSpan
span
=
widget
.
text
;
String
text
=
_extractTextFromTextSpan
(
span
);
...
...
packages/flutter_test/lib/flutter_test.dart
View file @
f3a4f722
...
...
@@ -5,6 +5,7 @@
/// Testing library for flutter, built on top of `package:test`.
library
flutter_test
;
export
'src/element_tree_tester.dart'
;
export
'src/instrumentation.dart'
;
export
'src/service_mocker.dart'
;
export
'src/test_pointer.dart'
;
...
...
packages/flutter_test/lib/src/element_tree_tester.dart
0 → 100644
View file @
f3a4f722
// Copyright 2016 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'
as
ui
show
window
;
import
'package:flutter/rendering.dart'
;
import
'package:flutter/scheduler.dart'
;
import
'package:flutter/services.dart'
;
import
'package:flutter/widgets.dart'
;
import
'package:quiver/testing/async.dart'
;
import
'package:quiver/time.dart'
;
import
'instrumentation.dart'
;
/// Enumeration of possible phases to reach in pumpWidget.
enum
EnginePhase
{
layout
,
compositingBits
,
paint
,
composite
,
flushSemantics
,
sendSemanticsTree
}
class
_SteppedWidgetFlutterBinding
extends
WidgetFlutterBinding
{
/// Creates and initializes the binding. This constructor is
/// idempotent; calling it a second time will just return the
/// previously-created instance.
static
WidgetFlutterBinding
ensureInitialized
()
{
if
(
WidgetFlutterBinding
.
instance
==
null
)
new
_SteppedWidgetFlutterBinding
();
return
WidgetFlutterBinding
.
instance
;
}
EnginePhase
phase
=
EnginePhase
.
sendSemanticsTree
;
// Pump the rendering pipeline up to the given phase.
@override
void
beginFrame
()
{
buildOwner
.
buildDirtyElements
();
_beginFrame
();
buildOwner
.
finalizeTree
();
}
// Cloned from Renderer.beginFrame() but with early-exit semantics.
void
_beginFrame
()
{
assert
(
renderView
!=
null
);
pipelineOwner
.
flushLayout
();
if
(
phase
==
EnginePhase
.
layout
)
return
;
pipelineOwner
.
flushCompositingBits
();
if
(
phase
==
EnginePhase
.
compositingBits
)
return
;
pipelineOwner
.
flushPaint
();
if
(
phase
==
EnginePhase
.
paint
)
return
;
renderView
.
compositeFrame
();
// this sends the bits to the GPU
if
(
phase
==
EnginePhase
.
composite
)
return
;
if
(
SemanticsNode
.
hasListeners
)
{
pipelineOwner
.
flushSemantics
();
if
(
phase
==
EnginePhase
.
flushSemantics
)
return
;
SemanticsNode
.
sendSemanticsTree
();
}
}
}
/// Helper class for flutter tests providing fake async.
///
/// This class extends Instrumentation to also abstract away the beginFrame
/// and async/clock access to allow writing tests which depend on the passage
/// of time without actually moving the clock forward.
class
ElementTreeTester
extends
Instrumentation
{
ElementTreeTester
.
_
(
FakeAsync
async
)
:
async
=
async
,
clock
=
async
.
getClock
(
new
DateTime
.
utc
(
2015
,
1
,
1
)),
super
(
binding:
_SteppedWidgetFlutterBinding
.
ensureInitialized
())
{
timeDilation
=
1.0
;
ui
.
window
.
onBeginFrame
=
null
;
debugPrint
=
_synchronousDebugPrint
;
}
void
_synchronousDebugPrint
(
String
message
,
{
int
wrapWidth
})
{
if
(
wrapWidth
!=
null
)
{
print
(
message
.
split
(
'
\n
'
).
expand
((
String
line
)
=>
debugWordWrap
(
line
,
wrapWidth
)).
join
(
'
\n
'
));
}
else
{
print
(
message
);
}
}
final
FakeAsync
async
;
final
Clock
clock
;
/// 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.
void
pumpWidget
(
Widget
widget
,
[
Duration
duration
,
EnginePhase
phase
])
{
runApp
(
widget
);
pump
(
duration
,
phase
);
}
/// Triggers a frame sequence (build/layout/paint/etc),
/// then flushes microtasks.
///
/// If duration is set, then advances the clock by that much first.
/// Doing this flushes microtasks.
///
/// The supplied EnginePhase is the final phase reached during the pump pass;
/// if not supplied, the whole pass is executed.
void
pump
([
Duration
duration
,
EnginePhase
phase
])
{
if
(
duration
!=
null
)
async
.
elapse
(
duration
);
if
(
binding
is
_SteppedWidgetFlutterBinding
)
{
// Some tests call WidgetFlutterBinding.ensureInitialized() manually, so
// we can't actually be sure we have a stepped binding.
_SteppedWidgetFlutterBinding
steppedBinding
=
binding
;
steppedBinding
.
phase
=
phase
??
EnginePhase
.
sendSemanticsTree
;
}
else
{
// Can't step to a given phase in that case
assert
(
phase
==
null
);
}
binding
.
handleBeginFrame
(
new
Duration
(
milliseconds:
clock
.
now
().
millisecondsSinceEpoch
)
);
async
.
flushMicrotasks
();
}
/// Artificially calls dispatchLocaleChanged on the Widget binding,
/// then flushes microtasks.
void
setLocale
(
String
languageCode
,
String
countryCode
)
{
Locale
locale
=
new
Locale
(
languageCode
,
countryCode
);
binding
.
dispatchLocaleChanged
(
locale
);
async
.
flushMicrotasks
();
}
@override
void
dispatchEvent
(
PointerEvent
event
,
HitTestResult
result
)
{
super
.
dispatchEvent
(
event
,
result
);
async
.
flushMicrotasks
();
}
/// Returns the exception most recently caught by the Flutter framework.
///
/// Call this if you expect an exception during a test. If an exception is
/// thrown and this is not called, then the exception is rethrown when
/// the [testWidgets] call completes.
///
/// If two exceptions are thrown in a row without the first one being
/// acknowledged with a call to this method, then when the second exception is
/// thrown, they are both dumped to the console and then the second is
/// rethrown from the exception handler. This will likely result in the
/// framework entering a highly unstable state and everything collapsing.
///
/// It's safe to call this when there's no pending exception; it will return
/// null in that case.
dynamic
takeException
()
{
dynamic
result
=
_pendingException
;
_pendingException
=
null
;
return
result
;
}
dynamic
_pendingException
;
}
void
testElementTree
(
callback
(
ElementTreeTester
tester
))
{
new
FakeAsync
().
run
((
FakeAsync
async
)
{
FlutterExceptionHandler
oldHandler
=
FlutterError
.
onError
;
try
{
ElementTreeTester
tester
=
new
ElementTreeTester
.
_
(
async
);
FlutterError
.
onError
=
(
FlutterErrorDetails
details
)
{
if
(
tester
.
_pendingException
!=
null
)
{
FlutterError
.
dumpErrorToConsole
(
tester
.
_pendingException
);
FlutterError
.
dumpErrorToConsole
(
details
.
exception
);
tester
.
_pendingException
=
'An uncaught exception was thrown.'
;
throw
details
.
exception
;
}
tester
.
_pendingException
=
details
;
};
runApp
(
new
Container
(
key:
new
UniqueKey
()));
// Reset the tree to a known state.
callback
(
tester
);
runApp
(
new
Container
(
key:
new
UniqueKey
()));
// Unmount any remaining widgets.
async
.
flushMicrotasks
();
assert
(
Scheduler
.
instance
.
debugAssertNoTransientCallbacks
(
'An animation is still running even after the widget tree was disposed.'
));
assert
(()
{
'A Timer is still running even after the widget tree was disposed.'
;
return
async
.
periodicTimerCount
==
0
;
});
assert
(()
{
'A Timer is still running even after the widget tree was disposed.'
;
return
async
.
nonPeriodicTimerCount
==
0
;
});
assert
(
async
.
microtaskCount
==
0
);
// Shouldn't be possible.
if
(
tester
.
_pendingException
!=
null
)
{
FlutterError
.
dumpErrorToConsole
(
tester
.
_pendingException
);
throw
'An exception (shown above) was thrown during the test.'
;
}
}
finally
{
FlutterError
.
onError
=
oldHandler
;
}
});
}
packages/flutter_test/lib/src/instrumentation.dart
View file @
f3a4f722
...
...
@@ -2,6 +2,8 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
import
'dart:collection'
;
import
'package:flutter/gestures.dart'
;
import
'package:flutter/rendering.dart'
;
import
'package:flutter/widgets.dart'
;
...
...
@@ -61,6 +63,20 @@ class Instrumentation {
return
null
;
}
/// Returns all elements ordered in a depth-first traversal fashion.
///
/// The returned iterable is lazy. It does not walk the entire element tree
/// immediately, but rather a chunk at a time as the iteration progresses
/// using [Iterator.moveNext].
Iterable
<
Element
>
get
allElements
{
return
new
_DepthFirstChildIterable
(
binding
.
renderViewElement
);
}
/// Returns all elements that satisfy [predicate].
Iterable
<
Element
>
findElements
(
bool
predicate
(
Element
element
))
{
return
allElements
.
where
(
predicate
);
}
/// Returns the first element that corresponds to a widget with the
/// given [Key], or null if there is no such element.
Element
findElementByKey
(
Key
key
)
{
...
...
@@ -284,3 +300,42 @@ class TestGesture {
_target
.
dispatchEvent
(
pointer
.
cancel
(),
_result
);
}
}
class
_DepthFirstChildIterable
extends
IterableBase
<
Element
>
{
_DepthFirstChildIterable
(
this
.
rootElement
);
Element
rootElement
;
@override
Iterator
<
Element
>
get
iterator
=>
new
_DepthFirstChildIterator
(
rootElement
);
}
class
_DepthFirstChildIterator
implements
Iterator
<
Element
>
{
_DepthFirstChildIterator
(
Element
rootElement
)
:
_stack
=
_reverseChildrenOf
(
rootElement
).
toList
();
Element
_current
;
final
List
<
Element
>
_stack
;
@override
Element
get
current
=>
_current
;
@override
bool
moveNext
()
{
if
(
_stack
.
isEmpty
)
return
false
;
_current
=
_stack
.
removeLast
();
// Stack children in reverse order to traverse first branch first
_stack
.
addAll
(
_reverseChildrenOf
(
_current
));
return
true
;
}
static
Iterable
<
Element
>
_reverseChildrenOf
(
Element
element
)
{
List
<
Element
>
children
=
<
Element
>[];
element
.
visitChildren
(
children
.
add
);
return
children
.
reversed
;
}
}
packages/flutter_test/lib/src/widget_tester.dart
View file @
f3a4f722
...
...
@@ -2,206 +2,463 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
import
'dart:ui'
as
ui
show
window
;
import
'package:flutter/services.dart'
;
import
'package:flutter/rendering.dart'
;
import
'package:flutter/scheduler.dart'
;
import
'package:flutter/widgets.dart'
;
import
'package:quiver/testing/async.dart'
;
import
'package:
quiver/time
.dart'
;
import
'package:
test/test
.dart'
;
import
'element_tree_tester.dart'
;
import
'instrumentation.dart'
;
/// Enumeration of possible phases to reach in pumpWidget.
enum
EnginePhase
{
layout
,
compositingBits
,
paint
,
composite
,
flushSemantics
,
sendSemanticsTree
/// Runs the [callback] inside the Flutter test environment.
///
/// Use this function for testing custom [StatelessWidget]s and
/// [StatefulWidget]s.
///
/// Example:
///
/// test('MyWidget', () {
/// testWidgets((WidgetTester tester) {
/// tester.pumpWidget(new MyWidget());
/// tester.tap(find.byText('Save'));
/// expect(tester, hasWidget(find.byText('Success')));
/// });
/// });
void
testWidgets
(
void
callback
(
WidgetTester
widgetTester
))
{
testElementTree
((
ElementTreeTester
elementTreeTester
)
{
callback
(
new
WidgetTester
.
_
(
elementTreeTester
));
});
}
class
_SteppedWidgetFlutterBinding
extends
WidgetFlutterBinding
{
/// Creates and initializes the binding. This constructor is
/// idempotent; calling it a second time will just return the
/// previously-created instance.
static
WidgetFlutterBinding
ensureInitialized
()
{
if
(
WidgetFlutterBinding
.
instance
==
null
)
new
_SteppedWidgetFlutterBinding
();
return
WidgetFlutterBinding
.
instance
;
}
EnginePhase
phase
=
EnginePhase
.
sendSemanticsTree
;
// Pump the rendering pipeline up to the given phase.
@override
void
beginFrame
()
{
buildOwner
.
buildDirtyElements
();
_beginFrame
();
buildOwner
.
finalizeTree
();
}
// Cloned from Renderer.beginFrame() but with early-exit semantics.
void
_beginFrame
()
{
assert
(
renderView
!=
null
);
pipelineOwner
.
flushLayout
();
if
(
phase
==
EnginePhase
.
layout
)
return
;
pipelineOwner
.
flushCompositingBits
();
if
(
phase
==
EnginePhase
.
compositingBits
)
return
;
pipelineOwner
.
flushPaint
();
if
(
phase
==
EnginePhase
.
paint
)
return
;
renderView
.
compositeFrame
();
// this sends the bits to the GPU
if
(
phase
==
EnginePhase
.
composite
)
return
;
if
(
SemanticsNode
.
hasListeners
)
{
pipelineOwner
.
flushSemantics
();
if
(
phase
==
EnginePhase
.
flushSemantics
)
return
;
SemanticsNode
.
sendSemanticsTree
();
}
}
}
/// A convenient accessor to frequently used finders.
///
/// Examples:
///
/// tester.tap(find.byText('Save'));
/// tester.widget(find.byType(MyWidget));
/// tester.stateOf(find.byConfig(config));
/// tester.getSize(find.byKey(new ValueKey('save-button')));
const
CommonFinders
find
=
const
CommonFinders
();
///
Helper class for flutter tests providing fake async
.
///
Asserts that [finder] locates a widget in the test element tree
.
///
/// This class extends Instrumentation to also abstract away the beginFrame
/// and async/clock access to allow writing tests which depend on the passage
/// of time without actually moving the clock forward.
class
WidgetTester
extends
Instrumentation
{
WidgetTester
.
_
(
FakeAsync
async
)
:
async
=
async
,
clock
=
async
.
getClock
(
new
DateTime
.
utc
(
2015
,
1
,
1
)),
super
(
binding:
_SteppedWidgetFlutterBinding
.
ensureInitialized
())
{
timeDilation
=
1.0
;
ui
.
window
.
onBeginFrame
=
null
;
debugPrint
=
_synchronousDebugPrint
;
}
void
_synchronousDebugPrint
(
String
message
,
{
int
wrapWidth
})
{
if
(
wrapWidth
!=
null
)
{
print
(
message
.
split
(
'
\n
'
).
expand
((
String
line
)
=>
debugWordWrap
(
line
,
wrapWidth
)).
join
(
'
\n
'
));
}
else
{
print
(
message
);
}
}
final
FakeAsync
async
;
final
Clock
clock
;
/// 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.
/// Example:
///
/// expect(tester, hasWidget(find.byText('Save')));
Matcher
hasWidget
(
Finder
finder
)
=>
new
_HasWidgetMatcher
(
finder
);
/// Opposite of [hasWidget].
Matcher
doesNotHaveWidget
(
Finder
finder
)
=>
new
_DoesNotHaveWidgetMatcher
(
finder
);
/// Class that programmatically interacts with widgets and the test environment.
class
WidgetTester
{
WidgetTester
.
_
(
this
.
elementTreeTester
);
/// Exposes the [Element] tree created from widgets.
final
ElementTreeTester
elementTreeTester
;
WidgetFlutterBinding
get
binding
=>
elementTreeTester
.
binding
;
/// Renders the UI from the given [widget].
///
/// See [ElementTreeTester.pumpWidget] for details.
void
pumpWidget
(
Widget
widget
,
[
Duration
duration
,
EnginePhase
phase
])
{
runApp
(
widget
);
pump
(
duration
,
phase
);
elementTreeTester
.
pumpWidget
(
widget
,
duration
,
phase
);
}
/// Triggers a frame sequence (build/layout/paint/etc),
/// then flushes microtasks.
/// Triggers a sequence of frames for [duration] amount of time.
///
/// If duration is set, then advances the clock by that much first.
/// Doing this flushes microtasks.
///
/// The supplied EnginePhase is the final phase reached during the pump pass;
/// if not supplied, the whole pass is executed.
/// See [ElementTreeTester.pump] for details.
void
pump
([
Duration
duration
,
EnginePhase
phase
])
{
if
(
duration
!=
null
)
async
.
elapse
(
duration
);
if
(
binding
is
_SteppedWidgetFlutterBinding
)
{
// Some tests call WidgetFlutterBinding.ensureInitialized() manually, so
// we can't actually be sure we have a stepped binding.
_SteppedWidgetFlutterBinding
steppedBinding
=
binding
;
steppedBinding
.
phase
=
phase
??
EnginePhase
.
sendSemanticsTree
;
}
else
{
// Can't step to a given phase in that case
assert
(
phase
==
null
);
}
binding
.
handleBeginFrame
(
new
Duration
(
milliseconds:
clock
.
now
().
millisecondsSinceEpoch
)
);
async
.
flushMicrotasks
();
elementTreeTester
.
pump
(
duration
,
phase
);
}
/// Artificially calls dispatchLocaleChanged on the Widget binding,
/// then flushes microtasks.
/// Changes the current locale.
///
/// See [ElementTreeTester.setLocale] for details.
void
setLocale
(
String
languageCode
,
String
countryCode
)
{
Locale
locale
=
new
Locale
(
languageCode
,
countryCode
);
binding
.
dispatchLocaleChanged
(
locale
);
async
.
flushMicrotasks
();
elementTreeTester
.
setLocale
(
languageCode
,
countryCode
);
}
@override
/// Sends an [event] at [result] location.
///
/// See [ElementTreeTester.dispatchEvent] for details.
void
dispatchEvent
(
PointerEvent
event
,
HitTestResult
result
)
{
super
.
dispatchEvent
(
event
,
result
);
async
.
flushMicrotasks
();
elementTreeTester
.
dispatchEvent
(
event
,
result
);
}
/// Returns the exception most recently caught by the Flutter framework.
///
/// Call this if you expect an exception during a test. If an exception is
/// thrown and this is not called, then the exception is rethrown when
/// the [testWidgets] call completes.
/// See [ElementTreeTester.takeException] for details.
dynamic
takeException
()
{
return
elementTreeTester
.
takeException
();
}
/// Returns the fake implmentation of the event loop used by the test
/// environment.
///
/// If two exceptions are thrown in a row without the first one being
/// acknowledged with a call to this method, then when the second exception is
/// thrown, they are both dumped to the console and then the second is
/// rethrown from the exception handler. This will likely result in the
/// framework entering a highly unstable state and everything collapsing.
/// Use it to travel into the future without actually waiting, control the
/// flushing of microtasks and timers.
FakeAsync
get
async
=>
elementTreeTester
.
async
;
/// Runs all remaining microtasks, including those scheduled as a result of
/// running them, until there are no more microtasks scheduled.
///
/// It's safe to call this when there's no pending exception; it will return
/// null in that case.
dynamic
takeException
()
{
dynamic
result
=
_pendingException
;
_pendingException
=
null
;
return
result
;
/// Does not run timers. May result in an infinite loop or run out of memory
/// if microtasks continue to recursively schedule new microtasks.
void
flushMicrotasks
()
{
elementTreeTester
.
async
.
flushMicrotasks
();
}
/// Checks if the element identified by [finder] exists in the tree.
bool
exists
(
Finder
finder
)
=>
finder
.
find
(
this
).
isNotEmpty
;
/// All widgets currently live on the UI returned in a depth-first traversal
/// order.
Iterable
<
Widget
>
get
widgets
{
return
this
.
elementTreeTester
.
allElements
.
map
((
Element
element
)
=>
element
.
widget
);
}
/// Finds the first widget, searching in the depth-first traversal order.
Widget
widget
(
Finder
finder
)
{
return
finder
.
findFirst
(
this
).
widget
;
}
/// Finds the first state object, searching in the depth-first traversal order.
State
stateOf
(
Finder
finder
)
{
Element
element
=
finder
.
findFirst
(
this
);
Widget
widget
=
element
.
widget
;
if
(
widget
is
StatefulWidget
)
return
(
element
as
StatefulElement
).
state
;
throw
new
ElementNotFoundError
(
'Widget of type
${widget.runtimeType}
found by
${finder.description}
does not correspond to a StatefulWidget'
);
}
/// Finds the [Element] corresponding to the first widget found by [finder],
/// searching in the depth-first traversal order.
Element
elementOf
(
Finder
finder
)
=>
finder
.
findFirst
(
this
);
/// Finds the [RenderObject] corresponding to the first widget found by
/// [finder], searching in the depth-first traversal order.
RenderObject
renderObjectOf
(
Finder
finder
)
=>
finder
.
findFirst
(
this
).
findRenderObject
();
/// Emulates a tapping action at the center of the widget found by [finder].
void
tap
(
Finder
finder
,
{
int
pointer:
1
})
{
tapAt
(
getCenter
(
finder
),
pointer:
pointer
);
}
/// Emulates a tapping action at the given [location].
///
/// See [ElementTreeTester.tapAt] for details.
void
tapAt
(
Point
location
,
{
int
pointer:
1
})
{
elementTreeTester
.
tapAt
(
location
,
pointer:
pointer
);
}
/// Scrolls by dragging the center of a widget found by [finder] by [offset].
void
scroll
(
Finder
finder
,
Offset
offset
,
{
int
pointer:
1
})
{
scrollAt
(
getCenter
(
finder
),
offset
,
pointer:
pointer
);
}
/// Scrolls by dragging the screen at [startLocation] by [offset].
///
/// See [ElementTreeTester.scrollAt] for details.
void
scrollAt
(
Point
startLocation
,
Offset
offset
,
{
int
pointer:
1
})
{
elementTreeTester
.
scrollAt
(
startLocation
,
offset
,
pointer:
pointer
);
}
/// Attempts a fling gesture starting at the center of a widget found by
/// [finder].
///
/// See also [flingFrom].
void
fling
(
Finder
finder
,
Offset
offset
,
double
velocity
,
{
int
pointer:
1
})
{
flingFrom
(
getCenter
(
finder
),
offset
,
velocity
,
pointer:
pointer
);
}
/// Attempts a fling gesture starting at [startLocation], moving by [offset]
/// with the given [velocity].
///
/// See [ElementTreeTester.flingFrom] for details.
void
flingFrom
(
Point
startLocation
,
Offset
offset
,
double
velocity
,
{
int
pointer:
1
})
{
elementTreeTester
.
flingFrom
(
startLocation
,
offset
,
velocity
,
pointer:
pointer
);
}
/// Begins a gesture at a particular point, and returns the
/// [TestGesture] object which you can use to continue the gesture.
TestGesture
startGesture
(
Point
downLocation
,
{
int
pointer:
1
})
{
return
elementTreeTester
.
startGesture
(
downLocation
,
pointer:
pointer
);
}
/// Returns the size of the element corresponding to the widget located by
/// [finder].
///
/// This is only valid once the element's render object has been laid out at
/// least once.
Size
getSize
(
Finder
finder
)
{
assert
(
finder
!=
null
);
Element
element
=
finder
.
findFirst
(
this
);
return
elementTreeTester
.
getSize
(
element
);
}
/// Returns the point at the center of the widget found by [finder].
Point
getCenter
(
Finder
finder
)
{
Element
element
=
finder
.
findFirst
(
this
);
return
elementTreeTester
.
getCenter
(
element
);
}
/// Returns the point at the top left of the given element.
Point
getTopLeft
(
Finder
finder
)
{
Element
element
=
finder
.
findFirst
(
this
);
return
elementTreeTester
.
getTopLeft
(
element
);
}
/// Returns the point at the top right of the given element. This
/// point is not inside the object's hit test area.
Point
getTopRight
(
Finder
finder
)
{
Element
element
=
finder
.
findFirst
(
this
);
return
elementTreeTester
.
getTopRight
(
element
);
}
/// Returns the point at the bottom left of the given element. This
/// point is not inside the object's hit test area.
Point
getBottomLeft
(
Finder
finder
)
{
Element
element
=
finder
.
findFirst
(
this
);
return
elementTreeTester
.
getBottomLeft
(
element
);
}
/// Returns the point at the bottom right of the given element. This
/// point is not inside the object's hit test area.
Point
getBottomRight
(
Finder
finder
)
{
Element
element
=
finder
.
findFirst
(
this
);
return
elementTreeTester
.
getBottomRight
(
element
);
}
dynamic
_pendingException
;
}
void
testWidgets
(
callback
(
WidgetTester
tester
))
{
new
FakeAsync
().
run
((
FakeAsync
async
)
{
FlutterExceptionHandler
oldHandler
=
FlutterError
.
onError
;
try
{
WidgetTester
tester
=
new
WidgetTester
.
_
(
async
);
FlutterError
.
onError
=
(
FlutterErrorDetails
details
)
{
if
(
tester
.
_pendingException
!=
null
)
{
FlutterError
.
dumpErrorToConsole
(
tester
.
_pendingException
);
FlutterError
.
dumpErrorToConsole
(
details
.
exception
);
tester
.
_pendingException
=
'An uncaught exception was thrown.'
;
throw
details
.
exception
;
/// Provides lightweight syntax for getting frequently used widget [Finder]s.
class
CommonFinders
{
const
CommonFinders
();
/// Finds [Text] widgets containing string equal to [text].
Finder
text
(
String
text
)
=>
new
_TextFinder
(
text
);
/// Looks for widgets that contain [Text] with [text] in it.
///
/// Example:
///
/// // Suppose you have a button with text 'Update' in it:
/// new Button(
/// child: new Text('Update')
/// )
///
/// // You can find and tap on it like this:
/// tester.tap(find.widgetWithText(Button, 'Update'));
Finder
widgetWithText
(
Type
widgetType
,
String
text
)
=>
new
_WidgetWithTextFinder
(
widgetType
,
text
);
/// Finds widgets by [key].
Finder
byKey
(
Key
key
)
=>
new
_KeyFinder
(
key
);
/// Finds widgets by [type].
Finder
byType
(
Type
type
)
=>
new
_TypeFinder
(
type
);
/// Finds widgets equal to [config].
Finder
byConfig
(
Widget
config
)
=>
new
_ConfigFinder
(
config
);
/// Finds widgets using an element [predicate].
Finder
byElement
(
ElementPredicate
predicate
)
=>
new
_ElementFinder
(
predicate
);
}
/// Finds [Element]s inside the element tree.
abstract
class
Finder
{
Iterable
<
Element
>
find
(
WidgetTester
tester
);
/// Describes what the finder is looking for. The description should be such
/// that [toString] reads as a descriptive English sentence.
String
get
description
;
Element
findFirst
(
WidgetTester
tester
)
{
Iterable
<
Element
>
results
=
find
(
tester
);
return
results
.
isNotEmpty
?
results
.
first
:
throw
new
ElementNotFoundError
.
fromFinder
(
this
);
}
@override
String
toString
()
=>
'widget with
$description
'
;
}
/// Indicates that an attempt to find a widget within the current element tree
/// failed.
class
ElementNotFoundError
extends
Error
{
ElementNotFoundError
(
this
.
message
);
ElementNotFoundError
.
fromFinder
(
Finder
finder
)
:
message
=
'Element not found by
${finder.description}
'
;
final
String
message
;
@override
String
toString
()
=>
'ElementNotFoundError:
$message
'
;
}
class
_TextFinder
extends
Finder
{
_TextFinder
(
this
.
text
);
final
String
text
;
@override
String
get
description
=>
'text "
$text
"'
;
@override
Iterable
<
Element
>
find
(
WidgetTester
tester
)
{
return
tester
.
elementTreeTester
.
findElements
((
Element
element
)
{
if
(
element
.
widget
is
!
Text
)
return
false
;
Text
textWidget
=
element
.
widget
;
return
textWidget
.
data
==
text
;
});
}
}
class
_WidgetWithTextFinder
extends
Finder
{
_WidgetWithTextFinder
(
this
.
widgetType
,
this
.
text
);
final
Type
widgetType
;
final
String
text
;
@override
String
get
description
=>
'type
$widgetType
with text "
$text
"'
;
@override
Iterable
<
Element
>
find
(
WidgetTester
tester
)
{
return
tester
.
elementTreeTester
.
allElements
.
map
((
Element
textElement
)
{
if
(
textElement
.
widget
is
!
Text
)
return
null
;
Text
textWidget
=
textElement
.
widget
;
if
(
textWidget
.
data
==
text
)
{
Element
parent
;
textElement
.
visitAncestorElements
((
Element
element
)
{
if
(
element
.
widget
.
runtimeType
==
widgetType
)
{
parent
=
element
;
return
false
;
}
return
true
;
});
return
parent
;
}
tester
.
_pendingException
=
details
;
};
runApp
(
new
Container
(
key:
new
UniqueKey
()));
// Reset the tree to a known state.
callback
(
tester
);
runApp
(
new
Container
(
key:
new
UniqueKey
()));
// Unmount any remaining widgets.
async
.
flushMicrotasks
();
assert
(
Scheduler
.
instance
.
debugAssertNoTransientCallbacks
(
'An animation is still running even after the widget tree was disposed.'
));
assert
(()
{
'A Timer is still running even after the widget tree was disposed.'
;
return
async
.
periodicTimerCount
==
0
;
});
assert
(()
{
'A Timer is still running even after the widget tree was disposed.'
;
return
async
.
nonPeriodicTimerCount
==
0
;
});
assert
(
async
.
microtaskCount
==
0
);
// Shouldn't be possible.
if
(
tester
.
_pendingException
!=
null
)
{
FlutterError
.
dumpErrorToConsole
(
tester
.
_pendingException
);
throw
'An exception (shown above) was thrown during the test.'
;
}
}
finally
{
FlutterError
.
onError
=
oldHandler
;
}
});
return
null
;
})
.
where
((
Element
element
)
=>
element
!=
null
);
}
}
class
_KeyFinder
extends
Finder
{
_KeyFinder
(
this
.
key
);
final
Key
key
;
@override
String
get
description
=>
'key
$key
'
;
@override
Iterable
<
Element
>
find
(
WidgetTester
tester
)
{
return
tester
.
elementTreeTester
.
findElements
((
Element
element
)
=>
element
.
widget
.
key
==
key
);
}
}
class
_TypeFinder
extends
Finder
{
_TypeFinder
(
this
.
widgetType
);
final
Type
widgetType
;
@override
String
get
description
=>
'type "
$widgetType
"'
;
@override
Iterable
<
Element
>
find
(
WidgetTester
tester
)
{
return
tester
.
elementTreeTester
.
allElements
.
where
((
Element
element
)
{
return
element
.
widget
.
runtimeType
==
widgetType
;
});
}
}
class
_ConfigFinder
extends
Finder
{
_ConfigFinder
(
this
.
config
);
final
Widget
config
;
@override
String
get
description
=>
'the given configuration (
$config
)'
;
@override
Iterable
<
Element
>
find
(
WidgetTester
tester
)
{
return
tester
.
elementTreeTester
.
allElements
.
where
((
Element
element
)
{
return
element
.
widget
==
config
;
});
}
}
typedef
bool
ElementPredicate
(
Element
element
);
class
_ElementFinder
extends
Finder
{
_ElementFinder
(
this
.
predicate
);
final
ElementPredicate
predicate
;
@override
String
get
description
=>
'element satisfying given predicate (
$predicate
)'
;
@override
Iterable
<
Element
>
find
(
WidgetTester
tester
)
{
return
tester
.
elementTreeTester
.
allElements
.
where
(
predicate
);
}
}
class
_HasWidgetMatcher
extends
Matcher
{
const
_HasWidgetMatcher
(
this
.
finder
);
final
Finder
finder
;
@override
bool
matches
(
WidgetTester
tester
,
Map
<
dynamic
,
dynamic
>
matchState
)
{
return
tester
.
exists
(
finder
);
}
@override
Description
describe
(
Description
description
)
{
return
description
.
add
(
'
$finder
exists in the element tree'
);
}
@override
Description
describeMismatch
(
dynamic
item
,
Description
mismatchDescription
,
Map
<
dynamic
,
dynamic
>
matchState
,
bool
verbose
)
{
return
mismatchDescription
.
add
(
'Does not contain
$finder
'
);
}
}
class
_DoesNotHaveWidgetMatcher
extends
Matcher
{
const
_DoesNotHaveWidgetMatcher
(
this
.
finder
);
final
Finder
finder
;
@override
bool
matches
(
WidgetTester
tester
,
Map
<
dynamic
,
dynamic
>
matchState
)
{
return
!
tester
.
exists
(
finder
);
}
@override
Description
describe
(
Description
description
)
{
return
description
.
add
(
'
$finder
does not exist in the element tree'
);
}
@override
Description
describeMismatch
(
dynamic
item
,
Description
mismatchDescription
,
Map
<
dynamic
,
dynamic
>
matchState
,
bool
verbose
)
{
return
mismatchDescription
.
add
(
'Contains
$finder
'
);
}
}
packages/flutter_test/test/widget_tester_test.dart
0 → 100644
View file @
f3a4f722
// Copyright 2016 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
'package:flutter/widgets.dart'
;
import
'package:flutter_test/flutter_test.dart'
;
import
'package:test/test.dart'
;
void
main
(
)
{
group
(
'hasWidget'
,
()
{
test
(
'succeeds'
,
()
{
testWidgets
((
WidgetTester
tester
)
{
tester
.
pumpWidget
(
new
Text
(
'foo'
));
expect
(
tester
,
hasWidget
(
find
.
text
(
'foo'
)));
});
});
test
(
'fails with a descriptive message'
,
()
{
testWidgets
((
WidgetTester
tester
)
{
TestFailure
failure
;
try
{
expect
(
tester
,
hasWidget
(
find
.
text
(
'foo'
)));
}
catch
(
e
)
{
failure
=
e
;
}
expect
(
failure
,
isNotNull
);
String
message
=
failure
.
message
;
expect
(
message
,
contains
(
'Expected: widget with text "foo" exists in the element tree'
));
expect
(
message
,
contains
(
"Actual: <Instance of 'WidgetTester'>"
));
expect
(
message
,
contains
(
'Which: Does not contain widget with text "foo"'
));
});
});
});
group
(
'doesNotHaveWidget'
,
()
{
test
(
'succeeds'
,
()
{
testWidgets
((
WidgetTester
tester
)
{
expect
(
tester
,
doesNotHaveWidget
(
find
.
text
(
'foo'
)));
});
});
test
(
'fails with a descriptive message'
,
()
{
testWidgets
((
WidgetTester
tester
)
{
tester
.
pumpWidget
(
new
Text
(
'foo'
));
TestFailure
failure
;
try
{
expect
(
tester
,
doesNotHaveWidget
(
find
.
text
(
'foo'
)));
}
catch
(
e
)
{
failure
=
e
;
}
expect
(
failure
,
isNotNull
);
String
message
=
failure
.
message
;
expect
(
message
,
contains
(
'Expected: widget with text "foo" does not exist in the element tree'
));
expect
(
message
,
contains
(
"Actual: <Instance of 'WidgetTester'>"
));
expect
(
message
,
contains
(
'Which: Contains widget with text "foo"'
));
});
});
});
}
travis/test.sh
View file @
f3a4f722
...
...
@@ -14,6 +14,7 @@ flutter analyze --flutter-repo --no-current-directory --no-current-package --con
(
cd
packages/flutter
;
flutter
test
)
(
cd
packages/flutter_driver
;
dart
-c
test
/all.dart
)
(
cd
packages/flutter_sprites
;
flutter
test
)
(
cd
packages/flutter_test
;
flutter
test
)
(
cd
packages/flutter_tools
;
dart
-c
test
/all.dart
)
(
cd
packages/flx
;
dart
-c
test
/all.dart
)
(
cd
packages/newton
;
dart
-c
test
/all.dart
)
...
...
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