1#!/usr/bin/env python3
2#
3# Copyright (C) 2019 The Android Open Source Project
4#
5# Licensed under the Apache License, Version 2.0 (the "License"); you may not
6# use this file except in compliance with the License. You may obtain a copy of
7# the License at
8#
9# http://www.apache.org/licenses/LICENSE-2.0
10#
11# Unless required by applicable law or agreed to in writing, software
12# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
13# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
14# License for the specific language governing permissions and limitations under
15# the License.
16"""Automated tests for testing passthrough commands in Avrcp/A2dp profile"""
17import time
18
19from acts.asserts import assert_equal
20from acts.test_utils.bt.AvrcpBaseTest import AvrcpBaseTest
21from acts.test_utils.car.car_media_utils import PlaybackState
22
23
24DEFAULT_TIMEOUT = 0.5
25
26class BtAvrcpPassthroughTest(AvrcpBaseTest):
27    def test_play_pause(self):
28        """
29        Test the Play/Pause passthrough commands.
30
31        Step:
32        1. Invoke Play/Pause from controller.
33        2. Wait to receive corresponding received event from target.
34        3. Check current playback state on target.
35
36        Expected Result:
37        Passthrough command received and music play then pause.
38
39        Returns:
40          Pass if True
41          Fail if False
42        """
43        self.play_from_controller()
44        time.sleep(DEFAULT_TIMEOUT)
45        state = (self.dut.droid
46                 .bluetoothMediaGetCurrentPlaybackState())['state']
47        assert_equal(state, PlaybackState.PLAY,
48                     'Current playback state is not Play, is {}'.format(state))
49
50        self.pause_from_controller()
51        time.sleep(DEFAULT_TIMEOUT)
52        state = (self.dut.droid
53                 .bluetoothMediaGetCurrentPlaybackState())['state']
54        assert_equal(state, PlaybackState.PAUSE,
55                     'Current playback state is not Pause, is {}'.format(state))
56
57    def test_skip_next(self):
58        """
59        Test the Skip Next passthrough command.
60
61        Step:
62        1. Invoke Skip Next from controller.
63        2. Wait to receive corresponding received event from target.
64
65        Expected Result:
66        Passthrough command received and music skip to next.
67
68        Returns:
69          Pass if True
70          Fail if False
71        """
72        self.skip_next_from_controller()
73
74    def test_skip_prev(self):
75        """
76        Test the Skip Previous passthrough command.
77
78        Step:
79        1. Invoke Skip Previous from controller.
80        2. Wait to receive corresponding received event from target.
81
82        Expected Result:
83        Passthrough command received and music skip to previous.
84
85        Returns:
86          Pass if True
87          Fail if False
88        """
89        self.skip_prev_from_controller()
90