File: connected_input_devices_log_source_unittest.cc

package info (click to toggle)
chromium 139.0.7258.127-1
  • links: PTS, VCS
  • area: main
  • in suites:
  • size: 6,122,068 kB
  • sloc: cpp: 35,100,771; ansic: 7,163,530; javascript: 4,103,002; python: 1,436,920; asm: 946,517; xml: 746,709; pascal: 187,653; perl: 88,691; sh: 88,436; objc: 79,953; sql: 51,488; cs: 44,583; fortran: 24,137; makefile: 22,147; tcl: 15,277; php: 13,980; yacc: 8,984; ruby: 7,485; awk: 3,720; lisp: 3,096; lex: 1,327; ada: 727; jsp: 228; sed: 36
file content (557 lines) | stat: -rw-r--r-- 20,618 bytes parent folder | download | duplicates (6)
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
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
// Copyright 2022 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#include "chrome/browser/ash/system_logs/connected_input_devices_log_source.h"

#include <functional>
#include <memory>
#include <set>
#include <string>
#include <tuple>
#include <vector>

#include "ash/constants/ash_switches.h"
#include "base/functional/bind.h"
#include "base/run_loop.h"
#include "base/strings/stringprintf.h"
#include "base/test/scoped_command_line.h"
#include "base/test/task_environment.h"
#include "chromeos/ash/components/mojo_service_manager/fake_mojo_service_manager.h"
#include "chromeos/ash/services/cros_healthd/public/cpp/fake_cros_healthd.h"
#include "content/public/test/browser_task_environment.h"
#include "testing/gtest/include/gtest/gtest.h"
#include "ui/events/devices/device_data_manager.h"
#include "ui/events/devices/device_data_manager_test_api.h"
#include "ui/events/devices/input_device.h"
#include "ui/events/devices/touchpad_device.h"

namespace system_logs {

class ConnectedInputDevicesLogSourceTest : public ::testing::Test {
 public:
  ConnectedInputDevicesLogSourceTest() = default;
  ConnectedInputDevicesLogSourceTest(
      const ConnectedInputDevicesLogSourceTest&) = delete;
  ConnectedInputDevicesLogSourceTest& operator=(
      const ConnectedInputDevicesLogSourceTest&) = delete;
  ~ConnectedInputDevicesLogSourceTest() override {
    ash::cros_healthd::FakeCrosHealthd::Shutdown();
    base::RunLoop().RunUntilIdle();
  }

  void SetUp() override {
    ui::DeviceDataManager::CreateInstance();
    ash::cros_healthd::FakeCrosHealthd::Initialize();
  }

  void TearDown() override { ui::DeviceDataManager::DeleteInstance(); }

  void SetCrosHealthdTouchpad(ash::cros_healthd::mojom::TelemetryInfoPtr& info,
                              std::string driver_name) {
    auto input_info = ash::cros_healthd::mojom::InputInfo::New();
    input_info->touchpad_devices =
        std::vector<ash::cros_healthd::mojom::TouchpadDevicePtr>{};

    auto touchpad_device = ash::cros_healthd::mojom::TouchpadDevice::New();
    touchpad_device->driver_name = driver_name;
    auto touchpad_input_device = ash::cros_healthd::mojom::InputDevice::New();
    touchpad_device->input_device = std::move(touchpad_input_device);

    input_info->touchpad_devices->push_back(std::move(touchpad_device));

    info->input_result = ash::cros_healthd::mojom::InputResult::NewInputInfo(
        std::move(input_info));
  }

 protected:
  base::test::TaskEnvironment task_environment_;

  static const uint16_t unknown_vid;
  static const char unknown_vendor_name[];

  size_t num_callback_calls() const { return num_callback_calls_; }
  const SystemLogsResponse& response() const { return response_; }

  SysLogsSourceCallback fetch_callback(base::OnceClosure quit_closure) {
    return base::BindOnce(&ConnectedInputDevicesLogSourceTest::OnFetchComplete,
                          base::Unretained(this), std::move(quit_closure));
  }

  ::ash::mojo_service_manager::FakeMojoServiceManager fake_service_manager_;

  raw_ptr<base::test::ScopedCommandLine> command_line_;

 private:
  void OnFetchComplete(base::OnceClosure quit_closure,
                       std::unique_ptr<SystemLogsResponse> response) {
    ++num_callback_calls_;
    response_ = *response;
    std::move(quit_closure).Run();
  }

  // Used to verify that OnGetFeedbackData was called the correct number of
  // times.
  size_t num_callback_calls_ = 0;

  // Stores results from the log source passed into fetch_callback().
  SystemLogsResponse response_;
};

// Obsolete VID of Fry's Electronics, unlikely to be used.
const uint16_t ConnectedInputDevicesLogSourceTest::unknown_vid = 0x0001;
const char ConnectedInputDevicesLogSourceTest::unknown_vendor_name[] = "0x0001";

TEST_F(ConnectedInputDevicesLogSourceTest, Touchpad_single) {
  const std::string vendor_name = "Synaptics";
  const uint16_t vid = 0x06cb;
  const uint16_t pid = 0x685f;
  const std::string driver_name = "SynPS/2";

  ui::DeviceDataManagerTestApi().SetTouchpadDevices({ui::TouchpadDevice(
      /*id=*/1, ui::INPUT_DEVICE_INTERNAL, /*name=*/"", /*phys=*/"",
      /*sys_path=*/base::FilePath(), vid, pid, /*version=*/0)});

  auto telem_info = ash::cros_healthd::mojom::TelemetryInfo::New();

  SetCrosHealthdTouchpad(telem_info, driver_name);
  ash::cros_healthd::FakeCrosHealthd::Get()
      ->SetProbeTelemetryInfoResponseForTesting(telem_info);

  /* Fetch log data. */
  ConnectedInputDevicesLogSource source;
  base::RunLoop run_loop;
  source.Fetch(fetch_callback(run_loop.QuitClosure()));
  run_loop.Run();

  /* Verify fetch_callback() has been called. */
  EXPECT_EQ(1U, num_callback_calls());
  ASSERT_EQ(3U, response().size());

  auto it = response().find("TOUCHPAD_VENDOR");
  ASSERT_NE(it, response().end());
  EXPECT_EQ(vendor_name, it->second);
  it = response().find("TOUCHPAD_PID");
  ASSERT_NE(it, response().end());
  EXPECT_EQ(base::StringPrintf("0x%04x", pid), it->second);
  it = response().find("TOUCHPAD_DRIVERS");
  EXPECT_EQ(driver_name, it->second);

  /* Verify fetch_callback() has not been called again. */
  EXPECT_EQ(1U, num_callback_calls());
}

TEST_F(ConnectedInputDevicesLogSourceTest, Flex_touchpad_single) {
  const std::string vendor_name = "Synaptics";
  const uint16_t vid = 0x06cb;
  const uint16_t pid = 0x685f;
  const std::string driver_name = "SynPS/2";
  const std::string flex_library_name = "libinput";

  ui::DeviceDataManagerTestApi().SetTouchpadDevices({ui::TouchpadDevice(
      /*id=*/1, ui::INPUT_DEVICE_INTERNAL, /*name=*/"", /*phys=*/"",
      /*sys_path=*/base::FilePath(), vid, pid, /*version=*/0)});

  auto telem_info = ash::cros_healthd::mojom::TelemetryInfo::New();

  SetCrosHealthdTouchpad(telem_info, driver_name);

  telem_info->input_result->get_input_info()->touchpad_library_name =
      flex_library_name;
  ash::cros_healthd::FakeCrosHealthd::Get()
      ->SetProbeTelemetryInfoResponseForTesting(telem_info);
  command_line_->GetProcessCommandLine()->AppendSwitch(
      ash::switches::kRevenBranding);

  /* Fetch log data. */
  ConnectedInputDevicesLogSource source;
  base::RunLoop run_loop;
  source.Fetch(fetch_callback(run_loop.QuitClosure()));
  run_loop.Run();

  /* Verify fetch_callback() has been called. */
  EXPECT_EQ(1U, num_callback_calls());
  ASSERT_EQ(4U, response().size());

  auto it = response().find("TOUCHPAD_VENDOR");
  ASSERT_NE(it, response().end());
  EXPECT_EQ(vendor_name, it->second);
  it = response().find("TOUCHPAD_PID");
  ASSERT_NE(it, response().end());
  EXPECT_EQ(base::StringPrintf("0x%04x", pid), it->second);
  it = response().find("TOUCHPAD_DRIVERS");
  EXPECT_EQ(driver_name, it->second);
  it = response().find("TOUCHPAD_LIBRARY");
  EXPECT_EQ(flex_library_name, it->second);

  /* Verify fetch_callback() has not been called again. */
  EXPECT_EQ(1U, num_callback_calls());
}

TEST_F(ConnectedInputDevicesLogSourceTest, Touchpad_single_other_ext) {
  const std::string t1_vendor_name = "Raydium";
  const uint16_t t1_vid = 0x2386;
  const uint16_t t1_pid = 0x3b1d;
  const uint16_t t2_vid = 0x0457;
  const uint16_t t2_pid = 0x3462;
  const std::string t1_driver_name = "driver1";
  const ui::TouchpadDevice tp1 = ui::TouchpadDevice(
      /*id=*/1, ui::INPUT_DEVICE_INTERNAL, /*name=*/"", /*phys=*/"",
      /*sys_path=*/base::FilePath(), t1_vid, t1_pid, /*version=*/0);
  const ui::TouchpadDevice tp2 = ui::TouchpadDevice(
      /*id=*/2, ui::INPUT_DEVICE_USB, /*name=*/"", /*phys=*/"",
      /*sys_path=*/base::FilePath(), t2_vid, t2_pid, /*version=*/0);

  ui::DeviceDataManagerTestApi().SetTouchpadDevices({tp1, tp2});

  auto telem_info = ash::cros_healthd::mojom::TelemetryInfo::New();

  // Currently healthD only pulls internal touchpad data, so only that needs
  // to be set
  SetCrosHealthdTouchpad(telem_info, t1_driver_name);
  ash::cros_healthd::FakeCrosHealthd::Get()
      ->SetProbeTelemetryInfoResponseForTesting(telem_info);

  /* Fetch log data. */
  ConnectedInputDevicesLogSource source;
  base::RunLoop run_loop;
  source.Fetch(fetch_callback(run_loop.QuitClosure()));
  run_loop.Run();

  /* Verify fetch_callback() has been called. */
  EXPECT_EQ(1U, num_callback_calls());
  ASSERT_EQ(3U, response().size());

  auto it = response().find("TOUCHPAD_VENDOR");
  ASSERT_NE(it, response().end());
  EXPECT_EQ(t1_vendor_name, it->second);
  it = response().find("TOUCHPAD_PID");
  ASSERT_NE(it, response().end());
  EXPECT_EQ(base::StringPrintf("0x%04x", t1_pid), it->second);
  it = response().find("TOUCHPAD_DRIVERS");
  EXPECT_EQ(t1_driver_name, it->second);

  /* Verify fetch_callback() has not been called again. */
  EXPECT_EQ(1U, num_callback_calls());
}

TEST_F(ConnectedInputDevicesLogSourceTest, Touchpad_single_ts_ext) {
  const std::string tp_vendor_name = "Elan";
  const uint16_t tp_vid = 0x04f3;
  const uint16_t tp_pid = 0x323b;
  const uint16_t ts_vid = 0x056a;
  const uint16_t ts_pid = 0xd4f4;
  const std::string driver_name = "ElanPS/2";
  const ui::TouchpadDevice tp = ui::TouchpadDevice(
      /*id=*/1, ui::INPUT_DEVICE_INTERNAL, /*name=*/"", /*phys=*/"",
      /*sys_path=*/base::FilePath(), tp_vid, tp_pid, /*version=*/0);
  const ui::InputDevice ts = ui::InputDevice(
      /*id=*/2, ui::INPUT_DEVICE_BLUETOOTH, /*name=*/"", /*phys=*/"",
      /*sys_path=*/base::FilePath(), ts_vid, ts_pid, /*version=*/0);

  ui::DeviceDataManagerTestApi().SetTouchpadDevices({tp});
  ui::DeviceDataManagerTestApi().SetTouchscreenDevices({{ts, gfx::Size(),
                                                         /*touch_points=*/0}});

  auto telem_info = ash::cros_healthd::mojom::TelemetryInfo::New();

  SetCrosHealthdTouchpad(telem_info, driver_name);
  ash::cros_healthd::FakeCrosHealthd::Get()
      ->SetProbeTelemetryInfoResponseForTesting(telem_info);

  /* Fetch log data. */
  ConnectedInputDevicesLogSource source;
  base::RunLoop run_loop;
  source.Fetch(fetch_callback(run_loop.QuitClosure()));
  run_loop.Run();

  /* Verify fetch_callback() has been called. */
  EXPECT_EQ(1U, num_callback_calls());
  ASSERT_EQ(3U, response().size());

  auto it = response().find("TOUCHPAD_VENDOR");
  ASSERT_NE(it, response().end());
  EXPECT_EQ(tp_vendor_name, it->second);
  it = response().find("TOUCHPAD_PID");
  ASSERT_NE(it, response().end());
  EXPECT_EQ(base::StringPrintf("0x%04x", tp_pid), it->second);
  it = response().find("TOUCHPAD_DRIVERS");
  EXPECT_EQ(driver_name, it->second);

  /* Verify fetch_callback() has not been called again. */
  EXPECT_EQ(1U, num_callback_calls());
}

TEST_F(ConnectedInputDevicesLogSourceTest, Touchscreen_single) {
  const std::string vendor_name = "Atmel";
  const uint16_t vid = 0x03eb;
  const uint16_t pid = 0x1234;

  auto input = ui::InputDevice(
      /*id=*/1, ui::INPUT_DEVICE_INTERNAL, /*name=*/"", /*phys=*/"",
      /*sys_path=*/base::FilePath(), vid, pid, /*version=*/0);
  ui::DeviceDataManagerTestApi().SetTouchscreenDevices(
      {{input, gfx::Size(), /*touch_points=*/0}});

  /* Fetch log data. */
  ConnectedInputDevicesLogSource source;
  base::RunLoop run_loop;
  source.Fetch(fetch_callback(run_loop.QuitClosure()));
  run_loop.Run();

  /* Verify fetch_callback() has been called. */
  EXPECT_EQ(1U, num_callback_calls());
  ASSERT_EQ(2U, response().size());

  auto it = response().find("TOUCHSCREEN_VENDOR");
  ASSERT_NE(it, response().end());
  EXPECT_EQ(vendor_name, it->second);
  it = response().find("TOUCHSCREEN_PID");
  ASSERT_NE(it, response().end());
  EXPECT_EQ(base::StringPrintf("0x%04x", pid), it->second);
  it = response().find("TOUCHPAD_DRIVERS");
  EXPECT_EQ(it, response().end());

  /* Verify fetch_callback() has not been called again. */
  EXPECT_EQ(1U, num_callback_calls());
}

TEST_F(ConnectedInputDevicesLogSourceTest, Touchscreen_single_other_ext) {
  const std::string t1_vendor_name = "Novatek";
  const uint16_t t1_vid = 0x0603;
  const uint16_t t1_pid = 0xd124;
  const uint16_t t2_vid = 0x1fd2;
  const uint16_t t2_pid = 0x0034;

  ui::InputDevice i1 = ui::InputDevice(
      /*id=*/1, ui::INPUT_DEVICE_INTERNAL, /*name=*/"", /*phys=*/"",
      /*sys_path=*/base::FilePath(), t1_vid, t1_pid, /*version=*/0);
  ui::InputDevice i2 = ui::InputDevice(
      /*id=*/2, ui::INPUT_DEVICE_BLUETOOTH, /*name=*/"", /*phys=*/"",
      /*sys_path=*/base::FilePath(), t2_vid, t2_pid, /*version=*/0);
  ui::TouchscreenDevice ts1 =
      ui::TouchscreenDevice(i1, gfx::Size(), /*touch_points=*/0);
  ui::TouchscreenDevice ts2 =
      ui::TouchscreenDevice(i2, gfx::Size(), /*touch_points=*/0);

  ui::DeviceDataManagerTestApi().SetTouchscreenDevices({ts1, ts2});

  /* Fetch log data. */
  ConnectedInputDevicesLogSource source;
  base::RunLoop run_loop;
  source.Fetch(fetch_callback(run_loop.QuitClosure()));
  run_loop.Run();

  /* Verify fetch_callback() has been called. */
  EXPECT_EQ(1U, num_callback_calls());
  ASSERT_EQ(2U, response().size());

  auto it = response().find("TOUCHSCREEN_VENDOR");
  ASSERT_NE(it, response().end());
  EXPECT_EQ(t1_vendor_name, it->second);
  it = response().find("TOUCHSCREEN_PID");
  ASSERT_NE(it, response().end());
  EXPECT_EQ(base::StringPrintf("0x%04x", t1_pid), it->second);
  it = response().find("TOUCHPAD_DRIVERS");
  EXPECT_EQ(it, response().end());

  /* Verify fetch_callback() has not been called again. */
  EXPECT_EQ(1U, num_callback_calls());
}

TEST_F(ConnectedInputDevicesLogSourceTest, Touchscreen_single_tp_ext) {
  const uint16_t tp_vid = 0x04f3;
  const uint16_t tp_pid = 0x323b;
  const std::string ts_vendor_name = "Wacom";
  const uint16_t ts_vid = 0x056a;
  const uint16_t ts_pid = 0xd4f4;
  const ui::TouchpadDevice tp = ui::TouchpadDevice(
      /*id=*/1, ui::INPUT_DEVICE_USB, /*name=*/"", /*phys=*/"",
      /*sys_path=*/base::FilePath(), tp_vid, tp_pid, /*version=*/0);
  const ui::InputDevice ts = ui::InputDevice(
      /*id=*/2, ui::INPUT_DEVICE_INTERNAL, /*name=*/"", /*phys=*/"",
      /*sys_path=*/base::FilePath(), ts_vid, ts_pid, /*version=*/0);

  ui::DeviceDataManagerTestApi().SetTouchpadDevices({tp});
  ui::DeviceDataManagerTestApi().SetTouchscreenDevices(
      {{ts, gfx::Size(), /*touch_points=*/0}});

  /* Fetch log data. */
  ConnectedInputDevicesLogSource source;
  base::RunLoop run_loop;
  source.Fetch(fetch_callback(run_loop.QuitClosure()));
  run_loop.Run();

  /* Verify fetch_callback() has been called. */
  EXPECT_EQ(1U, num_callback_calls());
  ASSERT_EQ(2U, response().size());

  auto it = response().find("TOUCHSCREEN_VENDOR");
  ASSERT_NE(it, response().end());
  EXPECT_EQ(ts_vendor_name, it->second);
  it = response().find("TOUCHSCREEN_PID");
  ASSERT_NE(it, response().end());
  EXPECT_EQ(base::StringPrintf("0x%04x", ts_pid), it->second);
  it = response().find("TOUCHPAD_DRIVERS");
  EXPECT_EQ(it, response().end());

  /* Verify fetch_callback() has not been called again. */
  EXPECT_EQ(1U, num_callback_calls());
}

TEST_F(ConnectedInputDevicesLogSourceTest, Touchpad_single_touchscreen_single) {
  const std::string tp_vendor_name = "Zinitix";
  const uint16_t tp_vid = 0x14e5;
  const uint16_t tp_pid = 0x0901;
  std::string driver_name = "psmouse";
  const std::string ts_vendor_name = "Google";
  const uint16_t ts_vid = 0x18d1;
  const uint16_t ts_pid = 0x5400;

  ui::DeviceDataManagerTestApi().SetTouchpadDevices({ui::TouchpadDevice(
      /*id=*/1, ui::INPUT_DEVICE_INTERNAL, /*name=*/"", /*phys=*/"",
      /*sys_path=*/base::FilePath(), tp_vid, tp_pid, /*version=*/0)});

  const auto input = ui::InputDevice(
      /*id=*/2, ui::INPUT_DEVICE_INTERNAL, /*name=*/"", /*phys=*/"",
      /*sys_path=*/base::FilePath(), ts_vid, ts_pid, /*version=*/0);
  ui::DeviceDataManagerTestApi().SetTouchscreenDevices(
      {{input, gfx::Size(), /*touch_points=*/0}});

  auto telem_info = ash::cros_healthd::mojom::TelemetryInfo::New();

  SetCrosHealthdTouchpad(telem_info, driver_name);
  ash::cros_healthd::FakeCrosHealthd::Get()
      ->SetProbeTelemetryInfoResponseForTesting(telem_info);

  /* Fetch log data. */
  ConnectedInputDevicesLogSource source;
  base::RunLoop run_loop;
  source.Fetch(fetch_callback(run_loop.QuitClosure()));
  run_loop.Run();

  /* Verify fetch_callback() has been called. */
  EXPECT_EQ(1U, num_callback_calls());
  ASSERT_EQ(5U, response().size());

  auto it = response().find("TOUCHPAD_VENDOR");
  ASSERT_NE(it, response().end());
  EXPECT_EQ(tp_vendor_name, it->second);
  it = response().find("TOUCHPAD_PID");
  ASSERT_NE(it, response().end());
  EXPECT_EQ(base::StringPrintf("0x%04x", tp_pid), it->second);
  it = response().find("TOUCHSCREEN_VENDOR");
  ASSERT_NE(it, response().end());
  EXPECT_EQ(ts_vendor_name, it->second);
  it = response().find("TOUCHSCREEN_PID");
  ASSERT_NE(it, response().end());
  EXPECT_EQ(base::StringPrintf("0x%04x", ts_pid), it->second);
  it = response().find("TOUCHPAD_DRIVERS");
  EXPECT_EQ(driver_name, it->second);

  /* Verify fetch_callback() has not been called again. */
  EXPECT_EQ(1U, num_callback_calls());
}

TEST_F(ConnectedInputDevicesLogSourceTest, Touchpad_unknown_vendor_single) {
  const uint16_t pid = 0x0002;
  std::string driver_name = "psmouse";

  ui::DeviceDataManagerTestApi().SetTouchpadDevices({ui::TouchpadDevice(
      /*id=*/1, ui::INPUT_DEVICE_INTERNAL, /*name=*/"", /*phys=*/"",
      /*sys_path=*/base::FilePath(), unknown_vid, pid, /*version=*/0)});

  auto telem_info = ash::cros_healthd::mojom::TelemetryInfo::New();

  SetCrosHealthdTouchpad(telem_info, driver_name);
  ash::cros_healthd::FakeCrosHealthd::Get()
      ->SetProbeTelemetryInfoResponseForTesting(telem_info);

  /* Fetch log data. */
  ConnectedInputDevicesLogSource source;
  base::RunLoop run_loop;
  source.Fetch(fetch_callback(run_loop.QuitClosure()));
  run_loop.Run();

  /* Verify fetch_callback() has been called. */
  EXPECT_EQ(1U, num_callback_calls());
  ASSERT_EQ(3U, response().size());

  auto it = response().find("TOUCHPAD_VENDOR");
  ASSERT_NE(it, response().end());
  EXPECT_EQ(unknown_vendor_name, it->second);
  it = response().find("TOUCHPAD_PID");
  ASSERT_NE(it, response().end());
  EXPECT_EQ(base::StringPrintf("0x%04x", pid), it->second);
  it = response().find("TOUCHPAD_DRIVERS");
  EXPECT_EQ(driver_name, it->second);

  /* Verify fetch_callback() has not been called again. */
  EXPECT_EQ(1U, num_callback_calls());
}

TEST_F(ConnectedInputDevicesLogSourceTest, Touchscreen_unknown_vendor_single) {
  const uint16_t pid = 0x0003;
  const auto input = ui::InputDevice(
      /*id=*/1, ui::INPUT_DEVICE_INTERNAL, /*name=*/"", /*phys=*/"",
      /*sys_path=*/base::FilePath(), unknown_vid, pid, /*version=*/0);

  ui::DeviceDataManagerTestApi().SetTouchscreenDevices(
      {{input, gfx::Size(), /*touch_points=*/0}});

  /* Fetch log data. */
  ConnectedInputDevicesLogSource source;
  base::RunLoop run_loop;
  source.Fetch(fetch_callback(run_loop.QuitClosure()));
  run_loop.Run();

  /* Verify fetch_callback() has been called. */
  EXPECT_EQ(1U, num_callback_calls());
  ASSERT_EQ(2U, response().size());

  auto it = response().find("TOUCHSCREEN_VENDOR");
  ASSERT_NE(it, response().end());
  EXPECT_EQ(unknown_vendor_name, it->second);
  it = response().find("TOUCHSCREEN_PID");
  ASSERT_NE(it, response().end());
  EXPECT_EQ(base::StringPrintf("0x%04x", pid), it->second);
  it = response().find("TOUCHPAD_DRIVERS");
  EXPECT_EQ(it, response().end());

  /* Verify fetch_callback() has not been called again. */
  EXPECT_EQ(1U, num_callback_calls());
}

TEST_F(ConnectedInputDevicesLogSourceTest, No_internal_touch_input) {
  const uint16_t tp_vid = 0x03eb;
  const uint16_t tp_pid = 0x1234;
  const uint16_t ts_vid = 0x04b4;
  const uint16_t ts_pid = 0x0763;

  ui::DeviceDataManagerTestApi().SetTouchpadDevices({ui::TouchpadDevice(
      /*id=*/1, ui::INPUT_DEVICE_USB, /*name=*/"", /*phys=*/"",
      /*sys_path=*/base::FilePath(), tp_vid, tp_pid, /*version=*/0)});

  const auto input = ui::InputDevice(
      /*id=*/2, ui::INPUT_DEVICE_BLUETOOTH, /*name=*/"", /*phys=*/"",
      /*sys_path=*/base::FilePath(), ts_vid, ts_pid, /*version=*/0);
  ui::DeviceDataManagerTestApi().SetTouchscreenDevices(
      {{input, gfx::Size(), /*touch_points=*/0}});

  /* Fetch log data. */
  ConnectedInputDevicesLogSource source;
  base::RunLoop run_loop;
  source.Fetch(fetch_callback(run_loop.QuitClosure()));
  run_loop.Run();

  /* Verify fetch_callback() has been called. */
  EXPECT_EQ(1U, num_callback_calls());
  ASSERT_EQ(0U, response().size());

  /* If size 0, then no point in checking ids. */

  /* Verify fetch_callback() has not been called again. */
  EXPECT_EQ(1U, num_callback_calls());
}

}  // namespace system_logs