Revert of Revert of Revert of ChromeOS NetworkScreenHandler should not call CheckAndR...
[chromium-blink-merge.git] / tools / usb_gadget / mouse_gadget_test.py
blob5216798e9777ba6ea2cb18ac3dc99c1758ba074a
1 #!/usr/bin/python
2 # Copyright 2014 The Chromium Authors. All rights reserved.
3 # Use of this source code is governed by a BSD-style license that can be
4 # found in the LICENSE file.
6 import unittest
8 import mock
10 import hid_constants
11 import mouse_gadget
12 import usb_constants
15 class MouseGadgetTest(unittest.TestCase):
17 def test_click(self):
18 g = mouse_gadget.MouseGadget()
19 chip = mock.Mock()
20 g.Connected(chip, usb_constants.Speed.FULL)
21 g.ButtonDown(hid_constants.Mouse.BUTTON_1)
22 self.assertEqual(g.ControlRead(0xA1, 1, 0x0100, 0, 8), '\x01\x00\x00')
23 g.ButtonUp(hid_constants.Mouse.BUTTON_1)
24 chip.SendPacket.assert_has_calls([
25 mock.call(0x81, '\x01\x00\x00'),
26 mock.call(0x81, '\x00\x00\x00'),
29 def test_move(self):
30 g = mouse_gadget.MouseGadget()
31 chip = mock.Mock()
32 g.Connected(chip, usb_constants.Speed.FULL)
33 g.Move(-1, 1)
34 chip.SendPacket.assert_called(0x81, '\x00\xFF\x01')
36 def test_drag(self):
37 g = mouse_gadget.MouseGadget()
38 chip = mock.Mock()
39 g.Connected(chip, usb_constants.Speed.FULL)
40 g.ButtonDown(hid_constants.Mouse.BUTTON_1)
41 g.Move(5, 5)
42 g.ButtonUp(hid_constants.Mouse.BUTTON_1)
43 chip.SendPacket.assert_has_calls([
44 mock.call(0x81, '\x01\x00\x00'),
45 mock.call(0x81, '\x01\x05\x05'),
46 mock.call(0x81, '\x00\x00\x00'),
49 if __name__ == '__main__':
50 unittest.main()