Commit 01399075 authored by Daniel Zhang's avatar Daniel Zhang Committed by Commit Bot

cros: Place AppList autocomplete behind a flag.

More testing of autocomplete behavior is needed.
Placing AppList autocomplete behind a flag and
updating tests to reflect this.

Bug: 874133
Change-Id: I35f78089045efc65da3a4f524d7e0b613b854705
Reviewed-on: https://chromium-review.googlesource.com/1178577Reviewed-by: default avatarXiyuan Xia <xiyuan@chromium.org>
Reviewed-by: default avatarAlex Newcomer <newcomer@chromium.org>
Commit-Queue: Daniel Zhang <oxyflush@google.com>
Cr-Commit-Position: refs/heads/master@{#583858}
parent d7b94b1c
......@@ -95,6 +95,8 @@ SearchBoxView::SearchBoxView(search_box::SearchBoxViewDelegate* delegate,
view_delegate_(view_delegate),
app_list_view_(app_list_view),
is_new_style_launcher_enabled_(features::IsNewStyleLauncherEnabled()),
is_app_list_search_autocomplete_enabled_(
features::IsAppListSearchAutocompleteEnabled()),
weak_ptr_factory_(this) {
set_is_tablet_mode(app_list_view->is_tablet_mode());
if (features::IsZeroStateSuggestionsEnabled())
......@@ -359,6 +361,9 @@ void SearchBoxView::OnWallpaperColorsChanged() {
}
void SearchBoxView::ProcessAutocomplete() {
if (!is_app_list_search_autocomplete_enabled_)
return;
// Current non-autocompleted text.
const base::string16& user_typed_text =
search_box()->text().substr(0, highlight_range_.start());
......@@ -418,11 +423,17 @@ void SearchBoxView::OnWallpaperProminentColorsReceived(
}
void SearchBoxView::AcceptAutocompleteText() {
if (!is_app_list_search_autocomplete_enabled_)
return;
if (highlight_range_.start() != search_box()->text().length())
ContentsChanged(search_box(), search_box()->text());
}
void SearchBoxView::AcceptOneCharInAutocompleteText() {
if (!is_app_list_search_autocomplete_enabled_)
return;
highlight_range_.set_start(highlight_range_.start() + 1);
highlight_range_.set_end(search_box()->text().length());
const base::string16 original_text = search_box()->text();
......@@ -434,6 +445,9 @@ void SearchBoxView::AcceptOneCharInAutocompleteText() {
}
void SearchBoxView::ClearAutocompleteText() {
if (!is_app_list_search_autocomplete_enabled_)
return;
search_box()->SetText(
search_box()->text().substr(0, highlight_range_.start()));
}
......@@ -441,6 +455,7 @@ void SearchBoxView::ClearAutocompleteText() {
void SearchBoxView::ContentsChanged(views::Textfield* sender,
const base::string16& new_contents) {
// Update autocomplete text highlight range to track user typed text.
if (is_app_list_search_autocomplete_enabled_)
highlight_range_.set_start(search_box()->text().length());
search_box::SearchBoxViewBase::ContentsChanged(sender, new_contents);
app_list_view_->SetStateFromSearchBoxView(
......@@ -449,6 +464,9 @@ void SearchBoxView::ContentsChanged(views::Textfield* sender,
void SearchBoxView::SetAutocompleteText(
const base::string16& autocomplete_text) {
if (!is_app_list_search_autocomplete_enabled_)
return;
const base::string16& current_text = search_box()->text();
// Currrent text is a prefix of autocomplete text.
DCHECK(base::StartsWith(autocomplete_text, current_text,
......@@ -469,7 +487,8 @@ void SearchBoxView::SetAutocompleteText(
bool SearchBoxView::HandleKeyEvent(views::Textfield* sender,
const ui::KeyEvent& key_event) {
if (search_box()->HasFocus() && is_search_box_active() &&
!search_box()->text().empty()) {
!search_box()->text().empty() &&
is_app_list_search_autocomplete_enabled_) {
// If the search box has no text in it currently, autocomplete should not
// work.
last_key_pressed_ = key_event.key_code();
......
......@@ -146,6 +146,9 @@ class APP_LIST_EXPORT SearchBoxView : public search_box::SearchBoxViewBase,
// True if new style launcher feature is enabled.
const bool is_new_style_launcher_enabled_;
// True if app list search autocomplete is enabled.
const bool is_app_list_search_autocomplete_enabled_;
base::WeakPtrFactory<SearchBoxView> weak_ptr_factory_;
DISALLOW_COPY_AND_ASSIGN(SearchBoxView);
......
......@@ -17,6 +17,7 @@
#include "ash/public/cpp/app_list/vector_icons/vector_icons.h"
#include "base/macros.h"
#include "base/strings/utf_string_conversions.h"
#include "base/test/scoped_feature_list.h"
#include "ui/chromeos/search_box/search_box_constants.h"
#include "ui/chromeos/search_box/search_box_view_delegate.h"
#include "ui/gfx/image/image_skia.h"
......@@ -286,9 +287,40 @@ TEST_F(SearchBoxViewTest, SearchBoxActiveSearchEngineNotGoogle) {
*actual_icon.bitmap()));
}
class SearchBoxViewAutocompleteTest
: public SearchBoxViewTest,
public ::testing::WithParamInterface<ui::KeyboardCode> {
public:
SearchBoxViewAutocompleteTest() = default;
~SearchBoxViewAutocompleteTest() override = default;
// Overridden from testing::Test
void SetUp() override {
scoped_feature_list_.InitWithFeatures(
{features::kEnableAppListSearchAutocomplete}, {});
SearchBoxViewTest::SetUp();
}
ui::KeyboardCode key_code() const { return GetParam(); }
private:
base::test::ScopedFeatureList scoped_feature_list_;
DISALLOW_COPY_AND_ASSIGN(SearchBoxViewAutocompleteTest);
};
INSTANTIATE_TEST_CASE_P(,
SearchBoxViewAutocompleteTest,
::testing::Values(ui::VKEY_TAB,
ui::VKEY_LEFT,
ui::VKEY_RIGHT,
ui::VKEY_UP,
ui::VKEY_DOWN));
// Tests that autocomplete suggestions are consistent with top SearchResult list
// titles.
TEST_F(SearchBoxViewTest, SearchBoxAutocompletesTopListResultTitle) {
TEST_F(SearchBoxViewAutocompleteTest,
SearchBoxAutocompletesTopListResultTitle) {
// Add two SearchResults, one with higher ranking. Initialize their title
// field to a non-empty string.
CreateSearchResult(ash::SearchResultDisplayType::kList, 1.0,
......@@ -307,7 +339,8 @@ TEST_F(SearchBoxViewTest, SearchBoxAutocompletesTopListResultTitle) {
// Tests that autocomplete suggestions are consistent with top SearchResult tile
// titles.
TEST_F(SearchBoxViewTest, SearchBoxAutocompletesTopTileResultTitle) {
TEST_F(SearchBoxViewAutocompleteTest,
SearchBoxAutocompletesTopTileResultTitle) {
// Add two SearchResults, one with higher ranking. Initialize their title
// field to a non-empty string.
CreateSearchResult(ash::SearchResultDisplayType::kTile, 1.0,
......@@ -326,7 +359,8 @@ TEST_F(SearchBoxViewTest, SearchBoxAutocompletesTopTileResultTitle) {
// Tests that autocomplete suggestions are consistent with top SearchResult list
// details.
TEST_F(SearchBoxViewTest, SearchBoxAutocompletesTopListResultDetails) {
TEST_F(SearchBoxViewAutocompleteTest,
SearchBoxAutocompletesTopListResultDetails) {
// Add two SearchResults, one with higher ranking. Initialize their details
// field to a non-empty string.
CreateSearchResult(ash::SearchResultDisplayType::kList, 1.0, base::string16(),
......@@ -345,7 +379,8 @@ TEST_F(SearchBoxViewTest, SearchBoxAutocompletesTopListResultDetails) {
// Tests that autocomplete suggestions are consistent with top SearchResult tile
// details.
TEST_F(SearchBoxViewTest, SearchBoxAutocompletesTopTileResultDetails) {
TEST_F(SearchBoxViewAutocompleteTest,
SearchBoxAutocompletesTopTileResultDetails) {
// Add two SearchResults, one with higher ranking. Initialize their details
// field to a non-empty string.
CreateSearchResult(ash::SearchResultDisplayType::kTile, 1.0, base::string16(),
......@@ -364,7 +399,8 @@ TEST_F(SearchBoxViewTest, SearchBoxAutocompletesTopTileResultDetails) {
// Tests that SearchBoxView's textfield text does not autocomplete if the top
// result title or details do not have a matching prefix.
TEST_F(SearchBoxViewTest, SearchBoxDoesNotAutocompleteWrongCharacter) {
TEST_F(SearchBoxViewAutocompleteTest,
SearchBoxDoesNotAutocompleteWrongCharacter) {
// Add a search result with non-empty details and title fields.
CreateSearchResult(ash::SearchResultDisplayType::kList, 1.0,
base::ASCIIToUTF16("title"),
......@@ -379,7 +415,7 @@ TEST_F(SearchBoxViewTest, SearchBoxDoesNotAutocompleteWrongCharacter) {
// Tests that autocomplete suggestion will remain if next key in the suggestion
// is typed.
TEST_F(SearchBoxViewTest, SearchBoxAutocompletesAcceptsNextChar) {
TEST_F(SearchBoxViewAutocompleteTest, SearchBoxAutocompletesAcceptsNextChar) {
// Add a search result with a non-empty title field.
CreateSearchResult(ash::SearchResultDisplayType::kList, 1.0,
base::ASCIIToUTF16("hello world!"), base::string16());
......@@ -403,7 +439,8 @@ TEST_F(SearchBoxViewTest, SearchBoxAutocompletesAcceptsNextChar) {
// Tests that only the autocomplete suggestion text is deleted after hitting
// backspace.
TEST_F(SearchBoxViewTest, SearchBoxDeletesAutocompleteTextOnlyAfterBackspace) {
TEST_F(SearchBoxViewAutocompleteTest,
SearchBoxDeletesAutocompleteTextOnlyAfterBackspace) {
// Add a search result with a non-empty title field.
CreateSearchResult(ash::SearchResultDisplayType::kList, 1.0,
base::ASCIIToUTF16("hello world!"), base::string16());
......@@ -422,26 +459,6 @@ TEST_F(SearchBoxViewTest, SearchBoxDeletesAutocompleteTextOnlyAfterBackspace) {
EXPECT_EQ(view()->search_box()->text(), base::ASCIIToUTF16("he"));
}
class SearchBoxViewAutocompleteTest
: public SearchBoxViewTest,
public ::testing::WithParamInterface<ui::KeyboardCode> {
public:
SearchBoxViewAutocompleteTest() = default;
~SearchBoxViewAutocompleteTest() = default;
ui::KeyboardCode key_code() const { return GetParam(); }
private:
DISALLOW_COPY_AND_ASSIGN(SearchBoxViewAutocompleteTest);
};
INSTANTIATE_TEST_CASE_P(,
SearchBoxViewAutocompleteTest,
::testing::Values(ui::VKEY_TAB,
ui::VKEY_LEFT,
ui::VKEY_RIGHT,
ui::VKEY_UP,
ui::VKEY_DOWN));
// Tests that autocomplete suggestion is accepted and displayed in SearchModel
// after hitting certain control keys.
TEST_P(SearchBoxViewAutocompleteTest,
......
......@@ -31,6 +31,8 @@ const base::Feature kEnableContinueReading{"EnableContinueReading",
base::FEATURE_DISABLED_BY_DEFAULT};
const base::Feature kEnableZeroStateSuggestions{
"EnableZeroStateSuggestions", base::FEATURE_DISABLED_BY_DEFAULT};
const base::Feature kEnableAppListSearchAutocomplete{
"EnableAppListSearchAutocomplete", base::FEATURE_DISABLED_BY_DEFAULT};
bool IsAnswerCardEnabled() {
// Not using local static variable to allow tests to change this value.
......@@ -74,6 +76,10 @@ bool IsZeroStateSuggestionsEnabled() {
return base::FeatureList::IsEnabled(kEnableZeroStateSuggestions);
}
bool IsAppListSearchAutocompleteEnabled() {
return base::FeatureList::IsEnabled(kEnableAppListSearchAutocomplete);
}
std::string AnswerServerUrl() {
const std::string experiment_url =
base::GetFieldTrialParamValueByFeature(kEnableAnswerCard, "ServerUrl");
......
......@@ -53,6 +53,9 @@ ASH_PUBLIC_EXPORT extern const base::Feature kEnableContinueReading;
// Enables the feature to display zero state suggestions.
ASH_PUBLIC_EXPORT extern const base::Feature kEnableZeroStateSuggestions;
// Enables the feature to autocomplete text typed in the AppList search box.
ASH_PUBLIC_EXPORT extern const base::Feature kEnableAppListSearchAutocomplete;
bool ASH_PUBLIC_EXPORT IsAnswerCardEnabled();
bool ASH_PUBLIC_EXPORT IsAppShortcutSearchEnabled();
bool ASH_PUBLIC_EXPORT IsBackgroundBlurEnabled();
......@@ -63,6 +66,7 @@ bool ASH_PUBLIC_EXPORT IsAppsGridGapFeatureEnabled();
bool ASH_PUBLIC_EXPORT IsNewStyleLauncherEnabled();
bool ASH_PUBLIC_EXPORT IsContinueReadingEnabled();
bool ASH_PUBLIC_EXPORT IsZeroStateSuggestionsEnabled();
bool ASH_PUBLIC_EXPORT IsAppListSearchAutocompleteEnabled();
std::string ASH_PUBLIC_EXPORT AnswerServerUrl();
std::string ASH_PUBLIC_EXPORT AnswerServerQuerySuffix();
......
......@@ -1668,6 +1668,10 @@ const FeatureEntry kFeatureEntries[] = {
flag_descriptions::kNotificationIndicatorName,
flag_descriptions::kNotificationIndicatorDescription, kOsCrOS,
FEATURE_VALUE_TYPE(features::kNotificationIndicator)},
{"enable-app-list-search-autocomplete",
flag_descriptions::kEnableAppListSearchAutocompleteName,
flag_descriptions::kEnableAppListSearchAutocompleteDescription, kOsCrOS,
FEATURE_VALUE_TYPE(app_list::features::kEnableAppListSearchAutocomplete)},
{
"enable-pinch", flag_descriptions::kPinchScaleName,
flag_descriptions::kPinchScaleDescription, kOsLinux | kOsWin | kOsCrOS,
......
......@@ -3136,6 +3136,12 @@ const char kDisableTabletSplitViewName[] = "Disable split view in Tablet mode";
const char kDisableTabletSplitViewDescription[] =
"Disable split view for Chrome OS tablet mode.";
const char kEnableAppListSearchAutocompleteName[] =
"App List Search Autocomplete";
const char kEnableAppListSearchAutocompleteDescription[] =
"Allow App List search box to autocomplete queries for Google searches and "
"apps.";
const char kEnableAppShortcutSearchName[] =
"Enable app shortcut search in launcher";
const char kEnableAppShortcutSearchDescription[] =
......
......@@ -1918,6 +1918,9 @@ extern const char kDisableTabletAutohideTitlebarsDescription[];
extern const char kDisableTabletSplitViewName[];
extern const char kDisableTabletSplitViewDescription[];
extern const char kEnableAppListSearchAutocompleteName[];
extern const char kEnableAppListSearchAutocompleteDescription[];
extern const char kEnableAppShortcutSearchName[];
extern const char kEnableAppShortcutSearchDescription[];
......
......@@ -28873,6 +28873,7 @@ from previous Chrome versions.
<int value="-77872983" label="BookmarkAppsMac:disabled"/>
<int value="-76631048" label="disable-offline-auto-reload-visible-only"/>
<int value="-75418012" label="ContextualSuggestionsOptOut:disabled"/>
<int value="-73282711" label="EnableAppListSearchAutocomplete:enabled"/>
<int value="-72455054" label="WebVrAutopresent:disabled"/>
<int value="-70595606" label="ash-enable-unified-desktop"/>
<int value="-69427025" label="OfflinePagesPrefetchingUI:enabled"/>
......@@ -29392,6 +29393,7 @@ from previous Chrome versions.
<int value="1012942422" label="HorizontalTabSwitcherAndroid:disabled"/>
<int value="1015895665" label="drop-sync-credential:enabled"/>
<int value="1017364362" label="VrIconInDaydreamHome:enabled"/>
<int value="1018797564" label="EnableAppListSearchAutocomplete:disabled"/>
<int value="1018998019" label="memlog"/>
<int value="1019623058" label="ash-enable-shelf-model-synchronization"/>
<int value="1019857902"
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