Index: device/usb/usb_service_unittest.cc |
diff --git a/device/usb/usb_service_unittest.cc b/device/usb/usb_service_unittest.cc |
index 4013fbefcd80f9a8e63e70c36f314ce1f69e0457..559e52a82fa3f3d3c6ce9920a6eb89878029421b 100644 |
--- a/device/usb/usb_service_unittest.cc |
+++ b/device/usb/usb_service_unittest.cc |
@@ -14,6 +14,7 @@ |
#include "device/test/test_device_client.h" |
#include "device/test/usb_test_gadget.h" |
#include "device/usb/usb_device.h" |
+#include "device/usb/usb_device_handle.h" |
#include "device/usb/usb_service.h" |
#include "testing/gtest/include/gtest/gtest.h" |
@@ -40,6 +41,13 @@ void OnGetDevices(const base::Closure& quit_closure, |
quit_closure.Run(); |
} |
+void OnOpen(scoped_refptr<UsbDeviceHandle>* output, |
+ const base::Closure& quit_closure, |
+ scoped_refptr<UsbDeviceHandle> input) { |
+ *output = input; |
+ quit_closure.Run(); |
+} |
+ |
TEST_F(UsbServiceTest, GetDevices) { |
// Since there's no guarantee that any devices are connected at the moment |
// this test doesn't assume anything about the result but it at least verifies |
@@ -70,7 +78,7 @@ TEST_F(UsbServiceTest, ClaimGadget) { |
std::unique_ptr<UsbTestGadget> gadget = |
UsbTestGadget::Claim(io_thread_->task_runner()); |
- ASSERT_TRUE(gadget.get()); |
+ ASSERT_TRUE(gadget); |
scoped_refptr<UsbDevice> device = gadget->GetDevice(); |
ASSERT_EQ("Google Inc.", base::UTF16ToUTF8(device->manufacturer_string())); |
@@ -83,11 +91,31 @@ TEST_F(UsbServiceTest, DisconnectAndReconnect) { |
std::unique_ptr<UsbTestGadget> gadget = |
UsbTestGadget::Claim(io_thread_->task_runner()); |
- ASSERT_TRUE(gadget.get()); |
+ ASSERT_TRUE(gadget); |
ASSERT_TRUE(gadget->Disconnect()); |
ASSERT_TRUE(gadget->Reconnect()); |
} |
+TEST_F(UsbServiceTest, Shutdown) { |
+ if (!UsbTestGadget::IsTestEnabled()) |
+ return; |
+ |
+ std::unique_ptr<UsbTestGadget> gadget = |
+ UsbTestGadget::Claim(io_thread_->task_runner()); |
+ ASSERT_TRUE(gadget); |
+ |
+ base::RunLoop loop; |
+ scoped_refptr<UsbDeviceHandle> device_handle; |
+ gadget->GetDevice()->Open( |
+ base::Bind(&OnOpen, &device_handle, loop.QuitClosure())); |
+ loop.Run(); |
+ ASSERT_TRUE(device_handle); |
+ |
+ // Shut down the USB service while the device handle is still open. |
+ device_client_.reset(); |
+ EXPECT_FALSE(device_handle->GetDevice()); |
+} |
+ |
} // namespace |
} // namespace device |