#include "extensions/browser/permissions_manager.h"
#include "base/memory/raw_ptr.h"
#include "base/test/gtest_util.h"
#include "base/test/scoped_feature_list.h"
#include "extensions/browser/extension_prefs.h"
#include "extensions/browser/extension_registry.h"
#include "extensions/browser/extension_util.h"
#include "extensions/browser/extensions_test.h"
#include "extensions/browser/pref_types.h"
#include "extensions/common/extension_builder.h"
#include "extensions/common/extension_features.h"
#include "extensions/common/permissions/permissions_data.h"
#include "extensions/common/url_pattern_set.h"
#include "testing/gmock/include/gmock/gmock.h"
#include "testing/gtest/include/gtest/gtest.h"
#include "url/origin.h"
namespace {
std::unique_ptr<KeyedService> SetTestingPermissionsManager(
content::BrowserContext* browser_context) { … }
}
namespace extensions {
UserSiteSetting;
UserSiteAccess;
class PermissionsManagerUnittest : public ExtensionsTest { … };
void PermissionsManagerUnittest::SetUp() { … }
scoped_refptr<const Extension> PermissionsManagerUnittest::AddExtension(
const std::string& name) { … }
scoped_refptr<const Extension>
PermissionsManagerUnittest::AddExtensionWithAPIPermission(
const std::string& name,
const std::string& permission,
extensions::mojom::ManifestLocation location) { … }
scoped_refptr<const Extension>
PermissionsManagerUnittest::AddExtensionWithHostPermission(
const std::string& name,
const std::string& host_permission) { … }
scoped_refptr<const Extension>
PermissionsManagerUnittest::AddExtensionWithActiveTab(
const std::string& name,
extensions::mojom::ManifestLocation location) { … }
const base::Value* PermissionsManagerUnittest::GetRestrictedSitesFromPrefs() { … }
const base::Value* PermissionsManagerUnittest::GetPermittedSitesFromPrefs() { … }
std::set<url::Origin>
PermissionsManagerUnittest::GetRestrictedSitesFromManager() { … }
std::set<url::Origin>
PermissionsManagerUnittest::GetPermittedSitesFromManager() { … }
std::set<std::string>
PermissionsManagerUnittest::GetRestrictedSitesFromPermissionsData() { … }
std::set<std::string>
PermissionsManagerUnittest::GetPermittedSitesFromPermissionsData() { … }
TEST_F(PermissionsManagerUnittest, AddAndRemoveRestrictedSite) { … }
TEST_F(PermissionsManagerUnittest, AddAndRemovePermittedSite) { … }
TEST_F(PermissionsManagerUnittest, UpdateUserSiteSetting) { … }
TEST_F(PermissionsManagerUnittest, GetSiteAccess_AllUrls) { … }
TEST_F(PermissionsManagerUnittest, GetSiteAccess_RequestedUrl) { … }
TEST_F(PermissionsManagerUnittest,
GetSiteAccess_ContentScript_RequestedUrlWithPath) { … }
TEST_F(PermissionsManagerUnittest, GetSiteAccess_ActiveTab) { … }
TEST_F(PermissionsManagerUnittest, GetSiteAccess_NoHostPermissions) { … }
TEST_F(PermissionsManagerUnittest, CanAffectExtension_ByLocation) { … }
TEST_F(PermissionsManagerUnittest, CanUserSelectSiteAccess_AllUrls) { … }
TEST_F(PermissionsManagerUnittest, CanUserSelectSiteAccess_SpecificUrl) { … }
TEST_F(PermissionsManagerUnittest, CanUserSelectSiteAccess_NoHostPermissions) { … }
TEST_F(PermissionsManagerUnittest, CanUserSelectSiteAccess_ActiveTab) { … }
TEST_F(PermissionsManagerUnittest, HasActiveTabAndCanAccess_PolicyUrl) { … }
TEST_F(PermissionsManagerUnittest,
ExtensionRequestsHostPermissionsOrActiveTab) { … }
class PermissionsManagerWithPermittedSitesUnitTest
: public PermissionsManagerUnittest { … };
PermissionsManagerWithPermittedSitesUnitTest::
PermissionsManagerWithPermittedSitesUnitTest() { … }
TEST_F(PermissionsManagerWithPermittedSitesUnitTest,
AddAndRemovePermittedSite) { … }
TEST_F(PermissionsManagerWithPermittedSitesUnitTest, GrantAllExtensionsAccess) { … }
TEST_F(PermissionsManagerWithPermittedSitesUnitTest,
RestrictedAndPermittedSitesAreMutuallyExclusive) { … }
}