Skip to content

Commit d862b0b

Browse files
committed
Modify bing search params - removed chrome attrs
fix brave/brave-browser#20659
1 parent 3e30087 commit d862b0b

5 files changed

+65
-2
lines changed

components/search_engines/BUILD.gn

+14
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,17 @@
11
group("search_engines") {
22
deps = [ "//components/search_engines" ]
33
}
4+
5+
source_set("unit_tests") {
6+
testonly = true
7+
8+
sources = [ "brave_prepopulated_engines_unittest.cc" ]
9+
10+
deps = [
11+
"//chrome/test:test_support",
12+
"//components/prefs",
13+
"//components/search_engines",
14+
"//content/test:test_support",
15+
"//testing/gtest",
16+
]
17+
}

components/search_engines/brave_prepopulated_engines.cc

+16-2
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ const std::map<BravePrepopulatedEngineID, const PrepopulatedEngine*>
2323
brave_engines_map = {
2424
{PREPOPULATED_ENGINE_ID_GOOGLE, &google},
2525
{PREPOPULATED_ENGINE_ID_YANDEX, &brave_yandex},
26-
{PREPOPULATED_ENGINE_ID_BING, &bing},
26+
{PREPOPULATED_ENGINE_ID_BING, &brave_bing},
2727
{PREPOPULATED_ENGINE_ID_DUCKDUCKGO, &duckduckgo},
2828
{PREPOPULATED_ENGINE_ID_DUCKDUCKGO_DE, &duckduckgo_de},
2929
{PREPOPULATED_ENGINE_ID_DUCKDUCKGO_AU_NZ_IE, &duckduckgo_au_nz_ie},
@@ -38,14 +38,15 @@ PrepopulatedEngine ModifyEngineParams(const PrepopulatedEngine& engine,
3838
const wchar_t* const keyword,
3939
const char* const search_url,
4040
const char* const suggest_url,
41+
const char* const image_url,
4142
int id) {
4243
return {name ? name : engine.name,
4344
keyword ? keyword : engine.keyword,
4445
engine.favicon_url,
4546
search_url ? search_url : engine.search_url,
4647
engine.encoding,
4748
suggest_url ? suggest_url : engine.suggest_url,
48-
engine.image_url,
49+
image_url ? image_url : engine.image_url,
4950
engine.new_tab_url,
5051
engine.contextual_search_url,
5152
engine.logo_url,
@@ -90,6 +91,7 @@ const PrepopulatedEngine duckduckgo_de =
9091
NULL,
9192
"https://duckduckgo.com/?q={searchTerms}&t=bravened",
9293
NULL,
94+
NULL,
9395
PREPOPULATED_ENGINE_ID_DUCKDUCKGO_DE);
9496

9597
const PrepopulatedEngine duckduckgo_au_nz_ie =
@@ -98,6 +100,7 @@ const PrepopulatedEngine duckduckgo_au_nz_ie =
98100
NULL,
99101
"https://duckduckgo.com/?q={searchTerms}&t=braveed",
100102
NULL,
103+
NULL,
101104
PREPOPULATED_ENGINE_ID_DUCKDUCKGO_AU_NZ_IE);
102105

103106
#if defined(OS_ANDROID)
@@ -136,6 +139,7 @@ const PrepopulatedEngine brave_ecosia =
136139
#endif
137140
"&q={searchTerms}&addon=brave",
138141
"https://ac.ecosia.org/?q={searchTerms}",
142+
NULL,
139143
PREPOPULATED_ENGINE_ID_ECOSIA);
140144

141145
const PrepopulatedEngine qwant = {
@@ -197,6 +201,7 @@ const PrepopulatedEngine brave_yandex =
197201
"&text={searchTerms}",
198202
"https://suggest.yandex.ru/suggest-ff.cgi?"
199203
"part={searchTerms}&v=3&sn=5&srv=brave_desktop",
204+
NULL,
200205
PREPOPULATED_ENGINE_ID_YANDEX);
201206

202207
const PrepopulatedEngine brave_search = {
@@ -226,6 +231,15 @@ const PrepopulatedEngine brave_search = {
226231
PREPOPULATED_ENGINE_ID_BRAVE,
227232
};
228233

234+
const PrepopulatedEngine brave_bing = ModifyEngineParams(
235+
bing,
236+
NULL,
237+
NULL,
238+
"https://www.bing.com/search?q={searchTerms}",
239+
"https://www.bing.com/osjson.aspx?query={searchTerms}&language={language}",
240+
"https://www.bing.com/images/detail/search?iss=sbiupload#enterInsights",
241+
PREPOPULATED_ENGINE_ID_BING);
242+
229243
const std::map<BravePrepopulatedEngineID, const PrepopulatedEngine*>&
230244
GetBraveEnginesMap() {
231245
return brave_engines_map;

components/search_engines/brave_prepopulated_engines.h

+1
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,7 @@ extern const PrepopulatedEngine qwant;
104104
extern const PrepopulatedEngine startpage;
105105
extern const PrepopulatedEngine brave_yandex;
106106
extern const PrepopulatedEngine brave_search;
107+
extern const PrepopulatedEngine brave_bing;
107108

108109
const std::map<BravePrepopulatedEngineID, const PrepopulatedEngine*>&
109110
GetBraveEnginesMap();
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
/* Copyright (c) 2022 The Brave Authors. All rights reserved.
2+
* This Source Code Form is subject to the terms of the Mozilla Public
3+
* License, v. 2.0. If a copy of the MPL was not distributed with this file,
4+
* You can obtain one at http://mozilla.org/MPL/2.0/. */
5+
6+
#include <memory>
7+
8+
#include "brave/components/search_engines/brave_prepopulated_engines.h"
9+
#include "chrome/test/base/testing_profile.h"
10+
#include "components/prefs/pref_service.h"
11+
#include "components/search_engines/template_url_data.h"
12+
#include "components/search_engines/template_url_prepopulate_data.h"
13+
#include "content/public/test/browser_task_environment.h"
14+
#include "testing/gtest/include/gtest/gtest.h"
15+
16+
class BravePrepopulatedEnginesTest : public testing::Test {
17+
public:
18+
BravePrepopulatedEnginesTest() = default;
19+
~BravePrepopulatedEnginesTest() override = default;
20+
21+
void SetUp() override { profile_ = std::make_unique<TestingProfile>(); }
22+
23+
content::BrowserTaskEnvironment browser_task_environment_;
24+
std::unique_ptr<TestingProfile> profile_;
25+
};
26+
27+
TEST_F(BravePrepopulatedEnginesTest, ModifiedProviderTest) {
28+
auto data = TemplateURLPrepopulateData::GetPrepopulatedEngine(
29+
profile_->GetPrefs(),
30+
TemplateURLPrepopulateData::PREPOPULATED_ENGINE_ID_BING);
31+
// Check modified bing provider url.
32+
EXPECT_EQ(data->url(), "https://www.bing.com/search?q={searchTerms}");
33+
}

test/BUILD.gn

+1
Original file line numberDiff line numberDiff line change
@@ -212,6 +212,7 @@ test("brave_unit_tests") {
212212
"//brave/components/ntp_widget_utils/browser",
213213
"//brave/components/p3a",
214214
"//brave/components/permissions:unit_tests",
215+
"//brave/components/search_engines:unit_tests",
215216
"//brave/components/services/ipfs/test:ipfs_service_unit_tests",
216217
"//brave/components/sidebar:unit_tests",
217218
"//brave/components/signin/public/identity_manager:unit_tests",

0 commit comments

Comments
 (0)