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

Side by Side Diff: chrome/browser/ui/omnibox/omnibox_view_browsertest.cc

Issue 9570064: Fix keyword search erroneously not triggering in two obscure cases: (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: Created 8 years, 9 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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include <stdio.h> 5 #include <stdio.h>
6 6
7 #include "base/message_loop.h" 7 #include "base/message_loop.h"
8 #include "base/string16.h" 8 #include "base/string16.h"
9 #include "base/string_util.h" 9 #include "base/string_util.h"
10 #include "base/time.h" 10 #include "base/time.h"
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
47 #include "ui/views/events/event.h" 47 #include "ui/views/events/event.h"
48 #include "ui/views/widget/widget.h" 48 #include "ui/views/widget/widget.h"
49 #endif 49 #endif
50 50
51 using base::Time; 51 using base::Time;
52 using base::TimeDelta; 52 using base::TimeDelta;
53 53
54 namespace { 54 namespace {
55 55
56 const char kSearchKeyword[] = "foo"; 56 const char kSearchKeyword[] = "foo";
57 const char kSearchKeyword2[] = "footest.com";
57 const wchar_t kSearchKeywordKeys[] = { 58 const wchar_t kSearchKeywordKeys[] = {
58 ui::VKEY_F, ui::VKEY_O, ui::VKEY_O, 0 59 ui::VKEY_F, ui::VKEY_O, ui::VKEY_O, 0
59 }; 60 };
60 const char kSearchURL[] = "http://www.foo.com/search?q={searchTerms}"; 61 const char kSearchURL[] = "http://www.foo.com/search?q={searchTerms}";
61 const char kSearchShortName[] = "foo"; 62 const char kSearchShortName[] = "foo";
62 const char kSearchText[] = "abc"; 63 const char kSearchText[] = "abc";
63 const wchar_t kSearchTextKeys[] = { 64 const wchar_t kSearchTextKeys[] = {
64 ui::VKEY_A, ui::VKEY_B, ui::VKEY_C, 0 65 ui::VKEY_A, ui::VKEY_B, ui::VKEY_C, 0
65 }; 66 };
66 const char kSearchTextURL[] = "http://www.foo.com/search?q=abc"; 67 const char kSearchTextURL[] = "http://www.foo.com/search?q=abc";
(...skipping 216 matching lines...) Expand 10 before | Expand all | Expand 10 after
283 for (TemplateURLService::TemplateURLVector::const_iterator 284 for (TemplateURLService::TemplateURLVector::const_iterator
284 i = builtins.begin(); i != builtins.end(); ++i) 285 i = builtins.begin(); i != builtins.end(); ++i)
285 model->Remove(*i); 286 model->Remove(*i);
286 287
287 TemplateURL* template_url = new TemplateURL(); 288 TemplateURL* template_url = new TemplateURL();
288 template_url->SetURL(kSearchURL, 0, 0); 289 template_url->SetURL(kSearchURL, 0, 0);
289 template_url->set_keyword(ASCIIToUTF16(kSearchKeyword)); 290 template_url->set_keyword(ASCIIToUTF16(kSearchKeyword));
290 template_url->set_short_name(ASCIIToUTF16(kSearchShortName)); 291 template_url->set_short_name(ASCIIToUTF16(kSearchShortName));
291 model->Add(template_url); 292 model->Add(template_url);
292 model->SetDefaultSearchProvider(template_url); 293 model->SetDefaultSearchProvider(template_url);
294
295 TemplateURL* second_url = new TemplateURL();
296 second_url->SetURL(kSearchURL, 0, 0);
297 second_url->set_keyword(ASCIIToUTF16(kSearchKeyword2));
298 second_url->set_short_name(ASCIIToUTF16(kSearchShortName));
299 model->Add(second_url);
293 } 300 }
294 301
295 void AddHistoryEntry(const TestHistoryEntry& entry, const Time& time) { 302 void AddHistoryEntry(const TestHistoryEntry& entry, const Time& time) {
296 Profile* profile = browser()->profile(); 303 Profile* profile = browser()->profile();
297 HistoryService* history_service = 304 HistoryService* history_service =
298 profile->GetHistoryService(Profile::EXPLICIT_ACCESS); 305 profile->GetHistoryService(Profile::EXPLICIT_ACCESS);
299 ASSERT_TRUE(history_service); 306 ASSERT_TRUE(history_service);
300 307
301 if (!history_service->BackendLoaded()) { 308 if (!history_service->BackendLoaded()) {
302 content::NotificationRegistrar registrar; 309 content::NotificationRegistrar registrar;
(...skipping 565 matching lines...) Expand 10 before | Expand all | Expand 10 after
868 875
869 // Keyword hint shouldn't be visible. 876 // Keyword hint shouldn't be visible.
870 ASSERT_FALSE(omnibox_view->model()->is_keyword_hint()); 877 ASSERT_FALSE(omnibox_view->model()->is_keyword_hint());
871 ASSERT_TRUE(omnibox_view->model()->keyword().empty()); 878 ASSERT_TRUE(omnibox_view->model()->keyword().empty());
872 879
873 // Trigger keyword mode by space. 880 // Trigger keyword mode by space.
874 ASSERT_NO_FATAL_FAILURE(SendKey(ui::VKEY_SPACE, 0)); 881 ASSERT_NO_FATAL_FAILURE(SendKey(ui::VKEY_SPACE, 0));
875 ASSERT_FALSE(omnibox_view->model()->is_keyword_hint()); 882 ASSERT_FALSE(omnibox_view->model()->is_keyword_hint());
876 ASSERT_EQ(search_keyword, omnibox_view->model()->keyword()); 883 ASSERT_EQ(search_keyword, omnibox_view->model()->keyword());
877 ASSERT_TRUE(omnibox_view->GetText().empty()); 884 ASSERT_TRUE(omnibox_view->GetText().empty());
885
886 // Space in the middle of a temporary text, which separates the text into
887 // keyword and replacement portions, should trigger keyword mode.
888 omnibox_view->SetUserText(string16());
889 ASSERT_NO_FATAL_FAILURE(SendKeySequence(kSearchKeywordKeys));
890 ASSERT_NO_FATAL_FAILURE(WaitForAutocompleteControllerDone());
891 AutocompletePopupModel* popup_model = omnibox_view->model()->popup_model();
892 ASSERT_TRUE(popup_model->IsOpen());
893 ASSERT_EQ(ASCIIToUTF16("foobar.com"), omnibox_view->GetText());
894 omnibox_view->model()->OnUpOrDownKeyPressed(1);
895 omnibox_view->model()->OnUpOrDownKeyPressed(-1);
896 ASSERT_NO_FATAL_FAILURE(SendKey(ui::VKEY_LEFT, 0));
897 ASSERT_NO_FATAL_FAILURE(SendKey(ui::VKEY_LEFT, 0));
898 ASSERT_NO_FATAL_FAILURE(SendKey(ui::VKEY_LEFT, 0));
899 ASSERT_NO_FATAL_FAILURE(SendKey(ui::VKEY_LEFT, 0));
900 ASSERT_NO_FATAL_FAILURE(SendKey(ui::VKEY_LEFT, 0));
901 ASSERT_NO_FATAL_FAILURE(SendKey(ui::VKEY_LEFT, 0));
902 ASSERT_NO_FATAL_FAILURE(SendKey(ui::VKEY_LEFT, 0));
903 ASSERT_NO_FATAL_FAILURE(SendKey(ui::VKEY_SPACE, 0));
904 ASSERT_FALSE(omnibox_view->model()->is_keyword_hint());
905 ASSERT_EQ(search_keyword, omnibox_view->model()->keyword());
906 ASSERT_EQ(ASCIIToUTF16("bar.com"), omnibox_view->GetText());
907
908 // Space after temporary text that looks like a keyword, when the original
909 // input does not look like a keyword, should trigger keyword mode.
910 omnibox_view->SetUserText(string16());
911 const TestHistoryEntry kHistoryFoo = {
912 "http://footest.com", "Page footest", kSearchText, 1000, 1000, true
913 };
914
915 // Add a history entry to trigger HQP matching with text == keyword when
916 // typing "fo te".
917 ASSERT_NO_FATAL_FAILURE(
918 AddHistoryEntry(kHistoryFoo, Time::Now() - TimeDelta::FromMinutes(10)));
919
920 ASSERT_NO_FATAL_FAILURE(SendKey(ui::VKEY_F, 0));
921 ASSERT_NO_FATAL_FAILURE(SendKey(ui::VKEY_O, 0));
922 ASSERT_NO_FATAL_FAILURE(SendKey(ui::VKEY_SPACE, 0));
923 ASSERT_NO_FATAL_FAILURE(SendKey(ui::VKEY_T, 0));
924 ASSERT_NO_FATAL_FAILURE(SendKey(ui::VKEY_E, 0));
925 ASSERT_NO_FATAL_FAILURE(WaitForAutocompleteControllerDone());
926 ASSERT_TRUE(popup_model->IsOpen());
927 string16 search_keyword2(ASCIIToUTF16(kSearchKeyword2));
928 while ((omnibox_view->GetText() != search_keyword2) &&
929 (popup_model->selected_line() < popup_model->result().size() - 1))
930 omnibox_view->model()->OnUpOrDownKeyPressed(1);
931 ASSERT_EQ(search_keyword2, omnibox_view->GetText());
932 ASSERT_NO_FATAL_FAILURE(SendKey(ui::VKEY_SPACE, 0));
933 ASSERT_FALSE(omnibox_view->model()->is_keyword_hint());
934 ASSERT_EQ(search_keyword2, omnibox_view->model()->keyword());
935 ASSERT_TRUE(omnibox_view->GetText().empty());
878 } 936 }
879 937
880 void NonSubstitutingKeywordTest() { 938 void NonSubstitutingKeywordTest() {
881 OmniboxView* omnibox_view = NULL; 939 OmniboxView* omnibox_view = NULL;
882 ASSERT_NO_FATAL_FAILURE(GetOmniboxView(&omnibox_view)); 940 ASSERT_NO_FATAL_FAILURE(GetOmniboxView(&omnibox_view));
883 AutocompletePopupModel* popup_model = omnibox_view->model()->popup_model(); 941 AutocompletePopupModel* popup_model = omnibox_view->model()->popup_model();
884 ASSERT_TRUE(popup_model); 942 ASSERT_TRUE(popup_model);
885 943
886 TemplateURLService* template_url_service = 944 TemplateURLService* template_url_service =
887 TemplateURLServiceFactory::GetForProfile(browser()->profile()); 945 TemplateURLServiceFactory::GetForProfile(browser()->profile());
(...skipping 531 matching lines...) Expand 10 before | Expand all | Expand 10 after
1419 1477
1420 // Paste text. 1478 // Paste text.
1421 ASSERT_NO_FATAL_FAILURE(SendKey(ui::VKEY_V, ui::EF_CONTROL_DOWN)); 1479 ASSERT_NO_FATAL_FAILURE(SendKey(ui::VKEY_V, ui::EF_CONTROL_DOWN));
1422 ASSERT_NO_FATAL_FAILURE(WaitForAutocompleteControllerDone()); 1480 ASSERT_NO_FATAL_FAILURE(WaitForAutocompleteControllerDone());
1423 ASSERT_TRUE(popup_model->IsOpen()); 1481 ASSERT_TRUE(popup_model->IsOpen());
1424 1482
1425 // Inline autocomplete shouldn't be triggered. 1483 // Inline autocomplete shouldn't be triggered.
1426 ASSERT_EQ(ASCIIToUTF16("abc"), omnibox_view->GetText()); 1484 ASSERT_EQ(ASCIIToUTF16("abc"), omnibox_view->GetText());
1427 } 1485 }
1428 #endif 1486 #endif
OLDNEW
« no previous file with comments | « chrome/browser/ui/gtk/omnibox/omnibox_view_gtk.cc ('k') | chrome/browser/ui/views/omnibox/omnibox_view_views.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698