From c4cc65cee56fcb261cd45d14dcd9a3bfd0e40424 Mon Sep 17 00:00:00 2001 From: "Brian R. Bondy" Date: Mon, 14 Jan 2019 15:53:13 -0500 Subject: [PATCH] Autocomplete to chrome://sync and not chrome://sync-internals --- .../brave_autocomplete_provider_client.cc | 15 +++++++ .../brave_autocomplete_provider_client.h | 1 + ...e_autocomplete_provider_client_unittest.cc | 39 +++++++++++++++++++ .../ui/omnibox/chrome_omnibox_client.cc | 10 +++++ test/BUILD.gn | 1 + 5 files changed, 66 insertions(+) create mode 100644 browser/autocomplete/brave_autocomplete_provider_client_unittest.cc create mode 100644 chromium_src/chrome/browser/ui/omnibox/chrome_omnibox_client.cc diff --git a/browser/autocomplete/brave_autocomplete_provider_client.cc b/browser/autocomplete/brave_autocomplete_provider_client.cc index 396bd4fcf2cc..03724301ff0f 100644 --- a/browser/autocomplete/brave_autocomplete_provider_client.cc +++ b/browser/autocomplete/brave_autocomplete_provider_client.cc @@ -4,8 +4,11 @@ #include "brave/browser/autocomplete/brave_autocomplete_provider_client.h" +#include "base/strings/utf_string_conversions.h" +#include "brave/common/webui_url_constants.h" #include "chrome/browser/profiles/profile.h" #include "chrome/browser/search_engines/template_url_service_factory.h" +#include "chrome/common/webui_url_constants.h" BraveAutocompleteProviderClient::BraveAutocompleteProviderClient( Profile* profile) @@ -24,3 +27,15 @@ const TemplateURLService* BraveAutocompleteProviderClient::GetTemplateURLService() const { return TemplateURLServiceFactory::GetForProfile(profile_); } + +std::vector BraveAutocompleteProviderClient::GetBuiltinURLs() { + std::vector v = + ChromeAutocompleteProviderClient::GetBuiltinURLs(); + auto it = std::find(v.begin(), v.end(), + base::ASCIIToUTF16(chrome::kChromeUISyncInternalsHost)); + DCHECK(it != v.end()); + if (it != v.end()) { + *it = base::ASCIIToUTF16(kBraveUISyncHost); + } + return v; +} diff --git a/browser/autocomplete/brave_autocomplete_provider_client.h b/browser/autocomplete/brave_autocomplete_provider_client.h index bcf6f8af3ea9..4970ab6ea371 100644 --- a/browser/autocomplete/brave_autocomplete_provider_client.h +++ b/browser/autocomplete/brave_autocomplete_provider_client.h @@ -33,6 +33,7 @@ class BraveAutocompleteProviderClient TemplateURLService* GetTemplateURLService() override; const TemplateURLService* GetTemplateURLService() const override; + std::vector GetBuiltinURLs() override; private: Profile* profile_; diff --git a/browser/autocomplete/brave_autocomplete_provider_client_unittest.cc b/browser/autocomplete/brave_autocomplete_provider_client_unittest.cc new file mode 100644 index 000000000000..5a4d4344250b --- /dev/null +++ b/browser/autocomplete/brave_autocomplete_provider_client_unittest.cc @@ -0,0 +1,39 @@ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this file, + * You can obtain one at http://mozilla.org/MPL/2.0/. */ + +#include "brave/browser/autocomplete/brave_autocomplete_provider_client.h" + +#include "base/strings/utf_string_conversions.h" +#include "brave/common/webui_url_constants.h" +#include "chrome/common/webui_url_constants.h" +#include "chrome/test/base/testing_profile.h" +#include "content/public/test/fake_service_worker_context.h" +#include "content/public/test/test_browser_thread_bundle.h" +#include "testing/gtest/include/gtest/gtest.h" + +class BraveAutocompleteProviderClientUnitTest : public testing::Test { + public: + void SetUp() override { + profile_ = std::make_unique(); + client_ = + std::make_unique(profile_.get()); + } + + bool BuiltinExists(const base::string16& builtin) { + std::vector v = client_->GetBuiltinURLs(); + auto it = std::find(v.begin(), v.end(), builtin); + return it != v.end(); + } + + protected: + content::TestBrowserThreadBundle test_browser_thread_bundle_; + std::unique_ptr profile_; + std::unique_ptr client_; +}; + +TEST_F(BraveAutocompleteProviderClientUnitTest, + SyncURLSuggestedNotSyncInternal) { + ASSERT_FALSE(BuiltinExists(base::ASCIIToUTF16(chrome::kChromeUISyncInternalsHost))); + ASSERT_TRUE(BuiltinExists(base::ASCIIToUTF16(kBraveUISyncHost))); +} diff --git a/chromium_src/chrome/browser/ui/omnibox/chrome_omnibox_client.cc b/chromium_src/chrome/browser/ui/omnibox/chrome_omnibox_client.cc new file mode 100644 index 000000000000..37b498b88d50 --- /dev/null +++ b/chromium_src/chrome/browser/ui/omnibox/chrome_omnibox_client.cc @@ -0,0 +1,10 @@ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this file, + * You can obtain one at http://mozilla.org/MPL/2.0/. */ + +#include "brave/browser/autocomplete/brave_autocomplete_provider_client.h" + +#define ChromeAutocompleteProviderClient BraveAutocompleteProviderClient +#include "../../../../../../chrome/browser/ui/omnibox/chrome_omnibox_client.cc" +#undef ChromeAutocompleteProviderClient + diff --git a/test/BUILD.gn b/test/BUILD.gn index 875b34da0f31..2ee0c3af4ff4 100644 --- a/test/BUILD.gn +++ b/test/BUILD.gn @@ -29,6 +29,7 @@ static_library("brave_test_support_unit") { test("brave_unit_tests") { sources = [ + "//brave/browser/autocomplete/brave_autocomplete_provider_client_unittest.cc", "//brave/browser/autoplay/autoplay_permission_context_unittest.cc", "//brave/browser/brave_resources_util_unittest.cc", "//brave/browser/brave_stats_updater_unittest.cc",