#include "chrome/browser/usb/chrome_usb_delegate.h"
#include <optional>
#include <string_view>
#include "base/barrier_closure.h"
#include "base/test/gmock_callback_support.h"
#include "base/test/test_future.h"
#include "build/build_config.h"
#include "chrome/browser/usb/usb_chooser_context.h"
#include "chrome/browser/usb/usb_chooser_context_factory.h"
#include "chrome/browser/usb/usb_connection_tracker.h"
#include "chrome/browser/usb/usb_connection_tracker_factory.h"
#include "chrome/common/chrome_features.h"
#include "chrome/test/base/chrome_render_view_host_test_harness.h"
#include "chrome/test/base/testing_browser_process.h"
#include "chrome/test/base/testing_profile_manager.h"
#include "content/public/browser/web_contents.h"
#include "content/public/test/embedded_worker_instance_test_harness.h"
#include "content/public/test/test_renderer_host.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 "testing/gmock/include/gmock/gmock.h"
#include "testing/gtest/include/gtest/gtest.h"
#include "third_party/blink/public/mojom/usb/web_usb_service.mojom.h"
#include "url/gurl.h"
#if BUILDFLAG(ENABLE_EXTENSIONS)
#include "base/command_line.h"
#include "base/values.h"
#include "build/chromeos_buildflags.h"
#include "chrome/browser/extensions/extension_service.h"
#include "chrome/browser/extensions/test_extension_system.h"
#include "extensions/browser/extension_registry.h"
#include "extensions/buildflags/buildflags.h"
#include "extensions/common/extension.h"
#include "extensions/common/extension_builder.h"
#endif
namespace {
RunClosure;
RunOnceCallback;
RunOnceClosure;
TestFuture;
_;
NiceMock;
constexpr std::string_view kDefaultTestUrl{ … };
constexpr std::string_view kCrossOriginTestUrl{ … };
#if BUILDFLAG(ENABLE_EXTENSIONS)
constexpr std::string_view kExtensionId{ … };
constexpr char kAllowlistedImprivataExtensionId[] = …;
constexpr char kAllowlistedSmartCardExtensionId[] = …;
#endif
ACTION_P2(ExpectGuidAndThen, expected_guid, callback) { … }
void GetDevicesBlocking(blink::mojom::WebUsbService* service,
const std::set<std::string>& expected_guids) { … }
device::mojom::UsbOpenDeviceResultPtr NewUsbOpenDeviceSuccess() { … }
#if BUILDFLAG(ENABLE_EXTENSIONS)
scoped_refptr<device::FakeUsbDeviceInfo> CreateFakeUsbDeviceInfo() { … }
scoped_refptr<device::FakeUsbDeviceInfo> CreateFakeSmartCardDeviceInfo() { … }
#endif
class MockDeviceManagerClient
: public UsbChooserContext::UsbDeviceManagerClient { … };
class MockUsbConnectionTracker : public UsbConnectionTracker { … };
class ChromeUsbTestHelper { … };
class ChromeUsbDelegateRenderFrameTestBase
: public ChromeRenderViewHostTestHarness,
public ChromeUsbTestHelper { … };
class ChromeUsbDelegateServiceWorkerTestBase
: public content::EmbeddedWorkerInstanceTestHarness,
public ChromeUsbTestHelper { … };
class ChromeUsbDelegateRenderFrameTest
: public ChromeUsbDelegateRenderFrameTestBase { … };
class ChromeUsbDelegateServiceWorkerTest
: public ChromeUsbDelegateServiceWorkerTestBase { … };
#if BUILDFLAG(ENABLE_EXTENSIONS)
class DisableWebUsbOnExtensionServiceWorkerHelper { … };
class ChromeUsbDelegateExtensionRenderFrameTest
: public ChromeUsbDelegateRenderFrameTestBase { … };
class ChromeUsbDelegateImprivataExtensionRenderFrameTest
: public ChromeUsbDelegateRenderFrameTestBase { … };
class ChromeUsbDelegateSmartCardExtensionRenderFrameTest
: public ChromeUsbDelegateRenderFrameTestBase { … };
class ChromeUsbDelegateExtensionRenderFrameFeatureDisabledTest
: public ChromeUsbDelegateRenderFrameTestBase,
public DisableWebUsbOnExtensionServiceWorkerHelper { … };
class ChromeUsbDelegateExtensionServiceWorkerTest
: public ChromeUsbDelegateServiceWorkerTestBase { … };
class ChromeUsbDelegateExtensionServiceWorkerFeatureDisabledTest
: public ChromeUsbDelegateServiceWorkerTestBase,
public DisableWebUsbOnExtensionServiceWorkerHelper { … };
class ChromeUsbDelegateImprivataExtensionServiceWorkerTest
: public ChromeUsbDelegateServiceWorkerTestBase { … };
class ChromeUsbDelegateSmartCardExtensionServiceWorkerTest
: public ChromeUsbDelegateServiceWorkerTestBase { … };
#endif
}
TEST_F(ChromeUsbDelegateRenderFrameTest, NoPermissionDevice) { … }
TEST_F(ChromeUsbDelegateRenderFrameTest, ReconnectDeviceManager) { … }
TEST_F(ChromeUsbDelegateRenderFrameTest, RevokeDevicePermission) { … }
TEST_F(ChromeUsbDelegateRenderFrameTest, OpenAndCloseDevice) { … }
TEST_F(ChromeUsbDelegateRenderFrameTest, OpenAndDisconnectDevice) { … }
TEST_F(ChromeUsbDelegateRenderFrameTest, OpenAndNavigateCrossOrigin) { … }
TEST_F(ChromeUsbDelegateServiceWorkerTest, WebUsbServiceNotConnected) { … }
#if BUILDFLAG(ENABLE_EXTENSIONS)
TEST_F(ChromeUsbDelegateExtensionRenderFrameTest, NoPermissionDevice) { … }
TEST_F(ChromeUsbDelegateExtensionRenderFrameTest, ReconnectDeviceManager) { … }
TEST_F(ChromeUsbDelegateExtensionRenderFrameTest, RevokeDevicePermission) { … }
TEST_F(ChromeUsbDelegateExtensionRenderFrameTest, OpenAndCloseDevice) { … }
TEST_F(ChromeUsbDelegateExtensionRenderFrameTest, OpenAndDisconnectDevice) { … }
TEST_F(ChromeUsbDelegateImprivataExtensionRenderFrameTest,
AllowlistedImprivataExtension) { … }
TEST_F(ChromeUsbDelegateSmartCardExtensionRenderFrameTest,
AllowlistedSmartCardConnectorExtension) { … }
TEST_F(ChromeUsbDelegateExtensionRenderFrameFeatureDisabledTest,
OpenAndCloseDevice) { … }
TEST_F(ChromeUsbDelegateExtensionRenderFrameFeatureDisabledTest,
OpenAndDisconnectDevice) { … }
TEST_F(ChromeUsbDelegateExtensionServiceWorkerFeatureDisabledTest,
WebUsbServiceNotConnected) { … }
TEST_F(ChromeUsbDelegateImprivataExtensionServiceWorkerTest,
AllowlistedImprivataExtension) { … }
TEST_F(ChromeUsbDelegateSmartCardExtensionServiceWorkerTest,
AllowlistedSmartCardConnectorExtension) { … }
TEST_F(ChromeUsbDelegateExtensionServiceWorkerTest, NoPermissionDevice) { … }
TEST_F(ChromeUsbDelegateExtensionServiceWorkerTest, ReconnectDeviceManager) { … }
TEST_F(ChromeUsbDelegateExtensionServiceWorkerTest, RevokeDevicePermission) { … }
TEST_F(ChromeUsbDelegateExtensionServiceWorkerTest, OpenAndCloseDevice) { … }
TEST_F(ChromeUsbDelegateExtensionServiceWorkerTest, OpenAndDisconnectDevice) { … }
#endif
TEST(ChromeUsbDelegateBrowserContextTest, BrowserContextIsNull) { … }