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

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: Fixed unit test compilation 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..1ce59b7bd8596625f821432dc05992006e7aa167 100644
--- a/chrome/browser/autocomplete/autocomplete_browsertest.cc
+++ b/chrome/browser/autocomplete/autocomplete_browsertest.cc
@@ -25,6 +25,7 @@
#include "chrome/common/chrome_paths.h"
#include "chrome/common/url_constants.h"
#include "chrome/test/base/in_process_browser_test.h"
+#include "chrome/test/base/interactive_test_utils.h"
#include "chrome/test/base/search_test_utils.h"
#include "chrome/test/base/test_switches.h"
#include "chrome/test/base/ui_test_utils.h"
@@ -35,6 +36,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"
@@ -69,6 +71,19 @@ class AutocompleteBrowserTest : public ExtensionBrowserTest {
return GetLocationBar()->GetOmniboxView()->model()->popup_model()->
autocomplete_controller();
}
+
+ void FocusSearchCheckPreconditions() const {
+ LocationBar* location_bar = GetLocationBar();
+ 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, Basic) {
@@ -208,85 +223,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();
+
+ TemplateURLService* template_url_service =
+ TemplateURLServiceFactory::GetForProfile(browser()->profile());
+ base::string16 default_search_keyword =
+ template_url_service->GetDefaultSearchProvider()->keyword();
+
+ base::string16 query_text = base::ASCIIToUTF16("foo");
- // Focus search when omnibox is blank
+ 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.
+ // Focus search when omnibox is _not_ alread in keyword mode.
Peter Kasting 2016/04/28 21:24:41 Nit: While here: alread -> already
Tom (Use chromium acct) 2016/04/29 01:10:20 Done.
{
- 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(0U, std::min(selection_start, selection_end));
+ EXPECT_EQ(query_text.length(), std::max(selection_start, selection_end));
+
+ omnibox_view->RevertAll();
}
- // Focus search when omnibox _is_ already in forced query mode, but no query
+ // Focus search when omnibox _is_ already in keyword 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
+ // Focus search when omnibox _is_ already in keyword 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(0U, std::min(selection_start, selection_end));
+ EXPECT_EQ(query_text.length(), std::max(selection_start, 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::max(selection_start, selection_end));
+
+ 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