• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1#  Copyright (C) 2022 The Android Open Source Project
2#
3#  Licensed under the Apache License, Version 2.0 (the "License");
4#  you may not use this file except in compliance with the License.
5#  You may obtain a copy of the License at
6#
7#       http://www.apache.org/licenses/LICENSE-2.0
8#
9#  Unless required by applicable law or agreed to in writing, software
10#  distributed under the License is distributed on an "AS IS" BASIS,
11#  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12#  See the License for the specific language governing permissions and
13#  limitations under the License.
14
15"""CTS-V Nearby Mainline Fast Pair end-to-end test case: initial pairing test."""
16
17from test_helper import constants
18from test_helper import fast_pair_base_test
19
20# The model ID to simulate on provider side.
21PROVIDER_SIMULATOR_MODEL_ID = constants.DEFAULT_MODEL_ID
22# The public key to simulate as registered headsets.
23PROVIDER_SIMULATOR_ANTI_SPOOFING_KEY = constants.DEFAULT_ANTI_SPOOFING_KEY
24# The anti-spoof key device metadata JSON file for data provider at seeker side.
25PROVIDER_SIMULATOR_KDM_JSON_FILE = constants.DEFAULT_KDM_JSON_FILE
26
27# Time in seconds for events waiting.
28SETUP_TIMEOUT_SEC = constants.SETUP_TIMEOUT_SEC
29BECOME_DISCOVERABLE_TIMEOUT_SEC = constants.BECOME_DISCOVERABLE_TIMEOUT_SEC
30START_ADVERTISING_TIMEOUT_SEC = constants.START_ADVERTISING_TIMEOUT_SEC
31HALF_SHEET_POPUP_TIMEOUT_SEC = constants.HALF_SHEET_POPUP_TIMEOUT_SEC
32MANAGE_ACCOUNT_DEVICE_TIMEOUT_SEC = constants.AVERAGE_PAIRING_TIMEOUT_SEC * 2
33
34
35class InitialPairingTest(fast_pair_base_test.FastPairBaseTest):
36    """Fast Pair initial pairing test."""
37
38    def setup_test(self) -> None:
39        super().setup_test()
40        self._provider.start_model_id_advertising(PROVIDER_SIMULATOR_MODEL_ID,
41                                                  PROVIDER_SIMULATOR_ANTI_SPOOFING_KEY)
42        self._provider.wait_for_discoverable_mode(BECOME_DISCOVERABLE_TIMEOUT_SEC)
43        self._provider.wait_for_advertising_start(START_ADVERTISING_TIMEOUT_SEC)
44        self._seeker.put_anti_spoof_key_device_metadata(PROVIDER_SIMULATOR_MODEL_ID,
45                                                        PROVIDER_SIMULATOR_KDM_JSON_FILE)
46        self._seeker.set_fast_pair_scan_enabled(True)
47
48    # TODO(b/214015364): Remove Bluetooth bound on both sides ("Forget device").
49    def teardown_test(self) -> None:
50        self._seeker.set_fast_pair_scan_enabled(False)
51        self._provider.teardown_provider_simulator()
52        self._seeker.dismiss_halfsheet()
53        super().teardown_test()
54
55    def test_seeker_initial_pair_provider(self) -> None:
56        self._seeker.wait_and_assert_halfsheet_showed(
57            timeout_seconds=HALF_SHEET_POPUP_TIMEOUT_SEC,
58            expected_model_id=PROVIDER_SIMULATOR_MODEL_ID)
59        self._seeker.start_pairing()
60        self._seeker.wait_and_assert_account_device(
61            get_account_key_from_provider=self._provider.get_latest_received_account_key,
62            timeout_seconds=MANAGE_ACCOUNT_DEVICE_TIMEOUT_SEC)
63