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

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

Issue 9586012: Some fixes split off from https://chromiumcodereview.appspot.com/9570064/ to try and make the omnib… (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
« no previous file with comments | « chrome/browser/history/history_backend.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 134 matching lines...) Expand 10 before | Expand all | Expand 10 after
145 #endif 145 #endif
146 146
147 } // namespace 147 } // namespace
148 148
149 class OmniboxViewTest : public InProcessBrowserTest, 149 class OmniboxViewTest : public InProcessBrowserTest,
150 public content::NotificationObserver { 150 public content::NotificationObserver {
151 protected: 151 protected:
152 OmniboxViewTest() 152 OmniboxViewTest()
153 : location_bar_focus_view_id_(VIEW_ID_LOCATION_BAR) { 153 : location_bar_focus_view_id_(VIEW_ID_LOCATION_BAR) {
154 set_show_window(true); 154 set_show_window(true);
155 // TODO(mrossetti): HQP does not yet support DeleteMatch.
156 // http://crbug.com/82335
157 HistoryQuickProvider::set_disabled(true);
158 } 155 }
159 156
160 virtual void SetUpOnMainThread() { 157 virtual void SetUpOnMainThread() {
161 ASSERT_TRUE(ui_test_utils::BringBrowserWindowToFront(browser())); 158 ASSERT_TRUE(ui_test_utils::BringBrowserWindowToFront(browser()));
162 ASSERT_NO_FATAL_FAILURE(SetupComponents()); 159 ASSERT_NO_FATAL_FAILURE(SetupComponents());
163 browser()->FocusLocationBar(); 160 browser()->FocusLocationBar();
164 // Use Textfield's view id on pure views. See crbug.com/71144. 161 // Use Textfield's view id on pure views. See crbug.com/71144.
165 #if defined(TOOLKIT_VIEWS) 162 #if defined(TOOLKIT_VIEWS)
166 if (views::Widget::IsPureViews()) 163 if (views::Widget::IsPureViews())
167 location_bar_focus_view_id_ = VIEW_ID_OMNIBOX; 164 location_bar_focus_view_id_ = VIEW_ID_OMNIBOX;
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after
241 238
242 void WaitForTabOpenOrClose(int expected_tab_count) { 239 void WaitForTabOpenOrClose(int expected_tab_count) {
243 WaitForTabOpenOrCloseForBrowser(browser(), expected_tab_count); 240 WaitForTabOpenOrCloseForBrowser(browser(), expected_tab_count);
244 } 241 }
245 242
246 void WaitForAutocompleteControllerDone() { 243 void WaitForAutocompleteControllerDone() {
247 OmniboxView* omnibox_view = NULL; 244 OmniboxView* omnibox_view = NULL;
248 ASSERT_NO_FATAL_FAILURE(GetOmniboxView(&omnibox_view)); 245 ASSERT_NO_FATAL_FAILURE(GetOmniboxView(&omnibox_view));
249 246
250 AutocompleteController* controller = 247 AutocompleteController* controller =
251 omnibox_view->model()->popup_model()->autocomplete_controller(); 248 omnibox_view->model()->autocomplete_controller();
252 ASSERT_TRUE(controller); 249 ASSERT_TRUE(controller);
253 250
254 if (controller->done()) 251 if (controller->done())
255 return; 252 return;
256 253
257 content::NotificationRegistrar registrar; 254 content::NotificationRegistrar registrar;
258 registrar.Add(this, 255 registrar.Add(this,
259 chrome::NOTIFICATION_AUTOCOMPLETE_CONTROLLER_RESULT_READY, 256 chrome::NOTIFICATION_AUTOCOMPLETE_CONTROLLER_RESULT_READY,
260 content::Source<AutocompleteController>(controller)); 257 content::Source<AutocompleteController>(controller));
261 258
(...skipping 20 matching lines...) Expand all
282 // Remove built-in template urls, like google.com, bing.com etc., as they 279 // Remove built-in template urls, like google.com, bing.com etc., as they
283 // may appear as autocomplete suggests and interfere with our tests. 280 // may appear as autocomplete suggests and interfere with our tests.
284 model->SetDefaultSearchProvider(NULL); 281 model->SetDefaultSearchProvider(NULL);
285 TemplateURLService::TemplateURLVector builtins = model->GetTemplateURLs(); 282 TemplateURLService::TemplateURLVector builtins = model->GetTemplateURLs();
286 for (TemplateURLService::TemplateURLVector::const_iterator 283 for (TemplateURLService::TemplateURLVector::const_iterator
287 i = builtins.begin(); i != builtins.end(); ++i) 284 i = builtins.begin(); i != builtins.end(); ++i)
288 model->Remove(*i); 285 model->Remove(*i);
289 286
290 TemplateURL* template_url = new TemplateURL(); 287 TemplateURL* template_url = new TemplateURL();
291 template_url->SetURL(kSearchURL, 0, 0); 288 template_url->SetURL(kSearchURL, 0, 0);
292 template_url->set_keyword(UTF8ToUTF16(kSearchKeyword)); 289 template_url->set_keyword(ASCIIToUTF16(kSearchKeyword));
293 template_url->set_short_name(UTF8ToUTF16(kSearchShortName)); 290 template_url->set_short_name(ASCIIToUTF16(kSearchShortName));
294
295 model->Add(template_url); 291 model->Add(template_url);
296 model->SetDefaultSearchProvider(template_url); 292 model->SetDefaultSearchProvider(template_url);
297 } 293 }
298 294
299 void AddHistoryEntry(const TestHistoryEntry& entry, const Time& time) { 295 void AddHistoryEntry(const TestHistoryEntry& entry, const Time& time) {
300 Profile* profile = browser()->profile(); 296 Profile* profile = browser()->profile();
301 HistoryService* history_service = 297 HistoryService* history_service =
302 profile->GetHistoryService(Profile::EXPLICIT_ACCESS); 298 profile->GetHistoryService(Profile::EXPLICIT_ACCESS);
303 ASSERT_TRUE(history_service); 299 ASSERT_TRUE(history_service);
304 300
(...skipping 17 matching lines...) Expand all
322 GURL url(entry.url); 318 GURL url(entry.url);
323 // Add everything in order of time. We don't want to have a time that 319 // Add everything in order of time. We don't want to have a time that
324 // is "right now" or it will nondeterministically appear in the results. 320 // is "right now" or it will nondeterministically appear in the results.
325 history_service->AddPageWithDetails(url, UTF8ToUTF16(entry.title), 321 history_service->AddPageWithDetails(url, UTF8ToUTF16(entry.title),
326 entry.visit_count, 322 entry.visit_count,
327 entry.typed_count, time, false, 323 entry.typed_count, time, false,
328 history::SOURCE_BROWSED); 324 history::SOURCE_BROWSED);
329 history_service->SetPageContents(url, UTF8ToUTF16(entry.body)); 325 history_service->SetPageContents(url, UTF8ToUTF16(entry.body));
330 if (entry.starred) 326 if (entry.starred)
331 bookmark_utils::AddIfNotBookmarked(bookmark_model, url, string16()); 327 bookmark_utils::AddIfNotBookmarked(bookmark_model, url, string16());
328 // Wait at least for the AddPageWithDetails() call to finish.
329 {
330 content::NotificationRegistrar registrar;
331 registrar.Add(this, chrome::NOTIFICATION_HISTORY_TYPED_URLS_MODIFIED,
332 content::Source<Profile>(profile));
333 ui_test_utils::RunMessageLoop();
334 // We don't want to return until all observers have processed this
335 // notification, because some (e.g. the in-memory history database) may do
336 // something important. Since we don't know where in the observer list we
337 // stand, just spin the message loop once more to allow the current
338 // callstack to complete.
339 ui_test_utils::RunAllPendingInMessageLoop();
340 }
332 } 341 }
333 342
334 void SetupHistory() { 343 void SetupHistory() {
335 // Add enough history pages containing |kSearchText| to trigger 344 // Add enough history pages containing |kSearchText| to trigger
336 // open history page url in autocomplete result. 345 // open history page url in autocomplete result.
337 for (size_t i = 0; i < arraysize(kHistoryEntries); i++) { 346 for (size_t i = 0; i < arraysize(kHistoryEntries); i++) {
338 // Add everything in order of time. We don't want to have a time that 347 // Add everything in order of time. We don't want to have a time that
339 // is "right now" or it will nondeterministically appear in the results. 348 // is "right now" or it will nondeterministically appear in the results.
340 Time t = Time::Now() - TimeDelta::FromHours(i + 1); 349 Time t = Time::Now() - TimeDelta::FromHours(i + 1);
341 ASSERT_NO_FATAL_FAILURE(AddHistoryEntry(kHistoryEntries[i], t)); 350 ASSERT_NO_FATAL_FAILURE(AddHistoryEntry(kHistoryEntries[i], t));
342 } 351 }
343 } 352 }
344 353
345 void SetupHostResolver() { 354 void SetupHostResolver() {
346 for (size_t i = 0; i < arraysize(kBlockedHostnames); ++i) 355 for (size_t i = 0; i < arraysize(kBlockedHostnames); ++i)
347 host_resolver()->AddSimulatedFailure(kBlockedHostnames[i]); 356 host_resolver()->AddSimulatedFailure(kBlockedHostnames[i]);
348 } 357 }
349 358
350 void SetupComponents() { 359 void SetupComponents() {
351 ASSERT_NO_FATAL_FAILURE(SetupHostResolver()); 360 ASSERT_NO_FATAL_FAILURE(SetupHostResolver());
352 ASSERT_NO_FATAL_FAILURE(SetupSearchEngine()); 361 ASSERT_NO_FATAL_FAILURE(SetupSearchEngine());
353 ASSERT_NO_FATAL_FAILURE(SetupHistory()); 362 ASSERT_NO_FATAL_FAILURE(SetupHistory());
354 } 363 }
355 364
356 virtual void Observe(int type, 365 virtual void Observe(int type,
357 const content::NotificationSource& source, 366 const content::NotificationSource& source,
358 const content::NotificationDetails& details) { 367 const content::NotificationDetails& details) {
359 switch (type) { 368 switch (type) {
369 case content::NOTIFICATION_TAB_CLOSED:
360 case content::NOTIFICATION_TAB_PARENTED: 370 case content::NOTIFICATION_TAB_PARENTED:
361 case content::NOTIFICATION_TAB_CLOSED: 371 case chrome::NOTIFICATION_AUTOCOMPLETE_CONTROLLER_RESULT_READY:
372 case chrome::NOTIFICATION_BOOKMARK_MODEL_LOADED:
373 case chrome::NOTIFICATION_HISTORY_LOADED:
374 case chrome::NOTIFICATION_HISTORY_TYPED_URLS_MODIFIED:
362 case chrome::NOTIFICATION_TEMPLATE_URL_SERVICE_LOADED: 375 case chrome::NOTIFICATION_TEMPLATE_URL_SERVICE_LOADED:
363 case chrome::NOTIFICATION_AUTOCOMPLETE_CONTROLLER_RESULT_READY:
364 case chrome::NOTIFICATION_HISTORY_LOADED:
365 case chrome::NOTIFICATION_BOOKMARK_MODEL_LOADED:
366 break; 376 break;
367 default: 377 default:
368 FAIL() << "Unexpected notification type"; 378 FAIL() << "Unexpected notification type";
369 } 379 }
370 MessageLoopForUI::current()->Quit(); 380 MessageLoop::current()->Quit();
371 } 381 }
372 382
373 void BrowserAcceleratorsTest() { 383 void BrowserAcceleratorsTest() {
374 OmniboxView* omnibox_view = NULL; 384 OmniboxView* omnibox_view = NULL;
375 ASSERT_NO_FATAL_FAILURE(GetOmniboxView(&omnibox_view)); 385 ASSERT_NO_FATAL_FAILURE(GetOmniboxView(&omnibox_view));
376 386
377 int tab_count = browser()->tab_count(); 387 int tab_count = browser()->tab_count();
378 388
379 // Create a new Tab. 389 // Create a new Tab.
380 browser()->NewTab(); 390 browser()->NewTab();
(...skipping 345 matching lines...) Expand 10 before | Expand all | Expand 10 after
726 EXPECT_EQ(old_text, omnibox_view->GetText()); 736 EXPECT_EQ(old_text, omnibox_view->GetText());
727 omnibox_view->GetSelectionBounds(&start, &end); 737 omnibox_view->GetSelectionBounds(&start, &end);
728 EXPECT_EQ(old_text.size(), start); 738 EXPECT_EQ(old_text.size(), start);
729 EXPECT_EQ(old_text.size(), end); 739 EXPECT_EQ(old_text.size(), end);
730 } 740 }
731 741
732 void AcceptKeywordBySpaceTest() { 742 void AcceptKeywordBySpaceTest() {
733 OmniboxView* omnibox_view = NULL; 743 OmniboxView* omnibox_view = NULL;
734 ASSERT_NO_FATAL_FAILURE(GetOmniboxView(&omnibox_view)); 744 ASSERT_NO_FATAL_FAILURE(GetOmniboxView(&omnibox_view));
735 745
736 string16 text = UTF8ToUTF16(kSearchKeyword); 746 string16 search_keyword(ASCIIToUTF16(kSearchKeyword));
737 747
738 // Trigger keyword hint mode. 748 // Trigger keyword hint mode.
739 ASSERT_NO_FATAL_FAILURE(SendKeySequence(kSearchKeywordKeys)); 749 ASSERT_NO_FATAL_FAILURE(SendKeySequence(kSearchKeywordKeys));
740 ASSERT_TRUE(omnibox_view->model()->is_keyword_hint()); 750 ASSERT_TRUE(omnibox_view->model()->is_keyword_hint());
741 ASSERT_EQ(text, omnibox_view->model()->keyword()); 751 ASSERT_EQ(search_keyword, omnibox_view->model()->keyword());
742 ASSERT_EQ(text, omnibox_view->GetText()); 752 ASSERT_EQ(search_keyword, omnibox_view->GetText());
743 753
744 // Trigger keyword mode by space. 754 // Trigger keyword mode by space.
745 ASSERT_NO_FATAL_FAILURE(SendKey(ui::VKEY_SPACE, 0)); 755 ASSERT_NO_FATAL_FAILURE(SendKey(ui::VKEY_SPACE, 0));
746 ASSERT_FALSE(omnibox_view->model()->is_keyword_hint()); 756 ASSERT_FALSE(omnibox_view->model()->is_keyword_hint());
747 ASSERT_EQ(text, omnibox_view->model()->keyword()); 757 ASSERT_EQ(search_keyword, omnibox_view->model()->keyword());
748 ASSERT_TRUE(omnibox_view->GetText().empty()); 758 ASSERT_TRUE(omnibox_view->GetText().empty());
749 759
750 // Revert to keyword hint mode. 760 // Revert to keyword hint mode.
751 omnibox_view->model()->ClearKeyword(string16()); 761 omnibox_view->model()->ClearKeyword(string16());
752 ASSERT_TRUE(omnibox_view->model()->is_keyword_hint()); 762 ASSERT_TRUE(omnibox_view->model()->is_keyword_hint());
753 ASSERT_EQ(text, omnibox_view->model()->keyword()); 763 ASSERT_EQ(search_keyword, omnibox_view->model()->keyword());
754 ASSERT_EQ(text, omnibox_view->GetText()); 764 ASSERT_EQ(search_keyword, omnibox_view->GetText());
755 765
756 // Keyword should also be accepted by typing an ideographic space. 766 // Keyword should also be accepted by typing an ideographic space.
757 omnibox_view->OnBeforePossibleChange(); 767 omnibox_view->OnBeforePossibleChange();
758 omnibox_view->SetWindowTextAndCaretPos(text + WideToUTF16(L"\x3000"), 768 omnibox_view->SetWindowTextAndCaretPos(search_keyword +
759 text.length() + 1, false, false); 769 WideToUTF16(L"\x3000"), search_keyword.length() + 1, false, false);
760 omnibox_view->OnAfterPossibleChange(); 770 omnibox_view->OnAfterPossibleChange();
761 ASSERT_FALSE(omnibox_view->model()->is_keyword_hint()); 771 ASSERT_FALSE(omnibox_view->model()->is_keyword_hint());
762 ASSERT_EQ(text, omnibox_view->model()->keyword()); 772 ASSERT_EQ(search_keyword, omnibox_view->model()->keyword());
763 ASSERT_TRUE(omnibox_view->GetText().empty()); 773 ASSERT_TRUE(omnibox_view->GetText().empty());
764 774
765 // Revert to keyword hint mode. 775 // Revert to keyword hint mode.
766 omnibox_view->model()->ClearKeyword(string16()); 776 omnibox_view->model()->ClearKeyword(string16());
767 ASSERT_TRUE(omnibox_view->model()->is_keyword_hint()); 777 ASSERT_TRUE(omnibox_view->model()->is_keyword_hint());
768 ASSERT_EQ(text, omnibox_view->model()->keyword()); 778 ASSERT_EQ(search_keyword, omnibox_view->model()->keyword());
769 ASSERT_EQ(text, omnibox_view->GetText()); 779 ASSERT_EQ(search_keyword, omnibox_view->GetText());
770 780
771 // Keyword shouldn't be accepted by pressing space with a trailing 781 // Keyword shouldn't be accepted by pressing space with a trailing
772 // whitespace. 782 // whitespace.
773 omnibox_view->SetWindowTextAndCaretPos( 783 omnibox_view->SetWindowTextAndCaretPos(search_keyword + char16(' '),
774 text + char16(' '), text.length() + 1, false, false); 784 search_keyword.length() + 1, false, false);
775 ASSERT_NO_FATAL_FAILURE(SendKey(ui::VKEY_SPACE, 0)); 785 ASSERT_NO_FATAL_FAILURE(SendKey(ui::VKEY_SPACE, 0));
776 ASSERT_TRUE(omnibox_view->model()->is_keyword_hint()); 786 ASSERT_TRUE(omnibox_view->model()->is_keyword_hint());
777 ASSERT_EQ(text, omnibox_view->model()->keyword()); 787 ASSERT_EQ(search_keyword, omnibox_view->model()->keyword());
778 ASSERT_EQ(text + ASCIIToUTF16(" "), omnibox_view->GetText()); 788 ASSERT_EQ(search_keyword + ASCIIToUTF16(" "), omnibox_view->GetText());
779 789
780 // Keyword shouldn't be accepted by deleting the trailing space. 790 // Keyword shouldn't be accepted by deleting the trailing space.
781 ASSERT_NO_FATAL_FAILURE(SendKey(ui::VKEY_BACK, 0)); 791 ASSERT_NO_FATAL_FAILURE(SendKey(ui::VKEY_BACK, 0));
782 ASSERT_TRUE(omnibox_view->model()->is_keyword_hint()); 792 ASSERT_TRUE(omnibox_view->model()->is_keyword_hint());
783 ASSERT_EQ(text, omnibox_view->model()->keyword()); 793 ASSERT_EQ(search_keyword, omnibox_view->model()->keyword());
784 ASSERT_EQ(text + char16(' '), omnibox_view->GetText()); 794 ASSERT_EQ(search_keyword + char16(' '), omnibox_view->GetText());
785 795
786 // Keyword shouldn't be accepted by pressing space before a trailing space. 796 // Keyword shouldn't be accepted by pressing space before a trailing space.
787 ASSERT_NO_FATAL_FAILURE(SendKey(ui::VKEY_LEFT, 0)); 797 ASSERT_NO_FATAL_FAILURE(SendKey(ui::VKEY_LEFT, 0));
788 ASSERT_NO_FATAL_FAILURE(SendKey(ui::VKEY_SPACE, 0)); 798 ASSERT_NO_FATAL_FAILURE(SendKey(ui::VKEY_SPACE, 0));
789 ASSERT_TRUE(omnibox_view->model()->is_keyword_hint()); 799 ASSERT_TRUE(omnibox_view->model()->is_keyword_hint());
790 ASSERT_EQ(text, omnibox_view->model()->keyword()); 800 ASSERT_EQ(search_keyword, omnibox_view->model()->keyword());
791 ASSERT_EQ(text + ASCIIToUTF16(" "), omnibox_view->GetText()); 801 ASSERT_EQ(search_keyword + ASCIIToUTF16(" "), omnibox_view->GetText());
792 802
793 // Keyword should be accepted by pressing space in the middle of context and 803 // Keyword should be accepted by pressing space in the middle of context and
794 // just after the keyword. 804 // just after the keyword.
795 ASSERT_NO_FATAL_FAILURE(SendKey(ui::VKEY_BACK, 0)); 805 ASSERT_NO_FATAL_FAILURE(SendKey(ui::VKEY_BACK, 0));
796 ASSERT_NO_FATAL_FAILURE(SendKey(ui::VKEY_A, 0)); 806 ASSERT_NO_FATAL_FAILURE(SendKey(ui::VKEY_A, 0));
797 ASSERT_NO_FATAL_FAILURE(SendKey(ui::VKEY_LEFT, 0)); 807 ASSERT_NO_FATAL_FAILURE(SendKey(ui::VKEY_LEFT, 0));
798 ASSERT_NO_FATAL_FAILURE(SendKey(ui::VKEY_SPACE, 0)); 808 ASSERT_NO_FATAL_FAILURE(SendKey(ui::VKEY_SPACE, 0));
799 ASSERT_FALSE(omnibox_view->model()->is_keyword_hint()); 809 ASSERT_FALSE(omnibox_view->model()->is_keyword_hint());
800 ASSERT_EQ(text, omnibox_view->model()->keyword()); 810 ASSERT_EQ(search_keyword, omnibox_view->model()->keyword());
801 ASSERT_EQ(ASCIIToUTF16("a "), omnibox_view->GetText()); 811 ASSERT_EQ(ASCIIToUTF16("a "), omnibox_view->GetText());
802 812
803 // Keyword shouldn't be accepted by pasting "foo bar". 813 // Keyword shouldn't be accepted by pasting "foo bar".
804 omnibox_view->SetUserText(string16()); 814 omnibox_view->SetUserText(string16());
805 ASSERT_FALSE(omnibox_view->model()->is_keyword_hint()); 815 ASSERT_FALSE(omnibox_view->model()->is_keyword_hint());
806 ASSERT_TRUE(omnibox_view->model()->keyword().empty()); 816 ASSERT_TRUE(omnibox_view->model()->keyword().empty());
807 817
808 omnibox_view->OnBeforePossibleChange(); 818 omnibox_view->OnBeforePossibleChange();
809 omnibox_view->model()->on_paste(); 819 omnibox_view->model()->on_paste();
810 omnibox_view->SetWindowTextAndCaretPos(text + ASCIIToUTF16(" bar"), 820 omnibox_view->SetWindowTextAndCaretPos(search_keyword +
811 text.length() + 4, false, false); 821 ASCIIToUTF16(" bar"), search_keyword.length() + 4, false, false);
812 omnibox_view->OnAfterPossibleChange(); 822 omnibox_view->OnAfterPossibleChange();
813 ASSERT_FALSE(omnibox_view->model()->is_keyword_hint()); 823 ASSERT_FALSE(omnibox_view->model()->is_keyword_hint());
814 ASSERT_TRUE(omnibox_view->model()->keyword().empty()); 824 ASSERT_TRUE(omnibox_view->model()->keyword().empty());
815 ASSERT_EQ(text + ASCIIToUTF16(" bar"), omnibox_view->GetText()); 825 ASSERT_EQ(search_keyword + ASCIIToUTF16(" bar"), omnibox_view->GetText());
816 826
817 // Keyword shouldn't be accepted for case like: "foo b|ar" -> "foo b |ar". 827 // Keyword shouldn't be accepted for case like: "foo b|ar" -> "foo b |ar".
818 ASSERT_NO_FATAL_FAILURE(SendKey(ui::VKEY_LEFT, 0)); 828 ASSERT_NO_FATAL_FAILURE(SendKey(ui::VKEY_LEFT, 0));
819 ASSERT_NO_FATAL_FAILURE(SendKey(ui::VKEY_LEFT, 0)); 829 ASSERT_NO_FATAL_FAILURE(SendKey(ui::VKEY_LEFT, 0));
820 ASSERT_NO_FATAL_FAILURE(SendKey(ui::VKEY_SPACE, 0)); 830 ASSERT_NO_FATAL_FAILURE(SendKey(ui::VKEY_SPACE, 0));
821 ASSERT_FALSE(omnibox_view->model()->is_keyword_hint()); 831 ASSERT_FALSE(omnibox_view->model()->is_keyword_hint());
822 ASSERT_TRUE(omnibox_view->model()->keyword().empty()); 832 ASSERT_TRUE(omnibox_view->model()->keyword().empty());
823 ASSERT_EQ(text + ASCIIToUTF16(" b ar"), omnibox_view->GetText()); 833 ASSERT_EQ(search_keyword + ASCIIToUTF16(" b ar"), omnibox_view->GetText());
824 834
825 // Keyword could be accepted by pressing space with a selected range at the 835 // Keyword could be accepted by pressing space with a selected range at the
826 // end of text. 836 // end of text.
827 omnibox_view->OnBeforePossibleChange(); 837 omnibox_view->OnBeforePossibleChange();
828 omnibox_view->OnInlineAutocompleteTextMaybeChanged( 838 omnibox_view->OnInlineAutocompleteTextMaybeChanged(
829 text + ASCIIToUTF16(" "), text.length()); 839 search_keyword + ASCIIToUTF16(" "), search_keyword.length());
830 omnibox_view->OnAfterPossibleChange(); 840 omnibox_view->OnAfterPossibleChange();
831 ASSERT_TRUE(omnibox_view->model()->is_keyword_hint()); 841 ASSERT_TRUE(omnibox_view->model()->is_keyword_hint());
832 ASSERT_EQ(text, omnibox_view->model()->keyword()); 842 ASSERT_EQ(search_keyword, omnibox_view->model()->keyword());
833 ASSERT_EQ(text + ASCIIToUTF16(" "), omnibox_view->GetText()); 843 ASSERT_EQ(search_keyword + ASCIIToUTF16(" "), omnibox_view->GetText());
834 844
835 size_t start, end; 845 size_t start, end;
836 omnibox_view->GetSelectionBounds(&start, &end); 846 omnibox_view->GetSelectionBounds(&start, &end);
837 ASSERT_NE(start, end); 847 ASSERT_NE(start, end);
838 ASSERT_NO_FATAL_FAILURE(SendKey(ui::VKEY_SPACE, 0)); 848 ASSERT_NO_FATAL_FAILURE(SendKey(ui::VKEY_SPACE, 0));
839 ASSERT_FALSE(omnibox_view->model()->is_keyword_hint()); 849 ASSERT_FALSE(omnibox_view->model()->is_keyword_hint());
840 ASSERT_EQ(text, omnibox_view->model()->keyword()); 850 ASSERT_EQ(search_keyword, omnibox_view->model()->keyword());
841 ASSERT_EQ(string16(), omnibox_view->GetText()); 851 ASSERT_EQ(string16(), omnibox_view->GetText());
842 852
853 // Space should accept keyword even when inline autocomplete is available.
843 omnibox_view->SetUserText(string16()); 854 omnibox_view->SetUserText(string16());
844
845 // Space should accept keyword even when inline autocomplete is available.
846 const TestHistoryEntry kHistoryFoobar = { 855 const TestHistoryEntry kHistoryFoobar = {
847 "http://www.foobar.com", "Page foobar", kSearchText, 10000, 10000, true 856 "http://www.foobar.com", "Page foobar", kSearchText, 100, 100, true
848 }; 857 };
849 858
850 // Add a history entry to trigger inline autocomplete when typing "foo". 859 // Add a history entry to trigger inline autocomplete when typing "foo".
851 ASSERT_NO_FATAL_FAILURE( 860 ASSERT_NO_FATAL_FAILURE(
852 AddHistoryEntry(kHistoryFoobar, Time::Now() - TimeDelta::FromHours(1))); 861 AddHistoryEntry(kHistoryFoobar, Time::Now() - TimeDelta::FromHours(1)));
853 862
854 // Type "foo" to trigger inline autocomplete. 863 // Type "foo" to trigger inline autocomplete.
855 ASSERT_NO_FATAL_FAILURE(SendKeySequence(kSearchKeywordKeys)); 864 ASSERT_NO_FATAL_FAILURE(SendKeySequence(kSearchKeywordKeys));
856 ASSERT_NO_FATAL_FAILURE(WaitForAutocompleteControllerDone()); 865 ASSERT_NO_FATAL_FAILURE(WaitForAutocompleteControllerDone());
857 ASSERT_TRUE(omnibox_view->model()->popup_model()->IsOpen()); 866 ASSERT_TRUE(omnibox_view->model()->popup_model()->IsOpen());
858 ASSERT_NE(text, omnibox_view->GetText()); 867 ASSERT_NE(search_keyword, omnibox_view->GetText());
859 868
860 // Keyword hint shouldn't be visible. 869 // Keyword hint shouldn't be visible.
861 ASSERT_FALSE(omnibox_view->model()->is_keyword_hint()); 870 ASSERT_FALSE(omnibox_view->model()->is_keyword_hint());
862 ASSERT_TRUE(omnibox_view->model()->keyword().empty()); 871 ASSERT_TRUE(omnibox_view->model()->keyword().empty());
863 872
864 // Trigger keyword mode by space. 873 // Trigger keyword mode by space.
865 ASSERT_NO_FATAL_FAILURE(SendKey(ui::VKEY_SPACE, 0)); 874 ASSERT_NO_FATAL_FAILURE(SendKey(ui::VKEY_SPACE, 0));
866 ASSERT_FALSE(omnibox_view->model()->is_keyword_hint()); 875 ASSERT_FALSE(omnibox_view->model()->is_keyword_hint());
867 ASSERT_EQ(text, omnibox_view->model()->keyword()); 876 ASSERT_EQ(search_keyword, omnibox_view->model()->keyword());
868 ASSERT_TRUE(omnibox_view->GetText().empty()); 877 ASSERT_TRUE(omnibox_view->GetText().empty());
869 } 878 }
870 879
871 void NonSubstitutingKeywordTest() { 880 void NonSubstitutingKeywordTest() {
872 OmniboxView* omnibox_view = NULL; 881 OmniboxView* omnibox_view = NULL;
873 ASSERT_NO_FATAL_FAILURE(GetOmniboxView(&omnibox_view)); 882 ASSERT_NO_FATAL_FAILURE(GetOmniboxView(&omnibox_view));
874 AutocompletePopupModel* popup_model = omnibox_view->model()->popup_model(); 883 AutocompletePopupModel* popup_model = omnibox_view->model()->popup_model();
875 ASSERT_TRUE(popup_model); 884 ASSERT_TRUE(popup_model);
876 885
877 TemplateURLService* template_url_service = 886 TemplateURLService* template_url_service =
(...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after
991 omnibox_view->model()->OnUpOrDownKeyPressed(1); 1000 omnibox_view->model()->OnUpOrDownKeyPressed(1);
992 ASSERT_EQ(default_line + 1, popup_model->selected_line()); 1001 ASSERT_EQ(default_line + 1, popup_model->selected_line());
993 omnibox_view->model()->OnUpOrDownKeyPressed(-1); 1002 omnibox_view->model()->OnUpOrDownKeyPressed(-1);
994 ASSERT_EQ(default_line, popup_model->selected_line()); 1003 ASSERT_EQ(default_line, popup_model->selected_line());
995 1004
996 selected_text = popup_model->result().match_at(default_line).fill_into_edit; 1005 selected_text = popup_model->result().match_at(default_line).fill_into_edit;
997 // New temporary text is shown. 1006 // New temporary text is shown.
998 ASSERT_EQ(selected_text, omnibox_view->GetText()); 1007 ASSERT_EQ(selected_text, omnibox_view->GetText());
999 ASSERT_FALSE(omnibox_view->IsSelectAll()); 1008 ASSERT_FALSE(omnibox_view->IsSelectAll());
1000 1009
1001 #if 0 1010 #if 0
mrossetti 2012/03/02 18:11:46 Note that this should be okay to re-enable now. I'
Mark P 2012/11/07 21:23:35 You seem to have forgotten to reenable this.
1002 // TODO(mrossetti): http://crbug.com/82335 1011 // TODO(mrossetti): http://crbug.com/82335
1003 // Delete the default item. 1012 // Delete the default item.
1004 popup_model->TryDeletingCurrentItem(); 1013 popup_model->TryDeletingCurrentItem();
1005 ASSERT_NO_FATAL_FAILURE(WaitForAutocompleteControllerDone()); 1014 ASSERT_NO_FATAL_FAILURE(WaitForAutocompleteControllerDone());
1006 // The selected line shouldn't be changed, but the default item should have 1015 // The selected line shouldn't be changed, but the default item should have
1007 // been changed. 1016 // been changed.
1008 ASSERT_EQ(default_line, popup_model->selected_line()); 1017 ASSERT_EQ(default_line, popup_model->selected_line());
1009 // Make sure the item is really deleted. 1018 // Make sure the item is really deleted.
1010 EXPECT_NE(selected_text, 1019 EXPECT_NE(selected_text,
1011 popup_model->result().match_at(default_line).fill_into_edit); 1020 popup_model->result().match_at(default_line).fill_into_edit);
(...skipping 398 matching lines...) Expand 10 before | Expand all | Expand 10 after
1410 1419
1411 // Paste text. 1420 // Paste text.
1412 ASSERT_NO_FATAL_FAILURE(SendKey(ui::VKEY_V, ui::EF_CONTROL_DOWN)); 1421 ASSERT_NO_FATAL_FAILURE(SendKey(ui::VKEY_V, ui::EF_CONTROL_DOWN));
1413 ASSERT_NO_FATAL_FAILURE(WaitForAutocompleteControllerDone()); 1422 ASSERT_NO_FATAL_FAILURE(WaitForAutocompleteControllerDone());
1414 ASSERT_TRUE(popup_model->IsOpen()); 1423 ASSERT_TRUE(popup_model->IsOpen());
1415 1424
1416 // Inline autocomplete shouldn't be triggered. 1425 // Inline autocomplete shouldn't be triggered.
1417 ASSERT_EQ(ASCIIToUTF16("abc"), omnibox_view->GetText()); 1426 ASSERT_EQ(ASCIIToUTF16("abc"), omnibox_view->GetText());
1418 } 1427 }
1419 #endif 1428 #endif
OLDNEW
« no previous file with comments | « chrome/browser/history/history_backend.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698