chromium/chrome/browser/serial/serial_chooser_context_unittest.cc

// Copyright 2019 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/serial/serial_chooser_context.h"

#include <string_view>

#include "base/memory/raw_ptr.h"
#include "base/run_loop.h"
#include "base/scoped_observation.h"
#include "base/test/metrics/histogram_tester.h"
#include "base/test/scoped_feature_list.h"
#include "base/test/test_future.h"
#include "base/test/values_test_util.h"
#include "build/build_config.h"
#include "build/chromeos_buildflags.h"
#include "chrome/browser/content_settings/host_content_settings_map_factory.h"
#include "chrome/browser/serial/serial_blocklist.h"
#include "chrome/browser/serial/serial_chooser_context_factory.h"
#include "chrome/browser/serial/serial_chooser_histograms.h"
#include "chrome/common/pref_names.h"
#include "chrome/test/base/scoped_testing_local_state.h"
#include "chrome/test/base/testing_browser_process.h"
#include "chrome/test/base/testing_profile.h"
#include "chrome/test/base/testing_profile_manager.h"
#include "components/content_settings/core/browser/host_content_settings_map.h"
#include "components/content_settings/core/common/content_settings.h"
#include "components/content_settings/core/common/pref_names.h"
#include "components/permissions/test/object_permission_context_base_mock_permission_observer.h"
#include "components/sync_preferences/testing_pref_service_syncable.h"
#include "content/public/test/browser_task_environment.h"
#include "services/device/public/cpp/test/fake_serial_port_manager.h"
#include "services/device/public/mojom/serial.mojom.h"
#include "testing/gmock/include/gmock/gmock.h"
#include "testing/gtest/include/gtest/gtest.h"

#if BUILDFLAG(IS_CHROMEOS_ASH)
#include "chrome/browser/ash/login/users/fake_chrome_user_manager.h"
#include "components/account_id/account_id.h"
#include "components/user_manager/scoped_user_manager.h"
#endif

namespace {

InvokeFuture;
ParseJson;
TestFuture;
SettingSource;
_;
NiceMock;

constexpr char kTestUserEmail[] =;

class MockPortObserver : public SerialChooserContext::PortObserver {};

device::mojom::SerialPortInfoPtr CreatePersistentBluetoothPort(
    std::optional<std::string> name,
    const std::string& bluetooth_address) {}

device::mojom::SerialPortInfoPtr CreatePersistentUsbPort(
    std::optional<std::string> name,
    const std::string& persistent_id) {}

class SerialChooserContextTestBase {};

class SerialChooserContextTest : public SerialChooserContextTestBase,
                                 public testing::Test {};

class SerialChooserContextAffiliatedTest : public SerialChooserContextTestBase,
                                           public testing::TestWithParam<bool> {};

}  // namespace

TEST_F(SerialChooserContextTest, GrantAndRevokeEphemeralPermission) {}

TEST_F(SerialChooserContextTest, RevokeEphemeralPermissionByWebsite) {}

TEST_F(SerialChooserContextTest, GrantAndCheckPersistentUsbPermission) {}

TEST_F(SerialChooserContextTest, GrantAndCheckPersistentBluetoothPermission) {}

TEST_F(SerialChooserContextTest, GrantAndRevokePersistentUsbPermission) {}

TEST_F(SerialChooserContextTest, GrantAndRevokePersistentBluetoothPermission) {}

TEST_F(SerialChooserContextTest, RevokePersistentPermissionByWebsite) {}

TEST_F(SerialChooserContextTest, EphemeralPermissionRevokedOnDisconnect) {}

TEST_F(SerialChooserContextTest, PersistenceRequiresDisplayName) {}

TEST_F(SerialChooserContextTest, PersistentPermissionNotRevokedOnDisconnect) {}

TEST_F(SerialChooserContextTest, GuardPermission) {}

TEST_F(SerialChooserContextTest, PolicyGuardPermission) {}

TEST_F(SerialChooserContextTest, PolicyAskForUrls) {}

TEST_F(SerialChooserContextTest, PolicyBlockedForUrls) {}

TEST_F(SerialChooserContextTest, BluetoothPortConnectedState) {}

TEST_P(SerialChooserContextAffiliatedTest, PolicyAllowForUrls) {}

TEST_P(SerialChooserContextAffiliatedTest,
       PolicyAllowForUrlsDescriptionStrings) {}

TEST_P(SerialChooserContextAffiliatedTest, PolicyAllowOverridesGuard) {}

TEST_P(SerialChooserContextAffiliatedTest, PolicyAllowOverridesBlocked) {}

TEST_F(SerialChooserContextTest, Blocklist) {}

TEST_P(SerialChooserContextAffiliatedTest, BlocklistOverridesPolicy) {}

// Boolean parameter means if user is affiliated on the device. Affiliated
// users belong to the domain that owns the device and is only meaningful
// on Chrome OS.
//
// The SerialAllowAllPortsForUrls and SerialAllowUsbDevicesForUrls policies
// only take effect for sffiliated users.
INSTANTIATE_TEST_SUITE_P();