Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(267)

Unified Diff: chrome/browser/autocomplete/autocomplete_browsertest.cc

Issue 1855423003: Interpret '?' and Ctrl-K or Ctrl-E as putting omnibox in keyword search mode for Default Search Pro… (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Removed forced queries using '?'. Removed Ctrl-K preserving the user's keyword if they're already … Created 4 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: chrome/browser/autocomplete/autocomplete_browsertest.cc
diff --git a/chrome/browser/autocomplete/autocomplete_browsertest.cc b/chrome/browser/autocomplete/autocomplete_browsertest.cc
index 00cecb7306f1477aa78bd79a77595cdb7be15cc8..203552cd80aeec94fc764cd789ad9b9f9c051b6d 100644
--- a/chrome/browser/autocomplete/autocomplete_browsertest.cc
+++ b/chrome/browser/autocomplete/autocomplete_browsertest.cc
@@ -35,6 +35,7 @@
#include "components/omnibox/browser/autocomplete_provider.h"
#include "components/omnibox/browser/omnibox_popup_model.h"
#include "components/omnibox/browser/omnibox_view.h"
+#include "components/search_engines/template_url_service.h"
#include "content/public/browser/notification_service.h"
#include "content/public/browser/notification_types.h"
#include "testing/gtest/include/gtest/gtest.h"
@@ -197,6 +198,19 @@ IN_PROC_BROWSER_TEST_F(AutocompleteBrowserTest, TabAwayRevertSelect) {
EXPECT_TRUE(omnibox_view->IsSelectAll());
}
+static void focusSearchCheckPreconditions() {
Peter Kasting 2016/04/13 02:52:16 Nit: First letter of function name should be capit
Tom (Use chromium acct) 2016/04/13 23:37:40 Done.
+ LocationBar* location_bar = GetLocationBar();
Peter Kasting 2016/04/13 02:52:16 You can't call GetLocationBar() from a non-member
Tom (Use chromium acct) 2016/04/13 23:37:40 Done.
+ OmniboxView* omnibox_view = location_bar->GetOmniboxView();
+ OmniboxEditModel* omnibox_model = omnibox_view->model();
+
+ EXPECT_FALSE(location_bar->GetDestinationURL().is_valid());
+ EXPECT_EQ(base::UTF8ToUTF16(url::kAboutBlankURL),
+ omnibox_view->GetText());
+ EXPECT_EQ(base::string16(), omnibox_model->keyword());
+ EXPECT_FALSE(omnibox_model->is_keyword_hint());
+ EXPECT_FALSE(omnibox_model->is_keyword_selected());
+}
+
IN_PROC_BROWSER_TEST_F(AutocompleteBrowserTest, FocusSearch) {
#if defined(OS_WIN) && defined(USE_ASH)
// Disable this test in Metro+Ash for now (http://crbug.com/262796).
@@ -208,85 +222,165 @@ IN_PROC_BROWSER_TEST_F(AutocompleteBrowserTest, FocusSearch) {
WaitForTemplateURLServiceToLoad();
LocationBar* location_bar = GetLocationBar();
OmniboxView* omnibox_view = location_bar->GetOmniboxView();
+ OmniboxEditModel* omnibox_model = omnibox_view->model();
- // Focus search when omnibox is blank
+ TemplateURLService* template_url_service =
+ TemplateURLServiceFactory::GetForProfile(browser()->profile());
+ base::string16 default_search_keyword =
+ template_url_service->GetDefaultSearchProvider()->keyword();
+
+ base::string16 query_text = ASCIIToUTF16("foo");
Peter Kasting 2016/04/13 02:52:16 Need base:: qualifier
Tom (Use chromium acct) 2016/04/13 23:37:40 Done.
+
+ size_t selection_start, selection_end;
+
+ // Focus search when omnibox is blank.
{
- EXPECT_FALSE(location_bar->GetDestinationURL().is_valid());
- EXPECT_EQ(base::UTF8ToUTF16(url::kAboutBlankURL), omnibox_view->GetText());
+ focusSearchCheckPreconditions();
location_bar->FocusSearch();
EXPECT_FALSE(location_bar->GetDestinationURL().is_valid());
- EXPECT_EQ(base::ASCIIToUTF16("?"), omnibox_view->GetText());
+ EXPECT_EQ(base::string16(), omnibox_view->GetText());
+ EXPECT_EQ(default_search_keyword, omnibox_model->keyword());
+ EXPECT_FALSE(omnibox_model->is_keyword_hint());
+ EXPECT_TRUE(omnibox_model->is_keyword_selected());
- size_t selection_start, selection_end;
omnibox_view->GetSelectionBounds(&selection_start, &selection_end);
- EXPECT_EQ(1U, selection_start);
- EXPECT_EQ(1U, selection_end);
+ EXPECT_EQ(0U, selection_start);
+ EXPECT_EQ(0U, selection_end);
+
+ omnibox_view->RevertAll();
}
// Focus search when omnibox is _not_ alread in forced query mode.
{
- omnibox_view->SetUserText(base::ASCIIToUTF16("foo"));
+ focusSearchCheckPreconditions();
+
+ omnibox_view->SetUserText(query_text);
EXPECT_FALSE(location_bar->GetDestinationURL().is_valid());
- EXPECT_EQ(base::ASCIIToUTF16("foo"), omnibox_view->GetText());
+ EXPECT_EQ(query_text, omnibox_view->GetText());
+ EXPECT_EQ(base::string16(), omnibox_model->keyword());
+ EXPECT_FALSE(omnibox_model->is_keyword_hint());
+ EXPECT_FALSE(omnibox_model->is_keyword_selected());
location_bar->FocusSearch();
EXPECT_FALSE(location_bar->GetDestinationURL().is_valid());
- EXPECT_EQ(base::ASCIIToUTF16("?"), omnibox_view->GetText());
+ EXPECT_EQ(query_text, omnibox_view->GetText());
+ EXPECT_EQ(default_search_keyword, omnibox_model->keyword());
+ EXPECT_FALSE(omnibox_model->is_keyword_hint());
+ EXPECT_TRUE(omnibox_model->is_keyword_selected());
- size_t selection_start, selection_end;
omnibox_view->GetSelectionBounds(&selection_start, &selection_end);
- EXPECT_EQ(1U, selection_start);
- EXPECT_EQ(1U, selection_end);
+ EXPECT_EQ(query_text.length(), selection_start);
+ EXPECT_EQ(query_text.length(), selection_end);
+
+ omnibox_view->RevertAll();
}
// Focus search when omnibox _is_ already in forced query mode, but no query
// has been typed.
{
- omnibox_view->SetUserText(base::ASCIIToUTF16("?"));
+ focusSearchCheckPreconditions();
+
+ location_bar->FocusSearch();
EXPECT_FALSE(location_bar->GetDestinationURL().is_valid());
- EXPECT_EQ(base::ASCIIToUTF16("?"), omnibox_view->GetText());
+ EXPECT_EQ(base::string16(), omnibox_view->GetText());
+ EXPECT_EQ(default_search_keyword, omnibox_model->keyword());
+ EXPECT_FALSE(omnibox_model->is_keyword_hint());
+ EXPECT_TRUE(omnibox_model->is_keyword_selected());
+
+ omnibox_view->GetSelectionBounds(&selection_start, &selection_end);
+ EXPECT_EQ(0U, selection_start);
+ EXPECT_EQ(0U, selection_end);
location_bar->FocusSearch();
EXPECT_FALSE(location_bar->GetDestinationURL().is_valid());
- EXPECT_EQ(base::ASCIIToUTF16("?"), omnibox_view->GetText());
+ EXPECT_EQ(base::string16(), omnibox_view->GetText());
+ EXPECT_EQ(default_search_keyword, omnibox_model->keyword());
+ EXPECT_FALSE(omnibox_model->is_keyword_hint());
+ EXPECT_TRUE(omnibox_model->is_keyword_selected());
- size_t selection_start, selection_end;
omnibox_view->GetSelectionBounds(&selection_start, &selection_end);
- EXPECT_EQ(1U, selection_start);
- EXPECT_EQ(1U, selection_end);
+ EXPECT_EQ(0U, selection_start);
+ EXPECT_EQ(0U, selection_end);
+
+ omnibox_view->RevertAll();
}
// Focus search when omnibox _is_ already in forced query mode, and some query
// has been typed.
{
- omnibox_view->SetUserText(base::ASCIIToUTF16("?foo"));
+ focusSearchCheckPreconditions();
+
+ omnibox_view->SetUserText(query_text);
+ location_bar->FocusSearch();
EXPECT_FALSE(location_bar->GetDestinationURL().is_valid());
- EXPECT_EQ(base::ASCIIToUTF16("?foo"), omnibox_view->GetText());
+ EXPECT_EQ(query_text, omnibox_view->GetText());
+ EXPECT_EQ(default_search_keyword, omnibox_model->keyword());
+ EXPECT_FALSE(omnibox_model->is_keyword_hint());
+ EXPECT_TRUE(omnibox_model->is_keyword_selected());
+
+ omnibox_view->GetSelectionBounds(&selection_start, &selection_end);
+ EXPECT_EQ(query_text.length(), selection_start);
+ EXPECT_EQ(query_text.length(), selection_end);
location_bar->FocusSearch();
EXPECT_FALSE(location_bar->GetDestinationURL().is_valid());
- EXPECT_EQ(base::ASCIIToUTF16("?foo"), omnibox_view->GetText());
+ EXPECT_EQ(query_text, omnibox_view->GetText());
+ EXPECT_EQ(default_search_keyword, omnibox_model->keyword());
+ EXPECT_FALSE(omnibox_model->is_keyword_hint());
+ EXPECT_TRUE(omnibox_model->is_keyword_selected());
- size_t selection_start, selection_end;
omnibox_view->GetSelectionBounds(&selection_start, &selection_end);
- EXPECT_EQ(1U, std::min(selection_start, selection_end));
- EXPECT_EQ(4U, std::max(selection_start, selection_end));
+ EXPECT_EQ(0U, std::min(selection_start, selection_end));
+ EXPECT_EQ(query_text.length(), std::min(selection_start, selection_end));
Peter Kasting 2016/04/13 02:52:16 Shouldn't this be max()?
Tom (Use chromium acct) 2016/04/13 23:37:40 Done.
+
+ omnibox_view->RevertAll();
}
- // Focus search when omnibox is in forced query mode with leading whitespace.
+ // If the user gets into keyword mode using a keyboard shortcut, and presses
+ // backspace, they should be left with their original query without their dsp
+ // keyword.
{
- omnibox_view->SetUserText(base::ASCIIToUTF16(" ?foo"));
- EXPECT_FALSE(location_bar->GetDestinationURL().is_valid());
- EXPECT_EQ(base::ASCIIToUTF16(" ?foo"), omnibox_view->GetText());
+ focusSearchCheckPreconditions();
+ omnibox_view->SetUserText(query_text);
+ // The user presses Ctrl-K.
location_bar->FocusSearch();
+ // The user presses backspace.
+ omnibox_model->ClearKeyword();
+
EXPECT_FALSE(location_bar->GetDestinationURL().is_valid());
- EXPECT_EQ(base::ASCIIToUTF16(" ?foo"), omnibox_view->GetText());
+ EXPECT_EQ(query_text, omnibox_view->GetText());
+ EXPECT_EQ(base::string16(), omnibox_model->keyword());
+ EXPECT_FALSE(omnibox_model->is_keyword_hint());
+ EXPECT_FALSE(omnibox_model->is_keyword_selected());
- size_t selection_start, selection_end;
- omnibox_view->GetSelectionBounds(&selection_start, &selection_end);
- EXPECT_EQ(4U, std::min(selection_start, selection_end));
- EXPECT_EQ(7U, std::max(selection_start, selection_end));
+ omnibox_view->RevertAll();
+ }
+
+ // If the user gets into keyword mode by typing '?', they should be put into
+ // keyword mode for their default search provider. If they press backspace,
+ // they should be left with '?' in the omnibox.
+ {
+ focusSearchCheckPreconditions();
+
+ omnibox_view->SetUserText(base::ASCIIToUTF16("?"));
+
+ EXPECT_FALSE(location_bar->GetDestinationURL().is_valid());
+ EXPECT_EQ(base::string16(), omnibox_view->GetText());
+ EXPECT_EQ(default_search_keyword, omnibox_model->keyword());
+ EXPECT_FALSE(omnibox_model->is_keyword_hint());
+ EXPECT_TRUE(omnibox_model->is_keyword_selected());
+
+ // The user presses backspace.
+ omnibox_model->ClearKeyword();
+
+ EXPECT_FALSE(location_bar->GetDestinationURL().is_valid());
+ EXPECT_EQ(base::ASCIIToUTF16("?"), omnibox_view->GetText());
+ EXPECT_EQ(base::string16(), omnibox_model->keyword());
+ EXPECT_FALSE(omnibox_model->is_keyword_hint());
+ EXPECT_FALSE(omnibox_model->is_keyword_selected());
+
+ omnibox_view->RevertAll();
}
}

Powered by Google App Engine
This is Rietveld 408576698