Skip to content

Commit

Permalink
disable translation service, disable TranslateURLFetcher, hide associ…
Browse files Browse the repository at this point in the history
…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
pilgrim-brave authored and bbondy committed Oct 4, 2018
1 parent e961d8b commit 3351db7
Show file tree
Hide file tree
Showing 4 changed files with 100 additions and 0 deletions.
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
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 patches/components-translate-core-browser-language_state.h.patch
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
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) {

0 comments on commit 3351db7

Please sign in to comment.