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() |