OLD | NEW |
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/command_line.h" | 7 #include "base/command_line.h" |
8 #include "base/strings/string16.h" | 8 #include "base/strings/string16.h" |
9 #include "base/strings/string_util.h" | 9 #include "base/strings/string_util.h" |
10 #include "base/strings/utf_string_conversions.h" | 10 #include "base/strings/utf_string_conversions.h" |
(...skipping 230 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
241 ASSERT_TRUE(model); | 241 ASSERT_TRUE(model); |
242 | 242 |
243 ui_test_utils::WaitForTemplateURLServiceToLoad(model); | 243 ui_test_utils::WaitForTemplateURLServiceToLoad(model); |
244 | 244 |
245 ASSERT_TRUE(model->loaded()); | 245 ASSERT_TRUE(model->loaded()); |
246 | 246 |
247 TemplateURLData data; | 247 TemplateURLData data; |
248 data.short_name = ASCIIToUTF16(kSearchShortName); | 248 data.short_name = ASCIIToUTF16(kSearchShortName); |
249 data.SetKeyword(ASCIIToUTF16(kSearchKeyword)); | 249 data.SetKeyword(ASCIIToUTF16(kSearchKeyword)); |
250 data.SetURL(kSearchURL); | 250 data.SetURL(kSearchURL); |
251 TemplateURL* template_url = new TemplateURL(profile, data); | 251 TemplateURL* template_url = new TemplateURL(data); |
252 model->Add(template_url); | 252 model->Add(template_url); |
253 model->SetUserSelectedDefaultSearchProvider(template_url); | 253 model->SetUserSelectedDefaultSearchProvider(template_url); |
254 | 254 |
255 data.SetKeyword(ASCIIToUTF16(kSearchKeyword2)); | 255 data.SetKeyword(ASCIIToUTF16(kSearchKeyword2)); |
256 model->Add(new TemplateURL(profile, data)); | 256 model->Add(new TemplateURL(data)); |
257 | 257 |
258 // Remove built-in template urls, like google.com, bing.com etc., as they | 258 // Remove built-in template urls, like google.com, bing.com etc., as they |
259 // may appear as autocomplete suggests and interfere with our tests. | 259 // may appear as autocomplete suggests and interfere with our tests. |
260 TemplateURLService::TemplateURLVector urls = model->GetTemplateURLs(); | 260 TemplateURLService::TemplateURLVector urls = model->GetTemplateURLs(); |
261 for (TemplateURLService::TemplateURLVector::const_iterator i = urls.begin(); | 261 for (TemplateURLService::TemplateURLVector::const_iterator i = urls.begin(); |
262 i != urls.end(); | 262 i != urls.end(); |
263 ++i) { | 263 ++i) { |
264 if ((*i)->prepopulate_id() != 0) | 264 if ((*i)->prepopulate_id() != 0) |
265 model->Remove(*i); | 265 model->Remove(*i); |
266 } | 266 } |
(...skipping 323 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
590 TemplateURLService* template_url_service = | 590 TemplateURLService* template_url_service = |
591 TemplateURLServiceFactory::GetForProfile(profile); | 591 TemplateURLServiceFactory::GetForProfile(profile); |
592 | 592 |
593 // Add a non-substituting keyword. This ensures the popup will have a | 593 // Add a non-substituting keyword. This ensures the popup will have a |
594 // non-verbatim entry with "ab" as a prefix. This way, by arrowing down, we | 594 // non-verbatim entry with "ab" as a prefix. This way, by arrowing down, we |
595 // can set "abc" as temporary text in the omnibox. | 595 // can set "abc" as temporary text in the omnibox. |
596 TemplateURLData data; | 596 TemplateURLData data; |
597 data.short_name = ASCIIToUTF16("abc"); | 597 data.short_name = ASCIIToUTF16("abc"); |
598 data.SetKeyword(ASCIIToUTF16(kSearchText)); | 598 data.SetKeyword(ASCIIToUTF16(kSearchText)); |
599 data.SetURL("http://abc.com/"); | 599 data.SetURL("http://abc.com/"); |
600 template_url_service->Add(new TemplateURL(profile, data)); | 600 template_url_service->Add(new TemplateURL(data)); |
601 | 601 |
602 // Send "ab", so that an "abc" entry appears in the popup. | 602 // Send "ab", so that an "abc" entry appears in the popup. |
603 const wchar_t kSearchTextPrefixKeys[] = { ui::VKEY_A, ui::VKEY_B, 0 }; | 603 const wchar_t kSearchTextPrefixKeys[] = { ui::VKEY_A, ui::VKEY_B, 0 }; |
604 ASSERT_NO_FATAL_FAILURE(SendKeySequence(kSearchTextPrefixKeys)); | 604 ASSERT_NO_FATAL_FAILURE(SendKeySequence(kSearchTextPrefixKeys)); |
605 ASSERT_NO_FATAL_FAILURE(WaitForAutocompleteControllerDone()); | 605 ASSERT_NO_FATAL_FAILURE(WaitForAutocompleteControllerDone()); |
606 ASSERT_TRUE(popup_model->IsOpen()); | 606 ASSERT_TRUE(popup_model->IsOpen()); |
607 | 607 |
608 // Arrow down to the "abc" entry in the popup. | 608 // Arrow down to the "abc" entry in the popup. |
609 size_t size = popup_model->result().size(); | 609 size_t size = popup_model->result().size(); |
610 while (popup_model->selected_line() < size - 1) { | 610 while (popup_model->selected_line() < size - 1) { |
(...skipping 401 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1012 | 1012 |
1013 Profile* profile = browser()->profile(); | 1013 Profile* profile = browser()->profile(); |
1014 TemplateURLService* template_url_service = | 1014 TemplateURLService* template_url_service = |
1015 TemplateURLServiceFactory::GetForProfile(profile); | 1015 TemplateURLServiceFactory::GetForProfile(profile); |
1016 | 1016 |
1017 // Add a non-default substituting keyword. | 1017 // Add a non-default substituting keyword. |
1018 TemplateURLData data; | 1018 TemplateURLData data; |
1019 data.short_name = ASCIIToUTF16("Search abc"); | 1019 data.short_name = ASCIIToUTF16("Search abc"); |
1020 data.SetKeyword(ASCIIToUTF16(kSearchText)); | 1020 data.SetKeyword(ASCIIToUTF16(kSearchText)); |
1021 data.SetURL("http://abc.com/{searchTerms}"); | 1021 data.SetURL("http://abc.com/{searchTerms}"); |
1022 TemplateURL* template_url = new TemplateURL(profile, data); | 1022 TemplateURL* template_url = new TemplateURL(data); |
1023 template_url_service->Add(template_url); | 1023 template_url_service->Add(template_url); |
1024 | 1024 |
1025 omnibox_view->SetUserText(base::string16()); | 1025 omnibox_view->SetUserText(base::string16()); |
1026 | 1026 |
1027 // Non-default substituting keyword shouldn't be matched by default. | 1027 // Non-default substituting keyword shouldn't be matched by default. |
1028 ASSERT_NO_FATAL_FAILURE(SendKeySequence(kSearchTextKeys)); | 1028 ASSERT_NO_FATAL_FAILURE(SendKeySequence(kSearchTextKeys)); |
1029 ASSERT_NO_FATAL_FAILURE(WaitForAutocompleteControllerDone()); | 1029 ASSERT_NO_FATAL_FAILURE(WaitForAutocompleteControllerDone()); |
1030 ASSERT_TRUE(popup_model->IsOpen()); | 1030 ASSERT_TRUE(popup_model->IsOpen()); |
1031 | 1031 |
1032 // Check if the default match result is Search Primary Provider. | 1032 // Check if the default match result is Search Primary Provider. |
1033 ASSERT_EQ(AutocompleteMatchType::SEARCH_WHAT_YOU_TYPED, | 1033 ASSERT_EQ(AutocompleteMatchType::SEARCH_WHAT_YOU_TYPED, |
1034 popup_model->result().default_match()->type); | 1034 popup_model->result().default_match()->type); |
1035 ASSERT_EQ(kSearchTextURL, | 1035 ASSERT_EQ(kSearchTextURL, |
1036 popup_model->result().default_match()->destination_url.spec()); | 1036 popup_model->result().default_match()->destination_url.spec()); |
1037 | 1037 |
1038 omnibox_view->SetUserText(base::string16()); | 1038 omnibox_view->SetUserText(base::string16()); |
1039 ASSERT_NO_FATAL_FAILURE(WaitForAutocompleteControllerDone()); | 1039 ASSERT_NO_FATAL_FAILURE(WaitForAutocompleteControllerDone()); |
1040 ASSERT_FALSE(popup_model->IsOpen()); | 1040 ASSERT_FALSE(popup_model->IsOpen()); |
1041 | 1041 |
1042 // Try a non-substituting keyword. | 1042 // Try a non-substituting keyword. |
1043 template_url_service->Remove(template_url); | 1043 template_url_service->Remove(template_url); |
1044 data.short_name = ASCIIToUTF16("abc"); | 1044 data.short_name = ASCIIToUTF16("abc"); |
1045 data.SetURL("http://abc.com/"); | 1045 data.SetURL("http://abc.com/"); |
1046 template_url_service->Add(new TemplateURL(profile, data)); | 1046 template_url_service->Add(new TemplateURL(data)); |
1047 | 1047 |
1048 // We always allow exact matches for non-substituting keywords. | 1048 // We always allow exact matches for non-substituting keywords. |
1049 ASSERT_NO_FATAL_FAILURE(SendKeySequence(kSearchTextKeys)); | 1049 ASSERT_NO_FATAL_FAILURE(SendKeySequence(kSearchTextKeys)); |
1050 ASSERT_NO_FATAL_FAILURE(WaitForAutocompleteControllerDone()); | 1050 ASSERT_NO_FATAL_FAILURE(WaitForAutocompleteControllerDone()); |
1051 ASSERT_TRUE(popup_model->IsOpen()); | 1051 ASSERT_TRUE(popup_model->IsOpen()); |
1052 ASSERT_EQ(AutocompleteMatchType::HISTORY_KEYWORD, | 1052 ASSERT_EQ(AutocompleteMatchType::HISTORY_KEYWORD, |
1053 popup_model->result().default_match()->type); | 1053 popup_model->result().default_match()->type); |
1054 ASSERT_EQ("http://abc.com/", | 1054 ASSERT_EQ("http://abc.com/", |
1055 popup_model->result().default_match()->destination_url.spec()); | 1055 popup_model->result().default_match()->destination_url.spec()); |
1056 } | 1056 } |
(...skipping 729 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1786 omnibox_view->Update(); | 1786 omnibox_view->Update(); |
1787 EXPECT_EQ(url_c, omnibox_view->GetText()); | 1787 EXPECT_EQ(url_c, omnibox_view->GetText()); |
1788 } | 1788 } |
1789 | 1789 |
1790 IN_PROC_BROWSER_TEST_F(OmniboxViewTest, EscDisablesSearchTermReplacement) { | 1790 IN_PROC_BROWSER_TEST_F(OmniboxViewTest, EscDisablesSearchTermReplacement) { |
1791 browser()->toolbar_model()->set_url_replacement_enabled(true); | 1791 browser()->toolbar_model()->set_url_replacement_enabled(true); |
1792 chrome::FocusLocationBar(browser()); | 1792 chrome::FocusLocationBar(browser()); |
1793 ASSERT_NO_FATAL_FAILURE(SendKey(ui::VKEY_ESCAPE, 0)); | 1793 ASSERT_NO_FATAL_FAILURE(SendKey(ui::VKEY_ESCAPE, 0)); |
1794 EXPECT_FALSE(browser()->toolbar_model()->url_replacement_enabled()); | 1794 EXPECT_FALSE(browser()->toolbar_model()->url_replacement_enabled()); |
1795 } | 1795 } |
OLD | NEW |