Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(338)

Side by Side Diff: tools/usb_gadget/mouse_gadget_test.py

Issue 418603003: [usb_gadget p05] Add a HID mouse gadget. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fix a copy-paste error. Created 6 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « tools/usb_gadget/mouse_gadget.py ('k') | tools/usb_gadget/usb_constants.py » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
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.
5
6 import unittest
7
8 import mock
9
10 import hid_constants
11 import mouse_gadget
12 import usb_constants
13
14
15 class MouseGadgetTest(unittest.TestCase):
16
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'),
27 ])
28
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')
35
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'),
47 ])
48
49 if __name__ == '__main__':
50 unittest.main()
OLDNEW
« no previous file with comments | « tools/usb_gadget/mouse_gadget.py ('k') | tools/usb_gadget/usb_constants.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698