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 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130
|
// Copyright 2024 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef CHROME_BROWSER_CONTROLLED_FRAME_CONTROLLED_FRAME_PERMISSION_REQUEST_TEST_BASE_H_
#define CHROME_BROWSER_CONTROLLED_FRAME_CONTROLLED_FRAME_PERMISSION_REQUEST_TEST_BASE_H_
#include <optional>
#include <set>
#include <string>
#include "base/functional/callback.h"
#include "chrome/browser/controlled_frame/controlled_frame_test_base.h"
#include "components/content_settings/core/common/content_settings_types.h"
#include "services/network/public/mojom/permissions_policy/permissions_policy_feature.mojom-forward.h"
#include "testing/gtest/include/gtest/gtest.h"
namespace base {
class CommandLine;
} // namespace base
namespace content {
class RenderFrameHost;
} // namespace content
namespace controlled_frame {
struct PermissionRequestTestCase {
PermissionRequestTestCase();
~PermissionRequestTestCase();
// Javascript to invoke and verify the permission request from the embedded
// content.
std::string test_script;
// The name of the permission in the event.
std::string permission_name;
// Policy features the permission depends on.
std::set<network::mojom::PermissionsPolicyFeature> policy_features;
// Corresponding ContentSettingsType(s) of the permission.
std::set<ContentSettingsType> content_settings_type;
// Wait for js 'document.hasFocus()';
// Default is false to not make tests longer
// where it is not necessary.
bool must_wait_for_document_focus = false;
};
enum class EmbedderPolicy {
kNoPolicy,
kNoRequestingOrigin,
kNoEmbedderOrigin,
kBothEmbedderAndRequestingOrigin
};
enum class ContentSettingsState { kDefault, kAllow, kDeny };
struct PermissionRequestTestParam {
std::string name;
bool calls_allow;
EmbedderPolicy embedder_policy;
bool allowed_by_embedder_content_settings;
ContentSettingsState embedded_origin_content_settings_state;
bool expected_success;
};
const std::vector<PermissionRequestTestParam>&
GetDefaultPermissionRequestTestParams();
struct DisabledPermissionTestCase {
DisabledPermissionTestCase();
~DisabledPermissionTestCase();
// Script to request the permission.
std::string request_script;
// Policy features the permission depends on.
std::set<network::mojom::PermissionsPolicyFeature> policy_features;
std::string success_result;
std::string failure_result;
// Wait for js 'document.hasFocus()';
// Default is false to not make tests longer
// where it is not necessary.
bool must_wait_for_document_focus = false;
};
struct DisabledPermissionTestParam {
std::string name;
bool policy_features_enabled;
bool iwa_expect_success;
bool controlled_frame_expect_success;
};
const std::vector<DisabledPermissionTestParam>&
GetDefaultDisabledPermissionTestParams();
class ControlledFramePermissionRequestTestBase
: public ControlledFrameTestBase {
protected:
// `ControlledFrameTestBase`:
void SetUpOnMainThread() override;
void SetUpCommandLine(base::CommandLine* command_line) override;
void VerifyEnabledPermission(
const PermissionRequestTestCase& test_case,
const PermissionRequestTestParam& test_param,
std::optional<base::OnceCallback<std::string(bool)>>
get_expected_result_callback = std::nullopt);
void VerifyDisabledPermission(const DisabledPermissionTestCase& test_case,
const DisabledPermissionTestParam& test_param);
void VerifyDisabledPermission(const DisabledPermissionTestCase& test_case,
const DisabledPermissionTestParam& test_param,
content::RenderFrameHost* app_frame,
content::RenderFrameHost* controlled_frame);
std::pair<content::RenderFrameHost*, content::RenderFrameHost*>
SetUpControlledFrame(const DisabledPermissionTestCase& test_case,
const DisabledPermissionTestParam& test_param);
private:
void SetUpPermissionRequestEventListener(
content::RenderFrameHost* app_frame,
const std::string& expected_permission_name,
bool allow_permission);
};
} // namespace controlled_frame
#endif // CHROME_BROWSER_CONTROLLED_FRAME_CONTROLLED_FRAME_PERMISSION_REQUEST_TEST_BASE_H_
|