Don't clobber the download metadata file when downloading a file for which we don...
[chromium-blink-merge.git] / device / usb / usb_service_unittest.cc
blob1ee013c65fb00994ec595705d5e5697a5c75bc02
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 "base/test/test_io_thread.h"
8 #include "device/test/test_device_client.h"
9 #include "device/test/usb_test_gadget.h"
10 #include "device/usb/usb_device.h"
11 #include "device/usb/usb_device_handle.h"
12 #include "testing/gtest/include/gtest/gtest.h"
14 namespace device {
16 namespace {
18 class UsbServiceTest : public ::testing::Test {
19 public:
20 void SetUp() override {
21 message_loop_.reset(new base::MessageLoopForUI);
22 io_thread_.reset(new base::TestIOThread(base::TestIOThread::kAutoStart));
23 device_client_.reset(new TestDeviceClient(io_thread_->task_runner()));
26 protected:
27 scoped_ptr<base::MessageLoop> message_loop_;
28 scoped_ptr<base::TestIOThread> io_thread_;
29 scoped_ptr<TestDeviceClient> device_client_;
32 TEST_F(UsbServiceTest, ClaimGadget) {
33 if (!UsbTestGadget::IsTestEnabled()) return;
35 scoped_ptr<UsbTestGadget> gadget =
36 UsbTestGadget::Claim(io_thread_->task_runner());
37 ASSERT_TRUE(gadget.get());
39 scoped_refptr<UsbDevice> device = gadget->GetDevice();
40 ASSERT_EQ("Google Inc.", base::UTF16ToUTF8(device->manufacturer_string()));
41 ASSERT_EQ("Test Gadget (default state)",
42 base::UTF16ToUTF8(device->product_string()));
45 TEST_F(UsbServiceTest, DisconnectAndReconnect) {
46 if (!UsbTestGadget::IsTestEnabled()) return;
48 scoped_ptr<UsbTestGadget> gadget =
49 UsbTestGadget::Claim(io_thread_->task_runner());
50 ASSERT_TRUE(gadget.get());
51 ASSERT_TRUE(gadget->Disconnect());
52 ASSERT_TRUE(gadget->Reconnect());
55 } // namespace
57 } // namespace device