peripheral_notification_manager_unittest.cc 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608
  1. // Copyright 2021 The Chromium 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. #include "ash/components/peripheral_notification/peripheral_notification_manager.h"
  5. #include <memory>
  6. #include "ash/constants/ash_features.h"
  7. #include "ash/test/ash_test_base.h"
  8. #include "base/files/file_util.h"
  9. #include "base/files/scoped_temp_dir.h"
  10. #include "base/test/metrics/histogram_tester.h"
  11. #include "base/test/scoped_feature_list.h"
  12. #include "chromeos/ash/components/dbus/pciguard/fake_pciguard_client.h"
  13. #include "chromeos/ash/components/dbus/pciguard/pciguard_client.h"
  14. #include "chromeos/ash/components/dbus/typecd/fake_typecd_client.h"
  15. #include "chromeos/ash/components/dbus/typecd/typecd_client.h"
  16. #include "services/device/public/cpp/test/fake_usb_device_info.h"
  17. #include "testing/gtest/include/gtest/gtest.h"
  18. #include "third_party/cros_system_api/dbus/typecd/dbus-constants.h"
  19. namespace {
  20. const int kUsbConfigWithInterfaces = 1;
  21. const int kBillboardDeviceClassCode = 17;
  22. const int kNonBillboardDeviceClassCode = 16;
  23. constexpr char thunderbolt_path_for_testing[] =
  24. "/tmp/tbt/sys/bus/thunderbolt/devices/0-0";
  25. constexpr char root_prefix_for_testing[] = "/tmp/tbt";
  26. } // namespace
  27. namespace ash {
  28. class FakeObserver : public PeripheralNotificationManager::Observer {
  29. public:
  30. FakeObserver() = default;
  31. ~FakeObserver() override = default;
  32. size_t num_limited_performance_notification_calls() const {
  33. return num_limited_performance_notification_calls_;
  34. }
  35. size_t num_guest_notification_calls() const {
  36. return num_guest_notification_calls_;
  37. }
  38. size_t num_peripheral_blocked_notification_calls() const {
  39. return num_peripheral_blocked_notification_calls_;
  40. }
  41. size_t num_billboard_notification_calls() const {
  42. return num_billboard_notification_calls_;
  43. }
  44. size_t num_invalid_dp_cable_notification_calls() const {
  45. return num_invalid_dp_cable_notification_calls_;
  46. }
  47. size_t num_invalid_usb4_valid_tbt_cable_notification_calls() const {
  48. return num_invalid_usb4_valid_tbt_cable_notification_calls_;
  49. }
  50. size_t num_invalid_usb4_cable_notification_calls() const {
  51. return num_invalid_usb4_cable_notification_calls_;
  52. }
  53. size_t num_invalid_tbt_cable_notification_calls() const {
  54. return num_invalid_tbt_cable_notification_calls_;
  55. }
  56. size_t num_speed_limiting_cable_notification_calls() const {
  57. return num_speed_limiting_cable_notification_calls_;
  58. }
  59. bool is_current_guest_device_tbt_only() const {
  60. return is_current_guest_device_tbt_only_;
  61. }
  62. // PeripheralNotificationManager::Observer:
  63. void OnLimitedPerformancePeripheralReceived() override {
  64. ++num_limited_performance_notification_calls_;
  65. }
  66. void OnGuestModeNotificationReceived(bool is_thunderbolt_only) override {
  67. is_current_guest_device_tbt_only_ = is_thunderbolt_only;
  68. ++num_guest_notification_calls_;
  69. }
  70. void OnPeripheralBlockedReceived() override {
  71. ++num_peripheral_blocked_notification_calls_;
  72. }
  73. void OnBillboardDeviceConnected() override {
  74. ++num_billboard_notification_calls_;
  75. }
  76. void OnInvalidDpCableWarning() override {
  77. ++num_invalid_dp_cable_notification_calls_;
  78. }
  79. void OnInvalidUSB4ValidTBTCableWarning() override {
  80. ++num_invalid_usb4_valid_tbt_cable_notification_calls_;
  81. }
  82. void OnInvalidUSB4CableWarning() override {
  83. ++num_invalid_usb4_cable_notification_calls_;
  84. }
  85. void OnInvalidTBTCableWarning() override {
  86. ++num_invalid_tbt_cable_notification_calls_;
  87. }
  88. void OnSpeedLimitingCableWarning() override {
  89. ++num_speed_limiting_cable_notification_calls_;
  90. }
  91. private:
  92. size_t num_limited_performance_notification_calls_ = 0u;
  93. size_t num_guest_notification_calls_ = 0u;
  94. size_t num_peripheral_blocked_notification_calls_ = 0u;
  95. size_t num_billboard_notification_calls_ = 0u;
  96. size_t num_invalid_dp_cable_notification_calls_ = 0u;
  97. size_t num_invalid_usb4_valid_tbt_cable_notification_calls_ = 0u;
  98. size_t num_invalid_usb4_cable_notification_calls_ = 0u;
  99. size_t num_invalid_tbt_cable_notification_calls_ = 0u;
  100. size_t num_speed_limiting_cable_notification_calls_ = 0u;
  101. bool is_current_guest_device_tbt_only_ = false;
  102. };
  103. class PeripheralNotificationManagerTest : public AshTestBase {
  104. protected:
  105. PeripheralNotificationManagerTest() = default;
  106. PeripheralNotificationManagerTest(const PeripheralNotificationManagerTest&) =
  107. delete;
  108. PeripheralNotificationManagerTest& operator=(
  109. const PeripheralNotificationManagerTest&) = delete;
  110. ~PeripheralNotificationManagerTest() override = default;
  111. // testing::Test:
  112. void SetUp() override {
  113. AshTestBase::SetUp();
  114. TypecdClient::InitializeFake();
  115. fake_typecd_client_ = static_cast<FakeTypecdClient*>(TypecdClient::Get());
  116. PciguardClient::InitializeFake();
  117. fake_pciguard_client_ =
  118. static_cast<FakePciguardClient*>(PciguardClient::Get());
  119. base::DeletePathRecursively(base::FilePath(thunderbolt_path_for_testing));
  120. }
  121. void InitializeManager(bool is_guest_session,
  122. bool is_pcie_tunneling_allowed) {
  123. PeripheralNotificationManager::Initialize(is_guest_session,
  124. is_pcie_tunneling_allowed);
  125. manager_ = PeripheralNotificationManager::Get();
  126. manager_->AddObserver(&fake_observer_);
  127. manager_->SetRootPrefixForTesting(root_prefix_for_testing);
  128. }
  129. void TearDown() override {
  130. AshTestBase::TearDown();
  131. manager_->RemoveObserver(&fake_observer_);
  132. PeripheralNotificationManager::Shutdown();
  133. TypecdClient::Shutdown();
  134. PciguardClient::Shutdown();
  135. base::DeletePathRecursively(base::FilePath(thunderbolt_path_for_testing));
  136. }
  137. FakeTypecdClient* fake_typecd_client() { return fake_typecd_client_; }
  138. FakePciguardClient* fake_pciguard_client() { return fake_pciguard_client_; }
  139. size_t GetNumLimitedPerformanceObserverCalls() {
  140. return fake_observer_.num_limited_performance_notification_calls();
  141. }
  142. size_t GetNumGuestModeNotificationObserverCalls() {
  143. return fake_observer_.num_guest_notification_calls();
  144. }
  145. size_t GetNumPeripheralBlockedNotificationObserverCalls() {
  146. return fake_observer_.num_peripheral_blocked_notification_calls();
  147. }
  148. size_t GetNumBillboardNotificationObserverCalls() {
  149. return fake_observer_.num_billboard_notification_calls();
  150. }
  151. size_t GetInvalidDpCableNotificationObserverCalls() {
  152. return fake_observer_.num_invalid_dp_cable_notification_calls();
  153. }
  154. size_t GetInvalidUSB4ValidTBTCableNotificationObserverCalls() {
  155. return fake_observer_.num_invalid_usb4_valid_tbt_cable_notification_calls();
  156. }
  157. size_t GetInvalidUSB4CableNotificationObserverCalls() {
  158. return fake_observer_.num_invalid_usb4_cable_notification_calls();
  159. }
  160. size_t GetInvalidTBTCableNotificationObserverCalls() {
  161. return fake_observer_.num_invalid_tbt_cable_notification_calls();
  162. }
  163. size_t GetSpeedLimitingCableNotificationObserverCalls() {
  164. return fake_observer_.num_speed_limiting_cable_notification_calls();
  165. }
  166. bool GetIsCurrentGuestDeviceTbtOnly() {
  167. return fake_observer_.is_current_guest_device_tbt_only();
  168. }
  169. base::HistogramTester histogram_tester_;
  170. private:
  171. FakeTypecdClient* fake_typecd_client_;
  172. FakePciguardClient* fake_pciguard_client_;
  173. PeripheralNotificationManager* manager_ = nullptr;
  174. FakeObserver fake_observer_;
  175. };
  176. scoped_refptr<device::FakeUsbDeviceInfo> CreateTestDeviceOfClass(
  177. uint8_t device_class) {
  178. auto config = device::mojom::UsbConfigurationInfo::New();
  179. config->configuration_value = kUsbConfigWithInterfaces;
  180. auto alternate = device::mojom::UsbAlternateInterfaceInfo::New();
  181. alternate->alternate_setting = 0;
  182. alternate->class_code = device_class;
  183. alternate->subclass_code = 0xff;
  184. alternate->protocol_code = 0xff;
  185. auto interface = device::mojom::UsbInterfaceInfo::New();
  186. interface->interface_number = 0;
  187. interface->alternates.push_back(std::move(alternate));
  188. config->interfaces.push_back(std::move(interface));
  189. std::vector<device::mojom::UsbConfigurationInfoPtr> configs;
  190. configs.push_back(std::move(config));
  191. scoped_refptr<device::FakeUsbDeviceInfo> device =
  192. base::MakeRefCounted<device::FakeUsbDeviceInfo>(
  193. /*vendor_id=*/0, /*product_id=*/1, device_class, std::move(configs));
  194. device->SetActiveConfig(kUsbConfigWithInterfaces);
  195. return device;
  196. }
  197. TEST_F(PeripheralNotificationManagerTest, InitialTest) {
  198. InitializeManager(/*is_guest_profile=*/false,
  199. /*is_pcie_tunneling_allowed=*/false);
  200. EXPECT_EQ(0u, GetNumLimitedPerformanceObserverCalls());
  201. EXPECT_EQ(0u, GetNumGuestModeNotificationObserverCalls());
  202. EXPECT_EQ(0u, GetNumBillboardNotificationObserverCalls());
  203. EXPECT_FALSE(GetIsCurrentGuestDeviceTbtOnly());
  204. }
  205. TEST_F(PeripheralNotificationManagerTest, LimitedPerformanceNotification) {
  206. InitializeManager(/*is_guest_profile=*/false,
  207. /*is_pcie_tunneling_allowed=*/false);
  208. EXPECT_EQ(0u, GetNumLimitedPerformanceObserverCalls());
  209. EXPECT_EQ(0u, GetNumGuestModeNotificationObserverCalls());
  210. EXPECT_FALSE(GetIsCurrentGuestDeviceTbtOnly());
  211. histogram_tester_.ExpectBucketCount(
  212. "Ash.Peripheral.ConnectivityResults",
  213. PeripheralNotificationManager::PeripheralConnectivityResults::
  214. kAltModeFallbackDueToPciguard,
  215. 0);
  216. // Simulate emitting D-Bus signal.
  217. fake_typecd_client()->EmitThunderboltDeviceConnectedSignal(
  218. /*is_thunderbolt_only=*/false);
  219. // pcie tunneling is not allowed and a alt-mode device has been plugged in.
  220. // Expect the notification observer to be called.
  221. EXPECT_EQ(1u, GetNumLimitedPerformanceObserverCalls());
  222. EXPECT_EQ(0u, GetNumGuestModeNotificationObserverCalls());
  223. EXPECT_FALSE(GetIsCurrentGuestDeviceTbtOnly());
  224. histogram_tester_.ExpectBucketCount(
  225. "Ash.Peripheral.ConnectivityResults",
  226. PeripheralNotificationManager::PeripheralConnectivityResults::
  227. kAltModeFallbackDueToPciguard,
  228. 1);
  229. }
  230. TEST_F(PeripheralNotificationManagerTest, NoNotificationShown) {
  231. InitializeManager(/*is_guest_profile=*/false,
  232. /*is_pcie_tunneling_allowed=*/true);
  233. EXPECT_EQ(0u, GetNumLimitedPerformanceObserverCalls());
  234. EXPECT_EQ(0u, GetNumGuestModeNotificationObserverCalls());
  235. EXPECT_FALSE(GetIsCurrentGuestDeviceTbtOnly());
  236. histogram_tester_.ExpectBucketCount(
  237. "Ash.Peripheral.ConnectivityResults",
  238. PeripheralNotificationManager::PeripheralConnectivityResults::
  239. kTBTSupportedAndAllowed,
  240. 0);
  241. // Simulate emitting D-Bus signal.
  242. fake_typecd_client()->EmitThunderboltDeviceConnectedSignal(
  243. /*is_thunderbolt_only=*/false);
  244. // Pcie tunneling allowed, we do not show any notifications for this case.
  245. EXPECT_EQ(0u, GetNumLimitedPerformanceObserverCalls());
  246. EXPECT_EQ(0u, GetNumGuestModeNotificationObserverCalls());
  247. EXPECT_FALSE(GetIsCurrentGuestDeviceTbtOnly());
  248. histogram_tester_.ExpectBucketCount(
  249. "Ash.Peripheral.ConnectivityResults",
  250. PeripheralNotificationManager::PeripheralConnectivityResults::
  251. kTBTSupportedAndAllowed,
  252. 1);
  253. // Simulate emitting a new D-Bus signal, this time with |is_thunderbolt_only|
  254. // set to true.
  255. fake_typecd_client()->EmitThunderboltDeviceConnectedSignal(
  256. /*is_thunderbolt_only=*/true);
  257. // Pcie tunneling allowed, we do not show any notifications for this case.
  258. EXPECT_EQ(0u, GetNumLimitedPerformanceObserverCalls());
  259. EXPECT_EQ(0u, GetNumGuestModeNotificationObserverCalls());
  260. // No observer was called, therefore don't expect this to be updated.
  261. EXPECT_FALSE(GetIsCurrentGuestDeviceTbtOnly());
  262. histogram_tester_.ExpectBucketCount(
  263. "Ash.Peripheral.ConnectivityResults",
  264. PeripheralNotificationManager::PeripheralConnectivityResults::
  265. kTBTSupportedAndAllowed,
  266. 2);
  267. }
  268. TEST_F(PeripheralNotificationManagerTest, TBTOnlyAndBlockedByPciguard) {
  269. InitializeManager(/*is_guest_profile=*/false,
  270. /*is_pcie_tunneling_allowed=*/false);
  271. EXPECT_EQ(0u, GetNumLimitedPerformanceObserverCalls());
  272. EXPECT_EQ(0u, GetNumGuestModeNotificationObserverCalls());
  273. EXPECT_FALSE(GetIsCurrentGuestDeviceTbtOnly());
  274. histogram_tester_.ExpectBucketCount(
  275. "Ash.Peripheral.ConnectivityResults",
  276. PeripheralNotificationManager::PeripheralConnectivityResults::
  277. kTBTOnlyAndBlockedByPciguard,
  278. 0);
  279. // Simulate emitting D-Bus signal.
  280. fake_typecd_client()->EmitThunderboltDeviceConnectedSignal(
  281. /*is_thunderbolt_only=*/true);
  282. // Pcie tunneling allowed, we do not show any notifications for this case.
  283. EXPECT_EQ(1u, GetNumLimitedPerformanceObserverCalls());
  284. EXPECT_EQ(0u, GetNumGuestModeNotificationObserverCalls());
  285. EXPECT_FALSE(GetIsCurrentGuestDeviceTbtOnly());
  286. histogram_tester_.ExpectBucketCount(
  287. "Ash.Peripheral.ConnectivityResults",
  288. PeripheralNotificationManager::PeripheralConnectivityResults::
  289. kTBTOnlyAndBlockedByPciguard,
  290. 1);
  291. }
  292. TEST_F(PeripheralNotificationManagerTest, GuestNotificationLimitedPerformance) {
  293. InitializeManager(/*is_guest_profile=*/true,
  294. /*is_pcie_tunneling_allowed=*/false);
  295. EXPECT_EQ(0u, GetNumLimitedPerformanceObserverCalls());
  296. EXPECT_EQ(0u, GetNumGuestModeNotificationObserverCalls());
  297. EXPECT_FALSE(GetIsCurrentGuestDeviceTbtOnly());
  298. histogram_tester_.ExpectBucketCount(
  299. "Ash.Peripheral.ConnectivityResults",
  300. PeripheralNotificationManager::PeripheralConnectivityResults::
  301. kAltModeFallbackInGuestSession,
  302. 0);
  303. // Simulate emitting D-Bus signal.
  304. fake_typecd_client()->EmitThunderboltDeviceConnectedSignal(
  305. /*is_thunderbolt_only=*/false);
  306. // Pcie tunneling not allowed and user is in guest session. The device
  307. // supports an alt-mode, expect the notification observer to be called.
  308. EXPECT_EQ(0u, GetNumLimitedPerformanceObserverCalls());
  309. EXPECT_EQ(1u, GetNumGuestModeNotificationObserverCalls());
  310. EXPECT_FALSE(GetIsCurrentGuestDeviceTbtOnly());
  311. histogram_tester_.ExpectBucketCount(
  312. "Ash.Peripheral.ConnectivityResults",
  313. PeripheralNotificationManager::PeripheralConnectivityResults::
  314. kAltModeFallbackInGuestSession,
  315. 1);
  316. }
  317. TEST_F(PeripheralNotificationManagerTest, GuestNotificationRestricted) {
  318. InitializeManager(/*is_guest_profile=*/true,
  319. /*is_pcie_tunneling_allowed=*/false);
  320. EXPECT_EQ(0u, GetNumLimitedPerformanceObserverCalls());
  321. EXPECT_EQ(0u, GetNumGuestModeNotificationObserverCalls());
  322. EXPECT_FALSE(GetIsCurrentGuestDeviceTbtOnly());
  323. histogram_tester_.ExpectBucketCount(
  324. "Ash.Peripheral.ConnectivityResults",
  325. PeripheralNotificationManager::PeripheralConnectivityResults::
  326. kTBTOnlyAndBlockedInGuestSession,
  327. 0);
  328. // Simulate emitting D-Bus signal.
  329. fake_typecd_client()->EmitThunderboltDeviceConnectedSignal(
  330. /*is_thunderbolt_only=*/true);
  331. // Pcie tunneling not allowed and user is in guest session. The device
  332. // does not support alt-mode, expect the notification observer to be called.
  333. EXPECT_EQ(0u, GetNumLimitedPerformanceObserverCalls());
  334. EXPECT_EQ(1u, GetNumGuestModeNotificationObserverCalls());
  335. EXPECT_TRUE(GetIsCurrentGuestDeviceTbtOnly());
  336. histogram_tester_.ExpectBucketCount(
  337. "Ash.Peripheral.ConnectivityResults",
  338. PeripheralNotificationManager::PeripheralConnectivityResults::
  339. kTBTOnlyAndBlockedInGuestSession,
  340. 1);
  341. }
  342. TEST_F(PeripheralNotificationManagerTest, BlockedDeviceReceived) {
  343. InitializeManager(/*is_guest_profile=*/false,
  344. /*is_pcie_tunneling_allowed=*/true);
  345. EXPECT_EQ(0u, GetNumLimitedPerformanceObserverCalls());
  346. EXPECT_EQ(0u, GetNumGuestModeNotificationObserverCalls());
  347. EXPECT_EQ(0u, GetNumPeripheralBlockedNotificationObserverCalls());
  348. // Simulate emitting D-Bus signal for a blocked device received.
  349. fake_pciguard_client()->EmitDeviceBlockedSignal(/*device_name=*/"test");
  350. EXPECT_EQ(0u, GetNumLimitedPerformanceObserverCalls());
  351. EXPECT_EQ(0u, GetNumGuestModeNotificationObserverCalls());
  352. EXPECT_EQ(1u, GetNumPeripheralBlockedNotificationObserverCalls());
  353. histogram_tester_.ExpectBucketCount(
  354. "Ash.Peripheral.ConnectivityResults",
  355. PeripheralNotificationManager::PeripheralConnectivityResults::
  356. kPeripheralBlocked,
  357. 1);
  358. }
  359. TEST_F(PeripheralNotificationManagerTest, BillboardDevice) {
  360. base::test::ScopedFeatureList feature_list;
  361. feature_list.InitAndEnableFeature(features::kPcieBillboardNotification);
  362. InitializeManager(/*is_guest_profile=*/false,
  363. /*is_pcie_tunneling_allowed=*/true);
  364. EXPECT_EQ(0u, GetNumLimitedPerformanceObserverCalls());
  365. EXPECT_EQ(0u, GetNumGuestModeNotificationObserverCalls());
  366. EXPECT_EQ(0u, GetNumPeripheralBlockedNotificationObserverCalls());
  367. EXPECT_EQ(0u, GetNumBillboardNotificationObserverCalls());
  368. // Simulate connecting a billboard device.
  369. const auto fake_device = CreateTestDeviceOfClass(kBillboardDeviceClassCode);
  370. const auto device = fake_device->GetDeviceInfo().Clone();
  371. PeripheralNotificationManager::Get()->OnDeviceConnected(device.get());
  372. task_environment()->RunUntilIdle();
  373. EXPECT_EQ(0u, GetNumLimitedPerformanceObserverCalls());
  374. EXPECT_EQ(0u, GetNumGuestModeNotificationObserverCalls());
  375. EXPECT_EQ(0u, GetNumPeripheralBlockedNotificationObserverCalls());
  376. EXPECT_EQ(1u, GetNumBillboardNotificationObserverCalls());
  377. histogram_tester_.ExpectBucketCount(
  378. "Ash.Peripheral.ConnectivityResults",
  379. PeripheralNotificationManager::PeripheralConnectivityResults::
  380. kBillboardDevice,
  381. 1);
  382. // Connect a non-billboard device. There should be no notification.
  383. const auto fake_device_1 =
  384. CreateTestDeviceOfClass(kNonBillboardDeviceClassCode);
  385. const auto device_1 = fake_device_1->GetDeviceInfo().Clone();
  386. PeripheralNotificationManager::Get()->OnDeviceConnected(device_1.get());
  387. EXPECT_EQ(0u, GetNumLimitedPerformanceObserverCalls());
  388. EXPECT_EQ(0u, GetNumGuestModeNotificationObserverCalls());
  389. EXPECT_EQ(0u, GetNumPeripheralBlockedNotificationObserverCalls());
  390. EXPECT_EQ(1u, GetNumBillboardNotificationObserverCalls());
  391. // Fake a board that supports Thunderbolt.
  392. auto thunderbolt_directory = std::make_unique<base::ScopedTempDir>();
  393. EXPECT_TRUE(thunderbolt_directory->CreateUniqueTempDirUnderPath(
  394. base::FilePath(thunderbolt_path_for_testing)));
  395. // Connect a billboard device. There should be no notification.
  396. const auto fake_device_2 = CreateTestDeviceOfClass(kBillboardDeviceClassCode);
  397. const auto device_2 = fake_device_2->GetDeviceInfo().Clone();
  398. PeripheralNotificationManager::Get()->OnDeviceConnected(device_2.get());
  399. EXPECT_EQ(0u, GetNumLimitedPerformanceObserverCalls());
  400. EXPECT_EQ(0u, GetNumGuestModeNotificationObserverCalls());
  401. EXPECT_EQ(0u, GetNumPeripheralBlockedNotificationObserverCalls());
  402. EXPECT_EQ(1u, GetNumBillboardNotificationObserverCalls());
  403. histogram_tester_.ExpectBucketCount(
  404. "Ash.Peripheral.ConnectivityResults",
  405. PeripheralNotificationManager::PeripheralConnectivityResults::
  406. kBillboardDevice,
  407. 1);
  408. }
  409. TEST_F(PeripheralNotificationManagerTest, InvalidDpCableWarning) {
  410. InitializeManager(/*is_guest_profile=*/false,
  411. /*is_pcie_tunneling_allowed=*/false);
  412. EXPECT_EQ(0u, GetInvalidDpCableNotificationObserverCalls());
  413. histogram_tester_.ExpectBucketCount(
  414. "Ash.Peripheral.ConnectivityResults",
  415. PeripheralNotificationManager::PeripheralConnectivityResults::
  416. kInvalidDpCable,
  417. 0);
  418. // Simulate emitting D-Bus signal for an invalid dp cable.
  419. typecd::CableWarningType cable_warning_type =
  420. typecd::CableWarningType::kInvalidDpCable;
  421. fake_typecd_client()->EmitCableWarningSignal(cable_warning_type);
  422. EXPECT_EQ(1u, GetInvalidDpCableNotificationObserverCalls());
  423. histogram_tester_.ExpectBucketCount(
  424. "Ash.Peripheral.ConnectivityResults",
  425. PeripheralNotificationManager::PeripheralConnectivityResults::
  426. kInvalidDpCable,
  427. 1);
  428. }
  429. TEST_F(PeripheralNotificationManagerTest, InvalidUSB4ValidTBTCableWarning) {
  430. InitializeManager(/*is_guest_profile=*/false,
  431. /*is_pcie_tunneling_allowed=*/false);
  432. EXPECT_EQ(0u, GetInvalidUSB4ValidTBTCableNotificationObserverCalls());
  433. histogram_tester_.ExpectBucketCount(
  434. "Ash.Peripheral.ConnectivityResults",
  435. PeripheralNotificationManager::PeripheralConnectivityResults::
  436. kInvalidUSB4ValidTBTCable,
  437. 0);
  438. typecd::CableWarningType cable_warning_type =
  439. typecd::CableWarningType::kInvalidUSB4ValidTBTCable;
  440. fake_typecd_client()->EmitCableWarningSignal(cable_warning_type);
  441. EXPECT_EQ(1u, GetInvalidUSB4ValidTBTCableNotificationObserverCalls());
  442. histogram_tester_.ExpectBucketCount(
  443. "Ash.Peripheral.ConnectivityResults",
  444. PeripheralNotificationManager::PeripheralConnectivityResults::
  445. kInvalidUSB4ValidTBTCable,
  446. 1);
  447. }
  448. TEST_F(PeripheralNotificationManagerTest, InvalidUSB4CableWarning) {
  449. InitializeManager(/*is_guest_profile=*/false,
  450. /*is_pcie_tunneling_allowed=*/false);
  451. EXPECT_EQ(0u, GetInvalidUSB4CableNotificationObserverCalls());
  452. histogram_tester_.ExpectBucketCount(
  453. "Ash.Peripheral.ConnectivityResults",
  454. PeripheralNotificationManager::PeripheralConnectivityResults::
  455. kInvalidUSB4Cable,
  456. 0);
  457. typecd::CableWarningType cable_warning_type =
  458. typecd::CableWarningType::kInvalidUSB4Cable;
  459. fake_typecd_client()->EmitCableWarningSignal(cable_warning_type);
  460. EXPECT_EQ(1u, GetInvalidUSB4CableNotificationObserverCalls());
  461. histogram_tester_.ExpectBucketCount(
  462. "Ash.Peripheral.ConnectivityResults",
  463. PeripheralNotificationManager::PeripheralConnectivityResults::
  464. kInvalidUSB4Cable,
  465. 1);
  466. }
  467. TEST_F(PeripheralNotificationManagerTest, InvalidTBTCableWarning) {
  468. InitializeManager(/*is_guest_profile=*/false,
  469. /*is_pcie_tunneling_allowed=*/false);
  470. EXPECT_EQ(0u, GetInvalidTBTCableNotificationObserverCalls());
  471. histogram_tester_.ExpectBucketCount(
  472. "Ash.Peripheral.ConnectivityResults",
  473. PeripheralNotificationManager::PeripheralConnectivityResults::
  474. kInvalidTBTCable,
  475. 0);
  476. typecd::CableWarningType cable_warning_type =
  477. typecd::CableWarningType::kInvalidTBTCable;
  478. fake_typecd_client()->EmitCableWarningSignal(cable_warning_type);
  479. EXPECT_EQ(1u, GetInvalidTBTCableNotificationObserverCalls());
  480. histogram_tester_.ExpectBucketCount(
  481. "Ash.Peripheral.ConnectivityResults",
  482. PeripheralNotificationManager::PeripheralConnectivityResults::
  483. kInvalidTBTCable,
  484. 1);
  485. }
  486. TEST_F(PeripheralNotificationManagerTest, SpeedLimitingCableWarning) {
  487. InitializeManager(/*is_guest_profile=*/false,
  488. /*is_pcie_tunneling_allowed=*/false);
  489. EXPECT_EQ(0u, GetSpeedLimitingCableNotificationObserverCalls());
  490. histogram_tester_.ExpectBucketCount(
  491. "Ash.Peripheral.ConnectivityResults",
  492. PeripheralNotificationManager::PeripheralConnectivityResults::
  493. kSpeedLimitingCable,
  494. 0);
  495. typecd::CableWarningType cable_warning_type =
  496. typecd::CableWarningType::kSpeedLimitingCable;
  497. fake_typecd_client()->EmitCableWarningSignal(cable_warning_type);
  498. EXPECT_EQ(1u, GetSpeedLimitingCableNotificationObserverCalls());
  499. histogram_tester_.ExpectBucketCount(
  500. "Ash.Peripheral.ConnectivityResults",
  501. PeripheralNotificationManager::PeripheralConnectivityResults::
  502. kSpeedLimitingCable,
  503. 1);
  504. }
  505. } // namespace ash