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

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: Add includes for mac tests Created 4 years, 6 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
« no previous file with comments | « no previous file | chrome/browser/autocomplete/search_provider_unittest.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/browser/autocomplete/autocomplete_browsertest.cc
diff --git a/chrome/browser/autocomplete/autocomplete_browsertest.cc b/chrome/browser/autocomplete/autocomplete_browsertest.cc
index 7ba7fbdbefdb5f0eb3e0b3f6fc2fe5994f2e3e24..8cce36c1ba41532eb1da62e04c5b1f46a00c0e83 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/ui_test_utils.h"
#include "components/history/core/browser/history_service.h"
@@ -34,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"
@@ -68,6 +70,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) {
@@ -179,85 +194,139 @@ 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");
+
+ size_t selection_start, selection_end;
- // Focus search when omnibox is blank
+ // 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_ already in keyword 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(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();
}
}
« no previous file with comments | « no previous file | chrome/browser/autocomplete/search_provider_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698