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 6import unittest 7 8import mock 9 10import hid_constants 11import mouse_gadget 12import usb_constants 13 14 15class 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 49if __name__ == '__main__': 50 unittest.main() 51