summaryrefslogtreecommitdiffstats
path: root/device/BUILD.gn
blob: a8870d3fc30c767bc23622aa567ecc62c7abcdec (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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
# 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.

import("//build/config/features.gni")
import("//testing/test.gni")

if (is_android) {
  import("//build/config/android/rules.gni")  # For generate_jni().
}

if (is_mac) {
  import("//build/config/mac/mac_sdk.gni")
}

is_linux_without_udev = is_linux && !use_udev
is_linux_without_dbus = is_linux && !use_dbus

test("device_unittests") {
  sources = [
    "battery/battery_status_manager_win_unittest.cc",
    "battery/battery_status_service_unittest.cc",
    "bluetooth/bluetooth_adapter_mac_unittest.mm",
    "bluetooth/bluetooth_adapter_unittest.cc",
    "bluetooth/bluetooth_adapter_win_unittest.cc",
    "bluetooth/bluetooth_advertisement_unittest.cc",
    "bluetooth/bluetooth_device_unittest.cc",
    "bluetooth/bluetooth_device_win_unittest.cc",
    "bluetooth/bluetooth_discovery_filter_unittest.cc",
    "bluetooth/bluetooth_gatt_characteristic_unittest.cc",
    "bluetooth/bluetooth_gatt_descriptor_unittest.cc",
    "bluetooth/bluetooth_gatt_service_unittest.cc",
    "bluetooth/bluetooth_low_energy_win_unittest.cc",
    "bluetooth/bluetooth_service_record_win_unittest.cc",
    "bluetooth/bluetooth_task_manager_win_unittest.cc",
    "bluetooth/bluetooth_uuid_unittest.cc",
    "bluetooth/test/bluetooth_test.cc",
    "bluetooth/test/bluetooth_test.h",
    "bluetooth/test/bluetooth_test_android.cc",
    "bluetooth/test/bluetooth_test_android.h",
    "bluetooth/test/bluetooth_test_mac.h",
    "bluetooth/test/bluetooth_test_mac.mm",
    "bluetooth/test/bluetooth_test_win.cc",
    "bluetooth/test/bluetooth_test_win.h",
    "bluetooth/test/mock_bluetooth_cbperipheral_mac.h",
    "bluetooth/test/mock_bluetooth_cbperipheral_mac.mm",
    "bluetooth/test/mock_bluetooth_central_manager_mac.h",
    "bluetooth/test/mock_bluetooth_central_manager_mac.mm",
    "bluetooth/test/test_bluetooth_adapter_observer.cc",
    "bluetooth/test/test_bluetooth_adapter_observer.h",
    "nfc/nfc_chromeos_unittest.cc",
    "nfc/nfc_ndef_record_unittest.cc",
    "test/run_all_unittests.cc",
  ]

  deps = [
    "//base/test:test_support",
    "//device/battery",
    "//device/battery:mojo_bindings",
    "//device/bluetooth",
    "//device/bluetooth:mocks",
    "//device/nfc",
    "//mojo/common",
    "//mojo/edk/system",
    "//mojo/public/cpp/bindings",
    "//net",
    "//testing/gmock",
    "//testing/gtest",
    "//tools/usb_gadget",
    "//url",
  ]

  if (!is_linux_without_dbus && !is_chromeos) {
    sources += [ "battery/battery_status_manager_linux_unittest.cc" ]
  }

  # HID and Serial:
  # Android doesn't compile.
  # Linux, requires udev.
  if (!is_linux_without_udev && !is_android) {
    sources += [
      "hid/hid_connection_unittest.cc",
      "hid/hid_device_filter_unittest.cc",
      "hid/hid_report_descriptor_unittest.cc",
      "hid/input_service_linux_unittest.cc",
      "hid/test_report_descriptors.cc",
      "hid/test_report_descriptors.h",
      "serial/data_sink_unittest.cc",
      "serial/data_source_unittest.cc",
      "serial/serial_connection_unittest.cc",
      "serial/serial_io_handler_posix_unittest.cc",
      "serial/serial_service_unittest.cc",
    ]
    deps += [
      "//device/hid",
      "//device/serial",
      "//device/serial:test_support",
    ]
  }

  if (use_udev) {
    sources += [ "udev_linux/udev_unittest.cc" ]
    deps += [ "//device/udev_linux" ]
  }

  # USB does not compile on iOS.
  if (!is_ios) {
    sources += [
      "test/test_device_client.cc",
      "test/test_device_client.h",
      "test/usb_test_gadget_impl.cc",
      "usb/mojo/device_impl_unittest.cc",
      "usb/mojo/device_manager_impl_unittest.cc",
      "usb/mojo/fake_permission_provider.cc",
      "usb/mojo/fake_permission_provider.h",
      "usb/usb_descriptors_unittest.cc",
      "usb/usb_device_filter_unittest.cc",
      "usb/usb_device_handle_unittest.cc",
      "usb/usb_ids_unittest.cc",
      "usb/usb_service_unittest.cc",
      "usb/webusb_descriptors_unittest.cc",
    ]
    deps += [
      "//device/core",
      "//device/core:mocks",
      "//device/usb",
      "//device/usb:mocks",
      "//device/usb/mojo",
      "//device/usb/public/interfaces",
    ]
  }

  # UsbContext is a libusb-specific object.
  if (!is_android && !is_ios) {
    sources += [ "usb/usb_context_unittest.cc" ]
    deps += [ "//third_party/libusb" ]
  }

  if (is_android) {
    sources -= [ "battery/battery_status_service_unittest.cc" ]
    deps += [
      ":bluetooth_test_java",
      ":bluetooth_test_jni_headers",
    ]
    deps -= [ "//device/battery" ]
  }

  if (is_chromeos) {
    deps += [
      "//chromeos",
      "//chromeos:test_support",
      "//chromeos:test_support_without_gmock",
    ]
  }

  if ((is_chromeos || is_linux) && use_dbus) {
    configs += [ "//build/config/linux:dbus" ]

    sources += [
      "bluetooth/bluetooth_adapter_profile_bluez_unittest.cc",
      "bluetooth/bluetooth_advertisement_bluez_unittest.cc",
      "bluetooth/bluetooth_audio_sink_bluez_unittest.cc",
      "bluetooth/bluetooth_bluez_unittest.cc",
      "bluetooth/bluetooth_gatt_bluez_unittest.cc",
      "bluetooth/bluetooth_socket_bluez_unittest.cc",
    ]

    deps += [ "//dbus" ]
  }

  if (is_mac) {
    deps += [ "//third_party/ocmock" ]
    ldflags = [ "-ObjC" ]
    libs = [ "IOBluetooth.framework" ]

    # In the OSX 10.10 SDK, CoreBluetooth became a top level framework.
    # Previously, it was nested in IOBluetooth. In order for Chrome to run on
    # OSes older than OSX 10.10, the top level CoreBluetooth framework must be
    # weakly linked.
    if (mac_sdk_version == "10.10") {
      ldflags += [
        "-weak_framework",
        "CoreBluetooth",
      ]
    }
  }

  if (is_win) {
    sources += [
      "bluetooth/bluetooth_classic_win_fake.cc",
      "bluetooth/bluetooth_classic_win_fake.h",
      "bluetooth/bluetooth_low_energy_win_fake.cc",
      "bluetooth/bluetooth_low_energy_win_fake.h",
    ]
  }
}

if (is_android) {
  bluetooth_java_sources_needing_jni = [ "bluetooth/test/android/java/src/org/chromium/device/bluetooth/Fakes.java" ]

  generate_jni("bluetooth_test_jni_headers") {
    sources = bluetooth_java_sources_needing_jni
    jni_package = "bluetooth"
  }

  android_library("bluetooth_test_java") {
    java_files = bluetooth_java_sources_needing_jni
    deps = [
      "//base:base_java",
      "//device/bluetooth:java",
    ]
  }
}