1# Copyright 2024 The Chromium Authors 2# Use of this source code is governed by a BSD-style license that can be 3# found in the LICENSE file. 4 5from __future__ import annotations 6 7from typing import Type 8from unittest import mock 9 10from tests.crossbench import mock_browser 11from tests.crossbench.base import BaseCrossbenchTestCase 12 13from crossbench import path as pth 14from crossbench.cli.config.browser_variants import BrowserVariantsConfig 15 16XCTRACE_DEVICES_OUTPUT = """ 17== Devices == 18a-macbookpro3 (00001234-AAAA-BBBB-0000-11AA22BB33DD) 19An iPhone (17.1.2) (00001111-11AA22BB33DD) 20An iPhone Pro (17.1.1) (00002222-11AA22BB33DD) 21 22== Devices Offline == 23An iPhone Pro Max (17.1.0) (00003333-11AA22BB33DD) 24 25== Simulators == 26iPad (10th generation) (17.0.1) (00001234-AAAA-BBBB-1111-11AA22BB33DD) 27iPad (9th generation) Simulator (15.5) (00001234-AAAA-BBBB-2222-11AA22BB33DD 28""" 29XCTRACE_DEVICES_SINGLE_OUTPUT = """ 30== Devices == 31a-macbookpro3 (00001234-AAAA-BBBB-0000-11AA22BB33DD) 32An iPhone (17.1.2) (00001111-11AA22BB33DD) 33 34== Devices Offline == 35An iPhone Pro (17.1.1) (00002222-11AA22BB33DD) 36 37== Simulators == 38iPad (10th generation) (17.0.1) (00001234-AAAA-BBBB-1111-11AA22BB33DD) 39iPad (9th generation) Simulator (15.5) (00001234-AAAA-BBBB-2222-11AA22BB33DD 40""" 41 42ADB_DEVICES_SINGLE_OUTPUT = ( 43 "List of devices attached\n" 44 "emulator-5556 device product:sdk_google_phone_x86_64 " 45 "model:Android_SDK_built_for_x86_64 device:generic_x86_64\n") 46 47ADB_DEVICES_OUTPUT = ( 48 f"{ADB_DEVICES_SINGLE_OUTPUT}" 49 "emulator-5554 device product:sdk_google_phone_x86 " 50 "model:Android_SDK_built_for_x86 device:generic_x86\n" 51 "0a388e93 device usb:1-1 product:razor model:Nexus_7 device:flo\n") 52 53 54class BaseConfigTestCase(BaseCrossbenchTestCase): 55 56 def setUp(self) -> None: 57 super().setUp() 58 adb_patcher = mock.patch( 59 "crossbench.plt.android_adb._find_adb_bin", 60 return_value=pth.LocalPath("adb")) 61 adb_patcher.start() 62 self.addCleanup(adb_patcher.stop) 63 64 def mock_chrome_stable(self, browser_cls: Type[mock_browser.MockBrowser]): 65 return mock.patch.object( 66 BrowserVariantsConfig, "get_browser_cls", return_value=browser_cls) 67