Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(454)

Unified Diff: device/usb/usb_service_unittest.cc

Issue 2797433005: Remove MessageLoop destruction observer from //device/usb (Closed)
Patch Set: Further clarify cross-thread ownership Created 3 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « device/usb/usb_service.cc ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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
« no previous file with comments | « device/usb/usb_service.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698