chromium/chrome/browser/devtools/device/usb/android_usb_browsertest.cc

// Copyright 2014 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#ifdef UNSAFE_BUFFERS_BUILD
// TODO(crbug.com/40285824): Remove this and convert code to safer constructs.
#pragma allow_unsafe_buffers
#endif

#include <stddef.h>
#include <stdint.h>

#include <algorithm>
#include <unordered_map>
#include <utility>

#include "base/containers/contains.h"
#include "base/containers/queue.h"
#include "base/containers/span.h"
#include "base/functional/bind.h"
#include "base/location.h"
#include "base/memory/ptr_util.h"
#include "base/memory/raw_ptr.h"
#include "base/memory/ref_counted_memory.h"
#include "base/run_loop.h"
#include "base/strings/utf_string_conversions.h"
#include "base/task/single_thread_task_runner.h"
#include "chrome/browser/devtools/device/adb/mock_adb_server.h"
#include "chrome/browser/devtools/device/devtools_android_bridge.h"
#include "chrome/browser/devtools/device/usb/android_usb_device.h"
#include "chrome/browser/devtools/device/usb/usb_device_provider.h"
#include "chrome/browser/ui/browser.h"
#include "chrome/test/base/in_process_browser_test.h"
#include "content/public/browser/browser_task_traits.h"
#include "content/public/browser/browser_thread.h"
#include "content/public/test/browser_test.h"
#include "content/public/test/test_utils.h"
#include "mojo/public/cpp/bindings/pending_receiver.h"
#include "mojo/public/cpp/bindings/pending_remote.h"
#include "mojo/public/cpp/bindings/self_owned_receiver.h"
#include "services/device/public/cpp/test/fake_usb_device.h"
#include "services/device/public/cpp/test/fake_usb_device_info.h"
#include "services/device/public/cpp/test/fake_usb_device_manager.h"
#include "services/device/public/mojom/usb_device.mojom.h"
#include "services/device/public/mojom/usb_enumeration_options.mojom.h"
#include "services/device/public/mojom/usb_manager.mojom.h"
#include "testing/gtest/include/gtest/gtest.h"

BrowserThread;

FakeUsbDevice;
FakeUsbDeviceInfo;
FakeUsbDeviceManager;
UsbAlternateInterfaceInfo;
UsbConfigurationInfo;
UsbConfigurationInfoPtr;
UsbDevice;
UsbEndpointInfo;
UsbEndpointInfoPtr;
UsbInterfaceInfo;
UsbInterfaceInfoPtr;
UsbTransferDirection;
UsbTransferStatus;
UsbTransferType;

namespace {

struct NoConfigTraits {};

struct AndroidTraits {};

struct NonAndroidTraits {};

struct BreakingAndroidTraits {};

const uint32_t kMaxPayload =;
const uint32_t kVersion =;
const uint8_t kAndroidConfigValue =;

const char kDeviceManufacturer[] =;
const char kDeviceModel[] =;
const char kDeviceSerial[] =;

UsbConfigurationInfoPtr ConstructAndroidConfig(uint8_t class_code,
                                               uint8_t subclass_code,
                                               uint8_t protocol_code) {}

class FakeAndroidUsbDeviceInfo : public FakeUsbDeviceInfo {};

template <class T>
scoped_refptr<FakeAndroidUsbDeviceInfo> ConstructFakeUsbDevice() {}

class MockLocalSocket : public MockAndroidConnection::Delegate {};

class FakeAndroidUsbDevice : public FakeUsbDevice {};

class FakeAndroidUsbManager : public FakeUsbDeviceManager {};

class FakeUsbManagerForCheckingTraits : public FakeAndroidUsbManager {};

class DevToolsAndroidBridgeWarmUp
    : public DevToolsAndroidBridge::DeviceCountListener {};

class AndroidUsbDiscoveryTest : public InProcessBrowserTest {};

class AndroidUsbCountTest : public AndroidUsbDiscoveryTest {};

class AndroidUsbTraitsTest : public AndroidUsbDiscoveryTest {};

class AndroidBreakingUsbTest : public AndroidUsbDiscoveryTest {};

class AndroidNoConfigUsbTest : public AndroidUsbDiscoveryTest {};

class MockListListener : public DevToolsAndroidBridge::DeviceListListener {};

class MockCountListener : public DevToolsAndroidBridge::DeviceCountListener {};

class MockCountListenerWithReAdd : public MockCountListener {};

class MockCountListenerWithReAddWhileQueued : public MockCountListener {};

class MockCountListenerForCheckingTraits : public MockCountListener {};

}  // namespace

IN_PROC_BROWSER_TEST_F(AndroidUsbDiscoveryTest, TestDeviceDiscovery) {}

IN_PROC_BROWSER_TEST_F(AndroidBreakingUsbTest, TestDeviceBreaking) {}

IN_PROC_BROWSER_TEST_F(AndroidNoConfigUsbTest, TestDeviceNoConfig) {}

IN_PROC_BROWSER_TEST_F(AndroidUsbCountTest,
                       TestNoMultipleCallsRemoveInCallback) {}

IN_PROC_BROWSER_TEST_F(AndroidUsbCountTest,
                       TestNoMultipleCallsRemoveAddInCallback) {}

IN_PROC_BROWSER_TEST_F(AndroidUsbCountTest,
                       TestNoMultipleCallsRemoveAddOnStart) {}

IN_PROC_BROWSER_TEST_F(AndroidUsbCountTest,
                       TestNoMultipleCallsRemoveAddWhileQueued) {}

IN_PROC_BROWSER_TEST_F(AndroidUsbTraitsTest, TestDeviceCounting) {}