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 7from __future__ import absolute_import 8 9import logging 10import time 11 12import common 13from autotest_lib.server.cros.bluetooth import bluetooth_adapter_tests 14 15 16class BluetoothAdapterHIDReportTests( 17 bluetooth_adapter_tests.BluetoothAdapterTests): 18 """Server side bluetooth tests about sending bluetooth HID reports. 19 20 This test tries to send HID reports to a DUT and verifies if the DUT 21 could receive the reports correctly. For the time being, only bluetooth 22 mouse events are tested. Bluetooth keyboard events will be supported 23 later. 24 """ 25 26 HID_TEST_SLEEP_SECS = 5 27 28 def run_mouse_tests(self, device): 29 """Run all bluetooth mouse reports tests. 30 31 @param device: the bluetooth HID device. 32 33 """ 34 self.test_mouse_left_click(device) 35 self.test_mouse_right_click(device) 36 self.test_mouse_move_in_x(device, 80) 37 self.test_mouse_move_in_y(device, -50) 38 self.test_mouse_move_in_xy(device, -60, 100) 39 self.test_mouse_scroll_down(device, 70) 40 self.test_mouse_scroll_up(device, 40) 41 self.test_mouse_click_and_drag(device, 90, 30) 42 43 44 def run_keyboard_tests(self, device): 45 """Run all bluetooth mouse reports tests. 46 47 @param device: the bluetooth HID device. 48 49 """ 50 51 self.test_keyboard_input_from_trace(device, "simple_text") 52 53 54 def run_battery_reporting_tests(self, device): 55 """Run battery reporting tests. 56 57 @param device: the Bluetooth device. 58 59 """ 60 61 self.test_battery_reporting(device) 62 63 def run_hid_reports_test(self, device, 64 check_connected_method=lambda device: True, 65 suspend_resume=False, reboot=False): 66 """Running Bluetooth HID reports tests.""" 67 logging.info("run hid reports test") 68 # Reset the adapter and set it pairable. 69 self.test_reset_on_adapter() 70 self.test_pairable() 71 72 # Let the adapter pair, and connect to the target device. 73 self.test_discover_device(device.address) 74 self.test_pairing(device.address, device.pin, trusted=True) 75 self.test_connection_by_adapter(device.address) 76 77 # Run hid test to make sure profile is connected 78 check_connected_method(device) 79 80 if suspend_resume: 81 self.suspend_resume() 82 83 time.sleep(self.HID_TEST_SLEEP_SECS) 84 self.test_device_is_paired(device.address) 85 86 87 # check if peripheral is connected after suspend resume, reconnect 88 # if it isn't 89 if not self.ignore_failure(check_connected_method, device): 90 logging.info("device not connected after suspend_resume") 91 self.test_connection_by_device(device) 92 else: 93 logging.info("device remains connected after suspend_resume") 94 95 time.sleep(self.HID_TEST_SLEEP_SECS) 96 check_connected_method(device) 97 98 time.sleep(self.HID_TEST_SLEEP_SECS) 99 self.test_device_name(device.address, device.name) 100 101 if reboot: 102 self.reboot() 103 104 time.sleep(self.HID_TEST_SLEEP_SECS) 105 # TODO(b/173146480) - Power on the adapter for now until this bug 106 # is resolved. 107 self.test_power_on_adapter() 108 109 self.test_device_is_paired(device.address) 110 111 time.sleep(self.HID_TEST_SLEEP_SECS) 112 self.test_connection_by_device(device) 113 114 time.sleep(self.HID_TEST_SLEEP_SECS) 115 self.test_device_name(device.address, device.name) 116 117 # Run HID test after suspend/reboot as well. 118 if suspend_resume or reboot: 119 check_connected_method(device) 120 121 # Disconnect the device, and remove the pairing. 122 self.test_disconnection_by_adapter(device.address) 123 self.test_remove_pairing(device.address) 124