• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1# Copyright 2019 The Chromium OS Authors. All rights reserved.
2# Use of this source code is governed by a BSD-style license that can be
3# found in the LICENSE file.
4
5"""Server side bluetooth tests about sending bluetooth HID reports."""
6
7import logging
8import time
9
10from autotest_lib.server.cros.bluetooth import bluetooth_adapter_tests
11
12
13class BluetoothAdapterHIDReportTests(
14        bluetooth_adapter_tests.BluetoothAdapterTests):
15    """Server side bluetooth tests about sending bluetooth HID reports.
16
17    This test tries to send HID reports to a DUT and verifies if the DUT
18    could receive the reports correctly. For the time being, only bluetooth
19    mouse events are tested. Bluetooth keyboard events will be supported
20    later.
21    """
22
23    HID_TEST_SLEEP_SECS = 5
24
25    def run_mouse_tests(self, device):
26        """Run all bluetooth mouse reports tests.
27
28        @param device: the bluetooth HID device.
29
30        """
31        self.test_mouse_left_click(device)
32        self.test_mouse_right_click(device)
33        self.test_mouse_move_in_x(device, 80)
34        self.test_mouse_move_in_y(device, -50)
35        self.test_mouse_move_in_xy(device, -60, 100)
36        self.test_mouse_scroll_down(device, 70)
37        self.test_mouse_scroll_up(device, 40)
38        self.test_mouse_click_and_drag(device, 90, 30)
39
40
41    def run_keyboard_tests(self, device):
42        """Run all bluetooth mouse reports tests.
43
44        @param device: the bluetooth HID device.
45
46        """
47
48        self.test_keyboard_input_from_trace(device, "simple_text")
49
50
51    def run_hid_reports_test(self, device, suspend_resume=False, reboot=False):
52        """Running Bluetooth HID reports tests."""
53        logging.info("run hid reports test")
54        # Reset the adapter and set it pairable.
55        self.test_reset_on_adapter()
56        self.test_pairable()
57
58        # Let the adapter pair, and connect to the target device.
59        time.sleep(self.HID_TEST_SLEEP_SECS)
60        self.test_discover_device(device.address)
61        time.sleep(self.HID_TEST_SLEEP_SECS)
62        self.test_pairing(device.address, device.pin, trusted=True)
63        time.sleep(self.HID_TEST_SLEEP_SECS)
64        self.test_connection_by_adapter(device.address)
65
66        if suspend_resume:
67            self.suspend_resume()
68
69            time.sleep(self.HID_TEST_SLEEP_SECS)
70            self.test_device_is_paired(device.address)
71
72            # After a suspend/resume, we should check if the device is
73            # connected.
74            # NOTE: After a suspend/resume, the RN42 kit remains connected.
75            #       However, this is not expected behavior for all bluetooth
76            #       peripherals.
77            time.sleep(self.HID_TEST_SLEEP_SECS)
78            self.test_device_is_connected(device.address)
79
80            time.sleep(self.HID_TEST_SLEEP_SECS)
81            self.test_device_name(device.address, device.name)
82
83        if reboot:
84            self.reboot()
85
86            time.sleep(self.HID_TEST_SLEEP_SECS)
87            self.test_device_is_paired(device.address)
88
89            time.sleep(self.HID_TEST_SLEEP_SECS)
90            self.test_connection_by_device(device)
91
92            time.sleep(self.HID_TEST_SLEEP_SECS)
93            self.test_device_name(device.address, device.name)
94
95        # Run tests about mouse reports.
96        if device.device_type.endswith('MOUSE'):
97            self.run_mouse_tests(device)
98
99        if device.device_type.endswith('KEYBOARD'):
100            self.run_keyboard_tests(device)
101
102        # Disconnect the device, and remove the pairing.
103        self.test_disconnection_by_adapter(device.address)
104        self.test_remove_pairing(device.address)
105