Updating trunk VERSION from 2139.0 to 2140.0
[chromium-blink-merge.git] / device / usb / usb_service_unittest.cc
blob1f8b8e2c36606fb5a010ed15d8c7d43119df1e04
1 // Copyright 2014 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.
5 #include "base/message_loop/message_loop.h"
6 #include "base/strings/utf_string_conversions.h"
7 #include "components/usb_service/usb_device.h"
8 #include "components/usb_service/usb_device_handle.h"
9 #include "device/test/usb_test_gadget.h"
10 #include "testing/gtest/include/gtest/gtest.h"
12 using ::usb_service::UsbDeviceHandle;
14 namespace device {
16 namespace {
18 class UsbServiceTest : public ::testing::Test {
19 public:
20 virtual void SetUp() {
21 message_loop_.reset(new base::MessageLoopForIO);
24 private:
25 scoped_ptr<base::MessageLoop> message_loop_;
28 TEST_F(UsbServiceTest, ClaimGadget) {
29 if (!UsbTestGadget::IsTestEnabled()) return;
31 scoped_ptr<UsbTestGadget> gadget = UsbTestGadget::Claim();
32 ASSERT_TRUE(gadget.get());
34 scoped_refptr<UsbDeviceHandle> handle = gadget->GetDevice()->Open();
36 base::string16 utf16;
37 ASSERT_TRUE(handle->GetManufacturer(&utf16));
38 ASSERT_EQ("Google Inc.", base::UTF16ToUTF8(utf16));
39 // Check again to make sure string descriptor caching works.
40 ASSERT_EQ("Google Inc.", base::UTF16ToUTF8(utf16));
42 ASSERT_TRUE(handle->GetProduct(&utf16));
43 ASSERT_EQ("Test Gadget (default state)", base::UTF16ToUTF8(utf16));
44 // Check again to make sure string descriptor caching works.
45 ASSERT_EQ("Test Gadget (default state)", base::UTF16ToUTF8(utf16));
47 ASSERT_TRUE(handle->GetSerial(&utf16));
48 ASSERT_EQ(gadget->GetSerial(), base::UTF16ToUTF8(utf16));
49 // Check again to make sure string descriptor caching works.
50 ASSERT_EQ(gadget->GetSerial(), base::UTF16ToUTF8(utf16));
53 TEST_F(UsbServiceTest, DisconnectAndReconnect) {
54 if (!UsbTestGadget::IsTestEnabled()) return;
56 scoped_ptr<UsbTestGadget> gadget = UsbTestGadget::Claim();
57 ASSERT_TRUE(gadget.get());
58 ASSERT_TRUE(gadget->Disconnect());
59 ASSERT_TRUE(gadget->Reconnect());
62 } // namespace
64 } // namespace device