1"""Tests for Connection switching feature of Triangle.""" 2 3import logging 4import time 5 6from mobly import test_runner 7from blueberry.utils import triangle_base_test as base_test 8from blueberry.utils import triangle_constants 9 10 11class ConnectionSwitchingTest(base_test.TriangleBaseTest): 12 """Connection Switching Test.""" 13 14 def setup_class(self): 15 """Executes Connection switching setups. 16 17 Pairs Phone to headset and Watch, then pairs and connect Watch to Headset, 18 let Watch be last connected device of Headset. 19 """ 20 super().setup_class() 21 self.headset.power_on() 22 self.pair_and_connect_phone_to_headset() 23 self.pair_and_connect_phone_to_watch() 24 self.pair_and_connect_watch_to_headset() 25 26 def setup_test(self): 27 """Makes sure that Headset is connected to Watch instead of Phone.""" 28 super().setup_test() 29 self.phone.disconnect_bluetooth(self.headset.mac_address) 30 self.watch.connect_bluetooth(self.headset.mac_address) 31 self.assert_headset_a2dp_connection(connected=False, device=self.phone) 32 self.assert_headset_hsp_connection(connected=False, device=self.phone) 33 34 def test_trigger_connection_switching_when_headset_powered_on(self): 35 """Test for triggering connection switching when Headset is powered on. 36 37 Steps: 38 1. Power off Headset. 39 2. Wait 1 minute. 40 3. Power on Headset, and then it will be reconnect. 41 42 Verifications: 43 The Headset connection is switched from Watch to Phone. 44 """ 45 logging.info('Power off Headset and wait 1 minute.') 46 self.headset.power_off() 47 time.sleep(triangle_constants.WAITING_TIME_SEC) 48 logging.info('Power on Headset.') 49 self.headset.power_on() 50 self.assert_headset_a2dp_connection(connected=True, device=self.phone) 51 self.assert_headset_hsp_connection(connected=True, device=self.phone) 52 53 def test_trigger_connection_switching_when_phone_tethered_watch(self): 54 """Test for triggering connection switching when Phone is tethered to Watch. 55 56 Steps: 57 1. Disable Bluetooth on Phone. 58 2. Wait 1 minute. 59 3. Enable Bluetooth on Phone, and then Phone will be tethered to Watch. 60 61 Verifications: 62 The Headset connection is switched from Watch to Phone. 63 """ 64 self.phone.log.info('Disable Bluetooth and wait 1 minute.') 65 self.phone.mbs.btDisable() 66 time.sleep(triangle_constants.WAITING_TIME_SEC) 67 self.phone.log.info('Enable Bluetooth.') 68 self.phone.mbs.btEnable() 69 self.assert_headset_a2dp_connection(connected=True, device=self.phone) 70 self.assert_headset_hsp_connection(connected=True, device=self.phone) 71 72 73if __name__ == '__main__': 74 test_runner.main() 75