-
Notifications
You must be signed in to change notification settings - Fork 879
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
disable translation service, disable TranslateURLFetcher, hide associ…
…ated UI in preferences (#562) * disable translation service, disable TranslateURLFetcher, hide associated UI in preferences Fix brave/brave-browser#663 * use comments * unit test
- Loading branch information
1 parent
e961d8b
commit 3351db7
Showing
4 changed files
with
100 additions
and
0 deletions.
There are no files selected for viewing
58 changes: 58 additions & 0 deletions
58
components/translate/core/browser/translate_language_list_unittest.cc
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
#include "components/translate/core/browser/translate_language_list.h" | ||
|
||
#include <string> | ||
#include <vector> | ||
|
||
#include "base/run_loop.h" | ||
#include "base/stl_util.h" | ||
#include "base/test/bind_test_util.h" | ||
#include "base/test/scoped_command_line.h" | ||
#include "base/test/scoped_task_environment.h" | ||
#include "base/threading/thread_task_runner_handle.h" | ||
#include "components/translate/core/browser/translate_download_manager.h" | ||
#include "components/translate/core/browser/translate_url_util.h" | ||
#include "services/network/public/cpp/weak_wrapper_shared_url_loader_factory.h" | ||
#include "services/network/test/test_url_loader_factory.h" | ||
#include "testing/gtest/include/gtest/gtest.h" | ||
#include "url/gurl.h" | ||
|
||
namespace translate { | ||
|
||
// Check that we don't send any network data to the translate server, | ||
// even if translation is allowed and resource requests are allowed | ||
TEST(TranslateLanguageListTest, GetSupportedLanguagesNoFetch) { | ||
base::test::ScopedTaskEnvironment scoped_task_environment; | ||
network::TestURLLoaderFactory test_url_loader_factory; | ||
scoped_refptr<network::SharedURLLoaderFactory> test_shared_loader_factory = | ||
base::MakeRefCounted<network::WeakWrapperSharedURLLoaderFactory>( | ||
&test_url_loader_factory); | ||
TranslateDownloadManager::GetInstance()->set_application_locale("en"); | ||
TranslateDownloadManager::GetInstance()->set_url_loader_factory( | ||
test_shared_loader_factory); | ||
|
||
bool network_access_occurred = false; | ||
base::RunLoop loop; | ||
// Since translate is allowed by policy, we will schedule a language list | ||
// load. Intercept to ensure the URL is correct. | ||
test_url_loader_factory.SetInterceptor( | ||
base::BindLambdaForTesting([&](const network::ResourceRequest& request) { | ||
network_access_occurred = true; | ||
loop.Quit(); | ||
})); | ||
|
||
// Populate supported languages. | ||
std::vector<std::string> languages; | ||
TranslateLanguageList language_list; | ||
language_list.SetResourceRequestsAllowed(true); | ||
language_list.GetSupportedLanguages(true /* translate_allowed */, | ||
&languages); | ||
|
||
// We should *not* have scheduled a language list load. | ||
EXPECT_FALSE(language_list.HasOngoingLanguageListLoadingForTesting()); | ||
EXPECT_TRUE(test_url_loader_factory.pending_requests()->empty()); | ||
EXPECT_FALSE(network_access_occurred); | ||
|
||
TranslateDownloadManager::GetInstance()->ResetForTesting(); | ||
} | ||
|
||
} // namespace translate |
17 changes: 17 additions & 0 deletions
17
patches/chrome-browser-resources-settings-languages_page-languages_page.html.patch
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
diff --git a/chrome/browser/resources/settings/languages_page/languages_page.html b/chrome/browser/resources/settings/languages_page/languages_page.html | ||
index a979b391e553..50bb65730a93 100644 | ||
--- a/chrome/browser/resources/settings/languages_page/languages_page.html | ||
+++ b/chrome/browser/resources/settings/languages_page/languages_page.html | ||
@@ -182,10 +182,12 @@ | ||
</a> | ||
</div> | ||
</div> | ||
+<!-- | ||
<settings-toggle-button id="offerTranslateOtherLanguages" | ||
class="first" pref="{{prefs.translate.enabled}}" | ||
label="$i18n{offerToEnableTranslate}"> | ||
</settings-toggle-button> | ||
+--> | ||
</iron-collapse> | ||
<if expr="chromeos"> | ||
<div id="manageInputMethodsSubpageTrigger" |
13 changes: 13 additions & 0 deletions
13
patches/components-translate-core-browser-language_state.h.patch
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
diff --git a/components/translate/core/browser/language_state.h b/components/translate/core/browser/language_state.h | ||
index 3cee8dc8f310..2957ecb16a42 100644 | ||
--- a/components/translate/core/browser/language_state.h | ||
+++ b/components/translate/core/browser/language_state.h | ||
@@ -70,7 +70,7 @@ class LanguageState { | ||
void set_translation_declined(bool value) { translation_declined_ = value; } | ||
|
||
// Whether the translate is enabled. | ||
- bool translate_enabled() const { return translate_enabled_; } | ||
+ bool translate_enabled() const { return false; } | ||
void SetTranslateEnabled(bool value); | ||
|
||
// Whether the current page's language is different from the previous |
12 changes: 12 additions & 0 deletions
12
patches/components-translate-core-browser-translate_url_fetcher.cc.patch
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
diff --git a/components/translate/core/browser/translate_url_fetcher.cc b/components/translate/core/browser/translate_url_fetcher.cc | ||
index 9dae29174d5f..585c1db28cf8 100644 | ||
--- a/components/translate/core/browser/translate_url_fetcher.cc | ||
+++ b/components/translate/core/browser/translate_url_fetcher.cc | ||
@@ -31,6 +31,7 @@ TranslateURLFetcher::~TranslateURLFetcher() {} | ||
bool TranslateURLFetcher::Request(const GURL& url, | ||
TranslateURLFetcher::Callback callback, | ||
bool is_incognito) { | ||
+ return false; // feature is disabled in Brave | ||
// This function is not supposed to be called if the previous operation is not | ||
// finished. | ||
if (state_ == REQUESTING) { |