661
661
self.assertFalse(touch.pressed)
664
class UInputTouchTestCase(TestCase):
664
class UInputTouchBaseTestCase(TestCase):
667
super(UInputTouchBaseTestCase, self).setUp()
668
# Mock the sleeps so we don't have to spend time actually sleeping.
669
self.addCleanup(utilities.sleep.disable_mock)
670
utilities.sleep.enable_mock()
672
def get_touch_with_mocked_backend(self):
673
touch = _uinput.Touch(device_class=Mock)
674
touch._device.mock_add_spec(_uinput._UInputTouchDevice)
678
class UInputTouchFingerCoordinatesTestCase(
679
testscenarios.TestWithScenarios, UInputTouchBaseTestCase):
681
TEST_X_DESTINATION = 10
682
TEST_Y_DESTINATION = 10
687
'args': (TEST_X_DESTINATION, TEST_Y_DESTINATION)
691
'args': (TEST_X_DESTINATION, TEST_Y_DESTINATION)
695
'args': (TEST_X_DESTINATION, TEST_Y_DESTINATION)
699
'args': (0, 0, TEST_X_DESTINATION, TEST_Y_DESTINATION)
703
def call_scenario_method(self, object_, method, *args):
704
getattr(object_, method)(*self.args)
706
def test_method_must_update_finger_coordinates(self):
707
touch = self.get_touch_with_mocked_backend()
709
self.call_scenario_method(touch, self.method, *self.args)
711
self.assertEqual(touch.x, self.TEST_X_DESTINATION)
712
self.assertEqual(touch.y, self.TEST_Y_DESTINATION)
715
class UInputTouchTestCase(UInputTouchBaseTestCase):
665
716
"""Test UInput Touch helper for autopilot tests."""
668
super(UInputTouchTestCase, self).setUp()
669
# Mock the sleeps so we don't have to spend time actually sleeping.
670
self.addCleanup(utilities.sleep.disable_mock)
671
utilities.sleep.enable_mock()
718
def test_initial_coordinates_must_be_zero(self):
719
touch = self.get_touch_with_mocked_backend()
673
def get_touch_with_mocked_backend(self):
674
touch = _uinput.Touch(device_class=Mock)
675
touch._device.mock_add_spec(_uinput._UInputTouchDevice)
721
self.assertEqual(touch.x, 0)
722
self.assertEqual(touch.y, 0)
678
724
def test_tap_must_put_finger_down_then_sleep_and_then_put_finger_up(self):
679
725
expected_calls = [
720
766
touch.move(10, 10)
721
767
self.assertEqual(expected_calls, touch._device.mock_calls)
723
def test_drag_must_call_finger_down_move_and_up(self):
725
call.finger_down(0, 0),
726
call.finger_move(10, 10),
730
touch = self.get_touch_with_mocked_backend()
731
touch.drag(0, 0, 10, 10)
732
self.assertEqual(expected_calls, touch._device.mock_calls)
734
def test_drag_must_move_with_specified_rate(self):
736
call.finger_down(0, 0),
769
def test_move_must_move_with_specified_rate(self):
737
771
call.finger_move(5, 5),
738
772
call.finger_move(10, 10),
739
773
call.finger_move(15, 15),
742
776
touch = self.get_touch_with_mocked_backend()
743
touch.drag(0, 0, 15, 15, rate=5)
777
touch.move(15, 15, rate=5)
745
779
self.assertEqual(
746
780
expected_calls, touch._device.mock_calls)
748
def test_drag_without_rate_must_use_default(self):
782
def test_move_without_rate_must_use_default(self):
749
783
expected_calls = [
750
call.finger_down(0, 0),
751
784
call.finger_move(10, 10),
752
785
call.finger_move(20, 20),
755
788
touch = self.get_touch_with_mocked_backend()
756
touch.drag(0, 0, 20, 20)
758
791
self.assertEqual(
759
792
expected_calls, touch._device.mock_calls)
761
def test_drag_to_same_place_must_not_move(self):
794
def test_move_to_same_place_must_not_move(self):
797
touch = self.get_touch_with_mocked_backend()
799
self.assertEqual(expected_calls, touch._device.mock_calls)
801
def test_drag_must_call_finger_down_move_and_up(self):
762
802
expected_calls = [
763
803
call.finger_down(0, 0),
804
call.finger_move(10, 10),
767
808
touch = self.get_touch_with_mocked_backend()
768
touch.drag(0, 0, 0, 0)
809
touch.drag(0, 0, 10, 10)
769
810
self.assertEqual(expected_calls, touch._device.mock_calls)
771
812
def test_tap_without_press_duration_must_sleep_default_time(self):
848
889
self.assertFalse(finger2.pressed)
851
class DragUInputTouchTestCase(testscenarios.TestWithScenarios, TestCase):
892
class MoveWithAnimationUInputTouchTestCase(
893
testscenarios.TestWithScenarios, TestCase):
854
('drag to top', dict(
896
('move to top', dict(
855
897
start_x=50, start_y=50, stop_x=50, stop_y=30,
856
898
expected_moves=[call.finger_move(50, 40),
857
899
call.finger_move(50, 30)])),
858
('drag to bottom', dict(
900
('move to bottom', dict(
859
901
start_x=50, start_y=50, stop_x=50, stop_y=70,
860
902
expected_moves=[call.finger_move(50, 60),
861
903
call.finger_move(50, 70)])),
862
('drag to left', dict(
904
('move to left', dict(
863
905
start_x=50, start_y=50, stop_x=30, stop_y=50,
864
906
expected_moves=[call.finger_move(40, 50),
865
907
call.finger_move(30, 50)])),
866
('drag to right', dict(
908
('move to right', dict(
867
909
start_x=50, start_y=50, stop_x=70, stop_y=50,
868
910
expected_moves=[call.finger_move(60, 50),
869
911
call.finger_move(70, 50)])),
871
('drag to top-left', dict(
913
('move to top-left', dict(
872
914
start_x=50, start_y=50, stop_x=30, stop_y=30,
873
915
expected_moves=[call.finger_move(40, 40),
874
916
call.finger_move(30, 30)])),
875
('drag to top-right', dict(
917
('move to top-right', dict(
876
918
start_x=50, start_y=50, stop_x=70, stop_y=30,
877
919
expected_moves=[call.finger_move(60, 40),
878
920
call.finger_move(70, 30)])),
879
('drag to bottom-left', dict(
921
('move to bottom-left', dict(
880
922
start_x=50, start_y=50, stop_x=30, stop_y=70,
881
923
expected_moves=[call.finger_move(40, 60),
882
924
call.finger_move(30, 70)])),
883
('drag to bottom-right', dict(
925
('move to bottom-right', dict(
884
926
start_x=50, start_y=50, stop_x=70, stop_y=70,
885
927
expected_moves=[call.finger_move(60, 60),
886
928
call.finger_move(70, 70)])),
888
('drag less than rate', dict(
930
('move less than rate', dict(
889
931
start_x=50, start_y=50, stop_x=55, stop_y=55,
890
932
expected_moves=[call.finger_move(55, 55)])),
892
('drag with last move less than rate', dict(
934
('move with last move less than rate', dict(
893
935
start_x=50, start_y=50, stop_x=65, stop_y=65,
894
936
expected_moves=[call.finger_move(60, 60),
895
937
call.finger_move(65, 65)])),
899
super(DragUInputTouchTestCase, self).setUp()
941
super(MoveWithAnimationUInputTouchTestCase, self).setUp()
900
942
# Mock the sleeps so we don't have to spend time actually sleeping.
901
943
self.addCleanup(utilities.sleep.disable_mock)
902
944
utilities.sleep.enable_mock()
929
971
pointer = autopilot.input.Pointer(touch)
974
def test_initial_coordinates_must_be_zero(self):
975
pointer = self.get_pointer_with_touch_backend_with_mock_device()
977
self.assertEqual(pointer.x, 0)
978
self.assertEqual(pointer.y, 0)
980
def test_drag_must_call_move_with_animation(self):
982
test_time_between_events = 1
983
test_destination_x = 20
984
test_destination_y = 20
986
pointer = self.get_pointer_with_touch_backend_with_mock_device()
987
with patch.object(pointer._device, 'move') as mock_move:
990
test_destination_x, test_destination_y,
991
rate=test_rate, time_between_events=test_time_between_events)
993
mock_move.assert_called_once_with(
994
test_destination_x, test_destination_y,
996
rate=test_rate, time_between_events=test_time_between_events)
932
998
def test_drag_with_rate(self):
933
999
pointer = self.get_pointer_with_touch_backend_with_mock_device()
934
1000
with patch.object(pointer._device, 'drag') as mock_drag:
969
1035
mock_tap.assert_called_once_with(
970
1036
0, 0, press_duration=10, time_between_events=0.1)
1038
def test_not_pressed_move_must_not_move_pointing_figer(self):
1039
"""Test for moving the finger when it is not pressed.
1041
The move method on the pointer class must update the finger coordinates
1042
but it must not execute a move on the device.
1045
test_x_destination = 20
1046
test_y_destination = 20
1047
pointer = self.get_pointer_with_touch_backend_with_mock_device()
1049
pointer.move(10, 10)
1050
pointer._device._device.pressed = False
1052
with patch.object(pointer._device._device, 'finger_move') as mock_move:
1053
pointer.move(test_x_destination, test_y_destination)
1055
self.assertFalse(mock_move.called)
1056
self.assertEqual(pointer.x, test_x_destination)
1057
self.assertEqual(pointer.y, test_y_destination)
1059
def test_pressed_move_must_move_pointing_finger(self):
1060
test_x_destination = 20
1061
test_y_destination = 20
1063
pointer = self.get_pointer_with_touch_backend_with_mock_device()
1065
pointer.move(10, 10)
1066
pointer._device._device.pressed = True
1068
with patch.object(pointer._device._device, 'finger_move') as mock_move:
1069
pointer.move(test_x_destination, test_y_destination)
1071
mock_move.assert_called_once_with(20, 20)
1072
self.assertEqual(pointer.x, test_x_destination)
1073
self.assertEqual(pointer.y, test_y_destination)