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

Side by Side Diff: chrome/browser/autocomplete/autocomplete_edit_view_browsertest.cc

Issue 6281011: Allow space to accept keyword even when inline autocomplete is available. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Accept keyword even with selection. Created 9 years, 11 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) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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 236 matching lines...) Expand 10 before | Expand all | Expand 10 after
247 247
248 TemplateURL* template_url = new TemplateURL(); 248 TemplateURL* template_url = new TemplateURL();
249 template_url->SetURL(kSearchURL, 0, 0); 249 template_url->SetURL(kSearchURL, 0, 0);
250 template_url->set_keyword(UTF8ToUTF16(kSearchKeyword)); 250 template_url->set_keyword(UTF8ToUTF16(kSearchKeyword));
251 template_url->set_short_name(UTF8ToUTF16(kSearchShortName)); 251 template_url->set_short_name(UTF8ToUTF16(kSearchShortName));
252 252
253 model->Add(template_url); 253 model->Add(template_url);
254 model->SetDefaultSearchProvider(template_url); 254 model->SetDefaultSearchProvider(template_url);
255 } 255 }
256 256
257 void SetupHistory() { 257 void AddHistoryEntry(const TestHistoryEntry& entry, const Time& time) {
258 Profile* profile = browser()->profile(); 258 Profile* profile = browser()->profile();
259 HistoryService* history_service = 259 HistoryService* history_service =
260 profile->GetHistoryService(Profile::EXPLICIT_ACCESS); 260 profile->GetHistoryService(Profile::EXPLICIT_ACCESS);
261 ASSERT_TRUE(history_service); 261 ASSERT_TRUE(history_service);
262 262
263 if (!history_service->BackendLoaded()) { 263 if (!history_service->BackendLoaded()) {
264 NotificationRegistrar registrar; 264 NotificationRegistrar registrar;
265 registrar.Add(this, NotificationType::HISTORY_LOADED, 265 registrar.Add(this, NotificationType::HISTORY_LOADED,
266 Source<Profile>(profile)); 266 Source<Profile>(profile));
267 ui_test_utils::RunMessageLoop(); 267 ui_test_utils::RunMessageLoop();
268 } 268 }
269 269
270 BookmarkModel* bookmark_model = profile->GetBookmarkModel(); 270 BookmarkModel* bookmark_model = profile->GetBookmarkModel();
271 ASSERT_TRUE(bookmark_model); 271 ASSERT_TRUE(bookmark_model);
272 272
273 if (!bookmark_model->IsLoaded()) { 273 if (!bookmark_model->IsLoaded()) {
274 NotificationRegistrar registrar; 274 NotificationRegistrar registrar;
275 registrar.Add(this, NotificationType::BOOKMARK_MODEL_LOADED, 275 registrar.Add(this, NotificationType::BOOKMARK_MODEL_LOADED,
276 Source<Profile>(profile)); 276 Source<Profile>(profile));
277 ui_test_utils::RunMessageLoop(); 277 ui_test_utils::RunMessageLoop();
278 } 278 }
279 279
280 GURL url(entry.url);
281 // Add everything in order of time. We don't want to have a time that
282 // is "right now" or it will nondeterministically appear in the results.
283 history_service->AddPageWithDetails(url, UTF8ToUTF16(entry.title),
284 entry.visit_count,
285 entry.typed_count, time, false,
286 history::SOURCE_BROWSED);
287 history_service->SetPageContents(url, UTF8ToUTF16(entry.body));
288 if (entry.starred)
289 bookmark_model->SetURLStarred(url, string16(), true);
290 }
291
292 void SetupHistory() {
280 // Add enough history pages containing |kSearchText| to trigger 293 // Add enough history pages containing |kSearchText| to trigger
281 // open history page url in autocomplete result. 294 // open history page url in autocomplete result.
282 for (size_t i = 0; i < arraysize(kHistoryEntries); i++) { 295 for (size_t i = 0; i < arraysize(kHistoryEntries); i++) {
283 const TestHistoryEntry& cur = kHistoryEntries[i];
284 GURL url(cur.url);
285 // Add everything in order of time. We don't want to have a time that 296 // Add everything in order of time. We don't want to have a time that
286 // is "right now" or it will nondeterministically appear in the results. 297 // is "right now" or it will nondeterministically appear in the results.
287 Time t = Time::Now() - TimeDelta::FromHours(i + 1); 298 Time t = Time::Now() - TimeDelta::FromHours(i + 1);
288 history_service->AddPageWithDetails(url, UTF8ToUTF16(cur.title), 299 ASSERT_NO_FATAL_FAILURE(AddHistoryEntry(kHistoryEntries[i], t));
289 cur.visit_count,
290 cur.typed_count, t, false,
291 history::SOURCE_BROWSED);
292 history_service->SetPageContents(url, UTF8ToUTF16(cur.body));
293 if (cur.starred) {
294 bookmark_model->SetURLStarred(url, string16(), true);
295 }
296 } 300 }
297 } 301 }
298 302
299 void SetupHostResolver() { 303 void SetupHostResolver() {
300 for (size_t i = 0; i < arraysize(kBlockedHostnames); ++i) 304 for (size_t i = 0; i < arraysize(kBlockedHostnames); ++i)
301 host_resolver()->AddSimulatedFailure(kBlockedHostnames[i]); 305 host_resolver()->AddSimulatedFailure(kBlockedHostnames[i]);
302 } 306 }
303 307
304 void SetupComponents() { 308 void SetupComponents() {
305 ASSERT_NO_FATAL_FAILURE(SetupHostResolver()); 309 ASSERT_NO_FATAL_FAILURE(SetupHostResolver());
(...skipping 425 matching lines...) Expand 10 before | Expand all | Expand 10 after
731 ASSERT_TRUE(edit_view->model()->keyword().empty()); 735 ASSERT_TRUE(edit_view->model()->keyword().empty());
732 736
733 edit_view->OnBeforePossibleChange(); 737 edit_view->OnBeforePossibleChange();
734 edit_view->model()->on_paste(); 738 edit_view->model()->on_paste();
735 edit_view->SetWindowTextAndCaretPos(text + L" bar", text.length() + 4); 739 edit_view->SetWindowTextAndCaretPos(text + L" bar", text.length() + 4);
736 edit_view->OnAfterPossibleChange(); 740 edit_view->OnAfterPossibleChange();
737 ASSERT_FALSE(edit_view->model()->is_keyword_hint()); 741 ASSERT_FALSE(edit_view->model()->is_keyword_hint());
738 ASSERT_TRUE(edit_view->model()->keyword().empty()); 742 ASSERT_TRUE(edit_view->model()->keyword().empty());
739 ASSERT_EQ(text + L" bar", edit_view->GetText()); 743 ASSERT_EQ(text + L" bar", edit_view->GetText());
740 744
741 // Keyword shouldn't be accepted by pressing space with a selected range. 745 // Keyword could be accepted by pressing space with a selected range at the
Peter Kasting 2011/01/25 02:12:22 Nit: could -> can
746 // end of text.
742 edit_view->OnBeforePossibleChange(); 747 edit_view->OnBeforePossibleChange();
743 edit_view->OnInlineAutocompleteTextMaybeChanged( 748 edit_view->OnInlineAutocompleteTextMaybeChanged(
744 text + L" ", text.length()); 749 text + L" ", text.length());
745 edit_view->OnAfterPossibleChange(); 750 edit_view->OnAfterPossibleChange();
746 ASSERT_TRUE(edit_view->model()->is_keyword_hint()); 751 ASSERT_TRUE(edit_view->model()->is_keyword_hint());
747 ASSERT_EQ(text, edit_view->model()->keyword()); 752 ASSERT_EQ(text, edit_view->model()->keyword());
748 ASSERT_EQ(text + L" ", edit_view->GetText()); 753 ASSERT_EQ(text + L" ", edit_view->GetText());
749 754
750 std::wstring::size_type start, end; 755 std::wstring::size_type start, end;
751 edit_view->GetSelectionBounds(&start, &end); 756 edit_view->GetSelectionBounds(&start, &end);
752 ASSERT_NE(start, end); 757 ASSERT_NE(start, end);
753 ASSERT_NO_FATAL_FAILURE(SendKey(ui::VKEY_SPACE, false, false, false)); 758 ASSERT_NO_FATAL_FAILURE(SendKey(ui::VKEY_SPACE, false, false, false));
754 ASSERT_TRUE(edit_view->model()->is_keyword_hint()); 759 ASSERT_FALSE(edit_view->model()->is_keyword_hint());
755 ASSERT_EQ(text, edit_view->model()->keyword()); 760 ASSERT_EQ(text, edit_view->model()->keyword());
756 ASSERT_EQ(text + L" ", edit_view->GetText()); 761 ASSERT_EQ(std::wstring(), edit_view->GetText());
757 762
758 edit_view->GetSelectionBounds(&start, &end); 763 edit_view->SetUserText(std::wstring());
759 ASSERT_EQ(start, end); 764
765 // Space should accept keyword even when inline autocomplete is available.
766 const TestHistoryEntry kHistoryFoobar = {
767 "http://www.foobar.com", "Page foobar", kSearchText, 10000, 10000, true
768 };
769
770 // Add a history entry to trigger inline autocomplete when typing "foo".
771 ASSERT_NO_FATAL_FAILURE(
772 AddHistoryEntry(kHistoryFoobar, Time::Now() - TimeDelta::FromHours(1)));
773
774 // Type "foo" to trigger inline autocomplete.
775 ASSERT_NO_FATAL_FAILURE(SendKeySequence(kSearchKeywordKeys));
776 ASSERT_NO_FATAL_FAILURE(WaitForAutocompleteControllerDone());
777 ASSERT_TRUE(edit_view->model()->popup_model()->IsOpen());
778 ASSERT_NE(text, edit_view->GetText());
779
780 // Keyword hint shouldn't be visible.
781 ASSERT_FALSE(edit_view->model()->is_keyword_hint());
782 ASSERT_TRUE(edit_view->model()->keyword().empty());
783
784 // Trigger keyword mode by space.
785 ASSERT_NO_FATAL_FAILURE(SendKey(ui::VKEY_SPACE, false, false, false));
786 ASSERT_FALSE(edit_view->model()->is_keyword_hint());
787 ASSERT_EQ(text, edit_view->model()->keyword());
788 ASSERT_TRUE(edit_view->GetText().empty());
760 } 789 }
761 790
762 }; 791 };
763 792
764 // Test if ctrl-* accelerators are workable in omnibox. 793 // Test if ctrl-* accelerators are workable in omnibox.
765 // See http://crbug.com/19193: omnibox blocks ctrl-* commands 794 // See http://crbug.com/19193: omnibox blocks ctrl-* commands
766 // 795 //
767 // Flaky on interactive tests (dbg), http://crbug.com/69433 796 // Flaky on interactive tests (dbg), http://crbug.com/69433
768 IN_PROC_BROWSER_TEST_F(AutocompleteEditViewTest, FLAKY_BrowserAccelerators) { 797 IN_PROC_BROWSER_TEST_F(AutocompleteEditViewTest, FLAKY_BrowserAccelerators) {
769 BrowserAcceleratorsTest(); 798 BrowserAcceleratorsTest();
(...skipping 212 matching lines...) Expand 10 before | Expand all | Expand 10 after
982 1011
983 IN_PROC_BROWSER_TEST_F(AutocompleteEditViewViewsTest, BasicTextOperations) { 1012 IN_PROC_BROWSER_TEST_F(AutocompleteEditViewViewsTest, BasicTextOperations) {
984 BasicTextOperationsTest(); 1013 BasicTextOperationsTest();
985 } 1014 }
986 1015
987 IN_PROC_BROWSER_TEST_F(AutocompleteEditViewViewsTest, AcceptKeywordBySpace) { 1016 IN_PROC_BROWSER_TEST_F(AutocompleteEditViewViewsTest, AcceptKeywordBySpace) {
988 AcceptKeywordBySpaceTest(); 1017 AcceptKeywordBySpaceTest();
989 } 1018 }
990 1019
991 #endif 1020 #endif
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698