#ifdef UNSAFE_BUFFERS_BUILD
#pragma allow_unsafe_buffers
#endif
#include "components/search_engines/enterprise/site_search_policy_handler.h"
#include "base/strings/string_number_conversions.h"
#include "base/strings/stringprintf.h"
#include "base/strings/utf_string_conversions.h"
#include "base/test/scoped_feature_list.h"
#include "components/omnibox/common/omnibox_features.h"
#include "components/policy/core/browser/configuration_policy_pref_store.h"
#include "components/policy/core/browser/configuration_policy_pref_store_test.h"
#include "components/policy/core/browser/policy_error_map.h"
#include "components/policy/core/common/policy_map.h"
#include "components/policy/core/common/policy_types.h"
#include "components/policy/core/common/schema.h"
#include "components/policy/policy_constants.h"
#include "components/prefs/pref_value_map.h"
#include "components/search_engines/default_search_manager.h"
#include "components/search_engines/enterprise/enterprise_site_search_manager.h"
#include "components/search_engines/template_url_data.h"
#include "components/strings/grit/components_strings.h"
#include "testing/gtest/include/gtest/gtest.h"
#include "ui/base/l10n/l10n_util.h"
AllOf;
ElementsAre;
namespace policy {
namespace {
struct TestProvider { … };
TestProvider kValidTestProviders[] = …;
TestProvider kMissingRequiredFieldsTestProviders[] = …;
TestProvider kEmptyFieldTestProviders[] = …;
TestProvider kUnknownFieldTestProviders[] = …;
TestProvider kShortcutNotUniqueTestProviders[] = …;
TestProvider kNoUniqueShortcutTestProviders[] = …;
TestProvider kShortcutWithSpacesTestProviders[] = …;
TestProvider kShortcutStartsWithAtTestProviders[] = …;
TestProvider kInvalidUrlTestProviders[] = …;
constexpr char kDSPKeyword[] = …;
TestProvider kShortcutSameAsDSPKeywordTestProviders[] = …;
TestProvider kNonHttpsUrlTestProviders[] = …;
TestProvider kTestProvidersWithFeaturedEntries[] = …;
base::Value::Dict GenerateSiteSearchPolicyEntry(const std::string& name,
const std::string& shortcut,
const std::string& url,
bool featured_by_policy) { … }
base::Value::Dict GenerateSiteSearchPolicyEntry(TestProvider test_case) { … }
MATCHER_P2(HasStringField,
field_name,
expected_value,
base::StringPrintf("%s string field `%s` with value `%s`",
negation ? "does not contain" : "contains",
field_name,
expected_value.c_str())) { … }
MATCHER_P2(HasBooleanField,
field_name,
expected_value,
base::StringPrintf("%s boolean field `%s` with value `%d`",
negation ? "does not contain" : "contains",
field_name,
expected_value)) { … }
MATCHER_P2(HasIntegerField,
field_name,
expected_value,
base::StringPrintf("%s integer field `%s` with value `%d`",
negation ? "does not contain" : "contains",
field_name,
expected_value)) { … }
MATCHER_P(HasDoubleField,
field_name,
base::StringPrintf("%s double field `%s` with non-zero value",
negation ? "does not contain" : "contains",
field_name)) { … }
testing::Matcher<const base::Value&> IsSiteSearchEntry(TestProvider test_case,
bool featured) { … }
testing::Matcher<const base::Value&> IsNonFeaturedSiteSearchEntry(
TestProvider test_case) { … }
testing::Matcher<const base::Value&> IsFeaturedSiteSearchEntry(
TestProvider test_case) { … }
MATCHER_P(HasValidationError,
expected_str,
base::StringPrintf("%s error message `%s` for `SiteSearchSettings`",
negation ? "does not contain" : "contains",
base::UTF16ToUTF8(expected_str).c_str())) { … }
}
TEST(SiteSearchPolicyHandlerTest, FeatureDisabled) { … }
TEST(SiteSearchPolicyHandlerTest, PolicyNotSet) { … }
TEST(SiteSearchPolicyHandlerTest, ValidSiteSearchEntries) { … }
TEST(SiteSearchPolicyHandlerTest, InvalidFormat) { … }
TEST(SiteSearchPolicyHandlerTest, TooManySiteSearchEntries) { … }
TEST(SiteSearchPolicyHandlerTest, TooManyFeaturedSiteSearchEntries) { … }
TEST(SiteSearchPolicyHandlerTest, MissingRequiredField) { … }
TEST(SiteSearchPolicyHandlerTest, ShortcutNotUnique) { … }
TEST(SiteSearchPolicyHandlerTest, NoUniqueShortcut) { … }
TEST(SiteSearchPolicyHandlerTest, EmptyRequiredField) { … }
TEST(SiteSearchPolicyHandlerTest, UnknownField) { … }
TEST(SiteSearchPolicyHandlerTest, ShortcutWithSpace) { … }
TEST(SiteSearchPolicyHandlerTest, ShortcutStartsWithAt) { … }
TEST(SiteSearchPolicyHandlerTest, InvalidUrl) { … }
TEST(SiteSearchPolicyHandlerTest, ShortcutSameAsDSPKeyword_DSPEnabledNotSet) { … }
TEST(SiteSearchPolicyHandlerTest, ShortcutSameAsDSPKeyword_DSPDisabled) { … }
TEST(SiteSearchPolicyHandlerTest, ShortcutSameAsDSPKeyword_DSPEnabled) { … }
TEST(SiteSearchPolicyHandlerTest, NonHttpsUrl) { … }
TEST(SiteSearchPolicyHandlerTest, NoValidEntry) { … }
TEST(SiteSearchPolicyHandlerTest, FeaturedSiteSearchEntries) { … }
}