Avi Drissman | 3a215d1e | 2022-09-07 19:43:09 | [diff] [blame] | 1 | // Copyright 2021 The Chromium Authors |
Jimmy Gong | e1bd808 | 2021-02-23 21:40:57 | [diff] [blame] | 2 | // Use of this source code is governed by a BSD-style license that can be |
| 3 | // found in the LICENSE file. |
| 4 | |
| 5 | #include "ash/system/pcie_peripheral/pcie_peripheral_notification_controller.h" |
| 6 | |
| 7 | #include <memory> |
Arthur Sonzogni | a98e443 | 2023-11-28 18:15:01 | [diff] [blame] | 8 | #include <optional> |
Jimmy Gong | e1bd808 | 2021-02-23 21:40:57 | [diff] [blame] | 9 | #include <vector> |
| 10 | |
Henrique Ferreiro | f9d1cb2 | 2021-07-13 01:32:47 | [diff] [blame] | 11 | #include "ash/constants/ash_pref_names.h" |
Jimmy Gong | e1bd808 | 2021-02-23 21:40:57 | [diff] [blame] | 12 | #include "ash/public/cpp/test/test_new_window_delegate.h" |
| 13 | #include "ash/public/cpp/test/test_system_tray_client.h" |
Jimmy Gong | c6f4fd0 | 2021-02-25 01:55:00 | [diff] [blame] | 14 | #include "ash/session/session_controller_impl.h" |
Jimmy Gong | e1bd808 | 2021-02-23 21:40:57 | [diff] [blame] | 15 | #include "ash/shell.h" |
| 16 | #include "ash/test/ash_test_base.h" |
Arthur Sonzogni | 834e018f | 2023-04-22 10:20:02 | [diff] [blame] | 17 | #include "base/memory/raw_ptr.h" |
Jimmy Gong | c6f4fd0 | 2021-02-25 01:55:00 | [diff] [blame] | 18 | #include "components/prefs/pref_service.h" |
Jimmy Gong | e1bd808 | 2021-02-23 21:40:57 | [diff] [blame] | 19 | #include "testing/gmock/include/gmock/gmock.h" |
| 20 | #include "ui/message_center/fake_message_center.h" |
Jimmy Gong | c6f4fd0 | 2021-02-25 01:55:00 | [diff] [blame] | 21 | #include "ui/message_center/message_center.h" |
Jimmy Gong | e1bd808 | 2021-02-23 21:40:57 | [diff] [blame] | 22 | #include "ui/message_center/public/cpp/notification.h" |
| 23 | #include "ui/message_center/public/cpp/notification_types.h" |
| 24 | |
| 25 | using message_center::MessageCenter; |
| 26 | |
| 27 | namespace ash { |
| 28 | |
| 29 | namespace { |
| 30 | const char kPciePeripheralLimitedPerformanceNotificationId[] = |
| 31 | "cros_pcie_peripheral_limited_performance_notification_id"; |
| 32 | const char kPciePeripheralLimitedPerformanceGuestModeNotificationId[] = |
| 33 | "cros_pcie_peripheral_limited_performance_guest_mode_notification_id"; |
| 34 | const char kPciePeripheralGuestModeNotSupportedNotificationId[] = |
| 35 | "cros_pcie_peripheral_guest_mode_not_supported_notifcation_id"; |
Jimmy Gong | 4041bd13 | 2021-03-10 00:00:03 | [diff] [blame] | 36 | const char kPciePeripheralDeviceBlockedNotificationId[] = |
| 37 | "cros_pcie_peripheral_device_blocked_notifcation_id"; |
Anton Swifton | a1cda03 | 2021-08-03 22:42:33 | [diff] [blame] | 38 | const char kPciePeripheralBillboardDeviceNotificationId[] = |
| 39 | "cros_pcie_peripheral_billboard_device_notifcation_id"; |
Jimmy Gong | e1bd808 | 2021-02-23 21:40:57 | [diff] [blame] | 40 | const char kLearnMoreHelpUrl[] = |
| 41 | "https://www.support.google.com/chromebook?p=connect_thblt_usb4_accy"; |
| 42 | |
| 43 | // A mock implementation of |NewWindowDelegate| for use in tests. |
| 44 | class MockNewWindowDelegate : public testing::NiceMock<TestNewWindowDelegate> { |
| 45 | public: |
| 46 | // TestNewWindowDelegate: |
Georg Neis | b386a342 | 2022-08-17 00:33:47 | [diff] [blame] | 47 | MOCK_METHOD(void, |
| 48 | OpenUrl, |
| 49 | (const GURL& url, OpenUrlFrom from, Disposition disposition), |
| 50 | (override)); |
Jimmy Gong | e1bd808 | 2021-02-23 21:40:57 | [diff] [blame] | 51 | }; |
| 52 | |
| 53 | } // namespace |
| 54 | |
| 55 | class PciePeripheralNotificationControllerTest : public AshTestBase { |
| 56 | public: |
Hidehiko Abe | 6e3e57f4 | 2021-03-23 11:23:58 | [diff] [blame] | 57 | PciePeripheralNotificationControllerTest() { |
Georg Neis | ed4e58d | 2022-02-08 17:47:26 | [diff] [blame] | 58 | auto instance = std::make_unique<MockNewWindowDelegate>(); |
| 59 | auto primary = std::make_unique<MockNewWindowDelegate>(); |
| 60 | new_window_delegate_primary_ = primary.get(); |
| 61 | delegate_provider_ = std::make_unique<TestNewWindowDelegateProvider>( |
| 62 | std::move(instance), std::move(primary)); |
Hidehiko Abe | 6e3e57f4 | 2021-03-23 11:23:58 | [diff] [blame] | 63 | } |
Jimmy Gong | e1bd808 | 2021-02-23 21:40:57 | [diff] [blame] | 64 | PciePeripheralNotificationControllerTest( |
| 65 | const PciePeripheralNotificationControllerTest&) = delete; |
| 66 | PciePeripheralNotificationControllerTest& operator=( |
| 67 | const PciePeripheralNotificationControllerTest&) = delete; |
| 68 | ~PciePeripheralNotificationControllerTest() override = default; |
| 69 | |
| 70 | PciePeripheralNotificationController* controller() { |
| 71 | return Shell::Get()->pcie_peripheral_notification_controller(); |
| 72 | } |
| 73 | |
Georg Neis | ed4e58d | 2022-02-08 17:47:26 | [diff] [blame] | 74 | MockNewWindowDelegate& new_window_delegate_primary() { |
| 75 | return *new_window_delegate_primary_; |
| 76 | } |
Jimmy Gong | e1bd808 | 2021-02-23 21:40:57 | [diff] [blame] | 77 | |
| 78 | message_center::Notification* GetLimitedPerformanceNotification() { |
| 79 | return MessageCenter::Get()->FindVisibleNotificationById( |
| 80 | kPciePeripheralLimitedPerformanceNotificationId); |
| 81 | } |
| 82 | |
| 83 | message_center::Notification* GetLimitedPerformanceGuestModeNotification() { |
| 84 | return MessageCenter::Get()->FindVisibleNotificationById( |
| 85 | kPciePeripheralLimitedPerformanceGuestModeNotificationId); |
| 86 | } |
| 87 | |
| 88 | message_center::Notification* GetGuestModeNotSupportedNotification() { |
| 89 | return MessageCenter::Get()->FindVisibleNotificationById( |
| 90 | kPciePeripheralGuestModeNotSupportedNotificationId); |
| 91 | } |
| 92 | |
Jimmy Gong | 4041bd13 | 2021-03-10 00:00:03 | [diff] [blame] | 93 | message_center::Notification* GetPeripheralBlockedNotification() { |
| 94 | return MessageCenter::Get()->FindVisibleNotificationById( |
| 95 | kPciePeripheralDeviceBlockedNotificationId); |
| 96 | } |
| 97 | |
Anton Swifton | a1cda03 | 2021-08-03 22:42:33 | [diff] [blame] | 98 | message_center::Notification* GetBillboardDeviceNotification() { |
| 99 | return MessageCenter::Get()->FindVisibleNotificationById( |
| 100 | kPciePeripheralBillboardDeviceNotificationId); |
| 101 | } |
| 102 | |
Jimmy Gong | e1bd808 | 2021-02-23 21:40:57 | [diff] [blame] | 103 | int GetNumOsPrivacySettingsOpened() { |
| 104 | return GetSystemTrayClient()->show_os_settings_privacy_and_security_count(); |
| 105 | } |
| 106 | |
Jimmy Gong | c6f4fd0 | 2021-02-25 01:55:00 | [diff] [blame] | 107 | int GetPrefNotificationCount() { |
| 108 | PrefService* prefs = |
| 109 | Shell::Get()->session_controller()->GetActivePrefService(); |
| 110 | return prefs->GetInteger( |
| 111 | prefs::kPciePeripheralDisplayNotificationRemaining); |
| 112 | } |
| 113 | |
Arthur Sonzogni | a98e443 | 2023-11-28 18:15:01 | [diff] [blame] | 114 | void ClickLimitedNotificationButton(std::optional<int> button_index) { |
Jimmy Gong | e1bd808 | 2021-02-23 21:40:57 | [diff] [blame] | 115 | // No button index means the notification body was clicked. |
| 116 | if (!button_index.has_value()) { |
| 117 | message_center::Notification* notification = |
| 118 | MessageCenter::Get()->FindVisibleNotificationById( |
| 119 | kPciePeripheralLimitedPerformanceNotificationId); |
Arthur Sonzogni | a98e443 | 2023-11-28 18:15:01 | [diff] [blame] | 120 | notification->delegate()->Click(std::nullopt, std::nullopt); |
Jimmy Gong | e1bd808 | 2021-02-23 21:40:57 | [diff] [blame] | 121 | return; |
| 122 | } |
| 123 | |
| 124 | message_center::Notification* notification = |
| 125 | MessageCenter::Get()->FindVisibleNotificationById( |
| 126 | kPciePeripheralLimitedPerformanceNotificationId); |
Arthur Sonzogni | a98e443 | 2023-11-28 18:15:01 | [diff] [blame] | 127 | notification->delegate()->Click(button_index, std::nullopt); |
Jimmy Gong | e1bd808 | 2021-02-23 21:40:57 | [diff] [blame] | 128 | } |
| 129 | |
| 130 | void ClickGuestNotification(bool is_thunderbolt_only) { |
| 131 | if (is_thunderbolt_only) { |
| 132 | MessageCenter::Get()->ClickOnNotification( |
| 133 | kPciePeripheralGuestModeNotSupportedNotificationId); |
| 134 | return; |
| 135 | } |
| 136 | |
| 137 | MessageCenter::Get()->ClickOnNotification( |
| 138 | kPciePeripheralLimitedPerformanceGuestModeNotificationId); |
| 139 | } |
| 140 | |
Jimmy Gong | c6f4fd0 | 2021-02-25 01:55:00 | [diff] [blame] | 141 | void RemoveAllNotifications() { |
| 142 | MessageCenter::Get()->RemoveAllNotifications( |
| 143 | /*by_user=*/false, message_center::MessageCenter::RemoveType::ALL); |
| 144 | } |
| 145 | |
Jimmy Gong | e1bd808 | 2021-02-23 21:40:57 | [diff] [blame] | 146 | private: |
Bartek Nowierski | deb7584 | 2023-12-27 02:32:42 | [diff] [blame] | 147 | raw_ptr<MockNewWindowDelegate, DanglingUntriaged> |
Arthur Sonzogni | 34efeb8 | 2023-08-17 12:55:11 | [diff] [blame] | 148 | new_window_delegate_primary_; |
Hidehiko Abe | 6e3e57f4 | 2021-03-23 11:23:58 | [diff] [blame] | 149 | std::unique_ptr<TestNewWindowDelegateProvider> delegate_provider_; |
Jimmy Gong | e1bd808 | 2021-02-23 21:40:57 | [diff] [blame] | 150 | }; |
| 151 | |
Jimmy Gong | e1bd808 | 2021-02-23 21:40:57 | [diff] [blame] | 152 | TEST_F(PciePeripheralNotificationControllerTest, GuestNotificationTbtOnly) { |
| 153 | EXPECT_EQ(0u, MessageCenter::Get()->NotificationCount()); |
| 154 | |
| 155 | controller()->NotifyGuestModeNotification(/*is_thunderbolt_only=*/true); |
Jimmy Gong | e1bd808 | 2021-02-23 21:40:57 | [diff] [blame] | 156 | EXPECT_EQ(1u, MessageCenter::Get()->NotificationCount()); |
| 157 | |
| 158 | message_center::Notification* notification = |
| 159 | GetGuestModeNotSupportedNotification(); |
Jimmy Gong | c6f4fd0 | 2021-02-25 01:55:00 | [diff] [blame] | 160 | ASSERT_TRUE(notification); |
Jimmy Gong | e1bd808 | 2021-02-23 21:40:57 | [diff] [blame] | 161 | |
| 162 | // This notification has no buttons. |
| 163 | EXPECT_EQ(0u, notification->buttons().size()); |
| 164 | |
| 165 | controller()->NotifyGuestModeNotification(/*is_thunderbolt_only=*/true); |
| 166 | EXPECT_EQ(1u, MessageCenter::Get()->NotificationCount()); |
| 167 | |
Anton Swifton | a1cda03 | 2021-08-03 22:42:33 | [diff] [blame] | 168 | // Click on the notification and expect the Learn More page to appear. |
Hidehiko Abe | 4eb522b | 2022-02-16 11:18:58 | [diff] [blame] | 169 | EXPECT_CALL(new_window_delegate_primary(), |
| 170 | OpenUrl(GURL(kLearnMoreHelpUrl), |
Georg Neis | b386a342 | 2022-08-17 00:33:47 | [diff] [blame] | 171 | NewWindowDelegate::OpenUrlFrom::kUserInteraction, |
| 172 | NewWindowDelegate::Disposition::kNewForegroundTab)); |
Jimmy Gong | e1bd808 | 2021-02-23 21:40:57 | [diff] [blame] | 173 | ClickGuestNotification(/*is_thunderbolt_only=*/true); |
| 174 | EXPECT_EQ(0u, MessageCenter::Get()->NotificationCount()); |
| 175 | } |
| 176 | |
| 177 | TEST_F(PciePeripheralNotificationControllerTest, GuestNotificationTbtAltMode) { |
| 178 | EXPECT_EQ(0u, MessageCenter::Get()->NotificationCount()); |
| 179 | |
| 180 | controller()->NotifyGuestModeNotification(/*is_thunderbolt_only=*/false); |
| 181 | EXPECT_EQ(1u, MessageCenter::Get()->NotificationCount()); |
| 182 | |
| 183 | message_center::Notification* notification = |
| 184 | GetLimitedPerformanceGuestModeNotification(); |
Jimmy Gong | c6f4fd0 | 2021-02-25 01:55:00 | [diff] [blame] | 185 | ASSERT_TRUE(notification); |
Jimmy Gong | e1bd808 | 2021-02-23 21:40:57 | [diff] [blame] | 186 | |
| 187 | // This notification has no buttons. |
| 188 | EXPECT_EQ(0u, notification->buttons().size()); |
| 189 | |
| 190 | controller()->NotifyGuestModeNotification(/*is_thunderbolt_only=*/false); |
| 191 | EXPECT_EQ(1u, MessageCenter::Get()->NotificationCount()); |
| 192 | |
Anton Swifton | a1cda03 | 2021-08-03 22:42:33 | [diff] [blame] | 193 | // Click on the notification and expect the Learn More page to appear. |
Hidehiko Abe | 4eb522b | 2022-02-16 11:18:58 | [diff] [blame] | 194 | EXPECT_CALL(new_window_delegate_primary(), |
| 195 | OpenUrl(GURL(kLearnMoreHelpUrl), |
Georg Neis | b386a342 | 2022-08-17 00:33:47 | [diff] [blame] | 196 | NewWindowDelegate::OpenUrlFrom::kUserInteraction, |
| 197 | NewWindowDelegate::Disposition::kNewForegroundTab)); |
Jimmy Gong | e1bd808 | 2021-02-23 21:40:57 | [diff] [blame] | 198 | ClickGuestNotification(/*is_thunderbolt_only=*/false); |
| 199 | EXPECT_EQ(0u, MessageCenter::Get()->NotificationCount()); |
| 200 | } |
| 201 | |
Jimmy Gong | c6f4fd0 | 2021-02-25 01:55:00 | [diff] [blame] | 202 | TEST_F(PciePeripheralNotificationControllerTest, |
Jimmy Gong | 4041bd13 | 2021-03-10 00:00:03 | [diff] [blame] | 203 | PeripheralBlockedNotification) { |
| 204 | EXPECT_EQ(0u, MessageCenter::Get()->NotificationCount()); |
| 205 | |
| 206 | controller()->NotifyPeripheralBlockedNotification(); |
| 207 | EXPECT_EQ(1u, MessageCenter::Get()->NotificationCount()); |
| 208 | |
| 209 | message_center::Notification* notification = |
| 210 | GetPeripheralBlockedNotification(); |
| 211 | ASSERT_TRUE(notification); |
| 212 | |
| 213 | // This notification has no buttons. |
| 214 | EXPECT_EQ(0u, notification->buttons().size()); |
| 215 | |
Anton Swifton | a1cda03 | 2021-08-03 22:42:33 | [diff] [blame] | 216 | // Click on the notification and expect the Learn More page to appear. |
Hidehiko Abe | 4eb522b | 2022-02-16 11:18:58 | [diff] [blame] | 217 | EXPECT_CALL(new_window_delegate_primary(), |
| 218 | OpenUrl(GURL(kLearnMoreHelpUrl), |
Georg Neis | b386a342 | 2022-08-17 00:33:47 | [diff] [blame] | 219 | NewWindowDelegate::OpenUrlFrom::kUserInteraction, |
| 220 | NewWindowDelegate::Disposition::kNewForegroundTab)); |
Jimmy Gong | 4041bd13 | 2021-03-10 00:00:03 | [diff] [blame] | 221 | MessageCenter::Get()->ClickOnNotification( |
| 222 | kPciePeripheralDeviceBlockedNotificationId); |
| 223 | EXPECT_EQ(0u, MessageCenter::Get()->NotificationCount()); |
| 224 | } |
| 225 | |
Anton Swifton | a1cda03 | 2021-08-03 22:42:33 | [diff] [blame] | 226 | TEST_F(PciePeripheralNotificationControllerTest, BillboardDeviceNotification) { |
| 227 | EXPECT_EQ(0u, MessageCenter::Get()->NotificationCount()); |
| 228 | EXPECT_EQ(3, GetPrefNotificationCount()); |
| 229 | |
| 230 | controller()->NotifyBillboardDevice(); |
| 231 | EXPECT_EQ(1u, MessageCenter::Get()->NotificationCount()); |
| 232 | |
| 233 | message_center::Notification* notification = GetBillboardDeviceNotification(); |
| 234 | ASSERT_TRUE(notification); |
| 235 | |
| 236 | // This notification has no buttons. |
| 237 | EXPECT_EQ(0u, notification->buttons().size()); |
| 238 | |
| 239 | controller()->NotifyBillboardDevice(); |
| 240 | EXPECT_EQ(1u, MessageCenter::Get()->NotificationCount()); |
| 241 | |
| 242 | // Click on the notification and expect the Learn More page to appear. |
Hidehiko Abe | 4eb522b | 2022-02-16 11:18:58 | [diff] [blame] | 243 | EXPECT_CALL(new_window_delegate_primary(), |
| 244 | OpenUrl(GURL(kLearnMoreHelpUrl), |
Georg Neis | b386a342 | 2022-08-17 00:33:47 | [diff] [blame] | 245 | NewWindowDelegate::OpenUrlFrom::kUserInteraction, |
| 246 | NewWindowDelegate::Disposition::kNewForegroundTab)); |
Anton Swifton | a1cda03 | 2021-08-03 22:42:33 | [diff] [blame] | 247 | MessageCenter::Get()->ClickOnNotification( |
| 248 | kPciePeripheralBillboardDeviceNotificationId); |
| 249 | EXPECT_EQ(0u, MessageCenter::Get()->NotificationCount()); |
| 250 | EXPECT_EQ(3, GetPrefNotificationCount()); |
| 251 | } |
| 252 | |
Jimmy Gong | 4041bd13 | 2021-03-10 00:00:03 | [diff] [blame] | 253 | TEST_F(PciePeripheralNotificationControllerTest, |
Jimmy Gong | c6f4fd0 | 2021-02-25 01:55:00 | [diff] [blame] | 254 | LimitedPerformanceNotificationLearnMoreClick) { |
| 255 | EXPECT_EQ(0u, MessageCenter::Get()->NotificationCount()); |
| 256 | EXPECT_EQ(3, GetPrefNotificationCount()); |
| 257 | |
| 258 | controller()->NotifyLimitedPerformance(); |
| 259 | EXPECT_EQ(1u, MessageCenter::Get()->NotificationCount()); |
| 260 | |
| 261 | message_center::Notification* notification = |
| 262 | GetLimitedPerformanceNotification(); |
| 263 | ASSERT_TRUE(notification); |
| 264 | |
| 265 | // Ensure this notification has the two correct buttons. |
| 266 | EXPECT_EQ(2u, notification->buttons().size()); |
| 267 | |
Hidehiko Abe | 4eb522b | 2022-02-16 11:18:58 | [diff] [blame] | 268 | EXPECT_CALL(new_window_delegate_primary(), |
| 269 | OpenUrl(GURL(kLearnMoreHelpUrl), |
Georg Neis | b386a342 | 2022-08-17 00:33:47 | [diff] [blame] | 270 | NewWindowDelegate::OpenUrlFrom::kUserInteraction, |
| 271 | NewWindowDelegate::Disposition::kNewForegroundTab)); |
Jimmy Gong | c6f4fd0 | 2021-02-25 01:55:00 | [diff] [blame] | 272 | // Click the learn more link. |
| 273 | ClickLimitedNotificationButton(/*button_index=*/1); |
| 274 | EXPECT_EQ(2, GetPrefNotificationCount()); |
| 275 | EXPECT_EQ(0u, MessageCenter::Get()->NotificationCount()); |
| 276 | |
Hidehiko Abe | 4eb522b | 2022-02-16 11:18:58 | [diff] [blame] | 277 | EXPECT_CALL(new_window_delegate_primary(), |
| 278 | OpenUrl(GURL(kLearnMoreHelpUrl), |
Georg Neis | b386a342 | 2022-08-17 00:33:47 | [diff] [blame] | 279 | NewWindowDelegate::OpenUrlFrom::kUserInteraction, |
| 280 | NewWindowDelegate::Disposition::kNewForegroundTab)); |
Jimmy Gong | c6f4fd0 | 2021-02-25 01:55:00 | [diff] [blame] | 281 | controller()->NotifyLimitedPerformance(); |
| 282 | ClickLimitedNotificationButton(/*button_index=*/1); |
| 283 | EXPECT_EQ(1, GetPrefNotificationCount()); |
| 284 | EXPECT_EQ(0u, MessageCenter::Get()->NotificationCount()); |
| 285 | |
Hidehiko Abe | 4eb522b | 2022-02-16 11:18:58 | [diff] [blame] | 286 | EXPECT_CALL(new_window_delegate_primary(), |
| 287 | OpenUrl(GURL(kLearnMoreHelpUrl), |
Georg Neis | b386a342 | 2022-08-17 00:33:47 | [diff] [blame] | 288 | NewWindowDelegate::OpenUrlFrom::kUserInteraction, |
| 289 | NewWindowDelegate::Disposition::kNewForegroundTab)); |
Jimmy Gong | c6f4fd0 | 2021-02-25 01:55:00 | [diff] [blame] | 290 | controller()->NotifyLimitedPerformance(); |
| 291 | ClickLimitedNotificationButton(/*button_index=*/1); |
| 292 | EXPECT_EQ(0, GetPrefNotificationCount()); |
| 293 | EXPECT_EQ(0u, MessageCenter::Get()->NotificationCount()); |
| 294 | |
| 295 | controller()->NotifyLimitedPerformance(); |
| 296 | // Pref is currently at 0, so no new notifications should appear. |
| 297 | EXPECT_EQ(0u, MessageCenter::Get()->NotificationCount()); |
| 298 | } |
| 299 | |
| 300 | TEST_F(PciePeripheralNotificationControllerTest, |
| 301 | LimitedPerformanceNotificationBodyClick) { |
| 302 | EXPECT_EQ(0u, MessageCenter::Get()->NotificationCount()); |
| 303 | EXPECT_EQ(3, GetPrefNotificationCount()); |
| 304 | |
| 305 | controller()->NotifyLimitedPerformance(); |
| 306 | EXPECT_EQ(1u, MessageCenter::Get()->NotificationCount()); |
| 307 | // New notifications will decrement the counter. |
| 308 | EXPECT_EQ(2, GetPrefNotificationCount()); |
| 309 | |
| 310 | message_center::Notification* notification = |
| 311 | GetLimitedPerformanceNotification(); |
| 312 | ASSERT_TRUE(notification); |
| 313 | |
| 314 | // Ensure this notification has the two correct buttons. |
| 315 | EXPECT_EQ(2u, notification->buttons().size()); |
| 316 | |
| 317 | // Click the notification body. |
Arthur Sonzogni | a98e443 | 2023-11-28 18:15:01 | [diff] [blame] | 318 | ClickLimitedNotificationButton(std::nullopt); |
Jimmy Gong | c6f4fd0 | 2021-02-25 01:55:00 | [diff] [blame] | 319 | EXPECT_EQ(0, GetPrefNotificationCount()); |
| 320 | EXPECT_EQ(0u, MessageCenter::Get()->NotificationCount()); |
| 321 | EXPECT_EQ(1, GetNumOsPrivacySettingsOpened()); |
| 322 | |
| 323 | // No new notifications can appear. |
| 324 | controller()->NotifyLimitedPerformance(); |
| 325 | EXPECT_EQ(0u, MessageCenter::Get()->NotificationCount()); |
| 326 | } |
| 327 | |
| 328 | TEST_F(PciePeripheralNotificationControllerTest, |
| 329 | LimitedPerformanceNotificationSettingsButtonClick) { |
| 330 | EXPECT_EQ(0u, MessageCenter::Get()->NotificationCount()); |
| 331 | EXPECT_EQ(3, GetPrefNotificationCount()); |
| 332 | |
| 333 | controller()->NotifyLimitedPerformance(); |
| 334 | EXPECT_EQ(1u, MessageCenter::Get()->NotificationCount()); |
| 335 | // New notifications will decrement the counter. |
| 336 | EXPECT_EQ(2, GetPrefNotificationCount()); |
| 337 | |
| 338 | message_center::Notification* notification = |
| 339 | GetLimitedPerformanceNotification(); |
| 340 | ASSERT_TRUE(notification); |
| 341 | |
| 342 | // Ensure this notification has the two correct buttons. |
| 343 | EXPECT_EQ(2u, notification->buttons().size()); |
| 344 | |
| 345 | // Click the Settings button. |
| 346 | ClickLimitedNotificationButton(/*button_index=*/0); |
| 347 | EXPECT_EQ(0, GetPrefNotificationCount()); |
| 348 | EXPECT_EQ(1, GetNumOsPrivacySettingsOpened()); |
| 349 | EXPECT_EQ(0u, MessageCenter::Get()->NotificationCount()); |
| 350 | |
| 351 | // No new notifications can appear. |
| 352 | controller()->NotifyLimitedPerformance(); |
| 353 | EXPECT_EQ(0u, MessageCenter::Get()->NotificationCount()); |
| 354 | } |
| 355 | |
| 356 | TEST_F(PciePeripheralNotificationControllerTest, |
| 357 | ClickGuestNotificationTbtOnly) { |
| 358 | EXPECT_EQ(0u, MessageCenter::Get()->NotificationCount()); |
| 359 | EXPECT_EQ(3, GetPrefNotificationCount()); |
| 360 | |
| 361 | controller()->NotifyGuestModeNotification(/*is_thunderbolt_only=*/true); |
| 362 | EXPECT_EQ(1u, MessageCenter::Get()->NotificationCount()); |
| 363 | |
| 364 | message_center::Notification* notification = |
| 365 | GetGuestModeNotSupportedNotification(); |
| 366 | ASSERT_TRUE(notification); |
| 367 | |
| 368 | // This notification has no buttons. |
| 369 | EXPECT_EQ(0u, notification->buttons().size()); |
| 370 | |
| 371 | // We will always show guest notifications, expect that the pref did not |
| 372 | // decrement. |
Hidehiko Abe | 4eb522b | 2022-02-16 11:18:58 | [diff] [blame] | 373 | EXPECT_CALL(new_window_delegate_primary(), |
| 374 | OpenUrl(GURL(kLearnMoreHelpUrl), |
Georg Neis | b386a342 | 2022-08-17 00:33:47 | [diff] [blame] | 375 | NewWindowDelegate::OpenUrlFrom::kUserInteraction, |
| 376 | NewWindowDelegate::Disposition::kNewForegroundTab)); |
Jimmy Gong | c6f4fd0 | 2021-02-25 01:55:00 | [diff] [blame] | 377 | ClickGuestNotification(/*is_thunderbolt_only=*/true); |
| 378 | EXPECT_EQ(3, GetPrefNotificationCount()); |
| 379 | EXPECT_EQ(0u, MessageCenter::Get()->NotificationCount()); |
| 380 | |
| 381 | controller()->NotifyGuestModeNotification(/*is_thunderbolt_only=*/true); |
| 382 | EXPECT_EQ(1u, MessageCenter::Get()->NotificationCount()); |
| 383 | } |
| 384 | |
| 385 | TEST_F(PciePeripheralNotificationControllerTest, |
| 386 | ClickGuestNotificationTbtAltMode) { |
| 387 | EXPECT_EQ(0u, MessageCenter::Get()->NotificationCount()); |
| 388 | EXPECT_EQ(3, GetPrefNotificationCount()); |
| 389 | |
| 390 | controller()->NotifyGuestModeNotification(/*is_thunderbolt_only=*/false); |
| 391 | EXPECT_EQ(1u, MessageCenter::Get()->NotificationCount()); |
| 392 | |
| 393 | message_center::Notification* notification = |
| 394 | GetLimitedPerformanceGuestModeNotification(); |
| 395 | ASSERT_TRUE(notification); |
| 396 | |
| 397 | // This notification has no buttons. |
| 398 | EXPECT_EQ(0u, notification->buttons().size()); |
| 399 | |
| 400 | // We will always show guest notifications, expect that the pref did not |
| 401 | // decrement. |
Hidehiko Abe | 4eb522b | 2022-02-16 11:18:58 | [diff] [blame] | 402 | EXPECT_CALL(new_window_delegate_primary(), |
| 403 | OpenUrl(GURL(kLearnMoreHelpUrl), |
Georg Neis | b386a342 | 2022-08-17 00:33:47 | [diff] [blame] | 404 | NewWindowDelegate::OpenUrlFrom::kUserInteraction, |
| 405 | NewWindowDelegate::Disposition::kNewForegroundTab)); |
Jimmy Gong | c6f4fd0 | 2021-02-25 01:55:00 | [diff] [blame] | 406 | ClickGuestNotification(/*is_thunderbolt_only=*/false); |
| 407 | EXPECT_EQ(3, GetPrefNotificationCount()); |
| 408 | EXPECT_EQ(0u, MessageCenter::Get()->NotificationCount()); |
| 409 | |
| 410 | controller()->NotifyGuestModeNotification(/*is_thunderbolt_only=*/false); |
| 411 | EXPECT_EQ(1u, MessageCenter::Get()->NotificationCount()); |
| 412 | } |
| 413 | |
Jimmy Gong | e1bd808 | 2021-02-23 21:40:57 | [diff] [blame] | 414 | } // namespace ash |