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 131 132 133 134 135 136 137 138 139 140 141 142 143
|
// 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.
#include "components/search_engines/reconciling_template_url_data_holder.h"
#include <memory>
#include "base/test/scoped_feature_list.h"
#include "components/regional_capabilities/regional_capabilities_switches.h"
#include "components/search_engines/search_engines_switches.h"
#include "components/search_engines/search_engines_test_environment.h"
#include "components/search_engines/search_engines_test_util.h"
#include "components/search_engines/template_url_data.h"
#include "testing/gtest/include/gtest/gtest.h"
class ReconcilingTemplateURLDataHolderTest : public testing::Test {
public:
ReconcilingTemplateURLDataHolderTest()
: holder_(search_engines_test_environment_.prepopulate_data_resolver()) {}
void SetUp() override {
// Ensure Top Search Engine definitions consistently reported for the US.
base::CommandLine::ForCurrentProcess()->AppendSwitchASCII(
switches::kSearchEngineChoiceCountry, "US");
}
protected:
search_engines::SearchEnginesTestEnvironment search_engines_test_environment_;
ReconcilingTemplateURLDataHolder holder_;
};
TEST_F(ReconcilingTemplateURLDataHolderTest, Set_SafeWithEmptyPointer) {
holder_.SetAndReconcile({});
ASSERT_EQ(nullptr, holder_.Get());
}
TEST_F(ReconcilingTemplateURLDataHolderTest,
GetOrComputeKeyword_Get_NonEligiblePlayKeyword) {
auto supplied_engine = GenerateDummyTemplateURLData("searchengine.com");
supplied_engine->regulatory_origin = RegulatoryExtensionType::kAndroidEEA;
supplied_engine->SetURL("https://de.yahoo.com");
holder_.SetSearchEngineBypassingReconciliationForTesting(
std::move(supplied_engine));
auto [keyword, is_generated] = holder_.GetOrComputeKeyword();
ASSERT_EQ(keyword, u"searchengine.com");
ASSERT_FALSE(is_generated);
}
TEST_F(ReconcilingTemplateURLDataHolderTest,
GetOrComputeKeyword_Get_NonEligibleNotFromPlay) {
auto supplied_engine = GenerateDummyTemplateURLData("yahoo.com");
supplied_engine->regulatory_origin = RegulatoryExtensionType::kDefault;
supplied_engine->SetURL("https://de.yahoo.com");
holder_.SetSearchEngineBypassingReconciliationForTesting(
std::move(supplied_engine));
auto [keyword, is_generated] = holder_.GetOrComputeKeyword();
ASSERT_EQ(keyword, u"yahoo.com");
ASSERT_FALSE(is_generated);
}
TEST_F(ReconcilingTemplateURLDataHolderTest,
GetOrComputeKeyword_Computed_EligibleFromPlay_Yahoo) {
auto supplied_engine = GenerateDummyTemplateURLData("yahoo.com");
supplied_engine->regulatory_origin = RegulatoryExtensionType::kAndroidEEA;
supplied_engine->SetURL("https://de.yahoo.com");
holder_.SetSearchEngineBypassingReconciliationForTesting(
std::move(supplied_engine));
auto [keyword, is_generated] = holder_.GetOrComputeKeyword();
ASSERT_EQ(keyword, u"de.yahoo.com");
ASSERT_TRUE(is_generated);
}
TEST_F(ReconcilingTemplateURLDataHolderTest,
GetOrComputeKeyword_Computed_EligibleFromPlay_Seznam) {
const char* const variants[] = {"seznam.cz", "seznam.sk"};
for (const auto* variant : variants) {
auto supplied_engine = GenerateDummyTemplateURLData(variant);
supplied_engine->regulatory_origin = RegulatoryExtensionType::kAndroidEEA;
holder_.SetSearchEngineBypassingReconciliationForTesting(
std::move(supplied_engine));
auto [keyword, is_generated] = holder_.GetOrComputeKeyword();
ASSERT_EQ(keyword, u"seznam");
ASSERT_TRUE(is_generated);
}
}
TEST_F(ReconcilingTemplateURLDataHolderTest,
FindMatchingBuiltInDefinitionsById_UnknownID) {
auto engine = holder_.FindMatchingBuiltInDefinitionsById(~0);
// Expect to see no definitions.
ASSERT_FALSE(engine);
}
TEST_F(ReconcilingTemplateURLDataHolderTest,
FindMatchingBuiltInDefinitionsById_ValidID_CountryAppropriate) {
auto engine = holder_.FindMatchingBuiltInDefinitionsById(/* duckduckgo */ 92);
ASSERT_TRUE(engine);
ASSERT_EQ(u"duckduckgo.com", engine->keyword());
}
TEST_F(ReconcilingTemplateURLDataHolderTest,
FindMatchingBuiltInDefinitionsById_ValidID_FromPrepopulatedEngines) {
base::test::ScopedFeatureList features;
auto engine =
holder_.FindMatchingBuiltInDefinitionsById(/* search.brave.com */ 109);
ASSERT_TRUE(engine);
ASSERT_EQ(u"search.brave.com", engine->keyword());
ASSERT_EQ(109, engine->prepopulate_id);
}
TEST_F(ReconcilingTemplateURLDataHolderTest,
FindMatchingBuiltInDefinitionsByKeyword_UnknownKeyword) {
auto engine = holder_.FindMatchingBuiltInDefinitionsByKeyword(u"bazzinga");
// Expect to see no definitions.
ASSERT_FALSE(engine);
}
TEST_F(
ReconcilingTemplateURLDataHolderTest,
FindMatchingBuiltInDefinitionsByKeyword_ValidKeyword_CountryAppropriate) {
auto engine =
holder_.FindMatchingBuiltInDefinitionsByKeyword(u"duckduckgo.com");
ASSERT_TRUE(engine);
ASSERT_EQ(u"duckduckgo.com", engine->keyword());
}
TEST_F(
ReconcilingTemplateURLDataHolderTest,
FindMatchingBuiltInDefinitionsByKeyword_ValidKeyword_FromPrepopulatedEngines) {
auto engine =
holder_.FindMatchingBuiltInDefinitionsByKeyword(u"search.brave.com");
ASSERT_TRUE(engine);
ASSERT_EQ(u"search.brave.com", engine->keyword());
ASSERT_EQ(109, engine->prepopulate_id);
}
|