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

Unified 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 side-by-side diff with in-line comments
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 »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: tools/usb_gadget/mouse_gadget_test.py
diff --git a/tools/usb_gadget/mouse_gadget_test.py b/tools/usb_gadget/mouse_gadget_test.py
new file mode 100755
index 0000000000000000000000000000000000000000..5216798e9777ba6ea2cb18ac3dc99c1758ba074a
--- /dev/null
+++ b/tools/usb_gadget/mouse_gadget_test.py
@@ -0,0 +1,50 @@
+#!/usr/bin/python
+# Copyright 2014 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 unittest
+
+import mock
+
+import hid_constants
+import mouse_gadget
+import usb_constants
+
+
+class MouseGadgetTest(unittest.TestCase):
+
+ def test_click(self):
+ g = mouse_gadget.MouseGadget()
+ chip = mock.Mock()
+ g.Connected(chip, usb_constants.Speed.FULL)
+ g.ButtonDown(hid_constants.Mouse.BUTTON_1)
+ self.assertEqual(g.ControlRead(0xA1, 1, 0x0100, 0, 8), '\x01\x00\x00')
+ g.ButtonUp(hid_constants.Mouse.BUTTON_1)
+ chip.SendPacket.assert_has_calls([
+ mock.call(0x81, '\x01\x00\x00'),
+ mock.call(0x81, '\x00\x00\x00'),
+ ])
+
+ def test_move(self):
+ g = mouse_gadget.MouseGadget()
+ chip = mock.Mock()
+ g.Connected(chip, usb_constants.Speed.FULL)
+ g.Move(-1, 1)
+ chip.SendPacket.assert_called(0x81, '\x00\xFF\x01')
+
+ def test_drag(self):
+ g = mouse_gadget.MouseGadget()
+ chip = mock.Mock()
+ g.Connected(chip, usb_constants.Speed.FULL)
+ g.ButtonDown(hid_constants.Mouse.BUTTON_1)
+ g.Move(5, 5)
+ g.ButtonUp(hid_constants.Mouse.BUTTON_1)
+ chip.SendPacket.assert_has_calls([
+ mock.call(0x81, '\x01\x00\x00'),
+ mock.call(0x81, '\x01\x05\x05'),
+ mock.call(0x81, '\x00\x00\x00'),
+ ])
+
+if __name__ == '__main__':
+ unittest.main()
« 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