Commit 45e450a1 authored by Nicholas Verne's avatar Nicholas Verne Committed by Commit Bot

CrosUsbDetector notification no longer calls Close twice.

Calling Close on a NotificationDelegate after its associated notification has
been closed can cause a Chrome crash.

Bug: None
Change-Id: I402f474e70a54e7eabe6d82c5a396011e836c8e1
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1659558Reviewed-by: default avatarFergus Dall <sidereal@google.com>
Commit-Queue: Nicholas Verne <nverne@chromium.org>
Cr-Commit-Position: refs/heads/master@{#669159}
parent 23b8e1d8
......@@ -99,6 +99,7 @@ class CrosUsbNotificationDelegate
if (detector) {
detector->AttachUsbDeviceToVm(crostini::kCrostiniDefaultVmName,
device_info_->guid, base::DoNothing());
return;
}
Close(false);
}
......
......@@ -149,6 +149,9 @@ class CrosUsbDetectorTest : public BrowserWithTestWindowTest {
device_manager_.AddBinding(mojo::MakeRequest(&device_manager_ptr));
chromeos::CrosUsbDetector::Get()->SetDeviceManagerForTesting(
std::move(device_manager_ptr));
// Create a default VM instance which is running.
crostini::CrostiniManager::GetForProfile(profile())->AddRunningVmForTesting(
crostini::kCrostiniDefaultVmName);
}
void TearDown() override {
......@@ -213,6 +216,30 @@ TEST_F(CrosUsbDetectorTest, UsbDeviceAddedAndRemoved) {
EXPECT_FALSE(display_service_->GetNotification(notification_id));
}
TEST_F(CrosUsbDetectorTest, UsbNotificationClicked) {
ConnectToDeviceManager();
base::RunLoop().RunUntilIdle();
auto device = base::MakeRefCounted<device::FakeUsbDeviceInfo>(
0, 1, kManufacturerName, kProductName_1, "002");
device_manager_.AddDevice(device);
base::RunLoop().RunUntilIdle();
std::string notification_id =
chromeos::CrosUsbDetector::MakeNotificationId(device->guid());
base::Optional<message_center::Notification> notification =
display_service_->GetNotification(notification_id);
ASSERT_TRUE(notification);
notification->delegate()->Click(0, base::nullopt);
base::RunLoop().RunUntilIdle();
EXPECT_TRUE(fake_concierge_client_->attach_usb_device_called());
// Notification should close.
EXPECT_FALSE(display_service_->GetNotification(notification_id));
}
TEST_F(CrosUsbDetectorTest, UsbDeviceClassBlockedAdded) {
ConnectToDeviceManager();
base::RunLoop().RunUntilIdle();
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment