chromium/chrome/browser/extensions/api/permissions/permissions_api_unittest.cc

// Copyright 2016 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/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) {}

// Runs permissions.request() with the provided |args|, and returns the result
// of the API call. Expects the function to succeed.
// Populates |did_prompt_user| with whether the user would be prompted for the
// new permissions.
bool RunRequestFunction(
    const Extension& extension,
    content::BrowserContext* browser_context,
    const char* args,
    std::unique_ptr<const PermissionSet>* prompted_permissions_out) {}

}  // namespace

class PermissionsAPIUnitTest : public ExtensionServiceTestWithInstall {};

TEST_F(PermissionsAPIUnitTest, Contains) {}

TEST_F(PermissionsAPIUnitTest, ContainsAndGetAllWithRuntimeHostPermissions) {}

// Tests requesting permissions that are already granted with the
// permissions.request() API.
TEST_F(PermissionsAPIUnitTest, RequestingGrantedPermissions) {}

// Tests requesting withheld permissions with the permissions.request() API.
TEST_F(PermissionsAPIUnitTest, RequestingWithheldPermissions) {}

// Tests requesting withheld content script permissions with the
// permissions.request() API.
TEST_F(PermissionsAPIUnitTest, RequestingWithheldContentScriptPermissions) {}

// Tests requesting a withheld host permission that is both an explicit and a
// scriptable host with the permissions.request() API.
TEST_F(PermissionsAPIUnitTest,
       RequestingWithheldExplicitAndScriptablePermissionsInTheSameCall) {}

// Tests an extension re-requesting an optional host after the user removes it.
TEST_F(PermissionsAPIUnitTest, ReRequestingWithheldOptionalPermissions) {}

// Tests requesting both optional and withheld permissions in the same call to
// permissions.request().
TEST_F(PermissionsAPIUnitTest, RequestingWithheldAndOptionalPermissions) {}

// Tests requesting permissions that weren't specified in the manifest (either
// in optional permissions or in required permissions).
TEST_F(PermissionsAPIUnitTest, RequestingPermissionsNotSpecifiedInManifest) {}

// Tests requesting withheld permissions that have already been granted.
TEST_F(PermissionsAPIUnitTest, RequestingAlreadyGrantedWithheldPermissions) {}

// Test that requesting chrome:-scheme URLs is disallowed in the permissions
// API.
TEST_F(PermissionsAPIUnitTest, RequestingChromeURLs) {}

// Tests requesting the a file:-scheme pattern with and without file
// access granted. Regression test for https://crbug.com/932703.
TEST_F(PermissionsAPIUnitTest, RequestingFilePermissions) {}

class PermissionsAPISiteAccessRequestsUnitTest : public PermissionsAPIUnitTest {};

// Tests extension can only add a site access request to a tab whose current
// site has site access withheld.
TEST_F(PermissionsAPISiteAccessRequestsUnitTest, AddSiteAccessRequest_TabId) {}

// Tests extension can only add a site access request to a document whose
// current site has site access withheld.
TEST_F(PermissionsAPISiteAccessRequestsUnitTest,
       AddSiteAccessRequest_DocumentId) {}

// Tests extension can add a site access request for a site where it has
// optional host permissions.
TEST_F(PermissionsAPISiteAccessRequestsUnitTest,
       AddSiteAccessRequest_OptionalHostPermissions) {}

// Tests extension can add a site access request for a site where it wants to
// inject a content script.
TEST_F(PermissionsAPISiteAccessRequestsUnitTest,
       AddSiteAccessRequest_ContentScriptMatches) {}

// Tests extension cannot add a site access request when it only has activeTab
// permission.
TEST_F(PermissionsAPISiteAccessRequestsUnitTest,
       AddSiteAccessRequest_ActiveTab) {}

// Tests extension can add a site access request for a site with access
// withheld, even if the site was blocked by the user. Having a valid request
// doesn't mean it will be signaled to the user.
TEST_F(PermissionsAPISiteAccessRequestsUnitTest,
       AddSiteAccessRequest_UserBlockedSite) {}

// An extension with granted tab permission (via granting activeTab or running
// an extension set on click) can't add a site request.
TEST_F(PermissionsAPISiteAccessRequestsUnitTest,
       AddSiteAccessRequest_OneTimeGrantedAccess) {}

// Tests extension can remove a site access request for a tab, if request is
// existent.
TEST_F(PermissionsAPISiteAccessRequestsUnitTest,
       RemoveSiteAccessRequest_TabId) {}

// Tests extension can remove a site access request for a document, if request
// is existent.
TEST_F(PermissionsAPISiteAccessRequestsUnitTest,
       RemoveSiteAccessRequest_DocumentId) {}

}  // namespace extensions