#include "chrome/browser/extensions/api/permissions/permissions_api.h"
#include <memory>
#include <optional>
#include <string>
#include "base/json/json_reader.h"
#include "base/json/json_writer.h"
#include "base/strings/string_number_conversions.h"
#include "base/strings/stringprintf.h"
#include "base/test/scoped_feature_list.h"
#include "chrome/browser/extensions/chrome_test_extension_loader.h"
#include "chrome/browser/extensions/extension_api_unittest.h"
#include "chrome/browser/extensions/extension_service.h"
#include "chrome/browser/extensions/extension_service_test_with_install.h"
#include "chrome/browser/extensions/extension_tab_util.h"
#include "chrome/browser/extensions/extension_util.h"
#include "chrome/browser/extensions/permissions/permissions_test_util.h"
#include "chrome/browser/extensions/permissions/permissions_updater.h"
#include "chrome/browser/extensions/permissions/scripting_permissions_modifier.h"
#include "chrome/browser/extensions/tab_helper.h"
#include "chrome/test/base/testing_profile.h"
#include "components/crx_file/id_util.h"
#include "content/public/browser/web_contents.h"
#include "content/public/test/web_contents_tester.h"
#include "extensions/browser/api_test_utils.h"
#include "extensions/browser/extension_api_frame_id_map.h"
#include "extensions/browser/extension_util.h"
#include "extensions/browser/permissions_manager.h"
#include "extensions/browser/test_extension_registry_observer.h"
#include "extensions/common/extension_builder.h"
#include "extensions/common/extension_features.h"
#include "extensions/common/manifest_handlers/permissions_parser.h"
#include "extensions/common/permissions/permissions_data.h"
#include "extensions/test/test_extension_dir.h"
#include "testing/gmock/include/gmock/gmock.h"
#include "testing/gtest/include/gtest/gtest.h"
namespace extensions {
namespace {
constexpr char kNotInManifestError[] = …;
GetPatternsAsStrings;
scoped_refptr<const Extension> CreateExtensionWithPermissions(
base::Value::List permissions,
const std::string& name,
bool allow_file_access) { … }
bool RunRequestFunction(
const Extension& extension,
content::BrowserContext* browser_context,
const char* args,
std::unique_ptr<const PermissionSet>* prompted_permissions_out) { … }
}
class PermissionsAPIUnitTest : public ExtensionServiceTestWithInstall { … };
TEST_F(PermissionsAPIUnitTest, Contains) { … }
TEST_F(PermissionsAPIUnitTest, ContainsAndGetAllWithRuntimeHostPermissions) { … }
TEST_F(PermissionsAPIUnitTest, RequestingGrantedPermissions) { … }
TEST_F(PermissionsAPIUnitTest, RequestingWithheldPermissions) { … }
TEST_F(PermissionsAPIUnitTest, RequestingWithheldContentScriptPermissions) { … }
TEST_F(PermissionsAPIUnitTest,
RequestingWithheldExplicitAndScriptablePermissionsInTheSameCall) { … }
TEST_F(PermissionsAPIUnitTest, ReRequestingWithheldOptionalPermissions) { … }
TEST_F(PermissionsAPIUnitTest, RequestingWithheldAndOptionalPermissions) { … }
TEST_F(PermissionsAPIUnitTest, RequestingPermissionsNotSpecifiedInManifest) { … }
TEST_F(PermissionsAPIUnitTest, RequestingAlreadyGrantedWithheldPermissions) { … }
TEST_F(PermissionsAPIUnitTest, RequestingChromeURLs) { … }
TEST_F(PermissionsAPIUnitTest, RequestingFilePermissions) { … }
class PermissionsAPISiteAccessRequestsUnitTest : public PermissionsAPIUnitTest { … };
TEST_F(PermissionsAPISiteAccessRequestsUnitTest, AddSiteAccessRequest_TabId) { … }
TEST_F(PermissionsAPISiteAccessRequestsUnitTest,
AddSiteAccessRequest_DocumentId) { … }
TEST_F(PermissionsAPISiteAccessRequestsUnitTest,
AddSiteAccessRequest_OptionalHostPermissions) { … }
TEST_F(PermissionsAPISiteAccessRequestsUnitTest,
AddSiteAccessRequest_ContentScriptMatches) { … }
TEST_F(PermissionsAPISiteAccessRequestsUnitTest,
AddSiteAccessRequest_ActiveTab) { … }
TEST_F(PermissionsAPISiteAccessRequestsUnitTest,
AddSiteAccessRequest_UserBlockedSite) { … }
TEST_F(PermissionsAPISiteAccessRequestsUnitTest,
AddSiteAccessRequest_OneTimeGrantedAccess) { … }
TEST_F(PermissionsAPISiteAccessRequestsUnitTest,
RemoveSiteAccessRequest_TabId) { … }
TEST_F(PermissionsAPISiteAccessRequestsUnitTest,
RemoveSiteAccessRequest_DocumentId) { … }
}