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
a499dc1d
Commit
a499dc1d
authored
Feb 22, 2016
by
Adam Barth
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #2065 from abarth/test_gesture
Add TestGesture
parents
aeb94191
1484add1
Changes
8
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
8 changed files
with
115 additions
and
98 deletions
+115
-98
icon_color_test.dart
examples/stocks/test/icon_color_test.dart
+3
-4
block_test.dart
packages/flutter/test/widget/block_test.dart
+6
-8
dismissable_test.dart
packages/flutter/test/widget/dismissable_test.dart
+9
-10
draggable_test.dart
packages/flutter/test/widget/draggable_test.dart
+46
-60
gesture_detector_test.dart
packages/flutter/test/widget/gesture_detector_test.dart
+9
-13
set_state_test.dart
packages/flutter/test/widget/set_state_test.dart
+2
-3
flutter_test.dart
packages/flutter_test/lib/flutter_test.dart
+1
-0
instrumentation.dart
packages/flutter_test/lib/src/instrumentation.dart
+39
-0
No files found.
examples/stocks/test/icon_color_test.dart
View file @
a499dc1d
...
@@ -76,14 +76,13 @@ void main() {
...
@@ -76,14 +76,13 @@ void main() {
expect
(
tester
.
findText
(
'Help & Feedback'
),
isNull
);
expect
(
tester
.
findText
(
'Help & Feedback'
),
isNull
);
// drag the drawer out
// drag the drawer out
TestPointer
pointer
=
new
TestPointer
(
1
);
Point
left
=
new
Point
(
0.0
,
ui
.
window
.
size
.
height
/
2.0
);
Point
left
=
new
Point
(
0.0
,
ui
.
window
.
size
.
height
/
2.0
);
Point
right
=
new
Point
(
ui
.
window
.
size
.
width
,
left
.
y
);
Point
right
=
new
Point
(
ui
.
window
.
size
.
width
,
left
.
y
);
tester
.
dispatchEvent
(
pointer
.
down
(
left
),
left
);
TestGesture
gesture
=
tester
.
startGesture
(
left
);
tester
.
pump
();
tester
.
pump
();
tester
.
dispatchEvent
(
pointer
.
move
(
right
),
lef
t
);
gesture
.
moveTo
(
righ
t
);
tester
.
pump
();
tester
.
pump
();
tester
.
dispatchEvent
(
pointer
.
up
(),
left
);
gesture
.
up
(
);
tester
.
pump
();
tester
.
pump
();
expect
(
tester
.
findText
(
'MARKET'
),
isNotNull
);
expect
(
tester
.
findText
(
'MARKET'
),
isNotNull
);
expect
(
tester
.
findText
(
'Help & Feedback'
),
isNotNull
);
expect
(
tester
.
findText
(
'Help & Feedback'
),
isNotNull
);
...
...
packages/flutter/test/widget/block_test.dart
View file @
a499dc1d
...
@@ -26,15 +26,14 @@ void main() {
...
@@ -26,15 +26,14 @@ void main() {
Point
middleOfContainer
=
tester
.
getCenter
(
tester
.
findText
(
'Hello'
));
Point
middleOfContainer
=
tester
.
getCenter
(
tester
.
findText
(
'Hello'
));
Point
target
=
tester
.
getCenter
(
tester
.
findElementByKey
(
blockKey
));
Point
target
=
tester
.
getCenter
(
tester
.
findElementByKey
(
blockKey
));
TestPointer
pointer
=
new
TestPointer
();
TestGesture
gesture
=
tester
.
startGesture
(
target
);
tester
.
dispatchEvent
(
pointer
.
down
(
target
),
target
);
gesture
.
moveBy
(
const
Offset
(
0.0
,
-
10.0
));
tester
.
dispatchEvent
(
pointer
.
move
(
target
+
const
Offset
(
0.0
,
-
10.0
)),
target
);
tester
.
pump
(
const
Duration
(
milliseconds:
1
));
tester
.
pump
(
const
Duration
(
milliseconds:
1
));
expect
(
tester
.
getCenter
(
tester
.
findText
(
'Hello'
))
==
middleOfContainer
,
isTrue
);
expect
(
tester
.
getCenter
(
tester
.
findText
(
'Hello'
))
==
middleOfContainer
,
isTrue
);
tester
.
dispatchEvent
(
pointer
.
up
(),
target
);
gesture
.
up
(
);
});
});
});
});
...
@@ -55,15 +54,14 @@ void main() {
...
@@ -55,15 +54,14 @@ void main() {
Point
middleOfContainer
=
tester
.
getCenter
(
tester
.
findText
(
'Hello'
));
Point
middleOfContainer
=
tester
.
getCenter
(
tester
.
findText
(
'Hello'
));
Point
target
=
tester
.
getCenter
(
tester
.
findElementByKey
(
blockKey
));
Point
target
=
tester
.
getCenter
(
tester
.
findElementByKey
(
blockKey
));
TestPointer
pointer
=
new
TestPointer
();
TestGesture
gesture
=
tester
.
startGesture
(
target
);
tester
.
dispatchEvent
(
pointer
.
down
(
target
),
target
);
gesture
.
moveBy
(
const
Offset
(
0.0
,
-
10.0
));
tester
.
dispatchEvent
(
pointer
.
move
(
target
+
const
Offset
(
0.0
,
-
10.0
)),
target
);
tester
.
pump
(
const
Duration
(
milliseconds:
1
));
tester
.
pump
(
const
Duration
(
milliseconds:
1
));
expect
(
tester
.
getCenter
(
tester
.
findText
(
'Hello'
))
==
middleOfContainer
,
isFalse
);
expect
(
tester
.
getCenter
(
tester
.
findText
(
'Hello'
))
==
middleOfContainer
,
isFalse
);
tester
.
dispatchEvent
(
pointer
.
up
(),
target
);
gesture
.
up
(
);
});
});
});
});
...
...
packages/flutter/test/widget/dismissable_test.dart
View file @
a499dc1d
...
@@ -82,10 +82,9 @@ void dismissElement(WidgetTester tester, Element itemElement, { DismissDirection
...
@@ -82,10 +82,9 @@ void dismissElement(WidgetTester tester, Element itemElement, { DismissDirection
fail
(
"unsupported gestureDirection"
);
fail
(
"unsupported gestureDirection"
);
}
}
TestPointer
pointer
=
new
TestPointer
(
5
);
TestGesture
gesture
=
tester
.
startGesture
(
downLocation
,
pointer:
5
);
tester
.
dispatchEvent
(
pointer
.
down
(
downLocation
),
downLocation
);
gesture
.
moveTo
(
upLocation
);
tester
.
dispatchEvent
(
pointer
.
move
(
upLocation
),
downLocation
);
gesture
.
up
();
tester
.
dispatchEvent
(
pointer
.
up
(),
downLocation
);
}
}
void
dismissItem
(
WidgetTester
tester
,
int
item
,
{
DismissDirection
gestureDirection
})
{
void
dismissItem
(
WidgetTester
tester
,
int
item
,
{
DismissDirection
gestureDirection
})
{
...
@@ -247,18 +246,18 @@ void main() {
...
@@ -247,18 +246,18 @@ void main() {
tester
.
pumpWidget
(
widgetBuilder
());
tester
.
pumpWidget
(
widgetBuilder
());
Element
itemElement
=
tester
.
findText
(
'0'
);
Element
itemElement
=
tester
.
findText
(
'0'
);
TestPointer
pointer
=
new
TestPointer
(
5
);
Point
location
=
tester
.
getTopLeft
(
itemElement
);
Point
location
=
tester
.
getTopLeft
(
itemElement
);
Offset
offset
=
new
Offset
(
0.0
,
5.0
);
Offset
offset
=
new
Offset
(
0.0
,
5.0
);
tester
.
dispatchEvent
(
pointer
.
down
(
location
),
location
);
TestGesture
gesture
=
tester
.
startGesture
(
location
,
pointer:
5
);
tester
.
dispatchEvent
(
pointer
.
move
(
location
+
offset
),
location
);
gesture
.
moveBy
(
offset
);
tester
.
pumpWidget
(
widgetBuilder
());
tester
.
pumpWidget
(
widgetBuilder
());
tester
.
dispatchEvent
(
pointer
.
move
(
location
+
(
offset
*
2.0
)),
location
);
gesture
.
moveBy
(
offset
);
tester
.
pumpWidget
(
widgetBuilder
());
tester
.
pumpWidget
(
widgetBuilder
());
tester
.
dispatchEvent
(
pointer
.
move
(
location
+
(
offset
*
3.0
)),
location
);
gesture
.
moveBy
(
offset
);
tester
.
pumpWidget
(
widgetBuilder
());
tester
.
pumpWidget
(
widgetBuilder
());
tester
.
dispatchEvent
(
pointer
.
move
(
location
+
(
offset
*
4.0
)),
location
);
gesture
.
moveBy
(
offset
);
tester
.
pumpWidget
(
widgetBuilder
());
tester
.
pumpWidget
(
widgetBuilder
());
gesture
.
up
();
});
});
});
});
...
...
packages/flutter/test/widget/draggable_test.dart
View file @
a499dc1d
This diff is collapsed.
Click to expand it.
packages/flutter/test/widget/gesture_detector_test.dart
View file @
a499dc1d
...
@@ -9,8 +9,6 @@ import 'package:test/test.dart';
...
@@ -9,8 +9,6 @@ import 'package:test/test.dart';
void
main
(
)
{
void
main
(
)
{
test
(
'Uncontested scrolls start immediately'
,
()
{
test
(
'Uncontested scrolls start immediately'
,
()
{
testWidgets
((
WidgetTester
tester
)
{
testWidgets
((
WidgetTester
tester
)
{
TestPointer
pointer
=
new
TestPointer
(
7
);
bool
didStartDrag
=
false
;
bool
didStartDrag
=
false
;
double
updatedDragDelta
;
double
updatedDragDelta
;
bool
didEndDrag
=
false
;
bool
didEndDrag
=
false
;
...
@@ -38,20 +36,20 @@ void main() {
...
@@ -38,20 +36,20 @@ void main() {
expect
(
didEndDrag
,
isFalse
);
expect
(
didEndDrag
,
isFalse
);
Point
firstLocation
=
new
Point
(
10.0
,
10.0
);
Point
firstLocation
=
new
Point
(
10.0
,
10.0
);
tester
.
dispatchEvent
(
pointer
.
down
(
firstLocation
),
firstLocation
);
TestGesture
gesture
=
tester
.
startGesture
(
firstLocation
,
pointer:
7
);
expect
(
didStartDrag
,
isTrue
);
expect
(
didStartDrag
,
isTrue
);
didStartDrag
=
false
;
didStartDrag
=
false
;
expect
(
updatedDragDelta
,
isNull
);
expect
(
updatedDragDelta
,
isNull
);
expect
(
didEndDrag
,
isFalse
);
expect
(
didEndDrag
,
isFalse
);
Point
secondLocation
=
new
Point
(
10.0
,
9.0
);
Point
secondLocation
=
new
Point
(
10.0
,
9.0
);
tester
.
dispatchEvent
(
pointer
.
move
(
secondLocation
),
first
Location
);
gesture
.
moveTo
(
second
Location
);
expect
(
didStartDrag
,
isFalse
);
expect
(
didStartDrag
,
isFalse
);
expect
(
updatedDragDelta
,
-
1.0
);
expect
(
updatedDragDelta
,
-
1.0
);
updatedDragDelta
=
null
;
updatedDragDelta
=
null
;
expect
(
didEndDrag
,
isFalse
);
expect
(
didEndDrag
,
isFalse
);
tester
.
dispatchEvent
(
pointer
.
up
(),
firstLocation
);
gesture
.
up
(
);
expect
(
didStartDrag
,
isFalse
);
expect
(
didStartDrag
,
isFalse
);
expect
(
updatedDragDelta
,
isNull
);
expect
(
updatedDragDelta
,
isNull
);
expect
(
didEndDrag
,
isTrue
);
expect
(
didEndDrag
,
isTrue
);
...
@@ -63,8 +61,6 @@ void main() {
...
@@ -63,8 +61,6 @@ void main() {
test
(
'Match two scroll gestures in succession'
,
()
{
test
(
'Match two scroll gestures in succession'
,
()
{
testWidgets
((
WidgetTester
tester
)
{
testWidgets
((
WidgetTester
tester
)
{
TestPointer
pointer
=
new
TestPointer
(
7
);
int
gestureCount
=
0
;
int
gestureCount
=
0
;
double
dragDistance
=
0.0
;
double
dragDistance
=
0.0
;
...
@@ -84,13 +80,13 @@ void main() {
...
@@ -84,13 +80,13 @@ void main() {
);
);
tester
.
pumpWidget
(
widget
);
tester
.
pumpWidget
(
widget
);
tester
.
dispatchEvent
(
pointer
.
down
(
downLocation
),
downLocation
);
TestGesture
gesture
=
tester
.
startGesture
(
downLocation
,
pointer:
7
);
tester
.
dispatchEvent
(
pointer
.
move
(
upLocation
),
down
Location
);
gesture
.
moveTo
(
up
Location
);
tester
.
dispatchEvent
(
pointer
.
up
(),
downLocation
);
gesture
.
up
(
);
tester
.
dispatchEvent
(
pointer
.
down
(
downLocation
),
downLocation
);
gesture
=
tester
.
startGesture
(
downLocation
,
pointer:
7
);
tester
.
dispatchEvent
(
pointer
.
move
(
upLocation
),
down
Location
);
gesture
.
moveTo
(
up
Location
);
tester
.
dispatchEvent
(
pointer
.
up
(),
downLocation
);
gesture
.
up
(
);
expect
(
gestureCount
,
2
);
expect
(
gestureCount
,
2
);
expect
(
dragDistance
,
20.0
);
expect
(
dragDistance
,
20.0
);
...
...
packages/flutter/test/widget/set_state_test.dart
View file @
a499dc1d
...
@@ -58,11 +58,10 @@ void main() {
...
@@ -58,11 +58,10 @@ void main() {
test
(
'setState() smoke test'
,
()
{
test
(
'setState() smoke test'
,
()
{
testWidgets
((
WidgetTester
tester
)
{
testWidgets
((
WidgetTester
tester
)
{
tester
.
pumpWidget
(
new
Outside
());
tester
.
pumpWidget
(
new
Outside
());
TestPointer
pointer
=
new
TestPointer
(
1
);
Point
location
=
tester
.
getCenter
(
tester
.
findText
(
'INSIDE'
));
Point
location
=
tester
.
getCenter
(
tester
.
findText
(
'INSIDE'
));
tester
.
dispatchEvent
(
pointer
.
down
(
location
),
location
);
TestGesture
gesture
=
tester
.
startGesture
(
location
);
tester
.
pump
();
tester
.
pump
();
tester
.
dispatchEvent
(
pointer
.
up
(),
location
);
gesture
.
up
(
);
tester
.
pump
();
tester
.
pump
();
});
});
});
});
...
...
packages/flutter_test/lib/flutter_test.dart
View file @
a499dc1d
...
@@ -5,6 +5,7 @@
...
@@ -5,6 +5,7 @@
/// Testing library for flutter, built on top of package:test.
/// Testing library for flutter, built on top of package:test.
library
flutter_test
;
library
flutter_test
;
export
'src/instrumentation.dart'
;
export
'src/service_mocker.dart'
;
export
'src/service_mocker.dart'
;
export
'src/test_pointer.dart'
;
export
'src/test_pointer.dart'
;
export
'src/widget_tester.dart'
;
export
'src/widget_tester.dart'
;
packages/flutter_test/lib/src/instrumentation.dart
View file @
a499dc1d
...
@@ -161,6 +161,14 @@ class Instrumentation {
...
@@ -161,6 +161,14 @@ class Instrumentation {
_dispatchEvent
(
p
.
up
(),
result
);
_dispatchEvent
(
p
.
up
(),
result
);
}
}
TestGesture
startGesture
(
Point
downLocation
,
{
int
pointer:
1
})
{
TestPointer
p
=
new
TestPointer
(
pointer
);
HitTestResult
result
=
_hitTest
(
downLocation
);
_dispatchEvent
(
p
.
down
(
downLocation
),
result
);
return
new
TestGesture
.
_
(
this
,
result
,
p
);
}
@Deprecated
(
'soon. Use startGesture instead.'
)
void
dispatchEvent
(
PointerEvent
event
,
Point
location
)
{
void
dispatchEvent
(
PointerEvent
event
,
Point
location
)
{
_dispatchEvent
(
event
,
_hitTest
(
location
));
_dispatchEvent
(
event
,
_hitTest
(
location
));
}
}
...
@@ -175,3 +183,34 @@ class Instrumentation {
...
@@ -175,3 +183,34 @@ class Instrumentation {
binding
.
dispatchEvent
(
event
,
result
);
binding
.
dispatchEvent
(
event
,
result
);
}
}
}
}
class
TestGesture
{
TestGesture
.
_
(
this
.
_target
,
this
.
_result
,
this
.
pointer
);
final
Instrumentation
_target
;
final
HitTestResult
_result
;
final
TestPointer
pointer
;
bool
_isDown
=
true
;
void
moveTo
(
Point
location
)
{
assert
(
_isDown
);
_target
.
_dispatchEvent
(
pointer
.
move
(
location
),
_result
);
}
void
moveBy
(
Offset
offset
)
{
assert
(
_isDown
);
moveTo
(
pointer
.
location
+
offset
);
}
void
up
()
{
assert
(
_isDown
);
_isDown
=
false
;
_target
.
_dispatchEvent
(
pointer
.
up
(),
_result
);
}
void
cancel
()
{
assert
(
_isDown
);
_isDown
=
false
;
_target
.
_dispatchEvent
(
pointer
.
cancel
(),
_result
);
}
}
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