summaryrefslogtreecommitdiffstats
path: root/device/devices_app/devices_apptest.cc
blob: b6b150324523d5b58e743985c66898f62dac6ad0 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
// Copyright 2015 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#include <utility>

#include "base/bind.h"
#include "base/callback.h"
#include "base/macros.h"
#include "base/run_loop.h"
#include "device/devices_app/devices_app.h"
#include "device/devices_app/usb/public/interfaces/device_manager.mojom.h"
#include "mojo/application/public/cpp/application_impl.h"
#include "mojo/application/public/cpp/application_test_base.h"

namespace device {
namespace {

class DevicesAppTest : public mojo::test::ApplicationTestBase {
 public:
  DevicesAppTest() {}
  ~DevicesAppTest() override {}

  void SetUp() override {
    ApplicationTestBase::SetUp();
    application_impl()->ConnectToService("mojo:devices", &usb_device_manager_);
  }

  usb::DeviceManager* usb_device_manager() { return usb_device_manager_.get(); }

 private:
  usb::DeviceManagerPtr usb_device_manager_;

  DISALLOW_COPY_AND_ASSIGN(DevicesAppTest);
};

void OnGetDevices(const base::Closure& continuation,
                  mojo::Array<usb::DeviceInfoPtr> devices) {
  continuation.Run();
}

}  // namespace

// Simple test to verify that we can connect to the USB DeviceManager and get
// a response.
TEST_F(DevicesAppTest, GetUSBDevices) {
  base::RunLoop loop;
  usb::EnumerationOptionsPtr options = usb::EnumerationOptions::New();
  options->filters = mojo::Array<usb::DeviceFilterPtr>(1);
  options->filters[0] = usb::DeviceFilter::New();
  usb_device_manager()->GetDevices(
      std::move(options), base::Bind(&OnGetDevices, loop.QuitClosure()));
  loop.Run();
}

}  // namespace device