• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1# Copyright (c) 2013 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
5import logging, time
6
7from autotest_lib.client.cros.bluetooth import bluetooth_semiauto_helper
8
9
10class bluetooth_RegressionClient(
11        bluetooth_semiauto_helper.BluetoothSemiAutoHelper):
12    """Implement Bluetooth Regression Tests with some interaction."""
13    version = 1
14
15    def _test_init(self, test_type):
16        """Init test by collecting intial logs, starting dump, etc.
17
18        @param: test_type: short string label for log files and messages
19        """
20        self._test_type = test_type
21        logging.info('Beginning test of type %s.', test_type)
22        self.start_dump()
23        self.collect_logs(message=('Before %s.' % test_type))
24
25    def _power_off(self):
26        self._test_init('power_off')
27
28    def _os_idle(self):
29        self._test_init('os_idle')
30        self.ask_user('OS Idle test: after pressing PASS, the OS will idle '
31                      'after a short delay.  Do not prevent it from idling.'
32                      '<br>After OS has idled for at least 10 seconds, use '
33                      'a Bluetooth device to wake machine (or use onboard '
34                      'inputs if no Bluetooth device is capable).<br>'
35                      'Make sure audio continues to play over Bluetooth.')
36        self.os_idle_time_set()
37        self.tell_user('Going to sleep now...')
38        time.sleep(20)
39        self.check_working()
40        self.os_idle_time_set(reset=True)
41        self.collect_logs(message='After idle.')
42
43    def _suspend(self):
44        self._test_init('suspend')
45        self.ask_user('OS Suspend test: after pressing PASS, the OS will '
46                      'suspend.<br>It will wake on its own after some time.'
47                      '<br>Audio will stop playing.')
48        self.os_suspend()
49        self.check_working()
50        self.collect_logs(message='After suspend.')
51
52    def _log_off(self):
53        self._test_init('log_off')
54        self.close_browser()
55        self.login_and_open_browser()
56        self.check_working()
57        self.collect_logs(message='After login.')
58
59    def _disconnect(self):
60        self._test_init('disconnect')
61        self.tell_user('Please disconnect all Bluetooth devices using (x).')
62        self.wait_for_adapter(adapter_status=True)
63        self.wait_for_connections(paired_status=True, connected_status=False)
64        self.ask_user('Audio NOT playing through onboard speakers?<br>'
65                      'Audio NOT playing through Bluetooth device?')
66        self.collect_logs(message='After disconnect.')
67        self.check_working()
68        self.collect_logs(message='After reconnect.')
69
70    def _device_off(self):
71        self._test_init('device_off')
72        self.tell_user('Please turn off all Bluetooth devices.<br>'
73                       'Disconnect them on the Settings page if needed.')
74        self.wait_for_adapter(adapter_status=True)
75        self.wait_for_connections(paired_status=True, connected_status=False)
76        self.ask_user('Audio NOT playing through onboard speakers?')
77        self.collect_logs(message='After device turned off.')
78        self.check_working(message='Please turn devices back on and connect.')
79        self.collect_logs(message='After device on.')
80
81    def _unpair(self):
82        self._test_init('unpair')
83        self.tell_user('Please unpair all Bluetooth devices (using (x))')
84        self.wait_for_adapter(adapter_status=True)
85        self.wait_for_connections(paired_status=False, connected_status=False)
86        self.ask_user('No Bluetooth devices work.<br> Audio is NOT playing '
87                      'through onboard speakers or wired headphones.')
88        self.collect_logs(message='After unpair.')
89        self.check_working(message='Please re-pair and connect devices.')
90        self.collect_logs(message='After re-pair.')
91
92    def _disable(self):
93        self._test_init('disable')
94        self.tell_user('Please disable Bluetooth (uncheck Enable Bluetooth).')
95        self.wait_for_adapter(adapter_status=False)
96        self.collect_logs(message='While disabled')
97        self.wait_for_connections(paired_status=True, connected_status=False)
98        self.ask_user('No Bluetooth devices work?<br> Audio is NOT playing '
99                      'through onboard speakers or wired headphones?')
100        self.tell_user('Please enable Bluetooth (check Enable Bluetooth).<br>'
101                       'Make sure all devices are still listed after enable.')
102        self.wait_for_adapter(adapter_status=True)
103        self.check_working()
104        self.collect_logs(message='After re-enable.')
105
106    def run_once(self):
107        """Runs Regression tests for Bluetooth.
108
109        Two phases: before and after reboot by server. Called by run_test.
110        """
111        self.check_working()
112
113        if self._test_phase == 'reboot':
114            self._disable()
115            self._power_off()
116        elif self._test_phase == 'client':
117            self._power_off()
118            self._os_idle()
119            self._suspend()
120            self._log_off()
121            self._disconnect()
122            self._device_off()
123            self._unpair()
124
125