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
|
// Copyright 2025 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "components/permissions/test/enums_to_string.h"
#include "base/containers/fixed_flat_map.h"
#include "components/permissions/permission_request_enums.h"
#include "components/permissions/prediction_service/permission_ui_selector.h"
#include "components/permissions/request_type.h"
namespace test {
std::string_view ToString(
permissions::PermissionUiSelector::QuietUiReason ui_reason) {
using QuietUiReason = ::permissions::PermissionUiSelector::QuietUiReason;
static constexpr auto map =
base::MakeFixedFlatMap<QuietUiReason, std::string_view>(
{{QuietUiReason::kEnabledInPrefs, "EnabledInPrefs"},
{QuietUiReason::kTriggeredByCrowdDeny, "TriggeredByCrowdDeny"},
{QuietUiReason::kServicePredictedVeryUnlikelyGrant,
"ServicePredictedVeryUnlikelyGrant"},
{QuietUiReason::kOnDevicePredictedVeryUnlikelyGrant,
"OnDevicePredictedVeryUnlikelyGrant"},
{QuietUiReason::kTriggeredDueToAbusiveRequests,
"TriggeredDueToAbusiveRequests"},
{QuietUiReason::kTriggeredDueToAbusiveContent,
"TriggeredDueToAbusiveContent"},
{QuietUiReason::kTriggeredDueToDisruptiveBehavior,
"TriggeredDueToDisruptiveBehavior"}});
auto it = map.find(ui_reason);
return (it == map.end()) ? "Unknown" : it->second;
}
std::string_view ToString(permissions::RequestType request_type) {
using RequestType = ::permissions::RequestType;
static constexpr auto map =
base::MakeFixedFlatMap<RequestType, std::string_view>({
{RequestType::kArSession, "ArSession"},
#if !BUILDFLAG(IS_ANDROID)
{RequestType::kCameraPanTiltZoom, "CameraPanTiltZoom"},
#endif
{RequestType::kCameraStream, "CameraStream"},
#if !BUILDFLAG(IS_ANDROID)
{RequestType::kCapturedSurfaceControl, "CapturedSurfaceControl"},
#endif
{RequestType::kClipboard, "Clipboard"},
{RequestType::kTopLevelStorageAccess, "TopLevelStorageAccess"},
{RequestType::kDiskQuota, "DiskQuota"},
{RequestType::kFileSystemAccess, "FileSystemAccess"},
{RequestType::kGeolocation, "Geolocation"},
{RequestType::kHandTracking, "HandTracking"},
{RequestType::kIdentityProvider, "IdentityProvider"},
{RequestType::kIdleDetection, "IdleDetection"},
#if !BUILDFLAG(IS_ANDROID)
{RequestType::kLocalFonts, "LocalFonts"},
#endif
{RequestType::kLocalNetworkAccess, "LocalNetworkAccess"},
{RequestType::kMicStream, "MicStream"},
{RequestType::kMidiSysex, "MidiSysex"},
{RequestType::kMultipleDownloads, "MultipleDownloads"},
#if BUILDFLAG(IS_ANDROID)
{RequestType::kNfcDevice, "NfcDevice"},
#endif
{RequestType::kNotifications, "Notifications"},
#if !BUILDFLAG(IS_ANDROID)
{RequestType::kKeyboardLock, "KeyboardLock"},
{RequestType::kPointerLock, "PointerLock"},
#endif
#if BUILDFLAG(IS_ANDROID) || BUILDFLAG(IS_CHROMEOS) || BUILDFLAG(IS_WIN)
{RequestType::kProtectedMediaIdentifier, "ProtectedMediaIdentifier"},
#endif
#if !BUILDFLAG(IS_ANDROID)
{RequestType::kRegisterProtocolHandler, "RegisterProtocolHandler"},
#endif
#if BUILDFLAG(IS_CHROMEOS)
{RequestType::kSmartCard, "SmartCard"},
#endif
{RequestType::kStorageAccess, "StorageAccess"},
{RequestType::kVrSession, "VrSession"},
#if !BUILDFLAG(IS_ANDROID)
{RequestType::kWebAppInstallation, "WebAppInstallation"},
#endif
#if BUILDFLAG(IS_CHROMEOS) && BUILDFLAG(USE_CUPS)
{RequestType::kWebPrinting, "WebPrinting"},
#endif
{RequestType::kWindowManagement, "WindowManagement"},
});
auto it = map.find(request_type);
return (it == map.end()) ? "Unknown" : it->second;
}
std::string_view ToString(
permissions::PermissionRequestRelevance request_relevance) {
using RequestRelevance = ::permissions::PermissionRequestRelevance;
static constexpr auto map =
base::MakeFixedFlatMap<RequestRelevance, std::string_view>({
{RequestRelevance::kVeryLow, "VeryLow"},
{RequestRelevance::kLow, "Low"},
{RequestRelevance::kMedium, "Medium"},
{RequestRelevance::kHigh, "High"},
{RequestRelevance::kVeryHigh, "VeryHigh"},
});
auto it = map.find(request_relevance);
return (it == map.end()) ? "Unknown" : it->second;
}
} // namespace test
|