Commit a2e76344 authored by My Nguyen's avatar My Nguyen Committed by Commit Bot

Add EmojiSuggestAdditionEnabled Pref

As an enterprise policy is required for emoji suggest addition, adding
preference's value first.

Bug: 1077629
Change-Id: I4a55ddc861c4c2216742c92cd90bd0c892ae0bf8
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2175762
Commit-Queue: My Nguyen <myy@chromium.org>
Reviewed-by: default avatarJing Wang <jiwan@chromium.org>
Reviewed-by: default avatarKeith Lee <keithlee@chromium.org>
Cr-Commit-Position: refs/heads/master@{#769906}
parent a4c53b16
...@@ -3011,6 +3011,7 @@ source_set("unit_tests") { ...@@ -3011,6 +3011,7 @@ source_set("unit_tests") {
"guest_os/guest_os_share_path_unittest.cc", "guest_os/guest_os_share_path_unittest.cc",
"hats/hats_finch_helper_unittest.cc", "hats/hats_finch_helper_unittest.cc",
"hats/hats_notification_controller_unittest.cc", "hats/hats_notification_controller_unittest.cc",
"input_method/assistive_suggester_unittest.cc",
"input_method/assistive_window_controller_unittest.cc", "input_method/assistive_window_controller_unittest.cc",
"input_method/emoji_suggester_unittest.cc", "input_method/emoji_suggester_unittest.cc",
"input_method/input_method_configuration_unittest.cc", "input_method/input_method_configuration_unittest.cc",
......
...@@ -7,7 +7,11 @@ ...@@ -7,7 +7,11 @@
#include "base/feature_list.h" #include "base/feature_list.h"
#include "base/metrics/histogram_functions.h" #include "base/metrics/histogram_functions.h"
#include "base/strings/string_util.h" #include "base/strings/string_util.h"
#include "chrome/browser/profiles/profile_manager.h"
#include "chromeos/constants/chromeos_features.h" #include "chromeos/constants/chromeos_features.h"
#include "chromeos/constants/chromeos_pref_names.h"
#include "components/prefs/pref_service.h"
#include "components/prefs/scoped_user_pref_update.h"
using input_method::InputMethodEngineBase; using input_method::InputMethodEngineBase;
...@@ -30,20 +34,29 @@ bool IsAssistPersonalInfoEnabled() { ...@@ -30,20 +34,29 @@ bool IsAssistPersonalInfoEnabled() {
return base::FeatureList::IsEnabled(chromeos::features::kAssistPersonalInfo); return base::FeatureList::IsEnabled(chromeos::features::kAssistPersonalInfo);
} }
bool IsEmojiSuggestAdditionEnabled() {
return base::FeatureList::IsEnabled(
chromeos::features::kEmojiSuggestAddition);
}
} // namespace } // namespace
bool IsAssistiveFeatureEnabled() { AssistiveSuggester::AssistiveSuggester(InputMethodEngine* engine,
Profile* profile)
: profile_(profile),
personal_info_suggester_(engine, profile),
emoji_suggester_(engine) {}
bool AssistiveSuggester::IsAssistiveFeatureEnabled() {
return IsAssistPersonalInfoEnabled() || IsEmojiSuggestAdditionEnabled(); return IsAssistPersonalInfoEnabled() || IsEmojiSuggestAdditionEnabled();
} }
AssistiveSuggester::AssistiveSuggester(InputMethodEngine* engine, bool AssistiveSuggester::IsEmojiSuggestAdditionEnabled() {
Profile* profile) if (!base::FeatureList::IsEnabled(chromeos::features::kEmojiSuggestAddition))
: personal_info_suggester_(engine, profile), emoji_suggester_(engine) {} return false;
base::Optional<bool> enabled =
profile_->GetPrefs()
->GetDictionary(prefs::kAssistiveInputFeatureSettings)
->FindBoolPath(kEmojiSuggestAdditionEnabledPrefName);
if (!enabled.has_value())
return true;
return enabled.value();
}
void AssistiveSuggester::OnFocus(int context_id) { void AssistiveSuggester::OnFocus(int context_id) {
context_id_ = context_id; context_id_ = context_id;
......
...@@ -16,8 +16,8 @@ ...@@ -16,8 +16,8 @@
namespace chromeos { namespace chromeos {
// Check if any assistive feature is enabled. const char kEmojiSuggestAdditionEnabledPrefName[] =
bool IsAssistiveFeatureEnabled(); "emoji_suggest_addition_enabled";
// An agent to suggest assistive information when the user types, and adopt or // An agent to suggest assistive information when the user types, and adopt or
// dismiss the suggestion according to the user action. // dismiss the suggestion according to the user action.
...@@ -25,6 +25,8 @@ class AssistiveSuggester { ...@@ -25,6 +25,8 @@ class AssistiveSuggester {
public: public:
AssistiveSuggester(InputMethodEngine* engine, Profile* profile); AssistiveSuggester(InputMethodEngine* engine, Profile* profile);
bool IsAssistiveFeatureEnabled();
// Called when a text field gains focus, and suggester starts working. // Called when a text field gains focus, and suggester starts working.
void OnFocus(int context_id); void OnFocus(int context_id);
...@@ -59,6 +61,9 @@ class AssistiveSuggester { ...@@ -59,6 +61,9 @@ class AssistiveSuggester {
// Check if suggestion is being shown. // Check if suggestion is being shown.
bool IsSuggestionShown(); bool IsSuggestionShown();
bool IsEmojiSuggestAdditionEnabled();
Profile* profile_;
PersonalInfoSuggester personal_info_suggester_; PersonalInfoSuggester personal_info_suggester_;
EmojiSuggester emoji_suggester_; EmojiSuggester emoji_suggester_;
......
// Copyright 2020 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "chrome/browser/chromeos/input_method/assistive_suggester.h"
#include "chrome/browser/chromeos/input_method/personal_info_suggester.h"
#include "base/test/scoped_feature_list.h"
#include "chrome/test/base/testing_profile.h"
#include "chromeos/constants/chromeos_features.h"
#include "chromeos/constants/chromeos_pref_names.h"
#include "components/prefs/scoped_user_pref_update.h"
#include "content/public/test/browser_task_environment.h"
#include "testing/gtest/include/gtest/gtest.h"
namespace chromeos {
class AssistiveSuggesterTest : public testing::Test {
protected:
AssistiveSuggesterTest() { profile_ = std::make_unique<TestingProfile>(); }
void SetUp() override {
engine_ = std::make_unique<InputMethodEngine>();
assistive_suggester_ =
std::make_unique<AssistiveSuggester>(engine_.get(), profile_.get());
}
content::BrowserTaskEnvironment task_environment_;
std::unique_ptr<TestingProfile> profile_;
std::unique_ptr<AssistiveSuggester> assistive_suggester_;
std::unique_ptr<InputMethodEngine> engine_;
};
TEST_F(AssistiveSuggesterTest,
EmojiSuggestionPrefFalseFeatureFlagTrue_AssitiveFeatureEnabledFalse) {
base::test::ScopedFeatureList feature_list;
feature_list.InitWithFeatures(
// enabled_features
{chromeos::features::kEmojiSuggestAddition},
// disabled_features
{chromeos::features::kAssistPersonalInfo});
DictionaryPrefUpdate update(profile_->GetPrefs(),
prefs::kAssistiveInputFeatureSettings);
update->SetPath(std::string(kEmojiSuggestAdditionEnabledPrefName),
base::Value(false));
EXPECT_FALSE(assistive_suggester_->IsAssistiveFeatureEnabled());
}
TEST_F(AssistiveSuggesterTest,
EmojiSuggestionPrefTrueFeatureFlagTrue_AssitiveFeatureEnabledTrue) {
base::test::ScopedFeatureList feature_list;
feature_list.InitWithFeatures(
// enabled_features
{chromeos::features::kEmojiSuggestAddition},
// disabled_features
{chromeos::features::kAssistPersonalInfo});
DictionaryPrefUpdate update(profile_->GetPrefs(),
prefs::kAssistiveInputFeatureSettings);
update->SetPath(std::string(kEmojiSuggestAdditionEnabledPrefName),
base::Value(true));
EXPECT_TRUE(assistive_suggester_->IsAssistiveFeatureEnabled());
}
} // namespace chromeos
...@@ -137,14 +137,14 @@ void NativeInputMethodEngine::ImeObserver::OnActivate( ...@@ -137,14 +137,14 @@ void NativeInputMethodEngine::ImeObserver::OnActivate(
void NativeInputMethodEngine::ImeObserver::OnFocus( void NativeInputMethodEngine::ImeObserver::OnFocus(
const IMEEngineHandlerInterface::InputContext& context) { const IMEEngineHandlerInterface::InputContext& context) {
if (IsAssistiveFeatureEnabled()) if (assistive_suggester_->IsAssistiveFeatureEnabled())
assistive_suggester_->OnFocus(context.id); assistive_suggester_->OnFocus(context.id);
base_observer_->OnFocus(context); base_observer_->OnFocus(context);
} }
void NativeInputMethodEngine::ImeObserver::OnBlur(int context_id) { void NativeInputMethodEngine::ImeObserver::OnBlur(int context_id) {
if (IsAssistiveFeatureEnabled()) if (assistive_suggester_->IsAssistiveFeatureEnabled())
assistive_suggester_->OnBlur(); assistive_suggester_->OnBlur();
base_observer_->OnBlur(context_id); base_observer_->OnBlur(context_id);
...@@ -154,7 +154,7 @@ void NativeInputMethodEngine::ImeObserver::OnKeyEvent( ...@@ -154,7 +154,7 @@ void NativeInputMethodEngine::ImeObserver::OnKeyEvent(
const std::string& engine_id, const std::string& engine_id,
const InputMethodEngineBase::KeyboardEvent& event, const InputMethodEngineBase::KeyboardEvent& event,
ui::IMEEngineHandlerInterface::KeyEventDoneCallback callback) { ui::IMEEngineHandlerInterface::KeyEventDoneCallback callback) {
if (IsAssistiveFeatureEnabled()) { if (assistive_suggester_->IsAssistiveFeatureEnabled()) {
if (assistive_suggester_->OnKeyEvent(event)) { if (assistive_suggester_->OnKeyEvent(event)) {
std::move(callback).Run(true); std::move(callback).Run(true);
return; return;
...@@ -201,7 +201,7 @@ void NativeInputMethodEngine::ImeObserver::OnSurroundingTextChanged( ...@@ -201,7 +201,7 @@ void NativeInputMethodEngine::ImeObserver::OnSurroundingTextChanged(
int offset_pos) { int offset_pos) {
assistive_suggester_->RecordAssistiveCoverageMetrics(text, cursor_pos, assistive_suggester_->RecordAssistiveCoverageMetrics(text, cursor_pos,
anchor_pos); anchor_pos);
if (IsAssistiveFeatureEnabled()) { if (assistive_suggester_->IsAssistiveFeatureEnabled()) {
// If |assistive_suggester_| changes the surrounding text, no longer need // If |assistive_suggester_| changes the surrounding text, no longer need
// to call the following function, as the information is out-dated. // to call the following function, as the information is out-dated.
if (assistive_suggester_->OnSurroundingTextChanged(text, cursor_pos, if (assistive_suggester_->OnSurroundingTextChanged(text, cursor_pos,
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment